mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +03:00
Add dm_split_words() and dm_split_lvm_name() to libdevmapper.
This commit is contained in:
parent
4aebd7be37
commit
a93fe79bc4
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -17,8 +17,6 @@
|
||||
#include "lvm-types.h"
|
||||
#include "lvm-string.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
* 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 <vg>-<lv>-<layer>, 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;
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
101
libdm/libdm-string.c
Normal file
101
libdm/libdm-string.c
Normal file
@ -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 <ctype.h>
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user