Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Anna Schumaker <Anna.Schumaker@Netapp.com> |
| 4 | */ |
| 5 | #include <linux/fs.h> |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 6 | #include <linux/sunrpc/addr.h> |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 7 | #include <linux/sunrpc/sched.h> |
| 8 | #include <linux/nfs.h> |
| 9 | #include <linux/nfs3.h> |
| 10 | #include <linux/nfs4.h> |
| 11 | #include <linux/nfs_xdr.h> |
| 12 | #include <linux/nfs_fs.h> |
| 13 | #include "nfs4_fs.h" |
| 14 | #include "nfs42.h" |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 15 | #include "iostat.h" |
| 16 | #include "pnfs.h" |
Anna Schumaker | efc6f4a | 2017-01-09 15:14:33 -0500 | [diff] [blame] | 17 | #include "nfs4session.h" |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 18 | #include "internal.h" |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 19 | #include "delegation.h" |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 20 | |
Anna Schumaker | 291e1b9 | 2015-11-16 14:51:07 -0500 | [diff] [blame] | 21 | #define NFSDBG_FACILITY NFSDBG_PROC |
Olga Kornievskaia | c975c20 | 2018-07-09 15:13:34 -0400 | [diff] [blame] | 22 | static int nfs42_do_offload_cancel_async(struct file *dst, nfs4_stateid *std); |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 23 | |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 24 | static void nfs42_set_netaddr(struct file *filep, struct nfs42_netaddr *naddr) |
| 25 | { |
| 26 | struct nfs_client *clp = (NFS_SERVER(file_inode(filep)))->nfs_client; |
| 27 | unsigned short port = 2049; |
| 28 | |
| 29 | rcu_read_lock(); |
| 30 | naddr->netid_len = scnprintf(naddr->netid, |
| 31 | sizeof(naddr->netid), "%s", |
| 32 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 33 | RPC_DISPLAY_NETID)); |
| 34 | naddr->addr_len = scnprintf(naddr->addr, |
| 35 | sizeof(naddr->addr), |
| 36 | "%s.%u.%u", |
| 37 | rpc_peeraddr2str(clp->cl_rpcclient, |
| 38 | RPC_DISPLAY_ADDR), |
| 39 | port >> 8, port & 255); |
| 40 | rcu_read_unlock(); |
| 41 | } |
| 42 | |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 43 | static int _nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 44 | struct nfs_lock_context *lock, loff_t offset, loff_t len) |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 45 | { |
| 46 | struct inode *inode = file_inode(filep); |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 47 | struct nfs_server *server = NFS_SERVER(inode); |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 48 | struct nfs42_falloc_args args = { |
| 49 | .falloc_fh = NFS_FH(inode), |
| 50 | .falloc_offset = offset, |
| 51 | .falloc_length = len, |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 52 | .falloc_bitmask = server->cache_consistency_bitmask, |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 53 | }; |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 54 | struct nfs42_falloc_res res = { |
| 55 | .falloc_server = server, |
| 56 | }; |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 57 | int status; |
| 58 | |
| 59 | msg->rpc_argp = &args; |
| 60 | msg->rpc_resp = &res; |
| 61 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 62 | status = nfs4_set_rw_stateid(&args.falloc_stateid, lock->open_context, |
| 63 | lock, FMODE_WRITE); |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 64 | if (status) |
| 65 | return status; |
| 66 | |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 67 | res.falloc_fattr = nfs_alloc_fattr(); |
| 68 | if (!res.falloc_fattr) |
| 69 | return -ENOMEM; |
| 70 | |
| 71 | status = nfs4_call_sync(server->client, server, msg, |
| 72 | &args.seq_args, &res.seq_res, 0); |
| 73 | if (status == 0) |
| 74 | status = nfs_post_op_update_inode(inode, res.falloc_fattr); |
| 75 | |
| 76 | kfree(res.falloc_fattr); |
| 77 | return status; |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | static int nfs42_proc_fallocate(struct rpc_message *msg, struct file *filep, |
| 81 | loff_t offset, loff_t len) |
| 82 | { |
| 83 | struct nfs_server *server = NFS_SERVER(file_inode(filep)); |
| 84 | struct nfs4_exception exception = { }; |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 85 | struct nfs_lock_context *lock; |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 86 | int err; |
| 87 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 88 | lock = nfs_get_lock_context(nfs_file_open_context(filep)); |
| 89 | if (IS_ERR(lock)) |
| 90 | return PTR_ERR(lock); |
| 91 | |
| 92 | exception.inode = file_inode(filep); |
| 93 | exception.state = lock->open_context->state; |
| 94 | |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 95 | do { |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 96 | err = _nfs42_proc_fallocate(msg, filep, lock, offset, len); |
| 97 | if (err == -ENOTSUPP) { |
| 98 | err = -EOPNOTSUPP; |
| 99 | break; |
| 100 | } |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 101 | err = nfs4_handle_exception(server, err, &exception); |
| 102 | } while (exception.retry); |
| 103 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 104 | nfs_put_lock_context(lock); |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 105 | return err; |
| 106 | } |
| 107 | |
| 108 | int nfs42_proc_allocate(struct file *filep, loff_t offset, loff_t len) |
| 109 | { |
| 110 | struct rpc_message msg = { |
| 111 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_ALLOCATE], |
| 112 | }; |
| 113 | struct inode *inode = file_inode(filep); |
| 114 | int err; |
| 115 | |
| 116 | if (!nfs_server_capable(inode, NFS_CAP_ALLOCATE)) |
| 117 | return -EOPNOTSUPP; |
| 118 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 119 | inode_lock(inode); |
Anna Schumaker | f830f7d | 2015-03-16 14:06:24 -0400 | [diff] [blame] | 120 | |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 121 | err = nfs42_proc_fallocate(&msg, filep, offset, len); |
| 122 | if (err == -EOPNOTSUPP) |
| 123 | NFS_SERVER(inode)->caps &= ~NFS_CAP_ALLOCATE; |
Anna Schumaker | f830f7d | 2015-03-16 14:06:24 -0400 | [diff] [blame] | 124 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 125 | inode_unlock(inode); |
Anna Schumaker | f4ac167 | 2014-11-25 13:18:15 -0500 | [diff] [blame] | 126 | return err; |
| 127 | } |
| 128 | |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 129 | int nfs42_proc_deallocate(struct file *filep, loff_t offset, loff_t len) |
| 130 | { |
| 131 | struct rpc_message msg = { |
| 132 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_DEALLOCATE], |
| 133 | }; |
| 134 | struct inode *inode = file_inode(filep); |
| 135 | int err; |
| 136 | |
| 137 | if (!nfs_server_capable(inode, NFS_CAP_DEALLOCATE)) |
| 138 | return -EOPNOTSUPP; |
| 139 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 140 | inode_lock(inode); |
Trond Myklebust | 1e564d3 | 2016-06-25 17:50:53 -0400 | [diff] [blame] | 141 | err = nfs_sync_inode(inode); |
| 142 | if (err) |
| 143 | goto out_unlock; |
Anna Schumaker | f830f7d | 2015-03-16 14:06:24 -0400 | [diff] [blame] | 144 | |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 145 | err = nfs42_proc_fallocate(&msg, filep, offset, len); |
Anna Schumaker | 9a51940 | 2015-03-16 14:06:23 -0400 | [diff] [blame] | 146 | if (err == 0) |
| 147 | truncate_pagecache_range(inode, offset, (offset + len) -1); |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 148 | if (err == -EOPNOTSUPP) |
| 149 | NFS_SERVER(inode)->caps &= ~NFS_CAP_DEALLOCATE; |
Trond Myklebust | 1e564d3 | 2016-06-25 17:50:53 -0400 | [diff] [blame] | 150 | out_unlock: |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 151 | inode_unlock(inode); |
Anna Schumaker | 624bd5b | 2014-11-25 13:18:16 -0500 | [diff] [blame] | 152 | return err; |
| 153 | } |
| 154 | |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 155 | static int handle_async_copy(struct nfs42_copy_res *res, |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 156 | struct nfs_server *dst_server, |
| 157 | struct nfs_server *src_server, |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 158 | struct file *src, |
| 159 | struct file *dst, |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 160 | nfs4_stateid *src_stateid, |
| 161 | bool *restart) |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 162 | { |
Olga Kornievskaia | 99f2c55 | 2018-11-21 11:24:22 -0500 | [diff] [blame] | 163 | struct nfs4_copy_state *copy, *tmp_copy; |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 164 | int status = NFS4_OK; |
Olga Kornievskaia | bc0c907 | 2018-07-09 15:13:32 -0400 | [diff] [blame] | 165 | bool found_pending = false; |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 166 | struct nfs_open_context *dst_ctx = nfs_file_open_context(dst); |
| 167 | struct nfs_open_context *src_ctx = nfs_file_open_context(src); |
Olga Kornievskaia | bc0c907 | 2018-07-09 15:13:32 -0400 | [diff] [blame] | 168 | |
Olga Kornievskaia | 99f2c55 | 2018-11-21 11:24:22 -0500 | [diff] [blame] | 169 | copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS); |
| 170 | if (!copy) |
| 171 | return -ENOMEM; |
| 172 | |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 173 | spin_lock(&dst_server->nfs_client->cl_lock); |
| 174 | list_for_each_entry(tmp_copy, |
| 175 | &dst_server->nfs_client->pending_cb_stateids, |
Olga Kornievskaia | bc0c907 | 2018-07-09 15:13:32 -0400 | [diff] [blame] | 176 | copies) { |
Olga Kornievskaia | 99f2c55 | 2018-11-21 11:24:22 -0500 | [diff] [blame] | 177 | if (memcmp(&res->write_res.stateid, &tmp_copy->stateid, |
Olga Kornievskaia | bc0c907 | 2018-07-09 15:13:32 -0400 | [diff] [blame] | 178 | NFS4_STATEID_SIZE)) |
| 179 | continue; |
| 180 | found_pending = true; |
Olga Kornievskaia | 99f2c55 | 2018-11-21 11:24:22 -0500 | [diff] [blame] | 181 | list_del(&tmp_copy->copies); |
Olga Kornievskaia | bc0c907 | 2018-07-09 15:13:32 -0400 | [diff] [blame] | 182 | break; |
| 183 | } |
| 184 | if (found_pending) { |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 185 | spin_unlock(&dst_server->nfs_client->cl_lock); |
Olga Kornievskaia | 99f2c55 | 2018-11-21 11:24:22 -0500 | [diff] [blame] | 186 | kfree(copy); |
| 187 | copy = tmp_copy; |
Olga Kornievskaia | bc0c907 | 2018-07-09 15:13:32 -0400 | [diff] [blame] | 188 | goto out; |
| 189 | } |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 190 | |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 191 | memcpy(©->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE); |
| 192 | init_completion(©->completion); |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 193 | copy->parent_dst_state = dst_ctx->state; |
| 194 | copy->parent_src_state = src_ctx->state; |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 195 | |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 196 | list_add_tail(©->copies, &dst_server->ss_copies); |
| 197 | spin_unlock(&dst_server->nfs_client->cl_lock); |
| 198 | |
| 199 | if (dst_server != src_server) { |
| 200 | spin_lock(&src_server->nfs_client->cl_lock); |
| 201 | list_add_tail(©->src_copies, &src_server->ss_copies); |
| 202 | spin_unlock(&src_server->nfs_client->cl_lock); |
| 203 | } |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 204 | |
Olga Kornievskaia | c975c20 | 2018-07-09 15:13:34 -0400 | [diff] [blame] | 205 | status = wait_for_completion_interruptible(©->completion); |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 206 | spin_lock(&dst_server->nfs_client->cl_lock); |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 207 | list_del_init(©->copies); |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 208 | spin_unlock(&dst_server->nfs_client->cl_lock); |
| 209 | if (dst_server != src_server) { |
| 210 | spin_lock(&src_server->nfs_client->cl_lock); |
| 211 | list_del_init(©->src_copies); |
| 212 | spin_unlock(&src_server->nfs_client->cl_lock); |
| 213 | } |
Olga Kornievskaia | c975c20 | 2018-07-09 15:13:34 -0400 | [diff] [blame] | 214 | if (status == -ERESTARTSYS) { |
Olga Kornievskaia | e4648aa | 2018-08-13 15:33:01 -0400 | [diff] [blame] | 215 | goto out_cancel; |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 216 | } else if (copy->flags || copy->error == NFS4ERR_PARTNER_NO_AUTH) { |
Olga Kornievskaia | e4648aa | 2018-08-13 15:33:01 -0400 | [diff] [blame] | 217 | status = -EAGAIN; |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 218 | *restart = true; |
Olga Kornievskaia | e4648aa | 2018-08-13 15:33:01 -0400 | [diff] [blame] | 219 | goto out_cancel; |
Olga Kornievskaia | c975c20 | 2018-07-09 15:13:34 -0400 | [diff] [blame] | 220 | } |
Olga Kornievskaia | bc0c907 | 2018-07-09 15:13:32 -0400 | [diff] [blame] | 221 | out: |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 222 | res->write_res.count = copy->count; |
| 223 | memcpy(&res->write_res.verifier, ©->verf, sizeof(copy->verf)); |
| 224 | status = -copy->error; |
| 225 | |
Olga Kornievskaia | 1240602 | 2019-07-02 14:57:25 -0400 | [diff] [blame] | 226 | out_free: |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 227 | kfree(copy); |
| 228 | return status; |
Olga Kornievskaia | e4648aa | 2018-08-13 15:33:01 -0400 | [diff] [blame] | 229 | out_cancel: |
| 230 | nfs42_do_offload_cancel_async(dst, ©->stateid); |
Olga Kornievskaia | 1240602 | 2019-07-02 14:57:25 -0400 | [diff] [blame] | 231 | if (!nfs42_files_from_same_server(src, dst)) |
| 232 | nfs42_do_offload_cancel_async(src, src_stateid); |
| 233 | goto out_free; |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 234 | } |
| 235 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 236 | static int process_copy_commit(struct file *dst, loff_t pos_dst, |
| 237 | struct nfs42_copy_res *res) |
| 238 | { |
| 239 | struct nfs_commitres cres; |
| 240 | int status = -ENOMEM; |
| 241 | |
| 242 | cres.verf = kzalloc(sizeof(struct nfs_writeverf), GFP_NOFS); |
| 243 | if (!cres.verf) |
| 244 | goto out; |
| 245 | |
| 246 | status = nfs4_proc_commit(dst, pos_dst, res->write_res.count, &cres); |
| 247 | if (status) |
| 248 | goto out_free; |
| 249 | if (nfs_write_verifier_cmp(&res->write_res.verifier.verifier, |
| 250 | &cres.verf->verifier)) { |
| 251 | dprintk("commit verf differs from copy verf\n"); |
| 252 | status = -EAGAIN; |
| 253 | } |
| 254 | out_free: |
| 255 | kfree(cres.verf); |
| 256 | out: |
| 257 | return status; |
| 258 | } |
| 259 | |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 260 | static ssize_t _nfs42_proc_copy(struct file *src, |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 261 | struct nfs_lock_context *src_lock, |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 262 | struct file *dst, |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 263 | struct nfs_lock_context *dst_lock, |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 264 | struct nfs42_copy_args *args, |
Olga Kornievskaia | 1d38f3f | 2019-06-04 11:54:18 -0400 | [diff] [blame] | 265 | struct nfs42_copy_res *res, |
| 266 | struct nl4_server *nss, |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 267 | nfs4_stateid *cnr_stateid, |
| 268 | bool *restart) |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 269 | { |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 270 | struct rpc_message msg = { |
| 271 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY], |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 272 | .rpc_argp = args, |
| 273 | .rpc_resp = res, |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 274 | }; |
| 275 | struct inode *dst_inode = file_inode(dst); |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 276 | struct inode *src_inode = file_inode(src); |
| 277 | struct nfs_server *dst_server = NFS_SERVER(dst_inode); |
| 278 | struct nfs_server *src_server = NFS_SERVER(src_inode); |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 279 | loff_t pos_src = args->src_pos; |
| 280 | loff_t pos_dst = args->dst_pos; |
| 281 | size_t count = args->count; |
Olga Kornievskaia | 1ee48bd | 2017-07-06 09:43:02 -0400 | [diff] [blame] | 282 | ssize_t status; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 283 | |
Olga Kornievskaia | 1d38f3f | 2019-06-04 11:54:18 -0400 | [diff] [blame] | 284 | if (nss) { |
| 285 | args->cp_src = nss; |
| 286 | nfs4_stateid_copy(&args->src_stateid, cnr_stateid); |
| 287 | } else { |
| 288 | status = nfs4_set_rw_stateid(&args->src_stateid, |
| 289 | src_lock->open_context, src_lock, FMODE_READ); |
| 290 | if (status) |
| 291 | return status; |
| 292 | } |
Trond Myklebust | 837bb1d | 2016-06-25 18:12:03 -0400 | [diff] [blame] | 293 | status = nfs_filemap_write_and_wait_range(file_inode(src)->i_mapping, |
| 294 | pos_src, pos_src + (loff_t)count - 1); |
| 295 | if (status) |
| 296 | return status; |
| 297 | |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 298 | status = nfs4_set_rw_stateid(&args->dst_stateid, dst_lock->open_context, |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 299 | dst_lock, FMODE_WRITE); |
| 300 | if (status) |
| 301 | return status; |
| 302 | |
Trond Myklebust | 837bb1d | 2016-06-25 18:12:03 -0400 | [diff] [blame] | 303 | status = nfs_sync_inode(dst_inode); |
| 304 | if (status) |
| 305 | return status; |
| 306 | |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 307 | res->commit_res.verf = NULL; |
| 308 | if (args->sync) { |
| 309 | res->commit_res.verf = |
| 310 | kzalloc(sizeof(struct nfs_writeverf), GFP_NOFS); |
| 311 | if (!res->commit_res.verf) |
| 312 | return -ENOMEM; |
| 313 | } |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 314 | set_bit(NFS_CLNT_SRC_SSC_COPY_STATE, |
| 315 | &src_lock->open_context->state->flags); |
Olga Kornievskaia | e4648aa | 2018-08-13 15:33:01 -0400 | [diff] [blame] | 316 | set_bit(NFS_CLNT_DST_SSC_COPY_STATE, |
| 317 | &dst_lock->open_context->state->flags); |
| 318 | |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 319 | status = nfs4_call_sync(dst_server->client, dst_server, &msg, |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 320 | &args->seq_args, &res->seq_res, 0); |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 321 | if (status == -ENOTSUPP) |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 322 | dst_server->caps &= ~NFS_CAP_COPY; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 323 | if (status) |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 324 | goto out; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 325 | |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 326 | if (args->sync && |
| 327 | nfs_write_verifier_cmp(&res->write_res.verifier.verifier, |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 328 | &res->commit_res.verf->verifier)) { |
| 329 | status = -EAGAIN; |
| 330 | goto out; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 331 | } |
| 332 | |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 333 | if (!res->synchronous) { |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 334 | status = handle_async_copy(res, dst_server, src_server, src, |
| 335 | dst, &args->src_stateid, restart); |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 336 | if (status) |
| 337 | return status; |
| 338 | } |
| 339 | |
Olga Kornievskaia | 6b8d84e | 2018-07-09 15:13:36 -0400 | [diff] [blame] | 340 | if ((!res->synchronous || !args->sync) && |
| 341 | res->write_res.verifier.committed != NFS_FILE_SYNC) { |
| 342 | status = process_copy_commit(dst, pos_dst, res); |
| 343 | if (status) |
| 344 | return status; |
| 345 | } |
| 346 | |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 347 | truncate_pagecache_range(dst_inode, pos_dst, |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 348 | pos_dst + res->write_res.count); |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 349 | |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 350 | status = res->write_res.count; |
| 351 | out: |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 352 | if (args->sync) |
| 353 | kfree(res->commit_res.verf); |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 354 | return status; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src, |
Olga Kornievskaia | 1d38f3f | 2019-06-04 11:54:18 -0400 | [diff] [blame] | 358 | struct file *dst, loff_t pos_dst, size_t count, |
| 359 | struct nl4_server *nss, |
| 360 | nfs4_stateid *cnr_stateid) |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 361 | { |
| 362 | struct nfs_server *server = NFS_SERVER(file_inode(dst)); |
| 363 | struct nfs_lock_context *src_lock; |
| 364 | struct nfs_lock_context *dst_lock; |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 365 | struct nfs42_copy_args args = { |
| 366 | .src_fh = NFS_FH(file_inode(src)), |
| 367 | .src_pos = pos_src, |
| 368 | .dst_fh = NFS_FH(file_inode(dst)), |
| 369 | .dst_pos = pos_dst, |
| 370 | .count = count, |
Olga Kornievskaia | 62164f3 | 2018-07-09 15:13:31 -0400 | [diff] [blame] | 371 | .sync = false, |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 372 | }; |
| 373 | struct nfs42_copy_res res; |
| 374 | struct nfs4_exception src_exception = { |
| 375 | .inode = file_inode(src), |
| 376 | .stateid = &args.src_stateid, |
| 377 | }; |
| 378 | struct nfs4_exception dst_exception = { |
| 379 | .inode = file_inode(dst), |
| 380 | .stateid = &args.dst_stateid, |
| 381 | }; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 382 | ssize_t err, err2; |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 383 | bool restart = false; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 384 | |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 385 | src_lock = nfs_get_lock_context(nfs_file_open_context(src)); |
| 386 | if (IS_ERR(src_lock)) |
| 387 | return PTR_ERR(src_lock); |
| 388 | |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 389 | src_exception.state = src_lock->open_context->state; |
| 390 | |
| 391 | dst_lock = nfs_get_lock_context(nfs_file_open_context(dst)); |
| 392 | if (IS_ERR(dst_lock)) { |
| 393 | err = PTR_ERR(dst_lock); |
| 394 | goto out_put_src_lock; |
| 395 | } |
| 396 | |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 397 | dst_exception.state = dst_lock->open_context->state; |
| 398 | |
| 399 | do { |
Linus Torvalds | ea8ea73 | 2016-05-26 10:33:33 -0700 | [diff] [blame] | 400 | inode_lock(file_inode(dst)); |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 401 | err = _nfs42_proc_copy(src, src_lock, |
| 402 | dst, dst_lock, |
Olga Kornievskaia | 1d38f3f | 2019-06-04 11:54:18 -0400 | [diff] [blame] | 403 | &args, &res, |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 404 | nss, cnr_stateid, &restart); |
Linus Torvalds | ea8ea73 | 2016-05-26 10:33:33 -0700 | [diff] [blame] | 405 | inode_unlock(file_inode(dst)); |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 406 | |
Trond Myklebust | 9d8cacb | 2017-02-17 18:42:32 -0500 | [diff] [blame] | 407 | if (err >= 0) |
| 408 | break; |
Olga Kornievskaia | 1240602 | 2019-07-02 14:57:25 -0400 | [diff] [blame] | 409 | if (err == -ENOTSUPP && |
| 410 | nfs42_files_from_same_server(src, dst)) { |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 411 | err = -EOPNOTSUPP; |
| 412 | break; |
Olga Kornievskaia | 539f57b | 2018-07-09 15:13:35 -0400 | [diff] [blame] | 413 | } else if (err == -EAGAIN) { |
Olga Kornievskaia | 0e65a32 | 2019-06-14 14:38:40 -0400 | [diff] [blame^] | 414 | if (!restart) { |
| 415 | dst_exception.retry = 1; |
| 416 | continue; |
| 417 | } |
| 418 | break; |
Olga Kornievskaia | 539f57b | 2018-07-09 15:13:35 -0400 | [diff] [blame] | 419 | } else if (err == -NFS4ERR_OFFLOAD_NO_REQS && !args.sync) { |
| 420 | args.sync = true; |
Olga Kornievskaia | e092693 | 2017-05-08 18:02:24 -0400 | [diff] [blame] | 421 | dst_exception.retry = 1; |
| 422 | continue; |
Olga Kornievskaia | 6b61c96 | 2017-09-26 13:51:39 -0400 | [diff] [blame] | 423 | } else if ((err == -ESTALE || |
Olga Kornievskaia | 1240602 | 2019-07-02 14:57:25 -0400 | [diff] [blame] | 424 | err == -NFS4ERR_OFFLOAD_DENIED || |
| 425 | err == -ENOTSUPP) && |
Olga Kornievskaia | 7e35019 | 2017-09-25 15:59:44 -0400 | [diff] [blame] | 426 | !nfs42_files_from_same_server(src, dst)) { |
| 427 | nfs42_do_offload_cancel_async(src, &args.src_stateid); |
| 428 | err = -EOPNOTSUPP; |
| 429 | break; |
Anna Schumaker | 2e72448 | 2013-05-21 16:53:03 -0400 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | err2 = nfs4_handle_exception(server, err, &src_exception); |
| 433 | err = nfs4_handle_exception(server, err, &dst_exception); |
| 434 | if (!err) |
| 435 | err = err2; |
| 436 | } while (src_exception.retry || dst_exception.retry); |
| 437 | |
| 438 | nfs_put_lock_context(dst_lock); |
| 439 | out_put_src_lock: |
| 440 | nfs_put_lock_context(src_lock); |
| 441 | return err; |
| 442 | } |
| 443 | |
Olga Kornievskaia | c975c20 | 2018-07-09 15:13:34 -0400 | [diff] [blame] | 444 | struct nfs42_offloadcancel_data { |
| 445 | struct nfs_server *seq_server; |
| 446 | struct nfs42_offload_status_args args; |
| 447 | struct nfs42_offload_status_res res; |
| 448 | }; |
| 449 | |
| 450 | static void nfs42_offload_cancel_prepare(struct rpc_task *task, void *calldata) |
| 451 | { |
| 452 | struct nfs42_offloadcancel_data *data = calldata; |
| 453 | |
| 454 | nfs4_setup_sequence(data->seq_server->nfs_client, |
| 455 | &data->args.osa_seq_args, |
| 456 | &data->res.osr_seq_res, task); |
| 457 | } |
| 458 | |
| 459 | static void nfs42_offload_cancel_done(struct rpc_task *task, void *calldata) |
| 460 | { |
| 461 | struct nfs42_offloadcancel_data *data = calldata; |
| 462 | |
| 463 | nfs41_sequence_done(task, &data->res.osr_seq_res); |
| 464 | if (task->tk_status && |
| 465 | nfs4_async_handle_error(task, data->seq_server, NULL, |
| 466 | NULL) == -EAGAIN) |
| 467 | rpc_restart_call_prepare(task); |
| 468 | } |
| 469 | |
| 470 | static void nfs42_free_offloadcancel_data(void *data) |
| 471 | { |
| 472 | kfree(data); |
| 473 | } |
| 474 | |
| 475 | static const struct rpc_call_ops nfs42_offload_cancel_ops = { |
| 476 | .rpc_call_prepare = nfs42_offload_cancel_prepare, |
| 477 | .rpc_call_done = nfs42_offload_cancel_done, |
| 478 | .rpc_release = nfs42_free_offloadcancel_data, |
| 479 | }; |
| 480 | |
| 481 | static int nfs42_do_offload_cancel_async(struct file *dst, |
| 482 | nfs4_stateid *stateid) |
| 483 | { |
| 484 | struct nfs_server *dst_server = NFS_SERVER(file_inode(dst)); |
| 485 | struct nfs42_offloadcancel_data *data = NULL; |
| 486 | struct nfs_open_context *ctx = nfs_file_open_context(dst); |
| 487 | struct rpc_task *task; |
| 488 | struct rpc_message msg = { |
| 489 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_OFFLOAD_CANCEL], |
| 490 | .rpc_cred = ctx->cred, |
| 491 | }; |
| 492 | struct rpc_task_setup task_setup_data = { |
| 493 | .rpc_client = dst_server->client, |
| 494 | .rpc_message = &msg, |
| 495 | .callback_ops = &nfs42_offload_cancel_ops, |
| 496 | .workqueue = nfsiod_workqueue, |
| 497 | .flags = RPC_TASK_ASYNC, |
| 498 | }; |
| 499 | int status; |
| 500 | |
| 501 | if (!(dst_server->caps & NFS_CAP_OFFLOAD_CANCEL)) |
| 502 | return -EOPNOTSUPP; |
| 503 | |
| 504 | data = kzalloc(sizeof(struct nfs42_offloadcancel_data), GFP_NOFS); |
| 505 | if (data == NULL) |
| 506 | return -ENOMEM; |
| 507 | |
| 508 | data->seq_server = dst_server; |
| 509 | data->args.osa_src_fh = NFS_FH(file_inode(dst)); |
| 510 | memcpy(&data->args.osa_stateid, stateid, |
| 511 | sizeof(data->args.osa_stateid)); |
| 512 | msg.rpc_argp = &data->args; |
| 513 | msg.rpc_resp = &data->res; |
| 514 | task_setup_data.callback_data = data; |
| 515 | nfs4_init_sequence(&data->args.osa_seq_args, &data->res.osr_seq_res, |
| 516 | 1, 0); |
| 517 | task = rpc_run_task(&task_setup_data); |
| 518 | if (IS_ERR(task)) |
| 519 | return PTR_ERR(task); |
| 520 | status = rpc_wait_for_completion_task(task); |
| 521 | if (status == -ENOTSUPP) |
| 522 | dst_server->caps &= ~NFS_CAP_OFFLOAD_CANCEL; |
| 523 | rpc_put_task(task); |
| 524 | return status; |
| 525 | } |
| 526 | |
Olga Kornievskaia | 0491567 | 2019-06-04 16:14:30 -0400 | [diff] [blame] | 527 | int _nfs42_proc_copy_notify(struct file *src, struct file *dst, |
| 528 | struct nfs42_copy_notify_args *args, |
| 529 | struct nfs42_copy_notify_res *res) |
| 530 | { |
| 531 | struct nfs_server *src_server = NFS_SERVER(file_inode(src)); |
| 532 | struct rpc_message msg = { |
| 533 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY_NOTIFY], |
| 534 | .rpc_argp = args, |
| 535 | .rpc_resp = res, |
| 536 | }; |
| 537 | int status; |
| 538 | struct nfs_open_context *ctx; |
| 539 | struct nfs_lock_context *l_ctx; |
| 540 | |
| 541 | ctx = get_nfs_open_context(nfs_file_open_context(src)); |
| 542 | l_ctx = nfs_get_lock_context(ctx); |
| 543 | if (IS_ERR(l_ctx)) |
| 544 | return PTR_ERR(l_ctx); |
| 545 | |
| 546 | status = nfs4_set_rw_stateid(&args->cna_src_stateid, ctx, l_ctx, |
| 547 | FMODE_READ); |
| 548 | nfs_put_lock_context(l_ctx); |
| 549 | if (status) |
| 550 | return status; |
| 551 | |
| 552 | status = nfs4_call_sync(src_server->client, src_server, &msg, |
| 553 | &args->cna_seq_args, &res->cnr_seq_res, 0); |
| 554 | if (status == -ENOTSUPP) |
| 555 | src_server->caps &= ~NFS_CAP_COPY_NOTIFY; |
| 556 | |
| 557 | put_nfs_open_context(nfs_file_open_context(src)); |
| 558 | return status; |
| 559 | } |
| 560 | |
| 561 | int nfs42_proc_copy_notify(struct file *src, struct file *dst, |
| 562 | struct nfs42_copy_notify_res *res) |
| 563 | { |
| 564 | struct nfs_server *src_server = NFS_SERVER(file_inode(src)); |
| 565 | struct nfs42_copy_notify_args *args; |
| 566 | struct nfs4_exception exception = { |
| 567 | .inode = file_inode(src), |
| 568 | }; |
| 569 | int status; |
| 570 | |
| 571 | if (!(src_server->caps & NFS_CAP_COPY_NOTIFY)) |
| 572 | return -EOPNOTSUPP; |
| 573 | |
| 574 | args = kzalloc(sizeof(struct nfs42_copy_notify_args), GFP_NOFS); |
| 575 | if (args == NULL) |
| 576 | return -ENOMEM; |
| 577 | |
| 578 | args->cna_src_fh = NFS_FH(file_inode(src)), |
| 579 | args->cna_dst.nl4_type = NL4_NETADDR; |
| 580 | nfs42_set_netaddr(dst, &args->cna_dst.u.nl4_addr); |
| 581 | exception.stateid = &args->cna_src_stateid; |
| 582 | |
| 583 | do { |
| 584 | status = _nfs42_proc_copy_notify(src, dst, args, res); |
| 585 | if (status == -ENOTSUPP) { |
| 586 | status = -EOPNOTSUPP; |
| 587 | goto out; |
| 588 | } |
| 589 | status = nfs4_handle_exception(src_server, status, &exception); |
| 590 | } while (exception.retry); |
| 591 | |
| 592 | out: |
| 593 | kfree(args); |
| 594 | return status; |
| 595 | } |
| 596 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 597 | static loff_t _nfs42_proc_llseek(struct file *filep, |
| 598 | struct nfs_lock_context *lock, loff_t offset, int whence) |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 599 | { |
| 600 | struct inode *inode = file_inode(filep); |
| 601 | struct nfs42_seek_args args = { |
| 602 | .sa_fh = NFS_FH(inode), |
| 603 | .sa_offset = offset, |
| 604 | .sa_what = (whence == SEEK_HOLE) ? |
| 605 | NFS4_CONTENT_HOLE : NFS4_CONTENT_DATA, |
| 606 | }; |
| 607 | struct nfs42_seek_res res; |
| 608 | struct rpc_message msg = { |
| 609 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_SEEK], |
| 610 | .rpc_argp = &args, |
| 611 | .rpc_resp = &res, |
| 612 | }; |
| 613 | struct nfs_server *server = NFS_SERVER(inode); |
| 614 | int status; |
| 615 | |
Anna Schumaker | 878ffa9 | 2014-10-23 14:00:54 -0400 | [diff] [blame] | 616 | if (!nfs_server_capable(inode, NFS_CAP_SEEK)) |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 617 | return -ENOTSUPP; |
| 618 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 619 | status = nfs4_set_rw_stateid(&args.sa_stateid, lock->open_context, |
| 620 | lock, FMODE_READ); |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 621 | if (status) |
| 622 | return status; |
| 623 | |
Trond Myklebust | e95fc4a | 2016-06-25 17:57:39 -0400 | [diff] [blame] | 624 | status = nfs_filemap_write_and_wait_range(inode->i_mapping, |
| 625 | offset, LLONG_MAX); |
| 626 | if (status) |
| 627 | return status; |
| 628 | |
Anna Schumaker | 1c6dcbe | 2014-09-26 13:58:48 -0400 | [diff] [blame] | 629 | status = nfs4_call_sync(server->client, server, &msg, |
| 630 | &args.seq_args, &res.seq_res, 0); |
| 631 | if (status == -ENOTSUPP) |
| 632 | server->caps &= ~NFS_CAP_SEEK; |
| 633 | if (status) |
| 634 | return status; |
| 635 | |
| 636 | return vfs_setpos(filep, res.sr_offset, inode->i_sb->s_maxbytes); |
| 637 | } |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 638 | |
J. Bruce Fields | bdcc2cd | 2015-07-23 11:08:43 -0400 | [diff] [blame] | 639 | loff_t nfs42_proc_llseek(struct file *filep, loff_t offset, int whence) |
| 640 | { |
| 641 | struct nfs_server *server = NFS_SERVER(file_inode(filep)); |
| 642 | struct nfs4_exception exception = { }; |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 643 | struct nfs_lock_context *lock; |
J. Bruce Fields | 306a554 | 2015-09-16 17:21:27 -0400 | [diff] [blame] | 644 | loff_t err; |
J. Bruce Fields | bdcc2cd | 2015-07-23 11:08:43 -0400 | [diff] [blame] | 645 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 646 | lock = nfs_get_lock_context(nfs_file_open_context(filep)); |
| 647 | if (IS_ERR(lock)) |
| 648 | return PTR_ERR(lock); |
| 649 | |
| 650 | exception.inode = file_inode(filep); |
| 651 | exception.state = lock->open_context->state; |
| 652 | |
J. Bruce Fields | bdcc2cd | 2015-07-23 11:08:43 -0400 | [diff] [blame] | 653 | do { |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 654 | err = _nfs42_proc_llseek(filep, lock, offset, whence); |
J. Bruce Fields | 306a554 | 2015-09-16 17:21:27 -0400 | [diff] [blame] | 655 | if (err >= 0) |
| 656 | break; |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 657 | if (err == -ENOTSUPP) { |
| 658 | err = -EOPNOTSUPP; |
| 659 | break; |
| 660 | } |
J. Bruce Fields | bdcc2cd | 2015-07-23 11:08:43 -0400 | [diff] [blame] | 661 | err = nfs4_handle_exception(server, err, &exception); |
| 662 | } while (exception.retry); |
| 663 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 664 | nfs_put_lock_context(lock); |
J. Bruce Fields | bdcc2cd | 2015-07-23 11:08:43 -0400 | [diff] [blame] | 665 | return err; |
| 666 | } |
| 667 | |
| 668 | |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 669 | static void |
| 670 | nfs42_layoutstat_prepare(struct rpc_task *task, void *calldata) |
| 671 | { |
| 672 | struct nfs42_layoutstat_data *data = calldata; |
Trond Myklebust | 9a0fe86 | 2016-08-19 15:33:12 -0400 | [diff] [blame] | 673 | struct inode *inode = data->inode; |
| 674 | struct nfs_server *server = NFS_SERVER(inode); |
| 675 | struct pnfs_layout_hdr *lo; |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 676 | |
Trond Myklebust | 9a0fe86 | 2016-08-19 15:33:12 -0400 | [diff] [blame] | 677 | spin_lock(&inode->i_lock); |
| 678 | lo = NFS_I(inode)->layout; |
| 679 | if (!pnfs_layout_is_valid(lo)) { |
| 680 | spin_unlock(&inode->i_lock); |
| 681 | rpc_exit(task, 0); |
| 682 | return; |
| 683 | } |
| 684 | nfs4_stateid_copy(&data->args.stateid, &lo->plh_stateid); |
| 685 | spin_unlock(&inode->i_lock); |
Anna Schumaker | 6de7e12 | 2017-01-09 16:51:52 -0500 | [diff] [blame] | 686 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 687 | &data->res.seq_res, task); |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | static void |
| 691 | nfs42_layoutstat_done(struct rpc_task *task, void *calldata) |
| 692 | { |
| 693 | struct nfs42_layoutstat_data *data = calldata; |
Peng Tao | 68d264c | 2015-12-06 20:55:09 -0500 | [diff] [blame] | 694 | struct inode *inode = data->inode; |
| 695 | struct pnfs_layout_hdr *lo; |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 696 | |
| 697 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 698 | return; |
| 699 | |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 700 | switch (task->tk_status) { |
| 701 | case 0: |
| 702 | break; |
Trond Myklebust | cf61eb2 | 2018-05-29 22:06:08 -0400 | [diff] [blame] | 703 | case -NFS4ERR_BADHANDLE: |
| 704 | case -ESTALE: |
| 705 | pnfs_destroy_layout(NFS_I(inode)); |
| 706 | break; |
Peng Tao | 68d264c | 2015-12-06 20:55:09 -0500 | [diff] [blame] | 707 | case -NFS4ERR_EXPIRED: |
Trond Myklebust | 206b3bb | 2016-08-05 12:16:19 -0400 | [diff] [blame] | 708 | case -NFS4ERR_ADMIN_REVOKED: |
| 709 | case -NFS4ERR_DELEG_REVOKED: |
Peng Tao | 68d264c | 2015-12-06 20:55:09 -0500 | [diff] [blame] | 710 | case -NFS4ERR_STALE_STATEID: |
Peng Tao | 68d264c | 2015-12-06 20:55:09 -0500 | [diff] [blame] | 711 | case -NFS4ERR_BAD_STATEID: |
| 712 | spin_lock(&inode->i_lock); |
| 713 | lo = NFS_I(inode)->layout; |
Trond Myklebust | 9a0fe86 | 2016-08-19 15:33:12 -0400 | [diff] [blame] | 714 | if (pnfs_layout_is_valid(lo) && |
| 715 | nfs4_stateid_match(&data->args.stateid, |
Peng Tao | 68d264c | 2015-12-06 20:55:09 -0500 | [diff] [blame] | 716 | &lo->plh_stateid)) { |
| 717 | LIST_HEAD(head); |
| 718 | |
| 719 | /* |
| 720 | * Mark the bad layout state as invalid, then retry |
| 721 | * with the current stateid. |
| 722 | */ |
Trond Myklebust | 5f46be0 | 2016-07-22 11:25:27 -0400 | [diff] [blame] | 723 | pnfs_mark_layout_stateid_invalid(lo, &head); |
Peng Tao | 68d264c | 2015-12-06 20:55:09 -0500 | [diff] [blame] | 724 | spin_unlock(&inode->i_lock); |
| 725 | pnfs_free_lseg_list(&head); |
Trond Myklebust | 1f18b82 | 2017-04-29 10:10:17 -0400 | [diff] [blame] | 726 | nfs_commit_inode(inode, 0); |
Peng Tao | 68d264c | 2015-12-06 20:55:09 -0500 | [diff] [blame] | 727 | } else |
| 728 | spin_unlock(&inode->i_lock); |
| 729 | break; |
Trond Myklebust | 9a0fe86 | 2016-08-19 15:33:12 -0400 | [diff] [blame] | 730 | case -NFS4ERR_OLD_STATEID: |
| 731 | spin_lock(&inode->i_lock); |
| 732 | lo = NFS_I(inode)->layout; |
| 733 | if (pnfs_layout_is_valid(lo) && |
| 734 | nfs4_stateid_match_other(&data->args.stateid, |
| 735 | &lo->plh_stateid)) { |
| 736 | /* Do we need to delay before resending? */ |
| 737 | if (!nfs4_stateid_is_newer(&lo->plh_stateid, |
| 738 | &data->args.stateid)) |
| 739 | rpc_delay(task, HZ); |
| 740 | rpc_restart_call_prepare(task); |
| 741 | } |
| 742 | spin_unlock(&inode->i_lock); |
| 743 | break; |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 744 | case -ENOTSUPP: |
| 745 | case -EOPNOTSUPP: |
Peng Tao | 68d264c | 2015-12-06 20:55:09 -0500 | [diff] [blame] | 746 | NFS_SERVER(inode)->caps &= ~NFS_CAP_LAYOUTSTATS; |
Trond Myklebust | 6c5a0d8 | 2015-06-27 11:45:46 -0400 | [diff] [blame] | 747 | } |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | static void |
| 751 | nfs42_layoutstat_release(void *calldata) |
| 752 | { |
| 753 | struct nfs42_layoutstat_data *data = calldata; |
Trond Myklebust | 422c93c | 2016-10-06 17:53:20 -0400 | [diff] [blame] | 754 | struct nfs42_layoutstat_devinfo *devinfo = data->args.devinfo; |
| 755 | int i; |
Peng Tao | 8733408 | 2015-06-23 19:51:57 +0800 | [diff] [blame] | 756 | |
Trond Myklebust | 422c93c | 2016-10-06 17:53:20 -0400 | [diff] [blame] | 757 | for (i = 0; i < data->args.num_dev; i++) { |
| 758 | if (devinfo[i].ld_private.ops && devinfo[i].ld_private.ops->free) |
| 759 | devinfo[i].ld_private.ops->free(&devinfo[i].ld_private); |
| 760 | } |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 761 | |
| 762 | pnfs_put_layout_hdr(NFS_I(data->args.inode)->layout); |
Peng Tao | 1bfe3b2 | 2015-06-23 19:52:03 +0800 | [diff] [blame] | 763 | smp_mb__before_atomic(); |
| 764 | clear_bit(NFS_INO_LAYOUTSTATS, &NFS_I(data->args.inode)->flags); |
| 765 | smp_mb__after_atomic(); |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 766 | nfs_iput_and_deactive(data->inode); |
| 767 | kfree(data->args.devinfo); |
| 768 | kfree(data); |
| 769 | } |
| 770 | |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 771 | static const struct rpc_call_ops nfs42_layoutstat_ops = { |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 772 | .rpc_call_prepare = nfs42_layoutstat_prepare, |
| 773 | .rpc_call_done = nfs42_layoutstat_done, |
| 774 | .rpc_release = nfs42_layoutstat_release, |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 775 | }; |
| 776 | |
| 777 | int nfs42_proc_layoutstats_generic(struct nfs_server *server, |
| 778 | struct nfs42_layoutstat_data *data) |
| 779 | { |
| 780 | struct rpc_message msg = { |
| 781 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTSTATS], |
| 782 | .rpc_argp = &data->args, |
| 783 | .rpc_resp = &data->res, |
| 784 | }; |
| 785 | struct rpc_task_setup task_setup = { |
| 786 | .rpc_client = server->client, |
| 787 | .rpc_message = &msg, |
| 788 | .callback_ops = &nfs42_layoutstat_ops, |
| 789 | .callback_data = data, |
| 790 | .flags = RPC_TASK_ASYNC, |
| 791 | }; |
| 792 | struct rpc_task *task; |
| 793 | |
Peng Tao | 1b4a4bd | 2015-06-23 19:51:56 +0800 | [diff] [blame] | 794 | data->inode = nfs_igrab_and_active(data->args.inode); |
| 795 | if (!data->inode) { |
| 796 | nfs42_layoutstat_release(data); |
| 797 | return -EAGAIN; |
| 798 | } |
Anna Schumaker | fba83f3 | 2018-05-04 16:22:50 -0400 | [diff] [blame] | 799 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0); |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 800 | task = rpc_run_task(&task_setup); |
| 801 | if (IS_ERR(task)) |
| 802 | return PTR_ERR(task); |
Jeff Layton | 3f807e5 | 2016-10-04 00:07:43 -0400 | [diff] [blame] | 803 | rpc_put_task(task); |
Trond Myklebust | be3a5d2 | 2015-06-23 19:51:55 +0800 | [diff] [blame] | 804 | return 0; |
| 805 | } |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 806 | |
Trond Myklebust | 3eb8609 | 2019-02-08 10:31:05 -0500 | [diff] [blame] | 807 | static struct nfs42_layouterror_data * |
| 808 | nfs42_alloc_layouterror_data(struct pnfs_layout_segment *lseg, gfp_t gfp_flags) |
| 809 | { |
| 810 | struct nfs42_layouterror_data *data; |
| 811 | struct inode *inode = lseg->pls_layout->plh_inode; |
| 812 | |
| 813 | data = kzalloc(sizeof(*data), gfp_flags); |
| 814 | if (data) { |
| 815 | data->args.inode = data->inode = nfs_igrab_and_active(inode); |
| 816 | if (data->inode) { |
| 817 | data->lseg = pnfs_get_lseg(lseg); |
| 818 | if (data->lseg) |
| 819 | return data; |
| 820 | nfs_iput_and_deactive(data->inode); |
| 821 | } |
| 822 | kfree(data); |
| 823 | } |
| 824 | return NULL; |
| 825 | } |
| 826 | |
| 827 | static void |
| 828 | nfs42_free_layouterror_data(struct nfs42_layouterror_data *data) |
| 829 | { |
| 830 | pnfs_put_lseg(data->lseg); |
| 831 | nfs_iput_and_deactive(data->inode); |
| 832 | kfree(data); |
| 833 | } |
| 834 | |
| 835 | static void |
| 836 | nfs42_layouterror_prepare(struct rpc_task *task, void *calldata) |
| 837 | { |
| 838 | struct nfs42_layouterror_data *data = calldata; |
| 839 | struct inode *inode = data->inode; |
| 840 | struct nfs_server *server = NFS_SERVER(inode); |
| 841 | struct pnfs_layout_hdr *lo = data->lseg->pls_layout; |
| 842 | unsigned i; |
| 843 | |
| 844 | spin_lock(&inode->i_lock); |
| 845 | if (!pnfs_layout_is_valid(lo)) { |
| 846 | spin_unlock(&inode->i_lock); |
| 847 | rpc_exit(task, 0); |
| 848 | return; |
| 849 | } |
| 850 | for (i = 0; i < data->args.num_errors; i++) |
| 851 | nfs4_stateid_copy(&data->args.errors[i].stateid, |
| 852 | &lo->plh_stateid); |
| 853 | spin_unlock(&inode->i_lock); |
| 854 | nfs4_setup_sequence(server->nfs_client, &data->args.seq_args, |
| 855 | &data->res.seq_res, task); |
| 856 | } |
| 857 | |
| 858 | static void |
| 859 | nfs42_layouterror_done(struct rpc_task *task, void *calldata) |
| 860 | { |
| 861 | struct nfs42_layouterror_data *data = calldata; |
| 862 | struct inode *inode = data->inode; |
| 863 | struct pnfs_layout_hdr *lo = data->lseg->pls_layout; |
| 864 | |
| 865 | if (!nfs4_sequence_done(task, &data->res.seq_res)) |
| 866 | return; |
| 867 | |
| 868 | switch (task->tk_status) { |
| 869 | case 0: |
| 870 | break; |
| 871 | case -NFS4ERR_BADHANDLE: |
| 872 | case -ESTALE: |
| 873 | pnfs_destroy_layout(NFS_I(inode)); |
| 874 | break; |
| 875 | case -NFS4ERR_EXPIRED: |
| 876 | case -NFS4ERR_ADMIN_REVOKED: |
| 877 | case -NFS4ERR_DELEG_REVOKED: |
| 878 | case -NFS4ERR_STALE_STATEID: |
| 879 | case -NFS4ERR_BAD_STATEID: |
| 880 | spin_lock(&inode->i_lock); |
| 881 | if (pnfs_layout_is_valid(lo) && |
| 882 | nfs4_stateid_match(&data->args.errors[0].stateid, |
| 883 | &lo->plh_stateid)) { |
| 884 | LIST_HEAD(head); |
| 885 | |
| 886 | /* |
| 887 | * Mark the bad layout state as invalid, then retry |
| 888 | * with the current stateid. |
| 889 | */ |
| 890 | pnfs_mark_layout_stateid_invalid(lo, &head); |
| 891 | spin_unlock(&inode->i_lock); |
| 892 | pnfs_free_lseg_list(&head); |
| 893 | nfs_commit_inode(inode, 0); |
| 894 | } else |
| 895 | spin_unlock(&inode->i_lock); |
| 896 | break; |
| 897 | case -NFS4ERR_OLD_STATEID: |
| 898 | spin_lock(&inode->i_lock); |
| 899 | if (pnfs_layout_is_valid(lo) && |
| 900 | nfs4_stateid_match_other(&data->args.errors[0].stateid, |
| 901 | &lo->plh_stateid)) { |
| 902 | /* Do we need to delay before resending? */ |
| 903 | if (!nfs4_stateid_is_newer(&lo->plh_stateid, |
| 904 | &data->args.errors[0].stateid)) |
| 905 | rpc_delay(task, HZ); |
| 906 | rpc_restart_call_prepare(task); |
| 907 | } |
| 908 | spin_unlock(&inode->i_lock); |
| 909 | break; |
| 910 | case -ENOTSUPP: |
| 911 | case -EOPNOTSUPP: |
| 912 | NFS_SERVER(inode)->caps &= ~NFS_CAP_LAYOUTERROR; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | static void |
| 917 | nfs42_layouterror_release(void *calldata) |
| 918 | { |
| 919 | struct nfs42_layouterror_data *data = calldata; |
| 920 | |
| 921 | nfs42_free_layouterror_data(data); |
| 922 | } |
| 923 | |
| 924 | static const struct rpc_call_ops nfs42_layouterror_ops = { |
| 925 | .rpc_call_prepare = nfs42_layouterror_prepare, |
| 926 | .rpc_call_done = nfs42_layouterror_done, |
| 927 | .rpc_release = nfs42_layouterror_release, |
| 928 | }; |
| 929 | |
| 930 | int nfs42_proc_layouterror(struct pnfs_layout_segment *lseg, |
| 931 | const struct nfs42_layout_error *errors, size_t n) |
| 932 | { |
| 933 | struct inode *inode = lseg->pls_layout->plh_inode; |
| 934 | struct nfs42_layouterror_data *data; |
| 935 | struct rpc_task *task; |
| 936 | struct rpc_message msg = { |
| 937 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_LAYOUTERROR], |
| 938 | }; |
| 939 | struct rpc_task_setup task_setup = { |
| 940 | .rpc_message = &msg, |
| 941 | .callback_ops = &nfs42_layouterror_ops, |
| 942 | .flags = RPC_TASK_ASYNC, |
| 943 | }; |
| 944 | unsigned int i; |
| 945 | |
| 946 | if (!nfs_server_capable(inode, NFS_CAP_LAYOUTERROR)) |
| 947 | return -EOPNOTSUPP; |
| 948 | if (n > NFS42_LAYOUTERROR_MAX) |
| 949 | return -EINVAL; |
| 950 | data = nfs42_alloc_layouterror_data(lseg, GFP_NOFS); |
| 951 | if (!data) |
| 952 | return -ENOMEM; |
| 953 | for (i = 0; i < n; i++) { |
| 954 | data->args.errors[i] = errors[i]; |
| 955 | data->args.num_errors++; |
| 956 | data->res.num_errors++; |
| 957 | } |
| 958 | msg.rpc_argp = &data->args; |
| 959 | msg.rpc_resp = &data->res; |
| 960 | task_setup.callback_data = data; |
| 961 | task_setup.rpc_client = NFS_SERVER(inode)->client; |
| 962 | nfs4_init_sequence(&data->args.seq_args, &data->res.seq_res, 0, 0); |
| 963 | task = rpc_run_task(&task_setup); |
| 964 | if (IS_ERR(task)) |
| 965 | return PTR_ERR(task); |
| 966 | rpc_put_task(task); |
| 967 | return 0; |
| 968 | } |
| 969 | EXPORT_SYMBOL_GPL(nfs42_proc_layouterror); |
| 970 | |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 971 | static int _nfs42_proc_clone(struct rpc_message *msg, struct file *src_f, |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 972 | struct file *dst_f, struct nfs_lock_context *src_lock, |
| 973 | struct nfs_lock_context *dst_lock, loff_t src_offset, |
| 974 | loff_t dst_offset, loff_t count) |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 975 | { |
| 976 | struct inode *src_inode = file_inode(src_f); |
| 977 | struct inode *dst_inode = file_inode(dst_f); |
| 978 | struct nfs_server *server = NFS_SERVER(dst_inode); |
| 979 | struct nfs42_clone_args args = { |
| 980 | .src_fh = NFS_FH(src_inode), |
| 981 | .dst_fh = NFS_FH(dst_inode), |
| 982 | .src_offset = src_offset, |
| 983 | .dst_offset = dst_offset, |
Christoph Hellwig | 9494b2c | 2015-11-13 09:38:45 +0100 | [diff] [blame] | 984 | .count = count, |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 985 | .dst_bitmask = server->cache_consistency_bitmask, |
| 986 | }; |
| 987 | struct nfs42_clone_res res = { |
| 988 | .server = server, |
| 989 | }; |
| 990 | int status; |
| 991 | |
| 992 | msg->rpc_argp = &args; |
| 993 | msg->rpc_resp = &res; |
| 994 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 995 | status = nfs4_set_rw_stateid(&args.src_stateid, src_lock->open_context, |
| 996 | src_lock, FMODE_READ); |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 997 | if (status) |
| 998 | return status; |
| 999 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 1000 | status = nfs4_set_rw_stateid(&args.dst_stateid, dst_lock->open_context, |
| 1001 | dst_lock, FMODE_WRITE); |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 1002 | if (status) |
| 1003 | return status; |
| 1004 | |
| 1005 | res.dst_fattr = nfs_alloc_fattr(); |
| 1006 | if (!res.dst_fattr) |
| 1007 | return -ENOMEM; |
| 1008 | |
| 1009 | status = nfs4_call_sync(server->client, server, msg, |
| 1010 | &args.seq_args, &res.seq_res, 0); |
| 1011 | if (status == 0) |
| 1012 | status = nfs_post_op_update_inode(dst_inode, res.dst_fattr); |
| 1013 | |
| 1014 | kfree(res.dst_fattr); |
| 1015 | return status; |
| 1016 | } |
| 1017 | |
| 1018 | int nfs42_proc_clone(struct file *src_f, struct file *dst_f, |
| 1019 | loff_t src_offset, loff_t dst_offset, loff_t count) |
| 1020 | { |
| 1021 | struct rpc_message msg = { |
| 1022 | .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_CLONE], |
| 1023 | }; |
| 1024 | struct inode *inode = file_inode(src_f); |
| 1025 | struct nfs_server *server = NFS_SERVER(file_inode(src_f)); |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 1026 | struct nfs_lock_context *src_lock; |
| 1027 | struct nfs_lock_context *dst_lock; |
| 1028 | struct nfs4_exception src_exception = { }; |
| 1029 | struct nfs4_exception dst_exception = { }; |
| 1030 | int err, err2; |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 1031 | |
| 1032 | if (!nfs_server_capable(inode, NFS_CAP_CLONE)) |
| 1033 | return -EOPNOTSUPP; |
| 1034 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 1035 | src_lock = nfs_get_lock_context(nfs_file_open_context(src_f)); |
| 1036 | if (IS_ERR(src_lock)) |
| 1037 | return PTR_ERR(src_lock); |
| 1038 | |
| 1039 | src_exception.inode = file_inode(src_f); |
| 1040 | src_exception.state = src_lock->open_context->state; |
| 1041 | |
| 1042 | dst_lock = nfs_get_lock_context(nfs_file_open_context(dst_f)); |
| 1043 | if (IS_ERR(dst_lock)) { |
| 1044 | err = PTR_ERR(dst_lock); |
| 1045 | goto out_put_src_lock; |
| 1046 | } |
| 1047 | |
| 1048 | dst_exception.inode = file_inode(dst_f); |
| 1049 | dst_exception.state = dst_lock->open_context->state; |
| 1050 | |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 1051 | do { |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 1052 | err = _nfs42_proc_clone(&msg, src_f, dst_f, src_lock, dst_lock, |
| 1053 | src_offset, dst_offset, count); |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 1054 | if (err == -ENOTSUPP || err == -EOPNOTSUPP) { |
| 1055 | NFS_SERVER(inode)->caps &= ~NFS_CAP_CLONE; |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 1056 | err = -EOPNOTSUPP; |
| 1057 | break; |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 1058 | } |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 1059 | |
Christoph Hellwig | 4bdf87e | 2016-02-17 15:48:28 +0100 | [diff] [blame] | 1060 | err2 = nfs4_handle_exception(server, err, &src_exception); |
| 1061 | err = nfs4_handle_exception(server, err, &dst_exception); |
| 1062 | if (!err) |
| 1063 | err = err2; |
| 1064 | } while (src_exception.retry || dst_exception.retry); |
| 1065 | |
| 1066 | nfs_put_lock_context(dst_lock); |
| 1067 | out_put_src_lock: |
| 1068 | nfs_put_lock_context(src_lock); |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 1069 | return err; |
Peng Tao | e5341f3 | 2015-09-26 02:24:35 +0800 | [diff] [blame] | 1070 | } |