diff --git a/WHATS_NEW b/WHATS_NEW index 648c00793..84325f35a 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.02.10 - ================================== + Move split_words() and split_dm_name() into libdevmapper. Add lvconvert man page. Add mirror options to man pages. Prevent mirror renames. diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 135a8764d..01d95e60c 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.10 - ============================== + Add dm_split_words() and dm_split_lvm_name() to libdevmapper. Reorder mm bounds_check code to reduce window for a dmeventd race. Version 1.02.09 - 15 Aug 2006 diff --git a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c index b4623a376..b459f4dc4 100644 --- a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c +++ b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c @@ -48,7 +48,7 @@ static int _get_mirror_event(char *params) char *p; int log_argc, num_devs, num_failures=0; - if (max_args <= split_words(params, max_args, args)) { + if (max_args <= dm_split_words(params, max_args, 0, args)) { syslog(LOG_ERR, "Unable to split mirror parameters: Arg list too long"); return -E2BIG; } @@ -121,7 +121,7 @@ static int _remove_failed_devices(const char *device) if (strlen(device) > 200) return -ENAMETOOLONG; - if (!split_dm_name(mem_pool, device, &vg, &lv, &layer)) { + if (!dm_split_lvm_name(mem_pool, device, &vg, &lv, &layer)) { syslog(LOG_ERR, "Unable to determine VG name from %s", device); return -ENOMEM; diff --git a/dmeventd/mirror/dmeventd_mirror.c b/dmeventd/mirror/dmeventd_mirror.c index b4623a376..b459f4dc4 100644 --- a/dmeventd/mirror/dmeventd_mirror.c +++ b/dmeventd/mirror/dmeventd_mirror.c @@ -48,7 +48,7 @@ static int _get_mirror_event(char *params) char *p; int log_argc, num_devs, num_failures=0; - if (max_args <= split_words(params, max_args, args)) { + if (max_args <= dm_split_words(params, max_args, 0, args)) { syslog(LOG_ERR, "Unable to split mirror parameters: Arg list too long"); return -E2BIG; } @@ -121,7 +121,7 @@ static int _remove_failed_devices(const char *device) if (strlen(device) > 200) return -ENAMETOOLONG; - if (!split_dm_name(mem_pool, device, &vg, &lv, &layer)) { + if (!dm_split_lvm_name(mem_pool, device, &vg, &lv, &layer)) { syslog(LOG_ERR, "Unable to determine VG name from %s", device); return -ENOMEM; diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c index 6d9407996..50275dde2 100644 --- a/lib/activate/dev_manager.c +++ b/lib/activate/dev_manager.c @@ -912,7 +912,7 @@ static int _create_lv_symlinks(struct dev_manager *dm, struct dm_tree_node *root name = dm_tree_node_get_name(child); if (name && lvlayer->old_name && *lvlayer->old_name && strcmp(name, lvlayer->old_name)) { - if (!split_dm_name(dm->mem, lvlayer->old_name, &vgname, &lvname, &layer)) { + if (!dm_split_lvm_name(dm->mem, lvlayer->old_name, &vgname, &lvname, &layer)) { log_error("_create_lv_symlinks: Couldn't split up old device name %s", lvlayer->old_name); return 0; } @@ -938,7 +938,7 @@ static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root) if (!(uuid = dm_tree_node_get_uuid(child))) continue; - if (!split_dm_name(dm->mem, name, &vgname, &lvname, &layer)) { + if (!dm_split_lvm_name(dm->mem, name, &vgname, &lvname, &layer)) { log_error("_clean_tree: Couldn't split up device name %s.", name); return 0; } diff --git a/lib/filters/filter-sysfs.c b/lib/filters/filter-sysfs.c index bbc84a50c..e1df587d1 100644 --- a/lib/filters/filter-sysfs.c +++ b/lib/filters/filter-sysfs.c @@ -44,7 +44,7 @@ static int _locate_sysfs_blocks(const char *proc, char *path, size_t len) } while (fgets(buffer, sizeof(buffer), fp)) { - if (split_words(buffer, 4, split) == 4 && + if (dm_split_words(buffer, 4, 0, split) == 4 && !strcmp(split[2], "sysfs")) { if (lvm_snprintf(path, len, "%s/%s", split[1], "block") >= 0) { diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c index 528c3b26f..7b56b552a 100644 --- a/lib/misc/lvm-string.c +++ b/lib/misc/lvm-string.c @@ -17,8 +17,6 @@ #include "lvm-types.h" #include "lvm-string.h" -#include - /* * On error, up to glibc 2.0.6, snprintf returned -1 if buffer was too small; * From glibc 2.1 it returns number of chars (excl. trailing null) that would @@ -58,47 +56,6 @@ int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...) return 1; } -/* - * consume characters while they match the predicate function. - */ -static char *_consume(char *buffer, int (*fn) (int)) -{ - while (*buffer && fn(*buffer)) - buffer++; - - return buffer; -} - -static int _isword(int c) -{ - return !isspace(c); -} - -/* - * Split buffer into NULL-separated words in argv. - * Returns number of words. - */ -int split_words(char *buffer, unsigned max, char **argv) -{ - unsigned arg; - - for (arg = 0; arg < max; arg++) { - buffer = _consume(buffer, isspace); - if (!*buffer) - break; - - argv[arg] = buffer; - buffer = _consume(buffer, _isword); - - if (*buffer) { - *buffer = '\0'; - buffer++; - } - } - - return arg; -} - /* * Device layer names are all of the form --, any * other hyphens that appear in these names are quoted with yet @@ -169,47 +126,6 @@ char *build_dm_name(struct dm_pool *mem, const char *vgname, return r; } -/* - * Remove hyphen quoting from a component of a name. - * NULL-terminates the component and returns start of next component. - */ -static char *_unquote(char *component) -{ - char *c = component; - char *o = c; - char *r; - - while (*c) { - if (*(c + 1)) { - if (*c == '-') { - if (*(c + 1) == '-') - c++; - else - break; - } - } - *o = *c; - o++; - c++; - } - - r = (*c) ? c + 1 : c; - *o = '\0'; - - return r; -} - -int split_dm_name(struct dm_pool *mem, const char *dmname, - char **vgname, char **lvname, char **layer) -{ - if (!(*vgname = dm_pool_strdup(mem, dmname))) - return 0; - - _unquote(*layer = _unquote(*lvname = _unquote(*vgname))); - - return 1; -} - int validate_name(const char *n) { register char c; diff --git a/lib/misc/lvm-string.h b/lib/misc/lvm-string.h index 45fac09f9..dc0cb92d4 100644 --- a/lib/misc/lvm-string.h +++ b/lib/misc/lvm-string.h @@ -34,14 +34,9 @@ int lvm_snprintf(char *buf, size_t bufsize, const char *format, ...); int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...); -int split_words(char *buffer, unsigned max, char **argv); - char *build_dm_name(struct dm_pool *mem, const char *vg, const char *lv, const char *layer); -int split_dm_name(struct dm_pool *mem, const char *dmname, - char **vgname, char **lvname, char **layer); - int validate_name(const char *n); #endif diff --git a/libdm/.exported_symbols b/libdm/.exported_symbols index 2407f0ab6..263d2ad61 100644 --- a/libdm/.exported_symbols +++ b/libdm/.exported_symbols @@ -109,3 +109,5 @@ dm_hash_get_first dm_hash_get_next dm_set_selinux_context dm_task_set_geometry +dm_split_lvm_name +dm_split_words diff --git a/libdm/Makefile.in b/libdm/Makefile.in index fd642922b..0f3deba17 100644 --- a/libdm/Makefile.in +++ b/libdm/Makefile.in @@ -23,6 +23,7 @@ SOURCES =\ libdm-common.c \ libdm-file.c \ libdm-deptree.c \ + libdm-string.c \ mm/dbg_malloc.c \ mm/pool.c \ $(interface)/libdm-iface.c diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h index ecfd72c6e..c979e8728 100644 --- a/libdm/libdevmapper.h +++ b/libdm/libdevmapper.h @@ -582,4 +582,23 @@ struct dm_hash_node *dm_hash_get_next(struct dm_hash_table *t, struct dm_hash_no *********/ int dm_set_selinux_context(const char *path, mode_t mode); +/********************* + * string manipulation + *********************/ + +/* + * Break up the name of a mapped device into its constituent + * Volume Group, Logical Volume and Layer (if present). + */ +int dm_split_lvm_name(struct dm_pool *mem, const char *dmname, + char **vgname, char **lvname, char **layer); + +/* + * Destructively split buffer into NULL-separated words in argv. + * Returns number of words. + */ +int dm_split_words(char *buffer, unsigned max, + unsigned ignore_comments, /* Not implemented */ + char **argv); + #endif /* LIB_DEVICE_MAPPER_H */ diff --git a/libdm/libdm-string.c b/libdm/libdm-string.c new file mode 100644 index 000000000..4ce660807 --- /dev/null +++ b/libdm/libdm-string.c @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2006 Red Hat, Inc. All rights reserved. + * + * This file is part of the device-mapper userspace tools. + * + * 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 General Public License v.2. + * + * You should have received a copy of the GNU 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 "libdevmapper.h" + +#include + +/* + * consume characters while they match the predicate function. + */ +static char *_consume(char *buffer, int (*fn) (int)) +{ + while (*buffer && fn(*buffer)) + buffer++; + + return buffer; +} + +static int _isword(int c) +{ + return !isspace(c); +} + +/* + * Split buffer into NULL-separated words in argv. + * Returns number of words. + */ +int dm_split_words(char *buffer, unsigned max, unsigned ignore_comments, + char **argv) +{ + unsigned arg; + + for (arg = 0; arg < max; arg++) { + buffer = _consume(buffer, isspace); + if (!*buffer) + break; + + argv[arg] = buffer; + buffer = _consume(buffer, _isword); + + if (*buffer) { + *buffer = '\0'; + buffer++; + } + } + + return arg; +} + +/* + * Remove hyphen quoting from a component of a name. + * NULL-terminates the component and returns start of next component. + */ +static char *_unquote(char *component) +{ + char *c = component; + char *o = c; + char *r; + + while (*c) { + if (*(c + 1)) { + if (*c == '-') { + if (*(c + 1) == '-') + c++; + else + break; + } + } + *o = *c; + o++; + c++; + } + + r = (*c) ? c + 1 : c; + *o = '\0'; + + return r; +} + +int dm_split_lvm_name(struct dm_pool *mem, const char *dmname, + char **vgname, char **lvname, char **layer) +{ + if (!(*vgname = dm_pool_strdup(mem, dmname))) + return 0; + + _unquote(*layer = _unquote(*lvname = _unquote(*vgname))); + + return 1; +} diff --git a/man/Makefile.in b/man/Makefile.in index 85a912347..174dfee5a 100644 --- a/man/Makefile.in +++ b/man/Makefile.in @@ -17,7 +17,7 @@ top_srcdir = @top_srcdir@ VPATH = @srcdir@ MAN5=lvm.conf.5 -MAN8=lvchange.8 lvconvert.8 lvcreate.8 lvdisplay.8 lvextend.8 lvm.8 +MAN8=lvchange.8 lvconvert.8 lvcreate.8 lvdisplay.8 lvextend.8 lvm.8 \ lvmchange.8 \ lvmdiskscan.8 lvreduce.8 lvremove.8 lvrename.8 lvresize.8 lvs.8 \ lvscan.8 pvchange.8 pvcreate.8 pvdisplay.8 pvmove.8 pvremove.8 \