WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [qemu-xen-unstable] implement cdrom eject from the guest

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [qemu-xen-unstable] implement cdrom eject from the guest
From: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Date: Mon, 4 Jan 2010 10:05:18 -0800
Delivery-date: Mon, 04 Jan 2010 10:05:15 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
commit 9bac5357507958e2eabcf96bce40cca336fa46ac
Author: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Date:   Mon Jan 4 16:21:55 2010 +0000

    implement cdrom eject from the guest
    
    Hi all,
    this patch allows a guest to eject the cdrom: when qemu detects that a
    cdrom eject request ahs been issued by the guest, it writes eject to the
    corresponding xenstore frontend, so that the toolstack can take care of
    removing the current cdrom frontend\backend couple and create an empty one
    instead.
    
    Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 hw/ide.c   |    2 ++
 qemu-xen.h |    2 ++
 xenstore.c |   34 +++++++++++++++++++++++++++++++++-
 3 files changed, 37 insertions(+), 1 deletions(-)

diff --git a/hw/ide.c b/hw/ide.c
index e8d676e..b38de55 100644
--- a/hw/ide.c
+++ b/hw/ide.c
@@ -35,6 +35,7 @@
 #include "mac_dbdma.h"
 #include "sh.h"
 #include "dma.h"
+#include "qemu-xen.h"
 
 /* debug IDE devices */
 //#define DEBUG_IDE
@@ -2100,6 +2101,7 @@ static void ide_atapi_cmd(IDEState *s)
 
             if (eject && !start) {
                 /* eject the disk */
+                xenstore_do_eject(s->bs);
                 bdrv_eject(s->bs, 1);
             } else if (eject && start) {
                 /* close the tray */
diff --git a/qemu-xen.h b/qemu-xen.h
index 29b8161..ab4b631 100644
--- a/qemu-xen.h
+++ b/qemu-xen.h
@@ -123,6 +123,8 @@ char *xenstore_read_battery_data(int battery_status);
 int xenstore_refresh_battery_status(void);
 int xenstore_pv_driver_build_blacklisted(uint16_t product_number,
                                          uint32_t build_nr);
+void xenstore_do_eject(BlockDriverState *bs);
+int xenstore_find_device(BlockDriverState *bs);
 
 /* xenfbfront.c */
 int xenfb_pv_display_init(DisplayState *ds);
diff --git a/xenstore.c b/xenstore.c
index 5064719..05a1c22 100644
--- a/xenstore.c
+++ b/xenstore.c
@@ -26,6 +26,31 @@
 struct xs_handle *xsh = NULL;
 static char *media_filename[MAX_DRIVES+1];
 static QEMUTimer *insert_timer = NULL;
+static char *xenbus_param_paths[MAX_DRIVES+1];
+
+int xenstore_find_device(BlockDriverState *bs)
+{
+    int i;
+
+    for (i = 0; i < MAX_DRIVES + 1; i++) {
+        if (drives_table[i].bdrv == bs)
+            return i;
+    }
+    return -1;
+}
+
+void xenstore_do_eject(BlockDriverState *bs)
+{
+    int i;
+
+    i = xenstore_find_device(bs);
+    if (i == -1) {
+        fprintf(stderr, "couldn't find disk to eject.\n");
+        return;
+    }
+    if (xenbus_param_paths[i])
+        xs_write(xsh, XBT_NULL, xenbus_param_paths[i], "eject", 
strlen("eject"));
+}
 
 #define UWAIT_MAX (30*1000000) /* thirty seconds */
 #define UWAIT     (100000)     /* 1/10th second  */
@@ -526,8 +551,15 @@ void xenstore_parse_domain_config(int hvm_domid)
         /* check if it is a cdrom */
         if (danger_type && !strcmp(danger_type, "cdrom")) {
             bdrv_set_type_hint(bs, BDRV_TYPE_CDROM);
-            if (pasprintf(&buf, "%s/params", bpath) != -1)
+            if (pasprintf(&buf, "%s/params", bpath) != -1) {
+                char *buf2, *frontend;
                 xs_watch(xsh, buf, dev);
+                asprintf(&buf2, "%s/frontend", bpath);
+                frontend = xs_read(xsh, XBT_NULL, buf2, &len);
+                asprintf(&xenbus_param_paths[nb_drives], "%s/eject", frontend);
+                free(frontend);
+                free(buf2);
+            }
         }
 
         /* open device now if media present */
--
generated by git-patchbot for /home/xen/git/qemu-xen-unstable.git

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [qemu-xen-unstable] implement cdrom eject from the guest, Ian Jackson <=