[libvirt] [TCK PATCH] block devices: allow specification of size for safety

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I was getting failures of domain/103-blockdev-save-restore.t when
connecting as qemu:///session, since my uid could stat /dev/sdb
but not open it.  That test now skips for unprivileged users, as well
as adds a layer of sanity checking against expected size to avoid
trashing the wrong device.

* conf/default.cfg (host_block_devices): Document optional size.
* lib/Sys/Virt/TCK.pm (get_host_block_device): If optional size is
supplied, skip a device that does not match.  Also, avoid devices
that can't be opened.
---

Go easy on me - I'm not that fluent in perl (yet); if there's
a better way to do the sanity check, I'm all ears.

 conf/default.cfg    |    8 ++++++++
 lib/Sys/Virt/TCK.pm |   14 +++++++++++++-
 2 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/conf/default.cfg b/conf/default.cfg
index 01f438c..12c05b7 100644
--- a/conf/default.cfg
+++ b/conf/default.cfg
@@ -134,5 +134,13 @@ host_pci_devices = (
 # the test suite itself needs to create partitions.
 # The disks should be at *least* 512 MB in size
 host_block_devices = (
+# Each block device is either a raw path
 #  /dev/vdb
+# or a path plus size in 1k blocks, as in /proc/partitions, to avoid
+# trashing the wrong device
+#  {
+#    path = /dev/sdb
+#    size = 989184
+#  }
+# Can list more than on block device if many are available
 )
diff --git a/lib/Sys/Virt/TCK.pm b/lib/Sys/Virt/TCK.pm
index 9cdef09..fc325a3 100644
--- a/lib/Sys/Virt/TCK.pm
+++ b/lib/Sys/Virt/TCK.pm
@@ -33,6 +33,7 @@ use IO::Uncompress::Gunzip qw(gunzip);
 use IO::Uncompress::Bunzip2 qw(bunzip2);
 use XML::XPath;
 use Carp qw(cluck carp);
+use Fcntl qw(O_RDONLY SEEK_END);

 use Test::Builder;
 use Sub::Uplevel qw(uplevel);
@@ -833,7 +834,18 @@ sub get_host_block_device {
     my $self = shift;
     my $devindex = @_ ? shift : 0;

-    return $self->config("host_block_devices/[$devindex]", undef);
+    my $device = $self->config("host_block_devices/[$devindex]/path", undef);
+    my $size = $self->config("host_block_devices/[$devindex]/size", 0);
+
+    if (!defined $device) {
+	$device = $self->config("host_block_devices/[$devindex]", undef);
+    }
+    if ($size) {
+	sysopen(BLK, "$device", O_RDONLY) or return undef;
+	return undef unless sysseek(BLK, 0, SEEK_END) == $size * 1024;
+	close(BLK);
+    }
+    return $device;
 }

 1;
-- 
1.6.6.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]