fsclient.c 56 KB

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