[PATCH 2/2] qemu_block: add locking option

Hiroki Narukawa posted 2 patches 1 year, 12 months ago
[PATCH 2/2] qemu_block: add locking option
Posted by Hiroki Narukawa 1 year, 12 months ago
There is a case that locking hits a bug and users wants to disable
locking like bug in Linux kernel.

This commit adds actual qemu option to the domain conf added in previous
commit.

Signed-off-by: Hiroki Narukawa <hnarukaw@yahoo-corp.jp>
---
 src/qemu/qemu_block.c                         |  7 ++++++
 tests/qemublocktest.c                         |  1 +
 ...le-raw-aio_native-locking-off-srconly.json | 10 ++++++++
 .../file-raw-aio_native-locking-off.json      | 23 +++++++++++++++++++
 .../file-raw-aio_native-locking-off.xml       | 12 ++++++++++
 5 files changed, 53 insertions(+)
 create mode 100644 tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off-srconly.json
 create mode 100644 tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.json
 create mode 100644 tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.xml

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 738b72d7ea..5905898b38 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -852,6 +852,13 @@ qemuBlockStorageSourceGetFileProps(virStorageSource *src,
                                        "S:aio", iomode,
                                        "S:pr-manager", prManagerAlias,
                                        NULL) < 0);
+
+    if (src->locking) {
+        const char *lockingStr = virTristateSwitchTypeToString(src->locking);
+        if (virJSONValueObjectAdd(&ret, "S:locking", lockingStr, NULL) < 0)
+            return NULL;
+    }
+
     return ret;
 }
 
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index c581bd1748..3b005cb475 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -1116,6 +1116,7 @@ mymain(void)
     TEST_DISK_TO_JSON("dir-fat-readonly");
     TEST_DISK_TO_JSON("dir-fat-floppy");
     TEST_DISK_TO_JSON("file-raw-aio_native");
+    TEST_DISK_TO_JSON("file-raw-aio_native-locking-off");
     TEST_DISK_TO_JSON("file-backing_basic-aio_threads");
     TEST_DISK_TO_JSON("file-backing_basic-aio_io_uring");
     TEST_DISK_TO_JSON("file-raw-luks");
diff --git a/tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off-srconly.json b/tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off-srconly.json
new file mode 100644
index 0000000000..88c9970ccf
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off-srconly.json
@@ -0,0 +1,10 @@
+(
+  source only properties:
+  {
+    "driver": "file",
+    "filename": "/path/to/i.img",
+    "locking": "off"
+  }
+  backing store string:
+  /path/to/i.img
+)
diff --git a/tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.json b/tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.json
new file mode 100644
index 0000000000..aeb483e4b4
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.json
@@ -0,0 +1,23 @@
+{
+  "node-name": "test1",
+  "read-only": false,
+  "cache": {
+    "direct": true,
+    "no-flush": false
+  },
+  "driver": "raw",
+  "file": "test2"
+}
+{
+  "driver": "file",
+  "filename": "/path/to/i.img",
+  "aio": "native",
+  "locking": "off",
+  "node-name": "test2",
+  "auto-read-only": true,
+  "discard": "unmap",
+  "cache": {
+    "direct": true,
+    "no-flush": false
+  }
+}
diff --git a/tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.xml b/tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.xml
new file mode 100644
index 0000000000..9e6a9d26bc
--- /dev/null
+++ b/tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.xml
@@ -0,0 +1,12 @@
+<disk device='disk'>
+  <driver name='qemu' type='raw' io='native' cache='none'/>
+  <source file='/path/to/i.img' locking='off'>
+    <privateData>
+      <nodenames>
+        <nodename type='storage' name='test2'/>
+        <nodename type='format' name='test1'/>
+      </nodenames>
+    </privateData>
+  </source>
+  <target dev='vda'/>
+</disk>
-- 
2.25.1
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [PATCH 2/2] qemu_block: add locking option
Posted by Peter Krempa 1 year, 12 months ago
On Wed, Feb 14, 2024 at 14:17:58 +0900, Hiroki Narukawa wrote:
> There is a case that locking hits a bug and users wants to disable
> locking like bug in Linux kernel.
> 
> This commit adds actual qemu option to the domain conf added in previous
> commit.
> 
> Signed-off-by: Hiroki Narukawa <hnarukaw@yahoo-corp.jp>
> ---
>  src/qemu/qemu_block.c                         |  7 ++++++
>  tests/qemublocktest.c                         |  1 +
>  ...le-raw-aio_native-locking-off-srconly.json | 10 ++++++++
>  .../file-raw-aio_native-locking-off.json      | 23 +++++++++++++++++++
>  .../file-raw-aio_native-locking-off.xml       | 12 ++++++++++

Rahter than qemublocktest we generally require testing via
qemuxmlconftest for anything that has XML or uis formatted on the
commandline.

>  5 files changed, 53 insertions(+)
>  create mode 100644 tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off-srconly.json
>  create mode 100644 tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.json
>  create mode 100644 tests/qemublocktestdata/xml2json/file-raw-aio_native-locking-off.xml
> 
> diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
> index 738b72d7ea..5905898b38 100644
> --- a/src/qemu/qemu_block.c
> +++ b/src/qemu/qemu_block.c
> @@ -852,6 +852,13 @@ qemuBlockStorageSourceGetFileProps(virStorageSource *src,
>                                         "S:aio", iomode,
>                                         "S:pr-manager", prManagerAlias,
>                                         NULL) < 0);
> +
> +    if (src->locking) {
> +        const char *lockingStr = virTristateSwitchTypeToString(src->locking);
> +        if (virJSONValueObjectAdd(&ret, "S:locking", lockingStr, NULL) < 0)
> +            return NULL;

The 'S:' conversion is skipped if the argument is NULL, thus no need for
an extra call to virJSONValueObjectAdd.
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org