From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37253) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsnZo-00026L-Ib for qemu-devel@nongnu.org; Fri, 15 Sep 2017 06:10:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsnZn-0004I8-By for qemu-devel@nongnu.org; Fri, 15 Sep 2017 06:10:24 -0400 From: Kevin Wolf Date: Fri, 15 Sep 2017 12:10:03 +0200 Message-Id: <20170915101008.16646-2-kwolf@redhat.com> In-Reply-To: <20170915101008.16646-1-kwolf@redhat.com> References: <20170915101008.16646-1-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/6] qemu-io: Reset qemuio_blk permissions before each command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: kwolf@redhat.com, mreitz@redhat.com, famz@redhat.com, qemu-devel@nongnu.org qemu-io provides a 'reopen' command that allows switching from writable to read-only access. We need to make sure that we don't try to keep write permissions to a BlockBackend that becomes read-only, otherwise things are going to fail. command() already makes sure to request any additional permissions that a qemu-io command requires, so just resetting the permissions to values that are safe for read-only images is enough to fix this. As a side effect, this makes the output of qemu-iotests case 187 more consistent. Signed-off-by: Kevin Wolf --- qemu-io.c | 13 +++++++++++++ tests/qemu-iotests/187.out | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/qemu-io.c b/qemu-io.c index 265445ad89..9e031f0f8e 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -366,6 +366,12 @@ static void command_loop(void) char *input; for (i = 0; !done && i < ncmdline; i++) { + /* Make sure that we start each command with clean permissions and only + * add whatever the specific cmdinfo_t describes */ + if (qemuio_blk) { + blk_set_perm(qemuio_blk, BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL, + &error_abort); + } done = qemuio_command(qemuio_blk, cmdline[i]); } if (cmdline) { @@ -391,6 +397,13 @@ static void command_loop(void) if (input == NULL) { break; } + + /* Make sure that we start each command with clean permissions and only + * add whatever the specific cmdinfo_t describes */ + if (qemuio_blk) { + blk_set_perm(qemuio_blk, BLK_PERM_CONSISTENT_READ, BLK_PERM_ALL, + &error_abort); + } done = qemuio_command(qemuio_blk, input); g_free(input); diff --git a/tests/qemu-iotests/187.out b/tests/qemu-iotests/187.out index 68fb944cd5..30b987f71f 100644 --- a/tests/qemu-iotests/187.out +++ b/tests/qemu-iotests/187.out @@ -12,7 +12,7 @@ Start from read-write wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -write failed: Operation not permitted +Block node is read-only wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done -- 2.13.5