From prajnoha@sourceware.org Thu Sep 9 13:07:00 2010 From: prajnoha@sourceware.org (prajnoha@sourceware.org) Date: Thu, 09 Sep 2010 13:07:00 -0000 Subject: LVM2 ./WHATS_NEW lib/commands/toolcontext.c li ... Message-ID: <20100909130715.9657.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: prajnoha@sourceware.org 2010-09-09 13:07:15 Modified files: . : WHATS_NEW lib/commands : toolcontext.c lib/format_text: archiver.c Log message: Reinitialize archive and backup handling on toolcontext refresh. For example, when using '--config "backup { ... }"' line, the values from lvm.conf (or default values) should be overridden. This patch adds reinitialisation of archive and backup handling on toolcontext refresh which makes these settings to be applied. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1727&r2=1.1728 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/commands/toolcontext.c.diff?cvsroot=lvm2&r1=1.103&r2=1.104 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/archiver.c.diff?cvsroot=lvm2&r1=1.33&r2=1.34 --- LVM2/WHATS_NEW 2010/08/30 18:37:42 1.1727 +++ LVM2/WHATS_NEW 2010/09/09 13:07:13 1.1728 @@ -1,5 +1,6 @@ Version 2.02.74 - ================================== + Reinitialize archive and backup handling on toolcontext refresh. Fix opprobriously slow I/O to cluster mirrors created with --nosync. Make poll_mirror_progress report PROGRESS_CHECK_FAILED if LV is not a mirror. Like mirrors, don't scan origins if ignore_suspended_devices() is set. --- LVM2/lib/commands/toolcontext.c 2010/08/11 12:14:23 1.103 +++ LVM2/lib/commands/toolcontext.c 2010/09/09 13:07:14 1.104 @@ -1343,6 +1343,9 @@ if (!_init_segtypes(cmd)) return 0; + if (!_init_backup(cmd)) + return 0; + cmd->config_valid = 1; reset_lvm_errno(1); --- LVM2/lib/format_text/archiver.c 2010/07/08 18:24:29 1.33 +++ LVM2/lib/format_text/archiver.c 2010/09/09 13:07:14 1.34 @@ -40,6 +40,8 @@ unsigned int keep_days, unsigned int keep_min, int enabled) { + archive_exit(cmd); + if (!(cmd->archive_params = dm_pool_zalloc(cmd->libmem, sizeof(*cmd->archive_params)))) { log_error("archive_params alloc failed"); @@ -156,6 +158,8 @@ int backup_init(struct cmd_context *cmd, const char *dir, int enabled) { + backup_exit(cmd); + if (!(cmd->backup_params = dm_pool_zalloc(cmd->libmem, sizeof(*cmd->backup_params)))) { log_error("backup_params alloc failed"); From prajnoha@sourceware.org Thu Sep 9 13:13:00 2010 From: prajnoha@sourceware.org (prajnoha@sourceware.org) Date: Thu, 09 Sep 2010 13:13:00 -0000 Subject: LVM2 ./WHATS_NEW lib/format_text/archive.c Message-ID: <20100909131314.13747.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: prajnoha@sourceware.org 2010-09-09 13:13:12 Modified files: . : WHATS_NEW lib/format_text: archive.c Log message: Add random suffix to archive file names to prevent races when being created. In certain configurations, we're not under a VG rw lock while trying to write a new archive file with VG metadata. A common example is using "vgs" while having the content of backup and archive directories empty. The code scans the content of these directories and tries to determine the final index that should be used in archive name. Since we're not under a lock, we can get into a race while choosing the index which could end up showing errors about not being able to rename to final archive name. Let's add random number suffix to these archive file names so we can avoid the race. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1728&r2=1.1729 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/archive.c.diff?cvsroot=lvm2&r1=1.38&r2=1.39 --- LVM2/WHATS_NEW 2010/09/09 13:07:13 1.1728 +++ LVM2/WHATS_NEW 2010/09/09 13:13:12 1.1729 @@ -1,5 +1,6 @@ Version 2.02.74 - ================================== + Add random suffix to archive file names to prevent races when being created. Reinitialize archive and backup handling on toolcontext refresh. Fix opprobriously slow I/O to cluster mirrors created with --nosync. Make poll_mirror_progress report PROGRESS_CHECK_FAILED if LV is not a mirror. --- LVM2/lib/format_text/archive.c 2010/08/03 13:09:22 1.38 +++ LVM2/lib/format_text/archive.c 2010/09/09 13:13:12 1.39 @@ -226,7 +226,7 @@ const char *dir, const char *desc, uint32_t retain_days, uint32_t min_archive) { - int i, fd, renamed = 0; + int i, fd, rnum, renamed = 0; uint32_t ix = 0; struct archive_file *last; FILE *fp = NULL; @@ -271,9 +271,12 @@ ix = last->index + 1; } + rnum = rand_r(&vg->cmd->rand_seed); + for (i = 0; i < 10; i++) { if (dm_snprintf(archive_name, sizeof(archive_name), - "%s/%s_%05u.vg", dir, vg->name, ix) < 0) { + "%s/%s_%05u-%d.vg", + dir, vg->name, ix, rnum) < 0) { log_error("Archive file name too long."); return 0; } From wysochanski@sourceware.org Thu Sep 9 19:38:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 09 Sep 2010 19:38:00 -0000 Subject: LVM2/lib/report properties.c Message-ID: <20100909193803.781.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-09 19:38:03 Modified files: lib/report : properties.c Log message: Update vg_mda_free 'get' function to multiply by SECTOR_SIZE. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/properties.c.diff?cvsroot=lvm2&r1=1.3&r2=1.4 --- LVM2/lib/report/properties.c 2010/08/20 13:02:39 1.3 +++ LVM2/lib/report/properties.c 2010/09/09 19:38:03 1.4 @@ -152,7 +152,7 @@ #define _vg_mda_count_set _not_implemented GET_NUM_PROPERTY_FN(vg_mda_used_count, (vg_mda_used_count(vg))) #define _vg_mda_used_count_set _not_implemented -GET_NUM_PROPERTY_FN(vg_mda_free, (vg_mda_free(vg))) +GET_NUM_PROPERTY_FN(vg_mda_free, (SECTOR_SIZE * vg_mda_free(vg))) #define _vg_mda_free_set _not_implemented GET_NUM_PROPERTY_FN(vg_mda_size, (SECTOR_SIZE * vg_mda_size(vg))) #define _vg_mda_size_set _not_implemented From prajnoha@sourceware.org Mon Sep 20 14:23:00 2010 From: prajnoha@sourceware.org (prajnoha@sourceware.org) Date: Mon, 20 Sep 2010 14:23:00 -0000 Subject: LVM2 ./WHATS_NEW lib/format_text/export.c lib/ ... Message-ID: <20100920142342.16058.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: prajnoha@sourceware.org 2010-09-20 14:23:20 Modified files: . : WHATS_NEW lib/format_text: export.c import-export.h tags.c Log message: Use dynamic allocation for metadata's tag buffer (removes 4096 char. limit). Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1729&r2=1.1730 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/export.c.diff?cvsroot=lvm2&r1=1.77&r2=1.78 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/import-export.h.diff?cvsroot=lvm2&r1=1.24&r2=1.25 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/tags.c.diff?cvsroot=lvm2&r1=1.7&r2=1.8 --- LVM2/WHATS_NEW 2010/09/09 13:13:12 1.1729 +++ LVM2/WHATS_NEW 2010/09/20 14:23:20 1.1730 @@ -1,5 +1,6 @@ Version 2.02.74 - ================================== + Use dynamic allocation for metadata's tag buffer (removes 4096 char. limit). Add random suffix to archive file names to prevent races when being created. Reinitialize archive and backup handling on toolcontext refresh. Fix opprobriously slow I/O to cluster mirrors created with --nosync. --- LVM2/lib/format_text/export.c 2010/07/09 15:34:44 1.77 +++ LVM2/lib/format_text/export.c 2010/09/20 14:23:20 1.78 @@ -366,6 +366,7 @@ static int _print_vg(struct formatter *f, struct volume_group *vg) { char buffer[4096]; + char *tag_buffer = NULL; if (!id_write_format(&vg->id, buffer, sizeof(buffer))) return_0; @@ -378,9 +379,10 @@ return_0; if (!dm_list_empty(&vg->tags)) { - if (!print_tags(&vg->tags, buffer, sizeof(buffer))) + if (!(tag_buffer = alloc_printed_tags(&vg->tags))) return_0; - outf(f, "tags = %s", buffer); + outf(f, "tags = %s", tag_buffer); + dm_free(tag_buffer); } if (vg->system_id && *vg->system_id) @@ -426,7 +428,7 @@ struct pv_list *pvl; struct physical_volume *pv; char buffer[4096]; - char *buf; + char *buf, *tag_buffer = NULL; const char *name; outf(f, "physical_volumes {"); @@ -461,9 +463,10 @@ return_0; if (!dm_list_empty(&pv->tags)) { - if (!print_tags(&pv->tags, buffer, sizeof(buffer))) + if (!(tag_buffer = alloc_printed_tags(&pv->tags))) return_0; - outf(f, "tags = %s", buffer); + outf(f, "tags = %s", tag_buffer); + dm_free(tag_buffer); } outsize(f, pv->size, "dev_size = %" PRIu64, pv->size); @@ -484,7 +487,7 @@ static int _print_segment(struct formatter *f, struct volume_group *vg, int count, struct lv_segment *seg) { - char buffer[4096]; + char *tag_buffer = NULL; outf(f, "segment%u {", count); _inc_indent(f); @@ -497,9 +500,10 @@ outf(f, "type = \"%s\"", seg->segtype->name); if (!dm_list_empty(&seg->tags)) { - if (!print_tags(&seg->tags, buffer, sizeof(buffer))) + if (!(tag_buffer = alloc_printed_tags(&seg->tags))) return_0; - outf(f, "tags = %s", buffer); + outf(f, "tags = %s", tag_buffer); + dm_free(tag_buffer); } if (seg->segtype->ops->text_export && @@ -553,6 +557,7 @@ { struct lv_segment *seg; char buffer[4096]; + char *tag_buffer = NULL; int seg_count; outnl(f); @@ -569,9 +574,10 @@ return_0; if (!dm_list_empty(&lv->tags)) { - if (!print_tags(&lv->tags, buffer, sizeof(buffer))) + if (!(tag_buffer = alloc_printed_tags(&lv->tags))) return_0; - outf(f, "tags = %s", buffer); + outf(f, "tags = %s", tag_buffer); + dm_free(tag_buffer); } if (lv->alloc != ALLOC_INHERIT) --- LVM2/lib/format_text/import-export.h 2010/03/17 02:11:19 1.24 +++ LVM2/lib/format_text/import-export.h 2010/09/20 14:23:20 1.25 @@ -61,7 +61,7 @@ int print_flags(uint64_t status, int type, char *buffer, size_t size); int read_flags(uint64_t *status, int type, struct config_value *cv); -int print_tags(struct dm_list *tags, char *buffer, size_t size); +char *alloc_printed_tags(struct dm_list *tags); int read_tags(struct dm_pool *mem, struct dm_list *tags, struct config_value *cv); int text_vg_export_file(struct volume_group *vg, const char *desc, FILE *fp); --- LVM2/lib/format_text/tags.c 2008/11/03 22:14:28 1.7 +++ LVM2/lib/format_text/tags.c 2010/09/20 14:23:20 1.8 @@ -19,29 +19,46 @@ #include "str_list.h" #include "lvm-string.h" -int print_tags(struct dm_list *tags, char *buffer, size_t size) +char *alloc_printed_tags(struct dm_list *tags) { struct str_list *sl; int first = 1; + size_t size = 0; + char *buffer, *buf; - if (!emit_to_buffer(&buffer, &size, "[")) - return_0; + dm_list_iterate_items(sl, tags) + /* '"' + tag + '"' + ',' + ' ' */ + size += strlen(sl->str) + 4; + /* '[' + ']' + '\0' */ + size += 3; + + if (!(buffer = buf = dm_malloc(size))) { + log_error("Could not allocate memory for tag list buffer."); + return NULL; + } + + if (!emit_to_buffer(&buf, &size, "[")) + goto bad; dm_list_iterate_items(sl, tags) { if (!first) { - if (!emit_to_buffer(&buffer, &size, ", ")) - return_0; + if (!emit_to_buffer(&buf, &size, ", ")) + goto bad; } else first = 0; - if (!emit_to_buffer(&buffer, &size, "\"%s\"", sl->str)) - return_0; + if (!emit_to_buffer(&buf, &size, "\"%s\"", sl->str)) + goto bad; } - if (!emit_to_buffer(&buffer, &size, "]")) - return_0; + if (!emit_to_buffer(&buf, &size, "]")) + goto bad; - return 1; + return buffer; + +bad: + dm_free(buffer); + return_NULL; } int read_tags(struct dm_pool *mem, struct dm_list *tags, struct config_value *cv) From prajnoha@sourceware.org Mon Sep 20 14:25:00 2010 From: prajnoha@sourceware.org (prajnoha@sourceware.org) Date: Mon, 20 Sep 2010 14:25:00 -0000 Subject: LVM2 ./WHATS_NEW lib/misc/lvm-string.c Message-ID: <20100920142528.16716.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: prajnoha@sourceware.org 2010-09-20 14:25:27 Modified files: . : WHATS_NEW lib/misc : lvm-string.c Log message: Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function. Revert to old glibc behaviour for vsnprintf used in emit_to_buffer fn. Otherwise, the check that follows would be wrong for new glibc versions. This caused the rh bug #633033 to be undetected and pass throught the check, corrupting the metadata! Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1730&r2=1.1731 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.20&r2=1.21 --- LVM2/WHATS_NEW 2010/09/20 14:23:20 1.1730 +++ LVM2/WHATS_NEW 2010/09/20 14:25:27 1.1731 @@ -1,5 +1,6 @@ Version 2.02.74 - ================================== + Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function. Use dynamic allocation for metadata's tag buffer (removes 4096 char. limit). Add random suffix to archive file names to prevent races when being created. Reinitialize archive and backup handling on toolcontext refresh. --- LVM2/lib/misc/lvm-string.c 2010/04/23 14:16:33 1.20 +++ LVM2/lib/misc/lvm-string.c 2010/09/20 14:25:27 1.21 @@ -27,6 +27,14 @@ n = vsnprintf(*buffer, *size, fmt, ap); va_end(ap); + /* + * Revert to old glibc behaviour (version <= 2.0.6) where snprintf + * returned -1 if buffer was too small. From glibc 2.1 it returns number + * of chars that would have been written had there been room. + */ + if (n < 0 || ((unsigned) n + 1 > *size)) + n = -1; + if (n < 0 || ((size_t)n == *size)) return 0; From prajnoha@sourceware.org Tue Sep 21 10:42:00 2010 From: prajnoha@sourceware.org (prajnoha@sourceware.org) Date: Tue, 21 Sep 2010 10:42:00 -0000 Subject: LVM2/lib/format_text tags.c Message-ID: <20100921104203.30536.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: prajnoha@sourceware.org 2010-09-21 10:42:03 Modified files: lib/format_text: tags.c Log message: "goto_bad" should be used in alloc_printed_tags function, not "goto bad". Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/tags.c.diff?cvsroot=lvm2&r1=1.8&r2=1.9 --- LVM2/lib/format_text/tags.c 2010/09/20 14:23:20 1.8 +++ LVM2/lib/format_text/tags.c 2010/09/21 10:42:02 1.9 @@ -38,21 +38,21 @@ } if (!emit_to_buffer(&buf, &size, "[")) - goto bad; + goto_bad; dm_list_iterate_items(sl, tags) { if (!first) { if (!emit_to_buffer(&buf, &size, ", ")) - goto bad; + goto_bad; } else first = 0; if (!emit_to_buffer(&buf, &size, "\"%s\"", sl->str)) - goto bad; + goto_bad; } if (!emit_to_buffer(&buf, &size, "]")) - goto bad; + goto_bad; return buffer; From agk@sourceware.org Wed Sep 22 01:36:00 2010 From: agk@sourceware.org (agk@sourceware.org) Date: Wed, 22 Sep 2010 01:36:00 -0000 Subject: LVM2 ./VERSION ./VERSION_DM ./WHATS_NEW ./WHAT ... Message-ID: <20100922013616.31676.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2010-09-22 01:36:14 Modified files: . : VERSION VERSION_DM WHATS_NEW WHATS_NEW_DM lib/cache : lvmcache.c lib/device : dev-cache.c dev-cache.h lib/filters : filter-composite.c filter-md.c filter-persistent.c filter-regex.c filter-sysfs.c filter.c Log message: Track recursive filter iteration to avoid refreshing while in use. (2.02.56) Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/VERSION.diff?cvsroot=lvm2&r1=1.253&r2=1.254 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/VERSION_DM.diff?cvsroot=lvm2&r1=1.62&r2=1.63 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1731&r2=1.1732 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW_DM.diff?cvsroot=lvm2&r1=1.413&r2=1.414 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/cache/lvmcache.c.diff?cvsroot=lvm2&r1=1.93&r2=1.94 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/device/dev-cache.c.diff?cvsroot=lvm2&r1=1.58&r2=1.59 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/device/dev-cache.h.diff?cvsroot=lvm2&r1=1.11&r2=1.12 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/filters/filter-composite.c.diff?cvsroot=lvm2&r1=1.15&r2=1.16 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/filters/filter-md.c.diff?cvsroot=lvm2&r1=1.9&r2=1.10 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/filters/filter-persistent.c.diff?cvsroot=lvm2&r1=1.44&r2=1.45 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/filters/filter-regex.c.diff?cvsroot=lvm2&r1=1.27&r2=1.28 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/filters/filter-sysfs.c.diff?cvsroot=lvm2&r1=1.21&r2=1.22 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/filters/filter.c.diff?cvsroot=lvm2&r1=1.56&r2=1.57 --- LVM2/VERSION 2010/08/25 11:25:02 1.253 +++ LVM2/VERSION 2010/09/22 01:36:13 1.254 @@ -1 +1 @@ -2.02.74(2)-cvs (2010-08-19) +2.02.74(2)-cvs (2010-09-22) --- LVM2/VERSION_DM 2010/08/19 22:33:14 1.62 +++ LVM2/VERSION_DM 2010/09/22 01:36:13 1.63 @@ -1 +1 @@ -1.02.55-cvs (2010-08-19) +1.02.55-cvs (2010-09-22) --- LVM2/WHATS_NEW 2010/09/20 14:25:27 1.1731 +++ LVM2/WHATS_NEW 2010/09/22 01:36:13 1.1732 @@ -1,7 +1,8 @@ Version 2.02.74 - -================================== - Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function. - Use dynamic allocation for metadata's tag buffer (removes 4096 char. limit). +===================================== + Track recursive filter iteration to avoid refreshing while in use. (2.02.56) + Revert to old glibc vsnprintf behaviour in emit_to_buffer() to catch overflow. + Allocate buffer for metadata tags dynamically to remove 4k limit. Add random suffix to archive file names to prevent races when being created. Reinitialize archive and backup handling on toolcontext refresh. Fix opprobriously slow I/O to cluster mirrors created with --nosync. @@ -16,16 +17,16 @@ Add "devices/default_data_alignment" to lvm.conf. Add implmentation for simple numeric 'get' property functions. Define GET_NUM_PROPERTY_FN macro to simplify numeric property 'get' function - Add properties.[ch] to lib/report, defined based on columns.h. + Add properties.[ch] to lib/report using columns.h. Add macro definitions to report infrastructure for character array length. Remove explicit double quotes from columns.h 'id' entries. Add 'flags' field to columns.h and define FIELD_MODIFIABLE. Add vg_mda_size and vg_mda_free functions. Simplify MD/swap signature detection in pvcreate and allow aborting. - Remove assumption that --yes must be used only in --force mode. + Allow --yes to be used without --force mode. Fix file descriptor leak in swap signature detection error path. Detect and allow abort in pvcreate if LUKS signature is detected. - Use proper locks mask when checking for LCK_WRITE. + Always mask lock flags correctly when checking for LCK_WRITE. Version 2.02.73 - 18th August 2010 ================================== --- LVM2/WHATS_NEW_DM 2010/08/19 22:33:14 1.413 +++ LVM2/WHATS_NEW_DM 2010/09/22 01:36:13 1.414 @@ -1,5 +1,6 @@ Version 1.02.55 - -================================== +===================================== + Add DM_REPORT_FIELD_TYPE_ID_LEN to libdevmapper.h. Version 1.02.54 - 18th August 2010 ================================== --- LVM2/lib/cache/lvmcache.c 2010/07/09 15:34:42 1.93 +++ LVM2/lib/cache/lvmcache.c 2010/09/22 01:36:14 1.94 @@ -570,7 +570,7 @@ goto out; } - if (full_scan == 2 && !refresh_filters(cmd)) { + if (full_scan == 2 && !cmd->filter->use_count && !refresh_filters(cmd)) { log_error("refresh filters failed"); goto out; } --- LVM2/lib/device/dev-cache.c 2010/08/03 13:39:27 1.58 +++ LVM2/lib/device/dev-cache.c 2010/09/22 01:36:14 1.59 @@ -815,12 +815,14 @@ di->current = btree_first(_cache.devices); di->filter = f; + di->filter->use_count++; return di; } void dev_iter_destroy(struct dev_iter *iter) { + iter->filter->use_count--; dm_free(iter); } --- LVM2/lib/device/dev-cache.h 2007/08/20 20:55:25 1.11 +++ LVM2/lib/device/dev-cache.h 2010/09/22 01:36:14 1.12 @@ -24,6 +24,7 @@ struct dev_filter { int (*passes_filter) (struct dev_filter * f, struct device * dev); void (*destroy) (struct dev_filter * f); + unsigned use_count; void *private; }; --- LVM2/lib/filters/filter-composite.c 2008/01/30 13:59:58 1.15 +++ LVM2/lib/filters/filter-composite.c 2010/09/22 01:36:14 1.16 @@ -37,6 +37,9 @@ { struct dev_filter **filters = (struct dev_filter **) f->private; + if (f->use_count) + log_error(INTERNAL_ERROR "Destroying composite filter while in use %u times.", f->use_count); + while (*filters) { (*filters)->destroy(*filters); filters++; @@ -69,6 +72,7 @@ cft->passes_filter = _and_p; cft->destroy = _composite_destroy; + cft->use_count = 0; cft->private = filters_copy; return cft; --- LVM2/lib/filters/filter-md.c 2010/07/09 15:34:43 1.9 +++ LVM2/lib/filters/filter-md.c 2010/09/22 01:36:14 1.10 @@ -45,6 +45,9 @@ static void _destroy(struct dev_filter *f) { + if (f->use_count) + log_error(INTERNAL_ERROR "Destroying sysfs filter while in use %u times.", f->use_count); + dm_free(f); } @@ -59,6 +62,7 @@ f->passes_filter = _ignore_md; f->destroy = _destroy; + f->use_count = 0; f->private = NULL; return f; --- LVM2/lib/filters/filter-persistent.c 2010/08/09 14:05:18 1.44 +++ LVM2/lib/filters/filter-persistent.c 2010/09/22 01:36:14 1.45 @@ -274,13 +274,13 @@ return 0; } - /* Test dm devices every time, so cache them as GOOD. */ + /* Test dm devices every time, so cache them as GOOD. */ if (MAJOR(dev->dev) == dm_major()) { if (!l) dm_list_iterate_items(sl, &dev->aliases) dm_hash_insert(pf->devices, sl->str, PF_GOOD_DEVICE); if (!device_is_usable(dev)) { - log_debug("%s: Skipping unusable device", dev_name(dev)); + log_debug("%s: Skipping unusable device", dev_name(dev)); return 0; } return pf->real->passes_filter(pf->real, dev); @@ -301,6 +301,9 @@ { struct pfilter *pf = (struct pfilter *) f->private; + if (f->use_count) + log_error(INTERNAL_ERROR "Destroying persistent filter while in use %u times.", f->use_count); + dm_hash_destroy(pf->devices); dm_free(pf->file); pf->real->destroy(pf->real); @@ -339,6 +342,7 @@ f->passes_filter = _lookup_p; f->destroy = _persistent_destroy; + f->use_count = 0; f->private = pf; return f; --- LVM2/lib/filters/filter-regex.c 2010/04/30 12:31:33 1.27 +++ LVM2/lib/filters/filter-regex.c 2010/09/22 01:36:14 1.28 @@ -181,6 +181,10 @@ static void _regex_destroy(struct dev_filter *f) { struct rfilter *rf = (struct rfilter *) f->private; + + if (f->use_count) + log_error(INTERNAL_ERROR "Destroying regex filter while in use %u times.", f->use_count); + dm_pool_destroy(rf->mem); } @@ -206,6 +210,7 @@ f->passes_filter = _accept_p; f->destroy = _regex_destroy; + f->use_count = 0; f->private = rf; return f; --- LVM2/lib/filters/filter-sysfs.c 2010/07/09 15:34:43 1.21 +++ LVM2/lib/filters/filter-sysfs.c 2010/09/22 01:36:14 1.22 @@ -282,6 +282,10 @@ static void _destroy(struct dev_filter *f) { struct dev_set *ds = (struct dev_set *) f->private; + + if (f->use_count) + log_error(INTERNAL_ERROR "Destroying sysfs filter while in use %u times.", f->use_count); + dm_pool_destroy(ds->mem); } @@ -316,6 +320,7 @@ f->passes_filter = _accept_p; f->destroy = _destroy; + f->use_count = 0; f->private = ds; return f; --- LVM2/lib/filters/filter.c 2010/08/11 12:14:24 1.56 +++ LVM2/lib/filters/filter.c 2010/09/22 01:36:14 1.57 @@ -326,6 +326,7 @@ f->passes_filter = _passes_lvm_type_device_filter; f->destroy = lvm_type_filter_destroy; + f->use_count = 0; f->private = NULL; if (!_scan_proc_dev(proc, cn)) { @@ -338,5 +339,8 @@ void lvm_type_filter_destroy(struct dev_filter *f) { + if (f->use_count) + log_error(INTERNAL_ERROR "Destroying lvm_type filter while in use %u times.", f->use_count); + dm_free(f); } From agk@sourceware.org Wed Sep 22 01:50:00 2010 From: agk@sourceware.org (agk@sourceware.org) Date: Wed, 22 Sep 2010 01:50:00 -0000 Subject: LVM2/lib/filters filter-md.c Message-ID: <20100922015038.11915.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2010-09-22 01:50:38 Modified files: lib/filters : filter-md.c Log message: Fix name in msg in last checkin. (The problem the last checkin addressed was a segfault in 'pvs -a' if .cache didn't contain every PV in a VG.) Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/filters/filter-md.c.diff?cvsroot=lvm2&r1=1.10&r2=1.11 --- LVM2/lib/filters/filter-md.c 2010/09/22 01:36:14 1.10 +++ LVM2/lib/filters/filter-md.c 2010/09/22 01:50:38 1.11 @@ -46,7 +46,7 @@ static void _destroy(struct dev_filter *f) { if (f->use_count) - log_error(INTERNAL_ERROR "Destroying sysfs filter while in use %u times.", f->use_count); + log_error(INTERNAL_ERROR "Destroying md filter while in use %u times.", f->use_count); dm_free(f); } From mbroz@sourceware.org Wed Sep 22 13:45:00 2010 From: mbroz@sourceware.org (mbroz@sourceware.org) Date: Wed, 22 Sep 2010 13:45:00 -0000 Subject: LVM2 ./WHATS_NEW lib/format1/format1.c test/t- ... Message-ID: <20100922134525.893.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: mbroz@sourceware.org 2010-09-22 13:45:23 Modified files: . : WHATS_NEW lib/format1 : format1.c test : t-vgcfgbackup-usage.sh Log message: Fix handling of partial VG for lvm1 format metadata If some lvm1 device is missing, lvm fails on all operations # vgcfgbackup -f bck -P vg_test Partial mode. Incomplete volume groups will be activated read-only. 3 PV(s) found for VG vg_test: expected 4 PV segment VG free_count mismatch: 152599 != 228909 PV segment VG extent_count mismatch: 152600 != 228910 Internal error: PV segments corrupted in vg_test. Volume group "vg_test" not found Allow loading of lvm1 partial VG by allocating "new" missing PV, which covers lost space. Also this fake mising PV inform code that it is partial VG. https://bugzilla.redhat.com/show_bug.cgi?id=501390 Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1732&r2=1.1733 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format1/format1.c.diff?cvsroot=lvm2&r1=1.121&r2=1.122 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/test/t-vgcfgbackup-usage.sh.diff?cvsroot=lvm2&r1=1.4&r2=1.5 --- LVM2/WHATS_NEW 2010/09/22 01:36:13 1.1732 +++ LVM2/WHATS_NEW 2010/09/22 13:45:21 1.1733 @@ -1,5 +1,6 @@ Version 2.02.74 - ===================================== + Fix partial mode operations for lvm1 metadata format. Track recursive filter iteration to avoid refreshing while in use. (2.02.56) Revert to old glibc vsnprintf behaviour in emit_to_buffer() to catch overflow. Allocate buffer for metadata tags dynamically to remove 4k limit. --- LVM2/lib/format1/format1.c 2010/07/09 15:34:44 1.121 +++ LVM2/lib/format1/format1.c 2010/09/22 13:45:22 1.122 @@ -21,9 +21,10 @@ #include "lvm1-label.h" #include "format1.h" #include "segtype.h" +#include "pv_alloc.h" /* VG consistency checks */ -static int _check_vgs(struct dm_list *pvs) +static int _check_vgs(struct dm_list *pvs, struct volume_group *vg) { struct dm_list *pvh, *t; struct disk_list *dl = NULL; @@ -105,11 +106,53 @@ if (pv_count != first->vgd.pv_cur) { log_error("%d PV(s) found for VG %s: expected %d", pv_count, first->pvd.vg_name, first->vgd.pv_cur); + vg->status |= PARTIAL_VG; } return 1; } +static int _fix_partial_vg(struct volume_group *vg, struct dm_list *pvs) +{ + uint32_t extent_count = 0; + struct disk_list *dl; + struct dm_list *pvh; + struct pv_list *pvl; + + dm_list_iterate(pvh, pvs) { + dl = dm_list_item(pvh, struct disk_list); + extent_count += dl->pvd.pe_total; + } + + /* FIXME: move this to one place to pv_manip */ + if (!(pvl = dm_pool_zalloc(vg->vgmem, sizeof(*pvl))) || + !(pvl->pv = dm_pool_zalloc(vg->vgmem, sizeof(*pvl->pv)))) + return_0; + + if (!id_create(&pvl->pv->id)) + goto_out; + if (!(pvl->pv->vg_name = dm_pool_strdup(vg->vgmem, vg->name))) + goto_out; + memcpy(&pvl->pv->vgid, &vg->id, sizeof(vg->id)); + pvl->pv->status |= MISSING_PV; + dm_list_init(&pvl->pv->tags); + dm_list_init(&pvl->pv->segments); + + pvl->pv->pe_size = vg->extent_size; + pvl->pv->pe_count = vg->extent_count - extent_count; + if (!alloc_pv_segment_whole_pv(vg->vgmem, pvl->pv)) + goto_out; + + add_pvl_to_vgs(vg, pvl); + log_debug("%s: partial VG, allocated missing PV using %d extents.", + vg->name, pvl->pv->pe_count); + + return 1; +out: + dm_pool_free(vg->vgmem, pvl); + return 0; +} + static struct volume_group *_build_vg(struct format_instance *fid, struct dm_list *pvs, struct dm_pool *mem) @@ -134,7 +177,7 @@ dm_list_init(&vg->tags); dm_list_init(&vg->removed_pvs); - if (!_check_vgs(pvs)) + if (!_check_vgs(pvs, vg)) goto_bad; dl = dm_list_item(pvs->n, struct disk_list); @@ -154,6 +197,10 @@ if (!import_snapshots(mem, vg, pvs)) goto_bad; + /* Fix extents counts by adding missing PV if partial VG */ + if ((vg->status & PARTIAL_VG) && !_fix_partial_vg(vg, pvs)) + goto_bad; + return vg; bad: --- LVM2/test/t-vgcfgbackup-usage.sh 2010/08/12 04:09:00 1.4 +++ LVM2/test/t-vgcfgbackup-usage.sh 2010/09/22 13:45:23 1.5 @@ -40,3 +40,12 @@ pvcreate -ff -y --norestorefile -u $pv1_uuid $dev1 pvcreate -ff -y --norestorefile -u $pv2_uuid $dev2 vgcfgrestore -f "$(pwd)/backup.$$1" $vg +vgremove -ff $vg + +# vgcfgbackup correctly stores metadata LVM1 with missing PVs +pvcreate -M1 $devs +vgcreate -M1 -c n $vg $devs +lvcreate -l1 -n $lv1 $vg $dev1 +pvremove -ff -y $dev2 +not lvcreate -l1 -n $lv1 $vg $dev3 +vgcfgbackup -f "$(pwd)/backup.$$" $vg From agk@sourceware.org Wed Sep 22 22:31:00 2010 From: agk@sourceware.org (agk@sourceware.org) Date: Wed, 22 Sep 2010 22:31:00 -0000 Subject: LVM2 ./WHATS_NEW lib/device/dev-io.c Message-ID: <20100922223146.17341.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2010-09-22 22:31:46 Modified files: . : WHATS_NEW lib/device : dev-io.c Log message: Replace alloca with dm_malloc in _aligned_io. (This section of code dates from 2.4 and could be written more efficiently nowadays.) Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1733&r2=1.1734 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/device/dev-io.c.diff?cvsroot=lvm2&r1=1.69&r2=1.70 --- LVM2/WHATS_NEW 2010/09/22 13:45:21 1.1733 +++ LVM2/WHATS_NEW 2010/09/22 22:31:45 1.1734 @@ -1,5 +1,6 @@ Version 2.02.74 - ===================================== + Replace alloca with dm_malloc in _aligned_io. Fix partial mode operations for lvm1 metadata format. Track recursive filter iteration to avoid refreshing while in use. (2.02.56) Revert to old glibc vsnprintf behaviour in emit_to_buffer() to catch overflow. --- LVM2/lib/device/dev-io.c 2010/07/09 15:34:42 1.69 +++ LVM2/lib/device/dev-io.c 2010/09/22 22:31:46 1.70 @@ -164,10 +164,11 @@ static int _aligned_io(struct device_area *where, void *buffer, int should_write) { - void *bounce; + void *bounce, *bounce_buf; unsigned int block_size = 0; uintptr_t mask; struct device_area widened; + int r = 0; if (!(where->dev->flags & DEV_REGULAR) && !_get_block_size(where->dev, &block_size)) @@ -185,8 +186,8 @@ return _io(where, buffer, should_write); /* Allocate a bounce buffer with an extra block */ - if (!(bounce = alloca((size_t) widened.size + block_size))) { - log_error("Bounce buffer alloca failed"); + if (!(bounce_buf = bounce = dm_malloc((size_t) widened.size + block_size))) { + log_error("Bounce buffer malloc failed"); return 0; } @@ -199,7 +200,7 @@ /* channel the io through the bounce buffer */ if (!_io(&widened, bounce, 0)) { if (!should_write) - return_0; + goto_out; /* FIXME pre-extend the file */ memset(bounce, '\n', widened.size); } @@ -209,13 +210,18 @@ (size_t) where->size); /* ... then we write */ - return _io(&widened, bounce, 1); + r = _io(&widened, bounce, 1); + goto_out; } memcpy(buffer, bounce + (where->start - widened.start), (size_t) where->size); - return 1; + r = 1; + +out: + dm_free(bounce_buf); + return r; } static int _dev_get_size_file(const struct device *dev, uint64_t *size) From prajnoha@sourceware.org Thu Sep 23 12:02:00 2010 From: prajnoha@sourceware.org (prajnoha@sourceware.org) Date: Thu, 23 Sep 2010 12:02:00 -0000 Subject: LVM2 ./WHATS_NEW lib/metadata/metadata.c lib/m ... Message-ID: <20100923120237.4064.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: prajnoha@sourceware.org 2010-09-23 12:02:35 Modified files: . : WHATS_NEW lib/metadata : metadata.c lib/misc : lvm-string.c lvm-string.h tools : pvchange.c pvck.c pvcreate.c pvmove.c pvremove.c toollib.c vgsplit.c Log message: Add escape sequence for ':' and '@' found in device names used as PVs. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1734&r2=1.1735 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.396&r2=1.397 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.21&r2=1.22 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.h.diff?cvsroot=lvm2&r1=1.20&r2=1.21 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvchange.c.diff?cvsroot=lvm2&r1=1.83&r2=1.84 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvck.c.diff?cvsroot=lvm2&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvcreate.c.diff?cvsroot=lvm2&r1=1.91&r2=1.92 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvmove.c.diff?cvsroot=lvm2&r1=1.79&r2=1.80 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/pvremove.c.diff?cvsroot=lvm2&r1=1.29&r2=1.30 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/toollib.c.diff?cvsroot=lvm2&r1=1.208&r2=1.209 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgsplit.c.diff?cvsroot=lvm2&r1=1.101&r2=1.102 --- LVM2/WHATS_NEW 2010/09/22 22:31:45 1.1734 +++ LVM2/WHATS_NEW 2010/09/23 12:02:33 1.1735 @@ -1,5 +1,6 @@ Version 2.02.74 - ===================================== + Add escape sequence for ':' and '@' found in device names used as PVs. Replace alloca with dm_malloc in _aligned_io. Fix partial mode operations for lvm1 metadata format. Track recursive filter iteration to avoid refreshing while in use. (2.02.56) --- LVM2/lib/metadata/metadata.c 2010/08/20 20:59:07 1.396 +++ LVM2/lib/metadata/metadata.c 2010/09/23 12:02:34 1.397 @@ -677,6 +677,7 @@ /* attach each pv */ for (i = 0; i < pv_count; i++) { + unescape_colons_and_at_signs(pv_names[i], NULL, NULL); if (!vg_extend_single_pv(vg, pv_names[i], pp)) goto bad; } --- LVM2/lib/misc/lvm-string.c 2010/09/20 14:25:27 1.21 +++ LVM2/lib/misc/lvm-string.c 2010/09/23 12:02:34 1.22 @@ -109,19 +109,31 @@ } /* - * Unquote orig_char in string. - * Also unquote quote_char. - */ -static void _unquote_characters(char *src, const int orig_char, - const int quote_char) + * Unquote each character given in orig_char array and unquote quote_char + * as well. The array ends up with '\0' character. Also save the first + * occurence of each character from orig_char that was found unquoted in + * arr_substr_first_unquoted array. This way we can process several + * characters in one go. + */ +static void _unquote_characters(char *src, const int orig_chars[], + const int quote_char, + char *arr_substr_first_unquoted[]) { char *out = src; + int c; + int i; while (*src) { - if (*src == quote_char && - (*(src + 1) == orig_char || *(src + 1) == quote_char)) - src++; - + for (i = 0; (c = orig_chars[i]); i++) { + if (*src == quote_char && + (*(src + 1) == c || *(src + 1) == quote_char)) { + src++; + break; + } + else if (arr_substr_first_unquoted && (*src == c) && + !arr_substr_first_unquoted[i]) + arr_substr_first_unquoted[i] = out; + } *out++ = *src++; } @@ -217,7 +229,31 @@ */ void unescape_double_quotes(char *src) { - _unquote_characters(src, '\"', '\\'); + const int orig_chars[] = {'\"', '\0'}; + + _unquote_characters(src, orig_chars, '\\', NULL); +} + +/* + * Unescape colons and "at" signs in situ and save the substrings + * starting at the position of the first unescaped colon and the + * first unescaped "at" sign. This is normally used to unescape + * device names used as PVs. + */ +void unescape_colons_and_at_signs(char *src, + char **substr_first_unquoted_colon, + char **substr_first_unquoted_at_sign) +{ + const int orig_chars[] = {':', '@', '\0'}; + char *arr_substr_first_unquoted[] = {NULL, NULL, NULL}; + + _unquote_characters(src, orig_chars, '\\', arr_substr_first_unquoted); + + if (substr_first_unquoted_colon) + *substr_first_unquoted_colon = arr_substr_first_unquoted[0]; + + if (substr_first_unquoted_at_sign) + *substr_first_unquoted_at_sign = arr_substr_first_unquoted[1]; } /* --- LVM2/lib/misc/lvm-string.h 2010/04/23 14:16:33 1.20 +++ LVM2/lib/misc/lvm-string.h 2010/09/23 12:02:34 1.21 @@ -60,4 +60,13 @@ */ void unescape_double_quotes(char *src); +/* + * Unescape colons and at signs in situ and save the substring starting + * at the position of the first unescaped colon and the first unescaped + * "at" sign. + */ +void unescape_colons_and_at_signs(char *src, + char **substr_first_unquoted_colon, + char **substr_first_unquoted_at_sign); + #endif --- LVM2/tools/pvchange.c 2010/07/09 15:34:48 1.83 +++ LVM2/tools/pvchange.c 2010/09/23 12:02:34 1.84 @@ -195,7 +195,8 @@ int total = 0; struct volume_group *vg; - const char *pv_name, *vg_name; + const char *vg_name; + char *pv_name; struct pv_list *pvl; struct dm_list *vgnames; @@ -223,6 +224,7 @@ log_verbose("Using physical volume(s) on command line"); for (; opt < argc; opt++) { pv_name = argv[opt]; + unescape_colons_and_at_signs(pv_name, NULL, NULL); vg_name = find_vgname_from_pvname(cmd, pv_name); if (!vg_name) { log_error("Failed to read physical volume %s", --- LVM2/tools/pvck.c 2007/08/22 14:38:18 1.4 +++ LVM2/tools/pvck.c 2010/09/23 12:02:34 1.5 @@ -31,6 +31,7 @@ /* FIXME: warning and/or check if in use? */ log_verbose("Scanning %s", argv[i]); + unescape_colons_and_at_signs(argv[i], NULL, NULL); pv_analyze(cmd, argv[i], arg_uint64_value(cmd, labelsector_ARG, UINT64_C(0))); --- LVM2/tools/pvcreate.c 2010/08/12 04:09:00 1.91 +++ LVM2/tools/pvcreate.c 2010/09/23 12:02:34 1.92 @@ -109,6 +109,8 @@ return ECMD_FAILED; } + unescape_colons_and_at_signs(argv[i], NULL, NULL); + if (!pvcreate_single(cmd, argv[i], &pp)) { stack; ret = ECMD_FAILED; --- LVM2/tools/pvmove.c 2010/08/23 11:34:10 1.79 +++ LVM2/tools/pvmove.c 2010/09/23 12:02:34 1.80 @@ -644,17 +644,16 @@ } if (argc) { - pv_name = argv[0]; + if (!(pv_name = dm_pool_strdup(cmd->mem, argv[0]))) { + log_error("Failed to clone PV name"); + return ECMD_FAILED; + } + + unescape_colons_and_at_signs(pv_name, &colon, NULL); /* Drop any PE lists from PV name */ - if ((colon = strchr(pv_name, ':'))) { - if (!(pv_name = dm_pool_strndup(cmd->mem, pv_name, - (unsigned) (colon - - pv_name)))) { - log_error("Failed to clone PV name"); - return ECMD_FAILED; - } - } + if (colon) + *colon = '\0'; if (!arg_count(cmd, abort_ARG) && (ret = _set_up_pvmove(cmd, pv_name, argc, argv)) != --- LVM2/tools/pvremove.c 2010/08/19 23:04:37 1.29 +++ LVM2/tools/pvremove.c 2010/09/23 12:02:34 1.30 @@ -144,6 +144,7 @@ } for (i = 0; i < argc; i++) { + unescape_colons_and_at_signs(argv[i], NULL, NULL); r = pvremove_single(cmd, argv[i], NULL); if (r > ret) ret = r; --- LVM2/tools/toollib.c 2010/08/19 23:04:37 1.208 +++ LVM2/tools/toollib.c 2010/09/23 12:02:34 1.209 @@ -680,7 +680,7 @@ struct dm_list *pvslist, *vgnames; struct dm_list tags; struct str_list *sll; - char *tagname; + char *at_sign, *tagname; int scanned = 0; struct dm_list mdas; @@ -694,8 +694,9 @@ if (argc) { log_verbose("Using physical volume(s) on command line"); for (; opt < argc; opt++) { - if (*argv[opt] == '@') { - tagname = argv[opt] + 1; + unescape_colons_and_at_signs(argv[opt], NULL, &at_sign); + if (at_sign && (at_sign == argv[opt])) { + tagname = at_sign + 1; if (!validate_name(tagname)) { log_error("Skipping invalid tag %s", @@ -1093,8 +1094,8 @@ struct dm_list *r; struct pv_list *pvl; struct dm_list tags, arg_pvnames; - const char *pvname = NULL; - char *colon, *tagname; + char *pvname = NULL; + char *colon, *at_sign, *tagname; int i; /* Build up list of PVs */ @@ -1108,8 +1109,10 @@ dm_list_init(&arg_pvnames); for (i = 0; i < argc; i++) { - if (*argv[i] == '@') { - tagname = argv[i] + 1; + unescape_colons_and_at_signs(argv[i], &colon, &at_sign); + + if (at_sign && (at_sign == argv[i])) { + tagname = at_sign + 1; if (!validate_name(tagname)) { log_error("Skipping invalid tag %s", tagname); continue; @@ -1128,13 +1131,10 @@ pvname = argv[i]; - if ((colon = strchr(pvname, ':'))) { - if (!(pvname = dm_pool_strndup(mem, pvname, - (unsigned) (colon - - pvname)))) { - log_error("Failed to clone PV name"); - return NULL; - } + if (colon && !(pvname = dm_pool_strndup(mem, pvname, + (unsigned) (colon - pvname)))) { + log_error("Failed to clone PV name"); + return NULL; } if (!(pvl = find_pv_in_vg(vg, pvname))) { --- LVM2/tools/vgsplit.c 2010/06/30 20:03:53 1.101 +++ LVM2/tools/vgsplit.c 2010/09/23 12:02:34 1.102 @@ -394,6 +394,7 @@ /* Move PVs across to new structure */ for (opt = 0; opt < argc; opt++) { + unescape_colons_and_at_signs(argv[opt], NULL, NULL); if (!move_pv(vg_from, vg_to, argv[opt])) goto_bad; } From agk@sourceware.org Fri Sep 24 16:25:00 2010 From: agk@sourceware.org (agk@sourceware.org) Date: Fri, 24 Sep 2010 16:25:00 -0000 Subject: LVM2 VERSION VERSION_DM WHATS_NEW WHATS_NEW_DM Message-ID: <20100924162504.22605.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2010-09-24 16:24:59 Modified files: . : VERSION VERSION_DM WHATS_NEW WHATS_NEW_DM Log message: pre-release Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/VERSION.diff?cvsroot=lvm2&r1=1.254&r2=1.255 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/VERSION_DM.diff?cvsroot=lvm2&r1=1.63&r2=1.64 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1735&r2=1.1736 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW_DM.diff?cvsroot=lvm2&r1=1.414&r2=1.415 --- LVM2/VERSION 2010/09/22 01:36:13 1.254 +++ LVM2/VERSION 2010/09/24 16:24:57 1.255 @@ -1 +1 @@ -2.02.74(2)-cvs (2010-09-22) +2.02.74(2)-cvs (2010-09-24) --- LVM2/VERSION_DM 2010/09/22 01:36:13 1.63 +++ LVM2/VERSION_DM 2010/09/24 16:24:57 1.64 @@ -1 +1 @@ -1.02.55-cvs (2010-09-22) +1.02.55-cvs (2010-09-24) --- LVM2/WHATS_NEW 2010/09/23 12:02:33 1.1735 +++ LVM2/WHATS_NEW 2010/09/24 16:24:57 1.1736 @@ -1,14 +1,13 @@ -Version 2.02.74 - +Version 2.02.74 - 24th September 2010 ===================================== - Add escape sequence for ':' and '@' found in device names used as PVs. - Replace alloca with dm_malloc in _aligned_io. + Allow : and @ to be escaped with \ in device names of PVs. + Replace alloca with dm_malloc in _aligned_io to avoid stack corruption. Fix partial mode operations for lvm1 metadata format. Track recursive filter iteration to avoid refreshing while in use. (2.02.56) Revert to old glibc vsnprintf behaviour in emit_to_buffer() to catch overflow. Allocate buffer for metadata tags dynamically to remove 4k limit. Add random suffix to archive file names to prevent races when being created. Reinitialize archive and backup handling on toolcontext refresh. - Fix opprobriously slow I/O to cluster mirrors created with --nosync. Make poll_mirror_progress report PROGRESS_CHECK_FAILED if LV is not a mirror. Like mirrors, don't scan origins if ignore_suspended_devices() is set. Fix return type qualifier to avoid compiler warning. (2.02.69) --- LVM2/WHATS_NEW_DM 2010/09/22 01:36:13 1.414 +++ LVM2/WHATS_NEW_DM 2010/09/24 16:24:57 1.415 @@ -1,5 +1,6 @@ -Version 1.02.55 - +Version 1.02.55 - 24th September 2010 ===================================== + Fix the way regions are marked complete to avoid slow --nosync cmirror I/O. Add DM_REPORT_FIELD_TYPE_ID_LEN to libdevmapper.h. Version 1.02.54 - 18th August 2010 From agk@sourceware.org Mon Sep 27 19:09:00 2010 From: agk@sourceware.org (agk@sourceware.org) Date: Mon, 27 Sep 2010 19:09:00 -0000 Subject: LVM2 ./VERSION ./VERSION_DM ./WHATS_NEW ./WHAT ... Message-ID: <20100927190940.21831.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2010-09-27 19:09:36 Modified files: . : VERSION VERSION_DM WHATS_NEW WHATS_NEW_DM make.tmpl.in lib/config : config.c config.h lib/format_text: format-text.c lib/label : label.c lib/misc : crc.c crc.h Added files: lib/misc : crc_gen.c Log message: Speed up CRC32 calculations by using a larger lookup table. Use -DDEBUG_CRC32 to revert to old function and check new one gives same result. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/VERSION.diff?cvsroot=lvm2&r1=1.255&r2=1.256 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/VERSION_DM.diff?cvsroot=lvm2&r1=1.64&r2=1.65 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1736&r2=1.1737 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW_DM.diff?cvsroot=lvm2&r1=1.415&r2=1.416 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/make.tmpl.in.diff?cvsroot=lvm2&r1=1.110&r2=1.111 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/config/config.c.diff?cvsroot=lvm2&r1=1.80&r2=1.81 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/config/config.h.diff?cvsroot=lvm2&r1=1.30&r2=1.31 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.144&r2=1.145 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/label/label.c.diff?cvsroot=lvm2&r1=1.50&r2=1.51 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/crc_gen.c.diff?cvsroot=lvm2&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/crc.c.diff?cvsroot=lvm2&r1=1.6&r2=1.7 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/crc.h.diff?cvsroot=lvm2&r1=1.5&r2=1.6 --- LVM2/VERSION 2010/09/24 16:24:57 1.255 +++ LVM2/VERSION 2010/09/27 19:09:34 1.256 @@ -1 +1 @@ -2.02.74(2)-cvs (2010-09-24) +2.02.75(2)-cvs (2010-09-24) --- LVM2/VERSION_DM 2010/09/24 16:24:57 1.64 +++ LVM2/VERSION_DM 2010/09/27 19:09:34 1.65 @@ -1 +1 @@ -1.02.55-cvs (2010-09-24) +1.02.56-cvs (2010-09-24) --- LVM2/WHATS_NEW 2010/09/24 16:24:57 1.1736 +++ LVM2/WHATS_NEW 2010/09/27 19:09:34 1.1737 @@ -1,3 +1,7 @@ +Version 2.02.75 - +===================================== + Speed up CRC32 calculations by using a larger lookup table. + Version 2.02.74 - 24th September 2010 ===================================== Allow : and @ to be escaped with \ in device names of PVs. @@ -17,7 +21,7 @@ Add configure --with-default-data-alignment. Update heuristic used for default and detected data alignment. Add "devices/default_data_alignment" to lvm.conf. - Add implmentation for simple numeric 'get' property functions. + Add implementation for simple numeric 'get' property functions. Define GET_NUM_PROPERTY_FN macro to simplify numeric property 'get' function Add properties.[ch] to lib/report using columns.h. Add macro definitions to report infrastructure for character array length. --- LVM2/WHATS_NEW_DM 2010/09/24 16:24:57 1.415 +++ LVM2/WHATS_NEW_DM 2010/09/27 19:09:34 1.416 @@ -1,3 +1,6 @@ +Version 1.02.56 - +===================================== + Version 1.02.55 - 24th September 2010 ===================================== Fix the way regions are marked complete to avoid slow --nosync cmirror I/O. --- LVM2/make.tmpl.in 2010/08/16 17:49:26 1.110 +++ LVM2/make.tmpl.in 2010/09/27 19:09:34 1.111 @@ -113,6 +113,7 @@ #CFLAGS += -W -Wconversion -Wpointer-arith -Wbad-function-cast -Wcast-qual #CFLAGS += -pedantic -std=gnu99 +#CFLAGS += -DDEBUG_CRC32 CFLAGS += @COPTIMISE_FLAG@ --- LVM2/lib/config/config.c 2010/07/09 15:34:42 1.80 +++ LVM2/lib/config/config.c 2010/09/27 19:09:34 1.81 @@ -239,8 +239,8 @@ } if (checksum_fn && checksum != - (checksum_fn(checksum_fn(INITIAL_CRC, p->fb, size), - p->fb + size, size2))) { + (checksum_fn(checksum_fn(INITIAL_CRC, (uint8_t *)p->fb, size), + (uint8_t *)(p->fb + size), size2))) { log_error("%s: Checksum error", dev_name(dev)); goto out; } --- LVM2/lib/config/config.h 2009/10/22 10:38:07 1.30 +++ LVM2/lib/config/config.h 2010/09/27 19:09:34 1.31 @@ -60,7 +60,7 @@ const char *config_settings); void destroy_config_tree(struct config_tree *cft); -typedef uint32_t (*checksum_fn_t) (uint32_t initial, const void *buf, uint32_t size); +typedef uint32_t (*checksum_fn_t) (uint32_t initial, const uint8_t *buf, uint32_t size); int read_config_fd(struct config_tree *cft, struct device *dev, off_t offset, size_t size, off_t offset2, size_t size2, --- LVM2/lib/format_text/format-text.c 2010/08/26 12:22:05 1.144 +++ LVM2/lib/format_text/format-text.c 2010/09/27 19:09:35 1.145 @@ -332,7 +332,7 @@ if (!dev_read(dev_area->dev, dev_area->start, MDA_HEADER_SIZE, mdah)) goto_bad; - if (mdah->checksum_xl != xlate32(calc_crc(INITIAL_CRC, mdah->magic, + if (mdah->checksum_xl != xlate32(calc_crc(INITIAL_CRC, (uint8_t *)mdah->magic, MDA_HEADER_SIZE - sizeof(mdah->checksum_xl)))) { log_error("Incorrect metadata area header checksum on %s" @@ -380,7 +380,7 @@ mdah->start = start_byte; _xlate_mdah(mdah); - mdah->checksum_xl = xlate32(calc_crc(INITIAL_CRC, mdah->magic, + mdah->checksum_xl = xlate32(calc_crc(INITIAL_CRC, (uint8_t *)mdah->magic, MDA_HEADER_SIZE - sizeof(mdah->checksum_xl))); @@ -650,12 +650,12 @@ goto_out; } - mdac->rlocn.checksum = calc_crc(INITIAL_CRC, fidtc->raw_metadata_buf, + mdac->rlocn.checksum = calc_crc(INITIAL_CRC, (uint8_t *)fidtc->raw_metadata_buf, (uint32_t) (mdac->rlocn.size - new_wrap)); if (new_wrap) mdac->rlocn.checksum = calc_crc(mdac->rlocn.checksum, - fidtc->raw_metadata_buf + + (uint8_t *)fidtc->raw_metadata_buf + mdac->rlocn.size - new_wrap, (uint32_t) new_wrap); --- LVM2/lib/label/label.c 2010/07/09 15:34:44 1.50 +++ LVM2/lib/label/label.c 2010/09/27 19:09:35 1.51 @@ -142,8 +142,8 @@ sector + scan_sector); continue; } - if (calc_crc(INITIAL_CRC, &lh->offset_xl, LABEL_SIZE - - ((uintptr_t) &lh->offset_xl - (uintptr_t) lh)) != + if (calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl, LABEL_SIZE - + ((uint8_t *) &lh->offset_xl - (uint8_t *) lh)) != xlate32(lh->crc_xl)) { log_info("Label checksum incorrect on %s - " "ignoring", dev_name(dev)); @@ -323,8 +323,8 @@ if (!(label->labeller->ops->write)(label, buf)) return_0; - lh->crc_xl = xlate32(calc_crc(INITIAL_CRC, &lh->offset_xl, LABEL_SIZE - - ((uintptr_t) &lh->offset_xl - (uintptr_t) lh))); + lh->crc_xl = xlate32(calc_crc(INITIAL_CRC, (uint8_t *)&lh->offset_xl, LABEL_SIZE - + ((uint8_t *) &lh->offset_xl - (uint8_t *) lh))); if (!dev_open(dev)) return_0; /cvs/lvm2/LVM2/lib/misc/crc_gen.c,v --> standard output revision 1.1 --- LVM2/lib/misc/crc_gen.c +++ - 2010-09-27 19:09:39.765327000 +0000 @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * Helper program to generate table included in crc.c. + */ +#include "lib.h" + +int main(int argc, char **argv) +{ + uint32_t crc, i, j; + + printf("\t/* CRC-32 byte lookup table generated by crcgen.c */\n"); + printf("\tstatic const uint32_t crctab[] = {"); + + for (i = 0; i < 256; i++) { + crc = i; + for (j = 0; j < 8; j++) { + if (crc & 1) + crc = 0xedb88320L ^ (crc >> 1); + else + crc = crc >> 1; + } + + if (i % 8) + printf(" "); + else + printf("\n\t\t"); + + printf("0x%08.8x,", crc); + } + + printf("\n\t};\n"); + + return 0; +} --- LVM2/lib/misc/crc.c 2008/01/30 14:00:00 1.6 +++ LVM2/lib/misc/crc.c 2010/09/27 19:09:35 1.7 @@ -18,7 +18,73 @@ #include "crc.h" /* Calculate an endian-independent CRC of supplied buffer */ -uint32_t calc_crc(uint32_t initial, const void *buf, uint32_t size) +#ifndef DEBUG_CRC32 +uint32_t calc_crc(uint32_t initial, const uint8_t *buf, uint32_t size) +#else +static uint32_t _calc_crc_new(uint32_t initial, const uint8_t *buf, uint32_t size) +#endif +{ + /* CRC-32 byte lookup table generated by crcgen.c */ + static const uint32_t crctab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, + }; + uint32_t *start = (uint32_t *) buf; + uint32_t *end = (uint32_t *) (buf + (size & 0xfffffffc)); + uint32_t crc = initial; + + /* Process 4 bytes per iteration */ + while (start < end) { + crc = crc ^ *start++; + crc = crctab[crc & 0xff] ^ crc >> 8; + crc = crctab[crc & 0xff] ^ crc >> 8; + crc = crctab[crc & 0xff] ^ crc >> 8; + crc = crctab[crc & 0xff] ^ crc >> 8; + } + + /* Process any bytes left over */ + buf = (uint8_t *) start; + size = size & 0x3; + while (size--) { + crc = crc ^ *buf++; + crc = crctab[crc & 0xff] ^ crc >> 8; + } + + return crc; +} + +#ifdef DEBUG_CRC32 +static uint32_t _calc_crc_old(uint32_t initial, const uint8_t *buf, uint32_t size) { static const uint32_t crctab[] = { 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, @@ -27,12 +93,24 @@ 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c }; uint32_t i, crc = initial; - const uint8_t *data = (const uint8_t *) buf; for (i = 0; i < size; i++) { - crc ^= *data++; + crc ^= *buf++; crc = (crc >> 4) ^ crctab[crc & 0xf]; crc = (crc >> 4) ^ crctab[crc & 0xf]; } return crc; } + +uint32_t calc_crc(uint32_t initial, const uint8_t *buf, uint32_t size) +{ + uint32_t new_crc = _calc_crc_new(initial, buf, size); + uint32_t old_crc = _calc_crc_old(initial, buf, size); + + if (new_crc != old_crc) + log_error(INTERNAL_ERROR "Old and new crc32 algorithms mismatch: 0x%08x != 0x%08x", old_crc, new_crc); + + return old_crc; +} + +#endif /* DEBUG_CRC32 */ --- LVM2/lib/misc/crc.h 2007/08/20 20:55:27 1.5 +++ LVM2/lib/misc/crc.h 2010/09/27 19:09:36 1.6 @@ -18,6 +18,6 @@ #define INITIAL_CRC 0xf597a6cf -uint32_t calc_crc(uint32_t initial, const void *buf, uint32_t size); +uint32_t calc_crc(uint32_t initial, const uint8_t *buf, uint32_t size); #endif From agk@sourceware.org Mon Sep 27 19:10:00 2010 From: agk@sourceware.org (agk@sourceware.org) Date: Mon, 27 Sep 2010 19:10:00 -0000 Subject: LVM2/lib/misc crc.c crc_gen.c Message-ID: <20100927191046.22189.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2010-09-27 19:10:46 Modified files: lib/misc : crc.c crc_gen.c Log message: was renamed Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/crc.c.diff?cvsroot=lvm2&r1=1.7&r2=1.8 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/crc_gen.c.diff?cvsroot=lvm2&r1=1.1&r2=1.2 --- LVM2/lib/misc/crc.c 2010/09/27 19:09:35 1.7 +++ LVM2/lib/misc/crc.c 2010/09/27 19:10:46 1.8 @@ -24,7 +24,7 @@ static uint32_t _calc_crc_new(uint32_t initial, const uint8_t *buf, uint32_t size) #endif { - /* CRC-32 byte lookup table generated by crcgen.c */ + /* CRC-32 byte lookup table generated by crc_gen.c */ static const uint32_t crctab[] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, --- LVM2/lib/misc/crc_gen.c 2010/09/27 19:09:36 1.1 +++ LVM2/lib/misc/crc_gen.c 2010/09/27 19:10:46 1.2 @@ -21,7 +21,7 @@ { uint32_t crc, i, j; - printf("\t/* CRC-32 byte lookup table generated by crcgen.c */\n"); + printf("\t/* CRC-32 byte lookup table generated by crc_gen.c */\n"); printf("\tstatic const uint32_t crctab[] = {"); for (i = 0; i < 256; i++) { From agk@sourceware.org Mon Sep 27 19:15:00 2010 From: agk@sourceware.org (agk@sourceware.org) Date: Mon, 27 Sep 2010 19:15:00 -0000 Subject: LVM2/lib/device dev-io.c Message-ID: <20100927191514.24881.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2010-09-27 19:15:13 Modified files: lib/device : dev-io.c Log message: drop an unnecessary 'stack' Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/device/dev-io.c.diff?cvsroot=lvm2&r1=1.70&r2=1.71 --- LVM2/lib/device/dev-io.c 2010/09/22 22:31:46 1.70 +++ LVM2/lib/device/dev-io.c 2010/09/27 19:15:13 1.71 @@ -210,8 +210,10 @@ (size_t) where->size); /* ... then we write */ - r = _io(&widened, bounce, 1); - goto_out; + if (!(r = _io(&widened, bounce, 1))) + stack; + + goto out; } memcpy(buffer, bounce + (where->start - widened.start), From agk@sourceware.org Tue Sep 28 01:29:00 2010 From: agk@sourceware.org (agk@sourceware.org) Date: Tue, 28 Sep 2010 01:29:00 -0000 Subject: LVM2 ./WHATS_NEW lib/misc/lvm-string.c Message-ID: <20100928012908.16589.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2010-09-28 01:29:07 Modified files: . : WHATS_NEW lib/misc : lvm-string.c Log message: Speed up unquoting of quoted double quotes and backslashes. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1737&r2=1.1738 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.22&r2=1.23 --- LVM2/WHATS_NEW 2010/09/27 19:09:34 1.1737 +++ LVM2/WHATS_NEW 2010/09/28 01:29:06 1.1738 @@ -1,5 +1,6 @@ Version 2.02.75 - ===================================== + Speed up unquoting of quoted double quotes and backslashes. Speed up CRC32 calculations by using a larger lookup table. Version 2.02.74 - 24th September 2010 --- LVM2/lib/misc/lvm-string.c 2010/09/23 12:02:34 1.22 +++ LVM2/lib/misc/lvm-string.c 2010/09/28 01:29:07 1.23 @@ -108,33 +108,64 @@ } } +static void _unquote_one_character(char *src, const char orig_char, + const char quote_char) +{ + char *out; + char s, n; + + /* Optimise for the common case where no changes are needed. */ + while ((s = *src++)) { + if (s == quote_char && + ((n = *src) == orig_char || n == quote_char)) { + out = src++; + *(out - 1) = n; + + while ((s = *src++)) { + if (s == quote_char && + ((n = *src) == orig_char || n == quote_char)) { + s = n; + src++; + } + *out = s; + out++; + } + + *out = '\0'; + return; + } + } +} + /* * Unquote each character given in orig_char array and unquote quote_char - * as well. The array ends up with '\0' character. Also save the first - * occurence of each character from orig_char that was found unquoted in - * arr_substr_first_unquoted array. This way we can process several - * characters in one go. + * as well. Also save the first occurrence of each character from orig_char + * that was found unquoted in arr_substr_first_unquoted array. This way we can + * process several characters in one go. */ -static void _unquote_characters(char *src, const int orig_chars[], - const int quote_char, +static void _unquote_characters(char *src, const char *orig_chars, + const int num_orig_chars, + const char quote_char, char *arr_substr_first_unquoted[]) { char *out = src; - int c; - int i; + char c, s, n; + unsigned i; - while (*src) { - for (i = 0; (c = orig_chars[i]); i++) { - if (*src == quote_char && - (*(src + 1) == c || *(src + 1) == quote_char)) { + while ((s = *src++)) { + for (i = 0; i < num_orig_chars; i++) { + c = orig_chars[i]; + if (s == quote_char && + ((n = *src) == c || n == quote_char)) { + s = n; src++; break; } - else if (arr_substr_first_unquoted && (*src == c) && - !arr_substr_first_unquoted[i]) + if (arr_substr_first_unquoted && (s == c) && + !arr_substr_first_unquoted[i]) arr_substr_first_unquoted[i] = out; - } - *out++ = *src++; + }; + *out++ = s; } *out = '\0'; @@ -229,9 +260,7 @@ */ void unescape_double_quotes(char *src) { - const int orig_chars[] = {'\"', '\0'}; - - _unquote_characters(src, orig_chars, '\\', NULL); + _unquote_one_character(src, '\"', '\\'); } /* @@ -244,10 +273,10 @@ char **substr_first_unquoted_colon, char **substr_first_unquoted_at_sign) { - const int orig_chars[] = {':', '@', '\0'}; + const char *orig_chars = ":@"; char *arr_substr_first_unquoted[] = {NULL, NULL, NULL}; - _unquote_characters(src, orig_chars, '\\', arr_substr_first_unquoted); + _unquote_characters(src, orig_chars, 2, '\\', arr_substr_first_unquoted); if (substr_first_unquoted_colon) *substr_first_unquoted_colon = arr_substr_first_unquoted[0]; From zkabelac@sourceware.org Thu Sep 30 10:09:00 2010 From: zkabelac@sourceware.org (zkabelac@sourceware.org) Date: Thu, 30 Sep 2010 10:09:00 -0000 Subject: LVM2/daemons/dmeventd/plugins lvm2/Makefile.in ... Message-ID: <20100930100900.22616.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: zkabelac@sourceware.org 2010-09-30 10:08:59 Modified files: daemons/dmeventd/plugins/lvm2: Makefile.in daemons/dmeventd/plugins/mirror: Makefile.in daemons/dmeventd/plugins/snapshot: Makefile.in Log message: Add missing cleanup rule for generated .exported_symbols_generated Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/lvm2/Makefile.in.diff?cvsroot=lvm2&r1=1.5&r2=1.6 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/mirror/Makefile.in.diff?cvsroot=lvm2&r1=1.21&r2=1.22 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/snapshot/Makefile.in.diff?cvsroot=lvm2&r1=1.16&r2=1.17 --- LVM2/daemons/dmeventd/plugins/lvm2/Makefile.in 2010/04/09 21:42:49 1.5 +++ LVM2/daemons/dmeventd/plugins/lvm2/Makefile.in 2010/09/30 10:08:58 1.6 @@ -29,3 +29,5 @@ install_lvm2: install_lib_shared install: install_lvm2 + +DISTCLEAN_TARGETS += .exported_symbols_generated --- LVM2/daemons/dmeventd/plugins/mirror/Makefile.in 2010/05/11 08:41:58 1.21 +++ LVM2/daemons/dmeventd/plugins/mirror/Makefile.in 2010/09/30 10:08:59 1.22 @@ -35,3 +35,5 @@ install_lvm2: install_dm_plugin install: install_lvm2 + +DISTCLEAN_TARGETS += .exported_symbols_generated --- LVM2/daemons/dmeventd/plugins/snapshot/Makefile.in 2010/05/11 08:41:59 1.16 +++ LVM2/daemons/dmeventd/plugins/snapshot/Makefile.in 2010/09/30 10:08:59 1.17 @@ -31,3 +31,5 @@ install_lvm2: install_dm_plugin install: install_lvm2 + +DISTCLEAN_TARGETS += .exported_symbols_generated From zkabelac@sourceware.org Thu Sep 30 11:32:00 2010 From: zkabelac@sourceware.org (zkabelac@sourceware.org) Date: Thu, 30 Sep 2010 11:32:00 -0000 Subject: LVM2 ./WHATS_NEW lib/mm/memlock.c Message-ID: <20100930113242.30347.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: zkabelac@sourceware.org 2010-09-30 11:32:41 Modified files: . : WHATS_NEW lib/mm : memlock.c Log message: Maps fix Read complete content of /proc/self/maps into one buffer without realocation in the middle of reading and before doing any m/unlock operation with these lines - as some of them gets change. With previous implementation we've read some mappings twice ([stack]) Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1738&r2=1.1739 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/mm/memlock.c.diff?cvsroot=lvm2&r1=1.29&r2=1.30 --- LVM2/WHATS_NEW 2010/09/28 01:29:06 1.1738 +++ LVM2/WHATS_NEW 2010/09/30 11:32:40 1.1739 @@ -1,5 +1,6 @@ Version 2.02.75 - ===================================== + Read whole /proc/self/maps file before working with maps entries. Speed up unquoting of quoted double quotes and backslashes. Speed up CRC32 calculations by using a larger lookup table. --- LVM2/lib/mm/memlock.c 2010/07/08 14:47:46 1.29 +++ LVM2/lib/mm/memlock.c 2010/09/30 11:32:41 1.30 @@ -76,7 +76,9 @@ typedef enum { LVM_MLOCK, LVM_MUNLOCK } lvmlock_t; static unsigned _use_mlockall; -static FILE *_mapsh; +static int _maps_fd; +static size_t _maps_len = 8192; /* Initial buffer size for reading /proc/self/maps */ +static char *_maps_buffer; static char _procselfmaps[PATH_MAX] = ""; #define SELF_MAPS "/self/maps" @@ -193,7 +195,7 @@ static int _memlock_maps(struct cmd_context *cmd, lvmlock_t lock, size_t *mstats) { - char *line = NULL; + char *line, *line_end; size_t len; ssize_t n; int ret = 1; @@ -222,15 +224,39 @@ (void)strerror(0); /* Reset statistic counters */ *mstats = 0; - rewind(_mapsh); - while ((n = getline(&line, &len, _mapsh)) != -1) { - line[n > 0 ? n - 1 : 0] = '\0'; /* remove \n */ - if (!_maps_line(cmd, lock, line, mstats)) - ret = 0; + /* read mapping into a single memory chunk without reallocation + * in the middle of reading maps file */ + for (len = 0;;) { + if (!_maps_buffer || len >= _maps_len) { + if (_maps_buffer) + _maps_len *= 2; + if (!(_maps_buffer = dm_realloc(_maps_buffer, _maps_len))) { + log_error("Allocation of maps buffer failed"); + return 0; + } + } + lseek(_maps_fd, 0, SEEK_SET); + for (len = 0 ; len < _maps_len; len += n) { + if (!(n = read(_maps_fd, _maps_buffer + len, _maps_len - len))) { + _maps_buffer[len] = '\0'; + break; /* EOF */ + } + if (n == -1) + return_0; + } + if (len < _maps_len) /* fits in buffer */ + break; } - free(line); + line = _maps_buffer; + + while ((line_end = strchr(line, '\n'))) { + *line_end = '\0'; /* remove \n */ + if (!_maps_line(cmd, lock, line, mstats)) + ret = 0; + line = line_end + 1; + } log_debug("%socked %ld bytes", (lock == LVM_MLOCK) ? "L" : "Unl", (long)*mstats); @@ -260,8 +286,8 @@ return; } - if (!(_mapsh = fopen(_procselfmaps, "r"))) { - log_sys_error("fopen", _procselfmaps); + if (!(_maps_fd = open(_procselfmaps, O_RDONLY))) { + log_sys_error("open", _procselfmaps); return; } } @@ -289,9 +315,10 @@ stack; if (!_use_mlockall) { - if (fclose(_mapsh)) - log_sys_error("fclose", _procselfmaps); - + if (close(_maps_fd)) + log_sys_error("close", _procselfmaps); + dm_free(_maps_buffer); + _maps_buffer = NULL; if (_mstats < unlock_mstats) log_error(INTERNAL_ERROR "Maps lock %ld < unlock %ld", (long)_mstats, (long)unlock_mstats); From zkabelac@sourceware.org Thu Sep 30 11:40:00 2010 From: zkabelac@sourceware.org (zkabelac@sourceware.org) Date: Thu, 30 Sep 2010 11:40:00 -0000 Subject: LVM2 ./WHATS_NEW daemons/dmeventd/plugins/lvm2 ... Message-ID: <20100930114015.19637.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: zkabelac@sourceware.org 2010-09-30 11:40:14 Modified files: . : WHATS_NEW daemons/dmeventd/plugins/lvm2: dmeventd_lvm.c Log message: Fix leaked pool report Swap pool destruction order in dmeventd_lvm2_exit() to fix leak report. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1739&r2=1.1740 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c.diff?cvsroot=lvm2&r1=1.4&r2=1.5 --- LVM2/WHATS_NEW 2010/09/30 11:32:40 1.1739 +++ LVM2/WHATS_NEW 2010/09/30 11:40:14 1.1740 @@ -1,5 +1,6 @@ Version 2.02.75 - ===================================== + Swap pool destruction order in dmeventd_lvm2_exit() to fix leak report. Read whole /proc/self/maps file before working with maps entries. Speed up unquoting of quoted double quotes and backslashes. Speed up CRC32 calculations by using a larger lookup table. --- LVM2/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c 2010/07/09 15:34:41 1.4 +++ LVM2/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c 2010/09/30 11:40:14 1.5 @@ -131,10 +131,10 @@ if (!--_register_count) { lvm2_run(_lvm_handle, "_memlock_dec"); - lvm2_exit(_lvm_handle); - _lvm_handle = NULL; dm_pool_destroy(_mem_pool); _mem_pool = NULL; + lvm2_exit(_lvm_handle); + _lvm_handle = NULL; } pthread_mutex_unlock(&_register_mutex); From zkabelac@sourceware.org Thu Sep 30 11:44:00 2010 From: zkabelac@sourceware.org (zkabelac@sourceware.org) Date: Thu, 30 Sep 2010 11:44:00 -0000 Subject: LVM2 ./WHATS_NEW tools/lvmcmdline.c Message-ID: <20100930114458.23234.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: zkabelac@sourceware.org 2010-09-30 11:44:55 Modified files: . : WHATS_NEW tools : lvmcmdline.c Log message: Fix memory leak of config_tree Adding missing destroy_config_tree() for cft_override if it has been allocated. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1740&r2=1.1741 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/lvmcmdline.c.diff?cvsroot=lvm2&r1=1.127&r2=1.128 --- LVM2/WHATS_NEW 2010/09/30 11:40:14 1.1740 +++ LVM2/WHATS_NEW 2010/09/30 11:44:54 1.1741 @@ -1,5 +1,6 @@ Version 2.02.75 - ===================================== + Fix memory leak of config_tree in reinitialization code path. Swap pool destruction order in dmeventd_lvm2_exit() to fix leak report. Read whole /proc/self/maps file before working with maps entries. Speed up unquoting of quoted double quotes and backslashes. --- LVM2/tools/lvmcmdline.c 2010/07/09 15:34:48 1.127 +++ LVM2/tools/lvmcmdline.c 2010/09/30 11:44:54 1.128 @@ -1048,6 +1048,10 @@ if (arg_count(cmd, config_ARG) || !cmd->config_valid || config_files_changed(cmd)) { /* Reinitialise various settings inc. logging, filters */ if (!refresh_toolcontext(cmd)) { + if (cmd->cft_override) { + destroy_config_tree(cmd->cft_override); + cmd->cft_override = NULL; + } log_error("Updated config file invalid. Aborting."); return ECMD_FAILED; } From wysochanski@sourceware.org Thu Sep 30 13:04:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 13:04:00 -0000 Subject: LVM2 include/.symlinks.in lib/Makefile.in lib/ ... Message-ID: <20100930130457.19463.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 13:04:56 Modified files: include : .symlinks.in lib : Makefile.in lib/metadata : metadata-exported.h metadata.c metadata.h Log message: Refactor metadata.[ch] into vg.[ch] for vg functions. The metadata.[ch] files are very large. This patch makes a first attempt at separating out vg functions and data, particularly related to the reporting fields calculations. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/include/.symlinks.in.diff?cvsroot=lvm2&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/Makefile.in.diff?cvsroot=lvm2&r1=1.105&r2=1.106 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.165&r2=1.166 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.397&r2=1.398 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.218&r2=1.219 --- LVM2/include/.symlinks.in 2010/08/20 12:44:47 1.3 +++ LVM2/include/.symlinks.in 2010/09/30 13:04:55 1.4 @@ -35,6 +35,7 @@ @top_srcdir@/lib/metadata/metadata-exported.h @top_srcdir@/lib/metadata/pv_alloc.h @top_srcdir@/lib/metadata/segtype.h +@top_srcdir@/lib/metadata/vg.h @top_srcdir@/lib/mm/memlock.h @top_srcdir@/lib/mm/xlate.h @top_builddir@/lib/misc/configure.h --- LVM2/lib/Makefile.in 2010/08/20 12:44:47 1.105 +++ LVM2/lib/Makefile.in 2010/09/30 13:04:55 1.106 @@ -82,6 +82,7 @@ metadata/replicator_manip.c \ metadata/segtype.c \ metadata/snapshot_manip.c \ + metadata/vg.c \ misc/crc.c \ misc/lvm-exec.c \ misc/lvm-file.c \ --- LVM2/lib/metadata/metadata-exported.h 2010/07/08 18:24:30 1.165 +++ LVM2/lib/metadata/metadata-exported.h 2010/09/30 13:04:56 1.166 @@ -22,6 +22,7 @@ #define _LVM_METADATA_EXPORTED_H #include "uuid.h" +#include "vg.h" #define MAX_STRIPES 128U #define SECTOR_SHIFT 9L @@ -122,15 +123,6 @@ /* Ordered list - see lv_manip.c */ typedef enum { - ALLOC_INVALID, - ALLOC_CONTIGUOUS, - ALLOC_CLING, - ALLOC_NORMAL, - ALLOC_ANYWHERE, - ALLOC_INHERIT -} alloc_policy_t; - -typedef enum { AREA_UNASSIGNED, AREA_PV, AREA_LV @@ -229,70 +221,6 @@ void *private; }; -struct volume_group { - struct cmd_context *cmd; - struct dm_pool *vgmem; - struct format_instance *fid; - struct dm_list *cmd_vgs;/* List of wanted/locked and opened VGs */ - uint32_t cmd_missing_vgs;/* Flag marks missing VG */ - uint32_t seqno; /* Metadata sequence number */ - - alloc_policy_t alloc; - uint64_t status; - - struct id id; - char *name; - char *old_name; /* Set during vgrename and vgcfgrestore */ - char *system_id; - - uint32_t extent_size; - uint32_t extent_count; - uint32_t free_count; - - uint32_t max_lv; - uint32_t max_pv; - - /* physical volumes */ - uint32_t pv_count; - struct dm_list pvs; - - /* - * logical volumes - * The following relationship should always hold: - * dm_list_size(lvs) = user visible lv_count + snapshot_count + other invisible LVs - * - * Snapshots consist of 2 instances of "struct logical_volume": - * - cow (lv_name is visible to the user) - * - snapshot (lv_name is 'snapshotN') - * - * Mirrors consist of multiple instances of "struct logical_volume": - * - one for the mirror log - * - one for each mirror leg - * - one for the user-visible mirror LV - */ - struct dm_list lvs; - - struct dm_list tags; - - /* - * FIXME: Move the next fields into a different struct? - */ - - /* - * List of removed physical volumes by pvreduce. - * They have to get cleared on vg_commit. - */ - struct dm_list removed_pvs; - uint32_t open_mode; /* FIXME: read or write - check lock type? */ - - /* - * Store result of the last vg_read(). - * 0 for success else appropriate FAILURE_* bits set. - */ - uint32_t read_status; - uint32_t mda_copies; /* target number of mdas for this VG */ -}; - /* There will be one area for each stripe */ struct lv_segment_area { area_type_t type; @@ -501,6 +429,7 @@ int is_orphan_vg(const char *vg_name); int is_orphan(const struct physical_volume *pv); int is_missing_pv(const struct physical_volume *pv); +int vg_missing_pv_count(const struct volume_group *vg); int vgs_are_compatible(struct cmd_context *cmd, struct volume_group *vg_from, struct volume_group *vg_to); @@ -552,11 +481,6 @@ struct pvcreate_params *pp); int vg_reduce(struct volume_group *vg, char *pv_name); int vg_change_tag(struct volume_group *vg, const char *tag, int add_tag); -int vg_set_extent_size(struct volume_group *vg, uint32_t new_extent_size); -int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv); -int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv); -int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc); -int vg_set_clustered(struct volume_group *vg, int clustered); int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from, struct volume_group *vg_to); /* FIXME: Investigate refactoring these functions to take a pv ISO pv_list */ @@ -746,10 +670,6 @@ int vg_check_status(const struct volume_group *vg, uint64_t status); -/* - * Returns visible LV count - number of LVs from user perspective - */ -unsigned vg_visible_lvs(const struct volume_group *vg); /* * Check if the VG reached maximal LVs count (if set) @@ -876,21 +796,6 @@ uint64_t lv_size(const struct logical_volume *lv); -int vg_missing_pv_count(const struct volume_group *vg); -uint32_t vg_seqno(const struct volume_group *vg); -uint64_t vg_status(const struct volume_group *vg); -uint64_t vg_size(const struct volume_group *vg); -uint64_t vg_free(const struct volume_group *vg); -uint64_t vg_extent_size(const struct volume_group *vg); -uint64_t vg_extent_count(const struct volume_group *vg); -uint64_t vg_free_count(const struct volume_group *vg); -uint64_t vg_pv_count(const struct volume_group *vg); -uint64_t vg_max_pv(const struct volume_group *vg); -uint64_t vg_max_lv(const struct volume_group *vg); -uint32_t vg_mda_count(const struct volume_group *vg); -uint32_t vg_mda_used_count(const struct volume_group *vg); -uint32_t vg_mda_copies(const struct volume_group *vg); -int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies); int vg_check_write_mode(struct volume_group *vg); #define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED) #define vg_is_exported(vg) (vg_status((vg)) & EXPORTED_VG) --- LVM2/lib/metadata/metadata.c 2010/09/23 12:02:34 1.397 +++ LVM2/lib/metadata/metadata.c 2010/09/30 13:04:56 1.398 @@ -1021,31 +1021,6 @@ return (uint64_t) size / extent_size; } -static int _recalc_extents(uint32_t *extents, const char *desc1, - const char *desc2, uint32_t old_size, - uint32_t new_size) -{ - uint64_t size = (uint64_t) old_size * (*extents); - - if (size % new_size) { - log_error("New size %" PRIu64 " for %s%s not an exact number " - "of new extents.", size, desc1, desc2); - return 0; - } - - size /= new_size; - - if (size > UINT32_MAX) { - log_error("New extent count %" PRIu64 " for %s%s exceeds " - "32 bits.", size, desc1, desc2); - return 0; - } - - *extents = (uint32_t) size; - - return 1; -} - static dm_bitset_t _bitset_with_random_bits(struct dm_pool *mem, uint32_t num_bits, uint32_t num_set_bits, unsigned *seed) { @@ -1220,22 +1195,6 @@ return 1; } -uint32_t vg_mda_copies(const struct volume_group *vg) -{ - return vg->mda_copies; -} - -int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies) -{ - vg->mda_copies = mda_copies; - - /* FIXME Use log_verbose when this is due to specific cmdline request. */ - log_debug("Setting mda_copies to %"PRIu32" for VG %s", - mda_copies, vg->name); - - return 1; -} - uint64_t find_min_mda_size(struct dm_list *mdas) { uint64_t min_mda_size = UINT64_MAX, mda_size; @@ -1255,285 +1214,6 @@ return min_mda_size; } -uint64_t vg_mda_size(const struct volume_group *vg) -{ - return find_min_mda_size(&vg->fid->metadata_areas_in_use); -} - -uint64_t vg_mda_free(const struct volume_group *vg) -{ - uint64_t freespace = UINT64_MAX, mda_free; - struct metadata_area *mda; - - dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) { - if (!mda->ops->mda_free_sectors) - continue; - mda_free = mda->ops->mda_free_sectors(mda); - if (mda_free < freespace) - freespace = mda_free; - } - - if (freespace == UINT64_MAX) - freespace = UINT64_C(0); - return freespace; -} - -int vg_set_extent_size(struct volume_group *vg, uint32_t new_size) -{ - uint32_t old_size = vg->extent_size; - struct pv_list *pvl; - struct lv_list *lvl; - struct physical_volume *pv; - struct logical_volume *lv; - struct lv_segment *seg; - struct pv_segment *pvseg; - uint32_t s; - - if (!vg_is_resizeable(vg)) { - log_error("Volume group \"%s\" must be resizeable " - "to change PE size", vg->name); - return 0; - } - - if (!new_size) { - log_error("Physical extent size may not be zero"); - return 0; - } - - if (new_size == vg->extent_size) - return 1; - - if (new_size & (new_size - 1)) { - log_error("Physical extent size must be a power of 2."); - return 0; - } - - if (new_size > vg->extent_size) { - if ((uint64_t) vg_size(vg) % new_size) { - /* FIXME Adjust used PV sizes instead */ - log_error("New extent size is not a perfect fit"); - return 0; - } - } - - vg->extent_size = new_size; - - if (vg->fid->fmt->ops->vg_setup && - !vg->fid->fmt->ops->vg_setup(vg->fid, vg)) - return_0; - - if (!_recalc_extents(&vg->extent_count, vg->name, "", old_size, - new_size)) - return_0; - - if (!_recalc_extents(&vg->free_count, vg->name, " free space", - old_size, new_size)) - return_0; - - /* foreach PV */ - dm_list_iterate_items(pvl, &vg->pvs) { - pv = pvl->pv; - - pv->pe_size = new_size; - if (!_recalc_extents(&pv->pe_count, pv_dev_name(pv), "", - old_size, new_size)) - return_0; - - if (!_recalc_extents(&pv->pe_alloc_count, pv_dev_name(pv), - " allocated space", old_size, new_size)) - return_0; - - /* foreach free PV Segment */ - dm_list_iterate_items(pvseg, &pv->segments) { - if (pvseg_is_allocated(pvseg)) - continue; - - if (!_recalc_extents(&pvseg->pe, pv_dev_name(pv), - " PV segment start", old_size, - new_size)) - return_0; - if (!_recalc_extents(&pvseg->len, pv_dev_name(pv), - " PV segment length", old_size, - new_size)) - return_0; - } - } - - /* foreach LV */ - dm_list_iterate_items(lvl, &vg->lvs) { - lv = lvl->lv; - - if (!_recalc_extents(&lv->le_count, lv->name, "", old_size, - new_size)) - return_0; - - dm_list_iterate_items(seg, &lv->segments) { - if (!_recalc_extents(&seg->le, lv->name, - " segment start", old_size, - new_size)) - return_0; - - if (!_recalc_extents(&seg->len, lv->name, - " segment length", old_size, - new_size)) - return_0; - - if (!_recalc_extents(&seg->area_len, lv->name, - " area length", old_size, - new_size)) - return_0; - - if (!_recalc_extents(&seg->extents_copied, lv->name, - " extents moved", old_size, - new_size)) - return_0; - - /* foreach area */ - for (s = 0; s < seg->area_count; s++) { - switch (seg_type(seg, s)) { - case AREA_PV: - if (!_recalc_extents - (&seg_pe(seg, s), - lv->name, - " pvseg start", old_size, - new_size)) - return_0; - if (!_recalc_extents - (&seg_pvseg(seg, s)->len, - lv->name, - " pvseg length", old_size, - new_size)) - return_0; - break; - case AREA_LV: - if (!_recalc_extents - (&seg_le(seg, s), lv->name, - " area start", old_size, - new_size)) - return_0; - break; - case AREA_UNASSIGNED: - log_error("Unassigned area %u found in " - "segment", s); - return 0; - } - } - } - - } - - return 1; -} - -int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv) -{ - if (!vg_is_resizeable(vg)) { - log_error("Volume group \"%s\" must be resizeable " - "to change MaxLogicalVolume", vg->name); - return 0; - } - - if (!(vg->fid->fmt->features & FMT_UNLIMITED_VOLS)) { - if (!max_lv) - max_lv = 255; - else if (max_lv > 255) { - log_error("MaxLogicalVolume limit is 255"); - return 0; - } - } - - if (max_lv && max_lv < vg_visible_lvs(vg)) { - log_error("MaxLogicalVolume is less than the current number " - "%d of LVs for %s", vg_visible_lvs(vg), - vg->name); - return 0; - } - vg->max_lv = max_lv; - - return 1; -} - -int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv) -{ - if (!vg_is_resizeable(vg)) { - log_error("Volume group \"%s\" must be resizeable " - "to change MaxPhysicalVolumes", vg->name); - return 0; - } - - if (!(vg->fid->fmt->features & FMT_UNLIMITED_VOLS)) { - if (!max_pv) - max_pv = 255; - else if (max_pv > 255) { - log_error("MaxPhysicalVolume limit is 255"); - return 0; - } - } - - if (max_pv && max_pv < vg->pv_count) { - log_error("MaxPhysicalVolumes is less than the current number " - "%d of PVs for \"%s\"", vg->pv_count, - vg->name); - return 0; - } - vg->max_pv = max_pv; - return 1; -} - -int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc) -{ - if (alloc == ALLOC_INHERIT) { - log_error("Volume Group allocation policy cannot inherit " - "from anything"); - return 0; - } - - if (alloc == vg->alloc) - return 1; - - vg->alloc = alloc; - return 1; -} - -int vg_set_clustered(struct volume_group *vg, int clustered) -{ - struct lv_list *lvl; - - /* - * We do not currently support switching the cluster attribute - * on active mirrors or snapshots. - */ - dm_list_iterate_items(lvl, &vg->lvs) { - if (lv_is_mirrored(lvl->lv) && lv_is_active(lvl->lv)) { - log_error("Mirror logical volumes must be inactive " - "when changing the cluster attribute."); - return 0; - } - - if (clustered) { - if (lv_is_origin(lvl->lv) || lv_is_cow(lvl->lv)) { - log_error("Volume group %s contains snapshots " - "that are not yet supported.", - vg->name); - return 0; - } - } - - if ((lv_is_origin(lvl->lv) || lv_is_cow(lvl->lv)) && - lv_is_active(lvl->lv)) { - log_error("Snapshot logical volumes must be inactive " - "when changing the cluster attribute."); - return 0; - } - } - - if (clustered) - vg->status |= CLUSTERED; - else - vg->status &= ~CLUSTERED; - return 1; -} - static int _move_mdas(struct volume_group *vg_from, struct volume_group *vg_to, struct dm_list *mdas_from, struct dm_list *mdas_to) { @@ -2168,31 +1848,6 @@ return 1; } -unsigned snapshot_count(const struct volume_group *vg) -{ - struct lv_list *lvl; - unsigned num_snapshots = 0; - - dm_list_iterate_items(lvl, &vg->lvs) - if (lv_is_cow(lvl->lv)) - num_snapshots++; - - return num_snapshots; -} - -unsigned vg_visible_lvs(const struct volume_group *vg) -{ - struct lv_list *lvl; - unsigned lv_count = 0; - - dm_list_iterate_items(lvl, &vg->lvs) { - if (lv_is_visible(lvl->lv)) - lv_count++; - } - - return lv_count; -} - /* * Determine whether two vgs are compatible for merging. */ @@ -4472,79 +4127,6 @@ return 1; } -uint32_t vg_seqno(const struct volume_group *vg) -{ - return vg->seqno; -} - -uint64_t vg_status(const struct volume_group *vg) -{ - return vg->status; -} - -uint64_t vg_size(const struct volume_group *vg) -{ - return (uint64_t) vg->extent_count * vg->extent_size; -} - -uint64_t vg_free(const struct volume_group *vg) -{ - return (uint64_t) vg->free_count * vg->extent_size; -} - -uint64_t vg_extent_size(const struct volume_group *vg) -{ - return (uint64_t) vg->extent_size; -} - -uint64_t vg_extent_count(const struct volume_group *vg) -{ - return (uint64_t) vg->extent_count; -} - -uint64_t vg_free_count(const struct volume_group *vg) -{ - return (uint64_t) vg->free_count; -} - -uint64_t vg_pv_count(const struct volume_group *vg) -{ - return (uint64_t) vg->pv_count; -} - -uint64_t vg_max_pv(const struct volume_group *vg) -{ - return (uint64_t) vg->max_pv; -} - -uint64_t vg_max_lv(const struct volume_group *vg) -{ - return (uint64_t) vg->max_lv; -} - -uint32_t vg_mda_count(const struct volume_group *vg) -{ - return dm_list_size(&vg->fid->metadata_areas_in_use) + - dm_list_size(&vg->fid->metadata_areas_ignored); -} - -uint32_t vg_mda_used_count(const struct volume_group *vg) -{ - uint32_t used_count = 0; - struct metadata_area *mda; - - /* - * Ignored mdas could be on either list - the reason being the state - * may have changed from ignored to un-ignored and we need to write - * the state to disk. - */ - dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) - if (!mda_is_ignored(mda)) - used_count++; - - return used_count; -} - uint64_t lv_size(const struct logical_volume *lv) { return lv->size; --- LVM2/lib/metadata/metadata.h 2010/08/26 12:08:19 1.218 +++ LVM2/lib/metadata/metadata.h 2010/09/30 13:04:56 1.219 @@ -378,11 +378,6 @@ struct lv_segment *get_only_segment_using_this_lv(struct logical_volume *lv); /* - * Count snapshot LVs. - */ -unsigned snapshot_count(const struct volume_group *vg); - -/* * Calculate readahead from underlying PV devices */ void lv_calculate_readahead(const struct logical_volume *lv, uint32_t *read_ahead); @@ -417,7 +412,5 @@ int is_mirror_image_removable(struct logical_volume *mimage_lv, void *baton); uint64_t find_min_mda_size(struct dm_list *mdas); -uint64_t vg_mda_size(const struct volume_group *vg); -uint64_t vg_mda_free(const struct volume_group *vg); #endif From wysochanski@sourceware.org Thu Sep 30 13:05:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 13:05:00 -0000 Subject: LVM2 include/.symlinks.in lib/Makefile.in lib/ ... Message-ID: <20100930130521.19959.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 13:05:20 Modified files: include : .symlinks.in lib : Makefile.in lib/metadata : metadata-exported.h metadata.c Log message: Refactor metadata.[ch] into pv.[ch] for pv functions. The metadata.[ch] files are very large. This patch makes a first attempt at separating out pv functions and data, particularly related to the reporting fields calculations. More code could be moved here but for now I'm stopping at reporting functions 'get' / 'set' functions. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/include/.symlinks.in.diff?cvsroot=lvm2&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/Makefile.in.diff?cvsroot=lvm2&r1=1.106&r2=1.107 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.166&r2=1.167 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.398&r2=1.399 --- LVM2/include/.symlinks.in 2010/09/30 13:04:55 1.4 +++ LVM2/include/.symlinks.in 2010/09/30 13:05:20 1.5 @@ -33,6 +33,7 @@ @top_srcdir@/lib/metadata/lv_alloc.h @top_srcdir@/lib/metadata/metadata.h @top_srcdir@/lib/metadata/metadata-exported.h +@top_srcdir@/lib/metadata/pv.h @top_srcdir@/lib/metadata/pv_alloc.h @top_srcdir@/lib/metadata/segtype.h @top_srcdir@/lib/metadata/vg.h --- LVM2/lib/Makefile.in 2010/09/30 13:04:55 1.106 +++ LVM2/lib/Makefile.in 2010/09/30 13:05:20 1.107 @@ -77,6 +77,7 @@ metadata/merge.c \ metadata/metadata.c \ metadata/mirror.c \ + metadata/pv.c \ metadata/pv_manip.c \ metadata/pv_map.c \ metadata/replicator_manip.c \ --- LVM2/lib/metadata/metadata-exported.h 2010/09/30 13:04:56 1.166 +++ LVM2/lib/metadata/metadata-exported.h 2010/09/30 13:05:20 1.167 @@ -22,6 +22,7 @@ #define _LVM_METADATA_EXPORTED_H #include "uuid.h" +#include "pv.h" #include "vg.h" #define MAX_STRIPES 128U @@ -175,39 +176,6 @@ #define pvseg_is_allocated(pvseg) ((pvseg)->lvseg) -struct physical_volume { - struct id id; - struct device *dev; - const struct format_type *fmt; - - /* - * vg_name and vgid are used before the parent VG struct exists. - * FIXME: Investigate removal/substitution with 'vg' fields. - */ - const char *vg_name; - struct id vgid; - - /* - * 'vg' is set and maintained when the PV belongs to a 'pvs' - * list in a parent VG struct. - */ - struct volume_group *vg; - - uint64_t status; - uint64_t size; - - /* physical extents */ - uint32_t pe_size; - uint64_t pe_start; - uint32_t pe_count; - uint32_t pe_alloc_count; - unsigned long pe_align; - unsigned long pe_align_offset; - - struct dm_list segments; /* Ordered pv_segments covering complete PV */ - struct dm_list tags; -}; - struct format_instance { const struct format_type *fmt; /* @@ -419,7 +387,6 @@ int pv_write(struct cmd_context *cmd, struct physical_volume *pv, struct dm_list *mdas, int64_t label_sector); -int is_pv(struct physical_volume *pv); int move_pv(struct volume_group *vg_from, struct volume_group *vg_to, const char *pv_name); int move_pvs_used_by_lv(struct volume_group *vg_from, @@ -427,8 +394,6 @@ const char *lv_name); int is_global_vg(const char *vg_name); int is_orphan_vg(const char *vg_name); -int is_orphan(const struct physical_volume *pv); -int is_missing_pv(const struct physical_volume *pv); int vg_missing_pv_count(const struct volume_group *vg); int vgs_are_compatible(struct cmd_context *cmd, struct volume_group *vg_from, @@ -777,21 +742,6 @@ /* * Begin skeleton for external LVM library */ -struct device *pv_dev(const struct physical_volume *pv); -const char *pv_vg_name(const struct physical_volume *pv); -const char *pv_dev_name(const struct physical_volume *pv); -uint64_t pv_size(const struct physical_volume *pv); -uint64_t pv_size_field(const struct physical_volume *pv); -uint64_t pv_dev_size(const struct physical_volume *pv); -uint64_t pv_free(const struct physical_volume *pv); -uint64_t pv_status(const struct physical_volume *pv); -uint32_t pv_pe_size(const struct physical_volume *pv); -uint64_t pv_pe_start(const struct physical_volume *pv); -uint32_t pv_pe_count(const struct physical_volume *pv); -uint32_t pv_pe_alloc_count(const struct physical_volume *pv); -uint32_t pv_mda_count(const struct physical_volume *pv); -uint32_t pv_mda_used_count(const struct physical_volume *pv); -unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored); int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignore); uint64_t lv_size(const struct logical_volume *lv); --- LVM2/lib/metadata/metadata.c 2010/09/30 13:04:56 1.398 +++ LVM2/lib/metadata/metadata.c 2010/09/30 13:05:20 1.399 @@ -34,12 +34,6 @@ #include #include -/* - * FIXME: Check for valid handle before dereferencing field or log error? - */ -#define pv_field(handle, field) \ - (((const struct physical_volume *)(handle))->field) - static struct physical_volume *_pv_read(struct cmd_context *cmd, struct dm_pool *pvmem, const char *pv_name, @@ -3425,29 +3419,6 @@ return (vg_name && !strncmp(vg_name, ORPHAN_PREFIX, sizeof(ORPHAN_PREFIX) - 1)) ? 1 : 0; } -/** - * is_orphan - Determine whether a pv is an orphan based on its vg_name - * @pv: handle to the physical volume - */ -int is_orphan(const struct physical_volume *pv) -{ - return is_orphan_vg(pv_field(pv, vg_name)); -} - -/** - * is_pv - Determine whether a pv is a real pv or dummy one - * @pv: handle to device - */ -int is_pv(struct physical_volume *pv) -{ - return (pv_field(pv, vg_name) ? 1 : 0); -} - -int is_missing_pv(const struct physical_volume *pv) -{ - return pv_field(pv, status) & MISSING_PV ? 1 : 0; -} - /* * Returns: * 0 - fail @@ -3791,101 +3762,6 @@ return FAILED_EXIST; } -/* - * Gets/Sets for external LVM library - */ -struct id pv_id(const struct physical_volume *pv) -{ - return pv_field(pv, id); -} - -const struct format_type *pv_format_type(const struct physical_volume *pv) -{ - return pv_field(pv, fmt); -} - -struct id pv_vgid(const struct physical_volume *pv) -{ - return pv_field(pv, vgid); -} - -struct device *pv_dev(const struct physical_volume *pv) -{ - return pv_field(pv, dev); -} - -const char *pv_vg_name(const struct physical_volume *pv) -{ - return pv_field(pv, vg_name); -} - -const char *pv_dev_name(const struct physical_volume *pv) -{ - return dev_name(pv_dev(pv)); -} - -uint64_t pv_size(const struct physical_volume *pv) -{ - return pv_field(pv, size); -} - -uint64_t pv_dev_size(const struct physical_volume *pv) -{ - uint64_t size; - - if (!dev_get_size(pv->dev, &size)) - size = 0; - return size; -} - -uint64_t pv_size_field(const struct physical_volume *pv) -{ - uint64_t size; - - if (!pv->pe_count) - size = pv->size; - else - size = (uint64_t) pv->pe_count * pv->pe_size; - return size; -} - -uint64_t pv_free(const struct physical_volume *pv) -{ - uint64_t freespace; - - if (!pv->pe_count) - freespace = pv->size; - else - freespace = (uint64_t) - (pv->pe_count - pv->pe_alloc_count) * pv->pe_size; - return freespace; -} - -uint64_t pv_status(const struct physical_volume *pv) -{ - return pv_field(pv, status); -} - -uint32_t pv_pe_size(const struct physical_volume *pv) -{ - return pv_field(pv, pe_size); -} - -uint64_t pv_pe_start(const struct physical_volume *pv) -{ - return pv_field(pv, pe_start); -} - -uint32_t pv_pe_count(const struct physical_volume *pv) -{ - return pv_field(pv, pe_count); -} - -uint32_t pv_pe_alloc_count(const struct physical_volume *pv) -{ - return pv_field(pv, pe_alloc_count); -} - void fid_add_mda(struct format_instance *fid, struct metadata_area *mda) { dm_list_add(mda_is_ignored(mda) ? &fid->metadata_areas_ignored : @@ -3984,88 +3860,6 @@ mda->ops->mda_metadata_locn_offset ? mda->ops->mda_metadata_locn_offset(locn) : UINT64_C(0)); } -uint32_t pv_mda_count(const struct physical_volume *pv) -{ - struct lvmcache_info *info; - - info = info_from_pvid((const char *)&pv->id.uuid, 0); - return info ? dm_list_size(&info->mdas) : UINT64_C(0); -} - -uint32_t pv_mda_used_count(const struct physical_volume *pv) -{ - struct lvmcache_info *info; - struct metadata_area *mda; - uint32_t used_count=0; - - info = info_from_pvid((const char *)&pv->id.uuid, 0); - if (!info) - return 0; - dm_list_iterate_items(mda, &info->mdas) { - if (!mda_is_ignored(mda)) - used_count++; - } - return used_count; -} - -unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored) -{ - struct lvmcache_info *info; - struct metadata_area *mda, *vg_mda, *tmda; - struct dm_list *vg_mdas_in_use, *vg_mdas_ignored; - - if (!(info = info_from_pvid((const char *)&pv->id.uuid, 0))) - return_0; - - if (is_orphan(pv)) { - dm_list_iterate_items(mda, &info->mdas) - mda_set_ignored(mda, mda_ignored); - return 1; - } - - /* - * Do not allow disabling of the the last PV in a VG. - */ - if (pv_mda_used_count(pv) == vg_mda_used_count(pv->vg)) { - log_error("Cannot disable all metadata areas in volume group %s.", - pv->vg->name); - return 0; - } - - /* - * Non-orphan case is more complex. - * If the PV's mdas are ignored, and we wish to un-ignore, - * we clear the bit and move them from the ignored mda list to the - * in_use list, ensuring the new state will get written to disk - * in the vg_write() path. - * If the PV's mdas are not ignored, and we are setting - * them to ignored, we set the bit but leave them on the in_use - * list, ensuring the new state will get written to disk in the - * vg_write() path. - */ - vg_mdas_in_use = &pv->vg->fid->metadata_areas_in_use; - vg_mdas_ignored = &pv->vg->fid->metadata_areas_ignored; - - dm_list_iterate_items(mda, &info->mdas) { - if (mda_is_ignored(mda) && !mda_ignored) - /* Changing an ignored mda to one in_use requires moving it */ - dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_ignored) - if (mda_locns_match(mda, vg_mda)) { - mda_set_ignored(vg_mda, mda_ignored); - dm_list_move(vg_mdas_in_use, &vg_mda->list); - } - - dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_in_use) - if (mda_locns_match(mda, vg_mda)) - /* Don't move mda: needs writing to disk. */ - mda_set_ignored(vg_mda, mda_ignored); - - mda_set_ignored(mda, mda_ignored); - } - - return 1; -} - int mdas_empty_or_ignored(struct dm_list *mdas) { struct metadata_area *mda; From wysochanski@sourceware.org Thu Sep 30 13:05:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 13:05:00 -0000 Subject: LVM2 include/.symlinks.in lib/Makefile.in lib/ ... Message-ID: <20100930130546.20183.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 13:05:45 Modified files: include : .symlinks.in lib : Makefile.in lib/metadata : metadata-exported.h metadata.c Log message: Refactor metadata.[ch] into lv.[ch] for lv functions. This patch is similar to the other patches for pv and vg functionality, and separates lv functionality into separate files, concentrating on reporting fields and simple functions. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/include/.symlinks.in.diff?cvsroot=lvm2&r1=1.5&r2=1.6 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/Makefile.in.diff?cvsroot=lvm2&r1=1.107&r2=1.108 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata-exported.h.diff?cvsroot=lvm2&r1=1.167&r2=1.168 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.399&r2=1.400 --- LVM2/include/.symlinks.in 2010/09/30 13:05:20 1.5 +++ LVM2/include/.symlinks.in 2010/09/30 13:05:45 1.6 @@ -30,6 +30,7 @@ @top_srcdir@/lib/locking/locking.h @top_srcdir@/lib/log/log.h @top_srcdir@/lib/log/lvm-logging.h +@top_srcdir@/lib/metadata/lv.h @top_srcdir@/lib/metadata/lv_alloc.h @top_srcdir@/lib/metadata/metadata.h @top_srcdir@/lib/metadata/metadata-exported.h --- LVM2/lib/Makefile.in 2010/09/30 13:05:20 1.107 +++ LVM2/lib/Makefile.in 2010/09/30 13:05:45 1.108 @@ -73,6 +73,7 @@ locking/locking.c \ locking/no_locking.c \ log/log.c \ + metadata/lv.c \ metadata/lv_manip.c \ metadata/merge.c \ metadata/metadata.c \ --- LVM2/lib/metadata/metadata-exported.h 2010/09/30 13:05:20 1.167 +++ LVM2/lib/metadata/metadata-exported.h 2010/09/30 13:05:45 1.168 @@ -24,6 +24,7 @@ #include "uuid.h" #include "pv.h" #include "vg.h" +#include "lv.h" #define MAX_STRIPES 128U #define SECTOR_SHIFT 9L @@ -291,33 +292,6 @@ #define seg_pv(seg, s) (seg)->areas[(s)].u.pv.pvseg->pv #define seg_lv(seg, s) (seg)->areas[(s)].u.lv.lv -struct logical_volume { - union lvid lvid; - char *name; - - struct volume_group *vg; - - uint64_t status; - alloc_policy_t alloc; - uint32_t read_ahead; - int32_t major; - int32_t minor; - - uint64_t size; /* Sectors */ - uint32_t le_count; - - uint32_t origin_count; - struct dm_list snapshot_segs; - struct lv_segment *snapshot; - - struct replicator_device *rdevice;/* For replicator-devs, rimages, slogs - reference to rdevice */ - struct dm_list rsites; /* For replicators - all sites */ - - struct dm_list segments; - struct dm_list tags; - struct dm_list segs_using_this_lv; -}; - struct pe_range { struct dm_list list; uint32_t start; /* PEs */ @@ -744,7 +718,6 @@ */ int pv_change_metadataignore(struct physical_volume *pv, uint32_t mda_ignore); -uint64_t lv_size(const struct logical_volume *lv); int vg_check_write_mode(struct volume_group *vg); #define vg_is_clustered(vg) (vg_status((vg)) & CLUSTERED) --- LVM2/lib/metadata/metadata.c 2010/09/30 13:05:20 1.399 +++ LVM2/lib/metadata/metadata.c 2010/09/30 13:05:45 1.400 @@ -3921,11 +3921,6 @@ return 1; } -uint64_t lv_size(const struct logical_volume *lv) -{ - return lv->size; -} - /** * pv_by_path - Given a device path return a PV handle if it is a PV * @cmd - handle to the LVM command instance From wysochanski@sourceware.org Thu Sep 30 13:15:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 13:15:00 -0000 Subject: LVM2/lib/metadata pv.c pv.h Message-ID: <20100930131544.1058.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 13:15:42 Added files: lib/metadata : pv.c pv.h Log message: Add lib/metadata/pv.[ch] new files. Apparently git cvsexportcommit does not properly add new files from a git commit. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.c.diff?cvsroot=lvm2&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.h.diff?cvsroot=lvm2&r1=NONE&r2=1.1 /cvs/lvm2/LVM2/lib/metadata/pv.c,v --> standard output revision 1.1 --- LVM2/lib/metadata/pv.c +++ - 2010-09-30 13:15:43.764416000 +0000 @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "lib.h" +#include "metadata.h" +#include "lvmcache.h" + +/* + * FIXME: Check for valid handle before dereferencing field or log error? + */ +#define pv_field(handle, field) ((handle)->field) + +/* + * Gets/Sets for external LVM library + */ +struct id pv_id(const struct physical_volume *pv) +{ + return pv_field(pv, id); +} + +const struct format_type *pv_format_type(const struct physical_volume *pv) +{ + return pv_field(pv, fmt); +} + +struct id pv_vgid(const struct physical_volume *pv) +{ + return pv_field(pv, vgid); +} + +struct device *pv_dev(const struct physical_volume *pv) +{ + return pv_field(pv, dev); +} + +const char *pv_vg_name(const struct physical_volume *pv) +{ + return pv_field(pv, vg_name); +} + +const char *pv_dev_name(const struct physical_volume *pv) +{ + return dev_name(pv_dev(pv)); +} + +uint64_t pv_size(const struct physical_volume *pv) +{ + return pv_field(pv, size); +} + +uint64_t pv_dev_size(const struct physical_volume *pv) +{ + uint64_t size; + + if (!dev_get_size(pv->dev, &size)) + size = 0; + return size; +} + +uint64_t pv_size_field(const struct physical_volume *pv) +{ + uint64_t size; + + if (!pv->pe_count) + size = pv->size; + else + size = (uint64_t) pv->pe_count * pv->pe_size; + return size; +} + +uint64_t pv_free(const struct physical_volume *pv) +{ + uint64_t freespace; + + if (!pv->pe_count) + freespace = pv->size; + else + freespace = (uint64_t) + (pv->pe_count - pv->pe_alloc_count) * pv->pe_size; + return freespace; +} + +uint64_t pv_status(const struct physical_volume *pv) +{ + return pv_field(pv, status); +} + +uint32_t pv_pe_size(const struct physical_volume *pv) +{ + return pv_field(pv, pe_size); +} + +uint64_t pv_pe_start(const struct physical_volume *pv) +{ + return pv_field(pv, pe_start); +} + +uint32_t pv_pe_count(const struct physical_volume *pv) +{ + return pv_field(pv, pe_count); +} + +uint32_t pv_pe_alloc_count(const struct physical_volume *pv) +{ + return pv_field(pv, pe_alloc_count); +} + +uint32_t pv_mda_count(const struct physical_volume *pv) +{ + struct lvmcache_info *info; + + info = info_from_pvid((const char *)&pv->id.uuid, 0); + return info ? dm_list_size(&info->mdas) : UINT64_C(0); +} + +uint32_t pv_mda_used_count(const struct physical_volume *pv) +{ + struct lvmcache_info *info; + struct metadata_area *mda; + uint32_t used_count=0; + + info = info_from_pvid((const char *)&pv->id.uuid, 0); + if (!info) + return 0; + dm_list_iterate_items(mda, &info->mdas) { + if (!mda_is_ignored(mda)) + used_count++; + } + return used_count; +} + +/** + * is_orphan - Determine whether a pv is an orphan based on its vg_name + * @pv: handle to the physical volume + */ +int is_orphan(const struct physical_volume *pv) +{ + return is_orphan_vg(pv_field(pv, vg_name)); +} + +/** + * is_pv - Determine whether a pv is a real pv or dummy one + * @pv: handle to device + */ +int is_pv(const struct physical_volume *pv) +{ + return (pv_field(pv, vg_name) ? 1 : 0); +} + +int is_missing_pv(const struct physical_volume *pv) +{ + return pv_field(pv, status) & MISSING_PV ? 1 : 0; +} + +unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored) +{ + struct lvmcache_info *info; + struct metadata_area *mda, *vg_mda, *tmda; + struct dm_list *vg_mdas_in_use, *vg_mdas_ignored; + + if (!(info = info_from_pvid((const char *)&pv->id.uuid, 0))) + return_0; + + if (is_orphan(pv)) { + dm_list_iterate_items(mda, &info->mdas) + mda_set_ignored(mda, mda_ignored); + return 1; + } + + /* + * Do not allow disabling of the the last PV in a VG. + */ + if (pv_mda_used_count(pv) == vg_mda_used_count(pv->vg)) { + log_error("Cannot disable all metadata areas in volume group %s.", + pv->vg->name); + return 0; + } + + /* + * Non-orphan case is more complex. + * If the PV's mdas are ignored, and we wish to un-ignore, + * we clear the bit and move them from the ignored mda list to the + * in_use list, ensuring the new state will get written to disk + * in the vg_write() path. + * If the PV's mdas are not ignored, and we are setting + * them to ignored, we set the bit but leave them on the in_use + * list, ensuring the new state will get written to disk in the + * vg_write() path. + */ + vg_mdas_in_use = &pv->vg->fid->metadata_areas_in_use; + vg_mdas_ignored = &pv->vg->fid->metadata_areas_ignored; + + dm_list_iterate_items(mda, &info->mdas) { + if (mda_is_ignored(mda) && !mda_ignored) + /* Changing an ignored mda to one in_use requires moving it */ + dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_ignored) + if (mda_locns_match(mda, vg_mda)) { + mda_set_ignored(vg_mda, mda_ignored); + dm_list_move(vg_mdas_in_use, &vg_mda->list); + } + + dm_list_iterate_items_safe(vg_mda, tmda, vg_mdas_in_use) + if (mda_locns_match(mda, vg_mda)) + /* Don't move mda: needs writing to disk. */ + mda_set_ignored(vg_mda, mda_ignored); + + mda_set_ignored(mda, mda_ignored); + } + + return 1; +} + /cvs/lvm2/LVM2/lib/metadata/pv.h,v --> standard output revision 1.1 --- LVM2/lib/metadata/pv.h +++ - 2010-09-30 13:15:44.115676000 +0000 @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _PV_H +#define _PV_H + +struct id; +struct device; +struct format_type; +struct volume_group; + +struct physical_volume { + struct id id; + struct device *dev; + const struct format_type *fmt; + + /* + * vg_name and vgid are used before the parent VG struct exists. + * FIXME: Investigate removal/substitution with 'vg' fields. + */ + const char *vg_name; + struct id vgid; + + /* + * 'vg' is set and maintained when the PV belongs to a 'pvs' + * list in a parent VG struct. + */ + struct volume_group *vg; + + uint64_t status; + uint64_t size; + + /* physical extents */ + uint32_t pe_size; + uint64_t pe_start; + uint32_t pe_count; + uint32_t pe_alloc_count; + unsigned long pe_align; + unsigned long pe_align_offset; + + struct dm_list segments; /* Ordered pv_segments covering complete PV */ + struct dm_list tags; +}; + +struct device *pv_dev(const struct physical_volume *pv); +const char *pv_vg_name(const struct physical_volume *pv); +const char *pv_dev_name(const struct physical_volume *pv); +uint64_t pv_size(const struct physical_volume *pv); +uint64_t pv_size_field(const struct physical_volume *pv); +uint64_t pv_dev_size(const struct physical_volume *pv); +uint64_t pv_free(const struct physical_volume *pv); +uint64_t pv_status(const struct physical_volume *pv); +uint32_t pv_pe_size(const struct physical_volume *pv); +uint64_t pv_pe_start(const struct physical_volume *pv); +uint32_t pv_pe_count(const struct physical_volume *pv); +uint32_t pv_pe_alloc_count(const struct physical_volume *pv); +uint32_t pv_mda_count(const struct physical_volume *pv); +uint32_t pv_mda_used_count(const struct physical_volume *pv); +unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored); +int is_orphan(const struct physical_volume *pv); +int is_missing_pv(const struct physical_volume *pv); +int is_pv(const struct physical_volume *pv); + +#endif From wysochanski@sourceware.org Thu Sep 30 13:16:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 13:16:00 -0000 Subject: LVM2/lib/metadata vg.c vg.h lv.c lv.h Message-ID: <20100930131657.1793.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 13:16:55 Added files: lib/metadata : vg.c vg.h lv.c lv.h Log message: Add lib/metadata/vg.[ch] and lib/metadata/lv.[ch]. These got missed when git cvsexportcommit was used. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.c.diff?cvsroot=lvm2&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.h.diff?cvsroot=lvm2&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.c.diff?cvsroot=lvm2&r1=NONE&r2=1.1 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.h.diff?cvsroot=lvm2&r1=NONE&r2=1.1 /cvs/lvm2/LVM2/lib/metadata/vg.c,v --> standard output revision 1.1 --- LVM2/lib/metadata/vg.c +++ - 2010-09-30 13:16:56.215268000 +0000 @@ -0,0 +1,436 @@ +/* + * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "lib.h" +#include "metadata.h" +#include "activate.h" + +uint32_t vg_seqno(const struct volume_group *vg) +{ + return vg->seqno; +} + +uint64_t vg_status(const struct volume_group *vg) +{ + return vg->status; +} + +uint64_t vg_size(const struct volume_group *vg) +{ + return (uint64_t) vg->extent_count * vg->extent_size; +} + +uint64_t vg_free(const struct volume_group *vg) +{ + return (uint64_t) vg->free_count * vg->extent_size; +} + +uint64_t vg_extent_size(const struct volume_group *vg) +{ + return (uint64_t) vg->extent_size; +} + +uint64_t vg_extent_count(const struct volume_group *vg) +{ + return (uint64_t) vg->extent_count; +} + +uint64_t vg_free_count(const struct volume_group *vg) +{ + return (uint64_t) vg->free_count; +} + +uint64_t vg_pv_count(const struct volume_group *vg) +{ + return (uint64_t) vg->pv_count; +} + +uint64_t vg_max_pv(const struct volume_group *vg) +{ + return (uint64_t) vg->max_pv; +} + +uint64_t vg_max_lv(const struct volume_group *vg) +{ + return (uint64_t) vg->max_lv; +} + +unsigned snapshot_count(const struct volume_group *vg) +{ + struct lv_list *lvl; + unsigned num_snapshots = 0; + + dm_list_iterate_items(lvl, &vg->lvs) + if (lv_is_cow(lvl->lv)) + num_snapshots++; + + return num_snapshots; +} + +unsigned vg_visible_lvs(const struct volume_group *vg) +{ + struct lv_list *lvl; + unsigned lv_count = 0; + + dm_list_iterate_items(lvl, &vg->lvs) { + if (lv_is_visible(lvl->lv)) + lv_count++; + } + + return lv_count; +} + +uint32_t vg_mda_count(const struct volume_group *vg) +{ + return dm_list_size(&vg->fid->metadata_areas_in_use) + + dm_list_size(&vg->fid->metadata_areas_ignored); +} + +uint32_t vg_mda_used_count(const struct volume_group *vg) +{ + uint32_t used_count = 0; + struct metadata_area *mda; + + /* + * Ignored mdas could be on either list - the reason being the state + * may have changed from ignored to un-ignored and we need to write + * the state to disk. + */ + dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) + if (!mda_is_ignored(mda)) + used_count++; + + return used_count; +} + +uint32_t vg_mda_copies(const struct volume_group *vg) +{ + return vg->mda_copies; +} + +uint64_t vg_mda_size(const struct volume_group *vg) +{ + return find_min_mda_size(&vg->fid->metadata_areas_in_use); +} + +uint64_t vg_mda_free(const struct volume_group *vg) +{ + uint64_t freespace = UINT64_MAX, mda_free; + struct metadata_area *mda; + + dm_list_iterate_items(mda, &vg->fid->metadata_areas_in_use) { + if (!mda->ops->mda_free_sectors) + continue; + mda_free = mda->ops->mda_free_sectors(mda); + if (mda_free < freespace) + freespace = mda_free; + } + + if (freespace == UINT64_MAX) + freespace = UINT64_C(0); + return freespace; +} + +int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies) +{ + vg->mda_copies = mda_copies; + + /* FIXME Use log_verbose when this is due to specific cmdline request. */ + log_debug("Setting mda_copies to %"PRIu32" for VG %s", + mda_copies, vg->name); + + return 1; +} + +static int _recalc_extents(uint32_t *extents, const char *desc1, + const char *desc2, uint32_t old_size, + uint32_t new_size) +{ + uint64_t size = (uint64_t) old_size * (*extents); + + if (size % new_size) { + log_error("New size %" PRIu64 " for %s%s not an exact number " + "of new extents.", size, desc1, desc2); + return 0; + } + + size /= new_size; + + if (size > UINT32_MAX) { + log_error("New extent count %" PRIu64 " for %s%s exceeds " + "32 bits.", size, desc1, desc2); + return 0; + } + + *extents = (uint32_t) size; + + return 1; +} + +int vg_set_extent_size(struct volume_group *vg, uint32_t new_size) +{ + uint32_t old_size = vg->extent_size; + struct pv_list *pvl; + struct lv_list *lvl; + struct physical_volume *pv; + struct logical_volume *lv; + struct lv_segment *seg; + struct pv_segment *pvseg; + uint32_t s; + + if (!vg_is_resizeable(vg)) { + log_error("Volume group \"%s\" must be resizeable " + "to change PE size", vg->name); + return 0; + } + + if (!new_size) { + log_error("Physical extent size may not be zero"); + return 0; + } + + if (new_size == vg->extent_size) + return 1; + + if (new_size & (new_size - 1)) { + log_error("Physical extent size must be a power of 2."); + return 0; + } + + if (new_size > vg->extent_size) { + if ((uint64_t) vg_size(vg) % new_size) { + /* FIXME Adjust used PV sizes instead */ + log_error("New extent size is not a perfect fit"); + return 0; + } + } + + vg->extent_size = new_size; + + if (vg->fid->fmt->ops->vg_setup && + !vg->fid->fmt->ops->vg_setup(vg->fid, vg)) + return_0; + + if (!_recalc_extents(&vg->extent_count, vg->name, "", old_size, + new_size)) + return_0; + + if (!_recalc_extents(&vg->free_count, vg->name, " free space", + old_size, new_size)) + return_0; + + /* foreach PV */ + dm_list_iterate_items(pvl, &vg->pvs) { + pv = pvl->pv; + + pv->pe_size = new_size; + if (!_recalc_extents(&pv->pe_count, pv_dev_name(pv), "", + old_size, new_size)) + return_0; + + if (!_recalc_extents(&pv->pe_alloc_count, pv_dev_name(pv), + " allocated space", old_size, new_size)) + return_0; + + /* foreach free PV Segment */ + dm_list_iterate_items(pvseg, &pv->segments) { + if (pvseg_is_allocated(pvseg)) + continue; + + if (!_recalc_extents(&pvseg->pe, pv_dev_name(pv), + " PV segment start", old_size, + new_size)) + return_0; + if (!_recalc_extents(&pvseg->len, pv_dev_name(pv), + " PV segment length", old_size, + new_size)) + return_0; + } + } + + /* foreach LV */ + dm_list_iterate_items(lvl, &vg->lvs) { + lv = lvl->lv; + + if (!_recalc_extents(&lv->le_count, lv->name, "", old_size, + new_size)) + return_0; + + dm_list_iterate_items(seg, &lv->segments) { + if (!_recalc_extents(&seg->le, lv->name, + " segment start", old_size, + new_size)) + return_0; + + if (!_recalc_extents(&seg->len, lv->name, + " segment length", old_size, + new_size)) + return_0; + + if (!_recalc_extents(&seg->area_len, lv->name, + " area length", old_size, + new_size)) + return_0; + + if (!_recalc_extents(&seg->extents_copied, lv->name, + " extents moved", old_size, + new_size)) + return_0; + + /* foreach area */ + for (s = 0; s < seg->area_count; s++) { + switch (seg_type(seg, s)) { + case AREA_PV: + if (!_recalc_extents + (&seg_pe(seg, s), + lv->name, + " pvseg start", old_size, + new_size)) + return_0; + if (!_recalc_extents + (&seg_pvseg(seg, s)->len, + lv->name, + " pvseg length", old_size, + new_size)) + return_0; + break; + case AREA_LV: + if (!_recalc_extents + (&seg_le(seg, s), lv->name, + " area start", old_size, + new_size)) + return_0; + break; + case AREA_UNASSIGNED: + log_error("Unassigned area %u found in " + "segment", s); + return 0; + } + } + } + + } + + return 1; +} + +int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv) +{ + if (!vg_is_resizeable(vg)) { + log_error("Volume group \"%s\" must be resizeable " + "to change MaxLogicalVolume", vg->name); + return 0; + } + + if (!(vg->fid->fmt->features & FMT_UNLIMITED_VOLS)) { + if (!max_lv) + max_lv = 255; + else if (max_lv > 255) { + log_error("MaxLogicalVolume limit is 255"); + return 0; + } + } + + if (max_lv && max_lv < vg_visible_lvs(vg)) { + log_error("MaxLogicalVolume is less than the current number " + "%d of LVs for %s", vg_visible_lvs(vg), + vg->name); + return 0; + } + vg->max_lv = max_lv; + + return 1; +} + +int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv) +{ + if (!vg_is_resizeable(vg)) { + log_error("Volume group \"%s\" must be resizeable " + "to change MaxPhysicalVolumes", vg->name); + return 0; + } + + if (!(vg->fid->fmt->features & FMT_UNLIMITED_VOLS)) { + if (!max_pv) + max_pv = 255; + else if (max_pv > 255) { + log_error("MaxPhysicalVolume limit is 255"); + return 0; + } + } + + if (max_pv && max_pv < vg->pv_count) { + log_error("MaxPhysicalVolumes is less than the current number " + "%d of PVs for \"%s\"", vg->pv_count, + vg->name); + return 0; + } + vg->max_pv = max_pv; + return 1; +} + +int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc) +{ + if (alloc == ALLOC_INHERIT) { + log_error("Volume Group allocation policy cannot inherit " + "from anything"); + return 0; + } + + if (alloc == vg->alloc) + return 1; + + vg->alloc = alloc; + return 1; +} + +int vg_set_clustered(struct volume_group *vg, int clustered) +{ + struct lv_list *lvl; + + /* + * We do not currently support switching the cluster attribute + * on active mirrors or snapshots. + */ + dm_list_iterate_items(lvl, &vg->lvs) { + if (lv_is_mirrored(lvl->lv) && lv_is_active(lvl->lv)) { + log_error("Mirror logical volumes must be inactive " + "when changing the cluster attribute."); + return 0; + } + + if (clustered) { + if (lv_is_origin(lvl->lv) || lv_is_cow(lvl->lv)) { + log_error("Volume group %s contains snapshots " + "that are not yet supported.", + vg->name); + return 0; + } + } + + if ((lv_is_origin(lvl->lv) || lv_is_cow(lvl->lv)) && + lv_is_active(lvl->lv)) { + log_error("Snapshot logical volumes must be inactive " + "when changing the cluster attribute."); + return 0; + } + } + + if (clustered) + vg->status |= CLUSTERED; + else + vg->status &= ~CLUSTERED; + return 1; +} + /cvs/lvm2/LVM2/lib/metadata/vg.h,v --> standard output revision 1.1 --- LVM2/lib/metadata/vg.h +++ - 2010-09-30 13:16:56.647085000 +0000 @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _VG_H +#define _VG_H + +struct cmd_context; +struct dm_pool; +struct format_instance; +struct dm_list; +struct id; + +typedef enum { + ALLOC_INVALID, + ALLOC_CONTIGUOUS, + ALLOC_CLING, + ALLOC_NORMAL, + ALLOC_ANYWHERE, + ALLOC_INHERIT +} alloc_policy_t; + +struct volume_group { + struct cmd_context *cmd; + struct dm_pool *vgmem; + struct format_instance *fid; + struct dm_list *cmd_vgs;/* List of wanted/locked and opened VGs */ + uint32_t cmd_missing_vgs;/* Flag marks missing VG */ + uint32_t seqno; /* Metadata sequence number */ + + alloc_policy_t alloc; + uint64_t status; + + struct id id; + char *name; + char *old_name; /* Set during vgrename and vgcfgrestore */ + char *system_id; + + uint32_t extent_size; + uint32_t extent_count; + uint32_t free_count; + + uint32_t max_lv; + uint32_t max_pv; + + /* physical volumes */ + uint32_t pv_count; + struct dm_list pvs; + + /* + * logical volumes + * The following relationship should always hold: + * dm_list_size(lvs) = user visible lv_count + snapshot_count + other invisible LVs + * + * Snapshots consist of 2 instances of "struct logical_volume": + * - cow (lv_name is visible to the user) + * - snapshot (lv_name is 'snapshotN') + * + * Mirrors consist of multiple instances of "struct logical_volume": + * - one for the mirror log + * - one for each mirror leg + * - one for the user-visible mirror LV + */ + struct dm_list lvs; + + struct dm_list tags; + + /* + * FIXME: Move the next fields into a different struct? + */ + + /* + * List of removed physical volumes by pvreduce. + * They have to get cleared on vg_commit. + */ + struct dm_list removed_pvs; + uint32_t open_mode; /* FIXME: read or write - check lock type? */ + + /* + * Store result of the last vg_read(). + * 0 for success else appropriate FAILURE_* bits set. + */ + uint32_t read_status; + uint32_t mda_copies; /* target number of mdas for this VG */ +}; + +uint32_t vg_seqno(const struct volume_group *vg); +uint64_t vg_status(const struct volume_group *vg); +int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc); +int vg_set_clustered(struct volume_group *vg, int clustered); +uint64_t vg_size(const struct volume_group *vg); +uint64_t vg_free(const struct volume_group *vg); +uint64_t vg_extent_size(const struct volume_group *vg); +int vg_set_extent_size(struct volume_group *vg, uint32_t new_extent_size); +uint64_t vg_extent_count(const struct volume_group *vg); +uint64_t vg_free_count(const struct volume_group *vg); +uint64_t vg_pv_count(const struct volume_group *vg); +uint64_t vg_max_pv(const struct volume_group *vg); +int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv); +uint64_t vg_max_lv(const struct volume_group *vg); +int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv); +uint32_t vg_mda_count(const struct volume_group *vg); +uint32_t vg_mda_used_count(const struct volume_group *vg); +uint32_t vg_mda_copies(const struct volume_group *vg); +int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies); +/* + * Returns visible LV count - number of LVs from user perspective + */ +unsigned vg_visible_lvs(const struct volume_group *vg); +/* + * Count snapshot LVs. + */ +unsigned snapshot_count(const struct volume_group *vg); + +uint64_t vg_mda_size(const struct volume_group *vg); +uint64_t vg_mda_free(const struct volume_group *vg); + +#endif /cvs/lvm2/LVM2/lib/metadata/lv.c,v --> standard output revision 1.1 --- LVM2/lib/metadata/lv.c +++ - 2010-09-30 13:16:56.895538000 +0000 @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "lib.h" +#include "metadata.h" + +uint64_t lv_size(const struct logical_volume *lv) +{ + return lv->size; +} /cvs/lvm2/LVM2/lib/metadata/lv.h,v --> standard output revision 1.1 --- LVM2/lib/metadata/lv.h +++ - 2010-09-30 13:16:57.348008000 +0000 @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _LV_H +#define _LV_H + +union lvid; +struct volume_group; +struct dm_list; +struct lv_segment; +struct replicator_device; + +struct logical_volume { + union lvid lvid; + char *name; + + struct volume_group *vg; + + uint64_t status; + alloc_policy_t alloc; + uint32_t read_ahead; + int32_t major; + int32_t minor; + + uint64_t size; /* Sectors */ + uint32_t le_count; + + uint32_t origin_count; + struct dm_list snapshot_segs; + struct lv_segment *snapshot; + + struct replicator_device *rdevice;/* For replicator-devs, rimages, slogs - reference to rdevice */ + struct dm_list rsites; /* For replicators - all sites */ + + struct dm_list segments; + struct dm_list tags; + struct dm_list segs_using_this_lv; +}; + +uint64_t lv_size(const struct logical_volume *lv); + +#endif From wysochanski@sourceware.org Thu Sep 30 13:53:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 13:53:00 -0000 Subject: LVM2/lib metadata/lv.c metadata/lv.h metadata/ ... Message-ID: <20100930135304.5268.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 13:52:57 Modified files: lib/metadata : lv.c lv.h metadata.c metadata.h pv.c pv.h vg.c vg.h lib/report : columns.h report.c Log message: Add {pv|vg|lv}_attr_dup() functions and refactor 'disp' functions. Move the creating of the 'attr' strings into a common function so they can be called from the 'disp' functions as well as the new 'get' property functions. Add "_dup" suffix to indicate memory is allocated. Refactor pvstatus_disp to take pv argument and call pv_attr_dup(). Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.c.diff?cvsroot=lvm2&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.h.diff?cvsroot=lvm2&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.400&r2=1.401 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.219&r2=1.220 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.c.diff?cvsroot=lvm2&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.h.diff?cvsroot=lvm2&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.c.diff?cvsroot=lvm2&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.h.diff?cvsroot=lvm2&r1=1.1&r2=1.2 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/columns.h.diff?cvsroot=lvm2&r1=1.44&r2=1.45 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/report.c.diff?cvsroot=lvm2&r1=1.127&r2=1.128 --- LVM2/lib/metadata/lv.c 2010/09/30 13:16:55 1.1 +++ LVM2/lib/metadata/lv.c 2010/09/30 13:52:55 1.2 @@ -14,8 +14,126 @@ #include "lib.h" #include "metadata.h" +#include "activate.h" uint64_t lv_size(const struct logical_volume *lv) { return lv->size; } + +static int _lv_mimage_in_sync(const struct logical_volume *lv) +{ + float percent; + percent_range_t percent_range; + struct lv_segment *mirror_seg = find_mirror_seg(first_seg(lv)); + + if (!(lv->status & MIRROR_IMAGE) || !mirror_seg) + return_0; + + if (!lv_mirror_percent(lv->vg->cmd, mirror_seg->lv, 0, &percent, + &percent_range, NULL)) + return_0; + + return (percent_range == PERCENT_100) ? 1 : 0; +} + +char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv) +{ + float snap_percent; + percent_range_t percent_range; + struct lvinfo info; + char *repstr; + + if (!(repstr = dm_pool_zalloc(mem, 7))) { + log_error("dm_pool_alloc failed"); + return 0; + } + + /* Blank if this is a "free space" LV. */ + if (!*lv->name) + goto out; + + if (lv->status & PVMOVE) + repstr[0] = 'p'; + else if (lv->status & CONVERTING) + repstr[0] = 'c'; + else if (lv->status & VIRTUAL) + repstr[0] = 'v'; + /* Origin takes precedence over Mirror */ + else if (lv_is_origin(lv)) { + if (lv_is_merging_origin(lv)) + repstr[0] = 'O'; + else + repstr[0] = 'o'; + } + else if (lv->status & MIRRORED) { + if (lv->status & MIRROR_NOTSYNCED) + repstr[0] = 'M'; + else + repstr[0] = 'm'; + }else if (lv->status & MIRROR_IMAGE) + if (_lv_mimage_in_sync(lv)) + repstr[0] = 'i'; + else + repstr[0] = 'I'; + else if (lv->status & MIRROR_LOG) + repstr[0] = 'l'; + else if (lv_is_cow(lv)) { + if (lv_is_merging_cow(lv)) + repstr[0] = 'S'; + else + repstr[0] = 's'; + } else + repstr[0] = '-'; + + if (lv->status & PVMOVE) + repstr[1] = '-'; + else if (lv->status & LVM_WRITE) + repstr[1] = 'w'; + else if (lv->status & LVM_READ) + repstr[1] = 'r'; + else + repstr[1] = '-'; + + repstr[2] = alloc_policy_char(lv->alloc); + + if (lv->status & LOCKED) + repstr[2] = toupper(repstr[2]); + + if (lv->status & FIXED_MINOR) + repstr[3] = 'm'; /* Fixed Minor */ + else + repstr[3] = '-'; + + if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) && info.exists) { + if (info.suspended) + repstr[4] = 's'; /* Suspended */ + else if (info.live_table) + repstr[4] = 'a'; /* Active */ + else if (info.inactive_table) + repstr[4] = 'i'; /* Inactive with table */ + else + repstr[4] = 'd'; /* Inactive without table */ + + /* Snapshot dropped? */ + if (info.live_table && lv_is_cow(lv) && + (!lv_snapshot_percent(lv, &snap_percent, &percent_range) || + percent_range == PERCENT_INVALID)) { + repstr[0] = toupper(repstr[0]); + if (info.suspended) + repstr[4] = 'S'; /* Susp Inv snapshot */ + else + repstr[4] = 'I'; /* Invalid snapshot */ + } + + if (info.open_count) + repstr[5] = 'o'; /* Open */ + else + repstr[5] = '-'; + } else { + repstr[4] = '-'; + repstr[5] = '-'; + } +out: + return repstr; +} --- LVM2/lib/metadata/lv.h 2010/09/30 13:16:55 1.1 +++ LVM2/lib/metadata/lv.h 2010/09/30 13:52:56 1.2 @@ -48,5 +48,6 @@ }; uint64_t lv_size(const struct logical_volume *lv); +char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv); #endif --- LVM2/lib/metadata/metadata.c 2010/09/30 13:05:45 1.400 +++ LVM2/lib/metadata/metadata.c 2010/09/30 13:52:56 1.401 @@ -3921,6 +3921,22 @@ return 1; } +char alloc_policy_char(alloc_policy_t alloc) +{ + switch (alloc) { + case ALLOC_CONTIGUOUS: + return 'c'; + case ALLOC_CLING: + return 'l'; + case ALLOC_NORMAL: + return 'n'; + case ALLOC_ANYWHERE: + return 'a'; + default: + return 'i'; + } +} + /** * pv_by_path - Given a device path return a PV handle if it is a PV * @cmd - handle to the LVM command instance --- LVM2/lib/metadata/metadata.h 2010/09/30 13:04:56 1.219 +++ LVM2/lib/metadata/metadata.h 2010/09/30 13:52:56 1.220 @@ -412,5 +412,6 @@ int is_mirror_image_removable(struct logical_volume *mimage_lv, void *baton); uint64_t find_min_mda_size(struct dm_list *mdas); +char alloc_policy_char(alloc_policy_t alloc); #endif --- LVM2/lib/metadata/pv.c 2010/09/30 13:15:42 1.1 +++ LVM2/lib/metadata/pv.c 2010/09/30 13:52:56 1.2 @@ -163,6 +163,27 @@ return pv_field(pv, status) & MISSING_PV ? 1 : 0; } +char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv) +{ + char *repstr; + + if (!(repstr = dm_pool_zalloc(mem, 3))) { + log_error("dm_pool_alloc failed"); + return NULL; + } + + if (pv->status & ALLOCATABLE_PV) + repstr[0] = 'a'; + else + repstr[0] = '-'; + + if (pv->status & EXPORTED_VG) + repstr[1] = 'x'; + else + repstr[1] = '-'; + return repstr; +} + unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored) { struct lvmcache_info *info; --- LVM2/lib/metadata/pv.h 2010/09/30 13:15:42 1.1 +++ LVM2/lib/metadata/pv.h 2010/09/30 13:52:56 1.2 @@ -54,6 +54,7 @@ struct device *pv_dev(const struct physical_volume *pv); const char *pv_vg_name(const struct physical_volume *pv); +char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv); const char *pv_dev_name(const struct physical_volume *pv); uint64_t pv_size(const struct physical_volume *pv); uint64_t pv_size_field(const struct physical_volume *pv); --- LVM2/lib/metadata/vg.c 2010/09/30 13:16:55 1.1 +++ LVM2/lib/metadata/vg.c 2010/09/30 13:52:56 1.2 @@ -434,3 +434,40 @@ return 1; } +char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg) +{ + char *repstr; + + if (!(repstr = dm_pool_zalloc(mem, 7))) { + log_error("dm_pool_alloc failed"); + return NULL; + } + + if (vg->status & LVM_WRITE) + repstr[0] = 'w'; + else + repstr[0] = 'r'; + + if (vg_is_resizeable(vg)) + repstr[1] = 'z'; + else + repstr[1] = '-'; + + if (vg_is_exported(vg)) + repstr[2] = 'x'; + else + repstr[2] = '-'; + + if (vg_missing_pv_count(vg)) + repstr[3] = 'p'; + else + repstr[3] = '-'; + + repstr[4] = alloc_policy_char(vg->alloc); + + if (vg_is_clustered(vg)) + repstr[5] = 'c'; + else + repstr[5] = '-'; + return repstr; +} --- LVM2/lib/metadata/vg.h 2010/09/30 13:16:55 1.1 +++ LVM2/lib/metadata/vg.h 2010/09/30 13:52:56 1.2 @@ -123,5 +123,6 @@ uint64_t vg_mda_size(const struct volume_group *vg); uint64_t vg_mda_free(const struct volume_group *vg); +char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg); #endif --- LVM2/lib/report/columns.h 2010/08/20 12:44:17 1.44 +++ LVM2/lib/report/columns.h 2010/09/30 13:52:57 1.45 @@ -93,7 +93,7 @@ FIELD(PVS, pv, NUM, "PSize", id, 5, pvsize, pv_size, "Size of PV in current units.", 0) FIELD(PVS, pv, NUM, "PFree", id, 5, pvfree, pv_free, "Total amount of unallocated space in current units.", 0) FIELD(PVS, pv, NUM, "Used", id, 4, pvused, pv_used, "Total amount of allocated space in current units.", 0) -FIELD(PVS, pv, STR, "Attr", status, 4, pvstatus, pv_attr, "Various attributes - see man page.", 0) +FIELD(PVS, pv, STR, "Attr", id, 4, pvstatus, pv_attr, "Various attributes - see man page.", 0) FIELD(PVS, pv, NUM, "PE", pe_count, 3, uint32, pv_pe_count, "Total number of Physical Extents.", 0) FIELD(PVS, pv, NUM, "Alloc", pe_alloc_count, 5, uint32, pv_pe_alloc_count, "Total number of allocated Physical Extents.", 0) FIELD(PVS, pv, STR, "PV Tags", tags, 7, tags, pv_tags, "Tags, if any.", 0) --- LVM2/lib/report/report.c 2010/08/20 12:44:17 1.127 +++ LVM2/lib/report/report.c 2010/09/30 13:52:57 1.128 @@ -34,22 +34,6 @@ struct pv_segment *pvseg; }; -static char _alloc_policy_char(alloc_policy_t alloc) -{ - switch (alloc) { - case ALLOC_CONTIGUOUS: - return 'c'; - case ALLOC_CLING: - return 'l'; - case ALLOC_NORMAL: - return 'n'; - case ALLOC_ANYWHERE: - return 'a'; - default: - return 'i'; - } -} - static const uint64_t _minusone64 = UINT64_C(-1); static const int32_t _minusone32 = INT32_C(-1); @@ -264,124 +248,16 @@ return dm_report_field_int32(rh, field, &_minusone32); } -static int _lv_mimage_in_sync(const struct logical_volume *lv) -{ - float percent; - percent_range_t percent_range; - struct lv_segment *mirror_seg = find_mirror_seg(first_seg(lv)); - - if (!(lv->status & MIRROR_IMAGE) || !mirror_seg) - return_0; - - if (!lv_mirror_percent(lv->vg->cmd, mirror_seg->lv, 0, &percent, - &percent_range, NULL)) - return_0; - - return (percent_range == PERCENT_100) ? 1 : 0; -} - static int _lvstatus_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem, struct dm_report_field *field, const void *data, void *private __attribute__((unused))) { const struct logical_volume *lv = (const struct logical_volume *) data; - struct lvinfo info; char *repstr; - float snap_percent; - percent_range_t percent_range; - if (!(repstr = dm_pool_zalloc(mem, 7))) { - log_error("dm_pool_alloc failed"); + if (!(repstr = lv_attr_dup(mem, lv))) return 0; - } - - /* Blank if this is a "free space" LV. */ - if (!*lv->name) - goto out; - - if (lv->status & PVMOVE) - repstr[0] = 'p'; - else if (lv->status & CONVERTING) - repstr[0] = 'c'; - else if (lv->status & VIRTUAL) - repstr[0] = 'v'; - /* Origin takes precedence over Mirror */ - else if (lv_is_origin(lv)) { - if (lv_is_merging_origin(lv)) - repstr[0] = 'O'; - else - repstr[0] = 'o'; - } - else if (lv->status & MIRRORED) { - if (lv->status & MIRROR_NOTSYNCED) - repstr[0] = 'M'; - else - repstr[0] = 'm'; - }else if (lv->status & MIRROR_IMAGE) - if (_lv_mimage_in_sync(lv)) - repstr[0] = 'i'; - else - repstr[0] = 'I'; - else if (lv->status & MIRROR_LOG) - repstr[0] = 'l'; - else if (lv_is_cow(lv)) { - if (lv_is_merging_cow(lv)) - repstr[0] = 'S'; - else - repstr[0] = 's'; - } else - repstr[0] = '-'; - - if (lv->status & PVMOVE) - repstr[1] = '-'; - else if (lv->status & LVM_WRITE) - repstr[1] = 'w'; - else if (lv->status & LVM_READ) - repstr[1] = 'r'; - else - repstr[1] = '-'; - - repstr[2] = _alloc_policy_char(lv->alloc); - - if (lv->status & LOCKED) - repstr[2] = toupper(repstr[2]); - - if (lv->status & FIXED_MINOR) - repstr[3] = 'm'; /* Fixed Minor */ - else - repstr[3] = '-'; - if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) && info.exists) { - if (info.suspended) - repstr[4] = 's'; /* Suspended */ - else if (info.live_table) - repstr[4] = 'a'; /* Active */ - else if (info.inactive_table) - repstr[4] = 'i'; /* Inactive with table */ - else - repstr[4] = 'd'; /* Inactive without table */ - - /* Snapshot dropped? */ - if (info.live_table && lv_is_cow(lv) && - (!lv_snapshot_percent(lv, &snap_percent, &percent_range) || - percent_range == PERCENT_INVALID)) { - repstr[0] = toupper(repstr[0]); - if (info.suspended) - repstr[4] = 'S'; /* Susp Inv snapshot */ - else - repstr[4] = 'I'; /* Invalid snapshot */ - } - - if (info.open_count) - repstr[5] = 'o'; /* Open */ - else - repstr[5] = '-'; - } else { - repstr[4] = '-'; - repstr[5] = '-'; - } - -out: dm_report_field_set_value(field, repstr, NULL); return 1; } @@ -390,23 +266,12 @@ struct dm_report_field *field, const void *data, void *private __attribute__((unused))) { - const uint32_t status = *(const uint32_t *) data; + const struct physical_volume *pv = + (const struct physical_volume *) data; char *repstr; - if (!(repstr = dm_pool_zalloc(mem, 3))) { - log_error("dm_pool_alloc failed"); + if (!(repstr = pv_attr_dup(mem, pv))) return 0; - } - - if (status & ALLOCATABLE_PV) - repstr[0] = 'a'; - else - repstr[0] = '-'; - - if (status & EXPORTED_VG) - repstr[1] = 'x'; - else - repstr[1] = '-'; dm_report_field_set_value(field, repstr, NULL); return 1; @@ -419,37 +284,8 @@ const struct volume_group *vg = (const struct volume_group *) data; char *repstr; - if (!(repstr = dm_pool_zalloc(mem, 7))) { - log_error("dm_pool_alloc failed"); + if (!(repstr = vg_attr_dup(mem, vg))) return 0; - } - - if (vg->status & LVM_WRITE) - repstr[0] = 'w'; - else - repstr[0] = 'r'; - - if (vg_is_resizeable(vg)) - repstr[1] = 'z'; - else - repstr[1] = '-'; - - if (vg_is_exported(vg)) - repstr[2] = 'x'; - else - repstr[2] = '-'; - - if (vg_missing_pv_count(vg)) - repstr[3] = 'p'; - else - repstr[3] = '-'; - - repstr[4] = _alloc_policy_char(vg->alloc); - - if (vg_is_clustered(vg)) - repstr[5] = 'c'; - else - repstr[5] = '-'; dm_report_field_set_value(field, repstr, NULL); return 1; From wysochanski@sourceware.org Thu Sep 30 14:07:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:07:00 -0000 Subject: LVM2/lib report/report.c uuid/uuid.c uuid/uuid.h Message-ID: <20100930140734.16135.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:07:34 Modified files: lib/report : report.c lib/uuid : uuid.c uuid.h Log message: Add id_format_and_copy() common function and call from _uuid_disp. Add supporting uuid function to allocate memory and call id_write_format. Call id_format_and_copy from _uuid_disp. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/report.c.diff?cvsroot=lvm2&r1=1.128&r2=1.129 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/uuid/uuid.c.diff?cvsroot=lvm2&r1=1.30&r2=1.31 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/uuid/uuid.h.diff?cvsroot=lvm2&r1=1.16&r2=1.17 --- LVM2/lib/report/report.c 2010/09/30 13:52:57 1.128 +++ LVM2/lib/report/report.c 2010/09/30 14:07:33 1.129 @@ -677,12 +677,7 @@ { char *repstr = NULL; - if (!(repstr = dm_pool_alloc(mem, 40))) { - log_error("dm_pool_alloc failed"); - return 0; - } - - if (!id_write_format((const struct id *) data, repstr, 40)) + if (!(repstr = id_format_and_copy(mem, (struct id *)data))) return_0; dm_report_field_set_value(field, repstr, NULL); --- LVM2/lib/uuid/uuid.c 2009/07/15 20:02:47 1.30 +++ LVM2/lib/uuid/uuid.c 2010/09/30 14:07:33 1.31 @@ -206,3 +206,18 @@ return id_valid(id); } + +char *id_format_and_copy(struct dm_pool *mem, const struct id *id) +{ + char *repstr = NULL; + + if (!(repstr = dm_pool_alloc(mem, 40))) { + log_error("dm_pool_alloc failed"); + return NULL; + } + + if (!id_write_format(id, repstr, 40)) + return_NULL; + + return repstr; +} --- LVM2/lib/uuid/uuid.h 2008/08/28 18:41:51 1.16 +++ LVM2/lib/uuid/uuid.h 2010/09/30 14:07:33 1.17 @@ -54,4 +54,6 @@ */ int id_read_format(struct id *id, const char *buffer); +char *id_format_and_copy(struct dm_pool *mem, const struct id *id); + #endif From wysochanski@sourceware.org Thu Sep 30 14:07:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:07:00 -0000 Subject: LVM2/lib/metadata lv.c pv.c vg.c Message-ID: <20100930140721.15911.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:07:19 Modified files: lib/metadata : lv.c pv.c vg.c Log message: Simplify logic to create 'attr' strings. This patch addresses code review request to simplify creation of 'attr' strings. The simplification is done in this separate patch to more easily review and ensure the simplification is done without error. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.c.diff?cvsroot=lvm2&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.c.diff?cvsroot=lvm2&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.c.diff?cvsroot=lvm2&r1=1.2&r2=1.3 --- LVM2/lib/metadata/lv.c 2010/09/30 13:52:55 1.2 +++ LVM2/lib/metadata/lv.c 2010/09/30 14:07:19 1.3 @@ -61,28 +61,16 @@ repstr[0] = 'v'; /* Origin takes precedence over Mirror */ else if (lv_is_origin(lv)) { - if (lv_is_merging_origin(lv)) - repstr[0] = 'O'; - else - repstr[0] = 'o'; + repstr[0] = (lv_is_merging_origin(lv)) ? 'O' : 'o'; } else if (lv->status & MIRRORED) { - if (lv->status & MIRROR_NOTSYNCED) - repstr[0] = 'M'; - else - repstr[0] = 'm'; + repstr[0] = (lv->status & MIRROR_NOTSYNCED) ? 'M' : 'm'; }else if (lv->status & MIRROR_IMAGE) - if (_lv_mimage_in_sync(lv)) - repstr[0] = 'i'; - else - repstr[0] = 'I'; + repstr[0] = (_lv_mimage_in_sync(lv)) ? 'i' : 'I'; else if (lv->status & MIRROR_LOG) repstr[0] = 'l'; else if (lv_is_cow(lv)) { - if (lv_is_merging_cow(lv)) - repstr[0] = 'S'; - else - repstr[0] = 's'; + repstr[0] = (lv_is_merging_cow(lv)) ? 'S' : 's'; } else repstr[0] = '-'; @@ -100,10 +88,7 @@ if (lv->status & LOCKED) repstr[2] = toupper(repstr[2]); - if (lv->status & FIXED_MINOR) - repstr[3] = 'm'; /* Fixed Minor */ - else - repstr[3] = '-'; + repstr[3] = (lv->status & FIXED_MINOR) ? 'm' : '-'; if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) && info.exists) { if (info.suspended) @@ -126,10 +111,7 @@ repstr[4] = 'I'; /* Invalid snapshot */ } - if (info.open_count) - repstr[5] = 'o'; /* Open */ - else - repstr[5] = '-'; + repstr[5] = (info.open_count) ? 'o' : '-'; } else { repstr[4] = '-'; repstr[5] = '-'; --- LVM2/lib/metadata/pv.c 2010/09/30 13:52:56 1.2 +++ LVM2/lib/metadata/pv.c 2010/09/30 14:07:19 1.3 @@ -172,15 +172,8 @@ return NULL; } - if (pv->status & ALLOCATABLE_PV) - repstr[0] = 'a'; - else - repstr[0] = '-'; - - if (pv->status & EXPORTED_VG) - repstr[1] = 'x'; - else - repstr[1] = '-'; + repstr[0] = (pv->status & ALLOCATABLE_PV) ? 'a' : '-'; + repstr[1] = (pv->status & EXPORTED_VG) ? 'x' : '-'; return repstr; } --- LVM2/lib/metadata/vg.c 2010/09/30 13:52:56 1.2 +++ LVM2/lib/metadata/vg.c 2010/09/30 14:07:19 1.3 @@ -443,31 +443,11 @@ return NULL; } - if (vg->status & LVM_WRITE) - repstr[0] = 'w'; - else - repstr[0] = 'r'; - - if (vg_is_resizeable(vg)) - repstr[1] = 'z'; - else - repstr[1] = '-'; - - if (vg_is_exported(vg)) - repstr[2] = 'x'; - else - repstr[2] = '-'; - - if (vg_missing_pv_count(vg)) - repstr[3] = 'p'; - else - repstr[3] = '-'; - + repstr[0] = (vg->status & LVM_WRITE) ? 'w' : 'r'; + repstr[1] = (vg_is_resizeable(vg)) ? 'z' : '-'; + repstr[2] = (vg_is_exported(vg)) ? 'x' : '-'; + repstr[3] = (vg_missing_pv_count(vg)) ? 'p' : '-'; repstr[4] = alloc_policy_char(vg->alloc); - - if (vg_is_clustered(vg)) - repstr[5] = 'c'; - else - repstr[5] = '-'; + repstr[5] = (vg_is_clustered(vg)) ? 'c' : '-'; return repstr; } From wysochanski@sourceware.org Thu Sep 30 14:07:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:07:00 -0000 Subject: LVM2 lib/metadata/lv.c lib/metadata/lv.h lib/m ... Message-ID: <20100930140750.16486.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:07:48 Modified files: lib/metadata : lv.c lv.h pv.c pv.h vg.c vg.h liblvm : lvm_lv.c lvm_pv.c lvm_vg.c Log message: Add pv_uuid_dup, vg_uuid_dup, and lv_uuid_dup, and call id_format_and_copy. Add supporting functions for pv_uuid, vg_uuid, and lv_uuid. Call new function id_format_and_copy. Use 'const' where appropriate. Add "_dup" suffix to indicate memory is being allocated. Call {pv|vg|lv}_uuid_dup from lvm2app uuid functions. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.c.diff?cvsroot=lvm2&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.h.diff?cvsroot=lvm2&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.c.diff?cvsroot=lvm2&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.h.diff?cvsroot=lvm2&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.c.diff?cvsroot=lvm2&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.h.diff?cvsroot=lvm2&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_lv.c.diff?cvsroot=lvm2&r1=1.25&r2=1.26 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_pv.c.diff?cvsroot=lvm2&r1=1.12&r2=1.13 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/liblvm/lvm_vg.c.diff?cvsroot=lvm2&r1=1.43&r2=1.44 --- LVM2/lib/metadata/lv.c 2010/09/30 14:07:19 1.3 +++ LVM2/lib/metadata/lv.c 2010/09/30 14:07:47 1.4 @@ -16,6 +16,11 @@ #include "metadata.h" #include "activate.h" +char *lv_uuid_dup(const struct logical_volume *lv) +{ + return id_format_and_copy(lv->vg->vgmem, &lv->lvid.id[1]); +} + uint64_t lv_size(const struct logical_volume *lv) { return lv->size; --- LVM2/lib/metadata/lv.h 2010/09/30 13:52:56 1.2 +++ LVM2/lib/metadata/lv.h 2010/09/30 14:07:47 1.3 @@ -49,5 +49,6 @@ uint64_t lv_size(const struct logical_volume *lv); char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv); +char *lv_uuid_dup(const struct logical_volume *lv); #endif --- LVM2/lib/metadata/pv.c 2010/09/30 14:07:19 1.3 +++ LVM2/lib/metadata/pv.c 2010/09/30 14:07:47 1.4 @@ -29,6 +29,11 @@ return pv_field(pv, id); } +char *pv_uuid_dup(const struct physical_volume *pv) +{ + return id_format_and_copy(pv->vg->vgmem, &pv->id); +} + const struct format_type *pv_format_type(const struct physical_volume *pv) { return pv_field(pv, fmt); --- LVM2/lib/metadata/pv.h 2010/09/30 13:52:56 1.2 +++ LVM2/lib/metadata/pv.h 2010/09/30 14:07:47 1.3 @@ -56,6 +56,7 @@ const char *pv_vg_name(const struct physical_volume *pv); char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv); const char *pv_dev_name(const struct physical_volume *pv); +char *pv_uuid_dup(const struct physical_volume *pv); uint64_t pv_size(const struct physical_volume *pv); uint64_t pv_size_field(const struct physical_volume *pv); uint64_t pv_dev_size(const struct physical_volume *pv); --- LVM2/lib/metadata/vg.c 2010/09/30 14:07:19 1.3 +++ LVM2/lib/metadata/vg.c 2010/09/30 14:07:47 1.4 @@ -16,6 +16,11 @@ #include "metadata.h" #include "activate.h" +char *vg_uuid_dup(const struct volume_group *vg) +{ + return id_format_and_copy(vg->vgmem, &vg->id); +} + uint32_t vg_seqno(const struct volume_group *vg) { return vg->seqno; --- LVM2/lib/metadata/vg.h 2010/09/30 13:52:56 1.2 +++ LVM2/lib/metadata/vg.h 2010/09/30 14:07:47 1.3 @@ -124,5 +124,6 @@ uint64_t vg_mda_size(const struct volume_group *vg); uint64_t vg_mda_free(const struct volume_group *vg); char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg); +char *vg_uuid_dup(const struct volume_group *vg); #endif --- LVM2/liblvm/lvm_lv.c 2010/08/17 16:25:35 1.25 +++ LVM2/liblvm/lvm_lv.c 2010/09/30 14:07:48 1.26 @@ -14,7 +14,7 @@ #include "lib.h" #include "lvm2app.h" -#include "metadata-exported.h" +#include "metadata.h" #include "lvm-string.h" #include "defaults.h" #include "segtype.h" @@ -39,13 +39,7 @@ const char *lvm_lv_get_uuid(const lv_t lv) { - char uuid[64] __attribute__((aligned(8))); - - if (!id_write_format(&lv->lvid.id[1], uuid, sizeof(uuid))) { - log_error(INTERNAL_ERROR "unable to convert uuid"); - return NULL; - } - return dm_pool_strndup(lv->vg->vgmem, (const char *)uuid, 64); + return lv_uuid_dup(lv); } const char *lvm_lv_get_name(const lv_t lv) --- LVM2/liblvm/lvm_pv.c 2010/07/09 15:34:47 1.12 +++ LVM2/liblvm/lvm_pv.c 2010/09/30 14:07:48 1.13 @@ -14,18 +14,12 @@ #include "lib.h" #include "lvm2app.h" -#include "metadata-exported.h" +#include "metadata.h" #include "lvm-string.h" const char *lvm_pv_get_uuid(const pv_t pv) { - char uuid[64] __attribute__((aligned(8))); - - if (!id_write_format(&pv->id, uuid, sizeof(uuid))) { - log_error(INTERNAL_ERROR "Unable to convert uuid"); - return NULL; - } - return dm_pool_strndup(pv->vg->vgmem, (const char *)uuid, 64); + return pv_uuid_dup(pv); } const char *lvm_pv_get_name(const pv_t pv) --- LVM2/liblvm/lvm_vg.c 2010/07/09 16:57:34 1.43 +++ LVM2/liblvm/lvm_vg.c 2010/09/30 14:07:48 1.44 @@ -327,13 +327,7 @@ const char *lvm_vg_get_uuid(const vg_t vg) { - char uuid[64] __attribute__((aligned(8))); - - if (!id_write_format(&vg->id, uuid, sizeof(uuid))) { - log_error(INTERNAL_ERROR "Unable to convert uuid"); - return NULL; - } - return dm_pool_strndup(vg->vgmem, (const char *)uuid, 64); + return vg_uuid_dup(vg); } const char *lvm_vg_get_name(const vg_t vg) From wysochanski@sourceware.org Thu Sep 30 14:08:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:08:00 -0000 Subject: LVM2/lib metadata/metadata.c metadata/metadata ... Message-ID: <20100930140808.17267.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:08:07 Modified files: lib/metadata : metadata.c metadata.h lib/report : report.c Log message: Add tags_format_and_copy() common function and call from _tags_disp. Add a common function to allocate memory and format a string of tags. Call tags_format_and_copy() from _tags_disp(). Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.401&r2=1.402 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.220&r2=1.221 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/report.c.diff?cvsroot=lvm2&r1=1.129&r2=1.130 --- LVM2/lib/metadata/metadata.c 2010/09/30 13:52:56 1.401 +++ LVM2/lib/metadata/metadata.c 2010/09/30 14:08:07 1.402 @@ -3937,6 +3937,30 @@ } } +char *tags_format_and_copy(struct dm_pool *mem, const struct dm_list *tags) +{ + struct str_list *sl; + + if (!dm_pool_begin_object(mem, 256)) { + log_error("dm_pool_begin_object failed"); + return NULL; + } + + dm_list_iterate_items(sl, tags) { + if (!dm_pool_grow_object(mem, sl->str, strlen(sl->str)) || + (sl->list.n != tags && !dm_pool_grow_object(mem, ",", 1))) { + log_error("dm_pool_grow_object failed"); + return NULL; + } + } + + if (!dm_pool_grow_object(mem, "\0", 1)) { + log_error("dm_pool_grow_object failed"); + return NULL; + } + return dm_pool_end_object(mem); +} + /** * pv_by_path - Given a device path return a PV handle if it is a PV * @cmd - handle to the LVM command instance --- LVM2/lib/metadata/metadata.h 2010/09/30 13:52:56 1.220 +++ LVM2/lib/metadata/metadata.h 2010/09/30 14:08:07 1.221 @@ -413,5 +413,6 @@ uint64_t find_min_mda_size(struct dm_list *mdas); char alloc_policy_char(alloc_policy_t alloc); +char *tags_format_and_copy(struct dm_pool *mem, const struct dm_list *tags); #endif --- LVM2/lib/report/report.c 2010/09/30 14:07:33 1.129 +++ LVM2/lib/report/report.c 2010/09/30 14:08:07 1.130 @@ -150,27 +150,12 @@ const void *data, void *private __attribute__((unused))) { const struct dm_list *tags = (const struct dm_list *) data; - struct str_list *sl; + char *tags_str; - if (!dm_pool_begin_object(mem, 256)) { - log_error("dm_pool_begin_object failed"); + if (!(tags_str = tags_format_and_copy(mem, tags))) return 0; - } - - dm_list_iterate_items(sl, tags) { - if (!dm_pool_grow_object(mem, sl->str, strlen(sl->str)) || - (sl->list.n != tags && !dm_pool_grow_object(mem, ",", 1))) { - log_error("dm_pool_grow_object failed"); - return 0; - } - } - - if (!dm_pool_grow_object(mem, "\0", 1)) { - log_error("dm_pool_grow_object failed"); - return 0; - } - dm_report_field_set_value(field, dm_pool_end_object(mem), NULL); + dm_report_field_set_value(field, tags_str, NULL); return 1; } From wysochanski@sourceware.org Thu Sep 30 14:08:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:08:00 -0000 Subject: LVM2/lib/metadata lv.c lv.h pv.c pv.h vg.c vg.h Message-ID: <20100930140822.17482.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:08:20 Modified files: lib/metadata : lv.c lv.h pv.c pv.h vg.c vg.h Log message: Add pv_tags_dup, vg_tags_dup, lv_tags_dup functions that call tags_format_and_copy. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.c.diff?cvsroot=lvm2&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.h.diff?cvsroot=lvm2&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.c.diff?cvsroot=lvm2&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.h.diff?cvsroot=lvm2&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.c.diff?cvsroot=lvm2&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.h.diff?cvsroot=lvm2&r1=1.3&r2=1.4 --- LVM2/lib/metadata/lv.c 2010/09/30 14:07:47 1.4 +++ LVM2/lib/metadata/lv.c 2010/09/30 14:08:19 1.5 @@ -21,6 +21,11 @@ return id_format_and_copy(lv->vg->vgmem, &lv->lvid.id[1]); } +char *lv_tags_dup(const struct logical_volume *lv) +{ + return tags_format_and_copy(lv->vg->vgmem, &lv->tags); +} + uint64_t lv_size(const struct logical_volume *lv) { return lv->size; --- LVM2/lib/metadata/lv.h 2010/09/30 14:07:47 1.3 +++ LVM2/lib/metadata/lv.h 2010/09/30 14:08:20 1.4 @@ -50,5 +50,6 @@ uint64_t lv_size(const struct logical_volume *lv); char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv); char *lv_uuid_dup(const struct logical_volume *lv); +char *lv_tags_dup(const struct logical_volume *lv); #endif --- LVM2/lib/metadata/pv.c 2010/09/30 14:07:47 1.4 +++ LVM2/lib/metadata/pv.c 2010/09/30 14:08:20 1.5 @@ -34,6 +34,11 @@ return id_format_and_copy(pv->vg->vgmem, &pv->id); } +char *pv_tags_dup(const struct physical_volume *pv) +{ + return tags_format_and_copy(pv->vg->vgmem, &pv->tags); +} + const struct format_type *pv_format_type(const struct physical_volume *pv) { return pv_field(pv, fmt); --- LVM2/lib/metadata/pv.h 2010/09/30 14:07:47 1.3 +++ LVM2/lib/metadata/pv.h 2010/09/30 14:08:20 1.4 @@ -57,6 +57,7 @@ char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv); const char *pv_dev_name(const struct physical_volume *pv); char *pv_uuid_dup(const struct physical_volume *pv); +char *pv_tags_dup(const struct physical_volume *pv); uint64_t pv_size(const struct physical_volume *pv); uint64_t pv_size_field(const struct physical_volume *pv); uint64_t pv_dev_size(const struct physical_volume *pv); --- LVM2/lib/metadata/vg.c 2010/09/30 14:07:47 1.4 +++ LVM2/lib/metadata/vg.c 2010/09/30 14:08:20 1.5 @@ -21,6 +21,11 @@ return id_format_and_copy(vg->vgmem, &vg->id); } +char *vg_tags_dup(const struct volume_group *vg) +{ + return tags_format_and_copy(vg->vgmem, &vg->tags); +} + uint32_t vg_seqno(const struct volume_group *vg) { return vg->seqno; --- LVM2/lib/metadata/vg.h 2010/09/30 14:07:47 1.3 +++ LVM2/lib/metadata/vg.h 2010/09/30 14:08:20 1.4 @@ -125,5 +125,6 @@ uint64_t vg_mda_free(const struct volume_group *vg); char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg); char *vg_uuid_dup(const struct volume_group *vg); +char *vg_tags_dup(const struct volume_group *vg); #endif From wysochanski@sourceware.org Thu Sep 30 14:08:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:08:00 -0000 Subject: LVM2/lib/report properties.c Message-ID: <20100930140846.17845.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:08:46 Modified files: lib/report : properties.c Log message: Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv. Will need similar macros for VG, PV and LV, so define a generic one, and just pass in the struct name and variable name for the specific macro. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/properties.c.diff?cvsroot=lvm2&r1=1.4&r2=1.5 --- LVM2/lib/report/properties.c 2010/09/09 19:38:03 1.4 +++ LVM2/lib/report/properties.c 2010/09/30 14:08:46 1.5 @@ -20,14 +20,35 @@ #include "lvm-types.h" #include "metadata.h" -#define GET_NUM_PROPERTY_FN(NAME, VALUE) \ +#define GET_NUM_PROPERTY_FN(NAME, VALUE, TYPE, VAR) \ static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \ { \ - struct volume_group *vg = (struct volume_group *)obj; \ + struct TYPE *VAR = (struct TYPE *)obj; \ \ prop->v.n_val = VALUE; \ return 1; \ } +#define GET_VG_NUM_PROPERTY_FN(NAME, VALUE) \ + GET_NUM_PROPERTY_FN(NAME, VALUE, volume_group, vg) +#define GET_PV_NUM_PROPERTY_FN(NAME, VALUE) \ + GET_NUM_PROPERTY_FN(NAME, VALUE, physical_volume, pv) +#define GET_LV_NUM_PROPERTY_FN(NAME, VALUE) \ + GET_NUM_PROPERTY_FN(NAME, VALUE, logical_volume, lv) + +#define GET_STR_PROPERTY_FN(NAME, VALUE, TYPE, VAR) \ +static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \ +{ \ + struct TYPE *VAR = (struct TYPE *)obj; \ +\ + prop->v.s_val = (char *)VALUE; \ + return 1; \ +} +#define GET_VG_STR_PROPERTY_FN(NAME, VALUE) \ + GET_STR_PROPERTY_FN(NAME, VALUE, volume_group, vg) +#define GET_PV_STR_PROPERTY_FN(NAME, VALUE) \ + GET_STR_PROPERTY_FN(NAME, VALUE, physical_volume, pv) +#define GET_LV_STR_PROPERTY_FN(NAME, VALUE) \ + GET_STR_PROPERTY_FN(NAME, VALUE, logical_volume, lv) static int _not_implemented(void *obj, struct lvm_property_type *prop) { @@ -122,41 +143,41 @@ #define _vg_name_set _not_implemented #define _vg_attr_get _not_implemented #define _vg_attr_set _not_implemented -GET_NUM_PROPERTY_FN(vg_size, (SECTOR_SIZE * vg_size(vg))) +GET_VG_NUM_PROPERTY_FN(vg_size, (SECTOR_SIZE * vg_size(vg))) #define _vg_size_set _not_implemented -GET_NUM_PROPERTY_FN(vg_free, (SECTOR_SIZE * vg_free(vg))) +GET_VG_NUM_PROPERTY_FN(vg_free, (SECTOR_SIZE * vg_free(vg))) #define _vg_free_set _not_implemented #define _vg_sysid_get _not_implemented #define _vg_sysid_set _not_implemented -GET_NUM_PROPERTY_FN(vg_extent_size, vg->extent_size) +GET_VG_NUM_PROPERTY_FN(vg_extent_size, vg->extent_size) #define _vg_extent_size_set _not_implemented -GET_NUM_PROPERTY_FN(vg_extent_count, vg->extent_count) +GET_VG_NUM_PROPERTY_FN(vg_extent_count, vg->extent_count) #define _vg_extent_count_set _not_implemented -GET_NUM_PROPERTY_FN(vg_free_count, vg->free_count) +GET_VG_NUM_PROPERTY_FN(vg_free_count, vg->free_count) #define _vg_free_count_set _not_implemented -GET_NUM_PROPERTY_FN(max_lv, vg->max_lv) +GET_VG_NUM_PROPERTY_FN(max_lv, vg->max_lv) #define _max_lv_set _not_implemented -GET_NUM_PROPERTY_FN(max_pv, vg->max_pv) +GET_VG_NUM_PROPERTY_FN(max_pv, vg->max_pv) #define _max_pv_set _not_implemented -GET_NUM_PROPERTY_FN(pv_count, vg->pv_count) +GET_VG_NUM_PROPERTY_FN(pv_count, vg->pv_count) #define _pv_count_set _not_implemented -GET_NUM_PROPERTY_FN(lv_count, (vg_visible_lvs(vg))) +GET_VG_NUM_PROPERTY_FN(lv_count, (vg_visible_lvs(vg))) #define _lv_count_set _not_implemented -GET_NUM_PROPERTY_FN(snap_count, (snapshot_count(vg))) +GET_VG_NUM_PROPERTY_FN(snap_count, (snapshot_count(vg))) #define _snap_count_set _not_implemented -GET_NUM_PROPERTY_FN(vg_seqno, vg->seqno) +GET_VG_NUM_PROPERTY_FN(vg_seqno, vg->seqno) #define _vg_seqno_set _not_implemented #define _vg_tags_get _not_implemented #define _vg_tags_set _not_implemented -GET_NUM_PROPERTY_FN(vg_mda_count, (vg_mda_count(vg))) +GET_VG_NUM_PROPERTY_FN(vg_mda_count, (vg_mda_count(vg))) #define _vg_mda_count_set _not_implemented -GET_NUM_PROPERTY_FN(vg_mda_used_count, (vg_mda_used_count(vg))) +GET_VG_NUM_PROPERTY_FN(vg_mda_used_count, (vg_mda_used_count(vg))) #define _vg_mda_used_count_set _not_implemented -GET_NUM_PROPERTY_FN(vg_mda_free, (SECTOR_SIZE * vg_mda_free(vg))) +GET_VG_NUM_PROPERTY_FN(vg_mda_free, (SECTOR_SIZE * vg_mda_free(vg))) #define _vg_mda_free_set _not_implemented -GET_NUM_PROPERTY_FN(vg_mda_size, (SECTOR_SIZE * vg_mda_size(vg))) +GET_VG_NUM_PROPERTY_FN(vg_mda_size, (SECTOR_SIZE * vg_mda_size(vg))) #define _vg_mda_size_set _not_implemented -GET_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg))) +GET_VG_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg))) #define _vg_mda_copies_set _not_implemented /* LVSEG */ From wysochanski@sourceware.org Thu Sep 30 14:08:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:08:00 -0000 Subject: LVM2/lib/metadata vg.c vg.h Message-ID: <20100930140834.17677.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:08:33 Modified files: lib/metadata : vg.c vg.h Log message: Add supporting functions vg_name_dup, vg_fmt_dup, vg_system_id_dup. Add supporting functions for vg_name, vg_fmt, vg_system_id. Append "_dup" to end of supporting functions to make clear the strings are dup'd and to avoid namespace conflict with vg_name. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.c.diff?cvsroot=lvm2&r1=1.5&r2=1.6 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.h.diff?cvsroot=lvm2&r1=1.4&r2=1.5 --- LVM2/lib/metadata/vg.c 2010/09/30 14:08:20 1.5 +++ LVM2/lib/metadata/vg.c 2010/09/30 14:08:33 1.6 @@ -16,6 +16,23 @@ #include "metadata.h" #include "activate.h" +char *vg_fmt_dup(const struct volume_group *vg) +{ + if (!vg->fid || !vg->fid->fmt) + return NULL; + return dm_pool_strdup(vg->vgmem, vg->fid->fmt->name); +} + +char *vg_name_dup(const struct volume_group *vg) +{ + return dm_pool_strdup(vg->vgmem, vg->name); +} + +char *vg_system_id_dup(const struct volume_group *vg) +{ + return dm_pool_strdup(vg->vgmem, vg->system_id); +} + char *vg_uuid_dup(const struct volume_group *vg) { return id_format_and_copy(vg->vgmem, &vg->id); --- LVM2/lib/metadata/vg.h 2010/09/30 14:08:20 1.4 +++ LVM2/lib/metadata/vg.h 2010/09/30 14:08:33 1.5 @@ -93,6 +93,9 @@ uint32_t mda_copies; /* target number of mdas for this VG */ }; +char *vg_fmt_dup(const struct volume_group *vg); +char *vg_name_dup(const struct volume_group *vg); +char *vg_system_id_dup(const struct volume_group *vg); uint32_t vg_seqno(const struct volume_group *vg); uint64_t vg_status(const struct volume_group *vg); int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc); From wysochanski@sourceware.org Thu Sep 30 14:08:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:08:00 -0000 Subject: LVM2/lib/report properties.c Message-ID: <20100930140858.18001.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:08:58 Modified files: lib/report : properties.c Log message: Add 'get' functions for vg fields. Add 'get' functions based on generic macros for VG, PV, and LV. Add 'get' functions for vg string fields, vg_name, vg_fmt, vg_sysid, vg_uuid, vg_attr, and vg_tags, and all numeric fields. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/properties.c.diff?cvsroot=lvm2&r1=1.5&r2=1.6 --- LVM2/lib/report/properties.c 2010/09/30 14:08:46 1.5 +++ LVM2/lib/report/properties.c 2010/09/30 14:08:58 1.6 @@ -135,19 +135,19 @@ #define _modules_set _not_implemented /* VG */ -#define _vg_fmt_get _not_implemented +GET_VG_STR_PROPERTY_FN(vg_fmt, vg_fmt_dup(vg)) #define _vg_fmt_set _not_implemented -#define _vg_uuid_get _not_implemented +GET_VG_STR_PROPERTY_FN(vg_uuid, vg_uuid_dup(vg)) #define _vg_uuid_set _not_implemented -#define _vg_name_get _not_implemented +GET_VG_STR_PROPERTY_FN(vg_name, vg_name_dup(vg)) #define _vg_name_set _not_implemented -#define _vg_attr_get _not_implemented +GET_VG_STR_PROPERTY_FN(vg_attr, vg_attr_dup(vg->vgmem, vg)) #define _vg_attr_set _not_implemented GET_VG_NUM_PROPERTY_FN(vg_size, (SECTOR_SIZE * vg_size(vg))) #define _vg_size_set _not_implemented GET_VG_NUM_PROPERTY_FN(vg_free, (SECTOR_SIZE * vg_free(vg))) #define _vg_free_set _not_implemented -#define _vg_sysid_get _not_implemented +GET_VG_STR_PROPERTY_FN(vg_sysid, vg_system_id_dup(vg)) #define _vg_sysid_set _not_implemented GET_VG_NUM_PROPERTY_FN(vg_extent_size, vg->extent_size) #define _vg_extent_size_set _not_implemented @@ -167,7 +167,7 @@ #define _snap_count_set _not_implemented GET_VG_NUM_PROPERTY_FN(vg_seqno, vg->seqno) #define _vg_seqno_set _not_implemented -#define _vg_tags_get _not_implemented +GET_VG_STR_PROPERTY_FN(vg_tags, vg_tags_dup(vg)) #define _vg_tags_set _not_implemented GET_VG_NUM_PROPERTY_FN(vg_mda_count, (vg_mda_count(vg))) #define _vg_mda_count_set _not_implemented From wysochanski@sourceware.org Thu Sep 30 14:09:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:09:00 -0000 Subject: LVM2/lib/report properties.c Message-ID: <20100930140933.18531.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:09:33 Modified files: lib/report : properties.c Log message: Add pv 'get' functions for all pv properties. Add 'get' functions for all pv properties. Multiply by SECTOR_SIZE for pv properties pv_mda_free, pv_mda_size, pe_start, pv_size, pv_free, pv_used. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/properties.c.diff?cvsroot=lvm2&r1=1.6&r2=1.7 --- LVM2/lib/report/properties.c 2010/09/30 14:08:58 1.6 +++ LVM2/lib/report/properties.c 2010/09/30 14:09:33 1.7 @@ -57,37 +57,37 @@ } /* PV */ -#define _pv_fmt_get _not_implemented +GET_PV_STR_PROPERTY_FN(pv_fmt, pv_fmt_dup(pv)) #define _pv_fmt_set _not_implemented -#define _pv_uuid_get _not_implemented +GET_PV_STR_PROPERTY_FN(pv_uuid, pv_uuid_dup(pv)) #define _pv_uuid_set _not_implemented -#define _dev_size_get _not_implemented +GET_PV_NUM_PROPERTY_FN(dev_size, SECTOR_SIZE * pv_dev_size(pv)) #define _dev_size_set _not_implemented -#define _pv_name_get _not_implemented +GET_PV_STR_PROPERTY_FN(pv_name, pv_name_dup(pv)) #define _pv_name_set _not_implemented -#define _pv_mda_free_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pv_mda_free, SECTOR_SIZE * pv_mda_free(pv)) #define _pv_mda_free_set _not_implemented -#define _pv_mda_size_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pv_mda_size, SECTOR_SIZE * pv_mda_size(pv)) #define _pv_mda_size_set _not_implemented -#define _pe_start_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pe_start, SECTOR_SIZE * pv->pe_start) #define _pe_start_set _not_implemented -#define _pv_size_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pv_size, SECTOR_SIZE * pv_size_field(pv)) #define _pv_size_set _not_implemented -#define _pv_free_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pv_free, SECTOR_SIZE * pv_free(pv)) #define _pv_free_set _not_implemented -#define _pv_used_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pv_used, SECTOR_SIZE * pv_used(pv)) #define _pv_used_set _not_implemented -#define _pv_attr_get _not_implemented +GET_PV_STR_PROPERTY_FN(pv_attr, pv_attr_dup(pv->vg->vgmem, pv)) #define _pv_attr_set _not_implemented -#define _pv_pe_count_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pv_pe_count, pv->pe_count) #define _pv_pe_count_set _not_implemented -#define _pv_pe_alloc_count_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pv_pe_alloc_count, pv->pe_alloc_count) #define _pv_pe_alloc_count_set _not_implemented -#define _pv_tags_get _not_implemented +GET_PV_STR_PROPERTY_FN(pv_tags, pv_tags_dup(pv)) #define _pv_tags_set _not_implemented -#define _pv_mda_count_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pv_mda_count, pv_mda_count(pv)) #define _pv_mda_count_set _not_implemented -#define _pv_mda_used_count_get _not_implemented +GET_PV_NUM_PROPERTY_FN(pv_mda_used_count, pv_mda_used_count(pv)) #define _pv_mda_used_count_set _not_implemented /* LV */ From wysochanski@sourceware.org Thu Sep 30 14:09:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:09:00 -0000 Subject: LVM2/lib/report properties.c properties.h Message-ID: <20100930140946.18705.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:09:46 Modified files: lib/report : properties.c properties.h Log message: Add pv_get_property and create generic internal _get_property function. We need to use a similar function for pv and lv properties, so just make a generic _get_property() function that contains most of the required functionality. Also, add a check to ensure the field name matches the object passed in by re-using report_type_t enum. For pv properties, the report_type might be either PVS or LABEL. In addition, add 'const' to 'get' functions object parameter, but not 'set' functions. Add _not_implemented_set() and _not_implemented_get() functions. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/properties.c.diff?cvsroot=lvm2&r1=1.7&r2=1.8 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/properties.h.diff?cvsroot=lvm2&r1=1.1&r2=1.2 --- LVM2/lib/report/properties.c 2010/09/30 14:09:33 1.7 +++ LVM2/lib/report/properties.c 2010/09/30 14:09:45 1.8 @@ -21,9 +21,9 @@ #include "metadata.h" #define GET_NUM_PROPERTY_FN(NAME, VALUE, TYPE, VAR) \ -static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \ +static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \ { \ - struct TYPE *VAR = (struct TYPE *)obj; \ + const struct TYPE *VAR = (const struct TYPE *)obj; \ \ prop->v.n_val = VALUE; \ return 1; \ @@ -36,9 +36,9 @@ GET_NUM_PROPERTY_FN(NAME, VALUE, logical_volume, lv) #define GET_STR_PROPERTY_FN(NAME, VALUE, TYPE, VAR) \ -static int _ ## NAME ## _get (void *obj, struct lvm_property_type *prop) \ +static int _ ## NAME ## _get (const void *obj, struct lvm_property_type *prop) \ { \ - struct TYPE *VAR = (struct TYPE *)obj; \ + const struct TYPE *VAR = (const struct TYPE *)obj; \ \ prop->v.s_val = (char *)VALUE; \ return 1; \ @@ -50,7 +50,13 @@ #define GET_LV_STR_PROPERTY_FN(NAME, VALUE) \ GET_STR_PROPERTY_FN(NAME, VALUE, logical_volume, lv) -static int _not_implemented(void *obj, struct lvm_property_type *prop) +static int _not_implemented_get(const void *obj, struct lvm_property_type *prop) +{ + log_errno(ENOSYS, "Function not implemented"); + return 0; +} + +static int _not_implemented_set(void *obj, struct lvm_property_type *prop) { log_errno(ENOSYS, "Function not implemented"); return 0; @@ -58,174 +64,174 @@ /* PV */ GET_PV_STR_PROPERTY_FN(pv_fmt, pv_fmt_dup(pv)) -#define _pv_fmt_set _not_implemented +#define _pv_fmt_set _not_implemented_set GET_PV_STR_PROPERTY_FN(pv_uuid, pv_uuid_dup(pv)) -#define _pv_uuid_set _not_implemented +#define _pv_uuid_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(dev_size, SECTOR_SIZE * pv_dev_size(pv)) -#define _dev_size_set _not_implemented +#define _dev_size_set _not_implemented_set GET_PV_STR_PROPERTY_FN(pv_name, pv_name_dup(pv)) -#define _pv_name_set _not_implemented +#define _pv_name_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pv_mda_free, SECTOR_SIZE * pv_mda_free(pv)) -#define _pv_mda_free_set _not_implemented +#define _pv_mda_free_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pv_mda_size, SECTOR_SIZE * pv_mda_size(pv)) -#define _pv_mda_size_set _not_implemented +#define _pv_mda_size_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pe_start, SECTOR_SIZE * pv->pe_start) -#define _pe_start_set _not_implemented +#define _pe_start_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pv_size, SECTOR_SIZE * pv_size_field(pv)) -#define _pv_size_set _not_implemented +#define _pv_size_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pv_free, SECTOR_SIZE * pv_free(pv)) -#define _pv_free_set _not_implemented +#define _pv_free_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pv_used, SECTOR_SIZE * pv_used(pv)) -#define _pv_used_set _not_implemented +#define _pv_used_set _not_implemented_set GET_PV_STR_PROPERTY_FN(pv_attr, pv_attr_dup(pv->vg->vgmem, pv)) -#define _pv_attr_set _not_implemented +#define _pv_attr_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pv_pe_count, pv->pe_count) -#define _pv_pe_count_set _not_implemented +#define _pv_pe_count_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pv_pe_alloc_count, pv->pe_alloc_count) -#define _pv_pe_alloc_count_set _not_implemented +#define _pv_pe_alloc_count_set _not_implemented_set GET_PV_STR_PROPERTY_FN(pv_tags, pv_tags_dup(pv)) -#define _pv_tags_set _not_implemented +#define _pv_tags_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pv_mda_count, pv_mda_count(pv)) -#define _pv_mda_count_set _not_implemented +#define _pv_mda_count_set _not_implemented_set GET_PV_NUM_PROPERTY_FN(pv_mda_used_count, pv_mda_used_count(pv)) -#define _pv_mda_used_count_set _not_implemented +#define _pv_mda_used_count_set _not_implemented_set /* LV */ -#define _lv_uuid_get _not_implemented -#define _lv_uuid_set _not_implemented -#define _lv_name_get _not_implemented -#define _lv_name_set _not_implemented -#define _lv_path_get _not_implemented -#define _lv_path_set _not_implemented -#define _lv_attr_get _not_implemented -#define _lv_attr_set _not_implemented -#define _lv_major_get _not_implemented -#define _lv_major_set _not_implemented -#define _lv_minor_get _not_implemented -#define _lv_minor_set _not_implemented -#define _lv_read_ahead_get _not_implemented -#define _lv_read_ahead_set _not_implemented -#define _lv_kernel_major_get _not_implemented -#define _lv_kernel_major_set _not_implemented -#define _lv_kernel_minor_get _not_implemented -#define _lv_kernel_minor_set _not_implemented -#define _lv_kernel_read_ahead_get _not_implemented -#define _lv_kernel_read_ahead_set _not_implemented -#define _lv_size_get _not_implemented -#define _lv_size_set _not_implemented -#define _seg_count_get _not_implemented -#define _seg_count_set _not_implemented -#define _origin_get _not_implemented -#define _origin_set _not_implemented -#define _origin_size_get _not_implemented -#define _origin_size_set _not_implemented -#define _snap_percent_get _not_implemented -#define _snap_percent_set _not_implemented -#define _copy_percent_get _not_implemented -#define _copy_percent_set _not_implemented -#define _move_pv_get _not_implemented -#define _move_pv_set _not_implemented -#define _convert_lv_get _not_implemented -#define _convert_lv_set _not_implemented -#define _lv_tags_get _not_implemented -#define _lv_tags_set _not_implemented -#define _mirror_log_get _not_implemented -#define _mirror_log_set _not_implemented -#define _modules_get _not_implemented -#define _modules_set _not_implemented +#define _lv_uuid_get _not_implemented_get +#define _lv_uuid_set _not_implemented_set +#define _lv_name_get _not_implemented_get +#define _lv_name_set _not_implemented_set +#define _lv_path_get _not_implemented_get +#define _lv_path_set _not_implemented_set +#define _lv_attr_get _not_implemented_get +#define _lv_attr_set _not_implemented_set +#define _lv_major_get _not_implemented_get +#define _lv_major_set _not_implemented_set +#define _lv_minor_get _not_implemented_get +#define _lv_minor_set _not_implemented_set +#define _lv_read_ahead_get _not_implemented_get +#define _lv_read_ahead_set _not_implemented_set +#define _lv_kernel_major_get _not_implemented_get +#define _lv_kernel_major_set _not_implemented_set +#define _lv_kernel_minor_get _not_implemented_get +#define _lv_kernel_minor_set _not_implemented_set +#define _lv_kernel_read_ahead_get _not_implemented_get +#define _lv_kernel_read_ahead_set _not_implemented_set +#define _lv_size_get _not_implemented_get +#define _lv_size_set _not_implemented_set +#define _seg_count_get _not_implemented_get +#define _seg_count_set _not_implemented_set +#define _origin_get _not_implemented_get +#define _origin_set _not_implemented_set +#define _origin_size_get _not_implemented_get +#define _origin_size_set _not_implemented_set +#define _snap_percent_get _not_implemented_get +#define _snap_percent_set _not_implemented_set +#define _copy_percent_get _not_implemented_get +#define _copy_percent_set _not_implemented_set +#define _move_pv_get _not_implemented_get +#define _move_pv_set _not_implemented_set +#define _convert_lv_get _not_implemented_get +#define _convert_lv_set _not_implemented_set +#define _lv_tags_get _not_implemented_get +#define _lv_tags_set _not_implemented_set +#define _mirror_log_get _not_implemented_get +#define _mirror_log_set _not_implemented_set +#define _modules_get _not_implemented_get +#define _modules_set _not_implemented_set /* VG */ GET_VG_STR_PROPERTY_FN(vg_fmt, vg_fmt_dup(vg)) -#define _vg_fmt_set _not_implemented +#define _vg_fmt_set _not_implemented_set GET_VG_STR_PROPERTY_FN(vg_uuid, vg_uuid_dup(vg)) -#define _vg_uuid_set _not_implemented +#define _vg_uuid_set _not_implemented_set GET_VG_STR_PROPERTY_FN(vg_name, vg_name_dup(vg)) -#define _vg_name_set _not_implemented +#define _vg_name_set _not_implemented_set GET_VG_STR_PROPERTY_FN(vg_attr, vg_attr_dup(vg->vgmem, vg)) -#define _vg_attr_set _not_implemented +#define _vg_attr_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_size, (SECTOR_SIZE * vg_size(vg))) -#define _vg_size_set _not_implemented +#define _vg_size_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_free, (SECTOR_SIZE * vg_free(vg))) -#define _vg_free_set _not_implemented +#define _vg_free_set _not_implemented_set GET_VG_STR_PROPERTY_FN(vg_sysid, vg_system_id_dup(vg)) -#define _vg_sysid_set _not_implemented +#define _vg_sysid_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_extent_size, vg->extent_size) -#define _vg_extent_size_set _not_implemented +#define _vg_extent_size_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_extent_count, vg->extent_count) -#define _vg_extent_count_set _not_implemented +#define _vg_extent_count_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_free_count, vg->free_count) -#define _vg_free_count_set _not_implemented +#define _vg_free_count_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(max_lv, vg->max_lv) -#define _max_lv_set _not_implemented +#define _max_lv_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(max_pv, vg->max_pv) -#define _max_pv_set _not_implemented +#define _max_pv_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(pv_count, vg->pv_count) -#define _pv_count_set _not_implemented +#define _pv_count_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(lv_count, (vg_visible_lvs(vg))) -#define _lv_count_set _not_implemented +#define _lv_count_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(snap_count, (snapshot_count(vg))) -#define _snap_count_set _not_implemented +#define _snap_count_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_seqno, vg->seqno) -#define _vg_seqno_set _not_implemented +#define _vg_seqno_set _not_implemented_set GET_VG_STR_PROPERTY_FN(vg_tags, vg_tags_dup(vg)) -#define _vg_tags_set _not_implemented +#define _vg_tags_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_mda_count, (vg_mda_count(vg))) -#define _vg_mda_count_set _not_implemented +#define _vg_mda_count_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_mda_used_count, (vg_mda_used_count(vg))) -#define _vg_mda_used_count_set _not_implemented +#define _vg_mda_used_count_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_mda_free, (SECTOR_SIZE * vg_mda_free(vg))) -#define _vg_mda_free_set _not_implemented +#define _vg_mda_free_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_mda_size, (SECTOR_SIZE * vg_mda_size(vg))) -#define _vg_mda_size_set _not_implemented +#define _vg_mda_size_set _not_implemented_set GET_VG_NUM_PROPERTY_FN(vg_mda_copies, (vg_mda_copies(vg))) -#define _vg_mda_copies_set _not_implemented +#define _vg_mda_copies_set _not_implemented_set /* LVSEG */ -#define _segtype_get _not_implemented -#define _segtype_set _not_implemented -#define _stripes_get _not_implemented -#define _stripes_set _not_implemented -#define _stripesize_get _not_implemented -#define _stripesize_set _not_implemented -#define _stripe_size_get _not_implemented -#define _stripe_size_set _not_implemented -#define _regionsize_get _not_implemented -#define _regionsize_set _not_implemented -#define _region_size_get _not_implemented -#define _region_size_set _not_implemented -#define _chunksize_get _not_implemented -#define _chunksize_set _not_implemented -#define _chunk_size_get _not_implemented -#define _chunk_size_set _not_implemented -#define _seg_start_get _not_implemented -#define _seg_start_set _not_implemented -#define _seg_start_pe_get _not_implemented -#define _seg_start_pe_set _not_implemented -#define _seg_size_get _not_implemented -#define _seg_size_set _not_implemented -#define _seg_tags_get _not_implemented -#define _seg_tags_set _not_implemented -#define _seg_pe_ranges_get _not_implemented -#define _seg_pe_ranges_set _not_implemented -#define _devices_get _not_implemented -#define _devices_set _not_implemented +#define _segtype_get _not_implemented_get +#define _segtype_set _not_implemented_set +#define _stripes_get _not_implemented_get +#define _stripes_set _not_implemented_set +#define _stripesize_get _not_implemented_get +#define _stripesize_set _not_implemented_set +#define _stripe_size_get _not_implemented_get +#define _stripe_size_set _not_implemented_set +#define _regionsize_get _not_implemented_get +#define _regionsize_set _not_implemented_set +#define _region_size_get _not_implemented_get +#define _region_size_set _not_implemented_set +#define _chunksize_get _not_implemented_get +#define _chunksize_set _not_implemented_set +#define _chunk_size_get _not_implemented_get +#define _chunk_size_set _not_implemented_set +#define _seg_start_get _not_implemented_get +#define _seg_start_set _not_implemented_set +#define _seg_start_pe_get _not_implemented_get +#define _seg_start_pe_set _not_implemented_set +#define _seg_size_get _not_implemented_get +#define _seg_size_set _not_implemented_set +#define _seg_tags_get _not_implemented_get +#define _seg_tags_set _not_implemented_set +#define _seg_pe_ranges_get _not_implemented_get +#define _seg_pe_ranges_set _not_implemented_set +#define _devices_get _not_implemented_get +#define _devices_set _not_implemented_set /* PVSEG */ -#define _pvseg_start_get _not_implemented -#define _pvseg_start_set _not_implemented -#define _pvseg_size_get _not_implemented -#define _pvseg_size_set _not_implemented +#define _pvseg_start_get _not_implemented_get +#define _pvseg_start_set _not_implemented_set +#define _pvseg_size_get _not_implemented_get +#define _pvseg_size_set _not_implemented_set #define STR DM_REPORT_FIELD_TYPE_STRING #define NUM DM_REPORT_FIELD_TYPE_NUMBER #define FIELD(type, strct, sorttype, head, field, width, fn, id, desc, writeable) \ - { #id, writeable, sorttype == STR, { .n_val = 0 }, _ ## id ## _get, _ ## id ## _set }, + { type, #id, writeable, sorttype == STR, { .n_val = 0 }, _ ## id ## _get, _ ## id ## _set }, struct lvm_property_type _properties[] = { #include "columns.h" - { "", 0, 0, { .n_val = 0 }, _not_implemented, _not_implemented }, + { 0, "", 0, 0, { .n_val = 0 }, _not_implemented_get, _not_implemented_set }, }; #undef STR @@ -233,7 +239,8 @@ #undef FIELD -int vg_get_property(struct volume_group *vg, struct lvm_property_type *prop) +static int _get_property(const void *obj, struct lvm_property_type *prop, + report_type_t type) { struct lvm_property_type *p; @@ -247,10 +254,27 @@ log_errno(EINVAL, "Invalid property name %s", prop->id); return 0; } + if (!(p->type & type)) { + log_errno(EINVAL, "Property name %s does not match type %d", + prop->id, p->type); + return 0; + } *prop = *p; - if (!p->get((void *)vg, prop)) { + if (!p->get(obj, prop)) { return 0; } return 1; } + +int vg_get_property(const struct volume_group *vg, + struct lvm_property_type *prop) +{ + return _get_property(vg, prop, VGS); +} + +int pv_get_property(const struct physical_volume *pv, + struct lvm_property_type *prop) +{ + return _get_property(pv, prop, PVS | LABEL); +} --- LVM2/lib/report/properties.h 2010/08/20 12:44:58 1.1 +++ LVM2/lib/report/properties.h 2010/09/30 14:09:45 1.2 @@ -17,10 +17,12 @@ #include "libdevmapper.h" #include "lvm-types.h" #include "metadata.h" +#include "report.h" #define LVM_PROPERTY_NAME_LEN DM_REPORT_FIELD_TYPE_ID_LEN struct lvm_property_type { + report_type_t type; char id[LVM_PROPERTY_NAME_LEN]; unsigned is_writeable; unsigned is_string; @@ -28,10 +30,13 @@ char *s_val; uint64_t n_val; } v; - int (*get) (void *obj, struct lvm_property_type *prop); + int (*get) (const void *obj, struct lvm_property_type *prop); int (*set) (void *obj, struct lvm_property_type *prop); }; -int vg_get_property(struct volume_group *vg, struct lvm_property_type *prop); +int vg_get_property(const struct volume_group *vg, + struct lvm_property_type *prop); +int pv_get_property(const struct physical_volume *pv, + struct lvm_property_type *prop); #endif From wysochanski@sourceware.org Thu Sep 30 14:09:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:09:00 -0000 Subject: LVM2/lib/metadata pv.c pv.h Message-ID: <20100930140922.18362.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:09:22 Modified files: lib/metadata : pv.c pv.h Log message: Add pv_name_dup() and pv_fmt_dup() helper functions. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.c.diff?cvsroot=lvm2&r1=1.6&r2=1.7 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.h.diff?cvsroot=lvm2&r1=1.5&r2=1.6 --- LVM2/lib/metadata/pv.c 2010/09/30 14:09:10 1.6 +++ LVM2/lib/metadata/pv.c 2010/09/30 14:09:22 1.7 @@ -21,6 +21,18 @@ */ #define pv_field(handle, field) ((handle)->field) +char *pv_fmt_dup(const struct physical_volume *pv) +{ + if (!pv->fmt) + return NULL; + return dm_pool_strdup(pv->vg->vgmem, pv->fmt->name); +} + +char *pv_name_dup(const struct physical_volume *pv) +{ + return dm_pool_strdup(pv->vg->vgmem, dev_name(pv->dev)); +} + /* * Gets/Sets for external LVM library */ --- LVM2/lib/metadata/pv.h 2010/09/30 14:09:10 1.5 +++ LVM2/lib/metadata/pv.h 2010/09/30 14:09:22 1.6 @@ -52,6 +52,8 @@ struct dm_list tags; }; +char *pv_fmt_dup(const struct physical_volume *pv); +char *pv_name_dup(const struct physical_volume *pv); struct device *pv_dev(const struct physical_volume *pv); const char *pv_vg_name(const struct physical_volume *pv); char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv); From wysochanski@sourceware.org Thu Sep 30 14:09:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:09:00 -0000 Subject: LVM2/lib metadata/pv.c metadata/pv.h report/re ... Message-ID: <20100930140911.18183.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:09:11 Modified files: lib/metadata : pv.c pv.h lib/report : report.c Log message: Add pv_mda_size, pv_mda_free, and pv_used functions, call from 'disp' functions. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.c.diff?cvsroot=lvm2&r1=1.5&r2=1.6 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.h.diff?cvsroot=lvm2&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/report/report.c.diff?cvsroot=lvm2&r1=1.130&r2=1.131 --- LVM2/lib/metadata/pv.c 2010/09/30 14:08:20 1.5 +++ LVM2/lib/metadata/pv.c 2010/09/30 14:09:10 1.6 @@ -187,6 +187,50 @@ return repstr; } +uint64_t pv_mda_size(const struct physical_volume *pv) +{ + struct lvmcache_info *info; + uint64_t min_mda_size = 0; + const char *pvid = (const char *)(&pv->id.uuid); + + /* PVs could have 2 mdas of different sizes (rounding effect) */ + if ((info = info_from_pvid(pvid, 0))) + min_mda_size = find_min_mda_size(&info->mdas); + return min_mda_size; +} + +uint64_t pv_mda_free(const struct physical_volume *pv) +{ + struct lvmcache_info *info; + uint64_t freespace = UINT64_MAX, mda_free; + const char *pvid = (const char *)&pv->id.uuid; + struct metadata_area *mda; + + if ((info = info_from_pvid(pvid, 0))) + dm_list_iterate_items(mda, &info->mdas) { + if (!mda->ops->mda_free_sectors) + continue; + mda_free = mda->ops->mda_free_sectors(mda); + if (mda_free < freespace) + freespace = mda_free; + } + + if (freespace == UINT64_MAX) + freespace = UINT64_C(0); + return freespace; +} + +uint64_t pv_used(const struct physical_volume *pv) +{ + uint64_t used; + + if (!pv->pe_count) + used = 0LL; + else + used = (uint64_t) pv->pe_alloc_count * pv->pe_size; + return used; +} + unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignored) { struct lvmcache_info *info; --- LVM2/lib/metadata/pv.h 2010/09/30 14:08:20 1.4 +++ LVM2/lib/metadata/pv.h 2010/09/30 14:09:10 1.5 @@ -67,6 +67,9 @@ uint64_t pv_pe_start(const struct physical_volume *pv); uint32_t pv_pe_count(const struct physical_volume *pv); uint32_t pv_pe_alloc_count(const struct physical_volume *pv); +uint64_t pv_mda_size(const struct physical_volume *pv); +uint64_t pv_mda_free(const struct physical_volume *pv); +uint64_t pv_used(const struct physical_volume *pv); uint32_t pv_mda_count(const struct physical_volume *pv); uint32_t pv_mda_used_count(const struct physical_volume *pv); unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored); --- LVM2/lib/report/report.c 2010/09/30 14:08:07 1.130 +++ LVM2/lib/report/report.c 2010/09/30 14:09:10 1.131 @@ -597,10 +597,7 @@ (const struct physical_volume *) data; uint64_t used; - if (!pv->pe_count) - used = 0LL; - else - used = (uint64_t) pv->pe_alloc_count * pv->pe_size; + used = pv_used(pv); return _size64_disp(rh, mem, field, &used, private); } @@ -754,22 +751,11 @@ struct dm_report_field *field, const void *data, void *private) { - struct lvmcache_info *info; - uint64_t freespace = UINT64_MAX, mda_free; - const char *pvid = (const char *)(&((const struct id *) data)->uuid); - struct metadata_area *mda; - - if ((info = info_from_pvid(pvid, 0))) - dm_list_iterate_items(mda, &info->mdas) { - if (!mda->ops->mda_free_sectors) - continue; - mda_free = mda->ops->mda_free_sectors(mda); - if (mda_free < freespace) - freespace = mda_free; - } + const struct physical_volume *pv = + (const struct physical_volume *) data; + uint64_t freespace; - if (freespace == UINT64_MAX) - freespace = UINT64_C(0); + freespace = pv_mda_free(pv); return _size64_disp(rh, mem, field, &freespace, private); } @@ -778,13 +764,11 @@ struct dm_report_field *field, const void *data, void *private) { - struct lvmcache_info *info; - uint64_t min_mda_size = 0; - const char *pvid = (const char *)(&((const struct id *) data)->uuid); - - /* PVs could have 2 mdas of different sizes (rounding effect) */ - if ((info = info_from_pvid(pvid, 0))) - min_mda_size = find_min_mda_size(&info->mdas); + const struct physical_volume *pv = + (const struct physical_volume *) data; + uint64_t min_mda_size; + + min_mda_size = pv_mda_size(pv); return _size64_disp(rh, mem, field, &min_mda_size, private); } From prajnoha@sourceware.org Thu Sep 30 14:12:00 2010 From: prajnoha@sourceware.org (prajnoha@sourceware.org) Date: Thu, 30 Sep 2010 14:12:00 -0000 Subject: LVM2 ./WHATS_NEW lib/format_text/format-text.c Message-ID: <20100930141215.19651.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: prajnoha@sourceware.org 2010-09-30 14:12:14 Modified files: . : WHATS_NEW lib/format_text: format-text.c Log message: Fix memory leak of vg_read while using live copies of metadata in directories. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1741&r2=1.1742 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/format-text.c.diff?cvsroot=lvm2&r1=1.145&r2=1.146 --- LVM2/WHATS_NEW 2010/09/30 11:44:54 1.1741 +++ LVM2/WHATS_NEW 2010/09/30 14:12:14 1.1742 @@ -1,5 +1,6 @@ Version 2.02.75 - ===================================== + Fix memory leak of vg_read while using live copies of metadata in directories. Fix memory leak of config_tree in reinitialization code path. Swap pool destruction order in dmeventd_lvm2_exit() to fix leak report. Read whole /proc/self/maps file before working with maps entries. --- LVM2/lib/format_text/format-text.c 2010/09/27 19:09:35 1.145 +++ LVM2/lib/format_text/format-text.c 2010/09/30 14:12:14 1.146 @@ -1083,9 +1083,11 @@ fid = _text_create_text_instance(fmt, NULL, NULL, NULL); if ((vg = _vg_read_file_name(fid, vgname, - path))) + path))) { /* FIXME Store creation host in vg */ lvmcache_update_vg(vg, 0); + dm_pool_destroy(vg->vgmem); + } } if (closedir(d)) From wysochanski@sourceware.org Thu Sep 30 14:26:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 14:26:00 -0000 Subject: LVM2 WHATS_NEW Message-ID: <20100930142649.29280.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 14:26:49 Modified files: . : WHATS_NEW Log message: Update WHATS_NEW for commits related to generic property functions Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1742&r2=1.1743 --- LVM2/WHATS_NEW 2010/09/30 14:12:14 1.1742 +++ LVM2/WHATS_NEW 2010/09/30 14:26:48 1.1743 @@ -1,5 +1,13 @@ Version 2.02.75 - ===================================== + Add pv_get_property and create generic internal _get_property function. + Add 'get' functions for pv and vg properties/fields. + Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv. + Add tags_format_and_copy() common function and call from _tags_disp. + Add id_format_and_copy() common function and call from _uuid_disp. + Simplify logic to create '{pv|vg|lv}_attr' strings. + Refactor report.c '*_disp' functions to call supporting functions. + Refactor lib/metadata/metadata.[ch] into {pv|vg|lv}.[ch]. Fix memory leak of vg_read while using live copies of metadata in directories. Fix memory leak of config_tree in reinitialization code path. Swap pool destruction order in dmeventd_lvm2_exit() to fix leak report. From wysochanski@sourceware.org Thu Sep 30 20:47:00 2010 From: wysochanski@sourceware.org (wysochanski@sourceware.org) Date: Thu, 30 Sep 2010 20:47:00 -0000 Subject: LVM2/lib/metadata lv.c lv.h metadata.c metadat ... Message-ID: <20100930204719.4998.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: wysochanski@sourceware.org 2010-09-30 20:47:18 Modified files: lib/metadata : lv.c lv.h metadata.c metadata.h pv.c pv.h vg.c vg.h Log message: Fix copyright dates on new files lib/metadata/{lv|vg|pv}.[ch]. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.c.diff?cvsroot=lvm2&r1=1.5&r2=1.6 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/lv.h.diff?cvsroot=lvm2&r1=1.4&r2=1.5 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.c.diff?cvsroot=lvm2&r1=1.402&r2=1.403 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/metadata.h.diff?cvsroot=lvm2&r1=1.221&r2=1.222 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.c.diff?cvsroot=lvm2&r1=1.7&r2=1.8 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/pv.h.diff?cvsroot=lvm2&r1=1.6&r2=1.7 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.c.diff?cvsroot=lvm2&r1=1.6&r2=1.7 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/metadata/vg.h.diff?cvsroot=lvm2&r1=1.5&r2=1.6 --- LVM2/lib/metadata/lv.c 2010/09/30 14:08:19 1.5 +++ LVM2/lib/metadata/lv.c 2010/09/30 20:47:18 1.6 @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * --- LVM2/lib/metadata/lv.h 2010/09/30 14:08:20 1.4 +++ LVM2/lib/metadata/lv.h 2010/09/30 20:47:18 1.5 @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * --- LVM2/lib/metadata/metadata.c 2010/09/30 14:08:07 1.402 +++ LVM2/lib/metadata/metadata.c 2010/09/30 20:47:18 1.403 @@ -1,6 +1,6 @@ /* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. - * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * --- LVM2/lib/metadata/metadata.h 2010/09/30 14:08:07 1.221 +++ LVM2/lib/metadata/metadata.h 2010/09/30 20:47:18 1.222 @@ -1,6 +1,6 @@ /* * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. - * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. + * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * --- LVM2/lib/metadata/pv.c 2010/09/30 14:09:22 1.7 +++ LVM2/lib/metadata/pv.c 2010/09/30 20:47:18 1.8 @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * --- LVM2/lib/metadata/pv.h 2010/09/30 14:09:22 1.6 +++ LVM2/lib/metadata/pv.h 2010/09/30 20:47:18 1.7 @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * --- LVM2/lib/metadata/vg.c 2010/09/30 14:08:33 1.6 +++ LVM2/lib/metadata/vg.c 2010/09/30 20:47:18 1.7 @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * --- LVM2/lib/metadata/vg.h 2010/09/30 14:08:33 1.5 +++ LVM2/lib/metadata/vg.h 2010/09/30 20:47:18 1.6 @@ -1,5 +1,6 @@ /* - * Copyright (C) 2010 Red Hat, Inc. All rights reserved. + * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved. + * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved. * * This file is part of LVM2. * From agk@sourceware.org Thu Sep 30 21:06:00 2010 From: agk@sourceware.org (agk@sourceware.org) Date: Thu, 30 Sep 2010 21:06:00 -0000 Subject: LVM2 ./WHATS_NEW daemons/dmeventd/dmeventd.c l ... Message-ID: <20100930210655.12746.qmail@sourceware.org> CVSROOT: /cvs/lvm2 Module name: LVM2 Changes by: agk@sourceware.org 2010-09-30 21:06:53 Modified files: . : WHATS_NEW daemons/dmeventd: dmeventd.c lib/cache : lvmcache.c lib/commands : toolcontext.c lib/config : config.c lib/filters : filter-persistent.c lib/format1 : disk-rep.c format1.c import-export.c lib/format_text: export.c lib/label : label.c libdm : libdevmapper.h libdm-common.c libdm-deptree.c libdm-report.c libdm/datastruct: bitset.c hash.c libdm/mm : dbg_malloc.c pool-fast.c libdm/regex : matcher.c tools : dmsetup.c Log message: Add dm_zalloc and use it and dm_pool_zalloc throughout. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1743&r2=1.1744 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/dmeventd.c.diff?cvsroot=lvm2&r1=1.65&r2=1.66 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/cache/lvmcache.c.diff?cvsroot=lvm2&r1=1.94&r2=1.95 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/commands/toolcontext.c.diff?cvsroot=lvm2&r1=1.104&r2=1.105 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/config/config.c.diff?cvsroot=lvm2&r1=1.81&r2=1.82 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/filters/filter-persistent.c.diff?cvsroot=lvm2&r1=1.45&r2=1.46 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format1/disk-rep.c.diff?cvsroot=lvm2&r1=1.81&r2=1.82 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format1/format1.c.diff?cvsroot=lvm2&r1=1.122&r2=1.123 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format1/import-export.c.diff?cvsroot=lvm2&r1=1.114&r2=1.115 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/format_text/export.c.diff?cvsroot=lvm2&r1=1.78&r2=1.79 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/label/label.c.diff?cvsroot=lvm2&r1=1.51&r2=1.52 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdevmapper.h.diff?cvsroot=lvm2&r1=1.125&r2=1.126 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdm-common.c.diff?cvsroot=lvm2&r1=1.99&r2=1.100 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdm-deptree.c.diff?cvsroot=lvm2&r1=1.85&r2=1.86 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/libdm-report.c.diff?cvsroot=lvm2&r1=1.36&r2=1.37 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/datastruct/bitset.c.diff?cvsroot=lvm2&r1=1.11&r2=1.12 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/datastruct/hash.c.diff?cvsroot=lvm2&r1=1.11&r2=1.12 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/mm/dbg_malloc.c.diff?cvsroot=lvm2&r1=1.20&r2=1.21 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/mm/pool-fast.c.diff?cvsroot=lvm2&r1=1.9&r2=1.10 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/regex/matcher.c.diff?cvsroot=lvm2&r1=1.12&r2=1.13 http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/dmsetup.c.diff?cvsroot=lvm2&r1=1.144&r2=1.145 --- LVM2/WHATS_NEW 2010/09/30 14:26:48 1.1743 +++ LVM2/WHATS_NEW 2010/09/30 21:06:50 1.1744 @@ -1,8 +1,9 @@ Version 2.02.75 - ===================================== + Add dm_zalloc and use it and dm_pool_zalloc throughout. Add pv_get_property and create generic internal _get_property function. Add 'get' functions for pv and vg properties/fields. - Make generic GET_*_PROPERTY_FN macros and define secondary macro for vg, pv, lv. + Make generic GET_*_PROPERTY_FN macros with secondary macro for vg, pv & lv. Add tags_format_and_copy() common function and call from _tags_disp. Add id_format_and_copy() common function and call from _uuid_disp. Simplify logic to create '{pv|vg|lv}_attr' strings. --- LVM2/daemons/dmeventd/dmeventd.c 2010/08/16 18:19:46 1.65 +++ LVM2/daemons/dmeventd/dmeventd.c 2010/09/30 21:06:50 1.66 @@ -223,12 +223,11 @@ static struct thread_status *_alloc_thread_status(struct message_data *data, struct dso_data *dso_data) { - struct thread_status *ret = (typeof(ret)) dm_malloc(sizeof(*ret)); + struct thread_status *ret = (typeof(ret)) dm_zalloc(sizeof(*ret)); if (!ret) return NULL; - memset(ret, 0, sizeof(*ret)); if (!(ret->device.uuid = dm_strdup(data->device_uuid))) { dm_free(ret); return NULL; @@ -259,12 +258,11 @@ /* Allocate/free DSO data. */ static struct dso_data *_alloc_dso_data(struct message_data *data) { - struct dso_data *ret = (typeof(ret)) dm_malloc(sizeof(*ret)); + struct dso_data *ret = (typeof(ret)) dm_zalloc(sizeof(*ret)); if (!ret) return NULL; - memset(ret, 0, sizeof(*ret)); if (!(ret->dso_name = dm_strdup(data->dso_name))) { dm_free(ret); return NULL; --- LVM2/lib/cache/lvmcache.c 2010/09/22 01:36:14 1.94 +++ LVM2/lib/cache/lvmcache.c 2010/09/30 21:06:51 1.95 @@ -1064,11 +1064,10 @@ } } else { ***/ - if (!(vginfo = dm_malloc(sizeof(*vginfo)))) { + if (!(vginfo = dm_zalloc(sizeof(*vginfo)))) { log_error("lvmcache_update_vgname: list alloc failed"); return 0; } - memset(vginfo, 0, sizeof(*vginfo)); if (!(vginfo->vgname = dm_strdup(vgname))) { dm_free(vginfo); log_error("cache vgname alloc failed for %s", vgname); @@ -1261,12 +1260,11 @@ !(existing = info_from_pvid(dev->pvid, 0))) { if (!(label = label_create(labeller))) return_NULL; - if (!(info = dm_malloc(sizeof(*info)))) { + if (!(info = dm_zalloc(sizeof(*info)))) { log_error("lvmcache_info allocation failed"); label_destroy(label); return NULL; } - memset(info, 0, sizeof(*info)); label->info = info; info->label = label; --- LVM2/lib/commands/toolcontext.c 2010/09/09 13:07:14 1.104 +++ LVM2/lib/commands/toolcontext.c 2010/09/30 21:06:51 1.105 @@ -1121,11 +1121,10 @@ init_syslog(DEFAULT_LOG_FACILITY); - if (!(cmd = dm_malloc(sizeof(*cmd)))) { + if (!(cmd = dm_zalloc(sizeof(*cmd)))) { log_error("Failed to allocate command context"); return NULL; } - memset(cmd, 0, sizeof(*cmd)); cmd->is_long_lived = is_long_lived; cmd->handles_missing_pvs = 0; cmd->handles_unknown_segments = 0; --- LVM2/lib/config/config.c 2010/09/27 19:09:34 1.81 +++ LVM2/lib/config/config.c 2010/09/30 21:06:51 1.82 @@ -724,6 +724,8 @@ { int values_allowed = 0; + const char *te; + p->tb = p->te; _eat_space(p); if (p->tb == p->fe || !*p->tb) { @@ -738,59 +740,61 @@ p->t = TOK_INT; /* fudge so the fall through for floats works */ - switch (*p->te) { + + te = p->te; + switch (*te) { case SECTION_B_CHAR: p->t = TOK_SECTION_B; - p->te++; + te++; break; case SECTION_E_CHAR: p->t = TOK_SECTION_E; - p->te++; + te++; break; case '[': p->t = TOK_ARRAY_B; - p->te++; + te++; break; case ']': p->t = TOK_ARRAY_E; - p->te++; + te++; break; case ',': p->t = TOK_COMMA; - p->te++; + te++; break; case '=': p->t = TOK_EQ; - p->te++; + te++; break; case '"': p->t = TOK_STRING_ESCAPED; - p->te++; - while ((p->te != p->fe) && (*p->te) && (*p->te != '"')) { - if ((*p->te == '\\') && (p->te + 1 != p->fe) && - *(p->te + 1)) - p->te++; - p->te++; + te++; + while ((te != p->fe) && (*te) && (*te != '"')) { + if ((*te == '\\') && (te + 1 != p->fe) && + *(te + 1)) + te++; + te++; } - if ((p->te != p->fe) && (*p->te)) - p->te++; + if ((te != p->fe) && (*te)) + te++; break; case '\'': p->t = TOK_STRING; - p->te++; - while ((p->te != p->fe) && (*p->te) && (*p->te != '\'')) - p->te++; + te++; + while ((te != p->fe) && (*te) && (*te != '\'')) + te++; - if ((p->te != p->fe) && (*p->te)) - p->te++; + if ((te != p->fe) && (*te)) + te++; break; case '.': @@ -808,28 +812,30 @@ case '+': case '-': if (values_allowed) { - p->te++; - while ((p->te != p->fe) && (*p->te)) { - if (*p->te == '.') { + te++; + while ((te != p->fe) && (*te)) { + if (*te == '.') { if (p->t == TOK_FLOAT) break; p->t = TOK_FLOAT; - } else if (!isdigit((int) *p->te)) + } else if (!isdigit((int) *te)) break; - p->te++; + te++; } break; } default: p->t = TOK_IDENTIFIER; - while ((p->te != p->fe) && (*p->te) && !isspace(*p->te) && - (*p->te != '#') && (*p->te != '=') && - (*p->te != SECTION_B_CHAR) && - (*p->te != SECTION_E_CHAR)) - p->te++; + while ((te != p->fe) && (*te) && !isspace(*te) && + (*te != '#') && (*te != '=') && + (*te != SECTION_B_CHAR) && + (*te != SECTION_E_CHAR)) + te++; break; } + + p->te = te; } static void _eat_space(struct parser *p) @@ -859,22 +865,12 @@ */ static struct config_value *_create_value(struct dm_pool *mem) { - struct config_value *v = dm_pool_alloc(mem, sizeof(*v)); - - if (v) - memset(v, 0, sizeof(*v)); - - return v; + return dm_pool_zalloc(mem, sizeof(struct config_value)); } static struct config_node *_create_node(struct dm_pool *mem) { - struct config_node *n = dm_pool_alloc(mem, sizeof(*n)); - - if (n) - memset(n, 0, sizeof(*n)); - - return n; + return dm_pool_zalloc(mem, sizeof(struct config_node)); } static char *_dup_tok(struct parser *p) --- LVM2/lib/filters/filter-persistent.c 2010/09/22 01:36:14 1.45 +++ LVM2/lib/filters/filter-persistent.c 2010/09/30 21:06:51 1.46 @@ -318,9 +318,8 @@ struct dev_filter *f = NULL; struct stat info; - if (!(pf = dm_malloc(sizeof(*pf)))) + if (!(pf = dm_zalloc(sizeof(*pf)))) return_NULL; - memset(pf, 0, sizeof(*pf)); if (!(pf->file = dm_malloc(strlen(file) + 1))) goto_bad; --- LVM2/lib/format1/disk-rep.c 2010/07/09 15:34:44 1.81 +++ LVM2/lib/format1/disk-rep.c 2010/09/30 21:06:51 1.82 @@ -624,13 +624,12 @@ /* Make sure that the gap between the PV structure and the next one is zeroed in order to make non LVM tools happy (idea from AED) */ - buf = dm_malloc(size); + buf = dm_zalloc(size); if (!buf) { log_error("Couldn't allocate temporary PV buffer."); return 0; } - memset(buf, 0, size); memcpy(buf, &data->pvd, sizeof(struct pv_disk)); log_debug("Writing %s PV metadata to %s at %" PRIu64 " len %" --- LVM2/lib/format1/format1.c 2010/09/22 13:45:22 1.122 +++ LVM2/lib/format1/format1.c 2010/09/30 21:06:51 1.123 @@ -157,7 +157,7 @@ struct dm_list *pvs, struct dm_pool *mem) { - struct volume_group *vg = dm_pool_alloc(mem, sizeof(*vg)); + struct volume_group *vg = dm_pool_zalloc(mem, sizeof(*vg)); struct disk_list *dl; if (!vg) @@ -166,8 +166,6 @@ if (dm_list_empty(pvs)) goto_bad; - memset(vg, 0, sizeof(*vg)); - vg->cmd = fid->fmt->cmd; vg->vgmem = mem; vg->fid = fid; --- LVM2/lib/format1/import-export.c 2010/07/09 15:34:44 1.114 +++ LVM2/lib/format1/import-export.c 2010/09/30 21:06:51 1.115 @@ -506,9 +506,8 @@ * setup the pv's extents array */ len = sizeof(struct pe_disk) * dl->pvd.pe_total; - if (!(dl->extents = dm_pool_alloc(dl->mem, len))) + if (!(dl->extents = dm_pool_zalloc(dl->mem, len))) goto_out; - memset(dl->extents, 0, len); dm_list_iterate_items(ll, &vg->lvs) { if (ll->lv->status & SNAPSHOT) --- LVM2/lib/format_text/export.c 2010/09/20 14:23:20 1.78 +++ LVM2/lib/format_text/export.c 2010/09/30 21:06:51 1.79 @@ -742,10 +742,9 @@ _init(); - if (!(f = dm_malloc(sizeof(*f)))) + if (!(f = dm_zalloc(sizeof(*f)))) return_0; - memset(f, 0, sizeof(*f)); f->data.fp = fp; f->indent = 0; f->header = 1; @@ -767,11 +766,9 @@ _init(); - if (!(f = dm_malloc(sizeof(*f)))) + if (!(f = dm_zalloc(sizeof(*f)))) return_0; - memset(f, 0, sizeof(*f)); - f->data.buf.size = 65536; /* Initial metadata limit */ if (!(f->data.buf.start = dm_malloc(f->data.buf.size))) { log_error("text_export buffer allocation failed"); --- LVM2/lib/label/label.c 2010/09/27 19:09:35 1.51 +++ LVM2/lib/label/label.c 2010/09/30 21:06:52 1.52 @@ -383,11 +383,10 @@ { struct label *label; - if (!(label = dm_malloc(sizeof(*label)))) { + if (!(label = dm_zalloc(sizeof(*label)))) { log_error("label allocaction failed"); return NULL; } - memset(label, 0, sizeof(*label)); label->labeller = labeller; --- LVM2/libdm/libdevmapper.h 2010/08/20 12:44:30 1.125 +++ LVM2/libdm/libdevmapper.h 2010/09/30 21:06:52 1.126 @@ -511,6 +511,8 @@ void *dm_malloc_aux(size_t s, const char *file, int line); void *dm_malloc_aux_debug(size_t s, const char *file, int line); +void *dm_zalloc_aux(size_t s, const char *file, int line); +void *dm_zalloc_aux_debug(size_t s, const char *file, int line); char *dm_strdup_aux(const char *str, const char *file, int line); void dm_free_aux(void *p); void *dm_realloc_aux(void *p, unsigned int s, const char *file, int line); @@ -520,6 +522,7 @@ #ifdef DEBUG_MEM # define dm_malloc(s) dm_malloc_aux_debug((s), __FILE__, __LINE__) +# define dm_zalloc(s) dm_zalloc_aux_debug((s), __FILE__, __LINE__) # define dm_strdup(s) dm_strdup_aux((s), __FILE__, __LINE__) # define dm_free(p) dm_free_aux(p) # define dm_realloc(p, s) dm_realloc_aux(p, s, __FILE__, __LINE__) @@ -529,6 +532,7 @@ #else # define dm_malloc(s) dm_malloc_aux((s), __FILE__, __LINE__) +# define dm_zalloc(s) dm_zalloc_aux((s), __FILE__, __LINE__) # define dm_strdup(s) strdup(s) # define dm_free(p) free(p) # define dm_realloc(p, s) realloc(p, s) --- LVM2/libdm/libdm-common.c 2010/08/03 13:06:36 1.99 +++ LVM2/libdm/libdm-common.c 2010/09/30 21:06:52 1.100 @@ -166,7 +166,7 @@ struct dm_task *dm_task_create(int type) { - struct dm_task *dmt = dm_malloc(sizeof(*dmt)); + struct dm_task *dmt = dm_zalloc(sizeof(*dmt)); if (!dmt) { log_error("dm_task_create: malloc(%" PRIsize_t ") failed", @@ -179,8 +179,6 @@ return NULL; } - memset(dmt, 0, sizeof(*dmt)); - dmt->type = type; dmt->minor = -1; dmt->major = -1; --- LVM2/libdm/libdm-deptree.c 2010/07/09 15:34:47 1.85 +++ LVM2/libdm/libdm-deptree.c 2010/09/30 21:06:52 1.86 @@ -197,12 +197,11 @@ { struct dm_tree *dtree; - if (!(dtree = dm_malloc(sizeof(*dtree)))) { + if (!(dtree = dm_zalloc(sizeof(*dtree)))) { log_error("dm_tree_create malloc failed"); return NULL; } - memset(dtree, 0, sizeof(*dtree)); dtree->root.dtree = dtree; dm_list_init(&dtree->root.uses); dm_list_init(&dtree->root.used_by); --- LVM2/libdm/libdm-report.c 2010/06/16 13:01:25 1.36 +++ LVM2/libdm/libdm-report.c 2010/09/30 21:06:52 1.37 @@ -571,11 +571,10 @@ struct dm_report *rh; const struct dm_report_object_type *type; - if (!(rh = dm_malloc(sizeof(*rh)))) { + if (!(rh = dm_zalloc(sizeof(*rh)))) { log_error("dm_report_init: dm_malloc failed"); return 0; } - memset(rh, 0, sizeof(*rh)); /* * rh->report_types is updated in _parse_fields() and _parse_keys() --- LVM2/libdm/datastruct/bitset.c 2010/07/08 12:16:16 1.11 +++ LVM2/libdm/datastruct/bitset.c 2010/09/30 21:06:52 1.12 @@ -26,8 +26,8 @@ if (mem) bs = dm_pool_zalloc(mem, size); - else if ((bs = dm_malloc(size))) - memset(bs, 0, size); + else + bs = dm_zalloc(size); if (!bs) return NULL; --- LVM2/libdm/datastruct/hash.c 2010/07/09 15:34:47 1.11 +++ LVM2/libdm/datastruct/hash.c 2010/09/30 21:06:52 1.12 @@ -90,14 +90,10 @@ { size_t len; unsigned new_size = 16u; - struct dm_hash_table *hc = dm_malloc(sizeof(*hc)); + struct dm_hash_table *hc = dm_zalloc(sizeof(*hc)); - if (!hc) { - stack; - return 0; - } - - memset(hc, 0, sizeof(*hc)); + if (!hc) + return_0; /* round size hint up to a power of two */ while (new_size < size_hint) --- LVM2/libdm/mm/dbg_malloc.c 2010/08/09 10:56:01 1.20 +++ LVM2/libdm/mm/dbg_malloc.c 2010/09/30 21:06:52 1.21 @@ -119,6 +119,16 @@ return nb + 1; } +void *dm_zalloc_aux_debug(size_t s, const char *file, int line) +{ + void *ptr = dm_malloc_aux_debug(s, file, line); + + if (ptr) + memset(ptr, 0, s); + + return ptr; +} + void dm_free_aux(void *p) { char *ptr; @@ -250,3 +260,13 @@ return malloc(s); } + +void *dm_zalloc_aux(size_t s, const char *file, int line) +{ + void *ptr = dm_malloc_aux(s, file, line); + + if (ptr) + memset(ptr, 0, s); + + return ptr; +} --- LVM2/libdm/mm/pool-fast.c 2010/08/09 10:56:01 1.9 +++ LVM2/libdm/mm/pool-fast.c 2010/09/30 21:06:52 1.10 @@ -43,14 +43,13 @@ struct dm_pool *dm_pool_create(const char *name, size_t chunk_hint) { size_t new_size = 1024; - struct dm_pool *p = dm_malloc(sizeof(*p)); + struct dm_pool *p = dm_zalloc(sizeof(*p)); if (!p) { log_error("Couldn't create memory pool %s (size %" PRIsize_t ")", name, sizeof(*p)); return 0; } - memset(p, 0, sizeof(*p)); /* round chunk_hint up to the next power of 2 */ p->chunk_size = chunk_hint + sizeof(struct chunk); --- LVM2/libdm/regex/matcher.c 2010/08/09 10:30:52 1.12 +++ LVM2/libdm/regex/matcher.c 2010/09/30 21:06:52 1.13 @@ -320,11 +320,9 @@ struct dm_regex *m; struct dm_pool *scratch = mem; - if (!(m = dm_pool_alloc(mem, sizeof(*m)))) + if (!(m = dm_pool_zalloc(mem, sizeof(*m)))) return_NULL; - memset(m, 0, sizeof(*m)); - /* join the regexps together, delimiting with zero */ for (i = 0; i < num_patterns; i++) len += strlen(patterns[i]) + 8; --- LVM2/tools/dmsetup.c 2010/08/03 13:04:32 1.144 +++ LVM2/tools/dmsetup.c 2010/09/30 21:06:53 1.145 @@ -730,13 +730,11 @@ for (i = 0; i < argc; i++) sz += strlen(argv[i]) + 1; - if (!(str = dm_malloc(sz))) { + if (!(str = dm_zalloc(sz))) { err("message string allocation failed"); goto out; } - memset(str, 0, sz); - for (i = 0; i < argc; i++) { if (i) strcat(str, " ");