Skip to content

Commit 606da57

Browse files
kofemanngregkh
authored andcommitted
flexfiles/pNFS: fix NULL checks on result of ff_layout_choose_ds_for_read
[ Upstream commit 5a46d23 ] Recent commit f06bedf ("pNFS/flexfiles: don't attempt pnfs on fatal DS errors") has changed the error return type of ff_layout_choose_ds_for_read() from NULL to an error pointer. However, not all code paths have been updated to match the change. Thus, some non-NULL checks will accept error pointers as a valid return value. Reported-by: Dan Carpenter <dan.carpenter@linaro.org> Suggested-by: Dan Carpenter <dan.carpenter@linaro.org> Fixes: f06bedf ("pNFS/flexfiles: don't attempt pnfs on fatal DS errors") Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 8d7cc14 commit 606da57

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

fs/nfs/flexfilelayout/flexfilelayout.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,11 @@ ff_layout_choose_ds_for_read(struct pnfs_layout_segment *lseg,
772772
continue;
773773

774774
if (check_device &&
775-
nfs4_test_deviceid_unavailable(&mirror->mirror_ds->id_node))
775+
nfs4_test_deviceid_unavailable(&mirror->mirror_ds->id_node)) {
776+
// reinitialize the error state in case if this is the last iteration
777+
ds = ERR_PTR(-EINVAL);
776778
continue;
779+
}
777780

778781
*best_idx = idx;
779782
break;
@@ -803,7 +806,7 @@ ff_layout_choose_best_ds_for_read(struct pnfs_layout_segment *lseg,
803806
struct nfs4_pnfs_ds *ds;
804807

805808
ds = ff_layout_choose_valid_ds_for_read(lseg, start_idx, best_idx);
806-
if (ds)
809+
if (!IS_ERR(ds))
807810
return ds;
808811
return ff_layout_choose_any_ds_for_read(lseg, start_idx, best_idx);
809812
}
@@ -817,7 +820,7 @@ ff_layout_get_ds_for_read(struct nfs_pageio_descriptor *pgio,
817820

818821
ds = ff_layout_choose_best_ds_for_read(lseg, pgio->pg_mirror_idx,
819822
best_idx);
820-
if (ds || !pgio->pg_mirror_idx)
823+
if (!IS_ERR(ds) || !pgio->pg_mirror_idx)
821824
return ds;
822825
return ff_layout_choose_best_ds_for_read(lseg, 0, best_idx);
823826
}
@@ -867,7 +870,7 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
867870
req->wb_nio = 0;
868871

869872
ds = ff_layout_get_ds_for_read(pgio, &ds_idx);
870-
if (!ds) {
873+
if (IS_ERR(ds)) {
871874
if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
872875
goto out_mds;
873876
pnfs_generic_pg_cleanup(pgio);
@@ -1071,11 +1074,13 @@ static void ff_layout_resend_pnfs_read(struct nfs_pgio_header *hdr)
10711074
{
10721075
u32 idx = hdr->pgio_mirror_idx + 1;
10731076
u32 new_idx = 0;
1077+
struct nfs4_pnfs_ds *ds;
10741078

1075-
if (ff_layout_choose_any_ds_for_read(hdr->lseg, idx, &new_idx))
1076-
ff_layout_send_layouterror(hdr->lseg);
1077-
else
1079+
ds = ff_layout_choose_any_ds_for_read(hdr->lseg, idx, &new_idx);
1080+
if (IS_ERR(ds))
10781081
pnfs_error_mark_layout_for_return(hdr->inode, hdr->lseg);
1082+
else
1083+
ff_layout_send_layouterror(hdr->lseg);
10791084
pnfs_read_resend_pnfs(hdr, new_idx);
10801085
}
10811086

0 commit comments

Comments
 (0)