Skip to content

Commit fd00ae0

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 0214b96 commit fd00ae0

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
@@ -756,8 +756,11 @@ ff_layout_choose_ds_for_read(struct pnfs_layout_segment *lseg,
756756
continue;
757757

758758
if (check_device &&
759-
nfs4_test_deviceid_unavailable(&mirror->mirror_ds->id_node))
759+
nfs4_test_deviceid_unavailable(&mirror->mirror_ds->id_node)) {
760+
// reinitialize the error state in case if this is the last iteration
761+
ds = ERR_PTR(-EINVAL);
760762
continue;
763+
}
761764

762765
*best_idx = idx;
763766
break;
@@ -787,7 +790,7 @@ ff_layout_choose_best_ds_for_read(struct pnfs_layout_segment *lseg,
787790
struct nfs4_pnfs_ds *ds;
788791

789792
ds = ff_layout_choose_valid_ds_for_read(lseg, start_idx, best_idx);
790-
if (ds)
793+
if (!IS_ERR(ds))
791794
return ds;
792795
return ff_layout_choose_any_ds_for_read(lseg, start_idx, best_idx);
793796
}
@@ -801,7 +804,7 @@ ff_layout_get_ds_for_read(struct nfs_pageio_descriptor *pgio,
801804

802805
ds = ff_layout_choose_best_ds_for_read(lseg, pgio->pg_mirror_idx,
803806
best_idx);
804-
if (ds || !pgio->pg_mirror_idx)
807+
if (!IS_ERR(ds) || !pgio->pg_mirror_idx)
805808
return ds;
806809
return ff_layout_choose_best_ds_for_read(lseg, 0, best_idx);
807810
}
@@ -859,7 +862,7 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
859862
req->wb_nio = 0;
860863

861864
ds = ff_layout_get_ds_for_read(pgio, &ds_idx);
862-
if (!ds) {
865+
if (IS_ERR(ds)) {
863866
if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
864867
goto out_mds;
865868
pnfs_generic_pg_cleanup(pgio);
@@ -1063,11 +1066,13 @@ static void ff_layout_resend_pnfs_read(struct nfs_pgio_header *hdr)
10631066
{
10641067
u32 idx = hdr->pgio_mirror_idx + 1;
10651068
u32 new_idx = 0;
1069+
struct nfs4_pnfs_ds *ds;
10661070

1067-
if (ff_layout_choose_any_ds_for_read(hdr->lseg, idx, &new_idx))
1068-
ff_layout_send_layouterror(hdr->lseg);
1069-
else
1071+
ds = ff_layout_choose_any_ds_for_read(hdr->lseg, idx, &new_idx);
1072+
if (IS_ERR(ds))
10701073
pnfs_error_mark_layout_for_return(hdr->inode, hdr->lseg);
1074+
else
1075+
ff_layout_send_layouterror(hdr->lseg);
10711076
pnfs_read_resend_pnfs(hdr, new_idx);
10721077
}
10731078

0 commit comments

Comments
 (0)