nfs4xdr.c 82 KB

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