summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2014-12-09 17:19:59 +0100
committerTomas Bzatek <tbzatek@redhat.com>2015-01-26 14:26:52 +0100
commit2c9bde756c991a56f26fa3fafab7cd14e93f4eb5 (patch)
tree9429fbb189ba3a565b4ab7e434682ff719c40a96
parenta3cce2974592de5050bc40a40d8e47a876d389ec (diff)
LVM2: Remove encoding of LVM2 names
Backported from original storaged: https://github.com/cockpit-project/storaged/commit/ebafbfeceb7a7e3b1bca008f7b8a56c974fae000
-rw-r--r--modules/lvm2/data/org.freedesktop.UDisks2.lvm2.xml28
-rw-r--r--modules/lvm2/udiskslinuxlogicalvolume.c21
-rw-r--r--modules/lvm2/udiskslinuxmanagerlvm2.c7
-rw-r--r--modules/lvm2/udiskslinuxvolumegroup.c35
-rw-r--r--modules/lvm2/udiskslvm2daemonutil.c88
-rw-r--r--modules/lvm2/udiskslvm2daemonutil.h3
6 files changed, 20 insertions, 162 deletions
diff --git a/modules/lvm2/data/org.freedesktop.UDisks2.lvm2.xml b/modules/lvm2/data/org.freedesktop.UDisks2.lvm2.xml
index 9ebbd36..f85efde 100644
--- a/modules/lvm2/data/org.freedesktop.UDisks2.lvm2.xml
+++ b/modules/lvm2/data/org.freedesktop.UDisks2.lvm2.xml
@@ -125,13 +125,6 @@
-->
<property name="Name" type="s" access="read"/>
- <!-- DisplayName:
-
- The name of this volume group as it should be displayed to
- the user.
- -->
- <property name="DisplayName" type="s" access="read"/>
-
<!-- UUID:
The UUID this volume group. It is guaranteed to be unique,
@@ -190,17 +183,14 @@
</method>
<!-- Rename:
- @new_display_name: The new display name.
+ @new_name: The new name.
Rename this volume group. This might cause the volume group
object to disappear from D-Bus and reappear with a different
path.
-
- The new display name can be any string and is not restricted
- by the rules for LVM2 names.
-->
<method name="Rename">
- <arg name="new_display_name" type="s" direction="in"/>
+ <arg name="new_name" type="s" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
<arg name="result" type="o" direction="out"/>
</method>
@@ -323,13 +313,6 @@
-->
<property name="Name" type="s" access="read"/>
- <!-- DisplayName:
-
- The name of this logical volume, as it should be displayed to
- the user.
- -->
- <property name="DisplayName" type="s" access="read"/>
-
<!-- Active:
Whether or not this volume is active.
@@ -424,17 +407,14 @@
</method>
<!-- Rename:
- @new_display_name: The new display name.
+ @new_name: The new name.
Rename this logical volume. This might cause the logical
volume object to disappear from D-Bus and reappear with a
different path.
-
- The new display name can be any string and is not restricted
- by the rules for LVM2 names.
-->
<method name="Rename">
- <arg name="new_display_name" type="s" direction="in"/>
+ <arg name="new_name" type="s" direction="in"/>
<arg name="options" type="a{sv}" direction="in"/>
<arg name="result" type="o" direction="out"/>
</method>
diff --git a/modules/lvm2/udiskslinuxlogicalvolume.c b/modules/lvm2/udiskslinuxlogicalvolume.c
index 4ad6c51..cce6185 100644
--- a/modules/lvm2/udiskslinuxlogicalvolume.c
+++ b/modules/lvm2/udiskslinuxlogicalvolume.c
@@ -131,12 +131,7 @@ udisks_linux_logical_volume_update (UDisksLinuxLogicalVolume *logical_volume,
iface = UDISKS_LOGICAL_VOLUME (logical_volume);
if (g_variant_lookup (info, "name", "&s", &str))
- {
- gchar *decoded = udisks_daemon_util_lvm2_decode_lvm_name (str);
- udisks_logical_volume_set_name (iface, str);
- udisks_logical_volume_set_display_name (iface, decoded);
- g_free (decoded);
- }
+ udisks_logical_volume_set_name (iface, str);
if (g_variant_lookup (info, "uuid", "&s", &str))
udisks_logical_volume_set_uuid (iface, str);
@@ -374,7 +369,6 @@ handle_rename (UDisksLogicalVolume *_volume,
UDisksLinuxVolumeGroupObject *group_object;
gchar *escaped_group_name = NULL;
gchar *escaped_name = NULL;
- gchar *encoded_new_name = NULL;
gchar *escaped_new_name = NULL;
gchar *error_message = NULL;
const gchar *lv_objpath;
@@ -414,8 +408,7 @@ handle_rename (UDisksLogicalVolume *_volume,
group_object = udisks_linux_logical_volume_object_get_volume_group (object);
escaped_group_name = udisks_daemon_util_escape_and_quote (udisks_linux_volume_group_object_get_name (group_object));
escaped_name = udisks_daemon_util_escape_and_quote (udisks_linux_logical_volume_object_get_name (object));
- encoded_new_name = udisks_daemon_util_lvm2_encode_lvm_name (new_name, TRUE);
- escaped_new_name = udisks_daemon_util_escape_and_quote (encoded_new_name);
+ escaped_new_name = udisks_daemon_util_escape_and_quote (new_name);
if (!udisks_daemon_launch_spawned_job_sync (daemon,
UDISKS_OBJECT (object),
@@ -439,7 +432,7 @@ handle_rename (UDisksLogicalVolume *_volume,
goto out;
}
- lv_objpath = wait_for_logical_volume_path (group_object, encoded_new_name, &error);
+ lv_objpath = wait_for_logical_volume_path (group_object, new_name, &error);
if (lv_objpath == NULL)
{
g_prefix_error (&error,
@@ -455,7 +448,6 @@ handle_rename (UDisksLogicalVolume *_volume,
g_free (error_message);
g_free (escaped_name);
g_free (escaped_group_name);
- g_free (encoded_new_name);
g_free (escaped_new_name);
g_clear_object (&object);
return TRUE;
@@ -810,7 +802,6 @@ handle_create_snapshot (UDisksLogicalVolume *_volume,
uid_t caller_uid;
gid_t caller_gid;
UDisksLinuxVolumeGroupObject *group_object;
- gchar *encoded_volume_name = NULL;
gchar *escaped_volume_name = NULL;
gchar *escaped_group_name = NULL;
gchar *escaped_origin_name = NULL;
@@ -850,8 +841,7 @@ handle_create_snapshot (UDisksLogicalVolume *_volume,
invocation))
goto out;
- encoded_volume_name = udisks_daemon_util_lvm2_encode_lvm_name (name, TRUE);
- escaped_volume_name = udisks_daemon_util_escape_and_quote (encoded_volume_name);
+ escaped_volume_name = udisks_daemon_util_escape_and_quote (name);
group_object = udisks_linux_logical_volume_object_get_volume_group (object);
escaped_group_name = udisks_daemon_util_escape_and_quote (udisks_linux_volume_group_object_get_name (group_object));
escaped_origin_name = udisks_daemon_util_escape_and_quote (udisks_linux_logical_volume_object_get_name (object));
@@ -885,7 +875,7 @@ handle_create_snapshot (UDisksLogicalVolume *_volume,
goto out;
}
- lv_objpath = wait_for_logical_volume_path (group_object, encoded_volume_name, &error);
+ lv_objpath = wait_for_logical_volume_path (group_object, name, &error);
if (lv_objpath == NULL)
{
g_prefix_error (&error,
@@ -899,7 +889,6 @@ handle_create_snapshot (UDisksLogicalVolume *_volume,
out:
g_free (error_message);
- g_free (encoded_volume_name);
g_free (escaped_volume_name);
g_free (escaped_origin_name);
g_free (escaped_group_name);
diff --git a/modules/lvm2/udiskslinuxmanagerlvm2.c b/modules/lvm2/udiskslinuxmanagerlvm2.c
index 04441eb..6c51b00 100644
--- a/modules/lvm2/udiskslinuxmanagerlvm2.c
+++ b/modules/lvm2/udiskslinuxmanagerlvm2.c
@@ -215,7 +215,6 @@ handle_volume_group_create (UDisksManagerLVM2 *_object,
GList *blocks = NULL;
GList *l;
guint n;
- gchar *encoded_name = NULL;
gchar *escaped_name = NULL;
GString *str = NULL;
gint status;
@@ -295,8 +294,7 @@ handle_volume_group_create (UDisksManagerLVM2 *_object,
}
/* Create the volume group... */
- encoded_name = udisks_daemon_util_lvm2_encode_lvm_name (arg_name, FALSE);
- escaped_name = udisks_daemon_util_escape_and_quote (encoded_name);
+ escaped_name = udisks_daemon_util_escape_and_quote (arg_name);
str = g_string_new ("vgcreate");
g_string_append_printf (str, " %s", escaped_name);
if (arg_extent_size > 0)
@@ -344,7 +342,7 @@ handle_volume_group_create (UDisksManagerLVM2 *_object,
/* ... then, sit and wait for the object to show up */
group_object = udisks_daemon_wait_for_object_sync (manager->daemon,
wait_for_volume_group_object,
- (gpointer)encoded_name,
+ (gpointer) arg_name,
NULL,
10, /* timeout_seconds */
&error);
@@ -366,7 +364,6 @@ handle_volume_group_create (UDisksManagerLVM2 *_object,
g_string_free (str, TRUE);
g_list_free_full (blocks, g_object_unref);
g_free (escaped_name);
- g_free (encoded_name);
return TRUE; /* returning TRUE means that we handled the method invocation */
}
diff --git a/modules/lvm2/udiskslinuxvolumegroup.c b/modules/lvm2/udiskslinuxvolumegroup.c
index e0dddc2..e0dd747 100644
--- a/modules/lvm2/udiskslinuxvolumegroup.c
+++ b/modules/lvm2/udiskslinuxvolumegroup.c
@@ -138,12 +138,7 @@ udisks_linux_volume_group_update (UDisksLinuxVolumeGroup *volume_group,
guint64 num;
if (g_variant_lookup (info, "name", "&s", &str))
- {
- gchar *decoded = udisks_daemon_util_lvm2_decode_lvm_name (str);
- udisks_volume_group_set_name (iface, str);
- udisks_volume_group_set_display_name (iface, decoded);
- g_free (decoded);
- }
+ udisks_volume_group_set_name (iface, str);
if (g_variant_lookup (info, "uuid", "&s", &str))
udisks_volume_group_set_uuid (iface, str);
@@ -320,7 +315,6 @@ handle_rename (UDisksVolumeGroup *_group,
uid_t caller_uid;
gid_t caller_gid;
gchar *escaped_name = NULL;
- gchar *encoded_new_name = NULL;
gchar *escaped_new_name = NULL;
gchar *error_message = NULL;
UDisksObject *group_object = NULL;
@@ -358,8 +352,7 @@ handle_rename (UDisksVolumeGroup *_group,
goto out;
escaped_name = udisks_daemon_util_escape_and_quote (udisks_linux_volume_group_object_get_name (object));
- encoded_new_name = udisks_daemon_util_lvm2_encode_lvm_name (new_name, FALSE);
- escaped_new_name = udisks_daemon_util_escape_and_quote (encoded_new_name);
+ escaped_new_name = udisks_daemon_util_escape_and_quote (new_name);
if (!udisks_daemon_launch_spawned_job_sync (daemon,
UDISKS_OBJECT (object),
@@ -384,7 +377,7 @@ handle_rename (UDisksVolumeGroup *_group,
group_object = udisks_daemon_wait_for_object_sync (daemon,
wait_for_volume_group_object,
- (gpointer)encoded_new_name,
+ (gpointer) new_name,
NULL,
10, /* timeout_seconds */
&error);
@@ -404,7 +397,6 @@ handle_rename (UDisksVolumeGroup *_group,
out:
g_free (error_message);
g_free (escaped_name);
- g_free (encoded_new_name);
g_free (escaped_new_name);
g_clear_object (&object);
return TRUE;
@@ -835,7 +827,6 @@ handle_create_plain_volume (UDisksVolumeGroup *_group,
const gchar *message;
uid_t caller_uid;
gid_t caller_gid;
- gchar *encoded_volume_name = NULL;
gchar *escaped_volume_name = NULL;
gchar *escaped_group_name = NULL;
GString *cmd = NULL;
@@ -874,8 +865,7 @@ handle_create_plain_volume (UDisksVolumeGroup *_group,
invocation))
goto out;
- encoded_volume_name = udisks_daemon_util_lvm2_encode_lvm_name (arg_name, TRUE);
- escaped_volume_name = udisks_daemon_util_escape_and_quote (encoded_volume_name);
+ escaped_volume_name = udisks_daemon_util_escape_and_quote (arg_name);
escaped_group_name = udisks_daemon_util_escape_and_quote (udisks_linux_volume_group_object_get_name (object));
arg_size -= arg_size % 512;
@@ -908,7 +898,7 @@ handle_create_plain_volume (UDisksVolumeGroup *_group,
goto out;
}
- lv_objpath = wait_for_logical_volume_path (object, encoded_volume_name, &error);
+ lv_objpath = wait_for_logical_volume_path (object, arg_name, &error);
if (lv_objpath == NULL)
{
g_prefix_error (&error,
@@ -923,7 +913,6 @@ handle_create_plain_volume (UDisksVolumeGroup *_group,
out:
g_free (error_message);
g_free (escaped_group_name);
- g_free (encoded_volume_name);
g_free (escaped_volume_name);
g_string_free (cmd, TRUE);
g_clear_object (&object);
@@ -947,7 +936,6 @@ handle_create_thin_pool_volume (UDisksVolumeGroup *_group,
const gchar *message;
uid_t caller_uid;
gid_t caller_gid;
- gchar *encoded_volume_name = NULL;
gchar *escaped_volume_name = NULL;
gchar *escaped_group_name = NULL;
GString *cmd = NULL;
@@ -986,8 +974,7 @@ handle_create_thin_pool_volume (UDisksVolumeGroup *_group,
invocation))
goto out;
- encoded_volume_name = udisks_daemon_util_lvm2_encode_lvm_name (arg_name, TRUE);
- escaped_volume_name = udisks_daemon_util_escape_and_quote (encoded_volume_name);
+ escaped_volume_name = udisks_daemon_util_escape_and_quote (arg_name);
escaped_group_name = udisks_daemon_util_escape_and_quote (udisks_linux_volume_group_object_get_name (object));
arg_size -= arg_size % 512;
@@ -1014,7 +1001,7 @@ handle_create_thin_pool_volume (UDisksVolumeGroup *_group,
goto out;
}
- lv_objpath = wait_for_logical_volume_path (object, encoded_volume_name, &error);
+ lv_objpath = wait_for_logical_volume_path (object, arg_name, &error);
if (lv_objpath == NULL)
{
g_prefix_error (&error,
@@ -1028,7 +1015,6 @@ handle_create_thin_pool_volume (UDisksVolumeGroup *_group,
out:
g_free (error_message);
- g_free (encoded_volume_name);
g_free (escaped_volume_name);
g_free (escaped_group_name);
g_string_free (cmd, TRUE);
@@ -1055,7 +1041,6 @@ handle_create_thin_volume (UDisksVolumeGroup *_group,
uid_t caller_uid;
gid_t caller_gid;
UDisksLinuxLogicalVolumeObject *pool_object = NULL;
- gchar *encoded_volume_name = NULL;
gchar *escaped_volume_name = NULL;
gchar *escaped_group_name = NULL;
gchar *escaped_pool_name = NULL;
@@ -1103,8 +1088,7 @@ handle_create_thin_volume (UDisksVolumeGroup *_group,
goto out;
}
- encoded_volume_name = udisks_daemon_util_lvm2_encode_lvm_name (arg_name, TRUE);
- escaped_volume_name = udisks_daemon_util_escape_and_quote (encoded_volume_name);
+ escaped_volume_name = udisks_daemon_util_escape_and_quote (arg_name);
escaped_group_name = udisks_daemon_util_escape_and_quote (udisks_linux_volume_group_object_get_name (object));
arg_size -= arg_size % 512;
escaped_pool_name = udisks_daemon_util_escape_and_quote (udisks_linux_logical_volume_object_get_name (pool_object));
@@ -1132,7 +1116,7 @@ handle_create_thin_volume (UDisksVolumeGroup *_group,
goto out;
}
- lv_objpath = wait_for_logical_volume_path (object, encoded_volume_name, &error);
+ lv_objpath = wait_for_logical_volume_path (object, arg_name, &error);
if (lv_objpath == NULL)
{
g_prefix_error (&error,
@@ -1146,7 +1130,6 @@ handle_create_thin_volume (UDisksVolumeGroup *_group,
out:
g_free (error_message);
- g_free (encoded_volume_name);
g_free (escaped_volume_name);
g_free (escaped_group_name);
g_free (escaped_pool_name);
diff --git a/modules/lvm2/udiskslvm2daemonutil.c b/modules/lvm2/udiskslvm2daemonutil.c
index 071fcc3..c249fe2 100644
--- a/modules/lvm2/udiskslvm2daemonutil.c
+++ b/modules/lvm2/udiskslvm2daemonutil.c
@@ -350,94 +350,6 @@ udisks_daemon_util_lvm2_spawn_for_variant (const gchar **argv,
return pid;
}
-static gboolean
-valid_lvm_name_char (gint c)
-{
- return ((c >= 'a' && c <= 'z')
- || (c >= 'A' && c <= 'Z')
- || (c >= '0' && c <= '9')
- || c == '+'
- || c == '_'
- || c == '.'
- || c == '-');
-}
-
-#define LVM_ENCODING_PREFIX "+_"
-
-gchar *
-udisks_daemon_util_lvm2_encode_lvm_name (const gchar *name,
- gboolean for_logical_volume)
-{
- const gchar *n;
- GString *enc;
- gchar *encoded;
-
- for (n = name; *n; n++)
- {
- if (!valid_lvm_name_char (*n))
- goto encode;
- }
-
- if (*name == '-')
- goto encode;
-
- if (g_str_has_prefix (name, LVM_ENCODING_PREFIX))
- goto encode;
-
- if (for_logical_volume && udisks_daemon_util_lvm2_name_is_reserved (name))
- goto encode;
-
- return g_strdup (name);
-
- encode:
- enc = g_string_new (LVM_ENCODING_PREFIX);
- for (n = name; *n; n++)
- {
- if (!valid_lvm_name_char (*n) || *n == '_')
- g_string_append_printf (enc, "_%02x", *(unsigned char *)n);
- else
- g_string_append_c (enc, *n);
- }
- encoded = enc->str;
- g_string_free (enc, FALSE);
- return encoded;
-}
-
-gchar *
-udisks_daemon_util_lvm2_decode_lvm_name (const gchar *encoded)
-{
- const gchar *e;
- GString *dec;
- gchar *decoded;
-
- if (!g_str_has_prefix (encoded, LVM_ENCODING_PREFIX))
- return g_strdup (encoded);
-
- dec = g_string_new ("");
- for (e = encoded + strlen (LVM_ENCODING_PREFIX); *e; e++)
- {
- if (e[0] == '_')
- {
- if (isxdigit (e[1]) && isxdigit (e[2]))
- {
- gint c = (g_ascii_xdigit_value (e[1]) << 4) | g_ascii_xdigit_value (e[2]);
- g_string_append_c (dec, c);
- e += 2;
- }
- else
- {
- g_string_free (dec, TRUE);
- return g_strdup (encoded);
- }
- }
- else
- g_string_append_c (dec, *e);
- }
- decoded = dec->str;
- g_string_free (dec, FALSE);
- return decoded;
-}
-
UDisksLinuxVolumeGroupObject *
udisks_daemon_util_lvm2_find_volume_group_object (UDisksDaemon *daemon,
const gchar *name)
diff --git a/modules/lvm2/udiskslvm2daemonutil.h b/modules/lvm2/udiskslvm2daemonutil.h
index 5fee977..10aae6a 100644
--- a/modules/lvm2/udiskslvm2daemonutil.h
+++ b/modules/lvm2/udiskslvm2daemonutil.h
@@ -41,9 +41,6 @@ GPid udisks_daemon_util_lvm2_spawn_for_variant (const gchar **argv,
gpointer user_data),
gpointer user_data);
-gchar *udisks_daemon_util_lvm2_encode_lvm_name (const gchar *name,
- gboolean for_logical_volume);
-gchar *udisks_daemon_util_lvm2_decode_lvm_name (const gchar *encoded);
gboolean udisks_daemon_util_lvm2_name_is_reserved (const gchar *name);
UDisksLinuxVolumeGroupObject * udisks_daemon_util_lvm2_find_volume_group_object (UDisksDaemon *daemon,