From 091d22f49e7fcb53fb3bb23e2ba94ca12eb88eab Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Mon, 22 Jul 2013 11:29:42 +0100 Subject: [PATCH] daemon: Implement set-label for XFS and fix it for btrfs (RHBZ#986875). Implement 'set-label' for XFS filesystems. Fix the call for btrfs. Previous commit d5817537fa6c51a7f851ecc5e4e63e60609e0c03 added some bogus documentation implying this call would work for btrfs, but it did not. Add tests. --- Makefile.am | 1 + configure.ac | 1 + daemon/labels.c | 47 +++++++++++++++++++++++++++++++ generator/actions.ml | 25 ++++++++++++++--- tests/btrfs/Makefile.am | 1 + tests/btrfs/test-btrfs-misc.pl | 51 ++++++++++++++++++++++++++++++++++ tests/xfs/Makefile.am | 26 +++++++++++++++++ tests/xfs/test-xfs-misc.pl | 50 +++++++++++++++++++++++++++++++++ 8 files changed, 198 insertions(+), 4 deletions(-) create mode 100755 tests/btrfs/test-btrfs-misc.pl create mode 100644 tests/xfs/Makefile.am create mode 100755 tests/xfs/test-xfs-misc.pl diff --git a/Makefile.am b/Makefile.am index 123045f7c..1352b5255 100644 --- a/Makefile.am +++ b/Makefile.am @@ -46,6 +46,7 @@ SUBDIRS += tests/md SUBDIRS += tests/selinux SUBDIRS += tests/ntfsclone SUBDIRS += tests/btrfs +SUBDIRS += tests/xfs SUBDIRS += tests/charsets SUBDIRS += tests/xml SUBDIRS += tests/mount-local diff --git a/configure.ac b/configure.ac index bbcda8238..7053e8895 100644 --- a/configure.ac +++ b/configure.ac @@ -1676,6 +1676,7 @@ AC_CONFIG_FILES([Makefile tests/selinux/Makefile tests/syslinux/Makefile tests/tmpdirs/Makefile + tests/xfs/Makefile tests/xml/Makefile tools/Makefile]) AC_OUTPUT diff --git a/daemon/labels.c b/daemon/labels.c index a0181382f..10e40dc30 100644 --- a/daemon/labels.c +++ b/daemon/labels.c @@ -27,8 +27,10 @@ #include "actions.h" #include "optgroups.h" +GUESTFSD_EXT_CMD(str_btrfs, btrfs); GUESTFSD_EXT_CMD(str_e2label, e2label); GUESTFSD_EXT_CMD(str_ntfslabel, ntfslabel); +GUESTFSD_EXT_CMD(str_xfs_admin, xfs_admin); static int e2label (const char *device, const char *label) @@ -70,6 +72,45 @@ ntfslabel (const char *device, const char *label) return 0; } +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. + */ + if (STREQ (label, "---")) { + reply_with_error ("xfs: invalid new label"); + 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; +} + +static int +btrfslabel (const char *device, const char *label) +{ + int r; + CLEANUP_FREE char *err = NULL; + + r = command (NULL, &err, str_btrfs, "filesystem", "label", + device, label, NULL); + if (r == -1) { + reply_with_error ("%s", err); + return -1; + } + + return 0; +} + int do_set_label (const mountable_t *mountable, const char *label) { @@ -86,6 +127,12 @@ do_set_label (const mountable_t *mountable, const char *label) else if (STREQ (vfs_type, "ntfs")) r = ntfslabel (mountable->device, label); + else if (STREQ (vfs_type, "xfs")) + r = xfslabel (mountable->device, label); + + else if (STREQ (vfs_type, "btrfs")) + r = btrfslabel (mountable->device, label); + else { reply_with_error ("don't know how to set the label for '%s' filesystems", vfs_type); diff --git a/generator/actions.ml b/generator/actions.ml index d2b0e0fc9..db2558577 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -9509,12 +9509,29 @@ Set the filesystem label on C to C