NFS/pnfs: Fix pnfs_generic_prepare_to_resend_writes()
authorTrond Myklebust <trondmy@gmail.com>
Mon, 6 Jan 2020 20:25:04 +0000 (15:25 -0500)
committerAnna Schumaker <Anna.Schumaker@Netapp.com>
Wed, 15 Jan 2020 15:54:32 +0000 (10:54 -0500)
Instead of making assumptions about the commit verifier contents, change
the commit code to ensure we always check that the verifier was set
by the XDR code.

Fixes: f54bcf2ecee9 ("pnfs: Prepare for flexfiles by pulling out common code")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
fs/nfs/direct.c
fs/nfs/nfs3xdr.c
fs/nfs/nfs4xdr.c
fs/nfs/pnfs_nfs.c
fs/nfs/write.c

index 040a50fd9bf307d9e2bdd25643a3db9f73dcb64e..29f00da8a0b7f030338da3eb97841f29e311696d 100644 (file)
@@ -245,10 +245,10 @@ static int nfs_direct_cmp_commit_data_verf(struct nfs_direct_req *dreq,
                                         data->ds_commit_index);
 
        /* verifier not set so always fail */
-       if (verfp->committed < 0)
+       if (verfp->committed < 0 || data->res.verf->committed <= NFS_UNSTABLE)
                return 1;
 
-       return nfs_direct_cmp_verf(verfp, &data->verf);
+       return nfs_direct_cmp_verf(verfp, data->res.verf);
 }
 
 /**
index 927eb680f16132eaa610ea4c860a149d5775508e..69971f6c840d2ff3639b455029090370dde507c0 100644 (file)
@@ -2334,6 +2334,7 @@ static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
                                   void *data)
 {
        struct nfs_commitres *result = data;
+       struct nfs_writeverf *verf = result->verf;
        enum nfs_stat status;
        int error;
 
@@ -2346,7 +2347,9 @@ static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
        result->op_status = status;
        if (status != NFS3_OK)
                goto out_status;
-       error = decode_writeverf3(xdr, &result->verf->verifier);
+       error = decode_writeverf3(xdr, &verf->verifier);
+       if (!error)
+               verf->committed = NFS_FILE_SYNC;
 out:
        return error;
 out_status:
index 8de4d250924b2f8cc74210d1ad1d86da23fab05f..47817ef0aadb1558d5c92b48d4e2ee7479f5abd9 100644 (file)
@@ -4313,11 +4313,14 @@ static int decode_write_verifier(struct xdr_stream *xdr, struct nfs_write_verifi
 
 static int decode_commit(struct xdr_stream *xdr, struct nfs_commitres *res)
 {
+       struct nfs_writeverf *verf = res->verf;
        int status;
 
        status = decode_op_hdr(xdr, OP_COMMIT);
        if (!status)
-               status = decode_write_verifier(xdr, &res->verf->verifier);
+               status = decode_write_verifier(xdr, &verf->verifier);
+       if (!status)
+               verf->committed = NFS_FILE_SYNC;
        return status;
 }
 
index 82af4809b869a63851ce8d49f4e0d982bdc6305c..8b37e7f8e789f9be96612089977142365553f7b1 100644 (file)
@@ -31,12 +31,11 @@ EXPORT_SYMBOL_GPL(pnfs_generic_rw_release);
 /* Fake up some data that will cause nfs_commit_release to retry the writes. */
 void pnfs_generic_prepare_to_resend_writes(struct nfs_commit_data *data)
 {
-       struct nfs_page *first = nfs_list_entry(data->pages.next);
+       struct nfs_writeverf *verf = data->res.verf;
 
        data->task.tk_status = 0;
-       memcpy(&data->verf.verifier, &first->wb_verf,
-              sizeof(data->verf.verifier));
-       data->verf.verifier.data[0]++; /* ensure verifier mismatch */
+       memset(&verf->verifier, 0, sizeof(verf->verifier));
+       verf->committed = NFS_UNSTABLE;
 }
 EXPORT_SYMBOL_GPL(pnfs_generic_prepare_to_resend_writes);
 
index 6dd8d6e6d847ac5336d605de13b1bdce04f9ab85..c86fc9efd99bc9736eb74e45bb33a99a122d812a 100644 (file)
@@ -1840,6 +1840,7 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
 
 static void nfs_commit_release_pages(struct nfs_commit_data *data)
 {
+       const struct nfs_writeverf *verf = data->res.verf;
        struct nfs_page *req;
        int status = data->task.tk_status;
        struct nfs_commit_info cinfo;
@@ -1868,7 +1869,8 @@ static void nfs_commit_release_pages(struct nfs_commit_data *data)
 
                /* Okay, COMMIT succeeded, apparently. Check the verifier
                 * returned by the server against all stored verfs. */
-               if (!nfs_write_verifier_cmp(&req->wb_verf, &data->verf.verifier)) {
+               if (verf->committed > NFS_UNSTABLE &&
+                   !nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier)) {
                        /* We have a match */
                        if (req->wb_page)
                                nfs_inode_remove_request(req);