nfs4xdr.c 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396
  1. /*
  2. * Server-side XDR for NFSv4
  3. *
  4. * Copyright (c) 2002 The Regents of the University of Michigan.
  5. * All rights reserved.
  6. *
  7. * Kendrick Smith <kmsmith@umich.edu>
  8. * Andy Adamson <andros@umich.edu>
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the University nor the names of its
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  30. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * TODO: Neil Brown made the following observation: We currently
  36. * initially reserve NFSD_BUFSIZE space on the transmit queue and
  37. * never release any of that until the request is complete.
  38. * It would be good to calculate a new maximum response size while
  39. * decoding the COMPOUND, and call svc_reserve with this number
  40. * at the end of nfs4svc_decode_compoundargs.
  41. */
  42. #include <linux/slab.h>
  43. #include <linux/namei.h>
  44. #include <linux/statfs.h>
  45. #include <linux/utsname.h>
  46. #include <linux/sunrpc/svcauth_gss.h>
  47. #include "idmap.h"
  48. #include "acl.h"
  49. #include "xdr4.h"
  50. #include "vfs.h"
  51. #define NFSDDBG_FACILITY NFSDDBG_XDR
  52. /*
  53. * As per referral draft, the fsid for a referral MUST be different from the fsid of the containing
  54. * directory in order to indicate to the client that a filesystem boundary is present
  55. * We use a fixed fsid for a referral
  56. */
  57. #define NFS4_REFERRAL_FSID_MAJOR 0x8000000ULL
  58. #define NFS4_REFERRAL_FSID_MINOR 0x8000000ULL
  59. static __be32
  60. check_filename(char *str, int len, __be32 err)
  61. {
  62. int i;
  63. if (len == 0)
  64. return nfserr_inval;
  65. if (isdotent(str, len))
  66. return err;
  67. for (i = 0; i < len; i++)
  68. if (str[i] == '/')
  69. return err;
  70. return 0;
  71. }
  72. #define DECODE_HEAD \
  73. __be32 *p; \
  74. __be32 status
  75. #define DECODE_TAIL \
  76. status = 0; \
  77. out: \
  78. return status; \
  79. xdr_error: \
  80. dprintk("NFSD: xdr error (%s:%d)\n", \
  81. __FILE__, __LINE__); \
  82. status = nfserr_bad_xdr; \
  83. goto out
  84. #define READ32(x) (x) = ntohl(*p++)
  85. #define READ64(x) do { \
  86. (x) = (u64)ntohl(*p++) << 32; \
  87. (x) |= ntohl(*p++); \
  88. } while (0)
  89. #define READTIME(x) do { \
  90. p++; \
  91. (x) = ntohl(*p++); \
  92. p++; \
  93. } while (0)
  94. #define READMEM(x,nbytes) do { \
  95. x = (char *)p; \
  96. p += XDR_QUADLEN(nbytes); \
  97. } while (0)
  98. #define SAVEMEM(x,nbytes) do { \
  99. if (!(x = (p==argp->tmp || p == argp->tmpp) ? \
  100. savemem(argp, p, nbytes) : \
  101. (char *)p)) { \
  102. dprintk("NFSD: xdr error (%s:%d)\n", \
  103. __FILE__, __LINE__); \
  104. goto xdr_error; \
  105. } \
  106. p += XDR_QUADLEN(nbytes); \
  107. } while (0)
  108. #define COPYMEM(x,nbytes) do { \
  109. memcpy((x), p, nbytes); \
  110. p += XDR_QUADLEN(nbytes); \
  111. } while (0)
  112. /* READ_BUF, read_buf(): nbytes must be <= PAGE_SIZE */
  113. #define READ_BUF(nbytes) do { \
  114. if (nbytes <= (u32)((char *)argp->end - (char *)argp->p)) { \
  115. p = argp->p; \
  116. argp->p += XDR_QUADLEN(nbytes); \
  117. } else if (!(p = read_buf(argp, nbytes))) { \
  118. dprintk("NFSD: xdr error (%s:%d)\n", \
  119. __FILE__, __LINE__); \
  120. goto xdr_error; \
  121. } \
  122. } while (0)
  123. static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes)
  124. {
  125. /* We want more bytes than seem to be available.
  126. * Maybe we need a new page, maybe we have just run out
  127. */
  128. unsigned int avail = (char *)argp->end - (char *)argp->p;
  129. __be32 *p;
  130. if (avail + argp->pagelen < nbytes)
  131. return NULL;
  132. if (avail + PAGE_SIZE < nbytes) /* need more than a page !! */
  133. return NULL;
  134. /* ok, we can do it with the current plus the next page */
  135. if (nbytes <= sizeof(argp->tmp))
  136. p = argp->tmp;
  137. else {
  138. kfree(argp->tmpp);
  139. p = argp->tmpp = kmalloc(nbytes, GFP_KERNEL);
  140. if (!p)
  141. return NULL;
  142. }
  143. /*
  144. * The following memcpy is safe because read_buf is always
  145. * called with nbytes > avail, and the two cases above both
  146. * guarantee p points to at least nbytes bytes.
  147. */
  148. memcpy(p, argp->p, avail);
  149. /* step to next page */
  150. argp->p = page_address(argp->pagelist[0]);
  151. argp->pagelist++;
  152. if (argp->pagelen < PAGE_SIZE) {
  153. argp->end = argp->p + (argp->pagelen>>2);
  154. argp->pagelen = 0;
  155. } else {
  156. argp->end = argp->p + (PAGE_SIZE>>2);
  157. argp->pagelen -= PAGE_SIZE;
  158. }
  159. memcpy(((char*)p)+avail, argp->p, (nbytes - avail));
  160. argp->p += XDR_QUADLEN(nbytes - avail);
  161. return p;
  162. }
  163. static int zero_clientid(clientid_t *clid)
  164. {
  165. return (clid->cl_boot == 0) && (clid->cl_id == 0);
  166. }
  167. static int
  168. defer_free(struct nfsd4_compoundargs *argp,
  169. void (*release)(const void *), void *p)
  170. {
  171. struct tmpbuf *tb;
  172. tb = kmalloc(sizeof(*tb), GFP_KERNEL);
  173. if (!tb)
  174. return -ENOMEM;
  175. tb->buf = p;
  176. tb->release = release;
  177. tb->next = argp->to_free;
  178. argp->to_free = tb;
  179. return 0;
  180. }
  181. static char *savemem(struct nfsd4_compoundargs *argp, __be32 *p, int nbytes)
  182. {
  183. if (p == argp->tmp) {
  184. p = kmalloc(nbytes, GFP_KERNEL);
  185. if (!p)
  186. return NULL;
  187. memcpy(p, argp->tmp, nbytes);
  188. } else {
  189. BUG_ON(p != argp->tmpp);
  190. argp->tmpp = NULL;
  191. }
  192. if (defer_free(argp, kfree, p)) {
  193. kfree(p);
  194. return NULL;
  195. } else
  196. return (char *)p;
  197. }
  198. static __be32
  199. nfsd4_decode_bitmap(struct nfsd4_compoundargs *argp, u32 *bmval)
  200. {
  201. u32 bmlen;
  202. DECODE_HEAD;
  203. bmval[0] = 0;
  204. bmval[1] = 0;
  205. bmval[2] = 0;
  206. READ_BUF(4);
  207. READ32(bmlen);
  208. if (bmlen > 1000)
  209. goto xdr_error;
  210. READ_BUF(bmlen << 2);
  211. if (bmlen > 0)
  212. READ32(bmval[0]);
  213. if (bmlen > 1)
  214. READ32(bmval[1]);
  215. if (bmlen > 2)
  216. READ32(bmval[2]);
  217. DECODE_TAIL;
  218. }
  219. static __be32
  220. nfsd4_decode_fattr(struct nfsd4_compoundargs *argp, u32 *bmval,
  221. struct iattr *iattr, struct nfs4_acl **acl)
  222. {
  223. int expected_len, len = 0;
  224. u32 dummy32;
  225. char *buf;
  226. int host_err;
  227. DECODE_HEAD;
  228. iattr->ia_valid = 0;
  229. if ((status = nfsd4_decode_bitmap(argp, bmval)))
  230. return status;
  231. READ_BUF(4);
  232. READ32(expected_len);
  233. if (bmval[0] & FATTR4_WORD0_SIZE) {
  234. READ_BUF(8);
  235. len += 8;
  236. READ64(iattr->ia_size);
  237. iattr->ia_valid |= ATTR_SIZE;
  238. }
  239. if (bmval[0] & FATTR4_WORD0_ACL) {
  240. int nace;
  241. struct nfs4_ace *ace;
  242. READ_BUF(4); len += 4;
  243. READ32(nace);
  244. if (nace > NFS4_ACL_MAX)
  245. return nfserr_resource;
  246. *acl = nfs4_acl_new(nace);
  247. if (*acl == NULL) {
  248. host_err = -ENOMEM;
  249. goto out_nfserr;
  250. }
  251. defer_free(argp, kfree, *acl);
  252. (*acl)->naces = nace;
  253. for (ace = (*acl)->aces; ace < (*acl)->aces + nace; ace++) {
  254. READ_BUF(16); len += 16;
  255. READ32(ace->type);
  256. READ32(ace->flag);
  257. READ32(ace->access_mask);
  258. READ32(dummy32);
  259. READ_BUF(dummy32);
  260. len += XDR_QUADLEN(dummy32) << 2;
  261. READMEM(buf, dummy32);
  262. ace->whotype = nfs4_acl_get_whotype(buf, dummy32);
  263. status = nfs_ok;
  264. if (ace->whotype != NFS4_ACL_WHO_NAMED)
  265. ace->who = 0;
  266. else if (ace->flag & NFS4_ACE_IDENTIFIER_GROUP)
  267. status = nfsd_map_name_to_gid(argp->rqstp,
  268. buf, dummy32, &ace->who);
  269. else
  270. status = nfsd_map_name_to_uid(argp->rqstp,
  271. buf, dummy32, &ace->who);
  272. if (status)
  273. return status;
  274. }
  275. } else
  276. *acl = NULL;
  277. if (bmval[1] & FATTR4_WORD1_MODE) {
  278. READ_BUF(4);
  279. len += 4;
  280. READ32(iattr->ia_mode);
  281. iattr->ia_mode &= (S_IFMT | S_IALLUGO);
  282. iattr->ia_valid |= ATTR_MODE;
  283. }
  284. if (bmval[1] & FATTR4_WORD1_OWNER) {
  285. READ_BUF(4);
  286. len += 4;
  287. READ32(dummy32);
  288. READ_BUF(dummy32);
  289. len += (XDR_QUADLEN(dummy32) << 2);
  290. READMEM(buf, dummy32);
  291. if ((status = nfsd_map_name_to_uid(argp->rqstp, buf, dummy32, &iattr->ia_uid)))
  292. return status;
  293. iattr->ia_valid |= ATTR_UID;
  294. }
  295. if (bmval[1] & FATTR4_WORD1_OWNER_GROUP) {
  296. READ_BUF(4);
  297. len += 4;
  298. READ32(dummy32);
  299. READ_BUF(dummy32);
  300. len += (XDR_QUADLEN(dummy32) << 2);
  301. READMEM(buf, dummy32);
  302. if ((status = nfsd_map_name_to_gid(argp->rqstp, buf, dummy32, &iattr->ia_gid)))
  303. return status;
  304. iattr->ia_valid |= ATTR_GID;
  305. }
  306. if (bmval[1] & FATTR4_WORD1_TIME_ACCESS_SET) {
  307. READ_BUF(4);
  308. len += 4;
  309. READ32(dummy32);
  310. switch (dummy32) {
  311. case NFS4_SET_TO_CLIENT_TIME:
  312. /* We require the high 32 bits of 'seconds' to be 0, and we ignore
  313. all 32 bits of 'nseconds'. */
  314. READ_BUF(12);
  315. len += 12;
  316. READ32(dummy32);
  317. if (dummy32)
  318. return nfserr_inval;
  319. READ32(iattr->ia_atime.tv_sec);
  320. READ32(iattr->ia_atime.tv_nsec);
  321. if (iattr->ia_atime.tv_nsec >= (u32)1000000000)
  322. return nfserr_inval;
  323. iattr->ia_valid |= (ATTR_ATIME | ATTR_ATIME_SET);
  324. break;
  325. case NFS4_SET_TO_SERVER_TIME:
  326. iattr->ia_valid |= ATTR_ATIME;
  327. break;
  328. default:
  329. goto xdr_error;
  330. }
  331. }
  332. if (bmval[1] & FATTR4_WORD1_TIME_MODIFY_SET) {
  333. READ_BUF(4);
  334. len += 4;
  335. READ32(dummy32);
  336. switch (dummy32) {
  337. case NFS4_SET_TO_CLIENT_TIME:
  338. /* We require the high 32 bits of 'seconds' to be 0, and we ignore
  339. all 32 bits of 'nseconds'. */
  340. READ_BUF(12);
  341. len += 12;
  342. READ32(dummy32);
  343. if (dummy32)
  344. return nfserr_inval;
  345. READ32(iattr->ia_mtime.tv_sec);
  346. READ32(iattr->ia_mtime.tv_nsec);
  347. if (iattr->ia_mtime.tv_nsec >= (u32)1000000000)
  348. return nfserr_inval;
  349. iattr->ia_valid |= (ATTR_MTIME | ATTR_MTIME_SET);
  350. break;
  351. case NFS4_SET_TO_SERVER_TIME:
  352. iattr->ia_valid |= ATTR_MTIME;
  353. break;
  354. default:
  355. goto xdr_error;
  356. }
  357. }
  358. if (bmval[0] & ~NFSD_WRITEABLE_ATTRS_WORD0
  359. || bmval[1] & ~NFSD_WRITEABLE_ATTRS_WORD1
  360. || bmval[2] & ~NFSD_WRITEABLE_ATTRS_WORD2)
  361. READ_BUF(expected_len - len);
  362. else if (len != expected_len)
  363. goto xdr_error;
  364. DECODE_TAIL;
  365. out_nfserr:
  366. status = nfserrno(host_err);
  367. goto out;
  368. }
  369. static __be32
  370. nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid)
  371. {
  372. DECODE_HEAD;
  373. READ_BUF(sizeof(stateid_t));
  374. READ32(sid->si_generation);
  375. COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
  376. DECODE_TAIL;
  377. }
  378. static __be32
  379. nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access)
  380. {
  381. DECODE_HEAD;
  382. READ_BUF(4);
  383. READ32(access->ac_req_access);
  384. DECODE_TAIL;
  385. }
  386. static __be32 nfsd4_decode_bind_conn_to_session(struct nfsd4_compoundargs *argp, struct nfsd4_bind_conn_to_session *bcts)
  387. {
  388. DECODE_HEAD;
  389. READ_BUF(NFS4_MAX_SESSIONID_LEN + 8);
  390. COPYMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  391. READ32(bcts->dir);
  392. /* XXX: skipping ctsa_use_conn_in_rdma_mode. Perhaps Tom Tucker
  393. * could help us figure out we should be using it. */
  394. DECODE_TAIL;
  395. }
  396. static __be32
  397. nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close)
  398. {
  399. DECODE_HEAD;
  400. close->cl_stateowner = NULL;
  401. READ_BUF(4);
  402. READ32(close->cl_seqid);
  403. return nfsd4_decode_stateid(argp, &close->cl_stateid);
  404. DECODE_TAIL;
  405. }
  406. static __be32
  407. nfsd4_decode_commit(struct nfsd4_compoundargs *argp, struct nfsd4_commit *commit)
  408. {
  409. DECODE_HEAD;
  410. READ_BUF(12);
  411. READ64(commit->co_offset);
  412. READ32(commit->co_count);
  413. DECODE_TAIL;
  414. }
  415. static __be32
  416. nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create)
  417. {
  418. DECODE_HEAD;
  419. READ_BUF(4);
  420. READ32(create->cr_type);
  421. switch (create->cr_type) {
  422. case NF4LNK:
  423. READ_BUF(4);
  424. READ32(create->cr_linklen);
  425. READ_BUF(create->cr_linklen);
  426. SAVEMEM(create->cr_linkname, create->cr_linklen);
  427. break;
  428. case NF4BLK:
  429. case NF4CHR:
  430. READ_BUF(8);
  431. READ32(create->cr_specdata1);
  432. READ32(create->cr_specdata2);
  433. break;
  434. case NF4SOCK:
  435. case NF4FIFO:
  436. case NF4DIR:
  437. default:
  438. break;
  439. }
  440. READ_BUF(4);
  441. READ32(create->cr_namelen);
  442. READ_BUF(create->cr_namelen);
  443. SAVEMEM(create->cr_name, create->cr_namelen);
  444. if ((status = check_filename(create->cr_name, create->cr_namelen, nfserr_inval)))
  445. return status;
  446. status = nfsd4_decode_fattr(argp, create->cr_bmval, &create->cr_iattr,
  447. &create->cr_acl);
  448. if (status)
  449. goto out;
  450. DECODE_TAIL;
  451. }
  452. static inline __be32
  453. nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr)
  454. {
  455. return nfsd4_decode_stateid(argp, &dr->dr_stateid);
  456. }
  457. static inline __be32
  458. nfsd4_decode_getattr(struct nfsd4_compoundargs *argp, struct nfsd4_getattr *getattr)
  459. {
  460. return nfsd4_decode_bitmap(argp, getattr->ga_bmval);
  461. }
  462. static __be32
  463. nfsd4_decode_link(struct nfsd4_compoundargs *argp, struct nfsd4_link *link)
  464. {
  465. DECODE_HEAD;
  466. READ_BUF(4);
  467. READ32(link->li_namelen);
  468. READ_BUF(link->li_namelen);
  469. SAVEMEM(link->li_name, link->li_namelen);
  470. if ((status = check_filename(link->li_name, link->li_namelen, nfserr_inval)))
  471. return status;
  472. DECODE_TAIL;
  473. }
  474. static __be32
  475. nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock)
  476. {
  477. DECODE_HEAD;
  478. lock->lk_replay_owner = NULL;
  479. /*
  480. * type, reclaim(boolean), offset, length, new_lock_owner(boolean)
  481. */
  482. READ_BUF(28);
  483. READ32(lock->lk_type);
  484. if ((lock->lk_type < NFS4_READ_LT) || (lock->lk_type > NFS4_WRITEW_LT))
  485. goto xdr_error;
  486. READ32(lock->lk_reclaim);
  487. READ64(lock->lk_offset);
  488. READ64(lock->lk_length);
  489. READ32(lock->lk_is_new);
  490. if (lock->lk_is_new) {
  491. READ_BUF(4);
  492. READ32(lock->lk_new_open_seqid);
  493. status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid);
  494. if (status)
  495. return status;
  496. READ_BUF(8 + sizeof(clientid_t));
  497. READ32(lock->lk_new_lock_seqid);
  498. COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t));
  499. READ32(lock->lk_new_owner.len);
  500. READ_BUF(lock->lk_new_owner.len);
  501. READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len);
  502. } else {
  503. status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid);
  504. if (status)
  505. return status;
  506. READ_BUF(4);
  507. READ32(lock->lk_old_lock_seqid);
  508. }
  509. DECODE_TAIL;
  510. }
  511. static __be32
  512. nfsd4_decode_lockt(struct nfsd4_compoundargs *argp, struct nfsd4_lockt *lockt)
  513. {
  514. DECODE_HEAD;
  515. READ_BUF(32);
  516. READ32(lockt->lt_type);
  517. if((lockt->lt_type < NFS4_READ_LT) || (lockt->lt_type > NFS4_WRITEW_LT))
  518. goto xdr_error;
  519. READ64(lockt->lt_offset);
  520. READ64(lockt->lt_length);
  521. COPYMEM(&lockt->lt_clientid, 8);
  522. READ32(lockt->lt_owner.len);
  523. READ_BUF(lockt->lt_owner.len);
  524. READMEM(lockt->lt_owner.data, lockt->lt_owner.len);
  525. DECODE_TAIL;
  526. }
  527. static __be32
  528. nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku)
  529. {
  530. DECODE_HEAD;
  531. locku->lu_stateowner = NULL;
  532. READ_BUF(8);
  533. READ32(locku->lu_type);
  534. if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT))
  535. goto xdr_error;
  536. READ32(locku->lu_seqid);
  537. status = nfsd4_decode_stateid(argp, &locku->lu_stateid);
  538. if (status)
  539. return status;
  540. READ_BUF(16);
  541. READ64(locku->lu_offset);
  542. READ64(locku->lu_length);
  543. DECODE_TAIL;
  544. }
  545. static __be32
  546. nfsd4_decode_lookup(struct nfsd4_compoundargs *argp, struct nfsd4_lookup *lookup)
  547. {
  548. DECODE_HEAD;
  549. READ_BUF(4);
  550. READ32(lookup->lo_len);
  551. READ_BUF(lookup->lo_len);
  552. SAVEMEM(lookup->lo_name, lookup->lo_len);
  553. if ((status = check_filename(lookup->lo_name, lookup->lo_len, nfserr_noent)))
  554. return status;
  555. DECODE_TAIL;
  556. }
  557. static __be32
  558. nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
  559. {
  560. DECODE_HEAD;
  561. memset(open->op_bmval, 0, sizeof(open->op_bmval));
  562. open->op_iattr.ia_valid = 0;
  563. open->op_stateowner = NULL;
  564. /* seqid, share_access, share_deny, clientid, ownerlen */
  565. READ_BUF(16 + sizeof(clientid_t));
  566. READ32(open->op_seqid);
  567. READ32(open->op_share_access);
  568. READ32(open->op_share_deny);
  569. COPYMEM(&open->op_clientid, sizeof(clientid_t));
  570. READ32(open->op_owner.len);
  571. /* owner, open_flag */
  572. READ_BUF(open->op_owner.len + 4);
  573. SAVEMEM(open->op_owner.data, open->op_owner.len);
  574. READ32(open->op_create);
  575. switch (open->op_create) {
  576. case NFS4_OPEN_NOCREATE:
  577. break;
  578. case NFS4_OPEN_CREATE:
  579. READ_BUF(4);
  580. READ32(open->op_createmode);
  581. switch (open->op_createmode) {
  582. case NFS4_CREATE_UNCHECKED:
  583. case NFS4_CREATE_GUARDED:
  584. status = nfsd4_decode_fattr(argp, open->op_bmval,
  585. &open->op_iattr, &open->op_acl);
  586. if (status)
  587. goto out;
  588. break;
  589. case NFS4_CREATE_EXCLUSIVE:
  590. READ_BUF(8);
  591. COPYMEM(open->op_verf.data, 8);
  592. break;
  593. case NFS4_CREATE_EXCLUSIVE4_1:
  594. if (argp->minorversion < 1)
  595. goto xdr_error;
  596. READ_BUF(8);
  597. COPYMEM(open->op_verf.data, 8);
  598. status = nfsd4_decode_fattr(argp, open->op_bmval,
  599. &open->op_iattr, &open->op_acl);
  600. if (status)
  601. goto out;
  602. break;
  603. default:
  604. goto xdr_error;
  605. }
  606. break;
  607. default:
  608. goto xdr_error;
  609. }
  610. /* open_claim */
  611. READ_BUF(4);
  612. READ32(open->op_claim_type);
  613. switch (open->op_claim_type) {
  614. case NFS4_OPEN_CLAIM_NULL:
  615. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  616. READ_BUF(4);
  617. READ32(open->op_fname.len);
  618. READ_BUF(open->op_fname.len);
  619. SAVEMEM(open->op_fname.data, open->op_fname.len);
  620. if ((status = check_filename(open->op_fname.data, open->op_fname.len, nfserr_inval)))
  621. return status;
  622. break;
  623. case NFS4_OPEN_CLAIM_PREVIOUS:
  624. READ_BUF(4);
  625. READ32(open->op_delegate_type);
  626. break;
  627. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  628. status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
  629. if (status)
  630. return status;
  631. READ_BUF(4);
  632. READ32(open->op_fname.len);
  633. READ_BUF(open->op_fname.len);
  634. SAVEMEM(open->op_fname.data, open->op_fname.len);
  635. if ((status = check_filename(open->op_fname.data, open->op_fname.len, nfserr_inval)))
  636. return status;
  637. break;
  638. default:
  639. goto xdr_error;
  640. }
  641. DECODE_TAIL;
  642. }
  643. static __be32
  644. nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_confirm *open_conf)
  645. {
  646. DECODE_HEAD;
  647. open_conf->oc_stateowner = NULL;
  648. status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid);
  649. if (status)
  650. return status;
  651. READ_BUF(4);
  652. READ32(open_conf->oc_seqid);
  653. DECODE_TAIL;
  654. }
  655. static __be32
  656. nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_downgrade *open_down)
  657. {
  658. DECODE_HEAD;
  659. open_down->od_stateowner = NULL;
  660. status = nfsd4_decode_stateid(argp, &open_down->od_stateid);
  661. if (status)
  662. return status;
  663. READ_BUF(12);
  664. READ32(open_down->od_seqid);
  665. READ32(open_down->od_share_access);
  666. READ32(open_down->od_share_deny);
  667. DECODE_TAIL;
  668. }
  669. static __be32
  670. nfsd4_decode_putfh(struct nfsd4_compoundargs *argp, struct nfsd4_putfh *putfh)
  671. {
  672. DECODE_HEAD;
  673. READ_BUF(4);
  674. READ32(putfh->pf_fhlen);
  675. if (putfh->pf_fhlen > NFS4_FHSIZE)
  676. goto xdr_error;
  677. READ_BUF(putfh->pf_fhlen);
  678. SAVEMEM(putfh->pf_fhval, putfh->pf_fhlen);
  679. DECODE_TAIL;
  680. }
  681. static __be32
  682. nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read)
  683. {
  684. DECODE_HEAD;
  685. status = nfsd4_decode_stateid(argp, &read->rd_stateid);
  686. if (status)
  687. return status;
  688. READ_BUF(12);
  689. READ64(read->rd_offset);
  690. READ32(read->rd_length);
  691. DECODE_TAIL;
  692. }
  693. static __be32
  694. nfsd4_decode_readdir(struct nfsd4_compoundargs *argp, struct nfsd4_readdir *readdir)
  695. {
  696. DECODE_HEAD;
  697. READ_BUF(24);
  698. READ64(readdir->rd_cookie);
  699. COPYMEM(readdir->rd_verf.data, sizeof(readdir->rd_verf.data));
  700. READ32(readdir->rd_dircount); /* just in case you needed a useless field... */
  701. READ32(readdir->rd_maxcount);
  702. if ((status = nfsd4_decode_bitmap(argp, readdir->rd_bmval)))
  703. goto out;
  704. DECODE_TAIL;
  705. }
  706. static __be32
  707. nfsd4_decode_remove(struct nfsd4_compoundargs *argp, struct nfsd4_remove *remove)
  708. {
  709. DECODE_HEAD;
  710. READ_BUF(4);
  711. READ32(remove->rm_namelen);
  712. READ_BUF(remove->rm_namelen);
  713. SAVEMEM(remove->rm_name, remove->rm_namelen);
  714. if ((status = check_filename(remove->rm_name, remove->rm_namelen, nfserr_noent)))
  715. return status;
  716. DECODE_TAIL;
  717. }
  718. static __be32
  719. nfsd4_decode_rename(struct nfsd4_compoundargs *argp, struct nfsd4_rename *rename)
  720. {
  721. DECODE_HEAD;
  722. READ_BUF(4);
  723. READ32(rename->rn_snamelen);
  724. READ_BUF(rename->rn_snamelen + 4);
  725. SAVEMEM(rename->rn_sname, rename->rn_snamelen);
  726. READ32(rename->rn_tnamelen);
  727. READ_BUF(rename->rn_tnamelen);
  728. SAVEMEM(rename->rn_tname, rename->rn_tnamelen);
  729. if ((status = check_filename(rename->rn_sname, rename->rn_snamelen, nfserr_noent)))
  730. return status;
  731. if ((status = check_filename(rename->rn_tname, rename->rn_tnamelen, nfserr_inval)))
  732. return status;
  733. DECODE_TAIL;
  734. }
  735. static __be32
  736. nfsd4_decode_renew(struct nfsd4_compoundargs *argp, clientid_t *clientid)
  737. {
  738. DECODE_HEAD;
  739. READ_BUF(sizeof(clientid_t));
  740. COPYMEM(clientid, sizeof(clientid_t));
  741. DECODE_TAIL;
  742. }
  743. static __be32
  744. nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp,
  745. struct nfsd4_secinfo *secinfo)
  746. {
  747. DECODE_HEAD;
  748. READ_BUF(4);
  749. READ32(secinfo->si_namelen);
  750. READ_BUF(secinfo->si_namelen);
  751. SAVEMEM(secinfo->si_name, secinfo->si_namelen);
  752. status = check_filename(secinfo->si_name, secinfo->si_namelen,
  753. nfserr_noent);
  754. if (status)
  755. return status;
  756. DECODE_TAIL;
  757. }
  758. static __be32
  759. nfsd4_decode_secinfo_no_name(struct nfsd4_compoundargs *argp,
  760. struct nfsd4_secinfo_no_name *sin)
  761. {
  762. DECODE_HEAD;
  763. READ_BUF(4);
  764. READ32(sin->sin_style);
  765. DECODE_TAIL;
  766. }
  767. static __be32
  768. nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr)
  769. {
  770. __be32 status;
  771. status = nfsd4_decode_stateid(argp, &setattr->sa_stateid);
  772. if (status)
  773. return status;
  774. return nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr,
  775. &setattr->sa_acl);
  776. }
  777. static __be32
  778. nfsd4_decode_setclientid(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid *setclientid)
  779. {
  780. DECODE_HEAD;
  781. READ_BUF(12);
  782. COPYMEM(setclientid->se_verf.data, 8);
  783. READ32(setclientid->se_namelen);
  784. READ_BUF(setclientid->se_namelen + 8);
  785. SAVEMEM(setclientid->se_name, setclientid->se_namelen);
  786. READ32(setclientid->se_callback_prog);
  787. READ32(setclientid->se_callback_netid_len);
  788. READ_BUF(setclientid->se_callback_netid_len + 4);
  789. SAVEMEM(setclientid->se_callback_netid_val, setclientid->se_callback_netid_len);
  790. READ32(setclientid->se_callback_addr_len);
  791. READ_BUF(setclientid->se_callback_addr_len + 4);
  792. SAVEMEM(setclientid->se_callback_addr_val, setclientid->se_callback_addr_len);
  793. READ32(setclientid->se_callback_ident);
  794. DECODE_TAIL;
  795. }
  796. static __be32
  797. nfsd4_decode_setclientid_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_setclientid_confirm *scd_c)
  798. {
  799. DECODE_HEAD;
  800. READ_BUF(8 + sizeof(nfs4_verifier));
  801. COPYMEM(&scd_c->sc_clientid, 8);
  802. COPYMEM(&scd_c->sc_confirm, sizeof(nfs4_verifier));
  803. DECODE_TAIL;
  804. }
  805. /* Also used for NVERIFY */
  806. static __be32
  807. nfsd4_decode_verify(struct nfsd4_compoundargs *argp, struct nfsd4_verify *verify)
  808. {
  809. #if 0
  810. struct nfsd4_compoundargs save = {
  811. .p = argp->p,
  812. .end = argp->end,
  813. .rqstp = argp->rqstp,
  814. };
  815. u32 ve_bmval[2];
  816. struct iattr ve_iattr; /* request */
  817. struct nfs4_acl *ve_acl; /* request */
  818. #endif
  819. DECODE_HEAD;
  820. if ((status = nfsd4_decode_bitmap(argp, verify->ve_bmval)))
  821. goto out;
  822. /* For convenience's sake, we compare raw xdr'd attributes in
  823. * nfsd4_proc_verify; however we still decode here just to return
  824. * correct error in case of bad xdr. */
  825. #if 0
  826. status = nfsd4_decode_fattr(ve_bmval, &ve_iattr, &ve_acl);
  827. if (status == nfserr_inval) {
  828. status = nfserrno(status);
  829. goto out;
  830. }
  831. #endif
  832. READ_BUF(4);
  833. READ32(verify->ve_attrlen);
  834. READ_BUF(verify->ve_attrlen);
  835. SAVEMEM(verify->ve_attrval, verify->ve_attrlen);
  836. DECODE_TAIL;
  837. }
  838. static __be32
  839. nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write)
  840. {
  841. int avail;
  842. int v;
  843. int len;
  844. DECODE_HEAD;
  845. status = nfsd4_decode_stateid(argp, &write->wr_stateid);
  846. if (status)
  847. return status;
  848. READ_BUF(16);
  849. READ64(write->wr_offset);
  850. READ32(write->wr_stable_how);
  851. if (write->wr_stable_how > 2)
  852. goto xdr_error;
  853. READ32(write->wr_buflen);
  854. /* Sorry .. no magic macros for this.. *
  855. * READ_BUF(write->wr_buflen);
  856. * SAVEMEM(write->wr_buf, write->wr_buflen);
  857. */
  858. avail = (char*)argp->end - (char*)argp->p;
  859. if (avail + argp->pagelen < write->wr_buflen) {
  860. dprintk("NFSD: xdr error (%s:%d)\n",
  861. __FILE__, __LINE__);
  862. goto xdr_error;
  863. }
  864. argp->rqstp->rq_vec[0].iov_base = p;
  865. argp->rqstp->rq_vec[0].iov_len = avail;
  866. v = 0;
  867. len = write->wr_buflen;
  868. while (len > argp->rqstp->rq_vec[v].iov_len) {
  869. len -= argp->rqstp->rq_vec[v].iov_len;
  870. v++;
  871. argp->rqstp->rq_vec[v].iov_base = page_address(argp->pagelist[0]);
  872. argp->pagelist++;
  873. if (argp->pagelen >= PAGE_SIZE) {
  874. argp->rqstp->rq_vec[v].iov_len = PAGE_SIZE;
  875. argp->pagelen -= PAGE_SIZE;
  876. } else {
  877. argp->rqstp->rq_vec[v].iov_len = argp->pagelen;
  878. argp->pagelen -= len;
  879. }
  880. }
  881. argp->end = (__be32*) (argp->rqstp->rq_vec[v].iov_base + argp->rqstp->rq_vec[v].iov_len);
  882. argp->p = (__be32*) (argp->rqstp->rq_vec[v].iov_base + (XDR_QUADLEN(len) << 2));
  883. argp->rqstp->rq_vec[v].iov_len = len;
  884. write->wr_vlen = v+1;
  885. DECODE_TAIL;
  886. }
  887. static __be32
  888. nfsd4_decode_release_lockowner(struct nfsd4_compoundargs *argp, struct nfsd4_release_lockowner *rlockowner)
  889. {
  890. DECODE_HEAD;
  891. READ_BUF(12);
  892. COPYMEM(&rlockowner->rl_clientid, sizeof(clientid_t));
  893. READ32(rlockowner->rl_owner.len);
  894. READ_BUF(rlockowner->rl_owner.len);
  895. READMEM(rlockowner->rl_owner.data, rlockowner->rl_owner.len);
  896. if (argp->minorversion && !zero_clientid(&rlockowner->rl_clientid))
  897. return nfserr_inval;
  898. DECODE_TAIL;
  899. }
  900. static __be32
  901. nfsd4_decode_exchange_id(struct nfsd4_compoundargs *argp,
  902. struct nfsd4_exchange_id *exid)
  903. {
  904. int dummy, tmp;
  905. DECODE_HEAD;
  906. READ_BUF(NFS4_VERIFIER_SIZE);
  907. COPYMEM(exid->verifier.data, NFS4_VERIFIER_SIZE);
  908. READ_BUF(4);
  909. READ32(exid->clname.len);
  910. READ_BUF(exid->clname.len);
  911. SAVEMEM(exid->clname.data, exid->clname.len);
  912. READ_BUF(4);
  913. READ32(exid->flags);
  914. /* Ignore state_protect4_a */
  915. READ_BUF(4);
  916. READ32(exid->spa_how);
  917. switch (exid->spa_how) {
  918. case SP4_NONE:
  919. break;
  920. case SP4_MACH_CRED:
  921. /* spo_must_enforce */
  922. READ_BUF(4);
  923. READ32(dummy);
  924. READ_BUF(dummy * 4);
  925. p += dummy;
  926. /* spo_must_allow */
  927. READ_BUF(4);
  928. READ32(dummy);
  929. READ_BUF(dummy * 4);
  930. p += dummy;
  931. break;
  932. case SP4_SSV:
  933. /* ssp_ops */
  934. READ_BUF(4);
  935. READ32(dummy);
  936. READ_BUF(dummy * 4);
  937. p += dummy;
  938. READ_BUF(4);
  939. READ32(dummy);
  940. READ_BUF(dummy * 4);
  941. p += dummy;
  942. /* ssp_hash_algs<> */
  943. READ_BUF(4);
  944. READ32(tmp);
  945. while (tmp--) {
  946. READ_BUF(4);
  947. READ32(dummy);
  948. READ_BUF(dummy);
  949. p += XDR_QUADLEN(dummy);
  950. }
  951. /* ssp_encr_algs<> */
  952. READ_BUF(4);
  953. READ32(tmp);
  954. while (tmp--) {
  955. READ_BUF(4);
  956. READ32(dummy);
  957. READ_BUF(dummy);
  958. p += XDR_QUADLEN(dummy);
  959. }
  960. /* ssp_window and ssp_num_gss_handles */
  961. READ_BUF(8);
  962. READ32(dummy);
  963. READ32(dummy);
  964. break;
  965. default:
  966. goto xdr_error;
  967. }
  968. /* Ignore Implementation ID */
  969. READ_BUF(4); /* nfs_impl_id4 array length */
  970. READ32(dummy);
  971. if (dummy > 1)
  972. goto xdr_error;
  973. if (dummy == 1) {
  974. /* nii_domain */
  975. READ_BUF(4);
  976. READ32(dummy);
  977. READ_BUF(dummy);
  978. p += XDR_QUADLEN(dummy);
  979. /* nii_name */
  980. READ_BUF(4);
  981. READ32(dummy);
  982. READ_BUF(dummy);
  983. p += XDR_QUADLEN(dummy);
  984. /* nii_date */
  985. READ_BUF(12);
  986. p += 3;
  987. }
  988. DECODE_TAIL;
  989. }
  990. static __be32
  991. nfsd4_decode_create_session(struct nfsd4_compoundargs *argp,
  992. struct nfsd4_create_session *sess)
  993. {
  994. DECODE_HEAD;
  995. u32 dummy;
  996. char *machine_name;
  997. int i;
  998. int nr_secflavs;
  999. READ_BUF(16);
  1000. COPYMEM(&sess->clientid, 8);
  1001. READ32(sess->seqid);
  1002. READ32(sess->flags);
  1003. /* Fore channel attrs */
  1004. READ_BUF(28);
  1005. READ32(dummy); /* headerpadsz is always 0 */
  1006. READ32(sess->fore_channel.maxreq_sz);
  1007. READ32(sess->fore_channel.maxresp_sz);
  1008. READ32(sess->fore_channel.maxresp_cached);
  1009. READ32(sess->fore_channel.maxops);
  1010. READ32(sess->fore_channel.maxreqs);
  1011. READ32(sess->fore_channel.nr_rdma_attrs);
  1012. if (sess->fore_channel.nr_rdma_attrs == 1) {
  1013. READ_BUF(4);
  1014. READ32(sess->fore_channel.rdma_attrs);
  1015. } else if (sess->fore_channel.nr_rdma_attrs > 1) {
  1016. dprintk("Too many fore channel attr bitmaps!\n");
  1017. goto xdr_error;
  1018. }
  1019. /* Back channel attrs */
  1020. READ_BUF(28);
  1021. READ32(dummy); /* headerpadsz is always 0 */
  1022. READ32(sess->back_channel.maxreq_sz);
  1023. READ32(sess->back_channel.maxresp_sz);
  1024. READ32(sess->back_channel.maxresp_cached);
  1025. READ32(sess->back_channel.maxops);
  1026. READ32(sess->back_channel.maxreqs);
  1027. READ32(sess->back_channel.nr_rdma_attrs);
  1028. if (sess->back_channel.nr_rdma_attrs == 1) {
  1029. READ_BUF(4);
  1030. READ32(sess->back_channel.rdma_attrs);
  1031. } else if (sess->back_channel.nr_rdma_attrs > 1) {
  1032. dprintk("Too many back channel attr bitmaps!\n");
  1033. goto xdr_error;
  1034. }
  1035. READ_BUF(8);
  1036. READ32(sess->callback_prog);
  1037. /* callback_sec_params4 */
  1038. READ32(nr_secflavs);
  1039. for (i = 0; i < nr_secflavs; ++i) {
  1040. READ_BUF(4);
  1041. READ32(dummy);
  1042. switch (dummy) {
  1043. case RPC_AUTH_NULL:
  1044. /* Nothing to read */
  1045. break;
  1046. case RPC_AUTH_UNIX:
  1047. READ_BUF(8);
  1048. /* stamp */
  1049. READ32(dummy);
  1050. /* machine name */
  1051. READ32(dummy);
  1052. READ_BUF(dummy);
  1053. SAVEMEM(machine_name, dummy);
  1054. /* uid, gid */
  1055. READ_BUF(8);
  1056. READ32(sess->uid);
  1057. READ32(sess->gid);
  1058. /* more gids */
  1059. READ_BUF(4);
  1060. READ32(dummy);
  1061. READ_BUF(dummy * 4);
  1062. break;
  1063. case RPC_AUTH_GSS:
  1064. dprintk("RPC_AUTH_GSS callback secflavor "
  1065. "not supported!\n");
  1066. READ_BUF(8);
  1067. /* gcbp_service */
  1068. READ32(dummy);
  1069. /* gcbp_handle_from_server */
  1070. READ32(dummy);
  1071. READ_BUF(dummy);
  1072. p += XDR_QUADLEN(dummy);
  1073. /* gcbp_handle_from_client */
  1074. READ_BUF(4);
  1075. READ32(dummy);
  1076. READ_BUF(dummy);
  1077. break;
  1078. default:
  1079. dprintk("Illegal callback secflavor\n");
  1080. return nfserr_inval;
  1081. }
  1082. }
  1083. DECODE_TAIL;
  1084. }
  1085. static __be32
  1086. nfsd4_decode_destroy_session(struct nfsd4_compoundargs *argp,
  1087. struct nfsd4_destroy_session *destroy_session)
  1088. {
  1089. DECODE_HEAD;
  1090. READ_BUF(NFS4_MAX_SESSIONID_LEN);
  1091. COPYMEM(destroy_session->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  1092. DECODE_TAIL;
  1093. }
  1094. static __be32
  1095. nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
  1096. struct nfsd4_sequence *seq)
  1097. {
  1098. DECODE_HEAD;
  1099. READ_BUF(NFS4_MAX_SESSIONID_LEN + 16);
  1100. COPYMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  1101. READ32(seq->seqid);
  1102. READ32(seq->slotid);
  1103. READ32(seq->maxslots);
  1104. READ32(seq->cachethis);
  1105. DECODE_TAIL;
  1106. }
  1107. static __be32 nfsd4_decode_reclaim_complete(struct nfsd4_compoundargs *argp, struct nfsd4_reclaim_complete *rc)
  1108. {
  1109. DECODE_HEAD;
  1110. READ_BUF(4);
  1111. READ32(rc->rca_one_fs);
  1112. DECODE_TAIL;
  1113. }
  1114. static __be32
  1115. nfsd4_decode_noop(struct nfsd4_compoundargs *argp, void *p)
  1116. {
  1117. return nfs_ok;
  1118. }
  1119. static __be32
  1120. nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
  1121. {
  1122. return nfserr_notsupp;
  1123. }
  1124. typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
  1125. static nfsd4_dec nfsd4_dec_ops[] = {
  1126. [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
  1127. [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
  1128. [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
  1129. [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
  1130. [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
  1131. [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
  1132. [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
  1133. [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
  1134. [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
  1135. [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
  1136. [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
  1137. [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
  1138. [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
  1139. [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
  1140. [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
  1141. [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
  1142. [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
  1143. [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_open_confirm,
  1144. [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
  1145. [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
  1146. [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_noop,
  1147. [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
  1148. [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
  1149. [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
  1150. [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
  1151. [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
  1152. [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
  1153. [OP_RENEW] = (nfsd4_dec)nfsd4_decode_renew,
  1154. [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
  1155. [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
  1156. [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
  1157. [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
  1158. [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_setclientid,
  1159. [OP_SETCLIENTID_CONFIRM] = (nfsd4_dec)nfsd4_decode_setclientid_confirm,
  1160. [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
  1161. [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
  1162. [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
  1163. };
  1164. static nfsd4_dec nfsd41_dec_ops[] = {
  1165. [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
  1166. [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
  1167. [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
  1168. [OP_CREATE] = (nfsd4_dec)nfsd4_decode_create,
  1169. [OP_DELEGPURGE] = (nfsd4_dec)nfsd4_decode_notsupp,
  1170. [OP_DELEGRETURN] = (nfsd4_dec)nfsd4_decode_delegreturn,
  1171. [OP_GETATTR] = (nfsd4_dec)nfsd4_decode_getattr,
  1172. [OP_GETFH] = (nfsd4_dec)nfsd4_decode_noop,
  1173. [OP_LINK] = (nfsd4_dec)nfsd4_decode_link,
  1174. [OP_LOCK] = (nfsd4_dec)nfsd4_decode_lock,
  1175. [OP_LOCKT] = (nfsd4_dec)nfsd4_decode_lockt,
  1176. [OP_LOCKU] = (nfsd4_dec)nfsd4_decode_locku,
  1177. [OP_LOOKUP] = (nfsd4_dec)nfsd4_decode_lookup,
  1178. [OP_LOOKUPP] = (nfsd4_dec)nfsd4_decode_noop,
  1179. [OP_NVERIFY] = (nfsd4_dec)nfsd4_decode_verify,
  1180. [OP_OPEN] = (nfsd4_dec)nfsd4_decode_open,
  1181. [OP_OPENATTR] = (nfsd4_dec)nfsd4_decode_notsupp,
  1182. [OP_OPEN_CONFIRM] = (nfsd4_dec)nfsd4_decode_notsupp,
  1183. [OP_OPEN_DOWNGRADE] = (nfsd4_dec)nfsd4_decode_open_downgrade,
  1184. [OP_PUTFH] = (nfsd4_dec)nfsd4_decode_putfh,
  1185. [OP_PUTPUBFH] = (nfsd4_dec)nfsd4_decode_notsupp,
  1186. [OP_PUTROOTFH] = (nfsd4_dec)nfsd4_decode_noop,
  1187. [OP_READ] = (nfsd4_dec)nfsd4_decode_read,
  1188. [OP_READDIR] = (nfsd4_dec)nfsd4_decode_readdir,
  1189. [OP_READLINK] = (nfsd4_dec)nfsd4_decode_noop,
  1190. [OP_REMOVE] = (nfsd4_dec)nfsd4_decode_remove,
  1191. [OP_RENAME] = (nfsd4_dec)nfsd4_decode_rename,
  1192. [OP_RENEW] = (nfsd4_dec)nfsd4_decode_notsupp,
  1193. [OP_RESTOREFH] = (nfsd4_dec)nfsd4_decode_noop,
  1194. [OP_SAVEFH] = (nfsd4_dec)nfsd4_decode_noop,
  1195. [OP_SECINFO] = (nfsd4_dec)nfsd4_decode_secinfo,
  1196. [OP_SETATTR] = (nfsd4_dec)nfsd4_decode_setattr,
  1197. [OP_SETCLIENTID] = (nfsd4_dec)nfsd4_decode_notsupp,
  1198. [OP_SETCLIENTID_CONFIRM]= (nfsd4_dec)nfsd4_decode_notsupp,
  1199. [OP_VERIFY] = (nfsd4_dec)nfsd4_decode_verify,
  1200. [OP_WRITE] = (nfsd4_dec)nfsd4_decode_write,
  1201. [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_notsupp,
  1202. /* new operations for NFSv4.1 */
  1203. [OP_BACKCHANNEL_CTL] = (nfsd4_dec)nfsd4_decode_notsupp,
  1204. [OP_BIND_CONN_TO_SESSION]= (nfsd4_dec)nfsd4_decode_bind_conn_to_session,
  1205. [OP_EXCHANGE_ID] = (nfsd4_dec)nfsd4_decode_exchange_id,
  1206. [OP_CREATE_SESSION] = (nfsd4_dec)nfsd4_decode_create_session,
  1207. [OP_DESTROY_SESSION] = (nfsd4_dec)nfsd4_decode_destroy_session,
  1208. [OP_FREE_STATEID] = (nfsd4_dec)nfsd4_decode_notsupp,
  1209. [OP_GET_DIR_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
  1210. [OP_GETDEVICEINFO] = (nfsd4_dec)nfsd4_decode_notsupp,
  1211. [OP_GETDEVICELIST] = (nfsd4_dec)nfsd4_decode_notsupp,
  1212. [OP_LAYOUTCOMMIT] = (nfsd4_dec)nfsd4_decode_notsupp,
  1213. [OP_LAYOUTGET] = (nfsd4_dec)nfsd4_decode_notsupp,
  1214. [OP_LAYOUTRETURN] = (nfsd4_dec)nfsd4_decode_notsupp,
  1215. [OP_SECINFO_NO_NAME] = (nfsd4_dec)nfsd4_decode_secinfo_no_name,
  1216. [OP_SEQUENCE] = (nfsd4_dec)nfsd4_decode_sequence,
  1217. [OP_SET_SSV] = (nfsd4_dec)nfsd4_decode_notsupp,
  1218. [OP_TEST_STATEID] = (nfsd4_dec)nfsd4_decode_notsupp,
  1219. [OP_WANT_DELEGATION] = (nfsd4_dec)nfsd4_decode_notsupp,
  1220. [OP_DESTROY_CLIENTID] = (nfsd4_dec)nfsd4_decode_notsupp,
  1221. [OP_RECLAIM_COMPLETE] = (nfsd4_dec)nfsd4_decode_reclaim_complete,
  1222. };
  1223. struct nfsd4_minorversion_ops {
  1224. nfsd4_dec *decoders;
  1225. int nops;
  1226. };
  1227. static struct nfsd4_minorversion_ops nfsd4_minorversion[] = {
  1228. [0] = { nfsd4_dec_ops, ARRAY_SIZE(nfsd4_dec_ops) },
  1229. [1] = { nfsd41_dec_ops, ARRAY_SIZE(nfsd41_dec_ops) },
  1230. };
  1231. static __be32
  1232. nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
  1233. {
  1234. DECODE_HEAD;
  1235. struct nfsd4_op *op;
  1236. struct nfsd4_minorversion_ops *ops;
  1237. int i;
  1238. /*
  1239. * XXX: According to spec, we should check the tag
  1240. * for UTF-8 compliance. I'm postponing this for
  1241. * now because it seems that some clients do use
  1242. * binary tags.
  1243. */
  1244. READ_BUF(4);
  1245. READ32(argp->taglen);
  1246. READ_BUF(argp->taglen + 8);
  1247. SAVEMEM(argp->tag, argp->taglen);
  1248. READ32(argp->minorversion);
  1249. READ32(argp->opcnt);
  1250. if (argp->taglen > NFSD4_MAX_TAGLEN)
  1251. goto xdr_error;
  1252. if (argp->opcnt > 100)
  1253. goto xdr_error;
  1254. if (argp->opcnt > ARRAY_SIZE(argp->iops)) {
  1255. argp->ops = kmalloc(argp->opcnt * sizeof(*argp->ops), GFP_KERNEL);
  1256. if (!argp->ops) {
  1257. argp->ops = argp->iops;
  1258. dprintk("nfsd: couldn't allocate room for COMPOUND\n");
  1259. goto xdr_error;
  1260. }
  1261. }
  1262. if (argp->minorversion >= ARRAY_SIZE(nfsd4_minorversion))
  1263. argp->opcnt = 0;
  1264. ops = &nfsd4_minorversion[argp->minorversion];
  1265. for (i = 0; i < argp->opcnt; i++) {
  1266. op = &argp->ops[i];
  1267. op->replay = NULL;
  1268. /*
  1269. * We can't use READ_BUF() here because we need to handle
  1270. * a missing opcode as an OP_WRITE + 1. So we need to check
  1271. * to see if we're truly at the end of our buffer or if there
  1272. * is another page we need to flip to.
  1273. */
  1274. if (argp->p == argp->end) {
  1275. if (argp->pagelen < 4) {
  1276. /* There isn't an opcode still on the wire */
  1277. op->opnum = OP_WRITE + 1;
  1278. op->status = nfserr_bad_xdr;
  1279. argp->opcnt = i+1;
  1280. break;
  1281. }
  1282. /*
  1283. * False alarm. We just hit a page boundary, but there
  1284. * is still data available. Move pointer across page
  1285. * boundary. *snip from READ_BUF*
  1286. */
  1287. argp->p = page_address(argp->pagelist[0]);
  1288. argp->pagelist++;
  1289. if (argp->pagelen < PAGE_SIZE) {
  1290. argp->end = argp->p + (argp->pagelen>>2);
  1291. argp->pagelen = 0;
  1292. } else {
  1293. argp->end = argp->p + (PAGE_SIZE>>2);
  1294. argp->pagelen -= PAGE_SIZE;
  1295. }
  1296. }
  1297. op->opnum = ntohl(*argp->p++);
  1298. if (op->opnum >= FIRST_NFS4_OP && op->opnum <= LAST_NFS4_OP)
  1299. op->status = ops->decoders[op->opnum](argp, &op->u);
  1300. else {
  1301. op->opnum = OP_ILLEGAL;
  1302. op->status = nfserr_op_illegal;
  1303. }
  1304. if (op->status) {
  1305. argp->opcnt = i+1;
  1306. break;
  1307. }
  1308. }
  1309. DECODE_TAIL;
  1310. }
  1311. #define WRITE32(n) *p++ = htonl(n)
  1312. #define WRITE64(n) do { \
  1313. *p++ = htonl((u32)((n) >> 32)); \
  1314. *p++ = htonl((u32)(n)); \
  1315. } while (0)
  1316. #define WRITEMEM(ptr,nbytes) do { if (nbytes > 0) { \
  1317. *(p + XDR_QUADLEN(nbytes) -1) = 0; \
  1318. memcpy(p, ptr, nbytes); \
  1319. p += XDR_QUADLEN(nbytes); \
  1320. }} while (0)
  1321. static void write32(__be32 **p, u32 n)
  1322. {
  1323. *(*p)++ = n;
  1324. }
  1325. static void write64(__be32 **p, u64 n)
  1326. {
  1327. write32(p, (u32)(n >> 32));
  1328. write32(p, (u32)n);
  1329. }
  1330. static void write_change(__be32 **p, struct kstat *stat, struct inode *inode)
  1331. {
  1332. if (IS_I_VERSION(inode)) {
  1333. write64(p, inode->i_version);
  1334. } else {
  1335. write32(p, stat->ctime.tv_sec);
  1336. write32(p, stat->ctime.tv_nsec);
  1337. }
  1338. }
  1339. static void write_cinfo(__be32 **p, struct nfsd4_change_info *c)
  1340. {
  1341. write32(p, c->atomic);
  1342. if (c->change_supported) {
  1343. write64(p, c->before_change);
  1344. write64(p, c->after_change);
  1345. } else {
  1346. write32(p, c->before_ctime_sec);
  1347. write32(p, c->before_ctime_nsec);
  1348. write32(p, c->after_ctime_sec);
  1349. write32(p, c->after_ctime_nsec);
  1350. }
  1351. }
  1352. #define RESERVE_SPACE(nbytes) do { \
  1353. p = resp->p; \
  1354. BUG_ON(p + XDR_QUADLEN(nbytes) > resp->end); \
  1355. } while (0)
  1356. #define ADJUST_ARGS() resp->p = p
  1357. /*
  1358. * Header routine to setup seqid operation replay cache
  1359. */
  1360. #define ENCODE_SEQID_OP_HEAD \
  1361. __be32 *save; \
  1362. \
  1363. save = resp->p;
  1364. /*
  1365. * Routine for encoding the result of a "seqid-mutating" NFSv4 operation. This
  1366. * is where sequence id's are incremented, and the replay cache is filled.
  1367. * Note that we increment sequence id's here, at the last moment, so we're sure
  1368. * we know whether the error to be returned is a sequence id mutating error.
  1369. */
  1370. #define ENCODE_SEQID_OP_TAIL(stateowner) do { \
  1371. if (seqid_mutating_err(nfserr) && stateowner) { \
  1372. stateowner->so_seqid++; \
  1373. stateowner->so_replay.rp_status = nfserr; \
  1374. stateowner->so_replay.rp_buflen = \
  1375. (((char *)(resp)->p - (char *)save)); \
  1376. memcpy(stateowner->so_replay.rp_buf, save, \
  1377. stateowner->so_replay.rp_buflen); \
  1378. } } while (0);
  1379. /* Encode as an array of strings the string given with components
  1380. * separated @sep.
  1381. */
  1382. static __be32 nfsd4_encode_components(char sep, char *components,
  1383. __be32 **pp, int *buflen)
  1384. {
  1385. __be32 *p = *pp;
  1386. __be32 *countp = p;
  1387. int strlen, count=0;
  1388. char *str, *end;
  1389. dprintk("nfsd4_encode_components(%s)\n", components);
  1390. if ((*buflen -= 4) < 0)
  1391. return nfserr_resource;
  1392. WRITE32(0); /* We will fill this in with @count later */
  1393. end = str = components;
  1394. while (*end) {
  1395. for (; *end && (*end != sep); end++)
  1396. ; /* Point to end of component */
  1397. strlen = end - str;
  1398. if (strlen) {
  1399. if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
  1400. return nfserr_resource;
  1401. WRITE32(strlen);
  1402. WRITEMEM(str, strlen);
  1403. count++;
  1404. }
  1405. else
  1406. end++;
  1407. str = end;
  1408. }
  1409. *pp = p;
  1410. p = countp;
  1411. WRITE32(count);
  1412. return 0;
  1413. }
  1414. /*
  1415. * encode a location element of a fs_locations structure
  1416. */
  1417. static __be32 nfsd4_encode_fs_location4(struct nfsd4_fs_location *location,
  1418. __be32 **pp, int *buflen)
  1419. {
  1420. __be32 status;
  1421. __be32 *p = *pp;
  1422. status = nfsd4_encode_components(':', location->hosts, &p, buflen);
  1423. if (status)
  1424. return status;
  1425. status = nfsd4_encode_components('/', location->path, &p, buflen);
  1426. if (status)
  1427. return status;
  1428. *pp = p;
  1429. return 0;
  1430. }
  1431. /*
  1432. * Return the path to an export point in the pseudo filesystem namespace
  1433. * Returned string is safe to use as long as the caller holds a reference
  1434. * to @exp.
  1435. */
  1436. static char *nfsd4_path(struct svc_rqst *rqstp, struct svc_export *exp, __be32 *stat)
  1437. {
  1438. struct svc_fh tmp_fh;
  1439. char *path = NULL, *rootpath;
  1440. size_t rootlen;
  1441. fh_init(&tmp_fh, NFS4_FHSIZE);
  1442. *stat = exp_pseudoroot(rqstp, &tmp_fh);
  1443. if (*stat)
  1444. return NULL;
  1445. rootpath = tmp_fh.fh_export->ex_pathname;
  1446. path = exp->ex_pathname;
  1447. rootlen = strlen(rootpath);
  1448. if (strncmp(path, rootpath, rootlen)) {
  1449. dprintk("nfsd: fs_locations failed;"
  1450. "%s is not contained in %s\n", path, rootpath);
  1451. *stat = nfserr_notsupp;
  1452. path = NULL;
  1453. goto out;
  1454. }
  1455. path += rootlen;
  1456. out:
  1457. fh_put(&tmp_fh);
  1458. return path;
  1459. }
  1460. /*
  1461. * encode a fs_locations structure
  1462. */
  1463. static __be32 nfsd4_encode_fs_locations(struct svc_rqst *rqstp,
  1464. struct svc_export *exp,
  1465. __be32 **pp, int *buflen)
  1466. {
  1467. __be32 status;
  1468. int i;
  1469. __be32 *p = *pp;
  1470. struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
  1471. char *root = nfsd4_path(rqstp, exp, &status);
  1472. if (status)
  1473. return status;
  1474. status = nfsd4_encode_components('/', root, &p, buflen);
  1475. if (status)
  1476. return status;
  1477. if ((*buflen -= 4) < 0)
  1478. return nfserr_resource;
  1479. WRITE32(fslocs->locations_count);
  1480. for (i=0; i<fslocs->locations_count; i++) {
  1481. status = nfsd4_encode_fs_location4(&fslocs->locations[i],
  1482. &p, buflen);
  1483. if (status)
  1484. return status;
  1485. }
  1486. *pp = p;
  1487. return 0;
  1488. }
  1489. static u32 nfs4_ftypes[16] = {
  1490. NF4BAD, NF4FIFO, NF4CHR, NF4BAD,
  1491. NF4DIR, NF4BAD, NF4BLK, NF4BAD,
  1492. NF4REG, NF4BAD, NF4LNK, NF4BAD,
  1493. NF4SOCK, NF4BAD, NF4LNK, NF4BAD,
  1494. };
  1495. static __be32
  1496. nfsd4_encode_name(struct svc_rqst *rqstp, int whotype, uid_t id, int group,
  1497. __be32 **p, int *buflen)
  1498. {
  1499. int status;
  1500. if (*buflen < (XDR_QUADLEN(IDMAP_NAMESZ) << 2) + 4)
  1501. return nfserr_resource;
  1502. if (whotype != NFS4_ACL_WHO_NAMED)
  1503. status = nfs4_acl_write_who(whotype, (u8 *)(*p + 1));
  1504. else if (group)
  1505. status = nfsd_map_gid_to_name(rqstp, id, (u8 *)(*p + 1));
  1506. else
  1507. status = nfsd_map_uid_to_name(rqstp, id, (u8 *)(*p + 1));
  1508. if (status < 0)
  1509. return nfserrno(status);
  1510. *p = xdr_encode_opaque(*p, NULL, status);
  1511. *buflen -= (XDR_QUADLEN(status) << 2) + 4;
  1512. BUG_ON(*buflen < 0);
  1513. return 0;
  1514. }
  1515. static inline __be32
  1516. nfsd4_encode_user(struct svc_rqst *rqstp, uid_t uid, __be32 **p, int *buflen)
  1517. {
  1518. return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, uid, 0, p, buflen);
  1519. }
  1520. static inline __be32
  1521. nfsd4_encode_group(struct svc_rqst *rqstp, uid_t gid, __be32 **p, int *buflen)
  1522. {
  1523. return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, gid, 1, p, buflen);
  1524. }
  1525. static inline __be32
  1526. nfsd4_encode_aclname(struct svc_rqst *rqstp, int whotype, uid_t id, int group,
  1527. __be32 **p, int *buflen)
  1528. {
  1529. return nfsd4_encode_name(rqstp, whotype, id, group, p, buflen);
  1530. }
  1531. #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
  1532. FATTR4_WORD0_RDATTR_ERROR)
  1533. #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
  1534. static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err)
  1535. {
  1536. /* As per referral draft: */
  1537. if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS ||
  1538. *bmval1 & ~WORD1_ABSENT_FS_ATTRS) {
  1539. if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR ||
  1540. *bmval0 & FATTR4_WORD0_FS_LOCATIONS)
  1541. *rdattr_err = NFSERR_MOVED;
  1542. else
  1543. return nfserr_moved;
  1544. }
  1545. *bmval0 &= WORD0_ABSENT_FS_ATTRS;
  1546. *bmval1 &= WORD1_ABSENT_FS_ATTRS;
  1547. return 0;
  1548. }
  1549. /*
  1550. * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  1551. * ourselves.
  1552. *
  1553. * @countp is the buffer size in _words_; upon successful return this becomes
  1554. * replaced with the number of words written.
  1555. */
  1556. __be32
  1557. nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
  1558. struct dentry *dentry, __be32 *buffer, int *countp, u32 *bmval,
  1559. struct svc_rqst *rqstp, int ignore_crossmnt)
  1560. {
  1561. u32 bmval0 = bmval[0];
  1562. u32 bmval1 = bmval[1];
  1563. u32 bmval2 = bmval[2];
  1564. struct kstat stat;
  1565. struct svc_fh tempfh;
  1566. struct kstatfs statfs;
  1567. int buflen = *countp << 2;
  1568. __be32 *attrlenp;
  1569. u32 dummy;
  1570. u64 dummy64;
  1571. u32 rdattr_err = 0;
  1572. __be32 *p = buffer;
  1573. __be32 status;
  1574. int err;
  1575. int aclsupport = 0;
  1576. struct nfs4_acl *acl = NULL;
  1577. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  1578. u32 minorversion = resp->cstate.minorversion;
  1579. struct path path = {
  1580. .mnt = exp->ex_path.mnt,
  1581. .dentry = dentry,
  1582. };
  1583. BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
  1584. BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
  1585. BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
  1586. BUG_ON(bmval2 & ~nfsd_suppattrs2(minorversion));
  1587. if (exp->ex_fslocs.migrated) {
  1588. BUG_ON(bmval[2]);
  1589. status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err);
  1590. if (status)
  1591. goto out;
  1592. }
  1593. err = vfs_getattr(exp->ex_path.mnt, dentry, &stat);
  1594. if (err)
  1595. goto out_nfserr;
  1596. if ((bmval0 & (FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL |
  1597. FATTR4_WORD0_MAXNAME)) ||
  1598. (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
  1599. FATTR4_WORD1_SPACE_TOTAL))) {
  1600. err = vfs_statfs(&path, &statfs);
  1601. if (err)
  1602. goto out_nfserr;
  1603. }
  1604. if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) {
  1605. fh_init(&tempfh, NFS4_FHSIZE);
  1606. status = fh_compose(&tempfh, exp, dentry, NULL);
  1607. if (status)
  1608. goto out;
  1609. fhp = &tempfh;
  1610. }
  1611. if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT
  1612. | FATTR4_WORD0_SUPPORTED_ATTRS)) {
  1613. err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl);
  1614. aclsupport = (err == 0);
  1615. if (bmval0 & FATTR4_WORD0_ACL) {
  1616. if (err == -EOPNOTSUPP)
  1617. bmval0 &= ~FATTR4_WORD0_ACL;
  1618. else if (err == -EINVAL) {
  1619. status = nfserr_attrnotsupp;
  1620. goto out;
  1621. } else if (err != 0)
  1622. goto out_nfserr;
  1623. }
  1624. }
  1625. if (bmval2) {
  1626. if ((buflen -= 16) < 0)
  1627. goto out_resource;
  1628. WRITE32(3);
  1629. WRITE32(bmval0);
  1630. WRITE32(bmval1);
  1631. WRITE32(bmval2);
  1632. } else if (bmval1) {
  1633. if ((buflen -= 12) < 0)
  1634. goto out_resource;
  1635. WRITE32(2);
  1636. WRITE32(bmval0);
  1637. WRITE32(bmval1);
  1638. } else {
  1639. if ((buflen -= 8) < 0)
  1640. goto out_resource;
  1641. WRITE32(1);
  1642. WRITE32(bmval0);
  1643. }
  1644. attrlenp = p++; /* to be backfilled later */
  1645. if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
  1646. u32 word0 = nfsd_suppattrs0(minorversion);
  1647. u32 word1 = nfsd_suppattrs1(minorversion);
  1648. u32 word2 = nfsd_suppattrs2(minorversion);
  1649. if (!aclsupport)
  1650. word0 &= ~FATTR4_WORD0_ACL;
  1651. if (!word2) {
  1652. if ((buflen -= 12) < 0)
  1653. goto out_resource;
  1654. WRITE32(2);
  1655. WRITE32(word0);
  1656. WRITE32(word1);
  1657. } else {
  1658. if ((buflen -= 16) < 0)
  1659. goto out_resource;
  1660. WRITE32(3);
  1661. WRITE32(word0);
  1662. WRITE32(word1);
  1663. WRITE32(word2);
  1664. }
  1665. }
  1666. if (bmval0 & FATTR4_WORD0_TYPE) {
  1667. if ((buflen -= 4) < 0)
  1668. goto out_resource;
  1669. dummy = nfs4_ftypes[(stat.mode & S_IFMT) >> 12];
  1670. if (dummy == NF4BAD)
  1671. goto out_serverfault;
  1672. WRITE32(dummy);
  1673. }
  1674. if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
  1675. if ((buflen -= 4) < 0)
  1676. goto out_resource;
  1677. if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
  1678. WRITE32(NFS4_FH_PERSISTENT);
  1679. else
  1680. WRITE32(NFS4_FH_PERSISTENT|NFS4_FH_VOL_RENAME);
  1681. }
  1682. if (bmval0 & FATTR4_WORD0_CHANGE) {
  1683. if ((buflen -= 8) < 0)
  1684. goto out_resource;
  1685. write_change(&p, &stat, dentry->d_inode);
  1686. }
  1687. if (bmval0 & FATTR4_WORD0_SIZE) {
  1688. if ((buflen -= 8) < 0)
  1689. goto out_resource;
  1690. WRITE64(stat.size);
  1691. }
  1692. if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
  1693. if ((buflen -= 4) < 0)
  1694. goto out_resource;
  1695. WRITE32(1);
  1696. }
  1697. if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) {
  1698. if ((buflen -= 4) < 0)
  1699. goto out_resource;
  1700. WRITE32(1);
  1701. }
  1702. if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
  1703. if ((buflen -= 4) < 0)
  1704. goto out_resource;
  1705. WRITE32(0);
  1706. }
  1707. if (bmval0 & FATTR4_WORD0_FSID) {
  1708. if ((buflen -= 16) < 0)
  1709. goto out_resource;
  1710. if (exp->ex_fslocs.migrated) {
  1711. WRITE64(NFS4_REFERRAL_FSID_MAJOR);
  1712. WRITE64(NFS4_REFERRAL_FSID_MINOR);
  1713. } else switch(fsid_source(fhp)) {
  1714. case FSIDSOURCE_FSID:
  1715. WRITE64((u64)exp->ex_fsid);
  1716. WRITE64((u64)0);
  1717. break;
  1718. case FSIDSOURCE_DEV:
  1719. WRITE32(0);
  1720. WRITE32(MAJOR(stat.dev));
  1721. WRITE32(0);
  1722. WRITE32(MINOR(stat.dev));
  1723. break;
  1724. case FSIDSOURCE_UUID:
  1725. WRITEMEM(exp->ex_uuid, 16);
  1726. break;
  1727. }
  1728. }
  1729. if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
  1730. if ((buflen -= 4) < 0)
  1731. goto out_resource;
  1732. WRITE32(0);
  1733. }
  1734. if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
  1735. if ((buflen -= 4) < 0)
  1736. goto out_resource;
  1737. WRITE32(nfsd4_lease);
  1738. }
  1739. if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
  1740. if ((buflen -= 4) < 0)
  1741. goto out_resource;
  1742. WRITE32(rdattr_err);
  1743. }
  1744. if (bmval0 & FATTR4_WORD0_ACL) {
  1745. struct nfs4_ace *ace;
  1746. if (acl == NULL) {
  1747. if ((buflen -= 4) < 0)
  1748. goto out_resource;
  1749. WRITE32(0);
  1750. goto out_acl;
  1751. }
  1752. if ((buflen -= 4) < 0)
  1753. goto out_resource;
  1754. WRITE32(acl->naces);
  1755. for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
  1756. if ((buflen -= 4*3) < 0)
  1757. goto out_resource;
  1758. WRITE32(ace->type);
  1759. WRITE32(ace->flag);
  1760. WRITE32(ace->access_mask & NFS4_ACE_MASK_ALL);
  1761. status = nfsd4_encode_aclname(rqstp, ace->whotype,
  1762. ace->who, ace->flag & NFS4_ACE_IDENTIFIER_GROUP,
  1763. &p, &buflen);
  1764. if (status == nfserr_resource)
  1765. goto out_resource;
  1766. if (status)
  1767. goto out;
  1768. }
  1769. }
  1770. out_acl:
  1771. if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
  1772. if ((buflen -= 4) < 0)
  1773. goto out_resource;
  1774. WRITE32(aclsupport ?
  1775. ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0);
  1776. }
  1777. if (bmval0 & FATTR4_WORD0_CANSETTIME) {
  1778. if ((buflen -= 4) < 0)
  1779. goto out_resource;
  1780. WRITE32(1);
  1781. }
  1782. if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
  1783. if ((buflen -= 4) < 0)
  1784. goto out_resource;
  1785. WRITE32(1);
  1786. }
  1787. if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
  1788. if ((buflen -= 4) < 0)
  1789. goto out_resource;
  1790. WRITE32(1);
  1791. }
  1792. if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) {
  1793. if ((buflen -= 4) < 0)
  1794. goto out_resource;
  1795. WRITE32(1);
  1796. }
  1797. if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
  1798. buflen -= (XDR_QUADLEN(fhp->fh_handle.fh_size) << 2) + 4;
  1799. if (buflen < 0)
  1800. goto out_resource;
  1801. WRITE32(fhp->fh_handle.fh_size);
  1802. WRITEMEM(&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size);
  1803. }
  1804. if (bmval0 & FATTR4_WORD0_FILEID) {
  1805. if ((buflen -= 8) < 0)
  1806. goto out_resource;
  1807. WRITE64(stat.ino);
  1808. }
  1809. if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
  1810. if ((buflen -= 8) < 0)
  1811. goto out_resource;
  1812. WRITE64((u64) statfs.f_ffree);
  1813. }
  1814. if (bmval0 & FATTR4_WORD0_FILES_FREE) {
  1815. if ((buflen -= 8) < 0)
  1816. goto out_resource;
  1817. WRITE64((u64) statfs.f_ffree);
  1818. }
  1819. if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
  1820. if ((buflen -= 8) < 0)
  1821. goto out_resource;
  1822. WRITE64((u64) statfs.f_files);
  1823. }
  1824. if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
  1825. status = nfsd4_encode_fs_locations(rqstp, exp, &p, &buflen);
  1826. if (status == nfserr_resource)
  1827. goto out_resource;
  1828. if (status)
  1829. goto out;
  1830. }
  1831. if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {
  1832. if ((buflen -= 4) < 0)
  1833. goto out_resource;
  1834. WRITE32(1);
  1835. }
  1836. if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
  1837. if ((buflen -= 8) < 0)
  1838. goto out_resource;
  1839. WRITE64(~(u64)0);
  1840. }
  1841. if (bmval0 & FATTR4_WORD0_MAXLINK) {
  1842. if ((buflen -= 4) < 0)
  1843. goto out_resource;
  1844. WRITE32(255);
  1845. }
  1846. if (bmval0 & FATTR4_WORD0_MAXNAME) {
  1847. if ((buflen -= 4) < 0)
  1848. goto out_resource;
  1849. WRITE32(statfs.f_namelen);
  1850. }
  1851. if (bmval0 & FATTR4_WORD0_MAXREAD) {
  1852. if ((buflen -= 8) < 0)
  1853. goto out_resource;
  1854. WRITE64((u64) svc_max_payload(rqstp));
  1855. }
  1856. if (bmval0 & FATTR4_WORD0_MAXWRITE) {
  1857. if ((buflen -= 8) < 0)
  1858. goto out_resource;
  1859. WRITE64((u64) svc_max_payload(rqstp));
  1860. }
  1861. if (bmval1 & FATTR4_WORD1_MODE) {
  1862. if ((buflen -= 4) < 0)
  1863. goto out_resource;
  1864. WRITE32(stat.mode & S_IALLUGO);
  1865. }
  1866. if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
  1867. if ((buflen -= 4) < 0)
  1868. goto out_resource;
  1869. WRITE32(1);
  1870. }
  1871. if (bmval1 & FATTR4_WORD1_NUMLINKS) {
  1872. if ((buflen -= 4) < 0)
  1873. goto out_resource;
  1874. WRITE32(stat.nlink);
  1875. }
  1876. if (bmval1 & FATTR4_WORD1_OWNER) {
  1877. status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
  1878. if (status == nfserr_resource)
  1879. goto out_resource;
  1880. if (status)
  1881. goto out;
  1882. }
  1883. if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
  1884. status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
  1885. if (status == nfserr_resource)
  1886. goto out_resource;
  1887. if (status)
  1888. goto out;
  1889. }
  1890. if (bmval1 & FATTR4_WORD1_RAWDEV) {
  1891. if ((buflen -= 8) < 0)
  1892. goto out_resource;
  1893. WRITE32((u32) MAJOR(stat.rdev));
  1894. WRITE32((u32) MINOR(stat.rdev));
  1895. }
  1896. if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
  1897. if ((buflen -= 8) < 0)
  1898. goto out_resource;
  1899. dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize;
  1900. WRITE64(dummy64);
  1901. }
  1902. if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
  1903. if ((buflen -= 8) < 0)
  1904. goto out_resource;
  1905. dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize;
  1906. WRITE64(dummy64);
  1907. }
  1908. if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
  1909. if ((buflen -= 8) < 0)
  1910. goto out_resource;
  1911. dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize;
  1912. WRITE64(dummy64);
  1913. }
  1914. if (bmval1 & FATTR4_WORD1_SPACE_USED) {
  1915. if ((buflen -= 8) < 0)
  1916. goto out_resource;
  1917. dummy64 = (u64)stat.blocks << 9;
  1918. WRITE64(dummy64);
  1919. }
  1920. if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
  1921. if ((buflen -= 12) < 0)
  1922. goto out_resource;
  1923. WRITE32(0);
  1924. WRITE32(stat.atime.tv_sec);
  1925. WRITE32(stat.atime.tv_nsec);
  1926. }
  1927. if (bmval1 & FATTR4_WORD1_TIME_DELTA) {
  1928. if ((buflen -= 12) < 0)
  1929. goto out_resource;
  1930. WRITE32(0);
  1931. WRITE32(1);
  1932. WRITE32(0);
  1933. }
  1934. if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
  1935. if ((buflen -= 12) < 0)
  1936. goto out_resource;
  1937. WRITE32(0);
  1938. WRITE32(stat.ctime.tv_sec);
  1939. WRITE32(stat.ctime.tv_nsec);
  1940. }
  1941. if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
  1942. if ((buflen -= 12) < 0)
  1943. goto out_resource;
  1944. WRITE32(0);
  1945. WRITE32(stat.mtime.tv_sec);
  1946. WRITE32(stat.mtime.tv_nsec);
  1947. }
  1948. if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
  1949. if ((buflen -= 8) < 0)
  1950. goto out_resource;
  1951. /*
  1952. * Get parent's attributes if not ignoring crossmount
  1953. * and this is the root of a cross-mounted filesystem.
  1954. */
  1955. if (ignore_crossmnt == 0 &&
  1956. dentry == exp->ex_path.mnt->mnt_root) {
  1957. struct path path = exp->ex_path;
  1958. path_get(&path);
  1959. while (follow_up(&path)) {
  1960. if (path.dentry != path.mnt->mnt_root)
  1961. break;
  1962. }
  1963. err = vfs_getattr(path.mnt, path.dentry, &stat);
  1964. path_put(&path);
  1965. if (err)
  1966. goto out_nfserr;
  1967. }
  1968. WRITE64(stat.ino);
  1969. }
  1970. if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
  1971. WRITE32(3);
  1972. WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0);
  1973. WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD1);
  1974. WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD2);
  1975. }
  1976. *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
  1977. *countp = p - buffer;
  1978. status = nfs_ok;
  1979. out:
  1980. kfree(acl);
  1981. if (fhp == &tempfh)
  1982. fh_put(&tempfh);
  1983. return status;
  1984. out_nfserr:
  1985. status = nfserrno(err);
  1986. goto out;
  1987. out_resource:
  1988. *countp = 0;
  1989. status = nfserr_resource;
  1990. goto out;
  1991. out_serverfault:
  1992. status = nfserr_serverfault;
  1993. goto out;
  1994. }
  1995. static inline int attributes_need_mount(u32 *bmval)
  1996. {
  1997. if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
  1998. return 1;
  1999. if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
  2000. return 1;
  2001. return 0;
  2002. }
  2003. static __be32
  2004. nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
  2005. const char *name, int namlen, __be32 *p, int *buflen)
  2006. {
  2007. struct svc_export *exp = cd->rd_fhp->fh_export;
  2008. struct dentry *dentry;
  2009. __be32 nfserr;
  2010. int ignore_crossmnt = 0;
  2011. dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen);
  2012. if (IS_ERR(dentry))
  2013. return nfserrno(PTR_ERR(dentry));
  2014. if (!dentry->d_inode) {
  2015. /*
  2016. * nfsd_buffered_readdir drops the i_mutex between
  2017. * readdir and calling this callback, leaving a window
  2018. * where this directory entry could have gone away.
  2019. */
  2020. dput(dentry);
  2021. return nfserr_noent;
  2022. }
  2023. exp_get(exp);
  2024. /*
  2025. * In the case of a mountpoint, the client may be asking for
  2026. * attributes that are only properties of the underlying filesystem
  2027. * as opposed to the cross-mounted file system. In such a case,
  2028. * we will not follow the cross mount and will fill the attribtutes
  2029. * directly from the mountpoint dentry.
  2030. */
  2031. if (nfsd_mountpoint(dentry, exp)) {
  2032. int err;
  2033. if (!(exp->ex_flags & NFSEXP_V4ROOT)
  2034. && !attributes_need_mount(cd->rd_bmval)) {
  2035. ignore_crossmnt = 1;
  2036. goto out_encode;
  2037. }
  2038. /*
  2039. * Why the heck aren't we just using nfsd_lookup??
  2040. * Different "."/".." handling? Something else?
  2041. * At least, add a comment here to explain....
  2042. */
  2043. err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp);
  2044. if (err) {
  2045. nfserr = nfserrno(err);
  2046. goto out_put;
  2047. }
  2048. nfserr = check_nfsd_access(exp, cd->rd_rqstp);
  2049. if (nfserr)
  2050. goto out_put;
  2051. }
  2052. out_encode:
  2053. nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval,
  2054. cd->rd_rqstp, ignore_crossmnt);
  2055. out_put:
  2056. dput(dentry);
  2057. exp_put(exp);
  2058. return nfserr;
  2059. }
  2060. static __be32 *
  2061. nfsd4_encode_rdattr_error(__be32 *p, int buflen, __be32 nfserr)
  2062. {
  2063. __be32 *attrlenp;
  2064. if (buflen < 6)
  2065. return NULL;
  2066. *p++ = htonl(2);
  2067. *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */
  2068. *p++ = htonl(0); /* bmval1 */
  2069. attrlenp = p++;
  2070. *p++ = nfserr; /* no htonl */
  2071. *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
  2072. return p;
  2073. }
  2074. static int
  2075. nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
  2076. loff_t offset, u64 ino, unsigned int d_type)
  2077. {
  2078. struct readdir_cd *ccd = ccdv;
  2079. struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common);
  2080. int buflen;
  2081. __be32 *p = cd->buffer;
  2082. __be32 *cookiep;
  2083. __be32 nfserr = nfserr_toosmall;
  2084. /* In nfsv4, "." and ".." never make it onto the wire.. */
  2085. if (name && isdotent(name, namlen)) {
  2086. cd->common.err = nfs_ok;
  2087. return 0;
  2088. }
  2089. if (cd->offset)
  2090. xdr_encode_hyper(cd->offset, (u64) offset);
  2091. buflen = cd->buflen - 4 - XDR_QUADLEN(namlen);
  2092. if (buflen < 0)
  2093. goto fail;
  2094. *p++ = xdr_one; /* mark entry present */
  2095. cookiep = p;
  2096. p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */
  2097. p = xdr_encode_array(p, name, namlen); /* name length & name */
  2098. nfserr = nfsd4_encode_dirent_fattr(cd, name, namlen, p, &buflen);
  2099. switch (nfserr) {
  2100. case nfs_ok:
  2101. p += buflen;
  2102. break;
  2103. case nfserr_resource:
  2104. nfserr = nfserr_toosmall;
  2105. goto fail;
  2106. case nfserr_noent:
  2107. goto skip_entry;
  2108. default:
  2109. /*
  2110. * If the client requested the RDATTR_ERROR attribute,
  2111. * we stuff the error code into this attribute
  2112. * and continue. If this attribute was not requested,
  2113. * then in accordance with the spec, we fail the
  2114. * entire READDIR operation(!)
  2115. */
  2116. if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR))
  2117. goto fail;
  2118. p = nfsd4_encode_rdattr_error(p, buflen, nfserr);
  2119. if (p == NULL) {
  2120. nfserr = nfserr_toosmall;
  2121. goto fail;
  2122. }
  2123. }
  2124. cd->buflen -= (p - cd->buffer);
  2125. cd->buffer = p;
  2126. cd->offset = cookiep;
  2127. skip_entry:
  2128. cd->common.err = nfs_ok;
  2129. return 0;
  2130. fail:
  2131. cd->common.err = nfserr;
  2132. return -EINVAL;
  2133. }
  2134. static void
  2135. nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid)
  2136. {
  2137. __be32 *p;
  2138. RESERVE_SPACE(sizeof(stateid_t));
  2139. WRITE32(sid->si_generation);
  2140. WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
  2141. ADJUST_ARGS();
  2142. }
  2143. static __be32
  2144. nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access)
  2145. {
  2146. __be32 *p;
  2147. if (!nfserr) {
  2148. RESERVE_SPACE(8);
  2149. WRITE32(access->ac_supported);
  2150. WRITE32(access->ac_resp_access);
  2151. ADJUST_ARGS();
  2152. }
  2153. return nfserr;
  2154. }
  2155. static __be32 nfsd4_encode_bind_conn_to_session(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_bind_conn_to_session *bcts)
  2156. {
  2157. __be32 *p;
  2158. if (!nfserr) {
  2159. RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 8);
  2160. WRITEMEM(bcts->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  2161. WRITE32(bcts->dir);
  2162. /* XXX: ? */
  2163. WRITE32(0);
  2164. ADJUST_ARGS();
  2165. }
  2166. return nfserr;
  2167. }
  2168. static __be32
  2169. nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close)
  2170. {
  2171. ENCODE_SEQID_OP_HEAD;
  2172. if (!nfserr)
  2173. nfsd4_encode_stateid(resp, &close->cl_stateid);
  2174. ENCODE_SEQID_OP_TAIL(close->cl_stateowner);
  2175. return nfserr;
  2176. }
  2177. static __be32
  2178. nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit)
  2179. {
  2180. __be32 *p;
  2181. if (!nfserr) {
  2182. RESERVE_SPACE(8);
  2183. WRITEMEM(commit->co_verf.data, 8);
  2184. ADJUST_ARGS();
  2185. }
  2186. return nfserr;
  2187. }
  2188. static __be32
  2189. nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create)
  2190. {
  2191. __be32 *p;
  2192. if (!nfserr) {
  2193. RESERVE_SPACE(32);
  2194. write_cinfo(&p, &create->cr_cinfo);
  2195. WRITE32(2);
  2196. WRITE32(create->cr_bmval[0]);
  2197. WRITE32(create->cr_bmval[1]);
  2198. ADJUST_ARGS();
  2199. }
  2200. return nfserr;
  2201. }
  2202. static __be32
  2203. nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr)
  2204. {
  2205. struct svc_fh *fhp = getattr->ga_fhp;
  2206. int buflen;
  2207. if (nfserr)
  2208. return nfserr;
  2209. buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2);
  2210. nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry,
  2211. resp->p, &buflen, getattr->ga_bmval,
  2212. resp->rqstp, 0);
  2213. if (!nfserr)
  2214. resp->p += buflen;
  2215. return nfserr;
  2216. }
  2217. static __be32
  2218. nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp)
  2219. {
  2220. struct svc_fh *fhp = *fhpp;
  2221. unsigned int len;
  2222. __be32 *p;
  2223. if (!nfserr) {
  2224. len = fhp->fh_handle.fh_size;
  2225. RESERVE_SPACE(len + 4);
  2226. WRITE32(len);
  2227. WRITEMEM(&fhp->fh_handle.fh_base, len);
  2228. ADJUST_ARGS();
  2229. }
  2230. return nfserr;
  2231. }
  2232. /*
  2233. * Including all fields other than the name, a LOCK4denied structure requires
  2234. * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
  2235. */
  2236. static void
  2237. nfsd4_encode_lock_denied(struct nfsd4_compoundres *resp, struct nfsd4_lock_denied *ld)
  2238. {
  2239. __be32 *p;
  2240. RESERVE_SPACE(32 + XDR_LEN(ld->ld_sop ? ld->ld_sop->so_owner.len : 0));
  2241. WRITE64(ld->ld_start);
  2242. WRITE64(ld->ld_length);
  2243. WRITE32(ld->ld_type);
  2244. if (ld->ld_sop) {
  2245. WRITEMEM(&ld->ld_clientid, 8);
  2246. WRITE32(ld->ld_sop->so_owner.len);
  2247. WRITEMEM(ld->ld_sop->so_owner.data, ld->ld_sop->so_owner.len);
  2248. kref_put(&ld->ld_sop->so_ref, nfs4_free_stateowner);
  2249. } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
  2250. WRITE64((u64)0); /* clientid */
  2251. WRITE32(0); /* length of owner name */
  2252. }
  2253. ADJUST_ARGS();
  2254. }
  2255. static __be32
  2256. nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock)
  2257. {
  2258. ENCODE_SEQID_OP_HEAD;
  2259. if (!nfserr)
  2260. nfsd4_encode_stateid(resp, &lock->lk_resp_stateid);
  2261. else if (nfserr == nfserr_denied)
  2262. nfsd4_encode_lock_denied(resp, &lock->lk_denied);
  2263. ENCODE_SEQID_OP_TAIL(lock->lk_replay_owner);
  2264. return nfserr;
  2265. }
  2266. static __be32
  2267. nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt)
  2268. {
  2269. if (nfserr == nfserr_denied)
  2270. nfsd4_encode_lock_denied(resp, &lockt->lt_denied);
  2271. return nfserr;
  2272. }
  2273. static __be32
  2274. nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku)
  2275. {
  2276. ENCODE_SEQID_OP_HEAD;
  2277. if (!nfserr)
  2278. nfsd4_encode_stateid(resp, &locku->lu_stateid);
  2279. ENCODE_SEQID_OP_TAIL(locku->lu_stateowner);
  2280. return nfserr;
  2281. }
  2282. static __be32
  2283. nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link)
  2284. {
  2285. __be32 *p;
  2286. if (!nfserr) {
  2287. RESERVE_SPACE(20);
  2288. write_cinfo(&p, &link->li_cinfo);
  2289. ADJUST_ARGS();
  2290. }
  2291. return nfserr;
  2292. }
  2293. static __be32
  2294. nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open)
  2295. {
  2296. __be32 *p;
  2297. ENCODE_SEQID_OP_HEAD;
  2298. if (nfserr)
  2299. goto out;
  2300. nfsd4_encode_stateid(resp, &open->op_stateid);
  2301. RESERVE_SPACE(40);
  2302. write_cinfo(&p, &open->op_cinfo);
  2303. WRITE32(open->op_rflags);
  2304. WRITE32(2);
  2305. WRITE32(open->op_bmval[0]);
  2306. WRITE32(open->op_bmval[1]);
  2307. WRITE32(open->op_delegate_type);
  2308. ADJUST_ARGS();
  2309. switch (open->op_delegate_type) {
  2310. case NFS4_OPEN_DELEGATE_NONE:
  2311. break;
  2312. case NFS4_OPEN_DELEGATE_READ:
  2313. nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
  2314. RESERVE_SPACE(20);
  2315. WRITE32(open->op_recall);
  2316. /*
  2317. * TODO: ACE's in delegations
  2318. */
  2319. WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
  2320. WRITE32(0);
  2321. WRITE32(0);
  2322. WRITE32(0); /* XXX: is NULL principal ok? */
  2323. ADJUST_ARGS();
  2324. break;
  2325. case NFS4_OPEN_DELEGATE_WRITE:
  2326. nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
  2327. RESERVE_SPACE(32);
  2328. WRITE32(0);
  2329. /*
  2330. * TODO: space_limit's in delegations
  2331. */
  2332. WRITE32(NFS4_LIMIT_SIZE);
  2333. WRITE32(~(u32)0);
  2334. WRITE32(~(u32)0);
  2335. /*
  2336. * TODO: ACE's in delegations
  2337. */
  2338. WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
  2339. WRITE32(0);
  2340. WRITE32(0);
  2341. WRITE32(0); /* XXX: is NULL principal ok? */
  2342. ADJUST_ARGS();
  2343. break;
  2344. default:
  2345. BUG();
  2346. }
  2347. /* XXX save filehandle here */
  2348. out:
  2349. ENCODE_SEQID_OP_TAIL(open->op_stateowner);
  2350. return nfserr;
  2351. }
  2352. static __be32
  2353. nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc)
  2354. {
  2355. ENCODE_SEQID_OP_HEAD;
  2356. if (!nfserr)
  2357. nfsd4_encode_stateid(resp, &oc->oc_resp_stateid);
  2358. ENCODE_SEQID_OP_TAIL(oc->oc_stateowner);
  2359. return nfserr;
  2360. }
  2361. static __be32
  2362. nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od)
  2363. {
  2364. ENCODE_SEQID_OP_HEAD;
  2365. if (!nfserr)
  2366. nfsd4_encode_stateid(resp, &od->od_stateid);
  2367. ENCODE_SEQID_OP_TAIL(od->od_stateowner);
  2368. return nfserr;
  2369. }
  2370. static __be32
  2371. nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
  2372. struct nfsd4_read *read)
  2373. {
  2374. u32 eof;
  2375. int v, pn;
  2376. unsigned long maxcount;
  2377. long len;
  2378. __be32 *p;
  2379. if (nfserr)
  2380. return nfserr;
  2381. if (resp->xbuf->page_len)
  2382. return nfserr_resource;
  2383. RESERVE_SPACE(8); /* eof flag and byte count */
  2384. maxcount = svc_max_payload(resp->rqstp);
  2385. if (maxcount > read->rd_length)
  2386. maxcount = read->rd_length;
  2387. len = maxcount;
  2388. v = 0;
  2389. while (len > 0) {
  2390. pn = resp->rqstp->rq_resused++;
  2391. resp->rqstp->rq_vec[v].iov_base =
  2392. page_address(resp->rqstp->rq_respages[pn]);
  2393. resp->rqstp->rq_vec[v].iov_len =
  2394. len < PAGE_SIZE ? len : PAGE_SIZE;
  2395. v++;
  2396. len -= PAGE_SIZE;
  2397. }
  2398. read->rd_vlen = v;
  2399. nfserr = nfsd_read_file(read->rd_rqstp, read->rd_fhp, read->rd_filp,
  2400. read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen,
  2401. &maxcount);
  2402. if (nfserr == nfserr_symlink)
  2403. nfserr = nfserr_inval;
  2404. if (nfserr)
  2405. return nfserr;
  2406. eof = (read->rd_offset + maxcount >=
  2407. read->rd_fhp->fh_dentry->d_inode->i_size);
  2408. WRITE32(eof);
  2409. WRITE32(maxcount);
  2410. ADJUST_ARGS();
  2411. resp->xbuf->head[0].iov_len = (char*)p
  2412. - (char*)resp->xbuf->head[0].iov_base;
  2413. resp->xbuf->page_len = maxcount;
  2414. /* Use rest of head for padding and remaining ops: */
  2415. resp->xbuf->tail[0].iov_base = p;
  2416. resp->xbuf->tail[0].iov_len = 0;
  2417. if (maxcount&3) {
  2418. RESERVE_SPACE(4);
  2419. WRITE32(0);
  2420. resp->xbuf->tail[0].iov_base += maxcount&3;
  2421. resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
  2422. ADJUST_ARGS();
  2423. }
  2424. return 0;
  2425. }
  2426. static __be32
  2427. nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink)
  2428. {
  2429. int maxcount;
  2430. char *page;
  2431. __be32 *p;
  2432. if (nfserr)
  2433. return nfserr;
  2434. if (resp->xbuf->page_len)
  2435. return nfserr_resource;
  2436. page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]);
  2437. maxcount = PAGE_SIZE;
  2438. RESERVE_SPACE(4);
  2439. /*
  2440. * XXX: By default, the ->readlink() VFS op will truncate symlinks
  2441. * if they would overflow the buffer. Is this kosher in NFSv4? If
  2442. * not, one easy fix is: if ->readlink() precisely fills the buffer,
  2443. * assume that truncation occurred, and return NFS4ERR_RESOURCE.
  2444. */
  2445. nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount);
  2446. if (nfserr == nfserr_isdir)
  2447. return nfserr_inval;
  2448. if (nfserr)
  2449. return nfserr;
  2450. WRITE32(maxcount);
  2451. ADJUST_ARGS();
  2452. resp->xbuf->head[0].iov_len = (char*)p
  2453. - (char*)resp->xbuf->head[0].iov_base;
  2454. resp->xbuf->page_len = maxcount;
  2455. /* Use rest of head for padding and remaining ops: */
  2456. resp->xbuf->tail[0].iov_base = p;
  2457. resp->xbuf->tail[0].iov_len = 0;
  2458. if (maxcount&3) {
  2459. RESERVE_SPACE(4);
  2460. WRITE32(0);
  2461. resp->xbuf->tail[0].iov_base += maxcount&3;
  2462. resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
  2463. ADJUST_ARGS();
  2464. }
  2465. return 0;
  2466. }
  2467. static __be32
  2468. nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir)
  2469. {
  2470. int maxcount;
  2471. loff_t offset;
  2472. __be32 *page, *savep, *tailbase;
  2473. __be32 *p;
  2474. if (nfserr)
  2475. return nfserr;
  2476. if (resp->xbuf->page_len)
  2477. return nfserr_resource;
  2478. RESERVE_SPACE(8); /* verifier */
  2479. savep = p;
  2480. /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
  2481. WRITE32(0);
  2482. WRITE32(0);
  2483. ADJUST_ARGS();
  2484. resp->xbuf->head[0].iov_len = ((char*)resp->p) - (char*)resp->xbuf->head[0].iov_base;
  2485. tailbase = p;
  2486. maxcount = PAGE_SIZE;
  2487. if (maxcount > readdir->rd_maxcount)
  2488. maxcount = readdir->rd_maxcount;
  2489. /*
  2490. * Convert from bytes to words, account for the two words already
  2491. * written, make sure to leave two words at the end for the next
  2492. * pointer and eof field.
  2493. */
  2494. maxcount = (maxcount >> 2) - 4;
  2495. if (maxcount < 0) {
  2496. nfserr = nfserr_toosmall;
  2497. goto err_no_verf;
  2498. }
  2499. page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]);
  2500. readdir->common.err = 0;
  2501. readdir->buflen = maxcount;
  2502. readdir->buffer = page;
  2503. readdir->offset = NULL;
  2504. offset = readdir->rd_cookie;
  2505. nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp,
  2506. &offset,
  2507. &readdir->common, nfsd4_encode_dirent);
  2508. if (nfserr == nfs_ok &&
  2509. readdir->common.err == nfserr_toosmall &&
  2510. readdir->buffer == page)
  2511. nfserr = nfserr_toosmall;
  2512. if (nfserr == nfserr_symlink)
  2513. nfserr = nfserr_notdir;
  2514. if (nfserr)
  2515. goto err_no_verf;
  2516. if (readdir->offset)
  2517. xdr_encode_hyper(readdir->offset, offset);
  2518. p = readdir->buffer;
  2519. *p++ = 0; /* no more entries */
  2520. *p++ = htonl(readdir->common.err == nfserr_eof);
  2521. resp->xbuf->page_len = ((char*)p) - (char*)page_address(
  2522. resp->rqstp->rq_respages[resp->rqstp->rq_resused-1]);
  2523. /* Use rest of head for padding and remaining ops: */
  2524. resp->xbuf->tail[0].iov_base = tailbase;
  2525. resp->xbuf->tail[0].iov_len = 0;
  2526. resp->p = resp->xbuf->tail[0].iov_base;
  2527. resp->end = resp->p + (PAGE_SIZE - resp->xbuf->head[0].iov_len)/4;
  2528. return 0;
  2529. err_no_verf:
  2530. p = savep;
  2531. ADJUST_ARGS();
  2532. return nfserr;
  2533. }
  2534. static __be32
  2535. nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove)
  2536. {
  2537. __be32 *p;
  2538. if (!nfserr) {
  2539. RESERVE_SPACE(20);
  2540. write_cinfo(&p, &remove->rm_cinfo);
  2541. ADJUST_ARGS();
  2542. }
  2543. return nfserr;
  2544. }
  2545. static __be32
  2546. nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename)
  2547. {
  2548. __be32 *p;
  2549. if (!nfserr) {
  2550. RESERVE_SPACE(40);
  2551. write_cinfo(&p, &rename->rn_sinfo);
  2552. write_cinfo(&p, &rename->rn_tinfo);
  2553. ADJUST_ARGS();
  2554. }
  2555. return nfserr;
  2556. }
  2557. static __be32
  2558. nfsd4_do_encode_secinfo(struct nfsd4_compoundres *resp,
  2559. __be32 nfserr,struct svc_export *exp)
  2560. {
  2561. int i = 0;
  2562. u32 nflavs;
  2563. struct exp_flavor_info *flavs;
  2564. struct exp_flavor_info def_flavs[2];
  2565. __be32 *p;
  2566. if (nfserr)
  2567. goto out;
  2568. if (exp->ex_nflavors) {
  2569. flavs = exp->ex_flavors;
  2570. nflavs = exp->ex_nflavors;
  2571. } else { /* Handling of some defaults in absence of real secinfo: */
  2572. flavs = def_flavs;
  2573. if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) {
  2574. nflavs = 2;
  2575. flavs[0].pseudoflavor = RPC_AUTH_UNIX;
  2576. flavs[1].pseudoflavor = RPC_AUTH_NULL;
  2577. } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) {
  2578. nflavs = 1;
  2579. flavs[0].pseudoflavor
  2580. = svcauth_gss_flavor(exp->ex_client);
  2581. } else {
  2582. nflavs = 1;
  2583. flavs[0].pseudoflavor
  2584. = exp->ex_client->flavour->flavour;
  2585. }
  2586. }
  2587. RESERVE_SPACE(4);
  2588. WRITE32(nflavs);
  2589. ADJUST_ARGS();
  2590. for (i = 0; i < nflavs; i++) {
  2591. u32 flav = flavs[i].pseudoflavor;
  2592. struct gss_api_mech *gm = gss_mech_get_by_pseudoflavor(flav);
  2593. if (gm) {
  2594. RESERVE_SPACE(4);
  2595. WRITE32(RPC_AUTH_GSS);
  2596. ADJUST_ARGS();
  2597. RESERVE_SPACE(4 + gm->gm_oid.len);
  2598. WRITE32(gm->gm_oid.len);
  2599. WRITEMEM(gm->gm_oid.data, gm->gm_oid.len);
  2600. ADJUST_ARGS();
  2601. RESERVE_SPACE(4);
  2602. WRITE32(0); /* qop */
  2603. ADJUST_ARGS();
  2604. RESERVE_SPACE(4);
  2605. WRITE32(gss_pseudoflavor_to_service(gm, flav));
  2606. ADJUST_ARGS();
  2607. gss_mech_put(gm);
  2608. } else {
  2609. RESERVE_SPACE(4);
  2610. WRITE32(flav);
  2611. ADJUST_ARGS();
  2612. }
  2613. }
  2614. out:
  2615. if (exp)
  2616. exp_put(exp);
  2617. return nfserr;
  2618. }
  2619. static __be32
  2620. nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
  2621. struct nfsd4_secinfo *secinfo)
  2622. {
  2623. return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->si_exp);
  2624. }
  2625. static __be32
  2626. nfsd4_encode_secinfo_no_name(struct nfsd4_compoundres *resp, __be32 nfserr,
  2627. struct nfsd4_secinfo_no_name *secinfo)
  2628. {
  2629. return nfsd4_do_encode_secinfo(resp, nfserr, secinfo->sin_exp);
  2630. }
  2631. /*
  2632. * The SETATTR encode routine is special -- it always encodes a bitmap,
  2633. * regardless of the error status.
  2634. */
  2635. static __be32
  2636. nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr)
  2637. {
  2638. __be32 *p;
  2639. RESERVE_SPACE(12);
  2640. if (nfserr) {
  2641. WRITE32(2);
  2642. WRITE32(0);
  2643. WRITE32(0);
  2644. }
  2645. else {
  2646. WRITE32(2);
  2647. WRITE32(setattr->sa_bmval[0]);
  2648. WRITE32(setattr->sa_bmval[1]);
  2649. }
  2650. ADJUST_ARGS();
  2651. return nfserr;
  2652. }
  2653. static __be32
  2654. nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd)
  2655. {
  2656. __be32 *p;
  2657. if (!nfserr) {
  2658. RESERVE_SPACE(8 + sizeof(nfs4_verifier));
  2659. WRITEMEM(&scd->se_clientid, 8);
  2660. WRITEMEM(&scd->se_confirm, sizeof(nfs4_verifier));
  2661. ADJUST_ARGS();
  2662. }
  2663. else if (nfserr == nfserr_clid_inuse) {
  2664. RESERVE_SPACE(8);
  2665. WRITE32(0);
  2666. WRITE32(0);
  2667. ADJUST_ARGS();
  2668. }
  2669. return nfserr;
  2670. }
  2671. static __be32
  2672. nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write)
  2673. {
  2674. __be32 *p;
  2675. if (!nfserr) {
  2676. RESERVE_SPACE(16);
  2677. WRITE32(write->wr_bytes_written);
  2678. WRITE32(write->wr_how_written);
  2679. WRITEMEM(write->wr_verifier.data, 8);
  2680. ADJUST_ARGS();
  2681. }
  2682. return nfserr;
  2683. }
  2684. static __be32
  2685. nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, int nfserr,
  2686. struct nfsd4_exchange_id *exid)
  2687. {
  2688. __be32 *p;
  2689. char *major_id;
  2690. char *server_scope;
  2691. int major_id_sz;
  2692. int server_scope_sz;
  2693. uint64_t minor_id = 0;
  2694. if (nfserr)
  2695. return nfserr;
  2696. major_id = utsname()->nodename;
  2697. major_id_sz = strlen(major_id);
  2698. server_scope = utsname()->nodename;
  2699. server_scope_sz = strlen(server_scope);
  2700. RESERVE_SPACE(
  2701. 8 /* eir_clientid */ +
  2702. 4 /* eir_sequenceid */ +
  2703. 4 /* eir_flags */ +
  2704. 4 /* spr_how (SP4_NONE) */ +
  2705. 8 /* so_minor_id */ +
  2706. 4 /* so_major_id.len */ +
  2707. (XDR_QUADLEN(major_id_sz) * 4) +
  2708. 4 /* eir_server_scope.len */ +
  2709. (XDR_QUADLEN(server_scope_sz) * 4) +
  2710. 4 /* eir_server_impl_id.count (0) */);
  2711. WRITEMEM(&exid->clientid, 8);
  2712. WRITE32(exid->seqid);
  2713. WRITE32(exid->flags);
  2714. /* state_protect4_r. Currently only support SP4_NONE */
  2715. BUG_ON(exid->spa_how != SP4_NONE);
  2716. WRITE32(exid->spa_how);
  2717. /* The server_owner struct */
  2718. WRITE64(minor_id); /* Minor id */
  2719. /* major id */
  2720. WRITE32(major_id_sz);
  2721. WRITEMEM(major_id, major_id_sz);
  2722. /* Server scope */
  2723. WRITE32(server_scope_sz);
  2724. WRITEMEM(server_scope, server_scope_sz);
  2725. /* Implementation id */
  2726. WRITE32(0); /* zero length nfs_impl_id4 array */
  2727. ADJUST_ARGS();
  2728. return 0;
  2729. }
  2730. static __be32
  2731. nfsd4_encode_create_session(struct nfsd4_compoundres *resp, int nfserr,
  2732. struct nfsd4_create_session *sess)
  2733. {
  2734. __be32 *p;
  2735. if (nfserr)
  2736. return nfserr;
  2737. RESERVE_SPACE(24);
  2738. WRITEMEM(sess->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  2739. WRITE32(sess->seqid);
  2740. WRITE32(sess->flags);
  2741. ADJUST_ARGS();
  2742. RESERVE_SPACE(28);
  2743. WRITE32(0); /* headerpadsz */
  2744. WRITE32(sess->fore_channel.maxreq_sz);
  2745. WRITE32(sess->fore_channel.maxresp_sz);
  2746. WRITE32(sess->fore_channel.maxresp_cached);
  2747. WRITE32(sess->fore_channel.maxops);
  2748. WRITE32(sess->fore_channel.maxreqs);
  2749. WRITE32(sess->fore_channel.nr_rdma_attrs);
  2750. ADJUST_ARGS();
  2751. if (sess->fore_channel.nr_rdma_attrs) {
  2752. RESERVE_SPACE(4);
  2753. WRITE32(sess->fore_channel.rdma_attrs);
  2754. ADJUST_ARGS();
  2755. }
  2756. RESERVE_SPACE(28);
  2757. WRITE32(0); /* headerpadsz */
  2758. WRITE32(sess->back_channel.maxreq_sz);
  2759. WRITE32(sess->back_channel.maxresp_sz);
  2760. WRITE32(sess->back_channel.maxresp_cached);
  2761. WRITE32(sess->back_channel.maxops);
  2762. WRITE32(sess->back_channel.maxreqs);
  2763. WRITE32(sess->back_channel.nr_rdma_attrs);
  2764. ADJUST_ARGS();
  2765. if (sess->back_channel.nr_rdma_attrs) {
  2766. RESERVE_SPACE(4);
  2767. WRITE32(sess->back_channel.rdma_attrs);
  2768. ADJUST_ARGS();
  2769. }
  2770. return 0;
  2771. }
  2772. static __be32
  2773. nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr,
  2774. struct nfsd4_destroy_session *destroy_session)
  2775. {
  2776. return nfserr;
  2777. }
  2778. static __be32
  2779. nfsd4_encode_sequence(struct nfsd4_compoundres *resp, int nfserr,
  2780. struct nfsd4_sequence *seq)
  2781. {
  2782. __be32 *p;
  2783. if (nfserr)
  2784. return nfserr;
  2785. RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 20);
  2786. WRITEMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  2787. WRITE32(seq->seqid);
  2788. WRITE32(seq->slotid);
  2789. WRITE32(seq->maxslots);
  2790. /* For now: target_maxslots = maxslots */
  2791. WRITE32(seq->maxslots);
  2792. WRITE32(seq->status_flags);
  2793. ADJUST_ARGS();
  2794. resp->cstate.datap = p; /* DRC cache data pointer */
  2795. return 0;
  2796. }
  2797. static __be32
  2798. nfsd4_encode_noop(struct nfsd4_compoundres *resp, __be32 nfserr, void *p)
  2799. {
  2800. return nfserr;
  2801. }
  2802. typedef __be32(* nfsd4_enc)(struct nfsd4_compoundres *, __be32, void *);
  2803. /*
  2804. * Note: nfsd4_enc_ops vector is shared for v4.0 and v4.1
  2805. * since we don't need to filter out obsolete ops as this is
  2806. * done in the decoding phase.
  2807. */
  2808. static nfsd4_enc nfsd4_enc_ops[] = {
  2809. [OP_ACCESS] = (nfsd4_enc)nfsd4_encode_access,
  2810. [OP_CLOSE] = (nfsd4_enc)nfsd4_encode_close,
  2811. [OP_COMMIT] = (nfsd4_enc)nfsd4_encode_commit,
  2812. [OP_CREATE] = (nfsd4_enc)nfsd4_encode_create,
  2813. [OP_DELEGPURGE] = (nfsd4_enc)nfsd4_encode_noop,
  2814. [OP_DELEGRETURN] = (nfsd4_enc)nfsd4_encode_noop,
  2815. [OP_GETATTR] = (nfsd4_enc)nfsd4_encode_getattr,
  2816. [OP_GETFH] = (nfsd4_enc)nfsd4_encode_getfh,
  2817. [OP_LINK] = (nfsd4_enc)nfsd4_encode_link,
  2818. [OP_LOCK] = (nfsd4_enc)nfsd4_encode_lock,
  2819. [OP_LOCKT] = (nfsd4_enc)nfsd4_encode_lockt,
  2820. [OP_LOCKU] = (nfsd4_enc)nfsd4_encode_locku,
  2821. [OP_LOOKUP] = (nfsd4_enc)nfsd4_encode_noop,
  2822. [OP_LOOKUPP] = (nfsd4_enc)nfsd4_encode_noop,
  2823. [OP_NVERIFY] = (nfsd4_enc)nfsd4_encode_noop,
  2824. [OP_OPEN] = (nfsd4_enc)nfsd4_encode_open,
  2825. [OP_OPENATTR] = (nfsd4_enc)nfsd4_encode_noop,
  2826. [OP_OPEN_CONFIRM] = (nfsd4_enc)nfsd4_encode_open_confirm,
  2827. [OP_OPEN_DOWNGRADE] = (nfsd4_enc)nfsd4_encode_open_downgrade,
  2828. [OP_PUTFH] = (nfsd4_enc)nfsd4_encode_noop,
  2829. [OP_PUTPUBFH] = (nfsd4_enc)nfsd4_encode_noop,
  2830. [OP_PUTROOTFH] = (nfsd4_enc)nfsd4_encode_noop,
  2831. [OP_READ] = (nfsd4_enc)nfsd4_encode_read,
  2832. [OP_READDIR] = (nfsd4_enc)nfsd4_encode_readdir,
  2833. [OP_READLINK] = (nfsd4_enc)nfsd4_encode_readlink,
  2834. [OP_REMOVE] = (nfsd4_enc)nfsd4_encode_remove,
  2835. [OP_RENAME] = (nfsd4_enc)nfsd4_encode_rename,
  2836. [OP_RENEW] = (nfsd4_enc)nfsd4_encode_noop,
  2837. [OP_RESTOREFH] = (nfsd4_enc)nfsd4_encode_noop,
  2838. [OP_SAVEFH] = (nfsd4_enc)nfsd4_encode_noop,
  2839. [OP_SECINFO] = (nfsd4_enc)nfsd4_encode_secinfo,
  2840. [OP_SETATTR] = (nfsd4_enc)nfsd4_encode_setattr,
  2841. [OP_SETCLIENTID] = (nfsd4_enc)nfsd4_encode_setclientid,
  2842. [OP_SETCLIENTID_CONFIRM] = (nfsd4_enc)nfsd4_encode_noop,
  2843. [OP_VERIFY] = (nfsd4_enc)nfsd4_encode_noop,
  2844. [OP_WRITE] = (nfsd4_enc)nfsd4_encode_write,
  2845. [OP_RELEASE_LOCKOWNER] = (nfsd4_enc)nfsd4_encode_noop,
  2846. /* NFSv4.1 operations */
  2847. [OP_BACKCHANNEL_CTL] = (nfsd4_enc)nfsd4_encode_noop,
  2848. [OP_BIND_CONN_TO_SESSION] = (nfsd4_enc)nfsd4_encode_bind_conn_to_session,
  2849. [OP_EXCHANGE_ID] = (nfsd4_enc)nfsd4_encode_exchange_id,
  2850. [OP_CREATE_SESSION] = (nfsd4_enc)nfsd4_encode_create_session,
  2851. [OP_DESTROY_SESSION] = (nfsd4_enc)nfsd4_encode_destroy_session,
  2852. [OP_FREE_STATEID] = (nfsd4_enc)nfsd4_encode_noop,
  2853. [OP_GET_DIR_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
  2854. [OP_GETDEVICEINFO] = (nfsd4_enc)nfsd4_encode_noop,
  2855. [OP_GETDEVICELIST] = (nfsd4_enc)nfsd4_encode_noop,
  2856. [OP_LAYOUTCOMMIT] = (nfsd4_enc)nfsd4_encode_noop,
  2857. [OP_LAYOUTGET] = (nfsd4_enc)nfsd4_encode_noop,
  2858. [OP_LAYOUTRETURN] = (nfsd4_enc)nfsd4_encode_noop,
  2859. [OP_SECINFO_NO_NAME] = (nfsd4_enc)nfsd4_encode_secinfo_no_name,
  2860. [OP_SEQUENCE] = (nfsd4_enc)nfsd4_encode_sequence,
  2861. [OP_SET_SSV] = (nfsd4_enc)nfsd4_encode_noop,
  2862. [OP_TEST_STATEID] = (nfsd4_enc)nfsd4_encode_noop,
  2863. [OP_WANT_DELEGATION] = (nfsd4_enc)nfsd4_encode_noop,
  2864. [OP_DESTROY_CLIENTID] = (nfsd4_enc)nfsd4_encode_noop,
  2865. [OP_RECLAIM_COMPLETE] = (nfsd4_enc)nfsd4_encode_noop,
  2866. };
  2867. /*
  2868. * Calculate the total amount of memory that the compound response has taken
  2869. * after encoding the current operation.
  2870. *
  2871. * pad: add on 8 bytes for the next operation's op_code and status so that
  2872. * there is room to cache a failure on the next operation.
  2873. *
  2874. * Compare this length to the session se_fmaxresp_cached.
  2875. *
  2876. * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so
  2877. * will be at least a page and will therefore hold the xdr_buf head.
  2878. */
  2879. static int nfsd4_check_drc_limit(struct nfsd4_compoundres *resp)
  2880. {
  2881. int status = 0;
  2882. struct xdr_buf *xb = &resp->rqstp->rq_res;
  2883. struct nfsd4_compoundargs *args = resp->rqstp->rq_argp;
  2884. struct nfsd4_session *session = NULL;
  2885. struct nfsd4_slot *slot = resp->cstate.slot;
  2886. u32 length, tlen = 0, pad = 8;
  2887. if (!nfsd4_has_session(&resp->cstate))
  2888. return status;
  2889. session = resp->cstate.session;
  2890. if (session == NULL || slot->sl_cachethis == 0)
  2891. return status;
  2892. if (resp->opcnt >= args->opcnt)
  2893. pad = 0; /* this is the last operation */
  2894. if (xb->page_len == 0) {
  2895. length = (char *)resp->p - (char *)xb->head[0].iov_base + pad;
  2896. } else {
  2897. if (xb->tail[0].iov_base && xb->tail[0].iov_len > 0)
  2898. tlen = (char *)resp->p - (char *)xb->tail[0].iov_base;
  2899. length = xb->head[0].iov_len + xb->page_len + tlen + pad;
  2900. }
  2901. dprintk("%s length %u, xb->page_len %u tlen %u pad %u\n", __func__,
  2902. length, xb->page_len, tlen, pad);
  2903. if (length <= session->se_fchannel.maxresp_cached)
  2904. return status;
  2905. else
  2906. return nfserr_rep_too_big_to_cache;
  2907. }
  2908. void
  2909. nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
  2910. {
  2911. __be32 *statp;
  2912. __be32 *p;
  2913. RESERVE_SPACE(8);
  2914. WRITE32(op->opnum);
  2915. statp = p++; /* to be backfilled at the end */
  2916. ADJUST_ARGS();
  2917. if (op->opnum == OP_ILLEGAL)
  2918. goto status;
  2919. BUG_ON(op->opnum < 0 || op->opnum >= ARRAY_SIZE(nfsd4_enc_ops) ||
  2920. !nfsd4_enc_ops[op->opnum]);
  2921. op->status = nfsd4_enc_ops[op->opnum](resp, op->status, &op->u);
  2922. /* nfsd4_check_drc_limit guarantees enough room for error status */
  2923. if (!op->status && nfsd4_check_drc_limit(resp))
  2924. op->status = nfserr_rep_too_big_to_cache;
  2925. status:
  2926. /*
  2927. * Note: We write the status directly, instead of using WRITE32(),
  2928. * since it is already in network byte order.
  2929. */
  2930. *statp = op->status;
  2931. }
  2932. /*
  2933. * Encode the reply stored in the stateowner reply cache
  2934. *
  2935. * XDR note: do not encode rp->rp_buflen: the buffer contains the
  2936. * previously sent already encoded operation.
  2937. *
  2938. * called with nfs4_lock_state() held
  2939. */
  2940. void
  2941. nfsd4_encode_replay(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
  2942. {
  2943. __be32 *p;
  2944. struct nfs4_replay *rp = op->replay;
  2945. BUG_ON(!rp);
  2946. RESERVE_SPACE(8);
  2947. WRITE32(op->opnum);
  2948. *p++ = rp->rp_status; /* already xdr'ed */
  2949. ADJUST_ARGS();
  2950. RESERVE_SPACE(rp->rp_buflen);
  2951. WRITEMEM(rp->rp_buf, rp->rp_buflen);
  2952. ADJUST_ARGS();
  2953. }
  2954. int
  2955. nfs4svc_encode_voidres(struct svc_rqst *rqstp, __be32 *p, void *dummy)
  2956. {
  2957. return xdr_ressize_check(rqstp, p);
  2958. }
  2959. void nfsd4_release_compoundargs(struct nfsd4_compoundargs *args)
  2960. {
  2961. if (args->ops != args->iops) {
  2962. kfree(args->ops);
  2963. args->ops = args->iops;
  2964. }
  2965. kfree(args->tmpp);
  2966. args->tmpp = NULL;
  2967. while (args->to_free) {
  2968. struct tmpbuf *tb = args->to_free;
  2969. args->to_free = tb->next;
  2970. tb->release(tb->buf);
  2971. kfree(tb);
  2972. }
  2973. }
  2974. int
  2975. nfs4svc_decode_compoundargs(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundargs *args)
  2976. {
  2977. __be32 status;
  2978. args->p = p;
  2979. args->end = rqstp->rq_arg.head[0].iov_base + rqstp->rq_arg.head[0].iov_len;
  2980. args->pagelist = rqstp->rq_arg.pages;
  2981. args->pagelen = rqstp->rq_arg.page_len;
  2982. args->tmpp = NULL;
  2983. args->to_free = NULL;
  2984. args->ops = args->iops;
  2985. args->rqstp = rqstp;
  2986. status = nfsd4_decode_compound(args);
  2987. if (status) {
  2988. nfsd4_release_compoundargs(args);
  2989. }
  2990. return !status;
  2991. }
  2992. int
  2993. nfs4svc_encode_compoundres(struct svc_rqst *rqstp, __be32 *p, struct nfsd4_compoundres *resp)
  2994. {
  2995. /*
  2996. * All that remains is to write the tag and operation count...
  2997. */
  2998. struct nfsd4_compound_state *cs = &resp->cstate;
  2999. struct kvec *iov;
  3000. p = resp->tagp;
  3001. *p++ = htonl(resp->taglen);
  3002. memcpy(p, resp->tag, resp->taglen);
  3003. p += XDR_QUADLEN(resp->taglen);
  3004. *p++ = htonl(resp->opcnt);
  3005. if (rqstp->rq_res.page_len)
  3006. iov = &rqstp->rq_res.tail[0];
  3007. else
  3008. iov = &rqstp->rq_res.head[0];
  3009. iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base;
  3010. BUG_ON(iov->iov_len > PAGE_SIZE);
  3011. if (nfsd4_has_session(cs)) {
  3012. if (cs->status != nfserr_replay_cache) {
  3013. nfsd4_store_cache_entry(resp);
  3014. dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__);
  3015. cs->slot->sl_inuse = false;
  3016. }
  3017. /* Renew the clientid on success and on replay */
  3018. release_session_client(cs->session);
  3019. nfsd4_put_session(cs->session);
  3020. }
  3021. return 1;
  3022. }
  3023. /*
  3024. * Local variables:
  3025. * c-basic-offset: 8
  3026. * End:
  3027. */