Skip to content

Commit d0fbb1d

Browse files
trondmyamschuma-ntap
authored andcommitted
NFSv4: Fix locking in pnfs_generic_recover_commit_reqs
The use of the inode->i_lock was converted to a mutex, but we forgot to remove the old inode unlock/lock() pair that allowed the layout segment to be put inside the loop. Reported-by: Jia-Ju Bai <baijiaju1990@gmail.com> Fixes: e824f99 ("NFSv4: Use a mutex to protect the per-inode commit...") Cc: stable@vger.kernel.org # v4.14+ Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent 62421cd commit d0fbb1d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

fs/nfs/pnfs_nfs.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ EXPORT_SYMBOL_GPL(pnfs_generic_commit_release);
6161

6262
/* The generic layer is about to remove the req from the commit list.
6363
* If this will make the bucket empty, it will need to put the lseg reference.
64-
* Note this must be called holding i_lock
64+
* Note this must be called holding nfsi->commit_mutex
6565
*/
6666
void
6767
pnfs_generic_clear_request_commit(struct nfs_page *req,
@@ -149,9 +149,7 @@ void pnfs_generic_recover_commit_reqs(struct list_head *dst,
149149
if (list_empty(&b->written)) {
150150
freeme = b->wlseg;
151151
b->wlseg = NULL;
152-
spin_unlock(&cinfo->inode->i_lock);
153152
pnfs_put_lseg(freeme);
154-
spin_lock(&cinfo->inode->i_lock);
155153
goto restart;
156154
}
157155
}
@@ -167,7 +165,7 @@ static void pnfs_generic_retry_commit(struct nfs_commit_info *cinfo, int idx)
167165
LIST_HEAD(pages);
168166
int i;
169167

170-
spin_lock(&cinfo->inode->i_lock);
168+
mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
171169
for (i = idx; i < fl_cinfo->nbuckets; i++) {
172170
bucket = &fl_cinfo->buckets[i];
173171
if (list_empty(&bucket->committing))
@@ -177,12 +175,12 @@ static void pnfs_generic_retry_commit(struct nfs_commit_info *cinfo, int idx)
177175
list_for_each(pos, &bucket->committing)
178176
cinfo->ds->ncommitting--;
179177
list_splice_init(&bucket->committing, &pages);
180-
spin_unlock(&cinfo->inode->i_lock);
178+
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
181179
nfs_retry_commit(&pages, freeme, cinfo, i);
182180
pnfs_put_lseg(freeme);
183-
spin_lock(&cinfo->inode->i_lock);
181+
mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
184182
}
185-
spin_unlock(&cinfo->inode->i_lock);
183+
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
186184
}
187185

188186
static unsigned int
@@ -222,13 +220,13 @@ void pnfs_fetch_commit_bucket_list(struct list_head *pages,
222220
struct list_head *pos;
223221

224222
bucket = &cinfo->ds->buckets[data->ds_commit_index];
225-
spin_lock(&cinfo->inode->i_lock);
223+
mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
226224
list_for_each(pos, &bucket->committing)
227225
cinfo->ds->ncommitting--;
228226
list_splice_init(&bucket->committing, pages);
229227
data->lseg = bucket->clseg;
230228
bucket->clseg = NULL;
231-
spin_unlock(&cinfo->inode->i_lock);
229+
mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
232230

233231
}
234232

0 commit comments

Comments
 (0)