]> git.proxmox.com Git - pve-qemu.git/blob - debian/patches/extra/0001-block-ignore-guest-dev-permissions-during-incoming-migration.patch
bump version to 2.9.0-1~rc3
[pve-qemu.git] / debian / patches / extra / 0001-block-ignore-guest-dev-permissions-during-incoming-migration.patch
1 From qemu-devel-bounces+w.bumiller=proxmox.com@nongnu.org Wed Apr 5 08:57:05 2017
2 Return-Path: <qemu-devel-bounces+w.bumiller=proxmox.com@nongnu.org>
3 Received: from ronja.mits.lan (localhost [127.0.0.1]) by ronja (Cyrus v2.4.16-Debian-2.4.16-4.32.201410011447) with LMTPA; Tue, 04 Apr 2017 17:40:54 +0200
4 X-Sieve: CMU Sieve 2.4
5 Received: from proxmox.maurer-it.com (mail.proxmox.com [192.168.2.110]) by ronja.mits.lan (Postfix) with ESMTPS id 666CAF61213 for <w.bumiller@proxmox.com>; Tue, 4 Apr 2017 17:40:54 +0200 (CEST)
6 Received: from proxmox.maurer-it.com (localhost [127.0.0.1]) by proxmox.maurer-it.com (Proxmox) with ESMTP id 9655510C7994 for <w.bumiller@proxmox.com>; Tue, 4 Apr 2017 17:40:54 +0200 (CEST)
7 Received-SPF: pass (nongnu.org ... gnu.org: 208.118.235.17 is authorized to use 'qemu-devel-bounces@nongnu.org' in 'mfrom' identity (mechanism 'ip4:208.118.235.0/24' matched)) receiver=proxmox.maurer-it.com; identity=mailfrom; envelope-from="qemu-devel-bounces@nongnu.org"; helo=lists.gnu.org; client-ip=208.118.235.17
8 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by proxmox.maurer-it.com (Proxmox) with ESMTPS id DDC8A110E4A3 for <w.bumiller@proxmox.com>; Tue, 4 Apr 2017 17:40:51 +0200 (CEST)
9 Received: from localhost ([::1]:36303 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <qemu-devel-bounces+w.bumiller=proxmox.com@nongnu.org>) id 1cvQZd-0001pP-Un for w.bumiller@proxmox.com; Tue, 04 Apr 2017 11:40:50 -0400
10 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1cvQVK-0006YZ-Kd for qemu-devel@nongnu.org; Tue, 04 Apr 2017 11:36:24 -0400
11 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1cvQVI-0007lq-5E for qemu-devel@nongnu.org; Tue, 04 Apr 2017 11:36:22 -0400
12 Received: from mx1.redhat.com ([209.132.183.28]:39314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <kwolf@redhat.com>) id 1cvQVC-0007bj-0p; Tue, 04 Apr 2017 11:36:14 -0400
13 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CDFA6C05678E; Tue, 4 Apr 2017 15:36:12 +0000 (UTC)
14 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CDFA6C05678E
15 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
16 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com
17 DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CDFA6C05678E
18 Received: from noname.str.redhat.com (dhcp-192-175.str.redhat.com [10.33.192.175]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9EEA19F34F; Tue, 4 Apr 2017 15:36:01 +0000 (UTC)
19 From: Kevin Wolf <kwolf@redhat.com>
20 To: qemu-block@nongnu.org
21 Date: Tue, 4 Apr 2017 17:35:56 +0200
22 Message-Id: <1491320156-4629-1-git-send-email-kwolf@redhat.com>
23 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12
24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 04 Apr 2017 15:36:13 +0000 (UTC)
25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy]
26 X-Received-From: 209.132.183.28
27 Subject: [Qemu-devel] [RFC PATCH for-2.9] block: Ignore guest dev permissions during incoming migration
28 X-BeenThere: qemu-devel@nongnu.org
29 X-Mailman-Version: 2.1.21
30 Precedence: list
31 List-Id: <qemu-devel.nongnu.org>
32 List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
33 List-Archive: <http://lists.nongnu.org/archive/html/qemu-devel/>
34 List-Post: <mailto:qemu-devel@nongnu.org>
35 List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
36 List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>, <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
37 Cc: kwolf@redhat.com, armband@enea.com, jcody@redhat.com, Ciprian.Barbu@enea.com, qemu-devel@nongnu.org, mreitz@redhat.com, Alexandru.Avadanii@enea.com, pbonzini@redhat.com
38 Errors-To: qemu-devel-bounces+w.bumiller=proxmox.com@nongnu.org
39 Sender: "Qemu-devel" <qemu-devel-bounces+w.bumiller=proxmox.com@nongnu.org>
40 X-Proxmox-CTCH-Refid: str=0001.0A0C0201.58E3BE85.00B9:SCFSTAT37688011,ss=1,re=-4.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0
41 x-proxmoxspam-level: Spam detection results: 0 AWL 0.002 Adjusted score from AWL reputation of From: address HEADER_FROM_DIFFERENT_DOMAINS 0.001 From and EnvelopeFrom 2nd level mail domains are different RCVD_IN_DNSWL_HI -5 Sender listed at http://www.dnswl.org/, high trust RCVD_IN_MSPIKE_H3 -0.01 Good reputation (+3) RCVD_IN_MSPIKE_WL -0.01 Mailspike good senders SPF_PASS -0.001 SPF: sender matches SPF record
42 X-TUID: mR1+KkAcSCza
43
44 Usually guest devices don't like other writers to the same image, so
45 they use blk_set_perm() to prevent this from happening. In the migration
46 phase before the VM is actually running, though, they don't have a
47 problem with writes to the image. On the other hand, storage migration
48 needs to be able to write to the image in this phase, so the restrictive
49 blk_set_perm() call of qdev devices breaks it.
50
51 This patch flags all BlockBackends with a qdev device as
52 blk->disable_perm during incoming migration, which means that the
53 requested permissions are stored in the BlockBackend, but not actually
54 applied to its root node yet.
55
56 Once migration has finished and the VM should be resumed, the
57 permissions are applied. If they cannot be applied (e.g. because the NBD
58 server used for block migration hasn't been shut down), resuming the VM
59 fails.
60
61 Signed-off-by: Kevin Wolf <kwolf@redhat.com>
62 ---
63 block/block-backend.c | 40 +++++++++++++++++++++++++++++++++++++++-
64 include/block/block.h | 2 ++
65 migration/migration.c | 8 ++++++++
66 qmp.c | 6 ++++++
67 4 files changed, 55 insertions(+), 1 deletion(-)
68
69 diff --git a/block/block-backend.c b/block/block-backend.c
70 index 0b63773..f817040 100644
71 --- a/block/block-backend.c
72 +++ b/block/block-backend.c
73 @@ -61,6 +61,7 @@ struct BlockBackend {
74
75 uint64_t perm;
76 uint64_t shared_perm;
77 + bool disable_perm;
78
79 bool allow_write_beyond_eof;
80
81 @@ -578,7 +579,7 @@ int blk_set_perm(BlockBackend *blk, uint64_t perm, uint64_t shared_perm,
82 {
83 int ret;
84
85 - if (blk->root) {
86 + if (blk->root && !blk->disable_perm) {
87 ret = bdrv_child_try_set_perm(blk->root, perm, shared_perm, errp);
88 if (ret < 0) {
89 return ret;
90 @@ -597,15 +598,52 @@ void blk_get_perm(BlockBackend *blk, uint64_t *perm, uint64_t *shared_perm)
91 *shared_perm = blk->shared_perm;
92 }
93
94 +/*
95 + * Notifies the user of all BlockBackends that migration has completed. qdev
96 + * devices can tighten their permissions in response (specifically revoke
97 + * shared write permissions that we needed for storage migration).
98 + *
99 + * If an error is returned, the VM cannot be allowed to be resumed.
100 + */
101 +void blk_resume_after_migration(Error **errp)
102 +{
103 + BlockBackend *blk;
104 + Error *local_err = NULL;
105 +
106 + for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
107 + if (!blk->disable_perm) {
108 + continue;
109 + }
110 +
111 + blk->disable_perm = false;
112 +
113 + blk_set_perm(blk, blk->perm, blk->shared_perm, &local_err);
114 + if (local_err) {
115 + error_propagate(errp, local_err);
116 + blk->disable_perm = true;
117 + return;
118 + }
119 + }
120 +}
121 +
122 static int blk_do_attach_dev(BlockBackend *blk, void *dev)
123 {
124 if (blk->dev) {
125 return -EBUSY;
126 }
127 +
128 + /* While migration is still incoming, we don't need to apply the
129 + * permissions of guest device BlockBackends. We might still have a block
130 + * job or NBD server writing to the image for storage migration. */
131 + if (runstate_check(RUN_STATE_INMIGRATE)) {
132 + blk->disable_perm = true;
133 + }
134 +
135 blk_ref(blk);
136 blk->dev = dev;
137 blk->legacy_dev = false;
138 blk_iostatus_reset(blk);
139 +
140 return 0;
141 }
142
143 diff --git a/include/block/block.h b/include/block/block.h
144 index 5149260..3e09222 100644
145 --- a/include/block/block.h
146 +++ b/include/block/block.h
147 @@ -366,6 +366,8 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp);
148 void bdrv_invalidate_cache_all(Error **errp);
149 int bdrv_inactivate_all(void);
150
151 +void blk_resume_after_migration(Error **errp);
152 +
153 /* Ensure contents are flushed to disk. */
154 int bdrv_flush(BlockDriverState *bs);
155 int coroutine_fn bdrv_co_flush(BlockDriverState *bs);
156 diff --git a/migration/migration.c b/migration/migration.c
157 index 54060f7..ad4036f 100644
158 --- a/migration/migration.c
159 +++ b/migration/migration.c
160 @@ -349,6 +349,14 @@ static void process_incoming_migration_bh(void *opaque)
161 exit(EXIT_FAILURE);
162 }
163
164 + /* If we get an error here, just don't restart the VM yet. */
165 + blk_resume_after_migration(&local_err);
166 + if (local_err) {
167 + error_free(local_err);
168 + local_err = NULL;
169 + autostart = false;
170 + }
171 +
172 /*
173 * This must happen after all error conditions are dealt with and
174 * we're sure the VM is going to be running on this host.
175 diff --git a/qmp.c b/qmp.c
176 index fa82b59..a744e44 100644
177 --- a/qmp.c
178 +++ b/qmp.c
179 @@ -207,6 +207,12 @@ void qmp_cont(Error **errp)
180 }
181 }
182
183 + blk_resume_after_migration(&local_err);
184 + if (local_err) {
185 + error_propagate(errp, local_err);
186 + return;
187 + }
188 +
189 if (runstate_check(RUN_STATE_INMIGRATE)) {
190 autostart = 1;
191 } else {
192 --
193 1.8.3.1
194
195
196