]> xenbits.xensource.com Git - xenclient/kernel.git/commitdiff
linux/blkfront: Add "media" file to vbd sysfs directory
authorKeir Fraser <keir.fraser@citrix.com>
Tue, 29 Jul 2008 15:16:31 +0000 (16:16 +0100)
committerKeir Fraser <keir.fraser@citrix.com>
Tue, 29 Jul 2008 15:16:31 +0000 (16:16 +0100)
Patch adds "media" file to the vbd sysfs directory.  File contains a
string,  cdrom or disk.

Currently all PV vbd devices are seen by HAL as "disk".  Applications
that query HAL info.capabilities attribute to determine a block
devices capabilities fail to see a PV cdrom as having CDROM
capabilities. With the attached patch and a small corresponding patch
to HAL, applications that query HAL for the storage type of the block
device will see it as a disk or a cdrom.  Standard Linux IDE devices
use this same mechanism.

lshal of vbd without patches:
     info.capabilities = {'storage', 'block'} (string list)
lshal of vbd with patches:
    info.capabilities = {'storage', 'block', 'storage.cdrom'} (string
     list)

Signed-off-by: Pat Campbell <plc@novell.com>
drivers/xen/blkfront/blkfront.c
drivers/xen/blkfront/block.h
drivers/xen/blkfront/vbd.c

index d7b9c5434731a05b8c0c5608e1c325892c58db26..c4b1ecd65242608a1552d9a9769c015368d3a69a 100644 (file)
@@ -352,6 +352,13 @@ static void connect(struct blkfront_info *info)
                return;
        }
 
+       err = xlvbd_sysfs_addif(info);
+       if (err) {
+               xenbus_dev_fatal(info->xbdev, err, "xlvbd_sysfs_addif at %s",
+                                info->xbdev->otherend);
+               return;
+       }
+
        (void)xenbus_switch_state(info->xbdev, XenbusStateConnected);
 
        /* Kick pending requests. */
@@ -391,6 +398,8 @@ static void blkfront_closing(struct xenbus_device *dev)
        /* Flush gnttab callback work. Must be done with no locks held. */
        flush_scheduled_work();
 
+       xlvbd_sysfs_delif(info);
+
        xlvbd_del(info);
 
  out:
index 29a877c0953545c02d3f043d598d6c7f32921bac..b8f0cf53f7317cb961cf6a871831fb957dead496 100644 (file)
@@ -140,4 +140,19 @@ int xlvbd_add(blkif_sector_t capacity, int device,
 void xlvbd_del(struct blkfront_info *info);
 int xlvbd_barrier(struct blkfront_info *info);
 
+#ifdef CONFIG_SYSFS
+int xlvbd_sysfs_addif(struct blkfront_info *info);
+void xlvbd_sysfs_delif(struct blkfront_info *info);
+#else
+static inline int xlvbd_sysfs_addif(struct blkfront_info *info)
+{
+       return 0;
+}
+
+static inline void xlvbd_sysfs_delif(struct blkfront_info *info)
+{
+       ;
+}
+#endif
+
 #endif /* __XEN_DRIVERS_BLOCK_H__ */
index 9acdcb40f74e8999dfe8c3a63459e2e828741ff6..3fb0958ee21990c24596e6fa5a4de7f67cf2fd29 100644 (file)
@@ -413,3 +413,48 @@ xlvbd_barrier(struct blkfront_info *info)
        return -ENOSYS;
 }
 #endif
+
+#ifdef CONFIG_SYSFS
+static ssize_t show_media(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+       struct xenbus_device *xendev = to_xenbus_device(dev);
+       struct blkfront_info *info = xendev->dev.driver_data;
+
+       if (info->gd->flags & GENHD_FL_CD)
+               return sprintf(buf, "cdrom\n");
+       return sprintf(buf, "disk\n");
+}
+
+static struct device_attribute xlvbd_attrs[] = {
+       __ATTR(media, S_IRUGO, show_media, NULL),
+};
+
+int xlvbd_sysfs_addif(struct blkfront_info *info)
+{
+       int i;
+       int error = 0;
+
+       for (i = 0; i < ARRAY_SIZE(xlvbd_attrs); i++) {
+               error = device_create_file(info->gd->driverfs_dev,
+                               &xlvbd_attrs[i]);
+               if (error)
+                       goto fail;
+       }
+       return 0;
+
+fail:
+       while (--i >= 0)
+               device_remove_file(info->gd->driverfs_dev, &xlvbd_attrs[i]);
+       return error;
+}
+
+void xlvbd_sysfs_delif(struct blkfront_info *info)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(xlvbd_attrs); i++)
+               device_remove_file(info->gd->driverfs_dev, &xlvbd_attrs[i]);
+}
+
+#endif /* CONFIG_SYSFS */