fsclient.c 48 KB

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