fsclient.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  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 "internal.h"
  16. #include "afs_fs.h"
  17. /*
  18. * decode an AFSFid block
  19. */
  20. static void xdr_decode_AFSFid(const __be32 **_bp, struct afs_fid *fid)
  21. {
  22. const __be32 *bp = *_bp;
  23. fid->vid = ntohl(*bp++);
  24. fid->vnode = ntohl(*bp++);
  25. fid->unique = ntohl(*bp++);
  26. *_bp = bp;
  27. }
  28. /*
  29. * decode an AFSFetchStatus block
  30. */
  31. static void xdr_decode_AFSFetchStatus(const __be32 **_bp,
  32. struct afs_file_status *status,
  33. struct afs_vnode *vnode,
  34. afs_dataversion_t *store_version)
  35. {
  36. afs_dataversion_t expected_version;
  37. const __be32 *bp = *_bp;
  38. umode_t mode;
  39. u64 data_version, size;
  40. u32 changed = 0; /* becomes non-zero if ctime-type changes seen */
  41. kuid_t owner;
  42. kgid_t group;
  43. #define EXTRACT(DST) \
  44. do { \
  45. u32 x = ntohl(*bp++); \
  46. changed |= DST - x; \
  47. DST = x; \
  48. } while (0)
  49. status->if_version = ntohl(*bp++);
  50. EXTRACT(status->type);
  51. EXTRACT(status->nlink);
  52. size = ntohl(*bp++);
  53. data_version = ntohl(*bp++);
  54. EXTRACT(status->author);
  55. owner = make_kuid(&init_user_ns, ntohl(*bp++));
  56. changed |= !uid_eq(owner, status->owner);
  57. status->owner = owner;
  58. EXTRACT(status->caller_access); /* call ticket dependent */
  59. EXTRACT(status->anon_access);
  60. EXTRACT(status->mode);
  61. EXTRACT(status->parent.vnode);
  62. EXTRACT(status->parent.unique);
  63. bp++; /* seg size */
  64. status->mtime_client = ntohl(*bp++);
  65. status->mtime_server = ntohl(*bp++);
  66. group = make_kgid(&init_user_ns, ntohl(*bp++));
  67. changed |= !gid_eq(group, status->group);
  68. status->group = group;
  69. bp++; /* sync counter */
  70. data_version |= (u64) ntohl(*bp++) << 32;
  71. EXTRACT(status->lock_count);
  72. size |= (u64) ntohl(*bp++) << 32;
  73. bp++; /* spare 4 */
  74. *_bp = bp;
  75. if (size != status->size) {
  76. status->size = size;
  77. changed |= true;
  78. }
  79. status->mode &= S_IALLUGO;
  80. _debug("vnode time %lx, %lx",
  81. status->mtime_client, status->mtime_server);
  82. if (vnode) {
  83. status->parent.vid = vnode->fid.vid;
  84. if (changed && !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
  85. _debug("vnode changed");
  86. i_size_write(&vnode->vfs_inode, size);
  87. vnode->vfs_inode.i_uid = status->owner;
  88. vnode->vfs_inode.i_gid = status->group;
  89. vnode->vfs_inode.i_generation = vnode->fid.unique;
  90. set_nlink(&vnode->vfs_inode, status->nlink);
  91. mode = vnode->vfs_inode.i_mode;
  92. mode &= ~S_IALLUGO;
  93. mode |= status->mode;
  94. barrier();
  95. vnode->vfs_inode.i_mode = mode;
  96. }
  97. vnode->vfs_inode.i_ctime.tv_sec = status->mtime_client;
  98. vnode->vfs_inode.i_mtime = vnode->vfs_inode.i_ctime;
  99. vnode->vfs_inode.i_atime = vnode->vfs_inode.i_ctime;
  100. vnode->vfs_inode.i_version = data_version;
  101. }
  102. expected_version = status->data_version;
  103. if (store_version)
  104. expected_version = *store_version;
  105. if (expected_version != data_version) {
  106. status->data_version = data_version;
  107. if (vnode && !test_bit(AFS_VNODE_UNSET, &vnode->flags)) {
  108. _debug("vnode modified %llx on {%x:%u}",
  109. (unsigned long long) data_version,
  110. vnode->fid.vid, vnode->fid.vnode);
  111. set_bit(AFS_VNODE_MODIFIED, &vnode->flags);
  112. set_bit(AFS_VNODE_ZAP_DATA, &vnode->flags);
  113. }
  114. } else if (store_version) {
  115. status->data_version = data_version;
  116. }
  117. }
  118. /*
  119. * decode an AFSCallBack block
  120. */
  121. static void xdr_decode_AFSCallBack(const __be32 **_bp, struct afs_vnode *vnode)
  122. {
  123. const __be32 *bp = *_bp;
  124. vnode->cb_version = ntohl(*bp++);
  125. vnode->cb_expiry = ntohl(*bp++);
  126. vnode->cb_type = ntohl(*bp++);
  127. vnode->cb_expires = vnode->cb_expiry + ktime_get_real_seconds();
  128. *_bp = bp;
  129. }
  130. static void xdr_decode_AFSCallBack_raw(const __be32 **_bp,
  131. struct afs_callback *cb)
  132. {
  133. const __be32 *bp = *_bp;
  134. cb->version = ntohl(*bp++);
  135. cb->expiry = ntohl(*bp++);
  136. cb->type = ntohl(*bp++);
  137. *_bp = bp;
  138. }
  139. /*
  140. * decode an AFSVolSync block
  141. */
  142. static void xdr_decode_AFSVolSync(const __be32 **_bp,
  143. struct afs_volsync *volsync)
  144. {
  145. const __be32 *bp = *_bp;
  146. volsync->creation = ntohl(*bp++);
  147. bp++; /* spare2 */
  148. bp++; /* spare3 */
  149. bp++; /* spare4 */
  150. bp++; /* spare5 */
  151. bp++; /* spare6 */
  152. *_bp = bp;
  153. }
  154. /*
  155. * encode the requested attributes into an AFSStoreStatus block
  156. */
  157. static void xdr_encode_AFS_StoreStatus(__be32 **_bp, struct iattr *attr)
  158. {
  159. __be32 *bp = *_bp;
  160. u32 mask = 0, mtime = 0, owner = 0, group = 0, mode = 0;
  161. mask = 0;
  162. if (attr->ia_valid & ATTR_MTIME) {
  163. mask |= AFS_SET_MTIME;
  164. mtime = attr->ia_mtime.tv_sec;
  165. }
  166. if (attr->ia_valid & ATTR_UID) {
  167. mask |= AFS_SET_OWNER;
  168. owner = from_kuid(&init_user_ns, attr->ia_uid);
  169. }
  170. if (attr->ia_valid & ATTR_GID) {
  171. mask |= AFS_SET_GROUP;
  172. group = from_kgid(&init_user_ns, attr->ia_gid);
  173. }
  174. if (attr->ia_valid & ATTR_MODE) {
  175. mask |= AFS_SET_MODE;
  176. mode = attr->ia_mode & S_IALLUGO;
  177. }
  178. *bp++ = htonl(mask);
  179. *bp++ = htonl(mtime);
  180. *bp++ = htonl(owner);
  181. *bp++ = htonl(group);
  182. *bp++ = htonl(mode);
  183. *bp++ = 0; /* segment size */
  184. *_bp = bp;
  185. }
  186. /*
  187. * decode an AFSFetchVolumeStatus block
  188. */
  189. static void xdr_decode_AFSFetchVolumeStatus(const __be32 **_bp,
  190. struct afs_volume_status *vs)
  191. {
  192. const __be32 *bp = *_bp;
  193. vs->vid = ntohl(*bp++);
  194. vs->parent_id = ntohl(*bp++);
  195. vs->online = ntohl(*bp++);
  196. vs->in_service = ntohl(*bp++);
  197. vs->blessed = ntohl(*bp++);
  198. vs->needs_salvage = ntohl(*bp++);
  199. vs->type = ntohl(*bp++);
  200. vs->min_quota = ntohl(*bp++);
  201. vs->max_quota = ntohl(*bp++);
  202. vs->blocks_in_use = ntohl(*bp++);
  203. vs->part_blocks_avail = ntohl(*bp++);
  204. vs->part_max_blocks = ntohl(*bp++);
  205. *_bp = bp;
  206. }
  207. /*
  208. * deliver reply data to an FS.FetchStatus
  209. */
  210. static int afs_deliver_fs_fetch_status(struct afs_call *call,
  211. struct sk_buff *skb, bool last)
  212. {
  213. struct afs_vnode *vnode = call->reply;
  214. const __be32 *bp;
  215. _enter(",,%u", last);
  216. afs_transfer_reply(call, skb);
  217. if (!last)
  218. return 0;
  219. if (call->reply_size != call->reply_max)
  220. return -EBADMSG;
  221. /* unmarshall the reply once we've received all of it */
  222. bp = call->buffer;
  223. xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
  224. xdr_decode_AFSCallBack(&bp, vnode);
  225. if (call->reply2)
  226. xdr_decode_AFSVolSync(&bp, call->reply2);
  227. _leave(" = 0 [done]");
  228. return 0;
  229. }
  230. /*
  231. * FS.FetchStatus operation type
  232. */
  233. static const struct afs_call_type afs_RXFSFetchStatus = {
  234. .name = "FS.FetchStatus",
  235. .deliver = afs_deliver_fs_fetch_status,
  236. .abort_to_error = afs_abort_to_error,
  237. .destructor = afs_flat_call_destructor,
  238. };
  239. /*
  240. * fetch the status information for a file
  241. */
  242. int afs_fs_fetch_file_status(struct afs_server *server,
  243. struct key *key,
  244. struct afs_vnode *vnode,
  245. struct afs_volsync *volsync,
  246. const struct afs_wait_mode *wait_mode)
  247. {
  248. struct afs_call *call;
  249. __be32 *bp;
  250. _enter(",%x,{%x:%u},,",
  251. key_serial(key), vnode->fid.vid, vnode->fid.vnode);
  252. call = afs_alloc_flat_call(&afs_RXFSFetchStatus, 16, (21 + 3 + 6) * 4);
  253. if (!call)
  254. return -ENOMEM;
  255. call->key = key;
  256. call->reply = vnode;
  257. call->reply2 = volsync;
  258. call->service_id = FS_SERVICE;
  259. call->port = htons(AFS_FS_PORT);
  260. /* marshall the parameters */
  261. bp = call->request;
  262. bp[0] = htonl(FSFETCHSTATUS);
  263. bp[1] = htonl(vnode->fid.vid);
  264. bp[2] = htonl(vnode->fid.vnode);
  265. bp[3] = htonl(vnode->fid.unique);
  266. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  267. }
  268. /*
  269. * deliver reply data to an FS.FetchData
  270. */
  271. static int afs_deliver_fs_fetch_data(struct afs_call *call,
  272. struct sk_buff *skb, bool last)
  273. {
  274. struct afs_vnode *vnode = call->reply;
  275. const __be32 *bp;
  276. struct page *page;
  277. void *buffer;
  278. int ret;
  279. _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
  280. switch (call->unmarshall) {
  281. case 0:
  282. call->offset = 0;
  283. call->unmarshall++;
  284. if (call->operation_ID != FSFETCHDATA64) {
  285. call->unmarshall++;
  286. goto no_msw;
  287. }
  288. /* extract the upper part of the returned data length of an
  289. * FSFETCHDATA64 op (which should always be 0 using this
  290. * client) */
  291. case 1:
  292. _debug("extract data length (MSW)");
  293. ret = afs_extract_data(call, skb, last, &call->tmp, 4);
  294. switch (ret) {
  295. case 0: break;
  296. case -EAGAIN: return 0;
  297. default: return ret;
  298. }
  299. call->count = ntohl(call->tmp);
  300. _debug("DATA length MSW: %u", call->count);
  301. if (call->count > 0)
  302. return -EBADMSG;
  303. call->offset = 0;
  304. call->unmarshall++;
  305. no_msw:
  306. /* extract the returned data length */
  307. case 2:
  308. _debug("extract data length");
  309. ret = afs_extract_data(call, skb, last, &call->tmp, 4);
  310. switch (ret) {
  311. case 0: break;
  312. case -EAGAIN: return 0;
  313. default: return ret;
  314. }
  315. call->count = ntohl(call->tmp);
  316. _debug("DATA length: %u", call->count);
  317. if (call->count > PAGE_SIZE)
  318. return -EBADMSG;
  319. call->offset = 0;
  320. call->unmarshall++;
  321. /* extract the returned data */
  322. case 3:
  323. _debug("extract data");
  324. if (call->count > 0) {
  325. page = call->reply3;
  326. buffer = kmap_atomic(page);
  327. ret = afs_extract_data(call, skb, last, buffer,
  328. call->count);
  329. kunmap_atomic(buffer);
  330. switch (ret) {
  331. case 0: break;
  332. case -EAGAIN: return 0;
  333. default: return ret;
  334. }
  335. }
  336. call->offset = 0;
  337. call->unmarshall++;
  338. /* extract the metadata */
  339. case 4:
  340. ret = afs_extract_data(call, skb, last, call->buffer,
  341. (21 + 3 + 6) * 4);
  342. switch (ret) {
  343. case 0: break;
  344. case -EAGAIN: return 0;
  345. default: return ret;
  346. }
  347. bp = call->buffer;
  348. xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
  349. xdr_decode_AFSCallBack(&bp, vnode);
  350. if (call->reply2)
  351. xdr_decode_AFSVolSync(&bp, call->reply2);
  352. call->offset = 0;
  353. call->unmarshall++;
  354. case 5:
  355. _debug("trailer");
  356. if (skb->len != 0)
  357. return -EBADMSG;
  358. break;
  359. }
  360. if (!last)
  361. return 0;
  362. if (call->count < PAGE_SIZE) {
  363. _debug("clear");
  364. page = call->reply3;
  365. buffer = kmap_atomic(page);
  366. memset(buffer + call->count, 0, PAGE_SIZE - call->count);
  367. kunmap_atomic(buffer);
  368. }
  369. _leave(" = 0 [done]");
  370. return 0;
  371. }
  372. /*
  373. * FS.FetchData operation type
  374. */
  375. static const struct afs_call_type afs_RXFSFetchData = {
  376. .name = "FS.FetchData",
  377. .deliver = afs_deliver_fs_fetch_data,
  378. .abort_to_error = afs_abort_to_error,
  379. .destructor = afs_flat_call_destructor,
  380. };
  381. static const struct afs_call_type afs_RXFSFetchData64 = {
  382. .name = "FS.FetchData64",
  383. .deliver = afs_deliver_fs_fetch_data,
  384. .abort_to_error = afs_abort_to_error,
  385. .destructor = afs_flat_call_destructor,
  386. };
  387. /*
  388. * fetch data from a very large file
  389. */
  390. static int afs_fs_fetch_data64(struct afs_server *server,
  391. struct key *key,
  392. struct afs_vnode *vnode,
  393. off_t offset, size_t length,
  394. struct page *buffer,
  395. const struct afs_wait_mode *wait_mode)
  396. {
  397. struct afs_call *call;
  398. __be32 *bp;
  399. _enter("");
  400. ASSERTCMP(length, <, ULONG_MAX);
  401. call = afs_alloc_flat_call(&afs_RXFSFetchData64, 32, (21 + 3 + 6) * 4);
  402. if (!call)
  403. return -ENOMEM;
  404. call->key = key;
  405. call->reply = vnode;
  406. call->reply2 = NULL; /* volsync */
  407. call->reply3 = buffer;
  408. call->service_id = FS_SERVICE;
  409. call->port = htons(AFS_FS_PORT);
  410. call->operation_ID = FSFETCHDATA64;
  411. /* marshall the parameters */
  412. bp = call->request;
  413. bp[0] = htonl(FSFETCHDATA64);
  414. bp[1] = htonl(vnode->fid.vid);
  415. bp[2] = htonl(vnode->fid.vnode);
  416. bp[3] = htonl(vnode->fid.unique);
  417. bp[4] = htonl(upper_32_bits(offset));
  418. bp[5] = htonl((u32) offset);
  419. bp[6] = 0;
  420. bp[7] = htonl((u32) length);
  421. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  422. }
  423. /*
  424. * fetch data from a file
  425. */
  426. int afs_fs_fetch_data(struct afs_server *server,
  427. struct key *key,
  428. struct afs_vnode *vnode,
  429. off_t offset, size_t length,
  430. struct page *buffer,
  431. const struct afs_wait_mode *wait_mode)
  432. {
  433. struct afs_call *call;
  434. __be32 *bp;
  435. if (upper_32_bits(offset) || upper_32_bits(offset + length))
  436. return afs_fs_fetch_data64(server, key, vnode, offset, length,
  437. buffer, wait_mode);
  438. _enter("");
  439. call = afs_alloc_flat_call(&afs_RXFSFetchData, 24, (21 + 3 + 6) * 4);
  440. if (!call)
  441. return -ENOMEM;
  442. call->key = key;
  443. call->reply = vnode;
  444. call->reply2 = NULL; /* volsync */
  445. call->reply3 = buffer;
  446. call->service_id = FS_SERVICE;
  447. call->port = htons(AFS_FS_PORT);
  448. call->operation_ID = FSFETCHDATA;
  449. /* marshall the parameters */
  450. bp = call->request;
  451. bp[0] = htonl(FSFETCHDATA);
  452. bp[1] = htonl(vnode->fid.vid);
  453. bp[2] = htonl(vnode->fid.vnode);
  454. bp[3] = htonl(vnode->fid.unique);
  455. bp[4] = htonl(offset);
  456. bp[5] = htonl(length);
  457. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  458. }
  459. /*
  460. * deliver reply data to an FS.GiveUpCallBacks
  461. */
  462. static int afs_deliver_fs_give_up_callbacks(struct afs_call *call,
  463. struct sk_buff *skb, bool last)
  464. {
  465. _enter(",{%u},%d", skb->len, last);
  466. if (skb->len > 0)
  467. return -EBADMSG; /* shouldn't be any reply data */
  468. return 0;
  469. }
  470. /*
  471. * FS.GiveUpCallBacks operation type
  472. */
  473. static const struct afs_call_type afs_RXFSGiveUpCallBacks = {
  474. .name = "FS.GiveUpCallBacks",
  475. .deliver = afs_deliver_fs_give_up_callbacks,
  476. .abort_to_error = afs_abort_to_error,
  477. .destructor = afs_flat_call_destructor,
  478. };
  479. /*
  480. * give up a set of callbacks
  481. * - the callbacks are held in the server->cb_break ring
  482. */
  483. int afs_fs_give_up_callbacks(struct afs_server *server,
  484. const struct afs_wait_mode *wait_mode)
  485. {
  486. struct afs_call *call;
  487. size_t ncallbacks;
  488. __be32 *bp, *tp;
  489. int loop;
  490. ncallbacks = CIRC_CNT(server->cb_break_head, server->cb_break_tail,
  491. ARRAY_SIZE(server->cb_break));
  492. _enter("{%zu},", ncallbacks);
  493. if (ncallbacks == 0)
  494. return 0;
  495. if (ncallbacks > AFSCBMAX)
  496. ncallbacks = AFSCBMAX;
  497. _debug("break %zu callbacks", ncallbacks);
  498. call = afs_alloc_flat_call(&afs_RXFSGiveUpCallBacks,
  499. 12 + ncallbacks * 6 * 4, 0);
  500. if (!call)
  501. return -ENOMEM;
  502. call->service_id = FS_SERVICE;
  503. call->port = htons(AFS_FS_PORT);
  504. /* marshall the parameters */
  505. bp = call->request;
  506. tp = bp + 2 + ncallbacks * 3;
  507. *bp++ = htonl(FSGIVEUPCALLBACKS);
  508. *bp++ = htonl(ncallbacks);
  509. *tp++ = htonl(ncallbacks);
  510. atomic_sub(ncallbacks, &server->cb_break_n);
  511. for (loop = ncallbacks; loop > 0; loop--) {
  512. struct afs_callback *cb =
  513. &server->cb_break[server->cb_break_tail];
  514. *bp++ = htonl(cb->fid.vid);
  515. *bp++ = htonl(cb->fid.vnode);
  516. *bp++ = htonl(cb->fid.unique);
  517. *tp++ = htonl(cb->version);
  518. *tp++ = htonl(cb->expiry);
  519. *tp++ = htonl(cb->type);
  520. smp_mb();
  521. server->cb_break_tail =
  522. (server->cb_break_tail + 1) &
  523. (ARRAY_SIZE(server->cb_break) - 1);
  524. }
  525. ASSERT(ncallbacks > 0);
  526. wake_up_nr(&server->cb_break_waitq, ncallbacks);
  527. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  528. }
  529. /*
  530. * deliver reply data to an FS.CreateFile or an FS.MakeDir
  531. */
  532. static int afs_deliver_fs_create_vnode(struct afs_call *call,
  533. struct sk_buff *skb, bool last)
  534. {
  535. struct afs_vnode *vnode = call->reply;
  536. const __be32 *bp;
  537. _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
  538. afs_transfer_reply(call, skb);
  539. if (!last)
  540. return 0;
  541. if (call->reply_size != call->reply_max)
  542. return -EBADMSG;
  543. /* unmarshall the reply once we've received all of it */
  544. bp = call->buffer;
  545. xdr_decode_AFSFid(&bp, call->reply2);
  546. xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL);
  547. xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
  548. xdr_decode_AFSCallBack_raw(&bp, call->reply4);
  549. /* xdr_decode_AFSVolSync(&bp, call->replyX); */
  550. _leave(" = 0 [done]");
  551. return 0;
  552. }
  553. /*
  554. * FS.CreateFile and FS.MakeDir operation type
  555. */
  556. static const struct afs_call_type afs_RXFSCreateXXXX = {
  557. .name = "FS.CreateXXXX",
  558. .deliver = afs_deliver_fs_create_vnode,
  559. .abort_to_error = afs_abort_to_error,
  560. .destructor = afs_flat_call_destructor,
  561. };
  562. /*
  563. * create a file or make a directory
  564. */
  565. int afs_fs_create(struct afs_server *server,
  566. struct key *key,
  567. struct afs_vnode *vnode,
  568. const char *name,
  569. umode_t mode,
  570. struct afs_fid *newfid,
  571. struct afs_file_status *newstatus,
  572. struct afs_callback *newcb,
  573. const struct afs_wait_mode *wait_mode)
  574. {
  575. struct afs_call *call;
  576. size_t namesz, reqsz, padsz;
  577. __be32 *bp;
  578. _enter("");
  579. namesz = strlen(name);
  580. padsz = (4 - (namesz & 3)) & 3;
  581. reqsz = (5 * 4) + namesz + padsz + (6 * 4);
  582. call = afs_alloc_flat_call(&afs_RXFSCreateXXXX, reqsz,
  583. (3 + 21 + 21 + 3 + 6) * 4);
  584. if (!call)
  585. return -ENOMEM;
  586. call->key = key;
  587. call->reply = vnode;
  588. call->reply2 = newfid;
  589. call->reply3 = newstatus;
  590. call->reply4 = newcb;
  591. call->service_id = FS_SERVICE;
  592. call->port = htons(AFS_FS_PORT);
  593. /* marshall the parameters */
  594. bp = call->request;
  595. *bp++ = htonl(S_ISDIR(mode) ? FSMAKEDIR : FSCREATEFILE);
  596. *bp++ = htonl(vnode->fid.vid);
  597. *bp++ = htonl(vnode->fid.vnode);
  598. *bp++ = htonl(vnode->fid.unique);
  599. *bp++ = htonl(namesz);
  600. memcpy(bp, name, namesz);
  601. bp = (void *) bp + namesz;
  602. if (padsz > 0) {
  603. memset(bp, 0, padsz);
  604. bp = (void *) bp + padsz;
  605. }
  606. *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
  607. *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
  608. *bp++ = 0; /* owner */
  609. *bp++ = 0; /* group */
  610. *bp++ = htonl(mode & S_IALLUGO); /* unix mode */
  611. *bp++ = 0; /* segment size */
  612. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  613. }
  614. /*
  615. * deliver reply data to an FS.RemoveFile or FS.RemoveDir
  616. */
  617. static int afs_deliver_fs_remove(struct afs_call *call,
  618. struct sk_buff *skb, bool last)
  619. {
  620. struct afs_vnode *vnode = call->reply;
  621. const __be32 *bp;
  622. _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
  623. afs_transfer_reply(call, skb);
  624. if (!last)
  625. return 0;
  626. if (call->reply_size != call->reply_max)
  627. return -EBADMSG;
  628. /* unmarshall the reply once we've received all of it */
  629. bp = call->buffer;
  630. xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
  631. /* xdr_decode_AFSVolSync(&bp, call->replyX); */
  632. _leave(" = 0 [done]");
  633. return 0;
  634. }
  635. /*
  636. * FS.RemoveDir/FS.RemoveFile operation type
  637. */
  638. static const struct afs_call_type afs_RXFSRemoveXXXX = {
  639. .name = "FS.RemoveXXXX",
  640. .deliver = afs_deliver_fs_remove,
  641. .abort_to_error = afs_abort_to_error,
  642. .destructor = afs_flat_call_destructor,
  643. };
  644. /*
  645. * remove a file or directory
  646. */
  647. int afs_fs_remove(struct afs_server *server,
  648. struct key *key,
  649. struct afs_vnode *vnode,
  650. const char *name,
  651. bool isdir,
  652. const struct afs_wait_mode *wait_mode)
  653. {
  654. struct afs_call *call;
  655. size_t namesz, reqsz, padsz;
  656. __be32 *bp;
  657. _enter("");
  658. namesz = strlen(name);
  659. padsz = (4 - (namesz & 3)) & 3;
  660. reqsz = (5 * 4) + namesz + padsz;
  661. call = afs_alloc_flat_call(&afs_RXFSRemoveXXXX, reqsz, (21 + 6) * 4);
  662. if (!call)
  663. return -ENOMEM;
  664. call->key = key;
  665. call->reply = vnode;
  666. call->service_id = FS_SERVICE;
  667. call->port = htons(AFS_FS_PORT);
  668. /* marshall the parameters */
  669. bp = call->request;
  670. *bp++ = htonl(isdir ? FSREMOVEDIR : FSREMOVEFILE);
  671. *bp++ = htonl(vnode->fid.vid);
  672. *bp++ = htonl(vnode->fid.vnode);
  673. *bp++ = htonl(vnode->fid.unique);
  674. *bp++ = htonl(namesz);
  675. memcpy(bp, name, namesz);
  676. bp = (void *) bp + namesz;
  677. if (padsz > 0) {
  678. memset(bp, 0, padsz);
  679. bp = (void *) bp + padsz;
  680. }
  681. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  682. }
  683. /*
  684. * deliver reply data to an FS.Link
  685. */
  686. static int afs_deliver_fs_link(struct afs_call *call,
  687. struct sk_buff *skb, bool last)
  688. {
  689. struct afs_vnode *dvnode = call->reply, *vnode = call->reply2;
  690. const __be32 *bp;
  691. _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
  692. afs_transfer_reply(call, skb);
  693. if (!last)
  694. return 0;
  695. if (call->reply_size != call->reply_max)
  696. return -EBADMSG;
  697. /* unmarshall the reply once we've received all of it */
  698. bp = call->buffer;
  699. xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
  700. xdr_decode_AFSFetchStatus(&bp, &dvnode->status, dvnode, NULL);
  701. /* xdr_decode_AFSVolSync(&bp, call->replyX); */
  702. _leave(" = 0 [done]");
  703. return 0;
  704. }
  705. /*
  706. * FS.Link operation type
  707. */
  708. static const struct afs_call_type afs_RXFSLink = {
  709. .name = "FS.Link",
  710. .deliver = afs_deliver_fs_link,
  711. .abort_to_error = afs_abort_to_error,
  712. .destructor = afs_flat_call_destructor,
  713. };
  714. /*
  715. * make a hard link
  716. */
  717. int afs_fs_link(struct afs_server *server,
  718. struct key *key,
  719. struct afs_vnode *dvnode,
  720. struct afs_vnode *vnode,
  721. const char *name,
  722. const struct afs_wait_mode *wait_mode)
  723. {
  724. struct afs_call *call;
  725. size_t namesz, reqsz, padsz;
  726. __be32 *bp;
  727. _enter("");
  728. namesz = strlen(name);
  729. padsz = (4 - (namesz & 3)) & 3;
  730. reqsz = (5 * 4) + namesz + padsz + (3 * 4);
  731. call = afs_alloc_flat_call(&afs_RXFSLink, reqsz, (21 + 21 + 6) * 4);
  732. if (!call)
  733. return -ENOMEM;
  734. call->key = key;
  735. call->reply = dvnode;
  736. call->reply2 = vnode;
  737. call->service_id = FS_SERVICE;
  738. call->port = htons(AFS_FS_PORT);
  739. /* marshall the parameters */
  740. bp = call->request;
  741. *bp++ = htonl(FSLINK);
  742. *bp++ = htonl(dvnode->fid.vid);
  743. *bp++ = htonl(dvnode->fid.vnode);
  744. *bp++ = htonl(dvnode->fid.unique);
  745. *bp++ = htonl(namesz);
  746. memcpy(bp, name, namesz);
  747. bp = (void *) bp + namesz;
  748. if (padsz > 0) {
  749. memset(bp, 0, padsz);
  750. bp = (void *) bp + padsz;
  751. }
  752. *bp++ = htonl(vnode->fid.vid);
  753. *bp++ = htonl(vnode->fid.vnode);
  754. *bp++ = htonl(vnode->fid.unique);
  755. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  756. }
  757. /*
  758. * deliver reply data to an FS.Symlink
  759. */
  760. static int afs_deliver_fs_symlink(struct afs_call *call,
  761. struct sk_buff *skb, bool last)
  762. {
  763. struct afs_vnode *vnode = call->reply;
  764. const __be32 *bp;
  765. _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
  766. afs_transfer_reply(call, skb);
  767. if (!last)
  768. return 0;
  769. if (call->reply_size != call->reply_max)
  770. return -EBADMSG;
  771. /* unmarshall the reply once we've received all of it */
  772. bp = call->buffer;
  773. xdr_decode_AFSFid(&bp, call->reply2);
  774. xdr_decode_AFSFetchStatus(&bp, call->reply3, NULL, NULL);
  775. xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, NULL);
  776. /* xdr_decode_AFSVolSync(&bp, call->replyX); */
  777. _leave(" = 0 [done]");
  778. return 0;
  779. }
  780. /*
  781. * FS.Symlink operation type
  782. */
  783. static const struct afs_call_type afs_RXFSSymlink = {
  784. .name = "FS.Symlink",
  785. .deliver = afs_deliver_fs_symlink,
  786. .abort_to_error = afs_abort_to_error,
  787. .destructor = afs_flat_call_destructor,
  788. };
  789. /*
  790. * create a symbolic link
  791. */
  792. int afs_fs_symlink(struct afs_server *server,
  793. struct key *key,
  794. struct afs_vnode *vnode,
  795. const char *name,
  796. const char *contents,
  797. struct afs_fid *newfid,
  798. struct afs_file_status *newstatus,
  799. const struct afs_wait_mode *wait_mode)
  800. {
  801. struct afs_call *call;
  802. size_t namesz, reqsz, padsz, c_namesz, c_padsz;
  803. __be32 *bp;
  804. _enter("");
  805. namesz = strlen(name);
  806. padsz = (4 - (namesz & 3)) & 3;
  807. c_namesz = strlen(contents);
  808. c_padsz = (4 - (c_namesz & 3)) & 3;
  809. reqsz = (6 * 4) + namesz + padsz + c_namesz + c_padsz + (6 * 4);
  810. call = afs_alloc_flat_call(&afs_RXFSSymlink, reqsz,
  811. (3 + 21 + 21 + 6) * 4);
  812. if (!call)
  813. return -ENOMEM;
  814. call->key = key;
  815. call->reply = vnode;
  816. call->reply2 = newfid;
  817. call->reply3 = newstatus;
  818. call->service_id = FS_SERVICE;
  819. call->port = htons(AFS_FS_PORT);
  820. /* marshall the parameters */
  821. bp = call->request;
  822. *bp++ = htonl(FSSYMLINK);
  823. *bp++ = htonl(vnode->fid.vid);
  824. *bp++ = htonl(vnode->fid.vnode);
  825. *bp++ = htonl(vnode->fid.unique);
  826. *bp++ = htonl(namesz);
  827. memcpy(bp, name, namesz);
  828. bp = (void *) bp + namesz;
  829. if (padsz > 0) {
  830. memset(bp, 0, padsz);
  831. bp = (void *) bp + padsz;
  832. }
  833. *bp++ = htonl(c_namesz);
  834. memcpy(bp, contents, c_namesz);
  835. bp = (void *) bp + c_namesz;
  836. if (c_padsz > 0) {
  837. memset(bp, 0, c_padsz);
  838. bp = (void *) bp + c_padsz;
  839. }
  840. *bp++ = htonl(AFS_SET_MODE | AFS_SET_MTIME);
  841. *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
  842. *bp++ = 0; /* owner */
  843. *bp++ = 0; /* group */
  844. *bp++ = htonl(S_IRWXUGO); /* unix mode */
  845. *bp++ = 0; /* segment size */
  846. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  847. }
  848. /*
  849. * deliver reply data to an FS.Rename
  850. */
  851. static int afs_deliver_fs_rename(struct afs_call *call,
  852. struct sk_buff *skb, bool last)
  853. {
  854. struct afs_vnode *orig_dvnode = call->reply, *new_dvnode = call->reply2;
  855. const __be32 *bp;
  856. _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
  857. afs_transfer_reply(call, skb);
  858. if (!last)
  859. return 0;
  860. if (call->reply_size != call->reply_max)
  861. return -EBADMSG;
  862. /* unmarshall the reply once we've received all of it */
  863. bp = call->buffer;
  864. xdr_decode_AFSFetchStatus(&bp, &orig_dvnode->status, orig_dvnode, NULL);
  865. if (new_dvnode != orig_dvnode)
  866. xdr_decode_AFSFetchStatus(&bp, &new_dvnode->status, new_dvnode,
  867. NULL);
  868. /* xdr_decode_AFSVolSync(&bp, call->replyX); */
  869. _leave(" = 0 [done]");
  870. return 0;
  871. }
  872. /*
  873. * FS.Rename operation type
  874. */
  875. static const struct afs_call_type afs_RXFSRename = {
  876. .name = "FS.Rename",
  877. .deliver = afs_deliver_fs_rename,
  878. .abort_to_error = afs_abort_to_error,
  879. .destructor = afs_flat_call_destructor,
  880. };
  881. /*
  882. * create a symbolic link
  883. */
  884. int afs_fs_rename(struct afs_server *server,
  885. struct key *key,
  886. struct afs_vnode *orig_dvnode,
  887. const char *orig_name,
  888. struct afs_vnode *new_dvnode,
  889. const char *new_name,
  890. const struct afs_wait_mode *wait_mode)
  891. {
  892. struct afs_call *call;
  893. size_t reqsz, o_namesz, o_padsz, n_namesz, n_padsz;
  894. __be32 *bp;
  895. _enter("");
  896. o_namesz = strlen(orig_name);
  897. o_padsz = (4 - (o_namesz & 3)) & 3;
  898. n_namesz = strlen(new_name);
  899. n_padsz = (4 - (n_namesz & 3)) & 3;
  900. reqsz = (4 * 4) +
  901. 4 + o_namesz + o_padsz +
  902. (3 * 4) +
  903. 4 + n_namesz + n_padsz;
  904. call = afs_alloc_flat_call(&afs_RXFSRename, reqsz, (21 + 21 + 6) * 4);
  905. if (!call)
  906. return -ENOMEM;
  907. call->key = key;
  908. call->reply = orig_dvnode;
  909. call->reply2 = new_dvnode;
  910. call->service_id = FS_SERVICE;
  911. call->port = htons(AFS_FS_PORT);
  912. /* marshall the parameters */
  913. bp = call->request;
  914. *bp++ = htonl(FSRENAME);
  915. *bp++ = htonl(orig_dvnode->fid.vid);
  916. *bp++ = htonl(orig_dvnode->fid.vnode);
  917. *bp++ = htonl(orig_dvnode->fid.unique);
  918. *bp++ = htonl(o_namesz);
  919. memcpy(bp, orig_name, o_namesz);
  920. bp = (void *) bp + o_namesz;
  921. if (o_padsz > 0) {
  922. memset(bp, 0, o_padsz);
  923. bp = (void *) bp + o_padsz;
  924. }
  925. *bp++ = htonl(new_dvnode->fid.vid);
  926. *bp++ = htonl(new_dvnode->fid.vnode);
  927. *bp++ = htonl(new_dvnode->fid.unique);
  928. *bp++ = htonl(n_namesz);
  929. memcpy(bp, new_name, n_namesz);
  930. bp = (void *) bp + n_namesz;
  931. if (n_padsz > 0) {
  932. memset(bp, 0, n_padsz);
  933. bp = (void *) bp + n_padsz;
  934. }
  935. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  936. }
  937. /*
  938. * deliver reply data to an FS.StoreData
  939. */
  940. static int afs_deliver_fs_store_data(struct afs_call *call,
  941. struct sk_buff *skb, bool last)
  942. {
  943. struct afs_vnode *vnode = call->reply;
  944. const __be32 *bp;
  945. _enter(",,%u", last);
  946. afs_transfer_reply(call, skb);
  947. if (!last) {
  948. _leave(" = 0 [more]");
  949. return 0;
  950. }
  951. if (call->reply_size != call->reply_max) {
  952. _leave(" = -EBADMSG [%u != %u]",
  953. call->reply_size, call->reply_max);
  954. return -EBADMSG;
  955. }
  956. /* unmarshall the reply once we've received all of it */
  957. bp = call->buffer;
  958. xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode,
  959. &call->store_version);
  960. /* xdr_decode_AFSVolSync(&bp, call->replyX); */
  961. afs_pages_written_back(vnode, call);
  962. _leave(" = 0 [done]");
  963. return 0;
  964. }
  965. /*
  966. * FS.StoreData operation type
  967. */
  968. static const struct afs_call_type afs_RXFSStoreData = {
  969. .name = "FS.StoreData",
  970. .deliver = afs_deliver_fs_store_data,
  971. .abort_to_error = afs_abort_to_error,
  972. .destructor = afs_flat_call_destructor,
  973. };
  974. static const struct afs_call_type afs_RXFSStoreData64 = {
  975. .name = "FS.StoreData64",
  976. .deliver = afs_deliver_fs_store_data,
  977. .abort_to_error = afs_abort_to_error,
  978. .destructor = afs_flat_call_destructor,
  979. };
  980. /*
  981. * store a set of pages to a very large file
  982. */
  983. static int afs_fs_store_data64(struct afs_server *server,
  984. struct afs_writeback *wb,
  985. pgoff_t first, pgoff_t last,
  986. unsigned offset, unsigned to,
  987. loff_t size, loff_t pos, loff_t i_size,
  988. const struct afs_wait_mode *wait_mode)
  989. {
  990. struct afs_vnode *vnode = wb->vnode;
  991. struct afs_call *call;
  992. __be32 *bp;
  993. _enter(",%x,{%x:%u},,",
  994. key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode);
  995. call = afs_alloc_flat_call(&afs_RXFSStoreData64,
  996. (4 + 6 + 3 * 2) * 4,
  997. (21 + 6) * 4);
  998. if (!call)
  999. return -ENOMEM;
  1000. call->wb = wb;
  1001. call->key = wb->key;
  1002. call->reply = vnode;
  1003. call->service_id = FS_SERVICE;
  1004. call->port = htons(AFS_FS_PORT);
  1005. call->mapping = vnode->vfs_inode.i_mapping;
  1006. call->first = first;
  1007. call->last = last;
  1008. call->first_offset = offset;
  1009. call->last_to = to;
  1010. call->send_pages = true;
  1011. call->store_version = vnode->status.data_version + 1;
  1012. /* marshall the parameters */
  1013. bp = call->request;
  1014. *bp++ = htonl(FSSTOREDATA64);
  1015. *bp++ = htonl(vnode->fid.vid);
  1016. *bp++ = htonl(vnode->fid.vnode);
  1017. *bp++ = htonl(vnode->fid.unique);
  1018. *bp++ = htonl(AFS_SET_MTIME); /* mask */
  1019. *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
  1020. *bp++ = 0; /* owner */
  1021. *bp++ = 0; /* group */
  1022. *bp++ = 0; /* unix mode */
  1023. *bp++ = 0; /* segment size */
  1024. *bp++ = htonl(pos >> 32);
  1025. *bp++ = htonl((u32) pos);
  1026. *bp++ = htonl(size >> 32);
  1027. *bp++ = htonl((u32) size);
  1028. *bp++ = htonl(i_size >> 32);
  1029. *bp++ = htonl((u32) i_size);
  1030. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  1031. }
  1032. /*
  1033. * store a set of pages
  1034. */
  1035. int afs_fs_store_data(struct afs_server *server, struct afs_writeback *wb,
  1036. pgoff_t first, pgoff_t last,
  1037. unsigned offset, unsigned to,
  1038. const struct afs_wait_mode *wait_mode)
  1039. {
  1040. struct afs_vnode *vnode = wb->vnode;
  1041. struct afs_call *call;
  1042. loff_t size, pos, i_size;
  1043. __be32 *bp;
  1044. _enter(",%x,{%x:%u},,",
  1045. key_serial(wb->key), vnode->fid.vid, vnode->fid.vnode);
  1046. size = (loff_t)to - (loff_t)offset;
  1047. if (first != last)
  1048. size += (loff_t)(last - first) << PAGE_SHIFT;
  1049. pos = (loff_t)first << PAGE_SHIFT;
  1050. pos += offset;
  1051. i_size = i_size_read(&vnode->vfs_inode);
  1052. if (pos + size > i_size)
  1053. i_size = size + pos;
  1054. _debug("size %llx, at %llx, i_size %llx",
  1055. (unsigned long long) size, (unsigned long long) pos,
  1056. (unsigned long long) i_size);
  1057. if (pos >> 32 || i_size >> 32 || size >> 32 || (pos + size) >> 32)
  1058. return afs_fs_store_data64(server, wb, first, last, offset, to,
  1059. size, pos, i_size, wait_mode);
  1060. call = afs_alloc_flat_call(&afs_RXFSStoreData,
  1061. (4 + 6 + 3) * 4,
  1062. (21 + 6) * 4);
  1063. if (!call)
  1064. return -ENOMEM;
  1065. call->wb = wb;
  1066. call->key = wb->key;
  1067. call->reply = vnode;
  1068. call->service_id = FS_SERVICE;
  1069. call->port = htons(AFS_FS_PORT);
  1070. call->mapping = vnode->vfs_inode.i_mapping;
  1071. call->first = first;
  1072. call->last = last;
  1073. call->first_offset = offset;
  1074. call->last_to = to;
  1075. call->send_pages = true;
  1076. call->store_version = vnode->status.data_version + 1;
  1077. /* marshall the parameters */
  1078. bp = call->request;
  1079. *bp++ = htonl(FSSTOREDATA);
  1080. *bp++ = htonl(vnode->fid.vid);
  1081. *bp++ = htonl(vnode->fid.vnode);
  1082. *bp++ = htonl(vnode->fid.unique);
  1083. *bp++ = htonl(AFS_SET_MTIME); /* mask */
  1084. *bp++ = htonl(vnode->vfs_inode.i_mtime.tv_sec); /* mtime */
  1085. *bp++ = 0; /* owner */
  1086. *bp++ = 0; /* group */
  1087. *bp++ = 0; /* unix mode */
  1088. *bp++ = 0; /* segment size */
  1089. *bp++ = htonl(pos);
  1090. *bp++ = htonl(size);
  1091. *bp++ = htonl(i_size);
  1092. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  1093. }
  1094. /*
  1095. * deliver reply data to an FS.StoreStatus
  1096. */
  1097. static int afs_deliver_fs_store_status(struct afs_call *call,
  1098. struct sk_buff *skb, bool last)
  1099. {
  1100. afs_dataversion_t *store_version;
  1101. struct afs_vnode *vnode = call->reply;
  1102. const __be32 *bp;
  1103. _enter(",,%u", last);
  1104. afs_transfer_reply(call, skb);
  1105. if (!last) {
  1106. _leave(" = 0 [more]");
  1107. return 0;
  1108. }
  1109. if (call->reply_size != call->reply_max) {
  1110. _leave(" = -EBADMSG [%u != %u]",
  1111. call->reply_size, call->reply_max);
  1112. return -EBADMSG;
  1113. }
  1114. /* unmarshall the reply once we've received all of it */
  1115. store_version = NULL;
  1116. if (call->operation_ID == FSSTOREDATA)
  1117. store_version = &call->store_version;
  1118. bp = call->buffer;
  1119. xdr_decode_AFSFetchStatus(&bp, &vnode->status, vnode, store_version);
  1120. /* xdr_decode_AFSVolSync(&bp, call->replyX); */
  1121. _leave(" = 0 [done]");
  1122. return 0;
  1123. }
  1124. /*
  1125. * FS.StoreStatus operation type
  1126. */
  1127. static const struct afs_call_type afs_RXFSStoreStatus = {
  1128. .name = "FS.StoreStatus",
  1129. .deliver = afs_deliver_fs_store_status,
  1130. .abort_to_error = afs_abort_to_error,
  1131. .destructor = afs_flat_call_destructor,
  1132. };
  1133. static const struct afs_call_type afs_RXFSStoreData_as_Status = {
  1134. .name = "FS.StoreData",
  1135. .deliver = afs_deliver_fs_store_status,
  1136. .abort_to_error = afs_abort_to_error,
  1137. .destructor = afs_flat_call_destructor,
  1138. };
  1139. static const struct afs_call_type afs_RXFSStoreData64_as_Status = {
  1140. .name = "FS.StoreData64",
  1141. .deliver = afs_deliver_fs_store_status,
  1142. .abort_to_error = afs_abort_to_error,
  1143. .destructor = afs_flat_call_destructor,
  1144. };
  1145. /*
  1146. * set the attributes on a very large file, using FS.StoreData rather than
  1147. * FS.StoreStatus so as to alter the file size also
  1148. */
  1149. static int afs_fs_setattr_size64(struct afs_server *server, struct key *key,
  1150. struct afs_vnode *vnode, struct iattr *attr,
  1151. const struct afs_wait_mode *wait_mode)
  1152. {
  1153. struct afs_call *call;
  1154. __be32 *bp;
  1155. _enter(",%x,{%x:%u},,",
  1156. key_serial(key), vnode->fid.vid, vnode->fid.vnode);
  1157. ASSERT(attr->ia_valid & ATTR_SIZE);
  1158. call = afs_alloc_flat_call(&afs_RXFSStoreData64_as_Status,
  1159. (4 + 6 + 3 * 2) * 4,
  1160. (21 + 6) * 4);
  1161. if (!call)
  1162. return -ENOMEM;
  1163. call->key = key;
  1164. call->reply = vnode;
  1165. call->service_id = FS_SERVICE;
  1166. call->port = htons(AFS_FS_PORT);
  1167. call->store_version = vnode->status.data_version + 1;
  1168. call->operation_ID = FSSTOREDATA;
  1169. /* marshall the parameters */
  1170. bp = call->request;
  1171. *bp++ = htonl(FSSTOREDATA64);
  1172. *bp++ = htonl(vnode->fid.vid);
  1173. *bp++ = htonl(vnode->fid.vnode);
  1174. *bp++ = htonl(vnode->fid.unique);
  1175. xdr_encode_AFS_StoreStatus(&bp, attr);
  1176. *bp++ = 0; /* position of start of write */
  1177. *bp++ = 0;
  1178. *bp++ = 0; /* size of write */
  1179. *bp++ = 0;
  1180. *bp++ = htonl(attr->ia_size >> 32); /* new file length */
  1181. *bp++ = htonl((u32) attr->ia_size);
  1182. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  1183. }
  1184. /*
  1185. * set the attributes on a file, using FS.StoreData rather than FS.StoreStatus
  1186. * so as to alter the file size also
  1187. */
  1188. static int afs_fs_setattr_size(struct afs_server *server, struct key *key,
  1189. struct afs_vnode *vnode, struct iattr *attr,
  1190. const struct afs_wait_mode *wait_mode)
  1191. {
  1192. struct afs_call *call;
  1193. __be32 *bp;
  1194. _enter(",%x,{%x:%u},,",
  1195. key_serial(key), vnode->fid.vid, vnode->fid.vnode);
  1196. ASSERT(attr->ia_valid & ATTR_SIZE);
  1197. if (attr->ia_size >> 32)
  1198. return afs_fs_setattr_size64(server, key, vnode, attr,
  1199. wait_mode);
  1200. call = afs_alloc_flat_call(&afs_RXFSStoreData_as_Status,
  1201. (4 + 6 + 3) * 4,
  1202. (21 + 6) * 4);
  1203. if (!call)
  1204. return -ENOMEM;
  1205. call->key = key;
  1206. call->reply = vnode;
  1207. call->service_id = FS_SERVICE;
  1208. call->port = htons(AFS_FS_PORT);
  1209. call->store_version = vnode->status.data_version + 1;
  1210. call->operation_ID = FSSTOREDATA;
  1211. /* marshall the parameters */
  1212. bp = call->request;
  1213. *bp++ = htonl(FSSTOREDATA);
  1214. *bp++ = htonl(vnode->fid.vid);
  1215. *bp++ = htonl(vnode->fid.vnode);
  1216. *bp++ = htonl(vnode->fid.unique);
  1217. xdr_encode_AFS_StoreStatus(&bp, attr);
  1218. *bp++ = 0; /* position of start of write */
  1219. *bp++ = 0; /* size of write */
  1220. *bp++ = htonl(attr->ia_size); /* new file length */
  1221. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  1222. }
  1223. /*
  1224. * set the attributes on a file, using FS.StoreData if there's a change in file
  1225. * size, and FS.StoreStatus otherwise
  1226. */
  1227. int afs_fs_setattr(struct afs_server *server, struct key *key,
  1228. struct afs_vnode *vnode, struct iattr *attr,
  1229. const struct afs_wait_mode *wait_mode)
  1230. {
  1231. struct afs_call *call;
  1232. __be32 *bp;
  1233. if (attr->ia_valid & ATTR_SIZE)
  1234. return afs_fs_setattr_size(server, key, vnode, attr,
  1235. wait_mode);
  1236. _enter(",%x,{%x:%u},,",
  1237. key_serial(key), vnode->fid.vid, vnode->fid.vnode);
  1238. call = afs_alloc_flat_call(&afs_RXFSStoreStatus,
  1239. (4 + 6) * 4,
  1240. (21 + 6) * 4);
  1241. if (!call)
  1242. return -ENOMEM;
  1243. call->key = key;
  1244. call->reply = vnode;
  1245. call->service_id = FS_SERVICE;
  1246. call->port = htons(AFS_FS_PORT);
  1247. call->operation_ID = FSSTORESTATUS;
  1248. /* marshall the parameters */
  1249. bp = call->request;
  1250. *bp++ = htonl(FSSTORESTATUS);
  1251. *bp++ = htonl(vnode->fid.vid);
  1252. *bp++ = htonl(vnode->fid.vnode);
  1253. *bp++ = htonl(vnode->fid.unique);
  1254. xdr_encode_AFS_StoreStatus(&bp, attr);
  1255. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  1256. }
  1257. /*
  1258. * deliver reply data to an FS.GetVolumeStatus
  1259. */
  1260. static int afs_deliver_fs_get_volume_status(struct afs_call *call,
  1261. struct sk_buff *skb, bool last)
  1262. {
  1263. const __be32 *bp;
  1264. char *p;
  1265. int ret;
  1266. _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
  1267. switch (call->unmarshall) {
  1268. case 0:
  1269. call->offset = 0;
  1270. call->unmarshall++;
  1271. /* extract the returned status record */
  1272. case 1:
  1273. _debug("extract status");
  1274. ret = afs_extract_data(call, skb, last, call->buffer,
  1275. 12 * 4);
  1276. switch (ret) {
  1277. case 0: break;
  1278. case -EAGAIN: return 0;
  1279. default: return ret;
  1280. }
  1281. bp = call->buffer;
  1282. xdr_decode_AFSFetchVolumeStatus(&bp, call->reply2);
  1283. call->offset = 0;
  1284. call->unmarshall++;
  1285. /* extract the volume name length */
  1286. case 2:
  1287. ret = afs_extract_data(call, skb, last, &call->tmp, 4);
  1288. switch (ret) {
  1289. case 0: break;
  1290. case -EAGAIN: return 0;
  1291. default: return ret;
  1292. }
  1293. call->count = ntohl(call->tmp);
  1294. _debug("volname length: %u", call->count);
  1295. if (call->count >= AFSNAMEMAX)
  1296. return -EBADMSG;
  1297. call->offset = 0;
  1298. call->unmarshall++;
  1299. /* extract the volume name */
  1300. case 3:
  1301. _debug("extract volname");
  1302. if (call->count > 0) {
  1303. ret = afs_extract_data(call, skb, last, call->reply3,
  1304. call->count);
  1305. switch (ret) {
  1306. case 0: break;
  1307. case -EAGAIN: return 0;
  1308. default: return ret;
  1309. }
  1310. }
  1311. p = call->reply3;
  1312. p[call->count] = 0;
  1313. _debug("volname '%s'", p);
  1314. call->offset = 0;
  1315. call->unmarshall++;
  1316. /* extract the volume name padding */
  1317. if ((call->count & 3) == 0) {
  1318. call->unmarshall++;
  1319. goto no_volname_padding;
  1320. }
  1321. call->count = 4 - (call->count & 3);
  1322. case 4:
  1323. ret = afs_extract_data(call, skb, last, call->buffer,
  1324. call->count);
  1325. switch (ret) {
  1326. case 0: break;
  1327. case -EAGAIN: return 0;
  1328. default: return ret;
  1329. }
  1330. call->offset = 0;
  1331. call->unmarshall++;
  1332. no_volname_padding:
  1333. /* extract the offline message length */
  1334. case 5:
  1335. ret = afs_extract_data(call, skb, last, &call->tmp, 4);
  1336. switch (ret) {
  1337. case 0: break;
  1338. case -EAGAIN: return 0;
  1339. default: return ret;
  1340. }
  1341. call->count = ntohl(call->tmp);
  1342. _debug("offline msg length: %u", call->count);
  1343. if (call->count >= AFSNAMEMAX)
  1344. return -EBADMSG;
  1345. call->offset = 0;
  1346. call->unmarshall++;
  1347. /* extract the offline message */
  1348. case 6:
  1349. _debug("extract offline");
  1350. if (call->count > 0) {
  1351. ret = afs_extract_data(call, skb, last, call->reply3,
  1352. call->count);
  1353. switch (ret) {
  1354. case 0: break;
  1355. case -EAGAIN: return 0;
  1356. default: return ret;
  1357. }
  1358. }
  1359. p = call->reply3;
  1360. p[call->count] = 0;
  1361. _debug("offline '%s'", p);
  1362. call->offset = 0;
  1363. call->unmarshall++;
  1364. /* extract the offline message padding */
  1365. if ((call->count & 3) == 0) {
  1366. call->unmarshall++;
  1367. goto no_offline_padding;
  1368. }
  1369. call->count = 4 - (call->count & 3);
  1370. case 7:
  1371. ret = afs_extract_data(call, skb, last, call->buffer,
  1372. call->count);
  1373. switch (ret) {
  1374. case 0: break;
  1375. case -EAGAIN: return 0;
  1376. default: return ret;
  1377. }
  1378. call->offset = 0;
  1379. call->unmarshall++;
  1380. no_offline_padding:
  1381. /* extract the message of the day length */
  1382. case 8:
  1383. ret = afs_extract_data(call, skb, last, &call->tmp, 4);
  1384. switch (ret) {
  1385. case 0: break;
  1386. case -EAGAIN: return 0;
  1387. default: return ret;
  1388. }
  1389. call->count = ntohl(call->tmp);
  1390. _debug("motd length: %u", call->count);
  1391. if (call->count >= AFSNAMEMAX)
  1392. return -EBADMSG;
  1393. call->offset = 0;
  1394. call->unmarshall++;
  1395. /* extract the message of the day */
  1396. case 9:
  1397. _debug("extract motd");
  1398. if (call->count > 0) {
  1399. ret = afs_extract_data(call, skb, last, call->reply3,
  1400. call->count);
  1401. switch (ret) {
  1402. case 0: break;
  1403. case -EAGAIN: return 0;
  1404. default: return ret;
  1405. }
  1406. }
  1407. p = call->reply3;
  1408. p[call->count] = 0;
  1409. _debug("motd '%s'", p);
  1410. call->offset = 0;
  1411. call->unmarshall++;
  1412. /* extract the message of the day padding */
  1413. if ((call->count & 3) == 0) {
  1414. call->unmarshall++;
  1415. goto no_motd_padding;
  1416. }
  1417. call->count = 4 - (call->count & 3);
  1418. case 10:
  1419. ret = afs_extract_data(call, skb, last, call->buffer,
  1420. call->count);
  1421. switch (ret) {
  1422. case 0: break;
  1423. case -EAGAIN: return 0;
  1424. default: return ret;
  1425. }
  1426. call->offset = 0;
  1427. call->unmarshall++;
  1428. no_motd_padding:
  1429. case 11:
  1430. _debug("trailer %d", skb->len);
  1431. if (skb->len != 0)
  1432. return -EBADMSG;
  1433. break;
  1434. }
  1435. if (!last)
  1436. return 0;
  1437. _leave(" = 0 [done]");
  1438. return 0;
  1439. }
  1440. /*
  1441. * destroy an FS.GetVolumeStatus call
  1442. */
  1443. static void afs_get_volume_status_call_destructor(struct afs_call *call)
  1444. {
  1445. kfree(call->reply3);
  1446. call->reply3 = NULL;
  1447. afs_flat_call_destructor(call);
  1448. }
  1449. /*
  1450. * FS.GetVolumeStatus operation type
  1451. */
  1452. static const struct afs_call_type afs_RXFSGetVolumeStatus = {
  1453. .name = "FS.GetVolumeStatus",
  1454. .deliver = afs_deliver_fs_get_volume_status,
  1455. .abort_to_error = afs_abort_to_error,
  1456. .destructor = afs_get_volume_status_call_destructor,
  1457. };
  1458. /*
  1459. * fetch the status of a volume
  1460. */
  1461. int afs_fs_get_volume_status(struct afs_server *server,
  1462. struct key *key,
  1463. struct afs_vnode *vnode,
  1464. struct afs_volume_status *vs,
  1465. const struct afs_wait_mode *wait_mode)
  1466. {
  1467. struct afs_call *call;
  1468. __be32 *bp;
  1469. void *tmpbuf;
  1470. _enter("");
  1471. tmpbuf = kmalloc(AFSOPAQUEMAX, GFP_KERNEL);
  1472. if (!tmpbuf)
  1473. return -ENOMEM;
  1474. call = afs_alloc_flat_call(&afs_RXFSGetVolumeStatus, 2 * 4, 12 * 4);
  1475. if (!call) {
  1476. kfree(tmpbuf);
  1477. return -ENOMEM;
  1478. }
  1479. call->key = key;
  1480. call->reply = vnode;
  1481. call->reply2 = vs;
  1482. call->reply3 = tmpbuf;
  1483. call->service_id = FS_SERVICE;
  1484. call->port = htons(AFS_FS_PORT);
  1485. /* marshall the parameters */
  1486. bp = call->request;
  1487. bp[0] = htonl(FSGETVOLUMESTATUS);
  1488. bp[1] = htonl(vnode->fid.vid);
  1489. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  1490. }
  1491. /*
  1492. * deliver reply data to an FS.SetLock, FS.ExtendLock or FS.ReleaseLock
  1493. */
  1494. static int afs_deliver_fs_xxxx_lock(struct afs_call *call,
  1495. struct sk_buff *skb, bool last)
  1496. {
  1497. const __be32 *bp;
  1498. _enter("{%u},{%u},%d", call->unmarshall, skb->len, last);
  1499. afs_transfer_reply(call, skb);
  1500. if (!last)
  1501. return 0;
  1502. if (call->reply_size != call->reply_max)
  1503. return -EBADMSG;
  1504. /* unmarshall the reply once we've received all of it */
  1505. bp = call->buffer;
  1506. /* xdr_decode_AFSVolSync(&bp, call->replyX); */
  1507. _leave(" = 0 [done]");
  1508. return 0;
  1509. }
  1510. /*
  1511. * FS.SetLock operation type
  1512. */
  1513. static const struct afs_call_type afs_RXFSSetLock = {
  1514. .name = "FS.SetLock",
  1515. .deliver = afs_deliver_fs_xxxx_lock,
  1516. .abort_to_error = afs_abort_to_error,
  1517. .destructor = afs_flat_call_destructor,
  1518. };
  1519. /*
  1520. * FS.ExtendLock operation type
  1521. */
  1522. static const struct afs_call_type afs_RXFSExtendLock = {
  1523. .name = "FS.ExtendLock",
  1524. .deliver = afs_deliver_fs_xxxx_lock,
  1525. .abort_to_error = afs_abort_to_error,
  1526. .destructor = afs_flat_call_destructor,
  1527. };
  1528. /*
  1529. * FS.ReleaseLock operation type
  1530. */
  1531. static const struct afs_call_type afs_RXFSReleaseLock = {
  1532. .name = "FS.ReleaseLock",
  1533. .deliver = afs_deliver_fs_xxxx_lock,
  1534. .abort_to_error = afs_abort_to_error,
  1535. .destructor = afs_flat_call_destructor,
  1536. };
  1537. /*
  1538. * get a lock on a file
  1539. */
  1540. int afs_fs_set_lock(struct afs_server *server,
  1541. struct key *key,
  1542. struct afs_vnode *vnode,
  1543. afs_lock_type_t type,
  1544. const struct afs_wait_mode *wait_mode)
  1545. {
  1546. struct afs_call *call;
  1547. __be32 *bp;
  1548. _enter("");
  1549. call = afs_alloc_flat_call(&afs_RXFSSetLock, 5 * 4, 6 * 4);
  1550. if (!call)
  1551. return -ENOMEM;
  1552. call->key = key;
  1553. call->reply = vnode;
  1554. call->service_id = FS_SERVICE;
  1555. call->port = htons(AFS_FS_PORT);
  1556. /* marshall the parameters */
  1557. bp = call->request;
  1558. *bp++ = htonl(FSSETLOCK);
  1559. *bp++ = htonl(vnode->fid.vid);
  1560. *bp++ = htonl(vnode->fid.vnode);
  1561. *bp++ = htonl(vnode->fid.unique);
  1562. *bp++ = htonl(type);
  1563. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  1564. }
  1565. /*
  1566. * extend a lock on a file
  1567. */
  1568. int afs_fs_extend_lock(struct afs_server *server,
  1569. struct key *key,
  1570. struct afs_vnode *vnode,
  1571. const struct afs_wait_mode *wait_mode)
  1572. {
  1573. struct afs_call *call;
  1574. __be32 *bp;
  1575. _enter("");
  1576. call = afs_alloc_flat_call(&afs_RXFSExtendLock, 4 * 4, 6 * 4);
  1577. if (!call)
  1578. return -ENOMEM;
  1579. call->key = key;
  1580. call->reply = vnode;
  1581. call->service_id = FS_SERVICE;
  1582. call->port = htons(AFS_FS_PORT);
  1583. /* marshall the parameters */
  1584. bp = call->request;
  1585. *bp++ = htonl(FSEXTENDLOCK);
  1586. *bp++ = htonl(vnode->fid.vid);
  1587. *bp++ = htonl(vnode->fid.vnode);
  1588. *bp++ = htonl(vnode->fid.unique);
  1589. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  1590. }
  1591. /*
  1592. * release a lock on a file
  1593. */
  1594. int afs_fs_release_lock(struct afs_server *server,
  1595. struct key *key,
  1596. struct afs_vnode *vnode,
  1597. const struct afs_wait_mode *wait_mode)
  1598. {
  1599. struct afs_call *call;
  1600. __be32 *bp;
  1601. _enter("");
  1602. call = afs_alloc_flat_call(&afs_RXFSReleaseLock, 4 * 4, 6 * 4);
  1603. if (!call)
  1604. return -ENOMEM;
  1605. call->key = key;
  1606. call->reply = vnode;
  1607. call->service_id = FS_SERVICE;
  1608. call->port = htons(AFS_FS_PORT);
  1609. /* marshall the parameters */
  1610. bp = call->request;
  1611. *bp++ = htonl(FSRELEASELOCK);
  1612. *bp++ = htonl(vnode->fid.vid);
  1613. *bp++ = htonl(vnode->fid.vnode);
  1614. *bp++ = htonl(vnode->fid.unique);
  1615. return afs_make_call(&server->addr, call, GFP_NOFS, wait_mode);
  1616. }