From patchwork Thu Sep 6 09:37:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 966892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="SJrqFWkw"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425bMP1x5fz9s9N for ; Thu, 6 Sep 2018 19:47:13 +1000 (AEST) Received: from localhost ([::1]:60457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqmc-000891-15 for incoming@patchwork.ozlabs.org; Thu, 06 Sep 2018 05:41:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjK-0005jB-NV for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjG-0003Zc-Ns for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54014) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjG-0003Q9-3Y; Thu, 06 Sep 2018 05:37:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=+im3/A+fxrBZGJaWiF7Tyr2Oi5bMVBZOYCFItuxKNb8=; b=SJrqFWkwgSQGy9mrFxSe31E3DtjdhZG5a8SH/bZo6TgSzRFtLpQ9dW5umJGCiK+AgFk2PKF0+S8d9IB8XjwxiZd39MrmNAJ7cP8z6p9OciiHMTHHfJ9qfHGZrGfEUieu3ocMg4FuYZIMtVojxtwxDh9HPSWjredu/00s8hciaFKtvV2N8AcHT9ateVOXf0T7nszg2d81NSbwa11Uv9RQ8CUO0azWuJQDJ28kW+r3L/WSpXpYY1fFsEdd2kbqaupCCY6kahyfSFP8IgiFQ28IgsWJhOzBCyUkyrhSB2zPSEa85i0PLBDcggRvR/zMnbvL3xCFo8ZtRKGhxhACOO3g9A==; Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049b-8c; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiy-0001ns-JK; Thu, 06 Sep 2018 12:37:16 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:01 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 01/10] qemu-io: Fix writethrough check in reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" "qemu-io reopen" doesn't allow changing the writethrough setting of the cache, but the check is wrong, causing an error even on a simple reopen with the default parameters: $ qemu-img create -f qcow2 hd.qcow2 1M $ qemu-system-x86_64 -monitor stdio -drive if=virtio,file=hd.qcow2 (qemu) qemu-io virtio0 reopen Cannot change cache.writeback: Device attached Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- qemu-io-cmds.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 5bf5f28178..db0b3ee5ef 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -2025,7 +2025,7 @@ static int reopen_f(BlockBackend *blk, int argc, char **argv) return -EINVAL; } - if (writethrough != blk_enable_write_cache(blk) && + if (!writethrough != blk_enable_write_cache(blk) && blk_get_attached_dev(blk)) { error_report("Cannot change cache.writeback: Device attached"); From patchwork Thu Sep 6 09:37:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 966878 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="hTuwvSif"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425b9F4txsz9sDb for ; Thu, 6 Sep 2018 19:38:25 +1000 (AEST) Received: from localhost ([::1]:60436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqk3-0005lt-6G for incoming@patchwork.ozlabs.org; Thu, 06 Sep 2018 05:38:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51961) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjK-0005j9-NK for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjG-0003aC-Qm for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54007) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjG-0003Q5-3h; Thu, 06 Sep 2018 05:37:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=2s51FxxSFglGXcOIgTRuoL/f4BaR1gVb4RQrXt0QSYk=; b=hTuwvSifKZW+yBb/9UJpdrt7wPKgzD0fxxDRCa7DToPzcFoo3tfbuIRt1lPtcfqKKIvLSWgpl8TTBSS/KixoPqzQ+HSbJMNYu7wq6g5AGw9zct1AYQJ8IMeXdx8xl311VWk32dXpomKGk+ix6Pv0/zbHswtqvFt4SYQYCSo12MTn56S5TbZOXZK3FZ9ev8gI6A0NcjFN7l39XbD+sJsV5w+OPL12H8QacdfAt9ff/CDMvdmzwAJnEoWfCI0/D9qXrn86Q+q83lHFeOqyHzwm0Oi9bGe+S2nCFNkh5Bv4YNw2JruMLL7cM8ThruTJe+xDX8aGCs0OlCG7ttc4zmbQEg==; Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049Z-6r; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiy-0001nw-MM; Thu, 06 Sep 2018 12:37:16 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:03 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 03/10] block: Remove child references from bs->{options, explicit_options} X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Block drivers allow opening their children using a reference to an existing BlockDriverState. These references remain stored in the 'options' and 'explicit_options' QDicts, but we don't need to keep them once everything is open. What is more important, these values can become wrong if the children change: $ qemu-img create -f qcow2 hd0.qcow2 10M $ qemu-img create -f qcow2 hd1.qcow2 10M $ qemu-img create -f qcow2 hd2.qcow2 10M $ $QEMU -drive if=none,file=hd0.qcow2,node-name=hd0 \ -drive if=none,file=hd1.qcow2,node-name=hd1,backing=hd0 \ -drive file=hd2.qcow2,node-name=hd2,backing=hd1 After this hd2 has hd1 as its backing file. Now let's remove it using block_stream: (qemu) block_stream hd2 0 hd0.qcow2 Now hd0 is the backing file of hd2, but hd2's options QDicts still contain backing=hd1. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 0dbb1fcc7b..c764eb731c 100644 --- a/block.c +++ b/block.c @@ -2763,12 +2763,15 @@ static BlockDriverState *bdrv_open_inherit(const char *filename, } } - /* Remove all children options from bs->options and bs->explicit_options */ + /* Remove all children options and references + * from bs->options and bs->explicit_options */ QLIST_FOREACH(child, &bs->children, next) { char *child_key_dot; child_key_dot = g_strdup_printf("%s.", child->name); qdict_extract_subqdict(bs->explicit_options, NULL, child_key_dot); qdict_extract_subqdict(bs->options, NULL, child_key_dot); + qdict_del(bs->explicit_options, child->name); + qdict_del(bs->options, child->name); g_free(child_key_dot); } @@ -3289,6 +3292,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) { BlockDriver *drv; BlockDriverState *bs; + BdrvChild *child; bool old_can_write, new_can_write; assert(reopen_state != NULL); @@ -3313,6 +3317,13 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) bs->open_flags = reopen_state->flags; bs->read_only = !(reopen_state->flags & BDRV_O_RDWR); + /* Remove child references from bs->options and bs->explicit_options. + * Child options were already removed in bdrv_reopen_queue_child() */ + QLIST_FOREACH(child, &bs->children, next) { + qdict_del(bs->explicit_options, child->name); + qdict_del(bs->options, child->name); + } + bdrv_refresh_limits(bs, NULL); bdrv_set_perm(reopen_state->bs, reopen_state->perm, From patchwork Thu Sep 6 09:37:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 966893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="c44+kqkv"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425bMS26kBz9s9N for ; Thu, 6 Sep 2018 19:47:16 +1000 (AEST) Received: from localhost ([::1]:60456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqmc-00088u-PV for incoming@patchwork.ozlabs.org; Thu, 06 Sep 2018 05:41:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjK-0005j7-MU for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjG-0003aU-RC for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjG-0003Q8-3T; Thu, 06 Sep 2018 05:37:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=e2gonpwuluc95Z92wHiLHlJf66OVUFblULszrJNuBgw=; b=c44+kqkvuMmufJdYesfHXkpI/kBPSy1lO5i5GjaiS/orCic0C5H1kg60iGNlVNqLnWb0IjkCI1Yq3n60zprr8MD9WX2XeUOvx/lIz/WWicL+tduwFMqfGxo/ygzanUdzF410kOUMuOTSsx/NpKYzfon9W9RqYrh2VAYTR/Q9jHBhWNRMYT8gS1Qa9IfYEudlqZmeyTFHc7eG4SMiTo2gFOUW9JADFAKhl5O7bDBgvjm9ASG2ZCjhwOidkGM38phD3c6JqyoCp4AMmqKfaqyOqCFC5FSQp1TFHRA/4pdh99/+5Ivs7ECbA2ERtaEHiXUp+M050+tVqE3n/O+28OMPnw==; Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049d-9c; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiy-0001ny-Nu; Thu, 06 Sep 2018 12:37:16 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:04 +0300 Message-Id: <4abf5ed9c4070955d76af2925d0fee4f30f3e7ac.1536226505.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 04/10] block: Don't look for child references in append_open_options() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In the previous patch we removed child references from bs->options, so there's no need to look for them here anymore. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/block.c b/block.c index c764eb731c..aaa4cf6897 100644 --- a/block.c +++ b/block.c @@ -5154,23 +5154,12 @@ static bool append_open_options(QDict *d, BlockDriverState *bs) { const QDictEntry *entry; QemuOptDesc *desc; - BdrvChild *child; bool found_any = false; for (entry = qdict_first(bs->options); entry; entry = qdict_next(bs->options, entry)) { - /* Exclude node-name references to children */ - QLIST_FOREACH(child, &bs->children, next) { - if (!strcmp(entry->key, child->name)) { - break; - } - } - if (child) { - continue; - } - - /* And exclude all non-driver-specific options */ + /* Exclude all non-driver-specific options */ for (desc = bdrv_runtime_opts.desc; desc->name; desc++) { if (!strcmp(qdict_entry_key(entry), desc->name)) { break; From patchwork Thu Sep 6 09:37:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 966888 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="FNcAS3Ld"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425bDb5h0pz9sD2 for ; Thu, 6 Sep 2018 19:41:19 +1000 (AEST) Received: from localhost ([::1]:60462 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqmr-0008MG-Ip for incoming@patchwork.ozlabs.org; Thu, 06 Sep 2018 05:41:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51966) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjK-0005jE-Nb for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjG-0003Yl-KA for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54015) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjG-0003QA-3P; Thu, 06 Sep 2018 05:37:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=V2jZt2dXjcOoqUefDzUVg/kfJEL0beDCNdf/Sin6CIQ=; b=FNcAS3LdIy5GcvZ8cmi6rh2H5g4ZWHtbN2IsD8l/2d2JXIxaMzoa30uQrKp7r6J9Zelsqn9Gyzm+cewNwk2+1q2ChYeFVLyaWZGAUKRr12Dfuuipc3ZdTpHZ1s+w3n2yu6rIQHbYnmeGWFXNCFT68XF3/dwyOxoTfEILPSYmymEeEb+kYDBCpNO+q/nm7AsW2HuI2FOLxqgwmREZJH6FFobhvaNvT0M3ifubnHyP5h7IZ4b1ezJT+8oKbUAN/2WuBaUUL28mp8Szu/9zTwjtxPi6T2XrtRKnvGzVE+sMEdATxvZP0/E9D1AWkXwT+zKHsn6sNV60GIXZK0gBGCppSg==; Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049c-9J; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiy-0001o1-P8; Thu, 06 Sep 2018 12:37:16 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:05 +0300 Message-Id: <70c436dbf3914d952a2839bf8383a436dc5267ce.1536226505.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 05/10] block: Allow child references on reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" In the previous patches we removed all child references from bs->{options,explicit_options} because keeping them is useless and wrong. Because of this, any attempt to reopen a BlockDriverState using a child reference as one of its options would result in a failure, because bdrv_reopen_prepare() would detect that there's a new option (the child reference) that wasn't present in bs->options. But passing child references on reopen can be useful. It's a way to specify a BDS's child without having to pass recursively all of the child's options, and if the reference points to a different BDS then this can allow us to replace the child. However, replacing the child is something that needs to be implemented case by case and only when it makes sense. For now, this patch allows passing a child reference as long as it points to the current child of the BlockDriverState. It's also important to remember that, as a consequence of the previous patches, this child reference will be removed from bs->{options,explicit_options} after the reopening has been completed. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block.c b/block.c index aaa4cf6897..5223d16f1b 100644 --- a/block.c +++ b/block.c @@ -3241,6 +3241,24 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, QObject *new = entry->value; QObject *old = qdict_get(reopen_state->bs->options, entry->key); + /* Allow child references (child_name=node_name) as long as they + * point to the current child (i.e. everything stays the same). */ + if (qobject_type(new) == QTYPE_QSTRING) { + BdrvChild *child; + QLIST_FOREACH(child, &reopen_state->bs->children, next) { + if (!strcmp(child->name, entry->key)) { + break; + } + } + + if (child) { + const char *str = qobject_get_try_str(new); + if (!strcmp(child->bs->node_name, str)) { + continue; /* Found child with this name, skip option */ + } + } + } + /* * TODO: When using -drive to specify blockdev options, all values * will be strings; however, when using -blockdev, blockdev-add or From patchwork Thu Sep 6 09:37:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 966889 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="DehDnIBb"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425bHQ2nt2z9s9N for ; Thu, 6 Sep 2018 19:43:46 +1000 (AEST) Received: from localhost ([::1]:60470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqpE-000211-7J for incoming@patchwork.ozlabs.org; Thu, 06 Sep 2018 05:43:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51965) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjK-0005jD-NX for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjG-0003aN-Qa for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54019) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjG-0003QD-3Z; Thu, 06 Sep 2018 05:37:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=XYraknwpR9m9UNEH64RoTKzL/xuxcRxzUG5e4hMHG/w=; b=DehDnIBb8RCw4SwFUPRuiosccOxx0OUIrH6IJa8KQ8DGdp0DI3PRtlbO69OzasY0PqICV4UIZsIC1xs1iHrwurBGLYR3KlYI/pnvjBDzobVNLE9Zi/5A8rsPE/2lF6pMQER3MaRn6w0EQ1h7s5QE7RYxqYKDrcOErhbTW+9xQWkBh3Uz99BCC4RqH9uzTx78EfYyLMucJO77GaFNYkYvTAb/RiY5J37hIafs8wBVvgqTkex8UBlOfhtQkJtNhEU3MQ7/HzjVdxHW3npu3fernKeW2ASgBZLULE3all2YHJ52z8TyXWjpuEFtMGK/Uftx0bW6iAFp2m346FVk/zcJ4Q==; Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049e-AJ; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiy-0001o3-QH; Thu, 06 Sep 2018 12:37:16 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:06 +0300 Message-Id: <0a5390573358f8d1f29f3d663e972c9169528194.1536226505.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 06/10] block: Forbid trying to change unsupported options during reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The bdrv_reopen_prepare() function checks all options passed to each BlockDriverState (in the reopen_state->options QDict) and makes all necessary preparations to apply the option changes requested by the user. Options are removed from the QDict as they are processed, so at the end of bdrv_reopen_prepare() only the options that can't be changed are left. Then a loop goes over all remaining options and verifies that the old and new values are identical, returning an error if they're not. The problem is that at the moment there are options that are removed from the QDict although they can't be changed. The consequence of this is any modification to any of those options is silently ignored: (qemu) qemu-io virtio0 "reopen -o discard=on" This happens when all options from bdrv_runtime_opts are removed from the QDict but then only a few of them are processed. Since it's especially important that "node-name" and "driver" are not changed, the code puts them back into the QDict so they are checked at the end of the function. Instead of putting only those two options back into the QDict, this patch puts all unprocessed options using qemu_opts_to_qdict(). update_flags_from_options() also needs to be modified to prevent BDRV_OPT_CACHE_NO_FLUSH, BDRV_OPT_CACHE_DIRECT and BDRV_OPT_READ_ONLY from going back to the QDict. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/block.c b/block.c index 5223d16f1b..1c0f72454a 100644 --- a/block.c +++ b/block.c @@ -1094,19 +1094,19 @@ static void update_flags_from_options(int *flags, QemuOpts *opts) *flags &= ~BDRV_O_CACHE_MASK; assert(qemu_opt_find(opts, BDRV_OPT_CACHE_NO_FLUSH)); - if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) { + if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) { *flags |= BDRV_O_NO_FLUSH; } assert(qemu_opt_find(opts, BDRV_OPT_CACHE_DIRECT)); - if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_DIRECT, false)) { + if (qemu_opt_get_bool_del(opts, BDRV_OPT_CACHE_DIRECT, false)) { *flags |= BDRV_O_NOCACHE; } *flags &= ~BDRV_O_RDWR; assert(qemu_opt_find(opts, BDRV_OPT_READ_ONLY)); - if (!qemu_opt_get_bool(opts, BDRV_OPT_READ_ONLY, false)) { + if (!qemu_opt_get_bool_del(opts, BDRV_OPT_READ_ONLY, false)) { *flags |= BDRV_O_RDWR; } @@ -3155,7 +3155,6 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, BlockDriver *drv; QemuOpts *opts; QDict *orig_reopen_opts; - const char *value; bool read_only; assert(reopen_state != NULL); @@ -3178,17 +3177,10 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, update_flags_from_options(&reopen_state->flags, opts); - /* node-name and driver must be unchanged. Put them back into the QDict, so - * that they are checked at the end of this function. */ - value = qemu_opt_get(opts, "node-name"); - if (value) { - qdict_put_str(reopen_state->options, "node-name", value); - } - - value = qemu_opt_get(opts, "driver"); - if (value) { - qdict_put_str(reopen_state->options, "driver", value); - } + /* All other options (including node-name and driver) must be unchanged. + * Put them back into the QDict, so that they are checked at the end + * of this function. */ + qemu_opts_to_qdict(opts, reopen_state->options); /* If we are to stay read-only, do not allow permission change * to r/w. Attempting to set to r/w may fail if either BDRV_O_ALLOW_RDWR is From patchwork Thu Sep 6 09:37:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 966877 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="Fomti+X9"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425b9B6ppzz9sD2 for ; Thu, 6 Sep 2018 19:38:22 +1000 (AEST) Received: from localhost ([::1]:60431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjz-0005kB-Ou for incoming@patchwork.ozlabs.org; Thu, 06 Sep 2018 05:38:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjK-0005jA-NM for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjG-0003aA-SB for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54018) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjG-0003QB-3j; Thu, 06 Sep 2018 05:37:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=3zxM+J6Gf0tyZfnCuavZPbJkaI2UbmgFMNgpzccqa1s=; b=Fomti+X9b0G6DfwihWu42fwC+LyXreULbmIX94m4dU+e/9VldDxPa2WyE7T5CSCvs8vqpQolv1ZvQHh89LcXc7k7OnVYY+AbIDVH1td8rWQb41Ype/DoTmS4v4sv0qCVusy64NqrROTDaWRgrWNwyPQZJdzjsJolUTi+AYw4IkTd8ArKPHMoFTuLAbOpArSm/eBKh2jCrmuC76h+HV4SDHriFpXyirXhJGRVHHVCOVeCmE3twpm4O6cHhZaBzRU4SuC1Avx6IXZ6XlGAMeZA/KO07XTmgZ3eZYCFMSiu/7jXfUZA66ybIRRfDMKchuAmUOf8g0yloH3oYrmQwO7uDg==; Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049k-HM; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiy-0001o5-TM; Thu, 06 Sep 2018 12:37:16 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:07 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 07/10] file-posix: Forbid trying to change unsupported options during reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The file-posix code is used for the "file", "host_device" and "host_cdrom" drivers, and it allows reopening images. However the only option that is actually processed is "x-check-cache-dropped", and changes in all other options (e.g. "filename") are silently ignored: (qemu) qemu-io virtio0 "reopen -o file.filename=no-such-file" While we could allow changing some of the other options, let's keep things as they are for now but return an error if the user tries to change any of them. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block/file-posix.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index ddac0cc3e6..d4ec2cb3dd 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -850,8 +850,13 @@ static int raw_reopen_prepare(BDRVReopenState *state, goto out; } - rs->check_cache_dropped = qemu_opt_get_bool(opts, "x-check-cache-dropped", - false); + rs->check_cache_dropped = + qemu_opt_get_bool_del(opts, "x-check-cache-dropped", false); + + /* This driver's reopen function doesn't currently allow changing + * other options, so let's put them back in the original QDict and + * bdrv_reopen_prepare() will detect changes and complain. */ + qemu_opts_to_qdict(opts, state->options); if (s->type == FTYPE_CD) { rs->open_flags |= O_NONBLOCK; From patchwork Thu Sep 6 09:37:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 966879 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="lrGGVXWG"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425b9V02nvz9s9N for ; Thu, 6 Sep 2018 19:38:38 +1000 (AEST) Received: from localhost ([::1]:60443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqkF-0005zu-M5 for incoming@patchwork.ozlabs.org; Thu, 06 Sep 2018 05:38:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjK-0005j8-Mh for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjG-0003ac-Qp for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54012) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjG-0003Q7-3g; Thu, 06 Sep 2018 05:37:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=cRlBNSZr71aDonFrZWIiaueFM8Gns1d/odRdrwRPHYQ=; b=lrGGVXWGobXqsO76QglqY3ASVwfctRj5qOPDJUyZvZ5aPdTiDiJzxTvYA1z3jTKZWhTyiO3SWbwqtLoeuNWCxSV5qZSmSjQKVWVVGKQq35lmqn2/1pZzHcBJA9irBL6/byCtx2xmGvN2GieHyQZSMFpcqO48NC3g35WBig9LD9Ap4RMq7xYrnArUyKAKZzwSakDqTYL43GtDZ94FquxPWHvbwce1unpMdS88xuFOj+NyRKEu90UJ7kACRMxqbF09+MrcAqFGTdmwH+GE8C9C8G3IUKdb1DXrb6ddr/WKnNsDKlEvQxI1ZpkgSA6Op9iXnWgz+3UHgo1kN3+AIk7xTQ==; Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049x-Ii; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiz-0001o7-3Z; Thu, 06 Sep 2018 12:37:17 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:08 +0300 Message-Id: <4e73b26693677b6067545590708adcba66da1c06.1536226505.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 08/10] block: Allow changing 'discard' on reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 'discard' is one of the basic BlockdevOptions available for all drivers, but it's not handled by bdrv_reopen_prepare() so any attempt to change it results in an error: (qemu) qemu-io virtio0 "reopen -o discard=on" Cannot change the option 'discard' Since there's no reason why we shouldn't allow changing it and the implementation is simple let's just do it. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/block.c b/block.c index 1c0f72454a..bd8467bed8 100644 --- a/block.c +++ b/block.c @@ -3155,6 +3155,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, BlockDriver *drv; QemuOpts *opts; QDict *orig_reopen_opts; + char *discard = NULL; bool read_only; assert(reopen_state != NULL); @@ -3177,6 +3178,15 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, update_flags_from_options(&reopen_state->flags, opts); + discard = qemu_opt_get_del(opts, "discard"); + if (discard != NULL) { + if (bdrv_parse_discard_flags(discard, &reopen_state->flags) != 0) { + error_setg(errp, "Invalid discard option"); + ret = -EINVAL; + goto error; + } + } + /* All other options (including node-name and driver) must be unchanged. * Put them back into the QDict, so that they are checked at the end * of this function. */ @@ -3290,6 +3300,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, error: qemu_opts_del(opts); qobject_unref(orig_reopen_opts); + g_free(discard); return ret; } From patchwork Thu Sep 6 09:37:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 966890 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="CRkABJTL"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425bHb3n2sz9s9N for ; Thu, 6 Sep 2018 19:43:55 +1000 (AEST) Received: from localhost ([::1]:60474 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqpN-0002Ei-By for incoming@patchwork.ozlabs.org; Thu, 06 Sep 2018 05:43:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52031) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjM-0005jn-Bb for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjK-0003lc-3o for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:40 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54032) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjJ-0003hY-Pj; Thu, 06 Sep 2018 05:37:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Jac8R0KmCGwdlHrbszUNevFsxzKjmKOALqCHyyB8P9s=; b=CRkABJTL6pkMMc8pxw8HxjBcMdL/9iHt6nGrAD0ZOdkurkyq3Sqq4qg1hr638B7azPII6dkNUkrR/6nsOKsP5i+ndvVjPv32KlovFRBZu+hjbBTETiAuy9jEn1yOGNJ8YKQvQqD8UGO8sDkmZBcYcx75PQ9m/RyVLGVi/Wm2NyCEeXvX9/yirgSRZL9ZQ1OgxU2PqeBstUk7I2eRadnskYq3mpim6wZGsN4s+KjEtF1wCMzBTaoK5h8zuU7p8ibed2NvjZv4+nuroO/ISNygQie/uQgDGHPMXQBnlT4p6AvUinO65lbShfZCExtDLA+TE52pFPQ9P0D2qRPG7slbzg==; Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049z-Kz; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiz-0001o9-5E; Thu, 06 Sep 2018 12:37:17 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:09 +0300 Message-Id: <70655489911f1b2335aa4ae715e153fbb57a37b1.1536226505.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 09/10] block: Allow changing 'detect-zeroes' on reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 'detect-zeroes' is one of the basic BlockdevOptions available for all drivers, but it's not handled by bdrv_reopen_prepare(), so any attempt to change it results in an error: (qemu) qemu-io virtio0 "reopen -o detect-zeroes=on" Cannot change the option 'detect-zeroes' Since there's no reason why we shouldn't allow changing it and the implementation is simple let's just do it. Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 64 ++++++++++++++++++++++++++++++++------------------- include/block/block.h | 1 + 2 files changed, 41 insertions(+), 24 deletions(-) diff --git a/block.c b/block.c index bd8467bed8..808411ebf3 100644 --- a/block.c +++ b/block.c @@ -764,6 +764,31 @@ static void bdrv_join_options(BlockDriverState *bs, QDict *options, } } +static BlockdevDetectZeroesOptions bdrv_parse_detect_zeroes(QemuOpts *opts, + int open_flags, + Error **errp) +{ + Error *local_err = NULL; + char *value = qemu_opt_get_del(opts, "detect-zeroes"); + BlockdevDetectZeroesOptions detect_zeroes = + qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, value, + BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, &local_err); + g_free(value); + if (local_err) { + error_propagate(errp, local_err); + return detect_zeroes; + } + + if (detect_zeroes == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP && + !(open_flags & BDRV_O_UNMAP)) + { + error_setg(errp, "setting detect-zeroes to unmap is not allowed " + "without setting discard operation to unmap"); + } + + return detect_zeroes; +} + /** * Set open flags for a given discard mode * @@ -1328,7 +1353,6 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, const char *driver_name = NULL; const char *node_name = NULL; const char *discard; - const char *detect_zeroes; QemuOpts *opts; BlockDriver *drv; Error *local_err = NULL; @@ -1417,29 +1441,12 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, } } - detect_zeroes = qemu_opt_get(opts, "detect-zeroes"); - if (detect_zeroes) { - BlockdevDetectZeroesOptions value = - qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup, - detect_zeroes, - BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF, - &local_err); - if (local_err) { - error_propagate(errp, local_err); - ret = -EINVAL; - goto fail_opts; - } - - if (value == BLOCKDEV_DETECT_ZEROES_OPTIONS_UNMAP && - !(bs->open_flags & BDRV_O_UNMAP)) - { - error_setg(errp, "setting detect-zeroes to unmap is not allowed " - "without setting discard operation to unmap"); - ret = -EINVAL; - goto fail_opts; - } - - bs->detect_zeroes = value; + bs->detect_zeroes = + bdrv_parse_detect_zeroes(opts, bs->open_flags, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret = -EINVAL; + goto fail_opts; } if (filename != NULL) { @@ -3187,6 +3194,14 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, } } + reopen_state->detect_zeroes = + bdrv_parse_detect_zeroes(opts, reopen_state->flags, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret = -EINVAL; + goto error; + } + /* All other options (including node-name and driver) must be unchanged. * Put them back into the QDict, so that they are checked at the end * of this function. */ @@ -3337,6 +3352,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) bs->options = reopen_state->options; bs->open_flags = reopen_state->flags; bs->read_only = !(reopen_state->flags & BDRV_O_RDWR); + bs->detect_zeroes = reopen_state->detect_zeroes; /* Remove child references from bs->options and bs->explicit_options. * Child options were already removed in bdrv_reopen_queue_child() */ diff --git a/include/block/block.h b/include/block/block.h index 4e0871aaf9..f71fa5a1c4 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -184,6 +184,7 @@ typedef QSIMPLEQ_HEAD(BlockReopenQueue, BlockReopenQueueEntry) BlockReopenQueue; typedef struct BDRVReopenState { BlockDriverState *bs; int flags; + BlockdevDetectZeroesOptions detect_zeroes; uint64_t perm, shared_perm; QDict *options; QDict *explicit_options; From patchwork Thu Sep 6 09:37:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Garcia X-Patchwork-Id: 966891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=208.118.235.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=igalia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="Jwk+sWiX"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 425bL22MQ0z9s9N for ; Thu, 6 Sep 2018 19:46:02 +1000 (AEST) Received: from localhost ([::1]:60492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqrP-0003zZ-UL for incoming@patchwork.ozlabs.org; Thu, 06 Sep 2018 05:46:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51974) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fxqjK-0005jG-P3 for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fxqjG-0003Zr-P5 for qemu-devel@nongnu.org; Thu, 06 Sep 2018 05:37:38 -0400 Received: from fanzine.igalia.com ([91.117.99.155]:54011) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fxqjG-0003Q6-3c; Thu, 06 Sep 2018 05:37:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=References:In-Reply-To:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=skNL4sSYePvUP93ucpBIl0e+sEgKLp4XpoBrdpEYsaw=; b=Jwk+sWiXcwSyp1JRXd4KIGM9zm1Vaxa/REnwwjf6Ls/81juIA1LGhS1cGFAgvcRqsO+16Q0g4D5zTQ9SJ93jpF56ylTu4dMcPi2n94Fy/9Qkg95lqvqdZP/IW4UBPUzhHRxkSfYgRVm6V96u+pD3Bp8AIJ+I9L/zdTataL2ksxJsma9WBvrcJCb0RwcSl0Az6oqoPBzb0wI4TT0R08fSXti5dSb2FcdXZIZV1UyhXlGgsVoAUKBPdygDUZJmT+ue+H+uzSj59DXYWuSEZJHq5uSwYxheu0IW2cqt85vUKk5xXg6Omwl5bhnY1YaJRQkqC2NWn7HrCAPTfu9Fkn99oA==; Received: from 91-158-71-53.elisa-laajakaista.fi ([91.158.71.53] helo=perseus.local) by fanzine.igalia.com with esmtpsa (Cipher TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim) id 1fxqjD-00049y-KT; Thu, 06 Sep 2018 11:37:31 +0200 Received: from berto by perseus.local with local (Exim 4.89) (envelope-from ) id 1fxqiz-0001oB-6U; Thu, 06 Sep 2018 12:37:17 +0300 From: Alberto Garcia To: qemu-devel@nongnu.org Date: Thu, 6 Sep 2018 12:37:10 +0300 Message-Id: <3c1b1ad5e50b71d98e0d6dcdc2ffb02681c600c7.1536226505.git.berto@igalia.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] [fuzzy] X-Received-From: 91.117.99.155 Subject: [Qemu-devel] [PATCH v3 10/10] block: Allow changing 'force-share' on reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alberto Garcia , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 'force-share' is one of the basic BlockdevOptions available for all drivers, but it's not handled by bdrv_reopen_prepare() so any attempt to change it results in a "Cannot change the option" error: (qemu) qemu-io virtio0 "reopen -o force-share=on" Cannot change the option 'force-share' Since there's no reason why we shouldn't allow changing it and the implementation is simple let's just do it. It's worth noting that after this patch the above reopen call will still return an error -although a different one- if the image is not read-only: (qemu) qemu-io virtio0 "reopen -o force-share=on" force-share=on can only be used with read-only images Signed-off-by: Alberto Garcia Reviewed-by: Max Reitz --- block.c | 30 ++++++++++++++++++++++++------ include/block/block.h | 1 + 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 808411ebf3..57cc4161a2 100644 --- a/block.c +++ b/block.c @@ -789,6 +789,18 @@ static BlockdevDetectZeroesOptions bdrv_parse_detect_zeroes(QemuOpts *opts, return detect_zeroes; } +static bool bdrv_parse_force_share(QemuOpts *opts, int flags, Error **errp) +{ + bool value = qemu_opt_get_bool_del(opts, BDRV_OPT_FORCE_SHARE, false); + + if (value && (flags & BDRV_O_RDWR)) { + error_setg(errp, BDRV_OPT_FORCE_SHARE + "=on can only be used with read-only images"); + } + + return value; +} + /** * Set open flags for a given discard mode * @@ -1374,12 +1386,9 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file, drv = bdrv_find_format(driver_name); assert(drv != NULL); - bs->force_share = qemu_opt_get_bool(opts, BDRV_OPT_FORCE_SHARE, false); - - if (bs->force_share && (bs->open_flags & BDRV_O_RDWR)) { - error_setg(errp, - BDRV_OPT_FORCE_SHARE - "=on can only be used with read-only images"); + bs->force_share = bdrv_parse_force_share(opts, bs->open_flags, &local_err); + if (local_err) { + error_propagate(errp, local_err); ret = -EINVAL; goto fail_opts; } @@ -3202,6 +3211,14 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, goto error; } + reopen_state->force_share = + bdrv_parse_force_share(opts, reopen_state->flags, &local_err); + if (local_err) { + error_propagate(errp, local_err); + ret = -EINVAL; + goto error; + } + /* All other options (including node-name and driver) must be unchanged. * Put them back into the QDict, so that they are checked at the end * of this function. */ @@ -3353,6 +3370,7 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state) bs->open_flags = reopen_state->flags; bs->read_only = !(reopen_state->flags & BDRV_O_RDWR); bs->detect_zeroes = reopen_state->detect_zeroes; + bs->force_share = reopen_state->force_share; /* Remove child references from bs->options and bs->explicit_options. * Child options were already removed in bdrv_reopen_queue_child() */ diff --git a/include/block/block.h b/include/block/block.h index f71fa5a1c4..a49a027c54 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -185,6 +185,7 @@ typedef struct BDRVReopenState { BlockDriverState *bs; int flags; BlockdevDetectZeroesOptions detect_zeroes; + bool force_share; uint64_t perm, shared_perm; QDict *options; QDict *explicit_options;