yfsclient.c 54 KB

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