]> git.proxmox.com Git - pve-qemu.git/commitdiff
merge: make file locking optional also on creation
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 26 Apr 2019 07:18:00 +0000 (09:18 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 26 Apr 2019 07:18:00 +0000 (09:18 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
debian/patches/pve/0028-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch [new file with mode: 0644]
debian/patches/series

diff --git a/debian/patches/pve/0028-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch b/debian/patches/pve/0028-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch
new file mode 100644 (file)
index 0000000..d5f2da8
--- /dev/null
@@ -0,0 +1,130 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Wolfgang Bumiller <w.bumiller@proxmox.com>
+Date: Fri, 26 Apr 2019 09:15:28 +0200
+Subject: [PATCH] PVE: [Up+Config] file-posix: make locking optiono on create
+
+Otherwise creating images on nfs/cifs can be problematic.
+
+Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
+---
+ block/file-posix.c   | 53 ++++++++++++++++++++++++++++++++++++----------------
+ qapi/block-core.json |  3 ++-
+ 2 files changed, 39 insertions(+), 17 deletions(-)
+
+diff --git a/block/file-posix.c b/block/file-posix.c
+index 431a9dddc6..be34698d04 100644
+--- a/block/file-posix.c
++++ b/block/file-posix.c
+@@ -2175,6 +2175,7 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
+     int fd;
+     uint64_t perm, shared;
+     int result = 0;
++    bool locked = false;
+     /* Validate options and set default values */
+     assert(options->driver == BLOCKDEV_DRIVER_FILE);
+@@ -2208,16 +2209,19 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
+     perm = BLK_PERM_WRITE | BLK_PERM_RESIZE;
+     shared = BLK_PERM_ALL & ~BLK_PERM_RESIZE;
+-    /* Step one: Take locks */
+-    result = raw_apply_lock_bytes(fd, perm, ~shared, false, errp);
+-    if (result < 0) {
+-        goto out_close;
+-    }
++    if (file_opts->locking != ON_OFF_AUTO_OFF) {
++        /* Step one: Take locks */
++        result = raw_apply_lock_bytes(fd, perm, ~shared, false, errp);
++        if (result < 0) {
++            goto out_close;
++        }
++        locked = true;
+-    /* Step two: Check that nobody else has taken conflicting locks */
+-    result = raw_check_lock_bytes(fd, perm, shared, errp);
+-    if (result < 0) {
+-        goto out_unlock;
++        /* Step two: Check that nobody else has taken conflicting locks */
++        result = raw_check_lock_bytes(fd, perm, shared, errp);
++        if (result < 0) {
++            goto out_unlock;
++        }
+     }
+     /* Clear the file by truncating it to 0 */
+@@ -2250,13 +2254,15 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
+     }
+ out_unlock:
+-    raw_apply_lock_bytes(fd, 0, 0, true, &local_err);
+-    if (local_err) {
+-        /* The above call should not fail, and if it does, that does
+-         * not mean the whole creation operation has failed.  So
+-         * report it the user for their convenience, but do not report
+-         * it to the caller. */
+-        error_report_err(local_err);
++    if (locked) {
++        raw_apply_lock_bytes(fd, 0, 0, true, &local_err);
++        if (local_err) {
++            /* The above call should not fail, and if it does, that does
++             * not mean the whole creation operation has failed.  So
++             * report it the user for their convenience, but do not report
++             * it to the caller. */
++            error_report_err(local_err);
++        }
+     }
+ out_close:
+@@ -2277,6 +2283,7 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,
+     PreallocMode prealloc;
+     char *buf = NULL;
+     Error *local_err = NULL;
++    OnOffAuto locking;
+     /* Skip file: protocol prefix */
+     strstart(filename, "file:", &filename);
+@@ -2294,6 +2301,18 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,
+         return -EINVAL;
+     }
++    locking = qapi_enum_parse(&OnOffAuto_lookup,
++                              qemu_opt_get(opts, "locking"),
++                              ON_OFF_AUTO_AUTO, &local_err);
++    if (local_err) {
++        error_propagate(errp, local_err);
++        return -EINVAL;
++    }
++
++    if (locking == ON_OFF_AUTO_AUTO) {
++        locking = ON_OFF_AUTO_OFF;
++    }
++
+     options = (BlockdevCreateOptions) {
+         .driver     = BLOCKDEV_DRIVER_FILE,
+         .u.file     = {
+@@ -2303,6 +2322,8 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,
+             .preallocation      = prealloc,
+             .has_nocow          = true,
+             .nocow              = nocow,
++            .has_locking        = true,
++            .locking            = locking,
+         },
+     };
+     return raw_co_create(&options, errp);
+diff --git a/qapi/block-core.json b/qapi/block-core.json
+index 9c3c2d4917..db859e20fa 100644
+--- a/qapi/block-core.json
++++ b/qapi/block-core.json
+@@ -3879,7 +3879,8 @@
+   'data': { 'filename':         'str',
+             'size':             'size',
+             '*preallocation':   'PreallocMode',
+-            '*nocow':           'bool' } }
++            '*nocow':           'bool',
++            '*locking':         'OnOffAuto' } }
+ ##
+ # @BlockdevCreateOptionsGluster:
+-- 
+2.11.0
+
index abfe175268bb9099964c11fecf1033f8b0b0718a..91171f947dcb5b02c089df6392ae3c87d2e63ed6 100644 (file)
@@ -25,5 +25,6 @@ pve/0024-PVE-vma-add-cache-option-to-device-map.patch
 pve/0025-PVE-vma-remove-forced-NO_FLUSH-option.patch
 pve/0026-PVE-Add-dummy-id-command-line-parameter.patch
 pve/0027-PVE-Config-Revert-target-i386-disable-LINT0-after-re.patch
+pve/0028-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch
 extra/0001-monitor-guard-iothread-access-by-mon-use_io_thread.patch
 extra/0002-monitor-delay-monitor-iothread-creation.patch