From: Rusty Russell <rusty@rustcorp.com.au>
To: Ryan Harper <ryanh@us.ibm.com>
Cc: virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, kvm-devel@lists.sourceforge.net,
Anthony Liguori <aliguori@us.ibm.com>
Subject: Re: [PATCH] add virtio disk geometry feature
Date: Thu, 17 Apr 2008 07:15:54 +1000 [thread overview]
Message-ID: <200804170715.55041.rusty@rustcorp.com.au> (raw)
In-Reply-To: <1208372197-20815-1-git-send-email-ryanh@us.ibm.com>
On Thursday 17 April 2008 04:56:37 Ryan Harper wrote:
> From: Ryan Harper <ryanh@us.ibm.com>
>
> Rather than faking up some geometry, allow the backend to push the disk
> geometry via virtio pci config option. Keep the old geo code around for
> compatibility.
Hi Ryan,
Looks good! Some brief review below. Mainly just "how I would have done
things" stuff. BTW, does this help in real life? I assume something in
userspace wants it?
> + int err = 0;
> +
> + /* see if the host passed in geometry config */
> + err = virtio_config_val(vblk->vdev, VIRTIO_BLK_F_GEOMETRY,
> + offsetof(struct virtio_blk_config, cylinders),
> + &geo->cylinders);
Unnecessary err initialization. Sometimes gcc catches bugs when you defer
initializations of err to as late as possible (ie. paths where err isn't
set properly), so I tend to do it.
> + /* if host sets geo flag, all 3 values must be present */
> + if (!err) {
> + __virtio_config_val(vblk->vdev,
> + offsetof(struct virtio_blk_config, heads),
> + &geo->heads);
> + __virtio_config_val(vblk->vdev,
> + offsetof(struct virtio_blk_config, sectors),
> + &geo->sectors);
Kind of ugly; we can represent this in the data structure explicitly tho...
> @@ -18,6 +19,12 @@ struct virtio_blk_config
> __le32 size_max;
> /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
> __le32 seg_max;
> + /* cylinders of the device (if VIRTIO_BLK_F_GEOMETRY) */
> + __le16 cylinders;
> + /* heads of the device (if VIRTIO_BLK_F_GEOMETRY) */
> + __u8 heads;
> + /* sectors of the device (if VIRTIO_BLK_F_GEOMETRY) */
> + __u8 sectors;
> } __attribute__((packed));
... using a struct-within-a-struct.
Here's the result:
Subject: add virtio disk geometry feature
Date: Wed, 16 Apr 2008 13:56:37 -0500
From: Ryan Harper <ryanh@us.ibm.com>
Rather than faking up some geometry, allow the backend to push the disk
geometry via virtio pci config option. Keep the old geo code around for
compatibility.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (modified to single struct)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -157,10 +157,25 @@ static int virtblk_ioctl(struct inode *i
/* We provide getgeo only to please some old bootloader/partitioning tools */
static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
{
- /* some standard values, similar to sd */
- geo->heads = 1 << 6;
- geo->sectors = 1 << 5;
- geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+ struct virtio_blk *vblk = bd->bd_disk->private_data;
+ struct virtio_blk_geometry vgeo;
+ int err;
+
+ /* see if the host passed in geometry config */
+ err = virtio_config_val(vblk->vdev, VIRTIO_BLK_F_GEOMETRY,
+ offsetof(struct virtio_blk_config, geometry),
+ &vgeo);
+
+ if (!err) {
+ geo->heads = vgeo.heads;
+ geo->sectors = vgeo.sectors;
+ geo->cylinders = vgeo.cylinders;
+ } else {
+ /* some standard values, similar to sd */
+ geo->heads = 1 << 6;
+ geo->sectors = 1 << 5;
+ geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+ }
return 0;
}
diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h
--- a/include/linux/virtio_blk.h
+++ b/include/linux/virtio_blk.h
@@ -9,6 +9,7 @@
#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
+#define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
struct virtio_blk_config
{
@@ -18,6 +19,12 @@ struct virtio_blk_config
__le32 size_max;
/* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
__le32 seg_max;
+ /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
+ struct virtio_blk_geometry {
+ __le16 cylinders;
+ __u8 heads;
+ __u8 sectors;
+ } geometry;
} __attribute__((packed));
/* These two define direction. */
WARNING: multiple messages have this Message-ID (diff)
From: Rusty Russell <rusty@rustcorp.com.au>
To: Ryan Harper <ryanh@us.ibm.com>
Cc: kvm-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org
Subject: Re: [PATCH] add virtio disk geometry feature
Date: Thu, 17 Apr 2008 07:15:54 +1000 [thread overview]
Message-ID: <200804170715.55041.rusty@rustcorp.com.au> (raw)
In-Reply-To: <1208372197-20815-1-git-send-email-ryanh@us.ibm.com>
On Thursday 17 April 2008 04:56:37 Ryan Harper wrote:
> From: Ryan Harper <ryanh@us.ibm.com>
>
> Rather than faking up some geometry, allow the backend to push the disk
> geometry via virtio pci config option. Keep the old geo code around for
> compatibility.
Hi Ryan,
Looks good! Some brief review below. Mainly just "how I would have done
things" stuff. BTW, does this help in real life? I assume something in
userspace wants it?
> + int err = 0;
> +
> + /* see if the host passed in geometry config */
> + err = virtio_config_val(vblk->vdev, VIRTIO_BLK_F_GEOMETRY,
> + offsetof(struct virtio_blk_config, cylinders),
> + &geo->cylinders);
Unnecessary err initialization. Sometimes gcc catches bugs when you defer
initializations of err to as late as possible (ie. paths where err isn't
set properly), so I tend to do it.
> + /* if host sets geo flag, all 3 values must be present */
> + if (!err) {
> + __virtio_config_val(vblk->vdev,
> + offsetof(struct virtio_blk_config, heads),
> + &geo->heads);
> + __virtio_config_val(vblk->vdev,
> + offsetof(struct virtio_blk_config, sectors),
> + &geo->sectors);
Kind of ugly; we can represent this in the data structure explicitly tho...
> @@ -18,6 +19,12 @@ struct virtio_blk_config
> __le32 size_max;
> /* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
> __le32 seg_max;
> + /* cylinders of the device (if VIRTIO_BLK_F_GEOMETRY) */
> + __le16 cylinders;
> + /* heads of the device (if VIRTIO_BLK_F_GEOMETRY) */
> + __u8 heads;
> + /* sectors of the device (if VIRTIO_BLK_F_GEOMETRY) */
> + __u8 sectors;
> } __attribute__((packed));
... using a struct-within-a-struct.
Here's the result:
Subject: add virtio disk geometry feature
Date: Wed, 16 Apr 2008 13:56:37 -0500
From: Ryan Harper <ryanh@us.ibm.com>
Rather than faking up some geometry, allow the backend to push the disk
geometry via virtio pci config option. Keep the old geo code around for
compatibility.
Signed-off-by: Ryan Harper <ryanh@us.ibm.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (modified to single struct)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -157,10 +157,25 @@ static int virtblk_ioctl(struct inode *i
/* We provide getgeo only to please some old bootloader/partitioning tools */
static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
{
- /* some standard values, similar to sd */
- geo->heads = 1 << 6;
- geo->sectors = 1 << 5;
- geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+ struct virtio_blk *vblk = bd->bd_disk->private_data;
+ struct virtio_blk_geometry vgeo;
+ int err;
+
+ /* see if the host passed in geometry config */
+ err = virtio_config_val(vblk->vdev, VIRTIO_BLK_F_GEOMETRY,
+ offsetof(struct virtio_blk_config, geometry),
+ &vgeo);
+
+ if (!err) {
+ geo->heads = vgeo.heads;
+ geo->sectors = vgeo.sectors;
+ geo->cylinders = vgeo.cylinders;
+ } else {
+ /* some standard values, similar to sd */
+ geo->heads = 1 << 6;
+ geo->sectors = 1 << 5;
+ geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+ }
return 0;
}
diff --git a/include/linux/virtio_blk.h b/include/linux/virtio_blk.h
--- a/include/linux/virtio_blk.h
+++ b/include/linux/virtio_blk.h
@@ -9,6 +9,7 @@
#define VIRTIO_BLK_F_BARRIER 0 /* Does host support barriers? */
#define VIRTIO_BLK_F_SIZE_MAX 1 /* Indicates maximum segment size */
#define VIRTIO_BLK_F_SEG_MAX 2 /* Indicates maximum # of segments */
+#define VIRTIO_BLK_F_GEOMETRY 4 /* Legacy geometry available */
struct virtio_blk_config
{
@@ -18,6 +19,12 @@ struct virtio_blk_config
__le32 size_max;
/* The maximum number of segments (if VIRTIO_BLK_F_SEG_MAX) */
__le32 seg_max;
+ /* geometry the device (if VIRTIO_BLK_F_GEOMETRY) */
+ struct virtio_blk_geometry {
+ __le16 cylinders;
+ __u8 heads;
+ __u8 sectors;
+ } geometry;
} __attribute__((packed));
/* These two define direction. */
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
next prev parent reply other threads:[~2008-04-16 21:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-16 18:56 [PATCH] add virtio disk geometry feature Ryan Harper
2008-04-16 18:56 ` Ryan Harper
2008-04-16 21:15 ` Rusty Russell
2008-04-16 21:15 ` Rusty Russell [this message]
2008-04-16 21:15 ` Rusty Russell
2008-04-16 21:32 ` Anthony Liguori
2008-04-16 21:32 ` Anthony Liguori
2008-04-16 21:57 ` Hollis Blanchard
2008-04-16 21:57 ` Hollis Blanchard
2008-04-16 21:57 ` Hollis Blanchard
2008-04-17 14:37 ` Ryan Harper
2008-04-17 14:37 ` Ryan Harper
2008-04-16 21:32 ` Anthony Liguori
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=200804170715.55041.rusty@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=aliguori@us.ibm.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=ryanh@us.ibm.com \
--cc=virtualization@lists.linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.