fsclient.c 50 KB

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