Skip to content

Commit 5a46d23

Browse files
kofemannTrond Myklebust
authored andcommitted
flexfiles/pNFS: fix NULL checks on result of ff_layout_choose_ds_for_read
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 <[email protected]> Suggested-by: Dan Carpenter <[email protected]> Fixes: f06bedf ("pNFS/flexfiles: don't attempt pnfs on fatal DS errors") Signed-off-by: Tigran Mkrtchyan <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent d368439 commit 5a46d23

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
@@ -773,8 +773,11 @@ ff_layout_choose_ds_for_read(struct pnfs_layout_segment *lseg,
773773
continue;
774774

775775
if (check_device &&
776-
nfs4_test_deviceid_unavailable(&mirror->mirror_ds->id_node))
776+
nfs4_test_deviceid_unavailable(&mirror->mirror_ds->id_node)) {
777+
// reinitialize the error state in case if this is the last iteration
778+
ds = ERR_PTR(-EINVAL);
777779
continue;
780+
}
778781

779782
*best_idx = idx;
780783
break;
@@ -804,7 +807,7 @@ ff_layout_choose_best_ds_for_read(struct pnfs_layout_segment *lseg,
804807
struct nfs4_pnfs_ds *ds;
805808

806809
ds = ff_layout_choose_valid_ds_for_read(lseg, start_idx, best_idx);
807-
if (ds)
810+
if (!IS_ERR(ds))
808811
return ds;
809812
return ff_layout_choose_any_ds_for_read(lseg, start_idx, best_idx);
810813
}
@@ -818,7 +821,7 @@ ff_layout_get_ds_for_read(struct nfs_pageio_descriptor *pgio,
818821

819822
ds = ff_layout_choose_best_ds_for_read(lseg, pgio->pg_mirror_idx,
820823
best_idx);
821-
if (ds || !pgio->pg_mirror_idx)
824+
if (!IS_ERR(ds) || !pgio->pg_mirror_idx)
822825
return ds;
823826
return ff_layout_choose_best_ds_for_read(lseg, 0, best_idx);
824827
}
@@ -868,7 +871,7 @@ ff_layout_pg_init_read(struct nfs_pageio_descriptor *pgio,
868871
req->wb_nio = 0;
869872

870873
ds = ff_layout_get_ds_for_read(pgio, &ds_idx);
871-
if (!ds) {
874+
if (IS_ERR(ds)) {
872875
if (!ff_layout_no_fallback_to_mds(pgio->pg_lseg))
873876
goto out_mds;
874877
pnfs_generic_pg_cleanup(pgio);
@@ -1072,11 +1075,13 @@ static void ff_layout_resend_pnfs_read(struct nfs_pgio_header *hdr)
10721075
{
10731076
u32 idx = hdr->pgio_mirror_idx + 1;
10741077
u32 new_idx = 0;
1078+
struct nfs4_pnfs_ds *ds;
10751079

1076-
if (ff_layout_choose_any_ds_for_read(hdr->lseg, idx, &new_idx))
1077-
ff_layout_send_layouterror(hdr->lseg);
1078-
else
1080+
ds = ff_layout_choose_any_ds_for_read(hdr->lseg, idx, &new_idx);
1081+
if (IS_ERR(ds))
10791082
pnfs_error_mark_layout_for_return(hdr->inode, hdr->lseg);
1083+
else
1084+
ff_layout_send_layouterror(hdr->lseg);
10801085
pnfs_read_resend_pnfs(hdr, new_idx);
10811086
}
10821087

0 commit comments

Comments
 (0)