nfs4xdr.c 83 KB

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