From patchwork Thu Jun 3 08:22:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john cooper X-Patchwork-Id: 54461 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 4E7CEB7D48 for ; Thu, 3 Jun 2010 18:37:25 +1000 (EST) Received: from localhost ([127.0.0.1]:47040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OK5vW-0001Re-J2 for incoming@patchwork.ozlabs.org; Thu, 03 Jun 2010 04:37:22 -0400 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 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o538aY2c026963 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 3 Jun 2010 04:36:34 -0400 Received: from anvil.naka.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o538aPhk021141; Thu, 3 Jun 2010 04:36:28 -0400 Message-ID: <4C076651.70507@redhat.com> Date: Thu, 03 Jun 2010 04:22:41 -0400 From: john cooper User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: Ryan Harper , Rusty Russell 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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: john.cooper@redhat.com, Anthony Liguori , Marc Haber , qemu-devel@nongnu.org X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@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.