diff options
author | Chuck Lever <chuck.lever@oracle.com> | 2012-07-11 16:30:14 -0400 |
---|---|---|
committer | Trond Myklebust <Trond.Myklebust@netapp.com> | 2012-07-16 14:49:40 -0400 |
commit | 3e60ffdd36fa518cc1822941dbb011e7a9adf513 (patch) | |
tree | 252c39f5ab56378b06f8bc6ca04e7a6fe9874c02 /fs/nfs/nfs4proc.c | |
parent | eb64cf964d453f8b559a8c0c2625952dbbcb5838 (diff) |
NFS: Clean up nfs41_check_expired_stateid()
Clean up: Instead of open-coded flag manipulation, use test_bit() and
clear_bit() just like all other accessors of the state->flag field.
This also eliminates several unnecessary implicit integer type
conversions.
To make it absolutely clear what is going on, a number of comments
are introduced.
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/nfs4proc.c')
-rw-r--r-- | fs/nfs/nfs4proc.c | 77 |
1 files changed, 61 insertions, 16 deletions
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index d1c1016cd505..1364569f1d1d 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c | |||
@@ -1756,32 +1756,67 @@ static int nfs4_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *sta | |||
1756 | } | 1756 | } |
1757 | 1757 | ||
1758 | #if defined(CONFIG_NFS_V4_1) | 1758 | #if defined(CONFIG_NFS_V4_1) |
1759 | static int nfs41_check_expired_stateid(struct nfs4_state *state, nfs4_stateid *stateid, unsigned int flags) | 1759 | static void nfs41_clear_delegation_stateid(struct nfs4_state *state) |
1760 | { | 1760 | { |
1761 | struct nfs_server *server = NFS_SERVER(state->inode); | 1761 | struct nfs_server *server = NFS_SERVER(state->inode); |
1762 | int status = -NFS4ERR_BAD_STATEID; | 1762 | nfs4_stateid *stateid = &state->stateid; |
1763 | 1763 | int status; | |
1764 | if (state->flags & flags) { | 1764 | |
1765 | status = nfs41_test_stateid(server, stateid); | 1765 | /* If a state reset has been done, test_stateid is unneeded */ |
1766 | if (status != NFS_OK) { | 1766 | if (test_bit(NFS_DELEGATED_STATE, &state->flags) == 0) |
1767 | if (status != -NFS4ERR_BAD_STATEID) | 1767 | return; |
1768 | nfs41_free_stateid(server, stateid); | 1768 | |
1769 | state->flags &= ~flags; | 1769 | status = nfs41_test_stateid(server, stateid); |
1770 | } | 1770 | if (status != NFS_OK) { |
1771 | /* Free the stateid unless the server explicitly | ||
1772 | * informs us the stateid is unrecognized. */ | ||
1773 | if (status != -NFS4ERR_BAD_STATEID) | ||
1774 | nfs41_free_stateid(server, stateid); | ||
1775 | |||
1776 | clear_bit(NFS_DELEGATED_STATE, &state->flags); | ||
1777 | } | ||
1778 | } | ||
1779 | |||
1780 | /** | ||
1781 | * nfs41_check_open_stateid - possibly free an open stateid | ||
1782 | * | ||
1783 | * @state: NFSv4 state for an inode | ||
1784 | * | ||
1785 | * Returns NFS_OK if recovery for this stateid is now finished. | ||
1786 | * Otherwise a negative NFS4ERR value is returned. | ||
1787 | */ | ||
1788 | static int nfs41_check_open_stateid(struct nfs4_state *state) | ||
1789 | { | ||
1790 | struct nfs_server *server = NFS_SERVER(state->inode); | ||
1791 | nfs4_stateid *stateid = &state->stateid; | ||
1792 | int status; | ||
1793 | |||
1794 | /* If a state reset has been done, test_stateid is unneeded */ | ||
1795 | if ((test_bit(NFS_O_RDONLY_STATE, &state->flags) == 0) && | ||
1796 | (test_bit(NFS_O_WRONLY_STATE, &state->flags) == 0) && | ||
1797 | (test_bit(NFS_O_RDWR_STATE, &state->flags) == 0)) | ||
1798 | return -NFS4ERR_BAD_STATEID; | ||
1799 | |||
1800 | status = nfs41_test_stateid(server, stateid); | ||
1801 | if (status != NFS_OK) { | ||
1802 | /* Free the stateid unless the server explicitly | ||
1803 | * informs us the stateid is unrecognized. */ | ||
1804 | if (status != -NFS4ERR_BAD_STATEID) | ||
1805 | nfs41_free_stateid(server, stateid); | ||
1806 | |||
1807 | clear_bit(NFS_O_RDONLY_STATE, &state->flags); | ||
1808 | clear_bit(NFS_O_WRONLY_STATE, &state->flags); | ||
1809 | clear_bit(NFS_O_RDWR_STATE, &state->flags); | ||
1771 | } | 1810 | } |
1772 | return status; | 1811 | return status; |
1773 | } | 1812 | } |
1774 | 1813 | ||
1775 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) | 1814 | static int nfs41_open_expired(struct nfs4_state_owner *sp, struct nfs4_state *state) |
1776 | { | 1815 | { |
1777 | int deleg_flags = 1 << NFS_DELEGATED_STATE; | ||
1778 | int open_flags = (1 << NFS_O_RDONLY_STATE) | (1 << NFS_O_WRONLY_STATE) | (1 << NFS_O_RDWR_STATE); | ||
1779 | int status; | 1816 | int status; |
1780 | 1817 | ||
1781 | nfs41_check_expired_stateid(state, &state->stateid, deleg_flags); | 1818 | nfs41_clear_delegation_stateid(state); |
1782 | status = nfs41_check_expired_stateid(state, &state->open_stateid, | 1819 | status = nfs41_check_open_stateid(state); |
1783 | open_flags); | ||
1784 | |||
1785 | if (status != NFS_OK) | 1820 | if (status != NFS_OK) |
1786 | status = nfs4_open_expired(sp, state); | 1821 | status = nfs4_open_expired(sp, state); |
1787 | return status; | 1822 | return status; |
@@ -4689,6 +4724,14 @@ out: | |||
4689 | } | 4724 | } |
4690 | 4725 | ||
4691 | #if defined(CONFIG_NFS_V4_1) | 4726 | #if defined(CONFIG_NFS_V4_1) |
4727 | /** | ||
4728 | * nfs41_check_expired_locks - possibly free a lock stateid | ||
4729 | * | ||
4730 | * @state: NFSv4 state for an inode | ||
4731 | * | ||
4732 | * Returns NFS_OK if recovery for this stateid is now finished. | ||
4733 | * Otherwise a negative NFS4ERR value is returned. | ||
4734 | */ | ||
4692 | static int nfs41_check_expired_locks(struct nfs4_state *state) | 4735 | static int nfs41_check_expired_locks(struct nfs4_state *state) |
4693 | { | 4736 | { |
4694 | int status, ret = -NFS4ERR_BAD_STATEID; | 4737 | int status, ret = -NFS4ERR_BAD_STATEID; |
@@ -4699,6 +4742,8 @@ static int nfs41_check_expired_locks(struct nfs4_state *state) | |||
4699 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { | 4742 | if (lsp->ls_flags & NFS_LOCK_INITIALIZED) { |
4700 | status = nfs41_test_stateid(server, &lsp->ls_stateid); | 4743 | status = nfs41_test_stateid(server, &lsp->ls_stateid); |
4701 | if (status != NFS_OK) { | 4744 | if (status != NFS_OK) { |
4745 | /* Free the stateid unless the server | ||
4746 | * informs us the stateid is unrecognized. */ | ||
4702 | if (status != -NFS4ERR_BAD_STATEID) | 4747 | if (status != -NFS4ERR_BAD_STATEID) |
4703 | nfs41_free_stateid(server, | 4748 | nfs41_free_stateid(server, |
4704 | &lsp->ls_stateid); | 4749 | &lsp->ls_stateid); |