From 99fbb3866c1ea7564bf757d79d9ccd520488be98 Mon Sep 17 00:00:00 2001 From: Deepak C Shetty Date: Tue, 10 Jan 2012 18:23:31 +0530 Subject: [PATCH] Do not generate security_model when fs driver is anything but 'path' QEMU does not support security_model for anything but 'path' fs driver type. Currently in libvirt, when security_model ( accessmode attribute) is not specified it auto-generates it irrespective of the fs driver type, which can result in a qemu error for drivers other than path. This patch ensures that the qemu cmdline is correctly generated by taking into account the fs driver type. Signed-off-by: Deepak C Shetty --- AUTHORS | 1 + src/qemu/qemu_command.c | 25 +++++++++++++------ tests/qemuxml2argvdata/qemuxml2argv-fs9p.args | 7 ++++-- tests/qemuxml2argvdata/qemuxml2argv-fs9p.xml | 7 +++++- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index d8599ed49c..b681424bcb 100644 --- a/AUTHORS +++ b/AUTHORS @@ -214,6 +214,7 @@ Patches have also been contributed by: Michael Ellerman Rommer Yuri Chornoivan + Deepak C Shetty [....send patches to get your name here....] diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 16ffb4c86f..d05130559d 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1,7 +1,7 @@ /* * qemu_command.c: QEMU command generation * - * Copyright (C) 2006-2011 Red Hat, Inc. + * Copyright (C) 2006-2012 Red Hat, Inc. * Copyright (C) 2006 Daniel P. Berrange * * This library is free software; you can redistribute it and/or @@ -2132,12 +2132,23 @@ char *qemuBuildFSStr(virDomainFSDefPtr fs, } virBufferAdd(&opt, driver, -1); - if (fs->accessmode == VIR_DOMAIN_FS_ACCESSMODE_MAPPED) { - virBufferAddLit(&opt, ",security_model=mapped"); - } else if(fs->accessmode == VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH) { - virBufferAddLit(&opt, ",security_model=passthrough"); - } else if(fs->accessmode == VIR_DOMAIN_FS_ACCESSMODE_SQUASH) { - virBufferAddLit(&opt, ",security_model=none"); + if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_PATH || + fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT) { + if (fs->accessmode == VIR_DOMAIN_FS_ACCESSMODE_MAPPED) { + virBufferAddLit(&opt, ",security_model=mapped"); + } else if(fs->accessmode == VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH) { + virBufferAddLit(&opt, ",security_model=passthrough"); + } else if(fs->accessmode == VIR_DOMAIN_FS_ACCESSMODE_SQUASH) { + virBufferAddLit(&opt, ",security_model=none"); + } + } else { + /* For other fs drivers, default(passthru) should always + * be supported */ + if (fs->accessmode != VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH) { + qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("only supports passthrough accessmode")); + goto error; + } } virBufferAsprintf(&opt, ",id=%s%s", QEMU_FSDEV_HOST_PREFIX, fs->info.alias); virBufferAsprintf(&opt, ",path=%s", fs->src); diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fs9p.args b/tests/qemuxml2argvdata/qemuxml2argv-fs9p.args index 4c498bab57..857981052f 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fs9p.args +++ b/tests/qemuxml2argvdata/qemuxml2argv-fs9p.args @@ -4,7 +4,10 @@ unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -hda \ /dev/HostVG/QEMUGuest1 -fsdev local,security_model=passthrough,id=fsdev-fs0,\ path=/export/to/guest -device virtio-9p-pci,id=fs0,fsdev=fsdev-fs0,\ mount_tag=/import/from/host,bus=pci.0,addr=0x3 \ --fsdev handle,security_model=mapped,id=fsdev-fs1,\ +-fsdev local,security_model=mapped,id=fsdev-fs1,\ path=/export/to/guest2 -device virtio-9p-pci,id=fs1,fsdev=fsdev-fs1,\ mount_tag=/import/from/host2,bus=pci.0,addr=0x4 \ --usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x5 +-fsdev handle,id=fsdev-fs2,\ +path=/export/to/guest3 -device virtio-9p-pci,id=fs2,fsdev=fsdev-fs2,\ +mount_tag=/import/from/host3,bus=pci.0,addr=0x5 \ +-usb -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fs9p.xml b/tests/qemuxml2argvdata/qemuxml2argv-fs9p.xml index 7ef5923b31..07d7e8abe3 100644 --- a/tests/qemuxml2argvdata/qemuxml2argv-fs9p.xml +++ b/tests/qemuxml2argvdata/qemuxml2argv-fs9p.xml @@ -25,9 +25,14 @@ - + + + + + + -- GitLab