From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=38910 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OK5uo-0001RY-Nc for qemu-devel@nongnu.org; Thu, 03 Jun 2010 04:36:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OK5un-00075A-DX for qemu-devel@nongnu.org; Thu, 03 Jun 2010 04:36:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3566) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OK5un-00074v-6c for qemu-devel@nongnu.org; Thu, 03 Jun 2010 04:36:37 -0400 Message-ID: <4C076651.70507@redhat.com> Date: Thu, 03 Jun 2010 04:22:41 -0400 From: john cooper MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 0/4] Add virtio disk identification support References: <4BAAF541.4090605@redhat.com> <20100602014652.GA16406@us.ibm.com> <4C05C846.7040306@redhat.com> In-Reply-To: <4C05C846.7040306@redhat.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Ryan Harper , Rusty Russell Cc: john.cooper@redhat.com, Anthony Liguori , Marc Haber , qemu-devel@nongnu.org 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 #include #include #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 --- 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