static struct config_group *target_fabric_make_mappedlun( struct config_group *group, const char *name) { struct se_node_acl *se_nacl = container_of(group, struct se_node_acl, acl_group); struct se_portal_group *se_tpg = se_nacl->se_tpg; struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; struct se_lun_acl *lacl; struct config_item *acl_ci; char *buf; unsigned long mapped_lun; int ret = 0; acl_ci = &group->cg_item; if (!(acl_ci)) { printk(KERN_ERR "Unable to locatel acl_ci\n"); return NULL; } buf = kzalloc(strlen(name) + 1, GFP_KERNEL); if (!(buf)) { printk(KERN_ERR "Unable to allocate memory for name buf\n"); return ERR_PTR(-ENOMEM); } snprintf(buf, strlen(name) + 1, "%s", name); /* * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID. */ if (strstr(buf, "lun_") != buf) { printk(KERN_ERR "Unable to locate \"lun_\" from buf: %s" " name: %s\n", buf, name); ret = -EINVAL; goto out; } /* * Determine the Mapped LUN value. This is what the SCSI Initiator * Port will actually see. */ if (strict_strtoul(buf + 4, 0, &mapped_lun) || mapped_lun > UINT_MAX) { ret = -EINVAL; goto out; } lacl = core_dev_init_initiator_node_lun_acl(se_tpg, mapped_lun, config_item_name(acl_ci), &ret); if (!(lacl)) goto out; config_group_init_type_name(&lacl->se_lun_group, name, &TF_CIT_TMPL(tf)->tfc_tpg_mappedlun_cit); kfree(buf); return &lacl->se_lun_group; out: kfree(buf); return ERR_PTR(ret); }
static struct config_group *target_fabric_make_mappedlun( struct config_group *group, const char *name) { struct se_node_acl *se_nacl = container_of(group, struct se_node_acl, acl_group); struct se_portal_group *se_tpg = se_nacl->se_tpg; struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; struct se_lun_acl *lacl; struct config_item *acl_ci; struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL; char *buf; unsigned long mapped_lun; int ret = 0; acl_ci = &group->cg_item; if (!acl_ci) { pr_err("Unable to locatel acl_ci\n"); return NULL; } buf = kzalloc(strlen(name) + 1, GFP_KERNEL); if (!buf) { pr_err("Unable to allocate memory for name buf\n"); return ERR_PTR(-ENOMEM); } snprintf(buf, strlen(name) + 1, "%s", name); /* * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID. */ if (strstr(buf, "lun_") != buf) { pr_err("Unable to locate \"lun_\" from buf: %s" " name: %s\n", buf, name); ret = -EINVAL; goto out; } /* * Determine the Mapped LUN value. This is what the SCSI Initiator * Port will actually see. */ ret = kstrtoul(buf + 4, 0, &mapped_lun); if (ret) goto out; if (mapped_lun > UINT_MAX) { ret = -EINVAL; goto out; } if (mapped_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) { pr_err("Mapped LUN: %lu exceeds TRANSPORT_MAX_LUNS_PER_TPG" "-1: %u for Target Portal Group: %u\n", mapped_lun, TRANSPORT_MAX_LUNS_PER_TPG-1, se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg)); ret = -EINVAL; goto out; } lacl = core_dev_init_initiator_node_lun_acl(se_tpg, se_nacl, mapped_lun, &ret); if (!lacl) { ret = -EINVAL; goto out; } lacl_cg = &lacl->se_lun_group; lacl_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, GFP_KERNEL); if (!lacl_cg->default_groups) { pr_err("Unable to allocate lacl_cg->default_groups\n"); ret = -ENOMEM; goto out; } config_group_init_type_name(&lacl->se_lun_group, name, &TF_CIT_TMPL(tf)->tfc_tpg_mappedlun_cit); config_group_init_type_name(&lacl->ml_stat_grps.stat_group, "statistics", &TF_CIT_TMPL(tf)->tfc_tpg_mappedlun_stat_cit); lacl_cg->default_groups[0] = &lacl->ml_stat_grps.stat_group; lacl_cg->default_groups[1] = NULL; ml_stat_grp = &lacl->ml_stat_grps.stat_group; ml_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 3, GFP_KERNEL); if (!ml_stat_grp->default_groups) { pr_err("Unable to allocate ml_stat_grp->default_groups\n"); ret = -ENOMEM; goto out; } target_stat_setup_mappedlun_default_groups(lacl); kfree(buf); return &lacl->se_lun_group; out: if (lacl_cg) kfree(lacl_cg->default_groups); kfree(buf); return ERR_PTR(ret); }