[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [RFC PATCH 35/41] stream: Use real permissions in streaming
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [RFC PATCH 35/41] stream: Use real permissions in streaming block job |
Date: |
Mon, 13 Feb 2017 18:22:57 +0100 |
The correct permissions are relatively obvious here (and explained in
code comments). For intermediate streaming, we need to reopen the top
node read-write before creating the job now because the permissions
system catches attempts to get the BLK_PERM_WRITE_UNCHANGED permission
on a read-only node.
Signed-off-by: Kevin Wolf <address@hidden>
---
block/stream.c | 38 ++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)
diff --git a/block/stream.c b/block/stream.c
index 47f0ffb..e562f57 100644
--- a/block/stream.c
+++ b/block/stream.c
@@ -229,27 +229,35 @@ void stream_start(const char *job_id, BlockDriverState
*bs,
BlockDriverState *iter;
int orig_bs_flags;
- /* FIXME Use real permissions */
- s = block_job_create(job_id, &stream_job_driver, bs, 0, BLK_PERM_ALL,
- speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp);
- if (!s) {
- return;
- }
-
/* Make sure that the image is opened in read-write mode */
orig_bs_flags = bdrv_get_flags(bs);
if (!(orig_bs_flags & BDRV_O_RDWR)) {
if (bdrv_reopen(bs, orig_bs_flags | BDRV_O_RDWR, errp) != 0) {
- block_job_unref(&s->common);
return;
}
}
- /* Block all intermediate nodes between bs and base, because they
- * will disappear from the chain after this operation */
+ /* Prevent concurrent jobs trying to modify the graph structure here, we
+ * already have our own plans. Also don't allow resize as the image size is
+ * queried only at the job start and then cached. */
+ s = block_job_create(job_id, &stream_job_driver, bs,
+ BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |
+ BLK_PERM_GRAPH_MOD,
+ BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |
+ BLK_PERM_WRITE,
+ speed, BLOCK_JOB_DEFAULT, NULL, NULL, errp);
+ if (!s) {
+ goto fail;
+ }
+
+ /* Block all intermediate nodes between bs and base, because they will
+ * disappear from the chain after this operation. The streaming job reads
+ * every block only once, assuming that it doesn't change, so block writes
+ * and resizes. */
for (iter = backing_bs(bs); iter && iter != base; iter = backing_bs(iter))
{
- /* FIXME Use real permissions */
- block_job_add_bdrv(&s->common, iter, 0, BLK_PERM_ALL, &error_abort);
+ block_job_add_bdrv(&s->common, iter, 0,
+ BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED,
+ &error_abort);
}
s->base = base;
@@ -259,4 +267,10 @@ void stream_start(const char *job_id, BlockDriverState *bs,
s->on_error = on_error;
trace_stream_start(bs, base, s);
block_job_start(&s->common);
+ return;
+
+fail:
+ if (orig_bs_flags != bdrv_get_flags(bs)) {
+ bdrv_reopen(bs, s->bs_flags, NULL);
+ }
}
--
1.8.3.1
- Re: [Qemu-block] [RFC PATCH 27/41] block: Add bdrv_new_open_driver(), (continued)
- [Qemu-block] [RFC PATCH 28/41] commit: Use real permissions in commit block job, Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 29/41] commit: Use real permissions for HMP 'commit', Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 30/41] backup: Use real permissions in backup block job, Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 33/41] block: Allow backing file links in change_parent_backing_link(), Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 36/41] hmp: Request permissions in qemu-io, Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 38/41] nbd/server: Use real permissions for NBD exports, Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 26/41] block: Factor out bdrv_open_driver(), Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 31/41] block: Fix pending requests check in bdrv_append(), Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 32/41] block: BdrvChildRole.attach/detach() callbacks, Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 35/41] stream: Use real permissions in streaming block job,
Kevin Wolf <=
- [Qemu-block] [RFC PATCH 34/41] mirror: Use real permissions in mirror/active commit block job, Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 37/41] migration/block: Use real permissions, Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 39/41] tests: Remove FIXME comments, Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 40/41] block: Pass BdrvChild to bdrv_aligned_preadv/pwritev, Kevin Wolf, 2017/02/13
- [Qemu-block] [RFC PATCH 41/41] block: Assertions for write permissions, Kevin Wolf, 2017/02/13
- Re: [Qemu-block] [Qemu-devel] [RFC PATCH 00/41] New op blocker system, no-reply, 2017/02/13