From patchwork Mon Jan 26 13:13:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 5709371 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5A089C058D for ; Mon, 26 Jan 2015 13:13:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7AF03200FF for ; Mon, 26 Jan 2015 13:13:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8DB94200F2 for ; Mon, 26 Jan 2015 13:13:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752202AbbAZNNw (ORCPT ); Mon, 26 Jan 2015 08:13:52 -0500 Received: from szxga03-in.huawei.com ([119.145.14.66]:5646 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751208AbbAZNNv (ORCPT ); Mon, 26 Jan 2015 08:13:51 -0500 Received: from 172.24.2.119 (EHLO szxeml425-hub.china.huawei.com) ([172.24.2.119]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BAY54117; Mon, 26 Jan 2015 21:13:36 +0800 (CST) Received: from localhost (10.177.19.102) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.158.1; Mon, 26 Jan 2015 21:13:28 +0800 From: To: , , CC: , , , Gonglei , Bo Su Subject: [PATCH] vhost-scsi: introduce an ioctl to get the minimum tpgt Date: Mon, 26 Jan 2015 21:13:18 +0800 Message-ID: <1422277998-6308-1-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020206.54C63D81.00F2, ss=1, re=0.001, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 5aa82cfa457f5e5e39cb19621e5be940 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Gonglei In order to support to assign a boot order for vhost-scsi device, we should get the tpgt for user level (such as Qemu). and at present, we only support the minimum tpgt can boot. Signed-off-by: Gonglei Signed-off-by: Bo Su --- drivers/vhost/scsi.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vhost.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index d695b16..12e79b9 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -1522,6 +1522,38 @@ err_dev: return ret; } +static int vhost_scsi_get_first_tpgt( + struct vhost_scsi *vs, + struct vhost_scsi_target *t) +{ + struct tcm_vhost_tpg *tv_tpg; + struct tcm_vhost_tport *tv_tport; + int tpgt = -1; + + mutex_lock(&tcm_vhost_mutex); + mutex_lock(&vs->dev.mutex); + + list_for_each_entry(tv_tpg, &tcm_vhost_list, tv_tpg_list) { + tv_tport = tv_tpg->tport; + + if (!strcmp(tv_tport->tport_name, t->vhost_wwpn)) { + if (tpgt < 0) + tpgt = tv_tpg->tport_tpgt; + else if (tpgt > tv_tpg->tport_tpgt) + tpgt = tv_tpg->tport_tpgt; + } + } + + mutex_unlock(&vs->dev.mutex); + mutex_unlock(&tcm_vhost_mutex); + + if (tpgt < 0) + return -ENXIO; + + t->vhost_tpgt = tpgt; + return 0; +} + static int vhost_scsi_set_features(struct vhost_scsi *vs, u64 features) { struct vhost_virtqueue *vq; @@ -1657,6 +1689,15 @@ vhost_scsi_ioctl(struct file *f, if (put_user(events_missed, eventsp)) return -EFAULT; return 0; + case VHOST_SCSI_GET_TPGT: + if (copy_from_user(&backend, argp, sizeof(backend))) + return -EFAULT; + r = vhost_scsi_get_first_tpgt(vs, &backend); + if (r < 0) + return r; + if (copy_to_user(argp, &backend, sizeof(backend))) + return -EFAULT; + return 0; case VHOST_GET_FEATURES: features = VHOST_SCSI_FEATURES; if (copy_to_user(featurep, &features, sizeof features)) diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h index bb6a5b4..5d350f7 100644 --- a/include/uapi/linux/vhost.h +++ b/include/uapi/linux/vhost.h @@ -155,4 +155,6 @@ struct vhost_scsi_target { #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32) #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32) +#define VHOST_SCSI_GET_TPGT _IOW(VHOST_VIRTIO, 0x45, struct vhost_scsi_target) + #endif