We should use the existing function from specific fs, if not, move it to specific fs files. Chen Hanxiao (4): labels: move e2label to ext2.c and call it directly labels: move ntfslabel to ntfs.c labels: use existing do_xfs_admin for xfslabel labels: return ENOTSUP if could not set label for specific fs daemon/daemon.h | 2 ++ daemon/ext2.c | 23 ++++++++++++----- daemon/labels.c | 70 ++++------------------------------------------------ daemon/ntfs.c | 19 ++++++++++++++ daemon/xfs.c | 7 ++++++ generator/actions.ml | 3 +++ 6 files changed, 53 insertions(+), 71 deletions(-) -- 2.1.0
Chen Hanxiao
2015-Jul-08 09:34 UTC
[Libguestfs] [PATCH v2 1/4] labels: move e2label to ext2.c and call it directly
ext2 should not call function in labels Signed-off-by: Chen Hanxiao <chenhanxiao@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
Chen Hanxiao
2015-Jul-08 09:34 UTC
[Libguestfs] [PATCH v2 2/4] labels: move ntfslabel to ntfs.c
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/daemon.h | 1 + daemon/labels.c | 22 +--------------------- daemon/ntfs.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index 783d739..ade385e 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -281,6 +281,7 @@ extern int btrfs_set_uuid_random (const char *device); /*-- in ntfs.c --*/ extern char *ntfs_get_label (const char *device); +extern int ntfs_set_label (const char *device, const char *label); /*-- in swap.c --*/ extern int swap_set_uuid (const char *device, const char *uuid); diff --git a/daemon/labels.c b/daemon/labels.c index e3830f9..5985d3a 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_ntfslabel, ntfslabel); GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin); static int @@ -47,25 +46,6 @@ dosfslabel (const char *device, const char *label) } static int -ntfslabel (const char *device, const char *label) -{ - int r; - CLEANUP_FREE char *err = NULL; - - /* XXX We should check if the label is longer than 128 unicode - * characters and return an error. This is not so easy since we - * don't have the required libraries. - */ - r = command (NULL, &err, str_ntfslabel, device, label, NULL); - if (r == -1) { - reply_with_error ("%s", err); - return -1; - } - - return 0; -} - -static int xfslabel (const char *device, const char *label) { int r; @@ -116,7 +96,7 @@ do_set_label (const mountable_t *mountable, const char *label) r = do_set_e2label (mountable->device, label); else if (STREQ (vfs_type, "ntfs")) - r = ntfslabel (mountable->device, label); + r = ntfs_set_label (mountable->device, label); else if (STREQ (vfs_type, "xfs")) r = xfslabel (mountable->device, label); diff --git a/daemon/ntfs.c b/daemon/ntfs.c index 0f63391..1ead159 100644 --- a/daemon/ntfs.c +++ b/daemon/ntfs.c @@ -71,6 +71,25 @@ ntfs_get_label (const char *device) } int +ntfs_set_label (const char *device, const char *label) +{ + int r; + CLEANUP_FREE char *err = NULL; + + /* XXX We should check if the label is longer than 128 unicode + * characters and return an error. This is not so easy since we + * don't have the required libraries. + */ + r = command (NULL, &err, str_ntfslabel, device, label, NULL); + if (r == -1) { + reply_with_error ("%s", err); + return -1; + } + + return 0; +} + +int do_ntfs_3g_probe (int rw, const char *device) { CLEANUP_FREE char *err = NULL; -- 2.1.0
Chen Hanxiao
2015-Jul-08 09:34 UTC
[Libguestfs] [PATCH v2 3/4] labels: use existing do_xfs_admin for xfslabel
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/daemon.h | 1 + daemon/labels.c | 18 +----------------- daemon/xfs.c | 7 +++++++ 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index ade385e..508691a 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -267,6 +267,7 @@ extern int copy_xattrs (const char *src, const char *dest); #define XFS_LABEL_MAX 12 extern int xfs_set_uuid (const char *device, const char *uuid); extern int xfs_set_uuid_random (const char *device); +extern int xfs_set_label (const char *device, const char *label); /*-- debug-bmap.c --*/ extern char *debug_bmap (const char *subcmd, size_t argc, char *const *const argv); diff --git a/daemon/labels.c b/daemon/labels.c index 5985d3a..57c6e93 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_xfs_admin, xfs_admin); static int dosfslabel (const char *device, const char *label) @@ -48,9 +47,6 @@ dosfslabel (const char *device, const char *label) static int xfslabel (const char *device, const char *label) { - int r; - CLEANUP_FREE char *err = NULL; - /* Don't allow the special value "---". If people want to clear * the label we'll have to add another call to do that. */ @@ -59,19 +55,7 @@ xfslabel (const char *device, const char *label) return -1; } - if (strlen (label) > XFS_LABEL_MAX) { - reply_with_error ("%s: xfs labels are limited to %d bytes", - label, XFS_LABEL_MAX); - return -1; - } - - r = command (NULL, &err, str_xfs_admin, "-L", label, device, NULL); - if (r == -1) { - reply_with_error ("%s", err); - return -1; - } - - return 0; + return xfs_set_label (device, label); } int diff --git a/daemon/xfs.c b/daemon/xfs.c index 2c93311..e5e8b62 100644 --- a/daemon/xfs.c +++ b/daemon/xfs.c @@ -470,6 +470,13 @@ xfs_set_uuid_random (const char *device) } int +xfs_set_label (const char *device, const char *label) +{ + optargs_bitmask = GUESTFS_XFS_ADMIN_LABEL_BITMASK; + return do_xfs_admin (device, 0, 0, 0, 0, 0, label, NULL); +} + +int do_xfs_admin (const char *device, int extunwritten, int imgfile, int v2log, int projid32bit, -- 2.1.0
Chen Hanxiao
2015-Jul-08 09:34 UTC
[Libguestfs] [PATCH v2] labels: return ENOTSUP if could not set label for specific fs
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- daemon/labels.c | 6 ++---- generator/actions.ml | 4 ++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/daemon/labels.c b/daemon/labels.c index 57c6e93..130f1db 100644 --- a/daemon/labels.c +++ b/daemon/labels.c @@ -85,11 +85,9 @@ do_set_label (const mountable_t *mountable, const char *label) else if (STREQ (vfs_type, "xfs")) r = xfslabel (mountable->device, label); - else { - reply_with_error ("don't know how to set the label for '%s' filesystems", + else + NOT_SUPPORTED(-1, "don't know how to set the label for '%s' filesystems", vfs_type); - r = -1; - } return r; } diff --git a/generator/actions.ml b/generator/actions.ml index 8136d7b..24bcae5 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -9947,6 +9947,10 @@ The label is limited to 11 bytes. =back +If there is no support for changing the UUID +for the type of the specified filesystem, +set_label will fail and set errno as ENOTSUP. + To read the label on a filesystem, call C<guestfs_vfs_label>." }; { defaults with -- 2.1.0
On Wednesday 08 July 2015 17:34:41 Chen Hanxiao wrote:> We should use the existing function from specific fs, > if not, move it to specific fs files. > > Chen Hanxiao (4): > labels: move e2label to ext2.c and call it directly > labels: move ntfslabel to ntfs.c > labels: use existing do_xfs_admin for xfslabel > labels: return ENOTSUP if could not set label for specific fsJust note that in the last patch, there was a typo:> +If there is no support for changing the UUIDshould have been "label"; I fixed it. The series is fine, and I pushed it. Thanks, -- Pino Toscano