mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-22 09:57:47 +03:00
o read_vg works (or so it claims)
This commit is contained in:
parent
43b7b8cf69
commit
f5f8443131
@ -38,13 +38,45 @@ int dev_get_size(struct device *dev, uint64_t *size)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _read(int fd, void *buf, size_t count)
|
||||||
|
{
|
||||||
|
size_t n = 0;
|
||||||
|
int tot = 0;
|
||||||
|
|
||||||
|
while (tot < count) {
|
||||||
|
n = read(fd, buf, count - tot);
|
||||||
|
|
||||||
|
if (n <= 0)
|
||||||
|
return tot ? tot : n;
|
||||||
|
|
||||||
|
tot += n;
|
||||||
|
buf += n;
|
||||||
|
}
|
||||||
|
|
||||||
|
return tot;
|
||||||
|
}
|
||||||
|
|
||||||
int64_t dev_read(struct device *dev, uint64_t offset,
|
int64_t dev_read(struct device *dev, uint64_t offset,
|
||||||
int64_t len, void *buffer)
|
int64_t len, void *buffer)
|
||||||
{
|
{
|
||||||
// FIXME: lazy programmer
|
int64_t r;
|
||||||
|
int fd = open(dev->name, O_RDONLY);
|
||||||
|
|
||||||
|
if (fd < 0) {
|
||||||
|
log_sys_err("open");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lseek(fd, offset, SEEK_SET) < 0) {
|
||||||
|
log_sys_err("lseek");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = _read(fd, buffer, len);
|
||||||
|
close(fd);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
int64_t dev_write(struct device *dev, uint64_t offset,
|
int64_t dev_write(struct device *dev, uint64_t offset,
|
||||||
int64_t len, void *buffer)
|
int64_t len, void *buffer)
|
||||||
{
|
{
|
||||||
|
@ -136,7 +136,7 @@ static int _read_uuids(struct disk_list *data)
|
|||||||
ulong pos = data->pv.pv_uuidlist_on_disk.base;
|
ulong pos = data->pv.pv_uuidlist_on_disk.base;
|
||||||
ulong end = pos + data->pv.pv_uuidlist_on_disk.size;
|
ulong end = pos + data->pv.pv_uuidlist_on_disk.size;
|
||||||
|
|
||||||
while(pos < end && num_read < MAX_PV) {
|
while(pos < end && num_read < data->vg.pv_cur) {
|
||||||
if (dev_read(data->dev, pos, sizeof(buffer), buffer) !=
|
if (dev_read(data->dev, pos, sizeof(buffer), buffer) !=
|
||||||
sizeof(buffer))
|
sizeof(buffer))
|
||||||
fail;
|
fail;
|
||||||
@ -202,41 +202,43 @@ struct disk_list *read_pv(struct device *dev, struct pool *mem,
|
|||||||
struct disk_list *data = pool_alloc(mem, sizeof(*data));
|
struct disk_list *data = pool_alloc(mem, sizeof(*data));
|
||||||
data->dev = dev;
|
data->dev = dev;
|
||||||
data->mem = mem;
|
data->mem = mem;
|
||||||
|
INIT_LIST_HEAD(&data->uuids);
|
||||||
|
INIT_LIST_HEAD(&data->lvs);
|
||||||
|
|
||||||
if (!_read_pv(data)) {
|
if (!_read_pv(data)) {
|
||||||
log_err("failed to read pv data from %s\n", dev->name);
|
log_debug("failed to read pv data from %s", dev->name);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp(data->pv.id, "HM")) {
|
if (data->pv.id[0] != 'H' || data->pv.id[1] != 'M') {
|
||||||
log_info("%s does not have a valid PV identifier.\n",
|
log_debug("%s does not have a valid PV identifier.",
|
||||||
dev->name);
|
dev->name);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vg_name && strcmp(vg_name, data->pv.vg_name)) {
|
if (vg_name && strcmp(vg_name, data->pv.vg_name)) {
|
||||||
log_info("%s is not a member of the vg '%s'\n",
|
log_info("%s is not a member of the vg '%s'",
|
||||||
dev->name, vg_name);
|
dev->name, vg_name);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_read_vg(data)) {
|
if (!_read_vg(data)) {
|
||||||
log_err("failed to read vg data from pv (%s)\n", dev->name);
|
log_err("failed to read vg data from pv (%s)", dev->name);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_read_uuids(data)) {
|
if (!_read_uuids(data)) {
|
||||||
log_err("failed to read pv uuid list from %s\n", dev->name);
|
log_err("failed to read pv uuid list from %s", dev->name);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_read_lvs(data)) {
|
if (!_read_lvs(data)) {
|
||||||
log_err("failed to read lv's from %s\n", dev->name);
|
log_err("failed to read lv's from %s", dev->name);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_read_extents(data)) {
|
if (!_read_extents(data)) {
|
||||||
log_err("failed to read extents from %s\n", dev->name);
|
log_err("failed to read extents from %s", dev->name);
|
||||||
goto bad;
|
goto bad;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,7 +295,7 @@ static int _write_uuids(struct disk_list *data)
|
|||||||
|
|
||||||
list_for_each(tmp, &data->uuids) {
|
list_for_each(tmp, &data->uuids) {
|
||||||
if (pos >= end) {
|
if (pos >= end) {
|
||||||
log_err("too many uuids to fit on %s\n",
|
log_err("too many uuids to fit on %s",
|
||||||
data->dev->name);
|
data->dev->name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -370,27 +372,27 @@ static int _write_all_pv(struct disk_list *data)
|
|||||||
const char *pv_name = data->dev->name;
|
const char *pv_name = data->dev->name;
|
||||||
|
|
||||||
if (!_write_pv(data)) {
|
if (!_write_pv(data)) {
|
||||||
log_err("failed to write pv struct to %s\n", pv_name);
|
log_err("failed to write pv struct to %s", pv_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_write_vg(data)) {
|
if (!_write_vg(data)) {
|
||||||
log_err("failed to write vg data to %s\n", pv_name);
|
log_err("failed to write vg data to %s", pv_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_write_uuids(data)) {
|
if (!_write_uuids(data)) {
|
||||||
log_err("failed to write pv uuid list to %s\n", pv_name);
|
log_err("failed to write pv uuid list to %s", pv_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_write_lvs(data)) {
|
if (!_write_lvs(data)) {
|
||||||
log_err("failed to write lv's to %s\n", pv_name);
|
log_err("failed to write lv's to %s", pv_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_write_extents(data)) {
|
if (!_write_extents(data)) {
|
||||||
log_err("failed to write extents to %s\n", pv_name);
|
log_err("failed to write extents to %s", pv_name);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -412,7 +414,7 @@ int write_pvs(struct list_head *pvs)
|
|||||||
if (!(_write_all_pv(dl)))
|
if (!(_write_all_pv(dl)))
|
||||||
fail;
|
fail;
|
||||||
|
|
||||||
log_debug("successfully wrote data to %s\n", dl->dev->name);
|
log_debug("successfully wrote data to %s", dl->dev->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
#define MAX_LV 256
|
#define MAX_LV 256
|
||||||
#define MAX_VG 99
|
#define MAX_VG 99
|
||||||
|
|
||||||
#define UNMAPPED_EXTENT ((uint16_t) -1)
|
#define UNMAPPED_EXTENT 0
|
||||||
|
|
||||||
struct data_area {
|
struct data_area {
|
||||||
uint32_t base;
|
uint32_t base;
|
||||||
|
@ -25,7 +25,7 @@ static int _import_vg(struct volume_group *vg, struct list_head *pvs)
|
|||||||
if (!first) {
|
if (!first) {
|
||||||
first = &dl->vg;
|
first = &dl->vg;
|
||||||
|
|
||||||
memcpy(vg->id, &first->vg_uuid, ID_LEN);
|
memcpy(&vg->id.uuid, &first->vg_uuid, ID_LEN);
|
||||||
vg->name = NULL;
|
vg->name = NULL;
|
||||||
|
|
||||||
// FIXME: encode flags
|
// FIXME: encode flags
|
||||||
@ -58,6 +58,7 @@ static int _import_pvs(struct pool *mem, struct volume_group *vg,
|
|||||||
list_for_each(tmp, pvs) {
|
list_for_each(tmp, pvs) {
|
||||||
dl = list_entry(tmp, struct disk_list, list);
|
dl = list_entry(tmp, struct disk_list, list);
|
||||||
pvl = pool_alloc(mem, sizeof(*pvl));
|
pvl = pool_alloc(mem, sizeof(*pvl));
|
||||||
|
memset(pvl, 0, sizeof(*pvl));
|
||||||
|
|
||||||
if (!pvl) {
|
if (!pvl) {
|
||||||
stack;
|
stack;
|
||||||
@ -66,8 +67,8 @@ static int _import_pvs(struct pool *mem, struct volume_group *vg,
|
|||||||
|
|
||||||
pv = &pvl->pv;
|
pv = &pvl->pv;
|
||||||
memcpy(&pv->id, &dl->pv.pv_uuid, ID_LEN);
|
memcpy(&pv->id, &dl->pv.pv_uuid, ID_LEN);
|
||||||
// FIXME: finish
|
|
||||||
//pv->dev = ??;
|
pv->dev = dl->dev;
|
||||||
pv->vg_name = pool_strdup(mem, dl->pv.vg_name);
|
pv->vg_name = pool_strdup(mem, dl->pv.vg_name);
|
||||||
|
|
||||||
if (!pv->vg_name) {
|
if (!pv->vg_name) {
|
||||||
@ -114,7 +115,7 @@ static struct physical_volume *_find_pv(struct volume_group *vg,
|
|||||||
struct physical_volume *pv;
|
struct physical_volume *pv;
|
||||||
struct pv_list *pl;
|
struct pv_list *pl;
|
||||||
|
|
||||||
list_for_each(tmp, &vg->lvs) {
|
list_for_each(tmp, &vg->pvs) {
|
||||||
pl = list_entry(tmp, struct pv_list, list);
|
pl = list_entry(tmp, struct pv_list, list);
|
||||||
pv = &pl->pv;
|
pv = &pl->pv;
|
||||||
if (dev == pv->dev)
|
if (dev == pv->dev)
|
||||||
@ -127,14 +128,16 @@ static struct logical_volume *_add_lv(struct pool *mem,
|
|||||||
struct volume_group *vg,
|
struct volume_group *vg,
|
||||||
struct lv_disk *lvd)
|
struct lv_disk *lvd)
|
||||||
{
|
{
|
||||||
struct logical_volume *lv = pool_alloc(mem, sizeof(*lv));
|
struct lv_list *ll = pool_alloc(mem, sizeof(*ll));
|
||||||
|
struct logical_volume *lv;
|
||||||
|
|
||||||
if (!lv) {
|
if (!ll) {
|
||||||
stack;
|
stack;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
lv = &ll->lv;
|
||||||
|
|
||||||
memset(lv->id, 0, sizeof(lv->id));
|
memset(&lv->id.uuid, 0, sizeof(lv->id));
|
||||||
if (!(lv->name = pool_strdup(mem, lvd->lv_name))) {
|
if (!(lv->name = pool_strdup(mem, lvd->lv_name))) {
|
||||||
stack;
|
stack;
|
||||||
return 0;
|
return 0;
|
||||||
@ -153,6 +156,8 @@ static struct logical_volume *_add_lv(struct pool *mem,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list_add(&ll->list, &vg->lvs);
|
||||||
|
|
||||||
return lv;
|
return lv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,11 +236,12 @@ static int _import_extents(struct pool *mem, struct volume_group *vg,
|
|||||||
if (lv_num == UNMAPPED_EXTENT)
|
if (lv_num == UNMAPPED_EXTENT)
|
||||||
lv->map[le].pv = NULL;
|
lv->map[le].pv = NULL;
|
||||||
|
|
||||||
else if(lv_num >= dl->pv.lv_cur) {
|
else if(lv_num > dl->pv.lv_cur) {
|
||||||
log_err("invalid lv in extent map\n");
|
log_err("invalid lv in extent map\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
lv_num--;
|
||||||
lv = lvs[lv_num];
|
lv = lvs[lv_num];
|
||||||
le = e[i].le_num;
|
le = e[i].le_num;
|
||||||
|
|
||||||
@ -259,6 +265,9 @@ static struct volume_group *_build_vg(struct pool *mem, struct list_head *pvs)
|
|||||||
|
|
||||||
memset(vg, 0, sizeof(*vg));
|
memset(vg, 0, sizeof(*vg));
|
||||||
|
|
||||||
|
INIT_LIST_HEAD(&vg->pvs);
|
||||||
|
INIT_LIST_HEAD(&vg->lvs);
|
||||||
|
|
||||||
if (!_import_vg(vg, pvs))
|
if (!_import_vg(vg, pvs))
|
||||||
goto bad;
|
goto bad;
|
||||||
|
|
||||||
@ -284,6 +293,7 @@ static struct volume_group *_vg_read(struct io_space *is, const char *vg_name)
|
|||||||
struct pool *mem = pool_create(1024 * 10);
|
struct pool *mem = pool_create(1024 * 10);
|
||||||
struct list_head pvs;
|
struct list_head pvs;
|
||||||
struct volume_group *vg;
|
struct volume_group *vg;
|
||||||
|
INIT_LIST_HEAD(&pvs);
|
||||||
|
|
||||||
if (!mem) {
|
if (!mem) {
|
||||||
stack;
|
stack;
|
||||||
|
@ -48,7 +48,7 @@ struct id {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct physical_volume {
|
struct physical_volume {
|
||||||
struct id *id;
|
struct id id;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
char *vg_name; /* VG component of name only - not full path */
|
char *vg_name; /* VG component of name only - not full path */
|
||||||
char *exported;
|
char *exported;
|
||||||
@ -70,7 +70,7 @@ struct pe_specifier {
|
|||||||
|
|
||||||
struct logical_volume {
|
struct logical_volume {
|
||||||
/* disk */
|
/* disk */
|
||||||
struct id *id;
|
struct id id;
|
||||||
char *name; /* LV component of name only - not full path */
|
char *name; /* LV component of name only - not full path */
|
||||||
|
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
@ -84,7 +84,7 @@ struct logical_volume {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct volume_group {
|
struct volume_group {
|
||||||
struct id *id;
|
struct id id;
|
||||||
char *name; /* VG component of name only - not full path */
|
char *name; /* VG component of name only - not full path */
|
||||||
|
|
||||||
uint32_t status;
|
uint32_t status;
|
||||||
|
@ -17,22 +17,22 @@ int main(int argc, char **argv)
|
|||||||
struct dev_iter *iter;
|
struct dev_iter *iter;
|
||||||
|
|
||||||
init_log(stderr);
|
init_log(stderr);
|
||||||
init_debug(_LOG_DEBUG);
|
init_debug(_LOG_INFO);
|
||||||
|
|
||||||
if (!dev_cache_init()) {
|
if (!dev_cache_init()) {
|
||||||
log_error("couldn't initialise dev_cache_init failed\n");
|
log_err("couldn't initialise dev_cache_init failed");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (!dev_cache_add_dir(argv[i])) {
|
if (!dev_cache_add_dir(argv[i])) {
|
||||||
log_error("couldn't add '%s' to dev_cache\n", argv[i]);
|
log_err("couldn't add '%s' to dev_cache", argv[i]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(iter = dev_iter_create(NULL))) {
|
if (!(iter = dev_iter_create(NULL))) {
|
||||||
log_error("couldn't create iterator\n");
|
log_err("couldn't create iterator");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,14 +23,14 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
init_log(stderr);
|
init_log(stderr);
|
||||||
init_debug(_LOG_DEBUG);
|
init_debug(_LOG_INFO);
|
||||||
|
|
||||||
if (!dev_cache_init()) {
|
if (!dev_cache_init()) {
|
||||||
fprintf(stderr, "init of dev-cache failed\n");
|
fprintf(stderr, "init of dev-cache failed\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dev_cache_add_dir("/dev")) {
|
if (!dev_cache_add_dir("/dev/loop")) {
|
||||||
fprintf(stderr, "couldn't add /dev to dir-cache\n");
|
fprintf(stderr, "couldn't add /dev to dir-cache\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -56,6 +56,8 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
ios->destroy(ios);
|
ios->destroy(ios);
|
||||||
|
|
||||||
|
pool_destroy(mem);
|
||||||
|
dev_cache_exit();
|
||||||
dump_memory();
|
dump_memory();
|
||||||
fin_log();
|
fin_log();
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user