From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGnRW-0002qi-H3 for qemu-devel@nongnu.org; Wed, 26 Sep 2012 04:58:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TGnRU-0005Rw-Qi for qemu-devel@nongnu.org; Wed, 26 Sep 2012 04:58:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TGnRU-0005Rp-IC for qemu-devel@nongnu.org; Wed, 26 Sep 2012 04:58:04 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8Q8w30l005701 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 26 Sep 2012 04:58:03 -0400 Message-ID: <5062C2BD.5020700@redhat.com> Date: Wed, 26 Sep 2012 16:54:21 +0800 From: Dave Young MIME-Version: 1.0 References: <20120926081805.GA6799@dhcp-16-143.nay.redhat.com> In-Reply-To: <20120926081805.GA6799@dhcp-16-143.nay.redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH V3] virtio-blk: add default serial id List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: eblake@redhat.com Hi, Eric This is in fact same with v1 except the spelling fixes. I switched back to v1 because of your concern about the same id reusing issue. For v1, unplugging 100000 times is not likely and insane, so I think we can safely ignore it. Unless qemu-img create some uuid for disk imgs I think there's no way to create some really ideal *uniq* ids. On 09/26/2012 04:18 PM, Dave Young wrote: > For virtio block device, if user does not specify the serial attribute, > There will be no serial availabe, this is not convenient for identifying > the disk. > > Doing something similar to ide disks, add a "VD0000?" default serial > number if user does not specify it. > > Signed-off-by: Dave Young > --- > hw/virtio-blk.c | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > --- qemu-kvm.orig/hw/virtio-blk.c 2012-09-02 09:45:03.115696878 +0800 > +++ qemu-kvm/hw/virtio-blk.c 2012-09-20 20:57:56.177206991 +0800 > @@ -22,6 +22,7 @@ > # include > #endif > > +#define DEFAULT_VIRTIO_BLK_SERIAL_LEN 8 > typedef struct VirtIOBlock > { > VirtIODevice vdev; > @@ -33,6 +34,7 @@ typedef struct VirtIOBlock > VirtIOBlkConf *blk; > unsigned short sector_mask; > DeviceState *qdev; > + int drive_serial; > } VirtIOBlock; > > static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) > @@ -364,6 +366,7 @@ static void virtio_blk_handle_request(Vi > MultiReqBuffer *mrb) > { > uint32_t type; > + char serial[DEFAULT_VIRTIO_BLK_SERIAL_LEN]; > > if (req->elem.out_num < 1 || req->elem.in_num < 1) { > error_report("virtio-blk missing headers"); > @@ -388,12 +391,14 @@ static void virtio_blk_handle_request(Vi > } else if (type & VIRTIO_BLK_T_GET_ID) { > VirtIOBlock *s = req->dev; > > + snprintf(serial, DEFAULT_VIRTIO_BLK_SERIAL_LEN, > + "VD%05d", s->drive_serial); > /* > * NB: per existing s/n string convention the string is > * terminated by '\0' only when shorter than buffer. > */ > strncpy(req->elem.in_sg[0].iov_base, > - s->blk->serial ? s->blk->serial : "", > + s->blk->serial ? s->blk->serial : serial, > MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES)); > virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); > g_free(req); > @@ -611,6 +616,7 @@ static const BlockDevOps virtio_block_op > > VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk) > { > + static int drive_serial = 1; > VirtIOBlock *s; > static int virtio_blk_id; > > @@ -632,6 +638,7 @@ VirtIODevice *virtio_blk_init(DeviceStat > sizeof(struct virtio_blk_config), > sizeof(VirtIOBlock)); > > + s->drive_serial = drive_serial++; > s->vdev.get_config = virtio_blk_update_config; > s->vdev.set_config = virtio_blk_set_config; > s->vdev.get_features = virtio_blk_get_features; > > -- Thanks Dave