Commit | Line | Data |
---|---|---|
30062bd1 DH |
1 | /* YFS File Server client stubs |
2 | * | |
3 | * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved. | |
4 | * Written by David Howells (dhowells@redhat.com) | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public Licence | |
8 | * as published by the Free Software Foundation; either version | |
9 | * 2 of the Licence, or (at your option) any later version. | |
10 | */ | |
11 | ||
12 | #include <linux/init.h> | |
13 | #include <linux/slab.h> | |
14 | #include <linux/sched.h> | |
15 | #include <linux/circ_buf.h> | |
16 | #include <linux/iversion.h> | |
17 | #include "internal.h" | |
18 | #include "afs_fs.h" | |
19 | #include "xdr_fs.h" | |
20 | #include "protocol_yfs.h" | |
21 | ||
22 | static const struct afs_fid afs_zero_fid; | |
23 | ||
24 | static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi) | |
25 | { | |
26 | call->cbi = afs_get_cb_interest(cbi); | |
27 | } | |
28 | ||
29 | #define xdr_size(x) (sizeof(*x) / sizeof(__be32)) | |
30 | ||
31 | static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid) | |
32 | { | |
33 | const struct yfs_xdr_YFSFid *x = (const void *)*_bp; | |
34 | ||
35 | fid->vid = xdr_to_u64(x->volume); | |
36 | fid->vnode = xdr_to_u64(x->vnode.lo); | |
37 | fid->vnode_hi = ntohl(x->vnode.hi); | |
38 | fid->unique = ntohl(x->vnode.unique); | |
39 | *_bp += xdr_size(x); | |
40 | } | |
41 | ||
42 | static __be32 *xdr_encode_u32(__be32 *bp, u32 n) | |
43 | { | |
44 | *bp++ = htonl(n); | |
45 | return bp; | |
46 | } | |
47 | ||
48 | static __be32 *xdr_encode_u64(__be32 *bp, u64 n) | |
49 | { | |
50 | struct yfs_xdr_u64 *x = (void *)bp; | |
51 | ||
52 | *x = u64_to_xdr(n); | |
53 | return bp + xdr_size(x); | |
54 | } | |
55 | ||
56 | static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid) | |
57 | { | |
58 | struct yfs_xdr_YFSFid *x = (void *)bp; | |
59 | ||
60 | x->volume = u64_to_xdr(fid->vid); | |
61 | x->vnode.lo = u64_to_xdr(fid->vnode); | |
62 | x->vnode.hi = htonl(fid->vnode_hi); | |
63 | x->vnode.unique = htonl(fid->unique); | |
64 | return bp + xdr_size(x); | |
65 | } | |
66 | ||
67 | static size_t xdr_strlen(unsigned int len) | |
68 | { | |
69 | return sizeof(__be32) + round_up(len, sizeof(__be32)); | |
70 | } | |
71 | ||
72 | static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len) | |
73 | { | |
74 | bp = xdr_encode_u32(bp, len); | |
75 | bp = memcpy(bp, p, len); | |
76 | if (len & 3) { | |
77 | unsigned int pad = 4 - (len & 3); | |
78 | ||
79 | memset((u8 *)bp + len, 0, pad); | |
80 | len += pad; | |
81 | } | |
82 | ||
83 | return bp + len / sizeof(__be32); | |
84 | } | |
85 | ||
86 | static s64 linux_to_yfs_time(const struct timespec64 *t) | |
87 | { | |
88 | /* Convert to 100ns intervals. */ | |
89 | return (u64)t->tv_sec * 10000000 + t->tv_nsec/100; | |
90 | } | |
91 | ||
92 | static __be32 *xdr_encode_YFSStoreStatus_mode(__be32 *bp, mode_t mode) | |
93 | { | |
94 | struct yfs_xdr_YFSStoreStatus *x = (void *)bp; | |
95 | ||
96 | x->mask = htonl(AFS_SET_MODE); | |
97 | x->mode = htonl(mode & S_IALLUGO); | |
98 | x->mtime_client = u64_to_xdr(0); | |
99 | x->owner = u64_to_xdr(0); | |
100 | x->group = u64_to_xdr(0); | |
101 | return bp + xdr_size(x); | |
102 | } | |
103 | ||
104 | static __be32 *xdr_encode_YFSStoreStatus_mtime(__be32 *bp, const struct timespec64 *t) | |
105 | { | |
106 | struct yfs_xdr_YFSStoreStatus *x = (void *)bp; | |
107 | s64 mtime = linux_to_yfs_time(t); | |
108 | ||
109 | x->mask = htonl(AFS_SET_MTIME); | |
110 | x->mode = htonl(0); | |
111 | x->mtime_client = u64_to_xdr(mtime); | |
112 | x->owner = u64_to_xdr(0); | |
113 | x->group = u64_to_xdr(0); | |
114 | return bp + xdr_size(x); | |
115 | } | |
116 | ||
117 | /* | |
118 | * Convert a signed 100ns-resolution 64-bit time into a timespec. | |
119 | */ | |
120 | static struct timespec64 yfs_time_to_linux(s64 t) | |
121 | { | |
122 | struct timespec64 ts; | |
123 | u64 abs_t; | |
124 | ||
125 | /* | |
126 | * Unfortunately can not use normal 64 bit division on 32 bit arch, but | |
127 | * the alternative, do_div, does not work with negative numbers so have | |
128 | * to special case them | |
129 | */ | |
130 | if (t < 0) { | |
131 | abs_t = -t; | |
132 | ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100); | |
133 | ts.tv_nsec = -ts.tv_nsec; | |
134 | ts.tv_sec = -abs_t; | |
135 | } else { | |
136 | abs_t = t; | |
137 | ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100; | |
138 | ts.tv_sec = abs_t; | |
139 | } | |
140 | ||
141 | return ts; | |
142 | } | |
143 | ||
144 | static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr) | |
145 | { | |
146 | s64 t = xdr_to_u64(xdr); | |
147 | ||
148 | return yfs_time_to_linux(t); | |
149 | } | |
150 | ||
151 | static void yfs_check_req(struct afs_call *call, __be32 *bp) | |
152 | { | |
153 | size_t len = (void *)bp - call->request; | |
154 | ||
155 | if (len > call->request_size) | |
156 | pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n", | |
157 | call->type->name, len, call->request_size); | |
158 | else if (len < call->request_size) | |
159 | pr_warning("kAFS: %s: Request buffer underflow (%zu<%u)\n", | |
160 | call->type->name, len, call->request_size); | |
161 | } | |
162 | ||
163 | /* | |
164 | * Dump a bad file status record. | |
165 | */ | |
166 | static void xdr_dump_bad(const __be32 *bp) | |
167 | { | |
168 | __be32 x[4]; | |
169 | int i; | |
170 | ||
171 | pr_notice("YFS XDR: Bad status record\n"); | |
172 | for (i = 0; i < 5 * 4 * 4; i += 16) { | |
173 | memcpy(x, bp, 16); | |
174 | bp += 4; | |
175 | pr_notice("%03x: %08x %08x %08x %08x\n", | |
176 | i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3])); | |
177 | } | |
178 | ||
179 | memcpy(x, bp, 4); | |
180 | pr_notice("0x50: %08x\n", ntohl(x[0])); | |
181 | } | |
182 | ||
183 | /* | |
184 | * Decode a YFSFetchStatus block | |
185 | */ | |
186 | static int xdr_decode_YFSFetchStatus(struct afs_call *call, | |
187 | const __be32 **_bp, | |
188 | struct afs_file_status *status, | |
189 | struct afs_vnode *vnode, | |
190 | const afs_dataversion_t *expected_version, | |
191 | struct afs_read *read_req) | |
192 | { | |
193 | const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp; | |
194 | u32 type; | |
195 | u8 flags = 0; | |
196 | ||
197 | status->abort_code = ntohl(xdr->abort_code); | |
198 | if (status->abort_code != 0) { | |
199 | if (vnode && status->abort_code == VNOVNODE) { | |
200 | set_bit(AFS_VNODE_DELETED, &vnode->flags); | |
201 | status->nlink = 0; | |
202 | __afs_break_callback(vnode); | |
203 | } | |
204 | return 0; | |
205 | } | |
206 | ||
207 | type = ntohl(xdr->type); | |
208 | switch (type) { | |
209 | case AFS_FTYPE_FILE: | |
210 | case AFS_FTYPE_DIR: | |
211 | case AFS_FTYPE_SYMLINK: | |
212 | if (type != status->type && | |
213 | vnode && | |
214 | !test_bit(AFS_VNODE_UNSET, &vnode->flags)) { | |
215 | pr_warning("Vnode %llx:%llx:%x changed type %u to %u\n", | |
216 | vnode->fid.vid, | |
217 | vnode->fid.vnode, | |
218 | vnode->fid.unique, | |
219 | status->type, type); | |
220 | goto bad; | |
221 | } | |
222 | status->type = type; | |
223 | break; | |
224 | default: | |
225 | goto bad; | |
226 | } | |
227 | ||
228 | #define EXTRACT_M4(FIELD) \ | |
229 | do { \ | |
230 | u32 x = ntohl(xdr->FIELD); \ | |
231 | if (status->FIELD != x) { \ | |
232 | flags |= AFS_VNODE_META_CHANGED; \ | |
233 | status->FIELD = x; \ | |
234 | } \ | |
235 | } while (0) | |
236 | ||
237 | #define EXTRACT_M8(FIELD) \ | |
238 | do { \ | |
239 | u64 x = xdr_to_u64(xdr->FIELD); \ | |
240 | if (status->FIELD != x) { \ | |
241 | flags |= AFS_VNODE_META_CHANGED; \ | |
242 | status->FIELD = x; \ | |
243 | } \ | |
244 | } while (0) | |
245 | ||
246 | #define EXTRACT_D8(FIELD) \ | |
247 | do { \ | |
248 | u64 x = xdr_to_u64(xdr->FIELD); \ | |
249 | if (status->FIELD != x) { \ | |
250 | flags |= AFS_VNODE_DATA_CHANGED; \ | |
251 | status->FIELD = x; \ | |
252 | } \ | |
253 | } while (0) | |
254 | ||
255 | EXTRACT_M4(nlink); | |
256 | EXTRACT_D8(size); | |
257 | EXTRACT_D8(data_version); | |
258 | EXTRACT_M8(author); | |
259 | EXTRACT_M8(owner); | |
260 | EXTRACT_M8(group); | |
261 | EXTRACT_M4(mode); | |
262 | EXTRACT_M4(caller_access); /* call ticket dependent */ | |
263 | EXTRACT_M4(anon_access); | |
264 | ||
265 | status->mtime_client = xdr_to_time(xdr->mtime_client); | |
266 | status->mtime_server = xdr_to_time(xdr->mtime_server); | |
267 | status->lock_count = ntohl(xdr->lock_count); | |
268 | ||
269 | if (read_req) { | |
270 | read_req->data_version = status->data_version; | |
271 | read_req->file_size = status->size; | |
272 | } | |
273 | ||
274 | *_bp += xdr_size(xdr); | |
275 | ||
276 | if (vnode) { | |
277 | if (test_bit(AFS_VNODE_UNSET, &vnode->flags)) | |
278 | flags |= AFS_VNODE_NOT_YET_SET; | |
279 | afs_update_inode_from_status(vnode, status, expected_version, | |
280 | flags); | |
281 | } | |
282 | ||
283 | return 0; | |
284 | ||
285 | bad: | |
286 | xdr_dump_bad(*_bp); | |
287 | return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status); | |
288 | } | |
289 | ||
290 | /* | |
291 | * Decode the file status. We need to lock the target vnode if we're going to | |
292 | * update its status so that stat() sees the attributes update atomically. | |
293 | */ | |
294 | static int yfs_decode_status(struct afs_call *call, | |
295 | const __be32 **_bp, | |
296 | struct afs_file_status *status, | |
297 | struct afs_vnode *vnode, | |
298 | const afs_dataversion_t *expected_version, | |
299 | struct afs_read *read_req) | |
300 | { | |
301 | int ret; | |
302 | ||
303 | if (!vnode) | |
304 | return xdr_decode_YFSFetchStatus(call, _bp, status, vnode, | |
305 | expected_version, read_req); | |
306 | ||
307 | write_seqlock(&vnode->cb_lock); | |
308 | ret = xdr_decode_YFSFetchStatus(call, _bp, status, vnode, | |
309 | expected_version, read_req); | |
310 | write_sequnlock(&vnode->cb_lock); | |
311 | return ret; | |
312 | } | |
313 | ||
78107055 DH |
314 | static void xdr_decode_YFSCallBack_raw(struct afs_call *call, |
315 | struct afs_callback *cb, | |
316 | const __be32 **_bp) | |
317 | { | |
318 | struct yfs_xdr_YFSCallBack *x = (void *)*_bp; | |
319 | ktime_t cb_expiry; | |
320 | ||
321 | cb_expiry = call->reply_time; | |
322 | cb_expiry = ktime_add(cb_expiry, xdr_to_u64(x->expiration_time) * 100); | |
323 | cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC); | |
324 | cb->version = ntohl(x->version); | |
325 | cb->type = ntohl(x->type); | |
326 | ||
327 | *_bp += xdr_size(x); | |
328 | } | |
329 | ||
30062bd1 DH |
330 | /* |
331 | * Decode a YFSCallBack block | |
332 | */ | |
333 | static void xdr_decode_YFSCallBack(struct afs_call *call, | |
334 | struct afs_vnode *vnode, | |
335 | const __be32 **_bp) | |
336 | { | |
30062bd1 | 337 | struct afs_cb_interest *old, *cbi = call->cbi; |
78107055 DH |
338 | struct afs_callback cb; |
339 | ||
340 | xdr_decode_YFSCallBack_raw(call, &cb, _bp); | |
87182759 | 341 | |
30062bd1 DH |
342 | write_seqlock(&vnode->cb_lock); |
343 | ||
18ac6185 | 344 | if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) { |
78107055 DH |
345 | vnode->cb_version = cb.version; |
346 | vnode->cb_type = cb.type; | |
347 | vnode->cb_expires_at = cb.expires_at; | |
30062bd1 DH |
348 | old = vnode->cb_interest; |
349 | if (old != call->cbi) { | |
350 | vnode->cb_interest = cbi; | |
351 | cbi = old; | |
352 | } | |
353 | set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags); | |
354 | } | |
355 | ||
356 | write_sequnlock(&vnode->cb_lock); | |
357 | call->cbi = cbi; | |
30062bd1 DH |
358 | } |
359 | ||
360 | /* | |
361 | * Decode a YFSVolSync block | |
362 | */ | |
363 | static void xdr_decode_YFSVolSync(const __be32 **_bp, | |
364 | struct afs_volsync *volsync) | |
365 | { | |
366 | struct yfs_xdr_YFSVolSync *x = (void *)*_bp; | |
367 | u64 creation; | |
368 | ||
369 | if (volsync) { | |
370 | creation = xdr_to_u64(x->vol_creation_date); | |
371 | do_div(creation, 10 * 1000 * 1000); | |
372 | volsync->creation = creation; | |
373 | } | |
374 | ||
375 | *_bp += xdr_size(x); | |
376 | } | |
377 | ||
378 | /* | |
379 | * Encode the requested attributes into a YFSStoreStatus block | |
380 | */ | |
381 | static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr) | |
382 | { | |
383 | struct yfs_xdr_YFSStoreStatus *x = (void *)bp; | |
384 | s64 mtime = 0, owner = 0, group = 0; | |
385 | u32 mask = 0, mode = 0; | |
386 | ||
387 | mask = 0; | |
388 | if (attr->ia_valid & ATTR_MTIME) { | |
389 | mask |= AFS_SET_MTIME; | |
390 | mtime = linux_to_yfs_time(&attr->ia_mtime); | |
391 | } | |
392 | ||
393 | if (attr->ia_valid & ATTR_UID) { | |
394 | mask |= AFS_SET_OWNER; | |
395 | owner = from_kuid(&init_user_ns, attr->ia_uid); | |
396 | } | |
397 | ||
398 | if (attr->ia_valid & ATTR_GID) { | |
399 | mask |= AFS_SET_GROUP; | |
400 | group = from_kgid(&init_user_ns, attr->ia_gid); | |
401 | } | |
402 | ||
403 | if (attr->ia_valid & ATTR_MODE) { | |
404 | mask |= AFS_SET_MODE; | |
405 | mode = attr->ia_mode & S_IALLUGO; | |
406 | } | |
407 | ||
408 | x->mask = htonl(mask); | |
409 | x->mode = htonl(mode); | |
410 | x->mtime_client = u64_to_xdr(mtime); | |
411 | x->owner = u64_to_xdr(owner); | |
412 | x->group = u64_to_xdr(group); | |
413 | return bp + xdr_size(x); | |
414 | } | |
415 | ||
416 | /* | |
417 | * Decode a YFSFetchVolumeStatus block. | |
418 | */ | |
419 | static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp, | |
420 | struct afs_volume_status *vs) | |
421 | { | |
422 | const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp; | |
423 | u32 flags; | |
424 | ||
425 | vs->vid = xdr_to_u64(x->vid); | |
426 | vs->parent_id = xdr_to_u64(x->parent_id); | |
427 | flags = ntohl(x->flags); | |
428 | vs->online = flags & yfs_FVSOnline; | |
429 | vs->in_service = flags & yfs_FVSInservice; | |
430 | vs->blessed = flags & yfs_FVSBlessed; | |
431 | vs->needs_salvage = flags & yfs_FVSNeedsSalvage; | |
432 | vs->type = ntohl(x->type); | |
433 | vs->min_quota = 0; | |
434 | vs->max_quota = xdr_to_u64(x->max_quota); | |
435 | vs->blocks_in_use = xdr_to_u64(x->blocks_in_use); | |
436 | vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail); | |
437 | vs->part_max_blocks = xdr_to_u64(x->part_max_blocks); | |
438 | vs->vol_copy_date = xdr_to_u64(x->vol_copy_date); | |
439 | vs->vol_backup_date = xdr_to_u64(x->vol_backup_date); | |
440 | *_bp += sizeof(*x) / sizeof(__be32); | |
441 | } | |
442 | ||
443 | /* | |
444 | * deliver reply data to an FS.FetchStatus | |
445 | */ | |
446 | static int yfs_deliver_fs_fetch_status_vnode(struct afs_call *call) | |
447 | { | |
ffba718e | 448 | struct afs_vnode *vnode = call->xvnode; |
30062bd1 DH |
449 | const __be32 *bp; |
450 | int ret; | |
451 | ||
452 | ret = afs_transfer_reply(call); | |
453 | if (ret < 0) | |
454 | return ret; | |
455 | ||
456 | _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode); | |
457 | ||
458 | /* unmarshall the reply once we've received all of it */ | |
459 | bp = call->buffer; | |
460 | ret = yfs_decode_status(call, &bp, &vnode->status, vnode, | |
461 | &call->expected_version, NULL); | |
462 | if (ret < 0) | |
463 | return ret; | |
464 | xdr_decode_YFSCallBack(call, vnode, &bp); | |
ffba718e | 465 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
30062bd1 DH |
466 | |
467 | _leave(" = 0 [done]"); | |
468 | return 0; | |
469 | } | |
470 | ||
471 | /* | |
472 | * YFS.FetchStatus operation type | |
473 | */ | |
474 | static const struct afs_call_type yfs_RXYFSFetchStatus_vnode = { | |
475 | .name = "YFS.FetchStatus(vnode)", | |
476 | .op = yfs_FS_FetchStatus, | |
477 | .deliver = yfs_deliver_fs_fetch_status_vnode, | |
478 | .destructor = afs_flat_call_destructor, | |
479 | }; | |
480 | ||
481 | /* | |
482 | * Fetch the status information for a file. | |
483 | */ | |
484 | int yfs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync, | |
485 | bool new_inode) | |
486 | { | |
487 | struct afs_vnode *vnode = fc->vnode; | |
488 | struct afs_call *call; | |
489 | struct afs_net *net = afs_v2net(vnode); | |
490 | __be32 *bp; | |
491 | ||
492 | _enter(",%x,{%llx:%llu},,", | |
493 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); | |
494 | ||
495 | call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus_vnode, | |
496 | sizeof(__be32) * 2 + | |
497 | sizeof(struct yfs_xdr_YFSFid), | |
498 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
499 | sizeof(struct yfs_xdr_YFSCallBack) + | |
500 | sizeof(struct yfs_xdr_YFSVolSync)); | |
501 | if (!call) { | |
502 | fc->ac.error = -ENOMEM; | |
503 | return -ENOMEM; | |
504 | } | |
505 | ||
506 | call->key = fc->key; | |
ffba718e DH |
507 | call->xvnode = vnode; |
508 | call->out_volsync = volsync; | |
30062bd1 DH |
509 | call->expected_version = new_inode ? 1 : vnode->status.data_version; |
510 | ||
511 | /* marshall the parameters */ | |
512 | bp = call->request; | |
513 | bp = xdr_encode_u32(bp, YFSFETCHSTATUS); | |
514 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
515 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
516 | yfs_check_req(call, bp); | |
517 | ||
518 | call->cb_break = fc->cb_break; | |
519 | afs_use_fs_server(call, fc->cbi); | |
520 | trace_afs_make_fs_call(call, &vnode->fid); | |
20b8391f | 521 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
522 | afs_make_call(&fc->ac, call, GFP_NOFS); |
523 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
524 | } |
525 | ||
526 | /* | |
527 | * Deliver reply data to an YFS.FetchData64. | |
528 | */ | |
529 | static int yfs_deliver_fs_fetch_data64(struct afs_call *call) | |
530 | { | |
ffba718e DH |
531 | struct afs_vnode *vnode = call->xvnode; |
532 | struct afs_read *req = call->read_request; | |
30062bd1 DH |
533 | const __be32 *bp; |
534 | unsigned int size; | |
535 | int ret; | |
536 | ||
537 | _enter("{%u,%zu/%llu}", | |
538 | call->unmarshall, iov_iter_count(&call->iter), req->actual_len); | |
539 | ||
540 | switch (call->unmarshall) { | |
541 | case 0: | |
542 | req->actual_len = 0; | |
543 | req->index = 0; | |
544 | req->offset = req->pos & (PAGE_SIZE - 1); | |
545 | afs_extract_to_tmp64(call); | |
546 | call->unmarshall++; | |
547 | ||
e690c9e3 | 548 | /* Fall through - and extract the returned data length */ |
30062bd1 DH |
549 | case 1: |
550 | _debug("extract data length"); | |
551 | ret = afs_extract_data(call, true); | |
552 | if (ret < 0) | |
553 | return ret; | |
554 | ||
555 | req->actual_len = be64_to_cpu(call->tmp64); | |
556 | _debug("DATA length: %llu", req->actual_len); | |
557 | req->remain = min(req->len, req->actual_len); | |
558 | if (req->remain == 0) | |
559 | goto no_more_data; | |
560 | ||
561 | call->unmarshall++; | |
562 | ||
563 | begin_page: | |
564 | ASSERTCMP(req->index, <, req->nr_pages); | |
565 | if (req->remain > PAGE_SIZE - req->offset) | |
566 | size = PAGE_SIZE - req->offset; | |
567 | else | |
568 | size = req->remain; | |
569 | call->bvec[0].bv_len = size; | |
570 | call->bvec[0].bv_offset = req->offset; | |
571 | call->bvec[0].bv_page = req->pages[req->index]; | |
572 | iov_iter_bvec(&call->iter, READ, call->bvec, 1, size); | |
573 | ASSERTCMP(size, <=, PAGE_SIZE); | |
574 | ||
e690c9e3 | 575 | /* Fall through - and extract the returned data */ |
30062bd1 DH |
576 | case 2: |
577 | _debug("extract data %zu/%llu", | |
578 | iov_iter_count(&call->iter), req->remain); | |
579 | ||
580 | ret = afs_extract_data(call, true); | |
581 | if (ret < 0) | |
582 | return ret; | |
583 | req->remain -= call->bvec[0].bv_len; | |
584 | req->offset += call->bvec[0].bv_len; | |
585 | ASSERTCMP(req->offset, <=, PAGE_SIZE); | |
586 | if (req->offset == PAGE_SIZE) { | |
587 | req->offset = 0; | |
588 | if (req->page_done) | |
589 | req->page_done(call, req); | |
590 | req->index++; | |
591 | if (req->remain > 0) | |
592 | goto begin_page; | |
593 | } | |
594 | ||
595 | ASSERTCMP(req->remain, ==, 0); | |
596 | if (req->actual_len <= req->len) | |
597 | goto no_more_data; | |
598 | ||
599 | /* Discard any excess data the server gave us */ | |
600 | iov_iter_discard(&call->iter, READ, req->actual_len - req->len); | |
601 | call->unmarshall = 3; | |
e690c9e3 GS |
602 | |
603 | /* Fall through */ | |
30062bd1 DH |
604 | case 3: |
605 | _debug("extract discard %zu/%llu", | |
606 | iov_iter_count(&call->iter), req->actual_len - req->len); | |
607 | ||
608 | ret = afs_extract_data(call, true); | |
609 | if (ret < 0) | |
610 | return ret; | |
611 | ||
612 | no_more_data: | |
613 | call->unmarshall = 4; | |
614 | afs_extract_to_buf(call, | |
615 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
616 | sizeof(struct yfs_xdr_YFSCallBack) + | |
617 | sizeof(struct yfs_xdr_YFSVolSync)); | |
618 | ||
e690c9e3 | 619 | /* Fall through - and extract the metadata */ |
30062bd1 DH |
620 | case 4: |
621 | ret = afs_extract_data(call, false); | |
622 | if (ret < 0) | |
623 | return ret; | |
624 | ||
625 | bp = call->buffer; | |
626 | ret = yfs_decode_status(call, &bp, &vnode->status, vnode, | |
627 | &vnode->status.data_version, req); | |
628 | if (ret < 0) | |
629 | return ret; | |
630 | xdr_decode_YFSCallBack(call, vnode, &bp); | |
ffba718e | 631 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
30062bd1 DH |
632 | |
633 | call->unmarshall++; | |
634 | ||
e690c9e3 | 635 | /* Fall through */ |
30062bd1 DH |
636 | case 5: |
637 | break; | |
638 | } | |
639 | ||
640 | for (; req->index < req->nr_pages; req->index++) { | |
641 | if (req->offset < PAGE_SIZE) | |
642 | zero_user_segment(req->pages[req->index], | |
643 | req->offset, PAGE_SIZE); | |
644 | if (req->page_done) | |
645 | req->page_done(call, req); | |
646 | req->offset = 0; | |
647 | } | |
648 | ||
649 | _leave(" = 0 [done]"); | |
650 | return 0; | |
651 | } | |
652 | ||
653 | static void yfs_fetch_data_destructor(struct afs_call *call) | |
654 | { | |
ffba718e | 655 | afs_put_read(call->read_request); |
30062bd1 DH |
656 | afs_flat_call_destructor(call); |
657 | } | |
658 | ||
659 | /* | |
660 | * YFS.FetchData64 operation type | |
661 | */ | |
662 | static const struct afs_call_type yfs_RXYFSFetchData64 = { | |
663 | .name = "YFS.FetchData64", | |
664 | .op = yfs_FS_FetchData64, | |
665 | .deliver = yfs_deliver_fs_fetch_data64, | |
666 | .destructor = yfs_fetch_data_destructor, | |
667 | }; | |
668 | ||
669 | /* | |
670 | * Fetch data from a file. | |
671 | */ | |
672 | int yfs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req) | |
673 | { | |
674 | struct afs_vnode *vnode = fc->vnode; | |
675 | struct afs_call *call; | |
676 | struct afs_net *net = afs_v2net(vnode); | |
677 | __be32 *bp; | |
678 | ||
679 | _enter(",%x,{%llx:%llu},%llx,%llx", | |
680 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode, | |
681 | req->pos, req->len); | |
682 | ||
683 | call = afs_alloc_flat_call(net, &yfs_RXYFSFetchData64, | |
684 | sizeof(__be32) * 2 + | |
685 | sizeof(struct yfs_xdr_YFSFid) + | |
686 | sizeof(struct yfs_xdr_u64) * 2, | |
687 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
688 | sizeof(struct yfs_xdr_YFSCallBack) + | |
689 | sizeof(struct yfs_xdr_YFSVolSync)); | |
690 | if (!call) | |
691 | return -ENOMEM; | |
692 | ||
693 | call->key = fc->key; | |
ffba718e DH |
694 | call->xvnode = vnode; |
695 | call->out_volsync = NULL; | |
696 | call->read_request = req; | |
30062bd1 | 697 | call->expected_version = vnode->status.data_version; |
30062bd1 DH |
698 | |
699 | /* marshall the parameters */ | |
700 | bp = call->request; | |
701 | bp = xdr_encode_u32(bp, YFSFETCHDATA64); | |
702 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
703 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
704 | bp = xdr_encode_u64(bp, req->pos); | |
705 | bp = xdr_encode_u64(bp, req->len); | |
706 | yfs_check_req(call, bp); | |
707 | ||
708 | refcount_inc(&req->usage); | |
709 | call->cb_break = fc->cb_break; | |
710 | afs_use_fs_server(call, fc->cbi); | |
711 | trace_afs_make_fs_call(call, &vnode->fid); | |
20b8391f | 712 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
713 | afs_make_call(&fc->ac, call, GFP_NOFS); |
714 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
715 | } |
716 | ||
717 | /* | |
718 | * Deliver reply data for YFS.CreateFile or YFS.MakeDir. | |
719 | */ | |
720 | static int yfs_deliver_fs_create_vnode(struct afs_call *call) | |
721 | { | |
ffba718e | 722 | struct afs_vnode *dvnode = call->dvnode; |
30062bd1 DH |
723 | const __be32 *bp; |
724 | int ret; | |
725 | ||
726 | _enter("{%u}", call->unmarshall); | |
727 | ||
728 | ret = afs_transfer_reply(call); | |
729 | if (ret < 0) | |
730 | return ret; | |
731 | ||
732 | /* unmarshall the reply once we've received all of it */ | |
733 | bp = call->buffer; | |
ffba718e DH |
734 | xdr_decode_YFSFid(&bp, call->out_fid); |
735 | ret = yfs_decode_status(call, &bp, call->out_extra_status, NULL, NULL, NULL); | |
30062bd1 DH |
736 | if (ret < 0) |
737 | return ret; | |
ffba718e | 738 | ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode, |
30062bd1 DH |
739 | &call->expected_version, NULL); |
740 | if (ret < 0) | |
741 | return ret; | |
ffba718e | 742 | xdr_decode_YFSCallBack_raw(call, call->out_cb, &bp); |
30062bd1 DH |
743 | xdr_decode_YFSVolSync(&bp, NULL); |
744 | ||
745 | _leave(" = 0 [done]"); | |
746 | return 0; | |
747 | } | |
748 | ||
749 | /* | |
750 | * FS.CreateFile and FS.MakeDir operation type | |
751 | */ | |
752 | static const struct afs_call_type afs_RXFSCreateFile = { | |
753 | .name = "YFS.CreateFile", | |
754 | .op = yfs_FS_CreateFile, | |
755 | .deliver = yfs_deliver_fs_create_vnode, | |
756 | .destructor = afs_flat_call_destructor, | |
757 | }; | |
758 | ||
759 | /* | |
760 | * Create a file. | |
761 | */ | |
762 | int yfs_fs_create_file(struct afs_fs_cursor *fc, | |
763 | const char *name, | |
764 | umode_t mode, | |
765 | u64 current_data_version, | |
766 | struct afs_fid *newfid, | |
767 | struct afs_file_status *newstatus, | |
768 | struct afs_callback *newcb) | |
769 | { | |
ffba718e | 770 | struct afs_vnode *dvnode = fc->vnode; |
30062bd1 | 771 | struct afs_call *call; |
ffba718e | 772 | struct afs_net *net = afs_v2net(dvnode); |
30062bd1 DH |
773 | size_t namesz, reqsz, rplsz; |
774 | __be32 *bp; | |
775 | ||
776 | _enter(""); | |
777 | ||
778 | namesz = strlen(name); | |
779 | reqsz = (sizeof(__be32) + | |
780 | sizeof(__be32) + | |
781 | sizeof(struct yfs_xdr_YFSFid) + | |
782 | xdr_strlen(namesz) + | |
783 | sizeof(struct yfs_xdr_YFSStoreStatus) + | |
784 | sizeof(__be32)); | |
785 | rplsz = (sizeof(struct yfs_xdr_YFSFid) + | |
786 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
787 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
788 | sizeof(struct yfs_xdr_YFSCallBack) + | |
789 | sizeof(struct yfs_xdr_YFSVolSync)); | |
790 | ||
791 | call = afs_alloc_flat_call(net, &afs_RXFSCreateFile, reqsz, rplsz); | |
792 | if (!call) | |
793 | return -ENOMEM; | |
794 | ||
795 | call->key = fc->key; | |
ffba718e DH |
796 | call->dvnode = dvnode; |
797 | call->out_fid = newfid; | |
798 | call->out_extra_status = newstatus; | |
799 | call->out_cb = newcb; | |
30062bd1 DH |
800 | call->expected_version = current_data_version + 1; |
801 | ||
802 | /* marshall the parameters */ | |
803 | bp = call->request; | |
804 | bp = xdr_encode_u32(bp, YFSCREATEFILE); | |
805 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
ffba718e | 806 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); |
30062bd1 DH |
807 | bp = xdr_encode_string(bp, name, namesz); |
808 | bp = xdr_encode_YFSStoreStatus_mode(bp, mode); | |
5edc22cc | 809 | bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */ |
30062bd1 DH |
810 | yfs_check_req(call, bp); |
811 | ||
812 | afs_use_fs_server(call, fc->cbi); | |
ffba718e | 813 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
20b8391f | 814 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
815 | afs_make_call(&fc->ac, call, GFP_NOFS); |
816 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
817 | } |
818 | ||
819 | static const struct afs_call_type yfs_RXFSMakeDir = { | |
820 | .name = "YFS.MakeDir", | |
821 | .op = yfs_FS_MakeDir, | |
822 | .deliver = yfs_deliver_fs_create_vnode, | |
823 | .destructor = afs_flat_call_destructor, | |
824 | }; | |
825 | ||
826 | /* | |
827 | * Make a directory. | |
828 | */ | |
829 | int yfs_fs_make_dir(struct afs_fs_cursor *fc, | |
830 | const char *name, | |
831 | umode_t mode, | |
832 | u64 current_data_version, | |
833 | struct afs_fid *newfid, | |
834 | struct afs_file_status *newstatus, | |
835 | struct afs_callback *newcb) | |
836 | { | |
ffba718e | 837 | struct afs_vnode *dvnode = fc->vnode; |
30062bd1 | 838 | struct afs_call *call; |
ffba718e | 839 | struct afs_net *net = afs_v2net(dvnode); |
30062bd1 DH |
840 | size_t namesz, reqsz, rplsz; |
841 | __be32 *bp; | |
842 | ||
843 | _enter(""); | |
844 | ||
845 | namesz = strlen(name); | |
846 | reqsz = (sizeof(__be32) + | |
847 | sizeof(struct yfs_xdr_RPCFlags) + | |
848 | sizeof(struct yfs_xdr_YFSFid) + | |
849 | xdr_strlen(namesz) + | |
850 | sizeof(struct yfs_xdr_YFSStoreStatus)); | |
851 | rplsz = (sizeof(struct yfs_xdr_YFSFid) + | |
852 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
853 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
854 | sizeof(struct yfs_xdr_YFSCallBack) + | |
855 | sizeof(struct yfs_xdr_YFSVolSync)); | |
856 | ||
857 | call = afs_alloc_flat_call(net, &yfs_RXFSMakeDir, reqsz, rplsz); | |
858 | if (!call) | |
859 | return -ENOMEM; | |
860 | ||
861 | call->key = fc->key; | |
ffba718e DH |
862 | call->dvnode = dvnode; |
863 | call->out_fid = newfid; | |
864 | call->out_extra_status = newstatus; | |
865 | call->out_cb = newcb; | |
30062bd1 DH |
866 | call->expected_version = current_data_version + 1; |
867 | ||
868 | /* marshall the parameters */ | |
869 | bp = call->request; | |
870 | bp = xdr_encode_u32(bp, YFSMAKEDIR); | |
871 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
ffba718e | 872 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); |
30062bd1 DH |
873 | bp = xdr_encode_string(bp, name, namesz); |
874 | bp = xdr_encode_YFSStoreStatus_mode(bp, mode); | |
875 | yfs_check_req(call, bp); | |
876 | ||
877 | afs_use_fs_server(call, fc->cbi); | |
ffba718e | 878 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
20b8391f | 879 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
880 | afs_make_call(&fc->ac, call, GFP_NOFS); |
881 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
882 | } |
883 | ||
884 | /* | |
885 | * Deliver reply data to a YFS.RemoveFile2 operation. | |
886 | */ | |
887 | static int yfs_deliver_fs_remove_file2(struct afs_call *call) | |
888 | { | |
ffba718e DH |
889 | struct afs_vnode *dvnode = call->dvnode; |
890 | struct afs_vnode *vnode = call->xvnode; | |
30062bd1 DH |
891 | struct afs_fid fid; |
892 | const __be32 *bp; | |
893 | int ret; | |
894 | ||
895 | _enter("{%u}", call->unmarshall); | |
896 | ||
897 | ret = afs_transfer_reply(call); | |
898 | if (ret < 0) | |
899 | return ret; | |
900 | ||
901 | /* unmarshall the reply once we've received all of it */ | |
902 | bp = call->buffer; | |
903 | ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode, | |
904 | &call->expected_version, NULL); | |
905 | if (ret < 0) | |
906 | return ret; | |
907 | ||
908 | xdr_decode_YFSFid(&bp, &fid); | |
909 | ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL); | |
910 | if (ret < 0) | |
911 | return ret; | |
912 | /* Was deleted if vnode->status.abort_code == VNOVNODE. */ | |
913 | ||
914 | xdr_decode_YFSVolSync(&bp, NULL); | |
915 | return 0; | |
916 | } | |
917 | ||
918 | /* | |
919 | * YFS.RemoveFile2 operation type. | |
920 | */ | |
921 | static const struct afs_call_type yfs_RXYFSRemoveFile2 = { | |
922 | .name = "YFS.RemoveFile2", | |
923 | .op = yfs_FS_RemoveFile2, | |
924 | .deliver = yfs_deliver_fs_remove_file2, | |
925 | .destructor = afs_flat_call_destructor, | |
926 | }; | |
927 | ||
928 | /* | |
929 | * Remove a file and retrieve new file status. | |
930 | */ | |
931 | int yfs_fs_remove_file2(struct afs_fs_cursor *fc, struct afs_vnode *vnode, | |
932 | const char *name, u64 current_data_version) | |
933 | { | |
934 | struct afs_vnode *dvnode = fc->vnode; | |
935 | struct afs_call *call; | |
936 | struct afs_net *net = afs_v2net(dvnode); | |
937 | size_t namesz; | |
938 | __be32 *bp; | |
939 | ||
940 | _enter(""); | |
941 | ||
942 | namesz = strlen(name); | |
943 | ||
944 | call = afs_alloc_flat_call(net, &yfs_RXYFSRemoveFile2, | |
945 | sizeof(__be32) + | |
946 | sizeof(struct yfs_xdr_RPCFlags) + | |
947 | sizeof(struct yfs_xdr_YFSFid) + | |
948 | xdr_strlen(namesz), | |
949 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
950 | sizeof(struct yfs_xdr_YFSFid) + | |
951 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
952 | sizeof(struct yfs_xdr_YFSVolSync)); | |
953 | if (!call) | |
954 | return -ENOMEM; | |
955 | ||
956 | call->key = fc->key; | |
ffba718e DH |
957 | call->dvnode = dvnode; |
958 | call->xvnode = vnode; | |
30062bd1 DH |
959 | call->expected_version = current_data_version + 1; |
960 | ||
961 | /* marshall the parameters */ | |
962 | bp = call->request; | |
963 | bp = xdr_encode_u32(bp, YFSREMOVEFILE2); | |
964 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
965 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); | |
966 | bp = xdr_encode_string(bp, name, namesz); | |
967 | yfs_check_req(call, bp); | |
968 | ||
969 | afs_use_fs_server(call, fc->cbi); | |
80548b03 | 970 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
20b8391f | 971 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
972 | afs_make_call(&fc->ac, call, GFP_NOFS); |
973 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
974 | } |
975 | ||
976 | /* | |
977 | * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation. | |
978 | */ | |
979 | static int yfs_deliver_fs_remove(struct afs_call *call) | |
980 | { | |
ffba718e | 981 | struct afs_vnode *dvnode = call->dvnode; |
30062bd1 DH |
982 | const __be32 *bp; |
983 | int ret; | |
984 | ||
985 | _enter("{%u}", call->unmarshall); | |
986 | ||
987 | ret = afs_transfer_reply(call); | |
988 | if (ret < 0) | |
989 | return ret; | |
990 | ||
991 | /* unmarshall the reply once we've received all of it */ | |
992 | bp = call->buffer; | |
993 | ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode, | |
994 | &call->expected_version, NULL); | |
995 | if (ret < 0) | |
996 | return ret; | |
997 | ||
998 | xdr_decode_YFSVolSync(&bp, NULL); | |
999 | return 0; | |
1000 | } | |
1001 | ||
1002 | /* | |
1003 | * FS.RemoveDir and FS.RemoveFile operation types. | |
1004 | */ | |
1005 | static const struct afs_call_type yfs_RXYFSRemoveFile = { | |
1006 | .name = "YFS.RemoveFile", | |
1007 | .op = yfs_FS_RemoveFile, | |
1008 | .deliver = yfs_deliver_fs_remove, | |
1009 | .destructor = afs_flat_call_destructor, | |
1010 | }; | |
1011 | ||
1012 | static const struct afs_call_type yfs_RXYFSRemoveDir = { | |
1013 | .name = "YFS.RemoveDir", | |
1014 | .op = yfs_FS_RemoveDir, | |
1015 | .deliver = yfs_deliver_fs_remove, | |
1016 | .destructor = afs_flat_call_destructor, | |
1017 | }; | |
1018 | ||
1019 | /* | |
1020 | * remove a file or directory | |
1021 | */ | |
1022 | int yfs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode, | |
1023 | const char *name, bool isdir, u64 current_data_version) | |
1024 | { | |
1025 | struct afs_vnode *dvnode = fc->vnode; | |
1026 | struct afs_call *call; | |
1027 | struct afs_net *net = afs_v2net(dvnode); | |
1028 | size_t namesz; | |
1029 | __be32 *bp; | |
1030 | ||
1031 | _enter(""); | |
1032 | ||
1033 | namesz = strlen(name); | |
1034 | call = afs_alloc_flat_call( | |
1035 | net, isdir ? &yfs_RXYFSRemoveDir : &yfs_RXYFSRemoveFile, | |
1036 | sizeof(__be32) + | |
1037 | sizeof(struct yfs_xdr_RPCFlags) + | |
1038 | sizeof(struct yfs_xdr_YFSFid) + | |
1039 | xdr_strlen(namesz), | |
1040 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1041 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1042 | if (!call) | |
1043 | return -ENOMEM; | |
1044 | ||
1045 | call->key = fc->key; | |
ffba718e DH |
1046 | call->dvnode = dvnode; |
1047 | call->xvnode = vnode; | |
30062bd1 DH |
1048 | call->expected_version = current_data_version + 1; |
1049 | ||
1050 | /* marshall the parameters */ | |
1051 | bp = call->request; | |
1052 | bp = xdr_encode_u32(bp, isdir ? YFSREMOVEDIR : YFSREMOVEFILE); | |
1053 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1054 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); | |
1055 | bp = xdr_encode_string(bp, name, namesz); | |
1056 | yfs_check_req(call, bp); | |
1057 | ||
1058 | afs_use_fs_server(call, fc->cbi); | |
80548b03 | 1059 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
20b8391f | 1060 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1061 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1062 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1063 | } |
1064 | ||
1065 | /* | |
1066 | * Deliver reply data to a YFS.Link operation. | |
1067 | */ | |
1068 | static int yfs_deliver_fs_link(struct afs_call *call) | |
1069 | { | |
ffba718e | 1070 | struct afs_vnode *dvnode = call->dvnode, *vnode = call->xvnode; |
30062bd1 DH |
1071 | const __be32 *bp; |
1072 | int ret; | |
1073 | ||
1074 | _enter("{%u}", call->unmarshall); | |
1075 | ||
1076 | ret = afs_transfer_reply(call); | |
1077 | if (ret < 0) | |
1078 | return ret; | |
1079 | ||
1080 | /* unmarshall the reply once we've received all of it */ | |
1081 | bp = call->buffer; | |
1082 | ret = yfs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL); | |
1083 | if (ret < 0) | |
1084 | return ret; | |
1085 | ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode, | |
1086 | &call->expected_version, NULL); | |
1087 | if (ret < 0) | |
1088 | return ret; | |
1089 | xdr_decode_YFSVolSync(&bp, NULL); | |
1090 | _leave(" = 0 [done]"); | |
1091 | return 0; | |
1092 | } | |
1093 | ||
1094 | /* | |
1095 | * YFS.Link operation type. | |
1096 | */ | |
1097 | static const struct afs_call_type yfs_RXYFSLink = { | |
1098 | .name = "YFS.Link", | |
1099 | .op = yfs_FS_Link, | |
1100 | .deliver = yfs_deliver_fs_link, | |
1101 | .destructor = afs_flat_call_destructor, | |
1102 | }; | |
1103 | ||
1104 | /* | |
1105 | * Make a hard link. | |
1106 | */ | |
1107 | int yfs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode, | |
1108 | const char *name, u64 current_data_version) | |
1109 | { | |
1110 | struct afs_vnode *dvnode = fc->vnode; | |
1111 | struct afs_call *call; | |
1112 | struct afs_net *net = afs_v2net(vnode); | |
1113 | size_t namesz; | |
1114 | __be32 *bp; | |
1115 | ||
1116 | _enter(""); | |
1117 | ||
1118 | namesz = strlen(name); | |
1119 | call = afs_alloc_flat_call(net, &yfs_RXYFSLink, | |
1120 | sizeof(__be32) + | |
1121 | sizeof(struct yfs_xdr_RPCFlags) + | |
1122 | sizeof(struct yfs_xdr_YFSFid) + | |
1123 | xdr_strlen(namesz) + | |
1124 | sizeof(struct yfs_xdr_YFSFid), | |
1125 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1126 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1127 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1128 | if (!call) | |
1129 | return -ENOMEM; | |
1130 | ||
1131 | call->key = fc->key; | |
ffba718e DH |
1132 | call->dvnode = dvnode; |
1133 | call->xvnode = vnode; | |
30062bd1 DH |
1134 | call->expected_version = current_data_version + 1; |
1135 | ||
1136 | /* marshall the parameters */ | |
1137 | bp = call->request; | |
1138 | bp = xdr_encode_u32(bp, YFSLINK); | |
1139 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1140 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); | |
1141 | bp = xdr_encode_string(bp, name, namesz); | |
1142 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
1143 | yfs_check_req(call, bp); | |
1144 | ||
1145 | afs_use_fs_server(call, fc->cbi); | |
80548b03 | 1146 | trace_afs_make_fs_call1(call, &vnode->fid, name); |
20b8391f | 1147 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1148 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1149 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1150 | } |
1151 | ||
1152 | /* | |
1153 | * Deliver reply data to a YFS.Symlink operation. | |
1154 | */ | |
1155 | static int yfs_deliver_fs_symlink(struct afs_call *call) | |
1156 | { | |
ffba718e | 1157 | struct afs_vnode *dvnode = call->dvnode; |
30062bd1 DH |
1158 | const __be32 *bp; |
1159 | int ret; | |
1160 | ||
1161 | _enter("{%u}", call->unmarshall); | |
1162 | ||
1163 | ret = afs_transfer_reply(call); | |
1164 | if (ret < 0) | |
1165 | return ret; | |
1166 | ||
1167 | /* unmarshall the reply once we've received all of it */ | |
1168 | bp = call->buffer; | |
ffba718e DH |
1169 | xdr_decode_YFSFid(&bp, call->out_fid); |
1170 | ret = yfs_decode_status(call, &bp, call->out_extra_status, NULL, NULL, NULL); | |
30062bd1 DH |
1171 | if (ret < 0) |
1172 | return ret; | |
ffba718e | 1173 | ret = yfs_decode_status(call, &bp, &dvnode->status, dvnode, |
30062bd1 DH |
1174 | &call->expected_version, NULL); |
1175 | if (ret < 0) | |
1176 | return ret; | |
1177 | xdr_decode_YFSVolSync(&bp, NULL); | |
1178 | ||
1179 | _leave(" = 0 [done]"); | |
1180 | return 0; | |
1181 | } | |
1182 | ||
1183 | /* | |
1184 | * YFS.Symlink operation type | |
1185 | */ | |
1186 | static const struct afs_call_type yfs_RXYFSSymlink = { | |
1187 | .name = "YFS.Symlink", | |
1188 | .op = yfs_FS_Symlink, | |
1189 | .deliver = yfs_deliver_fs_symlink, | |
1190 | .destructor = afs_flat_call_destructor, | |
1191 | }; | |
1192 | ||
1193 | /* | |
1194 | * Create a symbolic link. | |
1195 | */ | |
1196 | int yfs_fs_symlink(struct afs_fs_cursor *fc, | |
1197 | const char *name, | |
1198 | const char *contents, | |
1199 | u64 current_data_version, | |
1200 | struct afs_fid *newfid, | |
1201 | struct afs_file_status *newstatus) | |
1202 | { | |
1203 | struct afs_vnode *dvnode = fc->vnode; | |
1204 | struct afs_call *call; | |
1205 | struct afs_net *net = afs_v2net(dvnode); | |
1206 | size_t namesz, contents_sz; | |
1207 | __be32 *bp; | |
1208 | ||
1209 | _enter(""); | |
1210 | ||
1211 | namesz = strlen(name); | |
1212 | contents_sz = strlen(contents); | |
1213 | call = afs_alloc_flat_call(net, &yfs_RXYFSSymlink, | |
1214 | sizeof(__be32) + | |
1215 | sizeof(struct yfs_xdr_RPCFlags) + | |
1216 | sizeof(struct yfs_xdr_YFSFid) + | |
1217 | xdr_strlen(namesz) + | |
1218 | xdr_strlen(contents_sz) + | |
1219 | sizeof(struct yfs_xdr_YFSStoreStatus), | |
1220 | sizeof(struct yfs_xdr_YFSFid) + | |
1221 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1222 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1223 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1224 | if (!call) | |
1225 | return -ENOMEM; | |
1226 | ||
1227 | call->key = fc->key; | |
ffba718e DH |
1228 | call->dvnode = dvnode; |
1229 | call->out_fid = newfid; | |
1230 | call->out_extra_status = newstatus; | |
30062bd1 DH |
1231 | call->expected_version = current_data_version + 1; |
1232 | ||
1233 | /* marshall the parameters */ | |
1234 | bp = call->request; | |
1235 | bp = xdr_encode_u32(bp, YFSSYMLINK); | |
1236 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1237 | bp = xdr_encode_YFSFid(bp, &dvnode->fid); | |
1238 | bp = xdr_encode_string(bp, name, namesz); | |
1239 | bp = xdr_encode_string(bp, contents, contents_sz); | |
1240 | bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO); | |
1241 | yfs_check_req(call, bp); | |
1242 | ||
1243 | afs_use_fs_server(call, fc->cbi); | |
80548b03 | 1244 | trace_afs_make_fs_call1(call, &dvnode->fid, name); |
20b8391f | 1245 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1246 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1247 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1248 | } |
1249 | ||
1250 | /* | |
1251 | * Deliver reply data to a YFS.Rename operation. | |
1252 | */ | |
1253 | static int yfs_deliver_fs_rename(struct afs_call *call) | |
1254 | { | |
ffba718e DH |
1255 | struct afs_vnode *orig_dvnode = call->dvnode; |
1256 | struct afs_vnode *new_dvnode = call->xvnode; | |
30062bd1 DH |
1257 | const __be32 *bp; |
1258 | int ret; | |
1259 | ||
1260 | _enter("{%u}", call->unmarshall); | |
1261 | ||
1262 | ret = afs_transfer_reply(call); | |
1263 | if (ret < 0) | |
1264 | return ret; | |
1265 | ||
1266 | /* unmarshall the reply once we've received all of it */ | |
1267 | bp = call->buffer; | |
1268 | ret = yfs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode, | |
1269 | &call->expected_version, NULL); | |
1270 | if (ret < 0) | |
1271 | return ret; | |
1272 | if (new_dvnode != orig_dvnode) { | |
1273 | ret = yfs_decode_status(call, &bp, &new_dvnode->status, new_dvnode, | |
1274 | &call->expected_version_2, NULL); | |
1275 | if (ret < 0) | |
1276 | return ret; | |
1277 | } | |
1278 | ||
1279 | xdr_decode_YFSVolSync(&bp, NULL); | |
1280 | _leave(" = 0 [done]"); | |
1281 | return 0; | |
1282 | } | |
1283 | ||
1284 | /* | |
1285 | * YFS.Rename operation type | |
1286 | */ | |
1287 | static const struct afs_call_type yfs_RXYFSRename = { | |
1288 | .name = "FS.Rename", | |
1289 | .op = yfs_FS_Rename, | |
1290 | .deliver = yfs_deliver_fs_rename, | |
1291 | .destructor = afs_flat_call_destructor, | |
1292 | }; | |
1293 | ||
1294 | /* | |
1295 | * Rename a file or directory. | |
1296 | */ | |
1297 | int yfs_fs_rename(struct afs_fs_cursor *fc, | |
1298 | const char *orig_name, | |
1299 | struct afs_vnode *new_dvnode, | |
1300 | const char *new_name, | |
1301 | u64 current_orig_data_version, | |
1302 | u64 current_new_data_version) | |
1303 | { | |
1304 | struct afs_vnode *orig_dvnode = fc->vnode; | |
1305 | struct afs_call *call; | |
1306 | struct afs_net *net = afs_v2net(orig_dvnode); | |
1307 | size_t o_namesz, n_namesz; | |
1308 | __be32 *bp; | |
1309 | ||
1310 | _enter(""); | |
1311 | ||
1312 | o_namesz = strlen(orig_name); | |
1313 | n_namesz = strlen(new_name); | |
1314 | call = afs_alloc_flat_call(net, &yfs_RXYFSRename, | |
1315 | sizeof(__be32) + | |
1316 | sizeof(struct yfs_xdr_RPCFlags) + | |
1317 | sizeof(struct yfs_xdr_YFSFid) + | |
1318 | xdr_strlen(o_namesz) + | |
1319 | sizeof(struct yfs_xdr_YFSFid) + | |
1320 | xdr_strlen(n_namesz), | |
1321 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1322 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1323 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1324 | if (!call) | |
1325 | return -ENOMEM; | |
1326 | ||
1327 | call->key = fc->key; | |
ffba718e DH |
1328 | call->dvnode = orig_dvnode; |
1329 | call->xvnode = new_dvnode; | |
30062bd1 DH |
1330 | call->expected_version = current_orig_data_version + 1; |
1331 | call->expected_version_2 = current_new_data_version + 1; | |
1332 | ||
1333 | /* marshall the parameters */ | |
1334 | bp = call->request; | |
1335 | bp = xdr_encode_u32(bp, YFSRENAME); | |
1336 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1337 | bp = xdr_encode_YFSFid(bp, &orig_dvnode->fid); | |
1338 | bp = xdr_encode_string(bp, orig_name, o_namesz); | |
1339 | bp = xdr_encode_YFSFid(bp, &new_dvnode->fid); | |
1340 | bp = xdr_encode_string(bp, new_name, n_namesz); | |
1341 | yfs_check_req(call, bp); | |
1342 | ||
1343 | afs_use_fs_server(call, fc->cbi); | |
80548b03 | 1344 | trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name); |
20b8391f | 1345 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1346 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1347 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1348 | } |
1349 | ||
1350 | /* | |
1351 | * Deliver reply data to a YFS.StoreData64 operation. | |
1352 | */ | |
1353 | static int yfs_deliver_fs_store_data(struct afs_call *call) | |
1354 | { | |
ffba718e | 1355 | struct afs_vnode *vnode = call->xvnode; |
30062bd1 DH |
1356 | const __be32 *bp; |
1357 | int ret; | |
1358 | ||
1359 | _enter(""); | |
1360 | ||
1361 | ret = afs_transfer_reply(call); | |
1362 | if (ret < 0) | |
1363 | return ret; | |
1364 | ||
1365 | /* unmarshall the reply once we've received all of it */ | |
1366 | bp = call->buffer; | |
1367 | ret = yfs_decode_status(call, &bp, &vnode->status, vnode, | |
1368 | &call->expected_version, NULL); | |
1369 | if (ret < 0) | |
1370 | return ret; | |
1371 | xdr_decode_YFSVolSync(&bp, NULL); | |
1372 | ||
1373 | afs_pages_written_back(vnode, call); | |
1374 | ||
1375 | _leave(" = 0 [done]"); | |
1376 | return 0; | |
1377 | } | |
1378 | ||
1379 | /* | |
1380 | * YFS.StoreData64 operation type. | |
1381 | */ | |
1382 | static const struct afs_call_type yfs_RXYFSStoreData64 = { | |
1383 | .name = "YFS.StoreData64", | |
1384 | .op = yfs_FS_StoreData64, | |
1385 | .deliver = yfs_deliver_fs_store_data, | |
1386 | .destructor = afs_flat_call_destructor, | |
1387 | }; | |
1388 | ||
1389 | /* | |
1390 | * Store a set of pages to a large file. | |
1391 | */ | |
1392 | int yfs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping, | |
1393 | pgoff_t first, pgoff_t last, | |
1394 | unsigned offset, unsigned to) | |
1395 | { | |
1396 | struct afs_vnode *vnode = fc->vnode; | |
1397 | struct afs_call *call; | |
1398 | struct afs_net *net = afs_v2net(vnode); | |
1399 | loff_t size, pos, i_size; | |
1400 | __be32 *bp; | |
1401 | ||
1402 | _enter(",%x,{%llx:%llu},,", | |
1403 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); | |
1404 | ||
1405 | size = (loff_t)to - (loff_t)offset; | |
1406 | if (first != last) | |
1407 | size += (loff_t)(last - first) << PAGE_SHIFT; | |
1408 | pos = (loff_t)first << PAGE_SHIFT; | |
1409 | pos += offset; | |
1410 | ||
1411 | i_size = i_size_read(&vnode->vfs_inode); | |
1412 | if (pos + size > i_size) | |
1413 | i_size = size + pos; | |
1414 | ||
1415 | _debug("size %llx, at %llx, i_size %llx", | |
1416 | (unsigned long long)size, (unsigned long long)pos, | |
1417 | (unsigned long long)i_size); | |
1418 | ||
1419 | call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64, | |
1420 | sizeof(__be32) + | |
1421 | sizeof(__be32) + | |
1422 | sizeof(struct yfs_xdr_YFSFid) + | |
1423 | sizeof(struct yfs_xdr_YFSStoreStatus) + | |
1424 | sizeof(struct yfs_xdr_u64) * 3, | |
1425 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1426 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1427 | if (!call) | |
1428 | return -ENOMEM; | |
1429 | ||
1430 | call->key = fc->key; | |
1431 | call->mapping = mapping; | |
ffba718e | 1432 | call->xvnode = vnode; |
30062bd1 DH |
1433 | call->first = first; |
1434 | call->last = last; | |
1435 | call->first_offset = offset; | |
1436 | call->last_to = to; | |
1437 | call->send_pages = true; | |
1438 | call->expected_version = vnode->status.data_version + 1; | |
1439 | ||
1440 | /* marshall the parameters */ | |
1441 | bp = call->request; | |
1442 | bp = xdr_encode_u32(bp, YFSSTOREDATA64); | |
1443 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1444 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
1445 | bp = xdr_encode_YFSStoreStatus_mtime(bp, &vnode->vfs_inode.i_mtime); | |
1446 | bp = xdr_encode_u64(bp, pos); | |
1447 | bp = xdr_encode_u64(bp, size); | |
1448 | bp = xdr_encode_u64(bp, i_size); | |
1449 | yfs_check_req(call, bp); | |
1450 | ||
1451 | afs_use_fs_server(call, fc->cbi); | |
1452 | trace_afs_make_fs_call(call, &vnode->fid); | |
20b8391f | 1453 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1454 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1455 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1456 | } |
1457 | ||
1458 | /* | |
1459 | * deliver reply data to an FS.StoreStatus | |
1460 | */ | |
1461 | static int yfs_deliver_fs_store_status(struct afs_call *call) | |
1462 | { | |
ffba718e | 1463 | struct afs_vnode *vnode = call->xvnode; |
30062bd1 DH |
1464 | const __be32 *bp; |
1465 | int ret; | |
1466 | ||
1467 | _enter(""); | |
1468 | ||
1469 | ret = afs_transfer_reply(call); | |
1470 | if (ret < 0) | |
1471 | return ret; | |
1472 | ||
1473 | /* unmarshall the reply once we've received all of it */ | |
1474 | bp = call->buffer; | |
1475 | ret = yfs_decode_status(call, &bp, &vnode->status, vnode, | |
1476 | &call->expected_version, NULL); | |
1477 | if (ret < 0) | |
1478 | return ret; | |
1479 | xdr_decode_YFSVolSync(&bp, NULL); | |
1480 | ||
1481 | _leave(" = 0 [done]"); | |
1482 | return 0; | |
1483 | } | |
1484 | ||
1485 | /* | |
1486 | * YFS.StoreStatus operation type | |
1487 | */ | |
1488 | static const struct afs_call_type yfs_RXYFSStoreStatus = { | |
1489 | .name = "YFS.StoreStatus", | |
1490 | .op = yfs_FS_StoreStatus, | |
1491 | .deliver = yfs_deliver_fs_store_status, | |
1492 | .destructor = afs_flat_call_destructor, | |
1493 | }; | |
1494 | ||
1495 | static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = { | |
1496 | .name = "YFS.StoreData64", | |
1497 | .op = yfs_FS_StoreData64, | |
1498 | .deliver = yfs_deliver_fs_store_status, | |
1499 | .destructor = afs_flat_call_destructor, | |
1500 | }; | |
1501 | ||
1502 | /* | |
1503 | * Set the attributes on a file, using YFS.StoreData64 rather than | |
1504 | * YFS.StoreStatus so as to alter the file size also. | |
1505 | */ | |
1506 | static int yfs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr) | |
1507 | { | |
1508 | struct afs_vnode *vnode = fc->vnode; | |
1509 | struct afs_call *call; | |
1510 | struct afs_net *net = afs_v2net(vnode); | |
1511 | __be32 *bp; | |
1512 | ||
1513 | _enter(",%x,{%llx:%llu},,", | |
1514 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); | |
1515 | ||
1516 | call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64_as_Status, | |
1517 | sizeof(__be32) * 2 + | |
1518 | sizeof(struct yfs_xdr_YFSFid) + | |
1519 | sizeof(struct yfs_xdr_YFSStoreStatus) + | |
1520 | sizeof(struct yfs_xdr_u64) * 3, | |
1521 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1522 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1523 | if (!call) | |
1524 | return -ENOMEM; | |
1525 | ||
1526 | call->key = fc->key; | |
ffba718e | 1527 | call->xvnode = vnode; |
30062bd1 DH |
1528 | call->expected_version = vnode->status.data_version + 1; |
1529 | ||
1530 | /* marshall the parameters */ | |
1531 | bp = call->request; | |
1532 | bp = xdr_encode_u32(bp, YFSSTOREDATA64); | |
1533 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1534 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
1535 | bp = xdr_encode_YFS_StoreStatus(bp, attr); | |
8c7ae38d | 1536 | bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */ |
30062bd1 DH |
1537 | bp = xdr_encode_u64(bp, 0); /* size of write */ |
1538 | bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */ | |
1539 | yfs_check_req(call, bp); | |
1540 | ||
1541 | afs_use_fs_server(call, fc->cbi); | |
1542 | trace_afs_make_fs_call(call, &vnode->fid); | |
20b8391f | 1543 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1544 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1545 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1546 | } |
1547 | ||
1548 | /* | |
1549 | * Set the attributes on a file, using YFS.StoreData64 if there's a change in | |
1550 | * file size, and YFS.StoreStatus otherwise. | |
1551 | */ | |
1552 | int yfs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr) | |
1553 | { | |
1554 | struct afs_vnode *vnode = fc->vnode; | |
1555 | struct afs_call *call; | |
1556 | struct afs_net *net = afs_v2net(vnode); | |
1557 | __be32 *bp; | |
1558 | ||
1559 | if (attr->ia_valid & ATTR_SIZE) | |
1560 | return yfs_fs_setattr_size(fc, attr); | |
1561 | ||
1562 | _enter(",%x,{%llx:%llu},,", | |
1563 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); | |
1564 | ||
1565 | call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus, | |
1566 | sizeof(__be32) * 2 + | |
1567 | sizeof(struct yfs_xdr_YFSFid) + | |
1568 | sizeof(struct yfs_xdr_YFSStoreStatus), | |
1569 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1570 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1571 | if (!call) | |
1572 | return -ENOMEM; | |
1573 | ||
1574 | call->key = fc->key; | |
ffba718e | 1575 | call->xvnode = vnode; |
30062bd1 DH |
1576 | call->expected_version = vnode->status.data_version; |
1577 | ||
1578 | /* marshall the parameters */ | |
1579 | bp = call->request; | |
1580 | bp = xdr_encode_u32(bp, YFSSTORESTATUS); | |
1581 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1582 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
1583 | bp = xdr_encode_YFS_StoreStatus(bp, attr); | |
1584 | yfs_check_req(call, bp); | |
1585 | ||
1586 | afs_use_fs_server(call, fc->cbi); | |
1587 | trace_afs_make_fs_call(call, &vnode->fid); | |
20b8391f | 1588 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1589 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1590 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1591 | } |
1592 | ||
1593 | /* | |
1594 | * Deliver reply data to a YFS.GetVolumeStatus operation. | |
1595 | */ | |
1596 | static int yfs_deliver_fs_get_volume_status(struct afs_call *call) | |
1597 | { | |
1598 | const __be32 *bp; | |
1599 | char *p; | |
1600 | u32 size; | |
1601 | int ret; | |
1602 | ||
1603 | _enter("{%u}", call->unmarshall); | |
1604 | ||
1605 | switch (call->unmarshall) { | |
1606 | case 0: | |
1607 | call->unmarshall++; | |
1608 | afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus)); | |
1609 | ||
e690c9e3 | 1610 | /* Fall through - and extract the returned status record */ |
30062bd1 DH |
1611 | case 1: |
1612 | _debug("extract status"); | |
1613 | ret = afs_extract_data(call, true); | |
1614 | if (ret < 0) | |
1615 | return ret; | |
1616 | ||
1617 | bp = call->buffer; | |
ffba718e | 1618 | xdr_decode_YFSFetchVolumeStatus(&bp, call->out_volstatus); |
30062bd1 DH |
1619 | call->unmarshall++; |
1620 | afs_extract_to_tmp(call); | |
1621 | ||
e690c9e3 | 1622 | /* Fall through - and extract the volume name length */ |
30062bd1 DH |
1623 | case 2: |
1624 | ret = afs_extract_data(call, true); | |
1625 | if (ret < 0) | |
1626 | return ret; | |
1627 | ||
1628 | call->count = ntohl(call->tmp); | |
1629 | _debug("volname length: %u", call->count); | |
1630 | if (call->count >= AFSNAMEMAX) | |
1631 | return afs_protocol_error(call, -EBADMSG, | |
1632 | afs_eproto_volname_len); | |
1633 | size = (call->count + 3) & ~3; /* It's padded */ | |
ffba718e | 1634 | afs_extract_to_buf(call, size); |
30062bd1 DH |
1635 | call->unmarshall++; |
1636 | ||
e690c9e3 | 1637 | /* Fall through - and extract the volume name */ |
30062bd1 DH |
1638 | case 3: |
1639 | _debug("extract volname"); | |
1640 | ret = afs_extract_data(call, true); | |
1641 | if (ret < 0) | |
1642 | return ret; | |
1643 | ||
ffba718e | 1644 | p = call->buffer; |
30062bd1 DH |
1645 | p[call->count] = 0; |
1646 | _debug("volname '%s'", p); | |
1647 | afs_extract_to_tmp(call); | |
1648 | call->unmarshall++; | |
1649 | ||
e690c9e3 | 1650 | /* Fall through - and extract the offline message length */ |
30062bd1 DH |
1651 | case 4: |
1652 | ret = afs_extract_data(call, true); | |
1653 | if (ret < 0) | |
1654 | return ret; | |
1655 | ||
1656 | call->count = ntohl(call->tmp); | |
1657 | _debug("offline msg length: %u", call->count); | |
1658 | if (call->count >= AFSNAMEMAX) | |
1659 | return afs_protocol_error(call, -EBADMSG, | |
1660 | afs_eproto_offline_msg_len); | |
1661 | size = (call->count + 3) & ~3; /* It's padded */ | |
ffba718e | 1662 | afs_extract_to_buf(call, size); |
30062bd1 DH |
1663 | call->unmarshall++; |
1664 | ||
e690c9e3 | 1665 | /* Fall through - and extract the offline message */ |
30062bd1 DH |
1666 | case 5: |
1667 | _debug("extract offline"); | |
1668 | ret = afs_extract_data(call, true); | |
1669 | if (ret < 0) | |
1670 | return ret; | |
1671 | ||
ffba718e | 1672 | p = call->buffer; |
30062bd1 DH |
1673 | p[call->count] = 0; |
1674 | _debug("offline '%s'", p); | |
1675 | ||
1676 | afs_extract_to_tmp(call); | |
1677 | call->unmarshall++; | |
1678 | ||
e690c9e3 | 1679 | /* Fall through - and extract the message of the day length */ |
30062bd1 DH |
1680 | case 6: |
1681 | ret = afs_extract_data(call, true); | |
1682 | if (ret < 0) | |
1683 | return ret; | |
1684 | ||
1685 | call->count = ntohl(call->tmp); | |
1686 | _debug("motd length: %u", call->count); | |
1687 | if (call->count >= AFSNAMEMAX) | |
1688 | return afs_protocol_error(call, -EBADMSG, | |
1689 | afs_eproto_motd_len); | |
1690 | size = (call->count + 3) & ~3; /* It's padded */ | |
ffba718e | 1691 | afs_extract_to_buf(call, size); |
30062bd1 DH |
1692 | call->unmarshall++; |
1693 | ||
e690c9e3 | 1694 | /* Fall through - and extract the message of the day */ |
30062bd1 DH |
1695 | case 7: |
1696 | _debug("extract motd"); | |
1697 | ret = afs_extract_data(call, false); | |
1698 | if (ret < 0) | |
1699 | return ret; | |
1700 | ||
ffba718e | 1701 | p = call->buffer; |
30062bd1 DH |
1702 | p[call->count] = 0; |
1703 | _debug("motd '%s'", p); | |
1704 | ||
1705 | call->unmarshall++; | |
1706 | ||
e690c9e3 | 1707 | /* Fall through */ |
30062bd1 DH |
1708 | case 8: |
1709 | break; | |
1710 | } | |
1711 | ||
1712 | _leave(" = 0 [done]"); | |
1713 | return 0; | |
1714 | } | |
1715 | ||
30062bd1 DH |
1716 | /* |
1717 | * YFS.GetVolumeStatus operation type | |
1718 | */ | |
1719 | static const struct afs_call_type yfs_RXYFSGetVolumeStatus = { | |
1720 | .name = "YFS.GetVolumeStatus", | |
1721 | .op = yfs_FS_GetVolumeStatus, | |
1722 | .deliver = yfs_deliver_fs_get_volume_status, | |
ffba718e | 1723 | .destructor = afs_flat_call_destructor, |
30062bd1 DH |
1724 | }; |
1725 | ||
1726 | /* | |
1727 | * fetch the status of a volume | |
1728 | */ | |
1729 | int yfs_fs_get_volume_status(struct afs_fs_cursor *fc, | |
1730 | struct afs_volume_status *vs) | |
1731 | { | |
1732 | struct afs_vnode *vnode = fc->vnode; | |
1733 | struct afs_call *call; | |
1734 | struct afs_net *net = afs_v2net(vnode); | |
1735 | __be32 *bp; | |
30062bd1 DH |
1736 | |
1737 | _enter(""); | |
1738 | ||
30062bd1 DH |
1739 | call = afs_alloc_flat_call(net, &yfs_RXYFSGetVolumeStatus, |
1740 | sizeof(__be32) * 2 + | |
1741 | sizeof(struct yfs_xdr_u64), | |
ffba718e DH |
1742 | max_t(size_t, |
1743 | sizeof(struct yfs_xdr_YFSFetchVolumeStatus) + | |
1744 | sizeof(__be32), | |
1745 | AFSOPAQUEMAX + 1)); | |
1746 | if (!call) | |
30062bd1 | 1747 | return -ENOMEM; |
30062bd1 DH |
1748 | |
1749 | call->key = fc->key; | |
ffba718e | 1750 | call->out_volstatus = vs; |
30062bd1 DH |
1751 | |
1752 | /* marshall the parameters */ | |
1753 | bp = call->request; | |
1754 | bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS); | |
1755 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1756 | bp = xdr_encode_u64(bp, vnode->fid.vid); | |
1757 | yfs_check_req(call, bp); | |
1758 | ||
1759 | afs_use_fs_server(call, fc->cbi); | |
1760 | trace_afs_make_fs_call(call, &vnode->fid); | |
20b8391f | 1761 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1762 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1763 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1764 | } |
1765 | ||
1766 | /* | |
f5e45463 DH |
1767 | * Deliver reply data to operations that just return a file status and a volume |
1768 | * sync record. | |
30062bd1 | 1769 | */ |
f5e45463 | 1770 | static int yfs_deliver_status_and_volsync(struct afs_call *call) |
30062bd1 | 1771 | { |
ffba718e | 1772 | struct afs_vnode *vnode = call->xvnode; |
30062bd1 DH |
1773 | const __be32 *bp; |
1774 | int ret; | |
1775 | ||
1776 | _enter("{%u}", call->unmarshall); | |
1777 | ||
1778 | ret = afs_transfer_reply(call); | |
1779 | if (ret < 0) | |
1780 | return ret; | |
1781 | ||
1782 | /* unmarshall the reply once we've received all of it */ | |
1783 | bp = call->buffer; | |
1784 | ret = yfs_decode_status(call, &bp, &vnode->status, vnode, | |
1785 | &call->expected_version, NULL); | |
1786 | if (ret < 0) | |
1787 | return ret; | |
1788 | xdr_decode_YFSVolSync(&bp, NULL); | |
1789 | ||
1790 | _leave(" = 0 [done]"); | |
1791 | return 0; | |
1792 | } | |
1793 | ||
1794 | /* | |
1795 | * YFS.SetLock operation type | |
1796 | */ | |
1797 | static const struct afs_call_type yfs_RXYFSSetLock = { | |
1798 | .name = "YFS.SetLock", | |
1799 | .op = yfs_FS_SetLock, | |
f5e45463 | 1800 | .deliver = yfs_deliver_status_and_volsync, |
a690f60a | 1801 | .done = afs_lock_op_done, |
30062bd1 DH |
1802 | .destructor = afs_flat_call_destructor, |
1803 | }; | |
1804 | ||
1805 | /* | |
1806 | * YFS.ExtendLock operation type | |
1807 | */ | |
1808 | static const struct afs_call_type yfs_RXYFSExtendLock = { | |
1809 | .name = "YFS.ExtendLock", | |
1810 | .op = yfs_FS_ExtendLock, | |
f5e45463 | 1811 | .deliver = yfs_deliver_status_and_volsync, |
a690f60a | 1812 | .done = afs_lock_op_done, |
30062bd1 DH |
1813 | .destructor = afs_flat_call_destructor, |
1814 | }; | |
1815 | ||
1816 | /* | |
1817 | * YFS.ReleaseLock operation type | |
1818 | */ | |
1819 | static const struct afs_call_type yfs_RXYFSReleaseLock = { | |
1820 | .name = "YFS.ReleaseLock", | |
1821 | .op = yfs_FS_ReleaseLock, | |
f5e45463 | 1822 | .deliver = yfs_deliver_status_and_volsync, |
30062bd1 DH |
1823 | .destructor = afs_flat_call_destructor, |
1824 | }; | |
1825 | ||
1826 | /* | |
1827 | * Set a lock on a file | |
1828 | */ | |
1829 | int yfs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type) | |
1830 | { | |
1831 | struct afs_vnode *vnode = fc->vnode; | |
1832 | struct afs_call *call; | |
1833 | struct afs_net *net = afs_v2net(vnode); | |
1834 | __be32 *bp; | |
1835 | ||
1836 | _enter(""); | |
1837 | ||
1838 | call = afs_alloc_flat_call(net, &yfs_RXYFSSetLock, | |
1839 | sizeof(__be32) * 2 + | |
1840 | sizeof(struct yfs_xdr_YFSFid) + | |
1841 | sizeof(__be32), | |
1842 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1843 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1844 | if (!call) | |
1845 | return -ENOMEM; | |
1846 | ||
1847 | call->key = fc->key; | |
ffba718e | 1848 | call->xvnode = vnode; |
30062bd1 DH |
1849 | |
1850 | /* marshall the parameters */ | |
1851 | bp = call->request; | |
1852 | bp = xdr_encode_u32(bp, YFSSETLOCK); | |
1853 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1854 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
1855 | bp = xdr_encode_u32(bp, type); | |
1856 | yfs_check_req(call, bp); | |
1857 | ||
1858 | afs_use_fs_server(call, fc->cbi); | |
6c6c1d63 | 1859 | trace_afs_make_fs_calli(call, &vnode->fid, type); |
20b8391f | 1860 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1861 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1862 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1863 | } |
1864 | ||
1865 | /* | |
1866 | * extend a lock on a file | |
1867 | */ | |
1868 | int yfs_fs_extend_lock(struct afs_fs_cursor *fc) | |
1869 | { | |
1870 | struct afs_vnode *vnode = fc->vnode; | |
1871 | struct afs_call *call; | |
1872 | struct afs_net *net = afs_v2net(vnode); | |
1873 | __be32 *bp; | |
1874 | ||
1875 | _enter(""); | |
1876 | ||
1877 | call = afs_alloc_flat_call(net, &yfs_RXYFSExtendLock, | |
1878 | sizeof(__be32) * 2 + | |
1879 | sizeof(struct yfs_xdr_YFSFid), | |
1880 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1881 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1882 | if (!call) | |
1883 | return -ENOMEM; | |
1884 | ||
1885 | call->key = fc->key; | |
ffba718e | 1886 | call->xvnode = vnode; |
30062bd1 DH |
1887 | |
1888 | /* marshall the parameters */ | |
1889 | bp = call->request; | |
1890 | bp = xdr_encode_u32(bp, YFSEXTENDLOCK); | |
1891 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1892 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
1893 | yfs_check_req(call, bp); | |
1894 | ||
1895 | afs_use_fs_server(call, fc->cbi); | |
1896 | trace_afs_make_fs_call(call, &vnode->fid); | |
20b8391f | 1897 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1898 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1899 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1900 | } |
1901 | ||
1902 | /* | |
1903 | * release a lock on a file | |
1904 | */ | |
1905 | int yfs_fs_release_lock(struct afs_fs_cursor *fc) | |
1906 | { | |
1907 | struct afs_vnode *vnode = fc->vnode; | |
1908 | struct afs_call *call; | |
1909 | struct afs_net *net = afs_v2net(vnode); | |
1910 | __be32 *bp; | |
1911 | ||
1912 | _enter(""); | |
1913 | ||
1914 | call = afs_alloc_flat_call(net, &yfs_RXYFSReleaseLock, | |
1915 | sizeof(__be32) * 2 + | |
1916 | sizeof(struct yfs_xdr_YFSFid), | |
1917 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1918 | sizeof(struct yfs_xdr_YFSVolSync)); | |
1919 | if (!call) | |
1920 | return -ENOMEM; | |
1921 | ||
1922 | call->key = fc->key; | |
ffba718e | 1923 | call->xvnode = vnode; |
30062bd1 DH |
1924 | |
1925 | /* marshall the parameters */ | |
1926 | bp = call->request; | |
1927 | bp = xdr_encode_u32(bp, YFSRELEASELOCK); | |
1928 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
1929 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
1930 | yfs_check_req(call, bp); | |
1931 | ||
1932 | afs_use_fs_server(call, fc->cbi); | |
1933 | trace_afs_make_fs_call(call, &vnode->fid); | |
20b8391f | 1934 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
1935 | afs_make_call(&fc->ac, call, GFP_NOFS); |
1936 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
1937 | } |
1938 | ||
1939 | /* | |
1940 | * Deliver reply data to an FS.FetchStatus with no vnode. | |
1941 | */ | |
1942 | static int yfs_deliver_fs_fetch_status(struct afs_call *call) | |
1943 | { | |
ffba718e DH |
1944 | struct afs_file_status *status = call->out_extra_status; |
1945 | struct afs_callback *callback = call->out_cb; | |
1946 | struct afs_volsync *volsync = call->out_volsync; | |
30062bd1 DH |
1947 | const __be32 *bp; |
1948 | int ret; | |
1949 | ||
1950 | ret = afs_transfer_reply(call); | |
1951 | if (ret < 0) | |
1952 | return ret; | |
1953 | ||
ffba718e | 1954 | _enter(""); |
30062bd1 DH |
1955 | |
1956 | /* unmarshall the reply once we've received all of it */ | |
1957 | bp = call->buffer; | |
ffba718e | 1958 | ret = yfs_decode_status(call, &bp, status, NULL, |
30062bd1 DH |
1959 | &call->expected_version, NULL); |
1960 | if (ret < 0) | |
1961 | return ret; | |
78107055 | 1962 | xdr_decode_YFSCallBack_raw(call, callback, &bp); |
30062bd1 DH |
1963 | xdr_decode_YFSVolSync(&bp, volsync); |
1964 | ||
1965 | _leave(" = 0 [done]"); | |
1966 | return 0; | |
1967 | } | |
1968 | ||
1969 | /* | |
1970 | * YFS.FetchStatus operation type | |
1971 | */ | |
1972 | static const struct afs_call_type yfs_RXYFSFetchStatus = { | |
1973 | .name = "YFS.FetchStatus", | |
1974 | .op = yfs_FS_FetchStatus, | |
1975 | .deliver = yfs_deliver_fs_fetch_status, | |
1976 | .destructor = afs_flat_call_destructor, | |
1977 | }; | |
1978 | ||
1979 | /* | |
1980 | * Fetch the status information for a fid without needing a vnode handle. | |
1981 | */ | |
1982 | int yfs_fs_fetch_status(struct afs_fs_cursor *fc, | |
1983 | struct afs_net *net, | |
1984 | struct afs_fid *fid, | |
1985 | struct afs_file_status *status, | |
1986 | struct afs_callback *callback, | |
1987 | struct afs_volsync *volsync) | |
1988 | { | |
1989 | struct afs_call *call; | |
1990 | __be32 *bp; | |
1991 | ||
1992 | _enter(",%x,{%llx:%llu},,", | |
1993 | key_serial(fc->key), fid->vid, fid->vnode); | |
1994 | ||
1995 | call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus, | |
1996 | sizeof(__be32) * 2 + | |
1997 | sizeof(struct yfs_xdr_YFSFid), | |
1998 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
1999 | sizeof(struct yfs_xdr_YFSCallBack) + | |
2000 | sizeof(struct yfs_xdr_YFSVolSync)); | |
2001 | if (!call) { | |
2002 | fc->ac.error = -ENOMEM; | |
2003 | return -ENOMEM; | |
2004 | } | |
2005 | ||
2006 | call->key = fc->key; | |
ffba718e DH |
2007 | call->out_extra_status = status; |
2008 | call->out_cb = callback; | |
2009 | call->out_volsync = volsync; | |
30062bd1 DH |
2010 | call->expected_version = 1; /* vnode->status.data_version */ |
2011 | ||
2012 | /* marshall the parameters */ | |
2013 | bp = call->request; | |
2014 | bp = xdr_encode_u32(bp, YFSFETCHSTATUS); | |
2015 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
2016 | bp = xdr_encode_YFSFid(bp, fid); | |
2017 | yfs_check_req(call, bp); | |
2018 | ||
2019 | call->cb_break = fc->cb_break; | |
2020 | afs_use_fs_server(call, fc->cbi); | |
2021 | trace_afs_make_fs_call(call, fid); | |
20b8391f | 2022 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
2023 | afs_make_call(&fc->ac, call, GFP_NOFS); |
2024 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 DH |
2025 | } |
2026 | ||
2027 | /* | |
2028 | * Deliver reply data to an YFS.InlineBulkStatus call | |
2029 | */ | |
2030 | static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call) | |
2031 | { | |
87182759 | 2032 | struct afs_status_cb *scb; |
30062bd1 DH |
2033 | const __be32 *bp; |
2034 | u32 tmp; | |
2035 | int ret; | |
2036 | ||
2037 | _enter("{%u}", call->unmarshall); | |
2038 | ||
2039 | switch (call->unmarshall) { | |
2040 | case 0: | |
2041 | afs_extract_to_tmp(call); | |
2042 | call->unmarshall++; | |
2043 | ||
2044 | /* Extract the file status count and array in two steps */ | |
e690c9e3 | 2045 | /* Fall through */ |
30062bd1 DH |
2046 | case 1: |
2047 | _debug("extract status count"); | |
2048 | ret = afs_extract_data(call, true); | |
2049 | if (ret < 0) | |
2050 | return ret; | |
2051 | ||
2052 | tmp = ntohl(call->tmp); | |
2053 | _debug("status count: %u/%u", tmp, call->count2); | |
2054 | if (tmp != call->count2) | |
2055 | return afs_protocol_error(call, -EBADMSG, | |
2056 | afs_eproto_ibulkst_count); | |
2057 | ||
2058 | call->count = 0; | |
2059 | call->unmarshall++; | |
2060 | more_counts: | |
2061 | afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus)); | |
2062 | ||
e690c9e3 | 2063 | /* Fall through */ |
30062bd1 DH |
2064 | case 2: |
2065 | _debug("extract status array %u", call->count); | |
2066 | ret = afs_extract_data(call, true); | |
2067 | if (ret < 0) | |
2068 | return ret; | |
2069 | ||
2070 | bp = call->buffer; | |
87182759 DH |
2071 | scb = &call->out_scb[call->count]; |
2072 | ret = yfs_decode_status(call, &bp, &scb->status, | |
fefb2483 | 2073 | NULL, NULL, NULL); |
30062bd1 DH |
2074 | if (ret < 0) |
2075 | return ret; | |
2076 | ||
2077 | call->count++; | |
2078 | if (call->count < call->count2) | |
2079 | goto more_counts; | |
2080 | ||
2081 | call->count = 0; | |
2082 | call->unmarshall++; | |
2083 | afs_extract_to_tmp(call); | |
2084 | ||
2085 | /* Extract the callback count and array in two steps */ | |
e690c9e3 | 2086 | /* Fall through */ |
30062bd1 DH |
2087 | case 3: |
2088 | _debug("extract CB count"); | |
2089 | ret = afs_extract_data(call, true); | |
2090 | if (ret < 0) | |
2091 | return ret; | |
2092 | ||
2093 | tmp = ntohl(call->tmp); | |
2094 | _debug("CB count: %u", tmp); | |
2095 | if (tmp != call->count2) | |
2096 | return afs_protocol_error(call, -EBADMSG, | |
2097 | afs_eproto_ibulkst_cb_count); | |
2098 | call->count = 0; | |
2099 | call->unmarshall++; | |
2100 | more_cbs: | |
2101 | afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack)); | |
2102 | ||
e690c9e3 | 2103 | /* Fall through */ |
30062bd1 DH |
2104 | case 4: |
2105 | _debug("extract CB array"); | |
2106 | ret = afs_extract_data(call, true); | |
2107 | if (ret < 0) | |
2108 | return ret; | |
2109 | ||
2110 | _debug("unmarshall CB array"); | |
2111 | bp = call->buffer; | |
87182759 DH |
2112 | scb = &call->out_scb[call->count]; |
2113 | xdr_decode_YFSCallBack_raw(call, &scb->callback, &bp); | |
2114 | scb->have_cb = true; | |
30062bd1 DH |
2115 | call->count++; |
2116 | if (call->count < call->count2) | |
2117 | goto more_cbs; | |
2118 | ||
2119 | afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync)); | |
2120 | call->unmarshall++; | |
2121 | ||
e690c9e3 | 2122 | /* Fall through */ |
30062bd1 DH |
2123 | case 5: |
2124 | ret = afs_extract_data(call, false); | |
2125 | if (ret < 0) | |
2126 | return ret; | |
2127 | ||
2128 | bp = call->buffer; | |
ffba718e | 2129 | xdr_decode_YFSVolSync(&bp, call->out_volsync); |
30062bd1 DH |
2130 | |
2131 | call->unmarshall++; | |
2132 | ||
e690c9e3 | 2133 | /* Fall through */ |
30062bd1 DH |
2134 | case 6: |
2135 | break; | |
2136 | } | |
2137 | ||
2138 | _leave(" = 0 [done]"); | |
2139 | return 0; | |
2140 | } | |
2141 | ||
2142 | /* | |
2143 | * FS.InlineBulkStatus operation type | |
2144 | */ | |
2145 | static const struct afs_call_type yfs_RXYFSInlineBulkStatus = { | |
2146 | .name = "YFS.InlineBulkStatus", | |
2147 | .op = yfs_FS_InlineBulkStatus, | |
2148 | .deliver = yfs_deliver_fs_inline_bulk_status, | |
2149 | .destructor = afs_flat_call_destructor, | |
2150 | }; | |
2151 | ||
2152 | /* | |
2153 | * Fetch the status information for up to 1024 files | |
2154 | */ | |
2155 | int yfs_fs_inline_bulk_status(struct afs_fs_cursor *fc, | |
2156 | struct afs_net *net, | |
2157 | struct afs_fid *fids, | |
87182759 | 2158 | struct afs_status_cb *statuses, |
30062bd1 DH |
2159 | unsigned int nr_fids, |
2160 | struct afs_volsync *volsync) | |
2161 | { | |
2162 | struct afs_call *call; | |
2163 | __be32 *bp; | |
2164 | int i; | |
2165 | ||
2166 | _enter(",%x,{%llx:%llu},%u", | |
2167 | key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids); | |
2168 | ||
2169 | call = afs_alloc_flat_call(net, &yfs_RXYFSInlineBulkStatus, | |
2170 | sizeof(__be32) + | |
2171 | sizeof(__be32) + | |
2172 | sizeof(__be32) + | |
2173 | sizeof(struct yfs_xdr_YFSFid) * nr_fids, | |
2174 | sizeof(struct yfs_xdr_YFSFetchStatus)); | |
2175 | if (!call) { | |
2176 | fc->ac.error = -ENOMEM; | |
2177 | return -ENOMEM; | |
2178 | } | |
2179 | ||
2180 | call->key = fc->key; | |
87182759 | 2181 | call->out_scb = statuses; |
ffba718e | 2182 | call->out_volsync = volsync; |
30062bd1 DH |
2183 | call->count2 = nr_fids; |
2184 | ||
2185 | /* marshall the parameters */ | |
2186 | bp = call->request; | |
2187 | bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS); | |
2188 | bp = xdr_encode_u32(bp, 0); /* RPCFlags */ | |
2189 | bp = xdr_encode_u32(bp, nr_fids); | |
2190 | for (i = 0; i < nr_fids; i++) | |
2191 | bp = xdr_encode_YFSFid(bp, &fids[i]); | |
2192 | yfs_check_req(call, bp); | |
2193 | ||
2194 | call->cb_break = fc->cb_break; | |
2195 | afs_use_fs_server(call, fc->cbi); | |
2196 | trace_afs_make_fs_call(call, &fids[0]); | |
20b8391f | 2197 | afs_set_fc_call(call, fc); |
0b9bf381 DH |
2198 | afs_make_call(&fc->ac, call, GFP_NOFS); |
2199 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 | 2200 | } |
ae46578b DH |
2201 | |
2202 | /* | |
2203 | * Deliver reply data to an YFS.FetchOpaqueACL. | |
2204 | */ | |
2205 | static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call) | |
2206 | { | |
ffba718e DH |
2207 | struct afs_volsync *volsync = call->out_volsync; |
2208 | struct afs_vnode *vnode = call->xvnode; | |
2209 | struct yfs_acl *yacl = call->out_yacl; | |
ae46578b DH |
2210 | struct afs_acl *acl; |
2211 | const __be32 *bp; | |
2212 | unsigned int size; | |
2213 | int ret; | |
2214 | ||
2215 | _enter("{%u}", call->unmarshall); | |
2216 | ||
2217 | switch (call->unmarshall) { | |
2218 | case 0: | |
2219 | afs_extract_to_tmp(call); | |
2220 | call->unmarshall++; | |
2221 | ||
2222 | /* Extract the file ACL length */ | |
2223 | case 1: | |
2224 | ret = afs_extract_data(call, true); | |
2225 | if (ret < 0) | |
2226 | return ret; | |
2227 | ||
2228 | size = call->count2 = ntohl(call->tmp); | |
2229 | size = round_up(size, 4); | |
2230 | ||
2231 | if (yacl->flags & YFS_ACL_WANT_ACL) { | |
2232 | acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL); | |
2233 | if (!acl) | |
2234 | return -ENOMEM; | |
2235 | yacl->acl = acl; | |
2236 | acl->size = call->count2; | |
2237 | afs_extract_begin(call, acl->data, size); | |
2238 | } else { | |
2239 | iov_iter_discard(&call->iter, READ, size); | |
2240 | } | |
2241 | call->unmarshall++; | |
2242 | ||
2243 | /* Extract the file ACL */ | |
2244 | case 2: | |
2245 | ret = afs_extract_data(call, true); | |
2246 | if (ret < 0) | |
2247 | return ret; | |
2248 | ||
2249 | afs_extract_to_tmp(call); | |
2250 | call->unmarshall++; | |
2251 | ||
2252 | /* Extract the volume ACL length */ | |
2253 | case 3: | |
2254 | ret = afs_extract_data(call, true); | |
2255 | if (ret < 0) | |
2256 | return ret; | |
2257 | ||
2258 | size = call->count2 = ntohl(call->tmp); | |
2259 | size = round_up(size, 4); | |
2260 | ||
2261 | if (yacl->flags & YFS_ACL_WANT_VOL_ACL) { | |
2262 | acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL); | |
2263 | if (!acl) | |
2264 | return -ENOMEM; | |
2265 | yacl->vol_acl = acl; | |
2266 | acl->size = call->count2; | |
2267 | afs_extract_begin(call, acl->data, size); | |
2268 | } else { | |
2269 | iov_iter_discard(&call->iter, READ, size); | |
2270 | } | |
2271 | call->unmarshall++; | |
2272 | ||
2273 | /* Extract the volume ACL */ | |
2274 | case 4: | |
2275 | ret = afs_extract_data(call, true); | |
2276 | if (ret < 0) | |
2277 | return ret; | |
2278 | ||
2279 | afs_extract_to_buf(call, | |
2280 | sizeof(__be32) * 2 + | |
2281 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
2282 | sizeof(struct yfs_xdr_YFSVolSync)); | |
2283 | call->unmarshall++; | |
2284 | ||
2285 | /* extract the metadata */ | |
2286 | case 5: | |
2287 | ret = afs_extract_data(call, false); | |
2288 | if (ret < 0) | |
2289 | return ret; | |
2290 | ||
2291 | bp = call->buffer; | |
2292 | yacl->inherit_flag = ntohl(*bp++); | |
2293 | yacl->num_cleaned = ntohl(*bp++); | |
2294 | ret = yfs_decode_status(call, &bp, &vnode->status, vnode, | |
2295 | &call->expected_version, NULL); | |
2296 | if (ret < 0) | |
2297 | return ret; | |
2298 | xdr_decode_YFSVolSync(&bp, volsync); | |
2299 | ||
2300 | call->unmarshall++; | |
2301 | ||
2302 | case 6: | |
2303 | break; | |
2304 | } | |
2305 | ||
2306 | _leave(" = 0 [done]"); | |
2307 | return 0; | |
2308 | } | |
2309 | ||
2310 | void yfs_free_opaque_acl(struct yfs_acl *yacl) | |
2311 | { | |
2312 | if (yacl) { | |
2313 | kfree(yacl->acl); | |
2314 | kfree(yacl->vol_acl); | |
2315 | kfree(yacl); | |
2316 | } | |
2317 | } | |
2318 | ||
ae46578b DH |
2319 | /* |
2320 | * YFS.FetchOpaqueACL operation type | |
2321 | */ | |
2322 | static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = { | |
2323 | .name = "YFS.FetchOpaqueACL", | |
2324 | .op = yfs_FS_FetchOpaqueACL, | |
2325 | .deliver = yfs_deliver_fs_fetch_opaque_acl, | |
773e0c40 | 2326 | .destructor = afs_flat_call_destructor, |
ae46578b DH |
2327 | }; |
2328 | ||
2329 | /* | |
2330 | * Fetch the YFS advanced ACLs for a file. | |
2331 | */ | |
2332 | struct yfs_acl *yfs_fs_fetch_opaque_acl(struct afs_fs_cursor *fc, | |
773e0c40 | 2333 | struct yfs_acl *yacl) |
ae46578b DH |
2334 | { |
2335 | struct afs_vnode *vnode = fc->vnode; | |
2336 | struct afs_call *call; | |
ae46578b DH |
2337 | struct afs_net *net = afs_v2net(vnode); |
2338 | __be32 *bp; | |
2339 | ||
2340 | _enter(",%x,{%llx:%llu},,", | |
2341 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); | |
2342 | ||
2343 | call = afs_alloc_flat_call(net, &yfs_RXYFSFetchOpaqueACL, | |
2344 | sizeof(__be32) * 2 + | |
2345 | sizeof(struct yfs_xdr_YFSFid), | |
2346 | sizeof(__be32) * 2 + | |
2347 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
2348 | sizeof(struct yfs_xdr_YFSVolSync)); | |
773e0c40 DH |
2349 | if (!call) { |
2350 | fc->ac.error = -ENOMEM; | |
2351 | return ERR_PTR(-ENOMEM); | |
2352 | } | |
ae46578b | 2353 | |
ae46578b | 2354 | call->key = fc->key; |
ffba718e DH |
2355 | call->out_yacl = yacl; |
2356 | call->xvnode = vnode; | |
2357 | call->out_volsync = NULL; /* volsync */ | |
ae46578b DH |
2358 | |
2359 | /* marshall the parameters */ | |
2360 | bp = call->request; | |
2361 | bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL); | |
2362 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
2363 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
2364 | yfs_check_req(call, bp); | |
2365 | ||
2366 | call->cb_break = fc->cb_break; | |
2367 | afs_use_fs_server(call, fc->cbi); | |
2368 | trace_afs_make_fs_call(call, &vnode->fid); | |
2369 | afs_make_call(&fc->ac, call, GFP_KERNEL); | |
2370 | return (struct yfs_acl *)afs_wait_for_call_to_complete(call, &fc->ac); | |
ae46578b | 2371 | } |
f5e45463 DH |
2372 | |
2373 | /* | |
2374 | * YFS.StoreOpaqueACL2 operation type | |
2375 | */ | |
2376 | static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = { | |
2377 | .name = "YFS.StoreOpaqueACL2", | |
2378 | .op = yfs_FS_StoreOpaqueACL2, | |
2379 | .deliver = yfs_deliver_status_and_volsync, | |
2380 | .destructor = afs_flat_call_destructor, | |
2381 | }; | |
2382 | ||
2383 | /* | |
2384 | * Fetch the YFS ACL for a file. | |
2385 | */ | |
2386 | int yfs_fs_store_opaque_acl2(struct afs_fs_cursor *fc, const struct afs_acl *acl) | |
2387 | { | |
2388 | struct afs_vnode *vnode = fc->vnode; | |
2389 | struct afs_call *call; | |
2390 | struct afs_net *net = afs_v2net(vnode); | |
2391 | size_t size; | |
2392 | __be32 *bp; | |
2393 | ||
2394 | _enter(",%x,{%llx:%llu},,", | |
2395 | key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode); | |
2396 | ||
2397 | size = round_up(acl->size, 4); | |
2398 | call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus, | |
2399 | sizeof(__be32) * 2 + | |
2400 | sizeof(struct yfs_xdr_YFSFid) + | |
2401 | sizeof(__be32) + size, | |
2402 | sizeof(struct yfs_xdr_YFSFetchStatus) + | |
2403 | sizeof(struct yfs_xdr_YFSVolSync)); | |
2404 | if (!call) { | |
2405 | fc->ac.error = -ENOMEM; | |
2406 | return -ENOMEM; | |
2407 | } | |
2408 | ||
2409 | call->key = fc->key; | |
ffba718e DH |
2410 | call->xvnode = vnode; |
2411 | call->out_volsync = NULL; | |
f5e45463 DH |
2412 | |
2413 | /* marshall the parameters */ | |
2414 | bp = call->request; | |
2415 | bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2); | |
2416 | bp = xdr_encode_u32(bp, 0); /* RPC flags */ | |
2417 | bp = xdr_encode_YFSFid(bp, &vnode->fid); | |
2418 | bp = xdr_encode_u32(bp, acl->size); | |
2419 | memcpy(bp, acl->data, acl->size); | |
2420 | if (acl->size != size) | |
2421 | memset((void *)bp + acl->size, 0, size - acl->size); | |
2422 | yfs_check_req(call, bp); | |
2423 | ||
2424 | trace_afs_make_fs_call(call, &vnode->fid); | |
2425 | afs_make_call(&fc->ac, call, GFP_KERNEL); | |
2426 | return afs_wait_for_call_to_complete(call, &fc->ac); | |
30062bd1 | 2427 | } |