nfs4xdr.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320
  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 = NULL, *rootpath;
  1419. size_t rootlen;
  1420. fh_init(&tmp_fh, NFS4_FHSIZE);
  1421. *stat = exp_pseudoroot(rqstp, &tmp_fh);
  1422. if (*stat)
  1423. return NULL;
  1424. rootpath = tmp_fh.fh_export->ex_pathname;
  1425. path = exp->ex_pathname;
  1426. rootlen = strlen(rootpath);
  1427. if (strncmp(path, rootpath, rootlen)) {
  1428. dprintk("nfsd: fs_locations failed;"
  1429. "%s is not contained in %s\n", path, rootpath);
  1430. *stat = nfserr_notsupp;
  1431. path = NULL;
  1432. goto out;
  1433. }
  1434. path += rootlen;
  1435. out:
  1436. fh_put(&tmp_fh);
  1437. return path;
  1438. }
  1439. /*
  1440. * encode a fs_locations structure
  1441. */
  1442. static __be32 nfsd4_encode_fs_locations(struct svc_rqst *rqstp,
  1443. struct svc_export *exp,
  1444. __be32 **pp, int *buflen)
  1445. {
  1446. __be32 status;
  1447. int i;
  1448. __be32 *p = *pp;
  1449. struct nfsd4_fs_locations *fslocs = &exp->ex_fslocs;
  1450. char *root = nfsd4_path(rqstp, exp, &status);
  1451. if (status)
  1452. return status;
  1453. status = nfsd4_encode_components('/', root, &p, buflen);
  1454. if (status)
  1455. return status;
  1456. if ((*buflen -= 4) < 0)
  1457. return nfserr_resource;
  1458. WRITE32(fslocs->locations_count);
  1459. for (i=0; i<fslocs->locations_count; i++) {
  1460. status = nfsd4_encode_fs_location4(&fslocs->locations[i],
  1461. &p, buflen);
  1462. if (status)
  1463. return status;
  1464. }
  1465. *pp = p;
  1466. return 0;
  1467. }
  1468. static u32 nfs4_ftypes[16] = {
  1469. NF4BAD, NF4FIFO, NF4CHR, NF4BAD,
  1470. NF4DIR, NF4BAD, NF4BLK, NF4BAD,
  1471. NF4REG, NF4BAD, NF4LNK, NF4BAD,
  1472. NF4SOCK, NF4BAD, NF4LNK, NF4BAD,
  1473. };
  1474. static __be32
  1475. nfsd4_encode_name(struct svc_rqst *rqstp, int whotype, uid_t id, int group,
  1476. __be32 **p, int *buflen)
  1477. {
  1478. int status;
  1479. if (*buflen < (XDR_QUADLEN(IDMAP_NAMESZ) << 2) + 4)
  1480. return nfserr_resource;
  1481. if (whotype != NFS4_ACL_WHO_NAMED)
  1482. status = nfs4_acl_write_who(whotype, (u8 *)(*p + 1));
  1483. else if (group)
  1484. status = nfsd_map_gid_to_name(rqstp, id, (u8 *)(*p + 1));
  1485. else
  1486. status = nfsd_map_uid_to_name(rqstp, id, (u8 *)(*p + 1));
  1487. if (status < 0)
  1488. return nfserrno(status);
  1489. *p = xdr_encode_opaque(*p, NULL, status);
  1490. *buflen -= (XDR_QUADLEN(status) << 2) + 4;
  1491. BUG_ON(*buflen < 0);
  1492. return 0;
  1493. }
  1494. static inline __be32
  1495. nfsd4_encode_user(struct svc_rqst *rqstp, uid_t uid, __be32 **p, int *buflen)
  1496. {
  1497. return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, uid, 0, p, buflen);
  1498. }
  1499. static inline __be32
  1500. nfsd4_encode_group(struct svc_rqst *rqstp, uid_t gid, __be32 **p, int *buflen)
  1501. {
  1502. return nfsd4_encode_name(rqstp, NFS4_ACL_WHO_NAMED, gid, 1, p, buflen);
  1503. }
  1504. static inline __be32
  1505. nfsd4_encode_aclname(struct svc_rqst *rqstp, int whotype, uid_t id, int group,
  1506. __be32 **p, int *buflen)
  1507. {
  1508. return nfsd4_encode_name(rqstp, whotype, id, group, p, buflen);
  1509. }
  1510. #define WORD0_ABSENT_FS_ATTRS (FATTR4_WORD0_FS_LOCATIONS | FATTR4_WORD0_FSID | \
  1511. FATTR4_WORD0_RDATTR_ERROR)
  1512. #define WORD1_ABSENT_FS_ATTRS FATTR4_WORD1_MOUNTED_ON_FILEID
  1513. static __be32 fattr_handle_absent_fs(u32 *bmval0, u32 *bmval1, u32 *rdattr_err)
  1514. {
  1515. /* As per referral draft: */
  1516. if (*bmval0 & ~WORD0_ABSENT_FS_ATTRS ||
  1517. *bmval1 & ~WORD1_ABSENT_FS_ATTRS) {
  1518. if (*bmval0 & FATTR4_WORD0_RDATTR_ERROR ||
  1519. *bmval0 & FATTR4_WORD0_FS_LOCATIONS)
  1520. *rdattr_err = NFSERR_MOVED;
  1521. else
  1522. return nfserr_moved;
  1523. }
  1524. *bmval0 &= WORD0_ABSENT_FS_ATTRS;
  1525. *bmval1 &= WORD1_ABSENT_FS_ATTRS;
  1526. return 0;
  1527. }
  1528. /*
  1529. * Note: @fhp can be NULL; in this case, we might have to compose the filehandle
  1530. * ourselves.
  1531. *
  1532. * @countp is the buffer size in _words_; upon successful return this becomes
  1533. * replaced with the number of words written.
  1534. */
  1535. __be32
  1536. nfsd4_encode_fattr(struct svc_fh *fhp, struct svc_export *exp,
  1537. struct dentry *dentry, __be32 *buffer, int *countp, u32 *bmval,
  1538. struct svc_rqst *rqstp, int ignore_crossmnt)
  1539. {
  1540. u32 bmval0 = bmval[0];
  1541. u32 bmval1 = bmval[1];
  1542. u32 bmval2 = bmval[2];
  1543. struct kstat stat;
  1544. struct svc_fh tempfh;
  1545. struct kstatfs statfs;
  1546. int buflen = *countp << 2;
  1547. __be32 *attrlenp;
  1548. u32 dummy;
  1549. u64 dummy64;
  1550. u32 rdattr_err = 0;
  1551. __be32 *p = buffer;
  1552. __be32 status;
  1553. int err;
  1554. int aclsupport = 0;
  1555. struct nfs4_acl *acl = NULL;
  1556. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  1557. u32 minorversion = resp->cstate.minorversion;
  1558. BUG_ON(bmval1 & NFSD_WRITEONLY_ATTRS_WORD1);
  1559. BUG_ON(bmval0 & ~nfsd_suppattrs0(minorversion));
  1560. BUG_ON(bmval1 & ~nfsd_suppattrs1(minorversion));
  1561. BUG_ON(bmval2 & ~nfsd_suppattrs2(minorversion));
  1562. if (exp->ex_fslocs.migrated) {
  1563. BUG_ON(bmval[2]);
  1564. status = fattr_handle_absent_fs(&bmval0, &bmval1, &rdattr_err);
  1565. if (status)
  1566. goto out;
  1567. }
  1568. err = vfs_getattr(exp->ex_path.mnt, dentry, &stat);
  1569. if (err)
  1570. goto out_nfserr;
  1571. if ((bmval0 & (FATTR4_WORD0_FILES_FREE | FATTR4_WORD0_FILES_TOTAL |
  1572. FATTR4_WORD0_MAXNAME)) ||
  1573. (bmval1 & (FATTR4_WORD1_SPACE_AVAIL | FATTR4_WORD1_SPACE_FREE |
  1574. FATTR4_WORD1_SPACE_TOTAL))) {
  1575. err = vfs_statfs(dentry, &statfs);
  1576. if (err)
  1577. goto out_nfserr;
  1578. }
  1579. if ((bmval0 & (FATTR4_WORD0_FILEHANDLE | FATTR4_WORD0_FSID)) && !fhp) {
  1580. fh_init(&tempfh, NFS4_FHSIZE);
  1581. status = fh_compose(&tempfh, exp, dentry, NULL);
  1582. if (status)
  1583. goto out;
  1584. fhp = &tempfh;
  1585. }
  1586. if (bmval0 & (FATTR4_WORD0_ACL | FATTR4_WORD0_ACLSUPPORT
  1587. | FATTR4_WORD0_SUPPORTED_ATTRS)) {
  1588. err = nfsd4_get_nfs4_acl(rqstp, dentry, &acl);
  1589. aclsupport = (err == 0);
  1590. if (bmval0 & FATTR4_WORD0_ACL) {
  1591. if (err == -EOPNOTSUPP)
  1592. bmval0 &= ~FATTR4_WORD0_ACL;
  1593. else if (err == -EINVAL) {
  1594. status = nfserr_attrnotsupp;
  1595. goto out;
  1596. } else if (err != 0)
  1597. goto out_nfserr;
  1598. }
  1599. }
  1600. if ((buflen -= 16) < 0)
  1601. goto out_resource;
  1602. if (unlikely(bmval2)) {
  1603. WRITE32(3);
  1604. WRITE32(bmval0);
  1605. WRITE32(bmval1);
  1606. WRITE32(bmval2);
  1607. } else if (likely(bmval1)) {
  1608. WRITE32(2);
  1609. WRITE32(bmval0);
  1610. WRITE32(bmval1);
  1611. } else {
  1612. WRITE32(1);
  1613. WRITE32(bmval0);
  1614. }
  1615. attrlenp = p++; /* to be backfilled later */
  1616. if (bmval0 & FATTR4_WORD0_SUPPORTED_ATTRS) {
  1617. u32 word0 = nfsd_suppattrs0(minorversion);
  1618. u32 word1 = nfsd_suppattrs1(minorversion);
  1619. u32 word2 = nfsd_suppattrs2(minorversion);
  1620. if ((buflen -= 12) < 0)
  1621. goto out_resource;
  1622. if (!aclsupport)
  1623. word0 &= ~FATTR4_WORD0_ACL;
  1624. if (!word2) {
  1625. WRITE32(2);
  1626. WRITE32(word0);
  1627. WRITE32(word1);
  1628. } else {
  1629. WRITE32(3);
  1630. WRITE32(word0);
  1631. WRITE32(word1);
  1632. WRITE32(word2);
  1633. }
  1634. }
  1635. if (bmval0 & FATTR4_WORD0_TYPE) {
  1636. if ((buflen -= 4) < 0)
  1637. goto out_resource;
  1638. dummy = nfs4_ftypes[(stat.mode & S_IFMT) >> 12];
  1639. if (dummy == NF4BAD)
  1640. goto out_serverfault;
  1641. WRITE32(dummy);
  1642. }
  1643. if (bmval0 & FATTR4_WORD0_FH_EXPIRE_TYPE) {
  1644. if ((buflen -= 4) < 0)
  1645. goto out_resource;
  1646. if (exp->ex_flags & NFSEXP_NOSUBTREECHECK)
  1647. WRITE32(NFS4_FH_PERSISTENT);
  1648. else
  1649. WRITE32(NFS4_FH_PERSISTENT|NFS4_FH_VOL_RENAME);
  1650. }
  1651. if (bmval0 & FATTR4_WORD0_CHANGE) {
  1652. if ((buflen -= 8) < 0)
  1653. goto out_resource;
  1654. write_change(&p, &stat, dentry->d_inode);
  1655. }
  1656. if (bmval0 & FATTR4_WORD0_SIZE) {
  1657. if ((buflen -= 8) < 0)
  1658. goto out_resource;
  1659. WRITE64(stat.size);
  1660. }
  1661. if (bmval0 & FATTR4_WORD0_LINK_SUPPORT) {
  1662. if ((buflen -= 4) < 0)
  1663. goto out_resource;
  1664. WRITE32(1);
  1665. }
  1666. if (bmval0 & FATTR4_WORD0_SYMLINK_SUPPORT) {
  1667. if ((buflen -= 4) < 0)
  1668. goto out_resource;
  1669. WRITE32(1);
  1670. }
  1671. if (bmval0 & FATTR4_WORD0_NAMED_ATTR) {
  1672. if ((buflen -= 4) < 0)
  1673. goto out_resource;
  1674. WRITE32(0);
  1675. }
  1676. if (bmval0 & FATTR4_WORD0_FSID) {
  1677. if ((buflen -= 16) < 0)
  1678. goto out_resource;
  1679. if (exp->ex_fslocs.migrated) {
  1680. WRITE64(NFS4_REFERRAL_FSID_MAJOR);
  1681. WRITE64(NFS4_REFERRAL_FSID_MINOR);
  1682. } else switch(fsid_source(fhp)) {
  1683. case FSIDSOURCE_FSID:
  1684. WRITE64((u64)exp->ex_fsid);
  1685. WRITE64((u64)0);
  1686. break;
  1687. case FSIDSOURCE_DEV:
  1688. WRITE32(0);
  1689. WRITE32(MAJOR(stat.dev));
  1690. WRITE32(0);
  1691. WRITE32(MINOR(stat.dev));
  1692. break;
  1693. case FSIDSOURCE_UUID:
  1694. WRITEMEM(exp->ex_uuid, 16);
  1695. break;
  1696. }
  1697. }
  1698. if (bmval0 & FATTR4_WORD0_UNIQUE_HANDLES) {
  1699. if ((buflen -= 4) < 0)
  1700. goto out_resource;
  1701. WRITE32(0);
  1702. }
  1703. if (bmval0 & FATTR4_WORD0_LEASE_TIME) {
  1704. if ((buflen -= 4) < 0)
  1705. goto out_resource;
  1706. WRITE32(NFSD_LEASE_TIME);
  1707. }
  1708. if (bmval0 & FATTR4_WORD0_RDATTR_ERROR) {
  1709. if ((buflen -= 4) < 0)
  1710. goto out_resource;
  1711. WRITE32(rdattr_err);
  1712. }
  1713. if (bmval0 & FATTR4_WORD0_ACL) {
  1714. struct nfs4_ace *ace;
  1715. if (acl == NULL) {
  1716. if ((buflen -= 4) < 0)
  1717. goto out_resource;
  1718. WRITE32(0);
  1719. goto out_acl;
  1720. }
  1721. if ((buflen -= 4) < 0)
  1722. goto out_resource;
  1723. WRITE32(acl->naces);
  1724. for (ace = acl->aces; ace < acl->aces + acl->naces; ace++) {
  1725. if ((buflen -= 4*3) < 0)
  1726. goto out_resource;
  1727. WRITE32(ace->type);
  1728. WRITE32(ace->flag);
  1729. WRITE32(ace->access_mask & NFS4_ACE_MASK_ALL);
  1730. status = nfsd4_encode_aclname(rqstp, ace->whotype,
  1731. ace->who, ace->flag & NFS4_ACE_IDENTIFIER_GROUP,
  1732. &p, &buflen);
  1733. if (status == nfserr_resource)
  1734. goto out_resource;
  1735. if (status)
  1736. goto out;
  1737. }
  1738. }
  1739. out_acl:
  1740. if (bmval0 & FATTR4_WORD0_ACLSUPPORT) {
  1741. if ((buflen -= 4) < 0)
  1742. goto out_resource;
  1743. WRITE32(aclsupport ?
  1744. ACL4_SUPPORT_ALLOW_ACL|ACL4_SUPPORT_DENY_ACL : 0);
  1745. }
  1746. if (bmval0 & FATTR4_WORD0_CANSETTIME) {
  1747. if ((buflen -= 4) < 0)
  1748. goto out_resource;
  1749. WRITE32(1);
  1750. }
  1751. if (bmval0 & FATTR4_WORD0_CASE_INSENSITIVE) {
  1752. if ((buflen -= 4) < 0)
  1753. goto out_resource;
  1754. WRITE32(1);
  1755. }
  1756. if (bmval0 & FATTR4_WORD0_CASE_PRESERVING) {
  1757. if ((buflen -= 4) < 0)
  1758. goto out_resource;
  1759. WRITE32(1);
  1760. }
  1761. if (bmval0 & FATTR4_WORD0_CHOWN_RESTRICTED) {
  1762. if ((buflen -= 4) < 0)
  1763. goto out_resource;
  1764. WRITE32(1);
  1765. }
  1766. if (bmval0 & FATTR4_WORD0_FILEHANDLE) {
  1767. buflen -= (XDR_QUADLEN(fhp->fh_handle.fh_size) << 2) + 4;
  1768. if (buflen < 0)
  1769. goto out_resource;
  1770. WRITE32(fhp->fh_handle.fh_size);
  1771. WRITEMEM(&fhp->fh_handle.fh_base, fhp->fh_handle.fh_size);
  1772. }
  1773. if (bmval0 & FATTR4_WORD0_FILEID) {
  1774. if ((buflen -= 8) < 0)
  1775. goto out_resource;
  1776. WRITE64(stat.ino);
  1777. }
  1778. if (bmval0 & FATTR4_WORD0_FILES_AVAIL) {
  1779. if ((buflen -= 8) < 0)
  1780. goto out_resource;
  1781. WRITE64((u64) statfs.f_ffree);
  1782. }
  1783. if (bmval0 & FATTR4_WORD0_FILES_FREE) {
  1784. if ((buflen -= 8) < 0)
  1785. goto out_resource;
  1786. WRITE64((u64) statfs.f_ffree);
  1787. }
  1788. if (bmval0 & FATTR4_WORD0_FILES_TOTAL) {
  1789. if ((buflen -= 8) < 0)
  1790. goto out_resource;
  1791. WRITE64((u64) statfs.f_files);
  1792. }
  1793. if (bmval0 & FATTR4_WORD0_FS_LOCATIONS) {
  1794. status = nfsd4_encode_fs_locations(rqstp, exp, &p, &buflen);
  1795. if (status == nfserr_resource)
  1796. goto out_resource;
  1797. if (status)
  1798. goto out;
  1799. }
  1800. if (bmval0 & FATTR4_WORD0_HOMOGENEOUS) {
  1801. if ((buflen -= 4) < 0)
  1802. goto out_resource;
  1803. WRITE32(1);
  1804. }
  1805. if (bmval0 & FATTR4_WORD0_MAXFILESIZE) {
  1806. if ((buflen -= 8) < 0)
  1807. goto out_resource;
  1808. WRITE64(~(u64)0);
  1809. }
  1810. if (bmval0 & FATTR4_WORD0_MAXLINK) {
  1811. if ((buflen -= 4) < 0)
  1812. goto out_resource;
  1813. WRITE32(255);
  1814. }
  1815. if (bmval0 & FATTR4_WORD0_MAXNAME) {
  1816. if ((buflen -= 4) < 0)
  1817. goto out_resource;
  1818. WRITE32(statfs.f_namelen);
  1819. }
  1820. if (bmval0 & FATTR4_WORD0_MAXREAD) {
  1821. if ((buflen -= 8) < 0)
  1822. goto out_resource;
  1823. WRITE64((u64) svc_max_payload(rqstp));
  1824. }
  1825. if (bmval0 & FATTR4_WORD0_MAXWRITE) {
  1826. if ((buflen -= 8) < 0)
  1827. goto out_resource;
  1828. WRITE64((u64) svc_max_payload(rqstp));
  1829. }
  1830. if (bmval1 & FATTR4_WORD1_MODE) {
  1831. if ((buflen -= 4) < 0)
  1832. goto out_resource;
  1833. WRITE32(stat.mode & S_IALLUGO);
  1834. }
  1835. if (bmval1 & FATTR4_WORD1_NO_TRUNC) {
  1836. if ((buflen -= 4) < 0)
  1837. goto out_resource;
  1838. WRITE32(1);
  1839. }
  1840. if (bmval1 & FATTR4_WORD1_NUMLINKS) {
  1841. if ((buflen -= 4) < 0)
  1842. goto out_resource;
  1843. WRITE32(stat.nlink);
  1844. }
  1845. if (bmval1 & FATTR4_WORD1_OWNER) {
  1846. status = nfsd4_encode_user(rqstp, stat.uid, &p, &buflen);
  1847. if (status == nfserr_resource)
  1848. goto out_resource;
  1849. if (status)
  1850. goto out;
  1851. }
  1852. if (bmval1 & FATTR4_WORD1_OWNER_GROUP) {
  1853. status = nfsd4_encode_group(rqstp, stat.gid, &p, &buflen);
  1854. if (status == nfserr_resource)
  1855. goto out_resource;
  1856. if (status)
  1857. goto out;
  1858. }
  1859. if (bmval1 & FATTR4_WORD1_RAWDEV) {
  1860. if ((buflen -= 8) < 0)
  1861. goto out_resource;
  1862. WRITE32((u32) MAJOR(stat.rdev));
  1863. WRITE32((u32) MINOR(stat.rdev));
  1864. }
  1865. if (bmval1 & FATTR4_WORD1_SPACE_AVAIL) {
  1866. if ((buflen -= 8) < 0)
  1867. goto out_resource;
  1868. dummy64 = (u64)statfs.f_bavail * (u64)statfs.f_bsize;
  1869. WRITE64(dummy64);
  1870. }
  1871. if (bmval1 & FATTR4_WORD1_SPACE_FREE) {
  1872. if ((buflen -= 8) < 0)
  1873. goto out_resource;
  1874. dummy64 = (u64)statfs.f_bfree * (u64)statfs.f_bsize;
  1875. WRITE64(dummy64);
  1876. }
  1877. if (bmval1 & FATTR4_WORD1_SPACE_TOTAL) {
  1878. if ((buflen -= 8) < 0)
  1879. goto out_resource;
  1880. dummy64 = (u64)statfs.f_blocks * (u64)statfs.f_bsize;
  1881. WRITE64(dummy64);
  1882. }
  1883. if (bmval1 & FATTR4_WORD1_SPACE_USED) {
  1884. if ((buflen -= 8) < 0)
  1885. goto out_resource;
  1886. dummy64 = (u64)stat.blocks << 9;
  1887. WRITE64(dummy64);
  1888. }
  1889. if (bmval1 & FATTR4_WORD1_TIME_ACCESS) {
  1890. if ((buflen -= 12) < 0)
  1891. goto out_resource;
  1892. WRITE32(0);
  1893. WRITE32(stat.atime.tv_sec);
  1894. WRITE32(stat.atime.tv_nsec);
  1895. }
  1896. if (bmval1 & FATTR4_WORD1_TIME_DELTA) {
  1897. if ((buflen -= 12) < 0)
  1898. goto out_resource;
  1899. WRITE32(0);
  1900. WRITE32(1);
  1901. WRITE32(0);
  1902. }
  1903. if (bmval1 & FATTR4_WORD1_TIME_METADATA) {
  1904. if ((buflen -= 12) < 0)
  1905. goto out_resource;
  1906. WRITE32(0);
  1907. WRITE32(stat.ctime.tv_sec);
  1908. WRITE32(stat.ctime.tv_nsec);
  1909. }
  1910. if (bmval1 & FATTR4_WORD1_TIME_MODIFY) {
  1911. if ((buflen -= 12) < 0)
  1912. goto out_resource;
  1913. WRITE32(0);
  1914. WRITE32(stat.mtime.tv_sec);
  1915. WRITE32(stat.mtime.tv_nsec);
  1916. }
  1917. if (bmval1 & FATTR4_WORD1_MOUNTED_ON_FILEID) {
  1918. if ((buflen -= 8) < 0)
  1919. goto out_resource;
  1920. /*
  1921. * Get parent's attributes if not ignoring crossmount
  1922. * and this is the root of a cross-mounted filesystem.
  1923. */
  1924. if (ignore_crossmnt == 0 &&
  1925. exp->ex_path.mnt->mnt_root->d_inode == dentry->d_inode) {
  1926. err = vfs_getattr(exp->ex_path.mnt->mnt_parent,
  1927. exp->ex_path.mnt->mnt_mountpoint, &stat);
  1928. if (err)
  1929. goto out_nfserr;
  1930. }
  1931. WRITE64(stat.ino);
  1932. }
  1933. if (bmval2 & FATTR4_WORD2_SUPPATTR_EXCLCREAT) {
  1934. WRITE32(3);
  1935. WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD0);
  1936. WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD1);
  1937. WRITE32(NFSD_SUPPATTR_EXCLCREAT_WORD2);
  1938. }
  1939. *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
  1940. *countp = p - buffer;
  1941. status = nfs_ok;
  1942. out:
  1943. kfree(acl);
  1944. if (fhp == &tempfh)
  1945. fh_put(&tempfh);
  1946. return status;
  1947. out_nfserr:
  1948. status = nfserrno(err);
  1949. goto out;
  1950. out_resource:
  1951. *countp = 0;
  1952. status = nfserr_resource;
  1953. goto out;
  1954. out_serverfault:
  1955. status = nfserr_serverfault;
  1956. goto out;
  1957. }
  1958. static inline int attributes_need_mount(u32 *bmval)
  1959. {
  1960. if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
  1961. return 1;
  1962. if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
  1963. return 1;
  1964. return 0;
  1965. }
  1966. static __be32
  1967. nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
  1968. const char *name, int namlen, __be32 *p, int *buflen)
  1969. {
  1970. struct svc_export *exp = cd->rd_fhp->fh_export;
  1971. struct dentry *dentry;
  1972. __be32 nfserr;
  1973. int ignore_crossmnt = 0;
  1974. dentry = lookup_one_len(name, cd->rd_fhp->fh_dentry, namlen);
  1975. if (IS_ERR(dentry))
  1976. return nfserrno(PTR_ERR(dentry));
  1977. if (!dentry->d_inode) {
  1978. /*
  1979. * nfsd_buffered_readdir drops the i_mutex between
  1980. * readdir and calling this callback, leaving a window
  1981. * where this directory entry could have gone away.
  1982. */
  1983. dput(dentry);
  1984. return nfserr_noent;
  1985. }
  1986. exp_get(exp);
  1987. /*
  1988. * In the case of a mountpoint, the client may be asking for
  1989. * attributes that are only properties of the underlying filesystem
  1990. * as opposed to the cross-mounted file system. In such a case,
  1991. * we will not follow the cross mount and will fill the attribtutes
  1992. * directly from the mountpoint dentry.
  1993. */
  1994. if (d_mountpoint(dentry) && !attributes_need_mount(cd->rd_bmval))
  1995. ignore_crossmnt = 1;
  1996. else if (d_mountpoint(dentry)) {
  1997. int err;
  1998. /*
  1999. * Why the heck aren't we just using nfsd_lookup??
  2000. * Different "."/".." handling? Something else?
  2001. * At least, add a comment here to explain....
  2002. */
  2003. err = nfsd_cross_mnt(cd->rd_rqstp, &dentry, &exp);
  2004. if (err) {
  2005. nfserr = nfserrno(err);
  2006. goto out_put;
  2007. }
  2008. nfserr = check_nfsd_access(exp, cd->rd_rqstp);
  2009. if (nfserr)
  2010. goto out_put;
  2011. }
  2012. nfserr = nfsd4_encode_fattr(NULL, exp, dentry, p, buflen, cd->rd_bmval,
  2013. cd->rd_rqstp, ignore_crossmnt);
  2014. out_put:
  2015. dput(dentry);
  2016. exp_put(exp);
  2017. return nfserr;
  2018. }
  2019. static __be32 *
  2020. nfsd4_encode_rdattr_error(__be32 *p, int buflen, __be32 nfserr)
  2021. {
  2022. __be32 *attrlenp;
  2023. if (buflen < 6)
  2024. return NULL;
  2025. *p++ = htonl(2);
  2026. *p++ = htonl(FATTR4_WORD0_RDATTR_ERROR); /* bmval0 */
  2027. *p++ = htonl(0); /* bmval1 */
  2028. attrlenp = p++;
  2029. *p++ = nfserr; /* no htonl */
  2030. *attrlenp = htonl((char *)p - (char *)attrlenp - 4);
  2031. return p;
  2032. }
  2033. static int
  2034. nfsd4_encode_dirent(void *ccdv, const char *name, int namlen,
  2035. loff_t offset, u64 ino, unsigned int d_type)
  2036. {
  2037. struct readdir_cd *ccd = ccdv;
  2038. struct nfsd4_readdir *cd = container_of(ccd, struct nfsd4_readdir, common);
  2039. int buflen;
  2040. __be32 *p = cd->buffer;
  2041. __be32 *cookiep;
  2042. __be32 nfserr = nfserr_toosmall;
  2043. /* In nfsv4, "." and ".." never make it onto the wire.. */
  2044. if (name && isdotent(name, namlen)) {
  2045. cd->common.err = nfs_ok;
  2046. return 0;
  2047. }
  2048. if (cd->offset)
  2049. xdr_encode_hyper(cd->offset, (u64) offset);
  2050. buflen = cd->buflen - 4 - XDR_QUADLEN(namlen);
  2051. if (buflen < 0)
  2052. goto fail;
  2053. *p++ = xdr_one; /* mark entry present */
  2054. cookiep = p;
  2055. p = xdr_encode_hyper(p, NFS_OFFSET_MAX); /* offset of next entry */
  2056. p = xdr_encode_array(p, name, namlen); /* name length & name */
  2057. nfserr = nfsd4_encode_dirent_fattr(cd, name, namlen, p, &buflen);
  2058. switch (nfserr) {
  2059. case nfs_ok:
  2060. p += buflen;
  2061. break;
  2062. case nfserr_resource:
  2063. nfserr = nfserr_toosmall;
  2064. goto fail;
  2065. case nfserr_dropit:
  2066. goto fail;
  2067. case nfserr_noent:
  2068. goto skip_entry;
  2069. default:
  2070. /*
  2071. * If the client requested the RDATTR_ERROR attribute,
  2072. * we stuff the error code into this attribute
  2073. * and continue. If this attribute was not requested,
  2074. * then in accordance with the spec, we fail the
  2075. * entire READDIR operation(!)
  2076. */
  2077. if (!(cd->rd_bmval[0] & FATTR4_WORD0_RDATTR_ERROR))
  2078. goto fail;
  2079. p = nfsd4_encode_rdattr_error(p, buflen, nfserr);
  2080. if (p == NULL) {
  2081. nfserr = nfserr_toosmall;
  2082. goto fail;
  2083. }
  2084. }
  2085. cd->buflen -= (p - cd->buffer);
  2086. cd->buffer = p;
  2087. cd->offset = cookiep;
  2088. skip_entry:
  2089. cd->common.err = nfs_ok;
  2090. return 0;
  2091. fail:
  2092. cd->common.err = nfserr;
  2093. return -EINVAL;
  2094. }
  2095. static void
  2096. nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid)
  2097. {
  2098. __be32 *p;
  2099. RESERVE_SPACE(sizeof(stateid_t));
  2100. WRITE32(sid->si_generation);
  2101. WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
  2102. ADJUST_ARGS();
  2103. }
  2104. static __be32
  2105. nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access)
  2106. {
  2107. __be32 *p;
  2108. if (!nfserr) {
  2109. RESERVE_SPACE(8);
  2110. WRITE32(access->ac_supported);
  2111. WRITE32(access->ac_resp_access);
  2112. ADJUST_ARGS();
  2113. }
  2114. return nfserr;
  2115. }
  2116. static __be32
  2117. nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_close *close)
  2118. {
  2119. ENCODE_SEQID_OP_HEAD;
  2120. if (!nfserr)
  2121. nfsd4_encode_stateid(resp, &close->cl_stateid);
  2122. ENCODE_SEQID_OP_TAIL(close->cl_stateowner);
  2123. return nfserr;
  2124. }
  2125. static __be32
  2126. nfsd4_encode_commit(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_commit *commit)
  2127. {
  2128. __be32 *p;
  2129. if (!nfserr) {
  2130. RESERVE_SPACE(8);
  2131. WRITEMEM(commit->co_verf.data, 8);
  2132. ADJUST_ARGS();
  2133. }
  2134. return nfserr;
  2135. }
  2136. static __be32
  2137. nfsd4_encode_create(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_create *create)
  2138. {
  2139. __be32 *p;
  2140. if (!nfserr) {
  2141. RESERVE_SPACE(32);
  2142. write_cinfo(&p, &create->cr_cinfo);
  2143. WRITE32(2);
  2144. WRITE32(create->cr_bmval[0]);
  2145. WRITE32(create->cr_bmval[1]);
  2146. ADJUST_ARGS();
  2147. }
  2148. return nfserr;
  2149. }
  2150. static __be32
  2151. nfsd4_encode_getattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_getattr *getattr)
  2152. {
  2153. struct svc_fh *fhp = getattr->ga_fhp;
  2154. int buflen;
  2155. if (nfserr)
  2156. return nfserr;
  2157. buflen = resp->end - resp->p - (COMPOUND_ERR_SLACK_SPACE >> 2);
  2158. nfserr = nfsd4_encode_fattr(fhp, fhp->fh_export, fhp->fh_dentry,
  2159. resp->p, &buflen, getattr->ga_bmval,
  2160. resp->rqstp, 0);
  2161. if (!nfserr)
  2162. resp->p += buflen;
  2163. return nfserr;
  2164. }
  2165. static __be32
  2166. nfsd4_encode_getfh(struct nfsd4_compoundres *resp, __be32 nfserr, struct svc_fh **fhpp)
  2167. {
  2168. struct svc_fh *fhp = *fhpp;
  2169. unsigned int len;
  2170. __be32 *p;
  2171. if (!nfserr) {
  2172. len = fhp->fh_handle.fh_size;
  2173. RESERVE_SPACE(len + 4);
  2174. WRITE32(len);
  2175. WRITEMEM(&fhp->fh_handle.fh_base, len);
  2176. ADJUST_ARGS();
  2177. }
  2178. return nfserr;
  2179. }
  2180. /*
  2181. * Including all fields other than the name, a LOCK4denied structure requires
  2182. * 8(clientid) + 4(namelen) + 8(offset) + 8(length) + 4(type) = 32 bytes.
  2183. */
  2184. static void
  2185. nfsd4_encode_lock_denied(struct nfsd4_compoundres *resp, struct nfsd4_lock_denied *ld)
  2186. {
  2187. __be32 *p;
  2188. RESERVE_SPACE(32 + XDR_LEN(ld->ld_sop ? ld->ld_sop->so_owner.len : 0));
  2189. WRITE64(ld->ld_start);
  2190. WRITE64(ld->ld_length);
  2191. WRITE32(ld->ld_type);
  2192. if (ld->ld_sop) {
  2193. WRITEMEM(&ld->ld_clientid, 8);
  2194. WRITE32(ld->ld_sop->so_owner.len);
  2195. WRITEMEM(ld->ld_sop->so_owner.data, ld->ld_sop->so_owner.len);
  2196. kref_put(&ld->ld_sop->so_ref, nfs4_free_stateowner);
  2197. } else { /* non - nfsv4 lock in conflict, no clientid nor owner */
  2198. WRITE64((u64)0); /* clientid */
  2199. WRITE32(0); /* length of owner name */
  2200. }
  2201. ADJUST_ARGS();
  2202. }
  2203. static __be32
  2204. nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lock *lock)
  2205. {
  2206. ENCODE_SEQID_OP_HEAD;
  2207. if (!nfserr)
  2208. nfsd4_encode_stateid(resp, &lock->lk_resp_stateid);
  2209. else if (nfserr == nfserr_denied)
  2210. nfsd4_encode_lock_denied(resp, &lock->lk_denied);
  2211. ENCODE_SEQID_OP_TAIL(lock->lk_replay_owner);
  2212. return nfserr;
  2213. }
  2214. static __be32
  2215. nfsd4_encode_lockt(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lockt *lockt)
  2216. {
  2217. if (nfserr == nfserr_denied)
  2218. nfsd4_encode_lock_denied(resp, &lockt->lt_denied);
  2219. return nfserr;
  2220. }
  2221. static __be32
  2222. nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_locku *locku)
  2223. {
  2224. ENCODE_SEQID_OP_HEAD;
  2225. if (!nfserr)
  2226. nfsd4_encode_stateid(resp, &locku->lu_stateid);
  2227. ENCODE_SEQID_OP_TAIL(locku->lu_stateowner);
  2228. return nfserr;
  2229. }
  2230. static __be32
  2231. nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_link *link)
  2232. {
  2233. __be32 *p;
  2234. if (!nfserr) {
  2235. RESERVE_SPACE(20);
  2236. write_cinfo(&p, &link->li_cinfo);
  2237. ADJUST_ARGS();
  2238. }
  2239. return nfserr;
  2240. }
  2241. static __be32
  2242. nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open)
  2243. {
  2244. __be32 *p;
  2245. ENCODE_SEQID_OP_HEAD;
  2246. if (nfserr)
  2247. goto out;
  2248. nfsd4_encode_stateid(resp, &open->op_stateid);
  2249. RESERVE_SPACE(40);
  2250. write_cinfo(&p, &open->op_cinfo);
  2251. WRITE32(open->op_rflags);
  2252. WRITE32(2);
  2253. WRITE32(open->op_bmval[0]);
  2254. WRITE32(open->op_bmval[1]);
  2255. WRITE32(open->op_delegate_type);
  2256. ADJUST_ARGS();
  2257. switch (open->op_delegate_type) {
  2258. case NFS4_OPEN_DELEGATE_NONE:
  2259. break;
  2260. case NFS4_OPEN_DELEGATE_READ:
  2261. nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
  2262. RESERVE_SPACE(20);
  2263. WRITE32(open->op_recall);
  2264. /*
  2265. * TODO: ACE's in delegations
  2266. */
  2267. WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
  2268. WRITE32(0);
  2269. WRITE32(0);
  2270. WRITE32(0); /* XXX: is NULL principal ok? */
  2271. ADJUST_ARGS();
  2272. break;
  2273. case NFS4_OPEN_DELEGATE_WRITE:
  2274. nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
  2275. RESERVE_SPACE(32);
  2276. WRITE32(0);
  2277. /*
  2278. * TODO: space_limit's in delegations
  2279. */
  2280. WRITE32(NFS4_LIMIT_SIZE);
  2281. WRITE32(~(u32)0);
  2282. WRITE32(~(u32)0);
  2283. /*
  2284. * TODO: ACE's in delegations
  2285. */
  2286. WRITE32(NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE);
  2287. WRITE32(0);
  2288. WRITE32(0);
  2289. WRITE32(0); /* XXX: is NULL principal ok? */
  2290. ADJUST_ARGS();
  2291. break;
  2292. default:
  2293. BUG();
  2294. }
  2295. /* XXX save filehandle here */
  2296. out:
  2297. ENCODE_SEQID_OP_TAIL(open->op_stateowner);
  2298. return nfserr;
  2299. }
  2300. static __be32
  2301. nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc)
  2302. {
  2303. ENCODE_SEQID_OP_HEAD;
  2304. if (!nfserr)
  2305. nfsd4_encode_stateid(resp, &oc->oc_resp_stateid);
  2306. ENCODE_SEQID_OP_TAIL(oc->oc_stateowner);
  2307. return nfserr;
  2308. }
  2309. static __be32
  2310. nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od)
  2311. {
  2312. ENCODE_SEQID_OP_HEAD;
  2313. if (!nfserr)
  2314. nfsd4_encode_stateid(resp, &od->od_stateid);
  2315. ENCODE_SEQID_OP_TAIL(od->od_stateowner);
  2316. return nfserr;
  2317. }
  2318. static __be32
  2319. nfsd4_encode_read(struct nfsd4_compoundres *resp, __be32 nfserr,
  2320. struct nfsd4_read *read)
  2321. {
  2322. u32 eof;
  2323. int v, pn;
  2324. unsigned long maxcount;
  2325. long len;
  2326. __be32 *p;
  2327. if (nfserr)
  2328. return nfserr;
  2329. if (resp->xbuf->page_len)
  2330. return nfserr_resource;
  2331. RESERVE_SPACE(8); /* eof flag and byte count */
  2332. maxcount = svc_max_payload(resp->rqstp);
  2333. if (maxcount > read->rd_length)
  2334. maxcount = read->rd_length;
  2335. len = maxcount;
  2336. v = 0;
  2337. while (len > 0) {
  2338. pn = resp->rqstp->rq_resused++;
  2339. resp->rqstp->rq_vec[v].iov_base =
  2340. page_address(resp->rqstp->rq_respages[pn]);
  2341. resp->rqstp->rq_vec[v].iov_len =
  2342. len < PAGE_SIZE ? len : PAGE_SIZE;
  2343. v++;
  2344. len -= PAGE_SIZE;
  2345. }
  2346. read->rd_vlen = v;
  2347. nfserr = nfsd_read(read->rd_rqstp, read->rd_fhp, read->rd_filp,
  2348. read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen,
  2349. &maxcount);
  2350. if (nfserr == nfserr_symlink)
  2351. nfserr = nfserr_inval;
  2352. if (nfserr)
  2353. return nfserr;
  2354. eof = (read->rd_offset + maxcount >=
  2355. read->rd_fhp->fh_dentry->d_inode->i_size);
  2356. WRITE32(eof);
  2357. WRITE32(maxcount);
  2358. ADJUST_ARGS();
  2359. resp->xbuf->head[0].iov_len = (char*)p
  2360. - (char*)resp->xbuf->head[0].iov_base;
  2361. resp->xbuf->page_len = maxcount;
  2362. /* Use rest of head for padding and remaining ops: */
  2363. resp->xbuf->tail[0].iov_base = p;
  2364. resp->xbuf->tail[0].iov_len = 0;
  2365. if (maxcount&3) {
  2366. RESERVE_SPACE(4);
  2367. WRITE32(0);
  2368. resp->xbuf->tail[0].iov_base += maxcount&3;
  2369. resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
  2370. ADJUST_ARGS();
  2371. }
  2372. return 0;
  2373. }
  2374. static __be32
  2375. nfsd4_encode_readlink(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readlink *readlink)
  2376. {
  2377. int maxcount;
  2378. char *page;
  2379. __be32 *p;
  2380. if (nfserr)
  2381. return nfserr;
  2382. if (resp->xbuf->page_len)
  2383. return nfserr_resource;
  2384. page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]);
  2385. maxcount = PAGE_SIZE;
  2386. RESERVE_SPACE(4);
  2387. /*
  2388. * XXX: By default, the ->readlink() VFS op will truncate symlinks
  2389. * if they would overflow the buffer. Is this kosher in NFSv4? If
  2390. * not, one easy fix is: if ->readlink() precisely fills the buffer,
  2391. * assume that truncation occurred, and return NFS4ERR_RESOURCE.
  2392. */
  2393. nfserr = nfsd_readlink(readlink->rl_rqstp, readlink->rl_fhp, page, &maxcount);
  2394. if (nfserr == nfserr_isdir)
  2395. return nfserr_inval;
  2396. if (nfserr)
  2397. return nfserr;
  2398. WRITE32(maxcount);
  2399. ADJUST_ARGS();
  2400. resp->xbuf->head[0].iov_len = (char*)p
  2401. - (char*)resp->xbuf->head[0].iov_base;
  2402. resp->xbuf->page_len = maxcount;
  2403. /* Use rest of head for padding and remaining ops: */
  2404. resp->xbuf->tail[0].iov_base = p;
  2405. resp->xbuf->tail[0].iov_len = 0;
  2406. if (maxcount&3) {
  2407. RESERVE_SPACE(4);
  2408. WRITE32(0);
  2409. resp->xbuf->tail[0].iov_base += maxcount&3;
  2410. resp->xbuf->tail[0].iov_len = 4 - (maxcount&3);
  2411. ADJUST_ARGS();
  2412. }
  2413. return 0;
  2414. }
  2415. static __be32
  2416. nfsd4_encode_readdir(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_readdir *readdir)
  2417. {
  2418. int maxcount;
  2419. loff_t offset;
  2420. __be32 *page, *savep, *tailbase;
  2421. __be32 *p;
  2422. if (nfserr)
  2423. return nfserr;
  2424. if (resp->xbuf->page_len)
  2425. return nfserr_resource;
  2426. RESERVE_SPACE(8); /* verifier */
  2427. savep = p;
  2428. /* XXX: Following NFSv3, we ignore the READDIR verifier for now. */
  2429. WRITE32(0);
  2430. WRITE32(0);
  2431. ADJUST_ARGS();
  2432. resp->xbuf->head[0].iov_len = ((char*)resp->p) - (char*)resp->xbuf->head[0].iov_base;
  2433. tailbase = p;
  2434. maxcount = PAGE_SIZE;
  2435. if (maxcount > readdir->rd_maxcount)
  2436. maxcount = readdir->rd_maxcount;
  2437. /*
  2438. * Convert from bytes to words, account for the two words already
  2439. * written, make sure to leave two words at the end for the next
  2440. * pointer and eof field.
  2441. */
  2442. maxcount = (maxcount >> 2) - 4;
  2443. if (maxcount < 0) {
  2444. nfserr = nfserr_toosmall;
  2445. goto err_no_verf;
  2446. }
  2447. page = page_address(resp->rqstp->rq_respages[resp->rqstp->rq_resused++]);
  2448. readdir->common.err = 0;
  2449. readdir->buflen = maxcount;
  2450. readdir->buffer = page;
  2451. readdir->offset = NULL;
  2452. offset = readdir->rd_cookie;
  2453. nfserr = nfsd_readdir(readdir->rd_rqstp, readdir->rd_fhp,
  2454. &offset,
  2455. &readdir->common, nfsd4_encode_dirent);
  2456. if (nfserr == nfs_ok &&
  2457. readdir->common.err == nfserr_toosmall &&
  2458. readdir->buffer == page)
  2459. nfserr = nfserr_toosmall;
  2460. if (nfserr == nfserr_symlink)
  2461. nfserr = nfserr_notdir;
  2462. if (nfserr)
  2463. goto err_no_verf;
  2464. if (readdir->offset)
  2465. xdr_encode_hyper(readdir->offset, offset);
  2466. p = readdir->buffer;
  2467. *p++ = 0; /* no more entries */
  2468. *p++ = htonl(readdir->common.err == nfserr_eof);
  2469. resp->xbuf->page_len = ((char*)p) - (char*)page_address(
  2470. resp->rqstp->rq_respages[resp->rqstp->rq_resused-1]);
  2471. /* Use rest of head for padding and remaining ops: */
  2472. resp->xbuf->tail[0].iov_base = tailbase;
  2473. resp->xbuf->tail[0].iov_len = 0;
  2474. resp->p = resp->xbuf->tail[0].iov_base;
  2475. resp->end = resp->p + (PAGE_SIZE - resp->xbuf->head[0].iov_len)/4;
  2476. return 0;
  2477. err_no_verf:
  2478. p = savep;
  2479. ADJUST_ARGS();
  2480. return nfserr;
  2481. }
  2482. static __be32
  2483. nfsd4_encode_remove(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_remove *remove)
  2484. {
  2485. __be32 *p;
  2486. if (!nfserr) {
  2487. RESERVE_SPACE(20);
  2488. write_cinfo(&p, &remove->rm_cinfo);
  2489. ADJUST_ARGS();
  2490. }
  2491. return nfserr;
  2492. }
  2493. static __be32
  2494. nfsd4_encode_rename(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_rename *rename)
  2495. {
  2496. __be32 *p;
  2497. if (!nfserr) {
  2498. RESERVE_SPACE(40);
  2499. write_cinfo(&p, &rename->rn_sinfo);
  2500. write_cinfo(&p, &rename->rn_tinfo);
  2501. ADJUST_ARGS();
  2502. }
  2503. return nfserr;
  2504. }
  2505. static __be32
  2506. nfsd4_encode_secinfo(struct nfsd4_compoundres *resp, __be32 nfserr,
  2507. struct nfsd4_secinfo *secinfo)
  2508. {
  2509. int i = 0;
  2510. struct svc_export *exp = secinfo->si_exp;
  2511. u32 nflavs;
  2512. struct exp_flavor_info *flavs;
  2513. struct exp_flavor_info def_flavs[2];
  2514. __be32 *p;
  2515. if (nfserr)
  2516. goto out;
  2517. if (exp->ex_nflavors) {
  2518. flavs = exp->ex_flavors;
  2519. nflavs = exp->ex_nflavors;
  2520. } else { /* Handling of some defaults in absence of real secinfo: */
  2521. flavs = def_flavs;
  2522. if (exp->ex_client->flavour->flavour == RPC_AUTH_UNIX) {
  2523. nflavs = 2;
  2524. flavs[0].pseudoflavor = RPC_AUTH_UNIX;
  2525. flavs[1].pseudoflavor = RPC_AUTH_NULL;
  2526. } else if (exp->ex_client->flavour->flavour == RPC_AUTH_GSS) {
  2527. nflavs = 1;
  2528. flavs[0].pseudoflavor
  2529. = svcauth_gss_flavor(exp->ex_client);
  2530. } else {
  2531. nflavs = 1;
  2532. flavs[0].pseudoflavor
  2533. = exp->ex_client->flavour->flavour;
  2534. }
  2535. }
  2536. RESERVE_SPACE(4);
  2537. WRITE32(nflavs);
  2538. ADJUST_ARGS();
  2539. for (i = 0; i < nflavs; i++) {
  2540. u32 flav = flavs[i].pseudoflavor;
  2541. struct gss_api_mech *gm = gss_mech_get_by_pseudoflavor(flav);
  2542. if (gm) {
  2543. RESERVE_SPACE(4);
  2544. WRITE32(RPC_AUTH_GSS);
  2545. ADJUST_ARGS();
  2546. RESERVE_SPACE(4 + gm->gm_oid.len);
  2547. WRITE32(gm->gm_oid.len);
  2548. WRITEMEM(gm->gm_oid.data, gm->gm_oid.len);
  2549. ADJUST_ARGS();
  2550. RESERVE_SPACE(4);
  2551. WRITE32(0); /* qop */
  2552. ADJUST_ARGS();
  2553. RESERVE_SPACE(4);
  2554. WRITE32(gss_pseudoflavor_to_service(gm, flav));
  2555. ADJUST_ARGS();
  2556. gss_mech_put(gm);
  2557. } else {
  2558. RESERVE_SPACE(4);
  2559. WRITE32(flav);
  2560. ADJUST_ARGS();
  2561. }
  2562. }
  2563. out:
  2564. if (exp)
  2565. exp_put(exp);
  2566. return nfserr;
  2567. }
  2568. /*
  2569. * The SETATTR encode routine is special -- it always encodes a bitmap,
  2570. * regardless of the error status.
  2571. */
  2572. static __be32
  2573. nfsd4_encode_setattr(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setattr *setattr)
  2574. {
  2575. __be32 *p;
  2576. RESERVE_SPACE(12);
  2577. if (nfserr) {
  2578. WRITE32(2);
  2579. WRITE32(0);
  2580. WRITE32(0);
  2581. }
  2582. else {
  2583. WRITE32(2);
  2584. WRITE32(setattr->sa_bmval[0]);
  2585. WRITE32(setattr->sa_bmval[1]);
  2586. }
  2587. ADJUST_ARGS();
  2588. return nfserr;
  2589. }
  2590. static __be32
  2591. nfsd4_encode_setclientid(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_setclientid *scd)
  2592. {
  2593. __be32 *p;
  2594. if (!nfserr) {
  2595. RESERVE_SPACE(8 + sizeof(nfs4_verifier));
  2596. WRITEMEM(&scd->se_clientid, 8);
  2597. WRITEMEM(&scd->se_confirm, sizeof(nfs4_verifier));
  2598. ADJUST_ARGS();
  2599. }
  2600. else if (nfserr == nfserr_clid_inuse) {
  2601. RESERVE_SPACE(8);
  2602. WRITE32(0);
  2603. WRITE32(0);
  2604. ADJUST_ARGS();
  2605. }
  2606. return nfserr;
  2607. }
  2608. static __be32
  2609. nfsd4_encode_write(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_write *write)
  2610. {
  2611. __be32 *p;
  2612. if (!nfserr) {
  2613. RESERVE_SPACE(16);
  2614. WRITE32(write->wr_bytes_written);
  2615. WRITE32(write->wr_how_written);
  2616. WRITEMEM(write->wr_verifier.data, 8);
  2617. ADJUST_ARGS();
  2618. }
  2619. return nfserr;
  2620. }
  2621. static __be32
  2622. nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, int nfserr,
  2623. struct nfsd4_exchange_id *exid)
  2624. {
  2625. __be32 *p;
  2626. char *major_id;
  2627. char *server_scope;
  2628. int major_id_sz;
  2629. int server_scope_sz;
  2630. uint64_t minor_id = 0;
  2631. if (nfserr)
  2632. return nfserr;
  2633. major_id = utsname()->nodename;
  2634. major_id_sz = strlen(major_id);
  2635. server_scope = utsname()->nodename;
  2636. server_scope_sz = strlen(server_scope);
  2637. RESERVE_SPACE(
  2638. 8 /* eir_clientid */ +
  2639. 4 /* eir_sequenceid */ +
  2640. 4 /* eir_flags */ +
  2641. 4 /* spr_how (SP4_NONE) */ +
  2642. 8 /* so_minor_id */ +
  2643. 4 /* so_major_id.len */ +
  2644. (XDR_QUADLEN(major_id_sz) * 4) +
  2645. 4 /* eir_server_scope.len */ +
  2646. (XDR_QUADLEN(server_scope_sz) * 4) +
  2647. 4 /* eir_server_impl_id.count (0) */);
  2648. WRITEMEM(&exid->clientid, 8);
  2649. WRITE32(exid->seqid);
  2650. WRITE32(exid->flags);
  2651. /* state_protect4_r. Currently only support SP4_NONE */
  2652. BUG_ON(exid->spa_how != SP4_NONE);
  2653. WRITE32(exid->spa_how);
  2654. /* The server_owner struct */
  2655. WRITE64(minor_id); /* Minor id */
  2656. /* major id */
  2657. WRITE32(major_id_sz);
  2658. WRITEMEM(major_id, major_id_sz);
  2659. /* Server scope */
  2660. WRITE32(server_scope_sz);
  2661. WRITEMEM(server_scope, server_scope_sz);
  2662. /* Implementation id */
  2663. WRITE32(0); /* zero length nfs_impl_id4 array */
  2664. ADJUST_ARGS();
  2665. return 0;
  2666. }
  2667. static __be32
  2668. nfsd4_encode_create_session(struct nfsd4_compoundres *resp, int nfserr,
  2669. struct nfsd4_create_session *sess)
  2670. {
  2671. __be32 *p;
  2672. if (nfserr)
  2673. return nfserr;
  2674. RESERVE_SPACE(24);
  2675. WRITEMEM(sess->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  2676. WRITE32(sess->seqid);
  2677. WRITE32(sess->flags);
  2678. ADJUST_ARGS();
  2679. RESERVE_SPACE(28);
  2680. WRITE32(0); /* headerpadsz */
  2681. WRITE32(sess->fore_channel.maxreq_sz);
  2682. WRITE32(sess->fore_channel.maxresp_sz);
  2683. WRITE32(sess->fore_channel.maxresp_cached);
  2684. WRITE32(sess->fore_channel.maxops);
  2685. WRITE32(sess->fore_channel.maxreqs);
  2686. WRITE32(sess->fore_channel.nr_rdma_attrs);
  2687. ADJUST_ARGS();
  2688. if (sess->fore_channel.nr_rdma_attrs) {
  2689. RESERVE_SPACE(4);
  2690. WRITE32(sess->fore_channel.rdma_attrs);
  2691. ADJUST_ARGS();
  2692. }
  2693. RESERVE_SPACE(28);
  2694. WRITE32(0); /* headerpadsz */
  2695. WRITE32(sess->back_channel.maxreq_sz);
  2696. WRITE32(sess->back_channel.maxresp_sz);
  2697. WRITE32(sess->back_channel.maxresp_cached);
  2698. WRITE32(sess->back_channel.maxops);
  2699. WRITE32(sess->back_channel.maxreqs);
  2700. WRITE32(sess->back_channel.nr_rdma_attrs);
  2701. ADJUST_ARGS();
  2702. if (sess->back_channel.nr_rdma_attrs) {
  2703. RESERVE_SPACE(4);
  2704. WRITE32(sess->back_channel.rdma_attrs);
  2705. ADJUST_ARGS();
  2706. }
  2707. return 0;
  2708. }
  2709. static __be32
  2710. nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr,
  2711. struct nfsd4_destroy_session *destroy_session)
  2712. {
  2713. return nfserr;
  2714. }
  2715. __be32
  2716. nfsd4_encode_sequence(struct nfsd4_compoundres *resp, int nfserr,
  2717. struct nfsd4_sequence *seq)
  2718. {
  2719. __be32 *p;
  2720. if (nfserr)
  2721. return nfserr;
  2722. RESERVE_SPACE(NFS4_MAX_SESSIONID_LEN + 20);
  2723. WRITEMEM(seq->sessionid.data, NFS4_MAX_SESSIONID_LEN);
  2724. WRITE32(seq->seqid);
  2725. WRITE32(seq->slotid);
  2726. WRITE32(seq->maxslots);
  2727. /*
  2728. * FIXME: for now:
  2729. * target_maxslots = maxslots
  2730. * status_flags = 0
  2731. */
  2732. WRITE32(seq->maxslots);
  2733. WRITE32(0);
  2734. ADJUST_ARGS();
  2735. resp->cstate.datap = p; /* DRC cache data pointer */
  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_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 nfsd4_compound_state *cs = &resp->cstate;
  2940. struct kvec *iov;
  2941. p = resp->tagp;
  2942. *p++ = htonl(resp->taglen);
  2943. memcpy(p, resp->tag, resp->taglen);
  2944. p += XDR_QUADLEN(resp->taglen);
  2945. *p++ = htonl(resp->opcnt);
  2946. if (rqstp->rq_res.page_len)
  2947. iov = &rqstp->rq_res.tail[0];
  2948. else
  2949. iov = &rqstp->rq_res.head[0];
  2950. iov->iov_len = ((char*)resp->p) - (char*)iov->iov_base;
  2951. BUG_ON(iov->iov_len > PAGE_SIZE);
  2952. if (nfsd4_has_session(cs) && cs->status != nfserr_replay_cache) {
  2953. nfsd4_store_cache_entry(resp);
  2954. dprintk("%s: SET SLOT STATE TO AVAILABLE\n", __func__);
  2955. resp->cstate.slot->sl_inuse = false;
  2956. nfsd4_put_session(resp->cstate.session);
  2957. }
  2958. return 1;
  2959. }
  2960. /*
  2961. * Local variables:
  2962. * c-basic-offset: 8
  2963. * End:
  2964. */