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