[PATCH 1/2] qemu: introduce locking option for disk source of qemu

From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> Introduce locking option for disk source of qemu. It may be useful to avoid file lock issues. locking option supports three switches; 'auto', 'on' and 'off'. The default behaivor will work if locking option isn't set. Example of the usage: <disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/tmp/QEMUGuest1.img' locking='off'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk> Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> --- docs/schemas/domaincommon.rng | 9 +++++++++ src/conf/domain_conf.c | 8 ++++++++ src/conf/storage_source_conf.c | 9 +++++++++ src/conf/storage_source_conf.h | 14 ++++++++++++++ src/libvirt_private.syms | 1 + src/qemu/qemu_block.c | 5 +++++ 6 files changed, 46 insertions(+) diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index a4bddcf132..d33d853f31 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1676,6 +1676,15 @@ <ref name="devSeclabel"/> </zeroOrMore> </interleave> + <optional> + <attribute name="locking"> + <choice> + <value>auto</value> + <value>on</value> + <value>off</value> + </choice> + </attribute> + </optional> </element> </optional> </define> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index dab4f10326..067ffa877b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8540,6 +8540,7 @@ virDomainStorageSourceParse(xmlNodePtr node, { VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr tmp; + char *locking; ctxt->node = node; @@ -8606,6 +8607,9 @@ virDomainStorageSourceParse(xmlNodePtr node, return -1; } + if ((locking = virXMLPropString(node, "locking"))) + src->locking = virStorageFileLockingTypeFromString(locking); + return 0; } @@ -24102,6 +24106,10 @@ virDomainDiskSourceFormat(virBufferPtr buf, return -1; } + if (src->locking != VIR_STORAGE_FILE_LOCKING_DEFAULT) + virBufferEscapeString(&attrBuf, " locking='%s'", + virStorageFileLockingTypeToString(src->locking)); + virDomainDiskSourceFormatSlices(&childBuf, src); if (src->type != VIR_STORAGE_TYPE_NETWORK) diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index dab5e855f5..3ac0c7f75b 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -49,6 +49,15 @@ VIR_ENUM_IMPL(virStorage, ); +VIR_ENUM_IMPL(virStorageFileLocking, + VIR_STORAGE_FILE_LOCKING_LAST, + "default", + "auto", + "on", + "off", +); + + VIR_ENUM_IMPL(virStorageFileFormat, VIR_STORAGE_FILE_LAST, "none", diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index e66ccdedef..6f5b165504 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -82,6 +82,18 @@ typedef enum { VIR_ENUM_DECL(virStorageFileFormat); +typedef enum { + VIR_STORAGE_FILE_LOCKING_DEFAULT = 0, + VIR_STORAGE_FILE_LOCKING_AUTO, + VIR_STORAGE_FILE_LOCKING_ON, + VIR_STORAGE_FILE_LOCKING_OFF, + + VIR_STORAGE_FILE_LOCKING_LAST, +} virStorageFileLocking; + +VIR_ENUM_DECL(virStorageFileLocking); + + typedef enum { VIR_STORAGE_FILE_FEATURE_LAZY_REFCOUNTS = 0, @@ -394,6 +406,8 @@ struct _virStorageSource { char *nfs_group; uid_t nfs_uid; gid_t nfs_gid; + + int locking; /* enum virStorageFileLocking */ }; G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSource, virObjectUnref); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fbaf16704b..c72d2161b2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1068,6 +1068,7 @@ virStorageFileFeatureTypeFromString; virStorageFileFeatureTypeToString; virStorageFileFormatTypeFromString; virStorageFileFormatTypeToString; +virStorageFileLockingTypeToString; virStorageNetHostDefClear; virStorageNetHostDefCopy; virStorageNetHostDefFree; diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index d845a3312d..d7eec16ab6 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1015,6 +1015,7 @@ qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src, { const char *iomode = NULL; const char *prManagerAlias = NULL; + const char *locking = NULL; virJSONValuePtr ret = NULL; if (!onlytarget) { @@ -1023,12 +1024,16 @@ qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src, if (src->iomode != VIR_DOMAIN_DISK_IO_DEFAULT) iomode = virDomainDiskIoTypeToString(src->iomode); + + if (src->locking != VIR_STORAGE_FILE_LOCKING_DEFAULT) + locking = virStorageFileLockingTypeToString(src->locking); } ignore_value(virJSONValueObjectCreate(&ret, "s:filename", src->path, "S:aio", iomode, "S:pr-manager", prManagerAlias, + "S:locking", locking, NULL) < 0); return ret; } -- 2.27.0

From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> Add testing for locking option for qemu disk source. Test three switches for locking: 'auto', 'on' and 'off'. Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> --- .../disk-file-locking-auto.x86_64-latest.args | 43 +++++++++++++++++++ .../disk-file-locking-auto.xml | 27 ++++++++++++ .../disk-file-locking-off.x86_64-latest.args | 43 +++++++++++++++++++ .../disk-file-locking-off.xml | 27 ++++++++++++ .../disk-file-locking-on.x86_64-latest.args | 43 +++++++++++++++++++ .../qemuxml2argvdata/disk-file-locking-on.xml | 27 ++++++++++++ tests/qemuxml2argvtest.c | 3 ++ 7 files changed, 213 insertions(+) create mode 100644 tests/qemuxml2argvdata/disk-file-locking-auto.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-file-locking-auto.xml create mode 100644 tests/qemuxml2argvdata/disk-file-locking-off.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-file-locking-off.xml create mode 100644 tests/qemuxml2argvdata/disk-file-locking-on.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-file-locking-on.xml diff --git a/tests/qemuxml2argvdata/disk-file-locking-auto.x86_64-latest.args b/tests/qemuxml2argvdata/disk-file-locking-auto.x86_64-latest.args new file mode 100644 index 0000000000..4abe38515c --- /dev/null +++ b/tests/qemuxml2argvdata/disk-file-locking-auto.x86_64-latest.args @@ -0,0 +1,43 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off,memory-backend=pc.ram \ +-cpu qemu64 \ +-m 214 \ +-object memory-backend-ram,id=pc.ram,size=224395264 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-blockdev '{"driver":"file","filename":"/tmp/QEMUGuest1.img","locking":"auto",\ +"node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"file":"libvirt-1-storage"}' \ +-device ide-hd,bus=ide.0,unit=0,drive=libvirt-1-format,id=ide0-0-0,bootindex=1,\ +write-cache=on \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/disk-file-locking-auto.xml b/tests/qemuxml2argvdata/disk-file-locking-auto.xml new file mode 100644 index 0000000000..9ae9372c01 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-file-locking-auto.xml @@ -0,0 +1,27 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-i386</emulator> + <disk type='file' device='disk'> + <driver name='qemu' type='qcow2' cache='none'/> + <source file='/tmp/QEMUGuest1.img' locking='auto'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/disk-file-locking-off.x86_64-latest.args b/tests/qemuxml2argvdata/disk-file-locking-off.x86_64-latest.args new file mode 100644 index 0000000000..33786b46cd --- /dev/null +++ b/tests/qemuxml2argvdata/disk-file-locking-off.x86_64-latest.args @@ -0,0 +1,43 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off,memory-backend=pc.ram \ +-cpu qemu64 \ +-m 214 \ +-object memory-backend-ram,id=pc.ram,size=224395264 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-blockdev '{"driver":"file","filename":"/tmp/QEMUGuest1.img","locking":"off",\ +"node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"file":"libvirt-1-storage"}' \ +-device ide-hd,bus=ide.0,unit=0,drive=libvirt-1-format,id=ide0-0-0,bootindex=1,\ +write-cache=on \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/disk-file-locking-off.xml b/tests/qemuxml2argvdata/disk-file-locking-off.xml new file mode 100644 index 0000000000..2c9561b935 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-file-locking-off.xml @@ -0,0 +1,27 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-i386</emulator> + <disk type='file' device='disk'> + <driver name='qemu' type='qcow2' cache='none'/> + <source file='/tmp/QEMUGuest1.img' locking='off'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/disk-file-locking-on.x86_64-latest.args b/tests/qemuxml2argvdata/disk-file-locking-on.x86_64-latest.args new file mode 100644 index 0000000000..929eb064fc --- /dev/null +++ b/tests/qemuxml2argvdata/disk-file-locking-on.x86_64-latest.args @@ -0,0 +1,43 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off,memory-backend=pc.ram \ +-cpu qemu64 \ +-m 214 \ +-object memory-backend-ram,id=pc.ram,size=224395264 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-blockdev '{"driver":"file","filename":"/tmp/QEMUGuest1.img","locking":"on",\ +"node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"file":"libvirt-1-storage"}' \ +-device ide-hd,bus=ide.0,unit=0,drive=libvirt-1-format,id=ide0-0-0,bootindex=1,\ +write-cache=on \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/disk-file-locking-on.xml b/tests/qemuxml2argvdata/disk-file-locking-on.xml new file mode 100644 index 0000000000..9bcea0ed3e --- /dev/null +++ b/tests/qemuxml2argvdata/disk-file-locking-on.xml @@ -0,0 +1,27 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-i386</emulator> + <disk type='file' device='disk'> + <driver name='qemu' type='qcow2' cache='none'/> + <source file='/tmp/QEMUGuest1.img' locking='on'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index cf77224fc3..b4509c0083 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1319,6 +1319,9 @@ mymain(void) QEMU_CAPS_ICH9_AHCI); DO_TEST_PARSE_ERROR("disk-hostdev-scsi-address-conflict", QEMU_CAPS_VIRTIO_SCSI); + DO_TEST_CAPS_LATEST("disk-file-locking-auto"); + DO_TEST_CAPS_LATEST("disk-file-locking-on"); + DO_TEST_CAPS_LATEST("disk-file-locking-off"); DO_TEST_PARSE_ERROR("hostdevs-drive-address-conflict", QEMU_CAPS_VIRTIO_SCSI); DO_TEST("event_idx", -- 2.27.0

On Fri, Jan 22, 2021 at 21:32:06 -0500, Masayoshi Mizuma wrote:
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Add testing for locking option for qemu disk source. Test three switches for locking: 'auto', 'on' and 'off'.
Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> --- .../disk-file-locking-auto.x86_64-latest.args | 43 +++++++++++++++++++ .../disk-file-locking-auto.xml | 27 ++++++++++++ .../disk-file-locking-off.x86_64-latest.args | 43 +++++++++++++++++++ .../disk-file-locking-off.xml | 27 ++++++++++++ .../disk-file-locking-on.x86_64-latest.args | 43 +++++++++++++++++++ .../qemuxml2argvdata/disk-file-locking-on.xml | 27 ++++++++++++
You can add multiple disks with distinct locking parameters into a single file rather than having 3 separate files. Additionally the tests are missing the control of 'locking' for <backingStore>

On Fri, Jan 22, 2021 at 21:32:05 -0500, Masayoshi Mizuma wrote:
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Introduce locking option for disk source of qemu. It may be useful to avoid file lock issues.
Lock issues usually mean that you are doing something wrong.
locking option supports three switches; 'auto', 'on' and 'off'. The default behaivor will work if locking option isn't set.
Example of the usage:
<disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/tmp/QEMUGuest1.img' locking='off'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk>
Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> --- docs/schemas/domaincommon.rng | 9 +++++++++ src/conf/domain_conf.c | 8 ++++++++ src/conf/storage_source_conf.c | 9 +++++++++ src/conf/storage_source_conf.h | 14 ++++++++++++++ src/libvirt_private.syms | 1 + src/qemu/qemu_block.c | 5 +++++ 6 files changed, 46 insertions(+)
Few quick notes: - I'm not entirely persuaded that we should at this at all - qemu locking works to prevent user mistakes - you really need to know what to expect if you use images which are used by multiple VMs - you really need to add some form of justification, the current one definitely is insufficient and thus I'm inclined to NACKing the concept of enabling setting of the locks completely Please describe the use case in details. - documentation is completely missing - note that it should be worded such that it sternly discourages touching this option at all - the patch must be split at least into two - adding the XML bits and docs - qemu bits - it's only implemented for 'VIR_STORAGE_TYPE_BLOCK' and 'VIR_STORAGE_TYPE_FILE' but the patch is completely missing a check that it's used with a network or other disk which doesn't actually support locking.
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index dab4f10326..067ffa877b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8540,6 +8540,7 @@ virDomainStorageSourceParse(xmlNodePtr node, { VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr tmp; + char *locking;
ctxt->node = node;
@@ -8606,6 +8607,9 @@ virDomainStorageSourceParse(xmlNodePtr node, return -1; }
+ if ((locking = virXMLPropString(node, "locking"))) + src->locking = virStorageFileLockingTypeFromString(locking);
'locking' temporary variable is leaked
+ return 0; }
diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index e66ccdedef..6f5b165504 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h
[...]
@@ -394,6 +406,8 @@ struct _virStorageSource { char *nfs_group; uid_t nfs_uid; gid_t nfs_gid; + + int locking; /* enum virStorageFileLocking */
We prefer to use the enum type directly if possible. It requires a temproary variable in the parser though.
};
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageSource, virObjectUnref);
[...]
@@ -1023,12 +1024,16 @@ qemuBlockStorageSourceGetFileProps(virStorageSourcePtr src,
if (src->iomode != VIR_DOMAIN_DISK_IO_DEFAULT) iomode = virDomainDiskIoTypeToString(src->iomode); + + if (src->locking != VIR_STORAGE_FILE_LOCKING_DEFAULT) + locking = virStorageFileLockingTypeToString(src->locking); }
ignore_value(virJSONValueObjectCreate(&ret, "s:filename", src->path, "S:aio", iomode, "S:pr-manager", prManagerAlias, + "S:locking", locking, NULL) < 0); return ret; } -- 2.27.0

On Sat, Jan 23, 2021 at 11:12:15AM +0100, Peter Krempa wrote:
On Fri, Jan 22, 2021 at 21:32:05 -0500, Masayoshi Mizuma wrote:
From: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Introduce locking option for disk source of qemu. It may be useful to avoid file lock issues.
Lock issues usually mean that you are doing something wrong.
locking option supports three switches; 'auto', 'on' and 'off'. The default behaivor will work if locking option isn't set.
Example of the usage:
<disk type='file' device='disk'> <driver name='qemu' type='qcow2' cache='none'/> <source file='/tmp/QEMUGuest1.img' locking='off'/> <target dev='hda' bus='ide'/> <address type='drive' controller='0' bus='0' target='0' unit='0'/> </disk>
Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> --- docs/schemas/domaincommon.rng | 9 +++++++++ src/conf/domain_conf.c | 8 ++++++++ src/conf/storage_source_conf.c | 9 +++++++++ src/conf/storage_source_conf.h | 14 ++++++++++++++ src/libvirt_private.syms | 1 + src/qemu/qemu_block.c | 5 +++++ 6 files changed, 46 insertions(+)
Few quick notes:
- I'm not entirely persuaded that we should at this at all - qemu locking works to prevent user mistakes - you really need to know what to expect if you use images which are used by multiple VMs
- you really need to add some form of justification, the current one definitely is insufficient and thus I'm inclined to NACKing the concept of enabling setting of the locks completely
I agree - we should be providing higher level conceptual logic that indirectly maps into the different locking states. For example we have <readonly/> and <shareable/> elements that influence the type of locks held. A flag to unconditionally disable locking entirely feels like it is just hacking around some undefined problem that should be fixed in a better way. Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (3)
-
Daniel P. Berrangé
-
Masayoshi Mizuma
-
Peter Krempa