diff mbox

nfs: don't drop kiocb->ki_users in error case

Message ID 201101191255.p0JCtneP008444@rcsinet15.oracle.com (mailing list archive)
State Superseded, archived
Headers show

Commit Message

Wengang Wang Jan. 19, 2011, 12:53 p.m. UTC
None
diff mbox

Patch

diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index e6ace0d..fa5e5f9 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -219,6 +219,17 @@  static void nfs_direct_complete(struct nfs_direct_req *dreq)
 		long res = (long) dreq->error;
 		if (!res)
 			res = (long) dreq->count;
+		/*
+		 * vfs doesn't want us drop kiocb->ki_users in error case.
+		 * we get an extra ref on it then later drop it in aio_complete
+		 */
+		if (dreq->error) {
+			struct kioctx *ctx = dreq->iocb->ki_ctx;
+
+			spin_lock_irq(&ctx->ctx_lock);
+			dreq->iocb->ki_users ++;
+			spin_unlock_irq(&ctx->ctx_lock);
+		}
 		aio_complete(dreq->iocb, res, 0);
 	}
 	complete_all(&dreq->completion);
@@ -319,6 +330,7 @@  static ssize_t nfs_direct_read_schedule_segment(struct nfs_direct_req *dreq,
 					data->npages, 1, 0, data->pagevec, NULL);
 		up_read(&current->mm->mmap_sem);
 		if (result < 0) {
+			dreq->error = result;
 			nfs_readdata_free(data);
 			break;
 		}
@@ -357,8 +369,10 @@  static ssize_t nfs_direct_read_schedule_segment(struct nfs_direct_req *dreq,
 		NFS_PROTO(inode)->read_setup(data, &msg);
 
 		task = rpc_run_task(&task_setup_data);
-		if (IS_ERR(task))
+		if (IS_ERR(task)) {
+			dreq->error = PTR_ERR(task);
 			break;
+		}
 		rpc_put_task(task);
 
 		dprintk("NFS: %5u initiated direct read call "
@@ -748,6 +762,7 @@  static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq,
 					data->npages, 0, 0, data->pagevec, NULL);
 		up_read(&current->mm->mmap_sem);
 		if (result < 0) {
+			dreq->error = result;
 			nfs_writedata_free(data);
 			break;
 		}
@@ -789,8 +804,10 @@  static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq,
 		NFS_PROTO(inode)->write_setup(data, &msg);
 
 		task = rpc_run_task(&task_setup_data);
-		if (IS_ERR(task))
+		if (IS_ERR(task)) {
+			dreq->error = PTR_ERR(task);
 			break;
+		}
 		rpc_put_task(task);
 
 		dprintk("NFS: %5u initiated direct write call "