nfs4xdr.c 82 KB

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