ia64/linux-2.6.18-xen.hg

changeset 629:1d647ef26f3f

linux/blkfront: Add "media" file to vbd sysfs directory

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>
author Keir Fraser <keir.fraser@citrix.com>
date Tue Jul 29 16:16:31 2008 +0100 (2008-07-29)
parents b8916f4d48f6
children 44e3ace9a1f1
files drivers/xen/blkfront/blkfront.c drivers/xen/blkfront/block.h drivers/xen/blkfront/vbd.c
line diff
     1.1 --- a/drivers/xen/blkfront/blkfront.c	Tue Jul 29 13:26:15 2008 +0100
     1.2 +++ b/drivers/xen/blkfront/blkfront.c	Tue Jul 29 16:16:31 2008 +0100
     1.3 @@ -352,6 +352,13 @@ static void connect(struct blkfront_info
     1.4  		return;
     1.5  	}
     1.6  
     1.7 +	err = xlvbd_sysfs_addif(info);
     1.8 +	if (err) {
     1.9 +		xenbus_dev_fatal(info->xbdev, err, "xlvbd_sysfs_addif at %s",
    1.10 +				 info->xbdev->otherend);
    1.11 +		return;
    1.12 +	}
    1.13 +
    1.14  	(void)xenbus_switch_state(info->xbdev, XenbusStateConnected);
    1.15  
    1.16  	/* Kick pending requests. */
    1.17 @@ -391,6 +398,8 @@ static void blkfront_closing(struct xenb
    1.18  	/* Flush gnttab callback work. Must be done with no locks held. */
    1.19  	flush_scheduled_work();
    1.20  
    1.21 +	xlvbd_sysfs_delif(info);
    1.22 +
    1.23  	xlvbd_del(info);
    1.24  
    1.25   out:
     2.1 --- a/drivers/xen/blkfront/block.h	Tue Jul 29 13:26:15 2008 +0100
     2.2 +++ b/drivers/xen/blkfront/block.h	Tue Jul 29 16:16:31 2008 +0100
     2.3 @@ -140,4 +140,19 @@ int xlvbd_add(blkif_sector_t capacity, i
     2.4  void xlvbd_del(struct blkfront_info *info);
     2.5  int xlvbd_barrier(struct blkfront_info *info);
     2.6  
     2.7 +#ifdef CONFIG_SYSFS
     2.8 +int xlvbd_sysfs_addif(struct blkfront_info *info);
     2.9 +void xlvbd_sysfs_delif(struct blkfront_info *info);
    2.10 +#else
    2.11 +static inline int xlvbd_sysfs_addif(struct blkfront_info *info)
    2.12 +{
    2.13 +	return 0;
    2.14 +}
    2.15 +
    2.16 +static inline void xlvbd_sysfs_delif(struct blkfront_info *info)
    2.17 +{
    2.18 +	;
    2.19 +}
    2.20 +#endif
    2.21 +
    2.22  #endif /* __XEN_DRIVERS_BLOCK_H__ */
     3.1 --- a/drivers/xen/blkfront/vbd.c	Tue Jul 29 13:26:15 2008 +0100
     3.2 +++ b/drivers/xen/blkfront/vbd.c	Tue Jul 29 16:16:31 2008 +0100
     3.3 @@ -413,3 +413,48 @@ xlvbd_barrier(struct blkfront_info *info
     3.4  	return -ENOSYS;
     3.5  }
     3.6  #endif
     3.7 +
     3.8 +#ifdef CONFIG_SYSFS
     3.9 +static ssize_t show_media(struct device *dev,
    3.10 +		                  struct device_attribute *attr, char *buf)
    3.11 +{
    3.12 +	struct xenbus_device *xendev = to_xenbus_device(dev);
    3.13 +	struct blkfront_info *info = xendev->dev.driver_data;
    3.14 +
    3.15 +	if (info->gd->flags & GENHD_FL_CD)
    3.16 +		return sprintf(buf, "cdrom\n");
    3.17 +	return sprintf(buf, "disk\n");
    3.18 +}
    3.19 +
    3.20 +static struct device_attribute xlvbd_attrs[] = {
    3.21 +	__ATTR(media, S_IRUGO, show_media, NULL),
    3.22 +};
    3.23 +
    3.24 +int xlvbd_sysfs_addif(struct blkfront_info *info)
    3.25 +{
    3.26 +	int i;
    3.27 +	int error = 0;
    3.28 +
    3.29 +	for (i = 0; i < ARRAY_SIZE(xlvbd_attrs); i++) {
    3.30 +		error = device_create_file(info->gd->driverfs_dev,
    3.31 +				&xlvbd_attrs[i]);
    3.32 +		if (error)
    3.33 +			goto fail;
    3.34 +	}
    3.35 +	return 0;
    3.36 +
    3.37 +fail:
    3.38 +	while (--i >= 0)
    3.39 +		device_remove_file(info->gd->driverfs_dev, &xlvbd_attrs[i]);
    3.40 +	return error;
    3.41 +}
    3.42 +
    3.43 +void xlvbd_sysfs_delif(struct blkfront_info *info)
    3.44 +{
    3.45 +	int i;
    3.46 +
    3.47 +	for (i = 0; i < ARRAY_SIZE(xlvbd_attrs); i++)
    3.48 +		device_remove_file(info->gd->driverfs_dev, &xlvbd_attrs[i]);
    3.49 +}
    3.50 +
    3.51 +#endif /* CONFIG_SYSFS */