nfs4xdr.c 82 KB

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