From patchwork Fri Sep 21 13:30:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Young X-Patchwork-Id: 185731 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8391D2C0086 for ; Fri, 21 Sep 2012 23:30:53 +1000 (EST) Received: from localhost ([::1]:45870 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF3Jj-0006c6-3q for incoming@patchwork.ozlabs.org; Fri, 21 Sep 2012 09:30:51 -0400 Received: from eggs.gnu.org ([208.118.235.92]:46388) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF3JW-0006bu-NJ for qemu-devel@nongnu.org; Fri, 21 Sep 2012 09:30:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TF3JS-0002V5-CJ for qemu-devel@nongnu.org; Fri, 21 Sep 2012 09:30:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64227) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF3JS-0002V1-3W for qemu-devel@nongnu.org; Fri, 21 Sep 2012 09:30:34 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8LDUWk4024494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Sep 2012 09:30:32 -0400 Received: from darkstar.nay.redhat.com (vpn-224-56.phx2.redhat.com [10.3.224.56]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8LDUQin010281 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 21 Sep 2012 09:30:30 -0400 Date: Fri, 21 Sep 2012 21:30:31 +0800 From: Dave Young To: qemu-devel@nongnu.org Message-ID: <20120921133031.GA1682@darkstar.nay.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: dyoung@redhat.com, eblake@redhat.com Subject: [Qemu-devel] [PATCH v2] virtio-blk: add default serial id X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. [v1->v2 address comments from Eric Blake]: fix spell errors in patch description decrease drive_serial in virtio_blk_exit as well Signed-off-by: Dave Young --- hw/virtio-blk.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- qemu.orig/hw/virtio-blk.c +++ qemu/hw/virtio-blk.c @@ -22,6 +22,8 @@ # include #endif +static int drive_serial = 1; +#define DEFAULT_VIRTIO_BLK_SERIAL_LEN 8 typedef struct VirtIOBlock { VirtIODevice vdev; @@ -33,6 +35,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 +367,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 +392,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); @@ -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; @@ -664,4 +671,5 @@ void virtio_blk_exit(VirtIODevice *vdev) unregister_savevm(s->qdev, "virtio-blk", s); blockdev_mark_auto_del(s->bs); virtio_cleanup(vdev); + drive_serial--; }