yfsclient.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* YFS File Server client stubs
  3. *
  4. * Copyright (C) 2018 Red Hat, Inc. All Rights Reserved.
  5. * Written by David Howells (dhowells@redhat.com)
  6. */
  7. #include <linux/init.h>
  8. #include <linux/slab.h>
  9. #include <linux/sched.h>
  10. #include <linux/circ_buf.h>
  11. #include <linux/iversion.h>
  12. #include "internal.h"
  13. #include "afs_fs.h"
  14. #include "xdr_fs.h"
  15. #include "protocol_yfs.h"
  16. #define xdr_size(x) (sizeof(*x) / sizeof(__be32))
  17. static void xdr_decode_YFSFid(const __be32 **_bp, struct afs_fid *fid)
  18. {
  19. const struct yfs_xdr_YFSFid *x = (const void *)*_bp;
  20. fid->vid = xdr_to_u64(x->volume);
  21. fid->vnode = xdr_to_u64(x->vnode.lo);
  22. fid->vnode_hi = ntohl(x->vnode.hi);
  23. fid->unique = ntohl(x->vnode.unique);
  24. *_bp += xdr_size(x);
  25. }
  26. static __be32 *xdr_encode_u32(__be32 *bp, u32 n)
  27. {
  28. *bp++ = htonl(n);
  29. return bp;
  30. }
  31. static __be32 *xdr_encode_u64(__be32 *bp, u64 n)
  32. {
  33. struct yfs_xdr_u64 *x = (void *)bp;
  34. *x = u64_to_xdr(n);
  35. return bp + xdr_size(x);
  36. }
  37. static __be32 *xdr_encode_YFSFid(__be32 *bp, struct afs_fid *fid)
  38. {
  39. struct yfs_xdr_YFSFid *x = (void *)bp;
  40. x->volume = u64_to_xdr(fid->vid);
  41. x->vnode.lo = u64_to_xdr(fid->vnode);
  42. x->vnode.hi = htonl(fid->vnode_hi);
  43. x->vnode.unique = htonl(fid->unique);
  44. return bp + xdr_size(x);
  45. }
  46. static size_t xdr_strlen(unsigned int len)
  47. {
  48. return sizeof(__be32) + round_up(len, sizeof(__be32));
  49. }
  50. static __be32 *xdr_encode_string(__be32 *bp, const char *p, unsigned int len)
  51. {
  52. bp = xdr_encode_u32(bp, len);
  53. bp = memcpy(bp, p, len);
  54. if (len & 3) {
  55. unsigned int pad = 4 - (len & 3);
  56. memset((u8 *)bp + len, 0, pad);
  57. len += pad;
  58. }
  59. return bp + len / sizeof(__be32);
  60. }
  61. static __be32 *xdr_encode_name(__be32 *bp, const struct qstr *p)
  62. {
  63. return xdr_encode_string(bp, p->name, p->len);
  64. }
  65. static s64 linux_to_yfs_time(const struct timespec64 *t)
  66. {
  67. /* Convert to 100ns intervals. */
  68. return (u64)t->tv_sec * 10000000 + t->tv_nsec/100;
  69. }
  70. static __be32 *xdr_encode_YFSStoreStatus(__be32 *bp, mode_t *mode,
  71. const struct timespec64 *t)
  72. {
  73. struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
  74. mode_t masked_mode = mode ? *mode & S_IALLUGO : 0;
  75. s64 mtime = linux_to_yfs_time(t);
  76. u32 mask = AFS_SET_MTIME;
  77. mask |= mode ? AFS_SET_MODE : 0;
  78. x->mask = htonl(mask);
  79. x->mode = htonl(masked_mode);
  80. x->mtime_client = u64_to_xdr(mtime);
  81. x->owner = u64_to_xdr(0);
  82. x->group = u64_to_xdr(0);
  83. return bp + xdr_size(x);
  84. }
  85. /*
  86. * Convert a signed 100ns-resolution 64-bit time into a timespec.
  87. */
  88. static struct timespec64 yfs_time_to_linux(s64 t)
  89. {
  90. struct timespec64 ts;
  91. u64 abs_t;
  92. /*
  93. * Unfortunately can not use normal 64 bit division on 32 bit arch, but
  94. * the alternative, do_div, does not work with negative numbers so have
  95. * to special case them
  96. */
  97. if (t < 0) {
  98. abs_t = -t;
  99. ts.tv_nsec = (time64_t)(do_div(abs_t, 10000000) * 100);
  100. ts.tv_nsec = -ts.tv_nsec;
  101. ts.tv_sec = -abs_t;
  102. } else {
  103. abs_t = t;
  104. ts.tv_nsec = (time64_t)do_div(abs_t, 10000000) * 100;
  105. ts.tv_sec = abs_t;
  106. }
  107. return ts;
  108. }
  109. static struct timespec64 xdr_to_time(const struct yfs_xdr_u64 xdr)
  110. {
  111. s64 t = xdr_to_u64(xdr);
  112. return yfs_time_to_linux(t);
  113. }
  114. static void yfs_check_req(struct afs_call *call, __be32 *bp)
  115. {
  116. size_t len = (void *)bp - call->request;
  117. if (len > call->request_size)
  118. pr_err("kAFS: %s: Request buffer overflow (%zu>%u)\n",
  119. call->type->name, len, call->request_size);
  120. else if (len < call->request_size)
  121. pr_warn("kAFS: %s: Request buffer underflow (%zu<%u)\n",
  122. call->type->name, len, call->request_size);
  123. }
  124. /*
  125. * Dump a bad file status record.
  126. */
  127. static void xdr_dump_bad(const __be32 *bp)
  128. {
  129. __be32 x[4];
  130. int i;
  131. pr_notice("YFS XDR: Bad status record\n");
  132. for (i = 0; i < 6 * 4 * 4; i += 16) {
  133. memcpy(x, bp, 16);
  134. bp += 4;
  135. pr_notice("%03x: %08x %08x %08x %08x\n",
  136. i, ntohl(x[0]), ntohl(x[1]), ntohl(x[2]), ntohl(x[3]));
  137. }
  138. memcpy(x, bp, 8);
  139. pr_notice("0x60: %08x %08x\n", ntohl(x[0]), ntohl(x[1]));
  140. }
  141. /*
  142. * Decode a YFSFetchStatus block
  143. */
  144. static void xdr_decode_YFSFetchStatus(const __be32 **_bp,
  145. struct afs_call *call,
  146. struct afs_status_cb *scb)
  147. {
  148. const struct yfs_xdr_YFSFetchStatus *xdr = (const void *)*_bp;
  149. struct afs_file_status *status = &scb->status;
  150. u32 type;
  151. status->abort_code = ntohl(xdr->abort_code);
  152. if (status->abort_code != 0) {
  153. if (status->abort_code == VNOVNODE)
  154. status->nlink = 0;
  155. scb->have_error = true;
  156. goto advance;
  157. }
  158. type = ntohl(xdr->type);
  159. switch (type) {
  160. case AFS_FTYPE_FILE:
  161. case AFS_FTYPE_DIR:
  162. case AFS_FTYPE_SYMLINK:
  163. status->type = type;
  164. break;
  165. default:
  166. goto bad;
  167. }
  168. status->nlink = ntohl(xdr->nlink);
  169. status->author = xdr_to_u64(xdr->author);
  170. status->owner = xdr_to_u64(xdr->owner);
  171. status->caller_access = ntohl(xdr->caller_access); /* Ticket dependent */
  172. status->anon_access = ntohl(xdr->anon_access);
  173. status->mode = ntohl(xdr->mode) & S_IALLUGO;
  174. status->group = xdr_to_u64(xdr->group);
  175. status->lock_count = ntohl(xdr->lock_count);
  176. status->mtime_client = xdr_to_time(xdr->mtime_client);
  177. status->mtime_server = xdr_to_time(xdr->mtime_server);
  178. status->size = xdr_to_u64(xdr->size);
  179. status->data_version = xdr_to_u64(xdr->data_version);
  180. scb->have_status = true;
  181. advance:
  182. *_bp += xdr_size(xdr);
  183. return;
  184. bad:
  185. xdr_dump_bad(*_bp);
  186. afs_protocol_error(call, afs_eproto_bad_status);
  187. goto advance;
  188. }
  189. /*
  190. * Decode a YFSCallBack block
  191. */
  192. static void xdr_decode_YFSCallBack(const __be32 **_bp,
  193. struct afs_call *call,
  194. struct afs_status_cb *scb)
  195. {
  196. struct yfs_xdr_YFSCallBack *x = (void *)*_bp;
  197. struct afs_callback *cb = &scb->callback;
  198. ktime_t cb_expiry;
  199. cb_expiry = ktime_add(call->issue_time, xdr_to_u64(x->expiration_time) * 100);
  200. cb->expires_at = ktime_divns(cb_expiry, NSEC_PER_SEC);
  201. scb->have_cb = true;
  202. *_bp += xdr_size(x);
  203. }
  204. /*
  205. * Decode a YFSVolSync block
  206. */
  207. static void xdr_decode_YFSVolSync(const __be32 **_bp,
  208. struct afs_volsync *volsync)
  209. {
  210. struct yfs_xdr_YFSVolSync *x = (void *)*_bp;
  211. u64 creation, update;
  212. if (volsync) {
  213. creation = xdr_to_u64(x->vol_creation_date);
  214. do_div(creation, 10 * 1000 * 1000);
  215. volsync->creation = creation;
  216. update = xdr_to_u64(x->vol_update_date);
  217. do_div(update, 10 * 1000 * 1000);
  218. volsync->update = update;
  219. }
  220. *_bp += xdr_size(x);
  221. }
  222. /*
  223. * Encode the requested attributes into a YFSStoreStatus block
  224. */
  225. static __be32 *xdr_encode_YFS_StoreStatus(__be32 *bp, struct iattr *attr)
  226. {
  227. struct yfs_xdr_YFSStoreStatus *x = (void *)bp;
  228. s64 mtime = 0, owner = 0, group = 0;
  229. u32 mask = 0, mode = 0;
  230. mask = 0;
  231. if (attr->ia_valid & ATTR_MTIME) {
  232. mask |= AFS_SET_MTIME;
  233. mtime = linux_to_yfs_time(&attr->ia_mtime);
  234. }
  235. if (attr->ia_valid & ATTR_UID) {
  236. mask |= AFS_SET_OWNER;
  237. owner = from_kuid(&init_user_ns, attr->ia_uid);
  238. }
  239. if (attr->ia_valid & ATTR_GID) {
  240. mask |= AFS_SET_GROUP;
  241. group = from_kgid(&init_user_ns, attr->ia_gid);
  242. }
  243. if (attr->ia_valid & ATTR_MODE) {
  244. mask |= AFS_SET_MODE;
  245. mode = attr->ia_mode & S_IALLUGO;
  246. }
  247. x->mask = htonl(mask);
  248. x->mode = htonl(mode);
  249. x->mtime_client = u64_to_xdr(mtime);
  250. x->owner = u64_to_xdr(owner);
  251. x->group = u64_to_xdr(group);
  252. return bp + xdr_size(x);
  253. }
  254. /*
  255. * Decode a YFSFetchVolumeStatus block.
  256. */
  257. static void xdr_decode_YFSFetchVolumeStatus(const __be32 **_bp,
  258. struct afs_volume_status *vs)
  259. {
  260. const struct yfs_xdr_YFSFetchVolumeStatus *x = (const void *)*_bp;
  261. u32 flags;
  262. vs->vid = xdr_to_u64(x->vid);
  263. vs->parent_id = xdr_to_u64(x->parent_id);
  264. flags = ntohl(x->flags);
  265. vs->online = flags & yfs_FVSOnline;
  266. vs->in_service = flags & yfs_FVSInservice;
  267. vs->blessed = flags & yfs_FVSBlessed;
  268. vs->needs_salvage = flags & yfs_FVSNeedsSalvage;
  269. vs->type = ntohl(x->type);
  270. vs->min_quota = 0;
  271. vs->max_quota = xdr_to_u64(x->max_quota);
  272. vs->blocks_in_use = xdr_to_u64(x->blocks_in_use);
  273. vs->part_blocks_avail = xdr_to_u64(x->part_blocks_avail);
  274. vs->part_max_blocks = xdr_to_u64(x->part_max_blocks);
  275. vs->vol_copy_date = xdr_to_u64(x->vol_copy_date);
  276. vs->vol_backup_date = xdr_to_u64(x->vol_backup_date);
  277. *_bp += sizeof(*x) / sizeof(__be32);
  278. }
  279. /*
  280. * Deliver reply data to operations that just return a file status and a volume
  281. * sync record.
  282. */
  283. static int yfs_deliver_status_and_volsync(struct afs_call *call)
  284. {
  285. struct afs_operation *op = call->op;
  286. const __be32 *bp;
  287. int ret;
  288. ret = afs_transfer_reply(call);
  289. if (ret < 0)
  290. return ret;
  291. bp = call->buffer;
  292. xdr_decode_YFSFetchStatus(&bp, call, &op->file[0].scb);
  293. xdr_decode_YFSVolSync(&bp, &op->volsync);
  294. _leave(" = 0 [done]");
  295. return 0;
  296. }
  297. /*
  298. * Deliver reply data to an YFS.FetchData64.
  299. */
  300. static int yfs_deliver_fs_fetch_data64(struct afs_call *call)
  301. {
  302. struct afs_operation *op = call->op;
  303. struct afs_vnode_param *vp = &op->file[0];
  304. struct afs_read *req = op->fetch.req;
  305. const __be32 *bp;
  306. size_t count_before;
  307. int ret;
  308. _enter("{%u,%zu, %zu/%llu}",
  309. call->unmarshall, call->iov_len, iov_iter_count(call->iter),
  310. req->actual_len);
  311. switch (call->unmarshall) {
  312. case 0:
  313. req->actual_len = 0;
  314. afs_extract_to_tmp64(call);
  315. call->unmarshall++;
  316. fallthrough;
  317. /* Extract the returned data length into ->actual_len. This
  318. * may indicate more or less data than was requested will be
  319. * returned.
  320. */
  321. case 1:
  322. _debug("extract data length");
  323. ret = afs_extract_data(call, true);
  324. if (ret < 0)
  325. return ret;
  326. req->actual_len = be64_to_cpu(call->tmp64);
  327. _debug("DATA length: %llu", req->actual_len);
  328. if (req->actual_len == 0)
  329. goto no_more_data;
  330. call->iter = req->iter;
  331. call->iov_len = min(req->actual_len, req->len);
  332. call->unmarshall++;
  333. fallthrough;
  334. /* extract the returned data */
  335. case 2:
  336. count_before = call->iov_len;
  337. _debug("extract data %zu/%llu", count_before, req->actual_len);
  338. ret = afs_extract_data(call, true);
  339. if (req->subreq) {
  340. req->subreq->transferred += count_before - call->iov_len;
  341. netfs_read_subreq_progress(req->subreq, false);
  342. }
  343. if (ret < 0)
  344. return ret;
  345. call->iter = &call->def_iter;
  346. if (req->actual_len <= req->len)
  347. goto no_more_data;
  348. /* Discard any excess data the server gave us */
  349. afs_extract_discard(call, req->actual_len - req->len);
  350. call->unmarshall = 3;
  351. fallthrough;
  352. case 3:
  353. _debug("extract discard %zu/%llu",
  354. iov_iter_count(call->iter), req->actual_len - req->len);
  355. ret = afs_extract_data(call, true);
  356. if (ret < 0)
  357. return ret;
  358. no_more_data:
  359. call->unmarshall = 4;
  360. afs_extract_to_buf(call,
  361. sizeof(struct yfs_xdr_YFSFetchStatus) +
  362. sizeof(struct yfs_xdr_YFSCallBack) +
  363. sizeof(struct yfs_xdr_YFSVolSync));
  364. fallthrough;
  365. /* extract the metadata */
  366. case 4:
  367. ret = afs_extract_data(call, false);
  368. if (ret < 0)
  369. return ret;
  370. bp = call->buffer;
  371. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  372. xdr_decode_YFSCallBack(&bp, call, &vp->scb);
  373. xdr_decode_YFSVolSync(&bp, &op->volsync);
  374. req->data_version = vp->scb.status.data_version;
  375. req->file_size = vp->scb.status.size;
  376. call->unmarshall++;
  377. fallthrough;
  378. case 5:
  379. break;
  380. }
  381. _leave(" = 0 [done]");
  382. return 0;
  383. }
  384. /*
  385. * YFS.FetchData64 operation type
  386. */
  387. static const struct afs_call_type yfs_RXYFSFetchData64 = {
  388. .name = "YFS.FetchData64",
  389. .op = yfs_FS_FetchData64,
  390. .deliver = yfs_deliver_fs_fetch_data64,
  391. .destructor = afs_flat_call_destructor,
  392. };
  393. /*
  394. * Fetch data from a file.
  395. */
  396. void yfs_fs_fetch_data(struct afs_operation *op)
  397. {
  398. struct afs_vnode_param *vp = &op->file[0];
  399. struct afs_read *req = op->fetch.req;
  400. struct afs_call *call;
  401. __be32 *bp;
  402. _enter(",%x,{%llx:%llu},%llx,%llx",
  403. key_serial(op->key), vp->fid.vid, vp->fid.vnode,
  404. req->pos, req->len);
  405. call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchData64,
  406. sizeof(__be32) * 2 +
  407. sizeof(struct yfs_xdr_YFSFid) +
  408. sizeof(struct yfs_xdr_u64) * 2,
  409. sizeof(struct yfs_xdr_YFSFetchStatus) +
  410. sizeof(struct yfs_xdr_YFSCallBack) +
  411. sizeof(struct yfs_xdr_YFSVolSync));
  412. if (!call)
  413. return afs_op_nomem(op);
  414. req->call_debug_id = call->debug_id;
  415. /* marshall the parameters */
  416. bp = call->request;
  417. bp = xdr_encode_u32(bp, YFSFETCHDATA64);
  418. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  419. bp = xdr_encode_YFSFid(bp, &vp->fid);
  420. bp = xdr_encode_u64(bp, req->pos);
  421. bp = xdr_encode_u64(bp, req->len);
  422. yfs_check_req(call, bp);
  423. call->fid = vp->fid;
  424. trace_afs_make_fs_call(call, &vp->fid);
  425. afs_make_op_call(op, call, GFP_NOFS);
  426. }
  427. /*
  428. * Deliver reply data for YFS.CreateFile or YFS.MakeDir.
  429. */
  430. static int yfs_deliver_fs_create_vnode(struct afs_call *call)
  431. {
  432. struct afs_operation *op = call->op;
  433. struct afs_vnode_param *dvp = &op->file[0];
  434. struct afs_vnode_param *vp = &op->file[1];
  435. const __be32 *bp;
  436. int ret;
  437. _enter("{%u}", call->unmarshall);
  438. ret = afs_transfer_reply(call);
  439. if (ret < 0)
  440. return ret;
  441. /* unmarshall the reply once we've received all of it */
  442. bp = call->buffer;
  443. xdr_decode_YFSFid(&bp, &op->file[1].fid);
  444. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  445. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  446. xdr_decode_YFSCallBack(&bp, call, &vp->scb);
  447. xdr_decode_YFSVolSync(&bp, &op->volsync);
  448. _leave(" = 0 [done]");
  449. return 0;
  450. }
  451. /*
  452. * FS.CreateFile and FS.MakeDir operation type
  453. */
  454. static const struct afs_call_type afs_RXFSCreateFile = {
  455. .name = "YFS.CreateFile",
  456. .op = yfs_FS_CreateFile,
  457. .deliver = yfs_deliver_fs_create_vnode,
  458. .destructor = afs_flat_call_destructor,
  459. };
  460. /*
  461. * Create a file.
  462. */
  463. void yfs_fs_create_file(struct afs_operation *op)
  464. {
  465. const struct qstr *name = &op->dentry->d_name;
  466. struct afs_vnode_param *dvp = &op->file[0];
  467. struct afs_call *call;
  468. size_t reqsz, rplsz;
  469. __be32 *bp;
  470. _enter("");
  471. reqsz = (sizeof(__be32) +
  472. sizeof(__be32) +
  473. sizeof(struct yfs_xdr_YFSFid) +
  474. xdr_strlen(name->len) +
  475. sizeof(struct yfs_xdr_YFSStoreStatus) +
  476. sizeof(__be32));
  477. rplsz = (sizeof(struct yfs_xdr_YFSFid) +
  478. sizeof(struct yfs_xdr_YFSFetchStatus) +
  479. sizeof(struct yfs_xdr_YFSFetchStatus) +
  480. sizeof(struct yfs_xdr_YFSCallBack) +
  481. sizeof(struct yfs_xdr_YFSVolSync));
  482. call = afs_alloc_flat_call(op->net, &afs_RXFSCreateFile, reqsz, rplsz);
  483. if (!call)
  484. return afs_op_nomem(op);
  485. /* marshall the parameters */
  486. bp = call->request;
  487. bp = xdr_encode_u32(bp, YFSCREATEFILE);
  488. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  489. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  490. bp = xdr_encode_name(bp, name);
  491. bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
  492. bp = xdr_encode_u32(bp, yfs_LockNone); /* ViceLockType */
  493. yfs_check_req(call, bp);
  494. call->fid = dvp->fid;
  495. trace_afs_make_fs_call1(call, &dvp->fid, name);
  496. afs_make_op_call(op, call, GFP_NOFS);
  497. }
  498. static const struct afs_call_type yfs_RXFSMakeDir = {
  499. .name = "YFS.MakeDir",
  500. .op = yfs_FS_MakeDir,
  501. .deliver = yfs_deliver_fs_create_vnode,
  502. .destructor = afs_flat_call_destructor,
  503. };
  504. /*
  505. * Make a directory.
  506. */
  507. void yfs_fs_make_dir(struct afs_operation *op)
  508. {
  509. const struct qstr *name = &op->dentry->d_name;
  510. struct afs_vnode_param *dvp = &op->file[0];
  511. struct afs_call *call;
  512. size_t reqsz, rplsz;
  513. __be32 *bp;
  514. _enter("");
  515. reqsz = (sizeof(__be32) +
  516. sizeof(struct yfs_xdr_RPCFlags) +
  517. sizeof(struct yfs_xdr_YFSFid) +
  518. xdr_strlen(name->len) +
  519. sizeof(struct yfs_xdr_YFSStoreStatus));
  520. rplsz = (sizeof(struct yfs_xdr_YFSFid) +
  521. sizeof(struct yfs_xdr_YFSFetchStatus) +
  522. sizeof(struct yfs_xdr_YFSFetchStatus) +
  523. sizeof(struct yfs_xdr_YFSCallBack) +
  524. sizeof(struct yfs_xdr_YFSVolSync));
  525. call = afs_alloc_flat_call(op->net, &yfs_RXFSMakeDir, reqsz, rplsz);
  526. if (!call)
  527. return afs_op_nomem(op);
  528. /* marshall the parameters */
  529. bp = call->request;
  530. bp = xdr_encode_u32(bp, YFSMAKEDIR);
  531. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  532. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  533. bp = xdr_encode_name(bp, name);
  534. bp = xdr_encode_YFSStoreStatus(bp, &op->create.mode, &op->mtime);
  535. yfs_check_req(call, bp);
  536. call->fid = dvp->fid;
  537. trace_afs_make_fs_call1(call, &dvp->fid, name);
  538. afs_make_op_call(op, call, GFP_NOFS);
  539. }
  540. /*
  541. * Deliver reply data to a YFS.RemoveFile2 operation.
  542. */
  543. static int yfs_deliver_fs_remove_file2(struct afs_call *call)
  544. {
  545. struct afs_operation *op = call->op;
  546. struct afs_vnode_param *dvp = &op->file[0];
  547. struct afs_vnode_param *vp = &op->file[1];
  548. struct afs_fid fid;
  549. const __be32 *bp;
  550. int ret;
  551. _enter("{%u}", call->unmarshall);
  552. ret = afs_transfer_reply(call);
  553. if (ret < 0)
  554. return ret;
  555. bp = call->buffer;
  556. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  557. xdr_decode_YFSFid(&bp, &fid);
  558. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  559. /* Was deleted if vnode->status.abort_code == VNOVNODE. */
  560. xdr_decode_YFSVolSync(&bp, &op->volsync);
  561. return 0;
  562. }
  563. static void yfs_done_fs_remove_file2(struct afs_call *call)
  564. {
  565. if (call->error == -ECONNABORTED &&
  566. (call->abort_code == RX_INVALID_OPERATION ||
  567. call->abort_code == RXGEN_OPCODE)) {
  568. set_bit(AFS_SERVER_FL_NO_RM2, &call->op->server->flags);
  569. call->op->flags |= AFS_OPERATION_DOWNGRADE;
  570. }
  571. }
  572. /*
  573. * YFS.RemoveFile2 operation type.
  574. */
  575. static const struct afs_call_type yfs_RXYFSRemoveFile2 = {
  576. .name = "YFS.RemoveFile2",
  577. .op = yfs_FS_RemoveFile2,
  578. .deliver = yfs_deliver_fs_remove_file2,
  579. .done = yfs_done_fs_remove_file2,
  580. .destructor = afs_flat_call_destructor,
  581. };
  582. /*
  583. * Remove a file and retrieve new file status.
  584. */
  585. void yfs_fs_remove_file2(struct afs_operation *op)
  586. {
  587. struct afs_vnode_param *dvp = &op->file[0];
  588. const struct qstr *name = &op->dentry->d_name;
  589. struct afs_call *call;
  590. __be32 *bp;
  591. _enter("");
  592. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile2,
  593. sizeof(__be32) +
  594. sizeof(struct yfs_xdr_RPCFlags) +
  595. sizeof(struct yfs_xdr_YFSFid) +
  596. xdr_strlen(name->len),
  597. sizeof(struct yfs_xdr_YFSFetchStatus) +
  598. sizeof(struct yfs_xdr_YFSFid) +
  599. sizeof(struct yfs_xdr_YFSFetchStatus) +
  600. sizeof(struct yfs_xdr_YFSVolSync));
  601. if (!call)
  602. return afs_op_nomem(op);
  603. /* marshall the parameters */
  604. bp = call->request;
  605. bp = xdr_encode_u32(bp, YFSREMOVEFILE2);
  606. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  607. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  608. bp = xdr_encode_name(bp, name);
  609. yfs_check_req(call, bp);
  610. call->fid = dvp->fid;
  611. trace_afs_make_fs_call1(call, &dvp->fid, name);
  612. afs_make_op_call(op, call, GFP_NOFS);
  613. }
  614. /*
  615. * Deliver reply data to a YFS.RemoveFile or YFS.RemoveDir operation.
  616. */
  617. static int yfs_deliver_fs_remove(struct afs_call *call)
  618. {
  619. struct afs_operation *op = call->op;
  620. struct afs_vnode_param *dvp = &op->file[0];
  621. const __be32 *bp;
  622. int ret;
  623. _enter("{%u}", call->unmarshall);
  624. ret = afs_transfer_reply(call);
  625. if (ret < 0)
  626. return ret;
  627. bp = call->buffer;
  628. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  629. xdr_decode_YFSVolSync(&bp, &op->volsync);
  630. return 0;
  631. }
  632. /*
  633. * FS.RemoveDir and FS.RemoveFile operation types.
  634. */
  635. static const struct afs_call_type yfs_RXYFSRemoveFile = {
  636. .name = "YFS.RemoveFile",
  637. .op = yfs_FS_RemoveFile,
  638. .deliver = yfs_deliver_fs_remove,
  639. .destructor = afs_flat_call_destructor,
  640. };
  641. /*
  642. * Remove a file.
  643. */
  644. void yfs_fs_remove_file(struct afs_operation *op)
  645. {
  646. const struct qstr *name = &op->dentry->d_name;
  647. struct afs_vnode_param *dvp = &op->file[0];
  648. struct afs_call *call;
  649. __be32 *bp;
  650. _enter("");
  651. if (!test_bit(AFS_SERVER_FL_NO_RM2, &op->server->flags))
  652. return yfs_fs_remove_file2(op);
  653. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveFile,
  654. sizeof(__be32) +
  655. sizeof(struct yfs_xdr_RPCFlags) +
  656. sizeof(struct yfs_xdr_YFSFid) +
  657. xdr_strlen(name->len),
  658. sizeof(struct yfs_xdr_YFSFetchStatus) +
  659. sizeof(struct yfs_xdr_YFSVolSync));
  660. if (!call)
  661. return afs_op_nomem(op);
  662. /* marshall the parameters */
  663. bp = call->request;
  664. bp = xdr_encode_u32(bp, YFSREMOVEFILE);
  665. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  666. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  667. bp = xdr_encode_name(bp, name);
  668. yfs_check_req(call, bp);
  669. call->fid = dvp->fid;
  670. trace_afs_make_fs_call1(call, &dvp->fid, name);
  671. afs_make_op_call(op, call, GFP_NOFS);
  672. }
  673. static const struct afs_call_type yfs_RXYFSRemoveDir = {
  674. .name = "YFS.RemoveDir",
  675. .op = yfs_FS_RemoveDir,
  676. .deliver = yfs_deliver_fs_remove,
  677. .destructor = afs_flat_call_destructor,
  678. };
  679. /*
  680. * Remove a directory.
  681. */
  682. void yfs_fs_remove_dir(struct afs_operation *op)
  683. {
  684. const struct qstr *name = &op->dentry->d_name;
  685. struct afs_vnode_param *dvp = &op->file[0];
  686. struct afs_call *call;
  687. __be32 *bp;
  688. _enter("");
  689. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRemoveDir,
  690. sizeof(__be32) +
  691. sizeof(struct yfs_xdr_RPCFlags) +
  692. sizeof(struct yfs_xdr_YFSFid) +
  693. xdr_strlen(name->len),
  694. sizeof(struct yfs_xdr_YFSFetchStatus) +
  695. sizeof(struct yfs_xdr_YFSVolSync));
  696. if (!call)
  697. return afs_op_nomem(op);
  698. /* marshall the parameters */
  699. bp = call->request;
  700. bp = xdr_encode_u32(bp, YFSREMOVEDIR);
  701. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  702. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  703. bp = xdr_encode_name(bp, name);
  704. yfs_check_req(call, bp);
  705. call->fid = dvp->fid;
  706. trace_afs_make_fs_call1(call, &dvp->fid, name);
  707. afs_make_op_call(op, call, GFP_NOFS);
  708. }
  709. /*
  710. * Deliver reply data to a YFS.Link operation.
  711. */
  712. static int yfs_deliver_fs_link(struct afs_call *call)
  713. {
  714. struct afs_operation *op = call->op;
  715. struct afs_vnode_param *dvp = &op->file[0];
  716. struct afs_vnode_param *vp = &op->file[1];
  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. bp = call->buffer;
  724. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  725. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  726. xdr_decode_YFSVolSync(&bp, &op->volsync);
  727. _leave(" = 0 [done]");
  728. return 0;
  729. }
  730. /*
  731. * YFS.Link operation type.
  732. */
  733. static const struct afs_call_type yfs_RXYFSLink = {
  734. .name = "YFS.Link",
  735. .op = yfs_FS_Link,
  736. .deliver = yfs_deliver_fs_link,
  737. .destructor = afs_flat_call_destructor,
  738. };
  739. /*
  740. * Make a hard link.
  741. */
  742. void yfs_fs_link(struct afs_operation *op)
  743. {
  744. const struct qstr *name = &op->dentry->d_name;
  745. struct afs_vnode_param *dvp = &op->file[0];
  746. struct afs_vnode_param *vp = &op->file[1];
  747. struct afs_call *call;
  748. __be32 *bp;
  749. _enter("");
  750. call = afs_alloc_flat_call(op->net, &yfs_RXYFSLink,
  751. sizeof(__be32) +
  752. sizeof(struct yfs_xdr_RPCFlags) +
  753. sizeof(struct yfs_xdr_YFSFid) +
  754. xdr_strlen(name->len) +
  755. sizeof(struct yfs_xdr_YFSFid),
  756. sizeof(struct yfs_xdr_YFSFetchStatus) +
  757. sizeof(struct yfs_xdr_YFSFetchStatus) +
  758. sizeof(struct yfs_xdr_YFSVolSync));
  759. if (!call)
  760. return afs_op_nomem(op);
  761. /* marshall the parameters */
  762. bp = call->request;
  763. bp = xdr_encode_u32(bp, YFSLINK);
  764. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  765. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  766. bp = xdr_encode_name(bp, name);
  767. bp = xdr_encode_YFSFid(bp, &vp->fid);
  768. yfs_check_req(call, bp);
  769. call->fid = vp->fid;
  770. trace_afs_make_fs_call1(call, &vp->fid, name);
  771. afs_make_op_call(op, call, GFP_NOFS);
  772. }
  773. /*
  774. * Deliver reply data to a YFS.Symlink operation.
  775. */
  776. static int yfs_deliver_fs_symlink(struct afs_call *call)
  777. {
  778. struct afs_operation *op = call->op;
  779. struct afs_vnode_param *dvp = &op->file[0];
  780. struct afs_vnode_param *vp = &op->file[1];
  781. const __be32 *bp;
  782. int ret;
  783. _enter("{%u}", call->unmarshall);
  784. ret = afs_transfer_reply(call);
  785. if (ret < 0)
  786. return ret;
  787. /* unmarshall the reply once we've received all of it */
  788. bp = call->buffer;
  789. xdr_decode_YFSFid(&bp, &vp->fid);
  790. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  791. xdr_decode_YFSFetchStatus(&bp, call, &dvp->scb);
  792. xdr_decode_YFSVolSync(&bp, &op->volsync);
  793. _leave(" = 0 [done]");
  794. return 0;
  795. }
  796. /*
  797. * YFS.Symlink operation type
  798. */
  799. static const struct afs_call_type yfs_RXYFSSymlink = {
  800. .name = "YFS.Symlink",
  801. .op = yfs_FS_Symlink,
  802. .deliver = yfs_deliver_fs_symlink,
  803. .destructor = afs_flat_call_destructor,
  804. };
  805. /*
  806. * Create a symbolic link.
  807. */
  808. void yfs_fs_symlink(struct afs_operation *op)
  809. {
  810. const struct qstr *name = &op->dentry->d_name;
  811. struct afs_vnode_param *dvp = &op->file[0];
  812. struct afs_call *call;
  813. size_t contents_sz;
  814. mode_t mode = 0777;
  815. __be32 *bp;
  816. _enter("");
  817. contents_sz = strlen(op->create.symlink);
  818. call = afs_alloc_flat_call(op->net, &yfs_RXYFSSymlink,
  819. sizeof(__be32) +
  820. sizeof(struct yfs_xdr_RPCFlags) +
  821. sizeof(struct yfs_xdr_YFSFid) +
  822. xdr_strlen(name->len) +
  823. xdr_strlen(contents_sz) +
  824. sizeof(struct yfs_xdr_YFSStoreStatus),
  825. sizeof(struct yfs_xdr_YFSFid) +
  826. sizeof(struct yfs_xdr_YFSFetchStatus) +
  827. sizeof(struct yfs_xdr_YFSFetchStatus) +
  828. sizeof(struct yfs_xdr_YFSVolSync));
  829. if (!call)
  830. return afs_op_nomem(op);
  831. /* marshall the parameters */
  832. bp = call->request;
  833. bp = xdr_encode_u32(bp, YFSSYMLINK);
  834. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  835. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  836. bp = xdr_encode_name(bp, name);
  837. bp = xdr_encode_string(bp, op->create.symlink, contents_sz);
  838. bp = xdr_encode_YFSStoreStatus(bp, &mode, &op->mtime);
  839. yfs_check_req(call, bp);
  840. call->fid = dvp->fid;
  841. trace_afs_make_fs_call1(call, &dvp->fid, name);
  842. afs_make_op_call(op, call, GFP_NOFS);
  843. }
  844. /*
  845. * Deliver reply data to a YFS.Rename operation.
  846. */
  847. static int yfs_deliver_fs_rename(struct afs_call *call)
  848. {
  849. struct afs_operation *op = call->op;
  850. struct afs_vnode_param *orig_dvp = &op->file[0];
  851. struct afs_vnode_param *new_dvp = &op->file[1];
  852. const __be32 *bp;
  853. int ret;
  854. _enter("{%u}", call->unmarshall);
  855. ret = afs_transfer_reply(call);
  856. if (ret < 0)
  857. return ret;
  858. bp = call->buffer;
  859. /* If the two dirs are the same, we have two copies of the same status
  860. * report, so we just decode it twice.
  861. */
  862. xdr_decode_YFSFetchStatus(&bp, call, &orig_dvp->scb);
  863. xdr_decode_YFSFetchStatus(&bp, call, &new_dvp->scb);
  864. xdr_decode_YFSVolSync(&bp, &op->volsync);
  865. _leave(" = 0 [done]");
  866. return 0;
  867. }
  868. /*
  869. * YFS.Rename operation type
  870. */
  871. static const struct afs_call_type yfs_RXYFSRename = {
  872. .name = "FS.Rename",
  873. .op = yfs_FS_Rename,
  874. .deliver = yfs_deliver_fs_rename,
  875. .destructor = afs_flat_call_destructor,
  876. };
  877. /*
  878. * Rename a file or directory.
  879. */
  880. void yfs_fs_rename(struct afs_operation *op)
  881. {
  882. struct afs_vnode_param *orig_dvp = &op->file[0];
  883. struct afs_vnode_param *new_dvp = &op->file[1];
  884. const struct qstr *orig_name = &op->dentry->d_name;
  885. const struct qstr *new_name = &op->dentry_2->d_name;
  886. struct afs_call *call;
  887. __be32 *bp;
  888. _enter("");
  889. call = afs_alloc_flat_call(op->net, &yfs_RXYFSRename,
  890. sizeof(__be32) +
  891. sizeof(struct yfs_xdr_RPCFlags) +
  892. sizeof(struct yfs_xdr_YFSFid) +
  893. xdr_strlen(orig_name->len) +
  894. sizeof(struct yfs_xdr_YFSFid) +
  895. xdr_strlen(new_name->len),
  896. sizeof(struct yfs_xdr_YFSFetchStatus) +
  897. sizeof(struct yfs_xdr_YFSFetchStatus) +
  898. sizeof(struct yfs_xdr_YFSVolSync));
  899. if (!call)
  900. return afs_op_nomem(op);
  901. /* marshall the parameters */
  902. bp = call->request;
  903. bp = xdr_encode_u32(bp, YFSRENAME);
  904. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  905. bp = xdr_encode_YFSFid(bp, &orig_dvp->fid);
  906. bp = xdr_encode_name(bp, orig_name);
  907. bp = xdr_encode_YFSFid(bp, &new_dvp->fid);
  908. bp = xdr_encode_name(bp, new_name);
  909. yfs_check_req(call, bp);
  910. call->fid = orig_dvp->fid;
  911. trace_afs_make_fs_call2(call, &orig_dvp->fid, orig_name, new_name);
  912. afs_make_op_call(op, call, GFP_NOFS);
  913. }
  914. /*
  915. * YFS.StoreData64 operation type.
  916. */
  917. static const struct afs_call_type yfs_RXYFSStoreData64 = {
  918. .name = "YFS.StoreData64",
  919. .op = yfs_FS_StoreData64,
  920. .deliver = yfs_deliver_status_and_volsync,
  921. .destructor = afs_flat_call_destructor,
  922. };
  923. /*
  924. * Store a set of pages to a large file.
  925. */
  926. void yfs_fs_store_data(struct afs_operation *op)
  927. {
  928. struct afs_vnode_param *vp = &op->file[0];
  929. struct afs_call *call;
  930. __be32 *bp;
  931. _enter(",%x,{%llx:%llu},,",
  932. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  933. _debug("size %llx, at %llx, i_size %llx",
  934. (unsigned long long)op->store.size,
  935. (unsigned long long)op->store.pos,
  936. (unsigned long long)op->store.i_size);
  937. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64,
  938. sizeof(__be32) +
  939. sizeof(__be32) +
  940. sizeof(struct yfs_xdr_YFSFid) +
  941. sizeof(struct yfs_xdr_YFSStoreStatus) +
  942. sizeof(struct yfs_xdr_u64) * 3,
  943. sizeof(struct yfs_xdr_YFSFetchStatus) +
  944. sizeof(struct yfs_xdr_YFSVolSync));
  945. if (!call)
  946. return afs_op_nomem(op);
  947. call->write_iter = op->store.write_iter;
  948. /* marshall the parameters */
  949. bp = call->request;
  950. bp = xdr_encode_u32(bp, YFSSTOREDATA64);
  951. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  952. bp = xdr_encode_YFSFid(bp, &vp->fid);
  953. bp = xdr_encode_YFSStoreStatus(bp, NULL, &op->mtime);
  954. bp = xdr_encode_u64(bp, op->store.pos);
  955. bp = xdr_encode_u64(bp, op->store.size);
  956. bp = xdr_encode_u64(bp, op->store.i_size);
  957. yfs_check_req(call, bp);
  958. call->fid = vp->fid;
  959. trace_afs_make_fs_call(call, &vp->fid);
  960. afs_make_op_call(op, call, GFP_NOFS);
  961. }
  962. /*
  963. * YFS.StoreStatus operation type
  964. */
  965. static const struct afs_call_type yfs_RXYFSStoreStatus = {
  966. .name = "YFS.StoreStatus",
  967. .op = yfs_FS_StoreStatus,
  968. .deliver = yfs_deliver_status_and_volsync,
  969. .destructor = afs_flat_call_destructor,
  970. };
  971. static const struct afs_call_type yfs_RXYFSStoreData64_as_Status = {
  972. .name = "YFS.StoreData64",
  973. .op = yfs_FS_StoreData64,
  974. .deliver = yfs_deliver_status_and_volsync,
  975. .destructor = afs_flat_call_destructor,
  976. };
  977. /*
  978. * Set the attributes on a file, using YFS.StoreData64 rather than
  979. * YFS.StoreStatus so as to alter the file size also.
  980. */
  981. static void yfs_fs_setattr_size(struct afs_operation *op)
  982. {
  983. struct afs_vnode_param *vp = &op->file[0];
  984. struct afs_call *call;
  985. struct iattr *attr = op->setattr.attr;
  986. __be32 *bp;
  987. _enter(",%x,{%llx:%llu},,",
  988. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  989. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreData64_as_Status,
  990. sizeof(__be32) * 2 +
  991. sizeof(struct yfs_xdr_YFSFid) +
  992. sizeof(struct yfs_xdr_YFSStoreStatus) +
  993. sizeof(struct yfs_xdr_u64) * 3,
  994. sizeof(struct yfs_xdr_YFSFetchStatus) +
  995. sizeof(struct yfs_xdr_YFSVolSync));
  996. if (!call)
  997. return afs_op_nomem(op);
  998. /* marshall the parameters */
  999. bp = call->request;
  1000. bp = xdr_encode_u32(bp, YFSSTOREDATA64);
  1001. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1002. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1003. bp = xdr_encode_YFS_StoreStatus(bp, attr);
  1004. bp = xdr_encode_u64(bp, attr->ia_size); /* position of start of write */
  1005. bp = xdr_encode_u64(bp, 0); /* size of write */
  1006. bp = xdr_encode_u64(bp, attr->ia_size); /* new file length */
  1007. yfs_check_req(call, bp);
  1008. call->fid = vp->fid;
  1009. trace_afs_make_fs_call(call, &vp->fid);
  1010. afs_make_op_call(op, call, GFP_NOFS);
  1011. }
  1012. /*
  1013. * Set the attributes on a file, using YFS.StoreData64 if there's a change in
  1014. * file size, and YFS.StoreStatus otherwise.
  1015. */
  1016. void yfs_fs_setattr(struct afs_operation *op)
  1017. {
  1018. struct afs_vnode_param *vp = &op->file[0];
  1019. struct afs_call *call;
  1020. struct iattr *attr = op->setattr.attr;
  1021. __be32 *bp;
  1022. if (attr->ia_valid & ATTR_SIZE)
  1023. return yfs_fs_setattr_size(op);
  1024. _enter(",%x,{%llx:%llu},,",
  1025. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1026. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreStatus,
  1027. sizeof(__be32) * 2 +
  1028. sizeof(struct yfs_xdr_YFSFid) +
  1029. sizeof(struct yfs_xdr_YFSStoreStatus),
  1030. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1031. sizeof(struct yfs_xdr_YFSVolSync));
  1032. if (!call)
  1033. return afs_op_nomem(op);
  1034. /* marshall the parameters */
  1035. bp = call->request;
  1036. bp = xdr_encode_u32(bp, YFSSTORESTATUS);
  1037. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1038. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1039. bp = xdr_encode_YFS_StoreStatus(bp, attr);
  1040. yfs_check_req(call, bp);
  1041. call->fid = vp->fid;
  1042. trace_afs_make_fs_call(call, &vp->fid);
  1043. afs_make_op_call(op, call, GFP_NOFS);
  1044. }
  1045. /*
  1046. * Deliver reply data to a YFS.GetVolumeStatus operation.
  1047. */
  1048. static int yfs_deliver_fs_get_volume_status(struct afs_call *call)
  1049. {
  1050. struct afs_operation *op = call->op;
  1051. const __be32 *bp;
  1052. char *p;
  1053. u32 size;
  1054. int ret;
  1055. _enter("{%u}", call->unmarshall);
  1056. switch (call->unmarshall) {
  1057. case 0:
  1058. call->unmarshall++;
  1059. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchVolumeStatus));
  1060. fallthrough;
  1061. /* extract the returned status record */
  1062. case 1:
  1063. _debug("extract status");
  1064. ret = afs_extract_data(call, true);
  1065. if (ret < 0)
  1066. return ret;
  1067. bp = call->buffer;
  1068. xdr_decode_YFSFetchVolumeStatus(&bp, &op->volstatus.vs);
  1069. call->unmarshall++;
  1070. afs_extract_to_tmp(call);
  1071. fallthrough;
  1072. /* extract the volume name length */
  1073. case 2:
  1074. ret = afs_extract_data(call, true);
  1075. if (ret < 0)
  1076. return ret;
  1077. call->count = ntohl(call->tmp);
  1078. _debug("volname length: %u", call->count);
  1079. if (call->count >= AFSNAMEMAX)
  1080. return afs_protocol_error(call, afs_eproto_volname_len);
  1081. size = (call->count + 3) & ~3; /* It's padded */
  1082. afs_extract_to_buf(call, size);
  1083. call->unmarshall++;
  1084. fallthrough;
  1085. /* extract the volume name */
  1086. case 3:
  1087. _debug("extract volname");
  1088. ret = afs_extract_data(call, true);
  1089. if (ret < 0)
  1090. return ret;
  1091. p = call->buffer;
  1092. p[call->count] = 0;
  1093. _debug("volname '%s'", p);
  1094. afs_extract_to_tmp(call);
  1095. call->unmarshall++;
  1096. fallthrough;
  1097. /* extract the offline message length */
  1098. case 4:
  1099. ret = afs_extract_data(call, true);
  1100. if (ret < 0)
  1101. return ret;
  1102. call->count = ntohl(call->tmp);
  1103. _debug("offline msg length: %u", call->count);
  1104. if (call->count >= AFSNAMEMAX)
  1105. return afs_protocol_error(call, afs_eproto_offline_msg_len);
  1106. size = (call->count + 3) & ~3; /* It's padded */
  1107. afs_extract_to_buf(call, size);
  1108. call->unmarshall++;
  1109. fallthrough;
  1110. /* extract the offline message */
  1111. case 5:
  1112. _debug("extract offline");
  1113. ret = afs_extract_data(call, true);
  1114. if (ret < 0)
  1115. return ret;
  1116. p = call->buffer;
  1117. p[call->count] = 0;
  1118. _debug("offline '%s'", p);
  1119. afs_extract_to_tmp(call);
  1120. call->unmarshall++;
  1121. fallthrough;
  1122. /* extract the message of the day length */
  1123. case 6:
  1124. ret = afs_extract_data(call, true);
  1125. if (ret < 0)
  1126. return ret;
  1127. call->count = ntohl(call->tmp);
  1128. _debug("motd length: %u", call->count);
  1129. if (call->count >= AFSNAMEMAX)
  1130. return afs_protocol_error(call, afs_eproto_motd_len);
  1131. size = (call->count + 3) & ~3; /* It's padded */
  1132. afs_extract_to_buf(call, size);
  1133. call->unmarshall++;
  1134. fallthrough;
  1135. /* extract the message of the day */
  1136. case 7:
  1137. _debug("extract motd");
  1138. ret = afs_extract_data(call, false);
  1139. if (ret < 0)
  1140. return ret;
  1141. p = call->buffer;
  1142. p[call->count] = 0;
  1143. _debug("motd '%s'", p);
  1144. call->unmarshall++;
  1145. fallthrough;
  1146. case 8:
  1147. break;
  1148. }
  1149. _leave(" = 0 [done]");
  1150. return 0;
  1151. }
  1152. /*
  1153. * YFS.GetVolumeStatus operation type
  1154. */
  1155. static const struct afs_call_type yfs_RXYFSGetVolumeStatus = {
  1156. .name = "YFS.GetVolumeStatus",
  1157. .op = yfs_FS_GetVolumeStatus,
  1158. .deliver = yfs_deliver_fs_get_volume_status,
  1159. .destructor = afs_flat_call_destructor,
  1160. };
  1161. /*
  1162. * fetch the status of a volume
  1163. */
  1164. void yfs_fs_get_volume_status(struct afs_operation *op)
  1165. {
  1166. struct afs_vnode_param *vp = &op->file[0];
  1167. struct afs_call *call;
  1168. __be32 *bp;
  1169. _enter("");
  1170. call = afs_alloc_flat_call(op->net, &yfs_RXYFSGetVolumeStatus,
  1171. sizeof(__be32) * 2 +
  1172. sizeof(struct yfs_xdr_u64),
  1173. max_t(size_t,
  1174. sizeof(struct yfs_xdr_YFSFetchVolumeStatus) +
  1175. sizeof(__be32),
  1176. AFSOPAQUEMAX + 1));
  1177. if (!call)
  1178. return afs_op_nomem(op);
  1179. /* marshall the parameters */
  1180. bp = call->request;
  1181. bp = xdr_encode_u32(bp, YFSGETVOLUMESTATUS);
  1182. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1183. bp = xdr_encode_u64(bp, vp->fid.vid);
  1184. yfs_check_req(call, bp);
  1185. call->fid = vp->fid;
  1186. trace_afs_make_fs_call(call, &vp->fid);
  1187. afs_make_op_call(op, call, GFP_NOFS);
  1188. }
  1189. /*
  1190. * YFS.SetLock operation type
  1191. */
  1192. static const struct afs_call_type yfs_RXYFSSetLock = {
  1193. .name = "YFS.SetLock",
  1194. .op = yfs_FS_SetLock,
  1195. .deliver = yfs_deliver_status_and_volsync,
  1196. .done = afs_lock_op_done,
  1197. .destructor = afs_flat_call_destructor,
  1198. };
  1199. /*
  1200. * YFS.ExtendLock operation type
  1201. */
  1202. static const struct afs_call_type yfs_RXYFSExtendLock = {
  1203. .name = "YFS.ExtendLock",
  1204. .op = yfs_FS_ExtendLock,
  1205. .deliver = yfs_deliver_status_and_volsync,
  1206. .done = afs_lock_op_done,
  1207. .destructor = afs_flat_call_destructor,
  1208. };
  1209. /*
  1210. * YFS.ReleaseLock operation type
  1211. */
  1212. static const struct afs_call_type yfs_RXYFSReleaseLock = {
  1213. .name = "YFS.ReleaseLock",
  1214. .op = yfs_FS_ReleaseLock,
  1215. .deliver = yfs_deliver_status_and_volsync,
  1216. .destructor = afs_flat_call_destructor,
  1217. };
  1218. /*
  1219. * Set a lock on a file
  1220. */
  1221. void yfs_fs_set_lock(struct afs_operation *op)
  1222. {
  1223. struct afs_vnode_param *vp = &op->file[0];
  1224. struct afs_call *call;
  1225. __be32 *bp;
  1226. _enter("");
  1227. call = afs_alloc_flat_call(op->net, &yfs_RXYFSSetLock,
  1228. sizeof(__be32) * 2 +
  1229. sizeof(struct yfs_xdr_YFSFid) +
  1230. sizeof(__be32),
  1231. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1232. sizeof(struct yfs_xdr_YFSVolSync));
  1233. if (!call)
  1234. return afs_op_nomem(op);
  1235. /* marshall the parameters */
  1236. bp = call->request;
  1237. bp = xdr_encode_u32(bp, YFSSETLOCK);
  1238. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1239. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1240. bp = xdr_encode_u32(bp, op->lock.type);
  1241. yfs_check_req(call, bp);
  1242. call->fid = vp->fid;
  1243. trace_afs_make_fs_calli(call, &vp->fid, op->lock.type);
  1244. afs_make_op_call(op, call, GFP_NOFS);
  1245. }
  1246. /*
  1247. * extend a lock on a file
  1248. */
  1249. void yfs_fs_extend_lock(struct afs_operation *op)
  1250. {
  1251. struct afs_vnode_param *vp = &op->file[0];
  1252. struct afs_call *call;
  1253. __be32 *bp;
  1254. _enter("");
  1255. call = afs_alloc_flat_call(op->net, &yfs_RXYFSExtendLock,
  1256. sizeof(__be32) * 2 +
  1257. sizeof(struct yfs_xdr_YFSFid),
  1258. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1259. sizeof(struct yfs_xdr_YFSVolSync));
  1260. if (!call)
  1261. return afs_op_nomem(op);
  1262. /* marshall the parameters */
  1263. bp = call->request;
  1264. bp = xdr_encode_u32(bp, YFSEXTENDLOCK);
  1265. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1266. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1267. yfs_check_req(call, bp);
  1268. call->fid = vp->fid;
  1269. trace_afs_make_fs_call(call, &vp->fid);
  1270. afs_make_op_call(op, call, GFP_NOFS);
  1271. }
  1272. /*
  1273. * release a lock on a file
  1274. */
  1275. void yfs_fs_release_lock(struct afs_operation *op)
  1276. {
  1277. struct afs_vnode_param *vp = &op->file[0];
  1278. struct afs_call *call;
  1279. __be32 *bp;
  1280. _enter("");
  1281. call = afs_alloc_flat_call(op->net, &yfs_RXYFSReleaseLock,
  1282. sizeof(__be32) * 2 +
  1283. sizeof(struct yfs_xdr_YFSFid),
  1284. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1285. sizeof(struct yfs_xdr_YFSVolSync));
  1286. if (!call)
  1287. return afs_op_nomem(op);
  1288. /* marshall the parameters */
  1289. bp = call->request;
  1290. bp = xdr_encode_u32(bp, YFSRELEASELOCK);
  1291. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1292. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1293. yfs_check_req(call, bp);
  1294. call->fid = vp->fid;
  1295. trace_afs_make_fs_call(call, &vp->fid);
  1296. afs_make_op_call(op, call, GFP_NOFS);
  1297. }
  1298. /*
  1299. * Deliver a reply to YFS.FetchStatus
  1300. */
  1301. static int yfs_deliver_fs_fetch_status(struct afs_call *call)
  1302. {
  1303. struct afs_operation *op = call->op;
  1304. struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
  1305. const __be32 *bp;
  1306. int ret;
  1307. ret = afs_transfer_reply(call);
  1308. if (ret < 0)
  1309. return ret;
  1310. /* unmarshall the reply once we've received all of it */
  1311. bp = call->buffer;
  1312. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  1313. xdr_decode_YFSCallBack(&bp, call, &vp->scb);
  1314. xdr_decode_YFSVolSync(&bp, &op->volsync);
  1315. _leave(" = 0 [done]");
  1316. return 0;
  1317. }
  1318. /*
  1319. * YFS.FetchStatus operation type
  1320. */
  1321. static const struct afs_call_type yfs_RXYFSFetchStatus = {
  1322. .name = "YFS.FetchStatus",
  1323. .op = yfs_FS_FetchStatus,
  1324. .deliver = yfs_deliver_fs_fetch_status,
  1325. .destructor = afs_flat_call_destructor,
  1326. };
  1327. /*
  1328. * Fetch the status information for a fid without needing a vnode handle.
  1329. */
  1330. void yfs_fs_fetch_status(struct afs_operation *op)
  1331. {
  1332. struct afs_vnode_param *vp = &op->file[op->fetch_status.which];
  1333. struct afs_call *call;
  1334. __be32 *bp;
  1335. _enter(",%x,{%llx:%llu},,",
  1336. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1337. call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchStatus,
  1338. sizeof(__be32) * 2 +
  1339. sizeof(struct yfs_xdr_YFSFid),
  1340. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1341. sizeof(struct yfs_xdr_YFSCallBack) +
  1342. sizeof(struct yfs_xdr_YFSVolSync));
  1343. if (!call)
  1344. return afs_op_nomem(op);
  1345. /* marshall the parameters */
  1346. bp = call->request;
  1347. bp = xdr_encode_u32(bp, YFSFETCHSTATUS);
  1348. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1349. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1350. yfs_check_req(call, bp);
  1351. call->fid = vp->fid;
  1352. trace_afs_make_fs_call(call, &vp->fid);
  1353. afs_make_op_call(op, call, GFP_NOFS);
  1354. }
  1355. /*
  1356. * Deliver reply data to an YFS.InlineBulkStatus call
  1357. */
  1358. static int yfs_deliver_fs_inline_bulk_status(struct afs_call *call)
  1359. {
  1360. struct afs_operation *op = call->op;
  1361. struct afs_status_cb *scb;
  1362. const __be32 *bp;
  1363. u32 tmp;
  1364. int ret;
  1365. _enter("{%u}", call->unmarshall);
  1366. switch (call->unmarshall) {
  1367. case 0:
  1368. afs_extract_to_tmp(call);
  1369. call->unmarshall++;
  1370. fallthrough;
  1371. /* Extract the file status count and array in two steps */
  1372. case 1:
  1373. _debug("extract status count");
  1374. ret = afs_extract_data(call, true);
  1375. if (ret < 0)
  1376. return ret;
  1377. tmp = ntohl(call->tmp);
  1378. _debug("status count: %u/%u", tmp, op->nr_files);
  1379. if (tmp != op->nr_files)
  1380. return afs_protocol_error(call, afs_eproto_ibulkst_count);
  1381. call->count = 0;
  1382. call->unmarshall++;
  1383. more_counts:
  1384. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSFetchStatus));
  1385. fallthrough;
  1386. case 2:
  1387. _debug("extract status array %u", call->count);
  1388. ret = afs_extract_data(call, true);
  1389. if (ret < 0)
  1390. return ret;
  1391. switch (call->count) {
  1392. case 0:
  1393. scb = &op->file[0].scb;
  1394. break;
  1395. case 1:
  1396. scb = &op->file[1].scb;
  1397. break;
  1398. default:
  1399. scb = &op->more_files[call->count - 2].scb;
  1400. break;
  1401. }
  1402. bp = call->buffer;
  1403. xdr_decode_YFSFetchStatus(&bp, call, scb);
  1404. call->count++;
  1405. if (call->count < op->nr_files)
  1406. goto more_counts;
  1407. call->count = 0;
  1408. call->unmarshall++;
  1409. afs_extract_to_tmp(call);
  1410. fallthrough;
  1411. /* Extract the callback count and array in two steps */
  1412. case 3:
  1413. _debug("extract CB count");
  1414. ret = afs_extract_data(call, true);
  1415. if (ret < 0)
  1416. return ret;
  1417. tmp = ntohl(call->tmp);
  1418. _debug("CB count: %u", tmp);
  1419. if (tmp != op->nr_files)
  1420. return afs_protocol_error(call, afs_eproto_ibulkst_cb_count);
  1421. call->count = 0;
  1422. call->unmarshall++;
  1423. more_cbs:
  1424. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSCallBack));
  1425. fallthrough;
  1426. case 4:
  1427. _debug("extract CB array");
  1428. ret = afs_extract_data(call, true);
  1429. if (ret < 0)
  1430. return ret;
  1431. _debug("unmarshall CB array");
  1432. switch (call->count) {
  1433. case 0:
  1434. scb = &op->file[0].scb;
  1435. break;
  1436. case 1:
  1437. scb = &op->file[1].scb;
  1438. break;
  1439. default:
  1440. scb = &op->more_files[call->count - 2].scb;
  1441. break;
  1442. }
  1443. bp = call->buffer;
  1444. xdr_decode_YFSCallBack(&bp, call, scb);
  1445. call->count++;
  1446. if (call->count < op->nr_files)
  1447. goto more_cbs;
  1448. afs_extract_to_buf(call, sizeof(struct yfs_xdr_YFSVolSync));
  1449. call->unmarshall++;
  1450. fallthrough;
  1451. case 5:
  1452. ret = afs_extract_data(call, false);
  1453. if (ret < 0)
  1454. return ret;
  1455. bp = call->buffer;
  1456. xdr_decode_YFSVolSync(&bp, &op->volsync);
  1457. call->unmarshall++;
  1458. fallthrough;
  1459. case 6:
  1460. break;
  1461. }
  1462. _leave(" = 0 [done]");
  1463. return 0;
  1464. }
  1465. /*
  1466. * FS.InlineBulkStatus operation type
  1467. */
  1468. static const struct afs_call_type yfs_RXYFSInlineBulkStatus = {
  1469. .name = "YFS.InlineBulkStatus",
  1470. .op = yfs_FS_InlineBulkStatus,
  1471. .deliver = yfs_deliver_fs_inline_bulk_status,
  1472. .destructor = afs_flat_call_destructor,
  1473. };
  1474. /*
  1475. * Fetch the status information for up to 1024 files
  1476. */
  1477. void yfs_fs_inline_bulk_status(struct afs_operation *op)
  1478. {
  1479. struct afs_vnode_param *dvp = &op->file[0];
  1480. struct afs_vnode_param *vp = &op->file[1];
  1481. struct afs_call *call;
  1482. __be32 *bp;
  1483. int i;
  1484. _enter(",%x,{%llx:%llu},%u",
  1485. key_serial(op->key), vp->fid.vid, vp->fid.vnode, op->nr_files);
  1486. call = afs_alloc_flat_call(op->net, &yfs_RXYFSInlineBulkStatus,
  1487. sizeof(__be32) +
  1488. sizeof(__be32) +
  1489. sizeof(__be32) +
  1490. sizeof(struct yfs_xdr_YFSFid) * op->nr_files,
  1491. sizeof(struct yfs_xdr_YFSFetchStatus));
  1492. if (!call)
  1493. return afs_op_nomem(op);
  1494. /* marshall the parameters */
  1495. bp = call->request;
  1496. bp = xdr_encode_u32(bp, YFSINLINEBULKSTATUS);
  1497. bp = xdr_encode_u32(bp, 0); /* RPCFlags */
  1498. bp = xdr_encode_u32(bp, op->nr_files);
  1499. bp = xdr_encode_YFSFid(bp, &dvp->fid);
  1500. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1501. for (i = 0; i < op->nr_files - 2; i++)
  1502. bp = xdr_encode_YFSFid(bp, &op->more_files[i].fid);
  1503. yfs_check_req(call, bp);
  1504. call->fid = vp->fid;
  1505. trace_afs_make_fs_call(call, &vp->fid);
  1506. afs_make_op_call(op, call, GFP_NOFS);
  1507. }
  1508. /*
  1509. * Deliver reply data to an YFS.FetchOpaqueACL.
  1510. */
  1511. static int yfs_deliver_fs_fetch_opaque_acl(struct afs_call *call)
  1512. {
  1513. struct afs_operation *op = call->op;
  1514. struct afs_vnode_param *vp = &op->file[0];
  1515. struct yfs_acl *yacl = op->yacl;
  1516. struct afs_acl *acl;
  1517. const __be32 *bp;
  1518. unsigned int size;
  1519. int ret;
  1520. _enter("{%u}", call->unmarshall);
  1521. switch (call->unmarshall) {
  1522. case 0:
  1523. afs_extract_to_tmp(call);
  1524. call->unmarshall++;
  1525. fallthrough;
  1526. /* Extract the file ACL length */
  1527. case 1:
  1528. ret = afs_extract_data(call, true);
  1529. if (ret < 0)
  1530. return ret;
  1531. size = call->count2 = ntohl(call->tmp);
  1532. size = round_up(size, 4);
  1533. if (yacl->flags & YFS_ACL_WANT_ACL) {
  1534. acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
  1535. if (!acl)
  1536. return -ENOMEM;
  1537. yacl->acl = acl;
  1538. acl->size = call->count2;
  1539. afs_extract_begin(call, acl->data, size);
  1540. } else {
  1541. afs_extract_discard(call, size);
  1542. }
  1543. call->unmarshall++;
  1544. fallthrough;
  1545. /* Extract the file ACL */
  1546. case 2:
  1547. ret = afs_extract_data(call, true);
  1548. if (ret < 0)
  1549. return ret;
  1550. afs_extract_to_tmp(call);
  1551. call->unmarshall++;
  1552. fallthrough;
  1553. /* Extract the volume ACL length */
  1554. case 3:
  1555. ret = afs_extract_data(call, true);
  1556. if (ret < 0)
  1557. return ret;
  1558. size = call->count2 = ntohl(call->tmp);
  1559. size = round_up(size, 4);
  1560. if (yacl->flags & YFS_ACL_WANT_VOL_ACL) {
  1561. acl = kmalloc(struct_size(acl, data, size), GFP_KERNEL);
  1562. if (!acl)
  1563. return -ENOMEM;
  1564. yacl->vol_acl = acl;
  1565. acl->size = call->count2;
  1566. afs_extract_begin(call, acl->data, size);
  1567. } else {
  1568. afs_extract_discard(call, size);
  1569. }
  1570. call->unmarshall++;
  1571. fallthrough;
  1572. /* Extract the volume ACL */
  1573. case 4:
  1574. ret = afs_extract_data(call, true);
  1575. if (ret < 0)
  1576. return ret;
  1577. afs_extract_to_buf(call,
  1578. sizeof(__be32) * 2 +
  1579. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1580. sizeof(struct yfs_xdr_YFSVolSync));
  1581. call->unmarshall++;
  1582. fallthrough;
  1583. /* extract the metadata */
  1584. case 5:
  1585. ret = afs_extract_data(call, false);
  1586. if (ret < 0)
  1587. return ret;
  1588. bp = call->buffer;
  1589. yacl->inherit_flag = ntohl(*bp++);
  1590. yacl->num_cleaned = ntohl(*bp++);
  1591. xdr_decode_YFSFetchStatus(&bp, call, &vp->scb);
  1592. xdr_decode_YFSVolSync(&bp, &op->volsync);
  1593. call->unmarshall++;
  1594. fallthrough;
  1595. case 6:
  1596. break;
  1597. }
  1598. _leave(" = 0 [done]");
  1599. return 0;
  1600. }
  1601. void yfs_free_opaque_acl(struct yfs_acl *yacl)
  1602. {
  1603. if (yacl) {
  1604. kfree(yacl->acl);
  1605. kfree(yacl->vol_acl);
  1606. kfree(yacl);
  1607. }
  1608. }
  1609. /*
  1610. * YFS.FetchOpaqueACL operation type
  1611. */
  1612. static const struct afs_call_type yfs_RXYFSFetchOpaqueACL = {
  1613. .name = "YFS.FetchOpaqueACL",
  1614. .op = yfs_FS_FetchOpaqueACL,
  1615. .deliver = yfs_deliver_fs_fetch_opaque_acl,
  1616. .destructor = afs_flat_call_destructor,
  1617. };
  1618. /*
  1619. * Fetch the YFS advanced ACLs for a file.
  1620. */
  1621. void yfs_fs_fetch_opaque_acl(struct afs_operation *op)
  1622. {
  1623. struct afs_vnode_param *vp = &op->file[0];
  1624. struct afs_call *call;
  1625. __be32 *bp;
  1626. _enter(",%x,{%llx:%llu},,",
  1627. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1628. call = afs_alloc_flat_call(op->net, &yfs_RXYFSFetchOpaqueACL,
  1629. sizeof(__be32) * 2 +
  1630. sizeof(struct yfs_xdr_YFSFid),
  1631. sizeof(__be32) * 2 +
  1632. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1633. sizeof(struct yfs_xdr_YFSVolSync));
  1634. if (!call)
  1635. return afs_op_nomem(op);
  1636. /* marshall the parameters */
  1637. bp = call->request;
  1638. bp = xdr_encode_u32(bp, YFSFETCHOPAQUEACL);
  1639. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1640. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1641. yfs_check_req(call, bp);
  1642. call->fid = vp->fid;
  1643. trace_afs_make_fs_call(call, &vp->fid);
  1644. afs_make_op_call(op, call, GFP_KERNEL);
  1645. }
  1646. /*
  1647. * YFS.StoreOpaqueACL2 operation type
  1648. */
  1649. static const struct afs_call_type yfs_RXYFSStoreOpaqueACL2 = {
  1650. .name = "YFS.StoreOpaqueACL2",
  1651. .op = yfs_FS_StoreOpaqueACL2,
  1652. .deliver = yfs_deliver_status_and_volsync,
  1653. .destructor = afs_flat_call_destructor,
  1654. };
  1655. /*
  1656. * Fetch the YFS ACL for a file.
  1657. */
  1658. void yfs_fs_store_opaque_acl2(struct afs_operation *op)
  1659. {
  1660. struct afs_vnode_param *vp = &op->file[0];
  1661. struct afs_call *call;
  1662. struct afs_acl *acl = op->acl;
  1663. size_t size;
  1664. __be32 *bp;
  1665. _enter(",%x,{%llx:%llu},,",
  1666. key_serial(op->key), vp->fid.vid, vp->fid.vnode);
  1667. size = round_up(acl->size, 4);
  1668. call = afs_alloc_flat_call(op->net, &yfs_RXYFSStoreOpaqueACL2,
  1669. sizeof(__be32) * 2 +
  1670. sizeof(struct yfs_xdr_YFSFid) +
  1671. sizeof(__be32) + size,
  1672. sizeof(struct yfs_xdr_YFSFetchStatus) +
  1673. sizeof(struct yfs_xdr_YFSVolSync));
  1674. if (!call)
  1675. return afs_op_nomem(op);
  1676. /* marshall the parameters */
  1677. bp = call->request;
  1678. bp = xdr_encode_u32(bp, YFSSTOREOPAQUEACL2);
  1679. bp = xdr_encode_u32(bp, 0); /* RPC flags */
  1680. bp = xdr_encode_YFSFid(bp, &vp->fid);
  1681. bp = xdr_encode_u32(bp, acl->size);
  1682. memcpy(bp, acl->data, acl->size);
  1683. if (acl->size != size)
  1684. memset((void *)bp + acl->size, 0, size - acl->size);
  1685. bp += size / sizeof(__be32);
  1686. yfs_check_req(call, bp);
  1687. call->fid = vp->fid;
  1688. trace_afs_make_fs_call(call, &vp->fid);
  1689. afs_make_op_call(op, call, GFP_KERNEL);
  1690. }