Blob Blame History Raw
From 6d4a1c16c88e8a728183590fee2867aabe8a15d8 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
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.

(cherry picked from commit 091d22f49e7fcb53fb3bb23e2ba94ca12eb88eab)
---
 Makefile.am                    |  1 +
 configure.ac                   |  1 +
 tests/btrfs/Makefile.am        |  1 +
 tests/btrfs/test-btrfs-misc.pl | 51 ++++++++++++++++++++++++++++++++++++++++++
 tests/xfs/Makefile.am          | 26 +++++++++++++++++++++
 tests/xfs/test-xfs-misc.pl     | 50 +++++++++++++++++++++++++++++++++++++++++
 6 files changed, 130 insertions(+)
 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 de747b0..c36f028 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -49,6 +49,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 62d558f..75232e8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1654,6 +1654,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/tests/btrfs/Makefile.am b/tests/btrfs/Makefile.am
index 32a2d65..87854ac 100644
--- a/tests/btrfs/Makefile.am
+++ b/tests/btrfs/Makefile.am
@@ -18,6 +18,7 @@
 include $(top_srcdir)/subdir-rules.mk
 
 TESTS = \
+	test-btrfs-misc.pl \
 	test-btrfs-devices.sh \
 	test-btrfs-subvolume-default.pl
 
diff --git a/tests/btrfs/test-btrfs-misc.pl b/tests/btrfs/test-btrfs-misc.pl
new file mode 100755
index 0000000..2fe7c59
--- /dev/null
+++ b/tests/btrfs/test-btrfs-misc.pl
@@ -0,0 +1,51 @@
+#!/usr/bin/perl
+# libguestfs
+# Copyright (C) 2013 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Miscellaneous btrfs features.
+
+use strict;
+use warnings;
+
+use Sys::Guestfs;
+
+# Allow the test to be skipped since btrfs is often broken.
+exit 77 if $ENV{SKIP_TEST_BTRFS_MISC_PL};
+
+my $g = Sys::Guestfs->new ();
+
+$g->add_drive_scratch (1024*1024*1024);
+$g->launch ();
+
+# If btrfs is not available, bail.
+unless ($g->feature_available (["btrfs"])) {
+    warn "$0: skipping test because btrfs is not available\n";
+    exit 77;
+}
+
+$g->part_disk ("/dev/sda", "mbr");
+
+$g->mkfs_btrfs (["/dev/sda1"]);
+
+# Setting label.
+$g->set_label ("/dev/sda1", "newlabel");
+my $label = $g->vfs_label ("/dev/sda1");
+die "unexpected label: expecting 'newlabel' but got '$label'"
+    unless $label eq "newlabel";
+
+$g->shutdown ();
+$g->close ();
diff --git a/tests/xfs/Makefile.am b/tests/xfs/Makefile.am
new file mode 100644
index 0000000..fbe0e15
--- /dev/null
+++ b/tests/xfs/Makefile.am
@@ -0,0 +1,26 @@
+# libguestfs
+# Copyright (C) 2013 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+include $(top_srcdir)/subdir-rules.mk
+
+TESTS = \
+	test-xfs-misc.pl
+
+TESTS_ENVIRONMENT = $(top_builddir)/run --test
+
+EXTRA_DIST = \
+	$(TESTS)
diff --git a/tests/xfs/test-xfs-misc.pl b/tests/xfs/test-xfs-misc.pl
new file mode 100755
index 0000000..4036708
--- /dev/null
+++ b/tests/xfs/test-xfs-misc.pl
@@ -0,0 +1,50 @@
+#!/usr/bin/perl
+# libguestfs
+# Copyright (C) 2013 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+# Miscellaneous xfs features.
+
+use strict;
+use warnings;
+
+use Sys::Guestfs;
+
+exit 77 if $ENV{SKIP_TEST_XFS_MISC_PL};
+
+my $g = Sys::Guestfs->new ();
+
+$g->add_drive_scratch (1024*1024*1024);
+$g->launch ();
+
+# If xfs is not available, bail.
+unless ($g->feature_available (["xfs"])) {
+    warn "$0: skipping test because xfs is not available\n";
+    exit 77;
+}
+
+$g->part_disk ("/dev/sda", "mbr");
+
+$g->mkfs ("xfs", "/dev/sda1");
+
+# Setting label.
+$g->set_label ("/dev/sda1", "newlabel");
+my $label = $g->vfs_label ("/dev/sda1");
+die "unexpected label: expecting 'newlabel' but got '$label'"
+    unless $label eq "newlabel";
+
+$g->shutdown ();
+$g->close ();
-- 
1.8.3.1