* [Qemu-devel] [PATCH 0/2] v2: Add 'serial' attribute to virtio-blk devices
@ 2010-06-24 3:19 Ryan Harper
2010-06-24 3:19 ` [Qemu-devel] [PATCH 1/2] v2 " Ryan Harper
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Ryan Harper @ 2010-06-24 3:19 UTC (permalink / raw)
To: virtualization; +Cc: john cooper, Rusty Russell, qemu-devel, kvm, Ryan Harper
Using Rusty's suggestion I've respun the patch removing the special copy
function. I've tested this patch in a guest kernel with and without qemu
supplying serial numbers for the block devices and it's working as expected.
When qemu supplies serial numbers, the correct value is supplied to
/sys/block/vdX/serial and can be used by udev for generating disk/by-id paths
(without separate utility). When running without serial number support the path
still exists in sysfs but produces no output.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/2] v2 Add 'serial' attribute to virtio-blk devices
2010-06-24 3:19 [Qemu-devel] [PATCH 0/2] v2: Add 'serial' attribute to virtio-blk devices Ryan Harper
@ 2010-06-24 3:19 ` Ryan Harper
2010-06-24 3:19 ` [Qemu-devel] [PATCH 2/2] Remove virtio_blk VBID ioctl Ryan Harper
2010-06-25 3:04 ` [Qemu-devel] Re: [PATCH 0/2] v2: Add 'serial' attribute to virtio-blk devices Rusty Russell
2 siblings, 0 replies; 5+ messages in thread
From: Ryan Harper @ 2010-06-24 3:19 UTC (permalink / raw)
To: virtualization; +Cc: john cooper, Rusty Russell, qemu-devel, kvm, Ryan Harper
Create a new attribute for virtio-blk devices that will fetch the serial number
of the block device. This attribute can be used by udev to create disk/by-id
symlinks for devices that don't have a UUID (filesystem) associated with them.
ATA_IDENTIFY strings are special in that they can be up to 20 chars long
and aren't required to be nul-terminated. The buffer is also zero-padded
meaning that if the serial is 19 chars or less that we get a nul-terminated
string. When copying this value into a string buffer, we must be careful to
copy up to the nul (if it present) and only 20 if it is longer and not to
attempt to nul terminate; this isn't needed.
Changes since v1:
- Added BUILD_BUG_ON() for PAGE_SIZE check
- Removed min() since BUILD_BUG_ON() handles the check
- Replaced serial_sysfs() by copying id directly to buffer
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: john cooper <john.cooper@redhat.com>
---
drivers/block/virtio_blk.c | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 258bc2a..34411ff 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -281,6 +281,27 @@ static int index_to_minor(int index)
return index << PART_BITS;
}
+static ssize_t virtblk_serial_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct gendisk *disk = dev_to_disk(dev);
+ int err;
+
+ /* sysfs gives us a PAGE_SIZE buffer */
+ BUILD_BUG_ON(PAGE_SIZE < VIRTIO_BLK_ID_BYTES);
+
+ buf[VIRTIO_BLK_ID_BYTES] = '\0';
+ err = virtblk_get_id(disk, buf);
+ if (!err)
+ return strlen(buf);
+
+ if (err == -EIO) /* Unsupported? Make it empty. */
+ return 0;
+
+ return err;
+}
+DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL);
+
static int __devinit virtblk_probe(struct virtio_device *vdev)
{
struct virtio_blk *vblk;
@@ -445,8 +466,15 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
add_disk(vblk->disk);
+ err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial);
+ if (err)
+ goto out_del_disk;
+
return 0;
+out_del_disk:
+ del_gendisk(vblk->disk);
+ blk_cleanup_queue(vblk->disk->queue);
out_put_disk:
put_disk(vblk->disk);
out_mempool:
--
1.6.3.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/2] Remove virtio_blk VBID ioctl
2010-06-24 3:19 [Qemu-devel] [PATCH 0/2] v2: Add 'serial' attribute to virtio-blk devices Ryan Harper
2010-06-24 3:19 ` [Qemu-devel] [PATCH 1/2] v2 " Ryan Harper
@ 2010-06-24 3:19 ` Ryan Harper
2010-06-25 3:04 ` [Qemu-devel] Re: [PATCH 0/2] v2: Add 'serial' attribute to virtio-blk devices Rusty Russell
2 siblings, 0 replies; 5+ messages in thread
From: Ryan Harper @ 2010-06-24 3:19 UTC (permalink / raw)
To: virtualization; +Cc: john cooper, Rusty Russell, qemu-devel, kvm, Ryan Harper
With the availablility of a sysfs device attribute for examining disk serial
numbers the ioctl is no longer needed. The user-space changes for this aren't
upstream yet so we don't have any users to worry about.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
---
drivers/block/virtio_blk.c | 10 ----------
1 files changed, 0 insertions(+), 10 deletions(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 34411ff..04458cd 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -225,16 +225,6 @@ static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
struct gendisk *disk = bdev->bd_disk;
struct virtio_blk *vblk = disk->private_data;
- if (cmd == 0x56424944) { /* 'VBID' */
- void __user *usr_data = (void __user *)data;
- char id_str[VIRTIO_BLK_ID_BYTES];
- int err;
-
- err = virtblk_get_id(disk, id_str);
- if (!err && copy_to_user(usr_data, id_str, VIRTIO_BLK_ID_BYTES))
- err = -EFAULT;
- return err;
- }
/*
* Only allow the generic SCSI ioctls if the host can support it.
*/
--
1.6.3.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] Re: [PATCH 0/2] v2: Add 'serial' attribute to virtio-blk devices
2010-06-24 3:19 [Qemu-devel] [PATCH 0/2] v2: Add 'serial' attribute to virtio-blk devices Ryan Harper
2010-06-24 3:19 ` [Qemu-devel] [PATCH 1/2] v2 " Ryan Harper
2010-06-24 3:19 ` [Qemu-devel] [PATCH 2/2] Remove virtio_blk VBID ioctl Ryan Harper
@ 2010-06-25 3:04 ` Rusty Russell
2 siblings, 0 replies; 5+ messages in thread
From: Rusty Russell @ 2010-06-25 3:04 UTC (permalink / raw)
To: Ryan Harper; +Cc: john cooper, qemu-devel, kvm, virtualization
On Thu, 24 Jun 2010 12:49:56 pm Ryan Harper wrote:
> Using Rusty's suggestion I've respun the patch removing the special copy
> function. I've tested this patch in a guest kernel with and without qemu
> supplying serial numbers for the block devices and it's working as expected.
> When qemu supplies serial numbers, the correct value is supplied to
> /sys/block/vdX/serial and can be used by udev for generating disk/by-id paths
> (without separate utility). When running without serial number support the path
> still exists in sysfs but produces no output.
>
> Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Great, both applied.
BTW, a mail without a patch doesn't need a sign off, does it?
Thanks,
Ruty.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/2] Add 'serial' attribute to virtio-blk devices
@ 2010-06-18 18:38 Ryan Harper
2010-06-18 18:38 ` [Qemu-devel] [PATCH 2/2] Remove virtio_blk VBID ioctl Ryan Harper
0 siblings, 1 reply; 5+ messages in thread
From: Ryan Harper @ 2010-06-18 18:38 UTC (permalink / raw)
To: virtualization; +Cc: john cooper, Rusty Russell, qemu-devel, kvm, Ryan Harper
Create a new attribute for virtio-blk devices that will fetch the serial number
of the block device. This attribute can be used by udev to create disk/by-id
symlinks for devices that don't have a UUID (filesystem) associated with them.
ATA_IDENTIFY strings are special in that they can be up to 20 chars long
and aren't required to be NULL-terminated. The buffer is also zero-padded
meaning that if the serial is 19 chars or less that we get a NULL terminated
string. When copying this value into a string buffer, we must be careful to
copy up to the NULL (if it present) and only 20 if it is longer and not to
attempt to NULL terminate; this isn't needed.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Signed-off-by: john cooper <john.cooper@redhat.com>
---
drivers/block/virtio_blk.c | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 258bc2a..f1ef26f 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -281,6 +281,31 @@ static int index_to_minor(int index)
return index << PART_BITS;
}
+/* Copy serial number from *s to *d. Copy operation terminates on either
+ * encountering a nul in *s or after n bytes have been copied, whichever
+ * occurs first. *d is not forcibly nul terminated. Return # of bytes copied.
+ */
+static inline int serial_sysfs(char *d, char *s, int n)
+{
+ char *di = d;
+
+ while (*s && n--)
+ *d++ = *s++;
+ return d - di;
+}
+
+static ssize_t virtblk_serial_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct gendisk *disk = dev_to_disk(dev);
+ char id_str[VIRTIO_BLK_ID_BYTES];
+
+ if (IS_ERR(virtblk_get_id(disk, id_str)))
+ return 0;
+ return serial_sysfs(buf, id_str, min(VIRTIO_BLK_ID_BYTES, PAGE_SIZE));
+}
+DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL);
+
static int __devinit virtblk_probe(struct virtio_device *vdev)
{
struct virtio_blk *vblk;
@@ -445,8 +470,15 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
add_disk(vblk->disk);
+ err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial);
+ if (err)
+ goto out_del_disk;
+
return 0;
+out_del_disk:
+ del_gendisk(vblk->disk);
+ blk_cleanup_queue(vblk->disk->queue);
out_put_disk:
put_disk(vblk->disk);
out_mempool:
--
1.6.3.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/2] Remove virtio_blk VBID ioctl
2010-06-18 18:38 [Qemu-devel] [PATCH 1/2] " Ryan Harper
@ 2010-06-18 18:38 ` Ryan Harper
0 siblings, 0 replies; 5+ messages in thread
From: Ryan Harper @ 2010-06-18 18:38 UTC (permalink / raw)
To: virtualization; +Cc: Rusty Russell, qemu-devel, kvm, Ryan Harper
With the availablility of a sysfs device attribute for examining disk serial
numbers the ioctl is no longer needed. The user-space changes for this aren't
upstream yet so we don't have any users to worry about.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
---
drivers/block/virtio_blk.c | 10 ----------
1 files changed, 0 insertions(+), 10 deletions(-)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index f1ef26f..9e382dd 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -225,16 +225,6 @@ static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
struct gendisk *disk = bdev->bd_disk;
struct virtio_blk *vblk = disk->private_data;
- if (cmd == 0x56424944) { /* 'VBID' */
- void __user *usr_data = (void __user *)data;
- char id_str[VIRTIO_BLK_ID_BYTES];
- int err;
-
- err = virtblk_get_id(disk, id_str);
- if (!err && copy_to_user(usr_data, id_str, VIRTIO_BLK_ID_BYTES))
- err = -EFAULT;
- return err;
- }
/*
* Only allow the generic SCSI ioctls if the host can support it.
*/
--
1.6.3.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-06-25 3:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-24 3:19 [Qemu-devel] [PATCH 0/2] v2: Add 'serial' attribute to virtio-blk devices Ryan Harper
2010-06-24 3:19 ` [Qemu-devel] [PATCH 1/2] v2 " Ryan Harper
2010-06-24 3:19 ` [Qemu-devel] [PATCH 2/2] Remove virtio_blk VBID ioctl Ryan Harper
2010-06-25 3:04 ` [Qemu-devel] Re: [PATCH 0/2] v2: Add 'serial' attribute to virtio-blk devices Rusty Russell
-- strict thread matches above, loose matches on Subject: below --
2010-06-18 18:38 [Qemu-devel] [PATCH 1/2] " Ryan Harper
2010-06-18 18:38 ` [Qemu-devel] [PATCH 2/2] Remove virtio_blk VBID ioctl Ryan Harper
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).