fsclient.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* AFS File Server client stubs
  3. *
  4. * Copyright (C) 2002, 2007 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #include <linux/init.h>
  8. #include <linux/slab.h>
  9. #include <linux/sched.h>
  10. #include <linux/circ_buf.h>
  11. #include <linux/iversion.h>
  12. #include "internal.h"
  13. #include "afs_fs.h"
  14. #include "xdr_fs.h"
  15. /*
  16. * decode an AFSFid block
  17. */
  18. static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
  19. {
  20. const __be32 *bp = *_bp;
  21. fid->vid = ntohl(*bp++);
  22. fid->vnode = ntohl(*bp++);
  23. fid->unique = ntohl(*bp++);
  24. *_bp = bp;
  25. }
  26. /*
  27. * Dump a bad file status record.
  28. */
  29. static void xdr_dump_bad(const __be32 *bp)
  30. {
  31. __be32 x[4];
  32. int i;
  33. pr_notice("AFS XDR: Bad status record\n");
  34. for (i = 0; i < 5 * 4 * 4; i += 16) {
  35. memcpy(x, bp, 16);
  36. bp += 4;
  37. pr_notice("%03x: %08x %08x %08x %08x\n",
  38. i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
  39. }
  40. memcpy(x, bp, 4);
  41. pr_notice("0x50: %08x\n", ntohl(x[0]));
  42. }
  43. /*
  44. * decode an AFSFetchStatus block
  45. */
  46. static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
  47. struct afs_call *call,
  48. struct afs_status_cb *scb)
  49. {
  50. const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
  51. struct afs_file_status *status = &scb->status;
  52. bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
  53. u64 data_version, size;
  54. u32 type, abort_code;
  55. abort_code = ntohl(xdr->abort_code);
  56. if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
  57. if (xdr->if_version == htonl(0) &&
  58. abort_code != 0 &&
  59. inline_error) {
  60. /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
  61. * whereby it doesn't set the interface version in the error
  62. * case.
  63. */
  64. status->abort_code = abort_code;
  65. scb->have_error = true;
  66. goto advance;
  67. }
  68. pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
  69. goto bad;
  70. }
  71. if (abort_code != 0 && inline_error) {
  72. status->abort_code = abort_code;
  73. scb->have_error = true;
  74. goto advance;
  75. }
  76. type = ntohl(xdr->type);
  77. switch (type) {
  78. case AFS_FTYPE_FILE:
  79. case AFS_FTYPE_DIR:
  80. case AFS_FTYPE_SYMLINK:
  81. status->type = type;
  82. break;
  83. default:
  84. goto bad;
  85. }
  86. status->nlink = ntohl(xdr->nlink);
  87. status->author = ntohl(xdr->author);
  88. status->owner = ntohl(xdr->owner);
  89. status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
  90. status->anon_access = ntohl(xdr->anon_access);
  91. status->mode = ntohl(xdr->mode) & S_IALLUGO;
  92. status->group = ntohl(xdr->group);
  93. status->lock_count = ntohl(xdr->lock_count);
  94. status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
  95. status->mtime_client.tv_nsec = 0;
  96. status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
  97. status->mtime_server.tv_nsec = 0;
  98. size = (u64)ntohl(xdr->size_lo);
  99. size |= (u64)ntohl(xdr->size_hi) << 32;
  100. status->size = size;
  101. data_version = (u64)ntohl(xdr->data_version_lo);
  102. data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
  103. status->data_version = data_version;
  104. scb->have_status = true;
  105. advance:
  106. *_bp = (const void *)*_bp + sizeof(*xdr);
  107. return;
  108. bad:
  109. xdr_dump_bad(*_bp);
  110. afs_protocol_error(call, afs_eproto_bad_status);
  111. goto advance;
  112. }
  113. static time64_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
  114. {
  115. return ktime_divns(call->reply_time, NSEC_PER_SEC) + expiry;
  116. }
  117. static void xdr_decode_AFSCallBack(const __be32 **_bp,
  118. struct afs_call *call,
  119. struct afs_status_cb *scb)
  120. {
  121. struct afs_callback *cb = &scb->callback;
  122. const __be32 *bp = *_bp;
  123. bp++; /* version */
  124. cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
  125. bp++; /* type */
  126. scb->have_cb = true;
  127. *_bp = bp;
  128. }
  129. /*
  130. * decode an AFSVolSync block
  131. */
  132. static void xdr_decode_AFSVolSync(const __be32 **_bp,
  133. struct afs_volsync *volsync)
  134. {
  135. const __be32 *bp = *_bp;
  136. u32 creation;
  137. creation = ntohl(*bp++);
  138. bp++; /* spare2 */
  139. bp++; /* spare3 */
  140. bp++; /* spare4 */
  141. bp++; /* spare5 */
  142. bp++; /* spare6 */
  143. *_bp = bp;
  144. if (volsync)
  145. volsync->creation = creation;
  146. }
  147. /*
  148. * encode the requested attributes into an AFSStoreStatus block
  149. */
  150. static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
  151. {
  152. __be32 *bp = *_bp;
  153. u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
  154. mask = 0;
  155. if (attr->ia_valid & ATTR_MTIME) {
  156. mask |= AFS_SET_MTIME;
  157. mtime = attr->ia_mtime.tv_sec;
  158. }
  159. if (attr->ia_valid & ATTR_UID) {
  160. mask |= AFS_SET_OWNER;
  161. owner = from_kuid(&init_user_ns, attr->ia_uid);
  162. }
  163. if (attr->ia_valid & ATTR_GID) {
  164. mask |= AFS_SET_GROUP;
  165. group = from_kgid(&init_user_ns, attr->ia_gid);
  166. }
  167. if (attr->ia_valid & ATTR_MODE) {
  168. mask |= AFS_SET_MODE;
  169. mode = attr->ia_mode & S_IALLUGO;
  170. }
  171. *bp++ = htonl(mask);
  172. *bp++ = htonl(mtime);
  173. *bp++ = htonl(owner);
  174. *bp++ = htonl(group);
  175. *bp++ = htonl(mode);
  176. *bp++ = 0; /* segment size */
  177. *_bp = bp;
  178. }
  179. /*
  180. * decode an AFSFetchVolumeStatus block
  181. */
  182. static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
  183. struct afs_volume_status *vs)
  184. {
  185. const __be32 *bp = *_bp;
  186. vs->vid = ntohl(*bp++);
  187. vs->parent_id = ntohl(*bp++);
  188. vs->online = ntohl(*bp++);
  189. vs->in_service = ntohl(*bp++);
  190. vs->blessed = ntohl(*bp++);
  191. vs->needs_salvage = ntohl(*bp++);
  192. vs->type = ntohl(*bp++);
  193. vs->min_quota = ntohl(*bp++);
  194. vs->max_quota = ntohl(*bp++);
  195. vs->blocks_in_use = ntohl(*bp++);
  196. vs->part_blocks_avail = ntohl(*bp++);
  197. vs->part_max_blocks = ntohl(*bp++);
  198. vs->vol_copy_date = 0;
  199. vs->vol_backup_date = 0;
  200. *_bp = bp;
  201. }
  202. /*
  203. * deliver reply data to an FS.FetchStatus
  204. */
  205. static int afs_deliver_fs_fetch_status(struct afs_call *call)
  206. {
  207. struct afs_operation *op = call->op;
  208. struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
  209. const __be32 *bp;
  210. int ret;
  211. ret = afs_transfer_reply(call);
  212. if (ret < 0)
  213. return ret;
  214. /* unmarshall the reply once we've received all of it */
  215. bp = call->buffer;
  216. xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
  217. xdr_decode_AFSCallBack(&bp, call, &vp->scb);
  218. xdr_decode_AFSVolSync(&bp, &op->volsync);
  219. _leave(" = 0 [done]");
  220. return 0;
  221. }
  222. /*
  223. * FS.FetchStatus operation type
  224. */
  225. static const struct afs_call_type afs_RXFSFetchStatus = {
  226. .name = "FS.FetchStatus",
  227. .op = afs_FS_FetchStatus,
  228. .deliver = afs_deliver_fs_fetch_status,
  229. .destructor = afs_flat_call_destructor,
  230. };
  231. /*
  232. * fetch the status information for a file
  233. */
  234. void afs_fs_fetch_status(struct afs_operation *op)
  235. {
  236. struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
  237. struct afs_call *call;
  238. __be32 *bp;
  239. _enter(",%x,{%llx:%llu},,",
  240. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  241. call = afs_alloc_flat_call(op->net, &afs_RXFSFetchStatus,
  242. 16, (21 + 3 + 6) * 4);
  243. if (!call)
  244. return afs_op_nomem(op);
  245. /* marshall the parameters */
  246. bp = call->request;
  247. bp[0] = htonl(FSFETCHSTATUS);
  248. bp[1] = htonl(vp->fid.vid);
  249. bp[2] = htonl(vp->fid.vnode);
  250. bp[3] = htonl(vp->fid.unique);
  251. trace_afs_make_fs_call(call, &vp->fid);
  252. afs_make_op_call(op, call, GFP_NOFS);
  253. }
  254. /*
  255. * deliver reply data to an FS.FetchData
  256. */
  257. static int afs_deliver_fs_fetch_data(struct afs_call *call)
  258. {
  259. struct afs_operation *op = call->op;
  260. struct afs_vnode_param *vp = &op->file[0];
  261. struct afs_read *req = op->fetch.req;
  262. const __be32 *bp;
  263. unsigned int size;
  264. int ret;
  265. _enter("{%u,%zu/%llu}",
  266. call->unmarshall, iov_iter_count(call->iter), req->actual_len);
  267. switch (call->unmarshall) {
  268. case 0:
  269. req->actual_len = 0;
  270. req->index = 0;
  271. req->offset = req->pos & (PAGE_SIZE - 1);
  272. call->unmarshall++;
  273. if (call->operation_ID == FSFETCHDATA64) {
  274. afs_extract_to_tmp64(call);
  275. } else {
  276. call->tmp_u = htonl(0);
  277. afs_extract_to_tmp(call);
  278. }
  279. fallthrough;
  280. /* extract the returned data length */
  281. case 1:
  282. _debug("extract data length");
  283. ret = afs_extract_data(call, true);
  284. if (ret < 0)
  285. return ret;
  286. req->actual_len = be64_to_cpu(call->tmp64);
  287. _debug("DATA length: %llu", req->actual_len);
  288. req->remain = min(req->len, req->actual_len);
  289. if (req->remain == 0)
  290. goto no_more_data;
  291. call->unmarshall++;
  292. begin_page:
  293. ASSERTCMP(req->index, <, req->nr_pages);
  294. if (req->remain > PAGE_SIZE - req->offset)
  295. size = PAGE_SIZE - req->offset;
  296. else
  297. size = req->remain;
  298. call->bvec[0].bv_len = size;
  299. call->bvec[0].bv_offset = req->offset;
  300. call->bvec[0].bv_page = req->pages[req->index];
  301. iov_iter_bvec(&call->def_iter, READ, call->bvec, 1, size);
  302. ASSERTCMP(size, <=, PAGE_SIZE);
  303. fallthrough;
  304. /* extract the returned data */
  305. case 2:
  306. _debug("extract data %zu/%llu",
  307. iov_iter_count(call->iter), req->remain);
  308. ret = afs_extract_data(call, true);
  309. if (ret < 0)
  310. return ret;
  311. req->remain -= call->bvec[0].bv_len;
  312. req->offset += call->bvec[0].bv_len;
  313. ASSERTCMP(req->offset, <=, PAGE_SIZE);
  314. if (req->offset == PAGE_SIZE) {
  315. req->offset = 0;
  316. req->index++;
  317. if (req->remain > 0)
  318. goto begin_page;
  319. }
  320. ASSERTCMP(req->remain, ==, 0);
  321. if (req->actual_len <= req->len)
  322. goto no_more_data;
  323. /* Discard any excess data the server gave us */
  324. afs_extract_discard(call, req->actual_len - req->len);
  325. call->unmarshall = 3;
  326. fallthrough;
  327. case 3:
  328. _debug("extract discard %zu/%llu",
  329. iov_iter_count(call->iter), req->actual_len - req->len);
  330. ret = afs_extract_data(call, true);
  331. if (ret < 0)
  332. return ret;
  333. no_more_data:
  334. call->unmarshall = 4;
  335. afs_extract_to_buf(call, (21 + 3 + 6) * 4);
  336. fallthrough;
  337. /* extract the metadata */
  338. case 4:
  339. ret = afs_extract_data(call, false);
  340. if (ret < 0)
  341. return ret;
  342. bp = call->buffer;
  343. xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
  344. xdr_decode_AFSCallBack(&bp, call, &vp->scb);
  345. xdr_decode_AFSVolSync(&bp, &op->volsync);
  346. req->data_version = vp->scb.status.data_version;
  347. req->file_size = vp->scb.status.size;
  348. call->unmarshall++;
  349. case 5:
  350. break;
  351. }
  352. for (; req->index < req->nr_pages; req->index++) {
  353. if (req->offset < PAGE_SIZE)
  354. zero_user_segment(req->pages[req->index],
  355. req->offset, PAGE_SIZE);
  356. req->offset = 0;
  357. }
  358. if (req->page_done)
  359. for (req->index = 0; req->index < req->nr_pages; req->index++)
  360. req->page_done(req);
  361. _leave(" = 0 [done]");
  362. return 0;
  363. }
  364. /*
  365. * FS.FetchData operation type
  366. */
  367. static const struct afs_call_type afs_RXFSFetchData = {
  368. .name = "FS.FetchData",
  369. .op = afs_FS_FetchData,
  370. .deliver = afs_deliver_fs_fetch_data,
  371. .destructor = afs_flat_call_destructor,
  372. };
  373. static const struct afs_call_type afs_RXFSFetchData64 = {
  374. .name = "FS.FetchData64",
  375. .op = afs_FS_FetchData64,
  376. .deliver = afs_deliver_fs_fetch_data,
  377. .destructor = afs_flat_call_destructor,
  378. };
  379. /*
  380. * fetch data from a very large file
  381. */
  382. static void afs_fs_fetch_data64(struct afs_operation *op)
  383. {
  384. struct afs_vnode_param *vp = &op->file[0];
  385. struct afs_read *req = op->fetch.req;
  386. struct afs_call *call;
  387. __be32 *bp;
  388. _enter("");
  389. call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
  390. if (!call)
  391. return afs_op_nomem(op);
  392. /* marshall the parameters */
  393. bp = call->request;
  394. bp[0] = htonl(FSFETCHDATA64);
  395. bp[1] = htonl(vp->fid.vid);
  396. bp[2] = htonl(vp->fid.vnode);
  397. bp[3] = htonl(vp->fid.unique);
  398. bp[4] = htonl(upper_32_bits(req->pos));
  399. bp[5] = htonl(lower_32_bits(req->pos));
  400. bp[6] = 0;
  401. bp[7] = htonl(lower_32_bits(req->len));
  402. trace_afs_make_fs_call(call, &vp->fid);
  403. afs_make_op_call(op, call, GFP_NOFS);
  404. }
  405. /*
  406. * fetch data from a file
  407. */
  408. void afs_fs_fetch_data(struct afs_operation *op)
  409. {
  410. struct afs_vnode_param *vp = &op->file[0];
  411. struct afs_call *call;
  412. struct afs_read *req = op->fetch.req;
  413. __be32 *bp;
  414. if (upper_32_bits(req->pos) ||
  415. upper_32_bits(req->len) ||
  416. upper_32_bits(req->pos + req->len))
  417. return afs_fs_fetch_data64(op);
  418. _enter("");
  419. call = afs_alloc_flat_call(op->net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
  420. if (!call)
  421. return afs_op_nomem(op);
  422. /* marshall the parameters */
  423. bp = call->request;
  424. bp[0] = htonl(FSFETCHDATA);
  425. bp[1] = htonl(vp->fid.vid);
  426. bp[2] = htonl(vp->fid.vnode);
  427. bp[3] = htonl(vp->fid.unique);
  428. bp[4] = htonl(lower_32_bits(req->pos));
  429. bp[5] = htonl(lower_32_bits(req->len));
  430. trace_afs_make_fs_call(call, &vp->fid);
  431. afs_make_op_call(op, call, GFP_NOFS);
  432. }
  433. /*
  434. * deliver reply data to an FS.CreateFile or an FS.MakeDir
  435. */
  436. static int afs_deliver_fs_create_vnode(struct afs_call *call)
  437. {
  438. struct afs_operation *op = call->op;
  439. struct afs_vnode_param *dvp = &op->file[0];
  440. struct afs_vnode_param *vp = &op->file[1];
  441. const __be32 *bp;
  442. int ret;
  443. ret = afs_transfer_reply(call);
  444. if (ret < 0)
  445. return ret;
  446. /* unmarshall the reply once we've received all of it */
  447. bp = call->buffer;
  448. xdr_decode_AFSFid(&bp, &op->file[1].fid);
  449. xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
  450. xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
  451. xdr_decode_AFSCallBack(&bp, call, &vp->scb);
  452. xdr_decode_AFSVolSync(&bp, &op->volsync);
  453. _leave(" = 0 [done]");
  454. return 0;
  455. }
  456. /*
  457. * FS.CreateFile and FS.MakeDir operation type
  458. */
  459. static const struct afs_call_type afs_RXFSCreateFile = {
  460. .name = "FS.CreateFile",
  461. .op = afs_FS_CreateFile,
  462. .deliver = afs_deliver_fs_create_vnode,
  463. .destructor = afs_flat_call_destructor,
  464. };
  465. /*
  466. * Create a file.
  467. */
  468. void afs_fs_create_file(struct afs_operation *op)
  469. {
  470. const struct qstr *name = &op->dentry->d_name;
  471. struct afs_vnode_param *dvp = &op->file[0];
  472. struct afs_call *call;
  473. size_t namesz, reqsz, padsz;
  474. __be32 *bp;
  475. _enter("");
  476. namesz = name->len;
  477. padsz = (4 - (namesz & 3)) & 3;
  478. reqsz = (5 * 4) + namesz + padsz + (6 * 4);
  479. call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile,
  480. reqsz, (3 + 21 + 21 + 3 + 6) * 4);
  481. if (!call)
  482. return afs_op_nomem(op);
  483. /* marshall the parameters */
  484. bp = call->request;
  485. *bp++ = htonl(FSCREATEFILE);
  486. *bp++ = htonl(dvp->fid.vid);
  487. *bp++ = htonl(dvp->fid.vnode);
  488. *bp++ = htonl(dvp->fid.unique);
  489. *bp++ = htonl(namesz);
  490. memcpy(bp, name->name, namesz);
  491. bp = (void *) bp + namesz;
  492. if (padsz > 0) {
  493. memset(bp, 0, padsz);
  494. bp = (void *) bp + padsz;
  495. }
  496. *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
  497. *bp++ = htonl(op->mtime.tv_sec); /* mtime */
  498. *bp++ = 0; /* owner */
  499. *bp++ = 0; /* group */
  500. *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
  501. *bp++ = 0; /* segment size */
  502. trace_afs_make_fs_call1(call, &dvp->fid, name);
  503. afs_make_op_call(op, call, GFP_NOFS);
  504. }
  505. static const struct afs_call_type afs_RXFSMakeDir = {
  506. .name = "FS.MakeDir",
  507. .op = afs_FS_MakeDir,
  508. .deliver = afs_deliver_fs_create_vnode,
  509. .destructor = afs_flat_call_destructor,
  510. };
  511. /*
  512. * Create a new directory
  513. */
  514. void afs_fs_make_dir(struct afs_operation *op)
  515. {
  516. const struct qstr *name = &op->dentry->d_name;
  517. struct afs_vnode_param *dvp = &op->file[0];
  518. struct afs_call *call;
  519. size_t namesz, reqsz, padsz;
  520. __be32 *bp;
  521. _enter("");
  522. namesz = name->len;
  523. padsz = (4 - (namesz & 3)) & 3;
  524. reqsz = (5 * 4) + namesz + padsz + (6 * 4);
  525. call = afs_alloc_flat_call(op->net, &afs_RXFSMakeDir,
  526. reqsz, (3 + 21 + 21 + 3 + 6) * 4);
  527. if (!call)
  528. return afs_op_nomem(op);
  529. /* marshall the parameters */
  530. bp = call->request;
  531. *bp++ = htonl(FSMAKEDIR);
  532. *bp++ = htonl(dvp->fid.vid);
  533. *bp++ = htonl(dvp->fid.vnode);
  534. *bp++ = htonl(dvp->fid.unique);
  535. *bp++ = htonl(namesz);
  536. memcpy(bp, name->name, namesz);
  537. bp = (void *) bp + namesz;
  538. if (padsz > 0) {
  539. memset(bp, 0, padsz);
  540. bp = (void *) bp + padsz;
  541. }
  542. *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
  543. *bp++ = htonl(op->mtime.tv_sec); /* mtime */
  544. *bp++ = 0; /* owner */
  545. *bp++ = 0; /* group */
  546. *bp++ = htonl(op->create.mode & S_IALLUGO); /* unix mode */
  547. *bp++ = 0; /* segment size */
  548. trace_afs_make_fs_call1(call, &dvp->fid, name);
  549. afs_make_op_call(op, call, GFP_NOFS);
  550. }
  551. /*
  552. * Deliver reply data to any operation that returns status and volume sync.
  553. */
  554. static int afs_deliver_fs_file_status_and_vol(struct afs_call *call)
  555. {
  556. struct afs_operation *op = call->op;
  557. struct afs_vnode_param *vp = &op->file[0];
  558. const __be32 *bp;
  559. int ret;
  560. ret = afs_transfer_reply(call);
  561. if (ret < 0)
  562. return ret;
  563. /* unmarshall the reply once we've received all of it */
  564. bp = call->buffer;
  565. xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
  566. xdr_decode_AFSVolSync(&bp, &op->volsync);
  567. _leave(" = 0 [done]");
  568. return 0;
  569. }
  570. /*
  571. * FS.RemoveFile operation type
  572. */
  573. static const struct afs_call_type afs_RXFSRemoveFile = {
  574. .name = "FS.RemoveFile",
  575. .op = afs_FS_RemoveFile,
  576. .deliver = afs_deliver_fs_file_status_and_vol,
  577. .destructor = afs_flat_call_destructor,
  578. };
  579. /*
  580. * Remove a file.
  581. */
  582. void afs_fs_remove_file(struct afs_operation *op)
  583. {
  584. const struct qstr *name = &op->dentry->d_name;
  585. struct afs_vnode_param *dvp = &op->file[0];
  586. struct afs_call *call;
  587. size_t namesz, reqsz, padsz;
  588. __be32 *bp;
  589. _enter("");
  590. namesz = name->len;
  591. padsz = (4 - (namesz & 3)) & 3;
  592. reqsz = (5 * 4) + namesz + padsz;
  593. call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveFile,
  594. reqsz, (21 + 6) * 4);
  595. if (!call)
  596. return afs_op_nomem(op);
  597. /* marshall the parameters */
  598. bp = call->request;
  599. *bp++ = htonl(FSREMOVEFILE);
  600. *bp++ = htonl(dvp->fid.vid);
  601. *bp++ = htonl(dvp->fid.vnode);
  602. *bp++ = htonl(dvp->fid.unique);
  603. *bp++ = htonl(namesz);
  604. memcpy(bp, name->name, namesz);
  605. bp = (void *) bp + namesz;
  606. if (padsz > 0) {
  607. memset(bp, 0, padsz);
  608. bp = (void *) bp + padsz;
  609. }
  610. trace_afs_make_fs_call1(call, &dvp->fid, name);
  611. afs_make_op_call(op, call, GFP_NOFS);
  612. }
  613. static const struct afs_call_type afs_RXFSRemoveDir = {
  614. .name = "FS.RemoveDir",
  615. .op = afs_FS_RemoveDir,
  616. .deliver = afs_deliver_fs_file_status_and_vol,
  617. .destructor = afs_flat_call_destructor,
  618. };
  619. /*
  620. * Remove a directory.
  621. */
  622. void afs_fs_remove_dir(struct afs_operation *op)
  623. {
  624. const struct qstr *name = &op->dentry->d_name;
  625. struct afs_vnode_param *dvp = &op->file[0];
  626. struct afs_call *call;
  627. size_t namesz, reqsz, padsz;
  628. __be32 *bp;
  629. _enter("");
  630. namesz = name->len;
  631. padsz = (4 - (namesz & 3)) & 3;
  632. reqsz = (5 * 4) + namesz + padsz;
  633. call = afs_alloc_flat_call(op->net, &afs_RXFSRemoveDir,
  634. reqsz, (21 + 6) * 4);
  635. if (!call)
  636. return afs_op_nomem(op);
  637. /* marshall the parameters */
  638. bp = call->request;
  639. *bp++ = htonl(FSREMOVEDIR);
  640. *bp++ = htonl(dvp->fid.vid);
  641. *bp++ = htonl(dvp->fid.vnode);
  642. *bp++ = htonl(dvp->fid.unique);
  643. *bp++ = htonl(namesz);
  644. memcpy(bp, name->name, namesz);
  645. bp = (void *) bp + namesz;
  646. if (padsz > 0) {
  647. memset(bp, 0, padsz);
  648. bp = (void *) bp + padsz;
  649. }
  650. trace_afs_make_fs_call1(call, &dvp->fid, name);
  651. afs_make_op_call(op, call, GFP_NOFS);
  652. }
  653. /*
  654. * deliver reply data to an FS.Link
  655. */
  656. static int afs_deliver_fs_link(struct afs_call *call)
  657. {
  658. struct afs_operation *op = call->op;
  659. struct afs_vnode_param *dvp = &op->file[0];
  660. struct afs_vnode_param *vp = &op->file[1];
  661. const __be32 *bp;
  662. int ret;
  663. _enter("{%u}", call->unmarshall);
  664. ret = afs_transfer_reply(call);
  665. if (ret < 0)
  666. return ret;
  667. /* unmarshall the reply once we've received all of it */
  668. bp = call->buffer;
  669. xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
  670. xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
  671. xdr_decode_AFSVolSync(&bp, &op->volsync);
  672. _leave(" = 0 [done]");
  673. return 0;
  674. }
  675. /*
  676. * FS.Link operation type
  677. */
  678. static const struct afs_call_type afs_RXFSLink = {
  679. .name = "FS.Link",
  680. .op = afs_FS_Link,
  681. .deliver = afs_deliver_fs_link,
  682. .destructor = afs_flat_call_destructor,
  683. };
  684. /*
  685. * make a hard link
  686. */
  687. void afs_fs_link(struct afs_operation *op)
  688. {
  689. const struct qstr *name = &op->dentry->d_name;
  690. struct afs_vnode_param *dvp = &op->file[0];
  691. struct afs_vnode_param *vp = &op->file[1];
  692. struct afs_call *call;
  693. size_t namesz, reqsz, padsz;
  694. __be32 *bp;
  695. _enter("");
  696. namesz = name->len;
  697. padsz = (4 - (namesz & 3)) & 3;
  698. reqsz = (5 * 4) + namesz + padsz + (3 * 4);
  699. call = afs_alloc_flat_call(op->net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
  700. if (!call)
  701. return afs_op_nomem(op);
  702. /* marshall the parameters */
  703. bp = call->request;
  704. *bp++ = htonl(FSLINK);
  705. *bp++ = htonl(dvp->fid.vid);
  706. *bp++ = htonl(dvp->fid.vnode);
  707. *bp++ = htonl(dvp->fid.unique);
  708. *bp++ = htonl(namesz);
  709. memcpy(bp, name->name, namesz);
  710. bp = (void *) bp + namesz;
  711. if (padsz > 0) {
  712. memset(bp, 0, padsz);
  713. bp = (void *) bp + padsz;
  714. }
  715. *bp++ = htonl(vp->fid.vid);
  716. *bp++ = htonl(vp->fid.vnode);
  717. *bp++ = htonl(vp->fid.unique);
  718. trace_afs_make_fs_call1(call, &vp->fid, name);
  719. afs_make_op_call(op, call, GFP_NOFS);
  720. }
  721. /*
  722. * deliver reply data to an FS.Symlink
  723. */
  724. static int afs_deliver_fs_symlink(struct afs_call *call)
  725. {
  726. struct afs_operation *op = call->op;
  727. struct afs_vnode_param *dvp = &op->file[0];
  728. struct afs_vnode_param *vp = &op->file[1];
  729. const __be32 *bp;
  730. int ret;
  731. _enter("{%u}", call->unmarshall);
  732. ret = afs_transfer_reply(call);
  733. if (ret < 0)
  734. return ret;
  735. /* unmarshall the reply once we've received all of it */
  736. bp = call->buffer;
  737. xdr_decode_AFSFid(&bp, &vp->fid);
  738. xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
  739. xdr_decode_AFSFetchStatus(&bp, call, &dvp->scb);
  740. xdr_decode_AFSVolSync(&bp, &op->volsync);
  741. _leave(" = 0 [done]");
  742. return 0;
  743. }
  744. /*
  745. * FS.Symlink operation type
  746. */
  747. static const struct afs_call_type afs_RXFSSymlink = {
  748. .name = "FS.Symlink",
  749. .op = afs_FS_Symlink,
  750. .deliver = afs_deliver_fs_symlink,
  751. .destructor = afs_flat_call_destructor,
  752. };
  753. /*
  754. * create a symbolic link
  755. */
  756. void afs_fs_symlink(struct afs_operation *op)
  757. {
  758. const struct qstr *name = &op->dentry->d_name;
  759. struct afs_vnode_param *dvp = &op->file[0];
  760. struct afs_call *call;
  761. size_t namesz, reqsz, padsz, c_namesz, c_padsz;
  762. __be32 *bp;
  763. _enter("");
  764. namesz = name->len;
  765. padsz = (4 - (namesz & 3)) & 3;
  766. c_namesz = strlen(op->create.symlink);
  767. c_padsz = (4 - (c_namesz & 3)) & 3;
  768. reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
  769. call = afs_alloc_flat_call(op->net, &afs_RXFSSymlink, reqsz,
  770. (3 + 21 + 21 + 6) * 4);
  771. if (!call)
  772. return afs_op_nomem(op);
  773. /* marshall the parameters */
  774. bp = call->request;
  775. *bp++ = htonl(FSSYMLINK);
  776. *bp++ = htonl(dvp->fid.vid);
  777. *bp++ = htonl(dvp->fid.vnode);
  778. *bp++ = htonl(dvp->fid.unique);
  779. *bp++ = htonl(namesz);
  780. memcpy(bp, name->name, namesz);
  781. bp = (void *) bp + namesz;
  782. if (padsz > 0) {
  783. memset(bp, 0, padsz);
  784. bp = (void *) bp + padsz;
  785. }
  786. *bp++ = htonl(c_namesz);
  787. memcpy(bp, op->create.symlink, c_namesz);
  788. bp = (void *) bp + c_namesz;
  789. if (c_padsz > 0) {
  790. memset(bp, 0, c_padsz);
  791. bp = (void *) bp + c_padsz;
  792. }
  793. *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
  794. *bp++ = htonl(op->mtime.tv_sec); /* mtime */
  795. *bp++ = 0; /* owner */
  796. *bp++ = 0; /* group */
  797. *bp++ = htonl(S_IRWXUGO); /* unix mode */
  798. *bp++ = 0; /* segment size */
  799. trace_afs_make_fs_call1(call, &dvp->fid, name);
  800. afs_make_op_call(op, call, GFP_NOFS);
  801. }
  802. /*
  803. * deliver reply data to an FS.Rename
  804. */
  805. static int afs_deliver_fs_rename(struct afs_call *call)
  806. {
  807. struct afs_operation *op = call->op;
  808. struct afs_vnode_param *orig_dvp = &op->file[0];
  809. struct afs_vnode_param *new_dvp = &op->file[1];
  810. const __be32 *bp;
  811. int ret;
  812. ret = afs_transfer_reply(call);
  813. if (ret < 0)
  814. return ret;
  815. bp = call->buffer;
  816. /* If the two dirs are the same, we have two copies of the same status
  817. * report, so we just decode it twice.
  818. */
  819. xdr_decode_AFSFetchStatus(&bp, call, &orig_dvp->scb);
  820. xdr_decode_AFSFetchStatus(&bp, call, &new_dvp->scb);
  821. xdr_decode_AFSVolSync(&bp, &op->volsync);
  822. _leave(" = 0 [done]");
  823. return 0;
  824. }
  825. /*
  826. * FS.Rename operation type
  827. */
  828. static const struct afs_call_type afs_RXFSRename = {
  829. .name = "FS.Rename",
  830. .op = afs_FS_Rename,
  831. .deliver = afs_deliver_fs_rename,
  832. .destructor = afs_flat_call_destructor,
  833. };
  834. /*
  835. * Rename/move a file or directory.
  836. */
  837. void afs_fs_rename(struct afs_operation *op)
  838. {
  839. struct afs_vnode_param *orig_dvp = &op->file[0];
  840. struct afs_vnode_param *new_dvp = &op->file[1];
  841. const struct qstr *orig_name = &op->dentry->d_name;
  842. const struct qstr *new_name = &op->dentry_2->d_name;
  843. struct afs_call *call;
  844. size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
  845. __be32 *bp;
  846. _enter("");
  847. o_namesz = orig_name->len;
  848. o_padsz = (4 - (o_namesz & 3)) & 3;
  849. n_namesz = new_name->len;
  850. n_padsz = (4 - (n_namesz & 3)) & 3;
  851. reqsz = (4 * 4) +
  852. 4 + o_namesz + o_padsz +
  853. (3 * 4) +
  854. 4 + n_namesz + n_padsz;
  855. call = afs_alloc_flat_call(op->net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
  856. if (!call)
  857. return afs_op_nomem(op);
  858. /* marshall the parameters */
  859. bp = call->request;
  860. *bp++ = htonl(FSRENAME);
  861. *bp++ = htonl(orig_dvp->fid.vid);
  862. *bp++ = htonl(orig_dvp->fid.vnode);
  863. *bp++ = htonl(orig_dvp->fid.unique);
  864. *bp++ = htonl(o_namesz);
  865. memcpy(bp, orig_name->name, o_namesz);
  866. bp = (void *) bp + o_namesz;
  867. if (o_padsz > 0) {
  868. memset(bp, 0, o_padsz);
  869. bp = (void *) bp + o_padsz;
  870. }
  871. *bp++ = htonl(new_dvp->fid.vid);
  872. *bp++ = htonl(new_dvp->fid.vnode);
  873. *bp++ = htonl(new_dvp->fid.unique);
  874. *bp++ = htonl(n_namesz);
  875. memcpy(bp, new_name->name, n_namesz);
  876. bp = (void *) bp + n_namesz;
  877. if (n_padsz > 0) {
  878. memset(bp, 0, n_padsz);
  879. bp = (void *) bp + n_padsz;
  880. }
  881. trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
  882. afs_make_op_call(op, call, GFP_NOFS);
  883. }
  884. /*
  885. * Deliver reply data to FS.StoreData or FS.StoreStatus
  886. */
  887. static int afs_deliver_fs_store_data(struct afs_call *call)
  888. {
  889. struct afs_operation *op = call->op;
  890. struct afs_vnode_param *vp = &op->file[0];
  891. const __be32 *bp;
  892. int ret;
  893. _enter("");
  894. ret = afs_transfer_reply(call);
  895. if (ret < 0)
  896. return ret;
  897. /* unmarshall the reply once we've received all of it */
  898. bp = call->buffer;
  899. xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
  900. xdr_decode_AFSVolSync(&bp, &op->volsync);
  901. _leave(" = 0 [done]");
  902. return 0;
  903. }
  904. /*
  905. * FS.StoreData operation type
  906. */
  907. static const struct afs_call_type afs_RXFSStoreData = {
  908. .name = "FS.StoreData",
  909. .op = afs_FS_StoreData,
  910. .deliver = afs_deliver_fs_store_data,
  911. .destructor = afs_flat_call_destructor,
  912. };
  913. static const struct afs_call_type afs_RXFSStoreData64 = {
  914. .name = "FS.StoreData64",
  915. .op = afs_FS_StoreData64,
  916. .deliver = afs_deliver_fs_store_data,
  917. .destructor = afs_flat_call_destructor,
  918. };
  919. /*
  920. * store a set of pages to a very large file
  921. */
  922. static void afs_fs_store_data64(struct afs_operation *op,
  923. loff_t pos, loff_t size, loff_t i_size)
  924. {
  925. struct afs_vnode_param *vp = &op->file[0];
  926. struct afs_call *call;
  927. __be32 *bp;
  928. _enter(",%x,{%llx:%llu},,",
  929. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  930. call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64,
  931. (4 + 6 + 3 * 2) * 4,
  932. (21 + 6) * 4);
  933. if (!call)
  934. return afs_op_nomem(op);
  935. call->send_pages = true;
  936. /* marshall the parameters */
  937. bp = call->request;
  938. *bp++ = htonl(FSSTOREDATA64);
  939. *bp++ = htonl(vp->fid.vid);
  940. *bp++ = htonl(vp->fid.vnode);
  941. *bp++ = htonl(vp->fid.unique);
  942. *bp++ = htonl(AFS_SET_MTIME); /* mask */
  943. *bp++ = htonl(op->mtime.tv_sec); /* mtime */
  944. *bp++ = 0; /* owner */
  945. *bp++ = 0; /* group */
  946. *bp++ = 0; /* unix mode */
  947. *bp++ = 0; /* segment size */
  948. *bp++ = htonl(upper_32_bits(pos));
  949. *bp++ = htonl(lower_32_bits(pos));
  950. *bp++ = htonl(upper_32_bits(size));
  951. *bp++ = htonl(lower_32_bits(size));
  952. *bp++ = htonl(upper_32_bits(i_size));
  953. *bp++ = htonl(lower_32_bits(i_size));
  954. trace_afs_make_fs_call(call, &vp->fid);
  955. afs_make_op_call(op, call, GFP_NOFS);
  956. }
  957. /*
  958. * store a set of pages
  959. */
  960. void afs_fs_store_data(struct afs_operation *op)
  961. {
  962. struct afs_vnode_param *vp = &op->file[0];
  963. struct afs_call *call;
  964. loff_t size, pos, i_size;
  965. __be32 *bp;
  966. _enter(",%x,{%llx:%llu},,",
  967. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  968. size = (loff_t)op->store.last_to - (loff_t)op->store.first_offset;
  969. if (op->store.first != op->store.last)
  970. size += (loff_t)(op->store.last - op->store.first) << PAGE_SHIFT;
  971. pos = (loff_t)op->store.first << PAGE_SHIFT;
  972. pos += op->store.first_offset;
  973. i_size = i_size_read(&vp->vnode->vfs_inode);
  974. if (pos + size > i_size)
  975. i_size = size + pos;
  976. _debug("size %llx, at %llx, i_size %llx",
  977. (unsigned long long) size, (unsigned long long) pos,
  978. (unsigned long long) i_size);
  979. if (upper_32_bits(pos) || upper_32_bits(i_size) || upper_32_bits(size) ||
  980. upper_32_bits(pos + size))
  981. return afs_fs_store_data64(op, pos, size, i_size);
  982. call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData,
  983. (4 + 6 + 3) * 4,
  984. (21 + 6) * 4);
  985. if (!call)
  986. return afs_op_nomem(op);
  987. call->send_pages = true;
  988. /* marshall the parameters */
  989. bp = call->request;
  990. *bp++ = htonl(FSSTOREDATA);
  991. *bp++ = htonl(vp->fid.vid);
  992. *bp++ = htonl(vp->fid.vnode);
  993. *bp++ = htonl(vp->fid.unique);
  994. *bp++ = htonl(AFS_SET_MTIME); /* mask */
  995. *bp++ = htonl(op->mtime.tv_sec); /* mtime */
  996. *bp++ = 0; /* owner */
  997. *bp++ = 0; /* group */
  998. *bp++ = 0; /* unix mode */
  999. *bp++ = 0; /* segment size */
  1000. *bp++ = htonl(lower_32_bits(pos));
  1001. *bp++ = htonl(lower_32_bits(size));
  1002. *bp++ = htonl(lower_32_bits(i_size));
  1003. trace_afs_make_fs_call(call, &vp->fid);
  1004. afs_make_op_call(op, call, GFP_NOFS);
  1005. }
  1006. /*
  1007. * FS.StoreStatus operation type
  1008. */
  1009. static const struct afs_call_type afs_RXFSStoreStatus = {
  1010. .name = "FS.StoreStatus",
  1011. .op = afs_FS_StoreStatus,
  1012. .deliver = afs_deliver_fs_store_data,
  1013. .destructor = afs_flat_call_destructor,
  1014. };
  1015. static const struct afs_call_type afs_RXFSStoreData_as_Status = {
  1016. .name = "FS.StoreData",
  1017. .op = afs_FS_StoreData,
  1018. .deliver = afs_deliver_fs_store_data,
  1019. .destructor = afs_flat_call_destructor,
  1020. };
  1021. static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
  1022. .name = "FS.StoreData64",
  1023. .op = afs_FS_StoreData64,
  1024. .deliver = afs_deliver_fs_store_data,
  1025. .destructor = afs_flat_call_destructor,
  1026. };
  1027. /*
  1028. * set the attributes on a very large file, using FS.StoreData rather than
  1029. * FS.StoreStatus so as to alter the file size also
  1030. */
  1031. static void afs_fs_setattr_size64(struct afs_operation *op)
  1032. {
  1033. struct afs_vnode_param *vp = &op->file[0];
  1034. struct afs_call *call;
  1035. struct iattr *attr = op->setattr.attr;
  1036. __be32 *bp;
  1037. _enter(",%x,{%llx:%llu},,",
  1038. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1039. ASSERT(attr->ia_valid & ATTR_SIZE);
  1040. call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData64_as_Status,
  1041. (4 + 6 + 3 * 2) * 4,
  1042. (21 + 6) * 4);
  1043. if (!call)
  1044. return afs_op_nomem(op);
  1045. /* marshall the parameters */
  1046. bp = call->request;
  1047. *bp++ = htonl(FSSTOREDATA64);
  1048. *bp++ = htonl(vp->fid.vid);
  1049. *bp++ = htonl(vp->fid.vnode);
  1050. *bp++ = htonl(vp->fid.unique);
  1051. xdr_encode_AFS_StoreStatus(&bp, attr);
  1052. *bp++ = htonl(upper_32_bits(attr->ia_size)); /* position of start of write */
  1053. *bp++ = htonl(lower_32_bits(attr->ia_size));
  1054. *bp++ = 0; /* size of write */
  1055. *bp++ = 0;
  1056. *bp++ = htonl(upper_32_bits(attr->ia_size)); /* new file length */
  1057. *bp++ = htonl(lower_32_bits(attr->ia_size));
  1058. trace_afs_make_fs_call(call, &vp->fid);
  1059. afs_make_op_call(op, call, GFP_NOFS);
  1060. }
  1061. /*
  1062. * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
  1063. * so as to alter the file size also
  1064. */
  1065. static void afs_fs_setattr_size(struct afs_operation *op)
  1066. {
  1067. struct afs_vnode_param *vp = &op->file[0];
  1068. struct afs_call *call;
  1069. struct iattr *attr = op->setattr.attr;
  1070. __be32 *bp;
  1071. _enter(",%x,{%llx:%llu},,",
  1072. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1073. ASSERT(attr->ia_valid & ATTR_SIZE);
  1074. if (upper_32_bits(attr->ia_size))
  1075. return afs_fs_setattr_size64(op);
  1076. call = afs_alloc_flat_call(op->net, &afs_RXFSStoreData_as_Status,
  1077. (4 + 6 + 3) * 4,
  1078. (21 + 6) * 4);
  1079. if (!call)
  1080. return afs_op_nomem(op);
  1081. /* marshall the parameters */
  1082. bp = call->request;
  1083. *bp++ = htonl(FSSTOREDATA);
  1084. *bp++ = htonl(vp->fid.vid);
  1085. *bp++ = htonl(vp->fid.vnode);
  1086. *bp++ = htonl(vp->fid.unique);
  1087. xdr_encode_AFS_StoreStatus(&bp, attr);
  1088. *bp++ = htonl(attr->ia_size); /* position of start of write */
  1089. *bp++ = 0; /* size of write */
  1090. *bp++ = htonl(attr->ia_size); /* new file length */
  1091. trace_afs_make_fs_call(call, &vp->fid);
  1092. afs_make_op_call(op, call, GFP_NOFS);
  1093. }
  1094. /*
  1095. * set the attributes on a file, using FS.StoreData if there's a change in file
  1096. * size, and FS.StoreStatus otherwise
  1097. */
  1098. void afs_fs_setattr(struct afs_operation *op)
  1099. {
  1100. struct afs_vnode_param *vp = &op->file[0];
  1101. struct afs_call *call;
  1102. struct iattr *attr = op->setattr.attr;
  1103. __be32 *bp;
  1104. if (attr->ia_valid & ATTR_SIZE)
  1105. return afs_fs_setattr_size(op);
  1106. _enter(",%x,{%llx:%llu},,",
  1107. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1108. call = afs_alloc_flat_call(op->net, &afs_RXFSStoreStatus,
  1109. (4 + 6) * 4,
  1110. (21 + 6) * 4);
  1111. if (!call)
  1112. return afs_op_nomem(op);
  1113. /* marshall the parameters */
  1114. bp = call->request;
  1115. *bp++ = htonl(FSSTORESTATUS);
  1116. *bp++ = htonl(vp->fid.vid);
  1117. *bp++ = htonl(vp->fid.vnode);
  1118. *bp++ = htonl(vp->fid.unique);
  1119. xdr_encode_AFS_StoreStatus(&bp, op->setattr.attr);
  1120. trace_afs_make_fs_call(call, &vp->fid);
  1121. afs_make_op_call(op, call, GFP_NOFS);
  1122. }
  1123. /*
  1124. * deliver reply data to an FS.GetVolumeStatus
  1125. */
  1126. static int afs_deliver_fs_get_volume_status(struct afs_call *call)
  1127. {
  1128. struct afs_operation *op = call->op;
  1129. const __be32 *bp;
  1130. char *p;
  1131. u32 size;
  1132. int ret;
  1133. _enter("{%u}", call->unmarshall);
  1134. switch (call->unmarshall) {
  1135. case 0:
  1136. call->unmarshall++;
  1137. afs_extract_to_buf(call, 12 * 4);
  1138. fallthrough;
  1139. /* extract the returned status record */
  1140. case 1:
  1141. _debug("extract status");
  1142. ret = afs_extract_data(call, true);
  1143. if (ret < 0)
  1144. return ret;
  1145. bp = call->buffer;
  1146. xdr_decode_AFSFetchVolumeStatus(&bp, &op->volstatus.vs);
  1147. call->unmarshall++;
  1148. afs_extract_to_tmp(call);
  1149. fallthrough;
  1150. /* extract the volume name length */
  1151. case 2:
  1152. ret = afs_extract_data(call, true);
  1153. if (ret < 0)
  1154. return ret;
  1155. call->count = ntohl(call->tmp);
  1156. _debug("volname length: %u", call->count);
  1157. if (call->count >= AFSNAMEMAX)
  1158. return afs_protocol_error(call, afs_eproto_volname_len);
  1159. size = (call->count + 3) & ~3; /* It's padded */
  1160. afs_extract_to_buf(call, size);
  1161. call->unmarshall++;
  1162. fallthrough;
  1163. /* extract the volume name */
  1164. case 3:
  1165. _debug("extract volname");
  1166. ret = afs_extract_data(call, true);
  1167. if (ret < 0)
  1168. return ret;
  1169. p = call->buffer;
  1170. p[call->count] = 0;
  1171. _debug("volname '%s'", p);
  1172. afs_extract_to_tmp(call);
  1173. call->unmarshall++;
  1174. fallthrough;
  1175. /* extract the offline message length */
  1176. case 4:
  1177. ret = afs_extract_data(call, true);
  1178. if (ret < 0)
  1179. return ret;
  1180. call->count = ntohl(call->tmp);
  1181. _debug("offline msg length: %u", call->count);
  1182. if (call->count >= AFSNAMEMAX)
  1183. return afs_protocol_error(call, afs_eproto_offline_msg_len);
  1184. size = (call->count + 3) & ~3; /* It's padded */
  1185. afs_extract_to_buf(call, size);
  1186. call->unmarshall++;
  1187. fallthrough;
  1188. /* extract the offline message */
  1189. case 5:
  1190. _debug("extract offline");
  1191. ret = afs_extract_data(call, true);
  1192. if (ret < 0)
  1193. return ret;
  1194. p = call->buffer;
  1195. p[call->count] = 0;
  1196. _debug("offline '%s'", p);
  1197. afs_extract_to_tmp(call);
  1198. call->unmarshall++;
  1199. fallthrough;
  1200. /* extract the message of the day length */
  1201. case 6:
  1202. ret = afs_extract_data(call, true);
  1203. if (ret < 0)
  1204. return ret;
  1205. call->count = ntohl(call->tmp);
  1206. _debug("motd length: %u", call->count);
  1207. if (call->count >= AFSNAMEMAX)
  1208. return afs_protocol_error(call, afs_eproto_motd_len);
  1209. size = (call->count + 3) & ~3; /* It's padded */
  1210. afs_extract_to_buf(call, size);
  1211. call->unmarshall++;
  1212. fallthrough;
  1213. /* extract the message of the day */
  1214. case 7:
  1215. _debug("extract motd");
  1216. ret = afs_extract_data(call, false);
  1217. if (ret < 0)
  1218. return ret;
  1219. p = call->buffer;
  1220. p[call->count] = 0;
  1221. _debug("motd '%s'", p);
  1222. call->unmarshall++;
  1223. case 8:
  1224. break;
  1225. }
  1226. _leave(" = 0 [done]");
  1227. return 0;
  1228. }
  1229. /*
  1230. * FS.GetVolumeStatus operation type
  1231. */
  1232. static const struct afs_call_type afs_RXFSGetVolumeStatus = {
  1233. .name = "FS.GetVolumeStatus",
  1234. .op = afs_FS_GetVolumeStatus,
  1235. .deliver = afs_deliver_fs_get_volume_status,
  1236. .destructor = afs_flat_call_destructor,
  1237. };
  1238. /*
  1239. * fetch the status of a volume
  1240. */
  1241. void afs_fs_get_volume_status(struct afs_operation *op)
  1242. {
  1243. struct afs_vnode_param *vp = &op->file[0];
  1244. struct afs_call *call;
  1245. __be32 *bp;
  1246. _enter("");
  1247. call = afs_alloc_flat_call(op->net, &afs_RXFSGetVolumeStatus, 2 * 4,
  1248. max(12 * 4, AFSOPAQUEMAX + 1));
  1249. if (!call)
  1250. return afs_op_nomem(op);
  1251. /* marshall the parameters */
  1252. bp = call->request;
  1253. bp[0] = htonl(FSGETVOLUMESTATUS);
  1254. bp[1] = htonl(vp->fid.vid);
  1255. trace_afs_make_fs_call(call, &vp->fid);
  1256. afs_make_op_call(op, call, GFP_NOFS);
  1257. }
  1258. /*
  1259. * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
  1260. */
  1261. static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
  1262. {
  1263. struct afs_operation *op = call->op;
  1264. const __be32 *bp;
  1265. int ret;
  1266. _enter("{%u}", call->unmarshall);
  1267. ret = afs_transfer_reply(call);
  1268. if (ret < 0)
  1269. return ret;
  1270. /* unmarshall the reply once we've received all of it */
  1271. bp = call->buffer;
  1272. xdr_decode_AFSVolSync(&bp, &op->volsync);
  1273. _leave(" = 0 [done]");
  1274. return 0;
  1275. }
  1276. /*
  1277. * FS.SetLock operation type
  1278. */
  1279. static const struct afs_call_type afs_RXFSSetLock = {
  1280. .name = "FS.SetLock",
  1281. .op = afs_FS_SetLock,
  1282. .deliver = afs_deliver_fs_xxxx_lock,
  1283. .done = afs_lock_op_done,
  1284. .destructor = afs_flat_call_destructor,
  1285. };
  1286. /*
  1287. * FS.ExtendLock operation type
  1288. */
  1289. static const struct afs_call_type afs_RXFSExtendLock = {
  1290. .name = "FS.ExtendLock",
  1291. .op = afs_FS_ExtendLock,
  1292. .deliver = afs_deliver_fs_xxxx_lock,
  1293. .done = afs_lock_op_done,
  1294. .destructor = afs_flat_call_destructor,
  1295. };
  1296. /*
  1297. * FS.ReleaseLock operation type
  1298. */
  1299. static const struct afs_call_type afs_RXFSReleaseLock = {
  1300. .name = "FS.ReleaseLock",
  1301. .op = afs_FS_ReleaseLock,
  1302. .deliver = afs_deliver_fs_xxxx_lock,
  1303. .destructor = afs_flat_call_destructor,
  1304. };
  1305. /*
  1306. * Set a lock on a file
  1307. */
  1308. void afs_fs_set_lock(struct afs_operation *op)
  1309. {
  1310. struct afs_vnode_param *vp = &op->file[0];
  1311. struct afs_call *call;
  1312. __be32 *bp;
  1313. _enter("");
  1314. call = afs_alloc_flat_call(op->net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
  1315. if (!call)
  1316. return afs_op_nomem(op);
  1317. /* marshall the parameters */
  1318. bp = call->request;
  1319. *bp++ = htonl(FSSETLOCK);
  1320. *bp++ = htonl(vp->fid.vid);
  1321. *bp++ = htonl(vp->fid.vnode);
  1322. *bp++ = htonl(vp->fid.unique);
  1323. *bp++ = htonl(op->lock.type);
  1324. trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
  1325. afs_make_op_call(op, call, GFP_NOFS);
  1326. }
  1327. /*
  1328. * extend a lock on a file
  1329. */
  1330. void afs_fs_extend_lock(struct afs_operation *op)
  1331. {
  1332. struct afs_vnode_param *vp = &op->file[0];
  1333. struct afs_call *call;
  1334. __be32 *bp;
  1335. _enter("");
  1336. call = afs_alloc_flat_call(op->net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
  1337. if (!call)
  1338. return afs_op_nomem(op);
  1339. /* marshall the parameters */
  1340. bp = call->request;
  1341. *bp++ = htonl(FSEXTENDLOCK);
  1342. *bp++ = htonl(vp->fid.vid);
  1343. *bp++ = htonl(vp->fid.vnode);
  1344. *bp++ = htonl(vp->fid.unique);
  1345. trace_afs_make_fs_call(call, &vp->fid);
  1346. afs_make_op_call(op, call, GFP_NOFS);
  1347. }
  1348. /*
  1349. * release a lock on a file
  1350. */
  1351. void afs_fs_release_lock(struct afs_operation *op)
  1352. {
  1353. struct afs_vnode_param *vp = &op->file[0];
  1354. struct afs_call *call;
  1355. __be32 *bp;
  1356. _enter("");
  1357. call = afs_alloc_flat_call(op->net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
  1358. if (!call)
  1359. return afs_op_nomem(op);
  1360. /* marshall the parameters */
  1361. bp = call->request;
  1362. *bp++ = htonl(FSRELEASELOCK);
  1363. *bp++ = htonl(vp->fid.vid);
  1364. *bp++ = htonl(vp->fid.vnode);
  1365. *bp++ = htonl(vp->fid.unique);
  1366. trace_afs_make_fs_call(call, &vp->fid);
  1367. afs_make_op_call(op, call, GFP_NOFS);
  1368. }
  1369. /*
  1370. * Deliver reply data to an FS.GiveUpAllCallBacks operation.
  1371. */
  1372. static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
  1373. {
  1374. return afs_transfer_reply(call);
  1375. }
  1376. /*
  1377. * FS.GiveUpAllCallBacks operation type
  1378. */
  1379. static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
  1380. .name = "FS.GiveUpAllCallBacks",
  1381. .op = afs_FS_GiveUpAllCallBacks,
  1382. .deliver = afs_deliver_fs_give_up_all_callbacks,
  1383. .destructor = afs_flat_call_destructor,
  1384. };
  1385. /*
  1386. * Flush all the callbacks we have on a server.
  1387. */
  1388. int afs_fs_give_up_all_callbacks(struct afs_net *net,
  1389. struct afs_server *server,
  1390. struct afs_addr_cursor *ac,
  1391. struct key *key)
  1392. {
  1393. struct afs_call *call;
  1394. __be32 *bp;
  1395. _enter("");
  1396. call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
  1397. if (!call)
  1398. return -ENOMEM;
  1399. call->key = key;
  1400. /* marshall the parameters */
  1401. bp = call->request;
  1402. *bp++ = htonl(FSGIVEUPALLCALLBACKS);
  1403. call->server = afs_use_server(server, afs_server_trace_give_up_cb);
  1404. afs_make_call(ac, call, GFP_NOFS);
  1405. return afs_wait_for_call_to_complete(call, ac);
  1406. }
  1407. /*
  1408. * Deliver reply data to an FS.GetCapabilities operation.
  1409. */
  1410. static int afs_deliver_fs_get_capabilities(struct afs_call *call)
  1411. {
  1412. u32 count;
  1413. int ret;
  1414. _enter("{%u,%zu}", call->unmarshall, iov_iter_count(call->iter));
  1415. switch (call->unmarshall) {
  1416. case 0:
  1417. afs_extract_to_tmp(call);
  1418. call->unmarshall++;
  1419. fallthrough;
  1420. /* Extract the capabilities word count */
  1421. case 1:
  1422. ret = afs_extract_data(call, true);
  1423. if (ret < 0)
  1424. return ret;
  1425. count = ntohl(call->tmp);
  1426. call->count = count;
  1427. call->count2 = count;
  1428. afs_extract_discard(call, count * sizeof(__be32));
  1429. call->unmarshall++;
  1430. fallthrough;
  1431. /* Extract capabilities words */
  1432. case 2:
  1433. ret = afs_extract_data(call, false);
  1434. if (ret < 0)
  1435. return ret;
  1436. /* TODO: Examine capabilities */
  1437. call->unmarshall++;
  1438. break;
  1439. }
  1440. _leave(" = 0 [done]");
  1441. return 0;
  1442. }
  1443. /*
  1444. * FS.GetCapabilities operation type
  1445. */
  1446. static const struct afs_call_type afs_RXFSGetCapabilities = {
  1447. .name = "FS.GetCapabilities",
  1448. .op = afs_FS_GetCapabilities,
  1449. .deliver = afs_deliver_fs_get_capabilities,
  1450. .done = afs_fileserver_probe_result,
  1451. .destructor = afs_flat_call_destructor,
  1452. };
  1453. /*
  1454. * Probe a fileserver for the capabilities that it supports. This RPC can
  1455. * reply with up to 196 words. The operation is asynchronous and if we managed
  1456. * to allocate a call, true is returned the result is delivered through the
  1457. * ->done() - otherwise we return false to indicate we didn't even try.
  1458. */
  1459. bool afs_fs_get_capabilities(struct afs_net *net, struct afs_server *server,
  1460. struct afs_addr_cursor *ac, struct key *key)
  1461. {
  1462. struct afs_call *call;
  1463. __be32 *bp;
  1464. _enter("");
  1465. call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
  1466. if (!call)
  1467. return false;
  1468. call->key = key;
  1469. call->server = afs_use_server(server, afs_server_trace_get_caps);
  1470. call->upgrade = true;
  1471. call->async = true;
  1472. call->max_lifespan = AFS_PROBE_MAX_LIFESPAN;
  1473. /* marshall the parameters */
  1474. bp = call->request;
  1475. *bp++ = htonl(FSGETCAPABILITIES);
  1476. trace_afs_make_fs_call(call, NULL);
  1477. afs_make_call(ac, call, GFP_NOFS);
  1478. afs_put_call(call);
  1479. return true;
  1480. }
  1481. /*
  1482. * Deliver reply data to an FS.InlineBulkStatus call
  1483. */
  1484. static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
  1485. {
  1486. struct afs_operation *op = call->op;
  1487. struct afs_status_cb *scb;
  1488. const __be32 *bp;
  1489. u32 tmp;
  1490. int ret;
  1491. _enter("{%u}", call->unmarshall);
  1492. switch (call->unmarshall) {
  1493. case 0:
  1494. afs_extract_to_tmp(call);
  1495. call->unmarshall++;
  1496. fallthrough;
  1497. /* Extract the file status count and array in two steps */
  1498. case 1:
  1499. _debug("extract status count");
  1500. ret = afs_extract_data(call, true);
  1501. if (ret < 0)
  1502. return ret;
  1503. tmp = ntohl(call->tmp);
  1504. _debug("status count: %u/%u", tmp, op->nr_files);
  1505. if (tmp != op->nr_files)
  1506. return afs_protocol_error(call, afs_eproto_ibulkst_count);
  1507. call->count = 0;
  1508. call->unmarshall++;
  1509. more_counts:
  1510. afs_extract_to_buf(call, 21 * sizeof(__be32));
  1511. fallthrough;
  1512. case 2:
  1513. _debug("extract status array %u", call->count);
  1514. ret = afs_extract_data(call, true);
  1515. if (ret < 0)
  1516. return ret;
  1517. switch (call->count) {
  1518. case 0:
  1519. scb = &op->file[0].scb;
  1520. break;
  1521. case 1:
  1522. scb = &op->file[1].scb;
  1523. break;
  1524. default:
  1525. scb = &op->more_files[call->count - 2].scb;
  1526. break;
  1527. }
  1528. bp = call->buffer;
  1529. xdr_decode_AFSFetchStatus(&bp, call, scb);
  1530. call->count++;
  1531. if (call->count < op->nr_files)
  1532. goto more_counts;
  1533. call->count = 0;
  1534. call->unmarshall++;
  1535. afs_extract_to_tmp(call);
  1536. fallthrough;
  1537. /* Extract the callback count and array in two steps */
  1538. case 3:
  1539. _debug("extract CB count");
  1540. ret = afs_extract_data(call, true);
  1541. if (ret < 0)
  1542. return ret;
  1543. tmp = ntohl(call->tmp);
  1544. _debug("CB count: %u", tmp);
  1545. if (tmp != op->nr_files)
  1546. return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
  1547. call->count = 0;
  1548. call->unmarshall++;
  1549. more_cbs:
  1550. afs_extract_to_buf(call, 3 * sizeof(__be32));
  1551. fallthrough;
  1552. case 4:
  1553. _debug("extract CB array");
  1554. ret = afs_extract_data(call, true);
  1555. if (ret < 0)
  1556. return ret;
  1557. _debug("unmarshall CB array");
  1558. switch (call->count) {
  1559. case 0:
  1560. scb = &op->file[0].scb;
  1561. break;
  1562. case 1:
  1563. scb = &op->file[1].scb;
  1564. break;
  1565. default:
  1566. scb = &op->more_files[call->count - 2].scb;
  1567. break;
  1568. }
  1569. bp = call->buffer;
  1570. xdr_decode_AFSCallBack(&bp, call, scb);
  1571. call->count++;
  1572. if (call->count < op->nr_files)
  1573. goto more_cbs;
  1574. afs_extract_to_buf(call, 6 * sizeof(__be32));
  1575. call->unmarshall++;
  1576. fallthrough;
  1577. case 5:
  1578. ret = afs_extract_data(call, false);
  1579. if (ret < 0)
  1580. return ret;
  1581. bp = call->buffer;
  1582. xdr_decode_AFSVolSync(&bp, &op->volsync);
  1583. call->unmarshall++;
  1584. case 6:
  1585. break;
  1586. }
  1587. _leave(" = 0 [done]");
  1588. return 0;
  1589. }
  1590. static void afs_done_fs_inline_bulk_status(struct afs_call *call)
  1591. {
  1592. if (call->error == -ECONNABORTED &&
  1593. call->abort_code == RX_INVALID_OPERATION) {
  1594. set_bit(AFS_SERVER_FL_NO_IBULK, &call->server->flags);
  1595. if (call->op)
  1596. set_bit(AFS_VOLUME_MAYBE_NO_IBULK, &call->op->volume->flags);
  1597. }
  1598. }
  1599. /*
  1600. * FS.InlineBulkStatus operation type
  1601. */
  1602. static const struct afs_call_type afs_RXFSInlineBulkStatus = {
  1603. .name = "FS.InlineBulkStatus",
  1604. .op = afs_FS_InlineBulkStatus,
  1605. .deliver = afs_deliver_fs_inline_bulk_status,
  1606. .done = afs_done_fs_inline_bulk_status,
  1607. .destructor = afs_flat_call_destructor,
  1608. };
  1609. /*
  1610. * Fetch the status information for up to 50 files
  1611. */
  1612. void afs_fs_inline_bulk_status(struct afs_operation *op)
  1613. {
  1614. struct afs_vnode_param *dvp = &op->file[0];
  1615. struct afs_vnode_param *vp = &op->file[1];
  1616. struct afs_call *call;
  1617. __be32 *bp;
  1618. int i;
  1619. if (test_bit(AFS_SERVER_FL_NO_IBULK, &op->server->flags)) {
  1620. op->error = -ENOTSUPP;
  1621. return;
  1622. }
  1623. _enter(",%x,{%llx:%llu},%u",
  1624. key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
  1625. call = afs_alloc_flat_call(op->net, &afs_RXFSInlineBulkStatus,
  1626. (2 + op->nr_files * 3) * 4,
  1627. 21 * 4);
  1628. if (!call)
  1629. return afs_op_nomem(op);
  1630. /* marshall the parameters */
  1631. bp = call->request;
  1632. *bp++ = htonl(FSINLINEBULKSTATUS);
  1633. *bp++ = htonl(op->nr_files);
  1634. *bp++ = htonl(dvp->fid.vid);
  1635. *bp++ = htonl(dvp->fid.vnode);
  1636. *bp++ = htonl(dvp->fid.unique);
  1637. *bp++ = htonl(vp->fid.vid);
  1638. *bp++ = htonl(vp->fid.vnode);
  1639. *bp++ = htonl(vp->fid.unique);
  1640. for (i = 0; i < op->nr_files - 2; i++) {
  1641. *bp++ = htonl(op->more_files[i].fid.vid);
  1642. *bp++ = htonl(op->more_files[i].fid.vnode);
  1643. *bp++ = htonl(op->more_files[i].fid.unique);
  1644. }
  1645. trace_afs_make_fs_call(call, &vp->fid);
  1646. afs_make_op_call(op, call, GFP_NOFS);
  1647. }
  1648. /*
  1649. * deliver reply data to an FS.FetchACL
  1650. */
  1651. static int afs_deliver_fs_fetch_acl(struct afs_call *call)
  1652. {
  1653. struct afs_operation *op = call->op;
  1654. struct afs_vnode_param *vp = &op->file[0];
  1655. struct afs_acl *acl;
  1656. const __be32 *bp;
  1657. unsigned int size;
  1658. int ret;
  1659. _enter("{%u}", call->unmarshall);
  1660. switch (call->unmarshall) {
  1661. case 0:
  1662. afs_extract_to_tmp(call);
  1663. call->unmarshall++;
  1664. fallthrough;
  1665. /* extract the returned data length */
  1666. case 1:
  1667. ret = afs_extract_data(call, true);
  1668. if (ret < 0)
  1669. return ret;
  1670. size = call->count2 = ntohl(call->tmp);
  1671. size = round_up(size, 4);
  1672. acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
  1673. if (!acl)
  1674. return -ENOMEM;
  1675. op->acl = acl;
  1676. acl->size = call->count2;
  1677. afs_extract_begin(call, acl->data, size);
  1678. call->unmarshall++;
  1679. fallthrough;
  1680. /* extract the returned data */
  1681. case 2:
  1682. ret = afs_extract_data(call, true);
  1683. if (ret < 0)
  1684. return ret;
  1685. afs_extract_to_buf(call, (21 + 6) * 4);
  1686. call->unmarshall++;
  1687. fallthrough;
  1688. /* extract the metadata */
  1689. case 3:
  1690. ret = afs_extract_data(call, false);
  1691. if (ret < 0)
  1692. return ret;
  1693. bp = call->buffer;
  1694. xdr_decode_AFSFetchStatus(&bp, call, &vp->scb);
  1695. xdr_decode_AFSVolSync(&bp, &op->volsync);
  1696. call->unmarshall++;
  1697. case 4:
  1698. break;
  1699. }
  1700. _leave(" = 0 [done]");
  1701. return 0;
  1702. }
  1703. /*
  1704. * FS.FetchACL operation type
  1705. */
  1706. static const struct afs_call_type afs_RXFSFetchACL = {
  1707. .name = "FS.FetchACL",
  1708. .op = afs_FS_FetchACL,
  1709. .deliver = afs_deliver_fs_fetch_acl,
  1710. };
  1711. /*
  1712. * Fetch the ACL for a file.
  1713. */
  1714. void afs_fs_fetch_acl(struct afs_operation *op)
  1715. {
  1716. struct afs_vnode_param *vp = &op->file[0];
  1717. struct afs_call *call;
  1718. __be32 *bp;
  1719. _enter(",%x,{%llx:%llu},,",
  1720. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1721. call = afs_alloc_flat_call(op->net, &afs_RXFSFetchACL, 16, (21 + 6) * 4);
  1722. if (!call)
  1723. return afs_op_nomem(op);
  1724. /* marshall the parameters */
  1725. bp = call->request;
  1726. bp[0] = htonl(FSFETCHACL);
  1727. bp[1] = htonl(vp->fid.vid);
  1728. bp[2] = htonl(vp->fid.vnode);
  1729. bp[3] = htonl(vp->fid.unique);
  1730. trace_afs_make_fs_call(call, &vp->fid);
  1731. afs_make_op_call(op, call, GFP_KERNEL);
  1732. }
  1733. /*
  1734. * FS.StoreACL operation type
  1735. */
  1736. static const struct afs_call_type afs_RXFSStoreACL = {
  1737. .name = "FS.StoreACL",
  1738. .op = afs_FS_StoreACL,
  1739. .deliver = afs_deliver_fs_file_status_and_vol,
  1740. .destructor = afs_flat_call_destructor,
  1741. };
  1742. /*
  1743. * Fetch the ACL for a file.
  1744. */
  1745. void afs_fs_store_acl(struct afs_operation *op)
  1746. {
  1747. struct afs_vnode_param *vp = &op->file[0];
  1748. struct afs_call *call;
  1749. const struct afs_acl *acl = op->acl;
  1750. size_t size;
  1751. __be32 *bp;
  1752. _enter(",%x,{%llx:%llu},,",
  1753. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1754. size = round_up(acl->size, 4);
  1755. call = afs_alloc_flat_call(op->net, &afs_RXFSStoreACL,
  1756. 5 * 4 + size, (21 + 6) * 4);
  1757. if (!call)
  1758. return afs_op_nomem(op);
  1759. /* marshall the parameters */
  1760. bp = call->request;
  1761. bp[0] = htonl(FSSTOREACL);
  1762. bp[1] = htonl(vp->fid.vid);
  1763. bp[2] = htonl(vp->fid.vnode);
  1764. bp[3] = htonl(vp->fid.unique);
  1765. bp[4] = htonl(acl->size);
  1766. memcpy(&bp[5], acl->data, acl->size);
  1767. if (acl->size != size)
  1768. memset((void *)&bp[5] + acl->size, 0, size - acl->size);
  1769. trace_afs_make_fs_call(call, &vp->fid);
  1770. afs_make_op_call(op, call, GFP_KERNEL);
  1771. }