diff options
author | Alasdair Kergon <agk@redhat.com> | 2006-05-09 21:23:51 +0000 |
---|---|---|
committer | Alasdair Kergon <agk@redhat.com> | 2006-05-09 21:23:51 +0000 |
commit | 72b2cb613a57918dadf9722c59a30ca71d751c8e (patch) | |
tree | ae0130e37b873591370abd65ff44cb2a554db049 /lib/format1 | |
parent | b810c547004a98a7fc25c8dde65cf88d82ad9652 (diff) | |
download | lvm2-72b2cb613a57918dadf9722c59a30ca71d751c8e.tar.gz lvm2-72b2cb613a57918dadf9722c59a30ca71d751c8e.tar.xz lvm2-72b2cb613a57918dadf9722c59a30ca71d751c8e.zip |
Make SIZE_SHORT the default for display_size().
Fix some memory leaks in error paths found by coverity.
Use C99 struct initialisers.
Move DEFS into configure.h.
Clean-ups to remove miscellaneous compiler warnings.
Diffstat (limited to 'lib/format1')
-rw-r--r-- | lib/format1/disk-rep.c | 26 | ||||
-rw-r--r-- | lib/format1/disk-rep.h | 16 | ||||
-rw-r--r-- | lib/format1/format1.c | 39 | ||||
-rw-r--r-- | lib/format1/import-export.c | 40 | ||||
-rw-r--r-- | lib/format1/import-extents.c | 2 | ||||
-rw-r--r-- | lib/format1/lvm1-label.c | 20 | ||||
-rw-r--r-- | lib/format1/vg_number.c | 2 |
7 files changed, 70 insertions, 75 deletions
diff --git a/lib/format1/disk-rep.c b/lib/format1/disk-rep.c index a5b4e090..4c0b1a5e 100644 --- a/lib/format1/disk-rep.c +++ b/lib/format1/disk-rep.c @@ -102,7 +102,7 @@ static void _xlate_vgd(struct vg_disk *disk) static void _xlate_extents(struct pe_disk *extents, uint32_t count) { - int i; + unsigned i; for (i = 0; i < count; i++) { extents[i].lv_num = xlate16(extents[i].lv_num); @@ -116,7 +116,7 @@ static void _xlate_extents(struct pe_disk *extents, uint32_t count) static int _munge_formats(struct pv_disk *pvd) { uint32_t pe_start; - int b, e; + unsigned b, e; switch (pvd->version) { case 1: @@ -154,7 +154,7 @@ static int _munge_formats(struct pv_disk *pvd) /* If UUID is missing, create one */ if (pvd->pv_uuid[0] == '\0') - uuid_from_num(pvd->pv_uuid, pvd->pv_number); + uuid_from_num((char *)pvd->pv_uuid, pvd->pv_number); return 1; } @@ -172,9 +172,9 @@ static void _munge_exported_vg(struct pv_disk *pvd) return; /* FIXME also check vgd->status & VG_EXPORTED? */ - l = strlen(pvd->vg_name); + l = strlen((char *)pvd->vg_name); s = sizeof(EXPORTED_TAG); - if (!strncmp(pvd->vg_name + l - s + 1, EXPORTED_TAG, s)) { + if (!strncmp((char *)pvd->vg_name + l - s + 1, EXPORTED_TAG, s)) { pvd->vg_name[l - s + 1] = '\0'; pvd->pv_status |= VG_EXPORTED; } @@ -237,14 +237,14 @@ int read_vgd(struct device *dev, struct vg_disk *vgd, struct pv_disk *pvd) /* If UUID is missing, create one */ if (vgd->vg_uuid[0] == '\0') - uuid_from_num(vgd->vg_uuid, vgd->vg_number); + uuid_from_num((char *)vgd->vg_uuid, vgd->vg_number); return 1; } static int _read_uuids(struct disk_list *data) { - int num_read = 0; + unsigned num_read = 0; struct uuid_list *ul; char buffer[NAME_LEN]; uint64_t pos = data->pvd.pv_uuidlist_on_disk.base; @@ -322,12 +322,12 @@ static int _read_extents(struct disk_list *data) static void __update_lvmcache(const struct format_type *fmt, struct disk_list *dl, struct device *dev, const char *vgid, - int exported) + unsigned exported) { struct lvmcache_info *info; - if (!(info = lvmcache_add(fmt->labeller, dl->pvd.pv_uuid, dev, - dl->pvd.vg_name, vgid, + if (!(info = lvmcache_add(fmt->labeller, (char *)dl->pvd.pv_uuid, dev, + (char *)dl->pvd.vg_name, vgid, exported ? EXPORTED_VG : 0))) { stack; return; @@ -376,14 +376,14 @@ static struct disk_list *__read_disk(const struct format_type *fmt, goto bad; } - if (vg_name && strcmp(vg_name, dl->pvd.vg_name)) { + if (vg_name && strcmp(vg_name, (char *)dl->pvd.vg_name)) { log_very_verbose("%s is not a member of the VG %s", name, vg_name); __update_lvmcache(fmt, dl, dev, NULL, 0); goto bad; } - __update_lvmcache(fmt, dl, dev, dl->vgd.vg_uuid, + __update_lvmcache(fmt, dl, dev, (char *)dl->vgd.vg_uuid, dl->vgd.vg_status & VG_EXPORTED); if (!_read_uuids(dl)) { @@ -437,7 +437,7 @@ static void _add_pv_to_list(struct list *head, struct disk_list *data) list_iterate_items(diskl, head) { pvd = &diskl->pvd; - if (!strncmp(data->pvd.pv_uuid, pvd->pv_uuid, + if (!strncmp((char *)data->pvd.pv_uuid, (char *)pvd->pv_uuid, sizeof(pvd->pv_uuid))) { if (MAJOR(data->dev->dev) != md_major()) { log_very_verbose("Ignoring duplicate PV %s on " diff --git a/lib/format1/disk-rep.h b/lib/format1/disk-rep.h index d0e8d544..30ea3e11 100644 --- a/lib/format1/disk-rep.h +++ b/lib/format1/disk-rep.h @@ -73,16 +73,16 @@ struct data_area { } __attribute__ ((packed)); struct pv_disk { - uint8_t id[2]; + int8_t id[2]; uint16_t version; /* lvm version */ struct data_area pv_on_disk; struct data_area vg_on_disk; struct data_area pv_uuidlist_on_disk; struct data_area lv_on_disk; struct data_area pe_on_disk; - uint8_t pv_uuid[NAME_LEN]; - uint8_t vg_name[NAME_LEN]; - uint8_t system_id[NAME_LEN]; /* for vgexport/vgimport */ + int8_t pv_uuid[NAME_LEN]; + int8_t vg_name[NAME_LEN]; + int8_t system_id[NAME_LEN]; /* for vgexport/vgimport */ uint32_t pv_major; uint32_t pv_number; uint32_t pv_status; @@ -98,8 +98,8 @@ struct pv_disk { } __attribute__ ((packed)); struct lv_disk { - uint8_t lv_name[NAME_LEN]; - uint8_t vg_name[NAME_LEN]; + int8_t lv_name[NAME_LEN]; + int8_t vg_name[NAME_LEN]; uint32_t lv_access; uint32_t lv_status; uint32_t lv_open; @@ -122,8 +122,8 @@ struct lv_disk { } __attribute__ ((packed)); struct vg_disk { - uint8_t vg_uuid[ID_LEN]; /* volume group UUID */ - uint8_t vg_name_dummy[NAME_LEN - ID_LEN]; /* rest of v1 VG name */ + int8_t vg_uuid[ID_LEN]; /* volume group UUID */ + int8_t vg_name_dummy[NAME_LEN - ID_LEN]; /* rest of v1 VG name */ uint32_t vg_number; /* volume group number */ uint32_t vg_access; /* read/write */ uint32_t vg_status; /* active or not */ diff --git a/lib/format1/format1.c b/lib/format1/format1.c index 1049ba09..394d659b 100644 --- a/lib/format1/format1.c +++ b/lib/format1/format1.c @@ -337,8 +337,7 @@ static int _format1_pv_setup(const struct format_type *fmt, pv->size--; if (pv->size > MAX_PV_SIZE) { log_error("Physical volumes cannot be bigger than %s", - display_size(fmt->cmd, (uint64_t) MAX_PV_SIZE, - SIZE_SHORT)); + display_size(fmt->cmd, (uint64_t) MAX_PV_SIZE)); return 0; } @@ -378,8 +377,7 @@ static int _format1_lv_setup(struct format_instance *fid, struct logical_volume } if (lv->size > max_size) { log_error("logical volumes cannot be larger than %s", - display_size(fid->fmt->cmd, max_size, - SIZE_SHORT)); + display_size(fid->fmt->cmd, max_size)); return 0; } @@ -460,18 +458,15 @@ static int _format1_vg_setup(struct format_instance *fid, struct volume_group *v if (vg->extent_size > MAX_PE_SIZE || vg->extent_size < MIN_PE_SIZE) { log_error("Extent size must be between %s and %s", - display_size(fid->fmt->cmd, (uint64_t) MIN_PE_SIZE, - SIZE_SHORT), - display_size(fid->fmt->cmd, (uint64_t) MAX_PE_SIZE, - SIZE_SHORT)); + display_size(fid->fmt->cmd, (uint64_t) MIN_PE_SIZE), + display_size(fid->fmt->cmd, (uint64_t) MAX_PE_SIZE)); return 0; } if (vg->extent_size % MIN_PE_SIZE) { log_error("Extent size must be multiple of %s", - display_size(fid->fmt->cmd, (uint64_t) MIN_PE_SIZE, - SIZE_SHORT)); + display_size(fid->fmt->cmd, (uint64_t) MIN_PE_SIZE)); return 0; } @@ -485,7 +480,7 @@ static int _format1_vg_setup(struct format_instance *fid, struct volume_group *v } static int _format1_segtype_supported(struct format_instance *fid, - struct segment_type *segtype) + const struct segment_type *segtype) { if (!(segtype->flags & SEG_FORMAT1_SUPPORT)) { stack; @@ -496,8 +491,8 @@ static int _format1_segtype_supported(struct format_instance *fid, } static struct metadata_area_ops _metadata_format1_ops = { - vg_read:_format1_vg_read, - vg_write:_format1_vg_write, + .vg_read = _format1_vg_read, + .vg_write = _format1_vg_write, }; static struct format_instance *_format1_create_instance(const struct format_type *fmt, @@ -541,15 +536,15 @@ static void _format1_destroy(const struct format_type *fmt) } static struct format_handler _format1_ops = { - pv_read:_format1_pv_read, - pv_setup:_format1_pv_setup, - pv_write:_format1_pv_write, - lv_setup:_format1_lv_setup, - vg_setup:_format1_vg_setup, - segtype_supported:_format1_segtype_supported, - create_instance:_format1_create_instance, - destroy_instance:_format1_destroy_instance, - destroy:_format1_destroy, + .pv_read = _format1_pv_read, + .pv_setup = _format1_pv_setup, + .pv_write = _format1_pv_write, + .lv_setup = _format1_lv_setup, + .vg_setup = _format1_vg_setup, + .segtype_supported = _format1_segtype_supported, + .create_instance = _format1_create_instance, + .destroy_instance = _format1_destroy_instance, + .destroy = _format1_destroy, }; #ifdef LVM1_INTERNAL diff --git a/lib/format1/import-export.c b/lib/format1/import-export.c index 52febf44..a9da3815 100644 --- a/lib/format1/import-export.c +++ b/lib/format1/import-export.c @@ -56,7 +56,7 @@ int import_pv(struct dm_pool *mem, struct device *dev, memcpy(&pv->id, pvd->pv_uuid, ID_LEN); pv->dev = dev; - if (!(pv->vg_name = dm_pool_strdup(mem, pvd->vg_name))) { + if (!(pv->vg_name = dm_pool_strdup(mem, (char *)pvd->vg_name))) { stack; return 0; } @@ -65,10 +65,10 @@ int import_pv(struct dm_pool *mem, struct device *dev, /* Store system_id from first PV if PV belongs to a VG */ if (vg && !*vg->system_id) - strncpy(vg->system_id, pvd->system_id, NAME_LEN); + strncpy(vg->system_id, (char *)pvd->system_id, NAME_LEN); if (vg && - strncmp(vg->system_id, pvd->system_id, sizeof(pvd->system_id))) + strncmp(vg->system_id, (char *)pvd->system_id, sizeof(pvd->system_id))) log_very_verbose("System ID %s on %s differs from %s for " "volume group", pvd->system_id, dev_name(pv->dev), vg->system_id); @@ -132,11 +132,11 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem, memset(pvd->vg_name, 0, sizeof(pvd->vg_name)); if (pv->vg_name) - strncpy(pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name)); + strncpy((char *)pvd->vg_name, pv->vg_name, sizeof(pvd->vg_name)); /* Preserve existing system_id if it exists */ if (vg && *vg->system_id) - strncpy(pvd->system_id, vg->system_id, sizeof(pvd->system_id)); + strncpy((char *)pvd->system_id, vg->system_id, sizeof(pvd->system_id)); /* Is VG already exported or being exported? */ if (vg && (vg->status & EXPORTED_VG)) { @@ -144,24 +144,24 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem, if (!*vg->system_id || strncmp(vg->system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG) - 1)) { - if (!_system_id(cmd, pvd->system_id, EXPORTED_TAG)) { + if (!_system_id(cmd, (char *)pvd->system_id, EXPORTED_TAG)) { stack; return 0; } } - if (strlen(pvd->vg_name) + sizeof(EXPORTED_TAG) > + if (strlen((char *)pvd->vg_name) + sizeof(EXPORTED_TAG) > sizeof(pvd->vg_name)) { log_error("Volume group name %s too long to export", pvd->vg_name); return 0; } - strcat(pvd->vg_name, EXPORTED_TAG); + strcat((char *)pvd->vg_name, EXPORTED_TAG); } /* Is VG being imported? */ if (vg && !(vg->status & EXPORTED_VG) && *vg->system_id && !strncmp(vg->system_id, EXPORTED_TAG, sizeof(EXPORTED_TAG) - 1)) { - if (!_system_id(cmd, pvd->system_id, IMPORTED_TAG)) { + if (!_system_id(cmd, (char *)pvd->system_id, IMPORTED_TAG)) { stack; return 0; } @@ -169,7 +169,7 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem, /* Generate system_id if PV is in VG */ if (!pvd->system_id || !*pvd->system_id) - if (!_system_id(cmd, pvd->system_id, "")) { + if (!_system_id(cmd, (char *)pvd->system_id, "")) { stack; return 0; } @@ -177,8 +177,8 @@ int export_pv(struct cmd_context *cmd, struct dm_pool *mem, /* Update internal system_id if we changed it */ if (vg && (!*vg->system_id || - strncmp(vg->system_id, pvd->system_id, sizeof(pvd->system_id)))) - strncpy(vg->system_id, pvd->system_id, NAME_LEN); + strncmp(vg->system_id, (char *)pvd->system_id, sizeof(pvd->system_id)))) + strncpy(vg->system_id, (char *)pvd->system_id, NAME_LEN); //pvd->pv_major = MAJOR(pv->dev); @@ -204,12 +204,12 @@ int import_vg(struct dm_pool *mem, struct vg_disk *vgd = &dl->vgd; memcpy(vg->id.uuid, vgd->vg_uuid, ID_LEN); - if (!_check_vg_name(dl->pvd.vg_name)) { + if (!_check_vg_name((char *)dl->pvd.vg_name)) { stack; return 0; } - if (!(vg->name = dm_pool_strdup(mem, dl->pvd.vg_name))) { + if (!(vg->name = dm_pool_strdup(mem, (char *)dl->pvd.vg_name))) { stack; return 0; } @@ -292,7 +292,7 @@ int import_lv(struct dm_pool *mem, struct logical_volume *lv, struct lv_disk *lv { lvid_from_lvnum(&lv->lvid, &lv->vg->id, lvd->lv_number); - if (!(lv->name = _create_lv_name(mem, lvd->lv_name))) { + if (!(lv->name = _create_lv_name(mem, (char *)lvd->lv_name))) { stack; return 0; } @@ -342,10 +342,10 @@ static void _export_lv(struct lv_disk *lvd, struct volume_group *vg, struct logical_volume *lv, const char *dev_dir) { memset(lvd, 0, sizeof(*lvd)); - snprintf(lvd->lv_name, sizeof(lvd->lv_name), "%s%s/%s", + snprintf((char *)lvd->lv_name, sizeof(lvd->lv_name), "%s%s/%s", dev_dir, vg->name, lv->name); - strcpy(lvd->vg_name, vg->name); + strcpy((char *)lvd->vg_name, vg->name); if (lv->status & LVM_READ) lvd->lv_access |= LV_READ; @@ -478,7 +478,7 @@ int import_lvs(struct dm_pool *mem, struct volume_group *vg, struct list *pvds) list_iterate_items(ll, &dl->lvds) { lvd = &ll->lvd; - if (!find_lv(vg, lvd->lv_name) && + if (!find_lv(vg, (char *)lvd->lv_name) && !_add_lv(mem, vg, lvd)) { stack; return 0; @@ -586,14 +586,14 @@ int import_snapshots(struct dm_pool *mem, struct volume_group *vg, lvnum = lvd->lv_number; - if (lvnum > MAX_LV) { + if (lvnum >= MAX_LV) { log_err("Logical volume number " "out of bounds."); return 0; } if (!lvs[lvnum] && - !(lvs[lvnum] = find_lv(vg, lvd->lv_name))) { + !(lvs[lvnum] = find_lv(vg, (char *)lvd->lv_name))) { log_err("Couldn't find logical volume '%s'.", lvd->lv_name); return 0; diff --git a/lib/format1/import-extents.c b/lib/format1/import-extents.c index 54c4a546..0f308907 100644 --- a/lib/format1/import-extents.c +++ b/lib/format1/import-extents.c @@ -93,7 +93,7 @@ static int _fill_lv_array(struct lv_map **lvs, memset(lvs, 0, sizeof(*lvs) * MAX_LV); list_iterate_items(ll, &dl->lvds) { - if (!(lvm = dm_hash_lookup(maps, strrchr(ll->lvd.lv_name, '/') + if (!(lvm = dm_hash_lookup(maps, strrchr((char *)ll->lvd.lv_name, '/') + 1))) { log_err("Physical volume (%s) contains an " "unknown logical volume (%s).", diff --git a/lib/format1/lvm1-label.c b/lib/format1/lvm1-label.c index 276b063e..320651c5 100644 --- a/lib/format1/lvm1-label.c +++ b/lib/format1/lvm1-label.c @@ -61,16 +61,16 @@ static int _lvm1_read(struct labeller *l, struct device *dev, char *buf, struct vg_disk vgd; struct lvmcache_info *info; const char *vgid = NULL; - int exported = 0; + unsigned exported = 0; munge_pvd(dev, pvd); if (*pvd->vg_name && read_vgd(dev, &vgd, pvd)) { - vgid = vgd.vg_uuid; + vgid = (char *) vgd.vg_uuid; exported = pvd->pv_status & VG_EXPORTED; } - if (!(info = lvmcache_add(l, pvd->pv_uuid, dev, pvd->vg_name, vgid, + if (!(info = lvmcache_add(l, (char *)pvd->pv_uuid, dev, (char *)pvd->vg_name, vgid, exported))) { stack; return 0; @@ -103,13 +103,13 @@ static void _lvm1_destroy(struct labeller *l) } struct label_ops _lvm1_ops = { - can_handle:_lvm1_can_handle, - write:_lvm1_write, - read:_lvm1_read, - verify:_lvm1_can_handle, - initialise_label:_lvm1_initialise_label, - destroy_label:_lvm1_destroy_label, - destroy:_lvm1_destroy + .can_handle = _lvm1_can_handle, + .write = _lvm1_write, + .read = _lvm1_read, + .verify = _lvm1_can_handle, + .initialise_label = _lvm1_initialise_label, + .destroy_label = _lvm1_destroy_label, + .destroy = _lvm1_destroy, }; struct labeller *lvm1_labeller_create(struct format_type *fmt) diff --git a/lib/format1/vg_number.c b/lib/format1/vg_number.c index a57dd097..ad3e996e 100644 --- a/lib/format1/vg_number.c +++ b/lib/format1/vg_number.c @@ -46,7 +46,7 @@ int get_free_vg_number(struct format_instance *fid, struct dev_filter *filter, memset(numbers, 0, sizeof(numbers)); list_iterate_items(dl, &all_pvs) { - if (!*dl->pvd.vg_name || !strcmp(dl->pvd.vg_name, candidate_vg)) + if (!*dl->pvd.vg_name || !strcmp((char *)dl->pvd.vg_name, candidate_vg)) continue; numbers[dl->vgd.vg_number] = 1; |