[PATCH V6] nvme-core: use xarray for ctrl ns tracking
Chaitanya Kulkarni
Chaitanya.Kulkarni at wdc.com
Wed Jun 9 20:53:21 PDT 2021
On 6/9/21 13:48, Chaitanya Kulkarni wrote:
>>>
>>> static int nvme_scan_ns_list(struct nvme_ctrl *ctrl)
>>> @@ -4068,10 +4051,6 @@ static void nvme_scan_work(struct work_struct *work)
>>> if (nvme_scan_ns_list(ctrl) != 0)
>>> nvme_scan_ns_sequential(ctrl);
>>> mutex_unlock(&ctrl->scan_lock);
>>> -
>>> - down_write(&ctrl->namespaces_rwsem);
>>> - list_sort(NULL, &ctrl->namespaces, ns_cmp);
>>> - up_write(&ctrl->namespaces_rwsem);
>> Is xarray sorted by nsid? ana updates rely on ctrl->namespaces to be
>> sorted. Where is nvme_update_ana_state change anyway? you tested this
>> without CONFIG_NVME_MULTIPATH?
>>
We insert the code ns into xarray with nsid as index so there is 1:1 mapping
between the ns, nsid, and the array index. Given that it is an array in
iteration it always starts with the first element. Hence no sorting is
needed.
To check the correctness of the code (with multipath enabled) I used the
quick
debug.patch [1] and here is the the output [2].
nvme: print all the ns in id-ns from xarray
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 6fdbb0a22f3b..1f33fd46bf34 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -1425,6 +1425,8 @@ static int nvme_identify_ns(struct nvme_ctrl
*ctrl, unsigned nsid,
{
struct nvme_command c = { };
int error;
+ struct nvme_ns *ns;
+ unsigned long idx;
/* gcc-4.4.4 (at least) has issues with initializers and anon
unions */
c.identify.opcode = nvme_admin_identify;
@@ -1452,6 +1454,10 @@ static int nvme_identify_ns(struct nvme_ctrl
*ctrl, unsigned nsid,
!memchr_inv(ids->nguid, 0, sizeof(ids->nguid)))
memcpy(ids->nguid, (*id)->nguid, sizeof(ids->nguid));
+ xa_for_each(&ctrl->namespaces, idx, ns)
+ pr_info("%s %d nsid %d\n", __func__, __LINE__,
ns->head->ns_id);
+
+ pr_info("%s %d------------------------------", __func__, __LINE__);
return 0;
out_free_id:
Creation of the bdev controller with xarray (/dev/nvme1) and using that
as an
input to the passthru controller (/dev/nvme2), iterating over the xarray and
printing all the elements. All the ns are printed in sorted manner for the
passthru controller :-
[ 229.877166] nvmet: creating controller 2 for subsystem pt-nqn for NQN
nqn.2014-08.org.nvmexpress:uuid:e4cfc949-8f19-4db2-a232-ab360b79204a.
[ 229.880143] nvme nvme2: creating 64 I/O queues.
[ 229.901741] nvme nvme2: new ctrl: "pt-nqn"
[ 229.902230] nvme_identify_ns 1460------------------------------
[ 229.932624] nvme_identify_ns 1458 nsid 1
[ 229.932634] nvme_identify_ns 1460------------------------------
[ 229.961368] nvme_identify_ns 1458 nsid 1
[ 229.961375] nvme_identify_ns 1458 nsid 2
[ 229.961381] nvme_identify_ns 1460------------------------------
[ 229.986053] nvme_identify_ns 1458 nsid 1
[ 229.986060] nvme_identify_ns 1458 nsid 2
[ 229.986063] nvme_identify_ns 1458 nsid 3
[ 229.986068] nvme_identify_ns 1460------------------------------
[ 230.010679] nvme_identify_ns 1458 nsid 1
[ 230.010686] nvme_identify_ns 1458 nsid 2
[ 230.010689] nvme_identify_ns 1458 nsid 3
[ 230.010691] nvme_identify_ns 1458 nsid 4
[ 230.010696] nvme_identify_ns 1460------------------------------
[ 230.034748] nvme_identify_ns 1458 nsid 1
[ 230.034755] nvme_identify_ns 1458 nsid 2
[ 230.034758] nvme_identify_ns 1458 nsid 3
[ 230.034761] nvme_identify_ns 1458 nsid 4
[ 230.034763] nvme_identify_ns 1458 nsid 5
[ 230.034769] nvme_identify_ns 1460------------------------------
[ 230.058996] nvme_identify_ns 1458 nsid 1
[ 230.059003] nvme_identify_ns 1458 nsid 2
[ 230.059006] nvme_identify_ns 1458 nsid 3
[ 230.059009] nvme_identify_ns 1458 nsid 4
[ 230.059012] nvme_identify_ns 1458 nsid 5
[ 230.059014] nvme_identify_ns 1458 nsid 6
[ 230.059019] nvme_identify_ns 1460------------------------------
[ 230.083433] nvme_identify_ns 1458 nsid 1
[ 230.083440] nvme_identify_ns 1458 nsid 2
[ 230.083443] nvme_identify_ns 1458 nsid 3
[ 230.083446] nvme_identify_ns 1458 nsid 4
[ 230.083450] nvme_identify_ns 1458 nsid 5
[ 230.083452] nvme_identify_ns 1458 nsid 6
[ 230.083455] nvme_identify_ns 1458 nsid 7
[ 230.083459] nvme_identify_ns 1460------------------------------
[ 230.107702] nvme_identify_ns 1458 nsid 1
[ 230.107709] nvme_identify_ns 1458 nsid 2
[ 230.107744] nvme_identify_ns 1458 nsid 3
[ 230.107748] nvme_identify_ns 1458 nsid 4
[ 230.107751] nvme_identify_ns 1458 nsid 5
[ 230.107754] nvme_identify_ns 1458 nsid 6
[ 230.107756] nvme_identify_ns 1458 nsid 7
[ 230.107758] nvme_identify_ns 1458 nsid 8
[ 230.107763] nvme_identify_ns 1460------------------------------
[ 230.132132] nvme_identify_ns 1458 nsid 1
[ 230.132139] nvme_identify_ns 1458 nsid 2
[ 230.132141] nvme_identify_ns 1458 nsid 3
[ 230.132144] nvme_identify_ns 1458 nsid 4
[ 230.132147] nvme_identify_ns 1458 nsid 5
[ 230.132149] nvme_identify_ns 1458 nsid 6
[ 230.132152] nvme_identify_ns 1458 nsid 7
[ 230.132154] nvme_identify_ns 1458 nsid 8
[ 230.132156] nvme_identify_ns 1458 nsid 9
Now disable the 5th and 8th namespace from target that should leave nid
5 & 8
but rest of the namespaces should be printed in the ascending order
in the ns rescan sequence :-
# echo 0 > /sys/kernel/config/nvmet/subsystems/x/namespaces/5/enable
# echo 0 > /sys/kernel/config/nvmet/subsystems/x/namespaces/8/enable
[ 620.836412] nvme nvme1: rescanning namespaces.
[ 620.836985] nvme_identify_ns 1458 nsid 1
[ 620.836993] nvme_identify_ns 1458 nsid 2
[ 620.836998] nvme_identify_ns 1458 nsid 3
[ 620.837003] nvme_identify_ns 1458 nsid 4
[ 620.837007] nvme_identify_ns 1458 nsid 6
[ 620.837012] nvme_identify_ns 1458 nsid 7
[ 620.837017] nvme_identify_ns 1458 nsid 8
[ 620.837021] nvme_identify_ns 1458 nsid 9
[ 620.837026] nvme_identify_ns 1458 nsid 10
[ 620.837034] nvme_identify_ns 1460------------------------------
[ 620.857901] nvme_identify_ns 1458 nsid 1
[ 620.857909] nvme_identify_ns 1458 nsid 2
[ 620.857913] nvme_identify_ns 1458 nsid 3
[ 620.857929] nvme_identify_ns 1458 nsid 4
[ 620.857933] nvme_identify_ns 1458 nsid 6
[ 620.857937] nvme_identify_ns 1458 nsid 7
[ 620.857940] nvme_identify_ns 1458 nsid 8
[ 620.857944] nvme_identify_ns 1458 nsid 9
[ 620.857948] nvme_identify_ns 1458 nsid 10
[ 620.857956] nvme_identify_ns 1460------------------------------
[ 620.873913] nvme_identify_ns 1458 nsid 1
[ 620.873921] nvme_identify_ns 1458 nsid 2
[ 620.873925] nvme_identify_ns 1458 nsid 3
[ 620.873939] nvme_identify_ns 1458 nsid 4
[ 620.873943] nvme_identify_ns 1458 nsid 6
[ 620.873947] nvme_identify_ns 1458 nsid 7
[ 620.873951] nvme_identify_ns 1458 nsid 8
[ 620.873955] nvme_identify_ns 1458 nsid 9
[ 620.873960] nvme_identify_ns 1458 nsid 10
[ 620.873969] nvme_identify_ns 1460------------------------------
[ 620.887976] nvme_identify_ns 1458 nsid 1
[ 620.887983] nvme_identify_ns 1458 nsid 2
[ 620.887988] nvme_identify_ns 1458 nsid 3
[ 620.887991] nvme_identify_ns 1458 nsid 4
[ 620.887995] nvme_identify_ns 1458 nsid 6
[ 620.887999] nvme_identify_ns 1458 nsid 7
[ 620.888002] nvme_identify_ns 1458 nsid 8
[ 620.888006] nvme_identify_ns 1458 nsid 9
[ 620.888010] nvme_identify_ns 1458 nsid 10
[ 620.888018] nvme_identify_ns 1460------------------------------
[ 620.901911] nvme_identify_ns 1458 nsid 1
[ 620.901919] nvme_identify_ns 1458 nsid 2
[ 620.901924] nvme_identify_ns 1458 nsid 3
[ 620.901928] nvme_identify_ns 1458 nsid 4
[ 620.901932] nvme_identify_ns 1458 nsid 6
[ 620.901936] nvme_identify_ns 1458 nsid 7
[ 620.901941] nvme_identify_ns 1458 nsid 8
[ 620.901945] nvme_identify_ns 1458 nsid 9
[ 620.901948] nvme_identify_ns 1458 nsid 10
[ 620.901957] nvme_identify_ns 1460------------------------------
[ 620.919913] nvme_identify_ns 1458 nsid 1
[ 620.919921] nvme_identify_ns 1458 nsid 2
[ 620.919926] nvme_identify_ns 1458 nsid 3
[ 620.919930] nvme_identify_ns 1458 nsid 4
[ 620.919934] nvme_identify_ns 1458 nsid 6
[ 620.919938] nvme_identify_ns 1458 nsid 7
[ 620.919942] nvme_identify_ns 1458 nsid 8
[ 620.919946] nvme_identify_ns 1458 nsid 9
[ 620.919950] nvme_identify_ns 1458 nsid 10
[ 620.919959] nvme_identify_ns 1460------------------------------
[ 620.933910] nvme_identify_ns 1458 nsid 1
[ 620.933918] nvme_identify_ns 1458 nsid 2
[ 620.933923] nvme_identify_ns 1458 nsid 3
[ 620.933927] nvme_identify_ns 1458 nsid 4
[ 620.933931] nvme_identify_ns 1458 nsid 6
[ 620.933935] nvme_identify_ns 1458 nsid 7
[ 620.933939] nvme_identify_ns 1458 nsid 8
[ 620.933943] nvme_identify_ns 1458 nsid 9
[ 620.933947] nvme_identify_ns 1458 nsid 10
[ 620.933956] nvme_identify_ns 1460------------------------------
[ 621.022320] nvme_identify_ns 1458 nsid 1
[ 621.022330] nvme_identify_ns 1458 nsid 2
[ 621.022335] nvme_identify_ns 1458 nsid 3
[ 621.022340] nvme_identify_ns 1458 nsid 4
[ 621.022344] nvme_identify_ns 1458 nsid 6
[ 621.022348] nvme_identify_ns 1458 nsid 7
[ 621.022352] nvme_identify_ns 1458 nsid 9
[ 621.022355] nvme_identify_ns 1458 nsid 10
Hope this answers your questions.
More information about the Linux-nvme
mailing list