2 * Configfs interface for the NVMe target.
3 * Copyright (c) 2015-2016 HGST, a Western Digital Company.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/slab.h>
18 #include <linux/stat.h>
19 #include <linux/ctype.h>
23 static struct config_item_type nvmet_host_type
;
24 static struct config_item_type nvmet_subsys_type
;
27 * nvmet_port Generic ConfigFS definitions.
28 * Used in any place in the ConfigFS tree that refers to an address.
30 static ssize_t
nvmet_addr_adrfam_show(struct config_item
*item
,
33 switch (to_nvmet_port(item
)->disc_addr
.adrfam
) {
34 case NVMF_ADDR_FAMILY_IP4
:
35 return sprintf(page
, "ipv4\n");
36 case NVMF_ADDR_FAMILY_IP6
:
37 return sprintf(page
, "ipv6\n");
38 case NVMF_ADDR_FAMILY_IB
:
39 return sprintf(page
, "ib\n");
40 case NVMF_ADDR_FAMILY_FC
:
41 return sprintf(page
, "fc\n");
43 return sprintf(page
, "\n");
47 static ssize_t
nvmet_addr_adrfam_store(struct config_item
*item
,
48 const char *page
, size_t count
)
50 struct nvmet_port
*port
= to_nvmet_port(item
);
53 pr_err("Cannot modify address while enabled\n");
54 pr_err("Disable the address before modifying\n");
58 if (sysfs_streq(page
, "ipv4")) {
59 port
->disc_addr
.adrfam
= NVMF_ADDR_FAMILY_IP4
;
60 } else if (sysfs_streq(page
, "ipv6")) {
61 port
->disc_addr
.adrfam
= NVMF_ADDR_FAMILY_IP6
;
62 } else if (sysfs_streq(page
, "ib")) {
63 port
->disc_addr
.adrfam
= NVMF_ADDR_FAMILY_IB
;
64 } else if (sysfs_streq(page
, "fc")) {
65 port
->disc_addr
.adrfam
= NVMF_ADDR_FAMILY_FC
;
67 pr_err("Invalid value '%s' for adrfam\n", page
);
74 CONFIGFS_ATTR(nvmet_
, addr_adrfam
);
76 static ssize_t
nvmet_addr_portid_show(struct config_item
*item
,
79 struct nvmet_port
*port
= to_nvmet_port(item
);
81 return snprintf(page
, PAGE_SIZE
, "%d\n",
82 le16_to_cpu(port
->disc_addr
.portid
));
85 static ssize_t
nvmet_addr_portid_store(struct config_item
*item
,
86 const char *page
, size_t count
)
88 struct nvmet_port
*port
= to_nvmet_port(item
);
91 if (kstrtou16(page
, 0, &portid
)) {
92 pr_err("Invalid value '%s' for portid\n", page
);
97 pr_err("Cannot modify address while enabled\n");
98 pr_err("Disable the address before modifying\n");
101 port
->disc_addr
.portid
= cpu_to_le16(portid
);
105 CONFIGFS_ATTR(nvmet_
, addr_portid
);
107 static ssize_t
nvmet_addr_traddr_show(struct config_item
*item
,
110 struct nvmet_port
*port
= to_nvmet_port(item
);
112 return snprintf(page
, PAGE_SIZE
, "%s\n",
113 port
->disc_addr
.traddr
);
116 static ssize_t
nvmet_addr_traddr_store(struct config_item
*item
,
117 const char *page
, size_t count
)
119 struct nvmet_port
*port
= to_nvmet_port(item
);
121 if (count
> NVMF_TRADDR_SIZE
) {
122 pr_err("Invalid value '%s' for traddr\n", page
);
127 pr_err("Cannot modify address while enabled\n");
128 pr_err("Disable the address before modifying\n");
131 return snprintf(port
->disc_addr
.traddr
,
132 sizeof(port
->disc_addr
.traddr
), "%s", page
);
135 CONFIGFS_ATTR(nvmet_
, addr_traddr
);
137 static ssize_t
nvmet_addr_treq_show(struct config_item
*item
,
140 switch (to_nvmet_port(item
)->disc_addr
.treq
) {
141 case NVMF_TREQ_NOT_SPECIFIED
:
142 return sprintf(page
, "not specified\n");
143 case NVMF_TREQ_REQUIRED
:
144 return sprintf(page
, "required\n");
145 case NVMF_TREQ_NOT_REQUIRED
:
146 return sprintf(page
, "not required\n");
148 return sprintf(page
, "\n");
152 static ssize_t
nvmet_addr_treq_store(struct config_item
*item
,
153 const char *page
, size_t count
)
155 struct nvmet_port
*port
= to_nvmet_port(item
);
158 pr_err("Cannot modify address while enabled\n");
159 pr_err("Disable the address before modifying\n");
163 if (sysfs_streq(page
, "not specified")) {
164 port
->disc_addr
.treq
= NVMF_TREQ_NOT_SPECIFIED
;
165 } else if (sysfs_streq(page
, "required")) {
166 port
->disc_addr
.treq
= NVMF_TREQ_REQUIRED
;
167 } else if (sysfs_streq(page
, "not required")) {
168 port
->disc_addr
.treq
= NVMF_TREQ_NOT_REQUIRED
;
170 pr_err("Invalid value '%s' for treq\n", page
);
177 CONFIGFS_ATTR(nvmet_
, addr_treq
);
179 static ssize_t
nvmet_addr_trsvcid_show(struct config_item
*item
,
182 struct nvmet_port
*port
= to_nvmet_port(item
);
184 return snprintf(page
, PAGE_SIZE
, "%s\n",
185 port
->disc_addr
.trsvcid
);
188 static ssize_t
nvmet_addr_trsvcid_store(struct config_item
*item
,
189 const char *page
, size_t count
)
191 struct nvmet_port
*port
= to_nvmet_port(item
);
193 if (count
> NVMF_TRSVCID_SIZE
) {
194 pr_err("Invalid value '%s' for trsvcid\n", page
);
198 pr_err("Cannot modify address while enabled\n");
199 pr_err("Disable the address before modifying\n");
202 return snprintf(port
->disc_addr
.trsvcid
,
203 sizeof(port
->disc_addr
.trsvcid
), "%s", page
);
206 CONFIGFS_ATTR(nvmet_
, addr_trsvcid
);
208 static ssize_t
nvmet_addr_trtype_show(struct config_item
*item
,
211 switch (to_nvmet_port(item
)->disc_addr
.trtype
) {
212 case NVMF_TRTYPE_RDMA
:
213 return sprintf(page
, "rdma\n");
214 case NVMF_TRTYPE_LOOP
:
215 return sprintf(page
, "loop\n");
217 return sprintf(page
, "fc\n");
219 return sprintf(page
, "\n");
223 static void nvmet_port_init_tsas_rdma(struct nvmet_port
*port
)
225 port
->disc_addr
.trtype
= NVMF_TRTYPE_RDMA
;
226 memset(&port
->disc_addr
.tsas
.rdma
, 0, NVMF_TSAS_SIZE
);
227 port
->disc_addr
.tsas
.rdma
.qptype
= NVMF_RDMA_QPTYPE_CONNECTED
;
228 port
->disc_addr
.tsas
.rdma
.prtype
= NVMF_RDMA_PRTYPE_NOT_SPECIFIED
;
229 port
->disc_addr
.tsas
.rdma
.cms
= NVMF_RDMA_CMS_RDMA_CM
;
232 static void nvmet_port_init_tsas_loop(struct nvmet_port
*port
)
234 port
->disc_addr
.trtype
= NVMF_TRTYPE_LOOP
;
235 memset(&port
->disc_addr
.tsas
, 0, NVMF_TSAS_SIZE
);
238 static void nvmet_port_init_tsas_fc(struct nvmet_port
*port
)
240 port
->disc_addr
.trtype
= NVMF_TRTYPE_FC
;
241 memset(&port
->disc_addr
.tsas
, 0, NVMF_TSAS_SIZE
);
244 static ssize_t
nvmet_addr_trtype_store(struct config_item
*item
,
245 const char *page
, size_t count
)
247 struct nvmet_port
*port
= to_nvmet_port(item
);
250 pr_err("Cannot modify address while enabled\n");
251 pr_err("Disable the address before modifying\n");
255 if (sysfs_streq(page
, "rdma")) {
256 nvmet_port_init_tsas_rdma(port
);
257 } else if (sysfs_streq(page
, "loop")) {
258 nvmet_port_init_tsas_loop(port
);
259 } else if (sysfs_streq(page
, "fc")) {
260 nvmet_port_init_tsas_fc(port
);
262 pr_err("Invalid value '%s' for trtype\n", page
);
269 CONFIGFS_ATTR(nvmet_
, addr_trtype
);
272 * Namespace structures & file operation functions below
274 static ssize_t
nvmet_ns_device_path_show(struct config_item
*item
, char *page
)
276 return sprintf(page
, "%s\n", to_nvmet_ns(item
)->device_path
);
279 static ssize_t
nvmet_ns_device_path_store(struct config_item
*item
,
280 const char *page
, size_t count
)
282 struct nvmet_ns
*ns
= to_nvmet_ns(item
);
283 struct nvmet_subsys
*subsys
= ns
->subsys
;
286 mutex_lock(&subsys
->lock
);
291 kfree(ns
->device_path
);
294 ns
->device_path
= kstrdup(page
, GFP_KERNEL
);
295 if (!ns
->device_path
)
298 mutex_unlock(&subsys
->lock
);
302 mutex_unlock(&subsys
->lock
);
306 CONFIGFS_ATTR(nvmet_ns_
, device_path
);
308 static ssize_t
nvmet_ns_device_nguid_show(struct config_item
*item
, char *page
)
310 return sprintf(page
, "%pUb\n", &to_nvmet_ns(item
)->nguid
);
313 static ssize_t
nvmet_ns_device_nguid_store(struct config_item
*item
,
314 const char *page
, size_t count
)
316 struct nvmet_ns
*ns
= to_nvmet_ns(item
);
317 struct nvmet_subsys
*subsys
= ns
->subsys
;
319 const char *p
= page
;
323 mutex_lock(&subsys
->lock
);
329 for (i
= 0; i
< 16; i
++) {
330 if (p
+ 2 > page
+ count
) {
334 if (!isxdigit(p
[0]) || !isxdigit(p
[1])) {
339 nguid
[i
] = (hex_to_bin(p
[0]) << 4) | hex_to_bin(p
[1]);
342 if (*p
== '-' || *p
== ':')
346 memcpy(&ns
->nguid
, nguid
, sizeof(nguid
));
348 mutex_unlock(&subsys
->lock
);
349 return ret
? ret
: count
;
352 CONFIGFS_ATTR(nvmet_ns_
, device_nguid
);
354 static ssize_t
nvmet_ns_enable_show(struct config_item
*item
, char *page
)
356 return sprintf(page
, "%d\n", to_nvmet_ns(item
)->enabled
);
359 static ssize_t
nvmet_ns_enable_store(struct config_item
*item
,
360 const char *page
, size_t count
)
362 struct nvmet_ns
*ns
= to_nvmet_ns(item
);
366 if (strtobool(page
, &enable
))
370 ret
= nvmet_ns_enable(ns
);
372 nvmet_ns_disable(ns
);
374 return ret
? ret
: count
;
377 CONFIGFS_ATTR(nvmet_ns_
, enable
);
379 static struct configfs_attribute
*nvmet_ns_attrs
[] = {
380 &nvmet_ns_attr_device_path
,
381 &nvmet_ns_attr_device_nguid
,
382 &nvmet_ns_attr_enable
,
386 static void nvmet_ns_release(struct config_item
*item
)
388 struct nvmet_ns
*ns
= to_nvmet_ns(item
);
393 static struct configfs_item_operations nvmet_ns_item_ops
= {
394 .release
= nvmet_ns_release
,
397 static struct config_item_type nvmet_ns_type
= {
398 .ct_item_ops
= &nvmet_ns_item_ops
,
399 .ct_attrs
= nvmet_ns_attrs
,
400 .ct_owner
= THIS_MODULE
,
403 static struct config_group
*nvmet_ns_make(struct config_group
*group
,
406 struct nvmet_subsys
*subsys
= namespaces_to_subsys(&group
->cg_item
);
411 ret
= kstrtou32(name
, 0, &nsid
);
416 if (nsid
== 0 || nsid
== 0xffffffff)
420 ns
= nvmet_ns_alloc(subsys
, nsid
);
423 config_group_init_type_name(&ns
->group
, name
, &nvmet_ns_type
);
425 pr_info("adding nsid %d to subsystem %s\n", nsid
, subsys
->subsysnqn
);
432 static struct configfs_group_operations nvmet_namespaces_group_ops
= {
433 .make_group
= nvmet_ns_make
,
436 static struct config_item_type nvmet_namespaces_type
= {
437 .ct_group_ops
= &nvmet_namespaces_group_ops
,
438 .ct_owner
= THIS_MODULE
,
441 static int nvmet_port_subsys_allow_link(struct config_item
*parent
,
442 struct config_item
*target
)
444 struct nvmet_port
*port
= to_nvmet_port(parent
->ci_parent
);
445 struct nvmet_subsys
*subsys
;
446 struct nvmet_subsys_link
*link
, *p
;
449 if (target
->ci_type
!= &nvmet_subsys_type
) {
450 pr_err("can only link subsystems into the subsystems dir.!\n");
453 subsys
= to_subsys(target
);
454 link
= kmalloc(sizeof(*link
), GFP_KERNEL
);
457 link
->subsys
= subsys
;
459 down_write(&nvmet_config_sem
);
461 list_for_each_entry(p
, &port
->subsystems
, entry
) {
462 if (p
->subsys
== subsys
)
466 if (list_empty(&port
->subsystems
)) {
467 ret
= nvmet_enable_port(port
);
472 list_add_tail(&link
->entry
, &port
->subsystems
);
474 up_write(&nvmet_config_sem
);
478 up_write(&nvmet_config_sem
);
483 static void nvmet_port_subsys_drop_link(struct config_item
*parent
,
484 struct config_item
*target
)
486 struct nvmet_port
*port
= to_nvmet_port(parent
->ci_parent
);
487 struct nvmet_subsys
*subsys
= to_subsys(target
);
488 struct nvmet_subsys_link
*p
;
490 down_write(&nvmet_config_sem
);
491 list_for_each_entry(p
, &port
->subsystems
, entry
) {
492 if (p
->subsys
== subsys
)
495 up_write(&nvmet_config_sem
);
501 if (list_empty(&port
->subsystems
))
502 nvmet_disable_port(port
);
503 up_write(&nvmet_config_sem
);
507 static struct configfs_item_operations nvmet_port_subsys_item_ops
= {
508 .allow_link
= nvmet_port_subsys_allow_link
,
509 .drop_link
= nvmet_port_subsys_drop_link
,
512 static struct config_item_type nvmet_port_subsys_type
= {
513 .ct_item_ops
= &nvmet_port_subsys_item_ops
,
514 .ct_owner
= THIS_MODULE
,
517 static int nvmet_allowed_hosts_allow_link(struct config_item
*parent
,
518 struct config_item
*target
)
520 struct nvmet_subsys
*subsys
= to_subsys(parent
->ci_parent
);
521 struct nvmet_host
*host
;
522 struct nvmet_host_link
*link
, *p
;
525 if (target
->ci_type
!= &nvmet_host_type
) {
526 pr_err("can only link hosts into the allowed_hosts directory!\n");
530 host
= to_host(target
);
531 link
= kmalloc(sizeof(*link
), GFP_KERNEL
);
536 down_write(&nvmet_config_sem
);
538 if (subsys
->allow_any_host
) {
539 pr_err("can't add hosts when allow_any_host is set!\n");
544 list_for_each_entry(p
, &subsys
->hosts
, entry
) {
545 if (!strcmp(nvmet_host_name(p
->host
), nvmet_host_name(host
)))
548 list_add_tail(&link
->entry
, &subsys
->hosts
);
550 up_write(&nvmet_config_sem
);
553 up_write(&nvmet_config_sem
);
558 static void nvmet_allowed_hosts_drop_link(struct config_item
*parent
,
559 struct config_item
*target
)
561 struct nvmet_subsys
*subsys
= to_subsys(parent
->ci_parent
);
562 struct nvmet_host
*host
= to_host(target
);
563 struct nvmet_host_link
*p
;
565 down_write(&nvmet_config_sem
);
566 list_for_each_entry(p
, &subsys
->hosts
, entry
) {
567 if (!strcmp(nvmet_host_name(p
->host
), nvmet_host_name(host
)))
570 up_write(&nvmet_config_sem
);
576 up_write(&nvmet_config_sem
);
580 static struct configfs_item_operations nvmet_allowed_hosts_item_ops
= {
581 .allow_link
= nvmet_allowed_hosts_allow_link
,
582 .drop_link
= nvmet_allowed_hosts_drop_link
,
585 static struct config_item_type nvmet_allowed_hosts_type
= {
586 .ct_item_ops
= &nvmet_allowed_hosts_item_ops
,
587 .ct_owner
= THIS_MODULE
,
590 static ssize_t
nvmet_subsys_attr_allow_any_host_show(struct config_item
*item
,
593 return snprintf(page
, PAGE_SIZE
, "%d\n",
594 to_subsys(item
)->allow_any_host
);
597 static ssize_t
nvmet_subsys_attr_allow_any_host_store(struct config_item
*item
,
598 const char *page
, size_t count
)
600 struct nvmet_subsys
*subsys
= to_subsys(item
);
604 if (strtobool(page
, &allow_any_host
))
607 down_write(&nvmet_config_sem
);
608 if (allow_any_host
&& !list_empty(&subsys
->hosts
)) {
609 pr_err("Can't set allow_any_host when explicit hosts are set!\n");
614 subsys
->allow_any_host
= allow_any_host
;
616 up_write(&nvmet_config_sem
);
617 return ret
? ret
: count
;
620 CONFIGFS_ATTR(nvmet_subsys_
, attr_allow_any_host
);
622 static struct configfs_attribute
*nvmet_subsys_attrs
[] = {
623 &nvmet_subsys_attr_attr_allow_any_host
,
628 * Subsystem structures & folder operation functions below
630 static void nvmet_subsys_release(struct config_item
*item
)
632 struct nvmet_subsys
*subsys
= to_subsys(item
);
634 nvmet_subsys_del_ctrls(subsys
);
635 nvmet_subsys_put(subsys
);
638 static struct configfs_item_operations nvmet_subsys_item_ops
= {
639 .release
= nvmet_subsys_release
,
642 static struct config_item_type nvmet_subsys_type
= {
643 .ct_item_ops
= &nvmet_subsys_item_ops
,
644 .ct_attrs
= nvmet_subsys_attrs
,
645 .ct_owner
= THIS_MODULE
,
648 static struct config_group
*nvmet_subsys_make(struct config_group
*group
,
651 struct nvmet_subsys
*subsys
;
653 if (sysfs_streq(name
, NVME_DISC_SUBSYS_NAME
)) {
654 pr_err("can't create discovery subsystem through configfs\n");
655 return ERR_PTR(-EINVAL
);
658 subsys
= nvmet_subsys_alloc(name
, NVME_NQN_NVME
);
660 return ERR_PTR(-ENOMEM
);
662 config_group_init_type_name(&subsys
->group
, name
, &nvmet_subsys_type
);
664 config_group_init_type_name(&subsys
->namespaces_group
,
665 "namespaces", &nvmet_namespaces_type
);
666 configfs_add_default_group(&subsys
->namespaces_group
, &subsys
->group
);
668 config_group_init_type_name(&subsys
->allowed_hosts_group
,
669 "allowed_hosts", &nvmet_allowed_hosts_type
);
670 configfs_add_default_group(&subsys
->allowed_hosts_group
,
673 return &subsys
->group
;
676 static struct configfs_group_operations nvmet_subsystems_group_ops
= {
677 .make_group
= nvmet_subsys_make
,
680 static struct config_item_type nvmet_subsystems_type
= {
681 .ct_group_ops
= &nvmet_subsystems_group_ops
,
682 .ct_owner
= THIS_MODULE
,
685 static ssize_t
nvmet_referral_enable_show(struct config_item
*item
,
688 return snprintf(page
, PAGE_SIZE
, "%d\n", to_nvmet_port(item
)->enabled
);
691 static ssize_t
nvmet_referral_enable_store(struct config_item
*item
,
692 const char *page
, size_t count
)
694 struct nvmet_port
*parent
= to_nvmet_port(item
->ci_parent
->ci_parent
);
695 struct nvmet_port
*port
= to_nvmet_port(item
);
698 if (strtobool(page
, &enable
))
702 nvmet_referral_enable(parent
, port
);
704 nvmet_referral_disable(port
);
708 pr_err("Invalid value '%s' for enable\n", page
);
712 CONFIGFS_ATTR(nvmet_referral_
, enable
);
715 * Discovery Service subsystem definitions
717 static struct configfs_attribute
*nvmet_referral_attrs
[] = {
718 &nvmet_attr_addr_adrfam
,
719 &nvmet_attr_addr_portid
,
720 &nvmet_attr_addr_treq
,
721 &nvmet_attr_addr_traddr
,
722 &nvmet_attr_addr_trsvcid
,
723 &nvmet_attr_addr_trtype
,
724 &nvmet_referral_attr_enable
,
728 static void nvmet_referral_release(struct config_item
*item
)
730 struct nvmet_port
*port
= to_nvmet_port(item
);
732 nvmet_referral_disable(port
);
736 static struct configfs_item_operations nvmet_referral_item_ops
= {
737 .release
= nvmet_referral_release
,
740 static struct config_item_type nvmet_referral_type
= {
741 .ct_owner
= THIS_MODULE
,
742 .ct_attrs
= nvmet_referral_attrs
,
743 .ct_item_ops
= &nvmet_referral_item_ops
,
746 static struct config_group
*nvmet_referral_make(
747 struct config_group
*group
, const char *name
)
749 struct nvmet_port
*port
;
751 port
= kzalloc(sizeof(*port
), GFP_KERNEL
);
753 return ERR_PTR(-ENOMEM
);
755 INIT_LIST_HEAD(&port
->entry
);
756 config_group_init_type_name(&port
->group
, name
, &nvmet_referral_type
);
761 static struct configfs_group_operations nvmet_referral_group_ops
= {
762 .make_group
= nvmet_referral_make
,
765 static struct config_item_type nvmet_referrals_type
= {
766 .ct_owner
= THIS_MODULE
,
767 .ct_group_ops
= &nvmet_referral_group_ops
,
773 static void nvmet_port_release(struct config_item
*item
)
775 struct nvmet_port
*port
= to_nvmet_port(item
);
780 static struct configfs_attribute
*nvmet_port_attrs
[] = {
781 &nvmet_attr_addr_adrfam
,
782 &nvmet_attr_addr_treq
,
783 &nvmet_attr_addr_traddr
,
784 &nvmet_attr_addr_trsvcid
,
785 &nvmet_attr_addr_trtype
,
789 static struct configfs_item_operations nvmet_port_item_ops
= {
790 .release
= nvmet_port_release
,
793 static struct config_item_type nvmet_port_type
= {
794 .ct_attrs
= nvmet_port_attrs
,
795 .ct_item_ops
= &nvmet_port_item_ops
,
796 .ct_owner
= THIS_MODULE
,
799 static struct config_group
*nvmet_ports_make(struct config_group
*group
,
802 struct nvmet_port
*port
;
805 if (kstrtou16(name
, 0, &portid
))
806 return ERR_PTR(-EINVAL
);
808 port
= kzalloc(sizeof(*port
), GFP_KERNEL
);
810 return ERR_PTR(-ENOMEM
);
812 INIT_LIST_HEAD(&port
->entry
);
813 INIT_LIST_HEAD(&port
->subsystems
);
814 INIT_LIST_HEAD(&port
->referrals
);
816 port
->disc_addr
.portid
= cpu_to_le16(portid
);
817 config_group_init_type_name(&port
->group
, name
, &nvmet_port_type
);
819 config_group_init_type_name(&port
->subsys_group
,
820 "subsystems", &nvmet_port_subsys_type
);
821 configfs_add_default_group(&port
->subsys_group
, &port
->group
);
823 config_group_init_type_name(&port
->referrals_group
,
824 "referrals", &nvmet_referrals_type
);
825 configfs_add_default_group(&port
->referrals_group
, &port
->group
);
830 static struct configfs_group_operations nvmet_ports_group_ops
= {
831 .make_group
= nvmet_ports_make
,
834 static struct config_item_type nvmet_ports_type
= {
835 .ct_group_ops
= &nvmet_ports_group_ops
,
836 .ct_owner
= THIS_MODULE
,
839 static struct config_group nvmet_subsystems_group
;
840 static struct config_group nvmet_ports_group
;
842 static void nvmet_host_release(struct config_item
*item
)
844 struct nvmet_host
*host
= to_host(item
);
849 static struct configfs_item_operations nvmet_host_item_ops
= {
850 .release
= nvmet_host_release
,
853 static struct config_item_type nvmet_host_type
= {
854 .ct_item_ops
= &nvmet_host_item_ops
,
855 .ct_owner
= THIS_MODULE
,
858 static struct config_group
*nvmet_hosts_make_group(struct config_group
*group
,
861 struct nvmet_host
*host
;
863 host
= kzalloc(sizeof(*host
), GFP_KERNEL
);
865 return ERR_PTR(-ENOMEM
);
867 config_group_init_type_name(&host
->group
, name
, &nvmet_host_type
);
872 static struct configfs_group_operations nvmet_hosts_group_ops
= {
873 .make_group
= nvmet_hosts_make_group
,
876 static struct config_item_type nvmet_hosts_type
= {
877 .ct_group_ops
= &nvmet_hosts_group_ops
,
878 .ct_owner
= THIS_MODULE
,
881 static struct config_group nvmet_hosts_group
;
883 static struct config_item_type nvmet_root_type
= {
884 .ct_owner
= THIS_MODULE
,
887 static struct configfs_subsystem nvmet_configfs_subsystem
= {
890 .ci_namebuf
= "nvmet",
891 .ci_type
= &nvmet_root_type
,
896 int __init
nvmet_init_configfs(void)
900 config_group_init(&nvmet_configfs_subsystem
.su_group
);
901 mutex_init(&nvmet_configfs_subsystem
.su_mutex
);
903 config_group_init_type_name(&nvmet_subsystems_group
,
904 "subsystems", &nvmet_subsystems_type
);
905 configfs_add_default_group(&nvmet_subsystems_group
,
906 &nvmet_configfs_subsystem
.su_group
);
908 config_group_init_type_name(&nvmet_ports_group
,
909 "ports", &nvmet_ports_type
);
910 configfs_add_default_group(&nvmet_ports_group
,
911 &nvmet_configfs_subsystem
.su_group
);
913 config_group_init_type_name(&nvmet_hosts_group
,
914 "hosts", &nvmet_hosts_type
);
915 configfs_add_default_group(&nvmet_hosts_group
,
916 &nvmet_configfs_subsystem
.su_group
);
918 ret
= configfs_register_subsystem(&nvmet_configfs_subsystem
);
920 pr_err("configfs_register_subsystem: %d\n", ret
);
927 void __exit
nvmet_exit_configfs(void)
929 configfs_unregister_subsystem(&nvmet_configfs_subsystem
);