From patchwork Thu Sep 20 13:02:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Young X-Patchwork-Id: 185390 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 59BBA2C0092 for ; Thu, 20 Sep 2012 23:03:13 +1000 (EST) Received: from localhost ([::1]:35045 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEgPM-0005JG-EQ for incoming@patchwork.ozlabs.org; Thu, 20 Sep 2012 09:03:08 -0400 Received: from eggs.gnu.org ([208.118.235.92]:54384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEgPA-0005JA-W9 for qemu-devel@nongnu.org; Thu, 20 Sep 2012 09:03:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TEgP1-0000m2-Cv for qemu-devel@nongnu.org; Thu, 20 Sep 2012 09:02:56 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:43149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEgP1-0000lw-6P for qemu-devel@nongnu.org; Thu, 20 Sep 2012 09:02:47 -0400 Received: by pbbrp12 with SMTP id rp12so5074418pbb.4 for ; Thu, 20 Sep 2012 06:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=IRO3BdSbiveuihz6zqeWsDaccqnriFohWPvQhGZpxB8=; b=q00H5hPLnW9GEG+CaucstEeYizQm5YE5WUKiCxs1UnE2nmWjmmxfNC48AHzmGNp84L tLB0OuPf1LuX9V8//8iLE74vvV4y3jhKUa69eoyR5e3qqYw+5yT18UCb6+ZspxOovAmC a0An6h0jZM9O3aY5q0FYRcEAodWXKP9VyiD3PwiXGKJ/axwzgVGHgUv1wN8AF/gRetD+ 3ssNHXSCRPiJ8e376LV7WbZhpRo7pyDZf+3tm/LJSN2H2cJVRMKi+JneoPq9BKMrOaqj 41VAzf7xh74oWLbyCLW3nWVjUbngEGNpy58gEHeprdySFIIlP+kQG8nMmbkfWpSqQiq1 E2+Q== Received: by 10.68.231.67 with SMTP id te3mr6526795pbc.134.1348146165585; Thu, 20 Sep 2012 06:02:45 -0700 (PDT) Received: from darkstar ([123.115.193.44]) by mx.google.com with ESMTPS id gf8sm3486550pbc.52.2012.09.20.06.02.42 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 20 Sep 2012 06:02:44 -0700 (PDT) Date: Thu, 20 Sep 2012 21:02:41 +0800 From: Dave Young To: qemu-devel@nongnu.org Message-ID: <20120920130241.GB2158@darkstar> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.45 Cc: dyoung@redhat.com Subject: [Qemu-devel] [PATCH] virtio-blk: add default value to serial attribute 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 From: Dave Young For virtio block device, if user does not specify the serial attribute, There will be not serial availabe, this is not convinient for identify 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;