nfs4xdr.c 83 KB

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