qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Leonardo E. Reiter" <lreiter@win4lin.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Add support to enable dynamic removable block devices
Date: Sun, 16 Apr 2006 13:21:05 -0400	[thread overview]
Message-ID: <44427D01.7060804@win4lin.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1020 bytes --]

Hello,

attached is a patch that modifies the block driver infrastructure to 
support optional "dynamic" removable block devices.  For example, today, 
you can attach a CDROM block device, but it has to be manually attached 
and ejected from the monitor, even if this block device points to a real 
physical driver (i.e. /dev/cdrom on Linux), which itself supports really 
removable media.

The patch does not change any current functionality.  But, it can be 
used to build a block driver which has dynamic state for the media, even 
though the block device itself is attached statically.  For example, 
this will enable [in the future - new block driver needed] attaching a 
real CDROM device, and having the ability to actually eject the media 
and insert new media without having to use the monitor.

Regards,

Leo Reiter

-- 
Leonardo E. Reiter
Vice President of Product Development, CTO

Win4Lin, Inc.
Virtual Computing from Desktop to Data Center
Main: +1 512 339 7979
Fax: +1 512 532 6501
http://www.win4lin.com

[-- Attachment #2: qemu-blk-rmv.patch --]
[-- Type: text/x-patch, Size: 2704 bytes --]

Index: block.c
===================================================================
RCS file: /cvsroot/qemu/qemu/block.c,v
retrieving revision 1.25
diff -a -u -r1.25 block.c
--- block.c	18 Dec 2005 18:28:15 -0000	1.25
+++ block.c	16 Apr 2006 17:14:59 -0000
@@ -446,13 +446,21 @@
     return 0;
 }
 
+/* this function is needed to avoid checking for/calling dynamic methods for 
+ * removable devices if the device is not designated as removable */
+static inline int bdrv_can_write(BlockDriverState *bs)
+{
+    if (!bs->removable)
+        return (bs->inserted) && (!bs->read_only);
+    else
+        return (bdrv_is_inserted(bs)) && (!bdrv_is_read_only(bs));
+}
+
 /* return -1 if error */
 int bdrv_write(BlockDriverState *bs, int64_t sector_num, 
                const uint8_t *buf, int nb_sectors)
 {
-    if (!bs->inserted)
-        return -1;
-    if (bs->read_only)
+    if (!bdrv_can_write(bs))
         return -1;
     if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
         memcpy(bs->boot_sector_data, buf, 512);   
@@ -520,11 +528,15 @@
 
 int bdrv_is_read_only(BlockDriverState *bs)
 {
+    if (bs->drv && bs->drv->bdrv_is_read_only)
+        bs->read_only = bs->drv->bdrv_is_read_only(bs);
     return bs->read_only;
 }
 
 int bdrv_is_inserted(BlockDriverState *bs)
 {
+    if (bs->drv && bs->drv->bdrv_is_inserted)
+        bs->inserted = bs->drv->bdrv_is_inserted(bs);
     return bs->inserted;
 }
 
@@ -535,6 +547,13 @@
 
 void bdrv_set_locked(BlockDriverState *bs, int locked)
 {
+    /* XXX: bs->drv->bdrv_set_locked() has no need to set bs->locked; if this 
+     * function gets called from the disk controller, it has to always set the 
+     * locked state to whatever the disk controller says, regardless of whether 
+     * or not this is implemented by the block driver itself or whether or not
+     * the block driver succeeds in setting the locked state. */
+    if (bs->drv && bs->drv->bdrv_set_locked)
+        bs->drv->bdrv_set_locked(bs, locked);
     bs->locked = locked;
 }
 
Index: block_int.h
===================================================================
RCS file: /cvsroot/qemu/qemu/block_int.h,v
retrieving revision 1.4
diff -a -u -r1.4 block_int.h
--- block_int.h	18 Dec 2005 18:28:15 -0000	1.4
+++ block_int.h	16 Apr 2006 17:14:59 -0000
@@ -40,6 +40,9 @@
                              int nb_sectors, int *pnum);
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
     int (*bdrv_make_empty)(BlockDriverState *bs);
+    int (*bdrv_is_read_only)(BlockDriverState *bs);
+    int (*bdrv_is_inserted)(BlockDriverState *bs);
+    void (*bdrv_set_locked)(BlockDriverState *bs, int locked);
     struct BlockDriver *next;
 };
 

                 reply	other threads:[~2006-04-16 17:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=44427D01.7060804@win4lin.com \
    --to=lreiter@win4lin.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).