yfsclient.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* YFS File Server client stubs
  3. *
  4. * Copyright (C) 2018 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 "internal.h"
  13. #include "afs_fs.h"
  14. #include "xdr_fs.h"
  15. #include "protocol_yfs.h"
  16. #define xdr_size(x) (sizeof(*x) / sizeof(__be32))
  17. static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid)
  18. {
  19. const struct yfs_xdr_YFSFid *x = (const void *)*_bp;
  20. fid->vid = xdr_to_u64(x->volume);
  21. fid->vnode = xdr_to_u64(x->vnode.lo);
  22. fid->vnode_hi = ntohl(x->vnode.hi);
  23. fid->unique = ntohl(x->vnode.unique);
  24. *_bp += xdr_size(x);
  25. }
  26. static __be32 *xdr_encode_u32(__be32 *bp, u32 n)
  27. {
  28. *bp++ = htonl(n);
  29. return bp;
  30. }
  31. static __be32 *xdr_encode_u64(__be32 *bp, u64 n)
  32. {
  33. struct yfs_xdr_u64 *x = (void *)bp;
  34. *x = u64_to_xdr(n);
  35. return bp + xdr_size(x);
  36. }
  37. static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid)
  38. {
  39. struct yfs_xdr_YFSFid *x = (void *)bp;
  40. x->volume = u64_to_xdr(fid->vid);
  41. x->vnode.lo = u64_to_xdr(fid->vnode);
  42. x->vnode.hi = htonl(fid->vnode_hi);
  43. x->vnode.unique = htonl(fid->unique);
  44. return bp + xdr_size(x);
  45. }
  46. static size_t xdr_strlen(unsigned int len)
  47. {
  48. return sizeof(__be32) + round_up(len, sizeof(__be32));
  49. }
  50. static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len)
  51. {
  52. bp = xdr_encode_u32(bp, len);
  53. bp = memcpy(bp, p, len);
  54. if (len & 3) {
  55. unsigned int pad = 4 - (len & 3);
  56. memset((u8 *)bp + len, 0, pad);
  57. len += pad;
  58. }
  59. return bp + len / sizeof(__be32);
  60. }
  61. static __be32 *xdr_encode_name(__be32 *bp, const struct qstr *p)
  62. {
  63. return xdr_encode_string(bp, p->name, p->len);
  64. }
  65. static s64 linux_to_yfs_time(const struct timespec64 *t)
  66. {
  67. /* Convert to 100ns intervals. */
  68. return (u64)t->tv_sec * 10000000 + t->tv_nsec/100;
  69. }
  70. static __be32 *xdr_encode_YFSStoreStatus(__be32 *bp, mode_t *mode,
  71. const struct timespec64 *t)
  72. {
  73. struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
  74. mode_t masked_mode = mode ? *mode & S_IALLUGO : 0;
  75. s64 mtime = linux_to_yfs_time(t);
  76. u32 mask = AFS_SET_MTIME;
  77. mask |= mode ? AFS_SET_MODE : 0;
  78. x->mask = htonl(mask);
  79. x->mode = htonl(masked_mode);
  80. x->mtime_client = u64_to_xdr(mtime);
  81. x->owner = u64_to_xdr(0);
  82. x->group = u64_to_xdr(0);
  83. return bp + xdr_size(x);
  84. }
  85. /*
  86. * Convert a signed 100ns-resolution 64-bit time into a timespec.
  87. */
  88. static struct timespec64 yfs_time_to_linux(s64 t)
  89. {
  90. struct timespec64 ts;
  91. u64 abs_t;
  92. /*
  93. * Unfortunately can not use normal 64 bit division on 32 bit arch, but
  94. * the alternative, do_div, does not work with negative numbers so have
  95. * to special case them
  96. */
  97. if (t < 0) {
  98. abs_t = -t;
  99. ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
  100. ts.tv_nsec = -ts.tv_nsec;
  101. ts.tv_sec = -abs_t;
  102. } else {
  103. abs_t = t;
  104. ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
  105. ts.tv_sec = abs_t;
  106. }
  107. return ts;
  108. }
  109. static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
  110. {
  111. s64 t = xdr_to_u64(xdr);
  112. return yfs_time_to_linux(t);
  113. }
  114. static void yfs_check_req(struct afs_call *call, __be32 *bp)
  115. {
  116. size_t len = (void *)bp - call->request;
  117. if (len > call->request_size)
  118. pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n",
  119. call->type->name, len, call->request_size);
  120. else if (len < call->request_size)
  121. pr_warn("kAFS: %s: Request buffer underflow (%zu<%u)\n",
  122. call->type->name, len, call->request_size);
  123. }
  124. /*
  125. * Dump a bad file status record.
  126. */
  127. static void xdr_dump_bad(const __be32 *bp)
  128. {
  129. __be32 x[4];
  130. int i;
  131. pr_notice("YFS XDR: Bad status record\n");
  132. for (i = 0; i < 6 * 4 * 4; i += 16) {
  133. memcpy(x, bp, 16);
  134. bp += 4;
  135. pr_notice("%03x: %08x %08x %08x %08x\n",
  136. i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
  137. }
  138. memcpy(x, bp, 8);
  139. pr_notice("0x60: %08x %08x\n", ntohl(x[0]), ntohl(x[1]));
  140. }
  141. /*
  142. * Decode a YFSFetchStatus block
  143. */
  144. static void xdr_decode_YFSFetchStatus(const __be32 **_bp,
  145. struct afs_call *call,
  146. struct afs_status_cb *scb)
  147. {
  148. const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
  149. struct afs_file_status *status = &scb->status;
  150. u32 type;
  151. status->abort_code = ntohl(xdr->abort_code);
  152. if (status->abort_code != 0) {
  153. if (status->abort_code == VNOVNODE)
  154. status->nlink = 0;
  155. scb->have_error = true;
  156. goto advance;
  157. }
  158. type = ntohl(xdr->type);
  159. switch (type) {
  160. case AFS_FTYPE_FILE:
  161. case AFS_FTYPE_DIR:
  162. case AFS_FTYPE_SYMLINK:
  163. status->type = type;
  164. break;
  165. default:
  166. goto bad;
  167. }
  168. status->nlink = ntohl(xdr->nlink);
  169. status->author = xdr_to_u64(xdr->author);
  170. status->owner = xdr_to_u64(xdr->owner);
  171. status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
  172. status->anon_access = ntohl(xdr->anon_access);
  173. status->mode = ntohl(xdr->mode) & S_IALLUGO;
  174. status->group = xdr_to_u64(xdr->group);
  175. status->lock_count = ntohl(xdr->lock_count);
  176. status->mtime_client = xdr_to_time(xdr->mtime_client);
  177. status->mtime_server = xdr_to_time(xdr->mtime_server);
  178. status->size = xdr_to_u64(xdr->size);
  179. status->data_version = xdr_to_u64(xdr->data_version);
  180. scb->have_status = true;
  181. advance:
  182. *_bp += xdr_size(xdr);
  183. return;
  184. bad:
  185. xdr_dump_bad(*_bp);
  186. afs_protocol_error(call, afs_eproto_bad_status);
  187. goto advance;
  188. }
  189. /*
  190. * Decode a YFSCallBack block
  191. */
  192. static void xdr_decode_YFSCallBack(const __be32 **_bp,
  193. struct afs_call *call,
  194. struct afs_status_cb *scb)
  195. {
  196. struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
  197. struct afs_callback *cb = &scb->callback;
  198. ktime_t cb_expiry;
  199. cb_expiry = ktime_add(call->issue_time, xdr_to_u64(x->expiration_time) * 100);
  200. cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
  201. scb->have_cb = true;
  202. *_bp += xdr_size(x);
  203. }
  204. /*
  205. * Decode a YFSVolSync block
  206. */
  207. static void xdr_decode_YFSVolSync(const __be32 **_bp,
  208. struct afs_volsync *volsync)
  209. {
  210. struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
  211. u64 creation;
  212. if (volsync) {
  213. creation = xdr_to_u64(x->vol_creation_date);
  214. do_div(creation, 10 * 1000 * 1000);
  215. volsync->creation = creation;
  216. }
  217. *_bp += xdr_size(x);
  218. }
  219. /*
  220. * Encode the requested attributes into a YFSStoreStatus block
  221. */
  222. static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
  223. {
  224. struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
  225. s64 mtime = 0, owner = 0, group = 0;
  226. u32 mask = 0, mode = 0;
  227. mask = 0;
  228. if (attr->ia_valid & ATTR_MTIME) {
  229. mask |= AFS_SET_MTIME;
  230. mtime = linux_to_yfs_time(&attr->ia_mtime);
  231. }
  232. if (attr->ia_valid & ATTR_UID) {
  233. mask |= AFS_SET_OWNER;
  234. owner = from_kuid(&init_user_ns, attr->ia_uid);
  235. }
  236. if (attr->ia_valid & ATTR_GID) {
  237. mask |= AFS_SET_GROUP;
  238. group = from_kgid(&init_user_ns, attr->ia_gid);
  239. }
  240. if (attr->ia_valid & ATTR_MODE) {
  241. mask |= AFS_SET_MODE;
  242. mode = attr->ia_mode & S_IALLUGO;
  243. }
  244. x->mask = htonl(mask);
  245. x->mode = htonl(mode);
  246. x->mtime_client = u64_to_xdr(mtime);
  247. x->owner = u64_to_xdr(owner);
  248. x->group = u64_to_xdr(group);
  249. return bp + xdr_size(x);
  250. }
  251. /*
  252. * Decode a YFSFetchVolumeStatus block.
  253. */
  254. static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
  255. struct afs_volume_status *vs)
  256. {
  257. const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
  258. u32 flags;
  259. vs->vid = xdr_to_u64(x->vid);
  260. vs->parent_id = xdr_to_u64(x->parent_id);
  261. flags = ntohl(x->flags);
  262. vs->online = flags & yfs_FVSOnline;
  263. vs->in_service = flags & yfs_FVSInservice;
  264. vs->blessed = flags & yfs_FVSBlessed;
  265. vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
  266. vs->type = ntohl(x->type);
  267. vs->min_quota = 0;
  268. vs->max_quota = xdr_to_u64(x->max_quota);
  269. vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
  270. vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
  271. vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
  272. vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
  273. vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
  274. *_bp += sizeof(*x) / sizeof(__be32);
  275. }
  276. /*
  277. * Deliver reply data to operations that just return a file status and a volume
  278. * sync record.
  279. */
  280. static int yfs_deliver_status_and_volsync(struct afs_call *call)
  281. {
  282. struct afs_operation *op = call->op;
  283. const __be32 *bp;
  284. int ret;
  285. ret = afs_transfer_reply(call);
  286. if (ret < 0)
  287. return ret;
  288. bp = call->buffer;
  289. xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
  290. xdr_decode_YFSVolSync(&bp, &op->volsync);
  291. _leave(" = 0 [done]");
  292. return 0;
  293. }
  294. /*
  295. * Deliver reply data to an YFS.FetchData64.
  296. */
  297. static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
  298. {
  299. struct afs_operation *op = call->op;
  300. struct afs_vnode_param *vp = &op->file[0];
  301. struct afs_read *req = op->fetch.req;
  302. const __be32 *bp;
  303. int ret;
  304. _enter("{%u,%zu, %zu/%llu}",
  305. call->unmarshall, call->iov_len, iov_iter_count(call->iter),
  306. req->actual_len);
  307. switch (call->unmarshall) {
  308. case 0:
  309. req->actual_len = 0;
  310. afs_extract_to_tmp64(call);
  311. call->unmarshall++;
  312. fallthrough;
  313. /* Extract the returned data length into ->actual_len. This
  314. * may indicate more or less data than was requested will be
  315. * returned.
  316. */
  317. case 1:
  318. _debug("extract data length");
  319. ret = afs_extract_data(call, true);
  320. if (ret < 0)
  321. return ret;
  322. req->actual_len = be64_to_cpu(call->tmp64);
  323. _debug("DATA length: %llu", req->actual_len);
  324. if (req->actual_len == 0)
  325. goto no_more_data;
  326. call->iter = req->iter;
  327. call->iov_len = min(req->actual_len, req->len);
  328. call->unmarshall++;
  329. fallthrough;
  330. /* extract the returned data */
  331. case 2:
  332. _debug("extract data %zu/%llu",
  333. iov_iter_count(call->iter), req->actual_len);
  334. ret = afs_extract_data(call, true);
  335. if (ret < 0)
  336. return ret;
  337. call->iter = &call->def_iter;
  338. if (req->actual_len <= req->len)
  339. goto no_more_data;
  340. /* Discard any excess data the server gave us */
  341. afs_extract_discard(call, req->actual_len - req->len);
  342. call->unmarshall = 3;
  343. fallthrough;
  344. case 3:
  345. _debug("extract discard %zu/%llu",
  346. iov_iter_count(call->iter), req->actual_len - req->len);
  347. ret = afs_extract_data(call, true);
  348. if (ret < 0)
  349. return ret;
  350. no_more_data:
  351. call->unmarshall = 4;
  352. afs_extract_to_buf(call,
  353. sizeof(struct yfs_xdr_YFSFetchStatus) +
  354. sizeof(struct yfs_xdr_YFSCallBack) +
  355. sizeof(struct yfs_xdr_YFSVolSync));
  356. fallthrough;
  357. /* extract the metadata */
  358. case 4:
  359. ret = afs_extract_data(call, false);
  360. if (ret < 0)
  361. return ret;
  362. bp = call->buffer;
  363. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  364. xdr_decode_YFSCallBack(&bp, call, &vp->scb);
  365. xdr_decode_YFSVolSync(&bp, &op->volsync);
  366. req->data_version = vp->scb.status.data_version;
  367. req->file_size = vp->scb.status.size;
  368. call->unmarshall++;
  369. fallthrough;
  370. case 5:
  371. break;
  372. }
  373. _leave(" = 0 [done]");
  374. return 0;
  375. }
  376. /*
  377. * YFS.FetchData64 operation type
  378. */
  379. static const struct afs_call_type yfs_RXYFSFetchData64 = {
  380. .name = "YFS.FetchData64",
  381. .op = yfs_FS_FetchData64,
  382. .deliver = yfs_deliver_fs_fetch_data64,
  383. .destructor = afs_flat_call_destructor,
  384. };
  385. /*
  386. * Fetch data from a file.
  387. */
  388. void yfs_fs_fetch_data(struct afs_operation *op)
  389. {
  390. struct afs_vnode_param *vp = &op->file[0];
  391. struct afs_read *req = op->fetch.req;
  392. struct afs_call *call;
  393. __be32 *bp;
  394. _enter(",%x,{%llx:%llu},%llx,%llx",
  395. key_serial(op->key), vp->fid.vid, vp->fid.vnode,
  396. req->pos, req->len);
  397. call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
  398. sizeof(__be32) * 2 +
  399. sizeof(struct yfs_xdr_YFSFid) +
  400. sizeof(struct yfs_xdr_u64) * 2,
  401. sizeof(struct yfs_xdr_YFSFetchStatus) +
  402. sizeof(struct yfs_xdr_YFSCallBack) +
  403. sizeof(struct yfs_xdr_YFSVolSync));
  404. if (!call)
  405. return afs_op_nomem(op);
  406. req->call_debug_id = call->debug_id;
  407. /* marshall the parameters */
  408. bp = call->request;
  409. bp = xdr_encode_u32(bp, YFSFETCHDATA64);
  410. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  411. bp = xdr_encode_YFSFid(bp, &vp->fid);
  412. bp = xdr_encode_u64(bp, req->pos);
  413. bp = xdr_encode_u64(bp, req->len);
  414. yfs_check_req(call, bp);
  415. trace_afs_make_fs_call(call, &vp->fid);
  416. afs_make_op_call(op, call, GFP_NOFS);
  417. }
  418. /*
  419. * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
  420. */
  421. static int yfs_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. _enter("{%u}", call->unmarshall);
  429. ret = afs_transfer_reply(call);
  430. if (ret < 0)
  431. return ret;
  432. /* unmarshall the reply once we've received all of it */
  433. bp = call->buffer;
  434. xdr_decode_YFSFid(&bp, &op->file[1].fid);
  435. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  436. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  437. xdr_decode_YFSCallBack(&bp, call, &vp->scb);
  438. xdr_decode_YFSVolSync(&bp, &op->volsync);
  439. _leave(" = 0 [done]");
  440. return 0;
  441. }
  442. /*
  443. * FS.CreateFile and FS.MakeDir operation type
  444. */
  445. static const struct afs_call_type afs_RXFSCreateFile = {
  446. .name = "YFS.CreateFile",
  447. .op = yfs_FS_CreateFile,
  448. .deliver = yfs_deliver_fs_create_vnode,
  449. .destructor = afs_flat_call_destructor,
  450. };
  451. /*
  452. * Create a file.
  453. */
  454. void yfs_fs_create_file(struct afs_operation *op)
  455. {
  456. const struct qstr *name = &op->dentry->d_name;
  457. struct afs_vnode_param *dvp = &op->file[0];
  458. struct afs_call *call;
  459. size_t reqsz, rplsz;
  460. __be32 *bp;
  461. _enter("");
  462. reqsz = (sizeof(__be32) +
  463. sizeof(__be32) +
  464. sizeof(struct yfs_xdr_YFSFid) +
  465. xdr_strlen(name->len) +
  466. sizeof(struct yfs_xdr_YFSStoreStatus) +
  467. sizeof(__be32));
  468. rplsz = (sizeof(struct yfs_xdr_YFSFid) +
  469. sizeof(struct yfs_xdr_YFSFetchStatus) +
  470. sizeof(struct yfs_xdr_YFSFetchStatus) +
  471. sizeof(struct yfs_xdr_YFSCallBack) +
  472. sizeof(struct yfs_xdr_YFSVolSync));
  473. call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
  474. if (!call)
  475. return afs_op_nomem(op);
  476. /* marshall the parameters */
  477. bp = call->request;
  478. bp = xdr_encode_u32(bp, YFSCREATEFILE);
  479. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  480. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  481. bp = xdr_encode_name(bp, name);
  482. bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
  483. bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
  484. yfs_check_req(call, bp);
  485. trace_afs_make_fs_call1(call, &dvp->fid, name);
  486. afs_make_op_call(op, call, GFP_NOFS);
  487. }
  488. static const struct afs_call_type yfs_RXFSMakeDir = {
  489. .name = "YFS.MakeDir",
  490. .op = yfs_FS_MakeDir,
  491. .deliver = yfs_deliver_fs_create_vnode,
  492. .destructor = afs_flat_call_destructor,
  493. };
  494. /*
  495. * Make a directory.
  496. */
  497. void yfs_fs_make_dir(struct afs_operation *op)
  498. {
  499. const struct qstr *name = &op->dentry->d_name;
  500. struct afs_vnode_param *dvp = &op->file[0];
  501. struct afs_call *call;
  502. size_t reqsz, rplsz;
  503. __be32 *bp;
  504. _enter("");
  505. reqsz = (sizeof(__be32) +
  506. sizeof(struct yfs_xdr_RPCFlags) +
  507. sizeof(struct yfs_xdr_YFSFid) +
  508. xdr_strlen(name->len) +
  509. sizeof(struct yfs_xdr_YFSStoreStatus));
  510. rplsz = (sizeof(struct yfs_xdr_YFSFid) +
  511. sizeof(struct yfs_xdr_YFSFetchStatus) +
  512. sizeof(struct yfs_xdr_YFSFetchStatus) +
  513. sizeof(struct yfs_xdr_YFSCallBack) +
  514. sizeof(struct yfs_xdr_YFSVolSync));
  515. call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
  516. if (!call)
  517. return afs_op_nomem(op);
  518. /* marshall the parameters */
  519. bp = call->request;
  520. bp = xdr_encode_u32(bp, YFSMAKEDIR);
  521. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  522. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  523. bp = xdr_encode_name(bp, name);
  524. bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
  525. yfs_check_req(call, bp);
  526. trace_afs_make_fs_call1(call, &dvp->fid, name);
  527. afs_make_op_call(op, call, GFP_NOFS);
  528. }
  529. /*
  530. * Deliver reply data to a YFS.RemoveFile2 operation.
  531. */
  532. static int yfs_deliver_fs_remove_file2(struct afs_call *call)
  533. {
  534. struct afs_operation *op = call->op;
  535. struct afs_vnode_param *dvp = &op->file[0];
  536. struct afs_vnode_param *vp = &op->file[1];
  537. struct afs_fid fid;
  538. const __be32 *bp;
  539. int ret;
  540. _enter("{%u}", call->unmarshall);
  541. ret = afs_transfer_reply(call);
  542. if (ret < 0)
  543. return ret;
  544. bp = call->buffer;
  545. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  546. xdr_decode_YFSFid(&bp, &fid);
  547. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  548. /* Was deleted if vnode->status.abort_code == VNOVNODE. */
  549. xdr_decode_YFSVolSync(&bp, &op->volsync);
  550. return 0;
  551. }
  552. static void yfs_done_fs_remove_file2(struct afs_call *call)
  553. {
  554. if (call->error == -ECONNABORTED &&
  555. call->abort_code == RX_INVALID_OPERATION) {
  556. set_bit(AFS_SERVER_FL_NO_RM2, &call->server->flags);
  557. call->op->flags |= AFS_OPERATION_DOWNGRADE;
  558. }
  559. }
  560. /*
  561. * YFS.RemoveFile2 operation type.
  562. */
  563. static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
  564. .name = "YFS.RemoveFile2",
  565. .op = yfs_FS_RemoveFile2,
  566. .deliver = yfs_deliver_fs_remove_file2,
  567. .done = yfs_done_fs_remove_file2,
  568. .destructor = afs_flat_call_destructor,
  569. };
  570. /*
  571. * Remove a file and retrieve new file status.
  572. */
  573. void yfs_fs_remove_file2(struct afs_operation *op)
  574. {
  575. struct afs_vnode_param *dvp = &op->file[0];
  576. const struct qstr *name = &op->dentry->d_name;
  577. struct afs_call *call;
  578. __be32 *bp;
  579. _enter("");
  580. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
  581. sizeof(__be32) +
  582. sizeof(struct yfs_xdr_RPCFlags) +
  583. sizeof(struct yfs_xdr_YFSFid) +
  584. xdr_strlen(name->len),
  585. sizeof(struct yfs_xdr_YFSFetchStatus) +
  586. sizeof(struct yfs_xdr_YFSFid) +
  587. sizeof(struct yfs_xdr_YFSFetchStatus) +
  588. sizeof(struct yfs_xdr_YFSVolSync));
  589. if (!call)
  590. return afs_op_nomem(op);
  591. /* marshall the parameters */
  592. bp = call->request;
  593. bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
  594. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  595. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  596. bp = xdr_encode_name(bp, name);
  597. yfs_check_req(call, bp);
  598. trace_afs_make_fs_call1(call, &dvp->fid, name);
  599. afs_make_op_call(op, call, GFP_NOFS);
  600. }
  601. /*
  602. * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
  603. */
  604. static int yfs_deliver_fs_remove(struct afs_call *call)
  605. {
  606. struct afs_operation *op = call->op;
  607. struct afs_vnode_param *dvp = &op->file[0];
  608. const __be32 *bp;
  609. int ret;
  610. _enter("{%u}", call->unmarshall);
  611. ret = afs_transfer_reply(call);
  612. if (ret < 0)
  613. return ret;
  614. bp = call->buffer;
  615. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  616. xdr_decode_YFSVolSync(&bp, &op->volsync);
  617. return 0;
  618. }
  619. /*
  620. * FS.RemoveDir and FS.RemoveFile operation types.
  621. */
  622. static const struct afs_call_type yfs_RXYFSRemoveFile = {
  623. .name = "YFS.RemoveFile",
  624. .op = yfs_FS_RemoveFile,
  625. .deliver = yfs_deliver_fs_remove,
  626. .destructor = afs_flat_call_destructor,
  627. };
  628. /*
  629. * Remove a file.
  630. */
  631. void yfs_fs_remove_file(struct afs_operation *op)
  632. {
  633. const struct qstr *name = &op->dentry->d_name;
  634. struct afs_vnode_param *dvp = &op->file[0];
  635. struct afs_call *call;
  636. __be32 *bp;
  637. _enter("");
  638. if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
  639. return yfs_fs_remove_file2(op);
  640. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
  641. sizeof(__be32) +
  642. sizeof(struct yfs_xdr_RPCFlags) +
  643. sizeof(struct yfs_xdr_YFSFid) +
  644. xdr_strlen(name->len),
  645. sizeof(struct yfs_xdr_YFSFetchStatus) +
  646. sizeof(struct yfs_xdr_YFSVolSync));
  647. if (!call)
  648. return afs_op_nomem(op);
  649. /* marshall the parameters */
  650. bp = call->request;
  651. bp = xdr_encode_u32(bp, YFSREMOVEFILE);
  652. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  653. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  654. bp = xdr_encode_name(bp, name);
  655. yfs_check_req(call, bp);
  656. trace_afs_make_fs_call1(call, &dvp->fid, name);
  657. afs_make_op_call(op, call, GFP_NOFS);
  658. }
  659. static const struct afs_call_type yfs_RXYFSRemoveDir = {
  660. .name = "YFS.RemoveDir",
  661. .op = yfs_FS_RemoveDir,
  662. .deliver = yfs_deliver_fs_remove,
  663. .destructor = afs_flat_call_destructor,
  664. };
  665. /*
  666. * Remove a directory.
  667. */
  668. void yfs_fs_remove_dir(struct afs_operation *op)
  669. {
  670. const struct qstr *name = &op->dentry->d_name;
  671. struct afs_vnode_param *dvp = &op->file[0];
  672. struct afs_call *call;
  673. __be32 *bp;
  674. _enter("");
  675. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
  676. sizeof(__be32) +
  677. sizeof(struct yfs_xdr_RPCFlags) +
  678. sizeof(struct yfs_xdr_YFSFid) +
  679. xdr_strlen(name->len),
  680. sizeof(struct yfs_xdr_YFSFetchStatus) +
  681. sizeof(struct yfs_xdr_YFSVolSync));
  682. if (!call)
  683. return afs_op_nomem(op);
  684. /* marshall the parameters */
  685. bp = call->request;
  686. bp = xdr_encode_u32(bp, YFSREMOVEDIR);
  687. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  688. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  689. bp = xdr_encode_name(bp, name);
  690. yfs_check_req(call, bp);
  691. trace_afs_make_fs_call1(call, &dvp->fid, name);
  692. afs_make_op_call(op, call, GFP_NOFS);
  693. }
  694. /*
  695. * Deliver reply data to a YFS.Link operation.
  696. */
  697. static int yfs_deliver_fs_link(struct afs_call *call)
  698. {
  699. struct afs_operation *op = call->op;
  700. struct afs_vnode_param *dvp = &op->file[0];
  701. struct afs_vnode_param *vp = &op->file[1];
  702. const __be32 *bp;
  703. int ret;
  704. _enter("{%u}", call->unmarshall);
  705. ret = afs_transfer_reply(call);
  706. if (ret < 0)
  707. return ret;
  708. bp = call->buffer;
  709. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  710. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  711. xdr_decode_YFSVolSync(&bp, &op->volsync);
  712. _leave(" = 0 [done]");
  713. return 0;
  714. }
  715. /*
  716. * YFS.Link operation type.
  717. */
  718. static const struct afs_call_type yfs_RXYFSLink = {
  719. .name = "YFS.Link",
  720. .op = yfs_FS_Link,
  721. .deliver = yfs_deliver_fs_link,
  722. .destructor = afs_flat_call_destructor,
  723. };
  724. /*
  725. * Make a hard link.
  726. */
  727. void yfs_fs_link(struct afs_operation *op)
  728. {
  729. const struct qstr *name = &op->dentry->d_name;
  730. struct afs_vnode_param *dvp = &op->file[0];
  731. struct afs_vnode_param *vp = &op->file[1];
  732. struct afs_call *call;
  733. __be32 *bp;
  734. _enter("");
  735. call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
  736. sizeof(__be32) +
  737. sizeof(struct yfs_xdr_RPCFlags) +
  738. sizeof(struct yfs_xdr_YFSFid) +
  739. xdr_strlen(name->len) +
  740. sizeof(struct yfs_xdr_YFSFid),
  741. sizeof(struct yfs_xdr_YFSFetchStatus) +
  742. sizeof(struct yfs_xdr_YFSFetchStatus) +
  743. sizeof(struct yfs_xdr_YFSVolSync));
  744. if (!call)
  745. return afs_op_nomem(op);
  746. /* marshall the parameters */
  747. bp = call->request;
  748. bp = xdr_encode_u32(bp, YFSLINK);
  749. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  750. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  751. bp = xdr_encode_name(bp, name);
  752. bp = xdr_encode_YFSFid(bp, &vp->fid);
  753. yfs_check_req(call, bp);
  754. trace_afs_make_fs_call1(call, &vp->fid, name);
  755. afs_make_op_call(op, call, GFP_NOFS);
  756. }
  757. /*
  758. * Deliver reply data to a YFS.Symlink operation.
  759. */
  760. static int yfs_deliver_fs_symlink(struct afs_call *call)
  761. {
  762. struct afs_operation *op = call->op;
  763. struct afs_vnode_param *dvp = &op->file[0];
  764. struct afs_vnode_param *vp = &op->file[1];
  765. const __be32 *bp;
  766. int ret;
  767. _enter("{%u}", call->unmarshall);
  768. ret = afs_transfer_reply(call);
  769. if (ret < 0)
  770. return ret;
  771. /* unmarshall the reply once we've received all of it */
  772. bp = call->buffer;
  773. xdr_decode_YFSFid(&bp, &vp->fid);
  774. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  775. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  776. xdr_decode_YFSVolSync(&bp, &op->volsync);
  777. _leave(" = 0 [done]");
  778. return 0;
  779. }
  780. /*
  781. * YFS.Symlink operation type
  782. */
  783. static const struct afs_call_type yfs_RXYFSSymlink = {
  784. .name = "YFS.Symlink",
  785. .op = yfs_FS_Symlink,
  786. .deliver = yfs_deliver_fs_symlink,
  787. .destructor = afs_flat_call_destructor,
  788. };
  789. /*
  790. * Create a symbolic link.
  791. */
  792. void yfs_fs_symlink(struct afs_operation *op)
  793. {
  794. const struct qstr *name = &op->dentry->d_name;
  795. struct afs_vnode_param *dvp = &op->file[0];
  796. struct afs_call *call;
  797. size_t contents_sz;
  798. mode_t mode = 0777;
  799. __be32 *bp;
  800. _enter("");
  801. contents_sz = strlen(op->create.symlink);
  802. call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
  803. sizeof(__be32) +
  804. sizeof(struct yfs_xdr_RPCFlags) +
  805. sizeof(struct yfs_xdr_YFSFid) +
  806. xdr_strlen(name->len) +
  807. xdr_strlen(contents_sz) +
  808. sizeof(struct yfs_xdr_YFSStoreStatus),
  809. sizeof(struct yfs_xdr_YFSFid) +
  810. sizeof(struct yfs_xdr_YFSFetchStatus) +
  811. sizeof(struct yfs_xdr_YFSFetchStatus) +
  812. sizeof(struct yfs_xdr_YFSVolSync));
  813. if (!call)
  814. return afs_op_nomem(op);
  815. /* marshall the parameters */
  816. bp = call->request;
  817. bp = xdr_encode_u32(bp, YFSSYMLINK);
  818. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  819. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  820. bp = xdr_encode_name(bp, name);
  821. bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
  822. bp = xdr_encode_YFSStoreStatus(bp, &mode, &op->mtime);
  823. yfs_check_req(call, bp);
  824. trace_afs_make_fs_call1(call, &dvp->fid, name);
  825. afs_make_op_call(op, call, GFP_NOFS);
  826. }
  827. /*
  828. * Deliver reply data to a YFS.Rename operation.
  829. */
  830. static int yfs_deliver_fs_rename(struct afs_call *call)
  831. {
  832. struct afs_operation *op = call->op;
  833. struct afs_vnode_param *orig_dvp = &op->file[0];
  834. struct afs_vnode_param *new_dvp = &op->file[1];
  835. const __be32 *bp;
  836. int ret;
  837. _enter("{%u}", call->unmarshall);
  838. ret = afs_transfer_reply(call);
  839. if (ret < 0)
  840. return ret;
  841. bp = call->buffer;
  842. /* If the two dirs are the same, we have two copies of the same status
  843. * report, so we just decode it twice.
  844. */
  845. xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
  846. xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
  847. xdr_decode_YFSVolSync(&bp, &op->volsync);
  848. _leave(" = 0 [done]");
  849. return 0;
  850. }
  851. /*
  852. * YFS.Rename operation type
  853. */
  854. static const struct afs_call_type yfs_RXYFSRename = {
  855. .name = "FS.Rename",
  856. .op = yfs_FS_Rename,
  857. .deliver = yfs_deliver_fs_rename,
  858. .destructor = afs_flat_call_destructor,
  859. };
  860. /*
  861. * Rename a file or directory.
  862. */
  863. void yfs_fs_rename(struct afs_operation *op)
  864. {
  865. struct afs_vnode_param *orig_dvp = &op->file[0];
  866. struct afs_vnode_param *new_dvp = &op->file[1];
  867. const struct qstr *orig_name = &op->dentry->d_name;
  868. const struct qstr *new_name = &op->dentry_2->d_name;
  869. struct afs_call *call;
  870. __be32 *bp;
  871. _enter("");
  872. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
  873. sizeof(__be32) +
  874. sizeof(struct yfs_xdr_RPCFlags) +
  875. sizeof(struct yfs_xdr_YFSFid) +
  876. xdr_strlen(orig_name->len) +
  877. sizeof(struct yfs_xdr_YFSFid) +
  878. xdr_strlen(new_name->len),
  879. sizeof(struct yfs_xdr_YFSFetchStatus) +
  880. sizeof(struct yfs_xdr_YFSFetchStatus) +
  881. sizeof(struct yfs_xdr_YFSVolSync));
  882. if (!call)
  883. return afs_op_nomem(op);
  884. /* marshall the parameters */
  885. bp = call->request;
  886. bp = xdr_encode_u32(bp, YFSRENAME);
  887. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  888. bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
  889. bp = xdr_encode_name(bp, orig_name);
  890. bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
  891. bp = xdr_encode_name(bp, new_name);
  892. yfs_check_req(call, bp);
  893. trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
  894. afs_make_op_call(op, call, GFP_NOFS);
  895. }
  896. /*
  897. * YFS.StoreData64 operation type.
  898. */
  899. static const struct afs_call_type yfs_RXYFSStoreData64 = {
  900. .name = "YFS.StoreData64",
  901. .op = yfs_FS_StoreData64,
  902. .deliver = yfs_deliver_status_and_volsync,
  903. .destructor = afs_flat_call_destructor,
  904. };
  905. /*
  906. * Store a set of pages to a large file.
  907. */
  908. void yfs_fs_store_data(struct afs_operation *op)
  909. {
  910. struct afs_vnode_param *vp = &op->file[0];
  911. struct afs_call *call;
  912. __be32 *bp;
  913. _enter(",%x,{%llx:%llu},,",
  914. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  915. _debug("size %llx, at %llx, i_size %llx",
  916. (unsigned long long)op->store.size,
  917. (unsigned long long)op->store.pos,
  918. (unsigned long long)op->store.i_size);
  919. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
  920. sizeof(__be32) +
  921. sizeof(__be32) +
  922. sizeof(struct yfs_xdr_YFSFid) +
  923. sizeof(struct yfs_xdr_YFSStoreStatus) +
  924. sizeof(struct yfs_xdr_u64) * 3,
  925. sizeof(struct yfs_xdr_YFSFetchStatus) +
  926. sizeof(struct yfs_xdr_YFSVolSync));
  927. if (!call)
  928. return afs_op_nomem(op);
  929. call->write_iter = op->store.write_iter;
  930. /* marshall the parameters */
  931. bp = call->request;
  932. bp = xdr_encode_u32(bp, YFSSTOREDATA64);
  933. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  934. bp = xdr_encode_YFSFid(bp, &vp->fid);
  935. bp = xdr_encode_YFSStoreStatus(bp, NULL, &op->mtime);
  936. bp = xdr_encode_u64(bp, op->store.pos);
  937. bp = xdr_encode_u64(bp, op->store.size);
  938. bp = xdr_encode_u64(bp, op->store.i_size);
  939. yfs_check_req(call, bp);
  940. trace_afs_make_fs_call(call, &vp->fid);
  941. afs_make_op_call(op, call, GFP_NOFS);
  942. }
  943. /*
  944. * YFS.StoreStatus operation type
  945. */
  946. static const struct afs_call_type yfs_RXYFSStoreStatus = {
  947. .name = "YFS.StoreStatus",
  948. .op = yfs_FS_StoreStatus,
  949. .deliver = yfs_deliver_status_and_volsync,
  950. .destructor = afs_flat_call_destructor,
  951. };
  952. static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
  953. .name = "YFS.StoreData64",
  954. .op = yfs_FS_StoreData64,
  955. .deliver = yfs_deliver_status_and_volsync,
  956. .destructor = afs_flat_call_destructor,
  957. };
  958. /*
  959. * Set the attributes on a file, using YFS.StoreData64 rather than
  960. * YFS.StoreStatus so as to alter the file size also.
  961. */
  962. static void yfs_fs_setattr_size(struct afs_operation *op)
  963. {
  964. struct afs_vnode_param *vp = &op->file[0];
  965. struct afs_call *call;
  966. struct iattr *attr = op->setattr.attr;
  967. __be32 *bp;
  968. _enter(",%x,{%llx:%llu},,",
  969. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  970. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
  971. sizeof(__be32) * 2 +
  972. sizeof(struct yfs_xdr_YFSFid) +
  973. sizeof(struct yfs_xdr_YFSStoreStatus) +
  974. sizeof(struct yfs_xdr_u64) * 3,
  975. sizeof(struct yfs_xdr_YFSFetchStatus) +
  976. sizeof(struct yfs_xdr_YFSVolSync));
  977. if (!call)
  978. return afs_op_nomem(op);
  979. /* marshall the parameters */
  980. bp = call->request;
  981. bp = xdr_encode_u32(bp, YFSSTOREDATA64);
  982. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  983. bp = xdr_encode_YFSFid(bp, &vp->fid);
  984. bp = xdr_encode_YFS_StoreStatus(bp, attr);
  985. bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
  986. bp = xdr_encode_u64(bp, 0); /* size of write */
  987. bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
  988. yfs_check_req(call, bp);
  989. trace_afs_make_fs_call(call, &vp->fid);
  990. afs_make_op_call(op, call, GFP_NOFS);
  991. }
  992. /*
  993. * Set the attributes on a file, using YFS.StoreData64 if there's a change in
  994. * file size, and YFS.StoreStatus otherwise.
  995. */
  996. void yfs_fs_setattr(struct afs_operation *op)
  997. {
  998. struct afs_vnode_param *vp = &op->file[0];
  999. struct afs_call *call;
  1000. struct iattr *attr = op->setattr.attr;
  1001. __be32 *bp;
  1002. if (attr->ia_valid & ATTR_SIZE)
  1003. return yfs_fs_setattr_size(op);
  1004. _enter(",%x,{%llx:%llu},,",
  1005. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1006. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
  1007. sizeof(__be32) * 2 +
  1008. sizeof(struct yfs_xdr_YFSFid) +
  1009. sizeof(struct yfs_xdr_YFSStoreStatus),
  1010. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1011. sizeof(struct yfs_xdr_YFSVolSync));
  1012. if (!call)
  1013. return afs_op_nomem(op);
  1014. /* marshall the parameters */
  1015. bp = call->request;
  1016. bp = xdr_encode_u32(bp, YFSSTORESTATUS);
  1017. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1018. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1019. bp = xdr_encode_YFS_StoreStatus(bp, attr);
  1020. yfs_check_req(call, bp);
  1021. trace_afs_make_fs_call(call, &vp->fid);
  1022. afs_make_op_call(op, call, GFP_NOFS);
  1023. }
  1024. /*
  1025. * Deliver reply data to a YFS.GetVolumeStatus operation.
  1026. */
  1027. static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
  1028. {
  1029. struct afs_operation *op = call->op;
  1030. const __be32 *bp;
  1031. char *p;
  1032. u32 size;
  1033. int ret;
  1034. _enter("{%u}", call->unmarshall);
  1035. switch (call->unmarshall) {
  1036. case 0:
  1037. call->unmarshall++;
  1038. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
  1039. fallthrough;
  1040. /* extract the returned status record */
  1041. case 1:
  1042. _debug("extract status");
  1043. ret = afs_extract_data(call, true);
  1044. if (ret < 0)
  1045. return ret;
  1046. bp = call->buffer;
  1047. xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
  1048. call->unmarshall++;
  1049. afs_extract_to_tmp(call);
  1050. fallthrough;
  1051. /* extract the volume name length */
  1052. case 2:
  1053. ret = afs_extract_data(call, true);
  1054. if (ret < 0)
  1055. return ret;
  1056. call->count = ntohl(call->tmp);
  1057. _debug("volname length: %u", call->count);
  1058. if (call->count >= AFSNAMEMAX)
  1059. return afs_protocol_error(call, afs_eproto_volname_len);
  1060. size = (call->count + 3) & ~3; /* It's padded */
  1061. afs_extract_to_buf(call, size);
  1062. call->unmarshall++;
  1063. fallthrough;
  1064. /* extract the volume name */
  1065. case 3:
  1066. _debug("extract volname");
  1067. ret = afs_extract_data(call, true);
  1068. if (ret < 0)
  1069. return ret;
  1070. p = call->buffer;
  1071. p[call->count] = 0;
  1072. _debug("volname '%s'", p);
  1073. afs_extract_to_tmp(call);
  1074. call->unmarshall++;
  1075. fallthrough;
  1076. /* extract the offline message length */
  1077. case 4:
  1078. ret = afs_extract_data(call, true);
  1079. if (ret < 0)
  1080. return ret;
  1081. call->count = ntohl(call->tmp);
  1082. _debug("offline msg length: %u", call->count);
  1083. if (call->count >= AFSNAMEMAX)
  1084. return afs_protocol_error(call, afs_eproto_offline_msg_len);
  1085. size = (call->count + 3) & ~3; /* It's padded */
  1086. afs_extract_to_buf(call, size);
  1087. call->unmarshall++;
  1088. fallthrough;
  1089. /* extract the offline message */
  1090. case 5:
  1091. _debug("extract offline");
  1092. ret = afs_extract_data(call, true);
  1093. if (ret < 0)
  1094. return ret;
  1095. p = call->buffer;
  1096. p[call->count] = 0;
  1097. _debug("offline '%s'", p);
  1098. afs_extract_to_tmp(call);
  1099. call->unmarshall++;
  1100. fallthrough;
  1101. /* extract the message of the day length */
  1102. case 6:
  1103. ret = afs_extract_data(call, true);
  1104. if (ret < 0)
  1105. return ret;
  1106. call->count = ntohl(call->tmp);
  1107. _debug("motd length: %u", call->count);
  1108. if (call->count >= AFSNAMEMAX)
  1109. return afs_protocol_error(call, afs_eproto_motd_len);
  1110. size = (call->count + 3) & ~3; /* It's padded */
  1111. afs_extract_to_buf(call, size);
  1112. call->unmarshall++;
  1113. fallthrough;
  1114. /* extract the message of the day */
  1115. case 7:
  1116. _debug("extract motd");
  1117. ret = afs_extract_data(call, false);
  1118. if (ret < 0)
  1119. return ret;
  1120. p = call->buffer;
  1121. p[call->count] = 0;
  1122. _debug("motd '%s'", p);
  1123. call->unmarshall++;
  1124. fallthrough;
  1125. case 8:
  1126. break;
  1127. }
  1128. _leave(" = 0 [done]");
  1129. return 0;
  1130. }
  1131. /*
  1132. * YFS.GetVolumeStatus operation type
  1133. */
  1134. static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
  1135. .name = "YFS.GetVolumeStatus",
  1136. .op = yfs_FS_GetVolumeStatus,
  1137. .deliver = yfs_deliver_fs_get_volume_status,
  1138. .destructor = afs_flat_call_destructor,
  1139. };
  1140. /*
  1141. * fetch the status of a volume
  1142. */
  1143. void yfs_fs_get_volume_status(struct afs_operation *op)
  1144. {
  1145. struct afs_vnode_param *vp = &op->file[0];
  1146. struct afs_call *call;
  1147. __be32 *bp;
  1148. _enter("");
  1149. call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
  1150. sizeof(__be32) * 2 +
  1151. sizeof(struct yfs_xdr_u64),
  1152. max_t(size_t,
  1153. sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
  1154. sizeof(__be32),
  1155. AFSOPAQUEMAX + 1));
  1156. if (!call)
  1157. return afs_op_nomem(op);
  1158. /* marshall the parameters */
  1159. bp = call->request;
  1160. bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
  1161. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1162. bp = xdr_encode_u64(bp, vp->fid.vid);
  1163. yfs_check_req(call, bp);
  1164. trace_afs_make_fs_call(call, &vp->fid);
  1165. afs_make_op_call(op, call, GFP_NOFS);
  1166. }
  1167. /*
  1168. * YFS.SetLock operation type
  1169. */
  1170. static const struct afs_call_type yfs_RXYFSSetLock = {
  1171. .name = "YFS.SetLock",
  1172. .op = yfs_FS_SetLock,
  1173. .deliver = yfs_deliver_status_and_volsync,
  1174. .done = afs_lock_op_done,
  1175. .destructor = afs_flat_call_destructor,
  1176. };
  1177. /*
  1178. * YFS.ExtendLock operation type
  1179. */
  1180. static const struct afs_call_type yfs_RXYFSExtendLock = {
  1181. .name = "YFS.ExtendLock",
  1182. .op = yfs_FS_ExtendLock,
  1183. .deliver = yfs_deliver_status_and_volsync,
  1184. .done = afs_lock_op_done,
  1185. .destructor = afs_flat_call_destructor,
  1186. };
  1187. /*
  1188. * YFS.ReleaseLock operation type
  1189. */
  1190. static const struct afs_call_type yfs_RXYFSReleaseLock = {
  1191. .name = "YFS.ReleaseLock",
  1192. .op = yfs_FS_ReleaseLock,
  1193. .deliver = yfs_deliver_status_and_volsync,
  1194. .destructor = afs_flat_call_destructor,
  1195. };
  1196. /*
  1197. * Set a lock on a file
  1198. */
  1199. void yfs_fs_set_lock(struct afs_operation *op)
  1200. {
  1201. struct afs_vnode_param *vp = &op->file[0];
  1202. struct afs_call *call;
  1203. __be32 *bp;
  1204. _enter("");
  1205. call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
  1206. sizeof(__be32) * 2 +
  1207. sizeof(struct yfs_xdr_YFSFid) +
  1208. sizeof(__be32),
  1209. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1210. sizeof(struct yfs_xdr_YFSVolSync));
  1211. if (!call)
  1212. return afs_op_nomem(op);
  1213. /* marshall the parameters */
  1214. bp = call->request;
  1215. bp = xdr_encode_u32(bp, YFSSETLOCK);
  1216. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1217. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1218. bp = xdr_encode_u32(bp, op->lock.type);
  1219. yfs_check_req(call, bp);
  1220. trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
  1221. afs_make_op_call(op, call, GFP_NOFS);
  1222. }
  1223. /*
  1224. * extend a lock on a file
  1225. */
  1226. void yfs_fs_extend_lock(struct afs_operation *op)
  1227. {
  1228. struct afs_vnode_param *vp = &op->file[0];
  1229. struct afs_call *call;
  1230. __be32 *bp;
  1231. _enter("");
  1232. call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
  1233. sizeof(__be32) * 2 +
  1234. sizeof(struct yfs_xdr_YFSFid),
  1235. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1236. sizeof(struct yfs_xdr_YFSVolSync));
  1237. if (!call)
  1238. return afs_op_nomem(op);
  1239. /* marshall the parameters */
  1240. bp = call->request;
  1241. bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
  1242. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1243. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1244. yfs_check_req(call, bp);
  1245. trace_afs_make_fs_call(call, &vp->fid);
  1246. afs_make_op_call(op, call, GFP_NOFS);
  1247. }
  1248. /*
  1249. * release a lock on a file
  1250. */
  1251. void yfs_fs_release_lock(struct afs_operation *op)
  1252. {
  1253. struct afs_vnode_param *vp = &op->file[0];
  1254. struct afs_call *call;
  1255. __be32 *bp;
  1256. _enter("");
  1257. call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
  1258. sizeof(__be32) * 2 +
  1259. sizeof(struct yfs_xdr_YFSFid),
  1260. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1261. sizeof(struct yfs_xdr_YFSVolSync));
  1262. if (!call)
  1263. return afs_op_nomem(op);
  1264. /* marshall the parameters */
  1265. bp = call->request;
  1266. bp = xdr_encode_u32(bp, YFSRELEASELOCK);
  1267. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1268. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1269. yfs_check_req(call, bp);
  1270. trace_afs_make_fs_call(call, &vp->fid);
  1271. afs_make_op_call(op, call, GFP_NOFS);
  1272. }
  1273. /*
  1274. * Deliver a reply to YFS.FetchStatus
  1275. */
  1276. static int yfs_deliver_fs_fetch_status(struct afs_call *call)
  1277. {
  1278. struct afs_operation *op = call->op;
  1279. struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
  1280. const __be32 *bp;
  1281. int ret;
  1282. ret = afs_transfer_reply(call);
  1283. if (ret < 0)
  1284. return ret;
  1285. /* unmarshall the reply once we've received all of it */
  1286. bp = call->buffer;
  1287. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  1288. xdr_decode_YFSCallBack(&bp, call, &vp->scb);
  1289. xdr_decode_YFSVolSync(&bp, &op->volsync);
  1290. _leave(" = 0 [done]");
  1291. return 0;
  1292. }
  1293. /*
  1294. * YFS.FetchStatus operation type
  1295. */
  1296. static const struct afs_call_type yfs_RXYFSFetchStatus = {
  1297. .name = "YFS.FetchStatus",
  1298. .op = yfs_FS_FetchStatus,
  1299. .deliver = yfs_deliver_fs_fetch_status,
  1300. .destructor = afs_flat_call_destructor,
  1301. };
  1302. /*
  1303. * Fetch the status information for a fid without needing a vnode handle.
  1304. */
  1305. void yfs_fs_fetch_status(struct afs_operation *op)
  1306. {
  1307. struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
  1308. struct afs_call *call;
  1309. __be32 *bp;
  1310. _enter(",%x,{%llx:%llu},,",
  1311. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1312. call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
  1313. sizeof(__be32) * 2 +
  1314. sizeof(struct yfs_xdr_YFSFid),
  1315. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1316. sizeof(struct yfs_xdr_YFSCallBack) +
  1317. sizeof(struct yfs_xdr_YFSVolSync));
  1318. if (!call)
  1319. return afs_op_nomem(op);
  1320. /* marshall the parameters */
  1321. bp = call->request;
  1322. bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
  1323. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1324. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1325. yfs_check_req(call, bp);
  1326. trace_afs_make_fs_call(call, &vp->fid);
  1327. afs_make_op_call(op, call, GFP_NOFS);
  1328. }
  1329. /*
  1330. * Deliver reply data to an YFS.InlineBulkStatus call
  1331. */
  1332. static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
  1333. {
  1334. struct afs_operation *op = call->op;
  1335. struct afs_status_cb *scb;
  1336. const __be32 *bp;
  1337. u32 tmp;
  1338. int ret;
  1339. _enter("{%u}", call->unmarshall);
  1340. switch (call->unmarshall) {
  1341. case 0:
  1342. afs_extract_to_tmp(call);
  1343. call->unmarshall++;
  1344. fallthrough;
  1345. /* Extract the file status count and array in two steps */
  1346. case 1:
  1347. _debug("extract status count");
  1348. ret = afs_extract_data(call, true);
  1349. if (ret < 0)
  1350. return ret;
  1351. tmp = ntohl(call->tmp);
  1352. _debug("status count: %u/%u", tmp, op->nr_files);
  1353. if (tmp != op->nr_files)
  1354. return afs_protocol_error(call, afs_eproto_ibulkst_count);
  1355. call->count = 0;
  1356. call->unmarshall++;
  1357. more_counts:
  1358. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
  1359. fallthrough;
  1360. case 2:
  1361. _debug("extract status array %u", call->count);
  1362. ret = afs_extract_data(call, true);
  1363. if (ret < 0)
  1364. return ret;
  1365. switch (call->count) {
  1366. case 0:
  1367. scb = &op->file[0].scb;
  1368. break;
  1369. case 1:
  1370. scb = &op->file[1].scb;
  1371. break;
  1372. default:
  1373. scb = &op->more_files[call->count - 2].scb;
  1374. break;
  1375. }
  1376. bp = call->buffer;
  1377. xdr_decode_YFSFetchStatus(&bp, call, scb);
  1378. call->count++;
  1379. if (call->count < op->nr_files)
  1380. goto more_counts;
  1381. call->count = 0;
  1382. call->unmarshall++;
  1383. afs_extract_to_tmp(call);
  1384. fallthrough;
  1385. /* Extract the callback count and array in two steps */
  1386. case 3:
  1387. _debug("extract CB count");
  1388. ret = afs_extract_data(call, true);
  1389. if (ret < 0)
  1390. return ret;
  1391. tmp = ntohl(call->tmp);
  1392. _debug("CB count: %u", tmp);
  1393. if (tmp != op->nr_files)
  1394. return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
  1395. call->count = 0;
  1396. call->unmarshall++;
  1397. more_cbs:
  1398. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
  1399. fallthrough;
  1400. case 4:
  1401. _debug("extract CB array");
  1402. ret = afs_extract_data(call, true);
  1403. if (ret < 0)
  1404. return ret;
  1405. _debug("unmarshall CB array");
  1406. switch (call->count) {
  1407. case 0:
  1408. scb = &op->file[0].scb;
  1409. break;
  1410. case 1:
  1411. scb = &op->file[1].scb;
  1412. break;
  1413. default:
  1414. scb = &op->more_files[call->count - 2].scb;
  1415. break;
  1416. }
  1417. bp = call->buffer;
  1418. xdr_decode_YFSCallBack(&bp, call, scb);
  1419. call->count++;
  1420. if (call->count < op->nr_files)
  1421. goto more_cbs;
  1422. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
  1423. call->unmarshall++;
  1424. fallthrough;
  1425. case 5:
  1426. ret = afs_extract_data(call, false);
  1427. if (ret < 0)
  1428. return ret;
  1429. bp = call->buffer;
  1430. xdr_decode_YFSVolSync(&bp, &op->volsync);
  1431. call->unmarshall++;
  1432. fallthrough;
  1433. case 6:
  1434. break;
  1435. }
  1436. _leave(" = 0 [done]");
  1437. return 0;
  1438. }
  1439. /*
  1440. * FS.InlineBulkStatus operation type
  1441. */
  1442. static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
  1443. .name = "YFS.InlineBulkStatus",
  1444. .op = yfs_FS_InlineBulkStatus,
  1445. .deliver = yfs_deliver_fs_inline_bulk_status,
  1446. .destructor = afs_flat_call_destructor,
  1447. };
  1448. /*
  1449. * Fetch the status information for up to 1024 files
  1450. */
  1451. void yfs_fs_inline_bulk_status(struct afs_operation *op)
  1452. {
  1453. struct afs_vnode_param *dvp = &op->file[0];
  1454. struct afs_vnode_param *vp = &op->file[1];
  1455. struct afs_call *call;
  1456. __be32 *bp;
  1457. int i;
  1458. _enter(",%x,{%llx:%llu},%u",
  1459. key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
  1460. call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
  1461. sizeof(__be32) +
  1462. sizeof(__be32) +
  1463. sizeof(__be32) +
  1464. sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
  1465. sizeof(struct yfs_xdr_YFSFetchStatus));
  1466. if (!call)
  1467. return afs_op_nomem(op);
  1468. /* marshall the parameters */
  1469. bp = call->request;
  1470. bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
  1471. bp = xdr_encode_u32(bp, 0); /* RPCFlags */
  1472. bp = xdr_encode_u32(bp, op->nr_files);
  1473. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  1474. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1475. for (i = 0; i < op->nr_files - 2; i++)
  1476. bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
  1477. yfs_check_req(call, bp);
  1478. trace_afs_make_fs_call(call, &vp->fid);
  1479. afs_make_op_call(op, call, GFP_NOFS);
  1480. }
  1481. /*
  1482. * Deliver reply data to an YFS.FetchOpaqueACL.
  1483. */
  1484. static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
  1485. {
  1486. struct afs_operation *op = call->op;
  1487. struct afs_vnode_param *vp = &op->file[0];
  1488. struct yfs_acl *yacl = op->yacl;
  1489. struct afs_acl *acl;
  1490. const __be32 *bp;
  1491. unsigned int size;
  1492. int ret;
  1493. _enter("{%u}", call->unmarshall);
  1494. switch (call->unmarshall) {
  1495. case 0:
  1496. afs_extract_to_tmp(call);
  1497. call->unmarshall++;
  1498. fallthrough;
  1499. /* Extract the file ACL length */
  1500. case 1:
  1501. ret = afs_extract_data(call, true);
  1502. if (ret < 0)
  1503. return ret;
  1504. size = call->count2 = ntohl(call->tmp);
  1505. size = round_up(size, 4);
  1506. if (yacl->flags & YFS_ACL_WANT_ACL) {
  1507. acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
  1508. if (!acl)
  1509. return -ENOMEM;
  1510. yacl->acl = acl;
  1511. acl->size = call->count2;
  1512. afs_extract_begin(call, acl->data, size);
  1513. } else {
  1514. afs_extract_discard(call, size);
  1515. }
  1516. call->unmarshall++;
  1517. fallthrough;
  1518. /* Extract the file ACL */
  1519. case 2:
  1520. ret = afs_extract_data(call, true);
  1521. if (ret < 0)
  1522. return ret;
  1523. afs_extract_to_tmp(call);
  1524. call->unmarshall++;
  1525. fallthrough;
  1526. /* Extract the volume ACL length */
  1527. case 3:
  1528. ret = afs_extract_data(call, true);
  1529. if (ret < 0)
  1530. return ret;
  1531. size = call->count2 = ntohl(call->tmp);
  1532. size = round_up(size, 4);
  1533. if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
  1534. acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
  1535. if (!acl)
  1536. return -ENOMEM;
  1537. yacl->vol_acl = acl;
  1538. acl->size = call->count2;
  1539. afs_extract_begin(call, acl->data, size);
  1540. } else {
  1541. afs_extract_discard(call, size);
  1542. }
  1543. call->unmarshall++;
  1544. fallthrough;
  1545. /* Extract the volume ACL */
  1546. case 4:
  1547. ret = afs_extract_data(call, true);
  1548. if (ret < 0)
  1549. return ret;
  1550. afs_extract_to_buf(call,
  1551. sizeof(__be32) * 2 +
  1552. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1553. sizeof(struct yfs_xdr_YFSVolSync));
  1554. call->unmarshall++;
  1555. fallthrough;
  1556. /* extract the metadata */
  1557. case 5:
  1558. ret = afs_extract_data(call, false);
  1559. if (ret < 0)
  1560. return ret;
  1561. bp = call->buffer;
  1562. yacl->inherit_flag = ntohl(*bp++);
  1563. yacl->num_cleaned = ntohl(*bp++);
  1564. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  1565. xdr_decode_YFSVolSync(&bp, &op->volsync);
  1566. call->unmarshall++;
  1567. fallthrough;
  1568. case 6:
  1569. break;
  1570. }
  1571. _leave(" = 0 [done]");
  1572. return 0;
  1573. }
  1574. void yfs_free_opaque_acl(struct yfs_acl *yacl)
  1575. {
  1576. if (yacl) {
  1577. kfree(yacl->acl);
  1578. kfree(yacl->vol_acl);
  1579. kfree(yacl);
  1580. }
  1581. }
  1582. /*
  1583. * YFS.FetchOpaqueACL operation type
  1584. */
  1585. static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
  1586. .name = "YFS.FetchOpaqueACL",
  1587. .op = yfs_FS_FetchOpaqueACL,
  1588. .deliver = yfs_deliver_fs_fetch_opaque_acl,
  1589. .destructor = afs_flat_call_destructor,
  1590. };
  1591. /*
  1592. * Fetch the YFS advanced ACLs for a file.
  1593. */
  1594. void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
  1595. {
  1596. struct afs_vnode_param *vp = &op->file[0];
  1597. struct afs_call *call;
  1598. __be32 *bp;
  1599. _enter(",%x,{%llx:%llu},,",
  1600. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1601. call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
  1602. sizeof(__be32) * 2 +
  1603. sizeof(struct yfs_xdr_YFSFid),
  1604. sizeof(__be32) * 2 +
  1605. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1606. sizeof(struct yfs_xdr_YFSVolSync));
  1607. if (!call)
  1608. return afs_op_nomem(op);
  1609. /* marshall the parameters */
  1610. bp = call->request;
  1611. bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
  1612. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1613. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1614. yfs_check_req(call, bp);
  1615. trace_afs_make_fs_call(call, &vp->fid);
  1616. afs_make_op_call(op, call, GFP_KERNEL);
  1617. }
  1618. /*
  1619. * YFS.StoreOpaqueACL2 operation type
  1620. */
  1621. static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
  1622. .name = "YFS.StoreOpaqueACL2",
  1623. .op = yfs_FS_StoreOpaqueACL2,
  1624. .deliver = yfs_deliver_status_and_volsync,
  1625. .destructor = afs_flat_call_destructor,
  1626. };
  1627. /*
  1628. * Fetch the YFS ACL for a file.
  1629. */
  1630. void yfs_fs_store_opaque_acl2(struct afs_operation *op)
  1631. {
  1632. struct afs_vnode_param *vp = &op->file[0];
  1633. struct afs_call *call;
  1634. struct afs_acl *acl = op->acl;
  1635. size_t size;
  1636. __be32 *bp;
  1637. _enter(",%x,{%llx:%llu},,",
  1638. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1639. size = round_up(acl->size, 4);
  1640. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
  1641. sizeof(__be32) * 2 +
  1642. sizeof(struct yfs_xdr_YFSFid) +
  1643. sizeof(__be32) + size,
  1644. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1645. sizeof(struct yfs_xdr_YFSVolSync));
  1646. if (!call)
  1647. return afs_op_nomem(op);
  1648. /* marshall the parameters */
  1649. bp = call->request;
  1650. bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
  1651. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1652. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1653. bp = xdr_encode_u32(bp, acl->size);
  1654. memcpy(bp, acl->data, acl->size);
  1655. if (acl->size != size)
  1656. memset((void *)bp + acl->size, 0, size - acl->size);
  1657. bp += size / sizeof(__be32);
  1658. yfs_check_req(call, bp);
  1659. trace_afs_make_fs_call(call, &vp->fid);
  1660. afs_make_op_call(op, call, GFP_KERNEL);
  1661. }