From b1d75fe53ef20b90bb64b1e48b905416f0dfde23 Mon Sep 17 00:00:00 2001 From: Nicholas Bellinger Date: Sat, 28 Mar 2015 00:03:51 -0700 Subject: vhost/scsi: Add fabric_prot_type attribute support This patch updates vhost-scsi to add a new fabric_prot_type TPG attribute, used for controlling LLD level protection into LIO when the backend device does not support T10-PI. This is required for vhost-scsi to enable WRITE_STRIP + READ_INSERT operations using software emulation + crct10dif instruction offload. It's disabled by default and controls which se_sesion->sess_prot_type are set at vhost_scsi_make_nexus() session registration time. Cc: Michael S. Tsirkin Cc: Martin Petersen Cc: Sagi Grimberg Signed-off-by: Nicholas Bellinger --- drivers/vhost/scsi.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'drivers/vhost/scsi.c') diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 8d4f3f1ff799..27ed9642cc21 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -131,6 +131,8 @@ struct vhost_scsi_tpg { int tv_tpg_port_count; /* Used for vhost_scsi device reference to tpg_nexus, protected by tv_tpg_mutex */ int tv_tpg_vhost_count; + /* Used for enabling T10-PI with legacy devices */ + int tv_fabric_prot_type; /* list for vhost_scsi_list */ struct list_head tv_tpg_list; /* Used to protect access for tpg_nexus */ @@ -431,6 +433,14 @@ vhost_scsi_parse_pr_out_transport_id(struct se_portal_group *se_tpg, port_nexus_ptr); } +static int vhost_scsi_check_prot_fabric_only(struct se_portal_group *se_tpg) +{ + struct vhost_scsi_tpg *tpg = container_of(se_tpg, + struct vhost_scsi_tpg, se_tpg); + + return tpg->tv_fabric_prot_type; +} + static struct se_node_acl * vhost_scsi_alloc_fabric_acl(struct se_portal_group *se_tpg) { @@ -1878,6 +1888,45 @@ static void vhost_scsi_free_cmd_map_res(struct vhost_scsi_nexus *nexus, } } +static ssize_t vhost_scsi_tpg_attrib_store_fabric_prot_type( + struct se_portal_group *se_tpg, + const char *page, + size_t count) +{ + struct vhost_scsi_tpg *tpg = container_of(se_tpg, + struct vhost_scsi_tpg, se_tpg); + unsigned long val; + int ret = kstrtoul(page, 0, &val); + + if (ret) { + pr_err("kstrtoul() returned %d for fabric_prot_type\n", ret); + return ret; + } + if (val != 0 && val != 1 && val != 3) { + pr_err("Invalid vhost_scsi fabric_prot_type: %lu\n", val); + return -EINVAL; + } + tpg->tv_fabric_prot_type = val; + + return count; +} + +static ssize_t vhost_scsi_tpg_attrib_show_fabric_prot_type( + struct se_portal_group *se_tpg, + char *page) +{ + struct vhost_scsi_tpg *tpg = container_of(se_tpg, + struct vhost_scsi_tpg, se_tpg); + + return sprintf(page, "%d\n", tpg->tv_fabric_prot_type); +} +TF_TPG_ATTRIB_ATTR(vhost_scsi, fabric_prot_type, S_IRUGO | S_IWUSR); + +static struct configfs_attribute *vhost_scsi_tpg_attrib_attrs[] = { + &vhost_scsi_tpg_attrib_fabric_prot_type.attr, + NULL, +}; + static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg, const char *name) { @@ -2290,6 +2339,7 @@ static struct target_core_fabric_ops vhost_scsi_ops = { .tpg_check_demo_mode_cache = vhost_scsi_check_true, .tpg_check_demo_mode_write_protect = vhost_scsi_check_false, .tpg_check_prod_mode_write_protect = vhost_scsi_check_false, + .tpg_check_prot_fabric_only = vhost_scsi_check_prot_fabric_only, .tpg_alloc_fabric_acl = vhost_scsi_alloc_fabric_acl, .tpg_release_fabric_acl = vhost_scsi_release_fabric_acl, .tpg_get_inst_index = vhost_scsi_tpg_get_inst_index, @@ -2348,7 +2398,7 @@ static int vhost_scsi_register_configfs(void) */ fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = vhost_scsi_wwn_attrs; fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = vhost_scsi_tpg_attrs; - fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL; + fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = vhost_scsi_tpg_attrib_attrs; fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL; -- cgit From 9ac8928e6a3e1ed02e632e45aa766129fe6b1802 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 8 Apr 2015 20:01:35 +0200 Subject: target: simplify the target template registration API Instead of calling target_fabric_configfs_init() + target_fabric_configfs_register() / target_fabric_configfs_deregister() target_fabric_configfs_free() from every target driver, rewrite the API so that we have simple register/unregister functions that operate on a const operations vector. This patch also fixes a memory leak in several target drivers. Several target drivers namely called target_fabric_configfs_deregister() without calling target_fabric_configfs_free(). A large part of this patch is based on earlier changes from Bart Van Assche . (v2: Add a new TF_CIT_SETUP_DRV macro so that the core configfs code can declare attributes as either core only or for drivers) Signed-off-by: Christoph Hellwig Signed-off-by: Nicholas Bellinger --- drivers/vhost/scsi.c | 76 +++++++++------------------------------------------- 1 file changed, 13 insertions(+), 63 deletions(-) (limited to 'drivers/vhost/scsi.c') diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c index 27ed9642cc21..e8c88b453f79 100644 --- a/drivers/vhost/scsi.c +++ b/drivers/vhost/scsi.c @@ -216,9 +216,7 @@ struct vhost_scsi { int vs_events_nr; /* num of pending events, protected by vq->mutex */ }; -/* Local pointer to allocated TCM configfs fabric module */ -static struct target_fabric_configfs *vhost_scsi_fabric_configfs; - +static struct target_core_fabric_ops vhost_scsi_ops; static struct workqueue_struct *vhost_scsi_workqueue; /* Global spinlock to protect vhost_scsi TPG list for vhost IOCTL access */ @@ -2205,7 +2203,7 @@ vhost_scsi_make_tpg(struct se_wwn *wwn, tpg->tport = tport; tpg->tport_tpgt = tpgt; - ret = core_tpg_register(&vhost_scsi_fabric_configfs->tf_ops, wwn, + ret = core_tpg_register(&vhost_scsi_ops, wwn, &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); if (ret < 0) { kfree(tpg); @@ -2327,6 +2325,8 @@ static struct configfs_attribute *vhost_scsi_wwn_attrs[] = { }; static struct target_core_fabric_ops vhost_scsi_ops = { + .module = THIS_MODULE, + .name = "vhost", .get_fabric_name = vhost_scsi_get_fabric_name, .get_fabric_proto_ident = vhost_scsi_get_fabric_proto_ident, .tpg_get_wwn = vhost_scsi_get_fabric_wwn, @@ -2371,70 +2371,20 @@ static struct target_core_fabric_ops vhost_scsi_ops = { .fabric_drop_np = NULL, .fabric_make_nodeacl = vhost_scsi_make_nodeacl, .fabric_drop_nodeacl = vhost_scsi_drop_nodeacl, + + .tfc_wwn_attrs = vhost_scsi_wwn_attrs, + .tfc_tpg_base_attrs = vhost_scsi_tpg_attrs, + .tfc_tpg_attrib_attrs = vhost_scsi_tpg_attrib_attrs, }; -static int vhost_scsi_register_configfs(void) +static int __init vhost_scsi_init(void) { - struct target_fabric_configfs *fabric; - int ret; + int ret = -ENOMEM; - pr_debug("vhost-scsi fabric module %s on %s/%s" + pr_debug("TCM_VHOST fabric module %s on %s/%s" " on "UTS_RELEASE"\n", VHOST_SCSI_VERSION, utsname()->sysname, utsname()->machine); - /* - * Register the top level struct config_item_type with TCM core - */ - fabric = target_fabric_configfs_init(THIS_MODULE, "vhost"); - if (IS_ERR(fabric)) { - pr_err("target_fabric_configfs_init() failed\n"); - return PTR_ERR(fabric); - } - /* - * Setup fabric->tf_ops from our local vhost_scsi_ops - */ - fabric->tf_ops = vhost_scsi_ops; - /* - * Setup default attribute lists for various fabric->tf_cit_tmpl - */ - fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = vhost_scsi_wwn_attrs; - fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = vhost_scsi_tpg_attrs; - fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = vhost_scsi_tpg_attrib_attrs; - fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL; - fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL; - fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL; - fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL; - fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL; - fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL; - /* - * Register the fabric for use within TCM - */ - ret = target_fabric_configfs_register(fabric); - if (ret < 0) { - pr_err("target_fabric_configfs_register() failed" - " for TCM_VHOST\n"); - return ret; - } - /* - * Setup our local pointer to *fabric - */ - vhost_scsi_fabric_configfs = fabric; - pr_debug("TCM_VHOST[0] - Set fabric -> vhost_scsi_fabric_configfs\n"); - return 0; -}; - -static void vhost_scsi_deregister_configfs(void) -{ - if (!vhost_scsi_fabric_configfs) - return; - - target_fabric_configfs_deregister(vhost_scsi_fabric_configfs); - vhost_scsi_fabric_configfs = NULL; - pr_debug("TCM_VHOST[0] - Cleared vhost_scsi_fabric_configfs\n"); -}; -static int __init vhost_scsi_init(void) -{ - int ret = -ENOMEM; /* * Use our own dedicated workqueue for submitting I/O into * target core to avoid contention within system_wq. @@ -2447,7 +2397,7 @@ static int __init vhost_scsi_init(void) if (ret < 0) goto out_destroy_workqueue; - ret = vhost_scsi_register_configfs(); + ret = target_register_template(&vhost_scsi_ops); if (ret < 0) goto out_vhost_scsi_deregister; @@ -2463,7 +2413,7 @@ out: static void vhost_scsi_exit(void) { - vhost_scsi_deregister_configfs(); + target_unregister_template(&vhost_scsi_ops); vhost_scsi_deregister(); destroy_workqueue(vhost_scsi_workqueue); }; -- cgit