Skip to content

Commit 1e48b34

Browse files
hreineckekeithbusch
authored andcommitted
nvme: split off TLS sysfs attributes into a separate group
Split off TLS sysfs attributes into a separate group to improve readability and to keep all TLS related handling in one section. Signed-off-by: Hannes Reinecke <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent c5f2ca5 commit 1e48b34

File tree

1 file changed

+41
-21
lines changed

1 file changed

+41
-21
lines changed

drivers/nvme/host/sysfs.c

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -664,19 +664,6 @@ static DEVICE_ATTR(dhchap_ctrl_secret, S_IRUGO | S_IWUSR,
664664
nvme_ctrl_dhchap_ctrl_secret_show, nvme_ctrl_dhchap_ctrl_secret_store);
665665
#endif
666666

667-
#ifdef CONFIG_NVME_TCP_TLS
668-
static ssize_t tls_key_show(struct device *dev,
669-
struct device_attribute *attr, char *buf)
670-
{
671-
struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
672-
673-
if (!ctrl->tls_pskid)
674-
return 0;
675-
return sysfs_emit(buf, "%08x\n", ctrl->tls_pskid);
676-
}
677-
static DEVICE_ATTR_RO(tls_key);
678-
#endif
679-
680667
static struct attribute *nvme_dev_attrs[] = {
681668
&dev_attr_reset_controller.attr,
682669
&dev_attr_rescan_controller.attr,
@@ -703,9 +690,6 @@ static struct attribute *nvme_dev_attrs[] = {
703690
#ifdef CONFIG_NVME_HOST_AUTH
704691
&dev_attr_dhchap_secret.attr,
705692
&dev_attr_dhchap_ctrl_secret.attr,
706-
#endif
707-
#ifdef CONFIG_NVME_TCP_TLS
708-
&dev_attr_tls_key.attr,
709693
#endif
710694
&dev_attr_adm_passthru_err_log_enabled.attr,
711695
NULL
@@ -737,11 +721,6 @@ static umode_t nvme_dev_attrs_are_visible(struct kobject *kobj,
737721
if (a == &dev_attr_dhchap_ctrl_secret.attr && !ctrl->opts)
738722
return 0;
739723
#endif
740-
#ifdef CONFIG_NVME_TCP_TLS
741-
if (a == &dev_attr_tls_key.attr &&
742-
(!ctrl->opts || strcmp(ctrl->opts->transport, "tcp")))
743-
return 0;
744-
#endif
745724

746725
return a->mode;
747726
}
@@ -752,8 +731,49 @@ const struct attribute_group nvme_dev_attrs_group = {
752731
};
753732
EXPORT_SYMBOL_GPL(nvme_dev_attrs_group);
754733

734+
#ifdef CONFIG_NVME_TCP_TLS
735+
static ssize_t tls_key_show(struct device *dev,
736+
struct device_attribute *attr, char *buf)
737+
{
738+
struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
739+
740+
if (!ctrl->tls_pskid)
741+
return 0;
742+
return sysfs_emit(buf, "%08x\n", ctrl->tls_pskid);
743+
}
744+
static DEVICE_ATTR_RO(tls_key);
745+
746+
static struct attribute *nvme_tls_attrs[] = {
747+
&dev_attr_tls_key.attr,
748+
};
749+
750+
static umode_t nvme_tls_attrs_are_visible(struct kobject *kobj,
751+
struct attribute *a, int n)
752+
{
753+
struct device *dev = container_of(kobj, struct device, kobj);
754+
struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
755+
756+
if (!ctrl->opts || strcmp(ctrl->opts->transport, "tcp"))
757+
return 0;
758+
759+
if (a == &dev_attr_tls_key.attr &&
760+
!ctrl->opts->tls)
761+
return 0;
762+
763+
return a->mode;
764+
}
765+
766+
const struct attribute_group nvme_tls_attrs_group = {
767+
.attrs = nvme_tls_attrs,
768+
.is_visible = nvme_tls_attrs_are_visible,
769+
};
770+
#endif
771+
755772
const struct attribute_group *nvme_dev_attr_groups[] = {
756773
&nvme_dev_attrs_group,
774+
#ifdef CONFIG_NVME_TCP_TLS
775+
&nvme_tls_attrs_group,
776+
#endif
757777
NULL,
758778
};
759779

0 commit comments

Comments
 (0)