struct nfs_client *mds_client = mds_server->nfs_client;
        struct nfs4_slot_table *tbl = &clp->cl_session->fc_slot_table;
 
-       if (task->tk_status >= 0)
-               return 0;
-
        switch (task->tk_status) {
        /* MDS state errors */
        case -NFS4ERR_DELEG_REVOKED:
 {
        struct nfs4_deviceid_node *devid = FF_LAYOUT_DEVID_NODE(lseg, idx);
 
-       if (task->tk_status >= 0)
-               return 0;
-
        switch (task->tk_status) {
        /* File access problems. Don't mark the device as unavailable */
        case -EACCES:
 {
        int vers = clp->cl_nfs_mod->rpc_vers->number;
 
+       if (task->tk_status >= 0)
+               return 0;
+
+       /* Handle the case of an invalid layout segment */
+       if (!pnfs_is_valid_lseg(lseg))
+               return -NFS4ERR_RESET_TO_PNFS;
+
        switch (vers) {
        case 3:
                return ff_layout_async_handle_error_v3(task, lseg, idx);