From nobody Sat Apr 27 15:31:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491384045250219.56904098885184; Wed, 5 Apr 2017 02:20:45 -0700 (PDT) Received: from localhost ([::1]:39527 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvh7L-0001tv-J6 for importer@patchew.org; Wed, 05 Apr 2017 05:20:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvh69-0001A9-6A for qemu-devel@nongnu.org; Wed, 05 Apr 2017 05:19:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvh64-0000i0-T1 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 05:19:29 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:51330) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvh64-0000gI-Kc for qemu-devel@nongnu.org; Wed, 05 Apr 2017 05:19:24 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v359J1gW057527 for ; Wed, 5 Apr 2017 05:19:22 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 29mr5sdbrq-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 05 Apr 2017 05:19:22 -0400 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Apr 2017 03:19:20 -0600 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 5 Apr 2017 03:19:17 -0600 Received: from b03ledav002.gho.boulder.ibm.com (b03ledav002.gho.boulder.ibm.com [9.17.130.233]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v359JF8817301768; Wed, 5 Apr 2017 02:19:15 -0700 Received: from b03ledav002.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46B4213603C; Wed, 5 Apr 2017 03:19:15 -0600 (MDT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav002.gho.boulder.ibm.com (Postfix) with ESMTP id 1406E13603A; Wed, 5 Apr 2017 03:19:13 -0600 (MDT) From: Dong Jia Shi To: qemu-block@nongnu.org, kwolf@redhat.com, mreitz@redhat.com Date: Wed, 5 Apr 2017 11:19:09 +0200 X-Mailer: git-send-email 2.10.2 In-Reply-To: <20170405091909.36357-1-bjsdjshi@linux.vnet.ibm.com> References: <20170405091909.36357-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17040509-0012-0000-0000-000013FF988F X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006885; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000208; SDB=6.00843361; UDB=6.00415528; IPR=6.00621539; BA=6.00005268; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014919; XFM=3.00000013; UTC=2017-04-05 09:19:18 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17040509-0013-0000-0000-00004CBEC5D0 Message-Id: <20170405091909.36357-2-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-05_07:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704050083 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v4 1/1] block: pass the right options for BlockDriver.bdrv_open() 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: cornelia.huck@de.ibm.com, borntraeger@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" raw_open() expects the caller always passing in the right actual @options parameter. But when trying to applying snapshot on a RBD image, bdrv_snapshot_goto() calls raw_open() (by calling the bdrv_open callback on the BlockDriver) with a NULL @options, and that will result in a Segmentation fault. For the other non-raw format drivers, it also makes sense to passing in the actual options, althought they don't trigger the problem so far. Let's prepare a @options by adding the "file" key-value pair to a copy of the actual options that were given for the node (i.e. bs->options), and pass it to the callback. BlockDriver.bdrv_open() expects bs->file to be NULL and just overwrites it with the result from bdrv_open_child(). That means we should actually make sure it's NULL because otherwise the child BDS will have a reference count that is 1 too high. So we unconditionally invoke bdrv_unref_child() before calling BlockDriver.bdrv_open(), and we wrap everything in bdrv_ref()/bdrv_unref() so the BDS isn't deleted in the meantime. Suggested-by: Max Reitz Signed-off-by: Dong Jia Shi --- block/snapshot.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/block/snapshot.c b/block/snapshot.c index bf5c2ca..06b1185 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -27,6 +27,7 @@ #include "block/block_int.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" +#include "qapi/qmp/qstring.h" =20 QemuOptsList internal_snapshot_opts =3D { .name =3D "snapshot", @@ -189,14 +190,33 @@ int bdrv_snapshot_goto(BlockDriverState *bs, } =20 if (bs->file) { + BlockDriverState *file; + QDict *options =3D qdict_clone_shallow(bs->options); + QDict *file_options; + + file =3D bs->file->bs; + /* Prevent it from getting deleted when detached from bs */ + bdrv_ref(file); + + qdict_extract_subqdict(options, &file_options, "file."); + QDECREF(file_options); + qdict_put(options, "file", qstring_from_str(bdrv_get_node_name(fil= e))); + drv->bdrv_close(bs); - ret =3D bdrv_snapshot_goto(bs->file->bs, snapshot_id); - open_ret =3D drv->bdrv_open(bs, NULL, bs->open_flags, NULL); + bdrv_unref_child(bs, bs->file); + bs->file =3D NULL; + + ret =3D bdrv_snapshot_goto(file, snapshot_id); + open_ret =3D drv->bdrv_open(bs, options, bs->open_flags, NULL); + QDECREF(options); if (open_ret < 0) { - bdrv_unref(bs->file->bs); + bdrv_unref(file); bs->drv =3D NULL; return open_ret; } + + assert(bs->file->bs =3D=3D file); + bdrv_unref(file); return ret; } =20 --=20 2.10.2