1 // SPDX-License-Identifier: GPL-2.0
3 * Configfs interface for the NVMe target.
4 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/slab.h>
10 #include <linux/stat.h>
11 #include <linux/ctype.h>
12 #include <linux/pci.h>
13 #include <linux/pci-p2pdma.h>
17 static const struct config_item_type nvmet_host_type;
18 static const struct config_item_type nvmet_subsys_type;
20 static LIST_HEAD(nvmet_ports_list);
21 struct list_head *nvmet_ports = &nvmet_ports_list;
23 struct nvmet_type_name_map {
28 static struct nvmet_type_name_map nvmet_transport[] = {
29 { NVMF_TRTYPE_RDMA, "rdma" },
30 { NVMF_TRTYPE_FC, "fc" },
31 { NVMF_TRTYPE_TCP, "tcp" },
32 { NVMF_TRTYPE_LOOP, "loop" },
35 static const struct nvmet_type_name_map nvmet_addr_family[] = {
36 { NVMF_ADDR_FAMILY_PCI, "pcie" },
37 { NVMF_ADDR_FAMILY_IP4, "ipv4" },
38 { NVMF_ADDR_FAMILY_IP6, "ipv6" },
39 { NVMF_ADDR_FAMILY_IB, "ib" },
40 { NVMF_ADDR_FAMILY_FC, "fc" },
41 { NVMF_ADDR_FAMILY_LOOP, "loop" },
44 static bool nvmet_is_port_enabled(struct nvmet_port *p, const char *caller)
47 pr_err("Disable port '%u' before changing attribute in %s\n",
48 le16_to_cpu(p->disc_addr.portid), caller);
53 * nvmet_port Generic ConfigFS definitions.
54 * Used in any place in the ConfigFS tree that refers to an address.
56 static ssize_t nvmet_addr_adrfam_show(struct config_item *item, char *page)
58 u8 adrfam = to_nvmet_port(item)->disc_addr.adrfam;
61 for (i = 1; i < ARRAY_SIZE(nvmet_addr_family); i++) {
62 if (nvmet_addr_family[i].type == adrfam)
63 return sprintf(page, "%s\n", nvmet_addr_family[i].name);
66 return sprintf(page, "\n");
69 static ssize_t nvmet_addr_adrfam_store(struct config_item *item,
70 const char *page, size_t count)
72 struct nvmet_port *port = to_nvmet_port(item);
75 if (nvmet_is_port_enabled(port, __func__))
78 for (i = 1; i < ARRAY_SIZE(nvmet_addr_family); i++) {
79 if (sysfs_streq(page, nvmet_addr_family[i].name))
83 pr_err("Invalid value '%s' for adrfam\n", page);
87 port->disc_addr.adrfam = nvmet_addr_family[i].type;
91 CONFIGFS_ATTR(nvmet_, addr_adrfam);
93 static ssize_t nvmet_addr_portid_show(struct config_item *item,
96 struct nvmet_port *port = to_nvmet_port(item);
98 return snprintf(page, PAGE_SIZE, "%d\n",
99 le16_to_cpu(port->disc_addr.portid));
102 static ssize_t nvmet_addr_portid_store(struct config_item *item,
103 const char *page, size_t count)
105 struct nvmet_port *port = to_nvmet_port(item);
108 if (kstrtou16(page, 0, &portid)) {
109 pr_err("Invalid value '%s' for portid\n", page);
113 if (nvmet_is_port_enabled(port, __func__))
116 port->disc_addr.portid = cpu_to_le16(portid);
120 CONFIGFS_ATTR(nvmet_, addr_portid);
122 static ssize_t nvmet_addr_traddr_show(struct config_item *item,
125 struct nvmet_port *port = to_nvmet_port(item);
127 return snprintf(page, PAGE_SIZE, "%s\n",
128 port->disc_addr.traddr);
131 static ssize_t nvmet_addr_traddr_store(struct config_item *item,
132 const char *page, size_t count)
134 struct nvmet_port *port = to_nvmet_port(item);
136 if (count > NVMF_TRADDR_SIZE) {
137 pr_err("Invalid value '%s' for traddr\n", page);
141 if (nvmet_is_port_enabled(port, __func__))
144 if (sscanf(page, "%s\n", port->disc_addr.traddr) != 1)
149 CONFIGFS_ATTR(nvmet_, addr_traddr);
151 static const struct nvmet_type_name_map nvmet_addr_treq[] = {
152 { NVMF_TREQ_NOT_SPECIFIED, "not specified" },
153 { NVMF_TREQ_REQUIRED, "required" },
154 { NVMF_TREQ_NOT_REQUIRED, "not required" },
157 static ssize_t nvmet_addr_treq_show(struct config_item *item, char *page)
159 u8 treq = to_nvmet_port(item)->disc_addr.treq &
160 NVME_TREQ_SECURE_CHANNEL_MASK;
163 for (i = 0; i < ARRAY_SIZE(nvmet_addr_treq); i++) {
164 if (treq == nvmet_addr_treq[i].type)
165 return sprintf(page, "%s\n", nvmet_addr_treq[i].name);
168 return sprintf(page, "\n");
171 static ssize_t nvmet_addr_treq_store(struct config_item *item,
172 const char *page, size_t count)
174 struct nvmet_port *port = to_nvmet_port(item);
175 u8 treq = port->disc_addr.treq & ~NVME_TREQ_SECURE_CHANNEL_MASK;
178 if (nvmet_is_port_enabled(port, __func__))
181 for (i = 0; i < ARRAY_SIZE(nvmet_addr_treq); i++) {
182 if (sysfs_streq(page, nvmet_addr_treq[i].name))
186 pr_err("Invalid value '%s' for treq\n", page);
190 treq |= nvmet_addr_treq[i].type;
191 port->disc_addr.treq = treq;
195 CONFIGFS_ATTR(nvmet_, addr_treq);
197 static ssize_t nvmet_addr_trsvcid_show(struct config_item *item,
200 struct nvmet_port *port = to_nvmet_port(item);
202 return snprintf(page, PAGE_SIZE, "%s\n",
203 port->disc_addr.trsvcid);
206 static ssize_t nvmet_addr_trsvcid_store(struct config_item *item,
207 const char *page, size_t count)
209 struct nvmet_port *port = to_nvmet_port(item);
211 if (count > NVMF_TRSVCID_SIZE) {
212 pr_err("Invalid value '%s' for trsvcid\n", page);
215 if (nvmet_is_port_enabled(port, __func__))
218 if (sscanf(page, "%s\n", port->disc_addr.trsvcid) != 1)
223 CONFIGFS_ATTR(nvmet_, addr_trsvcid);
225 static ssize_t nvmet_param_inline_data_size_show(struct config_item *item,
228 struct nvmet_port *port = to_nvmet_port(item);
230 return snprintf(page, PAGE_SIZE, "%d\n", port->inline_data_size);
233 static ssize_t nvmet_param_inline_data_size_store(struct config_item *item,
234 const char *page, size_t count)
236 struct nvmet_port *port = to_nvmet_port(item);
239 if (nvmet_is_port_enabled(port, __func__))
241 ret = kstrtoint(page, 0, &port->inline_data_size);
243 pr_err("Invalid value '%s' for inline_data_size\n", page);
249 CONFIGFS_ATTR(nvmet_, param_inline_data_size);
251 #ifdef CONFIG_BLK_DEV_INTEGRITY
252 static ssize_t nvmet_param_pi_enable_show(struct config_item *item,
255 struct nvmet_port *port = to_nvmet_port(item);
257 return snprintf(page, PAGE_SIZE, "%d\n", port->pi_enable);
260 static ssize_t nvmet_param_pi_enable_store(struct config_item *item,
261 const char *page, size_t count)
263 struct nvmet_port *port = to_nvmet_port(item);
266 if (strtobool(page, &val))
269 if (nvmet_is_port_enabled(port, __func__))
272 port->pi_enable = val;
276 CONFIGFS_ATTR(nvmet_, param_pi_enable);
279 static ssize_t nvmet_addr_trtype_show(struct config_item *item,
282 struct nvmet_port *port = to_nvmet_port(item);
285 for (i = 0; i < ARRAY_SIZE(nvmet_transport); i++) {
286 if (port->disc_addr.trtype == nvmet_transport[i].type)
287 return sprintf(page, "%s\n", nvmet_transport[i].name);
290 return sprintf(page, "\n");
293 static void nvmet_port_init_tsas_rdma(struct nvmet_port *port)
295 port->disc_addr.tsas.rdma.qptype = NVMF_RDMA_QPTYPE_CONNECTED;
296 port->disc_addr.tsas.rdma.prtype = NVMF_RDMA_PRTYPE_NOT_SPECIFIED;
297 port->disc_addr.tsas.rdma.cms = NVMF_RDMA_CMS_RDMA_CM;
300 static ssize_t nvmet_addr_trtype_store(struct config_item *item,
301 const char *page, size_t count)
303 struct nvmet_port *port = to_nvmet_port(item);
306 if (nvmet_is_port_enabled(port, __func__))
309 for (i = 0; i < ARRAY_SIZE(nvmet_transport); i++) {
310 if (sysfs_streq(page, nvmet_transport[i].name))
314 pr_err("Invalid value '%s' for trtype\n", page);
318 memset(&port->disc_addr.tsas, 0, NVMF_TSAS_SIZE);
319 port->disc_addr.trtype = nvmet_transport[i].type;
320 if (port->disc_addr.trtype == NVMF_TRTYPE_RDMA)
321 nvmet_port_init_tsas_rdma(port);
325 CONFIGFS_ATTR(nvmet_, addr_trtype);
328 * Namespace structures & file operation functions below
330 static ssize_t nvmet_ns_device_path_show(struct config_item *item, char *page)
332 return sprintf(page, "%s\n", to_nvmet_ns(item)->device_path);
335 static ssize_t nvmet_ns_device_path_store(struct config_item *item,
336 const char *page, size_t count)
338 struct nvmet_ns *ns = to_nvmet_ns(item);
339 struct nvmet_subsys *subsys = ns->subsys;
343 mutex_lock(&subsys->lock);
349 len = strcspn(page, "\n");
353 kfree(ns->device_path);
355 ns->device_path = kmemdup_nul(page, len, GFP_KERNEL);
356 if (!ns->device_path)
359 mutex_unlock(&subsys->lock);
363 mutex_unlock(&subsys->lock);
367 CONFIGFS_ATTR(nvmet_ns_, device_path);
369 #ifdef CONFIG_PCI_P2PDMA
370 static ssize_t nvmet_ns_p2pmem_show(struct config_item *item, char *page)
372 struct nvmet_ns *ns = to_nvmet_ns(item);
374 return pci_p2pdma_enable_show(page, ns->p2p_dev, ns->use_p2pmem);
377 static ssize_t nvmet_ns_p2pmem_store(struct config_item *item,
378 const char *page, size_t count)
380 struct nvmet_ns *ns = to_nvmet_ns(item);
381 struct pci_dev *p2p_dev = NULL;
386 mutex_lock(&ns->subsys->lock);
392 error = pci_p2pdma_enable_store(page, &p2p_dev, &use_p2pmem);
398 ns->use_p2pmem = use_p2pmem;
399 pci_dev_put(ns->p2p_dev);
400 ns->p2p_dev = p2p_dev;
403 mutex_unlock(&ns->subsys->lock);
408 CONFIGFS_ATTR(nvmet_ns_, p2pmem);
409 #endif /* CONFIG_PCI_P2PDMA */
411 static ssize_t nvmet_ns_device_uuid_show(struct config_item *item, char *page)
413 return sprintf(page, "%pUb\n", &to_nvmet_ns(item)->uuid);
416 static ssize_t nvmet_ns_device_uuid_store(struct config_item *item,
417 const char *page, size_t count)
419 struct nvmet_ns *ns = to_nvmet_ns(item);
420 struct nvmet_subsys *subsys = ns->subsys;
423 mutex_lock(&subsys->lock);
429 if (uuid_parse(page, &ns->uuid))
433 mutex_unlock(&subsys->lock);
434 return ret ? ret : count;
437 CONFIGFS_ATTR(nvmet_ns_, device_uuid);
439 static ssize_t nvmet_ns_device_nguid_show(struct config_item *item, char *page)
441 return sprintf(page, "%pUb\n", &to_nvmet_ns(item)->nguid);
444 static ssize_t nvmet_ns_device_nguid_store(struct config_item *item,
445 const char *page, size_t count)
447 struct nvmet_ns *ns = to_nvmet_ns(item);
448 struct nvmet_subsys *subsys = ns->subsys;
450 const char *p = page;
454 mutex_lock(&subsys->lock);
460 for (i = 0; i < 16; i++) {
461 if (p + 2 > page + count) {
465 if (!isxdigit(p[0]) || !isxdigit(p[1])) {
470 nguid[i] = (hex_to_bin(p[0]) << 4) | hex_to_bin(p[1]);
473 if (*p == '-' || *p == ':')
477 memcpy(&ns->nguid, nguid, sizeof(nguid));
479 mutex_unlock(&subsys->lock);
480 return ret ? ret : count;
483 CONFIGFS_ATTR(nvmet_ns_, device_nguid);
485 static ssize_t nvmet_ns_ana_grpid_show(struct config_item *item, char *page)
487 return sprintf(page, "%u\n", to_nvmet_ns(item)->anagrpid);
490 static ssize_t nvmet_ns_ana_grpid_store(struct config_item *item,
491 const char *page, size_t count)
493 struct nvmet_ns *ns = to_nvmet_ns(item);
494 u32 oldgrpid, newgrpid;
497 ret = kstrtou32(page, 0, &newgrpid);
501 if (newgrpid < 1 || newgrpid > NVMET_MAX_ANAGRPS)
504 down_write(&nvmet_ana_sem);
505 oldgrpid = ns->anagrpid;
506 nvmet_ana_group_enabled[newgrpid]++;
507 ns->anagrpid = newgrpid;
508 nvmet_ana_group_enabled[oldgrpid]--;
510 up_write(&nvmet_ana_sem);
512 nvmet_send_ana_event(ns->subsys, NULL);
516 CONFIGFS_ATTR(nvmet_ns_, ana_grpid);
518 static ssize_t nvmet_ns_enable_show(struct config_item *item, char *page)
520 return sprintf(page, "%d\n", to_nvmet_ns(item)->enabled);
523 static ssize_t nvmet_ns_enable_store(struct config_item *item,
524 const char *page, size_t count)
526 struct nvmet_ns *ns = to_nvmet_ns(item);
530 if (strtobool(page, &enable))
534 ret = nvmet_ns_enable(ns);
536 nvmet_ns_disable(ns);
538 return ret ? ret : count;
541 CONFIGFS_ATTR(nvmet_ns_, enable);
543 static ssize_t nvmet_ns_buffered_io_show(struct config_item *item, char *page)
545 return sprintf(page, "%d\n", to_nvmet_ns(item)->buffered_io);
548 static ssize_t nvmet_ns_buffered_io_store(struct config_item *item,
549 const char *page, size_t count)
551 struct nvmet_ns *ns = to_nvmet_ns(item);
554 if (strtobool(page, &val))
557 mutex_lock(&ns->subsys->lock);
559 pr_err("disable ns before setting buffered_io value.\n");
560 mutex_unlock(&ns->subsys->lock);
564 ns->buffered_io = val;
565 mutex_unlock(&ns->subsys->lock);
569 CONFIGFS_ATTR(nvmet_ns_, buffered_io);
571 static ssize_t nvmet_ns_revalidate_size_store(struct config_item *item,
572 const char *page, size_t count)
574 struct nvmet_ns *ns = to_nvmet_ns(item);
577 if (strtobool(page, &val))
583 mutex_lock(&ns->subsys->lock);
585 pr_err("enable ns before revalidate.\n");
586 mutex_unlock(&ns->subsys->lock);
589 nvmet_ns_revalidate(ns);
590 mutex_unlock(&ns->subsys->lock);
594 CONFIGFS_ATTR_WO(nvmet_ns_, revalidate_size);
596 static struct configfs_attribute *nvmet_ns_attrs[] = {
597 &nvmet_ns_attr_device_path,
598 &nvmet_ns_attr_device_nguid,
599 &nvmet_ns_attr_device_uuid,
600 &nvmet_ns_attr_ana_grpid,
601 &nvmet_ns_attr_enable,
602 &nvmet_ns_attr_buffered_io,
603 &nvmet_ns_attr_revalidate_size,
604 #ifdef CONFIG_PCI_P2PDMA
605 &nvmet_ns_attr_p2pmem,
610 static void nvmet_ns_release(struct config_item *item)
612 struct nvmet_ns *ns = to_nvmet_ns(item);
617 static struct configfs_item_operations nvmet_ns_item_ops = {
618 .release = nvmet_ns_release,
621 static const struct config_item_type nvmet_ns_type = {
622 .ct_item_ops = &nvmet_ns_item_ops,
623 .ct_attrs = nvmet_ns_attrs,
624 .ct_owner = THIS_MODULE,
627 static struct config_group *nvmet_ns_make(struct config_group *group,
630 struct nvmet_subsys *subsys = namespaces_to_subsys(&group->cg_item);
635 ret = kstrtou32(name, 0, &nsid);
640 if (nsid == 0 || nsid == NVME_NSID_ALL) {
641 pr_err("invalid nsid %#x", nsid);
646 ns = nvmet_ns_alloc(subsys, nsid);
649 config_group_init_type_name(&ns->group, name, &nvmet_ns_type);
651 pr_info("adding nsid %d to subsystem %s\n", nsid, subsys->subsysnqn);
658 static struct configfs_group_operations nvmet_namespaces_group_ops = {
659 .make_group = nvmet_ns_make,
662 static const struct config_item_type nvmet_namespaces_type = {
663 .ct_group_ops = &nvmet_namespaces_group_ops,
664 .ct_owner = THIS_MODULE,
667 #ifdef CONFIG_NVME_TARGET_PASSTHRU
669 static ssize_t nvmet_passthru_device_path_show(struct config_item *item,
672 struct nvmet_subsys *subsys = to_subsys(item->ci_parent);
674 return snprintf(page, PAGE_SIZE, "%s\n", subsys->passthru_ctrl_path);
677 static ssize_t nvmet_passthru_device_path_store(struct config_item *item,
678 const char *page, size_t count)
680 struct nvmet_subsys *subsys = to_subsys(item->ci_parent);
684 mutex_lock(&subsys->lock);
687 if (subsys->passthru_ctrl)
691 len = strcspn(page, "\n");
695 kfree(subsys->passthru_ctrl_path);
697 subsys->passthru_ctrl_path = kstrndup(page, len, GFP_KERNEL);
698 if (!subsys->passthru_ctrl_path)
701 mutex_unlock(&subsys->lock);
705 mutex_unlock(&subsys->lock);
708 CONFIGFS_ATTR(nvmet_passthru_, device_path);
710 static ssize_t nvmet_passthru_enable_show(struct config_item *item,
713 struct nvmet_subsys *subsys = to_subsys(item->ci_parent);
715 return sprintf(page, "%d\n", subsys->passthru_ctrl ? 1 : 0);
718 static ssize_t nvmet_passthru_enable_store(struct config_item *item,
719 const char *page, size_t count)
721 struct nvmet_subsys *subsys = to_subsys(item->ci_parent);
725 if (strtobool(page, &enable))
729 ret = nvmet_passthru_ctrl_enable(subsys);
731 nvmet_passthru_ctrl_disable(subsys);
733 return ret ? ret : count;
735 CONFIGFS_ATTR(nvmet_passthru_, enable);
737 static ssize_t nvmet_passthru_admin_timeout_show(struct config_item *item,
740 return sprintf(page, "%u\n", to_subsys(item->ci_parent)->admin_timeout);
743 static ssize_t nvmet_passthru_admin_timeout_store(struct config_item *item,
744 const char *page, size_t count)
746 struct nvmet_subsys *subsys = to_subsys(item->ci_parent);
747 unsigned int timeout;
749 if (kstrtouint(page, 0, &timeout))
751 subsys->admin_timeout = timeout;
754 CONFIGFS_ATTR(nvmet_passthru_, admin_timeout);
756 static ssize_t nvmet_passthru_io_timeout_show(struct config_item *item,
759 return sprintf(page, "%u\n", to_subsys(item->ci_parent)->io_timeout);
762 static ssize_t nvmet_passthru_io_timeout_store(struct config_item *item,
763 const char *page, size_t count)
765 struct nvmet_subsys *subsys = to_subsys(item->ci_parent);
766 unsigned int timeout;
768 if (kstrtouint(page, 0, &timeout))
770 subsys->io_timeout = timeout;
773 CONFIGFS_ATTR(nvmet_passthru_, io_timeout);
775 static struct configfs_attribute *nvmet_passthru_attrs[] = {
776 &nvmet_passthru_attr_device_path,
777 &nvmet_passthru_attr_enable,
778 &nvmet_passthru_attr_admin_timeout,
779 &nvmet_passthru_attr_io_timeout,
783 static const struct config_item_type nvmet_passthru_type = {
784 .ct_attrs = nvmet_passthru_attrs,
785 .ct_owner = THIS_MODULE,
788 static void nvmet_add_passthru_group(struct nvmet_subsys *subsys)
790 config_group_init_type_name(&subsys->passthru_group,
791 "passthru", &nvmet_passthru_type);
792 configfs_add_default_group(&subsys->passthru_group,
796 #else /* CONFIG_NVME_TARGET_PASSTHRU */
798 static void nvmet_add_passthru_group(struct nvmet_subsys *subsys)
802 #endif /* CONFIG_NVME_TARGET_PASSTHRU */
804 static int nvmet_port_subsys_allow_link(struct config_item *parent,
805 struct config_item *target)
807 struct nvmet_port *port = to_nvmet_port(parent->ci_parent);
808 struct nvmet_subsys *subsys;
809 struct nvmet_subsys_link *link, *p;
812 if (target->ci_type != &nvmet_subsys_type) {
813 pr_err("can only link subsystems into the subsystems dir.!\n");
816 subsys = to_subsys(target);
817 link = kmalloc(sizeof(*link), GFP_KERNEL);
820 link->subsys = subsys;
822 down_write(&nvmet_config_sem);
824 list_for_each_entry(p, &port->subsystems, entry) {
825 if (p->subsys == subsys)
829 if (list_empty(&port->subsystems)) {
830 ret = nvmet_enable_port(port);
835 list_add_tail(&link->entry, &port->subsystems);
836 nvmet_port_disc_changed(port, subsys);
838 up_write(&nvmet_config_sem);
842 up_write(&nvmet_config_sem);
847 static void nvmet_port_subsys_drop_link(struct config_item *parent,
848 struct config_item *target)
850 struct nvmet_port *port = to_nvmet_port(parent->ci_parent);
851 struct nvmet_subsys *subsys = to_subsys(target);
852 struct nvmet_subsys_link *p;
854 down_write(&nvmet_config_sem);
855 list_for_each_entry(p, &port->subsystems, entry) {
856 if (p->subsys == subsys)
859 up_write(&nvmet_config_sem);
864 nvmet_port_del_ctrls(port, subsys);
865 nvmet_port_disc_changed(port, subsys);
867 if (list_empty(&port->subsystems))
868 nvmet_disable_port(port);
869 up_write(&nvmet_config_sem);
873 static struct configfs_item_operations nvmet_port_subsys_item_ops = {
874 .allow_link = nvmet_port_subsys_allow_link,
875 .drop_link = nvmet_port_subsys_drop_link,
878 static const struct config_item_type nvmet_port_subsys_type = {
879 .ct_item_ops = &nvmet_port_subsys_item_ops,
880 .ct_owner = THIS_MODULE,
883 static int nvmet_allowed_hosts_allow_link(struct config_item *parent,
884 struct config_item *target)
886 struct nvmet_subsys *subsys = to_subsys(parent->ci_parent);
887 struct nvmet_host *host;
888 struct nvmet_host_link *link, *p;
891 if (target->ci_type != &nvmet_host_type) {
892 pr_err("can only link hosts into the allowed_hosts directory!\n");
896 host = to_host(target);
897 link = kmalloc(sizeof(*link), GFP_KERNEL);
902 down_write(&nvmet_config_sem);
904 if (subsys->allow_any_host) {
905 pr_err("can't add hosts when allow_any_host is set!\n");
910 list_for_each_entry(p, &subsys->hosts, entry) {
911 if (!strcmp(nvmet_host_name(p->host), nvmet_host_name(host)))
914 list_add_tail(&link->entry, &subsys->hosts);
915 nvmet_subsys_disc_changed(subsys, host);
917 up_write(&nvmet_config_sem);
920 up_write(&nvmet_config_sem);
925 static void nvmet_allowed_hosts_drop_link(struct config_item *parent,
926 struct config_item *target)
928 struct nvmet_subsys *subsys = to_subsys(parent->ci_parent);
929 struct nvmet_host *host = to_host(target);
930 struct nvmet_host_link *p;
932 down_write(&nvmet_config_sem);
933 list_for_each_entry(p, &subsys->hosts, entry) {
934 if (!strcmp(nvmet_host_name(p->host), nvmet_host_name(host)))
937 up_write(&nvmet_config_sem);
942 nvmet_subsys_disc_changed(subsys, host);
944 up_write(&nvmet_config_sem);
948 static struct configfs_item_operations nvmet_allowed_hosts_item_ops = {
949 .allow_link = nvmet_allowed_hosts_allow_link,
950 .drop_link = nvmet_allowed_hosts_drop_link,
953 static const struct config_item_type nvmet_allowed_hosts_type = {
954 .ct_item_ops = &nvmet_allowed_hosts_item_ops,
955 .ct_owner = THIS_MODULE,
958 static ssize_t nvmet_subsys_attr_allow_any_host_show(struct config_item *item,
961 return snprintf(page, PAGE_SIZE, "%d\n",
962 to_subsys(item)->allow_any_host);
965 static ssize_t nvmet_subsys_attr_allow_any_host_store(struct config_item *item,
966 const char *page, size_t count)
968 struct nvmet_subsys *subsys = to_subsys(item);
972 if (strtobool(page, &allow_any_host))
975 down_write(&nvmet_config_sem);
976 if (allow_any_host && !list_empty(&subsys->hosts)) {
977 pr_err("Can't set allow_any_host when explicit hosts are set!\n");
982 if (subsys->allow_any_host != allow_any_host) {
983 subsys->allow_any_host = allow_any_host;
984 nvmet_subsys_disc_changed(subsys, NULL);
988 up_write(&nvmet_config_sem);
989 return ret ? ret : count;
992 CONFIGFS_ATTR(nvmet_subsys_, attr_allow_any_host);
994 static ssize_t nvmet_subsys_attr_version_show(struct config_item *item,
997 struct nvmet_subsys *subsys = to_subsys(item);
999 if (NVME_TERTIARY(subsys->ver))
1000 return snprintf(page, PAGE_SIZE, "%llu.%llu.%llu\n",
1001 NVME_MAJOR(subsys->ver),
1002 NVME_MINOR(subsys->ver),
1003 NVME_TERTIARY(subsys->ver));
1005 return snprintf(page, PAGE_SIZE, "%llu.%llu\n",
1006 NVME_MAJOR(subsys->ver),
1007 NVME_MINOR(subsys->ver));
1011 nvmet_subsys_attr_version_store_locked(struct nvmet_subsys *subsys,
1012 const char *page, size_t count)
1014 int major, minor, tertiary = 0;
1017 if (subsys->subsys_discovered) {
1018 if (NVME_TERTIARY(subsys->ver))
1019 pr_err("Can't set version number. %llu.%llu.%llu is already assigned\n",
1020 NVME_MAJOR(subsys->ver),
1021 NVME_MINOR(subsys->ver),
1022 NVME_TERTIARY(subsys->ver));
1024 pr_err("Can't set version number. %llu.%llu is already assigned\n",
1025 NVME_MAJOR(subsys->ver),
1026 NVME_MINOR(subsys->ver));
1030 /* passthru subsystems use the underlying controller's version */
1031 if (nvmet_is_passthru_subsys(subsys))
1034 ret = sscanf(page, "%d.%d.%d\n", &major, &minor, &tertiary);
1035 if (ret != 2 && ret != 3)
1038 subsys->ver = NVME_VS(major, minor, tertiary);
1043 static ssize_t nvmet_subsys_attr_version_store(struct config_item *item,
1044 const char *page, size_t count)
1046 struct nvmet_subsys *subsys = to_subsys(item);
1049 down_write(&nvmet_config_sem);
1050 mutex_lock(&subsys->lock);
1051 ret = nvmet_subsys_attr_version_store_locked(subsys, page, count);
1052 mutex_unlock(&subsys->lock);
1053 up_write(&nvmet_config_sem);
1057 CONFIGFS_ATTR(nvmet_subsys_, attr_version);
1059 /* See Section 1.5 of NVMe 1.4 */
1060 static bool nvmet_is_ascii(const char c)
1062 return c >= 0x20 && c <= 0x7e;
1065 static ssize_t nvmet_subsys_attr_serial_show(struct config_item *item,
1068 struct nvmet_subsys *subsys = to_subsys(item);
1070 return snprintf(page, PAGE_SIZE, "%.*s\n",
1071 NVMET_SN_MAX_SIZE, subsys->serial);
1075 nvmet_subsys_attr_serial_store_locked(struct nvmet_subsys *subsys,
1076 const char *page, size_t count)
1078 int pos, len = strcspn(page, "\n");
1080 if (subsys->subsys_discovered) {
1081 pr_err("Can't set serial number. %s is already assigned\n",
1086 if (!len || len > NVMET_SN_MAX_SIZE) {
1087 pr_err("Serial Number can not be empty or exceed %d Bytes\n",
1092 for (pos = 0; pos < len; pos++) {
1093 if (!nvmet_is_ascii(page[pos])) {
1094 pr_err("Serial Number must contain only ASCII strings\n");
1099 memcpy_and_pad(subsys->serial, NVMET_SN_MAX_SIZE, page, len, ' ');
1104 static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item,
1105 const char *page, size_t count)
1107 struct nvmet_subsys *subsys = to_subsys(item);
1110 down_write(&nvmet_config_sem);
1111 mutex_lock(&subsys->lock);
1112 ret = nvmet_subsys_attr_serial_store_locked(subsys, page, count);
1113 mutex_unlock(&subsys->lock);
1114 up_write(&nvmet_config_sem);
1118 CONFIGFS_ATTR(nvmet_subsys_, attr_serial);
1120 static ssize_t nvmet_subsys_attr_cntlid_min_show(struct config_item *item,
1123 return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_min);
1126 static ssize_t nvmet_subsys_attr_cntlid_min_store(struct config_item *item,
1127 const char *page, size_t cnt)
1131 if (sscanf(page, "%hu\n", &cntlid_min) != 1)
1134 if (cntlid_min == 0)
1137 down_write(&nvmet_config_sem);
1138 if (cntlid_min >= to_subsys(item)->cntlid_max)
1140 to_subsys(item)->cntlid_min = cntlid_min;
1141 up_write(&nvmet_config_sem);
1145 up_write(&nvmet_config_sem);
1148 CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_min);
1150 static ssize_t nvmet_subsys_attr_cntlid_max_show(struct config_item *item,
1153 return snprintf(page, PAGE_SIZE, "%u\n", to_subsys(item)->cntlid_max);
1156 static ssize_t nvmet_subsys_attr_cntlid_max_store(struct config_item *item,
1157 const char *page, size_t cnt)
1161 if (sscanf(page, "%hu\n", &cntlid_max) != 1)
1164 if (cntlid_max == 0)
1167 down_write(&nvmet_config_sem);
1168 if (cntlid_max <= to_subsys(item)->cntlid_min)
1170 to_subsys(item)->cntlid_max = cntlid_max;
1171 up_write(&nvmet_config_sem);
1175 up_write(&nvmet_config_sem);
1178 CONFIGFS_ATTR(nvmet_subsys_, attr_cntlid_max);
1180 static ssize_t nvmet_subsys_attr_model_show(struct config_item *item,
1183 struct nvmet_subsys *subsys = to_subsys(item);
1185 return snprintf(page, PAGE_SIZE, "%s\n", subsys->model_number);
1188 static ssize_t nvmet_subsys_attr_model_store_locked(struct nvmet_subsys *subsys,
1189 const char *page, size_t count)
1193 if (subsys->subsys_discovered) {
1194 pr_err("Can't set model number. %s is already assigned\n",
1195 subsys->model_number);
1199 len = strcspn(page, "\n");
1203 if (len > NVMET_MN_MAX_SIZE) {
1204 pr_err("Model number size can not exceed %d Bytes\n",
1209 for (pos = 0; pos < len; pos++) {
1210 if (!nvmet_is_ascii(page[pos]))
1214 subsys->model_number = kmemdup_nul(page, len, GFP_KERNEL);
1215 if (!subsys->model_number)
1220 static ssize_t nvmet_subsys_attr_model_store(struct config_item *item,
1221 const char *page, size_t count)
1223 struct nvmet_subsys *subsys = to_subsys(item);
1226 down_write(&nvmet_config_sem);
1227 mutex_lock(&subsys->lock);
1228 ret = nvmet_subsys_attr_model_store_locked(subsys, page, count);
1229 mutex_unlock(&subsys->lock);
1230 up_write(&nvmet_config_sem);
1234 CONFIGFS_ATTR(nvmet_subsys_, attr_model);
1236 static ssize_t nvmet_subsys_attr_discovery_nqn_show(struct config_item *item,
1239 return snprintf(page, PAGE_SIZE, "%s\n",
1240 nvmet_disc_subsys->subsysnqn);
1243 static ssize_t nvmet_subsys_attr_discovery_nqn_store(struct config_item *item,
1244 const char *page, size_t count)
1246 struct nvmet_subsys *subsys = to_subsys(item);
1250 len = strcspn(page, "\n");
1254 subsysnqn = kmemdup_nul(page, len, GFP_KERNEL);
1259 * The discovery NQN must be different from subsystem NQN.
1261 if (!strcmp(subsysnqn, subsys->subsysnqn)) {
1265 down_write(&nvmet_config_sem);
1266 kfree(nvmet_disc_subsys->subsysnqn);
1267 nvmet_disc_subsys->subsysnqn = subsysnqn;
1268 up_write(&nvmet_config_sem);
1272 CONFIGFS_ATTR(nvmet_subsys_, attr_discovery_nqn);
1274 #ifdef CONFIG_BLK_DEV_INTEGRITY
1275 static ssize_t nvmet_subsys_attr_pi_enable_show(struct config_item *item,
1278 return snprintf(page, PAGE_SIZE, "%d\n", to_subsys(item)->pi_support);
1281 static ssize_t nvmet_subsys_attr_pi_enable_store(struct config_item *item,
1282 const char *page, size_t count)
1284 struct nvmet_subsys *subsys = to_subsys(item);
1287 if (strtobool(page, &pi_enable))
1290 subsys->pi_support = pi_enable;
1293 CONFIGFS_ATTR(nvmet_subsys_, attr_pi_enable);
1296 static struct configfs_attribute *nvmet_subsys_attrs[] = {
1297 &nvmet_subsys_attr_attr_allow_any_host,
1298 &nvmet_subsys_attr_attr_version,
1299 &nvmet_subsys_attr_attr_serial,
1300 &nvmet_subsys_attr_attr_cntlid_min,
1301 &nvmet_subsys_attr_attr_cntlid_max,
1302 &nvmet_subsys_attr_attr_model,
1303 &nvmet_subsys_attr_attr_discovery_nqn,
1304 #ifdef CONFIG_BLK_DEV_INTEGRITY
1305 &nvmet_subsys_attr_attr_pi_enable,
1311 * Subsystem structures & folder operation functions below
1313 static void nvmet_subsys_release(struct config_item *item)
1315 struct nvmet_subsys *subsys = to_subsys(item);
1317 nvmet_subsys_del_ctrls(subsys);
1318 nvmet_subsys_put(subsys);
1321 static struct configfs_item_operations nvmet_subsys_item_ops = {
1322 .release = nvmet_subsys_release,
1325 static const struct config_item_type nvmet_subsys_type = {
1326 .ct_item_ops = &nvmet_subsys_item_ops,
1327 .ct_attrs = nvmet_subsys_attrs,
1328 .ct_owner = THIS_MODULE,
1331 static struct config_group *nvmet_subsys_make(struct config_group *group,
1334 struct nvmet_subsys *subsys;
1336 if (sysfs_streq(name, NVME_DISC_SUBSYS_NAME)) {
1337 pr_err("can't create discovery subsystem through configfs\n");
1338 return ERR_PTR(-EINVAL);
1341 subsys = nvmet_subsys_alloc(name, NVME_NQN_NVME);
1343 return ERR_CAST(subsys);
1345 config_group_init_type_name(&subsys->group, name, &nvmet_subsys_type);
1347 config_group_init_type_name(&subsys->namespaces_group,
1348 "namespaces", &nvmet_namespaces_type);
1349 configfs_add_default_group(&subsys->namespaces_group, &subsys->group);
1351 config_group_init_type_name(&subsys->allowed_hosts_group,
1352 "allowed_hosts", &nvmet_allowed_hosts_type);
1353 configfs_add_default_group(&subsys->allowed_hosts_group,
1356 nvmet_add_passthru_group(subsys);
1358 return &subsys->group;
1361 static struct configfs_group_operations nvmet_subsystems_group_ops = {
1362 .make_group = nvmet_subsys_make,
1365 static const struct config_item_type nvmet_subsystems_type = {
1366 .ct_group_ops = &nvmet_subsystems_group_ops,
1367 .ct_owner = THIS_MODULE,
1370 static ssize_t nvmet_referral_enable_show(struct config_item *item,
1373 return snprintf(page, PAGE_SIZE, "%d\n", to_nvmet_port(item)->enabled);
1376 static ssize_t nvmet_referral_enable_store(struct config_item *item,
1377 const char *page, size_t count)
1379 struct nvmet_port *parent = to_nvmet_port(item->ci_parent->ci_parent);
1380 struct nvmet_port *port = to_nvmet_port(item);
1383 if (strtobool(page, &enable))
1387 nvmet_referral_enable(parent, port);
1389 nvmet_referral_disable(parent, port);
1393 pr_err("Invalid value '%s' for enable\n", page);
1397 CONFIGFS_ATTR(nvmet_referral_, enable);
1400 * Discovery Service subsystem definitions
1402 static struct configfs_attribute *nvmet_referral_attrs[] = {
1403 &nvmet_attr_addr_adrfam,
1404 &nvmet_attr_addr_portid,
1405 &nvmet_attr_addr_treq,
1406 &nvmet_attr_addr_traddr,
1407 &nvmet_attr_addr_trsvcid,
1408 &nvmet_attr_addr_trtype,
1409 &nvmet_referral_attr_enable,
1413 static void nvmet_referral_notify(struct config_group *group,
1414 struct config_item *item)
1416 struct nvmet_port *parent = to_nvmet_port(item->ci_parent->ci_parent);
1417 struct nvmet_port *port = to_nvmet_port(item);
1419 nvmet_referral_disable(parent, port);
1422 static void nvmet_referral_release(struct config_item *item)
1424 struct nvmet_port *port = to_nvmet_port(item);
1429 static struct configfs_item_operations nvmet_referral_item_ops = {
1430 .release = nvmet_referral_release,
1433 static const struct config_item_type nvmet_referral_type = {
1434 .ct_owner = THIS_MODULE,
1435 .ct_attrs = nvmet_referral_attrs,
1436 .ct_item_ops = &nvmet_referral_item_ops,
1439 static struct config_group *nvmet_referral_make(
1440 struct config_group *group, const char *name)
1442 struct nvmet_port *port;
1444 port = kzalloc(sizeof(*port), GFP_KERNEL);
1446 return ERR_PTR(-ENOMEM);
1448 INIT_LIST_HEAD(&port->entry);
1449 config_group_init_type_name(&port->group, name, &nvmet_referral_type);
1451 return &port->group;
1454 static struct configfs_group_operations nvmet_referral_group_ops = {
1455 .make_group = nvmet_referral_make,
1456 .disconnect_notify = nvmet_referral_notify,
1459 static const struct config_item_type nvmet_referrals_type = {
1460 .ct_owner = THIS_MODULE,
1461 .ct_group_ops = &nvmet_referral_group_ops,
1464 static struct nvmet_type_name_map nvmet_ana_state[] = {
1465 { NVME_ANA_OPTIMIZED, "optimized" },
1466 { NVME_ANA_NONOPTIMIZED, "non-optimized" },
1467 { NVME_ANA_INACCESSIBLE, "inaccessible" },
1468 { NVME_ANA_PERSISTENT_LOSS, "persistent-loss" },
1469 { NVME_ANA_CHANGE, "change" },
1472 static ssize_t nvmet_ana_group_ana_state_show(struct config_item *item,
1475 struct nvmet_ana_group *grp = to_ana_group(item);
1476 enum nvme_ana_state state = grp->port->ana_state[grp->grpid];
1479 for (i = 0; i < ARRAY_SIZE(nvmet_ana_state); i++) {
1480 if (state == nvmet_ana_state[i].type)
1481 return sprintf(page, "%s\n", nvmet_ana_state[i].name);
1484 return sprintf(page, "\n");
1487 static ssize_t nvmet_ana_group_ana_state_store(struct config_item *item,
1488 const char *page, size_t count)
1490 struct nvmet_ana_group *grp = to_ana_group(item);
1491 enum nvme_ana_state *ana_state = grp->port->ana_state;
1494 for (i = 0; i < ARRAY_SIZE(nvmet_ana_state); i++) {
1495 if (sysfs_streq(page, nvmet_ana_state[i].name))
1499 pr_err("Invalid value '%s' for ana_state\n", page);
1503 down_write(&nvmet_ana_sem);
1504 ana_state[grp->grpid] = (enum nvme_ana_state) nvmet_ana_state[i].type;
1506 up_write(&nvmet_ana_sem);
1507 nvmet_port_send_ana_event(grp->port);
1511 CONFIGFS_ATTR(nvmet_ana_group_, ana_state);
1513 static struct configfs_attribute *nvmet_ana_group_attrs[] = {
1514 &nvmet_ana_group_attr_ana_state,
1518 static void nvmet_ana_group_release(struct config_item *item)
1520 struct nvmet_ana_group *grp = to_ana_group(item);
1522 if (grp == &grp->port->ana_default_group)
1525 down_write(&nvmet_ana_sem);
1526 grp->port->ana_state[grp->grpid] = NVME_ANA_INACCESSIBLE;
1527 nvmet_ana_group_enabled[grp->grpid]--;
1528 up_write(&nvmet_ana_sem);
1530 nvmet_port_send_ana_event(grp->port);
1534 static struct configfs_item_operations nvmet_ana_group_item_ops = {
1535 .release = nvmet_ana_group_release,
1538 static const struct config_item_type nvmet_ana_group_type = {
1539 .ct_item_ops = &nvmet_ana_group_item_ops,
1540 .ct_attrs = nvmet_ana_group_attrs,
1541 .ct_owner = THIS_MODULE,
1544 static struct config_group *nvmet_ana_groups_make_group(
1545 struct config_group *group, const char *name)
1547 struct nvmet_port *port = ana_groups_to_port(&group->cg_item);
1548 struct nvmet_ana_group *grp;
1552 ret = kstrtou32(name, 0, &grpid);
1557 if (grpid <= 1 || grpid > NVMET_MAX_ANAGRPS)
1561 grp = kzalloc(sizeof(*grp), GFP_KERNEL);
1567 down_write(&nvmet_ana_sem);
1568 nvmet_ana_group_enabled[grpid]++;
1569 up_write(&nvmet_ana_sem);
1571 nvmet_port_send_ana_event(grp->port);
1573 config_group_init_type_name(&grp->group, name, &nvmet_ana_group_type);
1576 return ERR_PTR(ret);
1579 static struct configfs_group_operations nvmet_ana_groups_group_ops = {
1580 .make_group = nvmet_ana_groups_make_group,
1583 static const struct config_item_type nvmet_ana_groups_type = {
1584 .ct_group_ops = &nvmet_ana_groups_group_ops,
1585 .ct_owner = THIS_MODULE,
1589 * Ports definitions.
1591 static void nvmet_port_release(struct config_item *item)
1593 struct nvmet_port *port = to_nvmet_port(item);
1595 /* Let inflight controllers teardown complete */
1596 flush_scheduled_work();
1597 list_del(&port->global_entry);
1599 kfree(port->ana_state);
1603 static struct configfs_attribute *nvmet_port_attrs[] = {
1604 &nvmet_attr_addr_adrfam,
1605 &nvmet_attr_addr_treq,
1606 &nvmet_attr_addr_traddr,
1607 &nvmet_attr_addr_trsvcid,
1608 &nvmet_attr_addr_trtype,
1609 &nvmet_attr_param_inline_data_size,
1610 #ifdef CONFIG_BLK_DEV_INTEGRITY
1611 &nvmet_attr_param_pi_enable,
1616 static struct configfs_item_operations nvmet_port_item_ops = {
1617 .release = nvmet_port_release,
1620 static const struct config_item_type nvmet_port_type = {
1621 .ct_attrs = nvmet_port_attrs,
1622 .ct_item_ops = &nvmet_port_item_ops,
1623 .ct_owner = THIS_MODULE,
1626 static struct config_group *nvmet_ports_make(struct config_group *group,
1629 struct nvmet_port *port;
1633 if (kstrtou16(name, 0, &portid))
1634 return ERR_PTR(-EINVAL);
1636 port = kzalloc(sizeof(*port), GFP_KERNEL);
1638 return ERR_PTR(-ENOMEM);
1640 port->ana_state = kcalloc(NVMET_MAX_ANAGRPS + 1,
1641 sizeof(*port->ana_state), GFP_KERNEL);
1642 if (!port->ana_state) {
1644 return ERR_PTR(-ENOMEM);
1647 for (i = 1; i <= NVMET_MAX_ANAGRPS; i++) {
1648 if (i == NVMET_DEFAULT_ANA_GRPID)
1649 port->ana_state[1] = NVME_ANA_OPTIMIZED;
1651 port->ana_state[i] = NVME_ANA_INACCESSIBLE;
1654 list_add(&port->global_entry, &nvmet_ports_list);
1656 INIT_LIST_HEAD(&port->entry);
1657 INIT_LIST_HEAD(&port->subsystems);
1658 INIT_LIST_HEAD(&port->referrals);
1659 port->inline_data_size = -1; /* < 0 == let the transport choose */
1661 port->disc_addr.portid = cpu_to_le16(portid);
1662 port->disc_addr.adrfam = NVMF_ADDR_FAMILY_MAX;
1663 port->disc_addr.treq = NVMF_TREQ_DISABLE_SQFLOW;
1664 config_group_init_type_name(&port->group, name, &nvmet_port_type);
1666 config_group_init_type_name(&port->subsys_group,
1667 "subsystems", &nvmet_port_subsys_type);
1668 configfs_add_default_group(&port->subsys_group, &port->group);
1670 config_group_init_type_name(&port->referrals_group,
1671 "referrals", &nvmet_referrals_type);
1672 configfs_add_default_group(&port->referrals_group, &port->group);
1674 config_group_init_type_name(&port->ana_groups_group,
1675 "ana_groups", &nvmet_ana_groups_type);
1676 configfs_add_default_group(&port->ana_groups_group, &port->group);
1678 port->ana_default_group.port = port;
1679 port->ana_default_group.grpid = NVMET_DEFAULT_ANA_GRPID;
1680 config_group_init_type_name(&port->ana_default_group.group,
1681 __stringify(NVMET_DEFAULT_ANA_GRPID),
1682 &nvmet_ana_group_type);
1683 configfs_add_default_group(&port->ana_default_group.group,
1684 &port->ana_groups_group);
1686 return &port->group;
1689 static struct configfs_group_operations nvmet_ports_group_ops = {
1690 .make_group = nvmet_ports_make,
1693 static const struct config_item_type nvmet_ports_type = {
1694 .ct_group_ops = &nvmet_ports_group_ops,
1695 .ct_owner = THIS_MODULE,
1698 static struct config_group nvmet_subsystems_group;
1699 static struct config_group nvmet_ports_group;
1701 static void nvmet_host_release(struct config_item *item)
1703 struct nvmet_host *host = to_host(item);
1708 static struct configfs_item_operations nvmet_host_item_ops = {
1709 .release = nvmet_host_release,
1712 static const struct config_item_type nvmet_host_type = {
1713 .ct_item_ops = &nvmet_host_item_ops,
1714 .ct_owner = THIS_MODULE,
1717 static struct config_group *nvmet_hosts_make_group(struct config_group *group,
1720 struct nvmet_host *host;
1722 host = kzalloc(sizeof(*host), GFP_KERNEL);
1724 return ERR_PTR(-ENOMEM);
1726 config_group_init_type_name(&host->group, name, &nvmet_host_type);
1728 return &host->group;
1731 static struct configfs_group_operations nvmet_hosts_group_ops = {
1732 .make_group = nvmet_hosts_make_group,
1735 static const struct config_item_type nvmet_hosts_type = {
1736 .ct_group_ops = &nvmet_hosts_group_ops,
1737 .ct_owner = THIS_MODULE,
1740 static struct config_group nvmet_hosts_group;
1742 static const struct config_item_type nvmet_root_type = {
1743 .ct_owner = THIS_MODULE,
1746 static struct configfs_subsystem nvmet_configfs_subsystem = {
1749 .ci_namebuf = "nvmet",
1750 .ci_type = &nvmet_root_type,
1755 int __init nvmet_init_configfs(void)
1759 config_group_init(&nvmet_configfs_subsystem.su_group);
1760 mutex_init(&nvmet_configfs_subsystem.su_mutex);
1762 config_group_init_type_name(&nvmet_subsystems_group,
1763 "subsystems", &nvmet_subsystems_type);
1764 configfs_add_default_group(&nvmet_subsystems_group,
1765 &nvmet_configfs_subsystem.su_group);
1767 config_group_init_type_name(&nvmet_ports_group,
1768 "ports", &nvmet_ports_type);
1769 configfs_add_default_group(&nvmet_ports_group,
1770 &nvmet_configfs_subsystem.su_group);
1772 config_group_init_type_name(&nvmet_hosts_group,
1773 "hosts", &nvmet_hosts_type);
1774 configfs_add_default_group(&nvmet_hosts_group,
1775 &nvmet_configfs_subsystem.su_group);
1777 ret = configfs_register_subsystem(&nvmet_configfs_subsystem);
1779 pr_err("configfs_register_subsystem: %d\n", ret);
1786 void __exit nvmet_exit_configfs(void)
1788 configfs_unregister_subsystem(&nvmet_configfs_subsystem);