All of lore.kernel.org
 help / color / mirror / Atom feed
From: john cooper <john.cooper@redhat.com>
To: Ryan Harper <ryanh@us.ibm.com>, Rusty Russell <rusty@rustcorp.com.au>
Cc: john.cooper@redhat.com, Anthony Liguori <aliguori@us.ibm.com>,
	Marc Haber <mh+qemu-devel@zugschlus.de>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 0/4] Add virtio disk identification support
Date: Thu, 03 Jun 2010 04:22:41 -0400	[thread overview]
Message-ID: <4C076651.70507@redhat.com> (raw)
In-Reply-To: <4C05C846.7040306@redhat.com>

john cooper wrote:
> I'm all for putting this issue to rest, but if we're
> going to live with an ioctl interface retrieving the
> id string, let's make it a little more friendly from
> the user's perspective.

The qemu side of the patch is ok as-is.  The guest-user
interface issue is contained in the driver.  While I
see the example ioctl patch has been incorporated into
the virtio_blk driver, there can be no data retrieved
through this interface as virtblk_get_id() will fail
without the qemu counterpart.  So we can clean up the
details without concern of existing usage.

The only difference (as above) is allowing the caller
to pass a buffer size to the driver and the driver
informing the caller of the total number of bytes
available:

#include <stdio.h>
#include <strings.h>
#include <fcntl.h>

#define IOCTL_CMD       'VBID'
#define BUFSZ           10

main()
{
        int fd, rv;
        char buf[255];

        bzero(buf, sizeof (buf));
        buf[0] = BUFSZ;
        if ((fd = open("/dev/vda", O_RDONLY)) < 0)
                perror("open");
        else if ((rv = ioctl(fd, IOCTL_CMD, buf)) < 0)
                perror("ioctl");
        else
                printf("[%s] %d of %d bytes\n", buf,
                       BUFSZ < rv ? BUFSZ : rv, rv);
}


Signed-off-by: john cooper <john.cooper@redhat.com>
---

diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 83fa09a..6237732 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -225,15 +225,29 @@ static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
 	struct gendisk *disk = bdev->bd_disk;
 	struct virtio_blk *vblk = disk->private_data;
 
+	/* user passes the address of a char[] for return of the id string
+	 * and has set char[0] to the array size.  copy id string to this
+	 * char[] and return the number of non-nul characters in the internal
+	 * id string.  The caller can then determine if all were received.
+	 */
 	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;
+		unsigned char idlen;
+		int rv;
+
+		if (copy_from_user(&idlen, usr_data, sizeof (idlen)))
+			return -EFAULT;
+		if (VIRTIO_BLK_ID_BYTES < idlen)
+			idlen = VIRTIO_BLK_ID_BYTES;
+		if ((rv = virtblk_get_id(disk, id_str)))
+			return rv;
+		if (copy_to_user(usr_data, id_str, idlen))
+			return -EFAULT;
+		for (rv = 0; rv < VIRTIO_BLK_ID_BYTES; ++rv)
+			if (!id_str[rv])
+				break;
+		return rv;
 	}
 	/*
 	 * Only allow the generic SCSI ioctls if the host can support it.

-- 
john.cooper@redhat.com

  reply	other threads:[~2010-06-03  8:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-25  5:31 [Qemu-devel] [PATCH 0/4] Add virtio disk identification support john cooper
2010-05-28 13:16 ` Ryan Harper
2010-06-02  1:46 ` Ryan Harper
2010-06-02  2:56   ` john cooper
2010-06-03  8:22     ` john cooper [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-07-02  5:50 john cooper
2010-07-02  6:39 ` Markus Armbruster
2010-07-02  6:27   ` 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=4C076651.70507@redhat.com \
    --to=john.cooper@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=mh+qemu-devel@zugschlus.de \
    --cc=qemu-devel@nongnu.org \
    --cc=rusty@rustcorp.com.au \
    --cc=ryanh@us.ibm.com \
    /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.