From patchwork Wed Jun 2 16:55:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 54397 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 2E891B7D29 for ; Thu, 3 Jun 2010 03:19:41 +1000 (EST) Received: from localhost ([127.0.0.1]:43890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJrbJ-00052k-Px for incoming@patchwork.ozlabs.org; Wed, 02 Jun 2010 13:19:33 -0400 Received: from [140.186.70.92] (port=40047 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OJrEq-0007Pc-9V for qemu-devel@nongnu.org; Wed, 02 Jun 2010 12:56:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OJrE4-0005hQ-MT for qemu-devel@nongnu.org; Wed, 02 Jun 2010 12:55:47 -0400 Received: from oxygen.pond.sub.org ([213.239.205.148]:35282) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OJrE4-0005gW-Cx for qemu-devel@nongnu.org; Wed, 02 Jun 2010 12:55:32 -0400 Received: from blackfin.pond.sub.org (pD9E39C24.dip.t-dialin.net [217.227.156.36]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 724BD2DD37C for ; Wed, 2 Jun 2010 18:55:30 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 86BDB375; Wed, 2 Jun 2010 18:55:29 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 2 Jun 2010 18:55:23 +0200 Message-Id: <1275497729-13120-8-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.6.6.1 In-Reply-To: <1275497729-13120-1-git-send-email-armbru@redhat.com> References: <1275497729-13120-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: kwolf@redhat.com, kraxel@redhat.com Subject: [Qemu-devel] [PATCH 07/13] blockdev: Means to destroy blockdev only if made with drive_init() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org All drives are still made that way. They get destroyed along with their device. That's inappropriate for the alternative way to make blockdevs that will appear later in this series. These won't have a DriveInfo. blockdev_detach() destroys the blockdev only if it has a DriveInfo. blockdev_attach() does nothing for now. It'll be fleshed out later. Signed-off-by: Markus Armbruster --- blockdev.c | 35 +++++++++++++++++++++++++++++++++++ blockdev.h | 7 +++++++ 2 files changed, 42 insertions(+), 0 deletions(-) diff --git a/blockdev.c b/blockdev.c index ace74e4..f90d4fc 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1,8 +1,12 @@ /* * QEMU host block devices * + * Copyright (C) 2010 Red Hat Inc. * Copyright (c) 2003-2008 Fabrice Bellard * + * Authors: + * Markus Armbruster , + * * This work is licensed under the terms of the GNU GPL, version 2 or * later. See the COPYING file in the top-level directory. */ @@ -17,6 +21,37 @@ static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives); +static int blockdev_del_dinfo(BlockDriverState *bs) +{ + DriveInfo *dinfo, *next_dinfo; + int res = 0; + + QTAILQ_FOREACH_SAFE(dinfo, &drives, next, next_dinfo) { + if (dinfo->bdrv == bs) { + qemu_opts_del(dinfo->opts); + QTAILQ_REMOVE(&drives, dinfo, next); + qemu_free(dinfo); + res = 1; + } + } + + return res; +} + +int blockdev_attach(BlockDriverState *bs, DeviceState *qdev) +{ + return 0; +} + +void blockdev_detach(BlockDriverState *bs, DeviceState *qdev) +{ + /* Backward compatibility: auto-destroy block device made with + * drive_init() when its guest device detaches */ + if (blockdev_del_dinfo(bs)) { + bdrv_delete(bs); + } +} + QemuOpts *drive_add(const char *file, const char *fmt, ...) { va_list ap; diff --git a/blockdev.h b/blockdev.h index 23ea576..8607086 100644 --- a/blockdev.h +++ b/blockdev.h @@ -1,8 +1,12 @@ /* * QEMU host block devices * + * Copyright (C) 2010 Red Hat Inc. * Copyright (c) 2003-2008 Fabrice Bellard * + * Authors: + * Markus Armbruster , + * * This work is licensed under the terms of the GNU GPL, version 2 or * later. See the COPYING file in the top-level directory. */ @@ -13,6 +17,9 @@ #include "block.h" #include "qemu-queue.h" +int blockdev_attach(BlockDriverState *, DeviceState *); +void blockdev_detach(BlockDriverState *, DeviceState *); + typedef enum { IF_NONE, IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,