From: Hollis Blanchard <hollisb@us.ibm.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>,
Ryan Harper <ryanh@us.ibm.com>,
virtualization@lists.linux-foundation.org,
linux-kernel@vger.kernel.org, kvm-devel@lists.sourceforge.net
Subject: Re: [PATCH] add virtio disk geometry feature
Date: Wed, 16 Apr 2008 16:57:24 -0500 [thread overview]
Message-ID: <200804161657.24454.hollisb@us.ibm.com> (raw)
In-Reply-To: <4806706E.10701@us.ibm.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 2566 bytes --]
On Wednesday 16 April 2008 16:32:30 Anthony Liguori wrote:> > 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;> > Â }> > Â > > You're probably breaking PPC since the values in the config space are in > little endian format. Â virtio_config_val does automagic endianness > conversion if the size is 2, 4, or 8. Â In this case, the structure size > is 4 so the endianness conversion will do the wrong thing.
Good catch; byte-swapping an entire structure is a terrible terrible idea.
> Magic endianness conversion based on read size is looking pretty evil to > me... Perhaps we need explicit *_val[8,16,32,64]?
Implicit byteswapping based on access size is the standard way of implementing accessors.
In this case, reading each structure member individually will do the right implicit swapping, rather than trying to load the whole thing as a single access.
-- Hollis BlanchardIBM Linux Technology Centerÿôèº{.nÇ+·®+%Ëÿ±éݶ\x17¥wÿº{.nÇ+·¥{±þG«éÿ{ayº\x1dÊÚë,j\a¢f£¢·hïêÿêçz_è®\x03(éÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?¨èÚ&£ø§~á¶iOæ¬z·vØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?I¥
next prev parent reply other threads:[~2008-04-16 21:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-16 18:56 Ryan Harper
2008-04-16 21:15 ` Rusty Russell
2008-04-16 21:32 ` Anthony Liguori
2008-04-16 21:57 ` Hollis Blanchard [this message]
2008-04-17 14:37 ` Ryan Harper
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=200804161657.24454.hollisb@us.ibm.com \
--to=hollisb@us.ibm.com \
--cc=aliguori@us.ibm.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®