]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - fs/nfs/nfs4proc.c
NFS: Always wait for I/O completion before unlock
[karo-tx-linux.git] / fs / nfs / nfs4proc.c
index c52f72c86940f7729d1d322ea349e47585f1d53c..dbfc7574fab0e636f0738b4d04e905cfaa850f8f 100644 (file)
@@ -5784,6 +5784,7 @@ struct nfs4_unlockdata {
        struct nfs_locku_res res;
        struct nfs4_lock_state *lsp;
        struct nfs_open_context *ctx;
+       struct nfs_lock_context *l_ctx;
        struct file_lock fl;
        struct nfs_server *server;
        unsigned long timestamp;
@@ -5808,6 +5809,7 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
        atomic_inc(&lsp->ls_count);
        /* Ensure we don't close file until we're done freeing locks! */
        p->ctx = get_nfs_open_context(ctx);
+       p->l_ctx = nfs_get_lock_context(ctx);
        memcpy(&p->fl, fl, sizeof(p->fl));
        p->server = NFS_SERVER(inode);
        return p;
@@ -5818,6 +5820,7 @@ static void nfs4_locku_release_calldata(void *data)
        struct nfs4_unlockdata *calldata = data;
        nfs_free_seqid(calldata->arg.seqid);
        nfs4_put_lock_state(calldata->lsp);
+       nfs_put_lock_context(calldata->l_ctx);
        put_nfs_open_context(calldata->ctx);
        kfree(calldata);
 }
@@ -5859,6 +5862,10 @@ static void nfs4_locku_prepare(struct rpc_task *task, void *data)
 {
        struct nfs4_unlockdata *calldata = data;
 
+       if (test_bit(NFS_CONTEXT_UNLOCK, &calldata->l_ctx->open_context->flags) &&
+               nfs_async_iocounter_wait(task, calldata->l_ctx))
+               return;
+
        if (nfs_wait_on_sequence(calldata->arg.seqid, task) != 0)
                goto out_wait;
        nfs4_stateid_copy(&calldata->arg.stateid, &calldata->lsp->ls_stateid);
@@ -5910,6 +5917,8 @@ static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
         * canceled lock is passed in, and it won't be an unlock.
         */
        fl->fl_type = F_UNLCK;
+       if (fl->fl_flags & FL_CLOSE)
+               set_bit(NFS_CONTEXT_UNLOCK, &ctx->flags);
 
        data = nfs4_alloc_unlockdata(fl, ctx, lsp, seqid);
        if (data == NULL) {