From patchwork Tue Mar 14 03:23:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Jia Shi X-Patchwork-Id: 738541 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vj0Sn5bQPz9s75 for ; Tue, 14 Mar 2017 14:23:53 +1100 (AEDT) Received: from localhost ([::1]:56178 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnd3u-0003k1-PX for incoming@patchwork.ozlabs.org; Mon, 13 Mar 2017 23:23:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cnd3U-0003je-UN for qemu-devel@nongnu.org; Mon, 13 Mar 2017 23:23:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cnd3Q-0003ns-TH for qemu-devel@nongnu.org; Mon, 13 Mar 2017 23:23:24 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:38317 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cnd3Q-0003nR-Mm for qemu-devel@nongnu.org; Mon, 13 Mar 2017 23:23:20 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2E3ERSv100371 for ; Mon, 13 Mar 2017 23:23:19 -0400 Received: from e13.ny.us.ibm.com (e13.ny.us.ibm.com [129.33.205.203]) by mx0b-001b2d01.pphosted.com with ESMTP id 295vx6pshn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 13 Mar 2017 23:23:18 -0400 Received: from localhost by e13.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 13 Mar 2017 23:23:18 -0400 Received: from b01cxnp22036.gho.pok.ibm.com (9.57.198.26) by e13.ny.us.ibm.com (146.89.104.200) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 13 Mar 2017 23:23:15 -0400 Received: from b01ledav005.gho.pok.ibm.com (b01ledav005.gho.pok.ibm.com [9.57.199.110]) by b01cxnp22036.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2E3NEhn55116002; Tue, 14 Mar 2017 03:23:14 GMT Received: from b01ledav005.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6273AE043; Mon, 13 Mar 2017 23:23:07 -0400 (EDT) Received: from oc7835276234.ibm.com (unknown [9.115.114.145]) by b01ledav005.gho.pok.ibm.com (Postfix) with ESMTP id 27B7CAE03B; Mon, 13 Mar 2017 23:23:06 -0400 (EDT) Date: Tue, 14 Mar 2017 11:23:12 +0800 From: Dong Jia Shi To: Kevin Wolf Mail-Followup-To: Kevin Wolf , Dong Jia Shi , qemu-block@nongnu.org, mreitz@redhat.com, qemu-devel@nongnu.org, cornelia.huck@de.ibm.com, pasic@linux.vnet.ibm.com References: <20170308021533.78292-1-bjsdjshi@linux.vnet.ibm.com> <20170308021533.78292-2-bjsdjshi@linux.vnet.ibm.com> <20170308091346.GB5211@noname.redhat.com> <20170308093105.GC7563@bjsdjshi@linux.vnet.ibm.com> <20170313033105.GA6756@bjsdjshi@linux.vnet.ibm.com> <20170313101522.GA5545@noname.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170313101522.GA5545@noname.redhat.com> Organization: (IBM CSL) X-URL: http://ibm.com/ User-Agent: Mutt/1.7.0 (2016-08-17) X-TM-AS-GCONF: 00 x-cbid: 17031403-0008-0000-0000-000001BE459C X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006778; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000206; SDB=6.00833495; UDB=6.00409219; IPR=6.00611152; BA=6.00005207; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014638; XFM=3.00000013; UTC=2017-03-14 03:23:17 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17031403-0009-0000-0000-000033CA06C5 Message-Id: <20170314032312.GF6756@bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-14_02:, , 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-1703140025 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: Re: [Qemu-devel] [PATCH RFC 1/1] block: Handle NULL options correctly in raw_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: pasic@linux.vnet.ibm.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com, cornelia.huck@de.ibm.com, Dong Jia Shi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" * Kevin Wolf [2017-03-13 11:15:22 +0100]: > Am 13.03.2017 um 04:31 hat Dong Jia Shi geschrieben: > > * Dong Jia Shi [2017-03-08 17:31:05 +0800]: > > > > > * Kevin Wolf [2017-03-08 10:13:46 +0100]: > > > > > > > Am 08.03.2017 um 03:15 hat Dong Jia Shi geschrieben: > > > > > A normal call for raw_open should always pass in a non-NULL @options, > > > > > but for some certain cases (e.g. trying to applying snapshot on a RBD > > > > > image), they call raw_open with a NULL @options right after the calling > > > > > for raw_close. > > > > > > > > > > Let's take the NULL @options as a sign of trying to do raw_open again, > > > > > and just simply return a success code. > > > > > > > > > > Signed-off-by: Dong Jia Shi > > > > > > > > I think we rather need to fix bdrv_snapshot_goto() so that it doesn't > > > > pass NULL, but the actual options that were given for the node (i.e. > > > > bs->options). > > > I've tried that before the current try. bs->options does not have the > > > "file" key-value pair, so that leads to a fail too. Should we put "file" > > > in to the options manually? I noticed that it was removed from > > > bs->options during the calling of bdrv_open_inherit. > > > > > Hi Kevin, > > > > After thinking for quite some time, I still don't think we need to fix > > the caller. The reason is that raw_close always does nothing, so no > > matter what the caller passing in, raw_open should do nothing but just > > return 0. > > raw is not the only format driver in qemu. > Hi Kevin, Before this I assumed that the long existing code in bdrv_snapshot_goto which passes in a NULL options to raw_open is on purpose, and that implies to me raw_open (and any other .bdrv_open callback) takes the responsibility to handle NULL options well. So at a first glance, I read your above comment as: "You should also fix .bdrv_open callback for every other formats to handle NULL options as well." But after staring it for a while, I read it from another point around: "You should fix the caller." If this is what you actually meant to tell, I have the following proposal then: I know I'm a little wordy, but that's because I want to make things clear. Anyway, I have to rely on your advice on this, since you are the expert. > Kevin > diff --git a/block/snapshot.c b/block/snapshot.c index bf5c2ca..dfec139 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" QemuOptsList internal_snapshot_opts = { .name = "snapshot", @@ -189,9 +190,14 @@ int bdrv_snapshot_goto(BlockDriverState *bs, } if (bs->file) { + QDict *options = qdict_clone_shallow(bs->options); + qdict_put(options, "file", + qstring_from_str(bdrv_get_node_name(bs->file->bs))); + drv->bdrv_close(bs); ret = bdrv_snapshot_goto(bs->file->bs, snapshot_id); - open_ret = drv->bdrv_open(bs, NULL, bs->open_flags, NULL); + open_ret = drv->bdrv_open(bs, options, bs->open_flags, NULL); + QDECREF(options); if (open_ret < 0) { bdrv_unref(bs->file->bs); bs->drv = NULL;