fsclient.c 42 KB

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