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