1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* YFS File Server client stubs
3 *
4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
7
8 #include <linux/init.h>
9 #include <linux/slab.h>
10 #include <linux/sched.h>
11 #include <linux/circ_buf.h>
12 #include <linux/iversion.h>
13 #include "internal.h"
14 #include "afs_fs.h"
15 #include "xdr_fs.h"
16 #include "protocol_yfs.h"
17
18 #define xdr_size(x) (sizeof(*x) / sizeof(__be32))
19
xdr_decode_YFSFid(const __be32 ** _bp,struct afs_fid * fid)20 static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid)
21 {
22 const struct yfs_xdr_YFSFid *x = (const void *)*_bp;
23
24 fid->vid = xdr_to_u64(x->volume);
25 fid->vnode = xdr_to_u64(x->vnode.lo);
26 fid->vnode_hi = ntohl(x->vnode.hi);
27 fid->unique = ntohl(x->vnode.unique);
28 *_bp += xdr_size(x);
29 }
30
xdr_encode_u32(__be32 * bp,u32 n)31 static __be32 *xdr_encode_u32(__be32 *bp, u32 n)
32 {
33 *bp++ = htonl(n);
34 return bp;
35 }
36
xdr_encode_u64(__be32 * bp,u64 n)37 static __be32 *xdr_encode_u64(__be32 *bp, u64 n)
38 {
39 struct yfs_xdr_u64 *x = (void *)bp;
40
41 *x = u64_to_xdr(n);
42 return bp + xdr_size(x);
43 }
44
xdr_encode_YFSFid(__be32 * bp,struct afs_fid * fid)45 static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid)
46 {
47 struct yfs_xdr_YFSFid *x = (void *)bp;
48
49 x->volume = u64_to_xdr(fid->vid);
50 x->vnode.lo = u64_to_xdr(fid->vnode);
51 x->vnode.hi = htonl(fid->vnode_hi);
52 x->vnode.unique = htonl(fid->unique);
53 return bp + xdr_size(x);
54 }
55
xdr_strlen(unsigned int len)56 static size_t xdr_strlen(unsigned int len)
57 {
58 return sizeof(__be32) + round_up(len, sizeof(__be32));
59 }
60
xdr_encode_string(__be32 * bp,const char * p,unsigned int len)61 static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len)
62 {
63 bp = xdr_encode_u32(bp, len);
64 bp = memcpy(bp, p, len);
65 if (len & 3) {
66 unsigned int pad = 4 - (len & 3);
67
68 memset((u8 *)bp + len, 0, pad);
69 len += pad;
70 }
71
72 return bp + len / sizeof(__be32);
73 }
74
xdr_encode_name(__be32 * bp,const struct qstr * p)75 static __be32 *xdr_encode_name(__be32 *bp, const struct qstr *p)
76 {
77 return xdr_encode_string(bp, p->name, p->len);
78 }
79
linux_to_yfs_time(const struct timespec64 * t)80 static s64 linux_to_yfs_time(const struct timespec64 *t)
81 {
82 /* Convert to 100ns intervals. */
83 return (u64)t->tv_sec * 10000000 + t->tv_nsec/100;
84 }
85
xdr_encode_YFSStoreStatus_mode(__be32 * bp,mode_t mode)86 static __be32 *xdr_encode_YFSStoreStatus_mode(__be32 *bp, mode_t mode)
87 {
88 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
89
90 x->mask = htonl(AFS_SET_MODE);
91 x->mode = htonl(mode & S_IALLUGO);
92 x->mtime_client = u64_to_xdr(0);
93 x->owner = u64_to_xdr(0);
94 x->group = u64_to_xdr(0);
95 return bp + xdr_size(x);
96 }
97
xdr_encode_YFSStoreStatus_mtime(__be32 * bp,const struct timespec64 * t)98 static __be32 *xdr_encode_YFSStoreStatus_mtime(__be32 *bp, const struct timespec64 *t)
99 {
100 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
101 s64 mtime = linux_to_yfs_time(t);
102
103 x->mask = htonl(AFS_SET_MTIME);
104 x->mode = htonl(0);
105 x->mtime_client = u64_to_xdr(mtime);
106 x->owner = u64_to_xdr(0);
107 x->group = u64_to_xdr(0);
108 return bp + xdr_size(x);
109 }
110
111 /*
112 * Convert a signed 100ns-resolution 64-bit time into a timespec.
113 */
yfs_time_to_linux(s64 t)114 static struct timespec64 yfs_time_to_linux(s64 t)
115 {
116 struct timespec64 ts;
117 u64 abs_t;
118
119 /*
120 * Unfortunately can not use normal 64 bit division on 32 bit arch, but
121 * the alternative, do_div, does not work with negative numbers so have
122 * to special case them
123 */
124 if (t < 0) {
125 abs_t = -t;
126 ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
127 ts.tv_nsec = -ts.tv_nsec;
128 ts.tv_sec = -abs_t;
129 } else {
130 abs_t = t;
131 ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
132 ts.tv_sec = abs_t;
133 }
134
135 return ts;
136 }
137
xdr_to_time(const struct yfs_xdr_u64 xdr)138 static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
139 {
140 s64 t = xdr_to_u64(xdr);
141
142 return yfs_time_to_linux(t);
143 }
144
yfs_check_req(struct afs_call * call,__be32 * bp)145 static void yfs_check_req(struct afs_call *call, __be32 *bp)
146 {
147 size_t len = (void *)bp - call->request;
148
149 if (len > call->request_size)
150 pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n",
151 call->type->name, len, call->request_size);
152 else if (len < call->request_size)
153 pr_warn("kAFS: %s: Request buffer underflow (%zu<%u)\n",
154 call->type->name, len, call->request_size);
155 }
156
157 /*
158 * Dump a bad file status record.
159 */
xdr_dump_bad(const __be32 * bp)160 static void xdr_dump_bad(const __be32 *bp)
161 {
162 __be32 x[4];
163 int i;
164
165 pr_notice("YFS XDR: Bad status record\n");
166 for (i = 0; i < 6 * 4 * 4; i += 16) {
167 memcpy(x, bp, 16);
168 bp += 4;
169 pr_notice("%03x: %08x %08x %08x %08x\n",
170 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
171 }
172
173 memcpy(x, bp, 8);
174 pr_notice("0x60: %08x %08x\n", ntohl(x[0]), ntohl(x[1]));
175 }
176
177 /*
178 * Decode a YFSFetchStatus block
179 */
xdr_decode_YFSFetchStatus(const __be32 ** _bp,struct afs_call * call,struct afs_status_cb * scb)180 static void xdr_decode_YFSFetchStatus(const __be32 **_bp,
181 struct afs_call *call,
182 struct afs_status_cb *scb)
183 {
184 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
185 struct afs_file_status *status = &scb->status;
186 u32 type;
187
188 status->abort_code = ntohl(xdr->abort_code);
189 if (status->abort_code != 0) {
190 if (status->abort_code == VNOVNODE)
191 status->nlink = 0;
192 scb->have_error = true;
193 goto advance;
194 }
195
196 type = ntohl(xdr->type);
197 switch (type) {
198 case AFS_FTYPE_FILE:
199 case AFS_FTYPE_DIR:
200 case AFS_FTYPE_SYMLINK:
201 status->type = type;
202 break;
203 default:
204 goto bad;
205 }
206
207 status->nlink = ntohl(xdr->nlink);
208 status->author = xdr_to_u64(xdr->author);
209 status->owner = xdr_to_u64(xdr->owner);
210 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
211 status->anon_access = ntohl(xdr->anon_access);
212 status->mode = ntohl(xdr->mode) & S_IALLUGO;
213 status->group = xdr_to_u64(xdr->group);
214 status->lock_count = ntohl(xdr->lock_count);
215
216 status->mtime_client = xdr_to_time(xdr->mtime_client);
217 status->mtime_server = xdr_to_time(xdr->mtime_server);
218 status->size = xdr_to_u64(xdr->size);
219 status->data_version = xdr_to_u64(xdr->data_version);
220 scb->have_status = true;
221 advance:
222 *_bp += xdr_size(xdr);
223 return;
224
225 bad:
226 xdr_dump_bad(*_bp);
227 afs_protocol_error(call, afs_eproto_bad_status);
228 goto advance;
229 }
230
231 /*
232 * Decode a YFSCallBack block
233 */
xdr_decode_YFSCallBack(const __be32 ** _bp,struct afs_call * call,struct afs_status_cb * scb)234 static void xdr_decode_YFSCallBack(const __be32 **_bp,
235 struct afs_call *call,
236 struct afs_status_cb *scb)
237 {
238 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
239 struct afs_callback *cb = &scb->callback;
240 ktime_t cb_expiry;
241
242 cb_expiry = ktime_add(call->issue_time, xdr_to_u64(x->expiration_time) * 100);
243 cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
244 scb->have_cb = true;
245 *_bp += xdr_size(x);
246 }
247
248 /*
249 * Decode a YFSVolSync block
250 */
xdr_decode_YFSVolSync(const __be32 ** _bp,struct afs_volsync * volsync)251 static void xdr_decode_YFSVolSync(const __be32 **_bp,
252 struct afs_volsync *volsync)
253 {
254 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
255 u64 creation;
256
257 if (volsync) {
258 creation = xdr_to_u64(x->vol_creation_date);
259 do_div(creation, 10 * 1000 * 1000);
260 volsync->creation = creation;
261 }
262
263 *_bp += xdr_size(x);
264 }
265
266 /*
267 * Encode the requested attributes into a YFSStoreStatus block
268 */
xdr_encode_YFS_StoreStatus(__be32 * bp,struct iattr * attr)269 static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
270 {
271 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
272 s64 mtime = 0, owner = 0, group = 0;
273 u32 mask = 0, mode = 0;
274
275 mask = 0;
276 if (attr->ia_valid & ATTR_MTIME) {
277 mask |= AFS_SET_MTIME;
278 mtime = linux_to_yfs_time(&attr->ia_mtime);
279 }
280
281 if (attr->ia_valid & ATTR_UID) {
282 mask |= AFS_SET_OWNER;
283 owner = from_kuid(&init_user_ns, attr->ia_uid);
284 }
285
286 if (attr->ia_valid & ATTR_GID) {
287 mask |= AFS_SET_GROUP;
288 group = from_kgid(&init_user_ns, attr->ia_gid);
289 }
290
291 if (attr->ia_valid & ATTR_MODE) {
292 mask |= AFS_SET_MODE;
293 mode = attr->ia_mode & S_IALLUGO;
294 }
295
296 x->mask = htonl(mask);
297 x->mode = htonl(mode);
298 x->mtime_client = u64_to_xdr(mtime);
299 x->owner = u64_to_xdr(owner);
300 x->group = u64_to_xdr(group);
301 return bp + xdr_size(x);
302 }
303
304 /*
305 * Decode a YFSFetchVolumeStatus block.
306 */
xdr_decode_YFSFetchVolumeStatus(const __be32 ** _bp,struct afs_volume_status * vs)307 static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
308 struct afs_volume_status *vs)
309 {
310 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
311 u32 flags;
312
313 vs->vid = xdr_to_u64(x->vid);
314 vs->parent_id = xdr_to_u64(x->parent_id);
315 flags = ntohl(x->flags);
316 vs->online = flags & yfs_FVSOnline;
317 vs->in_service = flags & yfs_FVSInservice;
318 vs->blessed = flags & yfs_FVSBlessed;
319 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
320 vs->type = ntohl(x->type);
321 vs->min_quota = 0;
322 vs->max_quota = xdr_to_u64(x->max_quota);
323 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
324 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
325 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
326 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
327 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
328 *_bp += sizeof(*x) / sizeof(__be32);
329 }
330
331 /*
332 * Deliver reply data to operations that just return a file status and a volume
333 * sync record.
334 */
yfs_deliver_status_and_volsync(struct afs_call * call)335 static int yfs_deliver_status_and_volsync(struct afs_call *call)
336 {
337 struct afs_operation *op = call->op;
338 const __be32 *bp;
339 int ret;
340
341 ret = afs_transfer_reply(call);
342 if (ret < 0)
343 return ret;
344
345 bp = call->buffer;
346 xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
347 xdr_decode_YFSVolSync(&bp, &op->volsync);
348
349 _leave(" = 0 [done]");
350 return 0;
351 }
352
353 /*
354 * Deliver reply data to an YFS.FetchData64.
355 */
yfs_deliver_fs_fetch_data64(struct afs_call * call)356 static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
357 {
358 struct afs_operation *op = call->op;
359 struct afs_vnode_param *vp = &op->file[0];
360 struct afs_read *req = op->fetch.req;
361 const __be32 *bp;
362 int ret;
363
364 _enter("{%u,%zu, %zu/%llu}",
365 call->unmarshall, call->iov_len, iov_iter_count(call->iter),
366 req->actual_len);
367
368 switch (call->unmarshall) {
369 case 0:
370 req->actual_len = 0;
371 afs_extract_to_tmp64(call);
372 call->unmarshall++;
373 fallthrough;
374
375 /* Extract the returned data length into ->actual_len. This
376 * may indicate more or less data than was requested will be
377 * returned.
378 */
379 case 1:
380 _debug("extract data length");
381 ret = afs_extract_data(call, true);
382 if (ret < 0)
383 return ret;
384
385 req->actual_len = be64_to_cpu(call->tmp64);
386 _debug("DATA length: %llu", req->actual_len);
387
388 if (req->actual_len == 0)
389 goto no_more_data;
390
391 call->iter = req->iter;
392 call->iov_len = min(req->actual_len, req->len);
393 call->unmarshall++;
394 fallthrough;
395
396 /* extract the returned data */
397 case 2:
398 _debug("extract data %zu/%llu",
399 iov_iter_count(call->iter), req->actual_len);
400
401 ret = afs_extract_data(call, true);
402 if (ret < 0)
403 return ret;
404
405 call->iter = &call->def_iter;
406 if (req->actual_len <= req->len)
407 goto no_more_data;
408
409 /* Discard any excess data the server gave us */
410 afs_extract_discard(call, req->actual_len - req->len);
411 call->unmarshall = 3;
412 fallthrough;
413
414 case 3:
415 _debug("extract discard %zu/%llu",
416 iov_iter_count(call->iter), req->actual_len - req->len);
417
418 ret = afs_extract_data(call, true);
419 if (ret < 0)
420 return ret;
421
422 no_more_data:
423 call->unmarshall = 4;
424 afs_extract_to_buf(call,
425 sizeof(struct yfs_xdr_YFSFetchStatus) +
426 sizeof(struct yfs_xdr_YFSCallBack) +
427 sizeof(struct yfs_xdr_YFSVolSync));
428 fallthrough;
429
430 /* extract the metadata */
431 case 4:
432 ret = afs_extract_data(call, false);
433 if (ret < 0)
434 return ret;
435
436 bp = call->buffer;
437 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
438 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
439 xdr_decode_YFSVolSync(&bp, &op->volsync);
440
441 req->data_version = vp->scb.status.data_version;
442 req->file_size = vp->scb.status.size;
443
444 call->unmarshall++;
445 fallthrough;
446
447 case 5:
448 break;
449 }
450
451 _leave(" = 0 [done]");
452 return 0;
453 }
454
455 /*
456 * YFS.FetchData64 operation type
457 */
458 static const struct afs_call_type yfs_RXYFSFetchData64 = {
459 .name = "YFS.FetchData64",
460 .op = yfs_FS_FetchData64,
461 .deliver = yfs_deliver_fs_fetch_data64,
462 .destructor = afs_flat_call_destructor,
463 };
464
465 /*
466 * Fetch data from a file.
467 */
yfs_fs_fetch_data(struct afs_operation * op)468 void yfs_fs_fetch_data(struct afs_operation *op)
469 {
470 struct afs_vnode_param *vp = &op->file[0];
471 struct afs_read *req = op->fetch.req;
472 struct afs_call *call;
473 __be32 *bp;
474
475 _enter(",%x,{%llx:%llu},%llx,%llx",
476 key_serial(op->key), vp->fid.vid, vp->fid.vnode,
477 req->pos, req->len);
478
479 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
480 sizeof(__be32) * 2 +
481 sizeof(struct yfs_xdr_YFSFid) +
482 sizeof(struct yfs_xdr_u64) * 2,
483 sizeof(struct yfs_xdr_YFSFetchStatus) +
484 sizeof(struct yfs_xdr_YFSCallBack) +
485 sizeof(struct yfs_xdr_YFSVolSync));
486 if (!call)
487 return afs_op_nomem(op);
488
489 req->call_debug_id = call->debug_id;
490
491 /* marshall the parameters */
492 bp = call->request;
493 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
494 bp = xdr_encode_u32(bp, 0); /* RPC flags */
495 bp = xdr_encode_YFSFid(bp, &vp->fid);
496 bp = xdr_encode_u64(bp, req->pos);
497 bp = xdr_encode_u64(bp, req->len);
498 yfs_check_req(call, bp);
499
500 trace_afs_make_fs_call(call, &vp->fid);
501 afs_make_op_call(op, call, GFP_NOFS);
502 }
503
504 /*
505 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
506 */
yfs_deliver_fs_create_vnode(struct afs_call * call)507 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
508 {
509 struct afs_operation *op = call->op;
510 struct afs_vnode_param *dvp = &op->file[0];
511 struct afs_vnode_param *vp = &op->file[1];
512 const __be32 *bp;
513 int ret;
514
515 _enter("{%u}", call->unmarshall);
516
517 ret = afs_transfer_reply(call);
518 if (ret < 0)
519 return ret;
520
521 /* unmarshall the reply once we've received all of it */
522 bp = call->buffer;
523 xdr_decode_YFSFid(&bp, &op->file[1].fid);
524 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
525 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
526 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
527 xdr_decode_YFSVolSync(&bp, &op->volsync);
528
529 _leave(" = 0 [done]");
530 return 0;
531 }
532
533 /*
534 * FS.CreateFile and FS.MakeDir operation type
535 */
536 static const struct afs_call_type afs_RXFSCreateFile = {
537 .name = "YFS.CreateFile",
538 .op = yfs_FS_CreateFile,
539 .deliver = yfs_deliver_fs_create_vnode,
540 .destructor = afs_flat_call_destructor,
541 };
542
543 /*
544 * Create a file.
545 */
yfs_fs_create_file(struct afs_operation * op)546 void yfs_fs_create_file(struct afs_operation *op)
547 {
548 const struct qstr *name = &op->dentry->d_name;
549 struct afs_vnode_param *dvp = &op->file[0];
550 struct afs_call *call;
551 size_t reqsz, rplsz;
552 __be32 *bp;
553
554 _enter("");
555
556 reqsz = (sizeof(__be32) +
557 sizeof(__be32) +
558 sizeof(struct yfs_xdr_YFSFid) +
559 xdr_strlen(name->len) +
560 sizeof(struct yfs_xdr_YFSStoreStatus) +
561 sizeof(__be32));
562 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
563 sizeof(struct yfs_xdr_YFSFetchStatus) +
564 sizeof(struct yfs_xdr_YFSFetchStatus) +
565 sizeof(struct yfs_xdr_YFSCallBack) +
566 sizeof(struct yfs_xdr_YFSVolSync));
567
568 call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
569 if (!call)
570 return afs_op_nomem(op);
571
572 /* marshall the parameters */
573 bp = call->request;
574 bp = xdr_encode_u32(bp, YFSCREATEFILE);
575 bp = xdr_encode_u32(bp, 0); /* RPC flags */
576 bp = xdr_encode_YFSFid(bp, &dvp->fid);
577 bp = xdr_encode_name(bp, name);
578 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
579 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
580 yfs_check_req(call, bp);
581
582 trace_afs_make_fs_call1(call, &dvp->fid, name);
583 afs_make_op_call(op, call, GFP_NOFS);
584 }
585
586 static const struct afs_call_type yfs_RXFSMakeDir = {
587 .name = "YFS.MakeDir",
588 .op = yfs_FS_MakeDir,
589 .deliver = yfs_deliver_fs_create_vnode,
590 .destructor = afs_flat_call_destructor,
591 };
592
593 /*
594 * Make a directory.
595 */
yfs_fs_make_dir(struct afs_operation * op)596 void yfs_fs_make_dir(struct afs_operation *op)
597 {
598 const struct qstr *name = &op->dentry->d_name;
599 struct afs_vnode_param *dvp = &op->file[0];
600 struct afs_call *call;
601 size_t reqsz, rplsz;
602 __be32 *bp;
603
604 _enter("");
605
606 reqsz = (sizeof(__be32) +
607 sizeof(struct yfs_xdr_RPCFlags) +
608 sizeof(struct yfs_xdr_YFSFid) +
609 xdr_strlen(name->len) +
610 sizeof(struct yfs_xdr_YFSStoreStatus));
611 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
612 sizeof(struct yfs_xdr_YFSFetchStatus) +
613 sizeof(struct yfs_xdr_YFSFetchStatus) +
614 sizeof(struct yfs_xdr_YFSCallBack) +
615 sizeof(struct yfs_xdr_YFSVolSync));
616
617 call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
618 if (!call)
619 return afs_op_nomem(op);
620
621 /* marshall the parameters */
622 bp = call->request;
623 bp = xdr_encode_u32(bp, YFSMAKEDIR);
624 bp = xdr_encode_u32(bp, 0); /* RPC flags */
625 bp = xdr_encode_YFSFid(bp, &dvp->fid);
626 bp = xdr_encode_name(bp, name);
627 bp = xdr_encode_YFSStoreStatus_mode(bp, op->create.mode);
628 yfs_check_req(call, bp);
629
630 trace_afs_make_fs_call1(call, &dvp->fid, name);
631 afs_make_op_call(op, call, GFP_NOFS);
632 }
633
634 /*
635 * Deliver reply data to a YFS.RemoveFile2 operation.
636 */
yfs_deliver_fs_remove_file2(struct afs_call * call)637 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
638 {
639 struct afs_operation *op = call->op;
640 struct afs_vnode_param *dvp = &op->file[0];
641 struct afs_vnode_param *vp = &op->file[1];
642 struct afs_fid fid;
643 const __be32 *bp;
644 int ret;
645
646 _enter("{%u}", call->unmarshall);
647
648 ret = afs_transfer_reply(call);
649 if (ret < 0)
650 return ret;
651
652 bp = call->buffer;
653 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
654 xdr_decode_YFSFid(&bp, &fid);
655 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
656 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
657
658 xdr_decode_YFSVolSync(&bp, &op->volsync);
659 return 0;
660 }
661
yfs_done_fs_remove_file2(struct afs_call * call)662 static void yfs_done_fs_remove_file2(struct afs_call *call)
663 {
664 if (call->error == -ECONNABORTED &&
665 call->abort_code == RX_INVALID_OPERATION) {
666 set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
667 call->op->flags |= AFS_OPERATION_DOWNGRADE;
668 }
669 }
670
671 /*
672 * YFS.RemoveFile2 operation type.
673 */
674 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
675 .name = "YFS.RemoveFile2",
676 .op = yfs_FS_RemoveFile2,
677 .deliver = yfs_deliver_fs_remove_file2,
678 .done = yfs_done_fs_remove_file2,
679 .destructor = afs_flat_call_destructor,
680 };
681
682 /*
683 * Remove a file and retrieve new file status.
684 */
yfs_fs_remove_file2(struct afs_operation * op)685 void yfs_fs_remove_file2(struct afs_operation *op)
686 {
687 struct afs_vnode_param *dvp = &op->file[0];
688 const struct qstr *name = &op->dentry->d_name;
689 struct afs_call *call;
690 __be32 *bp;
691
692 _enter("");
693
694 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
695 sizeof(__be32) +
696 sizeof(struct yfs_xdr_RPCFlags) +
697 sizeof(struct yfs_xdr_YFSFid) +
698 xdr_strlen(name->len),
699 sizeof(struct yfs_xdr_YFSFetchStatus) +
700 sizeof(struct yfs_xdr_YFSFid) +
701 sizeof(struct yfs_xdr_YFSFetchStatus) +
702 sizeof(struct yfs_xdr_YFSVolSync));
703 if (!call)
704 return afs_op_nomem(op);
705
706 /* marshall the parameters */
707 bp = call->request;
708 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
709 bp = xdr_encode_u32(bp, 0); /* RPC flags */
710 bp = xdr_encode_YFSFid(bp, &dvp->fid);
711 bp = xdr_encode_name(bp, name);
712 yfs_check_req(call, bp);
713
714 trace_afs_make_fs_call1(call, &dvp->fid, name);
715 afs_make_op_call(op, call, GFP_NOFS);
716 }
717
718 /*
719 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
720 */
yfs_deliver_fs_remove(struct afs_call * call)721 static int yfs_deliver_fs_remove(struct afs_call *call)
722 {
723 struct afs_operation *op = call->op;
724 struct afs_vnode_param *dvp = &op->file[0];
725 const __be32 *bp;
726 int ret;
727
728 _enter("{%u}", call->unmarshall);
729
730 ret = afs_transfer_reply(call);
731 if (ret < 0)
732 return ret;
733
734 bp = call->buffer;
735 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
736 xdr_decode_YFSVolSync(&bp, &op->volsync);
737 return 0;
738 }
739
740 /*
741 * FS.RemoveDir and FS.RemoveFile operation types.
742 */
743 static const struct afs_call_type yfs_RXYFSRemoveFile = {
744 .name = "YFS.RemoveFile",
745 .op = yfs_FS_RemoveFile,
746 .deliver = yfs_deliver_fs_remove,
747 .destructor = afs_flat_call_destructor,
748 };
749
750 /*
751 * Remove a file.
752 */
yfs_fs_remove_file(struct afs_operation * op)753 void yfs_fs_remove_file(struct afs_operation *op)
754 {
755 const struct qstr *name = &op->dentry->d_name;
756 struct afs_vnode_param *dvp = &op->file[0];
757 struct afs_call *call;
758 __be32 *bp;
759
760 _enter("");
761
762 if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
763 return yfs_fs_remove_file2(op);
764
765 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
766 sizeof(__be32) +
767 sizeof(struct yfs_xdr_RPCFlags) +
768 sizeof(struct yfs_xdr_YFSFid) +
769 xdr_strlen(name->len),
770 sizeof(struct yfs_xdr_YFSFetchStatus) +
771 sizeof(struct yfs_xdr_YFSVolSync));
772 if (!call)
773 return afs_op_nomem(op);
774
775 /* marshall the parameters */
776 bp = call->request;
777 bp = xdr_encode_u32(bp, YFSREMOVEFILE);
778 bp = xdr_encode_u32(bp, 0); /* RPC flags */
779 bp = xdr_encode_YFSFid(bp, &dvp->fid);
780 bp = xdr_encode_name(bp, name);
781 yfs_check_req(call, bp);
782
783 trace_afs_make_fs_call1(call, &dvp->fid, name);
784 afs_make_op_call(op, call, GFP_NOFS);
785 }
786
787 static const struct afs_call_type yfs_RXYFSRemoveDir = {
788 .name = "YFS.RemoveDir",
789 .op = yfs_FS_RemoveDir,
790 .deliver = yfs_deliver_fs_remove,
791 .destructor = afs_flat_call_destructor,
792 };
793
794 /*
795 * Remove a directory.
796 */
yfs_fs_remove_dir(struct afs_operation * op)797 void yfs_fs_remove_dir(struct afs_operation *op)
798 {
799 const struct qstr *name = &op->dentry->d_name;
800 struct afs_vnode_param *dvp = &op->file[0];
801 struct afs_call *call;
802 __be32 *bp;
803
804 _enter("");
805
806 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
807 sizeof(__be32) +
808 sizeof(struct yfs_xdr_RPCFlags) +
809 sizeof(struct yfs_xdr_YFSFid) +
810 xdr_strlen(name->len),
811 sizeof(struct yfs_xdr_YFSFetchStatus) +
812 sizeof(struct yfs_xdr_YFSVolSync));
813 if (!call)
814 return afs_op_nomem(op);
815
816 /* marshall the parameters */
817 bp = call->request;
818 bp = xdr_encode_u32(bp, YFSREMOVEDIR);
819 bp = xdr_encode_u32(bp, 0); /* RPC flags */
820 bp = xdr_encode_YFSFid(bp, &dvp->fid);
821 bp = xdr_encode_name(bp, name);
822 yfs_check_req(call, bp);
823
824 trace_afs_make_fs_call1(call, &dvp->fid, name);
825 afs_make_op_call(op, call, GFP_NOFS);
826 }
827
828 /*
829 * Deliver reply data to a YFS.Link operation.
830 */
yfs_deliver_fs_link(struct afs_call * call)831 static int yfs_deliver_fs_link(struct afs_call *call)
832 {
833 struct afs_operation *op = call->op;
834 struct afs_vnode_param *dvp = &op->file[0];
835 struct afs_vnode_param *vp = &op->file[1];
836 const __be32 *bp;
837 int ret;
838
839 _enter("{%u}", call->unmarshall);
840
841 ret = afs_transfer_reply(call);
842 if (ret < 0)
843 return ret;
844
845 bp = call->buffer;
846 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
847 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
848 xdr_decode_YFSVolSync(&bp, &op->volsync);
849 _leave(" = 0 [done]");
850 return 0;
851 }
852
853 /*
854 * YFS.Link operation type.
855 */
856 static const struct afs_call_type yfs_RXYFSLink = {
857 .name = "YFS.Link",
858 .op = yfs_FS_Link,
859 .deliver = yfs_deliver_fs_link,
860 .destructor = afs_flat_call_destructor,
861 };
862
863 /*
864 * Make a hard link.
865 */
yfs_fs_link(struct afs_operation * op)866 void yfs_fs_link(struct afs_operation *op)
867 {
868 const struct qstr *name = &op->dentry->d_name;
869 struct afs_vnode_param *dvp = &op->file[0];
870 struct afs_vnode_param *vp = &op->file[1];
871 struct afs_call *call;
872 __be32 *bp;
873
874 _enter("");
875
876 call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
877 sizeof(__be32) +
878 sizeof(struct yfs_xdr_RPCFlags) +
879 sizeof(struct yfs_xdr_YFSFid) +
880 xdr_strlen(name->len) +
881 sizeof(struct yfs_xdr_YFSFid),
882 sizeof(struct yfs_xdr_YFSFetchStatus) +
883 sizeof(struct yfs_xdr_YFSFetchStatus) +
884 sizeof(struct yfs_xdr_YFSVolSync));
885 if (!call)
886 return afs_op_nomem(op);
887
888 /* marshall the parameters */
889 bp = call->request;
890 bp = xdr_encode_u32(bp, YFSLINK);
891 bp = xdr_encode_u32(bp, 0); /* RPC flags */
892 bp = xdr_encode_YFSFid(bp, &dvp->fid);
893 bp = xdr_encode_name(bp, name);
894 bp = xdr_encode_YFSFid(bp, &vp->fid);
895 yfs_check_req(call, bp);
896
897 trace_afs_make_fs_call1(call, &vp->fid, name);
898 afs_make_op_call(op, call, GFP_NOFS);
899 }
900
901 /*
902 * Deliver reply data to a YFS.Symlink operation.
903 */
yfs_deliver_fs_symlink(struct afs_call * call)904 static int yfs_deliver_fs_symlink(struct afs_call *call)
905 {
906 struct afs_operation *op = call->op;
907 struct afs_vnode_param *dvp = &op->file[0];
908 struct afs_vnode_param *vp = &op->file[1];
909 const __be32 *bp;
910 int ret;
911
912 _enter("{%u}", call->unmarshall);
913
914 ret = afs_transfer_reply(call);
915 if (ret < 0)
916 return ret;
917
918 /* unmarshall the reply once we've received all of it */
919 bp = call->buffer;
920 xdr_decode_YFSFid(&bp, &vp->fid);
921 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
922 xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
923 xdr_decode_YFSVolSync(&bp, &op->volsync);
924
925 _leave(" = 0 [done]");
926 return 0;
927 }
928
929 /*
930 * YFS.Symlink operation type
931 */
932 static const struct afs_call_type yfs_RXYFSSymlink = {
933 .name = "YFS.Symlink",
934 .op = yfs_FS_Symlink,
935 .deliver = yfs_deliver_fs_symlink,
936 .destructor = afs_flat_call_destructor,
937 };
938
939 /*
940 * Create a symbolic link.
941 */
yfs_fs_symlink(struct afs_operation * op)942 void yfs_fs_symlink(struct afs_operation *op)
943 {
944 const struct qstr *name = &op->dentry->d_name;
945 struct afs_vnode_param *dvp = &op->file[0];
946 struct afs_call *call;
947 size_t contents_sz;
948 __be32 *bp;
949
950 _enter("");
951
952 contents_sz = strlen(op->create.symlink);
953 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
954 sizeof(__be32) +
955 sizeof(struct yfs_xdr_RPCFlags) +
956 sizeof(struct yfs_xdr_YFSFid) +
957 xdr_strlen(name->len) +
958 xdr_strlen(contents_sz) +
959 sizeof(struct yfs_xdr_YFSStoreStatus),
960 sizeof(struct yfs_xdr_YFSFid) +
961 sizeof(struct yfs_xdr_YFSFetchStatus) +
962 sizeof(struct yfs_xdr_YFSFetchStatus) +
963 sizeof(struct yfs_xdr_YFSVolSync));
964 if (!call)
965 return afs_op_nomem(op);
966
967 /* marshall the parameters */
968 bp = call->request;
969 bp = xdr_encode_u32(bp, YFSSYMLINK);
970 bp = xdr_encode_u32(bp, 0); /* RPC flags */
971 bp = xdr_encode_YFSFid(bp, &dvp->fid);
972 bp = xdr_encode_name(bp, name);
973 bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
974 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
975 yfs_check_req(call, bp);
976
977 trace_afs_make_fs_call1(call, &dvp->fid, name);
978 afs_make_op_call(op, call, GFP_NOFS);
979 }
980
981 /*
982 * Deliver reply data to a YFS.Rename operation.
983 */
yfs_deliver_fs_rename(struct afs_call * call)984 static int yfs_deliver_fs_rename(struct afs_call *call)
985 {
986 struct afs_operation *op = call->op;
987 struct afs_vnode_param *orig_dvp = &op->file[0];
988 struct afs_vnode_param *new_dvp = &op->file[1];
989 const __be32 *bp;
990 int ret;
991
992 _enter("{%u}", call->unmarshall);
993
994 ret = afs_transfer_reply(call);
995 if (ret < 0)
996 return ret;
997
998 bp = call->buffer;
999 /* If the two dirs are the same, we have two copies of the same status
1000 * report, so we just decode it twice.
1001 */
1002 xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
1003 xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
1004 xdr_decode_YFSVolSync(&bp, &op->volsync);
1005 _leave(" = 0 [done]");
1006 return 0;
1007 }
1008
1009 /*
1010 * YFS.Rename operation type
1011 */
1012 static const struct afs_call_type yfs_RXYFSRename = {
1013 .name = "FS.Rename",
1014 .op = yfs_FS_Rename,
1015 .deliver = yfs_deliver_fs_rename,
1016 .destructor = afs_flat_call_destructor,
1017 };
1018
1019 /*
1020 * Rename a file or directory.
1021 */
yfs_fs_rename(struct afs_operation * op)1022 void yfs_fs_rename(struct afs_operation *op)
1023 {
1024 struct afs_vnode_param *orig_dvp = &op->file[0];
1025 struct afs_vnode_param *new_dvp = &op->file[1];
1026 const struct qstr *orig_name = &op->dentry->d_name;
1027 const struct qstr *new_name = &op->dentry_2->d_name;
1028 struct afs_call *call;
1029 __be32 *bp;
1030
1031 _enter("");
1032
1033 call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
1034 sizeof(__be32) +
1035 sizeof(struct yfs_xdr_RPCFlags) +
1036 sizeof(struct yfs_xdr_YFSFid) +
1037 xdr_strlen(orig_name->len) +
1038 sizeof(struct yfs_xdr_YFSFid) +
1039 xdr_strlen(new_name->len),
1040 sizeof(struct yfs_xdr_YFSFetchStatus) +
1041 sizeof(struct yfs_xdr_YFSFetchStatus) +
1042 sizeof(struct yfs_xdr_YFSVolSync));
1043 if (!call)
1044 return afs_op_nomem(op);
1045
1046 /* marshall the parameters */
1047 bp = call->request;
1048 bp = xdr_encode_u32(bp, YFSRENAME);
1049 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1050 bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
1051 bp = xdr_encode_name(bp, orig_name);
1052 bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
1053 bp = xdr_encode_name(bp, new_name);
1054 yfs_check_req(call, bp);
1055
1056 trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
1057 afs_make_op_call(op, call, GFP_NOFS);
1058 }
1059
1060 /*
1061 * YFS.StoreData64 operation type.
1062 */
1063 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1064 .name = "YFS.StoreData64",
1065 .op = yfs_FS_StoreData64,
1066 .deliver = yfs_deliver_status_and_volsync,
1067 .destructor = afs_flat_call_destructor,
1068 };
1069
1070 /*
1071 * Store a set of pages to a large file.
1072 */
yfs_fs_store_data(struct afs_operation * op)1073 void yfs_fs_store_data(struct afs_operation *op)
1074 {
1075 struct afs_vnode_param *vp = &op->file[0];
1076 struct afs_call *call;
1077 __be32 *bp;
1078
1079 _enter(",%x,{%llx:%llu},,",
1080 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1081
1082 _debug("size %llx, at %llx, i_size %llx",
1083 (unsigned long long)op->store.size,
1084 (unsigned long long)op->store.pos,
1085 (unsigned long long)op->store.i_size);
1086
1087 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
1088 sizeof(__be32) +
1089 sizeof(__be32) +
1090 sizeof(struct yfs_xdr_YFSFid) +
1091 sizeof(struct yfs_xdr_YFSStoreStatus) +
1092 sizeof(struct yfs_xdr_u64) * 3,
1093 sizeof(struct yfs_xdr_YFSFetchStatus) +
1094 sizeof(struct yfs_xdr_YFSVolSync));
1095 if (!call)
1096 return afs_op_nomem(op);
1097
1098 call->write_iter = op->store.write_iter;
1099
1100 /* marshall the parameters */
1101 bp = call->request;
1102 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1103 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1104 bp = xdr_encode_YFSFid(bp, &vp->fid);
1105 bp = xdr_encode_YFSStoreStatus_mtime(bp, &op->mtime);
1106 bp = xdr_encode_u64(bp, op->store.pos);
1107 bp = xdr_encode_u64(bp, op->store.size);
1108 bp = xdr_encode_u64(bp, op->store.i_size);
1109 yfs_check_req(call, bp);
1110
1111 trace_afs_make_fs_call(call, &vp->fid);
1112 afs_make_op_call(op, call, GFP_NOFS);
1113 }
1114
1115 /*
1116 * YFS.StoreStatus operation type
1117 */
1118 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1119 .name = "YFS.StoreStatus",
1120 .op = yfs_FS_StoreStatus,
1121 .deliver = yfs_deliver_status_and_volsync,
1122 .destructor = afs_flat_call_destructor,
1123 };
1124
1125 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1126 .name = "YFS.StoreData64",
1127 .op = yfs_FS_StoreData64,
1128 .deliver = yfs_deliver_status_and_volsync,
1129 .destructor = afs_flat_call_destructor,
1130 };
1131
1132 /*
1133 * Set the attributes on a file, using YFS.StoreData64 rather than
1134 * YFS.StoreStatus so as to alter the file size also.
1135 */
yfs_fs_setattr_size(struct afs_operation * op)1136 static void yfs_fs_setattr_size(struct afs_operation *op)
1137 {
1138 struct afs_vnode_param *vp = &op->file[0];
1139 struct afs_call *call;
1140 struct iattr *attr = op->setattr.attr;
1141 __be32 *bp;
1142
1143 _enter(",%x,{%llx:%llu},,",
1144 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1145
1146 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
1147 sizeof(__be32) * 2 +
1148 sizeof(struct yfs_xdr_YFSFid) +
1149 sizeof(struct yfs_xdr_YFSStoreStatus) +
1150 sizeof(struct yfs_xdr_u64) * 3,
1151 sizeof(struct yfs_xdr_YFSFetchStatus) +
1152 sizeof(struct yfs_xdr_YFSVolSync));
1153 if (!call)
1154 return afs_op_nomem(op);
1155
1156 /* marshall the parameters */
1157 bp = call->request;
1158 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1159 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1160 bp = xdr_encode_YFSFid(bp, &vp->fid);
1161 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1162 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1163 bp = xdr_encode_u64(bp, 0); /* size of write */
1164 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1165 yfs_check_req(call, bp);
1166
1167 trace_afs_make_fs_call(call, &vp->fid);
1168 afs_make_op_call(op, call, GFP_NOFS);
1169 }
1170
1171 /*
1172 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1173 * file size, and YFS.StoreStatus otherwise.
1174 */
yfs_fs_setattr(struct afs_operation * op)1175 void yfs_fs_setattr(struct afs_operation *op)
1176 {
1177 struct afs_vnode_param *vp = &op->file[0];
1178 struct afs_call *call;
1179 struct iattr *attr = op->setattr.attr;
1180 __be32 *bp;
1181
1182 if (attr->ia_valid & ATTR_SIZE)
1183 return yfs_fs_setattr_size(op);
1184
1185 _enter(",%x,{%llx:%llu},,",
1186 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1187
1188 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
1189 sizeof(__be32) * 2 +
1190 sizeof(struct yfs_xdr_YFSFid) +
1191 sizeof(struct yfs_xdr_YFSStoreStatus),
1192 sizeof(struct yfs_xdr_YFSFetchStatus) +
1193 sizeof(struct yfs_xdr_YFSVolSync));
1194 if (!call)
1195 return afs_op_nomem(op);
1196
1197 /* marshall the parameters */
1198 bp = call->request;
1199 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1200 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1201 bp = xdr_encode_YFSFid(bp, &vp->fid);
1202 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1203 yfs_check_req(call, bp);
1204
1205 trace_afs_make_fs_call(call, &vp->fid);
1206 afs_make_op_call(op, call, GFP_NOFS);
1207 }
1208
1209 /*
1210 * Deliver reply data to a YFS.GetVolumeStatus operation.
1211 */
yfs_deliver_fs_get_volume_status(struct afs_call * call)1212 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1213 {
1214 struct afs_operation *op = call->op;
1215 const __be32 *bp;
1216 char *p;
1217 u32 size;
1218 int ret;
1219
1220 _enter("{%u}", call->unmarshall);
1221
1222 switch (call->unmarshall) {
1223 case 0:
1224 call->unmarshall++;
1225 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1226 fallthrough;
1227
1228 /* extract the returned status record */
1229 case 1:
1230 _debug("extract status");
1231 ret = afs_extract_data(call, true);
1232 if (ret < 0)
1233 return ret;
1234
1235 bp = call->buffer;
1236 xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
1237 call->unmarshall++;
1238 afs_extract_to_tmp(call);
1239 fallthrough;
1240
1241 /* extract the volume name length */
1242 case 2:
1243 ret = afs_extract_data(call, true);
1244 if (ret < 0)
1245 return ret;
1246
1247 call->count = ntohl(call->tmp);
1248 _debug("volname length: %u", call->count);
1249 if (call->count >= AFSNAMEMAX)
1250 return afs_protocol_error(call, afs_eproto_volname_len);
1251 size = (call->count + 3) & ~3; /* It's padded */
1252 afs_extract_to_buf(call, size);
1253 call->unmarshall++;
1254 fallthrough;
1255
1256 /* extract the volume name */
1257 case 3:
1258 _debug("extract volname");
1259 ret = afs_extract_data(call, true);
1260 if (ret < 0)
1261 return ret;
1262
1263 p = call->buffer;
1264 p[call->count] = 0;
1265 _debug("volname '%s'", p);
1266 afs_extract_to_tmp(call);
1267 call->unmarshall++;
1268 fallthrough;
1269
1270 /* extract the offline message length */
1271 case 4:
1272 ret = afs_extract_data(call, true);
1273 if (ret < 0)
1274 return ret;
1275
1276 call->count = ntohl(call->tmp);
1277 _debug("offline msg length: %u", call->count);
1278 if (call->count >= AFSNAMEMAX)
1279 return afs_protocol_error(call, afs_eproto_offline_msg_len);
1280 size = (call->count + 3) & ~3; /* It's padded */
1281 afs_extract_to_buf(call, size);
1282 call->unmarshall++;
1283 fallthrough;
1284
1285 /* extract the offline message */
1286 case 5:
1287 _debug("extract offline");
1288 ret = afs_extract_data(call, true);
1289 if (ret < 0)
1290 return ret;
1291
1292 p = call->buffer;
1293 p[call->count] = 0;
1294 _debug("offline '%s'", p);
1295
1296 afs_extract_to_tmp(call);
1297 call->unmarshall++;
1298 fallthrough;
1299
1300 /* extract the message of the day length */
1301 case 6:
1302 ret = afs_extract_data(call, true);
1303 if (ret < 0)
1304 return ret;
1305
1306 call->count = ntohl(call->tmp);
1307 _debug("motd length: %u", call->count);
1308 if (call->count >= AFSNAMEMAX)
1309 return afs_protocol_error(call, afs_eproto_motd_len);
1310 size = (call->count + 3) & ~3; /* It's padded */
1311 afs_extract_to_buf(call, size);
1312 call->unmarshall++;
1313 fallthrough;
1314
1315 /* extract the message of the day */
1316 case 7:
1317 _debug("extract motd");
1318 ret = afs_extract_data(call, false);
1319 if (ret < 0)
1320 return ret;
1321
1322 p = call->buffer;
1323 p[call->count] = 0;
1324 _debug("motd '%s'", p);
1325
1326 call->unmarshall++;
1327 fallthrough;
1328
1329 case 8:
1330 break;
1331 }
1332
1333 _leave(" = 0 [done]");
1334 return 0;
1335 }
1336
1337 /*
1338 * YFS.GetVolumeStatus operation type
1339 */
1340 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1341 .name = "YFS.GetVolumeStatus",
1342 .op = yfs_FS_GetVolumeStatus,
1343 .deliver = yfs_deliver_fs_get_volume_status,
1344 .destructor = afs_flat_call_destructor,
1345 };
1346
1347 /*
1348 * fetch the status of a volume
1349 */
yfs_fs_get_volume_status(struct afs_operation * op)1350 void yfs_fs_get_volume_status(struct afs_operation *op)
1351 {
1352 struct afs_vnode_param *vp = &op->file[0];
1353 struct afs_call *call;
1354 __be32 *bp;
1355
1356 _enter("");
1357
1358 call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
1359 sizeof(__be32) * 2 +
1360 sizeof(struct yfs_xdr_u64),
1361 max_t(size_t,
1362 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1363 sizeof(__be32),
1364 AFSOPAQUEMAX + 1));
1365 if (!call)
1366 return afs_op_nomem(op);
1367
1368 /* marshall the parameters */
1369 bp = call->request;
1370 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1371 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1372 bp = xdr_encode_u64(bp, vp->fid.vid);
1373 yfs_check_req(call, bp);
1374
1375 trace_afs_make_fs_call(call, &vp->fid);
1376 afs_make_op_call(op, call, GFP_NOFS);
1377 }
1378
1379 /*
1380 * YFS.SetLock operation type
1381 */
1382 static const struct afs_call_type yfs_RXYFSSetLock = {
1383 .name = "YFS.SetLock",
1384 .op = yfs_FS_SetLock,
1385 .deliver = yfs_deliver_status_and_volsync,
1386 .done = afs_lock_op_done,
1387 .destructor = afs_flat_call_destructor,
1388 };
1389
1390 /*
1391 * YFS.ExtendLock operation type
1392 */
1393 static const struct afs_call_type yfs_RXYFSExtendLock = {
1394 .name = "YFS.ExtendLock",
1395 .op = yfs_FS_ExtendLock,
1396 .deliver = yfs_deliver_status_and_volsync,
1397 .done = afs_lock_op_done,
1398 .destructor = afs_flat_call_destructor,
1399 };
1400
1401 /*
1402 * YFS.ReleaseLock operation type
1403 */
1404 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1405 .name = "YFS.ReleaseLock",
1406 .op = yfs_FS_ReleaseLock,
1407 .deliver = yfs_deliver_status_and_volsync,
1408 .destructor = afs_flat_call_destructor,
1409 };
1410
1411 /*
1412 * Set a lock on a file
1413 */
yfs_fs_set_lock(struct afs_operation * op)1414 void yfs_fs_set_lock(struct afs_operation *op)
1415 {
1416 struct afs_vnode_param *vp = &op->file[0];
1417 struct afs_call *call;
1418 __be32 *bp;
1419
1420 _enter("");
1421
1422 call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
1423 sizeof(__be32) * 2 +
1424 sizeof(struct yfs_xdr_YFSFid) +
1425 sizeof(__be32),
1426 sizeof(struct yfs_xdr_YFSFetchStatus) +
1427 sizeof(struct yfs_xdr_YFSVolSync));
1428 if (!call)
1429 return afs_op_nomem(op);
1430
1431 /* marshall the parameters */
1432 bp = call->request;
1433 bp = xdr_encode_u32(bp, YFSSETLOCK);
1434 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1435 bp = xdr_encode_YFSFid(bp, &vp->fid);
1436 bp = xdr_encode_u32(bp, op->lock.type);
1437 yfs_check_req(call, bp);
1438
1439 trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
1440 afs_make_op_call(op, call, GFP_NOFS);
1441 }
1442
1443 /*
1444 * extend a lock on a file
1445 */
yfs_fs_extend_lock(struct afs_operation * op)1446 void yfs_fs_extend_lock(struct afs_operation *op)
1447 {
1448 struct afs_vnode_param *vp = &op->file[0];
1449 struct afs_call *call;
1450 __be32 *bp;
1451
1452 _enter("");
1453
1454 call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
1455 sizeof(__be32) * 2 +
1456 sizeof(struct yfs_xdr_YFSFid),
1457 sizeof(struct yfs_xdr_YFSFetchStatus) +
1458 sizeof(struct yfs_xdr_YFSVolSync));
1459 if (!call)
1460 return afs_op_nomem(op);
1461
1462 /* marshall the parameters */
1463 bp = call->request;
1464 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1465 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1466 bp = xdr_encode_YFSFid(bp, &vp->fid);
1467 yfs_check_req(call, bp);
1468
1469 trace_afs_make_fs_call(call, &vp->fid);
1470 afs_make_op_call(op, call, GFP_NOFS);
1471 }
1472
1473 /*
1474 * release a lock on a file
1475 */
yfs_fs_release_lock(struct afs_operation * op)1476 void yfs_fs_release_lock(struct afs_operation *op)
1477 {
1478 struct afs_vnode_param *vp = &op->file[0];
1479 struct afs_call *call;
1480 __be32 *bp;
1481
1482 _enter("");
1483
1484 call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
1485 sizeof(__be32) * 2 +
1486 sizeof(struct yfs_xdr_YFSFid),
1487 sizeof(struct yfs_xdr_YFSFetchStatus) +
1488 sizeof(struct yfs_xdr_YFSVolSync));
1489 if (!call)
1490 return afs_op_nomem(op);
1491
1492 /* marshall the parameters */
1493 bp = call->request;
1494 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1495 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1496 bp = xdr_encode_YFSFid(bp, &vp->fid);
1497 yfs_check_req(call, bp);
1498
1499 trace_afs_make_fs_call(call, &vp->fid);
1500 afs_make_op_call(op, call, GFP_NOFS);
1501 }
1502
1503 /*
1504 * Deliver a reply to YFS.FetchStatus
1505 */
yfs_deliver_fs_fetch_status(struct afs_call * call)1506 static int yfs_deliver_fs_fetch_status(struct afs_call *call)
1507 {
1508 struct afs_operation *op = call->op;
1509 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1510 const __be32 *bp;
1511 int ret;
1512
1513 ret = afs_transfer_reply(call);
1514 if (ret < 0)
1515 return ret;
1516
1517 /* unmarshall the reply once we've received all of it */
1518 bp = call->buffer;
1519 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1520 xdr_decode_YFSCallBack(&bp, call, &vp->scb);
1521 xdr_decode_YFSVolSync(&bp, &op->volsync);
1522
1523 _leave(" = 0 [done]");
1524 return 0;
1525 }
1526
1527 /*
1528 * YFS.FetchStatus operation type
1529 */
1530 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1531 .name = "YFS.FetchStatus",
1532 .op = yfs_FS_FetchStatus,
1533 .deliver = yfs_deliver_fs_fetch_status,
1534 .destructor = afs_flat_call_destructor,
1535 };
1536
1537 /*
1538 * Fetch the status information for a fid without needing a vnode handle.
1539 */
yfs_fs_fetch_status(struct afs_operation * op)1540 void yfs_fs_fetch_status(struct afs_operation *op)
1541 {
1542 struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
1543 struct afs_call *call;
1544 __be32 *bp;
1545
1546 _enter(",%x,{%llx:%llu},,",
1547 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1548
1549 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
1550 sizeof(__be32) * 2 +
1551 sizeof(struct yfs_xdr_YFSFid),
1552 sizeof(struct yfs_xdr_YFSFetchStatus) +
1553 sizeof(struct yfs_xdr_YFSCallBack) +
1554 sizeof(struct yfs_xdr_YFSVolSync));
1555 if (!call)
1556 return afs_op_nomem(op);
1557
1558 /* marshall the parameters */
1559 bp = call->request;
1560 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1561 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1562 bp = xdr_encode_YFSFid(bp, &vp->fid);
1563 yfs_check_req(call, bp);
1564
1565 trace_afs_make_fs_call(call, &vp->fid);
1566 afs_make_op_call(op, call, GFP_NOFS);
1567 }
1568
1569 /*
1570 * Deliver reply data to an YFS.InlineBulkStatus call
1571 */
yfs_deliver_fs_inline_bulk_status(struct afs_call * call)1572 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1573 {
1574 struct afs_operation *op = call->op;
1575 struct afs_status_cb *scb;
1576 const __be32 *bp;
1577 u32 tmp;
1578 int ret;
1579
1580 _enter("{%u}", call->unmarshall);
1581
1582 switch (call->unmarshall) {
1583 case 0:
1584 afs_extract_to_tmp(call);
1585 call->unmarshall++;
1586 fallthrough;
1587
1588 /* Extract the file status count and array in two steps */
1589 case 1:
1590 _debug("extract status count");
1591 ret = afs_extract_data(call, true);
1592 if (ret < 0)
1593 return ret;
1594
1595 tmp = ntohl(call->tmp);
1596 _debug("status count: %u/%u", tmp, op->nr_files);
1597 if (tmp != op->nr_files)
1598 return afs_protocol_error(call, afs_eproto_ibulkst_count);
1599
1600 call->count = 0;
1601 call->unmarshall++;
1602 more_counts:
1603 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
1604 fallthrough;
1605
1606 case 2:
1607 _debug("extract status array %u", call->count);
1608 ret = afs_extract_data(call, true);
1609 if (ret < 0)
1610 return ret;
1611
1612 switch (call->count) {
1613 case 0:
1614 scb = &op->file[0].scb;
1615 break;
1616 case 1:
1617 scb = &op->file[1].scb;
1618 break;
1619 default:
1620 scb = &op->more_files[call->count - 2].scb;
1621 break;
1622 }
1623
1624 bp = call->buffer;
1625 xdr_decode_YFSFetchStatus(&bp, call, scb);
1626
1627 call->count++;
1628 if (call->count < op->nr_files)
1629 goto more_counts;
1630
1631 call->count = 0;
1632 call->unmarshall++;
1633 afs_extract_to_tmp(call);
1634 fallthrough;
1635
1636 /* Extract the callback count and array in two steps */
1637 case 3:
1638 _debug("extract CB count");
1639 ret = afs_extract_data(call, true);
1640 if (ret < 0)
1641 return ret;
1642
1643 tmp = ntohl(call->tmp);
1644 _debug("CB count: %u", tmp);
1645 if (tmp != op->nr_files)
1646 return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
1647 call->count = 0;
1648 call->unmarshall++;
1649 more_cbs:
1650 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
1651 fallthrough;
1652
1653 case 4:
1654 _debug("extract CB array");
1655 ret = afs_extract_data(call, true);
1656 if (ret < 0)
1657 return ret;
1658
1659 _debug("unmarshall CB array");
1660 switch (call->count) {
1661 case 0:
1662 scb = &op->file[0].scb;
1663 break;
1664 case 1:
1665 scb = &op->file[1].scb;
1666 break;
1667 default:
1668 scb = &op->more_files[call->count - 2].scb;
1669 break;
1670 }
1671
1672 bp = call->buffer;
1673 xdr_decode_YFSCallBack(&bp, call, scb);
1674 call->count++;
1675 if (call->count < op->nr_files)
1676 goto more_cbs;
1677
1678 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1679 call->unmarshall++;
1680 fallthrough;
1681
1682 case 5:
1683 ret = afs_extract_data(call, false);
1684 if (ret < 0)
1685 return ret;
1686
1687 bp = call->buffer;
1688 xdr_decode_YFSVolSync(&bp, &op->volsync);
1689
1690 call->unmarshall++;
1691 fallthrough;
1692
1693 case 6:
1694 break;
1695 }
1696
1697 _leave(" = 0 [done]");
1698 return 0;
1699 }
1700
1701 /*
1702 * FS.InlineBulkStatus operation type
1703 */
1704 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1705 .name = "YFS.InlineBulkStatus",
1706 .op = yfs_FS_InlineBulkStatus,
1707 .deliver = yfs_deliver_fs_inline_bulk_status,
1708 .destructor = afs_flat_call_destructor,
1709 };
1710
1711 /*
1712 * Fetch the status information for up to 1024 files
1713 */
yfs_fs_inline_bulk_status(struct afs_operation * op)1714 void yfs_fs_inline_bulk_status(struct afs_operation *op)
1715 {
1716 struct afs_vnode_param *dvp = &op->file[0];
1717 struct afs_vnode_param *vp = &op->file[1];
1718 struct afs_call *call;
1719 __be32 *bp;
1720 int i;
1721
1722 _enter(",%x,{%llx:%llu},%u",
1723 key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
1724
1725 call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
1726 sizeof(__be32) +
1727 sizeof(__be32) +
1728 sizeof(__be32) +
1729 sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
1730 sizeof(struct yfs_xdr_YFSFetchStatus));
1731 if (!call)
1732 return afs_op_nomem(op);
1733
1734 /* marshall the parameters */
1735 bp = call->request;
1736 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1737 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
1738 bp = xdr_encode_u32(bp, op->nr_files);
1739 bp = xdr_encode_YFSFid(bp, &dvp->fid);
1740 bp = xdr_encode_YFSFid(bp, &vp->fid);
1741 for (i = 0; i < op->nr_files - 2; i++)
1742 bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
1743 yfs_check_req(call, bp);
1744
1745 trace_afs_make_fs_call(call, &vp->fid);
1746 afs_make_op_call(op, call, GFP_NOFS);
1747 }
1748
1749 /*
1750 * Deliver reply data to an YFS.FetchOpaqueACL.
1751 */
yfs_deliver_fs_fetch_opaque_acl(struct afs_call * call)1752 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1753 {
1754 struct afs_operation *op = call->op;
1755 struct afs_vnode_param *vp = &op->file[0];
1756 struct yfs_acl *yacl = op->yacl;
1757 struct afs_acl *acl;
1758 const __be32 *bp;
1759 unsigned int size;
1760 int ret;
1761
1762 _enter("{%u}", call->unmarshall);
1763
1764 switch (call->unmarshall) {
1765 case 0:
1766 afs_extract_to_tmp(call);
1767 call->unmarshall++;
1768 fallthrough;
1769
1770 /* Extract the file ACL length */
1771 case 1:
1772 ret = afs_extract_data(call, true);
1773 if (ret < 0)
1774 return ret;
1775
1776 size = call->count2 = ntohl(call->tmp);
1777 size = round_up(size, 4);
1778
1779 if (yacl->flags & YFS_ACL_WANT_ACL) {
1780 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1781 if (!acl)
1782 return -ENOMEM;
1783 yacl->acl = acl;
1784 acl->size = call->count2;
1785 afs_extract_begin(call, acl->data, size);
1786 } else {
1787 afs_extract_discard(call, size);
1788 }
1789 call->unmarshall++;
1790 fallthrough;
1791
1792 /* Extract the file ACL */
1793 case 2:
1794 ret = afs_extract_data(call, true);
1795 if (ret < 0)
1796 return ret;
1797
1798 afs_extract_to_tmp(call);
1799 call->unmarshall++;
1800 fallthrough;
1801
1802 /* Extract the volume ACL length */
1803 case 3:
1804 ret = afs_extract_data(call, true);
1805 if (ret < 0)
1806 return ret;
1807
1808 size = call->count2 = ntohl(call->tmp);
1809 size = round_up(size, 4);
1810
1811 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
1812 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1813 if (!acl)
1814 return -ENOMEM;
1815 yacl->vol_acl = acl;
1816 acl->size = call->count2;
1817 afs_extract_begin(call, acl->data, size);
1818 } else {
1819 afs_extract_discard(call, size);
1820 }
1821 call->unmarshall++;
1822 fallthrough;
1823
1824 /* Extract the volume ACL */
1825 case 4:
1826 ret = afs_extract_data(call, true);
1827 if (ret < 0)
1828 return ret;
1829
1830 afs_extract_to_buf(call,
1831 sizeof(__be32) * 2 +
1832 sizeof(struct yfs_xdr_YFSFetchStatus) +
1833 sizeof(struct yfs_xdr_YFSVolSync));
1834 call->unmarshall++;
1835 fallthrough;
1836
1837 /* extract the metadata */
1838 case 5:
1839 ret = afs_extract_data(call, false);
1840 if (ret < 0)
1841 return ret;
1842
1843 bp = call->buffer;
1844 yacl->inherit_flag = ntohl(*bp++);
1845 yacl->num_cleaned = ntohl(*bp++);
1846 xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
1847 xdr_decode_YFSVolSync(&bp, &op->volsync);
1848
1849 call->unmarshall++;
1850 fallthrough;
1851
1852 case 6:
1853 break;
1854 }
1855
1856 _leave(" = 0 [done]");
1857 return 0;
1858 }
1859
yfs_free_opaque_acl(struct yfs_acl * yacl)1860 void yfs_free_opaque_acl(struct yfs_acl *yacl)
1861 {
1862 if (yacl) {
1863 kfree(yacl->acl);
1864 kfree(yacl->vol_acl);
1865 kfree(yacl);
1866 }
1867 }
1868
1869 /*
1870 * YFS.FetchOpaqueACL operation type
1871 */
1872 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
1873 .name = "YFS.FetchOpaqueACL",
1874 .op = yfs_FS_FetchOpaqueACL,
1875 .deliver = yfs_deliver_fs_fetch_opaque_acl,
1876 .destructor = afs_flat_call_destructor,
1877 };
1878
1879 /*
1880 * Fetch the YFS advanced ACLs for a file.
1881 */
yfs_fs_fetch_opaque_acl(struct afs_operation * op)1882 void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
1883 {
1884 struct afs_vnode_param *vp = &op->file[0];
1885 struct afs_call *call;
1886 __be32 *bp;
1887
1888 _enter(",%x,{%llx:%llu},,",
1889 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1890
1891 call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
1892 sizeof(__be32) * 2 +
1893 sizeof(struct yfs_xdr_YFSFid),
1894 sizeof(__be32) * 2 +
1895 sizeof(struct yfs_xdr_YFSFetchStatus) +
1896 sizeof(struct yfs_xdr_YFSVolSync));
1897 if (!call)
1898 return afs_op_nomem(op);
1899
1900 /* marshall the parameters */
1901 bp = call->request;
1902 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
1903 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1904 bp = xdr_encode_YFSFid(bp, &vp->fid);
1905 yfs_check_req(call, bp);
1906
1907 trace_afs_make_fs_call(call, &vp->fid);
1908 afs_make_op_call(op, call, GFP_KERNEL);
1909 }
1910
1911 /*
1912 * YFS.StoreOpaqueACL2 operation type
1913 */
1914 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
1915 .name = "YFS.StoreOpaqueACL2",
1916 .op = yfs_FS_StoreOpaqueACL2,
1917 .deliver = yfs_deliver_status_and_volsync,
1918 .destructor = afs_flat_call_destructor,
1919 };
1920
1921 /*
1922 * Fetch the YFS ACL for a file.
1923 */
yfs_fs_store_opaque_acl2(struct afs_operation * op)1924 void yfs_fs_store_opaque_acl2(struct afs_operation *op)
1925 {
1926 struct afs_vnode_param *vp = &op->file[0];
1927 struct afs_call *call;
1928 struct afs_acl *acl = op->acl;
1929 size_t size;
1930 __be32 *bp;
1931
1932 _enter(",%x,{%llx:%llu},,",
1933 key_serial(op->key), vp->fid.vid, vp->fid.vnode);
1934
1935 size = round_up(acl->size, 4);
1936 call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
1937 sizeof(__be32) * 2 +
1938 sizeof(struct yfs_xdr_YFSFid) +
1939 sizeof(__be32) + size,
1940 sizeof(struct yfs_xdr_YFSFetchStatus) +
1941 sizeof(struct yfs_xdr_YFSVolSync));
1942 if (!call)
1943 return afs_op_nomem(op);
1944
1945 /* marshall the parameters */
1946 bp = call->request;
1947 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
1948 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1949 bp = xdr_encode_YFSFid(bp, &vp->fid);
1950 bp = xdr_encode_u32(bp, acl->size);
1951 memcpy(bp, acl->data, acl->size);
1952 if (acl->size != size)
1953 memset((void *)bp + acl->size, 0, size - acl->size);
1954 bp += size / sizeof(__be32);
1955 yfs_check_req(call, bp);
1956
1957 trace_afs_make_fs_call(call, &vp->fid);
1958 afs_make_op_call(op, call, GFP_KERNEL);
1959 }
1960