nfs4xdr.c 82 KB

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