History

NFS: handle source server reboot

When the source server reboots after a server-to-server copy was issued, we need to retry the copy from COPY_NOTIFY. We need to detect that the source server rebooted and there is a copy waiting on a destination server and wake it up.

Olga Kornievskaia committed 7 years ago

Commit 0e65a321 parent fefa1a85 files · +75 −27Browse files

Unified · Split

5 files
  1. fs/nfs/nfs42proc.c +47 −21
  2. fs/nfs/nfs4_fs.h +1 −0
  3. fs/nfs/nfs4file.c +3 −0
  4. fs/nfs/nfs4state.c +21 −5
  5. include/linux/nfs_fs.h +3 −1
fs/nfs/nfs42proc.c+47−21
@@ -153,22 +153,26 @@ out_unlock: · 152 unmodified lines
153}153}
154 154
155static int handle_async_copy(struct nfs42_copy_res *res,155static int handle_async_copy(struct nfs42_copy_res *res,
156 struct nfs_server *server,156 struct nfs_server *dst_server,
157 struct nfs_server *src_server,
157 struct file *src,158 struct file *src,
158 struct file *dst,159 struct file *dst,
159 nfs4_stateid *src_stateid)160 nfs4_stateid *src_stateid,
161 bool *restart)
160{162{
161 struct nfs4_copy_state *copy, *tmp_copy;163 struct nfs4_copy_state *copy, *tmp_copy;
162 int status = NFS4_OK;164 int status = NFS4_OK;
163 bool found_pending = false;165 bool found_pending = false;
164 struct nfs_open_context *ctx = nfs_file_open_context(dst);166 struct nfs_open_context *dst_ctx = nfs_file_open_context(dst);
167 struct nfs_open_context *src_ctx = nfs_file_open_context(src);
165 168
166 copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS);169 copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS);
167 if (!copy)170 if (!copy)
168 return -ENOMEM;171 return -ENOMEM;
169 172
170 spin_lock(&server->nfs_client->cl_lock);173 spin_lock(&dst_server->nfs_client->cl_lock);
171 list_for_each_entry(tmp_copy, &server->nfs_client->pending_cb_stateids,174 list_for_each_entry(tmp_copy,
175 &dst_server->nfs_client->pending_cb_stateids,
172 copies) {176 copies) {
173 if (memcmp(&res->write_res.stateid, &tmp_copy->stateid,177 if (memcmp(&res->write_res.stateid, &tmp_copy->stateid,
174 NFS4_STATEID_SIZE))178 NFS4_STATEID_SIZE))
@@ -178,7 +182,7 @@ static int handle_async_copy(struct nfs42_copy_res *res, · 3 unmodified lines
178 break;182 break;
179 }183 }
180 if (found_pending) {184 if (found_pending) {
181 spin_unlock(&server->nfs_client->cl_lock);185 spin_unlock(&dst_server->nfs_client->cl_lock);
182 kfree(copy);186 kfree(copy);
183 copy = tmp_copy;187 copy = tmp_copy;
184 goto out;188 goto out;
@@ -186,19 +190,32 @@ static int handle_async_copy(struct nfs42_copy_res *res, · 1 unmodified line
186 190
187 memcpy(&copy->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE);191 memcpy(&copy->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE);
188 init_completion(&copy->completion);192 init_completion(&copy->completion);
189 copy->parent_state = ctx->state;193 copy->parent_dst_state = dst_ctx->state;
194 copy->parent_src_state = src_ctx->state;
195
196 list_add_tail(&copy->copies, &dst_server->ss_copies);
197 spin_unlock(&dst_server->nfs_client->cl_lock);
190 198
191 list_add_tail(&copy->copies, &server->ss_copies);199 if (dst_server != src_server) {
192 spin_unlock(&server->nfs_client->cl_lock);200 spin_lock(&src_server->nfs_client->cl_lock);
201 list_add_tail(&copy->src_copies, &src_server->ss_copies);
202 spin_unlock(&src_server->nfs_client->cl_lock);
203 }
193 204
194 status = wait_for_completion_interruptible(&copy->completion);205 status = wait_for_completion_interruptible(&copy->completion);
195 spin_lock(&server->nfs_client->cl_lock);206 spin_lock(&dst_server->nfs_client->cl_lock);
196 list_del_init(&copy->copies);207 list_del_init(&copy->copies);
197 spin_unlock(&server->nfs_client->cl_lock);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(&copy->src_copies);
212 spin_unlock(&src_server->nfs_client->cl_lock);
213 }
198 if (status == -ERESTARTSYS) {214 if (status == -ERESTARTSYS) {
199 goto out_cancel;215 goto out_cancel;
200 } else if (copy->flags) {216 } else if (copy->flags || copy->error == NFS4ERR_PARTNER_NO_AUTH) {
201 status = -EAGAIN;217 status = -EAGAIN;
218 *restart = true;
202 goto out_cancel;219 goto out_cancel;
203 }220 }
204out:221out:
@@ -247,7 +264,8 @@ static ssize_t _nfs42_proc_copy(struct file *src, · 42 unmodified lines
247 struct nfs42_copy_args *args,264 struct nfs42_copy_args *args,
248 struct nfs42_copy_res *res,265 struct nfs42_copy_res *res,
249 struct nl4_server *nss,266 struct nl4_server *nss,
250 nfs4_stateid *cnr_stateid)267 nfs4_stateid *cnr_stateid,
268 bool *restart)
251{269{
252 struct rpc_message msg = {270 struct rpc_message msg = {
253 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY],271 .rpc_proc = &nfs4_procedures[NFSPROC4_CLNT_COPY],
@@ -255,7 +273,9 @@ static ssize_t _nfs42_proc_copy(struct file *src, · 1 unmodified line
255 .rpc_resp = res,273 .rpc_resp = res,
256 };274 };
257 struct inode *dst_inode = file_inode(dst);275 struct inode *dst_inode = file_inode(dst);
258 struct nfs_server *server = NFS_SERVER(dst_inode);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);
259 loff_t pos_src = args->src_pos;279 loff_t pos_src = args->src_pos;
260 loff_t pos_dst = args->dst_pos;280 loff_t pos_dst = args->dst_pos;
261 size_t count = args->count;281 size_t count = args->count;
@@ -291,13 +311,15 @@ static ssize_t _nfs42_proc_copy(struct file *src, · 29 unmodified lines
291 if (!res->commit_res.verf)311 if (!res->commit_res.verf)
292 return -ENOMEM;312 return -ENOMEM;
293 }313 }
314 set_bit(NFS_CLNT_SRC_SSC_COPY_STATE,
315 &src_lock->open_context->state->flags);
294 set_bit(NFS_CLNT_DST_SSC_COPY_STATE,316 set_bit(NFS_CLNT_DST_SSC_COPY_STATE,
295 &dst_lock->open_context->state->flags);317 &dst_lock->open_context->state->flags);
296 318
297 status = nfs4_call_sync(server->client, server, &msg,319 status = nfs4_call_sync(dst_server->client, dst_server, &msg,
298 &args->seq_args, &res->seq_res, 0);320 &args->seq_args, &res->seq_res, 0);
299 if (status == -ENOTSUPP)321 if (status == -ENOTSUPP)
300 server->caps &= ~NFS_CAP_COPY;322 dst_server->caps &= ~NFS_CAP_COPY;
301 if (status)323 if (status)
302 goto out;324 goto out;
303 325
@@ -309,8 +331,8 @@ static ssize_t _nfs42_proc_copy(struct file *src, · 5 unmodified lines
309 }331 }
310 332
311 if (!res->synchronous) {333 if (!res->synchronous) {
312 status = handle_async_copy(res, server, src, dst,334 status = handle_async_copy(res, dst_server, src_server, src,
313 &args->src_stateid);335 dst, &args->src_stateid, restart);
314 if (status)336 if (status)
315 return status;337 return status;
316 }338 }
@@ -358,6 +380,7 @@ ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src, · 41 unmodified lines
358 .stateid = &args.dst_stateid,380 .stateid = &args.dst_stateid,
359 };381 };
360 ssize_t err, err2;382 ssize_t err, err2;
383 bool restart = false;
361 384
362 src_lock = nfs_get_lock_context(nfs_file_open_context(src));385 src_lock = nfs_get_lock_context(nfs_file_open_context(src));
363 if (IS_ERR(src_lock))386 if (IS_ERR(src_lock))
@@ -378,7 +401,7 @@ ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src, · 14 unmodified lines
378 err = _nfs42_proc_copy(src, src_lock,401 err = _nfs42_proc_copy(src, src_lock,
379 dst, dst_lock,402 dst, dst_lock,
380 &args, &res,403 &args, &res,
381 nss, cnr_stateid);404 nss, cnr_stateid, &restart);
382 inode_unlock(file_inode(dst));405 inode_unlock(file_inode(dst));
383 406
384 if (err >= 0)407 if (err >= 0)
@@ -388,8 +411,11 @@ ssize_t nfs42_proc_copy(struct file *src, loff_t pos_src, · 3 unmodified lines
388 err = -EOPNOTSUPP;411 err = -EOPNOTSUPP;
389 break;412 break;
390 } else if (err == -EAGAIN) {413 } else if (err == -EAGAIN) {
391 dst_exception.retry = 1;414 if (!restart) {
392 continue;415 dst_exception.retry = 1;
416 continue;
417 }
418 break;
393 } else if (err == -NFS4ERR_OFFLOAD_NO_REQS && !args.sync) {419 } else if (err == -NFS4ERR_OFFLOAD_NO_REQS && !args.sync) {
394 args.sync = true;420 args.sync = true;
395 dst_exception.retry = 1;421 dst_exception.retry = 1;
fs/nfs/nfs4_fs.h+1−0
@@ -168,6 +168,7 @@ enum { · 167 unmodified lines
168 NFS_STATE_CHANGE_WAIT, /* A state changing operation is outstanding */168 NFS_STATE_CHANGE_WAIT, /* A state changing operation is outstanding */
169#ifdef CONFIG_NFS_V4_2169#ifdef CONFIG_NFS_V4_2
170 NFS_CLNT_DST_SSC_COPY_STATE, /* dst server open state on client*/170 NFS_CLNT_DST_SSC_COPY_STATE, /* dst server open state on client*/
171 NFS_CLNT_SRC_SSC_COPY_STATE, /* src server open state on client*/
171 NFS_SRV_SSC_COPY_STATE, /* ssc state on the dst server */172 NFS_SRV_SSC_COPY_STATE, /* ssc state on the dst server */
172#endif /* CONFIG_NFS_V4_2 */173#endif /* CONFIG_NFS_V4_2 */
173};174};
fs/nfs/nfs4file.c+3−0
@@ -146,6 +146,7 @@ static ssize_t __nfs4_copy_file_range(struct file *file_in, loff_t pos_in, · 145 unmodified lines
146 return -EOPNOTSUPP;146 return -EOPNOTSUPP;
147 if (file_inode(file_in) == file_inode(file_out))147 if (file_inode(file_in) == file_inode(file_out))
148 return -EOPNOTSUPP;148 return -EOPNOTSUPP;
149retry:
149 if (!nfs42_files_from_same_server(file_in, file_out)) {150 if (!nfs42_files_from_same_server(file_in, file_out)) {
150 cn_resp = kzalloc(sizeof(struct nfs42_copy_notify_res),151 cn_resp = kzalloc(sizeof(struct nfs42_copy_notify_res),
151 GFP_NOFS);152 GFP_NOFS);
@@ -164,6 +165,8 @@ static ssize_t __nfs4_copy_file_range(struct file *file_in, loff_t pos_in, · 12 unmodified lines
164 nss, cnrs);165 nss, cnrs);
165out:166out:
166 kfree(cn_resp);167 kfree(cn_resp);
168 if (ret == -EAGAIN)
169 goto retry;
167 return ret;170 return ret;
168}171}
169 172
fs/nfs/nfs4state.c+21−5
@@ -1556,16 +1556,32 @@ static void nfs42_complete_copies(struct nfs4_state_owner *sp, struct nfs4_state · 1555 unmodified lines
1556{1556{
1557 struct nfs4_copy_state *copy;1557 struct nfs4_copy_state *copy;
1558 1558
1559 if (!test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags))1559 if (!test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) &&
1560 !test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags))
1560 return;1561 return;
1561 1562
1562 spin_lock(&sp->so_server->nfs_client->cl_lock);1563 spin_lock(&sp->so_server->nfs_client->cl_lock);
1563 list_for_each_entry(copy, &sp->so_server->ss_copies, copies) {1564 list_for_each_entry(copy, &sp->so_server->ss_copies, copies) {
1564 if (!nfs4_stateid_match_other(&state->stateid, &copy->parent_state->stateid))1565 if ((test_bit(NFS_CLNT_DST_SSC_COPY_STATE, &state->flags) &&
1565 continue;1566 !nfs4_stateid_match_other(&state->stateid,
1567 &copy->parent_dst_state->stateid)))
1568 continue;
1566 copy->flags = 1;1569 copy->flags = 1;
1567 complete(&copy->completion);1570 if (test_and_clear_bit(NFS_CLNT_DST_SSC_COPY_STATE,
1568 break;1571 &state->flags)) {
1572 clear_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags);
1573 complete(&copy->completion);
1574 }
1575 }
1576 list_for_each_entry(copy, &sp->so_server->ss_copies, src_copies) {
1577 if ((test_bit(NFS_CLNT_SRC_SSC_COPY_STATE, &state->flags) &&
1578 !nfs4_stateid_match_other(&state->stateid,
1579 &copy->parent_src_state->stateid)))
1580 continue;
1581 copy->flags = 1;
1582 if (test_and_clear_bit(NFS_CLNT_DST_SSC_COPY_STATE,
1583 &state->flags))
1584 complete(&copy->completion);
1569 }1585 }
1570 spin_unlock(&sp->so_server->nfs_client->cl_lock);1586 spin_unlock(&sp->so_server->nfs_client->cl_lock);
1571}1587}
include/linux/nfs_fs.h+3−1
@@ -189,13 +189,15 @@ struct nfs_inode { · 188 unmodified lines
189 189
190struct nfs4_copy_state {190struct nfs4_copy_state {
191 struct list_head copies;191 struct list_head copies;
192 struct list_head src_copies;
192 nfs4_stateid stateid;193 nfs4_stateid stateid;
193 struct completion completion;194 struct completion completion;
194 uint64_t count;195 uint64_t count;
195 struct nfs_writeverf verf;196 struct nfs_writeverf verf;
196 int error;197 int error;
197 int flags;198 int flags;
198 struct nfs4_state *parent_state;199 struct nfs4_state *parent_src_state;
200 struct nfs4_state *parent_dst_state;
199};201};
200 202
201/*203/*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t