fsclient.c 55 KB

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