diff options
author | Richard W.M. Jones <rjones@redhat.com> | 2012-04-25 16:35:12 +0100 |
---|---|---|
committer | Richard W.M. Jones <rjones@redhat.com> | 2012-04-25 17:32:30 +0100 |
commit | 87ea7a04094d5ed40f3f047ff2b7a613d4d530d4 (patch) | |
tree | 458b3713c313d124c37b8de11e45d0b081f3fde6 /tests | |
parent | 3cc9703f901e85a589692b9d0bf5ef7cbf72ed73 (diff) | |
download | libguestfs-87ea7a04094d5ed40f3f047ff2b7a613d4d530d4.tar.gz libguestfs-87ea7a04094d5ed40f3f047ff2b7a613d4d530d4.tar.xz libguestfs-87ea7a04094d5ed40f3f047ff2b7a613d4d530d4.zip |
New btrfs APIs.
Bind the easy parts of the 'btrfs' program.
The new APIs are:
btrfs-device-add: add devices to a btrfs filesystem
btrfs-device-delete: remove devices from a btrfs filesystem
btrfs-filesystem-sync: sync a btrfs filesystem
btrfs-filesystem-balance: balance a btrfs filesystem
btrfs-subvolume-create: create a btrfs snapshot
btrfs-subvolume-delete: delete a btrfs snapshot
btrfs-subvolume-list: list btrfs snapshots and subvolumes
btrfs-subvolume-set-default: set default btrfs subvolume
btrfs-subvolume-snapshot: create a writable btrfs snapshot
Diffstat (limited to 'tests')
-rw-r--r-- | tests/btrfs/Makefile.am | 31 | ||||
-rwxr-xr-x | tests/btrfs/test-btrfs-devices.sh | 57 | ||||
-rwxr-xr-x | tests/btrfs/test-btrfs-subvolume-default.pl | 95 |
3 files changed, 183 insertions, 0 deletions
diff --git a/tests/btrfs/Makefile.am b/tests/btrfs/Makefile.am new file mode 100644 index 00000000..6d789ba7 --- /dev/null +++ b/tests/btrfs/Makefile.am @@ -0,0 +1,31 @@ +# libguestfs +# Copyright (C) 2009-2012 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-btrfs-devices.sh \ + test-btrfs-subvolume-default.pl + +random_val := $(shell awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null) + +TESTS_ENVIRONMENT = \ + MALLOC_PERTURB_=$(random_val) \ + $(top_builddir)/run + +EXTRA_DIST = \ + $(TESTS) diff --git a/tests/btrfs/test-btrfs-devices.sh b/tests/btrfs/test-btrfs-devices.sh new file mode 100755 index 00000000..546ce7c5 --- /dev/null +++ b/tests/btrfs/test-btrfs-devices.sh @@ -0,0 +1,57 @@ +#!/bin/bash - +# libguestfs +# Copyright (C) 2012 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. + +# Test btrfs adding/removing devices. + +set -e + +# XXX Not a very good test. +if ! btrfs --help >/dev/null 2>&1; then + echo "$0: test skipped because no 'btrfs' utility" + exit 0 +fi + +rm -f test[1234].img + +../../fish/guestfish <<EOF +# Add four empty disks +sparse test1.img 1G +sparse test2.img 1G +sparse test3.img 1G +sparse test4.img 1G +run + +part-disk /dev/sda mbr +part-disk /dev/sdb mbr +part-disk /dev/sdc mbr +part-disk /dev/sdd mbr + +mkfs-btrfs "/dev/sda1 /dev/sdb1" +mount /dev/sda1 / + +mkdir /foo +touch /foo/bar + +btrfs-device-add "/dev/sdc1 /dev/sdd1" / + +# I cannot get this to work, seems to be a btrfs bug: +#btrfs-device-delete "/dev/sda1 /dev/sdb1" / + +EOF + +rm -f test[1234].img diff --git a/tests/btrfs/test-btrfs-subvolume-default.pl b/tests/btrfs/test-btrfs-subvolume-default.pl new file mode 100755 index 00000000..013291ba --- /dev/null +++ b/tests/btrfs/test-btrfs-subvolume-default.pl @@ -0,0 +1,95 @@ +#!/usr/bin/perl +# libguestfs +# Copyright (C) 2012 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. + +# Test btrfs subvolume list and btrfs subvolume default-id. + +use strict; +use warnings; + +use Sys::Guestfs; +use Sys::Guestfs::Lib qw(feature_available); + +my $testimg = "test1.img"; + +unlink $testimg; +open FILE, ">$testimg" or die "$testimg: $!"; +truncate FILE, 1024*1024*1024 or die "$testimg: truncate: $!"; +close FILE or die "$testimg: $!"; + +my $g = Sys::Guestfs->new (); + +$g->add_drive_opts ($testimg, format => "raw"); +$g->launch (); + +# If btrfs is not available, bail. +unless (feature_available ($g, "btrfs")) { + warn "$0: skipping test because btrfs is not available\n"; + exit 0; +} + +$g->part_disk ("/dev/sda", "mbr"); + +$g->mkfs_btrfs (["/dev/sda1"]); +$g->mount ("/dev/sda1", "/"); + +$g->btrfs_subvolume_create ("/test1"); +$g->mkdir ("/test1/foo"); +$g->btrfs_subvolume_create ("/test2"); + +my @vols = $g->btrfs_subvolume_list ("/"); + +# Check the subvolume list, and extract the subvolume ID of path 'test1', +# and the top level ID (which should be the same for both subvolumes). +die ("expected 2 subvolumes, but got ", 0+@vols, " instead") unless @vols == 2; + +my %ids; +my $top_level_id; +foreach (@vols) { + my $path = $_->{btrfssubvolume_path}; + my $id = $_->{btrfssubvolume_id}; + my $top = $_->{btrfssubvolume_top_level_id}; + + if (!defined $top_level_id) { + $top_level_id = $top; + } elsif ($top_level_id != $top) { + die "top_level_id fields are not all the same"; + } + + $ids{$path} = $id; +} + +die "no subvolume path 'test1' found" unless exists $ids{test1}; + +my $test1_id = $ids{test1}; + +$g->btrfs_subvolume_set_default ($test1_id, "/"); +$g->umount ("/"); +$g->mount ("/dev/sda1", "/"); +# This was originally /test1/foo, but now that we changed the +# default ID to 'test1', /test1 is mounted as /, so: +$g->mkdir ("/foo/bar"); + +$g->btrfs_subvolume_set_default ($top_level_id, "/"); +$g->umount ("/"); +$g->mount ("/dev/sda1", "/"); +# Now we're back to the original default volume, so this should work: +$g->mkdir ("/test1/foo/bar/baz"); + +$g->close (); + +unlink $testimg or die "$testimg: unlink: $!"; |