yfsclient.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232
  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 (dhowells@redhat.com)
  6. */
  7. #include <linux/init.h>
  8. #include <linux/slab.h>
  9. #include <linux/sched.h>
  10. #include <linux/circ_buf.h>
  11. #include <linux/iversion.h>
  12. #include "internal.h"
  13. #include "afs_fs.h"
  14. #include "xdr_fs.h"
  15. #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, update;
  212. if (volsync) {
  213. creation = xdr_to_u64(x->vol_creation_date);
  214. do_div(creation, 10 * 1000 * 1000);
  215. volsync->creation = creation;
  216. update = xdr_to_u64(x->vol_update_date);
  217. do_div(update, 10 * 1000 * 1000);
  218. volsync->update = update;
  219. }
  220. *_bp += xdr_size(x);
  221. }
  222. /*
  223. * Encode the requested attributes into a YFSStoreStatus block
  224. */
  225. static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
  226. {
  227. struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
  228. s64 mtime = 0, owner = 0, group = 0;
  229. u32 mask = 0, mode = 0;
  230. mask = 0;
  231. if (attr->ia_valid & ATTR_MTIME) {
  232. mask |= AFS_SET_MTIME;
  233. mtime = linux_to_yfs_time(&attr->ia_mtime);
  234. }
  235. if (attr->ia_valid & ATTR_UID) {
  236. mask |= AFS_SET_OWNER;
  237. owner = from_kuid(&init_user_ns, attr->ia_uid);
  238. }
  239. if (attr->ia_valid & ATTR_GID) {
  240. mask |= AFS_SET_GROUP;
  241. group = from_kgid(&init_user_ns, attr->ia_gid);
  242. }
  243. if (attr->ia_valid & ATTR_MODE) {
  244. mask |= AFS_SET_MODE;
  245. mode = attr->ia_mode & S_IALLUGO;
  246. }
  247. x->mask = htonl(mask);
  248. x->mode = htonl(mode);
  249. x->mtime_client = u64_to_xdr(mtime);
  250. x->owner = u64_to_xdr(owner);
  251. x->group = u64_to_xdr(group);
  252. return bp + xdr_size(x);
  253. }
  254. /*
  255. * Decode a YFSFetchVolumeStatus block.
  256. */
  257. static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
  258. struct afs_volume_status *vs)
  259. {
  260. const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
  261. u32 flags;
  262. vs->vid = xdr_to_u64(x->vid);
  263. vs->parent_id = xdr_to_u64(x->parent_id);
  264. flags = ntohl(x->flags);
  265. vs->online = flags & yfs_FVSOnline;
  266. vs->in_service = flags & yfs_FVSInservice;
  267. vs->blessed = flags & yfs_FVSBlessed;
  268. vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
  269. vs->type = ntohl(x->type);
  270. vs->min_quota = 0;
  271. vs->max_quota = xdr_to_u64(x->max_quota);
  272. vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
  273. vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
  274. vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
  275. vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
  276. vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
  277. *_bp += sizeof(*x) / sizeof(__be32);
  278. }
  279. /*
  280. * Deliver reply data to operations that just return a file status and a volume
  281. * sync record.
  282. */
  283. static int yfs_deliver_status_and_volsync(struct afs_call *call)
  284. {
  285. struct afs_operation *op = call->op;
  286. const __be32 *bp;
  287. int ret;
  288. ret = afs_transfer_reply(call);
  289. if (ret < 0)
  290. return ret;
  291. bp = call->buffer;
  292. xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
  293. xdr_decode_YFSVolSync(&bp, &op->volsync);
  294. _leave(" = 0 [done]");
  295. return 0;
  296. }
  297. /*
  298. * Deliver reply data to an YFS.FetchData64.
  299. */
  300. static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
  301. {
  302. struct afs_operation *op = call->op;
  303. struct netfs_io_subrequest *subreq = op->fetch.subreq;
  304. struct afs_vnode_param *vp = &op->file[0];
  305. const __be32 *bp;
  306. size_t count_before;
  307. int ret;
  308. _enter("{%u,%zu, %zu/%llu}",
  309. call->unmarshall, call->iov_len, iov_iter_count(call->iter),
  310. call->remaining);
  311. switch (call->unmarshall) {
  312. case 0:
  313. call->remaining = 0;
  314. afs_extract_to_tmp64(call);
  315. call->unmarshall++;
  316. fallthrough;
  317. /* Extract the returned data length into ->actual_len. This
  318. * may indicate more or less data than was requested will be
  319. * returned.
  320. */
  321. case 1:
  322. _debug("extract data length");
  323. ret = afs_extract_data(call, true);
  324. if (ret < 0)
  325. return ret;
  326. call->remaining = be64_to_cpu(call->tmp64);
  327. _debug("DATA length: %llu", call->remaining);
  328. if (call->remaining == 0)
  329. goto no_more_data;
  330. call->iter = &subreq->io_iter;
  331. call->iov_len = min(call->remaining, subreq->len - subreq->transferred);
  332. call->unmarshall++;
  333. fallthrough;
  334. /* extract the returned data */
  335. case 2:
  336. count_before = call->iov_len;
  337. _debug("extract data %zu/%llu", count_before, call->remaining);
  338. ret = afs_extract_data(call, true);
  339. subreq->transferred += count_before - call->iov_len;
  340. if (ret < 0)
  341. return ret;
  342. call->iter = &call->def_iter;
  343. if (call->remaining)
  344. goto no_more_data;
  345. /* Discard any excess data the server gave us */
  346. afs_extract_discard(call, call->remaining);
  347. call->unmarshall = 3;
  348. fallthrough;
  349. case 3:
  350. _debug("extract discard %zu/%llu",
  351. iov_iter_count(call->iter), call->remaining);
  352. ret = afs_extract_data(call, true);
  353. if (ret < 0)
  354. return ret;
  355. no_more_data:
  356. call->unmarshall = 4;
  357. afs_extract_to_buf(call,
  358. sizeof(struct yfs_xdr_YFSFetchStatus) +
  359. sizeof(struct yfs_xdr_YFSCallBack) +
  360. sizeof(struct yfs_xdr_YFSVolSync));
  361. fallthrough;
  362. /* extract the metadata */
  363. case 4:
  364. ret = afs_extract_data(call, false);
  365. if (ret < 0)
  366. return ret;
  367. bp = call->buffer;
  368. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  369. xdr_decode_YFSCallBack(&bp, call, &vp->scb);
  370. xdr_decode_YFSVolSync(&bp, &op->volsync);
  371. if (subreq->start + subreq->transferred >= vp->scb.status.size)
  372. __set_bit(NETFS_SREQ_HIT_EOF, &subreq->flags);
  373. call->unmarshall++;
  374. fallthrough;
  375. case 5:
  376. break;
  377. }
  378. _leave(" = 0 [done]");
  379. return 0;
  380. }
  381. /*
  382. * YFS.FetchData64 operation type
  383. */
  384. static const struct afs_call_type yfs_RXYFSFetchData64 = {
  385. .name = "YFS.FetchData64",
  386. .op = yfs_FS_FetchData64,
  387. .async_rx = afs_fetch_data_async_rx,
  388. .deliver = yfs_deliver_fs_fetch_data64,
  389. .immediate_cancel = afs_fetch_data_immediate_cancel,
  390. .destructor = afs_flat_call_destructor,
  391. };
  392. /*
  393. * Fetch data from a file.
  394. */
  395. void yfs_fs_fetch_data(struct afs_operation *op)
  396. {
  397. struct netfs_io_subrequest *subreq = op->fetch.subreq;
  398. struct afs_vnode_param *vp = &op->file[0];
  399. struct afs_call *call;
  400. __be32 *bp;
  401. _enter(",%x,{%llx:%llu},%llx,%zx",
  402. key_serial(op->key), vp->fid.vid, vp->fid.vnode,
  403. subreq->start + subreq->transferred,
  404. subreq->len - subreq->transferred);
  405. call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
  406. sizeof(__be32) * 2 +
  407. sizeof(struct yfs_xdr_YFSFid) +
  408. sizeof(struct yfs_xdr_u64) * 2,
  409. sizeof(struct yfs_xdr_YFSFetchStatus) +
  410. sizeof(struct yfs_xdr_YFSCallBack) +
  411. sizeof(struct yfs_xdr_YFSVolSync));
  412. if (!call)
  413. return afs_op_nomem(op);
  414. if (op->flags & AFS_OPERATION_ASYNC)
  415. call->async = true;
  416. /* marshall the parameters */
  417. bp = call->request;
  418. bp = xdr_encode_u32(bp, YFSFETCHDATA64);
  419. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  420. bp = xdr_encode_YFSFid(bp, &vp->fid);
  421. bp = xdr_encode_u64(bp, subreq->start + subreq->transferred);
  422. bp = xdr_encode_u64(bp, subreq->len - subreq->transferred);
  423. yfs_check_req(call, bp);
  424. call->fid = vp->fid;
  425. trace_afs_make_fs_call(call, &vp->fid);
  426. afs_make_op_call(op, call, GFP_NOFS);
  427. }
  428. /*
  429. * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
  430. */
  431. static int yfs_deliver_fs_create_vnode(struct afs_call *call)
  432. {
  433. struct afs_operation *op = call->op;
  434. struct afs_vnode_param *dvp = &op->file[0];
  435. struct afs_vnode_param *vp = &op->file[1];
  436. const __be32 *bp;
  437. int ret;
  438. _enter("{%u}", call->unmarshall);
  439. ret = afs_transfer_reply(call);
  440. if (ret < 0)
  441. return ret;
  442. /* unmarshall the reply once we've received all of it */
  443. bp = call->buffer;
  444. xdr_decode_YFSFid(&bp, &op->file[1].fid);
  445. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  446. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  447. xdr_decode_YFSCallBack(&bp, call, &vp->scb);
  448. xdr_decode_YFSVolSync(&bp, &op->volsync);
  449. _leave(" = 0 [done]");
  450. return 0;
  451. }
  452. /*
  453. * FS.CreateFile and FS.MakeDir operation type
  454. */
  455. static const struct afs_call_type afs_RXFSCreateFile = {
  456. .name = "YFS.CreateFile",
  457. .op = yfs_FS_CreateFile,
  458. .deliver = yfs_deliver_fs_create_vnode,
  459. .destructor = afs_flat_call_destructor,
  460. };
  461. /*
  462. * Create a file.
  463. */
  464. void yfs_fs_create_file(struct afs_operation *op)
  465. {
  466. const struct qstr *name = &op->dentry->d_name;
  467. struct afs_vnode_param *dvp = &op->file[0];
  468. struct afs_call *call;
  469. size_t reqsz, rplsz;
  470. __be32 *bp;
  471. _enter("");
  472. reqsz = (sizeof(__be32) +
  473. sizeof(__be32) +
  474. sizeof(struct yfs_xdr_YFSFid) +
  475. xdr_strlen(name->len) +
  476. sizeof(struct yfs_xdr_YFSStoreStatus) +
  477. sizeof(__be32));
  478. rplsz = (sizeof(struct yfs_xdr_YFSFid) +
  479. sizeof(struct yfs_xdr_YFSFetchStatus) +
  480. sizeof(struct yfs_xdr_YFSFetchStatus) +
  481. sizeof(struct yfs_xdr_YFSCallBack) +
  482. sizeof(struct yfs_xdr_YFSVolSync));
  483. call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
  484. if (!call)
  485. return afs_op_nomem(op);
  486. /* marshall the parameters */
  487. bp = call->request;
  488. bp = xdr_encode_u32(bp, YFSCREATEFILE);
  489. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  490. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  491. bp = xdr_encode_name(bp, name);
  492. bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
  493. bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
  494. yfs_check_req(call, bp);
  495. call->fid = dvp->fid;
  496. trace_afs_make_fs_call1(call, &dvp->fid, name);
  497. afs_make_op_call(op, call, GFP_NOFS);
  498. }
  499. static const struct afs_call_type yfs_RXFSMakeDir = {
  500. .name = "YFS.MakeDir",
  501. .op = yfs_FS_MakeDir,
  502. .deliver = yfs_deliver_fs_create_vnode,
  503. .destructor = afs_flat_call_destructor,
  504. };
  505. /*
  506. * Make a directory.
  507. */
  508. void yfs_fs_make_dir(struct afs_operation *op)
  509. {
  510. const struct qstr *name = &op->dentry->d_name;
  511. struct afs_vnode_param *dvp = &op->file[0];
  512. struct afs_call *call;
  513. size_t reqsz, rplsz;
  514. __be32 *bp;
  515. _enter("");
  516. reqsz = (sizeof(__be32) +
  517. sizeof(struct yfs_xdr_RPCFlags) +
  518. sizeof(struct yfs_xdr_YFSFid) +
  519. xdr_strlen(name->len) +
  520. sizeof(struct yfs_xdr_YFSStoreStatus));
  521. rplsz = (sizeof(struct yfs_xdr_YFSFid) +
  522. sizeof(struct yfs_xdr_YFSFetchStatus) +
  523. sizeof(struct yfs_xdr_YFSFetchStatus) +
  524. sizeof(struct yfs_xdr_YFSCallBack) +
  525. sizeof(struct yfs_xdr_YFSVolSync));
  526. call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
  527. if (!call)
  528. return afs_op_nomem(op);
  529. /* marshall the parameters */
  530. bp = call->request;
  531. bp = xdr_encode_u32(bp, YFSMAKEDIR);
  532. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  533. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  534. bp = xdr_encode_name(bp, name);
  535. bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
  536. yfs_check_req(call, bp);
  537. call->fid = dvp->fid;
  538. trace_afs_make_fs_call1(call, &dvp->fid, name);
  539. afs_make_op_call(op, call, GFP_NOFS);
  540. }
  541. /*
  542. * Deliver reply data to a YFS.RemoveFile2 operation.
  543. */
  544. static int yfs_deliver_fs_remove_file2(struct afs_call *call)
  545. {
  546. struct afs_operation *op = call->op;
  547. struct afs_vnode_param *dvp = &op->file[0];
  548. struct afs_vnode_param *vp = &op->file[1];
  549. struct afs_fid fid;
  550. const __be32 *bp;
  551. int ret;
  552. _enter("{%u}", call->unmarshall);
  553. ret = afs_transfer_reply(call);
  554. if (ret < 0)
  555. return ret;
  556. bp = call->buffer;
  557. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  558. xdr_decode_YFSFid(&bp, &fid);
  559. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  560. /* Was deleted if vnode->status.abort_code == VNOVNODE. */
  561. xdr_decode_YFSVolSync(&bp, &op->volsync);
  562. return 0;
  563. }
  564. static void yfs_done_fs_remove_file2(struct afs_call *call)
  565. {
  566. if (call->error == -ECONNABORTED &&
  567. (call->abort_code == RX_INVALID_OPERATION ||
  568. call->abort_code == RXGEN_OPCODE)) {
  569. set_bit(AFS_SERVER_FL_NO_RM2, &call->op->server->flags);
  570. call->op->flags |= AFS_OPERATION_DOWNGRADE;
  571. }
  572. }
  573. /*
  574. * YFS.RemoveFile2 operation type.
  575. */
  576. static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
  577. .name = "YFS.RemoveFile2",
  578. .op = yfs_FS_RemoveFile2,
  579. .deliver = yfs_deliver_fs_remove_file2,
  580. .done = yfs_done_fs_remove_file2,
  581. .destructor = afs_flat_call_destructor,
  582. };
  583. /*
  584. * Remove a file and retrieve new file status.
  585. */
  586. void yfs_fs_remove_file2(struct afs_operation *op)
  587. {
  588. struct afs_vnode_param *dvp = &op->file[0];
  589. const struct qstr *name = &op->dentry->d_name;
  590. struct afs_call *call;
  591. __be32 *bp;
  592. _enter("");
  593. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
  594. sizeof(__be32) +
  595. sizeof(struct yfs_xdr_RPCFlags) +
  596. sizeof(struct yfs_xdr_YFSFid) +
  597. xdr_strlen(name->len),
  598. sizeof(struct yfs_xdr_YFSFetchStatus) +
  599. sizeof(struct yfs_xdr_YFSFid) +
  600. sizeof(struct yfs_xdr_YFSFetchStatus) +
  601. sizeof(struct yfs_xdr_YFSVolSync));
  602. if (!call)
  603. return afs_op_nomem(op);
  604. /* marshall the parameters */
  605. bp = call->request;
  606. bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
  607. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  608. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  609. bp = xdr_encode_name(bp, name);
  610. yfs_check_req(call, bp);
  611. call->fid = dvp->fid;
  612. trace_afs_make_fs_call1(call, &dvp->fid, name);
  613. afs_make_op_call(op, call, GFP_NOFS);
  614. }
  615. /*
  616. * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
  617. */
  618. static int yfs_deliver_fs_remove(struct afs_call *call)
  619. {
  620. struct afs_operation *op = call->op;
  621. struct afs_vnode_param *dvp = &op->file[0];
  622. const __be32 *bp;
  623. int ret;
  624. _enter("{%u}", call->unmarshall);
  625. ret = afs_transfer_reply(call);
  626. if (ret < 0)
  627. return ret;
  628. bp = call->buffer;
  629. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  630. xdr_decode_YFSVolSync(&bp, &op->volsync);
  631. return 0;
  632. }
  633. /*
  634. * FS.RemoveDir and FS.RemoveFile operation types.
  635. */
  636. static const struct afs_call_type yfs_RXYFSRemoveFile = {
  637. .name = "YFS.RemoveFile",
  638. .op = yfs_FS_RemoveFile,
  639. .deliver = yfs_deliver_fs_remove,
  640. .destructor = afs_flat_call_destructor,
  641. };
  642. /*
  643. * Remove a file.
  644. */
  645. void yfs_fs_remove_file(struct afs_operation *op)
  646. {
  647. const struct qstr *name = &op->dentry->d_name;
  648. struct afs_vnode_param *dvp = &op->file[0];
  649. struct afs_call *call;
  650. __be32 *bp;
  651. _enter("");
  652. if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
  653. return yfs_fs_remove_file2(op);
  654. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
  655. sizeof(__be32) +
  656. sizeof(struct yfs_xdr_RPCFlags) +
  657. sizeof(struct yfs_xdr_YFSFid) +
  658. xdr_strlen(name->len),
  659. sizeof(struct yfs_xdr_YFSFetchStatus) +
  660. sizeof(struct yfs_xdr_YFSVolSync));
  661. if (!call)
  662. return afs_op_nomem(op);
  663. /* marshall the parameters */
  664. bp = call->request;
  665. bp = xdr_encode_u32(bp, YFSREMOVEFILE);
  666. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  667. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  668. bp = xdr_encode_name(bp, name);
  669. yfs_check_req(call, bp);
  670. call->fid = dvp->fid;
  671. trace_afs_make_fs_call1(call, &dvp->fid, name);
  672. afs_make_op_call(op, call, GFP_NOFS);
  673. }
  674. static const struct afs_call_type yfs_RXYFSRemoveDir = {
  675. .name = "YFS.RemoveDir",
  676. .op = yfs_FS_RemoveDir,
  677. .deliver = yfs_deliver_fs_remove,
  678. .destructor = afs_flat_call_destructor,
  679. };
  680. /*
  681. * Remove a directory.
  682. */
  683. void yfs_fs_remove_dir(struct afs_operation *op)
  684. {
  685. const struct qstr *name = &op->dentry->d_name;
  686. struct afs_vnode_param *dvp = &op->file[0];
  687. struct afs_call *call;
  688. __be32 *bp;
  689. _enter("");
  690. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
  691. sizeof(__be32) +
  692. sizeof(struct yfs_xdr_RPCFlags) +
  693. sizeof(struct yfs_xdr_YFSFid) +
  694. xdr_strlen(name->len),
  695. sizeof(struct yfs_xdr_YFSFetchStatus) +
  696. sizeof(struct yfs_xdr_YFSVolSync));
  697. if (!call)
  698. return afs_op_nomem(op);
  699. /* marshall the parameters */
  700. bp = call->request;
  701. bp = xdr_encode_u32(bp, YFSREMOVEDIR);
  702. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  703. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  704. bp = xdr_encode_name(bp, name);
  705. yfs_check_req(call, bp);
  706. call->fid = dvp->fid;
  707. trace_afs_make_fs_call1(call, &dvp->fid, name);
  708. afs_make_op_call(op, call, GFP_NOFS);
  709. }
  710. /*
  711. * Deliver reply data to a YFS.Link operation.
  712. */
  713. static int yfs_deliver_fs_link(struct afs_call *call)
  714. {
  715. struct afs_operation *op = call->op;
  716. struct afs_vnode_param *dvp = &op->file[0];
  717. struct afs_vnode_param *vp = &op->file[1];
  718. const __be32 *bp;
  719. int ret;
  720. _enter("{%u}", call->unmarshall);
  721. ret = afs_transfer_reply(call);
  722. if (ret < 0)
  723. return ret;
  724. bp = call->buffer;
  725. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  726. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  727. xdr_decode_YFSVolSync(&bp, &op->volsync);
  728. _leave(" = 0 [done]");
  729. return 0;
  730. }
  731. /*
  732. * YFS.Link operation type.
  733. */
  734. static const struct afs_call_type yfs_RXYFSLink = {
  735. .name = "YFS.Link",
  736. .op = yfs_FS_Link,
  737. .deliver = yfs_deliver_fs_link,
  738. .destructor = afs_flat_call_destructor,
  739. };
  740. /*
  741. * Make a hard link.
  742. */
  743. void yfs_fs_link(struct afs_operation *op)
  744. {
  745. const struct qstr *name = &op->dentry->d_name;
  746. struct afs_vnode_param *dvp = &op->file[0];
  747. struct afs_vnode_param *vp = &op->file[1];
  748. struct afs_call *call;
  749. __be32 *bp;
  750. _enter("");
  751. call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
  752. sizeof(__be32) +
  753. sizeof(struct yfs_xdr_RPCFlags) +
  754. sizeof(struct yfs_xdr_YFSFid) +
  755. xdr_strlen(name->len) +
  756. sizeof(struct yfs_xdr_YFSFid),
  757. sizeof(struct yfs_xdr_YFSFetchStatus) +
  758. sizeof(struct yfs_xdr_YFSFetchStatus) +
  759. sizeof(struct yfs_xdr_YFSVolSync));
  760. if (!call)
  761. return afs_op_nomem(op);
  762. /* marshall the parameters */
  763. bp = call->request;
  764. bp = xdr_encode_u32(bp, YFSLINK);
  765. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  766. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  767. bp = xdr_encode_name(bp, name);
  768. bp = xdr_encode_YFSFid(bp, &vp->fid);
  769. yfs_check_req(call, bp);
  770. call->fid = vp->fid;
  771. trace_afs_make_fs_call1(call, &vp->fid, name);
  772. afs_make_op_call(op, call, GFP_NOFS);
  773. }
  774. /*
  775. * Deliver reply data to a YFS.Symlink operation.
  776. */
  777. static int yfs_deliver_fs_symlink(struct afs_call *call)
  778. {
  779. struct afs_operation *op = call->op;
  780. struct afs_vnode_param *dvp = &op->file[0];
  781. struct afs_vnode_param *vp = &op->file[1];
  782. const __be32 *bp;
  783. int ret;
  784. _enter("{%u}", call->unmarshall);
  785. ret = afs_transfer_reply(call);
  786. if (ret < 0)
  787. return ret;
  788. /* unmarshall the reply once we've received all of it */
  789. bp = call->buffer;
  790. xdr_decode_YFSFid(&bp, &vp->fid);
  791. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  792. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  793. xdr_decode_YFSVolSync(&bp, &op->volsync);
  794. _leave(" = 0 [done]");
  795. return 0;
  796. }
  797. /*
  798. * YFS.Symlink operation type
  799. */
  800. static const struct afs_call_type yfs_RXYFSSymlink = {
  801. .name = "YFS.Symlink",
  802. .op = yfs_FS_Symlink,
  803. .deliver = yfs_deliver_fs_symlink,
  804. .destructor = afs_flat_call_destructor,
  805. };
  806. /*
  807. * Create a symbolic link.
  808. */
  809. void yfs_fs_symlink(struct afs_operation *op)
  810. {
  811. const struct qstr *name = &op->dentry->d_name;
  812. struct afs_vnode_param *dvp = &op->file[0];
  813. struct afs_call *call;
  814. size_t contents_sz;
  815. mode_t mode = 0777;
  816. __be32 *bp;
  817. _enter("");
  818. contents_sz = strlen(op->create.symlink);
  819. call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
  820. sizeof(__be32) +
  821. sizeof(struct yfs_xdr_RPCFlags) +
  822. sizeof(struct yfs_xdr_YFSFid) +
  823. xdr_strlen(name->len) +
  824. xdr_strlen(contents_sz) +
  825. sizeof(struct yfs_xdr_YFSStoreStatus),
  826. sizeof(struct yfs_xdr_YFSFid) +
  827. sizeof(struct yfs_xdr_YFSFetchStatus) +
  828. sizeof(struct yfs_xdr_YFSFetchStatus) +
  829. sizeof(struct yfs_xdr_YFSVolSync));
  830. if (!call)
  831. return afs_op_nomem(op);
  832. /* marshall the parameters */
  833. bp = call->request;
  834. bp = xdr_encode_u32(bp, YFSSYMLINK);
  835. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  836. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  837. bp = xdr_encode_name(bp, name);
  838. bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
  839. bp = xdr_encode_YFSStoreStatus(bp, &mode, &op->mtime);
  840. yfs_check_req(call, bp);
  841. call->fid = dvp->fid;
  842. trace_afs_make_fs_call1(call, &dvp->fid, name);
  843. afs_make_op_call(op, call, GFP_NOFS);
  844. }
  845. /*
  846. * Deliver reply data to a YFS.Rename operation.
  847. */
  848. static int yfs_deliver_fs_rename(struct afs_call *call)
  849. {
  850. struct afs_operation *op = call->op;
  851. struct afs_vnode_param *orig_dvp = &op->file[0];
  852. struct afs_vnode_param *new_dvp = &op->file[1];
  853. const __be32 *bp;
  854. int ret;
  855. _enter("{%u}", call->unmarshall);
  856. ret = afs_transfer_reply(call);
  857. if (ret < 0)
  858. return ret;
  859. bp = call->buffer;
  860. /* If the two dirs are the same, we have two copies of the same status
  861. * report, so we just decode it twice.
  862. */
  863. xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
  864. xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
  865. xdr_decode_YFSVolSync(&bp, &op->volsync);
  866. _leave(" = 0 [done]");
  867. return 0;
  868. }
  869. /*
  870. * YFS.Rename operation type
  871. */
  872. static const struct afs_call_type yfs_RXYFSRename = {
  873. .name = "FS.Rename",
  874. .op = yfs_FS_Rename,
  875. .deliver = yfs_deliver_fs_rename,
  876. .destructor = afs_flat_call_destructor,
  877. };
  878. /*
  879. * Rename a file or directory.
  880. */
  881. void yfs_fs_rename(struct afs_operation *op)
  882. {
  883. struct afs_vnode_param *orig_dvp = &op->file[0];
  884. struct afs_vnode_param *new_dvp = &op->file[1];
  885. const struct qstr *orig_name = &op->dentry->d_name;
  886. const struct qstr *new_name = &op->dentry_2->d_name;
  887. struct afs_call *call;
  888. __be32 *bp;
  889. _enter("");
  890. if (!test_bit(AFS_SERVER_FL_NO_RENAME2, &op->server->flags))
  891. return yfs_fs_rename_replace(op);
  892. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
  893. sizeof(__be32) +
  894. sizeof(struct yfs_xdr_RPCFlags) +
  895. sizeof(struct yfs_xdr_YFSFid) +
  896. xdr_strlen(orig_name->len) +
  897. sizeof(struct yfs_xdr_YFSFid) +
  898. xdr_strlen(new_name->len),
  899. sizeof(struct yfs_xdr_YFSFetchStatus) +
  900. sizeof(struct yfs_xdr_YFSFetchStatus) +
  901. sizeof(struct yfs_xdr_YFSVolSync));
  902. if (!call)
  903. return afs_op_nomem(op);
  904. /* marshall the parameters */
  905. bp = call->request;
  906. bp = xdr_encode_u32(bp, YFSRENAME);
  907. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  908. bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
  909. bp = xdr_encode_name(bp, orig_name);
  910. bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
  911. bp = xdr_encode_name(bp, new_name);
  912. yfs_check_req(call, bp);
  913. call->fid = orig_dvp->fid;
  914. trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
  915. afs_make_op_call(op, call, GFP_NOFS);
  916. }
  917. /*
  918. * Deliver reply data to a YFS.Rename_NoReplace operation. This does not
  919. * return the status of a displaced target inode as there cannot be one.
  920. */
  921. static int yfs_deliver_fs_rename_1(struct afs_call *call)
  922. {
  923. struct afs_operation *op = call->op;
  924. struct afs_vnode_param *orig_dvp = &op->file[0];
  925. struct afs_vnode_param *new_dvp = &op->file[1];
  926. struct afs_vnode_param *old_vp = &op->more_files[0];
  927. const __be32 *bp;
  928. int ret;
  929. _enter("{%u}", call->unmarshall);
  930. ret = afs_transfer_reply(call);
  931. if (ret < 0)
  932. return ret;
  933. bp = call->buffer;
  934. /* If the two dirs are the same, we have two copies of the same status
  935. * report, so we just decode it twice.
  936. */
  937. xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
  938. xdr_decode_YFSFid(&bp, &old_vp->fid);
  939. xdr_decode_YFSFetchStatus(&bp, call, &old_vp->scb);
  940. xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
  941. xdr_decode_YFSVolSync(&bp, &op->volsync);
  942. _leave(" = 0 [done]");
  943. return 0;
  944. }
  945. /*
  946. * Deliver reply data to a YFS.Rename_Replace or a YFS.Rename_Exchange
  947. * operation. These return the status of the displaced target inode if there
  948. * was one.
  949. */
  950. static int yfs_deliver_fs_rename_2(struct afs_call *call)
  951. {
  952. struct afs_operation *op = call->op;
  953. struct afs_vnode_param *orig_dvp = &op->file[0];
  954. struct afs_vnode_param *new_dvp = &op->file[1];
  955. struct afs_vnode_param *old_vp = &op->more_files[0];
  956. struct afs_vnode_param *new_vp = &op->more_files[1];
  957. const __be32 *bp;
  958. int ret;
  959. _enter("{%u}", call->unmarshall);
  960. ret = afs_transfer_reply(call);
  961. if (ret < 0)
  962. return ret;
  963. bp = call->buffer;
  964. /* If the two dirs are the same, we have two copies of the same status
  965. * report, so we just decode it twice.
  966. */
  967. xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
  968. xdr_decode_YFSFid(&bp, &old_vp->fid);
  969. xdr_decode_YFSFetchStatus(&bp, call, &old_vp->scb);
  970. xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
  971. xdr_decode_YFSFid(&bp, &new_vp->fid);
  972. xdr_decode_YFSFetchStatus(&bp, call, &new_vp->scb);
  973. xdr_decode_YFSVolSync(&bp, &op->volsync);
  974. _leave(" = 0 [done]");
  975. return 0;
  976. }
  977. static void yfs_done_fs_rename_replace(struct afs_call *call)
  978. {
  979. if (call->error == -ECONNABORTED &&
  980. (call->abort_code == RX_INVALID_OPERATION ||
  981. call->abort_code == RXGEN_OPCODE)) {
  982. set_bit(AFS_SERVER_FL_NO_RENAME2, &call->op->server->flags);
  983. call->op->flags |= AFS_OPERATION_DOWNGRADE;
  984. }
  985. }
  986. /*
  987. * YFS.Rename_Replace operation type
  988. */
  989. static const struct afs_call_type yfs_RXYFSRename_Replace = {
  990. .name = "FS.Rename_Replace",
  991. .op = yfs_FS_Rename_Replace,
  992. .deliver = yfs_deliver_fs_rename_2,
  993. .done = yfs_done_fs_rename_replace,
  994. .destructor = afs_flat_call_destructor,
  995. };
  996. /*
  997. * YFS.Rename_NoReplace operation type
  998. */
  999. static const struct afs_call_type yfs_RXYFSRename_NoReplace = {
  1000. .name = "FS.Rename_NoReplace",
  1001. .op = yfs_FS_Rename_NoReplace,
  1002. .deliver = yfs_deliver_fs_rename_1,
  1003. .destructor = afs_flat_call_destructor,
  1004. };
  1005. /*
  1006. * YFS.Rename_Exchange operation type
  1007. */
  1008. static const struct afs_call_type yfs_RXYFSRename_Exchange = {
  1009. .name = "FS.Rename_Exchange",
  1010. .op = yfs_FS_Rename_Exchange,
  1011. .deliver = yfs_deliver_fs_rename_2,
  1012. .destructor = afs_flat_call_destructor,
  1013. };
  1014. /*
  1015. * Rename a file or directory, replacing the target if it exists. The status
  1016. * of a displaced target is returned.
  1017. */
  1018. void yfs_fs_rename_replace(struct afs_operation *op)
  1019. {
  1020. struct afs_vnode_param *orig_dvp = &op->file[0];
  1021. struct afs_vnode_param *new_dvp = &op->file[1];
  1022. const struct qstr *orig_name = &op->dentry->d_name;
  1023. const struct qstr *new_name = &op->dentry_2->d_name;
  1024. struct afs_call *call;
  1025. __be32 *bp;
  1026. _enter("");
  1027. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename_Replace,
  1028. sizeof(__be32) +
  1029. sizeof(struct yfs_xdr_RPCFlags) +
  1030. sizeof(struct yfs_xdr_YFSFid) +
  1031. xdr_strlen(orig_name->len) +
  1032. sizeof(struct yfs_xdr_YFSFid) +
  1033. xdr_strlen(new_name->len),
  1034. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1035. sizeof(struct yfs_xdr_YFSFid) +
  1036. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1037. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1038. sizeof(struct yfs_xdr_YFSFid) +
  1039. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1040. sizeof(struct yfs_xdr_YFSVolSync));
  1041. if (!call)
  1042. return afs_op_nomem(op);
  1043. /* Marshall the parameters. */
  1044. bp = call->request;
  1045. bp = xdr_encode_u32(bp, YFSRENAME_REPLACE);
  1046. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1047. bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
  1048. bp = xdr_encode_name(bp, orig_name);
  1049. bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
  1050. bp = xdr_encode_name(bp, new_name);
  1051. yfs_check_req(call, bp);
  1052. call->fid = orig_dvp->fid;
  1053. trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
  1054. afs_make_op_call(op, call, GFP_NOFS);
  1055. }
  1056. /*
  1057. * Rename a file or directory, failing if the target dirent exists.
  1058. */
  1059. void yfs_fs_rename_noreplace(struct afs_operation *op)
  1060. {
  1061. struct afs_vnode_param *orig_dvp = &op->file[0];
  1062. struct afs_vnode_param *new_dvp = &op->file[1];
  1063. const struct qstr *orig_name = &op->dentry->d_name;
  1064. const struct qstr *new_name = &op->dentry_2->d_name;
  1065. struct afs_call *call;
  1066. __be32 *bp;
  1067. _enter("");
  1068. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename_NoReplace,
  1069. sizeof(__be32) +
  1070. sizeof(struct yfs_xdr_RPCFlags) +
  1071. sizeof(struct yfs_xdr_YFSFid) +
  1072. xdr_strlen(orig_name->len) +
  1073. sizeof(struct yfs_xdr_YFSFid) +
  1074. xdr_strlen(new_name->len),
  1075. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1076. sizeof(struct yfs_xdr_YFSFid) +
  1077. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1078. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1079. sizeof(struct yfs_xdr_YFSVolSync));
  1080. if (!call)
  1081. return afs_op_nomem(op);
  1082. /* Marshall the parameters. */
  1083. bp = call->request;
  1084. bp = xdr_encode_u32(bp, YFSRENAME_NOREPLACE);
  1085. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1086. bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
  1087. bp = xdr_encode_name(bp, orig_name);
  1088. bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
  1089. bp = xdr_encode_name(bp, new_name);
  1090. yfs_check_req(call, bp);
  1091. call->fid = orig_dvp->fid;
  1092. trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
  1093. afs_make_op_call(op, call, GFP_NOFS);
  1094. }
  1095. /*
  1096. * Exchange a pair of files directories.
  1097. */
  1098. void yfs_fs_rename_exchange(struct afs_operation *op)
  1099. {
  1100. struct afs_vnode_param *orig_dvp = &op->file[0];
  1101. struct afs_vnode_param *new_dvp = &op->file[1];
  1102. const struct qstr *orig_name = &op->dentry->d_name;
  1103. const struct qstr *new_name = &op->dentry_2->d_name;
  1104. struct afs_call *call;
  1105. __be32 *bp;
  1106. _enter("");
  1107. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename_Exchange,
  1108. sizeof(__be32) +
  1109. sizeof(struct yfs_xdr_RPCFlags) +
  1110. sizeof(struct yfs_xdr_YFSFid) +
  1111. xdr_strlen(orig_name->len) +
  1112. sizeof(struct yfs_xdr_YFSFid) +
  1113. xdr_strlen(new_name->len),
  1114. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1115. sizeof(struct yfs_xdr_YFSFid) +
  1116. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1117. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1118. sizeof(struct yfs_xdr_YFSFid) +
  1119. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1120. sizeof(struct yfs_xdr_YFSVolSync));
  1121. if (!call)
  1122. return afs_op_nomem(op);
  1123. /* Marshall the parameters. */
  1124. bp = call->request;
  1125. bp = xdr_encode_u32(bp, YFSRENAME_EXCHANGE);
  1126. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1127. bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
  1128. bp = xdr_encode_name(bp, orig_name);
  1129. bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
  1130. bp = xdr_encode_name(bp, new_name);
  1131. yfs_check_req(call, bp);
  1132. call->fid = orig_dvp->fid;
  1133. trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
  1134. afs_make_op_call(op, call, GFP_NOFS);
  1135. }
  1136. /*
  1137. * YFS.StoreData64 operation type.
  1138. */
  1139. static const struct afs_call_type yfs_RXYFSStoreData64 = {
  1140. .name = "YFS.StoreData64",
  1141. .op = yfs_FS_StoreData64,
  1142. .deliver = yfs_deliver_status_and_volsync,
  1143. .destructor = afs_flat_call_destructor,
  1144. };
  1145. /*
  1146. * Store a set of pages to a large file.
  1147. */
  1148. void yfs_fs_store_data(struct afs_operation *op)
  1149. {
  1150. struct afs_vnode_param *vp = &op->file[0];
  1151. struct afs_call *call;
  1152. __be32 *bp;
  1153. _enter(",%x,{%llx:%llu},,",
  1154. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1155. _debug("size %llx, at %llx, i_size %llx",
  1156. (unsigned long long)op->store.size,
  1157. (unsigned long long)op->store.pos,
  1158. (unsigned long long)op->store.i_size);
  1159. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
  1160. sizeof(__be32) +
  1161. sizeof(__be32) +
  1162. sizeof(struct yfs_xdr_YFSFid) +
  1163. sizeof(struct yfs_xdr_YFSStoreStatus) +
  1164. sizeof(struct yfs_xdr_u64) * 3,
  1165. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1166. sizeof(struct yfs_xdr_YFSVolSync));
  1167. if (!call)
  1168. return afs_op_nomem(op);
  1169. call->write_iter = op->store.write_iter;
  1170. /* marshall the parameters */
  1171. bp = call->request;
  1172. bp = xdr_encode_u32(bp, YFSSTOREDATA64);
  1173. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1174. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1175. bp = xdr_encode_YFSStoreStatus(bp, NULL, &op->mtime);
  1176. bp = xdr_encode_u64(bp, op->store.pos);
  1177. bp = xdr_encode_u64(bp, op->store.size);
  1178. bp = xdr_encode_u64(bp, op->store.i_size);
  1179. yfs_check_req(call, bp);
  1180. call->fid = vp->fid;
  1181. trace_afs_make_fs_call(call, &vp->fid);
  1182. afs_make_op_call(op, call, GFP_NOFS);
  1183. }
  1184. /*
  1185. * YFS.StoreStatus operation type
  1186. */
  1187. static const struct afs_call_type yfs_RXYFSStoreStatus = {
  1188. .name = "YFS.StoreStatus",
  1189. .op = yfs_FS_StoreStatus,
  1190. .deliver = yfs_deliver_status_and_volsync,
  1191. .destructor = afs_flat_call_destructor,
  1192. };
  1193. static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
  1194. .name = "YFS.StoreData64",
  1195. .op = yfs_FS_StoreData64,
  1196. .deliver = yfs_deliver_status_and_volsync,
  1197. .destructor = afs_flat_call_destructor,
  1198. };
  1199. /*
  1200. * Set the attributes on a file, using YFS.StoreData64 rather than
  1201. * YFS.StoreStatus so as to alter the file size also.
  1202. */
  1203. static void yfs_fs_setattr_size(struct afs_operation *op)
  1204. {
  1205. struct afs_vnode_param *vp = &op->file[0];
  1206. struct afs_call *call;
  1207. struct iattr *attr = op->setattr.attr;
  1208. __be32 *bp;
  1209. _enter(",%x,{%llx:%llu},,",
  1210. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1211. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
  1212. sizeof(__be32) * 2 +
  1213. sizeof(struct yfs_xdr_YFSFid) +
  1214. sizeof(struct yfs_xdr_YFSStoreStatus) +
  1215. sizeof(struct yfs_xdr_u64) * 3,
  1216. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1217. sizeof(struct yfs_xdr_YFSVolSync));
  1218. if (!call)
  1219. return afs_op_nomem(op);
  1220. /* marshall the parameters */
  1221. bp = call->request;
  1222. bp = xdr_encode_u32(bp, YFSSTOREDATA64);
  1223. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1224. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1225. bp = xdr_encode_YFS_StoreStatus(bp, attr);
  1226. bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
  1227. bp = xdr_encode_u64(bp, 0); /* size of write */
  1228. bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
  1229. yfs_check_req(call, bp);
  1230. call->fid = vp->fid;
  1231. trace_afs_make_fs_call(call, &vp->fid);
  1232. afs_make_op_call(op, call, GFP_NOFS);
  1233. }
  1234. /*
  1235. * Set the attributes on a file, using YFS.StoreData64 if there's a change in
  1236. * file size, and YFS.StoreStatus otherwise.
  1237. */
  1238. void yfs_fs_setattr(struct afs_operation *op)
  1239. {
  1240. struct afs_vnode_param *vp = &op->file[0];
  1241. struct afs_call *call;
  1242. struct iattr *attr = op->setattr.attr;
  1243. __be32 *bp;
  1244. if (attr->ia_valid & ATTR_SIZE)
  1245. return yfs_fs_setattr_size(op);
  1246. _enter(",%x,{%llx:%llu},,",
  1247. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1248. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
  1249. sizeof(__be32) * 2 +
  1250. sizeof(struct yfs_xdr_YFSFid) +
  1251. sizeof(struct yfs_xdr_YFSStoreStatus),
  1252. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1253. sizeof(struct yfs_xdr_YFSVolSync));
  1254. if (!call)
  1255. return afs_op_nomem(op);
  1256. /* marshall the parameters */
  1257. bp = call->request;
  1258. bp = xdr_encode_u32(bp, YFSSTORESTATUS);
  1259. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1260. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1261. bp = xdr_encode_YFS_StoreStatus(bp, attr);
  1262. yfs_check_req(call, bp);
  1263. call->fid = vp->fid;
  1264. trace_afs_make_fs_call(call, &vp->fid);
  1265. afs_make_op_call(op, call, GFP_NOFS);
  1266. }
  1267. /*
  1268. * Deliver reply data to a YFS.GetVolumeStatus operation.
  1269. */
  1270. static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
  1271. {
  1272. struct afs_operation *op = call->op;
  1273. const __be32 *bp;
  1274. char *p;
  1275. u32 size;
  1276. int ret;
  1277. _enter("{%u}", call->unmarshall);
  1278. switch (call->unmarshall) {
  1279. case 0:
  1280. call->unmarshall++;
  1281. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
  1282. fallthrough;
  1283. /* extract the returned status record */
  1284. case 1:
  1285. _debug("extract status");
  1286. ret = afs_extract_data(call, true);
  1287. if (ret < 0)
  1288. return ret;
  1289. bp = call->buffer;
  1290. xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
  1291. call->unmarshall++;
  1292. afs_extract_to_tmp(call);
  1293. fallthrough;
  1294. /* extract the volume name length */
  1295. case 2:
  1296. ret = afs_extract_data(call, true);
  1297. if (ret < 0)
  1298. return ret;
  1299. call->count = ntohl(call->tmp);
  1300. _debug("volname length: %u", call->count);
  1301. if (call->count >= AFSNAMEMAX)
  1302. return afs_protocol_error(call, afs_eproto_volname_len);
  1303. size = (call->count + 3) & ~3; /* It's padded */
  1304. afs_extract_to_buf(call, size);
  1305. call->unmarshall++;
  1306. fallthrough;
  1307. /* extract the volume name */
  1308. case 3:
  1309. _debug("extract volname");
  1310. ret = afs_extract_data(call, true);
  1311. if (ret < 0)
  1312. return ret;
  1313. p = call->buffer;
  1314. p[call->count] = 0;
  1315. _debug("volname '%s'", p);
  1316. afs_extract_to_tmp(call);
  1317. call->unmarshall++;
  1318. fallthrough;
  1319. /* extract the offline message length */
  1320. case 4:
  1321. ret = afs_extract_data(call, true);
  1322. if (ret < 0)
  1323. return ret;
  1324. call->count = ntohl(call->tmp);
  1325. _debug("offline msg length: %u", call->count);
  1326. if (call->count >= AFSNAMEMAX)
  1327. return afs_protocol_error(call, afs_eproto_offline_msg_len);
  1328. size = (call->count + 3) & ~3; /* It's padded */
  1329. afs_extract_to_buf(call, size);
  1330. call->unmarshall++;
  1331. fallthrough;
  1332. /* extract the offline message */
  1333. case 5:
  1334. _debug("extract offline");
  1335. ret = afs_extract_data(call, true);
  1336. if (ret < 0)
  1337. return ret;
  1338. p = call->buffer;
  1339. p[call->count] = 0;
  1340. _debug("offline '%s'", p);
  1341. afs_extract_to_tmp(call);
  1342. call->unmarshall++;
  1343. fallthrough;
  1344. /* extract the message of the day length */
  1345. case 6:
  1346. ret = afs_extract_data(call, true);
  1347. if (ret < 0)
  1348. return ret;
  1349. call->count = ntohl(call->tmp);
  1350. _debug("motd length: %u", call->count);
  1351. if (call->count >= AFSNAMEMAX)
  1352. return afs_protocol_error(call, afs_eproto_motd_len);
  1353. size = (call->count + 3) & ~3; /* It's padded */
  1354. afs_extract_to_buf(call, size);
  1355. call->unmarshall++;
  1356. fallthrough;
  1357. /* extract the message of the day */
  1358. case 7:
  1359. _debug("extract motd");
  1360. ret = afs_extract_data(call, false);
  1361. if (ret < 0)
  1362. return ret;
  1363. p = call->buffer;
  1364. p[call->count] = 0;
  1365. _debug("motd '%s'", p);
  1366. call->unmarshall++;
  1367. fallthrough;
  1368. case 8:
  1369. break;
  1370. }
  1371. _leave(" = 0 [done]");
  1372. return 0;
  1373. }
  1374. /*
  1375. * YFS.GetVolumeStatus operation type
  1376. */
  1377. static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
  1378. .name = "YFS.GetVolumeStatus",
  1379. .op = yfs_FS_GetVolumeStatus,
  1380. .deliver = yfs_deliver_fs_get_volume_status,
  1381. .destructor = afs_flat_call_destructor,
  1382. };
  1383. /*
  1384. * fetch the status of a volume
  1385. */
  1386. void yfs_fs_get_volume_status(struct afs_operation *op)
  1387. {
  1388. struct afs_vnode_param *vp = &op->file[0];
  1389. struct afs_call *call;
  1390. __be32 *bp;
  1391. _enter("");
  1392. call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
  1393. sizeof(__be32) * 2 +
  1394. sizeof(struct yfs_xdr_u64),
  1395. max_t(size_t,
  1396. sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
  1397. sizeof(__be32),
  1398. AFSOPAQUEMAX + 1));
  1399. if (!call)
  1400. return afs_op_nomem(op);
  1401. /* marshall the parameters */
  1402. bp = call->request;
  1403. bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
  1404. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1405. bp = xdr_encode_u64(bp, vp->fid.vid);
  1406. yfs_check_req(call, bp);
  1407. call->fid = vp->fid;
  1408. trace_afs_make_fs_call(call, &vp->fid);
  1409. afs_make_op_call(op, call, GFP_NOFS);
  1410. }
  1411. /*
  1412. * YFS.SetLock operation type
  1413. */
  1414. static const struct afs_call_type yfs_RXYFSSetLock = {
  1415. .name = "YFS.SetLock",
  1416. .op = yfs_FS_SetLock,
  1417. .deliver = yfs_deliver_status_and_volsync,
  1418. .done = afs_lock_op_done,
  1419. .destructor = afs_flat_call_destructor,
  1420. };
  1421. /*
  1422. * YFS.ExtendLock operation type
  1423. */
  1424. static const struct afs_call_type yfs_RXYFSExtendLock = {
  1425. .name = "YFS.ExtendLock",
  1426. .op = yfs_FS_ExtendLock,
  1427. .deliver = yfs_deliver_status_and_volsync,
  1428. .done = afs_lock_op_done,
  1429. .destructor = afs_flat_call_destructor,
  1430. };
  1431. /*
  1432. * YFS.ReleaseLock operation type
  1433. */
  1434. static const struct afs_call_type yfs_RXYFSReleaseLock = {
  1435. .name = "YFS.ReleaseLock",
  1436. .op = yfs_FS_ReleaseLock,
  1437. .deliver = yfs_deliver_status_and_volsync,
  1438. .destructor = afs_flat_call_destructor,
  1439. };
  1440. /*
  1441. * Set a lock on a file
  1442. */
  1443. void yfs_fs_set_lock(struct afs_operation *op)
  1444. {
  1445. struct afs_vnode_param *vp = &op->file[0];
  1446. struct afs_call *call;
  1447. __be32 *bp;
  1448. _enter("");
  1449. call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
  1450. sizeof(__be32) * 2 +
  1451. sizeof(struct yfs_xdr_YFSFid) +
  1452. sizeof(__be32),
  1453. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1454. sizeof(struct yfs_xdr_YFSVolSync));
  1455. if (!call)
  1456. return afs_op_nomem(op);
  1457. /* marshall the parameters */
  1458. bp = call->request;
  1459. bp = xdr_encode_u32(bp, YFSSETLOCK);
  1460. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1461. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1462. bp = xdr_encode_u32(bp, op->lock.type);
  1463. yfs_check_req(call, bp);
  1464. call->fid = vp->fid;
  1465. trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
  1466. afs_make_op_call(op, call, GFP_NOFS);
  1467. }
  1468. /*
  1469. * extend a lock on a file
  1470. */
  1471. void yfs_fs_extend_lock(struct afs_operation *op)
  1472. {
  1473. struct afs_vnode_param *vp = &op->file[0];
  1474. struct afs_call *call;
  1475. __be32 *bp;
  1476. _enter("");
  1477. call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
  1478. sizeof(__be32) * 2 +
  1479. sizeof(struct yfs_xdr_YFSFid),
  1480. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1481. sizeof(struct yfs_xdr_YFSVolSync));
  1482. if (!call)
  1483. return afs_op_nomem(op);
  1484. /* marshall the parameters */
  1485. bp = call->request;
  1486. bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
  1487. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1488. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1489. yfs_check_req(call, bp);
  1490. call->fid = vp->fid;
  1491. trace_afs_make_fs_call(call, &vp->fid);
  1492. afs_make_op_call(op, call, GFP_NOFS);
  1493. }
  1494. /*
  1495. * release a lock on a file
  1496. */
  1497. void yfs_fs_release_lock(struct afs_operation *op)
  1498. {
  1499. struct afs_vnode_param *vp = &op->file[0];
  1500. struct afs_call *call;
  1501. __be32 *bp;
  1502. _enter("");
  1503. call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
  1504. sizeof(__be32) * 2 +
  1505. sizeof(struct yfs_xdr_YFSFid),
  1506. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1507. sizeof(struct yfs_xdr_YFSVolSync));
  1508. if (!call)
  1509. return afs_op_nomem(op);
  1510. /* marshall the parameters */
  1511. bp = call->request;
  1512. bp = xdr_encode_u32(bp, YFSRELEASELOCK);
  1513. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1514. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1515. yfs_check_req(call, bp);
  1516. call->fid = vp->fid;
  1517. trace_afs_make_fs_call(call, &vp->fid);
  1518. afs_make_op_call(op, call, GFP_NOFS);
  1519. }
  1520. /*
  1521. * Deliver a reply to YFS.FetchStatus
  1522. */
  1523. static int yfs_deliver_fs_fetch_status(struct afs_call *call)
  1524. {
  1525. struct afs_operation *op = call->op;
  1526. struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
  1527. const __be32 *bp;
  1528. int ret;
  1529. ret = afs_transfer_reply(call);
  1530. if (ret < 0)
  1531. return ret;
  1532. /* unmarshall the reply once we've received all of it */
  1533. bp = call->buffer;
  1534. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  1535. xdr_decode_YFSCallBack(&bp, call, &vp->scb);
  1536. xdr_decode_YFSVolSync(&bp, &op->volsync);
  1537. _leave(" = 0 [done]");
  1538. return 0;
  1539. }
  1540. /*
  1541. * YFS.FetchStatus operation type
  1542. */
  1543. static const struct afs_call_type yfs_RXYFSFetchStatus = {
  1544. .name = "YFS.FetchStatus",
  1545. .op = yfs_FS_FetchStatus,
  1546. .deliver = yfs_deliver_fs_fetch_status,
  1547. .destructor = afs_flat_call_destructor,
  1548. };
  1549. /*
  1550. * Fetch the status information for a fid without needing a vnode handle.
  1551. */
  1552. void yfs_fs_fetch_status(struct afs_operation *op)
  1553. {
  1554. struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
  1555. struct afs_call *call;
  1556. __be32 *bp;
  1557. _enter(",%x,{%llx:%llu},,",
  1558. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1559. call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
  1560. sizeof(__be32) * 2 +
  1561. sizeof(struct yfs_xdr_YFSFid),
  1562. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1563. sizeof(struct yfs_xdr_YFSCallBack) +
  1564. sizeof(struct yfs_xdr_YFSVolSync));
  1565. if (!call)
  1566. return afs_op_nomem(op);
  1567. /* marshall the parameters */
  1568. bp = call->request;
  1569. bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
  1570. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1571. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1572. yfs_check_req(call, bp);
  1573. call->fid = vp->fid;
  1574. trace_afs_make_fs_call(call, &vp->fid);
  1575. afs_make_op_call(op, call, GFP_NOFS);
  1576. }
  1577. /*
  1578. * Deliver reply data to an YFS.InlineBulkStatus call
  1579. */
  1580. static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
  1581. {
  1582. struct afs_operation *op = call->op;
  1583. struct afs_status_cb *scb;
  1584. const __be32 *bp;
  1585. u32 tmp;
  1586. int ret;
  1587. _enter("{%u}", call->unmarshall);
  1588. switch (call->unmarshall) {
  1589. case 0:
  1590. afs_extract_to_tmp(call);
  1591. call->unmarshall++;
  1592. fallthrough;
  1593. /* Extract the file status count and array in two steps */
  1594. case 1:
  1595. _debug("extract status count");
  1596. ret = afs_extract_data(call, true);
  1597. if (ret < 0)
  1598. return ret;
  1599. tmp = ntohl(call->tmp);
  1600. _debug("status count: %u/%u", tmp, op->nr_files);
  1601. if (tmp != op->nr_files)
  1602. return afs_protocol_error(call, afs_eproto_ibulkst_count);
  1603. call->count = 0;
  1604. call->unmarshall++;
  1605. more_counts:
  1606. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
  1607. fallthrough;
  1608. case 2:
  1609. _debug("extract status array %u", call->count);
  1610. ret = afs_extract_data(call, true);
  1611. if (ret < 0)
  1612. return ret;
  1613. switch (call->count) {
  1614. case 0:
  1615. scb = &op->file[0].scb;
  1616. break;
  1617. case 1:
  1618. scb = &op->file[1].scb;
  1619. break;
  1620. default:
  1621. scb = &op->more_files[call->count - 2].scb;
  1622. break;
  1623. }
  1624. bp = call->buffer;
  1625. xdr_decode_YFSFetchStatus(&bp, call, scb);
  1626. call->count++;
  1627. if (call->count < op->nr_files)
  1628. goto more_counts;
  1629. call->count = 0;
  1630. call->unmarshall++;
  1631. afs_extract_to_tmp(call);
  1632. fallthrough;
  1633. /* Extract the callback count and array in two steps */
  1634. case 3:
  1635. _debug("extract CB count");
  1636. ret = afs_extract_data(call, true);
  1637. if (ret < 0)
  1638. return ret;
  1639. tmp = ntohl(call->tmp);
  1640. _debug("CB count: %u", tmp);
  1641. if (tmp != op->nr_files)
  1642. return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
  1643. call->count = 0;
  1644. call->unmarshall++;
  1645. more_cbs:
  1646. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
  1647. fallthrough;
  1648. case 4:
  1649. _debug("extract CB array");
  1650. ret = afs_extract_data(call, true);
  1651. if (ret < 0)
  1652. return ret;
  1653. _debug("unmarshall CB array");
  1654. switch (call->count) {
  1655. case 0:
  1656. scb = &op->file[0].scb;
  1657. break;
  1658. case 1:
  1659. scb = &op->file[1].scb;
  1660. break;
  1661. default:
  1662. scb = &op->more_files[call->count - 2].scb;
  1663. break;
  1664. }
  1665. bp = call->buffer;
  1666. xdr_decode_YFSCallBack(&bp, call, scb);
  1667. call->count++;
  1668. if (call->count < op->nr_files)
  1669. goto more_cbs;
  1670. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
  1671. call->unmarshall++;
  1672. fallthrough;
  1673. case 5:
  1674. ret = afs_extract_data(call, false);
  1675. if (ret < 0)
  1676. return ret;
  1677. bp = call->buffer;
  1678. xdr_decode_YFSVolSync(&bp, &op->volsync);
  1679. call->unmarshall++;
  1680. fallthrough;
  1681. case 6:
  1682. break;
  1683. }
  1684. _leave(" = 0 [done]");
  1685. return 0;
  1686. }
  1687. /*
  1688. * FS.InlineBulkStatus operation type
  1689. */
  1690. static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
  1691. .name = "YFS.InlineBulkStatus",
  1692. .op = yfs_FS_InlineBulkStatus,
  1693. .deliver = yfs_deliver_fs_inline_bulk_status,
  1694. .destructor = afs_flat_call_destructor,
  1695. };
  1696. /*
  1697. * Fetch the status information for up to 1024 files
  1698. */
  1699. void yfs_fs_inline_bulk_status(struct afs_operation *op)
  1700. {
  1701. struct afs_vnode_param *dvp = &op->file[0];
  1702. struct afs_vnode_param *vp = &op->file[1];
  1703. struct afs_call *call;
  1704. __be32 *bp;
  1705. int i;
  1706. _enter(",%x,{%llx:%llu},%u",
  1707. key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
  1708. call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
  1709. sizeof(__be32) +
  1710. sizeof(__be32) +
  1711. sizeof(__be32) +
  1712. sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
  1713. sizeof(struct yfs_xdr_YFSFetchStatus));
  1714. if (!call)
  1715. return afs_op_nomem(op);
  1716. /* marshall the parameters */
  1717. bp = call->request;
  1718. bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
  1719. bp = xdr_encode_u32(bp, 0); /* RPCFlags */
  1720. bp = xdr_encode_u32(bp, op->nr_files);
  1721. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  1722. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1723. for (i = 0; i < op->nr_files - 2; i++)
  1724. bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
  1725. yfs_check_req(call, bp);
  1726. call->fid = vp->fid;
  1727. trace_afs_make_fs_call(call, &vp->fid);
  1728. afs_make_op_call(op, call, GFP_NOFS);
  1729. }
  1730. /*
  1731. * Deliver reply data to an YFS.FetchOpaqueACL.
  1732. */
  1733. static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
  1734. {
  1735. struct afs_operation *op = call->op;
  1736. struct afs_vnode_param *vp = &op->file[0];
  1737. struct yfs_acl *yacl = op->yacl;
  1738. struct afs_acl *acl;
  1739. const __be32 *bp;
  1740. unsigned int size;
  1741. int ret;
  1742. _enter("{%u}", call->unmarshall);
  1743. switch (call->unmarshall) {
  1744. case 0:
  1745. afs_extract_to_tmp(call);
  1746. call->unmarshall++;
  1747. fallthrough;
  1748. /* Extract the file ACL length */
  1749. case 1:
  1750. ret = afs_extract_data(call, true);
  1751. if (ret < 0)
  1752. return ret;
  1753. size = call->count2 = ntohl(call->tmp);
  1754. size = round_up(size, 4);
  1755. if (yacl->flags & YFS_ACL_WANT_ACL) {
  1756. acl = kmalloc_flex(*acl, data, size);
  1757. if (!acl)
  1758. return -ENOMEM;
  1759. yacl->acl = acl;
  1760. acl->size = call->count2;
  1761. afs_extract_begin(call, acl->data, size);
  1762. } else {
  1763. afs_extract_discard(call, size);
  1764. }
  1765. call->unmarshall++;
  1766. fallthrough;
  1767. /* Extract the file ACL */
  1768. case 2:
  1769. ret = afs_extract_data(call, true);
  1770. if (ret < 0)
  1771. return ret;
  1772. afs_extract_to_tmp(call);
  1773. call->unmarshall++;
  1774. fallthrough;
  1775. /* Extract the volume ACL length */
  1776. case 3:
  1777. ret = afs_extract_data(call, true);
  1778. if (ret < 0)
  1779. return ret;
  1780. size = call->count2 = ntohl(call->tmp);
  1781. size = round_up(size, 4);
  1782. if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
  1783. acl = kmalloc_flex(*acl, data, size);
  1784. if (!acl)
  1785. return -ENOMEM;
  1786. yacl->vol_acl = acl;
  1787. acl->size = call->count2;
  1788. afs_extract_begin(call, acl->data, size);
  1789. } else {
  1790. afs_extract_discard(call, size);
  1791. }
  1792. call->unmarshall++;
  1793. fallthrough;
  1794. /* Extract the volume ACL */
  1795. case 4:
  1796. ret = afs_extract_data(call, true);
  1797. if (ret < 0)
  1798. return ret;
  1799. afs_extract_to_buf(call,
  1800. sizeof(__be32) * 2 +
  1801. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1802. sizeof(struct yfs_xdr_YFSVolSync));
  1803. call->unmarshall++;
  1804. fallthrough;
  1805. /* extract the metadata */
  1806. case 5:
  1807. ret = afs_extract_data(call, false);
  1808. if (ret < 0)
  1809. return ret;
  1810. bp = call->buffer;
  1811. yacl->inherit_flag = ntohl(*bp++);
  1812. yacl->num_cleaned = ntohl(*bp++);
  1813. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  1814. xdr_decode_YFSVolSync(&bp, &op->volsync);
  1815. call->unmarshall++;
  1816. fallthrough;
  1817. case 6:
  1818. break;
  1819. }
  1820. _leave(" = 0 [done]");
  1821. return 0;
  1822. }
  1823. void yfs_free_opaque_acl(struct yfs_acl *yacl)
  1824. {
  1825. if (yacl) {
  1826. kfree(yacl->acl);
  1827. kfree(yacl->vol_acl);
  1828. kfree(yacl);
  1829. }
  1830. }
  1831. /*
  1832. * YFS.FetchOpaqueACL operation type
  1833. */
  1834. static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
  1835. .name = "YFS.FetchOpaqueACL",
  1836. .op = yfs_FS_FetchOpaqueACL,
  1837. .deliver = yfs_deliver_fs_fetch_opaque_acl,
  1838. .destructor = afs_flat_call_destructor,
  1839. };
  1840. /*
  1841. * Fetch the YFS advanced ACLs for a file.
  1842. */
  1843. void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
  1844. {
  1845. struct afs_vnode_param *vp = &op->file[0];
  1846. struct afs_call *call;
  1847. __be32 *bp;
  1848. _enter(",%x,{%llx:%llu},,",
  1849. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1850. call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
  1851. sizeof(__be32) * 2 +
  1852. sizeof(struct yfs_xdr_YFSFid),
  1853. sizeof(__be32) * 2 +
  1854. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1855. sizeof(struct yfs_xdr_YFSVolSync));
  1856. if (!call)
  1857. return afs_op_nomem(op);
  1858. /* marshall the parameters */
  1859. bp = call->request;
  1860. bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
  1861. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1862. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1863. yfs_check_req(call, bp);
  1864. call->fid = vp->fid;
  1865. trace_afs_make_fs_call(call, &vp->fid);
  1866. afs_make_op_call(op, call, GFP_KERNEL);
  1867. }
  1868. /*
  1869. * YFS.StoreOpaqueACL2 operation type
  1870. */
  1871. static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
  1872. .name = "YFS.StoreOpaqueACL2",
  1873. .op = yfs_FS_StoreOpaqueACL2,
  1874. .deliver = yfs_deliver_status_and_volsync,
  1875. .destructor = afs_flat_call_destructor,
  1876. };
  1877. /*
  1878. * Fetch the YFS ACL for a file.
  1879. */
  1880. void yfs_fs_store_opaque_acl2(struct afs_operation *op)
  1881. {
  1882. struct afs_vnode_param *vp = &op->file[0];
  1883. struct afs_call *call;
  1884. struct afs_acl *acl = op->acl;
  1885. size_t size;
  1886. __be32 *bp;
  1887. _enter(",%x,{%llx:%llu},,",
  1888. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1889. size = round_up(acl->size, 4);
  1890. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
  1891. sizeof(__be32) * 2 +
  1892. sizeof(struct yfs_xdr_YFSFid) +
  1893. sizeof(__be32) + size,
  1894. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1895. sizeof(struct yfs_xdr_YFSVolSync));
  1896. if (!call)
  1897. return afs_op_nomem(op);
  1898. /* marshall the parameters */
  1899. bp = call->request;
  1900. bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
  1901. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1902. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1903. bp = xdr_encode_u32(bp, acl->size);
  1904. memcpy(bp, acl->data, acl->size);
  1905. if (acl->size != size)
  1906. memset((void *)bp + acl->size, 0, size - acl->size);
  1907. bp += size / sizeof(__be32);
  1908. yfs_check_req(call, bp);
  1909. call->fid = vp->fid;
  1910. trace_afs_make_fs_call(call, &vp->fid);
  1911. afs_make_op_call(op, call, GFP_KERNEL);
  1912. }