@@ -422,7 +422,7 @@ static bool nvme_available_path(struct nvme_ns_head *head)
422422 struct nvme_ns * ns ;
423423
424424 if (!test_bit (NVME_NSHEAD_DISK_LIVE , & head -> flags ))
425- return NULL ;
425+ return false ;
426426
427427 list_for_each_entry_srcu (ns , & head -> list , siblings ,
428428 srcu_read_lock_held (& head -> srcu )) {
@@ -683,6 +683,8 @@ static void nvme_mpath_set_live(struct nvme_ns *ns)
683683 kblockd_schedule_work (& head -> partition_scan_work );
684684 }
685685
686+ nvme_mpath_add_sysfs_link (ns -> head );
687+
686688 mutex_lock (& head -> lock );
687689 if (nvme_path_is_optimized (ns )) {
688690 int node , srcu_idx ;
@@ -765,6 +767,25 @@ static void nvme_update_ns_ana_state(struct nvme_ana_group_desc *desc,
765767 if (nvme_state_is_live (ns -> ana_state ) &&
766768 nvme_ctrl_state (ns -> ctrl ) == NVME_CTRL_LIVE )
767769 nvme_mpath_set_live (ns );
770+ else {
771+ /*
772+ * Add sysfs link from multipath head gendisk node to path
773+ * device gendisk node.
774+ * If path's ana state is live (i.e. state is either optimized
775+ * or non-optimized) while we alloc the ns then sysfs link would
776+ * be created from nvme_mpath_set_live(). In that case we would
777+ * not fallthrough this code path. However for the path's ana
778+ * state other than live, we call nvme_mpath_set_live() only
779+ * after ana state transitioned to the live state. But we still
780+ * want to create the sysfs link from head node to a path device
781+ * irrespctive of the path's ana state.
782+ * If we reach through here then it means that path's ana state
783+ * is not live but still create the sysfs link to this path from
784+ * head node if head node of the path has already come alive.
785+ */
786+ if (test_bit (NVME_NSHEAD_DISK_LIVE , & ns -> head -> flags ))
787+ nvme_mpath_add_sysfs_link (ns -> head );
788+ }
768789}
769790
770791static int nvme_update_ana_state (struct nvme_ctrl * ctrl ,
@@ -952,6 +973,45 @@ static ssize_t ana_state_show(struct device *dev, struct device_attribute *attr,
952973}
953974DEVICE_ATTR_RO (ana_state );
954975
976+ static ssize_t queue_depth_show (struct device * dev ,
977+ struct device_attribute * attr , char * buf )
978+ {
979+ struct nvme_ns * ns = nvme_get_ns_from_dev (dev );
980+
981+ if (ns -> head -> subsys -> iopolicy != NVME_IOPOLICY_QD )
982+ return 0 ;
983+
984+ return sysfs_emit (buf , "%d\n" , atomic_read (& ns -> ctrl -> nr_active ));
985+ }
986+ DEVICE_ATTR_RO (queue_depth );
987+
988+ static ssize_t numa_nodes_show (struct device * dev , struct device_attribute * attr ,
989+ char * buf )
990+ {
991+ int node , srcu_idx ;
992+ nodemask_t numa_nodes ;
993+ struct nvme_ns * current_ns ;
994+ struct nvme_ns * ns = nvme_get_ns_from_dev (dev );
995+ struct nvme_ns_head * head = ns -> head ;
996+
997+ if (head -> subsys -> iopolicy != NVME_IOPOLICY_NUMA )
998+ return 0 ;
999+
1000+ nodes_clear (numa_nodes );
1001+
1002+ srcu_idx = srcu_read_lock (& head -> srcu );
1003+ for_each_node (node ) {
1004+ current_ns = srcu_dereference (head -> current_path [node ],
1005+ & head -> srcu );
1006+ if (ns == current_ns )
1007+ node_set (node , numa_nodes );
1008+ }
1009+ srcu_read_unlock (& head -> srcu , srcu_idx );
1010+
1011+ return sysfs_emit (buf , "%*pbl\n" , nodemask_pr_args (& numa_nodes ));
1012+ }
1013+ DEVICE_ATTR_RO (numa_nodes );
1014+
9551015static int nvme_lookup_ana_group_desc (struct nvme_ctrl * ctrl ,
9561016 struct nvme_ana_group_desc * desc , void * data )
9571017{
@@ -964,6 +1024,84 @@ static int nvme_lookup_ana_group_desc(struct nvme_ctrl *ctrl,
9641024 return - ENXIO ; /* just break out of the loop */
9651025}
9661026
1027+ void nvme_mpath_add_sysfs_link (struct nvme_ns_head * head )
1028+ {
1029+ struct device * target ;
1030+ int rc , srcu_idx ;
1031+ struct nvme_ns * ns ;
1032+ struct kobject * kobj ;
1033+
1034+ /*
1035+ * Ensure head disk node is already added otherwise we may get invalid
1036+ * kobj for head disk node
1037+ */
1038+ if (!test_bit (GD_ADDED , & head -> disk -> state ))
1039+ return ;
1040+
1041+ kobj = & disk_to_dev (head -> disk )-> kobj ;
1042+
1043+ /*
1044+ * loop through each ns chained through the head->list and create the
1045+ * sysfs link from head node to the ns path node
1046+ */
1047+ srcu_idx = srcu_read_lock (& head -> srcu );
1048+
1049+ list_for_each_entry_rcu (ns , & head -> list , siblings ) {
1050+ /*
1051+ * Ensure that ns path disk node is already added otherwise we
1052+ * may get invalid kobj name for target
1053+ */
1054+ if (!test_bit (GD_ADDED , & ns -> disk -> state ))
1055+ continue ;
1056+
1057+ /*
1058+ * Avoid creating link if it already exists for the given path.
1059+ * When path ana state transitions from optimized to non-
1060+ * optimized or vice-versa, the nvme_mpath_set_live() is
1061+ * invoked which in truns call this function. Now if the sysfs
1062+ * link already exists for the given path and we attempt to re-
1063+ * create the link then sysfs code would warn about it loudly.
1064+ * So we evaluate NVME_NS_SYSFS_ATTR_LINK flag here to ensure
1065+ * that we're not creating duplicate link.
1066+ * The test_and_set_bit() is used because it is protecting
1067+ * against multiple nvme paths being simultaneously added.
1068+ */
1069+ if (test_and_set_bit (NVME_NS_SYSFS_ATTR_LINK , & ns -> flags ))
1070+ continue ;
1071+
1072+ target = disk_to_dev (ns -> disk );
1073+ /*
1074+ * Create sysfs link from head gendisk kobject @kobj to the
1075+ * ns path gendisk kobject @target->kobj.
1076+ */
1077+ rc = sysfs_add_link_to_group (kobj , nvme_ns_mpath_attr_group .name ,
1078+ & target -> kobj , dev_name (target ));
1079+ if (unlikely (rc )) {
1080+ dev_err (disk_to_dev (ns -> head -> disk ),
1081+ "failed to create link to %s\n" ,
1082+ dev_name (target ));
1083+ clear_bit (NVME_NS_SYSFS_ATTR_LINK , & ns -> flags );
1084+ }
1085+ }
1086+
1087+ srcu_read_unlock (& head -> srcu , srcu_idx );
1088+ }
1089+
1090+ void nvme_mpath_remove_sysfs_link (struct nvme_ns * ns )
1091+ {
1092+ struct device * target ;
1093+ struct kobject * kobj ;
1094+
1095+ if (!test_bit (NVME_NS_SYSFS_ATTR_LINK , & ns -> flags ))
1096+ return ;
1097+
1098+ target = disk_to_dev (ns -> disk );
1099+ kobj = & disk_to_dev (ns -> head -> disk )-> kobj ;
1100+ sysfs_remove_link_from_group (kobj , nvme_ns_mpath_attr_group .name ,
1101+ dev_name (target ));
1102+ clear_bit (NVME_NS_SYSFS_ATTR_LINK , & ns -> flags );
1103+ }
1104+
9671105void nvme_mpath_add_disk (struct nvme_ns * ns , __le32 anagrpid )
9681106{
9691107 if (nvme_ctrl_use_ana (ns -> ctrl )) {
0 commit comments