libndctl/inject: Refuse error injection for BTT namespaces
Vishal Verma
maintainerPATCH 1/1 libndctl/inject: Refuse error injection for BTT namespaces
Error injection on a BTT namespace would treat the namespace as 'raw' for the purposes of the injection. This can be useful for development, but to a user this can be surprising, as injecting with --block=1 would corrupt the BTT info block, and the BTT would be lost.
The unit tests do not rely on injecting errors directly into a BTT namespace - they convert the namespace to 'raw' mode before performing such an injection. For development and testing purposes, we will still retain this ability by enforcing that the BTT namespace be explicitly forced into raw mode before injection.
--- ndctl/lib/inject.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-)
ndctl/lib/inject.c +24 -9
@@ -34,28 +34,36 @@ NDCTL_EXPORT int ndctl_bus_has_error_injection(struct ndctl_bus *bus)return 0 ; } -static void ndctl_namespace_get_injection_bounds ( +static int ndctl_namespace_get_injection_bounds (struct ndctl_namespace *ndns,unsigned long long *ns_offset,unsigned long long *ns_size) {struct ndctl_pfn *pfn =ndctl_namespace_get_pfn (ndns);struct ndctl_dax *dax =ndctl_namespace_get_dax (ndns); +struct ndctl_btt *btt =ndctl_namespace_get_btt (ndns);if (!ns_offset || !ns_size) -return ; +return -ENXIO ;if (pfn) { *ns_offset =ndctl_pfn_get_resource (pfn); *ns_size =ndctl_pfn_get_size (pfn); -return ; - }else if (dax) { +return 0 ; + } + +if (dax) { *ns_offset =ndctl_dax_get_resource (dax); *ns_size =ndctl_dax_get_size (dax); -return ; +return 0 ; } -/* raw or btt */ + +if (btt) +return -EOPNOTSUPP ; + +/* raw */ *ns_offset =ndctl_namespace_get_resource (ndns); *ns_size =ndctl_namespace_get_size (ndns); +return 0 ; } static int block_to_spa_offset(struct ndctl_namespace *ndns,
@@ -64,8 +72,11 @@ static int block_to_spa_offset(struct ndctl_namespace *ndns, {struct ndctl_ctx *ctx =ndctl_namespace_get_ctx (ndns);unsigned long long ns_offset, ns_size; +int rc; -ndctl_namespace_get_injection_bounds (ndns, &ns_offset, &ns_size); + rc =ndctl_namespace_get_injection_bounds (ndns, &ns_offset, &ns_size); +if (rc) +return rc; *offset = ns_offset + block *512 ; *length = count *512 ;
@@ -98,8 +109,10 @@ static int ndctl_namespace_get_clear_unit(struct ndctl_namespace *ndns)struct ndctl_cmd *cmd;int rc; -ndctl_namespace_get_injection_bounds (ndns, &ns_offset, + rc =ndctl_namespace_get_injection_bounds (ndns, &ns_offset, &ns_size); +if (rc) +return rc; cmd =ndctl_bus_cmd_new_ars_cap (bus, ns_offset, ns_size); rc =ndctl_cmd_submit (cmd);if (rc <0 ) {
@@ -438,8 +451,10 @@ NDCTL_EXPORT int ndctl_namespace_injection_status(struct ndctl_namespace *ndns)return -EOPNOTSUPP ;if (ndctl_bus_has_nfit (bus)) { -ndctl_namespace_get_injection_bounds (ndns, &ns_offset, + rc =ndctl_namespace_get_injection_bounds (ndns, &ns_offset, &ns_size); +if (rc) +return rc; cmd =ndctl_bus_cmd_new_ars_cap (bus, ns_offset, ns_size); rc =ndctl_cmd_submit (cmd);
Signature · 6 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 12 lines · Vishal Verma
Error injection on a BTT namespace would treat the namespace as 'raw' for the purposes of the injection. This can be useful for development, but to a user this can be surprising, as injecting with --block=1 would corrupt the BTT info block, and the BTT would be lost.
The unit tests do not rely on injecting errors directly into a BTT namespace - they convert the namespace to 'raw' mode before performing such an injection. For development and testing purposes, we will still retain this ability by enforcing that the BTT namespace be explicitly forced into raw mode before injection.
Quoted 3 lines
Reported-by Marek de Rosier <[email protected]>Reported-by Dan Williams <[email protected]>Signed-off-by Vishal Verma <[email protected]>
Looks good,
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm