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