Skip to content

Commit cb7a838

Browse files
amschuma-ntapTrond Myklebust
authored andcommitted
NFS: Split out the body of nfs4_reclaim_open_state()
Moving all of this into a new function removes the need for cramped indentation, making the code overall easier to look at. I also take this chance to switch copy recovery over to using nfs4_stateid_match_other() Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent 10ec57e commit cb7a838

File tree

1 file changed

+47
-36
lines changed

1 file changed

+47
-36
lines changed

fs/nfs/nfs4state.c

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,10 +1549,51 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
15491549
return status;
15501550
}
15511551

1552+
static int __nfs4_reclaim_open_state(struct nfs4_state_owner *sp, struct nfs4_state *state,
1553+
const struct nfs4_state_recovery_ops *ops)
1554+
{
1555+
struct nfs4_lock_state *lock;
1556+
int status;
1557+
1558+
status = ops->recover_open(sp, state);
1559+
if (status < 0)
1560+
return status;
1561+
1562+
status = nfs4_reclaim_locks(state, ops);
1563+
if (status < 0)
1564+
return status;
1565+
1566+
if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) {
1567+
spin_lock(&state->state_lock);
1568+
list_for_each_entry(lock, &state->lock_states, ls_locks) {
1569+
if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags))
1570+
pr_warn_ratelimited("NFS: %s: Lock reclaim failed!\n", __func__);
1571+
}
1572+
spin_unlock(&state->state_lock);
1573+
}
1574+
1575+
#ifdef CONFIG_NFS_V4_2
1576+
if (test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags)) {
1577+
struct nfs4_copy_state *copy;
1578+
spin_lock(&sp->so_server->nfs_client->cl_lock);
1579+
list_for_each_entry(copy, &sp->so_server->ss_copies, copies) {
1580+
if (nfs4_stateid_match_other(&state->stateid, &copy->parent_state->stateid))
1581+
continue;
1582+
copy->flags = 1;
1583+
complete(&copy->completion);
1584+
break;
1585+
}
1586+
spin_unlock(&sp->so_server->nfs_client->cl_lock);
1587+
}
1588+
#endif /* CONFIG_NFS_V4_2 */
1589+
1590+
clear_bit(NFS_STATE_RECLAIM_NOGRACE, &state->flags);
1591+
return status;
1592+
}
1593+
15521594
static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs4_state_recovery_ops *ops)
15531595
{
15541596
struct nfs4_state *state;
1555-
struct nfs4_lock_state *lock;
15561597
int status = 0;
15571598

15581599
/* Note: we rely on the sp->so_states list being ordered
@@ -1575,43 +1616,13 @@ static int nfs4_reclaim_open_state(struct nfs4_state_owner *sp, const struct nfs
15751616
continue;
15761617
refcount_inc(&state->count);
15771618
spin_unlock(&sp->so_lock);
1578-
status = ops->recover_open(sp, state);
1619+
status = __nfs4_reclaim_open_state(sp, state, ops);
15791620
if (status >= 0) {
1580-
status = nfs4_reclaim_locks(state, ops);
1581-
if (status >= 0) {
1582-
if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) {
1583-
spin_lock(&state->state_lock);
1584-
list_for_each_entry(lock, &state->lock_states, ls_locks) {
1585-
if (!test_bit(NFS_LOCK_INITIALIZED, &lock->ls_flags))
1586-
pr_warn_ratelimited("NFS: "
1587-
"%s: Lock reclaim "
1588-
"failed!\n", __func__);
1589-
}
1590-
spin_unlock(&state->state_lock);
1591-
}
1592-
clear_bit(NFS_STATE_RECLAIM_NOGRACE,
1593-
&state->flags);
1594-
#ifdef CONFIG_NFS_V4_2
1595-
if (test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags)) {
1596-
struct nfs4_copy_state *copy;
1597-
1598-
spin_lock(&sp->so_server->nfs_client->cl_lock);
1599-
list_for_each_entry(copy, &sp->so_server->ss_copies, copies) {
1600-
if (memcmp(&state->stateid.other, &copy->parent_state->stateid.other, NFS4_STATEID_SIZE))
1601-
continue;
1602-
copy->flags = 1;
1603-
complete(&copy->completion);
1604-
printk("AGLO: server rebooted waking up the copy\n");
1605-
break;
1606-
}
1607-
spin_unlock(&sp->so_server->nfs_client->cl_lock);
1608-
}
1609-
#endif /* CONFIG_NFS_V4_2 */
1610-
nfs4_put_open_state(state);
1611-
spin_lock(&sp->so_lock);
1612-
goto restart;
1613-
}
1621+
nfs4_put_open_state(state);
1622+
spin_lock(&sp->so_lock);
1623+
goto restart;
16141624
}
1625+
16151626
switch (status) {
16161627
default:
16171628
printk(KERN_ERR "NFS: %s: unhandled error %d\n",

0 commit comments

Comments
 (0)