From 5238b63f1ac67e97f0e246a2f506cc0ba78ad2c2 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Wed, 14 Nov 2001 13:52:38 +0000 Subject: [PATCH] Miscellaneous tidying --- lib/device/dev-io.c | 18 +++++++---- lib/format1/disk-rep.c | 2 +- lib/format1/disk-rep.h | 19 +++++------ lib/format1/format1.c | 26 +++++++-------- lib/format1/import-export.c | 64 ++++++++++++++++++------------------- lib/metadata/lv_manip.c | 19 +++++------ lib/metadata/metadata.c | 2 +- lib/metadata/metadata.h | 2 +- tools/lvcreate.c | 9 ++++-- 9 files changed, 85 insertions(+), 76 deletions(-) diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c index 552cb5e0b..0ae07038e 100644 --- a/lib/device/dev-io.c +++ b/lib/device/dev-io.c @@ -44,13 +44,14 @@ int dev_open(struct device *dev, int flags) { const char *name = dev_name(dev); + /* FIXME Check flags (eg is write now reqd?) */ if (dev->fd >= 0) { - log_err("Device '%s' has already been opened", name); + log_error("Device '%s' has already been opened", name); return 0; } if ((dev->fd = open(name, flags)) < 0) { - log_sys_error("open", "opening device"); + log_sys_error("open", name); return 0; } @@ -60,12 +61,14 @@ int dev_open(struct device *dev, int flags) int dev_close(struct device *dev) { if (dev->fd < 0) { - log_err("Request to close device '%s', " - "which has not been opened.", dev_name(dev)); + log_error("Attempt to close device '%s' " + "which is not open.", dev_name(dev)); return 0; } - close(dev->fd); + if (close(dev->fd)) + log_sys_error("close", dev_name(dev)); + dev->fd = -1; return 1; @@ -140,7 +143,7 @@ int64_t dev_write(struct device *dev, uint64_t offset, int fd = dev->fd; if (fd < 0) { - log_err("Attempt to write to an unopened device (%s).", name); + log_error("Attempt to write to unopened device %s", name); return 0; } @@ -160,7 +163,8 @@ int dev_zero(struct device *dev, uint64_t offset, int64_t len) int fd = dev->fd; if (fd < 0) { - log_err("Attempt to zero an unopened device (%s).", name); + log_error("Attempt to zero part of an unopened device %s", + name); return 0; } diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c index df61448d1..09bbc4dc7 100644 --- a/lib/format1/disk-rep.c +++ b/lib/format1/disk-rep.c @@ -411,7 +411,7 @@ static int _write_lvs(struct disk_list *data) pos = data->pvd.lv_on_disk.base; if (!dev_zero(data->dev, pos, data->pvd.lv_on_disk.size)) { - log_err("couldn't zero lv area on device '%s'", + log_error("Couldn't zero lv area on device '%s'", dev_name(data->dev)); return 0; } diff --git a/lib/format1/disk-rep.h b/lib/format1/disk-rep.h index 051f25e23..261f13fd8 100644 --- a/lib/format1/disk-rep.h +++ b/lib/format1/disk-rep.h @@ -184,7 +184,7 @@ struct disk_list *read_disk(struct device *dev, struct pool *mem, int read_pvs_in_vg(const char *vg_name, struct dev_filter *filter, struct pool *mem, struct list *results); -int write_disks(struct list *pvs); +int write_disks(struct list *pvds); /* @@ -202,31 +202,32 @@ int export_vg(struct vg_disk *vgd, struct volume_group *vg); int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd); void export_lv(struct lv_disk *lvd, struct volume_group *vg, - struct logical_volume *lv, const char *prefix); + struct logical_volume *lv, const char *dev_dir); -int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvs); +int import_extents(struct pool *mem, struct volume_group *vg, + struct list *pvds); int export_extents(struct disk_list *dl, int lv_num, struct logical_volume *lv, struct physical_volume *pv); -int import_pvs(struct pool *mem, struct list *pvs, +int import_pvs(struct pool *mem, struct list *pvds, struct list *results, int *count); int import_lvs(struct pool *mem, struct volume_group *vg, - struct list *pvs); + struct list *pvds); int export_lvs(struct disk_list *dl, struct volume_group *vg, - struct physical_volume *pv, const char *prefix); + struct physical_volume *pv, const char *dev_dir); int export_uuids(struct disk_list *dl, struct volume_group *vg); -void export_numbers(struct list *pvs, struct volume_group *vg); +void export_numbers(struct list *pvds, struct volume_group *vg); -void export_pv_act(struct list *pvs); +void export_pv_act(struct list *pvds); /* blech */ int get_free_vg_number(struct dev_filter *filter, const char *candidate_vg, int *result); -int export_vg_number(struct list *pvs, const char *vg_name, +int export_vg_number(struct list *pvds, const char *vg_name, struct dev_filter *filter); diff --git a/lib/format1/format1.c b/lib/format1/format1.c index fdfe2da7d..2b3e55580 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -100,7 +100,7 @@ static struct volume_group *_vg_read(struct format_instance *fi, return NULL; } - /* Strip prefix if present */ + /* Strip dev_dir if present */ vg_name = strip_dir(vg_name, fi->cmd->dev_dir); if (!read_pvs_in_vg(vg_name, fi->cmd->filter, mem, &pvs)) { @@ -122,7 +122,7 @@ static struct volume_group *_vg_read(struct format_instance *fi, static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg, struct physical_volume *pv, - const char *prefix) + const char *dev_dir) { struct disk_list *dl = pool_alloc(mem, sizeof(*dl)); @@ -140,7 +140,7 @@ static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg, if (!export_pv(&dl->pvd, pv) || !export_vg(&dl->vgd, vg) || !export_uuids(dl, vg) || - !export_lvs(dl, vg, pv, prefix) || + !export_lvs(dl, vg, pv, dev_dir) || !calculate_layout(dl)) { stack; pool_free(mem, dl); @@ -151,7 +151,7 @@ static struct disk_list *_flatten_pv(struct pool *mem, struct volume_group *vg, } static int _flatten_vg(struct pool *mem, struct volume_group *vg, - struct list *pvs, const char *prefix, + struct list *pvds, const char *dev_dir, struct dev_filter *filter) { struct list *pvh; @@ -161,18 +161,18 @@ static int _flatten_vg(struct pool *mem, struct volume_group *vg, list_iterate(pvh, &vg->pvs) { pvl = list_item(pvh, struct pv_list); - if (!(data = _flatten_pv(mem, vg, &pvl->pv, prefix))) { + if (!(data = _flatten_pv(mem, vg, &pvl->pv, dev_dir))) { stack; return 0; } - list_add(pvs, &data->list); + list_add(pvds, &data->list); } - export_numbers(pvs, vg); - export_pv_act(pvs); + export_numbers(pvds, vg); + export_pv_act(pvds); - if (!export_vg_number(pvs, vg->name, filter)) { + if (!export_vg_number(pvds, vg->name, filter)) { stack; return 0; } @@ -183,7 +183,7 @@ static int _flatten_vg(struct pool *mem, struct volume_group *vg, static int _vg_write(struct format_instance *fi, struct volume_group *vg) { struct pool *mem = pool_create(1024 * 10); - struct list pvs; + struct list pvds; int r = 0; if (!mem) { @@ -191,10 +191,10 @@ static int _vg_write(struct format_instance *fi, struct volume_group *vg) return 0; } - list_init(&pvs); + list_init(&pvds); - r = (_flatten_vg(mem, vg, &pvs, fi->cmd->dev_dir, fi->cmd->filter) && - write_disks(&pvs)); + r = (_flatten_vg(mem, vg, &pvds, fi->cmd->dev_dir, fi->cmd->filter) && + write_disks(&pvds)); pool_destroy(mem); return r; } diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index cd6922589..0e7bf57ec 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -279,11 +279,11 @@ int import_lv(struct pool *mem, struct logical_volume *lv, struct lv_disk *lvd) } void export_lv(struct lv_disk *lvd, struct volume_group *vg, - struct logical_volume *lv, const char *prefix) + struct logical_volume *lv, const char *dev_dir) { memset(lvd, 0, sizeof(*lvd)); snprintf(lvd->lv_name, sizeof(lvd->lv_name), "%s%s/%s", - prefix, vg->name, lv->name); + dev_dir, vg->name, lv->name); /* FIXME: Add 'if' test */ _check_vg_name(vg->name); @@ -323,7 +323,7 @@ void export_lv(struct lv_disk *lvd, struct volume_group *vg, lvd->lv_allocation |= LV_CONTIGUOUS; } -int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvs) +int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvds) { struct disk_list *dl; struct logical_volume *lv, *lvs[MAX_LV]; @@ -331,10 +331,10 @@ int import_extents(struct pool *mem, struct volume_group *vg, struct list *pvs) struct pe_disk *e; int i; uint32_t lv_num, le; - struct list *pvh; + struct list *pvdh; - list_iterate(pvh, pvs) { - dl = list_item(pvh, struct disk_list); + list_iterate(pvdh, pvds) { + dl = list_item(pvdh, struct disk_list); pv = _find_pv(vg, dl->dev); e = dl->extents; @@ -391,16 +391,16 @@ int export_extents(struct disk_list *dl, int lv_num, return 1; } -int import_pvs(struct pool *mem, struct list *pvs, +int import_pvs(struct pool *mem, struct list *pvds, struct list *results, int *count) { - struct list *pvh; + struct list *pvdh; struct disk_list *dl; struct pv_list *pvl; *count = 0; - list_iterate(pvh, pvs) { - dl = list_item(pvh, struct disk_list); + list_iterate(pvdh, pvds) { + dl = list_item(pvdh, struct disk_list); pvl = pool_alloc(mem, sizeof(*pvl)); if (!pvl) { @@ -446,17 +446,17 @@ static struct logical_volume *_add_lv(struct pool *mem, } int import_lvs(struct pool *mem, struct volume_group *vg, - struct list *pvs) + struct list *pvds) { struct disk_list *dl; struct lvd_list *ll; struct lv_disk *lvd; - struct list *pvh, *lvh; + struct list *pvdh, *lvdh; - list_iterate(pvh, pvs) { - dl = list_item(pvh, struct disk_list); - list_iterate(lvh, &dl->lvds) { - ll = list_item(lvh, struct lvd_list); + list_iterate(pvdh, pvds) { + dl = list_item(pvdh, struct disk_list); + list_iterate(lvdh, &dl->lvds) { + ll = list_item(lvdh, struct lvd_list); lvd = &ll->lvd; if (!find_lv(vg, lvd->lv_name) && @@ -471,7 +471,7 @@ int import_lvs(struct pool *mem, struct volume_group *vg, } int export_lvs(struct disk_list *dl, struct volume_group *vg, - struct physical_volume *pv, const char *prefix) + struct physical_volume *pv, const char *dev_dir) { struct list *lvh; struct lv_list *ll; @@ -496,7 +496,7 @@ int export_lvs(struct disk_list *dl, struct volume_group *vg, return 0; } - export_lv(&lvdl->lvd, vg, &ll->lv, prefix); + export_lv(&lvdl->lvd, vg, &ll->lv, dev_dir); lvdl->lvd.lv_number = lv_num; if (!export_extents(dl, lv_num + 1, &ll->lv, pv)) { stack; @@ -536,14 +536,14 @@ int export_uuids(struct disk_list *dl, struct volume_group *vg) * lv_number fields used by LVM1. Very * inefficient code. */ -void export_numbers(struct list *pvs, struct volume_group *vg) +void export_numbers(struct list *pvds, struct volume_group *vg) { - struct list *pvh; + struct list *pvdh; struct disk_list *dl; int pv_num = 1; - list_iterate(pvh, pvs) { - dl = list_item(pvh, struct disk_list); + list_iterate(pvdh, pvds) { + dl = list_item(pvdh, struct disk_list); dl->pvd.pv_number = pv_num++; } } @@ -551,28 +551,28 @@ void export_numbers(struct list *pvs, struct volume_group *vg) /* * Calculate vg_disk->pv_act. */ -void export_pv_act(struct list *pvs) +void export_pv_act(struct list *pvds) { - struct list *pvh; + struct list *pvdh; struct disk_list *dl; int act = 0; - list_iterate(pvh, pvs) { - dl = list_item(pvh, struct disk_list); + list_iterate(pvdh, pvds) { + dl = list_item(pvdh, struct disk_list); if (dl->pvd.pv_status & PV_ACTIVE) act++; } - list_iterate(pvh, pvs) { - dl = list_item(pvh, struct disk_list); + list_iterate(pvdh, pvds) { + dl = list_item(pvdh, struct disk_list); dl->vgd.pv_act = act; } } -int export_vg_number(struct list *pvs, const char *vg_name, +int export_vg_number(struct list *pvds, const char *vg_name, struct dev_filter *filter) { - struct list *pvh; + struct list *pvdh; struct disk_list *dl; int vg_num; @@ -581,8 +581,8 @@ int export_vg_number(struct list *pvs, const char *vg_name, return 0; } - list_iterate(pvh, pvs) { - dl = list_item(pvh, struct disk_list); + list_iterate(pvdh, pvds) { + dl = list_item(pvdh, struct disk_list); dl->vgd.vg_number = vg_num; } diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c index f0d8fe4a1..02ba761d3 100644 --- a/lib/metadata/lv_manip.c +++ b/lib/metadata/lv_manip.c @@ -160,8 +160,8 @@ static int _allocate(struct volume_group *vg, struct logical_volume *lv, r = _alloc_simple(lv, pvms, allocated); else { - log_err("Unknown allocation policy, " - "unable to setup logical volume."); + log_error("Unknown allocation policy: " + "unable to setup logical volume."); goto out; } @@ -179,7 +179,7 @@ static char *_make_up_lv_name(struct volume_group *vg, { struct list *lvh; struct logical_volume *lv; - int high = 1, i; + int high = 1, i, s; list_iterate(lvh, &vg->lvs) { lv = &(list_item(lvh, struct lv_list)->lv); @@ -191,7 +191,7 @@ static char *_make_up_lv_name(struct volume_group *vg, high = i + 1; } - if (snprintf(buffer, len, "lvol%d", high) < 0) + if ((s = snprintf(buffer, len, "lvol%d", high)) < 0 || s >= len) return NULL; return buffer; @@ -212,14 +212,14 @@ struct logical_volume *lv_create(const char *name, int i; if (!extents) { - log_err("Unable to create logical volume %s with no extents", - name); + log_error("Unable to create logical volume %s with no extents", + name); return NULL; } if (vg->free_count < extents) { - log_err("Insufficient free extents (%u) in volume group %s: " - "%u required", vg->free_count, vg->name, extents); + log_error("Insufficient free extents (%u) in volume group %s: " + "%u required", vg->free_count, vg->name, extents); return NULL; } @@ -231,7 +231,8 @@ struct logical_volume *lv_create(const char *name, if (!name && !(name = _make_up_lv_name(vg, dname, sizeof(dname)))) { - log_err("Unable to think of a name for logical volume."); + log_error("Failed to generate unique name for the new " + "logical volume"); return NULL; } diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 24be027f5..304b8642a 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -149,7 +149,7 @@ struct volume_group *vg_create(struct format_instance *fi, const char *vg_name, goto bad; } - /* Strip prefix if present */ + /* Strip dev_dir if present */ vg_name = strip_dir(vg_name, fi->cmd->dev_dir); if (!(vg->name = pool_strdup(mem, vg_name))) { diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h index a87054618..1d9e91c88 100644 --- a/lib/metadata/metadata.h +++ b/lib/metadata/metadata.h @@ -277,7 +277,7 @@ struct physical_volume *_find_pv(struct volume_group *vg, struct device *dev); struct logical_volume *find_lv(struct volume_group *vg, const char *lv_name); /* - * Remove a prefix directory if present. + * Remove a dev_dir if present. */ const char *strip_dir(const char *vg_name, const char *dir); diff --git a/tools/lvcreate.c b/tools/lvcreate.c index 383c5eec8..f16fc0368 100644 --- a/tools/lvcreate.c +++ b/tools/lvcreate.c @@ -84,7 +84,7 @@ int lvcreate(int argc, char **argv) /* If VG not on command line, try -n arg and then environment */ if (!argc) { - if (!lv_name || !(vg_name = extract_vgname(fid, lv_name))) { + if (!(vg_name = extract_vgname(fid, lv_name))) { log_error("Please provide a volume group name"); return EINVALID_CMD_LINE; } @@ -236,7 +236,7 @@ int lvcreate(int argc, char **argv) if (!lv_activate(lv)) return ECMD_FAILED; - if (0) { + if (zero) { struct device *dev; /* FIXME 2 blocks */ char buf[4096]; @@ -245,13 +245,16 @@ int lvcreate(int argc, char **argv) log_verbose("Zeroing start of logical volume %s", lv->name); - /* FIXME get dev = dev_cache_get(lv_name, fid->cmd->filter); */ + log_print("WARNING: %s not zeroed", lv->name); + /* FIXME get dev = dev_cache_get(lv->name, fid->cmd->filter); */ /* FIXME Add fsync! */ +/******** FIXME Really zero it if (!(dev_write(dev, 0, sizeof(buf), &buf) == sizeof(buf))) { log_error("Initialisation of %s failed", dev_name(dev)); return ECMD_FAILED; } +**************/ } else log_print("WARNING: %s not zeroed", lv->name);