24 #include <linux/module.h>
26 #include <generated/utsrelease.h>
27 #include <linux/utsname.h>
31 #include <linux/slab.h>
32 #include <linux/types.h>
35 #include <linux/string.h>
68 static inline struct se_hba *
81 return sprintf(page,
"Target Engine Core ConfigFS Infrastructure %s"
83 utsname()->sysname, utsname()->
machine);
87 .show_attribute = target_core_attr_show,
120 static struct config_group *target_core_register_fabric(
127 pr_debug(
"Target_Core_ConfigFS: REGISTER -> group: %p name:"
128 " %s\n", group, name);
139 if (!
strncmp(name,
"iscsi", 5)) {
146 ret = request_module(
"iscsi_target_mod");
148 pr_err(
"request_module() failed for"
149 " iscsi_target_mod.ko: %d\n", ret);
152 }
else if (!
strncmp(name,
"loopback", 8)) {
159 ret = request_module(
"tcm_loop");
161 pr_err(
"request_module() failed for"
162 " tcm_loop.ko: %d\n", ret);
167 tf = target_core_get_fabric(name);
169 pr_err(
"target_core_get_fabric() failed for %s\n",
173 pr_debug(
"Target_Core_ConfigFS: REGISTER -> Located fabric:"
179 pr_debug(
"Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
191 pr_debug(
"Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
192 " %s\n", tf->
tf_group.cg_item.ci_name);
198 pr_debug(
"Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
207 static void target_core_deregister_fabric(
217 pr_debug(
"Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
218 " tf list\n", config_item_name(item));
220 pr_debug(
"Target_Core_ConfigFS: DEREGISTER -> located fabric:"
224 pr_debug(
"Target_Core_ConfigFS: DEREGISTER -> Releasing"
225 " tf->tf_fabric for %s\n", tf->
tf_name);
228 pr_debug(
"Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
229 " %s\n", config_item_name(item));
241 .make_group = &target_core_register_fabric,
242 .drop_item = &target_core_deregister_fabric,
249 &target_core_item_attr_version,
257 .ct_item_ops = &target_core_fabric_item_ops,
258 .ct_group_ops = &target_core_fabric_group_ops,
259 .ct_attrs = target_core_fabric_item_attrs,
266 .ci_namebuf =
"target",
267 .ci_type = &target_core_fabrics_item,
273 &target_core_fabrics,
290 struct module *fabric_mod,
296 pr_err(
"Unable to locate passed fabric name\n");
300 pr_err(
"Passed name: %s exceeds TARGET_FABRIC"
301 "_NAME_SIZE\n", name);
318 tf->
tf_subsys = target_core_subsystem[0];
325 pr_debug(
"<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
327 pr_debug(
"Initialized struct target_fabric_configfs: %p for"
351 static int target_fabric_tf_ops_check(
357 pr_err(
"Missing tfo->get_fabric_name()\n");
361 pr_err(
"Missing tfo->get_fabric_proto_ident()\n");
365 pr_err(
"Missing tfo->tpg_get_wwn()\n");
369 pr_err(
"Missing tfo->tpg_get_tag()\n");
373 pr_err(
"Missing tfo->tpg_get_default_depth()\n");
377 pr_err(
"Missing tfo->tpg_get_pr_transport_id()\n");
381 pr_err(
"Missing tfo->tpg_get_pr_transport_id_len()\n");
385 pr_err(
"Missing tfo->tpg_check_demo_mode()\n");
389 pr_err(
"Missing tfo->tpg_check_demo_mode_cache()\n");
393 pr_err(
"Missing tfo->tpg_check_demo_mode_write_protect()\n");
397 pr_err(
"Missing tfo->tpg_check_prod_mode_write_protect()\n");
401 pr_err(
"Missing tfo->tpg_alloc_fabric_acl()\n");
405 pr_err(
"Missing tfo->tpg_release_fabric_acl()\n");
409 pr_err(
"Missing tfo->tpg_get_inst_index()\n");
413 pr_err(
"Missing tfo->release_cmd()\n");
417 pr_err(
"Missing tfo->shutdown_session()\n");
421 pr_err(
"Missing tfo->close_session()\n");
425 pr_err(
"Missing tfo->sess_get_index()\n");
429 pr_err(
"Missing tfo->write_pending()\n");
433 pr_err(
"Missing tfo->write_pending_status()\n");
437 pr_err(
"Missing tfo->set_default_node_attributes()\n");
441 pr_err(
"Missing tfo->get_task_tag()\n");
445 pr_err(
"Missing tfo->get_cmd_state()\n");
449 pr_err(
"Missing tfo->queue_data_in()\n");
453 pr_err(
"Missing tfo->queue_status()\n");
457 pr_err(
"Missing tfo->queue_tm_rsp()\n");
466 pr_err(
"Missing tfo->fabric_make_wwn()\n");
470 pr_err(
"Missing tfo->fabric_drop_wwn()\n");
474 pr_err(
"Missing tfo->fabric_make_tpg()\n");
478 pr_err(
"Missing tfo->fabric_drop_tpg()\n");
499 pr_err(
"Unable to locate target_fabric_configfs"
504 pr_err(
"Unable to target struct config_subsystem"
508 ret = target_fabric_tf_ops_check(tf);
512 pr_debug(
"<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
524 pr_err(
"Unable to locate passed target_fabric_"
530 pr_err(
"Unable to locate passed tf->tf_subsys"
534 pr_debug(
"<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
539 pr_err(
"Non zero tf->tf_access_cnt for fabric %s\n",
546 pr_debug(
"Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
552 pr_debug(
"<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
563 #define DEF_DEV_ATTRIB_SHOW(_name) \
564 static ssize_t target_core_dev_show_attr_##_name( \
565 struct se_dev_attrib *da, \
568 struct se_device *dev; \
569 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
572 spin_lock(&se_dev->se_dev_lock); \
573 dev = se_dev->se_dev_ptr; \
575 spin_unlock(&se_dev->se_dev_lock); \
578 rb = snprintf(page, PAGE_SIZE, "%u\n", \
579 (u32)dev->se_sub_dev->se_dev_attrib._name); \
580 spin_unlock(&se_dev->se_dev_lock); \
585 #define DEF_DEV_ATTRIB_STORE(_name) \
586 static ssize_t target_core_dev_store_attr_##_name( \
587 struct se_dev_attrib *da, \
591 struct se_device *dev; \
592 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
596 spin_lock(&se_dev->se_dev_lock); \
597 dev = se_dev->se_dev_ptr; \
599 spin_unlock(&se_dev->se_dev_lock); \
602 ret = strict_strtoul(page, 0, &val); \
604 spin_unlock(&se_dev->se_dev_lock); \
605 pr_err("strict_strtoul() failed with" \
606 " ret: %d\n", ret); \
609 ret = se_dev_set_##_name(dev, (u32)val); \
610 spin_unlock(&se_dev->se_dev_lock); \
612 return (!ret) ? count : -EINVAL; \
615 #define DEF_DEV_ATTRIB(_name) \
616 DEF_DEV_ATTRIB_SHOW(_name); \
617 DEF_DEV_ATTRIB_STORE(_name);
619 #define DEF_DEV_ATTRIB_RO(_name) \
620 DEF_DEV_ATTRIB_SHOW(_name);
623 #define SE_DEV_ATTR(_name, _mode) \
624 static struct target_core_dev_attrib_attribute \
625 target_core_dev_attrib_##_name = \
626 __CONFIGFS_EATTR(_name, _mode, \
627 target_core_dev_show_attr_##_name, \
628 target_core_dev_store_attr_##_name);
630 #define SE_DEV_ATTR_RO(_name); \
631 static struct target_core_dev_attrib_attribute \
632 target_core_dev_attrib_##_name = \
633 __CONFIGFS_EATTR_RO(_name, \
634 target_core_dev_show_attr_##_name);
705 &target_core_dev_attrib_emulate_dpo.attr,
706 &target_core_dev_attrib_emulate_fua_write.attr,
707 &target_core_dev_attrib_emulate_fua_read.attr,
708 &target_core_dev_attrib_emulate_write_cache.attr,
709 &target_core_dev_attrib_emulate_ua_intlck_ctrl.attr,
710 &target_core_dev_attrib_emulate_tas.attr,
711 &target_core_dev_attrib_emulate_tpu.attr,
712 &target_core_dev_attrib_emulate_tpws.attr,
713 &target_core_dev_attrib_enforce_pr_isids.attr,
714 &target_core_dev_attrib_is_nonrot.attr,
715 &target_core_dev_attrib_emulate_rest_reord.attr,
716 &target_core_dev_attrib_hw_block_size.attr,
717 &target_core_dev_attrib_block_size.attr,
718 &target_core_dev_attrib_hw_max_sectors.attr,
719 &target_core_dev_attrib_fabric_max_sectors.attr,
720 &target_core_dev_attrib_optimal_sectors.attr,
721 &target_core_dev_attrib_hw_queue_depth.attr,
722 &target_core_dev_attrib_queue_depth.attr,
723 &target_core_dev_attrib_max_unmap_lba_count.attr,
724 &target_core_dev_attrib_max_unmap_block_desc_count.attr,
725 &target_core_dev_attrib_unmap_granularity.attr,
726 &target_core_dev_attrib_unmap_granularity_alignment.attr,
731 .show_attribute = target_core_dev_attrib_attr_show,
732 .store_attribute = target_core_dev_attrib_attr_store,
736 .ct_item_ops = &target_core_dev_attrib_ops,
737 .ct_attrs = target_core_dev_attrib_attrs,
746 #define SE_DEV_WWN_ATTR(_name, _mode) \
747 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
748 __CONFIGFS_EATTR(_name, _mode, \
749 target_core_dev_wwn_show_attr_##_name, \
750 target_core_dev_wwn_store_attr_##_name);
752 #define SE_DEV_WWN_ATTR_RO(_name); \
754 static struct target_core_dev_wwn_attribute \
755 target_core_dev_wwn_##_name = \
756 __CONFIGFS_EATTR_RO(_name, \
757 target_core_dev_wwn_show_attr_##_name); \
763 static ssize_t target_core_dev_wwn_show_attr_vpd_unit_serial(
774 return sprintf(page,
"T10 VPD Unit Serial Number: %s\n",
778 static ssize_t target_core_dev_wwn_store_attr_vpd_unit_serial(
798 pr_err(
"Underlying SCSI device firmware provided VPD"
799 " Unit Serial, ignoring request\n");
804 pr_err(
"Emulated VPD Unit Serial exceeds"
817 pr_err(
"Unable to set VPD Unit Serial while"
818 " active %d $FABRIC_MOD exports exist\n",
832 "%s", strstrip(buf));
835 pr_debug(
"Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
836 " %s\n", su_dev->
t10_wwn.unit_serial);
846 static ssize_t target_core_dev_wwn_show_attr_vpd_protocol_identifier(
847 struct t10_wwn *t10_wwn,
872 len +=
sprintf(page+len,
"%s", buf);
879 static ssize_t target_core_dev_wwn_store_attr_vpd_protocol_identifier(
880 struct t10_wwn *t10_wwn,
892 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
893 static ssize_t target_core_dev_wwn_show_attr_##_name( \
894 struct t10_wwn *t10_wwn, \
897 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev; \
898 struct se_device *dev; \
899 struct t10_vpd *vpd; \
900 unsigned char buf[VPD_TMP_BUF_SIZE]; \
903 dev = se_dev->se_dev_ptr; \
907 spin_lock(&t10_wwn->t10_vpd_lock); \
908 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
909 if (vpd->association != _assoc) \
912 memset(buf, 0, VPD_TMP_BUF_SIZE); \
913 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
914 if (len + strlen(buf) >= PAGE_SIZE) \
916 len += sprintf(page+len, "%s", buf); \
918 memset(buf, 0, VPD_TMP_BUF_SIZE); \
919 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
920 if (len + strlen(buf) >= PAGE_SIZE) \
922 len += sprintf(page+len, "%s", buf); \
924 memset(buf, 0, VPD_TMP_BUF_SIZE); \
925 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
926 if (len + strlen(buf) >= PAGE_SIZE) \
928 len += sprintf(page+len, "%s", buf); \
930 spin_unlock(&t10_wwn->t10_vpd_lock); \
940 static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
941 struct t10_wwn *t10_wwn,
955 static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_target_port(
956 struct t10_wwn *t10_wwn,
970 static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
971 struct t10_wwn *t10_wwn,
983 &target_core_dev_wwn_vpd_unit_serial.attr,
984 &target_core_dev_wwn_vpd_protocol_identifier.attr,
985 &target_core_dev_wwn_vpd_assoc_logical_unit.attr,
986 &target_core_dev_wwn_vpd_assoc_target_port.attr,
987 &target_core_dev_wwn_vpd_assoc_scsi_target_device.attr,
992 .show_attribute = target_core_dev_wwn_attr_show,
993 .store_attribute = target_core_dev_wwn_attr_store,
997 .ct_item_ops = &target_core_dev_wwn_ops,
998 .ct_attrs = target_core_dev_wwn_attrs,
1007 #define SE_DEV_PR_ATTR(_name, _mode) \
1008 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1009 __CONFIGFS_EATTR(_name, _mode, \
1010 target_core_dev_pr_show_attr_##_name, \
1011 target_core_dev_pr_store_attr_##_name);
1013 #define SE_DEV_PR_ATTR_RO(_name); \
1014 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1015 __CONFIGFS_EATTR_RO(_name, \
1016 target_core_dev_pr_show_attr_##_name);
1021 static ssize_t target_core_dev_pr_show_spc3_res(
1036 *len +=
sprintf(page + *len,
"No SPC-3 Reservation holder\n");
1044 *len +=
sprintf(page + *len,
"SPC-3 Reservation: %s Initiator: %s%s\n",
1045 se_nacl->
se_tpg->se_tpg_tfo->get_fabric_name(),
1052 static ssize_t target_core_dev_pr_show_spc2_res(
1062 *len +=
sprintf(page + *len,
"No SPC-2 Reservation holder\n");
1066 *len +=
sprintf(page + *len,
"SPC-2 Reservation: %s Initiator: %s\n",
1067 se_nacl->
se_tpg->se_tpg_tfo->get_fabric_name(),
1074 static ssize_t target_core_dev_pr_show_attr_res_holder(
1083 switch (su_dev->
t10_pr.res_type) {
1085 target_core_dev_pr_show_spc3_res(su_dev->
se_dev_ptr,
1089 target_core_dev_pr_show_spc2_res(su_dev->
se_dev_ptr,
1093 len +=
sprintf(page+len,
"Passthrough\n");
1096 len +=
sprintf(page+len,
"Unknown\n");
1108 static ssize_t target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1126 len =
sprintf(page,
"No SPC-3 Reservation holder\n");
1135 len =
sprintf(page,
"SPC-3 Reservation: All Target"
1136 " Ports registration\n");
1138 len =
sprintf(page,
"SPC-3 Reservation: Single"
1139 " Target Port registration\n");
1150 static ssize_t target_core_dev_pr_show_attr_res_pr_generation(
1160 return sprintf(page,
"0x%08x\n", su_dev->
t10_pr.pr_generation);
1168 static ssize_t target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1190 len =
sprintf(page,
"No SPC-3 Reservation holder\n");
1195 se_tpg = se_nacl->
se_tpg;
1199 len +=
sprintf(page+len,
"SPC-3 Reservation: %s"
1202 len +=
sprintf(page+len,
"SPC-3 Reservation: Relative Port"
1203 " Identifier Tag: %hu %s Portal Group Tag: %hu"
1204 " %s Logical Unit: %u\n", lun->
lun_sep->sep_rtpi,
1217 static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1223 unsigned char buf[384];
1226 int reg_count = 0, prf_isid;
1234 len +=
sprintf(page+len,
"SPC-3 PR Registrations:\n");
1236 spin_lock(&su_dev->
t10_pr.registration_lock);
1245 sprintf(buf,
"%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1254 len +=
sprintf(page+len,
"%s", buf);
1257 spin_unlock(&su_dev->
t10_pr.registration_lock);
1260 len +=
sprintf(page+len,
"None\n");
1270 static ssize_t target_core_dev_pr_show_attr_res_pr_type(
1288 len =
sprintf(page,
"No SPC-3 Reservation holder\n");
1292 len =
sprintf(page,
"SPC-3 Reservation Type: %s\n",
1304 static ssize_t target_core_dev_pr_show_attr_res_type(
1313 switch (su_dev->
t10_pr.res_type) {
1315 len =
sprintf(page,
"SPC3_PERSISTENT_RESERVATIONS\n");
1318 len =
sprintf(page,
"SPC2_RESERVATIONS\n");
1321 len =
sprintf(page,
"SPC_PASSTHROUGH\n");
1324 len =
sprintf(page,
"UNKNOWN\n");
1337 static ssize_t target_core_dev_pr_show_attr_res_aptpl_active(
1347 return sprintf(page,
"APTPL Bit Status: %s\n",
1348 (su_dev->
t10_pr.pr_aptpl_active) ?
"Activated" :
"Disabled");
1356 static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata(
1366 return sprintf(page,
"Ready to process PR APTPL metadata..\n");
1394 static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
1400 unsigned char *i_fabric =
NULL, *i_port =
NULL, *isid =
NULL;
1401 unsigned char *t_fabric =
NULL, *t_port =
NULL;
1402 char *orig, *
ptr, *arg_p, *
opts;
1404 unsigned long long tmp_ll;
1406 u32 mapped_lun = 0, target_lun = 0;
1407 int ret = -1, res_holder = 0, all_tg_pt = 0,
arg,
token;
1408 u16 port_rpti = 0, tpgt = 0;
1419 pr_debug(
"Unable to process APTPL metadata while"
1420 " active fabric exports exist\n");
1429 while ((ptr =
strsep(&opts,
",\n")) !=
NULL) {
1449 pr_err(
"APTPL metadata initiator_node="
1450 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1463 pr_err(
"APTPL metadata initiator_isid"
1464 "= exceeds PR_REG_ISID_LEN: %d\n",
1478 pr_err(
"strict_strtoull() failed for"
1482 sa_res_key = (
u64)tmp_ll;
1524 pr_err(
"APTPL metadata target_node="
1525 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1548 if (!i_port || !t_port || !sa_res_key) {
1549 pr_err(
"Illegal parameters for APTPL registration\n");
1554 if (res_holder && !(type)) {
1555 pr_err(
"Illegal PR type: 0x%02x for reservation"
1562 i_port, isid, mapped_lun, t_port, tpgt, target_lun,
1563 res_holder, all_tg_pt, type);
1571 return (ret == 0) ? count :
ret;
1579 &target_core_dev_pr_res_holder.attr,
1580 &target_core_dev_pr_res_pr_all_tgt_pts.attr,
1581 &target_core_dev_pr_res_pr_generation.attr,
1582 &target_core_dev_pr_res_pr_holder_tg_port.attr,
1583 &target_core_dev_pr_res_pr_registered_i_pts.attr,
1584 &target_core_dev_pr_res_pr_type.attr,
1585 &target_core_dev_pr_res_type.attr,
1586 &target_core_dev_pr_res_aptpl_active.attr,
1587 &target_core_dev_pr_res_aptpl_metadata.attr,
1592 .show_attribute = target_core_dev_pr_attr_show,
1593 .store_attribute = target_core_dev_pr_attr_store,
1597 .ct_item_ops = &target_core_dev_pr_ops,
1598 .ct_attrs = target_core_dev_pr_attrs,
1606 static ssize_t target_core_show_dev_info(
void *
p,
char *page)
1627 .show = target_core_show_dev_info,
1631 static ssize_t target_core_store_dev_control(
1641 pr_err(
"Unable to locate struct se_subsystem_dev>se"
1651 .ca_name =
"control",
1654 .store = target_core_store_dev_control,
1657 static ssize_t target_core_show_dev_alias(
void *p,
char *page)
1667 static ssize_t target_core_store_dev_alias(
1677 pr_err(
"alias count: %d exceeds"
1678 " SE_DEV_ALIAS_LEN-1: %u\n", (
int)count,
1692 pr_debug(
"Target_Core_ConfigFS: %s/%s set alias: %s\n",
1693 config_item_name(&hba->
hba_group.cg_item),
1704 .show = target_core_show_dev_alias,
1705 .store = target_core_store_dev_alias,
1708 static ssize_t target_core_show_dev_udev_path(
void *p,
char *page)
1718 static ssize_t target_core_store_dev_udev_path(
1728 pr_err(
"udev_path count: %d exceeds"
1729 " SE_UDEV_PATH_LEN-1: %u\n", (
int)count,
1743 pr_debug(
"Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1744 config_item_name(&hba->
hba_group.cg_item),
1753 .ca_name =
"udev_path",
1755 .show = target_core_show_dev_udev_path,
1756 .store = target_core_store_dev_udev_path,
1759 static ssize_t target_core_store_dev_enable(
1772 pr_err(
"For dev_enable ops, only valid value"
1777 pr_err(
"se_dev->se_dev_ptr already set for storage"
1787 return PTR_ERR(dev);
1792 pr_debug(
"Target_Core_ConfigFS: Registered se_dev->se_dev_ptr:"
1800 .ca_name =
"enable",
1803 .store = target_core_store_dev_enable,
1806 static ssize_t target_core_show_alua_lu_gp(
void *p,
char *page)
1824 pr_err(
"NULL struct se_device->dev_alua_lu_gp_mem"
1830 lu_gp = lu_gp_mem->
lu_gp;
1833 len +=
sprintf(page,
"LU Group Alias: %s\nLU Group ID: %hu\n",
1834 config_item_name(lu_ci), lu_gp->
lu_gp_id);
1841 static ssize_t target_core_store_alua_lu_gp(
1859 pr_warn(
"SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1860 config_item_name(&hba->
hba_group.cg_item),
1865 pr_err(
"ALUA LU Group Alias too large!\n");
1869 memcpy(buf, page, count);
1874 if (
strcmp(strstrip(buf),
"NULL")) {
1888 pr_err(
"NULL struct se_device->dev_alua_lu_gp_mem"
1894 lu_gp = lu_gp_mem->
lu_gp;
1901 pr_debug(
"Target_Core_ConfigFS: Releasing %s/%s"
1902 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1904 config_item_name(&hba->
hba_group.cg_item),
1926 pr_debug(
"Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1927 " core/alua/lu_gps/%s, ID: %hu\n",
1928 (move) ?
"Moving" :
"Adding",
1929 config_item_name(&hba->
hba_group.cg_item),
1931 config_item_name(&lu_gp_new->lu_gp_group.cg_item),
1932 lu_gp_new->lu_gp_id);
1940 .ca_name =
"alua_lu_gp",
1942 .show = target_core_show_alua_lu_gp,
1943 .store = target_core_store_alua_lu_gp,
1947 &target_core_attr_dev_info.
attr,
1948 &target_core_attr_dev_control.
attr,
1949 &target_core_attr_dev_alias.
attr,
1950 &target_core_attr_dev_udev_path.
attr,
1951 &target_core_attr_dev_enable.
attr,
1952 &target_core_attr_dev_alua_lu_gp.
attr,
1956 static void target_core_dev_release(
struct config_item *item)
1970 pr_debug(
"Target_Core_ConfigFS: Calling se_free_"
1971 "virtual_device() for se_dev_ptr: %p\n",
1979 pr_debug(
"Target_Core_ConfigFS: Calling t->free_"
1980 "device() for se_dev_su_ptr: %p\n",
1986 pr_debug(
"Target_Core_ConfigFS: Deallocating se_subsystem"
1987 "_dev_t: %p\n", se_dev);
2004 return tc_attr->
show(se_dev, page);
2009 const char *page,
size_t count)
2017 if (!tc_attr->
store)
2020 return tc_attr->
store(se_dev, page, count);
2024 .release = target_core_dev_release,
2025 .show_attribute = target_core_dev_show,
2026 .store_attribute = target_core_dev_store,
2030 .ct_item_ops = &target_core_dev_item_ops,
2031 .ct_attrs = lio_core_dev_attrs,
2040 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2041 static struct target_core_alua_lu_gp_attribute \
2042 target_core_alua_lu_gp_##_name = \
2043 __CONFIGFS_EATTR(_name, _mode, \
2044 target_core_alua_lu_gp_show_attr_##_name, \
2045 target_core_alua_lu_gp_store_attr_##_name);
2047 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2048 static struct target_core_alua_lu_gp_attribute \
2049 target_core_alua_lu_gp_##_name = \
2050 __CONFIGFS_EATTR_RO(_name, \
2051 target_core_alua_lu_gp_show_attr_##_name);
2056 static ssize_t target_core_alua_lu_gp_show_attr_lu_gp_id(
2066 static ssize_t target_core_alua_lu_gp_store_attr_lu_gp_id(
2072 unsigned long lu_gp_id;
2077 pr_err(
"strict_strtoul() returned %d for"
2078 " lu_gp_id\n", ret);
2081 if (lu_gp_id > 0x0000ffff) {
2082 pr_err(
"ALUA lu_gp_id: %lu exceeds maximum:"
2083 " 0x0000ffff\n", lu_gp_id);
2091 pr_debug(
"Target_Core_ConfigFS: Set ALUA Logical Unit"
2092 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2093 config_item_name(&alua_lu_gp_cg->
cg_item),
2104 static ssize_t target_core_alua_lu_gp_show_attr_members(
2124 config_item_name(&hba->
hba_group.cg_item),
2129 pr_warn(
"Ran out of lu_gp_show_attr"
2130 "_members buffer\n");
2133 memcpy(page+len, buf, cur_len);
2146 &target_core_alua_lu_gp_lu_gp_id.attr,
2147 &target_core_alua_lu_gp_members.attr,
2151 static void target_core_alua_lu_gp_release(
struct config_item *item)
2160 .release = target_core_alua_lu_gp_release,
2161 .show_attribute = target_core_alua_lu_gp_attr_show,
2162 .store_attribute = target_core_alua_lu_gp_attr_store,
2166 .ct_item_ops = &target_core_alua_lu_gp_ops,
2167 .ct_attrs = target_core_alua_lu_gp_attrs,
2175 static struct config_group *target_core_alua_create_lu_gp(
2188 alua_lu_gp_ci = &alua_lu_gp_cg->
cg_item;
2191 &target_core_alua_lu_gp_cit);
2193 pr_debug(
"Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2194 " Group: core/alua/lu_gps/%s\n",
2195 config_item_name(alua_lu_gp_ci));
2197 return alua_lu_gp_cg;
2201 static void target_core_alua_drop_lu_gp(
2208 pr_debug(
"Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2209 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2210 config_item_name(item), lu_gp->
lu_gp_id);
2219 .make_group = &target_core_alua_create_lu_gp,
2220 .drop_item = &target_core_alua_drop_lu_gp,
2224 .ct_item_ops =
NULL,
2225 .ct_group_ops = &target_core_alua_lu_gps_group_ops,
2234 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2235 static struct target_core_alua_tg_pt_gp_attribute \
2236 target_core_alua_tg_pt_gp_##_name = \
2237 __CONFIGFS_EATTR(_name, _mode, \
2238 target_core_alua_tg_pt_gp_show_attr_##_name, \
2239 target_core_alua_tg_pt_gp_store_attr_##_name);
2241 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2242 static struct target_core_alua_tg_pt_gp_attribute \
2243 target_core_alua_tg_pt_gp_##_name = \
2244 __CONFIGFS_EATTR_RO(_name, \
2245 target_core_alua_tg_pt_gp_show_attr_##_name);
2250 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2258 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2268 pr_err(
"Unable to do implict ALUA on non valid"
2275 pr_err(
"Unable to extract new ALUA access state from"
2279 new_state = (
int)tmp;
2282 pr_err(
"Unable to process implict configfs ALUA"
2283 " transition while TPGS_IMPLICT_ALUA is disabled\n");
2289 return (!ret) ? count : -
EINVAL;
2297 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2305 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2311 int new_status,
ret;
2314 pr_err(
"Unable to do set ALUA access status on non"
2315 " valid tg_pt_gp ID: %hu\n",
2322 pr_err(
"Unable to extract new ALUA access status"
2323 " from %s\n", page);
2326 new_status = (
int)tmp;
2331 pr_err(
"Illegal ALUA access status: 0x%02x\n",
2345 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2352 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2365 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2372 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2382 pr_err(
"Unable to extract alua_write_metadata\n");
2386 if ((tmp != 0) && (tmp != 1)) {
2387 pr_err(
"Illegal value for alua_write_metadata:"
2403 static ssize_t target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2411 static ssize_t target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2424 static ssize_t target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2431 static ssize_t target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2444 static ssize_t target_core_alua_tg_pt_gp_show_attr_implict_trans_secs(
2451 static ssize_t target_core_alua_tg_pt_gp_store_attr_implict_trans_secs(
2465 static ssize_t target_core_alua_tg_pt_gp_show_attr_preferred(
2472 static ssize_t target_core_alua_tg_pt_gp_store_attr_preferred(
2485 static ssize_t target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2495 static ssize_t target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2501 unsigned long tg_pt_gp_id;
2506 pr_err(
"strict_strtoul() returned %d for"
2507 " tg_pt_gp_id\n", ret);
2510 if (tg_pt_gp_id > 0x0000ffff) {
2511 pr_err(
"ALUA tg_pt_gp_id: %lu exceeds maximum:"
2512 " 0x0000ffff\n", tg_pt_gp_id);
2520 pr_debug(
"Target_Core_ConfigFS: Set ALUA Target Port Group: "
2521 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2522 config_item_name(&alua_tg_pt_gp_cg->
cg_item),
2533 static ssize_t target_core_alua_tg_pt_gp_show_attr_members(
2549 port = tg_pt_gp_mem->
tg_pt;
2557 config_item_name(&lun->
lun_group.cg_item));
2561 pr_warn(
"Ran out of lu_gp_show_attr"
2562 "_members buffer\n");
2565 memcpy(page+len, buf, cur_len);
2579 &target_core_alua_tg_pt_gp_alua_access_state.attr,
2580 &target_core_alua_tg_pt_gp_alua_access_status.attr,
2581 &target_core_alua_tg_pt_gp_alua_access_type.attr,
2582 &target_core_alua_tg_pt_gp_alua_write_metadata.attr,
2583 &target_core_alua_tg_pt_gp_nonop_delay_msecs.attr,
2584 &target_core_alua_tg_pt_gp_trans_delay_msecs.attr,
2585 &target_core_alua_tg_pt_gp_implict_trans_secs.attr,
2586 &target_core_alua_tg_pt_gp_preferred.attr,
2587 &target_core_alua_tg_pt_gp_tg_pt_gp_id.attr,
2588 &target_core_alua_tg_pt_gp_members.attr,
2592 static void target_core_alua_tg_pt_gp_release(
struct config_item *item)
2601 .release = target_core_alua_tg_pt_gp_release,
2602 .show_attribute = target_core_alua_tg_pt_gp_attr_show,
2603 .store_attribute = target_core_alua_tg_pt_gp_attr_store,
2607 .ct_item_ops = &target_core_alua_tg_pt_gp_ops,
2608 .ct_attrs = target_core_alua_tg_pt_gp_attrs,
2616 static struct config_group *target_core_alua_create_tg_pt_gp(
2632 alua_tg_pt_gp_ci = &alua_tg_pt_gp_cg->
cg_item;
2635 &target_core_alua_tg_pt_gp_cit);
2637 pr_debug(
"Target_Core_ConfigFS: Allocated ALUA Target Port"
2638 " Group: alua/tg_pt_gps/%s\n",
2639 config_item_name(alua_tg_pt_gp_ci));
2641 return alua_tg_pt_gp_cg;
2644 static void target_core_alua_drop_tg_pt_gp(
2651 pr_debug(
"Target_Core_ConfigFS: Releasing ALUA Target Port"
2652 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2662 .make_group = &target_core_alua_create_tg_pt_gp,
2663 .drop_item = &target_core_alua_drop_tg_pt_gp,
2667 .ct_group_ops = &target_core_alua_tg_pt_gps_group_ops,
2682 .ct_item_ops =
NULL,
2698 static void target_core_stat_rmdir(
2706 .make_group = &target_core_stat_mkdir,
2707 .drop_item = &target_core_stat_rmdir,
2711 .ct_group_ops = &target_core_stat_group_ops,
2727 struct se_hba *hba = item_to_hba(hba_ci);
2734 return ERR_PTR(ret);
2742 pr_err(
"Unable to allocate memory for"
2743 " struct se_subsystem_dev\n");
2746 INIT_LIST_HEAD(&se_dev->
t10_wwn.t10_vpd_list);
2748 INIT_LIST_HEAD(&se_dev->
t10_pr.registration_list);
2749 INIT_LIST_HEAD(&se_dev->
t10_pr.aptpl_reg_list);
2752 INIT_LIST_HEAD(&se_dev->
t10_alua.tg_pt_gps_list);
2756 se_dev->
t10_wwn.t10_sub_dev = se_dev;
2757 se_dev->
t10_alua.t10_sub_dev = se_dev;
2777 pr_err(
"Unable to locate subsystem dependent pointer"
2778 " from allocate_virtdevice()\n");
2783 &target_core_dev_cit);
2785 &target_core_dev_attrib_cit);
2787 &target_core_dev_pr_cit);
2789 &target_core_dev_wwn_cit);
2791 "alua", &target_core_alua_tg_pt_gps_cit);
2793 "statistics", &target_core_stat_cit);
2808 tg_pt_gp_cg = &se_dev->
t10_alua.alua_tg_pt_gps_group;
2809 tg_pt_gp_cg->default_groups = kzalloc(
sizeof(
struct config_group) * 2,
2811 if (!tg_pt_gp_cg->default_groups) {
2812 pr_err(
"Unable to allocate tg_pt_gp_cg->"
2813 "default_groups\n");
2818 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit);
2820 tg_pt_gp_cg->default_groups[1] =
NULL;
2821 se_dev->
t10_alua.default_tg_pt_gp = tg_pt_gp;
2829 pr_err(
"Unable to allocate dev_stat_grp->default_groups\n");
2834 pr_debug(
"Target_Core_ConfigFS: Allocated struct se_subsystem_dev:"
2840 if (se_dev->
t10_alua.default_tg_pt_gp) {
2847 kfree(tg_pt_gp_cg->default_groups);
2855 return ERR_PTR(errno);
2858 static void target_core_drop_subdev(
2866 struct config_group *dev_cg, *tg_pt_gp_cg, *dev_stat_grp;
2869 hba = item_to_hba(&se_dev->
se_dev_hba->hba_group.cg_item);
2881 tg_pt_gp_cg = &se_dev->
t10_alua.alua_tg_pt_gps_group;
2909 .make_group = target_core_make_subdev,
2910 .drop_item = target_core_drop_subdev,
2914 #define SE_HBA_ATTR(_name, _mode) \
2915 static struct target_core_hba_attribute \
2916 target_core_hba_##_name = \
2917 __CONFIGFS_EATTR(_name, _mode, \
2918 target_core_hba_show_attr_##_name, \
2919 target_core_hba_store_attr_##_name);
2921 #define SE_HBA_ATTR_RO(_name) \
2922 static struct target_core_hba_attribute \
2923 target_core_hba_##_name = \
2924 __CONFIGFS_EATTR_RO(_name, \
2925 target_core_hba_show_attr_##_name);
2927 static ssize_t target_core_hba_show_attr_hba_info(
2931 return sprintf(page,
"HBA Index: %d plugin: %s version: %s\n",
2938 static ssize_t target_core_hba_show_attr_hba_mode(
struct se_hba *hba,
2946 return sprintf(page,
"%d\n", hba_mode);
2949 static ssize_t target_core_hba_store_attr_hba_mode(
struct se_hba *hba,
2950 const char *page,
size_t count)
2953 unsigned long mode_flag;
2961 pr_err(
"Unable to extract hba mode flag: %d\n", ret);
2967 pr_err(
"Unable to set hba_mode with active devices\n");
2988 static void target_core_hba_release(
struct config_item *item)
2996 &target_core_hba_hba_info.attr,
2997 &target_core_hba_hba_mode.attr,
3002 .release = target_core_hba_release,
3003 .show_attribute = target_core_hba_attr_show,
3004 .store_attribute = target_core_hba_attr_store,
3008 .ct_item_ops = &target_core_hba_item_ops,
3009 .ct_group_ops = &target_core_hba_group_ops,
3010 .ct_attrs = target_core_hba_attrs,
3014 static struct config_group *target_core_call_addhbatotarget(
3018 char *se_plugin_str, *
str, *str2;
3021 unsigned long plugin_dep_id = 0;
3026 pr_err(
"Passed *name strlen(): %d exceeds"
3027 " TARGET_CORE_NAME_MAX_LEN: %d\n", (
int)
strlen(name),
3035 pr_err(
"Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3038 se_plugin_str =
buf;
3043 str2 =
strstr(str+1,
"_");
3055 pr_err(
"strict_strtoul() returned %d for"
3056 " plugin_dep_id\n", ret);
3066 return ERR_CAST(hba);
3069 &target_core_hba_cit);
3074 static void target_core_call_delhbafromtarget(
3086 .make_group = target_core_call_addhbatotarget,
3087 .drop_item = target_core_call_delhbafromtarget,
3091 .ct_item_ops =
NULL,
3092 .ct_group_ops = &target_core_group_ops,
3099 static int __init target_core_init_configfs(
void)
3107 pr_debug(
"TARGET_CORE[0]: Loading Generic Kernel Storage"
3108 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3111 subsys = target_core_subsystem[0];
3126 pr_err(
"Unable to allocate target_cg->default_groups\n");
3132 "core", &target_core_cit);
3138 hba_cg = &target_core_hbagroup;
3142 pr_err(
"Unable to allocate hba_cg->default_groups\n");
3147 "alua", &target_core_alua_cit);
3154 alua_cg = &alua_group;
3155 alua_cg->default_groups = kzalloc(
sizeof(
struct config_group) * 2,
3157 if (!alua_cg->default_groups) {
3158 pr_err(
"Unable to allocate alua_cg->default_groups\n");
3164 "lu_gps", &target_core_alua_lu_gps_cit);
3165 alua_cg->default_groups[0] = &alua_lu_gps_group;
3166 alua_cg->default_groups[1] =
NULL;
3171 if (IS_ERR(lu_gp)) {
3176 lu_gp_cg = &alua_lu_gps_group;
3180 pr_err(
"Unable to allocate lu_gp_cg->default_groups\n");
3186 &target_core_alua_lu_gp_cit);
3189 default_lu_gp = lu_gp;
3195 pr_err(
"Error %d while registering subsystem %s\n",
3196 ret, subsys->
su_group.cg_item.ci_namebuf);
3199 pr_debug(
"TARGET_CORE[0]: Initialized ConfigFS Fabric"
3201 " on "UTS_RELEASE
"\n", utsname()->sysname, utsname()->
machine);
3220 if (default_lu_gp) {
3222 default_lu_gp =
NULL;
3227 kfree(alua_cg->default_groups);
3235 static void __exit target_core_exit_configfs(
void)
3242 subsys = target_core_subsystem[0];
3244 lu_gp_cg = &alua_lu_gps_group;
3253 alua_cg = &alua_group;
3262 hba_cg = &target_core_hbagroup;
3278 default_lu_gp =
NULL;
3280 pr_debug(
"TARGET_CORE[0]: Released ConfigFS Fabric"
3281 " Infrastructure\n");