qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: john cooper <john.cooper@redhat.com>
Cc: rusty@rustcorp.com.au, qemu-devel@nongnu.org,
	KVM list <kvm@vger.kernel.org>
Subject: Re: [Qemu-devel] [PATCH 2/2] Add serial number support for virtio_blk, V3
Date: Wed, 27 May 2009 09:49:19 +0200	[thread overview]
Message-ID: <20090527074919.GB7356@lst.de> (raw)
In-Reply-To: <4A1C88DE.6050608@redhat.com>

You should probably include rusty as he's collecting the patches
for the virtio guest drivers.

Also can you send the patch inline next time? That makes quoting it for
review a lot easier.


 drivers/block/virtio_blk.c |   32 +++++++++++++++++++++++++++++---
 include/linux/virtio_blk.h |    6 ++++++
 2 files changed, 35 insertions(+), 3 deletions(-)
=================================================================
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -146,12 +146,37 @@ static void do_virtblk_request(struct re
 		vblk->vq->vq_ops->kick(vblk->vq);
 }
 
+/* return serial# in IDE identify data (all other fields are currently zero)
+ */
+static int virtblk_identity(struct block_device *bdev, void *buf)
+{
+	struct virtio_blk *vblk = bdev->bd_disk->private_data;
+	u16 *id;
+	int rv;
+
+	if (!(id = kzalloc(ATA_ID_WORDS, GFP_KERNEL)))
+		rv = -ENOMEM;
+	else if ((rv = virtio_config_buf(vblk->vdev, VIRTIO_BLK_F_SN,
+		offsetof(struct virtio_blk_config, serial), &id[ATA_ID_SERNO],
+		ATA_ID_SERNO_LEN)))
+			;
+	else if (copy_to_user(buf, id, ATA_ID_WORDS))
+		rv = -EFAULT;
+	else
+		rv = 0;
+	if (id)
+        	kfree(id);
+        return (rv);
+}
+
 static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
 			 unsigned cmd, unsigned long data)
 {
-	return scsi_cmd_ioctl(bdev->bd_disk->queue,
-			      bdev->bd_disk, mode, cmd,
-			      (void __user *)data);
+	if (cmd == HDIO_GET_IDENTITY)
+		return (virtblk_identity(bdev, (void __user *)data));
+	else
+		return scsi_cmd_ioctl(bdev->bd_disk->queue, bdev->bd_disk,
+			mode, cmd, (void __user *)data);
 }
 

This looks functionally correct, but pretty far from normal kernel coding
style.  I'd envision something like this instead:

/*
 * IDE-compatible identify ioctl.
 *
 * Currenlyt only returns the serial number and leaves all other fields
 * zero.
 */
static int virtblk_identity(struct gendisk *disk, void *argp)
{
	struct virtio_blk *vblk = disk->private_data;
	u16 *id;
	int error = -ENOMEM;

	id = kzalloc(ATA_ID_WORDS, GFP_KERNEL)
	if (!id)
		goto out;

	error = virtio_config_buf(vblk->vdev, VIRTIO_BLK_F_SN,
				  offsetof(struct virtio_blk_config, serial),
				  &id[ATA_ID_SERNO], ATA_ID_SERNO_LEN);
	if (error)
		goto out_kfree;

	if (copy_to_user(argp, id, ATA_ID_WORDS))
		error = -EFAULT;

out_kfree:
	kfree(id);
out:
	return error;
}


static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
			 unsigned cmd, unsigned long arg)
{
	struct gendisk *disk = bdev->bd_disk;
	void __user *argp = (void __user *arg);

	switch (cmd) {
	case HDIO_GET_IDENTITY:
		return virtblk_identity(disk, argp);
	default:
		return scsi_cmd_ioctl(disk->queue, disk, mode, cmd, argp);
	}
}
 

  reply	other threads:[~2009-05-27  7:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-27  0:27 [Qemu-devel] [PATCH 2/2] Add serial number support for virtio_blk, V3 john cooper
2009-05-27  7:49 ` Christoph Hellwig [this message]
2009-05-27  7:54   ` Christoph Hellwig
2009-05-29  4:04     ` john cooper
2009-05-27 12:53   ` Rusty Russell
2009-05-29  4:05     ` john cooper
2009-05-27 15:06   ` john cooper

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=20090527074919.GB7356@lst.de \
    --to=hch@lst.de \
    --cc=john.cooper@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    /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;
as well as URLs for NNTP newsgroup(s).