master - libdm: introduce and use DEV_UUID macro
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=842167eb17b21e...
Commit: 842167eb17b21e5fada08fd3a4beafd96a5b4021
Parent: 8dccbae35e6a26fbc736d215de8e0538773de5e0
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Oct 10 17:02:19 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Oct 10 17:16:15 2012 +0200
libdm: introduce and use DEV_UUID macro
To automatically prefer mangled UUID over unmangled UUID. The same
logic that is already used for dm name mangling...
---
libdm/ioctl/libdm-iface.c | 15 ++++++++-------
libdm/libdm-common.h | 1 +
2 files changed, 9 insertions(+), 7 deletions(-)
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index ac3442e..3b6731d 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -1083,7 +1083,7 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
}
/* Does driver support device number referencing? */
- if (_dm_version_minor < 3 && !DEV_NAME(dmt) && !dmt->uuid && dmi->dev) {
+ if (_dm_version_minor < 3 && !DEV_NAME(dmt) && !DEV_UUID(dmt) && dmi->dev) {
if (!_lookup_dev_name(dmi->dev, dmi->name, sizeof(dmi->name))) {
log_error("Unable to find name for device (%" PRIu32
":%" PRIu32 ")", dmt->major, dmt->minor);
@@ -1099,8 +1099,8 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
dmt->major < 0))
strncpy(dmi->name, DEV_NAME(dmt), sizeof(dmi->name));
- if (dmt->uuid)
- strncpy(dmi->uuid, dmt->uuid, sizeof(dmi->uuid));
+ if (DEV_UUID(dmt))
+ strncpy(dmi->uuid, DEV_UUID(dmt), sizeof(dmi->uuid));
if (dmt->type == DM_DEVICE_SUSPEND)
dmi->flags |= DM_SUSPEND_FLAG;
@@ -1510,7 +1510,7 @@ static int _check_children_not_suspended_v4(struct dm_task *dmt, uint64_t device
else
log_error(INTERNAL_ERROR "Attempt to suspend device %s%s%s%.0d%s%.0d%s%s"
"that uses already-suspended device (%u:%u)",
- DEV_NAME(dmt) ? : "", dmt->uuid ? : "",
+ DEV_NAME(dmt) ? : "", DEV_UUID(dmt) ? : "",
dmt->major > 0 ? "(" : "",
dmt->major > 0 ? dmt->major : 0,
dmt->major > 0 ? ":" : "",
@@ -1792,6 +1792,7 @@ int dm_task_run(struct dm_task *dmt)
unsigned ioctl_retry = 1;
int retryable = 0;
const char *dev_name = DEV_NAME(dmt);
+ const char *dev_uuid = DEV_UUID(dmt);
if ((unsigned) dmt->type >=
(sizeof(_cmd_data_v4) / sizeof(*_cmd_data_v4))) {
@@ -1807,7 +1808,7 @@ int dm_task_run(struct dm_task *dmt)
return _create_and_load_v4(dmt);
if (dmt->type == DM_DEVICE_MKNODES && !dev_name &&
- !dmt->uuid && dmt->major <= 0)
+ !dev_uuid && dmt->major <= 0)
return _mknodes_v4(dmt);
if ((dmt->type == DM_DEVICE_RELOAD) && dmt->suppress_identical_reload)
@@ -1828,8 +1829,8 @@ int dm_task_run(struct dm_task *dmt)
"%s%s%s %s%.0d%s%.0d%s%s",
suspended_counter,
dev_name ? : "",
- dmt->uuid ? " UUID " : "",
- dmt->uuid ? : "",
+ dev_uuid ? " UUID " : "",
+ dev_uuid ? : "",
dmt->major > 0 ? "(" : "",
dmt->major > 0 ? dmt->major : 0,
dmt->major > 0 ? ":" : "",
diff --git a/libdm/libdm-common.h b/libdm/libdm-common.h
index 75ee60e..4705a77 100644
--- a/libdm/libdm-common.h
+++ b/libdm/libdm-common.h
@@ -21,6 +21,7 @@
#define DM_DEFAULT_NAME_MANGLING_MODE_ENV_VAR_NAME "DM_DEFAULT_NAME_MANGLING_MODE"
#define DEV_NAME(dmt) (dmt->mangled_dev_name ? : dmt->dev_name)
+#define DEV_UUID(DMT) (dmt->mangled_uuid ? : dmt->uuid)
int mangle_string(const char *str, const char *str_name, size_t len,
char *buf, size_t buf_len, dm_string_mangling_t mode);
11 years, 7 months
master - libdm: unmangle dm UUIDs on dm ioctl return
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8dccbae35e6a26...
Commit: 8dccbae35e6a26fbc736d215de8e0538773de5e0
Parent: 7e71ecbaf6137fa6b6e3ca5c25c090369fe69dd4
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Oct 10 17:01:42 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Oct 10 17:16:15 2012 +0200
libdm: unmangle dm UUIDs on dm ioctl return
---
libdm/ioctl/libdm-iface.c | 39 +++++++++++++++++++++++++++++----------
1 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index 04e458c..ac3442e 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -1571,44 +1571,48 @@ static const char *_sanitise_message(char *message)
return sanitised_message;
}
-static int _do_dm_ioctl_unmangle_name(char *name)
+static int _do_dm_ioctl_unmangle_string(char *str, const char *str_name,
+ char *buf, size_t buf_size,
+ dm_string_mangling_t mode)
{
- dm_string_mangling_t mode = dm_get_name_mangling_mode();
- char buf[DM_NAME_LEN];
int r;
if (mode == DM_STRING_MANGLING_NONE)
return 1;
- if (!check_multiple_mangled_string_allowed(name, "name", mode))
+ if (!check_multiple_mangled_string_allowed(str, str_name, mode))
return_0;
- if ((r = unmangle_string(name, "name", DM_NAME_LEN, buf, sizeof(buf), mode)) < 0) {
- log_debug("_do_dm_ioctl_unmangle_name: failed to "
- "unmangle \"%s\"", name);
+ if ((r = unmangle_string(str, str_name, strlen(str), buf, buf_size, mode)) < 0) {
+ log_debug("_do_dm_ioctl_unmangle_string: failed to "
+ "unmangle %s \"%s\"", str_name, str);
return 0;
} else if (r)
- memcpy(name, buf, strlen(buf) + 1);
+ memcpy(str, buf, strlen(buf) + 1);
return 1;
}
static int _dm_ioctl_unmangle_names(int type, struct dm_ioctl *dmi)
{
+ char buf[DM_NAME_LEN];
struct dm_names *names;
unsigned next = 0;
char *name;
int r = 1;
if ((name = dmi->name))
- r = _do_dm_ioctl_unmangle_name(name);
+ r = _do_dm_ioctl_unmangle_string(name, "name", buf, sizeof(buf),
+ dm_get_name_mangling_mode());
if (type == DM_DEVICE_LIST &&
((names = ((struct dm_names *) ((char *)dmi + dmi->data_start)))) &&
names->dev) {
do {
names = (struct dm_names *)((char *) names + next);
- r = _do_dm_ioctl_unmangle_name(names->name);
+ r = _do_dm_ioctl_unmangle_string(names->name, "name",
+ buf, sizeof(buf),
+ dm_get_name_mangling_mode());
next = names->next;
} while (next);
}
@@ -1616,6 +1620,18 @@ static int _dm_ioctl_unmangle_names(int type, struct dm_ioctl *dmi)
return r;
}
+static int _dm_ioctl_unmangle_uuids(int type, struct dm_ioctl *dmi)
+{
+ char buf[DM_UUID_LEN];
+ char *uuid = dmi->uuid;
+
+ if (uuid)
+ return _do_dm_ioctl_unmangle_string(uuid, "UUID", buf, sizeof(buf),
+ dm_get_name_mangling_mode());
+
+ return 1;
+}
+
static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
unsigned buffer_repeat_count,
unsigned retry_repeat_count,
@@ -1746,6 +1762,9 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
if (!_dm_ioctl_unmangle_names(dmt->type, dmi))
goto error;
+ if (!_dm_ioctl_unmangle_uuids(dmt->type, dmi))
+ goto error;
+
#else /* Userspace alternative for testing */
#endif
return dmi;
11 years, 7 months
master - libdm: add mangling support for dm_task_set_newuuid
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7e71ecbaf6137f...
Commit: 7e71ecbaf6137fa6b6e3ca5c25c090369fe69dd4
Parent: a621795a3c011d3e3cf9031f09f2bdfa05d4dc8c
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Oct 10 17:01:13 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Oct 10 17:16:14 2012 +0200
libdm: add mangling support for dm_task_set_newuuid
---
libdm/ioctl/libdm-iface.c | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index 0dd25ef..04e458c 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -736,11 +736,32 @@ int dm_task_set_add_node(struct dm_task *dmt, dm_add_node_t add_node)
int dm_task_set_newuuid(struct dm_task *dmt, const char *newuuid)
{
+ dm_string_mangling_t mangling_mode = dm_get_name_mangling_mode();
+ char mangled_uuid[DM_UUID_LEN];
+ int r = 0;
+
if (strlen(newuuid) >= DM_UUID_LEN) {
log_error("Uuid \"%s\" too long", newuuid);
return 0;
}
+ if (!check_multiple_mangled_string_allowed(newuuid, "new UUID", mangling_mode))
+ return_0;
+
+ if (mangling_mode != DM_STRING_MANGLING_NONE &&
+ (r = mangle_string(newuuid, "new UUID", strlen(newuuid), mangled_uuid,
+ sizeof(mangled_uuid), mangling_mode)) < 0) {
+ log_error("Failed to mangle new device UUID \"%s\"", newuuid);
+ return 0;
+ }
+
+ if (r) {
+ log_debug("New device uuid mangled [%s]: %s --> %s",
+ mangling_mode == DM_STRING_MANGLING_AUTO ? "auto" : "hex",
+ newuuid, mangled_uuid);
+ newuuid = mangled_uuid;
+ }
+
if (!(dmt->newname = dm_strdup(newuuid))) {
log_error("dm_task_set_newuuid: strdup(%s) failed", newuuid);
return 0;
11 years, 7 months
master - libdm: add mangling support for dm_task_set_uuid
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a621795a3c011d...
Commit: a621795a3c011d3e3cf9031f09f2bdfa05d4dc8c
Parent: 12f5c3f726823d13be561645935d0f77c1334e95
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Oct 10 17:00:41 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Oct 10 17:16:13 2012 +0200
libdm: add mangling support for dm_task_set_uuid
Also, add a new field to struct dm_task called "mangled_uuid" that
will store mangled form of uuid if it differs from original uuid.
---
libdm/ioctl/libdm-iface.c | 5 +++++
libdm/ioctl/libdm-targets.h | 1 +
libdm/libdm-common.c | 28 ++++++++++++++++++++++++++++
3 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index 3166c06..0dd25ef 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -455,6 +455,7 @@ void dm_task_destroy(struct dm_task *dmt)
dm_free(dmt->message);
dm_free(dmt->geometry);
dm_free(dmt->uuid);
+ dm_free(dmt->mangled_uuid);
dm_free(dmt);
}
@@ -1317,6 +1318,8 @@ static int _create_and_load_v4(struct dm_task *dmt)
dmt->type = DM_DEVICE_RESUME;
dm_free(dmt->uuid);
dmt->uuid = NULL;
+ dm_free(dmt->mangled_uuid);
+ dmt->mangled_uuid = NULL;
if (dm_task_run(dmt))
return 1;
@@ -1325,6 +1328,8 @@ static int _create_and_load_v4(struct dm_task *dmt)
dmt->type = DM_DEVICE_REMOVE;
dm_free(dmt->uuid);
dmt->uuid = NULL;
+ dm_free(dmt->mangled_uuid);
+ dmt->mangled_uuid = NULL;
/*
* Also udev-synchronize "remove" dm task that is a part of this revert!
diff --git a/libdm/ioctl/libdm-targets.h b/libdm/ioctl/libdm-targets.h
index c004d3e..8fc8738 100644
--- a/libdm/ioctl/libdm-targets.h
+++ b/libdm/ioctl/libdm-targets.h
@@ -69,6 +69,7 @@ struct dm_task {
int expected_errno;
char *uuid;
+ char *mangled_uuid;
};
struct cmd_data {
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index b990ded..b8533ed 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -717,7 +717,35 @@ int dm_task_set_newname(struct dm_task *dmt, const char *newname)
int dm_task_set_uuid(struct dm_task *dmt, const char *uuid)
{
+ char mangled_uuid[DM_UUID_LEN];
+ dm_string_mangling_t mangling_mode = dm_get_name_mangling_mode();
+ int r = 0;
+
dm_free(dmt->uuid);
+ dmt->uuid = NULL;
+ dm_free(dmt->mangled_uuid);
+ dmt->mangled_uuid = NULL;
+
+ if (!check_multiple_mangled_string_allowed(uuid, "UUID", mangling_mode))
+ return_0;
+
+ if (mangling_mode != DM_STRING_MANGLING_NONE &&
+ (r = mangle_string(uuid, "UUID", strlen(uuid), mangled_uuid,
+ sizeof(mangled_uuid), mangling_mode)) < 0) {
+ log_error("Failed to mangle device uuid \"%s\".", uuid);
+ return 0;
+ }
+
+ if (r) {
+ log_debug("Device uuid mangled [%s]: %s --> %s",
+ mangling_mode == DM_STRING_MANGLING_AUTO ? "auto" : "hex",
+ uuid, mangled_uuid);
+
+ if (!(dmt->mangled_uuid = dm_strdup(mangled_uuid))) {
+ log_error("dm_task_set_uuid: dm_strdup(%s) failed", mangled_uuid);
+ return 0;
+ }
+ }
if (!(dmt->uuid = dm_strdup(uuid))) {
log_error("dm_task_set_uuid: strdup(%s) failed", uuid);
11 years, 7 months
master - libdm: add dm_task_get_uuid_mangled/unmangled
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=12f5c3f726823d...
Commit: 12f5c3f726823d13be561645935d0f77c1334e95
Parent: b0f48b9533b9fd13aaf0ad1bca4cbf68330e60b8
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Oct 10 16:59:47 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Oct 10 16:59:47 2012 +0200
libdm: add dm_task_get_uuid_mangled/unmangled
Just like we already have existing mangling support for
device-mapper names, we need exactly the same for device-mapper
UUIDs as their character whitelist is wider than what udev supports.
In case udev is used to create entries in /dev based on UUIDs
and these UUIDs contain characters not supported by udev,
we'll end up with incorrect /dev content for such devices.
So we need to mangle them to a form that is supported by udev.
The mangling used for UUIDs follows the mangling used for names
(that is already supported and used throughout). That means,
setting the name mangling mode via dm_set_name_mangling_mode
affects mangling used for UUIDs in exactly the same manner.
It would be useless to add a new and separate
dm_set_uuid_mangling_mode fn, we'll reuse existing interface.
---
libdm/ioctl/libdm-iface.c | 5 ---
libdm/libdevmapper.h | 18 ++++++++--
libdm/libdm-common.c | 87 ++++++++++++++++++++++++++++++++++++---------
3 files changed, 85 insertions(+), 25 deletions(-)
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index 526ec3f..3166c06 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -681,11 +681,6 @@ uint32_t dm_task_get_read_ahead(const struct dm_task *dmt, uint32_t *read_ahead)
MINOR(dmt->dmi.v4->dev), read_ahead);
}
-const char *dm_task_get_uuid(const struct dm_task *dmt)
-{
- return (dmt->dmi.v4->uuid);
-}
-
struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
{
return (struct dm_deps *) (((char *) dmt->dmi.v4) +
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index 6d24102..70862f3 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -164,6 +164,16 @@ struct dm_versions {
int dm_get_library_version(char *version, size_t size);
int dm_task_get_driver_version(struct dm_task *dmt, char *version, size_t size);
int dm_task_get_info(struct dm_task *dmt, struct dm_info *dmi);
+
+/*
+ * This function returns dm device's UUID based on the value
+ * of the mangling mode set during preceding dm_task_run call:
+ * - unmangled name for DM_STRING_MANGLING_{AUTO, HEX},
+ * - name without any changes for DM_STRING_MANGLING_NONE.
+ *
+ * To get mangled or unmangled form of the name directly, use
+ * dm_task_get_uuid_mangled or dm_task_get_uuid_unmangled function.
+ */
const char *dm_task_get_uuid(const struct dm_task *dmt);
struct dm_deps *dm_task_get_deps(struct dm_task *dmt);
@@ -297,18 +307,20 @@ typedef enum {
} dm_string_mangling_t;
/*
- * Set/get mangling mode used for device-mapper names.
+ * Set/get mangling mode used for device-mapper names and uuids.
*/
int dm_set_name_mangling_mode(dm_string_mangling_t name_mangling);
dm_string_mangling_t dm_get_name_mangling_mode(void);
/*
- * Get mangled/unmangled form of the device-mapper name
+ * Get mangled/unmangled form of the device-mapper name or uuid
* irrespective of the global setting (set by dm_set_name_mangling_mode).
- * The name returned needs to be freed after use by calling dm_free!
+ * The name or uuid returned needs to be freed after use by calling dm_free!
*/
char *dm_task_get_name_mangled(const struct dm_task *dmt);
char *dm_task_get_name_unmangled(const struct dm_task *dmt);
+char *dm_task_get_uuid_mangled(const struct dm_task *dmt);
+char *dm_task_get_uuid_unmangled(const struct dm_task *dmt);
/*
* Configure the device-mapper directory
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index 982fd3e..b990ded 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -582,18 +582,51 @@ const char *dm_task_get_name(const struct dm_task *dmt)
return (dmt->dmi.v4->name);
}
+static char *_task_get_string_mangled(const char *str, const char *str_name,
+ char *buf, size_t buf_size,
+ dm_string_mangling_t mode)
+{
+ char *rs;
+ int r;
+
+ if ((r = mangle_string(str, str_name, strlen(str), buf, buf_size, mode)) < 0)
+ return NULL;
+
+ if (!(rs = r ? dm_strdup(buf) : dm_strdup(str)))
+ log_error("_task_get_string_mangled: dm_strdup failed");
+
+ return rs;
+}
+
+static char *_task_get_string_unmangled(const char *str, const char *str_name,
+ char *buf, size_t buf_size,
+ dm_string_mangling_t mode)
+{
+ char *rs;
+ int r = 0;
+
+ /*
+ * Unless the mode used is 'none', the string
+ * is *already* unmangled on ioctl return!
+ */
+ if (mode == DM_STRING_MANGLING_NONE &&
+ (r = unmangle_string(str, str_name, strlen(str), buf, buf_size, mode)) < 0)
+ return NULL;
+
+ if (!(rs = r ? dm_strdup(buf) : dm_strdup(str)))
+ log_error("_task_get_string_unmangled: dm_strdup failed");
+
+ return rs;
+}
+
char *dm_task_get_name_mangled(const struct dm_task *dmt)
{
const char *s = dm_task_get_name(dmt);
char buf[DM_NAME_LEN];
- char *rs = NULL;
- int r;
+ char *rs;
- if ((r = mangle_string(s, "name", strlen(s), buf, sizeof(buf),
- dm_get_name_mangling_mode())) < 0)
+ if (!(rs = _task_get_string_mangled(s, "name", buf, sizeof(buf), dm_get_name_mangling_mode())))
log_error("Failed to mangle device name \"%s\".", s);
- else if (!(rs = r ? dm_strdup(buf) : dm_strdup(s)))
- log_error("dm_task_get_name_mangled: dm_strdup failed");
return rs;
}
@@ -602,19 +635,39 @@ char *dm_task_get_name_unmangled(const struct dm_task *dmt)
{
const char *s = dm_task_get_name(dmt);
char buf[DM_NAME_LEN];
- char *rs = NULL;
- int r = 0;
+ char *rs;
- /*
- * Unless the mode used is 'none', the name
- * is *already* unmangled on ioctl return!
- */
- if (dm_get_name_mangling_mode() == DM_STRING_MANGLING_NONE &&
- (r = unmangle_string(s, "name", strlen(s), buf, sizeof(buf),
- dm_get_name_mangling_mode())) < 0)
+ if (!(rs = _task_get_string_unmangled(s, "name", buf, sizeof(buf), dm_get_name_mangling_mode())))
log_error("Failed to unmangle device name \"%s\".", s);
- else if (!(rs = r ? dm_strdup(buf) : dm_strdup(s)))
- log_error("dm_task_get_name_unmangled: dm_strdup failed");
+
+ return rs;
+}
+
+const char *dm_task_get_uuid(const struct dm_task *dmt)
+{
+ return (dmt->dmi.v4->uuid);
+}
+
+char *dm_task_get_uuid_mangled(const struct dm_task *dmt)
+{
+ const char *s = dm_task_get_uuid(dmt);
+ char buf[DM_UUID_LEN];
+ char *rs;
+
+ if (!(rs = _task_get_string_mangled(s, "UUID", buf, sizeof(buf), dm_get_name_mangling_mode())))
+ log_error("Failed to mangle device uuid \"%s\".", s);
+
+ return rs;
+}
+
+char *dm_task_get_uuid_unmangled(const struct dm_task *dmt)
+{
+ const char *s = dm_task_get_uuid(dmt);
+ char buf[DM_UUID_LEN];
+ char *rs;
+
+ if (!(rs = _task_get_string_unmangled(s, "UUID", buf, sizeof(buf), dm_get_name_mangling_mode())))
+ log_error("Failed to unmangle device uuid \"%s\".", s);
return rs;
}
11 years, 7 months
master - libdm: refactor internal mangling functions
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b0f48b9533b9fd...
Commit: b0f48b9533b9fd13aaf0ad1bca4cbf68330e60b8
Parent: f65754e6fc0e7e1eb17f058fe92db1ea6eead809
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Oct 10 16:59:11 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Oct 10 16:59:11 2012 +0200
libdm: refactor internal mangling functions
(un)mangle_name -> (un)mangle_string
check_multiple_mangled_name_allowed -> check_multiple_mangled_string_allowed
Just for clarity as the same functions will be reused to (un)mangle dm UUIDs.
---
libdm/ioctl/libdm-iface.c | 4 +-
libdm/libdm-common.c | 55 +++++++++++++++++++++++----------------------
libdm/libdm-common.h | 11 +++++----
3 files changed, 36 insertions(+), 34 deletions(-)
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index 9932aa9..526ec3f 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -1559,10 +1559,10 @@ static int _do_dm_ioctl_unmangle_name(char *name)
if (mode == DM_STRING_MANGLING_NONE)
return 1;
- if (!check_multiple_mangled_name_allowed(mode, name))
+ if (!check_multiple_mangled_string_allowed(name, "name", mode))
return_0;
- if ((r = unmangle_name(name, DM_NAME_LEN, buf, sizeof(buf), mode)) < 0) {
+ if ((r = unmangle_string(name, "name", DM_NAME_LEN, buf, sizeof(buf), mode)) < 0) {
log_debug("_do_dm_ioctl_unmangle_name: failed to "
"unmangle \"%s\"", name);
return 0;
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index 7929889..982fd3e 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -326,11 +326,12 @@ static int _is_whitelisted_char(char c)
return 0;
}
-int check_multiple_mangled_name_allowed(dm_string_mangling_t mode, const char *name)
+int check_multiple_mangled_string_allowed(const char *str, const char *str_name,
+ dm_string_mangling_t mode)
{
- if (mode == DM_STRING_MANGLING_AUTO && strstr(name, "\\x5cx")) {
- log_error("The name \"%s\" seems to be mangled more than once. "
- "This is not allowed in auto mode.", name);
+ if (mode == DM_STRING_MANGLING_AUTO && strstr(str, "\\x5cx")) {
+ log_error("The %s \"%s\" seems to be mangled more than once. "
+ "This is not allowed in auto mode.", str_name, str);
return 0;
}
@@ -341,8 +342,8 @@ int check_multiple_mangled_name_allowed(dm_string_mangling_t mode, const char *n
* Mangle all characters in the input string which are not on a whitelist
* with '\xNN' format where NN is the hex value of the character.
*/
-int mangle_name(const char *str, size_t len, char *buf,
- size_t buf_len, dm_string_mangling_t mode)
+int mangle_string(const char *str, const char *str_name, size_t len,
+ char *buf, size_t buf_len, dm_string_mangling_t mode)
{
int need_mangling = -1; /* -1 don't know yet, 0 no, 1 yes */
size_t i, j;
@@ -355,7 +356,7 @@ int mangle_name(const char *str, size_t len, char *buf,
return 0;
if (buf_len < DM_NAME_LEN) {
- log_error(INTERNAL_ERROR "mangle_name: supplied buffer too small");
+ log_error(INTERNAL_ERROR "mangle_string: supplied buffer too small");
return -1;
}
@@ -417,11 +418,11 @@ int mangle_name(const char *str, size_t len, char *buf,
return need_mangling;
bad1:
- log_error("The name \"%s\" contains mixed mangled and unmangled "
- "characters or it's already mangled improperly.", str);
+ log_error("The %s \"%s\" contains mixed mangled and unmangled "
+ "characters or it's already mangled improperly.", str_name, str);
return -1;
bad2:
- log_error("Mangled form of the name too long for \"%s\".", str);
+ log_error("Mangled form of the %s too long for \"%s\".", str_name, str);
return -1;
}
@@ -429,8 +430,8 @@ bad2:
* Try to unmangle supplied string.
* Return value: -1 on error, 0 when no unmangling needed, 1 when unmangling applied
*/
-int unmangle_name(const char *str, size_t len, char *buf,
- size_t buf_len, dm_string_mangling_t mode)
+int unmangle_string(const char *str, const char *str_name, size_t len,
+ char *buf, size_t buf_len, dm_string_mangling_t mode)
{
int strict = mode != DM_STRING_MANGLING_NONE;
char str_rest[DM_NAME_LEN];
@@ -446,22 +447,22 @@ int unmangle_name(const char *str, size_t len, char *buf,
return 0;
if (buf_len < DM_NAME_LEN) {
- log_error(INTERNAL_ERROR "unmangle_name: supplied buffer too small");
+ log_error(INTERNAL_ERROR "unmangle_string: supplied buffer too small");
return -1;
}
for (i = 0, j = 0; str[i]; i++, j++) {
if (strict && !(_is_whitelisted_char(str[i]) || str[i]=='\\')) {
- log_error("The name \"%s\" should be mangled but "
- "it contains blacklisted characters.", str);
+ log_error("The %s \"%s\" should be mangled but "
+ "it contains blacklisted characters.", str_name, str);
j=0; r=-1;
goto out;
}
if (str[i] == '\\' && str[i+1] == 'x') {
if (!sscanf(&str[i+2], "%2x%s", &code, str_rest)) {
- log_debug("Hex encoding mismatch detected in \"%s\" "
- "while trying to unmangle it.", str);
+ log_debug("Hex encoding mismatch detected in %s \"%s\" "
+ "while trying to unmangle it.", str_name, str);
goto out;
}
buf[j] = (unsigned char) code;
@@ -496,12 +497,12 @@ static int _dm_task_set_name(struct dm_task *dmt, const char *name,
return 0;
}
- if (!check_multiple_mangled_name_allowed(mangling_mode, name))
+ if (!check_multiple_mangled_string_allowed(name, "name", mangling_mode))
return_0;
if (mangling_mode != DM_STRING_MANGLING_NONE &&
- (r = mangle_name(name, strlen(name), mangled_name,
- sizeof(mangled_name), mangling_mode)) < 0) {
+ (r = mangle_string(name, "name", strlen(name), mangled_name,
+ sizeof(mangled_name), mangling_mode)) < 0) {
log_error("Failed to mangle device name \"%s\".", name);
return 0;
}
@@ -588,8 +589,8 @@ char *dm_task_get_name_mangled(const struct dm_task *dmt)
char *rs = NULL;
int r;
- if ((r = mangle_name(s, strlen(s), buf, sizeof(buf),
- dm_get_name_mangling_mode())) < 0)
+ if ((r = mangle_string(s, "name", strlen(s), buf, sizeof(buf),
+ dm_get_name_mangling_mode())) < 0)
log_error("Failed to mangle device name \"%s\".", s);
else if (!(rs = r ? dm_strdup(buf) : dm_strdup(s)))
log_error("dm_task_get_name_mangled: dm_strdup failed");
@@ -609,8 +610,8 @@ char *dm_task_get_name_unmangled(const struct dm_task *dmt)
* is *already* unmangled on ioctl return!
*/
if (dm_get_name_mangling_mode() == DM_STRING_MANGLING_NONE &&
- (r = unmangle_name(s, strlen(s), buf, sizeof(buf),
- dm_get_name_mangling_mode())) < 0)
+ (r = unmangle_string(s, "name", strlen(s), buf, sizeof(buf),
+ dm_get_name_mangling_mode())) < 0)
log_error("Failed to unmangle device name \"%s\".", s);
else if (!(rs = r ? dm_strdup(buf) : dm_strdup(s)))
log_error("dm_task_get_name_unmangled: dm_strdup failed");
@@ -634,12 +635,12 @@ int dm_task_set_newname(struct dm_task *dmt, const char *newname)
return 0;
}
- if (!check_multiple_mangled_name_allowed(mangling_mode, newname))
+ if (!check_multiple_mangled_string_allowed(newname, "new name", mangling_mode))
return_0;
if (mangling_mode != DM_STRING_MANGLING_NONE &&
- (r = mangle_name(newname, strlen(newname), mangled_name,
- sizeof(mangled_name), mangling_mode)) < 0) {
+ (r = mangle_string(newname, "new name", strlen(newname), mangled_name,
+ sizeof(mangled_name), mangling_mode)) < 0) {
log_error("Failed to mangle new device name \"%s\"", newname);
return 0;
}
diff --git a/libdm/libdm-common.h b/libdm/libdm-common.h
index b57bae9..75ee60e 100644
--- a/libdm/libdm-common.h
+++ b/libdm/libdm-common.h
@@ -22,13 +22,14 @@
#define DEV_NAME(dmt) (dmt->mangled_dev_name ? : dmt->dev_name)
-int mangle_name(const char *str, size_t len, char *buf,
- size_t buf_len, dm_string_mangling_t mode);
+int mangle_string(const char *str, const char *str_name, size_t len,
+ char *buf, size_t buf_len, dm_string_mangling_t mode);
-int unmangle_name(const char *str, size_t len, char *buf,
- size_t buf_len, dm_string_mangling_t mode);
+int unmangle_string(const char *str, const char *str_name, size_t len,
+ char *buf, size_t buf_len, dm_string_mangling_t mode);
-int check_multiple_mangled_name_allowed(dm_string_mangling_t mode, const char *name);
+int check_multiple_mangled_string_allowed(const char *str, const char *str_name,
+ dm_string_mangling_t mode);
struct target *create_target(uint64_t start,
uint64_t len,
11 years, 7 months
master - test: Check that lvmetad is refreshed correctly on restart.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=f65754e6fc0e7e...
Commit: f65754e6fc0e7e1eb17f058fe92db1ea6eead809
Parent: 71d718a4a4202d0e8a10bed1551878c68dd99a59
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Wed Oct 10 12:34:44 2012 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Wed Oct 10 13:54:36 2012 +0200
test: Check that lvmetad is refreshed correctly on restart.
---
test/shell/lvmetad-restart.sh | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/test/shell/lvmetad-restart.sh b/test/shell/lvmetad-restart.sh
new file mode 100644
index 0000000..10268c2
--- /dev/null
+++ b/test/shell/lvmetad-restart.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# 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
+
+. lib/test
+
+test -e LOCAL_LVMETAD || skip
+aux prepare_pvs 2
+
+vgcreate $vg1 $dev1 $dev2
+vgs | grep $vg1
+
+kill $(cat LOCAL_LVMETAD)
+aux prepare_lvmetad
+
+vgs | grep $vg1
11 years, 7 months
master - lvmetad: Warn if lvmetad is running but disabled.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=71d718a4a4202d...
Commit: 71d718a4a4202d0e8a10bed1551878c68dd99a59
Parent: 622fb968a22d5b2c6ba3dcd9155743adfe5dec8c
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Wed Oct 10 12:33:48 2012 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Wed Oct 10 13:54:29 2012 +0200
lvmetad: Warn if lvmetad is running but disabled.
---
lib/cache/lvmetad.c | 2 ++
test/Makefile.in | 1 +
test/shell/lvmetad-disabled.sh | 26 ++++++++++++++++++++++++++
3 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index b5fdc54..b5e3787 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -41,6 +41,8 @@ void lvmetad_disconnect(void)
void lvmetad_init(struct cmd_context *cmd)
{
+ if (!_lvmetad_use && !access(LVMETAD_PIDFILE, F_OK))
+ log_warn("WARNING: lvmetad is running but disabled. Restart lvmetad before enabling it!");
if (_lvmetad_use && _lvmetad_socket && !_lvmetad_connected) {
assert(_lvmetad_socket);
_lvmetad = lvmetad_open(_lvmetad_socket);
diff --git a/test/Makefile.in b/test/Makefile.in
index 6d7ee2c..5bbd1d6 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -99,6 +99,7 @@ lib/paths: $(srcdir)/Makefile.in .lib-dir-stamp
echo 'abs_builddir=$(abs_builddir)' >> $@-t
echo 'export DM_UDEV_SYNCHRONISATION=$(dm_udev_synchronisation)' >> $@-t
echo 'export THIN=@THIN@' >> $@-t
+ echo 'export LVMETAD_PIDFILE=@LVMETAD_PIDFILE@' >> $@-t
mv $@-t $@
LIB = lib/not lib/should lib/harness \
diff --git a/test/shell/lvmetad-disabled.sh b/test/shell/lvmetad-disabled.sh
new file mode 100644
index 0000000..41a3a19
--- /dev/null
+++ b/test/shell/lvmetad-disabled.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Copyright (C) 2012 Red Hat, Inc. All rights reserved.
+#
+# 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
+
+. lib/test
+
+test -e LOCAL_LVMETAD || skip
+kill $(cat LOCAL_LVMETAD)
+
+test -e $LVMETAD_PIDFILE && skip
+lvmetad
+test -e $LVMETAD_PIDFILE
+cp $LVMETAD_PIDFILE LOCAL_LVMETAD
+pvs 2>&1 | not grep "lvmetad is running"
+aux lvmconf "global/use_lvmetad = 0"
+pvs 2>&1 | grep "lvmetad is running"
+
+kill $(cat $LVMETAD_PIDFILE)
+not ls $LVMETAD_PIDFILE
11 years, 7 months
master - lvmetad: Fix the -f pidfile (non-)creation logic.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=622fb968a22d5b...
Commit: 622fb968a22d5b2c6ba3dcd9155743adfe5dec8c
Parent: 6e523f01d07d7d819c2f0d9b1595e628ddffea24
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Wed Oct 10 12:32:24 2012 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Wed Oct 10 13:53:21 2012 +0200
lvmetad: Fix the -f pidfile (non-)creation logic.
---
daemons/lvmetad/lvmetad-core.c | 12 +++++++-----
1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index ff861a2..22625c5 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -1105,11 +1105,13 @@ int main(int argc, char *argv[])
}
}
- if (s.foreground && !_socket_override) {
- fprintf(stderr, "A socket path (-s) is required in foreground mode.");
- exit(2);
- } else {
- s.pidfile = NULL;
+ if (s.foreground) {
+ if (!_socket_override) {
+ fprintf(stderr, "A socket path (-s) is required in foreground mode.");
+ exit(2);
+ } else {
+ s.pidfile = NULL;
+ }
}
daemon_start(s);
11 years, 7 months
master - test: Skip thin tests if thin support is configured out.
by Petr Rockai
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6e523f01d07d7d...
Commit: 6e523f01d07d7d819c2f0d9b1595e628ddffea24
Parent: d760669e80f029a4d507e91ad431431b627f5555
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Wed Oct 10 00:20:22 2012 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Wed Oct 10 00:20:22 2012 +0200
test: Skip thin tests if thin support is configured out.
---
test/Makefile.in | 1 +
test/api/thin_percent.sh | 2 +-
test/lib/aux.sh | 6 ++++++
test/shell/discards-thin.sh | 2 +-
test/shell/lvconvert-thin.sh | 2 +-
test/shell/lvcreate-thin-snap.sh | 2 +-
test/shell/lvcreate-thin.sh | 2 +-
7 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/test/Makefile.in b/test/Makefile.in
index da97f2c..6d7ee2c 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -98,6 +98,7 @@ lib/paths: $(srcdir)/Makefile.in .lib-dir-stamp
echo 'abs_srcdir=$(abs_srcdir)' >> $@-t
echo 'abs_builddir=$(abs_builddir)' >> $@-t
echo 'export DM_UDEV_SYNCHRONISATION=$(dm_udev_synchronisation)' >> $@-t
+ echo 'export THIN=@THIN@' >> $@-t
mv $@-t $@
LIB = lib/not lib/should lib/harness \
diff --git a/test/api/thin_percent.sh b/test/api/thin_percent.sh
index bba33ba..9287cf3 100644
--- a/test/api/thin_percent.sh
+++ b/test/api/thin_percent.sh
@@ -13,7 +13,7 @@
. lib/test
-aux target_at_least dm-thin-pool 1 0 0 || skip
+aux have_thin 1 0 0 || skip
# disable thin_check if not present in system
which thin_check || aux lvmconf 'global/thin_check_executable = ""'
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 6cfd6db..d972d10 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -530,6 +530,12 @@ target_at_least()
test "$revision" -ge "$3" 2>/dev/null || return 1
}
+have_thin()
+{
+ target_at_least dm-thin-pool "$@" || exit 1
+ test "$THIN" = shared || test "$THIN" = internal || exit 1
+}
+
test -f DEVICES && devs=$(cat DEVICES)
#unset LVM_VALGRIND
diff --git a/test/shell/discards-thin.sh b/test/shell/discards-thin.sh
index 28300d9..ec3bd1f 100644
--- a/test/shell/discards-thin.sh
+++ b/test/shell/discards-thin.sh
@@ -18,7 +18,7 @@
#
# Main
#
-aux target_at_least dm-thin-pool 1 1 0 || skip
+aux have_thin 1 1 0 || skip
aux prepare_pvs 2 64
diff --git a/test/shell/lvconvert-thin.sh b/test/shell/lvconvert-thin.sh
index 3ad3248..abaa620 100644
--- a/test/shell/lvconvert-thin.sh
+++ b/test/shell/lvconvert-thin.sh
@@ -15,7 +15,7 @@
#
# Main
#
-aux target_at_least dm-thin-pool 1 0 0 || skip
+aux have_thin 1 0 0 || skip
aux prepare_pvs 4 64
diff --git a/test/shell/lvcreate-thin-snap.sh b/test/shell/lvcreate-thin-snap.sh
index 0e91222..2ee8748 100644
--- a/test/shell/lvcreate-thin-snap.sh
+++ b/test/shell/lvcreate-thin-snap.sh
@@ -26,7 +26,7 @@ check_lv_field_modules_()
#
# Main
#
-aux target_at_least dm-thin-pool 1 0 0 || skip
+aux have_thin 1 0 0 || skip
aux prepare_pvs 2 64
diff --git a/test/shell/lvcreate-thin.sh b/test/shell/lvcreate-thin.sh
index 32ffef8..7ba97ed 100644
--- a/test/shell/lvcreate-thin.sh
+++ b/test/shell/lvcreate-thin.sh
@@ -29,7 +29,7 @@ check_lv_field_modules_()
#
# Main
#
-aux target_at_least dm-thin-pool 1 0 0 || skip
+aux have_thin 1 0 0 || skip
aux prepare_pvs 2 64
11 years, 7 months