[Libguestfs] [PATCH v2 1/4] labels: move e2label to ext2.c and call it directly

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Wed Jul 8 09:34:42 UTC 2015


ext2 should not call function in labels

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
v2: move e2label codes inside do_set_e2label
  call do_set_e2label in do_set_label

 daemon/ext2.c   | 23 +++++++++++++++++------
 daemon/labels.c | 24 +-----------------------
 2 files changed, 18 insertions(+), 29 deletions(-)

diff --git a/daemon/ext2.c b/daemon/ext2.c
index e8d2655..ebaf0f0 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -38,6 +38,7 @@ GUESTFSD_EXT_CMD(str_resize2fs, resize2fs);
 GUESTFSD_EXT_CMD(str_mke2fs, mke2fs);
 GUESTFSD_EXT_CMD(str_lsattr, lsattr);
 GUESTFSD_EXT_CMD(str_chattr, chattr);
+GUESTFSD_EXT_CMD(str_e2label, e2label);
 
 /* https://bugzilla.redhat.com/show_bug.cgi?id=978302#c1 */
 int
@@ -125,12 +126,22 @@ do_tune2fs_l (const char *device)
 int
 do_set_e2label (const char *device, const char *label)
 {
-  const mountable_t mountable = {
-    .type = MOUNTABLE_DEVICE,
-    .device = /* not really ... */ (char *) device,
-    .volume = NULL,
-  };
-  return do_set_label (&mountable, label);
+  int r;
+  CLEANUP_FREE char *err = NULL;
+
+  if (strlen (label) > EXT2_LABEL_MAX) {
+    reply_with_error ("%s: ext2 labels are limited to %d bytes",
+                      label, EXT2_LABEL_MAX);
+    return -1;
+  }
+
+  r = command (NULL, &err, str_e2label, device, label, NULL);
+  if (r == -1) {
+    reply_with_error ("%s", err);
+    return -1;
+  }
+
+  return 0;
 }
 
 char *
diff --git a/daemon/labels.c b/daemon/labels.c
index eec5b96..e3830f9 100644
--- a/daemon/labels.c
+++ b/daemon/labels.c
@@ -28,7 +28,6 @@
 #include "optgroups.h"
 
 GUESTFSD_EXT_CMD(str_dosfslabel, dosfslabel);
-GUESTFSD_EXT_CMD(str_e2label, e2label);
 GUESTFSD_EXT_CMD(str_ntfslabel, ntfslabel);
 GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin);
 
@@ -48,27 +47,6 @@ dosfslabel (const char *device, const char *label)
 }
 
 static int
-e2label (const char *device, const char *label)
-{
-  int r;
-  CLEANUP_FREE char *err = NULL;
-
-  if (strlen (label) > EXT2_LABEL_MAX) {
-    reply_with_error ("%s: ext2 labels are limited to %d bytes",
-                      label, EXT2_LABEL_MAX);
-    return -1;
-  }
-
-  r = command (NULL, &err, str_e2label, device, label, NULL);
-  if (r == -1) {
-    reply_with_error ("%s", err);
-    return -1;
-  }
-
-  return 0;
-}
-
-static int
 ntfslabel (const char *device, const char *label)
 {
   int r;
@@ -135,7 +113,7 @@ do_set_label (const mountable_t *mountable, const char *label)
     r = dosfslabel (mountable->device, label);
 
   else if (fstype_is_extfs (vfs_type))
-    r = e2label (mountable->device, label);
+    r = do_set_e2label (mountable->device, label);
 
   else if (STREQ (vfs_type, "ntfs"))
     r = ntfslabel (mountable->device, label);
-- 
2.1.0




More information about the Libguestfs mailing list