]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/pve/0028-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch
update qemu submodule to v4.0.0
[pve-qemu.git] / debian / patches / pve / 0028-PVE-Up-Config-file-posix-make-locking-optiono-on-cre.patch
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
5
6 Otherwise creating images on nfs/cifs can be problematic.
7
8 Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
9 ---
10 block/file-posix.c | 53 ++++++++++++++++++++++++++++++++++++----------------
11 qapi/block-core.json | 3 ++-
12 2 files changed, 39 insertions(+), 17 deletions(-)
13
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)
19 int fd;
20 uint64_t perm, shared;
21 int result = 0;
22 + bool locked = false;
23
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;
29
30 - /* Step one: Take locks */
31 - result = raw_apply_lock_bytes(fd, perm, ~shared, false, errp);
32 - if (result < 0) {
33 - goto out_close;
34 - }
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);
38 + if (result < 0) {
39 + goto out_close;
40 + }
41 + locked = true;
42
43 - /* Step two: Check that nobody else has taken conflicting locks */
44 - result = raw_check_lock_bytes(fd, perm, shared, errp);
45 - if (result < 0) {
46 - goto out_unlock;
47 + /* Step two: Check that nobody else has taken conflicting locks */
48 + result = raw_check_lock_bytes(fd, perm, shared, errp);
49 + if (result < 0) {
50 + goto out_unlock;
51 + }
52 }
53
54 /* Clear the file by truncating it to 0 */
55 @@ -2250,13 +2254,15 @@ raw_co_create(BlockdevCreateOptions *options, Error **errp)
56 }
57
58 out_unlock:
59 - raw_apply_lock_bytes(fd, 0, 0, true, &local_err);
60 - if (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);
66 + if (locked) {
67 + raw_apply_lock_bytes(fd, 0, 0, true, &local_err);
68 + if (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);
74 + }
75 }
76
77 out_close:
78 @@ -2277,6 +2283,7 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,
79 PreallocMode prealloc;
80 char *buf = NULL;
81 Error *local_err = NULL;
82 + OnOffAuto locking;
83
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,
87 return -EINVAL;
88 }
89
90 + locking = qapi_enum_parse(&OnOffAuto_lookup,
91 + qemu_opt_get(opts, "locking"),
92 + ON_OFF_AUTO_AUTO, &local_err);
93 + if (local_err) {
94 + error_propagate(errp, local_err);
95 + return -EINVAL;
96 + }
97 +
98 + if (locking == ON_OFF_AUTO_AUTO) {
99 + locking = ON_OFF_AUTO_OFF;
100 + }
101 +
102 options = (BlockdevCreateOptions) {
103 .driver = BLOCKDEV_DRIVER_FILE,
104 .u.file = {
105 @@ -2303,6 +2322,8 @@ static int coroutine_fn raw_co_create_opts(const char *filename, QemuOpts *opts,
106 .preallocation = prealloc,
107 .has_nocow = true,
108 .nocow = nocow,
109 + .has_locking = true,
110 + .locking = locking,
111 },
112 };
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',
120 'size': 'size',
121 '*preallocation': 'PreallocMode',
122 - '*nocow': 'bool' } }
123 + '*nocow': 'bool',
124 + '*locking': 'OnOffAuto' } }
125
126 ##
127 # @BlockdevCreateOptionsGluster:
128 --
129 2.11.0
130