Skip to content

Commit 39e6bc8

Browse files
committed
tree: propagate error code for nvme_scan_ctrl
The scanning can fail due to missing permissions etc. Thus propagate this error code instead creating invalid objects. Signed-off-by: Daniel Wagner <[email protected]>
1 parent c6601cf commit 39e6bc8

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

libnvme/src/nvme/tree.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
18431843
static int nvme_ctrl_scan_paths(struct nvme_global_ctx *ctx, struct nvme_ctrl *c)
18441844
{
18451845
_cleanup_dirents_ struct dirents paths = {};
1846-
int i;
1846+
int err, i;
18471847

18481848
if (ctx->create_only) {
18491849
nvme_msg(ctx, LOG_DEBUG,
@@ -1854,25 +1854,32 @@ static int nvme_ctrl_scan_paths(struct nvme_global_ctx *ctx, struct nvme_ctrl *c
18541854
if (paths.num < 0)
18551855
return paths.num;
18561856

1857-
for (i = 0; i < paths.num; i++)
1858-
nvme_ctrl_scan_path(ctx, c, paths.ents[i]->d_name);
1857+
for (i = 0; i < paths.num; i++) {
1858+
err = nvme_ctrl_scan_path(ctx, c, paths.ents[i]->d_name);
1859+
if (err)
1860+
return err;
1861+
}
18591862

18601863
return 0;
18611864
}
18621865

18631866
static int nvme_ctrl_scan_namespaces(struct nvme_global_ctx *ctx, struct nvme_ctrl *c)
18641867
{
18651868
_cleanup_dirents_ struct dirents namespaces = {};
1866-
int i;
1869+
int err, i;
18671870

18681871
if (ctx->create_only) {
18691872
nvme_msg(ctx, LOG_DEBUG, "skipping namespace scan for ctrl %s\n",
18701873
c->name);
18711874
return 0;
18721875
}
18731876
namespaces.num = nvme_scan_ctrl_namespaces(c, &namespaces.ents);
1874-
for (i = 0; i < namespaces.num; i++)
1875-
nvme_ctrl_scan_namespace(ctx, c, namespaces.ents[i]->d_name);
1877+
for (i = 0; i < namespaces.num; i++) {
1878+
err = nvme_ctrl_scan_namespace(ctx, c,
1879+
namespaces.ents[i]->d_name);
1880+
if (err)
1881+
return err;
1882+
}
18761883

18771884
return 0;
18781885
}
@@ -2267,8 +2274,17 @@ int nvme_scan_ctrl(struct nvme_global_ctx *ctx, const char *name,
22672274
if (ret)
22682275
return ret;
22692276

2270-
nvme_ctrl_scan_paths(ctx, c);
2271-
nvme_ctrl_scan_namespaces(ctx, c);
2277+
ret = nvme_ctrl_scan_paths(ctx, c);
2278+
if (ret) {
2279+
nvme_free_ctrl(c);
2280+
return ret;
2281+
}
2282+
2283+
ret = nvme_ctrl_scan_namespaces(ctx, c);
2284+
if (ret) {
2285+
nvme_free_ctrl(c);
2286+
return ret;
2287+
}
22722288

22732289
*cp = c;
22742290
return 0;

0 commit comments

Comments
 (0)