浏览代码

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: e824f99adaaf1 ("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>
Trond Myklebust 7 年之前
父节点
当前提交
d0fbb1d8a1
共有 1 个文件被更改,包括 7 次插入9 次删除
  1. 7 9
      fs/nfs/pnfs_nfs.c

+ 7 - 9
fs/nfs/pnfs_nfs.c

@@ -61,7 +61,7 @@ EXPORT_SYMBOL_GPL(pnfs_generic_commit_release);
 
 
 /* The generic layer is about to remove the req from the commit list.
 /* The generic layer is about to remove the req from the commit list.
  * If this will make the bucket empty, it will need to put the lseg reference.
  * If this will make the bucket empty, it will need to put the lseg reference.
- * Note this must be called holding i_lock
+ * Note this must be called holding nfsi->commit_mutex
  */
  */
 void
 void
 pnfs_generic_clear_request_commit(struct nfs_page *req,
 pnfs_generic_clear_request_commit(struct nfs_page *req,
@@ -149,9 +149,7 @@ restart:
 		if (list_empty(&b->written)) {
 		if (list_empty(&b->written)) {
 			freeme = b->wlseg;
 			freeme = b->wlseg;
 			b->wlseg = NULL;
 			b->wlseg = NULL;
-			spin_unlock(&cinfo->inode->i_lock);
 			pnfs_put_lseg(freeme);
 			pnfs_put_lseg(freeme);
-			spin_lock(&cinfo->inode->i_lock);
 			goto restart;
 			goto restart;
 		}
 		}
 	}
 	}
@@ -167,7 +165,7 @@ static void pnfs_generic_retry_commit(struct nfs_commit_info *cinfo, int idx)
 	LIST_HEAD(pages);
 	LIST_HEAD(pages);
 	int i;
 	int i;
 
 
-	spin_lock(&cinfo->inode->i_lock);
+	mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
 	for (i = idx; i < fl_cinfo->nbuckets; i++) {
 	for (i = idx; i < fl_cinfo->nbuckets; i++) {
 		bucket = &fl_cinfo->buckets[i];
 		bucket = &fl_cinfo->buckets[i];
 		if (list_empty(&bucket->committing))
 		if (list_empty(&bucket->committing))
@@ -177,12 +175,12 @@ static void pnfs_generic_retry_commit(struct nfs_commit_info *cinfo, int idx)
 		list_for_each(pos, &bucket->committing)
 		list_for_each(pos, &bucket->committing)
 			cinfo->ds->ncommitting--;
 			cinfo->ds->ncommitting--;
 		list_splice_init(&bucket->committing, &pages);
 		list_splice_init(&bucket->committing, &pages);
-		spin_unlock(&cinfo->inode->i_lock);
+		mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
 		nfs_retry_commit(&pages, freeme, cinfo, i);
 		nfs_retry_commit(&pages, freeme, cinfo, i);
 		pnfs_put_lseg(freeme);
 		pnfs_put_lseg(freeme);
-		spin_lock(&cinfo->inode->i_lock);
+		mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
 	}
 	}
-	spin_unlock(&cinfo->inode->i_lock);
+	mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
 }
 }
 
 
 static unsigned int
 static unsigned int
@@ -222,13 +220,13 @@ void pnfs_fetch_commit_bucket_list(struct list_head *pages,
 	struct list_head *pos;
 	struct list_head *pos;
 
 
 	bucket = &cinfo->ds->buckets[data->ds_commit_index];
 	bucket = &cinfo->ds->buckets[data->ds_commit_index];
-	spin_lock(&cinfo->inode->i_lock);
+	mutex_lock(&NFS_I(cinfo->inode)->commit_mutex);
 	list_for_each(pos, &bucket->committing)
 	list_for_each(pos, &bucket->committing)
 		cinfo->ds->ncommitting--;
 		cinfo->ds->ncommitting--;
 	list_splice_init(&bucket->committing, pages);
 	list_splice_init(&bucket->committing, pages);
 	data->lseg = bucket->clseg;
 	data->lseg = bucket->clseg;
 	bucket->clseg = NULL;
 	bucket->clseg = NULL;
-	spin_unlock(&cinfo->inode->i_lock);
+	mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
 
 
 }
 }