[pve-devel] [PATCH qemu-server] fix #947: reenable disk passthrough
Dominik Csapak
d.csapak at proxmox.com
Thu Apr 21 08:58:47 CEST 2016
previously, we did not check the file parameter of a disk,
allowing passthrough of a block device (by design)
with the change to the json parser for the disks, the format
became 'pve-volume-id' which is only valid for our volume ids
(and later we also allowed the value 'none')
this patch alternatively checks if the parameter is a path
and if it is, whether it is a block device in /dev
if this check passes, we allow it
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/QemuServer.pm | 22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 189d760..4198fd4 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -619,11 +619,27 @@ for (my $i = 0; $i < $MAX_NETS; $i++) {
$confdesc->{"net$i"} = $netdesc;
}
-PVE::JSONSchema::register_format('pve-volume-id-or-none', \&verify_volume_id_or_none);
-sub verify_volume_id_or_none {
+PVE::JSONSchema::register_format('pve-qm-disk', \&verify_qm_disk);
+sub verify_qm_disk {
my ($volid, $noerr) = @_;
return $volid if $volid eq 'none';
+
+ # if parameter is a path, we check if its a block device in /dev
+ # this is for sata/disk passthrough
+ if ($volid =~ m|^/|) {
+ my $realpath = Cwd::realpath($volid);
+
+ # check if its in /dev and a blockdevice
+ if ($realpath =~ m|^/dev| && -b $realpath) {
+ return $realpath;
+ } else {
+ return undef if $noerr;
+ die "$realpath is not a valid block device\n";
+ }
+ }
+
+ # if its neither 'none' nor a path, check if its a volume-id
$volid = eval { PVE::JSONSchema::check_format('pve-volume-id', $volid, '') };
if ($@) {
return undef if $noerr;
@@ -638,7 +654,7 @@ my %drivedesc_base = (
volume => { alias => 'file' },
file => {
type => 'string',
- format => 'pve-volume-id-or-none',
+ format => 'pve-qm-disk',
default_key => 1,
format_description => 'volume',
description => "The drive's backing volume.",
--
2.1.4
More information about the pve-devel
mailing list