nfs4xdr.c 82 KB

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