1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Fri, 26 Apr 2019 09:15:28 +0200
4 Subject: [PATCH] PVE: [Up+Config] file-posix: make locking optiono on create
6 Otherwise creating images on nfs/cifs can be problematic.
8 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
10 block/file-posix.c | 53 ++++++++++++++++++++++++++++++++++++----------------
11 qapi/block-core.json | 3 ++-
12 2 files changed, 39 insertions(+), 17 deletions(-)
14 diff --git a/block/file-posix.c b/block/file-posix.c
15 index 431a9dddc6..be34698d04 100644
16 --- a/block/file-posix.c
17 +++ b/block/file-posix.c
18 @@ -2175,6 +2175,7 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
20 uint64_t perm, shared;
22 + bool locked = false;
24 /* Validate options and set default values */
25 assert(options->driver == BLOCKDEV_DRIVER_FILE);
26 @@ -2208,16 +2209,19 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
27 perm = BLK_PERM_WRITE | BLK_PERM_RESIZE;
28 shared = BLK_PERM_ALL & ~BLK_PERM_RESIZE;
30 - /* Step one: Take locks */
31 - result = raw_apply_lock_bytes(fd, perm, ~shared, false, errp);
35 + if (file_opts->locking != ON_OFF_AUTO_OFF) {
36 + /* Step one: Take locks */
37 + result = raw_apply_lock_bytes(fd, perm, ~shared, false, errp);
43 - /* Step two: Check that nobody else has taken conflicting locks */
44 - result = raw_check_lock_bytes(fd, perm, shared, errp);
47 + /* Step two: Check that nobody else has taken conflicting locks */
48 + result = raw_check_lock_bytes(fd, perm, shared, errp);
54 /* Clear the file by truncating it to 0 */
55 @@ -2250,13 +2254,15 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
59 - raw_apply_lock_bytes(fd, 0, 0, true, &local_err);
61 - /* The above call should not fail, and if it does, that does
62 - * not mean the whole creation operation has failed. So
63 - * report it the user for their convenience, but do not report
64 - * it to the caller. */
65 - error_report_err(local_err);
67 + raw_apply_lock_bytes(fd, 0, 0, true, &local_err);
69 + /* The above call should not fail, and if it does, that does
70 + * not mean the whole creation operation has failed. So
71 + * report it the user for their convenience, but do not report
72 + * it to the caller. */
73 + error_report_err(local_err);
78 @@ -2277,6 +2283,7 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,
79 PreallocMode prealloc;
81 Error *local_err = NULL;
84 /* Skip file: protocol prefix */
85 strstart(filename, "file:", &filename);
86 @@ -2294,6 +2301,18 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,
90 + locking = qapi_enum_parse(&OnOffAuto_lookup,
91 + qemu_opt_get(opts, "locking"),
92 + ON_OFF_AUTO_AUTO, &local_err);
94 + error_propagate(errp, local_err);
98 + if (locking == ON_OFF_AUTO_AUTO) {
99 + locking = ON_OFF_AUTO_OFF;
102 options = (BlockdevCreateOptions) {
103 .driver = BLOCKDEV_DRIVER_FILE,
105 @@ -2303,6 +2322,8 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,
106 .preallocation = prealloc,
109 + .has_locking = true,
110 + .locking = locking,
113 return raw_co_create(&options, errp);
114 diff --git a/qapi/block-core.json b/qapi/block-core.json
115 index 9c3c2d4917..db859e20fa 100644
116 --- a/qapi/block-core.json
117 +++ b/qapi/block-core.json
118 @@ -3879,7 +3879,8 @@
119 'data': { 'filename': 'str',
121 '*preallocation': 'PreallocMode',
122 - '*nocow': 'bool' } }
124 + '*locking': 'OnOffAuto' } }
127 # @BlockdevCreateOptionsGluster: