diff options
author | Alasdair Kergon <agk@redhat.com> | 2002-12-19 23:25:55 +0000 |
---|---|---|
committer | Alasdair Kergon <agk@redhat.com> | 2002-12-19 23:25:55 +0000 |
commit | 8ef2b021edcdec38f160675349c4797335f7a264 (patch) | |
tree | 9abf06514583ded09112a98cb066879f557bee87 /lib/format_text | |
parent | 4c64ed4ced7dcd3a98a63da1cd3a6f2f1f2d1701 (diff) | |
download | lvm2-8ef2b021edcdec38f160675349c4797335f7a264.tar.gz |
Default stripesize 64k & config file setting for it;
Clear many compiler warnings (i386) & associated bugs - hopefully without
introducing too many new bugs:-) (Same exercise required for other archs.)
Default compilation has optimisation - or else use ./configure --enable-debug
Diffstat (limited to 'lib/format_text')
-rw-r--r-- | lib/format_text/archive.c | 28 | ||||
-rw-r--r-- | lib/format_text/export.c | 13 | ||||
-rw-r--r-- | lib/format_text/flags.c | 6 | ||||
-rw-r--r-- | lib/format_text/format-text.c | 94 | ||||
-rw-r--r-- | lib/format_text/format-text.h | 8 | ||||
-rw-r--r-- | lib/format_text/import_vsn1.c | 2 | ||||
-rw-r--r-- | lib/format_text/text_label.c | 8 |
7 files changed, 85 insertions, 74 deletions
diff --git a/lib/format_text/archive.c b/lib/format_text/archive.c index f2397d26c..b5b6b3c2a 100644 --- a/lib/format_text/archive.c +++ b/lib/format_text/archive.c @@ -51,23 +51,23 @@ struct archive_file { * Extract vg name and version number from a filename. */ static int _split_vg(const char *filename, char *vg, size_t vg_size, - uint32_t *index) + uint32_t *ix) { - int len, vg_len; - char *dot, *underscore; + size_t len, vg_len; + const char *dot, *underscore; len = strlen(filename); if (len < 7) return 0; - dot = (char *) (filename + len - 3); + dot = (filename + len - 3); if (strcmp(".vg", dot)) return 0; if (!(underscore = rindex(filename, '_'))) return 0; - if (sscanf(underscore + 1, "%u", index) != 1) + if (sscanf(underscore + 1, "%u", ix) != 1) return 0; vg_len = underscore - filename; @@ -83,7 +83,7 @@ static int _split_vg(const char *filename, char *vg, size_t vg_size, static void _insert_file(struct list *head, struct archive_file *b) { struct list *bh; - struct archive_file *bf; + struct archive_file *bf = NULL; if (list_empty(head)) { list_add(head, &b->list); @@ -123,7 +123,7 @@ static char *_join(struct pool *mem, const char *dir, const char *name) static struct list *_scan_archive(struct pool *mem, const char *vg, const char *dir) { - int i, count, index; + int i, count, ix; char vg_name[64], *path; struct dirent **dirent; struct archive_file *af; @@ -149,7 +149,7 @@ static struct list *_scan_archive(struct pool *mem, /* check the name is the correct format */ if (!_split_vg(dirent[i]->d_name, vg_name, sizeof(vg_name), - &index)) + &ix)) continue; /* is it the vg we're interested in ? */ @@ -170,7 +170,7 @@ static struct list *_scan_archive(struct pool *mem, goto out; } - af->index = index; + af->index = ix; af->path = path; /* @@ -231,7 +231,7 @@ int archive_vg(struct volume_group *vg, uint32_t retain_days, uint32_t min_archive) { int i, fd, renamed = 0; - unsigned int index = 0; + unsigned int ix = 0; struct archive_file *last; FILE *fp = NULL; char temp_file[PATH_MAX], archive_name[PATH_MAX]; @@ -268,15 +268,15 @@ int archive_vg(struct volume_group *vg, } if (list_empty(archives)) - index = 0; + ix = 0; else { last = list_item(archives->p, struct archive_file); - index = last->index + 1; + ix = last->index + 1; } for (i = 0; i < 10; i++) { if (lvm_snprintf(archive_name, sizeof(archive_name), - "%s/%s_%05d.vg", dir, vg->name, index) < 0) { + "%s/%s_%05d.vg", dir, vg->name, ix) < 0) { log_error("Archive file name too long."); return 0; } @@ -284,7 +284,7 @@ int archive_vg(struct volume_group *vg, if ((renamed = lvm_rename(temp_file, archive_name))) break; - index++; + ix++; } if (!renamed) diff --git a/lib/format_text/export.c b/lib/format_text/export.c index 8c7e54572..50b36a346 100644 --- a/lib/format_text/export.c +++ b/lib/format_text/export.c @@ -173,7 +173,7 @@ static int _out_with_comment_raw(struct formatter *f, const char *comment, */ static int _sectors_to_units(uint64_t sectors, char *buffer, size_t s) { - static char *_units[] = { + static const char *_units[] = { "Kilobytes", "Megabytes", "Gigabytes", @@ -288,7 +288,8 @@ static int _print_vg(struct formatter *f, struct volume_group *vg) _outf(f, "status = %s", buffer); if (vg->system_id && *vg->system_id) _outf(f, "system_id = \"%s\"", vg->system_id); - if (!_out_size(f, vg->extent_size, "extent_size = %u", vg->extent_size)) { + if (!_out_size(f, (uint64_t) vg->extent_size, "extent_size = %u", + vg->extent_size)) { stack; return 0; } @@ -369,15 +370,15 @@ static int _print_pvs(struct formatter *f, struct volume_group *vg) static int _print_segment(struct formatter *f, struct volume_group *vg, int count, struct lv_segment *seg) { - int s; + unsigned int s; const char *name; _outf(f, "segment%u {", count); _inc_indent(f); _outf(f, "start_extent = %u", seg->le); - if (!_out_size(f, seg->len * vg->extent_size, "extent_count = %u", - seg->len)) { + if (!_out_size(f, (uint64_t) seg->len * vg->extent_size, + "extent_count = %u", seg->len)) { stack; return 0; } @@ -391,7 +392,7 @@ static int _print_segment(struct formatter *f, struct volume_group *vg, (seg->stripes == 1) ? "\t# linear" : ""); if (seg->stripes > 1) - _out_size(f, seg->stripe_size, + _out_size(f, (uint64_t) seg->stripe_size, "stripe_size = %u", seg->stripe_size); f->nl(f); diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c index 63f8a4795..d504b7ef9 100644 --- a/lib/format_text/flags.c +++ b/lib/format_text/flags.c @@ -14,8 +14,8 @@ * converted into arrays of strings. */ struct flag { - int mask; - char *description; + const int mask; + const char *description; }; static struct flag _vg_flags[] = { @@ -62,7 +62,7 @@ static struct flag *_get_flags(int type) static int _emit(char **buffer, size_t *size, const char *fmt, ...) { - size_t n; + int n; va_list ap; va_start(ap, fmt); diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c index 31cef13e6..f400971fe 100644 --- a/lib/format_text/format-text.c +++ b/lib/format_text/format-text.c @@ -27,8 +27,8 @@ #include <dirent.h> #include <ctype.h> -static struct format_instance *_create_text_instance(struct format_type *fmt, - const char *vgname, +static struct format_instance *_create_text_instance(const struct format_type + *fmt, const char *vgname, void *context); struct dir_list { @@ -48,9 +48,7 @@ struct text_context { }; /* - * NOTE: Currently there can be only one vg per text file, and locking - * assumes VG's metadata is only held in metadata areas on PVs - * inside the VG. + * NOTE: Currently there can be only one vg per text file. */ static int _vg_setup(struct format_instance *fid, struct volume_group *vg) @@ -99,7 +97,7 @@ static void _xlate_mdah(struct mda_header *mdah) } } -static struct mda_header *_raw_read_mda_header(struct format_type *fmt, +static struct mda_header *_raw_read_mda_header(const struct format_type *fmt, struct device_area *dev_area) { struct mda_header *mdah; @@ -145,7 +143,7 @@ static struct mda_header *_raw_read_mda_header(struct format_type *fmt, return mdah; } -static int _raw_write_mda_header(struct format_type *fmt, +static int _raw_write_mda_header(const struct format_type *fmt, struct device *dev, uint64_t start_byte, struct mda_header *mdah) { @@ -172,7 +170,7 @@ static struct raw_locn *_find_vg_rlocn(struct device_area *dev_area, struct mda_header *mdah, const char *vgname) { - int len; + size_t len; char vgnamebuf[NAME_LEN + 2]; struct raw_locn *rlocn; @@ -239,7 +237,7 @@ static struct volume_group *_vg_read_raw_area(struct format_instance *fid, struct mda_header *mdah; time_t when; char *desc; - uint64_t wrap = 0; + uint32_t wrap = 0; if (!dev_open(area->dev, O_RDONLY)) { stack; @@ -257,7 +255,7 @@ static struct volume_group *_vg_read_raw_area(struct format_instance *fid, } if (rlocn->offset + rlocn->size > mdah->size) - wrap = (rlocn->offset + rlocn->size) - mdah->size; + wrap = (uint32_t) ((rlocn->offset + rlocn->size) - mdah->size); if (wrap > rlocn->offset) { log_error("VG %s metadata too large for circular buffer", @@ -265,12 +263,13 @@ static struct volume_group *_vg_read_raw_area(struct format_instance *fid, goto out; } + /* FIXME 64-bit */ if (!(vg = text_vg_import_fd(fid, dev_name(area->dev), dev_fd(area->dev), - area->start + rlocn->offset, - rlocn->size - wrap, - area->start + MDA_HEADER_SIZE, wrap, - calc_crc, rlocn->checksum, &when, + (off_t) (area->start + rlocn->offset), + (uint32_t) (rlocn->size - wrap), + (off_t) (area->start + MDA_HEADER_SIZE), + wrap, calc_crc, rlocn->checksum, &when, &desc))) { stack; goto out; @@ -301,7 +300,7 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg, struct physical_volume *pv; struct list *pvh; int r = 0; - uint64_t new_wrap = 0, old_wrap = 0; + uint32_t new_wrap = 0, old_wrap = 0; /* FIXME Essential fix! Make dynamic (realloc? pool?) */ char buf[65536]; @@ -369,20 +368,21 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg, /* Write text out, circularly */ if (dev_write(mdac->area.dev, mdac->area.start + mdac->rlocn.offset, - mdac->rlocn.size - new_wrap, + (size_t) (mdac->rlocn.size - new_wrap), buf) != mdac->rlocn.size - new_wrap) { stack; goto out; } if (new_wrap) { - log_debug("Writing metadata to %s at %" PRIu64 " len %" PRIu64, + log_debug("Writing metadata to %s at %" PRIu64 " len %" PRIu32, dev_name(mdac->area.dev), mdac->area.start + MDA_HEADER_SIZE, new_wrap); if (dev_write(mdac->area.dev, mdac->area.start + MDA_HEADER_SIZE, - new_wrap, buf + mdac->rlocn.size - new_wrap) + (size_t) new_wrap, + buf + mdac->rlocn.size - new_wrap) != new_wrap) { stack; goto out; @@ -390,7 +390,8 @@ static int _vg_write_raw(struct format_instance *fid, struct volume_group *vg, } mdac->rlocn.checksum = calc_crc(INITIAL_CRC, buf, - mdac->rlocn.size - new_wrap); + (uint32_t) (mdac->rlocn.size - + new_wrap)); if (new_wrap) mdac->rlocn.checksum = calc_crc(mdac->rlocn.checksum, buf + mdac->rlocn.size - @@ -560,7 +561,8 @@ static int _vg_write_file(struct format_instance *fid, struct volume_group *vg, if (slash == 0) strcpy(temp_dir, "."); else if (slash - tc->path_edit < PATH_MAX) { - strncpy(temp_dir, tc->path_edit, slash - tc->path_edit); + strncpy(temp_dir, tc->path_edit, + (size_t) (slash - tc->path_edit)); temp_dir[slash - tc->path_edit] = '\0'; } else { @@ -643,7 +645,7 @@ static int _vg_commit_file(struct format_instance *fid, struct volume_group *vg, struct text_context *tc = (struct text_context *) mda->metadata_locn; char *slash; char newname[PATH_MAX]; - int len; + size_t len; if (!_vg_commit_file_backup(fid, vg, mda)) return 0; @@ -695,7 +697,7 @@ static int _vg_remove_file(struct format_instance *fid, struct volume_group *vg, return 1; } -static int _scan_file(struct format_type *fmt) +static int _scan_file(const struct format_type *fmt) { struct dirent *dirent; struct dir_list *dl; @@ -743,13 +745,13 @@ static int _scan_file(struct format_type *fmt) return 1; } -int vgname_from_mda(struct format_type *fmt, struct device_area *dev_area, +int vgname_from_mda(const struct format_type *fmt, struct device_area *dev_area, char *buf, uint32_t size) { struct raw_locn *rlocn; struct mda_header *mdah; int already_open; - int len; + unsigned int len; int r = 0; already_open = dev_is_open(dev_area->dev); @@ -768,13 +770,13 @@ int vgname_from_mda(struct format_type *fmt, struct device_area *dev_area, while (rlocn->offset) { if (dev_read(dev_area->dev, dev_area->start + rlocn->offset, - size, buf) != size) { + size, buf) != (signed) size) { stack; goto out; } len = 0; while (buf[len] && !isspace(buf[len]) && buf[len] != '{' && - len < size - 1) + len < (size - 1)) len++; buf[len] = '\0'; @@ -798,7 +800,7 @@ int vgname_from_mda(struct format_type *fmt, struct device_area *dev_area, return r; } -static int _scan_raw(struct format_type *fmt) +static int _scan_raw(const struct format_type *fmt) { struct raw_list *rl; struct list *rlh, *raw_list; @@ -826,14 +828,14 @@ static int _scan_raw(struct format_type *fmt) return 1; } -static int _scan(struct format_type *fmt) +static int _scan(const struct format_type *fmt) { return (_scan_file(fmt) & _scan_raw(fmt)); } /* For orphan, creates new mdas according to policy. Always have an mda between end-of-label and PE_ALIGN boundary */ -static int _mda_setup(struct format_type *fmt, +static int _mda_setup(const struct format_type *fmt, uint64_t pe_start, uint64_t pe_end, int pvmetadatacopies, uint64_t pvmetadatasize, struct list *mdas, @@ -889,8 +891,9 @@ static int _mda_setup(struct format_type *fmt, mda_size1)) return 0; - if (!dev_zero(pv->dev, start1, - mda_size1 > wipe_size ? wipe_size : mda_size1)) { + if (!dev_zero((struct device *) pv->dev, start1, + (size_t) (mda_size1 > + wipe_size ? wipe_size : mda_size1))) { log_error("Failed to wipe new metadata area"); return 0; } @@ -936,7 +939,8 @@ static int _mda_setup(struct format_type *fmt, mda_size2)) return 0; if (!dev_zero(pv->dev, start2, - mda_size1 > wipe_size ? wipe_size : mda_size1)) { + (size_t) (mda_size1 > + wipe_size ? wipe_size : mda_size1))) { log_error("Failed to wipe new metadata area"); return 0; } @@ -949,7 +953,7 @@ static int _mda_setup(struct format_type *fmt, /* Only for orphans */ /* Set label_sector to -1 if rewriting existing label into same sector */ -static int _pv_write(struct format_type *fmt, struct physical_volume *pv, +static int _pv_write(const struct format_type *fmt, struct physical_volume *pv, struct list *mdas, int64_t label_sector) { struct label *label; @@ -961,6 +965,8 @@ static int _pv_write(struct format_type *fmt, struct physical_volume *pv, struct mda_header *mdah = (struct mda_header *) buf; uint64_t adjustment; + /* FIXME Test mode don't update cache? */ + if (!(info = cache_add(fmt->labeller, (char *) &pv->id, pv->dev, ORPHAN, NULL))) { stack; @@ -1019,7 +1025,9 @@ static int _pv_write(struct format_type *fmt, struct physical_volume *pv, pv->pe_start += (PE_ALIGN - adjustment); } } - if (!add_da(fmt, NULL, &info->das, pv->pe_start << SECTOR_SHIFT, 0)) { + if (!add_da + (fmt, NULL, &info->das, pv->pe_start << SECTOR_SHIFT, + __UINT64_C(0))) { stack; return 0; } @@ -1053,7 +1061,7 @@ static int _pv_write(struct format_type *fmt, struct physical_volume *pv, return 1; } -static int _get_pv_from_vg(struct format_type *fmt, const char *vg_name, +static int _get_pv_from_vg(const struct format_type *fmt, const char *vg_name, const char *id, struct physical_volume *pv) { struct volume_group *vg; @@ -1073,7 +1081,7 @@ static int _get_pv_from_vg(struct format_type *fmt, const char *vg_name, list_iterate(pvh, &vg->pvs) { pvl = list_item(pvh, struct pv_list); - if (id_equal(&pvl->pv->id, (struct id *) id)) { + if (id_equal(&pvl->pv->id, (const struct id *) id)) { memcpy(pv, pvl->pv, sizeof(*pv)); return 1; } @@ -1105,7 +1113,7 @@ static int _add_raw(struct list *raw_list, struct device_area *dev_area) return 1; } -static int _pv_read(struct format_type *fmt, const char *pv_name, +static int _pv_read(const struct format_type *fmt, const char *pv_name, struct physical_volume *pv, struct list *mdas) { struct label *label; @@ -1121,6 +1129,7 @@ static int _pv_read(struct format_type *fmt, const char *pv_name, return 0; } + /* FIXME Optimise out repeated reading when cache lock held */ if (!(label_read(dev, &label))) { stack; return 0; @@ -1210,7 +1219,7 @@ static void _free_raws(struct list *raw_list) } } -static void _destroy(struct format_type *fmt) +static void _destroy(const struct format_type *fmt) { if (fmt->private) { _free_dirs(&((struct mda_lists *) fmt->private)->dirs); @@ -1218,7 +1227,7 @@ static void _destroy(struct format_type *fmt) dbg_free(fmt->private); } - dbg_free(fmt); + dbg_free((void *) fmt); } static struct metadata_area_ops _metadata_text_file_ops = { @@ -1243,7 +1252,7 @@ static struct metadata_area_ops _metadata_text_raw_ops = { }; /* pvmetadatasize in sectors */ -static int _pv_setup(struct format_type *fmt, +static int _pv_setup(const struct format_type *fmt, uint64_t pe_start, uint32_t extent_count, uint32_t extent_size, int pvmetadatacopies, @@ -1334,8 +1343,8 @@ static int _pv_setup(struct format_type *fmt, } /* NULL vgname means use only the supplied context e.g. an archive file */ -static struct format_instance *_create_text_instance(struct format_type *fmt, - const char *vgname, +static struct format_instance *_create_text_instance(const struct format_type + *fmt, const char *vgname, void *context) { struct format_instance *fid; @@ -1408,6 +1417,7 @@ static struct format_instance *_create_text_instance(struct format_type *fmt, /* FIXME Allow multiple dev_areas inside area */ memcpy(&mdac->area, &rl->dev_area, sizeof(mdac->area)); mda->ops = &_metadata_text_raw_ops; + /* FIXME MISTAKE? mda->metadata_locn = context; */ list_add(&fid->metadata_areas, &mda->list); } diff --git a/lib/format_text/format-text.h b/lib/format_text/format-text.h index f14c0adfb..dccc10e77 100644 --- a/lib/format_text/format-text.h +++ b/lib/format_text/format-text.h @@ -36,19 +36,19 @@ struct format_type *create_text_format(struct cmd_context *cmd); void *create_text_context(struct cmd_context *cmd, const char *path, const char *desc); -struct labeller *text_labeller_create(struct format_type *fmt); +struct labeller *text_labeller_create(const struct format_type *fmt); int pvhdr_read(struct device *dev, char *buf); -int add_da(struct format_type *fmt, struct pool *mem, struct list *das, +int add_da(const struct format_type *fmt, struct pool *mem, struct list *das, uint64_t start, uint64_t size); void del_das(struct list *das); -int add_mda(struct format_type *fmt, struct pool *mem, struct list *mdas, +int add_mda(const struct format_type *fmt, struct pool *mem, struct list *mdas, struct device *dev, uint64_t start, uint64_t size); void del_mdas(struct list *mdas); -int vgname_from_mda(struct format_type *fmt, struct device_area *dev_area, +int vgname_from_mda(const struct format_type *fmt, struct device_area *dev_area, char *buf, uint32_t size); #endif diff --git a/lib/format_text/import_vsn1.c b/lib/format_text/import_vsn1.c index cb944f7cc..bf1e0b5a3 100644 --- a/lib/format_text/import_vsn1.c +++ b/lib/format_text/import_vsn1.c @@ -214,7 +214,7 @@ static int _read_segment(struct pool *mem, struct volume_group *vg, struct logical_volume *lv, struct config_node *sn, struct hash_table *pv_hash) { - int s; + unsigned int s; uint32_t stripes = 0; struct lv_segment *seg; struct config_node *cn; diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c index b39d61ef8..08006c6a1 100644 --- a/lib/format_text/text_label.c +++ b/lib/format_text/text_label.c @@ -80,7 +80,7 @@ static int _write(struct label *label, char *buf) return 1; } -int add_da(struct format_type *fmt, struct pool *mem, struct list *das, +int add_da(const struct format_type *fmt, struct pool *mem, struct list *das, uint64_t start, uint64_t size) { struct data_area_list *dal; @@ -117,7 +117,7 @@ void del_das(struct list *das) } } -int add_mda(struct format_type *fmt, struct pool *mem, struct list *mdas, +int add_mda(const struct format_type *fmt, struct pool *mem, struct list *mdas, struct device *dev, uint64_t start, uint64_t size) { /* FIXME List size restricted by pv_header SECTOR_SIZE */ @@ -264,7 +264,7 @@ struct label_ops _text_ops = { destroy:_destroy }; -struct labeller *text_labeller_create(struct format_type *fmt) +struct labeller *text_labeller_create(const struct format_type *fmt) { struct labeller *l; @@ -274,7 +274,7 @@ struct labeller *text_labeller_create(struct format_type *fmt) } l->ops = &_text_ops; - l->private = (void *) fmt; + l->private = (const void *) fmt; return l; } |