fsclient.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367
  1. /* AFS File Server client stubs
  2. *
  3. * Copyright (C) 2002, 2007 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 License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, 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. /*
  26. * decode an AFSFid block
  27. */
  28. static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
  29. {
  30. const __be32 *bp = *_bp;
  31. fid->vid = ntohl(*bp++);
  32. fid->vnode = ntohl(*bp++);
  33. fid->unique = ntohl(*bp++);
  34. *_bp = bp;
  35. }
  36. /*
  37. * Dump a bad file status record.
  38. */
  39. static void xdr_dump_bad(const __be32 *bp)
  40. {
  41. __be32 x[4];
  42. int i;
  43. pr_notice("AFS XDR: Bad status record\n");
  44. for (i = 0; i < 5 * 4 * 4; i += 16) {
  45. memcpy(x, bp, 16);
  46. bp += 4;
  47. pr_notice("%03x: %08x %08x %08x %08x\n",
  48. i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
  49. }
  50. memcpy(x, bp, 4);
  51. pr_notice("0x50: %08x\n", ntohl(x[0]));
  52. }
  53. /*
  54. * Update the core inode struct from a returned status record.
  55. */
  56. void afs_update_inode_from_status(struct afs_vnode *vnode,
  57. struct afs_file_status *status,
  58. const afs_dataversion_t *expected_version,
  59. u8 flags)
  60. {
  61. struct timespec64 t;
  62. umode_t mode;
  63. t = status->mtime_client;
  64. vnode->vfs_inode.i_ctime = t;
  65. vnode->vfs_inode.i_mtime = t;
  66. vnode->vfs_inode.i_atime = t;
  67. if (flags & (AFS_VNODE_META_CHANGED | AFS_VNODE_NOT_YET_SET)) {
  68. vnode->vfs_inode.i_uid = make_kuid(&init_user_ns, status->owner);
  69. vnode->vfs_inode.i_gid = make_kgid(&init_user_ns, status->group);
  70. set_nlink(&vnode->vfs_inode, status->nlink);
  71. mode = vnode->vfs_inode.i_mode;
  72. mode &= ~S_IALLUGO;
  73. mode |= status->mode;
  74. barrier();
  75. vnode->vfs_inode.i_mode = mode;
  76. }
  77. if (!(flags & AFS_VNODE_NOT_YET_SET)) {
  78. if (expected_version &&
  79. *expected_version != status->data_version) {
  80. _debug("vnode modified %llx on {%llx:%llu} [exp %llx]",
  81. (unsigned long long) status->data_version,
  82. vnode->fid.vid, vnode->fid.vnode,
  83. (unsigned long long) *expected_version);
  84. vnode->invalid_before = status->data_version;
  85. if (vnode->status.type == AFS_FTYPE_DIR) {
  86. if (test_and_clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
  87. afs_stat_v(vnode, n_inval);
  88. } else {
  89. set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags);
  90. }
  91. } else if (vnode->status.type == AFS_FTYPE_DIR) {
  92. /* Expected directory change is handled elsewhere so
  93. * that we can locally edit the directory and save on a
  94. * download.
  95. */
  96. if (test_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
  97. flags &= ~AFS_VNODE_DATA_CHANGED;
  98. }
  99. }
  100. if (flags & (AFS_VNODE_DATA_CHANGED | AFS_VNODE_NOT_YET_SET)) {
  101. inode_set_iversion_raw(&vnode->vfs_inode, status->data_version);
  102. i_size_write(&vnode->vfs_inode, status->size);
  103. }
  104. }
  105. /*
  106. * decode an AFSFetchStatus block
  107. */
  108. static int xdr_decode_AFSFetchStatus(struct afs_call *call,
  109. const __be32 **_bp,
  110. struct afs_file_status *status,
  111. struct afs_vnode *vnode,
  112. const afs_dataversion_t *expected_version,
  113. struct afs_read *read_req)
  114. {
  115. const struct afs_xdr_AFSFetchStatus *xdr = (const void *)*_bp;
  116. bool inline_error = (call->operation_ID == afs_FS_InlineBulkStatus);
  117. u64 data_version, size;
  118. u32 type, abort_code;
  119. u8 flags = 0;
  120. abort_code = ntohl(xdr->abort_code);
  121. if (xdr->if_version != htonl(AFS_FSTATUS_VERSION)) {
  122. if (xdr->if_version == htonl(0) &&
  123. abort_code != 0 &&
  124. inline_error) {
  125. /* The OpenAFS fileserver has a bug in FS.InlineBulkStatus
  126. * whereby it doesn't set the interface version in the error
  127. * case.
  128. */
  129. status->abort_code = abort_code;
  130. return 0;
  131. }
  132. pr_warn("Unknown AFSFetchStatus version %u\n", ntohl(xdr->if_version));
  133. goto bad;
  134. }
  135. if (abort_code != 0 && inline_error) {
  136. status->abort_code = abort_code;
  137. return 0;
  138. }
  139. type = ntohl(xdr->type);
  140. switch (type) {
  141. case AFS_FTYPE_FILE:
  142. case AFS_FTYPE_DIR:
  143. case AFS_FTYPE_SYMLINK:
  144. if (type != status->type &&
  145. vnode &&
  146. !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
  147. pr_warning("Vnode %llx:%llx:%x changed type %u to %u\n",
  148. vnode->fid.vid,
  149. vnode->fid.vnode,
  150. vnode->fid.unique,
  151. status->type, type);
  152. goto bad;
  153. }
  154. status->type = type;
  155. break;
  156. default:
  157. goto bad;
  158. }
  159. #define EXTRACT_M(FIELD) \
  160. do { \
  161. u32 x = ntohl(xdr->FIELD); \
  162. if (status->FIELD != x) { \
  163. flags |= AFS_VNODE_META_CHANGED; \
  164. status->FIELD = x; \
  165. } \
  166. } while (0)
  167. EXTRACT_M(nlink);
  168. EXTRACT_M(author);
  169. EXTRACT_M(owner);
  170. EXTRACT_M(caller_access); /* call ticket dependent */
  171. EXTRACT_M(anon_access);
  172. EXTRACT_M(mode);
  173. EXTRACT_M(group);
  174. status->mtime_client.tv_sec = ntohl(xdr->mtime_client);
  175. status->mtime_client.tv_nsec = 0;
  176. status->mtime_server.tv_sec = ntohl(xdr->mtime_server);
  177. status->mtime_server.tv_nsec = 0;
  178. status->lock_count = ntohl(xdr->lock_count);
  179. size = (u64)ntohl(xdr->size_lo);
  180. size |= (u64)ntohl(xdr->size_hi) << 32;
  181. status->size = size;
  182. data_version = (u64)ntohl(xdr->data_version_lo);
  183. data_version |= (u64)ntohl(xdr->data_version_hi) << 32;
  184. if (data_version != status->data_version) {
  185. status->data_version = data_version;
  186. flags |= AFS_VNODE_DATA_CHANGED;
  187. }
  188. if (read_req) {
  189. read_req->data_version = data_version;
  190. read_req->file_size = size;
  191. }
  192. *_bp = (const void *)*_bp + sizeof(*xdr);
  193. if (vnode) {
  194. if (test_bit(AFS_VNODE_UNSET, &vnode->flags))
  195. flags |= AFS_VNODE_NOT_YET_SET;
  196. afs_update_inode_from_status(vnode, status, expected_version,
  197. flags);
  198. }
  199. return 0;
  200. bad:
  201. xdr_dump_bad(*_bp);
  202. return afs_protocol_error(call, -EBADMSG, afs_eproto_bad_status);
  203. }
  204. /*
  205. * Decode the file status. We need to lock the target vnode if we're going to
  206. * update its status so that stat() sees the attributes update atomically.
  207. */
  208. static int afs_decode_status(struct afs_call *call,
  209. const __be32 **_bp,
  210. struct afs_file_status *status,
  211. struct afs_vnode *vnode,
  212. const afs_dataversion_t *expected_version,
  213. struct afs_read *read_req)
  214. {
  215. int ret;
  216. if (!vnode)
  217. return xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
  218. expected_version, read_req);
  219. write_seqlock(&vnode->cb_lock);
  220. ret = xdr_decode_AFSFetchStatus(call, _bp, status, vnode,
  221. expected_version, read_req);
  222. write_sequnlock(&vnode->cb_lock);
  223. return ret;
  224. }
  225. /*
  226. * decode an AFSCallBack block
  227. */
  228. static void xdr_decode_AFSCallBack(struct afs_call *call,
  229. struct afs_vnode *vnode,
  230. const __be32 **_bp)
  231. {
  232. struct afs_cb_interest *old, *cbi = call->cbi;
  233. const __be32 *bp = *_bp;
  234. u32 cb_expiry;
  235. write_seqlock(&vnode->cb_lock);
  236. if (!afs_cb_is_broken(call->cb_break, vnode, cbi)) {
  237. vnode->cb_version = ntohl(*bp++);
  238. cb_expiry = ntohl(*bp++);
  239. vnode->cb_type = ntohl(*bp++);
  240. vnode->cb_expires_at = cb_expiry + ktime_get_real_seconds();
  241. old = vnode->cb_interest;
  242. if (old != call->cbi) {
  243. vnode->cb_interest = cbi;
  244. cbi = old;
  245. }
  246. set_bit(AFS_VNODE_CB_PROMISED, &vnode->flags);
  247. } else {
  248. bp += 3;
  249. }
  250. write_sequnlock(&vnode->cb_lock);
  251. call->cbi = cbi;
  252. *_bp = bp;
  253. }
  254. static ktime_t xdr_decode_expiry(struct afs_call *call, u32 expiry)
  255. {
  256. return ktime_add_ns(call->reply_time, expiry * NSEC_PER_SEC);
  257. }
  258. static void xdr_decode_AFSCallBack_raw(struct afs_call *call,
  259. const __be32 **_bp,
  260. struct afs_callback *cb)
  261. {
  262. const __be32 *bp = *_bp;
  263. cb->version = ntohl(*bp++);
  264. cb->expires_at = xdr_decode_expiry(call, ntohl(*bp++));
  265. cb->type = ntohl(*bp++);
  266. *_bp = bp;
  267. }
  268. /*
  269. * decode an AFSVolSync block
  270. */
  271. static void xdr_decode_AFSVolSync(const __be32 **_bp,
  272. struct afs_volsync *volsync)
  273. {
  274. const __be32 *bp = *_bp;
  275. u32 creation;
  276. creation = ntohl(*bp++);
  277. bp++; /* spare2 */
  278. bp++; /* spare3 */
  279. bp++; /* spare4 */
  280. bp++; /* spare5 */
  281. bp++; /* spare6 */
  282. *_bp = bp;
  283. if (volsync)
  284. volsync->creation = creation;
  285. }
  286. /*
  287. * encode the requested attributes into an AFSStoreStatus block
  288. */
  289. static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
  290. {
  291. __be32 *bp = *_bp;
  292. u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
  293. mask = 0;
  294. if (attr->ia_valid & ATTR_MTIME) {
  295. mask |= AFS_SET_MTIME;
  296. mtime = attr->ia_mtime.tv_sec;
  297. }
  298. if (attr->ia_valid & ATTR_UID) {
  299. mask |= AFS_SET_OWNER;
  300. owner = from_kuid(&init_user_ns, attr->ia_uid);
  301. }
  302. if (attr->ia_valid & ATTR_GID) {
  303. mask |= AFS_SET_GROUP;
  304. group = from_kgid(&init_user_ns, attr->ia_gid);
  305. }
  306. if (attr->ia_valid & ATTR_MODE) {
  307. mask |= AFS_SET_MODE;
  308. mode = attr->ia_mode & S_IALLUGO;
  309. }
  310. *bp++ = htonl(mask);
  311. *bp++ = htonl(mtime);
  312. *bp++ = htonl(owner);
  313. *bp++ = htonl(group);
  314. *bp++ = htonl(mode);
  315. *bp++ = 0; /* segment size */
  316. *_bp = bp;
  317. }
  318. /*
  319. * decode an AFSFetchVolumeStatus block
  320. */
  321. static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
  322. struct afs_volume_status *vs)
  323. {
  324. const __be32 *bp = *_bp;
  325. vs->vid = ntohl(*bp++);
  326. vs->parent_id = ntohl(*bp++);
  327. vs->online = ntohl(*bp++);
  328. vs->in_service = ntohl(*bp++);
  329. vs->blessed = ntohl(*bp++);
  330. vs->needs_salvage = ntohl(*bp++);
  331. vs->type = ntohl(*bp++);
  332. vs->min_quota = ntohl(*bp++);
  333. vs->max_quota = ntohl(*bp++);
  334. vs->blocks_in_use = ntohl(*bp++);
  335. vs->part_blocks_avail = ntohl(*bp++);
  336. vs->part_max_blocks = ntohl(*bp++);
  337. vs->vol_copy_date = 0;
  338. vs->vol_backup_date = 0;
  339. *_bp = bp;
  340. }
  341. /*
  342. * deliver reply data to an FS.FetchStatus
  343. */
  344. static int afs_deliver_fs_fetch_status_vnode(struct afs_call *call)
  345. {
  346. struct afs_vnode *vnode = call->reply[0];
  347. const __be32 *bp;
  348. int ret;
  349. ret = afs_transfer_reply(call);
  350. if (ret < 0)
  351. return ret;
  352. _enter("{%llx:%llu}", vnode->fid.vid, vnode->fid.vnode);
  353. /* unmarshall the reply once we've received all of it */
  354. bp = call->buffer;
  355. ret = afs_decode_status(call, &bp, &vnode->status, vnode,
  356. &call->expected_version, NULL);
  357. if (ret < 0)
  358. return ret;
  359. xdr_decode_AFSCallBack(call, vnode, &bp);
  360. xdr_decode_AFSVolSync(&bp, call->reply[1]);
  361. _leave(" = 0 [done]");
  362. return 0;
  363. }
  364. /*
  365. * FS.FetchStatus operation type
  366. */
  367. static const struct afs_call_type afs_RXFSFetchStatus_vnode = {
  368. .name = "FS.FetchStatus(vnode)",
  369. .op = afs_FS_FetchStatus,
  370. .deliver = afs_deliver_fs_fetch_status_vnode,
  371. .destructor = afs_flat_call_destructor,
  372. };
  373. /*
  374. * fetch the status information for a file
  375. */
  376. int afs_fs_fetch_file_status(struct afs_fs_cursor *fc, struct afs_volsync *volsync,
  377. bool new_inode)
  378. {
  379. struct afs_vnode *vnode = fc->vnode;
  380. struct afs_call *call;
  381. struct afs_net *net = afs_v2net(vnode);
  382. __be32 *bp;
  383. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  384. return yfs_fs_fetch_file_status(fc, volsync, new_inode);
  385. _enter(",%x,{%llx:%llu},,",
  386. key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
  387. call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus_vnode,
  388. 16, (21 + 3 + 6) * 4);
  389. if (!call) {
  390. fc->ac.error = -ENOMEM;
  391. return -ENOMEM;
  392. }
  393. call->key = fc->key;
  394. call->reply[0] = vnode;
  395. call->reply[1] = volsync;
  396. call->expected_version = new_inode ? 1 : vnode->status.data_version;
  397. call->want_reply_time = true;
  398. /* marshall the parameters */
  399. bp = call->request;
  400. bp[0] = htonl(FSFETCHSTATUS);
  401. bp[1] = htonl(vnode->fid.vid);
  402. bp[2] = htonl(vnode->fid.vnode);
  403. bp[3] = htonl(vnode->fid.unique);
  404. call->cb_break = fc->cb_break;
  405. afs_use_fs_server(call, fc->cbi);
  406. trace_afs_make_fs_call(call, &vnode->fid);
  407. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  408. }
  409. /*
  410. * deliver reply data to an FS.FetchData
  411. */
  412. static int afs_deliver_fs_fetch_data(struct afs_call *call)
  413. {
  414. struct afs_vnode *vnode = call->reply[0];
  415. struct afs_read *req = call->reply[2];
  416. const __be32 *bp;
  417. unsigned int size;
  418. int ret;
  419. _enter("{%u,%zu/%llu}",
  420. call->unmarshall, iov_iter_count(&call->iter), req->actual_len);
  421. switch (call->unmarshall) {
  422. case 0:
  423. req->actual_len = 0;
  424. req->index = 0;
  425. req->offset = req->pos & (PAGE_SIZE - 1);
  426. call->unmarshall++;
  427. if (call->operation_ID == FSFETCHDATA64) {
  428. afs_extract_to_tmp64(call);
  429. } else {
  430. call->tmp_u = htonl(0);
  431. afs_extract_to_tmp(call);
  432. }
  433. /* extract the returned data length */
  434. case 1:
  435. _debug("extract data length");
  436. ret = afs_extract_data(call, true);
  437. if (ret < 0)
  438. return ret;
  439. req->actual_len = be64_to_cpu(call->tmp64);
  440. _debug("DATA length: %llu", req->actual_len);
  441. req->remain = min(req->len, req->actual_len);
  442. if (req->remain == 0)
  443. goto no_more_data;
  444. call->unmarshall++;
  445. begin_page:
  446. ASSERTCMP(req->index, <, req->nr_pages);
  447. if (req->remain > PAGE_SIZE - req->offset)
  448. size = PAGE_SIZE - req->offset;
  449. else
  450. size = req->remain;
  451. call->bvec[0].bv_len = size;
  452. call->bvec[0].bv_offset = req->offset;
  453. call->bvec[0].bv_page = req->pages[req->index];
  454. iov_iter_bvec(&call->iter, READ, call->bvec, 1, size);
  455. ASSERTCMP(size, <=, PAGE_SIZE);
  456. /* extract the returned data */
  457. case 2:
  458. _debug("extract data %zu/%llu",
  459. iov_iter_count(&call->iter), req->remain);
  460. ret = afs_extract_data(call, true);
  461. if (ret < 0)
  462. return ret;
  463. req->remain -= call->bvec[0].bv_len;
  464. req->offset += call->bvec[0].bv_len;
  465. ASSERTCMP(req->offset, <=, PAGE_SIZE);
  466. if (req->offset == PAGE_SIZE) {
  467. req->offset = 0;
  468. if (req->page_done)
  469. req->page_done(call, req);
  470. req->index++;
  471. if (req->remain > 0)
  472. goto begin_page;
  473. }
  474. ASSERTCMP(req->remain, ==, 0);
  475. if (req->actual_len <= req->len)
  476. goto no_more_data;
  477. /* Discard any excess data the server gave us */
  478. iov_iter_discard(&call->iter, READ, req->actual_len - req->len);
  479. call->unmarshall = 3;
  480. case 3:
  481. _debug("extract discard %zu/%llu",
  482. iov_iter_count(&call->iter), req->actual_len - req->len);
  483. ret = afs_extract_data(call, true);
  484. if (ret < 0)
  485. return ret;
  486. no_more_data:
  487. call->unmarshall = 4;
  488. afs_extract_to_buf(call, (21 + 3 + 6) * 4);
  489. /* extract the metadata */
  490. case 4:
  491. ret = afs_extract_data(call, false);
  492. if (ret < 0)
  493. return ret;
  494. bp = call->buffer;
  495. ret = afs_decode_status(call, &bp, &vnode->status, vnode,
  496. &vnode->status.data_version, req);
  497. if (ret < 0)
  498. return ret;
  499. xdr_decode_AFSCallBack(call, vnode, &bp);
  500. xdr_decode_AFSVolSync(&bp, call->reply[1]);
  501. call->unmarshall++;
  502. case 5:
  503. break;
  504. }
  505. for (; req->index < req->nr_pages; req->index++) {
  506. if (req->offset < PAGE_SIZE)
  507. zero_user_segment(req->pages[req->index],
  508. req->offset, PAGE_SIZE);
  509. if (req->page_done)
  510. req->page_done(call, req);
  511. req->offset = 0;
  512. }
  513. _leave(" = 0 [done]");
  514. return 0;
  515. }
  516. static void afs_fetch_data_destructor(struct afs_call *call)
  517. {
  518. struct afs_read *req = call->reply[2];
  519. afs_put_read(req);
  520. afs_flat_call_destructor(call);
  521. }
  522. /*
  523. * FS.FetchData operation type
  524. */
  525. static const struct afs_call_type afs_RXFSFetchData = {
  526. .name = "FS.FetchData",
  527. .op = afs_FS_FetchData,
  528. .deliver = afs_deliver_fs_fetch_data,
  529. .destructor = afs_fetch_data_destructor,
  530. };
  531. static const struct afs_call_type afs_RXFSFetchData64 = {
  532. .name = "FS.FetchData64",
  533. .op = afs_FS_FetchData64,
  534. .deliver = afs_deliver_fs_fetch_data,
  535. .destructor = afs_fetch_data_destructor,
  536. };
  537. /*
  538. * fetch data from a very large file
  539. */
  540. static int afs_fs_fetch_data64(struct afs_fs_cursor *fc, struct afs_read *req)
  541. {
  542. struct afs_vnode *vnode = fc->vnode;
  543. struct afs_call *call;
  544. struct afs_net *net = afs_v2net(vnode);
  545. __be32 *bp;
  546. _enter("");
  547. call = afs_alloc_flat_call(net, &afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
  548. if (!call)
  549. return -ENOMEM;
  550. call->key = fc->key;
  551. call->reply[0] = vnode;
  552. call->reply[1] = NULL; /* volsync */
  553. call->reply[2] = req;
  554. call->expected_version = vnode->status.data_version;
  555. call->want_reply_time = true;
  556. /* marshall the parameters */
  557. bp = call->request;
  558. bp[0] = htonl(FSFETCHDATA64);
  559. bp[1] = htonl(vnode->fid.vid);
  560. bp[2] = htonl(vnode->fid.vnode);
  561. bp[3] = htonl(vnode->fid.unique);
  562. bp[4] = htonl(upper_32_bits(req->pos));
  563. bp[5] = htonl(lower_32_bits(req->pos));
  564. bp[6] = 0;
  565. bp[7] = htonl(lower_32_bits(req->len));
  566. refcount_inc(&req->usage);
  567. call->cb_break = fc->cb_break;
  568. afs_use_fs_server(call, fc->cbi);
  569. trace_afs_make_fs_call(call, &vnode->fid);
  570. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  571. }
  572. /*
  573. * fetch data from a file
  574. */
  575. int afs_fs_fetch_data(struct afs_fs_cursor *fc, struct afs_read *req)
  576. {
  577. struct afs_vnode *vnode = fc->vnode;
  578. struct afs_call *call;
  579. struct afs_net *net = afs_v2net(vnode);
  580. __be32 *bp;
  581. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  582. return yfs_fs_fetch_data(fc, req);
  583. if (upper_32_bits(req->pos) ||
  584. upper_32_bits(req->len) ||
  585. upper_32_bits(req->pos + req->len))
  586. return afs_fs_fetch_data64(fc, req);
  587. _enter("");
  588. call = afs_alloc_flat_call(net, &afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
  589. if (!call)
  590. return -ENOMEM;
  591. call->key = fc->key;
  592. call->reply[0] = vnode;
  593. call->reply[1] = NULL; /* volsync */
  594. call->reply[2] = req;
  595. call->expected_version = vnode->status.data_version;
  596. call->want_reply_time = true;
  597. /* marshall the parameters */
  598. bp = call->request;
  599. bp[0] = htonl(FSFETCHDATA);
  600. bp[1] = htonl(vnode->fid.vid);
  601. bp[2] = htonl(vnode->fid.vnode);
  602. bp[3] = htonl(vnode->fid.unique);
  603. bp[4] = htonl(lower_32_bits(req->pos));
  604. bp[5] = htonl(lower_32_bits(req->len));
  605. refcount_inc(&req->usage);
  606. call->cb_break = fc->cb_break;
  607. afs_use_fs_server(call, fc->cbi);
  608. trace_afs_make_fs_call(call, &vnode->fid);
  609. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  610. }
  611. /*
  612. * deliver reply data to an FS.CreateFile or an FS.MakeDir
  613. */
  614. static int afs_deliver_fs_create_vnode(struct afs_call *call)
  615. {
  616. struct afs_vnode *vnode = call->reply[0];
  617. const __be32 *bp;
  618. int ret;
  619. _enter("{%u}", call->unmarshall);
  620. ret = afs_transfer_reply(call);
  621. if (ret < 0)
  622. return ret;
  623. /* unmarshall the reply once we've received all of it */
  624. bp = call->buffer;
  625. xdr_decode_AFSFid(&bp, call->reply[1]);
  626. ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
  627. if (ret < 0)
  628. return ret;
  629. ret = afs_decode_status(call, &bp, &vnode->status, vnode,
  630. &call->expected_version, NULL);
  631. if (ret < 0)
  632. return ret;
  633. xdr_decode_AFSCallBack_raw(call, &bp, call->reply[3]);
  634. /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
  635. _leave(" = 0 [done]");
  636. return 0;
  637. }
  638. /*
  639. * FS.CreateFile and FS.MakeDir operation type
  640. */
  641. static const struct afs_call_type afs_RXFSCreateFile = {
  642. .name = "FS.CreateFile",
  643. .op = afs_FS_CreateFile,
  644. .deliver = afs_deliver_fs_create_vnode,
  645. .destructor = afs_flat_call_destructor,
  646. };
  647. static const struct afs_call_type afs_RXFSMakeDir = {
  648. .name = "FS.MakeDir",
  649. .op = afs_FS_MakeDir,
  650. .deliver = afs_deliver_fs_create_vnode,
  651. .destructor = afs_flat_call_destructor,
  652. };
  653. /*
  654. * create a file or make a directory
  655. */
  656. int afs_fs_create(struct afs_fs_cursor *fc,
  657. const char *name,
  658. umode_t mode,
  659. u64 current_data_version,
  660. struct afs_fid *newfid,
  661. struct afs_file_status *newstatus,
  662. struct afs_callback *newcb)
  663. {
  664. struct afs_vnode *vnode = fc->vnode;
  665. struct afs_call *call;
  666. struct afs_net *net = afs_v2net(vnode);
  667. size_t namesz, reqsz, padsz;
  668. __be32 *bp;
  669. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags)){
  670. if (S_ISDIR(mode))
  671. return yfs_fs_make_dir(fc, name, mode, current_data_version,
  672. newfid, newstatus, newcb);
  673. else
  674. return yfs_fs_create_file(fc, name, mode, current_data_version,
  675. newfid, newstatus, newcb);
  676. }
  677. _enter("");
  678. namesz = strlen(name);
  679. padsz = (4 - (namesz & 3)) & 3;
  680. reqsz = (5 * 4) + namesz + padsz + (6 * 4);
  681. call = afs_alloc_flat_call(
  682. net, S_ISDIR(mode) ? &afs_RXFSMakeDir : &afs_RXFSCreateFile,
  683. reqsz, (3 + 21 + 21 + 3 + 6) * 4);
  684. if (!call)
  685. return -ENOMEM;
  686. call->key = fc->key;
  687. call->reply[0] = vnode;
  688. call->reply[1] = newfid;
  689. call->reply[2] = newstatus;
  690. call->reply[3] = newcb;
  691. call->expected_version = current_data_version + 1;
  692. call->want_reply_time = true;
  693. /* marshall the parameters */
  694. bp = call->request;
  695. *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
  696. *bp++ = htonl(vnode->fid.vid);
  697. *bp++ = htonl(vnode->fid.vnode);
  698. *bp++ = htonl(vnode->fid.unique);
  699. *bp++ = htonl(namesz);
  700. memcpy(bp, name, namesz);
  701. bp = (void *) bp + namesz;
  702. if (padsz > 0) {
  703. memset(bp, 0, padsz);
  704. bp = (void *) bp + padsz;
  705. }
  706. *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
  707. *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
  708. *bp++ = 0; /* owner */
  709. *bp++ = 0; /* group */
  710. *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
  711. *bp++ = 0; /* segment size */
  712. afs_use_fs_server(call, fc->cbi);
  713. trace_afs_make_fs_call(call, &vnode->fid);
  714. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  715. }
  716. /*
  717. * deliver reply data to an FS.RemoveFile or FS.RemoveDir
  718. */
  719. static int afs_deliver_fs_remove(struct afs_call *call)
  720. {
  721. struct afs_vnode *vnode = call->reply[0];
  722. const __be32 *bp;
  723. int ret;
  724. _enter("{%u}", call->unmarshall);
  725. ret = afs_transfer_reply(call);
  726. if (ret < 0)
  727. return ret;
  728. /* unmarshall the reply once we've received all of it */
  729. bp = call->buffer;
  730. ret = afs_decode_status(call, &bp, &vnode->status, vnode,
  731. &call->expected_version, NULL);
  732. if (ret < 0)
  733. return ret;
  734. /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
  735. _leave(" = 0 [done]");
  736. return 0;
  737. }
  738. /*
  739. * FS.RemoveDir/FS.RemoveFile operation type
  740. */
  741. static const struct afs_call_type afs_RXFSRemoveFile = {
  742. .name = "FS.RemoveFile",
  743. .op = afs_FS_RemoveFile,
  744. .deliver = afs_deliver_fs_remove,
  745. .destructor = afs_flat_call_destructor,
  746. };
  747. static const struct afs_call_type afs_RXFSRemoveDir = {
  748. .name = "FS.RemoveDir",
  749. .op = afs_FS_RemoveDir,
  750. .deliver = afs_deliver_fs_remove,
  751. .destructor = afs_flat_call_destructor,
  752. };
  753. /*
  754. * remove a file or directory
  755. */
  756. int afs_fs_remove(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
  757. const char *name, bool isdir, u64 current_data_version)
  758. {
  759. struct afs_vnode *dvnode = fc->vnode;
  760. struct afs_call *call;
  761. struct afs_net *net = afs_v2net(dvnode);
  762. size_t namesz, reqsz, padsz;
  763. __be32 *bp;
  764. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  765. return yfs_fs_remove(fc, vnode, name, isdir, current_data_version);
  766. _enter("");
  767. namesz = strlen(name);
  768. padsz = (4 - (namesz & 3)) & 3;
  769. reqsz = (5 * 4) + namesz + padsz;
  770. call = afs_alloc_flat_call(
  771. net, isdir ? &afs_RXFSRemoveDir : &afs_RXFSRemoveFile,
  772. reqsz, (21 + 6) * 4);
  773. if (!call)
  774. return -ENOMEM;
  775. call->key = fc->key;
  776. call->reply[0] = dvnode;
  777. call->reply[1] = vnode;
  778. call->expected_version = current_data_version + 1;
  779. /* marshall the parameters */
  780. bp = call->request;
  781. *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
  782. *bp++ = htonl(dvnode->fid.vid);
  783. *bp++ = htonl(dvnode->fid.vnode);
  784. *bp++ = htonl(dvnode->fid.unique);
  785. *bp++ = htonl(namesz);
  786. memcpy(bp, name, namesz);
  787. bp = (void *) bp + namesz;
  788. if (padsz > 0) {
  789. memset(bp, 0, padsz);
  790. bp = (void *) bp + padsz;
  791. }
  792. afs_use_fs_server(call, fc->cbi);
  793. trace_afs_make_fs_call(call, &dvnode->fid);
  794. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  795. }
  796. /*
  797. * deliver reply data to an FS.Link
  798. */
  799. static int afs_deliver_fs_link(struct afs_call *call)
  800. {
  801. struct afs_vnode *dvnode = call->reply[0], *vnode = call->reply[1];
  802. const __be32 *bp;
  803. int ret;
  804. _enter("{%u}", call->unmarshall);
  805. ret = afs_transfer_reply(call);
  806. if (ret < 0)
  807. return ret;
  808. /* unmarshall the reply once we've received all of it */
  809. bp = call->buffer;
  810. ret = afs_decode_status(call, &bp, &vnode->status, vnode, NULL, NULL);
  811. if (ret < 0)
  812. return ret;
  813. ret = afs_decode_status(call, &bp, &dvnode->status, dvnode,
  814. &call->expected_version, NULL);
  815. if (ret < 0)
  816. return ret;
  817. /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
  818. _leave(" = 0 [done]");
  819. return 0;
  820. }
  821. /*
  822. * FS.Link operation type
  823. */
  824. static const struct afs_call_type afs_RXFSLink = {
  825. .name = "FS.Link",
  826. .op = afs_FS_Link,
  827. .deliver = afs_deliver_fs_link,
  828. .destructor = afs_flat_call_destructor,
  829. };
  830. /*
  831. * make a hard link
  832. */
  833. int afs_fs_link(struct afs_fs_cursor *fc, struct afs_vnode *vnode,
  834. const char *name, u64 current_data_version)
  835. {
  836. struct afs_vnode *dvnode = fc->vnode;
  837. struct afs_call *call;
  838. struct afs_net *net = afs_v2net(vnode);
  839. size_t namesz, reqsz, padsz;
  840. __be32 *bp;
  841. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  842. return yfs_fs_link(fc, vnode, name, current_data_version);
  843. _enter("");
  844. namesz = strlen(name);
  845. padsz = (4 - (namesz & 3)) & 3;
  846. reqsz = (5 * 4) + namesz + padsz + (3 * 4);
  847. call = afs_alloc_flat_call(net, &afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
  848. if (!call)
  849. return -ENOMEM;
  850. call->key = fc->key;
  851. call->reply[0] = dvnode;
  852. call->reply[1] = vnode;
  853. call->expected_version = current_data_version + 1;
  854. /* marshall the parameters */
  855. bp = call->request;
  856. *bp++ = htonl(FSLINK);
  857. *bp++ = htonl(dvnode->fid.vid);
  858. *bp++ = htonl(dvnode->fid.vnode);
  859. *bp++ = htonl(dvnode->fid.unique);
  860. *bp++ = htonl(namesz);
  861. memcpy(bp, name, namesz);
  862. bp = (void *) bp + namesz;
  863. if (padsz > 0) {
  864. memset(bp, 0, padsz);
  865. bp = (void *) bp + padsz;
  866. }
  867. *bp++ = htonl(vnode->fid.vid);
  868. *bp++ = htonl(vnode->fid.vnode);
  869. *bp++ = htonl(vnode->fid.unique);
  870. afs_use_fs_server(call, fc->cbi);
  871. trace_afs_make_fs_call(call, &vnode->fid);
  872. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  873. }
  874. /*
  875. * deliver reply data to an FS.Symlink
  876. */
  877. static int afs_deliver_fs_symlink(struct afs_call *call)
  878. {
  879. struct afs_vnode *vnode = call->reply[0];
  880. const __be32 *bp;
  881. int ret;
  882. _enter("{%u}", call->unmarshall);
  883. ret = afs_transfer_reply(call);
  884. if (ret < 0)
  885. return ret;
  886. /* unmarshall the reply once we've received all of it */
  887. bp = call->buffer;
  888. xdr_decode_AFSFid(&bp, call->reply[1]);
  889. ret = afs_decode_status(call, &bp, call->reply[2], NULL, NULL, NULL);
  890. if (ret < 0)
  891. return ret;
  892. ret = afs_decode_status(call, &bp, &vnode->status, vnode,
  893. &call->expected_version, NULL);
  894. if (ret < 0)
  895. return ret;
  896. /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
  897. _leave(" = 0 [done]");
  898. return 0;
  899. }
  900. /*
  901. * FS.Symlink operation type
  902. */
  903. static const struct afs_call_type afs_RXFSSymlink = {
  904. .name = "FS.Symlink",
  905. .op = afs_FS_Symlink,
  906. .deliver = afs_deliver_fs_symlink,
  907. .destructor = afs_flat_call_destructor,
  908. };
  909. /*
  910. * create a symbolic link
  911. */
  912. int afs_fs_symlink(struct afs_fs_cursor *fc,
  913. const char *name,
  914. const char *contents,
  915. u64 current_data_version,
  916. struct afs_fid *newfid,
  917. struct afs_file_status *newstatus)
  918. {
  919. struct afs_vnode *vnode = fc->vnode;
  920. struct afs_call *call;
  921. struct afs_net *net = afs_v2net(vnode);
  922. size_t namesz, reqsz, padsz, c_namesz, c_padsz;
  923. __be32 *bp;
  924. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  925. return yfs_fs_symlink(fc, name, contents, current_data_version,
  926. newfid, newstatus);
  927. _enter("");
  928. namesz = strlen(name);
  929. padsz = (4 - (namesz & 3)) & 3;
  930. c_namesz = strlen(contents);
  931. c_padsz = (4 - (c_namesz & 3)) & 3;
  932. reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
  933. call = afs_alloc_flat_call(net, &afs_RXFSSymlink, reqsz,
  934. (3 + 21 + 21 + 6) * 4);
  935. if (!call)
  936. return -ENOMEM;
  937. call->key = fc->key;
  938. call->reply[0] = vnode;
  939. call->reply[1] = newfid;
  940. call->reply[2] = newstatus;
  941. call->expected_version = current_data_version + 1;
  942. /* marshall the parameters */
  943. bp = call->request;
  944. *bp++ = htonl(FSSYMLINK);
  945. *bp++ = htonl(vnode->fid.vid);
  946. *bp++ = htonl(vnode->fid.vnode);
  947. *bp++ = htonl(vnode->fid.unique);
  948. *bp++ = htonl(namesz);
  949. memcpy(bp, name, namesz);
  950. bp = (void *) bp + namesz;
  951. if (padsz > 0) {
  952. memset(bp, 0, padsz);
  953. bp = (void *) bp + padsz;
  954. }
  955. *bp++ = htonl(c_namesz);
  956. memcpy(bp, contents, c_namesz);
  957. bp = (void *) bp + c_namesz;
  958. if (c_padsz > 0) {
  959. memset(bp, 0, c_padsz);
  960. bp = (void *) bp + c_padsz;
  961. }
  962. *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
  963. *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
  964. *bp++ = 0; /* owner */
  965. *bp++ = 0; /* group */
  966. *bp++ = htonl(S_IRWXUGO); /* unix mode */
  967. *bp++ = 0; /* segment size */
  968. afs_use_fs_server(call, fc->cbi);
  969. trace_afs_make_fs_call(call, &vnode->fid);
  970. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  971. }
  972. /*
  973. * deliver reply data to an FS.Rename
  974. */
  975. static int afs_deliver_fs_rename(struct afs_call *call)
  976. {
  977. struct afs_vnode *orig_dvnode = call->reply[0], *new_dvnode = call->reply[1];
  978. const __be32 *bp;
  979. int ret;
  980. _enter("{%u}", call->unmarshall);
  981. ret = afs_transfer_reply(call);
  982. if (ret < 0)
  983. return ret;
  984. /* unmarshall the reply once we've received all of it */
  985. bp = call->buffer;
  986. ret = afs_decode_status(call, &bp, &orig_dvnode->status, orig_dvnode,
  987. &call->expected_version, NULL);
  988. if (ret < 0)
  989. return ret;
  990. if (new_dvnode != orig_dvnode) {
  991. ret = afs_decode_status(call, &bp, &new_dvnode->status, new_dvnode,
  992. &call->expected_version_2, NULL);
  993. if (ret < 0)
  994. return ret;
  995. }
  996. /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
  997. _leave(" = 0 [done]");
  998. return 0;
  999. }
  1000. /*
  1001. * FS.Rename operation type
  1002. */
  1003. static const struct afs_call_type afs_RXFSRename = {
  1004. .name = "FS.Rename",
  1005. .op = afs_FS_Rename,
  1006. .deliver = afs_deliver_fs_rename,
  1007. .destructor = afs_flat_call_destructor,
  1008. };
  1009. /*
  1010. * create a symbolic link
  1011. */
  1012. int afs_fs_rename(struct afs_fs_cursor *fc,
  1013. const char *orig_name,
  1014. struct afs_vnode *new_dvnode,
  1015. const char *new_name,
  1016. u64 current_orig_data_version,
  1017. u64 current_new_data_version)
  1018. {
  1019. struct afs_vnode *orig_dvnode = fc->vnode;
  1020. struct afs_call *call;
  1021. struct afs_net *net = afs_v2net(orig_dvnode);
  1022. size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
  1023. __be32 *bp;
  1024. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  1025. return yfs_fs_rename(fc, orig_name,
  1026. new_dvnode, new_name,
  1027. current_orig_data_version,
  1028. current_new_data_version);
  1029. _enter("");
  1030. o_namesz = strlen(orig_name);
  1031. o_padsz = (4 - (o_namesz & 3)) & 3;
  1032. n_namesz = strlen(new_name);
  1033. n_padsz = (4 - (n_namesz & 3)) & 3;
  1034. reqsz = (4 * 4) +
  1035. 4 + o_namesz + o_padsz +
  1036. (3 * 4) +
  1037. 4 + n_namesz + n_padsz;
  1038. call = afs_alloc_flat_call(net, &afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
  1039. if (!call)
  1040. return -ENOMEM;
  1041. call->key = fc->key;
  1042. call->reply[0] = orig_dvnode;
  1043. call->reply[1] = new_dvnode;
  1044. call->expected_version = current_orig_data_version + 1;
  1045. call->expected_version_2 = current_new_data_version + 1;
  1046. /* marshall the parameters */
  1047. bp = call->request;
  1048. *bp++ = htonl(FSRENAME);
  1049. *bp++ = htonl(orig_dvnode->fid.vid);
  1050. *bp++ = htonl(orig_dvnode->fid.vnode);
  1051. *bp++ = htonl(orig_dvnode->fid.unique);
  1052. *bp++ = htonl(o_namesz);
  1053. memcpy(bp, orig_name, o_namesz);
  1054. bp = (void *) bp + o_namesz;
  1055. if (o_padsz > 0) {
  1056. memset(bp, 0, o_padsz);
  1057. bp = (void *) bp + o_padsz;
  1058. }
  1059. *bp++ = htonl(new_dvnode->fid.vid);
  1060. *bp++ = htonl(new_dvnode->fid.vnode);
  1061. *bp++ = htonl(new_dvnode->fid.unique);
  1062. *bp++ = htonl(n_namesz);
  1063. memcpy(bp, new_name, n_namesz);
  1064. bp = (void *) bp + n_namesz;
  1065. if (n_padsz > 0) {
  1066. memset(bp, 0, n_padsz);
  1067. bp = (void *) bp + n_padsz;
  1068. }
  1069. afs_use_fs_server(call, fc->cbi);
  1070. trace_afs_make_fs_call(call, &orig_dvnode->fid);
  1071. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1072. }
  1073. /*
  1074. * deliver reply data to an FS.StoreData
  1075. */
  1076. static int afs_deliver_fs_store_data(struct afs_call *call)
  1077. {
  1078. struct afs_vnode *vnode = call->reply[0];
  1079. const __be32 *bp;
  1080. int ret;
  1081. _enter("");
  1082. ret = afs_transfer_reply(call);
  1083. if (ret < 0)
  1084. return ret;
  1085. /* unmarshall the reply once we've received all of it */
  1086. bp = call->buffer;
  1087. ret = afs_decode_status(call, &bp, &vnode->status, vnode,
  1088. &call->expected_version, NULL);
  1089. if (ret < 0)
  1090. return ret;
  1091. /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
  1092. afs_pages_written_back(vnode, call);
  1093. _leave(" = 0 [done]");
  1094. return 0;
  1095. }
  1096. /*
  1097. * FS.StoreData operation type
  1098. */
  1099. static const struct afs_call_type afs_RXFSStoreData = {
  1100. .name = "FS.StoreData",
  1101. .op = afs_FS_StoreData,
  1102. .deliver = afs_deliver_fs_store_data,
  1103. .destructor = afs_flat_call_destructor,
  1104. };
  1105. static const struct afs_call_type afs_RXFSStoreData64 = {
  1106. .name = "FS.StoreData64",
  1107. .op = afs_FS_StoreData64,
  1108. .deliver = afs_deliver_fs_store_data,
  1109. .destructor = afs_flat_call_destructor,
  1110. };
  1111. /*
  1112. * store a set of pages to a very large file
  1113. */
  1114. static int afs_fs_store_data64(struct afs_fs_cursor *fc,
  1115. struct address_space *mapping,
  1116. pgoff_t first, pgoff_t last,
  1117. unsigned offset, unsigned to,
  1118. loff_t size, loff_t pos, loff_t i_size)
  1119. {
  1120. struct afs_vnode *vnode = fc->vnode;
  1121. struct afs_call *call;
  1122. struct afs_net *net = afs_v2net(vnode);
  1123. __be32 *bp;
  1124. _enter(",%x,{%llx:%llu},,",
  1125. key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
  1126. call = afs_alloc_flat_call(net, &afs_RXFSStoreData64,
  1127. (4 + 6 + 3 * 2) * 4,
  1128. (21 + 6) * 4);
  1129. if (!call)
  1130. return -ENOMEM;
  1131. call->key = fc->key;
  1132. call->mapping = mapping;
  1133. call->reply[0] = vnode;
  1134. call->first = first;
  1135. call->last = last;
  1136. call->first_offset = offset;
  1137. call->last_to = to;
  1138. call->send_pages = true;
  1139. call->expected_version = vnode->status.data_version + 1;
  1140. /* marshall the parameters */
  1141. bp = call->request;
  1142. *bp++ = htonl(FSSTOREDATA64);
  1143. *bp++ = htonl(vnode->fid.vid);
  1144. *bp++ = htonl(vnode->fid.vnode);
  1145. *bp++ = htonl(vnode->fid.unique);
  1146. *bp++ = htonl(AFS_SET_MTIME); /* mask */
  1147. *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
  1148. *bp++ = 0; /* owner */
  1149. *bp++ = 0; /* group */
  1150. *bp++ = 0; /* unix mode */
  1151. *bp++ = 0; /* segment size */
  1152. *bp++ = htonl(pos >> 32);
  1153. *bp++ = htonl((u32) pos);
  1154. *bp++ = htonl(size >> 32);
  1155. *bp++ = htonl((u32) size);
  1156. *bp++ = htonl(i_size >> 32);
  1157. *bp++ = htonl((u32) i_size);
  1158. trace_afs_make_fs_call(call, &vnode->fid);
  1159. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1160. }
  1161. /*
  1162. * store a set of pages
  1163. */
  1164. int afs_fs_store_data(struct afs_fs_cursor *fc, struct address_space *mapping,
  1165. pgoff_t first, pgoff_t last,
  1166. unsigned offset, unsigned to)
  1167. {
  1168. struct afs_vnode *vnode = fc->vnode;
  1169. struct afs_call *call;
  1170. struct afs_net *net = afs_v2net(vnode);
  1171. loff_t size, pos, i_size;
  1172. __be32 *bp;
  1173. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  1174. return yfs_fs_store_data(fc, mapping, first, last, offset, to);
  1175. _enter(",%x,{%llx:%llu},,",
  1176. key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
  1177. size = (loff_t)to - (loff_t)offset;
  1178. if (first != last)
  1179. size += (loff_t)(last - first) << PAGE_SHIFT;
  1180. pos = (loff_t)first << PAGE_SHIFT;
  1181. pos += offset;
  1182. i_size = i_size_read(&vnode->vfs_inode);
  1183. if (pos + size > i_size)
  1184. i_size = size + pos;
  1185. _debug("size %llx, at %llx, i_size %llx",
  1186. (unsigned long long) size, (unsigned long long) pos,
  1187. (unsigned long long) i_size);
  1188. if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
  1189. return afs_fs_store_data64(fc, mapping, first, last, offset, to,
  1190. size, pos, i_size);
  1191. call = afs_alloc_flat_call(net, &afs_RXFSStoreData,
  1192. (4 + 6 + 3) * 4,
  1193. (21 + 6) * 4);
  1194. if (!call)
  1195. return -ENOMEM;
  1196. call->key = fc->key;
  1197. call->mapping = mapping;
  1198. call->reply[0] = vnode;
  1199. call->first = first;
  1200. call->last = last;
  1201. call->first_offset = offset;
  1202. call->last_to = to;
  1203. call->send_pages = true;
  1204. call->expected_version = vnode->status.data_version + 1;
  1205. /* marshall the parameters */
  1206. bp = call->request;
  1207. *bp++ = htonl(FSSTOREDATA);
  1208. *bp++ = htonl(vnode->fid.vid);
  1209. *bp++ = htonl(vnode->fid.vnode);
  1210. *bp++ = htonl(vnode->fid.unique);
  1211. *bp++ = htonl(AFS_SET_MTIME); /* mask */
  1212. *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
  1213. *bp++ = 0; /* owner */
  1214. *bp++ = 0; /* group */
  1215. *bp++ = 0; /* unix mode */
  1216. *bp++ = 0; /* segment size */
  1217. *bp++ = htonl(pos);
  1218. *bp++ = htonl(size);
  1219. *bp++ = htonl(i_size);
  1220. afs_use_fs_server(call, fc->cbi);
  1221. trace_afs_make_fs_call(call, &vnode->fid);
  1222. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1223. }
  1224. /*
  1225. * deliver reply data to an FS.StoreStatus
  1226. */
  1227. static int afs_deliver_fs_store_status(struct afs_call *call)
  1228. {
  1229. struct afs_vnode *vnode = call->reply[0];
  1230. const __be32 *bp;
  1231. int ret;
  1232. _enter("");
  1233. ret = afs_transfer_reply(call);
  1234. if (ret < 0)
  1235. return ret;
  1236. /* unmarshall the reply once we've received all of it */
  1237. bp = call->buffer;
  1238. ret = afs_decode_status(call, &bp, &vnode->status, vnode,
  1239. &call->expected_version, NULL);
  1240. if (ret < 0)
  1241. return ret;
  1242. /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
  1243. _leave(" = 0 [done]");
  1244. return 0;
  1245. }
  1246. /*
  1247. * FS.StoreStatus operation type
  1248. */
  1249. static const struct afs_call_type afs_RXFSStoreStatus = {
  1250. .name = "FS.StoreStatus",
  1251. .op = afs_FS_StoreStatus,
  1252. .deliver = afs_deliver_fs_store_status,
  1253. .destructor = afs_flat_call_destructor,
  1254. };
  1255. static const struct afs_call_type afs_RXFSStoreData_as_Status = {
  1256. .name = "FS.StoreData",
  1257. .op = afs_FS_StoreData,
  1258. .deliver = afs_deliver_fs_store_status,
  1259. .destructor = afs_flat_call_destructor,
  1260. };
  1261. static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
  1262. .name = "FS.StoreData64",
  1263. .op = afs_FS_StoreData64,
  1264. .deliver = afs_deliver_fs_store_status,
  1265. .destructor = afs_flat_call_destructor,
  1266. };
  1267. /*
  1268. * set the attributes on a very large file, using FS.StoreData rather than
  1269. * FS.StoreStatus so as to alter the file size also
  1270. */
  1271. static int afs_fs_setattr_size64(struct afs_fs_cursor *fc, struct iattr *attr)
  1272. {
  1273. struct afs_vnode *vnode = fc->vnode;
  1274. struct afs_call *call;
  1275. struct afs_net *net = afs_v2net(vnode);
  1276. __be32 *bp;
  1277. _enter(",%x,{%llx:%llu},,",
  1278. key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
  1279. ASSERT(attr->ia_valid & ATTR_SIZE);
  1280. call = afs_alloc_flat_call(net, &afs_RXFSStoreData64_as_Status,
  1281. (4 + 6 + 3 * 2) * 4,
  1282. (21 + 6) * 4);
  1283. if (!call)
  1284. return -ENOMEM;
  1285. call->key = fc->key;
  1286. call->reply[0] = vnode;
  1287. call->expected_version = vnode->status.data_version + 1;
  1288. /* marshall the parameters */
  1289. bp = call->request;
  1290. *bp++ = htonl(FSSTOREDATA64);
  1291. *bp++ = htonl(vnode->fid.vid);
  1292. *bp++ = htonl(vnode->fid.vnode);
  1293. *bp++ = htonl(vnode->fid.unique);
  1294. xdr_encode_AFS_StoreStatus(&bp, attr);
  1295. *bp++ = 0; /* position of start of write */
  1296. *bp++ = 0;
  1297. *bp++ = 0; /* size of write */
  1298. *bp++ = 0;
  1299. *bp++ = htonl(attr->ia_size >> 32); /* new file length */
  1300. *bp++ = htonl((u32) attr->ia_size);
  1301. afs_use_fs_server(call, fc->cbi);
  1302. trace_afs_make_fs_call(call, &vnode->fid);
  1303. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1304. }
  1305. /*
  1306. * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
  1307. * so as to alter the file size also
  1308. */
  1309. static int afs_fs_setattr_size(struct afs_fs_cursor *fc, struct iattr *attr)
  1310. {
  1311. struct afs_vnode *vnode = fc->vnode;
  1312. struct afs_call *call;
  1313. struct afs_net *net = afs_v2net(vnode);
  1314. __be32 *bp;
  1315. _enter(",%x,{%llx:%llu},,",
  1316. key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
  1317. ASSERT(attr->ia_valid & ATTR_SIZE);
  1318. if (attr->ia_size >> 32)
  1319. return afs_fs_setattr_size64(fc, attr);
  1320. call = afs_alloc_flat_call(net, &afs_RXFSStoreData_as_Status,
  1321. (4 + 6 + 3) * 4,
  1322. (21 + 6) * 4);
  1323. if (!call)
  1324. return -ENOMEM;
  1325. call->key = fc->key;
  1326. call->reply[0] = vnode;
  1327. call->expected_version = vnode->status.data_version + 1;
  1328. /* marshall the parameters */
  1329. bp = call->request;
  1330. *bp++ = htonl(FSSTOREDATA);
  1331. *bp++ = htonl(vnode->fid.vid);
  1332. *bp++ = htonl(vnode->fid.vnode);
  1333. *bp++ = htonl(vnode->fid.unique);
  1334. xdr_encode_AFS_StoreStatus(&bp, attr);
  1335. *bp++ = 0; /* position of start of write */
  1336. *bp++ = 0; /* size of write */
  1337. *bp++ = htonl(attr->ia_size); /* new file length */
  1338. afs_use_fs_server(call, fc->cbi);
  1339. trace_afs_make_fs_call(call, &vnode->fid);
  1340. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1341. }
  1342. /*
  1343. * set the attributes on a file, using FS.StoreData if there's a change in file
  1344. * size, and FS.StoreStatus otherwise
  1345. */
  1346. int afs_fs_setattr(struct afs_fs_cursor *fc, struct iattr *attr)
  1347. {
  1348. struct afs_vnode *vnode = fc->vnode;
  1349. struct afs_call *call;
  1350. struct afs_net *net = afs_v2net(vnode);
  1351. __be32 *bp;
  1352. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  1353. return yfs_fs_setattr(fc, attr);
  1354. if (attr->ia_valid & ATTR_SIZE)
  1355. return afs_fs_setattr_size(fc, attr);
  1356. _enter(",%x,{%llx:%llu},,",
  1357. key_serial(fc->key), vnode->fid.vid, vnode->fid.vnode);
  1358. call = afs_alloc_flat_call(net, &afs_RXFSStoreStatus,
  1359. (4 + 6) * 4,
  1360. (21 + 6) * 4);
  1361. if (!call)
  1362. return -ENOMEM;
  1363. call->key = fc->key;
  1364. call->reply[0] = vnode;
  1365. call->expected_version = vnode->status.data_version;
  1366. /* marshall the parameters */
  1367. bp = call->request;
  1368. *bp++ = htonl(FSSTORESTATUS);
  1369. *bp++ = htonl(vnode->fid.vid);
  1370. *bp++ = htonl(vnode->fid.vnode);
  1371. *bp++ = htonl(vnode->fid.unique);
  1372. xdr_encode_AFS_StoreStatus(&bp, attr);
  1373. afs_use_fs_server(call, fc->cbi);
  1374. trace_afs_make_fs_call(call, &vnode->fid);
  1375. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1376. }
  1377. /*
  1378. * deliver reply data to an FS.GetVolumeStatus
  1379. */
  1380. static int afs_deliver_fs_get_volume_status(struct afs_call *call)
  1381. {
  1382. const __be32 *bp;
  1383. char *p;
  1384. u32 size;
  1385. int ret;
  1386. _enter("{%u}", call->unmarshall);
  1387. switch (call->unmarshall) {
  1388. case 0:
  1389. call->unmarshall++;
  1390. afs_extract_to_buf(call, 12 * 4);
  1391. /* extract the returned status record */
  1392. case 1:
  1393. _debug("extract status");
  1394. ret = afs_extract_data(call, true);
  1395. if (ret < 0)
  1396. return ret;
  1397. bp = call->buffer;
  1398. xdr_decode_AFSFetchVolumeStatus(&bp, call->reply[1]);
  1399. call->unmarshall++;
  1400. afs_extract_to_tmp(call);
  1401. /* extract the volume name length */
  1402. case 2:
  1403. ret = afs_extract_data(call, true);
  1404. if (ret < 0)
  1405. return ret;
  1406. call->count = ntohl(call->tmp);
  1407. _debug("volname length: %u", call->count);
  1408. if (call->count >= AFSNAMEMAX)
  1409. return afs_protocol_error(call, -EBADMSG,
  1410. afs_eproto_volname_len);
  1411. size = (call->count + 3) & ~3; /* It's padded */
  1412. afs_extract_begin(call, call->reply[2], size);
  1413. call->unmarshall++;
  1414. /* extract the volume name */
  1415. case 3:
  1416. _debug("extract volname");
  1417. ret = afs_extract_data(call, true);
  1418. if (ret < 0)
  1419. return ret;
  1420. p = call->reply[2];
  1421. p[call->count] = 0;
  1422. _debug("volname '%s'", p);
  1423. afs_extract_to_tmp(call);
  1424. call->unmarshall++;
  1425. /* extract the offline message length */
  1426. case 4:
  1427. ret = afs_extract_data(call, true);
  1428. if (ret < 0)
  1429. return ret;
  1430. call->count = ntohl(call->tmp);
  1431. _debug("offline msg length: %u", call->count);
  1432. if (call->count >= AFSNAMEMAX)
  1433. return afs_protocol_error(call, -EBADMSG,
  1434. afs_eproto_offline_msg_len);
  1435. size = (call->count + 3) & ~3; /* It's padded */
  1436. afs_extract_begin(call, call->reply[2], size);
  1437. call->unmarshall++;
  1438. /* extract the offline message */
  1439. case 5:
  1440. _debug("extract offline");
  1441. ret = afs_extract_data(call, true);
  1442. if (ret < 0)
  1443. return ret;
  1444. p = call->reply[2];
  1445. p[call->count] = 0;
  1446. _debug("offline '%s'", p);
  1447. afs_extract_to_tmp(call);
  1448. call->unmarshall++;
  1449. /* extract the message of the day length */
  1450. case 6:
  1451. ret = afs_extract_data(call, true);
  1452. if (ret < 0)
  1453. return ret;
  1454. call->count = ntohl(call->tmp);
  1455. _debug("motd length: %u", call->count);
  1456. if (call->count >= AFSNAMEMAX)
  1457. return afs_protocol_error(call, -EBADMSG,
  1458. afs_eproto_motd_len);
  1459. size = (call->count + 3) & ~3; /* It's padded */
  1460. afs_extract_begin(call, call->reply[2], size);
  1461. call->unmarshall++;
  1462. /* extract the message of the day */
  1463. case 7:
  1464. _debug("extract motd");
  1465. ret = afs_extract_data(call, false);
  1466. if (ret < 0)
  1467. return ret;
  1468. p = call->reply[2];
  1469. p[call->count] = 0;
  1470. _debug("motd '%s'", p);
  1471. call->unmarshall++;
  1472. case 8:
  1473. break;
  1474. }
  1475. _leave(" = 0 [done]");
  1476. return 0;
  1477. }
  1478. /*
  1479. * destroy an FS.GetVolumeStatus call
  1480. */
  1481. static void afs_get_volume_status_call_destructor(struct afs_call *call)
  1482. {
  1483. kfree(call->reply[2]);
  1484. call->reply[2] = NULL;
  1485. afs_flat_call_destructor(call);
  1486. }
  1487. /*
  1488. * FS.GetVolumeStatus operation type
  1489. */
  1490. static const struct afs_call_type afs_RXFSGetVolumeStatus = {
  1491. .name = "FS.GetVolumeStatus",
  1492. .op = afs_FS_GetVolumeStatus,
  1493. .deliver = afs_deliver_fs_get_volume_status,
  1494. .destructor = afs_get_volume_status_call_destructor,
  1495. };
  1496. /*
  1497. * fetch the status of a volume
  1498. */
  1499. int afs_fs_get_volume_status(struct afs_fs_cursor *fc,
  1500. struct afs_volume_status *vs)
  1501. {
  1502. struct afs_vnode *vnode = fc->vnode;
  1503. struct afs_call *call;
  1504. struct afs_net *net = afs_v2net(vnode);
  1505. __be32 *bp;
  1506. void *tmpbuf;
  1507. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  1508. return yfs_fs_get_volume_status(fc, vs);
  1509. _enter("");
  1510. tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
  1511. if (!tmpbuf)
  1512. return -ENOMEM;
  1513. call = afs_alloc_flat_call(net, &afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
  1514. if (!call) {
  1515. kfree(tmpbuf);
  1516. return -ENOMEM;
  1517. }
  1518. call->key = fc->key;
  1519. call->reply[0] = vnode;
  1520. call->reply[1] = vs;
  1521. call->reply[2] = tmpbuf;
  1522. /* marshall the parameters */
  1523. bp = call->request;
  1524. bp[0] = htonl(FSGETVOLUMESTATUS);
  1525. bp[1] = htonl(vnode->fid.vid);
  1526. afs_use_fs_server(call, fc->cbi);
  1527. trace_afs_make_fs_call(call, &vnode->fid);
  1528. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1529. }
  1530. /*
  1531. * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
  1532. */
  1533. static int afs_deliver_fs_xxxx_lock(struct afs_call *call)
  1534. {
  1535. const __be32 *bp;
  1536. int ret;
  1537. _enter("{%u}", call->unmarshall);
  1538. ret = afs_transfer_reply(call);
  1539. if (ret < 0)
  1540. return ret;
  1541. /* unmarshall the reply once we've received all of it */
  1542. bp = call->buffer;
  1543. /* xdr_decode_AFSVolSync(&bp, call->reply[X]); */
  1544. _leave(" = 0 [done]");
  1545. return 0;
  1546. }
  1547. /*
  1548. * FS.SetLock operation type
  1549. */
  1550. static const struct afs_call_type afs_RXFSSetLock = {
  1551. .name = "FS.SetLock",
  1552. .op = afs_FS_SetLock,
  1553. .deliver = afs_deliver_fs_xxxx_lock,
  1554. .destructor = afs_flat_call_destructor,
  1555. };
  1556. /*
  1557. * FS.ExtendLock operation type
  1558. */
  1559. static const struct afs_call_type afs_RXFSExtendLock = {
  1560. .name = "FS.ExtendLock",
  1561. .op = afs_FS_ExtendLock,
  1562. .deliver = afs_deliver_fs_xxxx_lock,
  1563. .destructor = afs_flat_call_destructor,
  1564. };
  1565. /*
  1566. * FS.ReleaseLock operation type
  1567. */
  1568. static const struct afs_call_type afs_RXFSReleaseLock = {
  1569. .name = "FS.ReleaseLock",
  1570. .op = afs_FS_ReleaseLock,
  1571. .deliver = afs_deliver_fs_xxxx_lock,
  1572. .destructor = afs_flat_call_destructor,
  1573. };
  1574. /*
  1575. * Set a lock on a file
  1576. */
  1577. int afs_fs_set_lock(struct afs_fs_cursor *fc, afs_lock_type_t type)
  1578. {
  1579. struct afs_vnode *vnode = fc->vnode;
  1580. struct afs_call *call;
  1581. struct afs_net *net = afs_v2net(vnode);
  1582. __be32 *bp;
  1583. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  1584. return yfs_fs_set_lock(fc, type);
  1585. _enter("");
  1586. call = afs_alloc_flat_call(net, &afs_RXFSSetLock, 5 * 4, 6 * 4);
  1587. if (!call)
  1588. return -ENOMEM;
  1589. call->key = fc->key;
  1590. call->reply[0] = vnode;
  1591. /* marshall the parameters */
  1592. bp = call->request;
  1593. *bp++ = htonl(FSSETLOCK);
  1594. *bp++ = htonl(vnode->fid.vid);
  1595. *bp++ = htonl(vnode->fid.vnode);
  1596. *bp++ = htonl(vnode->fid.unique);
  1597. *bp++ = htonl(type);
  1598. afs_use_fs_server(call, fc->cbi);
  1599. trace_afs_make_fs_call(call, &vnode->fid);
  1600. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1601. }
  1602. /*
  1603. * extend a lock on a file
  1604. */
  1605. int afs_fs_extend_lock(struct afs_fs_cursor *fc)
  1606. {
  1607. struct afs_vnode *vnode = fc->vnode;
  1608. struct afs_call *call;
  1609. struct afs_net *net = afs_v2net(vnode);
  1610. __be32 *bp;
  1611. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  1612. return yfs_fs_extend_lock(fc);
  1613. _enter("");
  1614. call = afs_alloc_flat_call(net, &afs_RXFSExtendLock, 4 * 4, 6 * 4);
  1615. if (!call)
  1616. return -ENOMEM;
  1617. call->key = fc->key;
  1618. call->reply[0] = vnode;
  1619. /* marshall the parameters */
  1620. bp = call->request;
  1621. *bp++ = htonl(FSEXTENDLOCK);
  1622. *bp++ = htonl(vnode->fid.vid);
  1623. *bp++ = htonl(vnode->fid.vnode);
  1624. *bp++ = htonl(vnode->fid.unique);
  1625. afs_use_fs_server(call, fc->cbi);
  1626. trace_afs_make_fs_call(call, &vnode->fid);
  1627. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1628. }
  1629. /*
  1630. * release a lock on a file
  1631. */
  1632. int afs_fs_release_lock(struct afs_fs_cursor *fc)
  1633. {
  1634. struct afs_vnode *vnode = fc->vnode;
  1635. struct afs_call *call;
  1636. struct afs_net *net = afs_v2net(vnode);
  1637. __be32 *bp;
  1638. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  1639. return yfs_fs_release_lock(fc);
  1640. _enter("");
  1641. call = afs_alloc_flat_call(net, &afs_RXFSReleaseLock, 4 * 4, 6 * 4);
  1642. if (!call)
  1643. return -ENOMEM;
  1644. call->key = fc->key;
  1645. call->reply[0] = vnode;
  1646. /* marshall the parameters */
  1647. bp = call->request;
  1648. *bp++ = htonl(FSRELEASELOCK);
  1649. *bp++ = htonl(vnode->fid.vid);
  1650. *bp++ = htonl(vnode->fid.vnode);
  1651. *bp++ = htonl(vnode->fid.unique);
  1652. afs_use_fs_server(call, fc->cbi);
  1653. trace_afs_make_fs_call(call, &vnode->fid);
  1654. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1655. }
  1656. /*
  1657. * Deliver reply data to an FS.GiveUpAllCallBacks operation.
  1658. */
  1659. static int afs_deliver_fs_give_up_all_callbacks(struct afs_call *call)
  1660. {
  1661. return afs_transfer_reply(call);
  1662. }
  1663. /*
  1664. * FS.GiveUpAllCallBacks operation type
  1665. */
  1666. static const struct afs_call_type afs_RXFSGiveUpAllCallBacks = {
  1667. .name = "FS.GiveUpAllCallBacks",
  1668. .op = afs_FS_GiveUpAllCallBacks,
  1669. .deliver = afs_deliver_fs_give_up_all_callbacks,
  1670. .destructor = afs_flat_call_destructor,
  1671. };
  1672. /*
  1673. * Flush all the callbacks we have on a server.
  1674. */
  1675. int afs_fs_give_up_all_callbacks(struct afs_net *net,
  1676. struct afs_server *server,
  1677. struct afs_addr_cursor *ac,
  1678. struct key *key)
  1679. {
  1680. struct afs_call *call;
  1681. __be32 *bp;
  1682. _enter("");
  1683. call = afs_alloc_flat_call(net, &afs_RXFSGiveUpAllCallBacks, 1 * 4, 0);
  1684. if (!call)
  1685. return -ENOMEM;
  1686. call->key = key;
  1687. /* marshall the parameters */
  1688. bp = call->request;
  1689. *bp++ = htonl(FSGIVEUPALLCALLBACKS);
  1690. /* Can't take a ref on server */
  1691. return afs_make_call(ac, call, GFP_NOFS, false);
  1692. }
  1693. /*
  1694. * Deliver reply data to an FS.GetCapabilities operation.
  1695. */
  1696. static int afs_deliver_fs_get_capabilities(struct afs_call *call)
  1697. {
  1698. u32 count;
  1699. int ret;
  1700. _enter("{%u,%zu}", call->unmarshall, iov_iter_count(&call->iter));
  1701. switch (call->unmarshall) {
  1702. case 0:
  1703. afs_extract_to_tmp(call);
  1704. call->unmarshall++;
  1705. /* Extract the capabilities word count */
  1706. case 1:
  1707. ret = afs_extract_data(call, true);
  1708. if (ret < 0)
  1709. return ret;
  1710. count = ntohl(call->tmp);
  1711. call->count = count;
  1712. call->count2 = count;
  1713. iov_iter_discard(&call->iter, READ, count * sizeof(__be32));
  1714. call->unmarshall++;
  1715. /* Extract capabilities words */
  1716. case 2:
  1717. ret = afs_extract_data(call, false);
  1718. if (ret < 0)
  1719. return ret;
  1720. /* TODO: Examine capabilities */
  1721. call->unmarshall++;
  1722. break;
  1723. }
  1724. _leave(" = 0 [done]");
  1725. return 0;
  1726. }
  1727. static void afs_destroy_fs_get_capabilities(struct afs_call *call)
  1728. {
  1729. struct afs_server *server = call->reply[0];
  1730. afs_put_server(call->net, server);
  1731. afs_flat_call_destructor(call);
  1732. }
  1733. /*
  1734. * FS.GetCapabilities operation type
  1735. */
  1736. static const struct afs_call_type afs_RXFSGetCapabilities = {
  1737. .name = "FS.GetCapabilities",
  1738. .op = afs_FS_GetCapabilities,
  1739. .deliver = afs_deliver_fs_get_capabilities,
  1740. .done = afs_fileserver_probe_result,
  1741. .destructor = afs_destroy_fs_get_capabilities,
  1742. };
  1743. /*
  1744. * Probe a fileserver for the capabilities that it supports. This can
  1745. * return up to 196 words.
  1746. */
  1747. int afs_fs_get_capabilities(struct afs_net *net,
  1748. struct afs_server *server,
  1749. struct afs_addr_cursor *ac,
  1750. struct key *key,
  1751. unsigned int server_index,
  1752. bool async)
  1753. {
  1754. struct afs_call *call;
  1755. __be32 *bp;
  1756. _enter("");
  1757. call = afs_alloc_flat_call(net, &afs_RXFSGetCapabilities, 1 * 4, 16 * 4);
  1758. if (!call)
  1759. return -ENOMEM;
  1760. call->key = key;
  1761. call->reply[0] = afs_get_server(server);
  1762. call->reply[1] = (void *)(long)server_index;
  1763. call->upgrade = true;
  1764. call->want_reply_time = true;
  1765. /* marshall the parameters */
  1766. bp = call->request;
  1767. *bp++ = htonl(FSGETCAPABILITIES);
  1768. /* Can't take a ref on server */
  1769. trace_afs_make_fs_call(call, NULL);
  1770. return afs_make_call(ac, call, GFP_NOFS, async);
  1771. }
  1772. /*
  1773. * Deliver reply data to an FS.FetchStatus with no vnode.
  1774. */
  1775. static int afs_deliver_fs_fetch_status(struct afs_call *call)
  1776. {
  1777. struct afs_file_status *status = call->reply[1];
  1778. struct afs_callback *callback = call->reply[2];
  1779. struct afs_volsync *volsync = call->reply[3];
  1780. struct afs_fid *fid = call->reply[0];
  1781. const __be32 *bp;
  1782. int ret;
  1783. ret = afs_transfer_reply(call);
  1784. if (ret < 0)
  1785. return ret;
  1786. _enter("{%llx:%llu}", fid->vid, fid->vnode);
  1787. /* unmarshall the reply once we've received all of it */
  1788. bp = call->buffer;
  1789. ret = afs_decode_status(call, &bp, status, NULL,
  1790. &call->expected_version, NULL);
  1791. if (ret < 0)
  1792. return ret;
  1793. xdr_decode_AFSCallBack_raw(call, &bp, callback);
  1794. xdr_decode_AFSVolSync(&bp, volsync);
  1795. _leave(" = 0 [done]");
  1796. return 0;
  1797. }
  1798. /*
  1799. * FS.FetchStatus operation type
  1800. */
  1801. static const struct afs_call_type afs_RXFSFetchStatus = {
  1802. .name = "FS.FetchStatus",
  1803. .op = afs_FS_FetchStatus,
  1804. .deliver = afs_deliver_fs_fetch_status,
  1805. .destructor = afs_flat_call_destructor,
  1806. };
  1807. /*
  1808. * Fetch the status information for a fid without needing a vnode handle.
  1809. */
  1810. int afs_fs_fetch_status(struct afs_fs_cursor *fc,
  1811. struct afs_net *net,
  1812. struct afs_fid *fid,
  1813. struct afs_file_status *status,
  1814. struct afs_callback *callback,
  1815. struct afs_volsync *volsync)
  1816. {
  1817. struct afs_call *call;
  1818. __be32 *bp;
  1819. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  1820. return yfs_fs_fetch_status(fc, net, fid, status, callback, volsync);
  1821. _enter(",%x,{%llx:%llu},,",
  1822. key_serial(fc->key), fid->vid, fid->vnode);
  1823. call = afs_alloc_flat_call(net, &afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
  1824. if (!call) {
  1825. fc->ac.error = -ENOMEM;
  1826. return -ENOMEM;
  1827. }
  1828. call->key = fc->key;
  1829. call->reply[0] = fid;
  1830. call->reply[1] = status;
  1831. call->reply[2] = callback;
  1832. call->reply[3] = volsync;
  1833. call->expected_version = 1; /* vnode->status.data_version */
  1834. call->want_reply_time = true;
  1835. /* marshall the parameters */
  1836. bp = call->request;
  1837. bp[0] = htonl(FSFETCHSTATUS);
  1838. bp[1] = htonl(fid->vid);
  1839. bp[2] = htonl(fid->vnode);
  1840. bp[3] = htonl(fid->unique);
  1841. call->cb_break = fc->cb_break;
  1842. afs_use_fs_server(call, fc->cbi);
  1843. trace_afs_make_fs_call(call, fid);
  1844. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1845. }
  1846. /*
  1847. * Deliver reply data to an FS.InlineBulkStatus call
  1848. */
  1849. static int afs_deliver_fs_inline_bulk_status(struct afs_call *call)
  1850. {
  1851. struct afs_file_status *statuses;
  1852. struct afs_callback *callbacks;
  1853. struct afs_vnode *vnode = call->reply[0];
  1854. const __be32 *bp;
  1855. u32 tmp;
  1856. int ret;
  1857. _enter("{%u}", call->unmarshall);
  1858. switch (call->unmarshall) {
  1859. case 0:
  1860. afs_extract_to_tmp(call);
  1861. call->unmarshall++;
  1862. /* Extract the file status count and array in two steps */
  1863. case 1:
  1864. _debug("extract status count");
  1865. ret = afs_extract_data(call, true);
  1866. if (ret < 0)
  1867. return ret;
  1868. tmp = ntohl(call->tmp);
  1869. _debug("status count: %u/%u", tmp, call->count2);
  1870. if (tmp != call->count2)
  1871. return afs_protocol_error(call, -EBADMSG,
  1872. afs_eproto_ibulkst_count);
  1873. call->count = 0;
  1874. call->unmarshall++;
  1875. more_counts:
  1876. afs_extract_to_buf(call, 21 * sizeof(__be32));
  1877. case 2:
  1878. _debug("extract status array %u", call->count);
  1879. ret = afs_extract_data(call, true);
  1880. if (ret < 0)
  1881. return ret;
  1882. bp = call->buffer;
  1883. statuses = call->reply[1];
  1884. ret = afs_decode_status(call, &bp, &statuses[call->count],
  1885. call->count == 0 ? vnode : NULL,
  1886. NULL, NULL);
  1887. if (ret < 0)
  1888. return ret;
  1889. call->count++;
  1890. if (call->count < call->count2)
  1891. goto more_counts;
  1892. call->count = 0;
  1893. call->unmarshall++;
  1894. afs_extract_to_tmp(call);
  1895. /* Extract the callback count and array in two steps */
  1896. case 3:
  1897. _debug("extract CB count");
  1898. ret = afs_extract_data(call, true);
  1899. if (ret < 0)
  1900. return ret;
  1901. tmp = ntohl(call->tmp);
  1902. _debug("CB count: %u", tmp);
  1903. if (tmp != call->count2)
  1904. return afs_protocol_error(call, -EBADMSG,
  1905. afs_eproto_ibulkst_cb_count);
  1906. call->count = 0;
  1907. call->unmarshall++;
  1908. more_cbs:
  1909. afs_extract_to_buf(call, 3 * sizeof(__be32));
  1910. case 4:
  1911. _debug("extract CB array");
  1912. ret = afs_extract_data(call, true);
  1913. if (ret < 0)
  1914. return ret;
  1915. _debug("unmarshall CB array");
  1916. bp = call->buffer;
  1917. callbacks = call->reply[2];
  1918. callbacks[call->count].version = ntohl(bp[0]);
  1919. callbacks[call->count].expires_at = xdr_decode_expiry(call, ntohl(bp[1]));
  1920. callbacks[call->count].type = ntohl(bp[2]);
  1921. statuses = call->reply[1];
  1922. if (call->count == 0 && vnode && statuses[0].abort_code == 0)
  1923. xdr_decode_AFSCallBack(call, vnode, &bp);
  1924. call->count++;
  1925. if (call->count < call->count2)
  1926. goto more_cbs;
  1927. afs_extract_to_buf(call, 6 * sizeof(__be32));
  1928. call->unmarshall++;
  1929. case 5:
  1930. ret = afs_extract_data(call, false);
  1931. if (ret < 0)
  1932. return ret;
  1933. bp = call->buffer;
  1934. xdr_decode_AFSVolSync(&bp, call->reply[3]);
  1935. call->unmarshall++;
  1936. case 6:
  1937. break;
  1938. }
  1939. _leave(" = 0 [done]");
  1940. return 0;
  1941. }
  1942. /*
  1943. * FS.InlineBulkStatus operation type
  1944. */
  1945. static const struct afs_call_type afs_RXFSInlineBulkStatus = {
  1946. .name = "FS.InlineBulkStatus",
  1947. .op = afs_FS_InlineBulkStatus,
  1948. .deliver = afs_deliver_fs_inline_bulk_status,
  1949. .destructor = afs_flat_call_destructor,
  1950. };
  1951. /*
  1952. * Fetch the status information for up to 50 files
  1953. */
  1954. int afs_fs_inline_bulk_status(struct afs_fs_cursor *fc,
  1955. struct afs_net *net,
  1956. struct afs_fid *fids,
  1957. struct afs_file_status *statuses,
  1958. struct afs_callback *callbacks,
  1959. unsigned int nr_fids,
  1960. struct afs_volsync *volsync)
  1961. {
  1962. struct afs_call *call;
  1963. __be32 *bp;
  1964. int i;
  1965. if (test_bit(AFS_SERVER_FL_IS_YFS, &fc->cbi->server->flags))
  1966. return yfs_fs_inline_bulk_status(fc, net, fids, statuses, callbacks,
  1967. nr_fids, volsync);
  1968. _enter(",%x,{%llx:%llu},%u",
  1969. key_serial(fc->key), fids[0].vid, fids[1].vnode, nr_fids);
  1970. call = afs_alloc_flat_call(net, &afs_RXFSInlineBulkStatus,
  1971. (2 + nr_fids * 3) * 4,
  1972. 21 * 4);
  1973. if (!call) {
  1974. fc->ac.error = -ENOMEM;
  1975. return -ENOMEM;
  1976. }
  1977. call->key = fc->key;
  1978. call->reply[0] = NULL; /* vnode for fid[0] */
  1979. call->reply[1] = statuses;
  1980. call->reply[2] = callbacks;
  1981. call->reply[3] = volsync;
  1982. call->count2 = nr_fids;
  1983. call->want_reply_time = true;
  1984. /* marshall the parameters */
  1985. bp = call->request;
  1986. *bp++ = htonl(FSINLINEBULKSTATUS);
  1987. *bp++ = htonl(nr_fids);
  1988. for (i = 0; i < nr_fids; i++) {
  1989. *bp++ = htonl(fids[i].vid);
  1990. *bp++ = htonl(fids[i].vnode);
  1991. *bp++ = htonl(fids[i].unique);
  1992. }
  1993. call->cb_break = fc->cb_break;
  1994. afs_use_fs_server(call, fc->cbi);
  1995. trace_afs_make_fs_call(call, &fids[0]);
  1996. return afs_make_call(&fc->ac, call, GFP_NOFS, false);
  1997. }