From patchwork Mon Feb 22 14:39:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8377921 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 35A96C0553 for ; Mon, 22 Feb 2016 14:40:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 899232039C for ; Mon, 22 Feb 2016 14:40:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A5E2B2034B for ; Mon, 22 Feb 2016 14:40:31 +0000 (UTC) Received: from localhost ([::1]:49458 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXrf5-0001nk-4i for patchwork-qemu-devel@patchwork.kernel.org; Mon, 22 Feb 2016 09:40:31 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXrdq-0008BD-3P for qemu-devel@nongnu.org; Mon, 22 Feb 2016 09:39:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aXrdp-0007WE-3U for qemu-devel@nongnu.org; Mon, 22 Feb 2016 09:39:14 -0500 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]:38241) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aXrdo-0007W0-SS for qemu-devel@nongnu.org; Mon, 22 Feb 2016 09:39:13 -0500 Received: by mail-wm0-x229.google.com with SMTP id a4so165734302wme.1 for ; Mon, 22 Feb 2016 06:39:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=dnVleBkHJt9LiV8yKaVGdDMTJ3aw+ZDOWkyAqzl/HIo=; b=q1IL598ZJJbqRv5ULK1qd5pSMW6HgLLxPGrQuFzi/qxQ+ZvLrsrRQ0aSMPQnsCN6Bb osQ66pZPFMWxghmIoDFGhnv+u3g9d0Op5BQnlwLNrbGsLCXDzWzUmOaTVxicBAinDMV5 l1CJZEikr11KI2+Vom1J85GPbTIItSGSI5Wn5CITC1KLxhva5uQzmi9SdHe4ot8B3viq /Gzo5ELqvzuJCyJapQ4DW+wwVqKeMx8FTVr8PWTSq9QwOGlue8B/dqtLn99swtKr+rJM tRnEl5LnYUMafaldGkyhkSxHhnxy3Ea5mvgda7dqIMpACSWdiA/PZWBBnRtNk9s6ELnT m9iQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=dnVleBkHJt9LiV8yKaVGdDMTJ3aw+ZDOWkyAqzl/HIo=; b=fSMQCfO5WqX7MvinRumoIUWMd3gSRFH1y8vy4Lf4aJHRLI9KqZLM52Zef181LWeenA COMyicrkc7c4279WGyqsLGTeDZ7eOAHwrOiGMYBo6TJqbX2Co/L6sjX0LN/vXBJRskpA 2zY7Jil19MqRQrGzFJ0TvfZa5nC7Gg+uvorSECqUWSjaP8ZW1aFpXu55cX1pZ03Dt0BN 5gic/0yl7FdoAX325jJlVcLGRC45/igFM7FciwCi4cwkJdgKT/A/O49+Y3czxqG4A2MO jWBmflh97h5t6DlZXMCbS+KukAV77dTIfP2ZoemyLhZjXtAHu8IWmCWEeWxGQepcLF+b Od9g== X-Gm-Message-State: AG10YOTSodwSi9mFKbl6MpJHAS4S98ADF1zJLAQy6LR4R7raTT5BApVdyoslBJjXksalNw== X-Received: by 10.194.82.41 with SMTP id f9mr28206652wjy.139.1456151952272; Mon, 22 Feb 2016 06:39:12 -0800 (PST) Received: from donizetti.lan (94-39-138-146.adsl-ull.clienti.tiscali.it. [94.39.138.146]) by smtp.gmail.com with ESMTPSA id b5sm21410196wmh.15.2016.02.22.06.39.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Feb 2016 06:39:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 22 Feb 2016 15:39:04 +0100 Message-Id: <1456151945-11225-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1456151945-11225-1-git-send-email-pbonzini@redhat.com> References: <1456151945-11225-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::229 Cc: Kevin Wolf , Markus Armbruster , Max Reitz Subject: [Qemu-devel] [PATCH 2/3] block: keep BlockBackend alive until device finalize time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP While the next patch will anticipate the death of the DriveInfo data structure, the BlockBackend must survive after unrealize, for example in case there are outstanding operations on it. The good thing is that we can just use reference counting to do it. Signed-off-by: Paolo Bonzini --- hw/core/qdev-properties-system.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c index 469ba8a..5e84b55 100644 --- a/hw/core/qdev-properties-system.c +++ b/hw/core/qdev-properties-system.c @@ -93,6 +93,7 @@ static void parse_drive(DeviceState *dev, const char *str, void **ptr, return; } *ptr = blk; + blk_ref(blk); } static void release_drive(Object *obj, const char *name, void *opaque) @@ -101,13 +102,17 @@ static void release_drive(Object *obj, const char *name, void *opaque) Property *prop = opaque; BlockBackend **ptr = qdev_get_prop_ptr(dev, prop); - if (*ptr && blk_get_attached_dev(*ptr) != NULL) { - /* Unrealize has already called blk_detach_dev and blockdev_del_drive - * if the device has been realized; in that case, blk_get_attached_dev - * returns NULL. Thus, we get here if the device failed to realize, - * and the -drive must not be released. - */ - blk_detach_dev(*ptr, dev); + if (*ptr) { + if (blk_get_attached_dev(*ptr) != NULL) { + /* Unrealize has already called blk_detach_dev and + * blockdev_del_drive if the device has been realized; + * in that case, blk_get_attached_dev returns NULL. Thus, + * we get here if the device failed to realize, and the + * -drive must not be released. + */ + blk_detach_dev(*ptr, dev); + } + blk_unref(*ptr); } }