1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-10 05:18:36 +03:00

o read_vg works (or so it claims)

This commit is contained in:
Joe Thornber 2001-10-08 16:08:16 +00:00
parent 22e9960697
commit 66c887d0f3
7 changed files with 83 additions and 37 deletions

View File

@ -38,11 +38,43 @@ int dev_get_size(struct device *dev, uint64_t *size)
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 len, void *buffer)
{
// FIXME: lazy programmer
return 0;
int64_t r;
int fd = open(dev->name, O_RDONLY);
if (fd < 0) {
log_sys_err("open");
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,

View File

@ -136,7 +136,7 @@ static int _read_uuids(struct disk_list *data)
ulong pos = data->pv.pv_uuidlist_on_disk.base;
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) !=
sizeof(buffer))
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));
data->dev = dev;
data->mem = mem;
INIT_LIST_HEAD(&data->uuids);
INIT_LIST_HEAD(&data->lvs);
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;
}
if (strcmp(data->pv.id, "HM")) {
log_info("%s does not have a valid PV identifier.\n",
if (data->pv.id[0] != 'H' || data->pv.id[1] != 'M') {
log_debug("%s does not have a valid PV identifier.",
dev->name);
goto bad;
}
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);
goto bad;
}
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;
}
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;
}
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;
}
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;
}
@ -293,7 +295,7 @@ static int _write_uuids(struct disk_list *data)
list_for_each(tmp, &data->uuids) {
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);
return 0;
}
@ -370,27 +372,27 @@ static int _write_all_pv(struct disk_list *data)
const char *pv_name = data->dev->name;
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;
}
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;
}
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;
}
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;
}
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;
}
@ -412,7 +414,7 @@ int write_pvs(struct list_head *pvs)
if (!(_write_all_pv(dl)))
fail;
log_debug("successfully wrote data to %s\n", dl->dev->name);
log_debug("successfully wrote data to %s", dl->dev->name);
}
return 1;

View File

@ -15,7 +15,7 @@
#define MAX_LV 256
#define MAX_VG 99
#define UNMAPPED_EXTENT ((uint16_t) -1)
#define UNMAPPED_EXTENT 0
struct data_area {
uint32_t base;

View File

@ -25,7 +25,7 @@ static int _import_vg(struct volume_group *vg, struct list_head *pvs)
if (!first) {
first = &dl->vg;
memcpy(vg->id, &first->vg_uuid, ID_LEN);
memcpy(&vg->id.uuid, &first->vg_uuid, ID_LEN);
vg->name = NULL;
// FIXME: encode flags
@ -58,6 +58,7 @@ static int _import_pvs(struct pool *mem, struct volume_group *vg,
list_for_each(tmp, pvs) {
dl = list_entry(tmp, struct disk_list, list);
pvl = pool_alloc(mem, sizeof(*pvl));
memset(pvl, 0, sizeof(*pvl));
if (!pvl) {
stack;
@ -66,8 +67,8 @@ static int _import_pvs(struct pool *mem, struct volume_group *vg,
pv = &pvl->pv;
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);
if (!pv->vg_name) {
@ -114,7 +115,7 @@ static struct physical_volume *_find_pv(struct volume_group *vg,
struct physical_volume *pv;
struct pv_list *pl;
list_for_each(tmp, &vg->lvs) {
list_for_each(tmp, &vg->pvs) {
pl = list_entry(tmp, struct pv_list, list);
pv = &pl->pv;
if (dev == pv->dev)
@ -127,14 +128,16 @@ static struct logical_volume *_add_lv(struct pool *mem,
struct volume_group *vg,
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;
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))) {
stack;
return 0;
@ -153,6 +156,8 @@ static struct logical_volume *_add_lv(struct pool *mem,
return 0;
}
list_add(&ll->list, &vg->lvs);
return lv;
}
@ -231,11 +236,12 @@ static int _import_extents(struct pool *mem, struct volume_group *vg,
if (lv_num == UNMAPPED_EXTENT)
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");
return 0;
} else {
lv_num--;
lv = lvs[lv_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));
INIT_LIST_HEAD(&vg->pvs);
INIT_LIST_HEAD(&vg->lvs);
if (!_import_vg(vg, pvs))
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 list_head pvs;
struct volume_group *vg;
INIT_LIST_HEAD(&pvs);
if (!mem) {
stack;

View File

@ -48,7 +48,7 @@ struct id {
};
struct physical_volume {
struct id *id;
struct id id;
struct device *dev;
char *vg_name; /* VG component of name only - not full path */
char *exported;
@ -70,7 +70,7 @@ struct pe_specifier {
struct logical_volume {
/* disk */
struct id *id;
struct id id;
char *name; /* LV component of name only - not full path */
uint32_t status;
@ -84,7 +84,7 @@ struct logical_volume {
};
struct volume_group {
struct id *id;
struct id id;
char *name; /* VG component of name only - not full path */
uint32_t status;
@ -107,7 +107,7 @@ struct volume_group {
struct name_list {
struct list_head list;
char * name;
char *name;
};
struct pv_list {

View File

@ -17,22 +17,22 @@ int main(int argc, char **argv)
struct dev_iter *iter;
init_log(stderr);
init_debug(_LOG_DEBUG);
init_debug(_LOG_INFO);
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);
}
for (i = 1; i < argc; 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);
}
}
if (!(iter = dev_iter_create(NULL))) {
log_error("couldn't create iterator\n");
log_err("couldn't create iterator");
exit(1);
}

View File

@ -23,14 +23,14 @@ int main(int argc, char **argv)
}
init_log(stderr);
init_debug(_LOG_DEBUG);
init_debug(_LOG_INFO);
if (!dev_cache_init()) {
fprintf(stderr, "init of dev-cache failed\n");
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");
exit(1);
}
@ -56,6 +56,8 @@ int main(int argc, char **argv)
ios->destroy(ios);
pool_destroy(mem);
dev_cache_exit();
dump_memory();
fin_log();
return 0;