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