mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
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 d5817537fa added some bogus
documentation implying this call would work for btrfs, but it did
not.
Add tests.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -9509,12 +9509,29 @@ Set the filesystem label on C<mountable> to C<label>.
|
||||
Only some filesystem types support labels, and libguestfs supports
|
||||
setting labels on only a subset of these.
|
||||
|
||||
On ext2/3/4 filesystems, labels are limited to 16 bytes.
|
||||
=over 4
|
||||
|
||||
On NTFS filesystems, labels are limited to 128 unicode characters.
|
||||
=item ext2, ext3, ext4
|
||||
|
||||
Setting the label on a btrfs subvolume will set the label on its parent
|
||||
filesystem.
|
||||
Labels are limited to 16 bytes.
|
||||
|
||||
=item NTFS
|
||||
|
||||
Labels are limited to 128 unicode characters.
|
||||
|
||||
=item XFS
|
||||
|
||||
The label is limited to 12 bytes. The filesystem must not
|
||||
be mounted when trying to set the label.
|
||||
|
||||
=item btrfs
|
||||
|
||||
The label is limited to 256 bytes and some characters are
|
||||
not allowed. Setting the label on a btrfs subvolume will set the
|
||||
label on its parent filesystem. The filesystem must not be mounted
|
||||
when trying to set the label.
|
||||
|
||||
=back
|
||||
|
||||
To read the label on a filesystem, call C<guestfs_vfs_label>." };
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
include $(top_srcdir)/subdir-rules.mk
|
||||
|
||||
TESTS = \
|
||||
test-btrfs-misc.pl \
|
||||
test-btrfs-devices.sh \
|
||||
test-btrfs-subvolume-default.pl
|
||||
|
||||
|
||||
51
tests/btrfs/test-btrfs-misc.pl
Executable file
51
tests/btrfs/test-btrfs-misc.pl
Executable file
@@ -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 ();
|
||||
26
tests/xfs/Makefile.am
Normal file
26
tests/xfs/Makefile.am
Normal file
@@ -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)
|
||||
50
tests/xfs/test-xfs-misc.pl
Executable file
50
tests/xfs/test-xfs-misc.pl
Executable file
@@ -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 ();
|
||||
Reference in New Issue
Block a user