i2c: tegra: Add Dmitry as a reviewer
[linux-2.6/linux-2.6-arm.git] / fs / afs / yfsclient.c
blob18722aaeda33a02ffb6a75c665f48ad3eb0fb88d
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* YFS File Server client stubs
4 * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 */
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"
18 static const struct afs_fid afs_zero_fid;
20 static inline void afs_use_fs_server(struct afs_call *call, struct afs_cb_interest *cbi)
22 call->cbi = afs_get_cb_interest(cbi);
25 #define xdr_size(x) (sizeof(*x) / sizeof(__be32))
27 static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid)
29 const struct yfs_xdr_YFSFid *x = (const void *)*_bp;
31 fid->vid = xdr_to_u64(x->volume);
32 fid->vnode = xdr_to_u64(x->vnode.lo);
33 fid->vnode_hi = ntohl(x->vnode.hi);
34 fid->unique = ntohl(x->vnode.unique);
35 *_bp += xdr_size(x);
38 static __be32 *xdr_encode_u32(__be32 *bp, u32 n)
40 *bp++ = htonl(n);
41 return bp;
44 static __be32 *xdr_encode_u64(__be32 *bp, u64 n)
46 struct yfs_xdr_u64 *x = (void *)bp;
48 *x = u64_to_xdr(n);
49 return bp + xdr_size(x);
52 static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid)
54 struct yfs_xdr_YFSFid *x = (void *)bp;
56 x->volume = u64_to_xdr(fid->vid);
57 x->vnode.lo = u64_to_xdr(fid->vnode);
58 x->vnode.hi = htonl(fid->vnode_hi);
59 x->vnode.unique = htonl(fid->unique);
60 return bp + xdr_size(x);
63 static size_t xdr_strlen(unsigned int len)
65 return sizeof(__be32) + round_up(len, sizeof(__be32));
68 static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len)
70 bp = xdr_encode_u32(bp, len);
71 bp = memcpy(bp, p, len);
72 if (len & 3) {
73 unsigned int pad = 4 - (len & 3);
75 memset((u8 *)bp + len, 0, pad);
76 len += pad;
79 return bp + len / sizeof(__be32);
82 static s64 linux_to_yfs_time(const struct timespec64 *t)
84 /* Convert to 100ns intervals. */
85 return (u64)t->tv_sec * 10000000 + t->tv_nsec/100;
88 static __be32 *xdr_encode_YFSStoreStatus_mode(__be32 *bp, mode_t mode)
90 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
92 x->mask = htonl(AFS_SET_MODE);
93 x->mode = htonl(mode & S_IALLUGO);
94 x->mtime_client = u64_to_xdr(0);
95 x->owner = u64_to_xdr(0);
96 x->group = u64_to_xdr(0);
97 return bp + xdr_size(x);
100 static __be32 *xdr_encode_YFSStoreStatus_mtime(__be32 *bp, const struct timespec64 *t)
102 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
103 s64 mtime = linux_to_yfs_time(t);
105 x->mask = htonl(AFS_SET_MTIME);
106 x->mode = htonl(0);
107 x->mtime_client = u64_to_xdr(mtime);
108 x->owner = u64_to_xdr(0);
109 x->group = u64_to_xdr(0);
110 return bp + xdr_size(x);
114 * Convert a signed 100ns-resolution 64-bit time into a timespec.
116 static struct timespec64 yfs_time_to_linux(s64 t)
118 struct timespec64 ts;
119 u64 abs_t;
122 * Unfortunately can not use normal 64 bit division on 32 bit arch, but
123 * the alternative, do_div, does not work with negative numbers so have
124 * to special case them
126 if (t < 0) {
127 abs_t = -t;
128 ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
129 ts.tv_nsec = -ts.tv_nsec;
130 ts.tv_sec = -abs_t;
131 } else {
132 abs_t = t;
133 ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
134 ts.tv_sec = abs_t;
137 return ts;
140 static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
142 s64 t = xdr_to_u64(xdr);
144 return yfs_time_to_linux(t);
147 static void yfs_check_req(struct afs_call *call, __be32 *bp)
149 size_t len = (void *)bp - call->request;
151 if (len > call->request_size)
152 pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n",
153 call->type->name, len, call->request_size);
154 else if (len < call->request_size)
155 pr_warning("kAFS: %s: Request buffer underflow (%zu<%u)\n",
156 call->type->name, len, call->request_size);
160 * Dump a bad file status record.
162 static void xdr_dump_bad(const __be32 *bp)
164 __be32 x[4];
165 int i;
167 pr_notice("YFS XDR: Bad status record\n");
168 for (i = 0; i < 5 * 4 * 4; i += 16) {
169 memcpy(x, bp, 16);
170 bp += 4;
171 pr_notice("%03x: %08x %08x %08x %08x\n",
172 i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
175 memcpy(x, bp, 4);
176 pr_notice("0x50: %08x\n", ntohl(x[0]));
180 * Decode a YFSFetchStatus block
182 static int xdr_decode_YFSFetchStatus(const __be32 **_bp,
183 struct afs_call *call,
184 struct afs_status_cb *scb)
186 const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
187 struct afs_file_status *status = &scb->status;
188 u32 type;
190 status->abort_code = ntohl(xdr->abort_code);
191 if (status->abort_code != 0) {
192 if (status->abort_code == VNOVNODE)
193 status->nlink = 0;
194 scb->have_error = true;
195 return 0;
198 type = ntohl(xdr->type);
199 switch (type) {
200 case AFS_FTYPE_FILE:
201 case AFS_FTYPE_DIR:
202 case AFS_FTYPE_SYMLINK:
203 status->type = type;
204 break;
205 default:
206 goto bad;
209 status->nlink = ntohl(xdr->nlink);
210 status->author = xdr_to_u64(xdr->author);
211 status->owner = xdr_to_u64(xdr->owner);
212 status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
213 status->anon_access = ntohl(xdr->anon_access);
214 status->mode = ntohl(xdr->mode) & S_IALLUGO;
215 status->group = xdr_to_u64(xdr->group);
216 status->lock_count = ntohl(xdr->lock_count);
218 status->mtime_client = xdr_to_time(xdr->mtime_client);
219 status->mtime_server = xdr_to_time(xdr->mtime_server);
220 status->size = xdr_to_u64(xdr->size);
221 status->data_version = xdr_to_u64(xdr->data_version);
222 scb->have_status = true;
224 *_bp += xdr_size(xdr);
225 return 0;
227 bad:
228 xdr_dump_bad(*_bp);
229 return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
233 * Decode a YFSCallBack block
235 static void xdr_decode_YFSCallBack(const __be32 **_bp,
236 struct afs_call *call,
237 struct afs_status_cb *scb)
239 struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
240 struct afs_callback *cb = &scb->callback;
241 ktime_t cb_expiry;
243 cb_expiry = call->reply_time;
244 cb_expiry = ktime_add(cb_expiry, xdr_to_u64(x->expiration_time) * 100);
245 cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
246 scb->have_cb = true;
247 *_bp += xdr_size(x);
251 * Decode a YFSVolSync block
253 static void xdr_decode_YFSVolSync(const __be32 **_bp,
254 struct afs_volsync *volsync)
256 struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
257 u64 creation;
259 if (volsync) {
260 creation = xdr_to_u64(x->vol_creation_date);
261 do_div(creation, 10 * 1000 * 1000);
262 volsync->creation = creation;
265 *_bp += xdr_size(x);
269 * Encode the requested attributes into a YFSStoreStatus block
271 static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
273 struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
274 s64 mtime = 0, owner = 0, group = 0;
275 u32 mask = 0, mode = 0;
277 mask = 0;
278 if (attr->ia_valid & ATTR_MTIME) {
279 mask |= AFS_SET_MTIME;
280 mtime = linux_to_yfs_time(&attr->ia_mtime);
283 if (attr->ia_valid & ATTR_UID) {
284 mask |= AFS_SET_OWNER;
285 owner = from_kuid(&init_user_ns, attr->ia_uid);
288 if (attr->ia_valid & ATTR_GID) {
289 mask |= AFS_SET_GROUP;
290 group = from_kgid(&init_user_ns, attr->ia_gid);
293 if (attr->ia_valid & ATTR_MODE) {
294 mask |= AFS_SET_MODE;
295 mode = attr->ia_mode & S_IALLUGO;
298 x->mask = htonl(mask);
299 x->mode = htonl(mode);
300 x->mtime_client = u64_to_xdr(mtime);
301 x->owner = u64_to_xdr(owner);
302 x->group = u64_to_xdr(group);
303 return bp + xdr_size(x);
307 * Decode a YFSFetchVolumeStatus block.
309 static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
310 struct afs_volume_status *vs)
312 const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
313 u32 flags;
315 vs->vid = xdr_to_u64(x->vid);
316 vs->parent_id = xdr_to_u64(x->parent_id);
317 flags = ntohl(x->flags);
318 vs->online = flags & yfs_FVSOnline;
319 vs->in_service = flags & yfs_FVSInservice;
320 vs->blessed = flags & yfs_FVSBlessed;
321 vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
322 vs->type = ntohl(x->type);
323 vs->min_quota = 0;
324 vs->max_quota = xdr_to_u64(x->max_quota);
325 vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
326 vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
327 vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
328 vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
329 vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
330 *_bp += sizeof(*x) / sizeof(__be32);
334 * Deliver a reply that's a status, callback and volsync.
336 static int yfs_deliver_fs_status_cb_and_volsync(struct afs_call *call)
338 const __be32 *bp;
339 int ret;
341 ret = afs_transfer_reply(call);
342 if (ret < 0)
343 return ret;
345 /* unmarshall the reply once we've received all of it */
346 bp = call->buffer;
347 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb);
348 if (ret < 0)
349 return ret;
350 xdr_decode_YFSCallBack(&bp, call, call->out_scb);
351 xdr_decode_YFSVolSync(&bp, call->out_volsync);
353 _leave(" = 0 [done]");
354 return 0;
358 * Deliver reply data to operations that just return a file status and a volume
359 * sync record.
361 static int yfs_deliver_status_and_volsync(struct afs_call *call)
363 const __be32 *bp;
364 int ret;
366 ret = afs_transfer_reply(call);
367 if (ret < 0)
368 return ret;
370 bp = call->buffer;
371 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb);
372 if (ret < 0)
373 return ret;
374 xdr_decode_YFSVolSync(&bp, call->out_volsync);
376 _leave(" = 0 [done]");
377 return 0;
381 * YFS.FetchStatus operation type
383 static const struct afs_call_type yfs_RXYFSFetchStatus_vnode = {
384 .name = "YFS.FetchStatus(vnode)",
385 .op = yfs_FS_FetchStatus,
386 .deliver = yfs_deliver_fs_status_cb_and_volsync,
387 .destructor = afs_flat_call_destructor,
391 * Fetch the status information for a file.
393 int yfs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_status_cb *scb,
394 struct afs_volsync *volsync)
396 struct afs_vnode *vnode = fc->vnode;
397 struct afs_call *call;
398 struct afs_net *net = afs_v2net(vnode);
399 __be32 *bp;
401 _enter(",%x,{%llx:%llu},,",
402 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
404 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus_vnode,
405 sizeof(__be32) * 2 +
406 sizeof(struct yfs_xdr_YFSFid),
407 sizeof(struct yfs_xdr_YFSFetchStatus) +
408 sizeof(struct yfs_xdr_YFSCallBack) +
409 sizeof(struct yfs_xdr_YFSVolSync));
410 if (!call) {
411 fc->ac.error = -ENOMEM;
412 return -ENOMEM;
415 call->key = fc->key;
416 call->out_scb = scb;
417 call->out_volsync = volsync;
419 /* marshall the parameters */
420 bp = call->request;
421 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
422 bp = xdr_encode_u32(bp, 0); /* RPC flags */
423 bp = xdr_encode_YFSFid(bp, &vnode->fid);
424 yfs_check_req(call, bp);
426 afs_use_fs_server(call, fc->cbi);
427 trace_afs_make_fs_call(call, &vnode->fid);
428 afs_set_fc_call(call, fc);
429 afs_make_call(&fc->ac, call, GFP_NOFS);
430 return afs_wait_for_call_to_complete(call, &fc->ac);
434 * Deliver reply data to an YFS.FetchData64.
436 static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
438 struct afs_read *req = call->read_request;
439 const __be32 *bp;
440 unsigned int size;
441 int ret;
443 _enter("{%u,%zu/%llu}",
444 call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
446 switch (call->unmarshall) {
447 case 0:
448 req->actual_len = 0;
449 req->index = 0;
450 req->offset = req->pos & (PAGE_SIZE - 1);
451 afs_extract_to_tmp64(call);
452 call->unmarshall++;
454 /* Fall through - and extract the returned data length */
455 case 1:
456 _debug("extract data length");
457 ret = afs_extract_data(call, true);
458 if (ret < 0)
459 return ret;
461 req->actual_len = be64_to_cpu(call->tmp64);
462 _debug("DATA length: %llu", req->actual_len);
463 req->remain = min(req->len, req->actual_len);
464 if (req->remain == 0)
465 goto no_more_data;
467 call->unmarshall++;
469 begin_page:
470 ASSERTCMP(req->index, <, req->nr_pages);
471 if (req->remain > PAGE_SIZE - req->offset)
472 size = PAGE_SIZE - req->offset;
473 else
474 size = req->remain;
475 call->bvec[0].bv_len = size;
476 call->bvec[0].bv_offset = req->offset;
477 call->bvec[0].bv_page = req->pages[req->index];
478 iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
479 ASSERTCMP(size, <=, PAGE_SIZE);
481 /* Fall through - and extract the returned data */
482 case 2:
483 _debug("extract data %zu/%llu",
484 iov_iter_count(&call->iter), req->remain);
486 ret = afs_extract_data(call, true);
487 if (ret < 0)
488 return ret;
489 req->remain -= call->bvec[0].bv_len;
490 req->offset += call->bvec[0].bv_len;
491 ASSERTCMP(req->offset, <=, PAGE_SIZE);
492 if (req->offset == PAGE_SIZE) {
493 req->offset = 0;
494 if (req->page_done)
495 req->page_done(req);
496 req->index++;
497 if (req->remain > 0)
498 goto begin_page;
501 ASSERTCMP(req->remain, ==, 0);
502 if (req->actual_len <= req->len)
503 goto no_more_data;
505 /* Discard any excess data the server gave us */
506 iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
507 call->unmarshall = 3;
509 /* Fall through */
510 case 3:
511 _debug("extract discard %zu/%llu",
512 iov_iter_count(&call->iter), req->actual_len - req->len);
514 ret = afs_extract_data(call, true);
515 if (ret < 0)
516 return ret;
518 no_more_data:
519 call->unmarshall = 4;
520 afs_extract_to_buf(call,
521 sizeof(struct yfs_xdr_YFSFetchStatus) +
522 sizeof(struct yfs_xdr_YFSCallBack) +
523 sizeof(struct yfs_xdr_YFSVolSync));
525 /* Fall through - and extract the metadata */
526 case 4:
527 ret = afs_extract_data(call, false);
528 if (ret < 0)
529 return ret;
531 bp = call->buffer;
532 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb);
533 if (ret < 0)
534 return ret;
535 xdr_decode_YFSCallBack(&bp, call, call->out_scb);
536 xdr_decode_YFSVolSync(&bp, call->out_volsync);
538 req->data_version = call->out_scb->status.data_version;
539 req->file_size = call->out_scb->status.size;
541 call->unmarshall++;
543 /* Fall through */
544 case 5:
545 break;
548 for (; req->index < req->nr_pages; req->index++) {
549 if (req->offset < PAGE_SIZE)
550 zero_user_segment(req->pages[req->index],
551 req->offset, PAGE_SIZE);
552 if (req->page_done)
553 req->page_done(req);
554 req->offset = 0;
557 _leave(" = 0 [done]");
558 return 0;
561 static void yfs_fetch_data_destructor(struct afs_call *call)
563 afs_put_read(call->read_request);
564 afs_flat_call_destructor(call);
568 * YFS.FetchData64 operation type
570 static const struct afs_call_type yfs_RXYFSFetchData64 = {
571 .name = "YFS.FetchData64",
572 .op = yfs_FS_FetchData64,
573 .deliver = yfs_deliver_fs_fetch_data64,
574 .destructor = yfs_fetch_data_destructor,
578 * Fetch data from a file.
580 int yfs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_status_cb *scb,
581 struct afs_read *req)
583 struct afs_vnode *vnode = fc->vnode;
584 struct afs_call *call;
585 struct afs_net *net = afs_v2net(vnode);
586 __be32 *bp;
588 _enter(",%x,{%llx:%llu},%llx,%llx",
589 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode,
590 req->pos, req->len);
592 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchData64,
593 sizeof(__be32) * 2 +
594 sizeof(struct yfs_xdr_YFSFid) +
595 sizeof(struct yfs_xdr_u64) * 2,
596 sizeof(struct yfs_xdr_YFSFetchStatus) +
597 sizeof(struct yfs_xdr_YFSCallBack) +
598 sizeof(struct yfs_xdr_YFSVolSync));
599 if (!call)
600 return -ENOMEM;
602 call->key = fc->key;
603 call->out_scb = scb;
604 call->out_volsync = NULL;
605 call->read_request = req;
607 /* marshall the parameters */
608 bp = call->request;
609 bp = xdr_encode_u32(bp, YFSFETCHDATA64);
610 bp = xdr_encode_u32(bp, 0); /* RPC flags */
611 bp = xdr_encode_YFSFid(bp, &vnode->fid);
612 bp = xdr_encode_u64(bp, req->pos);
613 bp = xdr_encode_u64(bp, req->len);
614 yfs_check_req(call, bp);
616 refcount_inc(&req->usage);
617 afs_use_fs_server(call, fc->cbi);
618 trace_afs_make_fs_call(call, &vnode->fid);
619 afs_set_fc_call(call, fc);
620 afs_make_call(&fc->ac, call, GFP_NOFS);
621 return afs_wait_for_call_to_complete(call, &fc->ac);
625 * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
627 static int yfs_deliver_fs_create_vnode(struct afs_call *call)
629 const __be32 *bp;
630 int ret;
632 _enter("{%u}", call->unmarshall);
634 ret = afs_transfer_reply(call);
635 if (ret < 0)
636 return ret;
638 /* unmarshall the reply once we've received all of it */
639 bp = call->buffer;
640 xdr_decode_YFSFid(&bp, call->out_fid);
641 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb);
642 if (ret < 0)
643 return ret;
644 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb);
645 if (ret < 0)
646 return ret;
647 xdr_decode_YFSCallBack(&bp, call, call->out_scb);
648 xdr_decode_YFSVolSync(&bp, call->out_volsync);
650 _leave(" = 0 [done]");
651 return 0;
655 * FS.CreateFile and FS.MakeDir operation type
657 static const struct afs_call_type afs_RXFSCreateFile = {
658 .name = "YFS.CreateFile",
659 .op = yfs_FS_CreateFile,
660 .deliver = yfs_deliver_fs_create_vnode,
661 .destructor = afs_flat_call_destructor,
665 * Create a file.
667 int yfs_fs_create_file(struct afs_fs_cursor *fc,
668 const char *name,
669 umode_t mode,
670 struct afs_status_cb *dvnode_scb,
671 struct afs_fid *newfid,
672 struct afs_status_cb *new_scb)
674 struct afs_vnode *dvnode = fc->vnode;
675 struct afs_call *call;
676 struct afs_net *net = afs_v2net(dvnode);
677 size_t namesz, reqsz, rplsz;
678 __be32 *bp;
680 _enter("");
682 namesz = strlen(name);
683 reqsz = (sizeof(__be32) +
684 sizeof(__be32) +
685 sizeof(struct yfs_xdr_YFSFid) +
686 xdr_strlen(namesz) +
687 sizeof(struct yfs_xdr_YFSStoreStatus) +
688 sizeof(__be32));
689 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
690 sizeof(struct yfs_xdr_YFSFetchStatus) +
691 sizeof(struct yfs_xdr_YFSFetchStatus) +
692 sizeof(struct yfs_xdr_YFSCallBack) +
693 sizeof(struct yfs_xdr_YFSVolSync));
695 call = afs_alloc_flat_call(net, &afs_RXFSCreateFile, reqsz, rplsz);
696 if (!call)
697 return -ENOMEM;
699 call->key = fc->key;
700 call->out_dir_scb = dvnode_scb;
701 call->out_fid = newfid;
702 call->out_scb = new_scb;
704 /* marshall the parameters */
705 bp = call->request;
706 bp = xdr_encode_u32(bp, YFSCREATEFILE);
707 bp = xdr_encode_u32(bp, 0); /* RPC flags */
708 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
709 bp = xdr_encode_string(bp, name, namesz);
710 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
711 bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
712 yfs_check_req(call, bp);
714 afs_use_fs_server(call, fc->cbi);
715 trace_afs_make_fs_call1(call, &dvnode->fid, name);
716 afs_set_fc_call(call, fc);
717 afs_make_call(&fc->ac, call, GFP_NOFS);
718 return afs_wait_for_call_to_complete(call, &fc->ac);
721 static const struct afs_call_type yfs_RXFSMakeDir = {
722 .name = "YFS.MakeDir",
723 .op = yfs_FS_MakeDir,
724 .deliver = yfs_deliver_fs_create_vnode,
725 .destructor = afs_flat_call_destructor,
729 * Make a directory.
731 int yfs_fs_make_dir(struct afs_fs_cursor *fc,
732 const char *name,
733 umode_t mode,
734 struct afs_status_cb *dvnode_scb,
735 struct afs_fid *newfid,
736 struct afs_status_cb *new_scb)
738 struct afs_vnode *dvnode = fc->vnode;
739 struct afs_call *call;
740 struct afs_net *net = afs_v2net(dvnode);
741 size_t namesz, reqsz, rplsz;
742 __be32 *bp;
744 _enter("");
746 namesz = strlen(name);
747 reqsz = (sizeof(__be32) +
748 sizeof(struct yfs_xdr_RPCFlags) +
749 sizeof(struct yfs_xdr_YFSFid) +
750 xdr_strlen(namesz) +
751 sizeof(struct yfs_xdr_YFSStoreStatus));
752 rplsz = (sizeof(struct yfs_xdr_YFSFid) +
753 sizeof(struct yfs_xdr_YFSFetchStatus) +
754 sizeof(struct yfs_xdr_YFSFetchStatus) +
755 sizeof(struct yfs_xdr_YFSCallBack) +
756 sizeof(struct yfs_xdr_YFSVolSync));
758 call = afs_alloc_flat_call(net, &yfs_RXFSMakeDir, reqsz, rplsz);
759 if (!call)
760 return -ENOMEM;
762 call->key = fc->key;
763 call->out_dir_scb = dvnode_scb;
764 call->out_fid = newfid;
765 call->out_scb = new_scb;
767 /* marshall the parameters */
768 bp = call->request;
769 bp = xdr_encode_u32(bp, YFSMAKEDIR);
770 bp = xdr_encode_u32(bp, 0); /* RPC flags */
771 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
772 bp = xdr_encode_string(bp, name, namesz);
773 bp = xdr_encode_YFSStoreStatus_mode(bp, mode);
774 yfs_check_req(call, bp);
776 afs_use_fs_server(call, fc->cbi);
777 trace_afs_make_fs_call1(call, &dvnode->fid, name);
778 afs_set_fc_call(call, fc);
779 afs_make_call(&fc->ac, call, GFP_NOFS);
780 return afs_wait_for_call_to_complete(call, &fc->ac);
784 * Deliver reply data to a YFS.RemoveFile2 operation.
786 static int yfs_deliver_fs_remove_file2(struct afs_call *call)
788 struct afs_fid fid;
789 const __be32 *bp;
790 int ret;
792 _enter("{%u}", call->unmarshall);
794 ret = afs_transfer_reply(call);
795 if (ret < 0)
796 return ret;
798 bp = call->buffer;
799 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb);
800 if (ret < 0)
801 return ret;
803 xdr_decode_YFSFid(&bp, &fid);
804 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb);
805 if (ret < 0)
806 return ret;
807 /* Was deleted if vnode->status.abort_code == VNOVNODE. */
809 xdr_decode_YFSVolSync(&bp, call->out_volsync);
810 return 0;
814 * YFS.RemoveFile2 operation type.
816 static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
817 .name = "YFS.RemoveFile2",
818 .op = yfs_FS_RemoveFile2,
819 .deliver = yfs_deliver_fs_remove_file2,
820 .destructor = afs_flat_call_destructor,
824 * Remove a file and retrieve new file status.
826 int yfs_fs_remove_file2(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
827 const char *name, struct afs_status_cb *dvnode_scb,
828 struct afs_status_cb *vnode_scb)
830 struct afs_vnode *dvnode = fc->vnode;
831 struct afs_call *call;
832 struct afs_net *net = afs_v2net(dvnode);
833 size_t namesz;
834 __be32 *bp;
836 _enter("");
838 namesz = strlen(name);
840 call = afs_alloc_flat_call(net, &yfs_RXYFSRemoveFile2,
841 sizeof(__be32) +
842 sizeof(struct yfs_xdr_RPCFlags) +
843 sizeof(struct yfs_xdr_YFSFid) +
844 xdr_strlen(namesz),
845 sizeof(struct yfs_xdr_YFSFetchStatus) +
846 sizeof(struct yfs_xdr_YFSFid) +
847 sizeof(struct yfs_xdr_YFSFetchStatus) +
848 sizeof(struct yfs_xdr_YFSVolSync));
849 if (!call)
850 return -ENOMEM;
852 call->key = fc->key;
853 call->out_dir_scb = dvnode_scb;
854 call->out_scb = vnode_scb;
856 /* marshall the parameters */
857 bp = call->request;
858 bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
859 bp = xdr_encode_u32(bp, 0); /* RPC flags */
860 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
861 bp = xdr_encode_string(bp, name, namesz);
862 yfs_check_req(call, bp);
864 afs_use_fs_server(call, fc->cbi);
865 trace_afs_make_fs_call1(call, &dvnode->fid, name);
866 afs_set_fc_call(call, fc);
867 afs_make_call(&fc->ac, call, GFP_NOFS);
868 return afs_wait_for_call_to_complete(call, &fc->ac);
872 * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
874 static int yfs_deliver_fs_remove(struct afs_call *call)
876 const __be32 *bp;
877 int ret;
879 _enter("{%u}", call->unmarshall);
881 ret = afs_transfer_reply(call);
882 if (ret < 0)
883 return ret;
885 bp = call->buffer;
886 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb);
887 if (ret < 0)
888 return ret;
890 xdr_decode_YFSVolSync(&bp, call->out_volsync);
891 return 0;
895 * FS.RemoveDir and FS.RemoveFile operation types.
897 static const struct afs_call_type yfs_RXYFSRemoveFile = {
898 .name = "YFS.RemoveFile",
899 .op = yfs_FS_RemoveFile,
900 .deliver = yfs_deliver_fs_remove,
901 .destructor = afs_flat_call_destructor,
904 static const struct afs_call_type yfs_RXYFSRemoveDir = {
905 .name = "YFS.RemoveDir",
906 .op = yfs_FS_RemoveDir,
907 .deliver = yfs_deliver_fs_remove,
908 .destructor = afs_flat_call_destructor,
912 * remove a file or directory
914 int yfs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
915 const char *name, bool isdir,
916 struct afs_status_cb *dvnode_scb)
918 struct afs_vnode *dvnode = fc->vnode;
919 struct afs_call *call;
920 struct afs_net *net = afs_v2net(dvnode);
921 size_t namesz;
922 __be32 *bp;
924 _enter("");
926 namesz = strlen(name);
927 call = afs_alloc_flat_call(
928 net, isdir ? &yfs_RXYFSRemoveDir : &yfs_RXYFSRemoveFile,
929 sizeof(__be32) +
930 sizeof(struct yfs_xdr_RPCFlags) +
931 sizeof(struct yfs_xdr_YFSFid) +
932 xdr_strlen(namesz),
933 sizeof(struct yfs_xdr_YFSFetchStatus) +
934 sizeof(struct yfs_xdr_YFSVolSync));
935 if (!call)
936 return -ENOMEM;
938 call->key = fc->key;
939 call->out_dir_scb = dvnode_scb;
941 /* marshall the parameters */
942 bp = call->request;
943 bp = xdr_encode_u32(bp, isdir ? YFSREMOVEDIR : YFSREMOVEFILE);
944 bp = xdr_encode_u32(bp, 0); /* RPC flags */
945 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
946 bp = xdr_encode_string(bp, name, namesz);
947 yfs_check_req(call, bp);
949 afs_use_fs_server(call, fc->cbi);
950 trace_afs_make_fs_call1(call, &dvnode->fid, name);
951 afs_set_fc_call(call, fc);
952 afs_make_call(&fc->ac, call, GFP_NOFS);
953 return afs_wait_for_call_to_complete(call, &fc->ac);
957 * Deliver reply data to a YFS.Link operation.
959 static int yfs_deliver_fs_link(struct afs_call *call)
961 const __be32 *bp;
962 int ret;
964 _enter("{%u}", call->unmarshall);
966 ret = afs_transfer_reply(call);
967 if (ret < 0)
968 return ret;
970 bp = call->buffer;
971 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb);
972 if (ret < 0)
973 return ret;
974 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb);
975 if (ret < 0)
976 return ret;
977 xdr_decode_YFSVolSync(&bp, call->out_volsync);
978 _leave(" = 0 [done]");
979 return 0;
983 * YFS.Link operation type.
985 static const struct afs_call_type yfs_RXYFSLink = {
986 .name = "YFS.Link",
987 .op = yfs_FS_Link,
988 .deliver = yfs_deliver_fs_link,
989 .destructor = afs_flat_call_destructor,
993 * Make a hard link.
995 int yfs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
996 const char *name,
997 struct afs_status_cb *dvnode_scb,
998 struct afs_status_cb *vnode_scb)
1000 struct afs_vnode *dvnode = fc->vnode;
1001 struct afs_call *call;
1002 struct afs_net *net = afs_v2net(vnode);
1003 size_t namesz;
1004 __be32 *bp;
1006 _enter("");
1008 namesz = strlen(name);
1009 call = afs_alloc_flat_call(net, &yfs_RXYFSLink,
1010 sizeof(__be32) +
1011 sizeof(struct yfs_xdr_RPCFlags) +
1012 sizeof(struct yfs_xdr_YFSFid) +
1013 xdr_strlen(namesz) +
1014 sizeof(struct yfs_xdr_YFSFid),
1015 sizeof(struct yfs_xdr_YFSFetchStatus) +
1016 sizeof(struct yfs_xdr_YFSFetchStatus) +
1017 sizeof(struct yfs_xdr_YFSVolSync));
1018 if (!call)
1019 return -ENOMEM;
1021 call->key = fc->key;
1022 call->out_dir_scb = dvnode_scb;
1023 call->out_scb = vnode_scb;
1025 /* marshall the parameters */
1026 bp = call->request;
1027 bp = xdr_encode_u32(bp, YFSLINK);
1028 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1029 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1030 bp = xdr_encode_string(bp, name, namesz);
1031 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1032 yfs_check_req(call, bp);
1034 afs_use_fs_server(call, fc->cbi);
1035 trace_afs_make_fs_call1(call, &vnode->fid, name);
1036 afs_set_fc_call(call, fc);
1037 afs_make_call(&fc->ac, call, GFP_NOFS);
1038 return afs_wait_for_call_to_complete(call, &fc->ac);
1042 * Deliver reply data to a YFS.Symlink operation.
1044 static int yfs_deliver_fs_symlink(struct afs_call *call)
1046 const __be32 *bp;
1047 int ret;
1049 _enter("{%u}", call->unmarshall);
1051 ret = afs_transfer_reply(call);
1052 if (ret < 0)
1053 return ret;
1055 /* unmarshall the reply once we've received all of it */
1056 bp = call->buffer;
1057 xdr_decode_YFSFid(&bp, call->out_fid);
1058 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb);
1059 if (ret < 0)
1060 return ret;
1061 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb);
1062 if (ret < 0)
1063 return ret;
1064 xdr_decode_YFSVolSync(&bp, call->out_volsync);
1066 _leave(" = 0 [done]");
1067 return 0;
1071 * YFS.Symlink operation type
1073 static const struct afs_call_type yfs_RXYFSSymlink = {
1074 .name = "YFS.Symlink",
1075 .op = yfs_FS_Symlink,
1076 .deliver = yfs_deliver_fs_symlink,
1077 .destructor = afs_flat_call_destructor,
1081 * Create a symbolic link.
1083 int yfs_fs_symlink(struct afs_fs_cursor *fc,
1084 const char *name,
1085 const char *contents,
1086 struct afs_status_cb *dvnode_scb,
1087 struct afs_fid *newfid,
1088 struct afs_status_cb *vnode_scb)
1090 struct afs_vnode *dvnode = fc->vnode;
1091 struct afs_call *call;
1092 struct afs_net *net = afs_v2net(dvnode);
1093 size_t namesz, contents_sz;
1094 __be32 *bp;
1096 _enter("");
1098 namesz = strlen(name);
1099 contents_sz = strlen(contents);
1100 call = afs_alloc_flat_call(net, &yfs_RXYFSSymlink,
1101 sizeof(__be32) +
1102 sizeof(struct yfs_xdr_RPCFlags) +
1103 sizeof(struct yfs_xdr_YFSFid) +
1104 xdr_strlen(namesz) +
1105 xdr_strlen(contents_sz) +
1106 sizeof(struct yfs_xdr_YFSStoreStatus),
1107 sizeof(struct yfs_xdr_YFSFid) +
1108 sizeof(struct yfs_xdr_YFSFetchStatus) +
1109 sizeof(struct yfs_xdr_YFSFetchStatus) +
1110 sizeof(struct yfs_xdr_YFSVolSync));
1111 if (!call)
1112 return -ENOMEM;
1114 call->key = fc->key;
1115 call->out_dir_scb = dvnode_scb;
1116 call->out_fid = newfid;
1117 call->out_scb = vnode_scb;
1119 /* marshall the parameters */
1120 bp = call->request;
1121 bp = xdr_encode_u32(bp, YFSSYMLINK);
1122 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1123 bp = xdr_encode_YFSFid(bp, &dvnode->fid);
1124 bp = xdr_encode_string(bp, name, namesz);
1125 bp = xdr_encode_string(bp, contents, contents_sz);
1126 bp = xdr_encode_YFSStoreStatus_mode(bp, S_IRWXUGO);
1127 yfs_check_req(call, bp);
1129 afs_use_fs_server(call, fc->cbi);
1130 trace_afs_make_fs_call1(call, &dvnode->fid, name);
1131 afs_set_fc_call(call, fc);
1132 afs_make_call(&fc->ac, call, GFP_NOFS);
1133 return afs_wait_for_call_to_complete(call, &fc->ac);
1137 * Deliver reply data to a YFS.Rename operation.
1139 static int yfs_deliver_fs_rename(struct afs_call *call)
1141 const __be32 *bp;
1142 int ret;
1144 _enter("{%u}", call->unmarshall);
1146 ret = afs_transfer_reply(call);
1147 if (ret < 0)
1148 return ret;
1150 bp = call->buffer;
1151 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_dir_scb);
1152 if (ret < 0)
1153 return ret;
1154 if (call->out_dir_scb != call->out_scb) {
1155 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb);
1156 if (ret < 0)
1157 return ret;
1160 xdr_decode_YFSVolSync(&bp, call->out_volsync);
1161 _leave(" = 0 [done]");
1162 return 0;
1166 * YFS.Rename operation type
1168 static const struct afs_call_type yfs_RXYFSRename = {
1169 .name = "FS.Rename",
1170 .op = yfs_FS_Rename,
1171 .deliver = yfs_deliver_fs_rename,
1172 .destructor = afs_flat_call_destructor,
1176 * Rename a file or directory.
1178 int yfs_fs_rename(struct afs_fs_cursor *fc,
1179 const char *orig_name,
1180 struct afs_vnode *new_dvnode,
1181 const char *new_name,
1182 struct afs_status_cb *orig_dvnode_scb,
1183 struct afs_status_cb *new_dvnode_scb)
1185 struct afs_vnode *orig_dvnode = fc->vnode;
1186 struct afs_call *call;
1187 struct afs_net *net = afs_v2net(orig_dvnode);
1188 size_t o_namesz, n_namesz;
1189 __be32 *bp;
1191 _enter("");
1193 o_namesz = strlen(orig_name);
1194 n_namesz = strlen(new_name);
1195 call = afs_alloc_flat_call(net, &yfs_RXYFSRename,
1196 sizeof(__be32) +
1197 sizeof(struct yfs_xdr_RPCFlags) +
1198 sizeof(struct yfs_xdr_YFSFid) +
1199 xdr_strlen(o_namesz) +
1200 sizeof(struct yfs_xdr_YFSFid) +
1201 xdr_strlen(n_namesz),
1202 sizeof(struct yfs_xdr_YFSFetchStatus) +
1203 sizeof(struct yfs_xdr_YFSFetchStatus) +
1204 sizeof(struct yfs_xdr_YFSVolSync));
1205 if (!call)
1206 return -ENOMEM;
1208 call->key = fc->key;
1209 call->out_dir_scb = orig_dvnode_scb;
1210 call->out_scb = new_dvnode_scb;
1212 /* marshall the parameters */
1213 bp = call->request;
1214 bp = xdr_encode_u32(bp, YFSRENAME);
1215 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1216 bp = xdr_encode_YFSFid(bp, &orig_dvnode->fid);
1217 bp = xdr_encode_string(bp, orig_name, o_namesz);
1218 bp = xdr_encode_YFSFid(bp, &new_dvnode->fid);
1219 bp = xdr_encode_string(bp, new_name, n_namesz);
1220 yfs_check_req(call, bp);
1222 afs_use_fs_server(call, fc->cbi);
1223 trace_afs_make_fs_call2(call, &orig_dvnode->fid, orig_name, new_name);
1224 afs_set_fc_call(call, fc);
1225 afs_make_call(&fc->ac, call, GFP_NOFS);
1226 return afs_wait_for_call_to_complete(call, &fc->ac);
1230 * YFS.StoreData64 operation type.
1232 static const struct afs_call_type yfs_RXYFSStoreData64 = {
1233 .name = "YFS.StoreData64",
1234 .op = yfs_FS_StoreData64,
1235 .deliver = yfs_deliver_status_and_volsync,
1236 .destructor = afs_flat_call_destructor,
1240 * Store a set of pages to a large file.
1242 int yfs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
1243 pgoff_t first, pgoff_t last,
1244 unsigned offset, unsigned to,
1245 struct afs_status_cb *scb)
1247 struct afs_vnode *vnode = fc->vnode;
1248 struct afs_call *call;
1249 struct afs_net *net = afs_v2net(vnode);
1250 loff_t size, pos, i_size;
1251 __be32 *bp;
1253 _enter(",%x,{%llx:%llu},,",
1254 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1256 size = (loff_t)to - (loff_t)offset;
1257 if (first != last)
1258 size += (loff_t)(last - first) << PAGE_SHIFT;
1259 pos = (loff_t)first << PAGE_SHIFT;
1260 pos += offset;
1262 i_size = i_size_read(&vnode->vfs_inode);
1263 if (pos + size > i_size)
1264 i_size = size + pos;
1266 _debug("size %llx, at %llx, i_size %llx",
1267 (unsigned long long)size, (unsigned long long)pos,
1268 (unsigned long long)i_size);
1270 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64,
1271 sizeof(__be32) +
1272 sizeof(__be32) +
1273 sizeof(struct yfs_xdr_YFSFid) +
1274 sizeof(struct yfs_xdr_YFSStoreStatus) +
1275 sizeof(struct yfs_xdr_u64) * 3,
1276 sizeof(struct yfs_xdr_YFSFetchStatus) +
1277 sizeof(struct yfs_xdr_YFSVolSync));
1278 if (!call)
1279 return -ENOMEM;
1281 call->key = fc->key;
1282 call->mapping = mapping;
1283 call->first = first;
1284 call->last = last;
1285 call->first_offset = offset;
1286 call->last_to = to;
1287 call->send_pages = true;
1288 call->out_scb = scb;
1290 /* marshall the parameters */
1291 bp = call->request;
1292 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1293 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1294 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1295 bp = xdr_encode_YFSStoreStatus_mtime(bp, &vnode->vfs_inode.i_mtime);
1296 bp = xdr_encode_u64(bp, pos);
1297 bp = xdr_encode_u64(bp, size);
1298 bp = xdr_encode_u64(bp, i_size);
1299 yfs_check_req(call, bp);
1301 afs_use_fs_server(call, fc->cbi);
1302 trace_afs_make_fs_call(call, &vnode->fid);
1303 afs_set_fc_call(call, fc);
1304 afs_make_call(&fc->ac, call, GFP_NOFS);
1305 return afs_wait_for_call_to_complete(call, &fc->ac);
1309 * YFS.StoreStatus operation type
1311 static const struct afs_call_type yfs_RXYFSStoreStatus = {
1312 .name = "YFS.StoreStatus",
1313 .op = yfs_FS_StoreStatus,
1314 .deliver = yfs_deliver_status_and_volsync,
1315 .destructor = afs_flat_call_destructor,
1318 static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
1319 .name = "YFS.StoreData64",
1320 .op = yfs_FS_StoreData64,
1321 .deliver = yfs_deliver_status_and_volsync,
1322 .destructor = afs_flat_call_destructor,
1326 * Set the attributes on a file, using YFS.StoreData64 rather than
1327 * YFS.StoreStatus so as to alter the file size also.
1329 static int yfs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr,
1330 struct afs_status_cb *scb)
1332 struct afs_vnode *vnode = fc->vnode;
1333 struct afs_call *call;
1334 struct afs_net *net = afs_v2net(vnode);
1335 __be32 *bp;
1337 _enter(",%x,{%llx:%llu},,",
1338 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1340 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreData64_as_Status,
1341 sizeof(__be32) * 2 +
1342 sizeof(struct yfs_xdr_YFSFid) +
1343 sizeof(struct yfs_xdr_YFSStoreStatus) +
1344 sizeof(struct yfs_xdr_u64) * 3,
1345 sizeof(struct yfs_xdr_YFSFetchStatus) +
1346 sizeof(struct yfs_xdr_YFSVolSync));
1347 if (!call)
1348 return -ENOMEM;
1350 call->key = fc->key;
1351 call->out_scb = scb;
1353 /* marshall the parameters */
1354 bp = call->request;
1355 bp = xdr_encode_u32(bp, YFSSTOREDATA64);
1356 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1357 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1358 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1359 bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
1360 bp = xdr_encode_u64(bp, 0); /* size of write */
1361 bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
1362 yfs_check_req(call, bp);
1364 afs_use_fs_server(call, fc->cbi);
1365 trace_afs_make_fs_call(call, &vnode->fid);
1366 afs_set_fc_call(call, fc);
1367 afs_make_call(&fc->ac, call, GFP_NOFS);
1368 return afs_wait_for_call_to_complete(call, &fc->ac);
1372 * Set the attributes on a file, using YFS.StoreData64 if there's a change in
1373 * file size, and YFS.StoreStatus otherwise.
1375 int yfs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr,
1376 struct afs_status_cb *scb)
1378 struct afs_vnode *vnode = fc->vnode;
1379 struct afs_call *call;
1380 struct afs_net *net = afs_v2net(vnode);
1381 __be32 *bp;
1383 if (attr->ia_valid & ATTR_SIZE)
1384 return yfs_fs_setattr_size(fc, attr, scb);
1386 _enter(",%x,{%llx:%llu},,",
1387 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
1389 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
1390 sizeof(__be32) * 2 +
1391 sizeof(struct yfs_xdr_YFSFid) +
1392 sizeof(struct yfs_xdr_YFSStoreStatus),
1393 sizeof(struct yfs_xdr_YFSFetchStatus) +
1394 sizeof(struct yfs_xdr_YFSVolSync));
1395 if (!call)
1396 return -ENOMEM;
1398 call->key = fc->key;
1399 call->out_scb = scb;
1401 /* marshall the parameters */
1402 bp = call->request;
1403 bp = xdr_encode_u32(bp, YFSSTORESTATUS);
1404 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1405 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1406 bp = xdr_encode_YFS_StoreStatus(bp, attr);
1407 yfs_check_req(call, bp);
1409 afs_use_fs_server(call, fc->cbi);
1410 trace_afs_make_fs_call(call, &vnode->fid);
1411 afs_set_fc_call(call, fc);
1412 afs_make_call(&fc->ac, call, GFP_NOFS);
1413 return afs_wait_for_call_to_complete(call, &fc->ac);
1417 * Deliver reply data to a YFS.GetVolumeStatus operation.
1419 static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
1421 const __be32 *bp;
1422 char *p;
1423 u32 size;
1424 int ret;
1426 _enter("{%u}", call->unmarshall);
1428 switch (call->unmarshall) {
1429 case 0:
1430 call->unmarshall++;
1431 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
1433 /* Fall through - and extract the returned status record */
1434 case 1:
1435 _debug("extract status");
1436 ret = afs_extract_data(call, true);
1437 if (ret < 0)
1438 return ret;
1440 bp = call->buffer;
1441 xdr_decode_YFSFetchVolumeStatus(&bp, call->out_volstatus);
1442 call->unmarshall++;
1443 afs_extract_to_tmp(call);
1445 /* Fall through - and extract the volume name length */
1446 case 2:
1447 ret = afs_extract_data(call, true);
1448 if (ret < 0)
1449 return ret;
1451 call->count = ntohl(call->tmp);
1452 _debug("volname length: %u", call->count);
1453 if (call->count >= AFSNAMEMAX)
1454 return afs_protocol_error(call, -EBADMSG,
1455 afs_eproto_volname_len);
1456 size = (call->count + 3) & ~3; /* It's padded */
1457 afs_extract_to_buf(call, size);
1458 call->unmarshall++;
1460 /* Fall through - and extract the volume name */
1461 case 3:
1462 _debug("extract volname");
1463 ret = afs_extract_data(call, true);
1464 if (ret < 0)
1465 return ret;
1467 p = call->buffer;
1468 p[call->count] = 0;
1469 _debug("volname '%s'", p);
1470 afs_extract_to_tmp(call);
1471 call->unmarshall++;
1473 /* Fall through - and extract the offline message length */
1474 case 4:
1475 ret = afs_extract_data(call, true);
1476 if (ret < 0)
1477 return ret;
1479 call->count = ntohl(call->tmp);
1480 _debug("offline msg length: %u", call->count);
1481 if (call->count >= AFSNAMEMAX)
1482 return afs_protocol_error(call, -EBADMSG,
1483 afs_eproto_offline_msg_len);
1484 size = (call->count + 3) & ~3; /* It's padded */
1485 afs_extract_to_buf(call, size);
1486 call->unmarshall++;
1488 /* Fall through - and extract the offline message */
1489 case 5:
1490 _debug("extract offline");
1491 ret = afs_extract_data(call, true);
1492 if (ret < 0)
1493 return ret;
1495 p = call->buffer;
1496 p[call->count] = 0;
1497 _debug("offline '%s'", p);
1499 afs_extract_to_tmp(call);
1500 call->unmarshall++;
1502 /* Fall through - and extract the message of the day length */
1503 case 6:
1504 ret = afs_extract_data(call, true);
1505 if (ret < 0)
1506 return ret;
1508 call->count = ntohl(call->tmp);
1509 _debug("motd length: %u", call->count);
1510 if (call->count >= AFSNAMEMAX)
1511 return afs_protocol_error(call, -EBADMSG,
1512 afs_eproto_motd_len);
1513 size = (call->count + 3) & ~3; /* It's padded */
1514 afs_extract_to_buf(call, size);
1515 call->unmarshall++;
1517 /* Fall through - and extract the message of the day */
1518 case 7:
1519 _debug("extract motd");
1520 ret = afs_extract_data(call, false);
1521 if (ret < 0)
1522 return ret;
1524 p = call->buffer;
1525 p[call->count] = 0;
1526 _debug("motd '%s'", p);
1528 call->unmarshall++;
1530 /* Fall through */
1531 case 8:
1532 break;
1535 _leave(" = 0 [done]");
1536 return 0;
1540 * YFS.GetVolumeStatus operation type
1542 static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
1543 .name = "YFS.GetVolumeStatus",
1544 .op = yfs_FS_GetVolumeStatus,
1545 .deliver = yfs_deliver_fs_get_volume_status,
1546 .destructor = afs_flat_call_destructor,
1550 * fetch the status of a volume
1552 int yfs_fs_get_volume_status(struct afs_fs_cursor *fc,
1553 struct afs_volume_status *vs)
1555 struct afs_vnode *vnode = fc->vnode;
1556 struct afs_call *call;
1557 struct afs_net *net = afs_v2net(vnode);
1558 __be32 *bp;
1560 _enter("");
1562 call = afs_alloc_flat_call(net, &yfs_RXYFSGetVolumeStatus,
1563 sizeof(__be32) * 2 +
1564 sizeof(struct yfs_xdr_u64),
1565 max_t(size_t,
1566 sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
1567 sizeof(__be32),
1568 AFSOPAQUEMAX + 1));
1569 if (!call)
1570 return -ENOMEM;
1572 call->key = fc->key;
1573 call->out_volstatus = vs;
1575 /* marshall the parameters */
1576 bp = call->request;
1577 bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
1578 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1579 bp = xdr_encode_u64(bp, vnode->fid.vid);
1580 yfs_check_req(call, bp);
1582 afs_use_fs_server(call, fc->cbi);
1583 trace_afs_make_fs_call(call, &vnode->fid);
1584 afs_set_fc_call(call, fc);
1585 afs_make_call(&fc->ac, call, GFP_NOFS);
1586 return afs_wait_for_call_to_complete(call, &fc->ac);
1590 * YFS.SetLock operation type
1592 static const struct afs_call_type yfs_RXYFSSetLock = {
1593 .name = "YFS.SetLock",
1594 .op = yfs_FS_SetLock,
1595 .deliver = yfs_deliver_status_and_volsync,
1596 .done = afs_lock_op_done,
1597 .destructor = afs_flat_call_destructor,
1601 * YFS.ExtendLock operation type
1603 static const struct afs_call_type yfs_RXYFSExtendLock = {
1604 .name = "YFS.ExtendLock",
1605 .op = yfs_FS_ExtendLock,
1606 .deliver = yfs_deliver_status_and_volsync,
1607 .done = afs_lock_op_done,
1608 .destructor = afs_flat_call_destructor,
1612 * YFS.ReleaseLock operation type
1614 static const struct afs_call_type yfs_RXYFSReleaseLock = {
1615 .name = "YFS.ReleaseLock",
1616 .op = yfs_FS_ReleaseLock,
1617 .deliver = yfs_deliver_status_and_volsync,
1618 .destructor = afs_flat_call_destructor,
1622 * Set a lock on a file
1624 int yfs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type,
1625 struct afs_status_cb *scb)
1627 struct afs_vnode *vnode = fc->vnode;
1628 struct afs_call *call;
1629 struct afs_net *net = afs_v2net(vnode);
1630 __be32 *bp;
1632 _enter("");
1634 call = afs_alloc_flat_call(net, &yfs_RXYFSSetLock,
1635 sizeof(__be32) * 2 +
1636 sizeof(struct yfs_xdr_YFSFid) +
1637 sizeof(__be32),
1638 sizeof(struct yfs_xdr_YFSFetchStatus) +
1639 sizeof(struct yfs_xdr_YFSVolSync));
1640 if (!call)
1641 return -ENOMEM;
1643 call->key = fc->key;
1644 call->lvnode = vnode;
1645 call->out_scb = scb;
1647 /* marshall the parameters */
1648 bp = call->request;
1649 bp = xdr_encode_u32(bp, YFSSETLOCK);
1650 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1651 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1652 bp = xdr_encode_u32(bp, type);
1653 yfs_check_req(call, bp);
1655 afs_use_fs_server(call, fc->cbi);
1656 trace_afs_make_fs_calli(call, &vnode->fid, type);
1657 afs_set_fc_call(call, fc);
1658 afs_make_call(&fc->ac, call, GFP_NOFS);
1659 return afs_wait_for_call_to_complete(call, &fc->ac);
1663 * extend a lock on a file
1665 int yfs_fs_extend_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1667 struct afs_vnode *vnode = fc->vnode;
1668 struct afs_call *call;
1669 struct afs_net *net = afs_v2net(vnode);
1670 __be32 *bp;
1672 _enter("");
1674 call = afs_alloc_flat_call(net, &yfs_RXYFSExtendLock,
1675 sizeof(__be32) * 2 +
1676 sizeof(struct yfs_xdr_YFSFid),
1677 sizeof(struct yfs_xdr_YFSFetchStatus) +
1678 sizeof(struct yfs_xdr_YFSVolSync));
1679 if (!call)
1680 return -ENOMEM;
1682 call->key = fc->key;
1683 call->lvnode = vnode;
1684 call->out_scb = scb;
1686 /* marshall the parameters */
1687 bp = call->request;
1688 bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
1689 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1690 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1691 yfs_check_req(call, bp);
1693 afs_use_fs_server(call, fc->cbi);
1694 trace_afs_make_fs_call(call, &vnode->fid);
1695 afs_set_fc_call(call, fc);
1696 afs_make_call(&fc->ac, call, GFP_NOFS);
1697 return afs_wait_for_call_to_complete(call, &fc->ac);
1701 * release a lock on a file
1703 int yfs_fs_release_lock(struct afs_fs_cursor *fc, struct afs_status_cb *scb)
1705 struct afs_vnode *vnode = fc->vnode;
1706 struct afs_call *call;
1707 struct afs_net *net = afs_v2net(vnode);
1708 __be32 *bp;
1710 _enter("");
1712 call = afs_alloc_flat_call(net, &yfs_RXYFSReleaseLock,
1713 sizeof(__be32) * 2 +
1714 sizeof(struct yfs_xdr_YFSFid),
1715 sizeof(struct yfs_xdr_YFSFetchStatus) +
1716 sizeof(struct yfs_xdr_YFSVolSync));
1717 if (!call)
1718 return -ENOMEM;
1720 call->key = fc->key;
1721 call->lvnode = vnode;
1722 call->out_scb = scb;
1724 /* marshall the parameters */
1725 bp = call->request;
1726 bp = xdr_encode_u32(bp, YFSRELEASELOCK);
1727 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1728 bp = xdr_encode_YFSFid(bp, &vnode->fid);
1729 yfs_check_req(call, bp);
1731 afs_use_fs_server(call, fc->cbi);
1732 trace_afs_make_fs_call(call, &vnode->fid);
1733 afs_set_fc_call(call, fc);
1734 afs_make_call(&fc->ac, call, GFP_NOFS);
1735 return afs_wait_for_call_to_complete(call, &fc->ac);
1739 * YFS.FetchStatus operation type
1741 static const struct afs_call_type yfs_RXYFSFetchStatus = {
1742 .name = "YFS.FetchStatus",
1743 .op = yfs_FS_FetchStatus,
1744 .deliver = yfs_deliver_fs_status_cb_and_volsync,
1745 .destructor = afs_flat_call_destructor,
1749 * Fetch the status information for a fid without needing a vnode handle.
1751 int yfs_fs_fetch_status(struct afs_fs_cursor *fc,
1752 struct afs_net *net,
1753 struct afs_fid *fid,
1754 struct afs_status_cb *scb,
1755 struct afs_volsync *volsync)
1757 struct afs_call *call;
1758 __be32 *bp;
1760 _enter(",%x,{%llx:%llu},,",
1761 key_serial(fc->key), fid->vid, fid->vnode);
1763 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchStatus,
1764 sizeof(__be32) * 2 +
1765 sizeof(struct yfs_xdr_YFSFid),
1766 sizeof(struct yfs_xdr_YFSFetchStatus) +
1767 sizeof(struct yfs_xdr_YFSCallBack) +
1768 sizeof(struct yfs_xdr_YFSVolSync));
1769 if (!call) {
1770 fc->ac.error = -ENOMEM;
1771 return -ENOMEM;
1774 call->key = fc->key;
1775 call->out_scb = scb;
1776 call->out_volsync = volsync;
1778 /* marshall the parameters */
1779 bp = call->request;
1780 bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
1781 bp = xdr_encode_u32(bp, 0); /* RPC flags */
1782 bp = xdr_encode_YFSFid(bp, fid);
1783 yfs_check_req(call, bp);
1785 afs_use_fs_server(call, fc->cbi);
1786 trace_afs_make_fs_call(call, fid);
1787 afs_set_fc_call(call, fc);
1788 afs_make_call(&fc->ac, call, GFP_NOFS);
1789 return afs_wait_for_call_to_complete(call, &fc->ac);
1793 * Deliver reply data to an YFS.InlineBulkStatus call
1795 static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
1797 struct afs_status_cb *scb;
1798 const __be32 *bp;
1799 u32 tmp;
1800 int ret;
1802 _enter("{%u}", call->unmarshall);
1804 switch (call->unmarshall) {
1805 case 0:
1806 afs_extract_to_tmp(call);
1807 call->unmarshall++;
1809 /* Extract the file status count and array in two steps */
1810 /* Fall through */
1811 case 1:
1812 _debug("extract status count");
1813 ret = afs_extract_data(call, true);
1814 if (ret < 0)
1815 return ret;
1817 tmp = ntohl(call->tmp);
1818 _debug("status count: %u/%u", tmp, call->count2);
1819 if (tmp != call->count2)
1820 return afs_protocol_error(call, -EBADMSG,
1821 afs_eproto_ibulkst_count);
1823 call->count = 0;
1824 call->unmarshall++;
1825 more_counts:
1826 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
1828 /* Fall through */
1829 case 2:
1830 _debug("extract status array %u", call->count);
1831 ret = afs_extract_data(call, true);
1832 if (ret < 0)
1833 return ret;
1835 bp = call->buffer;
1836 scb = &call->out_scb[call->count];
1837 ret = xdr_decode_YFSFetchStatus(&bp, call, scb);
1838 if (ret < 0)
1839 return ret;
1841 call->count++;
1842 if (call->count < call->count2)
1843 goto more_counts;
1845 call->count = 0;
1846 call->unmarshall++;
1847 afs_extract_to_tmp(call);
1849 /* Extract the callback count and array in two steps */
1850 /* Fall through */
1851 case 3:
1852 _debug("extract CB count");
1853 ret = afs_extract_data(call, true);
1854 if (ret < 0)
1855 return ret;
1857 tmp = ntohl(call->tmp);
1858 _debug("CB count: %u", tmp);
1859 if (tmp != call->count2)
1860 return afs_protocol_error(call, -EBADMSG,
1861 afs_eproto_ibulkst_cb_count);
1862 call->count = 0;
1863 call->unmarshall++;
1864 more_cbs:
1865 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
1867 /* Fall through */
1868 case 4:
1869 _debug("extract CB array");
1870 ret = afs_extract_data(call, true);
1871 if (ret < 0)
1872 return ret;
1874 _debug("unmarshall CB array");
1875 bp = call->buffer;
1876 scb = &call->out_scb[call->count];
1877 xdr_decode_YFSCallBack(&bp, call, scb);
1878 call->count++;
1879 if (call->count < call->count2)
1880 goto more_cbs;
1882 afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
1883 call->unmarshall++;
1885 /* Fall through */
1886 case 5:
1887 ret = afs_extract_data(call, false);
1888 if (ret < 0)
1889 return ret;
1891 bp = call->buffer;
1892 xdr_decode_YFSVolSync(&bp, call->out_volsync);
1894 call->unmarshall++;
1896 /* Fall through */
1897 case 6:
1898 break;
1901 _leave(" = 0 [done]");
1902 return 0;
1906 * FS.InlineBulkStatus operation type
1908 static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
1909 .name = "YFS.InlineBulkStatus",
1910 .op = yfs_FS_InlineBulkStatus,
1911 .deliver = yfs_deliver_fs_inline_bulk_status,
1912 .destructor = afs_flat_call_destructor,
1916 * Fetch the status information for up to 1024 files
1918 int yfs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
1919 struct afs_net *net,
1920 struct afs_fid *fids,
1921 struct afs_status_cb *statuses,
1922 unsigned int nr_fids,
1923 struct afs_volsync *volsync)
1925 struct afs_call *call;
1926 __be32 *bp;
1927 int i;
1929 _enter(",%x,{%llx:%llu},%u",
1930 key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
1932 call = afs_alloc_flat_call(net, &yfs_RXYFSInlineBulkStatus,
1933 sizeof(__be32) +
1934 sizeof(__be32) +
1935 sizeof(__be32) +
1936 sizeof(struct yfs_xdr_YFSFid) * nr_fids,
1937 sizeof(struct yfs_xdr_YFSFetchStatus));
1938 if (!call) {
1939 fc->ac.error = -ENOMEM;
1940 return -ENOMEM;
1943 call->key = fc->key;
1944 call->out_scb = statuses;
1945 call->out_volsync = volsync;
1946 call->count2 = nr_fids;
1948 /* marshall the parameters */
1949 bp = call->request;
1950 bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
1951 bp = xdr_encode_u32(bp, 0); /* RPCFlags */
1952 bp = xdr_encode_u32(bp, nr_fids);
1953 for (i = 0; i < nr_fids; i++)
1954 bp = xdr_encode_YFSFid(bp, &fids[i]);
1955 yfs_check_req(call, bp);
1957 afs_use_fs_server(call, fc->cbi);
1958 trace_afs_make_fs_call(call, &fids[0]);
1959 afs_set_fc_call(call, fc);
1960 afs_make_call(&fc->ac, call, GFP_NOFS);
1961 return afs_wait_for_call_to_complete(call, &fc->ac);
1965 * Deliver reply data to an YFS.FetchOpaqueACL.
1967 static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
1969 struct yfs_acl *yacl = call->out_yacl;
1970 struct afs_acl *acl;
1971 const __be32 *bp;
1972 unsigned int size;
1973 int ret;
1975 _enter("{%u}", call->unmarshall);
1977 switch (call->unmarshall) {
1978 case 0:
1979 afs_extract_to_tmp(call);
1980 call->unmarshall++;
1982 /* Extract the file ACL length */
1983 case 1:
1984 ret = afs_extract_data(call, true);
1985 if (ret < 0)
1986 return ret;
1988 size = call->count2 = ntohl(call->tmp);
1989 size = round_up(size, 4);
1991 if (yacl->flags & YFS_ACL_WANT_ACL) {
1992 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
1993 if (!acl)
1994 return -ENOMEM;
1995 yacl->acl = acl;
1996 acl->size = call->count2;
1997 afs_extract_begin(call, acl->data, size);
1998 } else {
1999 iov_iter_discard(&call->iter, READ, size);
2001 call->unmarshall++;
2003 /* Extract the file ACL */
2004 case 2:
2005 ret = afs_extract_data(call, true);
2006 if (ret < 0)
2007 return ret;
2009 afs_extract_to_tmp(call);
2010 call->unmarshall++;
2012 /* Extract the volume ACL length */
2013 case 3:
2014 ret = afs_extract_data(call, true);
2015 if (ret < 0)
2016 return ret;
2018 size = call->count2 = ntohl(call->tmp);
2019 size = round_up(size, 4);
2021 if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
2022 acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
2023 if (!acl)
2024 return -ENOMEM;
2025 yacl->vol_acl = acl;
2026 acl->size = call->count2;
2027 afs_extract_begin(call, acl->data, size);
2028 } else {
2029 iov_iter_discard(&call->iter, READ, size);
2031 call->unmarshall++;
2033 /* Extract the volume ACL */
2034 case 4:
2035 ret = afs_extract_data(call, true);
2036 if (ret < 0)
2037 return ret;
2039 afs_extract_to_buf(call,
2040 sizeof(__be32) * 2 +
2041 sizeof(struct yfs_xdr_YFSFetchStatus) +
2042 sizeof(struct yfs_xdr_YFSVolSync));
2043 call->unmarshall++;
2045 /* extract the metadata */
2046 case 5:
2047 ret = afs_extract_data(call, false);
2048 if (ret < 0)
2049 return ret;
2051 bp = call->buffer;
2052 yacl->inherit_flag = ntohl(*bp++);
2053 yacl->num_cleaned = ntohl(*bp++);
2054 ret = xdr_decode_YFSFetchStatus(&bp, call, call->out_scb);
2055 if (ret < 0)
2056 return ret;
2057 xdr_decode_YFSVolSync(&bp, call->out_volsync);
2059 call->unmarshall++;
2061 case 6:
2062 break;
2065 _leave(" = 0 [done]");
2066 return 0;
2069 void yfs_free_opaque_acl(struct yfs_acl *yacl)
2071 if (yacl) {
2072 kfree(yacl->acl);
2073 kfree(yacl->vol_acl);
2074 kfree(yacl);
2079 * YFS.FetchOpaqueACL operation type
2081 static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
2082 .name = "YFS.FetchOpaqueACL",
2083 .op = yfs_FS_FetchOpaqueACL,
2084 .deliver = yfs_deliver_fs_fetch_opaque_acl,
2085 .destructor = afs_flat_call_destructor,
2089 * Fetch the YFS advanced ACLs for a file.
2091 struct yfs_acl *yfs_fs_fetch_opaque_acl(struct afs_fs_cursor *fc,
2092 struct yfs_acl *yacl,
2093 struct afs_status_cb *scb)
2095 struct afs_vnode *vnode = fc->vnode;
2096 struct afs_call *call;
2097 struct afs_net *net = afs_v2net(vnode);
2098 __be32 *bp;
2100 _enter(",%x,{%llx:%llu},,",
2101 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2103 call = afs_alloc_flat_call(net, &yfs_RXYFSFetchOpaqueACL,
2104 sizeof(__be32) * 2 +
2105 sizeof(struct yfs_xdr_YFSFid),
2106 sizeof(__be32) * 2 +
2107 sizeof(struct yfs_xdr_YFSFetchStatus) +
2108 sizeof(struct yfs_xdr_YFSVolSync));
2109 if (!call) {
2110 fc->ac.error = -ENOMEM;
2111 return ERR_PTR(-ENOMEM);
2114 call->key = fc->key;
2115 call->out_yacl = yacl;
2116 call->out_scb = scb;
2117 call->out_volsync = NULL;
2119 /* marshall the parameters */
2120 bp = call->request;
2121 bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
2122 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2123 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2124 yfs_check_req(call, bp);
2126 afs_use_fs_server(call, fc->cbi);
2127 trace_afs_make_fs_call(call, &vnode->fid);
2128 afs_make_call(&fc->ac, call, GFP_KERNEL);
2129 return (struct yfs_acl *)afs_wait_for_call_to_complete(call, &fc->ac);
2133 * YFS.StoreOpaqueACL2 operation type
2135 static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
2136 .name = "YFS.StoreOpaqueACL2",
2137 .op = yfs_FS_StoreOpaqueACL2,
2138 .deliver = yfs_deliver_status_and_volsync,
2139 .destructor = afs_flat_call_destructor,
2143 * Fetch the YFS ACL for a file.
2145 int yfs_fs_store_opaque_acl2(struct afs_fs_cursor *fc, const struct afs_acl *acl,
2146 struct afs_status_cb *scb)
2148 struct afs_vnode *vnode = fc->vnode;
2149 struct afs_call *call;
2150 struct afs_net *net = afs_v2net(vnode);
2151 size_t size;
2152 __be32 *bp;
2154 _enter(",%x,{%llx:%llu},,",
2155 key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
2157 size = round_up(acl->size, 4);
2158 call = afs_alloc_flat_call(net, &yfs_RXYFSStoreStatus,
2159 sizeof(__be32) * 2 +
2160 sizeof(struct yfs_xdr_YFSFid) +
2161 sizeof(__be32) + size,
2162 sizeof(struct yfs_xdr_YFSFetchStatus) +
2163 sizeof(struct yfs_xdr_YFSVolSync));
2164 if (!call) {
2165 fc->ac.error = -ENOMEM;
2166 return -ENOMEM;
2169 call->key = fc->key;
2170 call->out_scb = scb;
2171 call->out_volsync = NULL;
2173 /* marshall the parameters */
2174 bp = call->request;
2175 bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
2176 bp = xdr_encode_u32(bp, 0); /* RPC flags */
2177 bp = xdr_encode_YFSFid(bp, &vnode->fid);
2178 bp = xdr_encode_u32(bp, acl->size);
2179 memcpy(bp, acl->data, acl->size);
2180 if (acl->size != size)
2181 memset((void *)bp + acl->size, 0, size - acl->size);
2182 yfs_check_req(call, bp);
2184 trace_afs_make_fs_call(call, &vnode->fid);
2185 afs_make_call(&fc->ac, call, GFP_KERNEL);
2186 return afs_wait_for_call_to_complete(call, &fc->ac);