From patchwork Tue Jul 24 01:30:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 172771 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 19C702C0339 for ; Tue, 24 Jul 2012 11:33:43 +1000 (EST) Received: from localhost ([::1]:59030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StU0L-0003HN-4I for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2012 21:33:41 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StTzw-0002jB-Bf for qemu-devel@nongnu.org; Mon, 23 Jul 2012 21:33:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StTzu-0007ic-Tp for qemu-devel@nongnu.org; Mon, 23 Jul 2012 21:33:16 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:38331 helo=linux-iscsi.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StTzu-0007iW-D0 for qemu-devel@nongnu.org; Mon, 23 Jul 2012 21:33:14 -0400 Received: from linux-iscsi.org (localhost [127.0.0.1]) by linux-iscsi.org (Postfix) with ESMTP id 509C222D9DD; Tue, 24 Jul 2012 01:30:13 +0000 (UTC) From: "Nicholas A. Bellinger" To: target-devel Date: Tue, 24 Jul 2012 01:30:10 +0000 Message-Id: <1343093410-5843-3-git-send-email-nab@linux-iscsi.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1343093410-5843-1-git-send-email-nab@linux-iscsi.org> References: <1343093410-5843-1-git-send-email-nab@linux-iscsi.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 67.23.28.174 Cc: Jens Axboe , Stefan Hajnoczi , kvm-devel , "Michael S. Tsirkin" , qemu-devel , Nicholas Bellinger , Zhi Yong Wu , Anthony Liguori , Zhi Yong Wu , Hannes Reinecke , Paolo Bonzini , lf-virt , Christoph Hellwig Subject: [Qemu-devel] [PATCH 2/2] vhost-scsi: Add support for VHOST_SCSI_GET_ABI_VERSION ioctl 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: Nicholas Bellinger This patch adds support in vhost-scsi QEMU userspace code to check the running tcm_vhost ABI version using VHOST_SCSI_GET_ABI_VERSION. This series selects VHOST_SCSI_ABI_VERSION=1 for current code, and requires the pre-requsite tcm_vhost patch to expose an ABI version number. This patch patch will fail to initialize vhost_scsi_start() unless both vhost-scsi <-> tcm_vhost agree on VHOST_SCSI_ABI_VERSION=1. Reported-by: Anthony Liguori Cc: Stefan Hajnoczi Cc: Michael S. Tsirkin Cc: Paolo Bonzini Cc: Zhi Yong Wu Signed-off-by: Nicholas Bellinger --- hw/vhost-scsi.c | 17 +++++++++++++++++ hw/vhost-scsi.h | 11 +++++++++++ 2 files changed, 28 insertions(+), 0 deletions(-) diff --git a/hw/vhost-scsi.c b/hw/vhost-scsi.c index 3e9fa0e..9ab314c 100644 --- a/hw/vhost-scsi.c +++ b/hw/vhost-scsi.c @@ -68,6 +68,23 @@ int vhost_scsi_start(VHostSCSI *vs, VirtIODevice *vdev) return ret; } + memset(&backend, 0, sizeof(backend)); + ret = ioctl(vs->dev.control, VHOST_SCSI_GET_ABI_VERSION, &backend); + if (ret < 0) { + ret = -errno; + vhost_dev_stop(&vs->dev, vdev); + return ret; + } + if (backend.abi_version > VHOST_SCSI_ABI_VERSION) { + fprintf(stderr, "The running tcm_vhost kernel abi_version: %d is greater" + " than vhost_scsi userspace supports: %d\n", backend.abi_version, + VHOST_SCSI_ABI_VERSION); + ret = -ENOSYS; + vhost_dev_stop(&vs->dev, vdev); + return ret; + } + printf("Using TCM_Vhost ABI version: %d\n", backend.abi_version); + pstrcpy((char *)backend.vhost_wwpn, sizeof(backend.vhost_wwpn), vs->wwpn); backend.vhost_tpgt = vs->tpgt; ret = ioctl(vs->dev.control, VHOST_SCSI_SET_ENDPOINT, &backend); diff --git a/hw/vhost-scsi.h b/hw/vhost-scsi.h index 8ce974a..393fe39 100644 --- a/hw/vhost-scsi.h +++ b/hw/vhost-scsi.h @@ -17,9 +17,19 @@ #include "qemu-common.h" #include "qemu-option.h" +/* + * Used by QEMU userspace to ensure a consistent vhost-scsi ABI. + * + * ABI Rev 0: All pre 2012 revisions used by prototype out-of-tree code + * ABI Rev 1: 2012 version for v3.6 kernel merge candiate + */ + +#define VHOST_SCSI_ABI_VERSION 1 + /* TODO #include properly */ /* For VHOST_SCSI_SET_ENDPOINT/VHOST_SCSI_CLEAR_ENDPOINT ioctl */ struct vhost_scsi_target { + int abi_version; unsigned char vhost_wwpn[224]; unsigned short vhost_tpgt; }; @@ -27,6 +37,7 @@ struct vhost_scsi_target { #define VHOST_VIRTIO 0xAF #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target) #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target) +#define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, struct vhost_scsi_target) VHostSCSI *find_vhost_scsi(const char *id); const char *vhost_scsi_get_id(VHostSCSI *vs);