From patchwork Thu Jun 20 17:46:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 253053 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EDE9E2C0040 for ; Fri, 21 Jun 2013 04:10:20 +1000 (EST) Received: from localhost ([::1]:54094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpjBQ-0000WN-F4 for incoming@patchwork.ozlabs.org; Thu, 20 Jun 2013 14:02:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upj4y-0005LY-FF for qemu-devel@nongnu.org; Thu, 20 Jun 2013 13:55:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Upj4x-0005CP-88 for qemu-devel@nongnu.org; Thu, 20 Jun 2013 13:55:28 -0400 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]:63967) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upiwb-0002IL-7A for qemu-devel@nongnu.org; Thu, 20 Jun 2013 13:46:49 -0400 Received: by mail-wi0-f170.google.com with SMTP id ey16so2183542wid.1 for ; Thu, 20 Jun 2013 10:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=nwnWZWyLzZREkX8dZAsmepUASawNY+WWAz6XtghW2R8=; b=WGJtDk7UrlJC7wg9orcrI9gHgSPFjxRUcSnhA3VLRlqFxfkvpvxJe9Yb8RDyKWdSHE 5F3S6ZZhTHLTj4gvNDMBg2kVQrglV9CIb9BIiWJhyV60iHRtN32Pd/bJ6PrshXpZDX1s P1BPGGSJcY+GkiMpR2JSdax+8VsHSNiSagngbnfwhi64o8R1rpvMRW/SMSRFD3hcjNO9 dK+cq1+l+SX+kLA1PGtuA+8DBFb+3ptKxs2lOiMqZp2OGDIWOYCb3E/aUTuEZvjOdB51 gx0mgiWT6CdnyxLiJUArCRArrKxwgOM+VaWcYOEemZyYvDcsUxhJ0mNVIfMPrgF3+D4i f/EQ== X-Received: by 10.180.75.110 with SMTP id b14mr377802wiw.6.1371750408554; Thu, 20 Jun 2013 10:46:48 -0700 (PDT) Received: from localhost (158.red-80-26-177.adsl.dynamic.ccgg.telefonica.net. [80.26.177.158]) by mx.google.com with ESMTPSA id nj19sm2085814wic.1.2013.06.20.10.46.46 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 20 Jun 2013 10:46:47 -0700 (PDT) From: "=?UTF-8?q?Marc-Andr=C3=A9=20Lureau?=" To: qemu-devel@nongnu.org Date: Thu, 20 Jun 2013 19:46:06 +0200 Message-Id: <1371750371-18491-8-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 1.8.3.rc1.49.g8d97506 In-Reply-To: <1371750371-18491-1-git-send-email-marcandre.lureau@redhat.com> References: <1371750371-18491-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::22a Cc: spice-devel@lists.freedesktop.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [Qemu-devel] [PATCH 07/12] block: save the associated child in BlockDriverState 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This allows the Spice block driver to eject the associated device. Signed-off-by: Marc-André Lureau --- block.c | 46 +++++++++++++++++++++++++++++----------------- include/block/block_int.h | 1 + 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/block.c b/block.c index b88ad2f..f502eed 100644 --- a/block.c +++ b/block.c @@ -294,7 +294,8 @@ void bdrv_register(BlockDriver *bdrv) } /* create a new block device (by default it is empty) */ -BlockDriverState *bdrv_new(const char *device_name) +static BlockDriverState *bdrv_new_int(const char *device_name, + BlockDriverState *child) { BlockDriverState *bs; @@ -305,10 +306,16 @@ BlockDriverState *bdrv_new(const char *device_name) } bdrv_iostatus_disable(bs); notifier_list_init(&bs->close_notifiers); + bs->child = child; return bs; } +BlockDriverState *bdrv_new(const char *device_name) +{ + return bdrv_new_int(device_name, NULL); +} + void bdrv_add_close_notifier(BlockDriverState *bs, Notifier *notify) { notifier_list_add(&bs->close_notifiers, notify); @@ -769,16 +776,8 @@ free_and_fail: return ret; } -/* - * Opens a file using a protocol (file, host_device, nbd, ...) - * - * options is a QDict of options to pass to the block drivers, or NULL for an - * empty set of options. The reference to the QDict belongs to the block layer - * after the call (even on failure), so if the caller intends to reuse the - * dictionary, it needs to use QINCREF() before calling bdrv_file_open. - */ -int bdrv_file_open(BlockDriverState **pbs, const char *filename, - QDict *options, int flags) +static int bdrv_file_open_int(BlockDriverState **pbs, const char *filename, + QDict *options, int flags, BlockDriverState *child) { BlockDriverState *bs; BlockDriver *drv; @@ -790,7 +789,7 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, options = qdict_new(); } - bs = bdrv_new(""); + bs = bdrv_new_int("", child); bs->options = options; options = qdict_clone_shallow(options); @@ -873,6 +872,20 @@ fail: } /* + * Opens a file using a protocol (file, host_device, nbd, ...) + * + * options is a QDict of options to pass to the block drivers, or NULL for an + * empty set of options. The reference to the QDict belongs to the block layer + * after the call (even on failure), so if the caller intends to reuse the + * dictionary, it needs to use QINCREF() before calling bdrv_file_open. + */ +int bdrv_file_open(BlockDriverState **pbs, const char *filename, + QDict *options, int flags) +{ + return bdrv_file_open_int(pbs, filename, options, flags, NULL); +} + +/* * Opens the backing file for a BlockDriverState if not yet open * * options is a QDict of options to pass to the block drivers, or NULL for an @@ -904,7 +917,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options) return 0; } - bs->backing_hd = bdrv_new(""); + bs->backing_hd = bdrv_new_int("", bs); bdrv_get_full_backing_filename(bs, backing_filename, sizeof(backing_filename)); @@ -990,7 +1003,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, instead of opening 'filename' directly */ /* if there is a backing file, use it */ - bs1 = bdrv_new(""); + bs1 = bdrv_new_int("", bs); ret = bdrv_open(bs1, filename, NULL, 0, drv); if (ret < 0) { bdrv_delete(bs1); @@ -1043,9 +1056,8 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, } extract_subqdict(options, &file_options, "file."); - - ret = bdrv_file_open(&file, filename, file_options, - bdrv_open_flags(bs, flags)); + ret = bdrv_file_open_int(&file, filename, file_options, + bdrv_open_flags(bs, flags), bs); if (ret < 0) { goto fail; } diff --git a/include/block/block_int.h b/include/block/block_int.h index ba52247..9c72b32 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -245,6 +245,7 @@ struct BlockDriverState { BlockDriverState *backing_hd; BlockDriverState *file; + BlockDriverState *child; NotifierList close_notifiers;