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