From patchwork Fri Jul 2 05:50:15 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: john cooper X-Patchwork-Id: 57632 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 056C81007D1 for ; Fri, 2 Jul 2010 16:16:54 +1000 (EST) Received: from localhost ([127.0.0.1]:52661 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OUZYR-0004Xh-3v for incoming@patchwork.ozlabs.org; Fri, 02 Jul 2010 02:16:51 -0400 Received: from [140.186.70.92] (port=40210 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OUZWE-0003Ci-7C for qemu-devel@nongnu.org; Fri, 02 Jul 2010 02:14:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OUZWD-0006W6-28 for qemu-devel@nongnu.org; Fri, 02 Jul 2010 02:14:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:24255) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OUZWC-0006Vs-Oj for qemu-devel@nongnu.org; Fri, 02 Jul 2010 02:14:33 -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 o626ESuX030984 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 2 Jul 2010 02:14:28 -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 o626EJLW010995; Fri, 2 Jul 2010 02:14:22 -0400 Message-ID: <4C2D7E17.10105@redhat.com> Date: Fri, 02 Jul 2010 01:50:15 -0400 From: john cooper User-Agent: Thunderbird 2.0.0.9 (X11/20071115) MIME-Version: 1.0 To: qemu-devel@nongnu.org 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, Rusty Russell , Ryan Harper , Marc Haber Subject: [Qemu-devel] [PATCH 0/4] Add virtio disk identification support 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 This patch adds the final missing bits for support of passing a serial/id string to a virtio-blk guest driver. The guest-side component already exists in the virtio driver, and has recently been reworked by Ryan to export a /sys interface for retrival of the id from guest userland. Signed-off-by: john cooper diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c index 0bf929a..bd6b896 100644 --- a/hw/virtio-blk.c +++ b/hw/virtio-blk.c @@ -26,6 +26,7 @@ typedef struct VirtIOBlock QEMUBH *bh; BlockConf *conf; unsigned short sector_mask; + char sn[BLOCK_SERIAL_STRLEN]; } VirtIOBlock; static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev) @@ -324,6 +325,12 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req, virtio_blk_handle_flush(req, mrb); } else if (req->out->type & VIRTIO_BLK_T_SCSI_CMD) { virtio_blk_handle_scsi(req); + } else if (req->out->type & VIRTIO_BLK_T_GET_ID) { + VirtIOBlock *s = req->dev; + + memcpy(req->elem.in_sg[0].iov_base, s->sn, + MIN(req->elem.in_sg[0].iov_len, sizeof(s->sn))); + virtio_blk_req_complete(req, VIRTIO_BLK_S_OK); } else if (req->out->type & VIRTIO_BLK_T_OUT) { qemu_iovec_init_external(&req->qiov, &req->elem.out_sg[1], req->elem.out_num - 1); @@ -495,6 +502,12 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf) s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1; bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs); + /* NB: per existing s/n string convention we really intend to hard-limit + * the copy length to sizeof (s->sn) even in the case we're left without + * a trailing '\0' + */ + strncpy(s->sn, drive_get_serial(s->bs), sizeof (s->sn)); + s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output); qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s); diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h index 7a7ece3..fff46da 100644 --- a/hw/virtio-blk.h +++ b/hw/virtio-blk.h @@ -59,6 +59,9 @@ struct virtio_blk_config /* Flush the volatile write cache */ #define VIRTIO_BLK_T_FLUSH 4 +/* return the device ID string */ +#define VIRTIO_BLK_T_GET_ID 8 + /* Barrier before this op. */ #define VIRTIO_BLK_T_BARRIER 0x80000000