All of lore.kernel.org
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 07/13] blockdev: Means to destroy blockdev only if made with drive_init()
Date: Wed,  2 Jun 2010 18:55:23 +0200	[thread overview]
Message-ID: <1275497729-13120-8-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1275497729-13120-1-git-send-email-armbru@redhat.com>

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 <armbru@redhat.com>
---
 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 <armbru@redhat.com>,
+ *
  * 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 <armbru@redhat.com>,
+ *
  * 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,
-- 
1.6.6.1

  parent reply	other threads:[~2010-06-02 16:56 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-02 16:55 [Qemu-devel] [PATCH 00/13] New -blockdev to define a host block device Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 01/13] block: Move error actions from DriveInfo to BlockDriverState Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 02/13] block: Decouple block device "commit all" from DriveInfo Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 03/13] monitor: Make "commit FOO" complain when FOO doesn't exist Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 04/13] block: New bdrv_next() Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 05/13] block: Decouple savevm from DriveInfo Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 06/13] blockdev: Give drives internal linkage Markus Armbruster
2010-06-02 16:55 ` Markus Armbruster [this message]
2010-06-10 14:19   ` [Qemu-devel] Re: [PATCH 07/13] blockdev: Means to destroy blockdev only if made with drive_init() Kevin Wolf
2010-06-10 16:00     ` Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 08/13] qdev: Decouple qdev_prop_drive from DriveInfo Markus Armbruster
2010-06-02 19:28   ` [Qemu-devel] " Gerd Hoffmann
2010-06-04  8:22     ` Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 09/13] blockdev: drive_get_by_id() is no longer used, remove Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 10/13] qemu-option: New qemu_opts_reset() Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 11/13] qemu-option: New qemu_opt_next(), qemu_opt_name() Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 12/13] blockdev: Factor option value parsers out of drive_init() Markus Armbruster
2010-06-02 16:55 ` [Qemu-devel] [PATCH 13/13] blockdev: New -blockdev to define a host block device Markus Armbruster
2010-06-03  8:00   ` Christoph Hellwig
2010-06-04  8:23     ` Markus Armbruster
2010-06-10 15:32   ` [Qemu-devel] " Paolo Bonzini
2010-06-10 16:32     ` Markus Armbruster
2010-06-10 17:03       ` Paolo Bonzini
2010-06-14 14:46   ` [Qemu-devel] " Anthony Liguori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1275497729-13120-8-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.