nfs4proc.c 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738
  1. /*
  2. * Server-side procedures 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. #include <linux/fs_struct.h>
  36. #include <linux/file.h>
  37. #include <linux/falloc.h>
  38. #include <linux/slab.h>
  39. #include <linux/kthread.h>
  40. #include <linux/namei.h>
  41. #include <linux/sunrpc/addr.h>
  42. #include <linux/nfs_ssc.h>
  43. #include "idmap.h"
  44. #include "cache.h"
  45. #include "xdr4.h"
  46. #include "vfs.h"
  47. #include "current_stateid.h"
  48. #include "netns.h"
  49. #include "acl.h"
  50. #include "pnfs.h"
  51. #include "trace.h"
  52. static bool inter_copy_offload_enable;
  53. module_param(inter_copy_offload_enable, bool, 0644);
  54. MODULE_PARM_DESC(inter_copy_offload_enable,
  55. "Enable inter server to server copy offload. Default: false");
  56. #ifdef CONFIG_NFSD_V4_2_INTER_SSC
  57. static int nfsd4_ssc_umount_timeout = 900000; /* default to 15 mins */
  58. module_param(nfsd4_ssc_umount_timeout, int, 0644);
  59. MODULE_PARM_DESC(nfsd4_ssc_umount_timeout,
  60. "idle msecs before unmount export from source server");
  61. #endif
  62. #define NFSDDBG_FACILITY NFSDDBG_PROC
  63. static u32 nfsd_attrmask[] = {
  64. NFSD_WRITEABLE_ATTRS_WORD0,
  65. NFSD_WRITEABLE_ATTRS_WORD1,
  66. NFSD_WRITEABLE_ATTRS_WORD2
  67. };
  68. static u32 nfsd41_ex_attrmask[] = {
  69. NFSD_SUPPATTR_EXCLCREAT_WORD0,
  70. NFSD_SUPPATTR_EXCLCREAT_WORD1,
  71. NFSD_SUPPATTR_EXCLCREAT_WORD2
  72. };
  73. static __be32
  74. check_attr_support(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  75. u32 *bmval, u32 *writable)
  76. {
  77. struct dentry *dentry = cstate->current_fh.fh_dentry;
  78. struct svc_export *exp = cstate->current_fh.fh_export;
  79. if (!nfsd_attrs_supported(cstate->minorversion, bmval))
  80. return nfserr_attrnotsupp;
  81. if ((bmval[0] & FATTR4_WORD0_ACL) && !IS_POSIXACL(d_inode(dentry)))
  82. return nfserr_attrnotsupp;
  83. if ((bmval[2] & FATTR4_WORD2_SECURITY_LABEL) &&
  84. !(exp->ex_flags & NFSEXP_SECURITY_LABEL))
  85. return nfserr_attrnotsupp;
  86. if (writable && !bmval_is_subset(bmval, writable))
  87. return nfserr_inval;
  88. if (writable && (bmval[2] & FATTR4_WORD2_MODE_UMASK) &&
  89. (bmval[1] & FATTR4_WORD1_MODE))
  90. return nfserr_inval;
  91. return nfs_ok;
  92. }
  93. static __be32
  94. nfsd4_check_open_attributes(struct svc_rqst *rqstp,
  95. struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
  96. {
  97. __be32 status = nfs_ok;
  98. if (open->op_create == NFS4_OPEN_CREATE) {
  99. if (open->op_createmode == NFS4_CREATE_UNCHECKED
  100. || open->op_createmode == NFS4_CREATE_GUARDED)
  101. status = check_attr_support(rqstp, cstate,
  102. open->op_bmval, nfsd_attrmask);
  103. else if (open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1)
  104. status = check_attr_support(rqstp, cstate,
  105. open->op_bmval, nfsd41_ex_attrmask);
  106. }
  107. return status;
  108. }
  109. static int
  110. is_create_with_attrs(struct nfsd4_open *open)
  111. {
  112. return open->op_create == NFS4_OPEN_CREATE
  113. && (open->op_createmode == NFS4_CREATE_UNCHECKED
  114. || open->op_createmode == NFS4_CREATE_GUARDED
  115. || open->op_createmode == NFS4_CREATE_EXCLUSIVE4_1);
  116. }
  117. static inline void
  118. fh_dup2(struct svc_fh *dst, struct svc_fh *src)
  119. {
  120. fh_put(dst);
  121. dget(src->fh_dentry);
  122. if (src->fh_export)
  123. exp_get(src->fh_export);
  124. *dst = *src;
  125. }
  126. static __be32
  127. do_open_permission(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_open *open, int accmode)
  128. {
  129. if (open->op_truncate &&
  130. !(open->op_share_access & NFS4_SHARE_ACCESS_WRITE))
  131. return nfserr_inval;
  132. accmode |= NFSD_MAY_READ_IF_EXEC;
  133. if (open->op_share_access & NFS4_SHARE_ACCESS_READ)
  134. accmode |= NFSD_MAY_READ;
  135. if (open->op_share_access & NFS4_SHARE_ACCESS_WRITE)
  136. accmode |= (NFSD_MAY_WRITE | NFSD_MAY_TRUNC);
  137. if (open->op_share_deny & NFS4_SHARE_DENY_READ)
  138. accmode |= NFSD_MAY_WRITE;
  139. return fh_verify(rqstp, current_fh, S_IFREG, accmode);
  140. }
  141. static __be32 nfsd_check_obj_isreg(struct svc_fh *fh, u32 minor_version)
  142. {
  143. umode_t mode = d_inode(fh->fh_dentry)->i_mode;
  144. if (S_ISREG(mode))
  145. return nfs_ok;
  146. if (S_ISDIR(mode))
  147. return nfserr_isdir;
  148. if (S_ISLNK(mode))
  149. return nfserr_symlink;
  150. /* RFC 7530 - 16.16.6 */
  151. if (minor_version == 0)
  152. return nfserr_symlink;
  153. else
  154. return nfserr_wrong_type;
  155. }
  156. static void nfsd4_set_open_owner_reply_cache(struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh *resfh)
  157. {
  158. if (nfsd4_has_session(cstate))
  159. return;
  160. fh_copy_shallow(&open->op_openowner->oo_owner.so_replay.rp_openfh,
  161. &resfh->fh_handle);
  162. }
  163. static inline bool nfsd4_create_is_exclusive(int createmode)
  164. {
  165. return createmode == NFS4_CREATE_EXCLUSIVE ||
  166. createmode == NFS4_CREATE_EXCLUSIVE4_1;
  167. }
  168. static __be32
  169. nfsd4_vfs_create(struct svc_fh *fhp, struct dentry *child,
  170. struct nfsd4_open *open)
  171. {
  172. struct file *filp;
  173. struct path path;
  174. int oflags;
  175. oflags = O_CREAT | O_LARGEFILE;
  176. switch (open->op_share_access & NFS4_SHARE_ACCESS_BOTH) {
  177. case NFS4_SHARE_ACCESS_WRITE:
  178. oflags |= O_WRONLY;
  179. break;
  180. case NFS4_SHARE_ACCESS_BOTH:
  181. oflags |= O_RDWR;
  182. break;
  183. default:
  184. oflags |= O_RDONLY;
  185. }
  186. path.mnt = fhp->fh_export->ex_path.mnt;
  187. path.dentry = child;
  188. filp = dentry_create(&path, oflags, open->op_iattr.ia_mode,
  189. current_cred());
  190. if (IS_ERR(filp))
  191. return nfserrno(PTR_ERR(filp));
  192. open->op_filp = filp;
  193. return nfs_ok;
  194. }
  195. /*
  196. * Implement NFSv4's unchecked, guarded, and exclusive create
  197. * semantics for regular files. Open state for this new file is
  198. * subsequently fabricated in nfsd4_process_open2().
  199. *
  200. * Upon return, caller must release @fhp and @resfhp.
  201. */
  202. static __be32
  203. nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,
  204. struct svc_fh *resfhp, struct nfsd4_open *open)
  205. {
  206. struct iattr *iap = &open->op_iattr;
  207. struct nfsd_attrs attrs = {
  208. .na_iattr = iap,
  209. .na_seclabel = &open->op_label,
  210. };
  211. struct dentry *parent, *child;
  212. __u32 v_mtime, v_atime;
  213. struct inode *inode;
  214. __be32 status;
  215. int host_err;
  216. if (isdotent(open->op_fname, open->op_fnamelen))
  217. return nfserr_exist;
  218. if (!(iap->ia_valid & ATTR_MODE))
  219. iap->ia_mode = 0;
  220. status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_EXEC);
  221. if (status != nfs_ok)
  222. return status;
  223. parent = fhp->fh_dentry;
  224. inode = d_inode(parent);
  225. host_err = fh_want_write(fhp);
  226. if (host_err)
  227. return nfserrno(host_err);
  228. if (is_create_with_attrs(open))
  229. nfsd4_acl_to_attr(NF4REG, open->op_acl, &attrs);
  230. inode_lock_nested(inode, I_MUTEX_PARENT);
  231. child = lookup_one_len(open->op_fname, parent, open->op_fnamelen);
  232. if (IS_ERR(child)) {
  233. status = nfserrno(PTR_ERR(child));
  234. goto out;
  235. }
  236. if (d_really_is_negative(child)) {
  237. status = fh_verify(rqstp, fhp, S_IFDIR, NFSD_MAY_CREATE);
  238. if (status != nfs_ok)
  239. goto out;
  240. }
  241. status = fh_compose(resfhp, fhp->fh_export, child, fhp);
  242. if (status != nfs_ok)
  243. goto out;
  244. v_mtime = 0;
  245. v_atime = 0;
  246. if (nfsd4_create_is_exclusive(open->op_createmode)) {
  247. u32 *verifier = (u32 *)open->op_verf.data;
  248. /*
  249. * Solaris 7 gets confused (bugid 4218508) if these have
  250. * the high bit set, as do xfs filesystems without the
  251. * "bigtime" feature. So just clear the high bits. If this
  252. * is ever changed to use different attrs for storing the
  253. * verifier, then do_open_lookup() will also need to be
  254. * fixed accordingly.
  255. */
  256. v_mtime = verifier[0] & 0x7fffffff;
  257. v_atime = verifier[1] & 0x7fffffff;
  258. }
  259. if (d_really_is_positive(child)) {
  260. /* NFSv4 protocol requires change attributes even though
  261. * no change happened.
  262. */
  263. status = fh_fill_both_attrs(fhp);
  264. if (status != nfs_ok)
  265. goto out;
  266. switch (open->op_createmode) {
  267. case NFS4_CREATE_UNCHECKED:
  268. if (!d_is_reg(child))
  269. break;
  270. /*
  271. * In NFSv4, we don't want to truncate the file
  272. * now. This would be wrong if the OPEN fails for
  273. * some other reason. Furthermore, if the size is
  274. * nonzero, we should ignore it according to spec!
  275. */
  276. open->op_truncate = (iap->ia_valid & ATTR_SIZE) &&
  277. !iap->ia_size;
  278. break;
  279. case NFS4_CREATE_GUARDED:
  280. status = nfserr_exist;
  281. break;
  282. case NFS4_CREATE_EXCLUSIVE:
  283. if (inode_get_mtime_sec(d_inode(child)) == v_mtime &&
  284. inode_get_atime_sec(d_inode(child)) == v_atime &&
  285. d_inode(child)->i_size == 0) {
  286. open->op_created = true;
  287. break; /* subtle */
  288. }
  289. status = nfserr_exist;
  290. break;
  291. case NFS4_CREATE_EXCLUSIVE4_1:
  292. if (inode_get_mtime_sec(d_inode(child)) == v_mtime &&
  293. inode_get_atime_sec(d_inode(child)) == v_atime &&
  294. d_inode(child)->i_size == 0) {
  295. open->op_created = true;
  296. goto set_attr; /* subtle */
  297. }
  298. status = nfserr_exist;
  299. }
  300. goto out;
  301. }
  302. if (!IS_POSIXACL(inode))
  303. iap->ia_mode &= ~current_umask();
  304. status = fh_fill_pre_attrs(fhp);
  305. if (status != nfs_ok)
  306. goto out;
  307. status = nfsd4_vfs_create(fhp, child, open);
  308. if (status != nfs_ok)
  309. goto out;
  310. open->op_created = true;
  311. fh_fill_post_attrs(fhp);
  312. /* A newly created file already has a file size of zero. */
  313. if ((iap->ia_valid & ATTR_SIZE) && (iap->ia_size == 0))
  314. iap->ia_valid &= ~ATTR_SIZE;
  315. if (nfsd4_create_is_exclusive(open->op_createmode)) {
  316. iap->ia_valid = ATTR_MTIME | ATTR_ATIME |
  317. ATTR_MTIME_SET|ATTR_ATIME_SET;
  318. iap->ia_mtime.tv_sec = v_mtime;
  319. iap->ia_atime.tv_sec = v_atime;
  320. iap->ia_mtime.tv_nsec = 0;
  321. iap->ia_atime.tv_nsec = 0;
  322. }
  323. set_attr:
  324. status = nfsd_create_setattr(rqstp, fhp, resfhp, &attrs);
  325. if (attrs.na_labelerr)
  326. open->op_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  327. if (attrs.na_aclerr)
  328. open->op_bmval[0] &= ~FATTR4_WORD0_ACL;
  329. out:
  330. inode_unlock(inode);
  331. nfsd_attrs_free(&attrs);
  332. if (child && !IS_ERR(child))
  333. dput(child);
  334. fh_drop_write(fhp);
  335. return status;
  336. }
  337. /**
  338. * set_change_info - set up the change_info4 for a reply
  339. * @cinfo: pointer to nfsd4_change_info to be populated
  340. * @fhp: pointer to svc_fh to use as source
  341. *
  342. * Many operations in NFSv4 require change_info4 in the reply. This function
  343. * populates that from the info that we (should!) have already collected. In
  344. * the event that we didn't get any pre-attrs, just zero out both.
  345. */
  346. static void
  347. set_change_info(struct nfsd4_change_info *cinfo, struct svc_fh *fhp)
  348. {
  349. cinfo->atomic = (u32)(fhp->fh_pre_saved && fhp->fh_post_saved && !fhp->fh_no_atomic_attr);
  350. cinfo->before_change = fhp->fh_pre_change;
  351. cinfo->after_change = fhp->fh_post_change;
  352. /*
  353. * If fetching the pre-change attributes failed, then we should
  354. * have already failed the whole operation. We could have still
  355. * failed to fetch post-change attributes however.
  356. *
  357. * If we didn't get post-op attrs, just zero-out the after
  358. * field since we don't know what it should be. If the pre_saved
  359. * field isn't set for some reason, throw warning and just copy
  360. * whatever is in the after field.
  361. */
  362. if (WARN_ON_ONCE(!fhp->fh_pre_saved))
  363. cinfo->before_change = 0;
  364. if (!fhp->fh_post_saved)
  365. cinfo->after_change = cinfo->before_change + 1;
  366. }
  367. static __be32
  368. do_open_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open, struct svc_fh **resfh)
  369. {
  370. struct svc_fh *current_fh = &cstate->current_fh;
  371. int accmode;
  372. __be32 status;
  373. *resfh = kmalloc(sizeof(struct svc_fh), GFP_KERNEL);
  374. if (!*resfh)
  375. return nfserr_jukebox;
  376. fh_init(*resfh, NFS4_FHSIZE);
  377. open->op_truncate = false;
  378. if (open->op_create) {
  379. /* FIXME: check session persistence and pnfs flags.
  380. * The nfsv4.1 spec requires the following semantics:
  381. *
  382. * Persistent | pNFS | Server REQUIRED | Client Allowed
  383. * Reply Cache | server | |
  384. * -------------+--------+-----------------+--------------------
  385. * no | no | EXCLUSIVE4_1 | EXCLUSIVE4_1
  386. * | | | (SHOULD)
  387. * | | and EXCLUSIVE4 | or EXCLUSIVE4
  388. * | | | (SHOULD NOT)
  389. * no | yes | EXCLUSIVE4_1 | EXCLUSIVE4_1
  390. * yes | no | GUARDED4 | GUARDED4
  391. * yes | yes | GUARDED4 | GUARDED4
  392. */
  393. current->fs->umask = open->op_umask;
  394. status = nfsd4_create_file(rqstp, current_fh, *resfh, open);
  395. current->fs->umask = 0;
  396. /*
  397. * Following rfc 3530 14.2.16, and rfc 5661 18.16.4
  398. * use the returned bitmask to indicate which attributes
  399. * we used to store the verifier:
  400. */
  401. if (nfsd4_create_is_exclusive(open->op_createmode) && status == 0)
  402. open->op_bmval[1] |= (FATTR4_WORD1_TIME_ACCESS |
  403. FATTR4_WORD1_TIME_MODIFY);
  404. } else {
  405. status = nfsd_lookup(rqstp, current_fh,
  406. open->op_fname, open->op_fnamelen, *resfh);
  407. if (status == nfs_ok)
  408. /* NFSv4 protocol requires change attributes even though
  409. * no change happened.
  410. */
  411. status = fh_fill_both_attrs(current_fh);
  412. }
  413. if (status)
  414. goto out;
  415. status = nfsd_check_obj_isreg(*resfh, cstate->minorversion);
  416. if (status)
  417. goto out;
  418. nfsd4_set_open_owner_reply_cache(cstate, open, *resfh);
  419. accmode = NFSD_MAY_NOP;
  420. if (open->op_created ||
  421. open->op_claim_type == NFS4_OPEN_CLAIM_DELEGATE_CUR)
  422. accmode |= NFSD_MAY_OWNER_OVERRIDE;
  423. status = do_open_permission(rqstp, *resfh, open, accmode);
  424. set_change_info(&open->op_cinfo, current_fh);
  425. out:
  426. return status;
  427. }
  428. static __be32
  429. do_open_fhandle(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_open *open)
  430. {
  431. struct svc_fh *current_fh = &cstate->current_fh;
  432. int accmode = 0;
  433. /* We don't know the target directory, and therefore can not
  434. * set the change info
  435. */
  436. memset(&open->op_cinfo, 0, sizeof(struct nfsd4_change_info));
  437. nfsd4_set_open_owner_reply_cache(cstate, open, current_fh);
  438. open->op_truncate = (open->op_iattr.ia_valid & ATTR_SIZE) &&
  439. (open->op_iattr.ia_size == 0);
  440. /*
  441. * In the delegation case, the client is telling us about an
  442. * open that it *already* performed locally, some time ago. We
  443. * should let it succeed now if possible.
  444. *
  445. * In the case of a CLAIM_FH open, on the other hand, the client
  446. * may be counting on us to enforce permissions (the Linux 4.1
  447. * client uses this for normal opens, for example).
  448. */
  449. if (open->op_claim_type == NFS4_OPEN_CLAIM_DELEG_CUR_FH)
  450. accmode = NFSD_MAY_OWNER_OVERRIDE;
  451. return do_open_permission(rqstp, current_fh, open, accmode);
  452. }
  453. static void
  454. copy_clientid(clientid_t *clid, struct nfsd4_session *session)
  455. {
  456. struct nfsd4_sessionid *sid =
  457. (struct nfsd4_sessionid *)session->se_sessionid.data;
  458. clid->cl_boot = sid->clientid.cl_boot;
  459. clid->cl_id = sid->clientid.cl_id;
  460. }
  461. static __be32
  462. nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  463. union nfsd4_op_u *u)
  464. {
  465. struct nfsd4_open *open = &u->open;
  466. __be32 status;
  467. struct svc_fh *resfh = NULL;
  468. struct net *net = SVC_NET(rqstp);
  469. struct nfsd_net *nn = net_generic(net, nfsd_net_id);
  470. bool reclaim = false;
  471. dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
  472. (int)open->op_fnamelen, open->op_fname,
  473. open->op_openowner);
  474. open->op_filp = NULL;
  475. open->op_rqstp = rqstp;
  476. /* This check required by spec. */
  477. if (open->op_create && open->op_claim_type != NFS4_OPEN_CLAIM_NULL)
  478. return nfserr_inval;
  479. open->op_created = false;
  480. /*
  481. * RFC5661 18.51.3
  482. * Before RECLAIM_COMPLETE done, server should deny new lock
  483. */
  484. if (nfsd4_has_session(cstate) &&
  485. !test_bit(NFSD4_CLIENT_RECLAIM_COMPLETE, &cstate->clp->cl_flags) &&
  486. open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  487. return nfserr_grace;
  488. if (nfsd4_has_session(cstate))
  489. copy_clientid(&open->op_clientid, cstate->session);
  490. /* check seqid for replay. set nfs4_owner */
  491. status = nfsd4_process_open1(cstate, open, nn);
  492. if (status == nfserr_replay_me) {
  493. struct nfs4_replay *rp = &open->op_openowner->oo_owner.so_replay;
  494. fh_put(&cstate->current_fh);
  495. fh_copy_shallow(&cstate->current_fh.fh_handle,
  496. &rp->rp_openfh);
  497. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  498. if (status)
  499. dprintk("nfsd4_open: replay failed"
  500. " restoring previous filehandle\n");
  501. else
  502. status = nfserr_replay_me;
  503. }
  504. if (status)
  505. goto out;
  506. if (open->op_xdr_error) {
  507. status = open->op_xdr_error;
  508. goto out;
  509. }
  510. status = nfsd4_check_open_attributes(rqstp, cstate, open);
  511. if (status)
  512. goto out;
  513. /* Openowner is now set, so sequence id will get bumped. Now we need
  514. * these checks before we do any creates: */
  515. status = nfserr_grace;
  516. if (opens_in_grace(net) && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
  517. goto out;
  518. status = nfserr_no_grace;
  519. if (!opens_in_grace(net) && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
  520. goto out;
  521. switch (open->op_claim_type) {
  522. case NFS4_OPEN_CLAIM_DELEGATE_CUR:
  523. case NFS4_OPEN_CLAIM_NULL:
  524. status = do_open_lookup(rqstp, cstate, open, &resfh);
  525. if (status)
  526. goto out;
  527. break;
  528. case NFS4_OPEN_CLAIM_PREVIOUS:
  529. status = nfs4_check_open_reclaim(cstate->clp);
  530. if (status)
  531. goto out;
  532. open->op_openowner->oo_flags |= NFS4_OO_CONFIRMED;
  533. reclaim = true;
  534. fallthrough;
  535. case NFS4_OPEN_CLAIM_FH:
  536. case NFS4_OPEN_CLAIM_DELEG_CUR_FH:
  537. status = do_open_fhandle(rqstp, cstate, open);
  538. if (status)
  539. goto out;
  540. resfh = &cstate->current_fh;
  541. break;
  542. case NFS4_OPEN_CLAIM_DELEG_PREV_FH:
  543. case NFS4_OPEN_CLAIM_DELEGATE_PREV:
  544. status = nfserr_notsupp;
  545. goto out;
  546. default:
  547. status = nfserr_inval;
  548. goto out;
  549. }
  550. status = nfsd4_process_open2(rqstp, resfh, open);
  551. if (status && open->op_created)
  552. pr_warn("nfsd4_process_open2 failed to open newly-created file: status=%u\n",
  553. be32_to_cpu(status));
  554. if (reclaim && !status)
  555. nn->somebody_reclaimed = true;
  556. out:
  557. if (open->op_filp) {
  558. fput(open->op_filp);
  559. open->op_filp = NULL;
  560. }
  561. if (resfh && resfh != &cstate->current_fh) {
  562. fh_dup2(&cstate->current_fh, resfh);
  563. fh_put(resfh);
  564. kfree(resfh);
  565. }
  566. nfsd4_cleanup_open_state(cstate, open);
  567. nfsd4_bump_seqid(cstate, status);
  568. return status;
  569. }
  570. /*
  571. * OPEN is the only seqid-mutating operation whose decoding can fail
  572. * with a seqid-mutating error (specifically, decoding of user names in
  573. * the attributes). Therefore we have to do some processing to look up
  574. * the stateowner so that we can bump the seqid.
  575. */
  576. static __be32 nfsd4_open_omfg(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_op *op)
  577. {
  578. struct nfsd4_open *open = &op->u.open;
  579. if (!seqid_mutating_err(ntohl(op->status)))
  580. return op->status;
  581. if (nfsd4_has_session(cstate))
  582. return op->status;
  583. open->op_xdr_error = op->status;
  584. return nfsd4_open(rqstp, cstate, &op->u);
  585. }
  586. /*
  587. * filehandle-manipulating ops.
  588. */
  589. static __be32
  590. nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  591. union nfsd4_op_u *u)
  592. {
  593. u->getfh = &cstate->current_fh;
  594. return nfs_ok;
  595. }
  596. static __be32
  597. nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  598. union nfsd4_op_u *u)
  599. {
  600. struct nfsd4_putfh *putfh = &u->putfh;
  601. __be32 ret;
  602. fh_put(&cstate->current_fh);
  603. cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
  604. memcpy(&cstate->current_fh.fh_handle.fh_raw, putfh->pf_fhval,
  605. putfh->pf_fhlen);
  606. ret = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_BYPASS_GSS);
  607. #ifdef CONFIG_NFSD_V4_2_INTER_SSC
  608. if (ret == nfserr_stale && putfh->no_verify) {
  609. SET_FH_FLAG(&cstate->current_fh, NFSD4_FH_FOREIGN);
  610. ret = 0;
  611. }
  612. #endif
  613. return ret;
  614. }
  615. static __be32
  616. nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  617. union nfsd4_op_u *u)
  618. {
  619. fh_put(&cstate->current_fh);
  620. return exp_pseudoroot(rqstp, &cstate->current_fh);
  621. }
  622. static __be32
  623. nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  624. union nfsd4_op_u *u)
  625. {
  626. if (!cstate->save_fh.fh_dentry)
  627. return nfserr_restorefh;
  628. fh_dup2(&cstate->current_fh, &cstate->save_fh);
  629. if (HAS_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG)) {
  630. memcpy(&cstate->current_stateid, &cstate->save_stateid, sizeof(stateid_t));
  631. SET_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG);
  632. }
  633. return nfs_ok;
  634. }
  635. static __be32
  636. nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  637. union nfsd4_op_u *u)
  638. {
  639. fh_dup2(&cstate->save_fh, &cstate->current_fh);
  640. if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) {
  641. memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
  642. SET_CSTATE_FLAG(cstate, SAVED_STATE_ID_FLAG);
  643. }
  644. return nfs_ok;
  645. }
  646. /*
  647. * misc nfsv4 ops
  648. */
  649. static __be32
  650. nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  651. union nfsd4_op_u *u)
  652. {
  653. struct nfsd4_access *access = &u->access;
  654. u32 access_full;
  655. access_full = NFS3_ACCESS_FULL;
  656. if (cstate->minorversion >= 2)
  657. access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD |
  658. NFS4_ACCESS_XAWRITE;
  659. if (access->ac_req_access & ~access_full)
  660. return nfserr_inval;
  661. access->ac_resp_access = access->ac_req_access;
  662. return nfsd_access(rqstp, &cstate->current_fh, &access->ac_resp_access,
  663. &access->ac_supported);
  664. }
  665. static __be32
  666. nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  667. union nfsd4_op_u *u)
  668. {
  669. struct nfsd4_commit *commit = &u->commit;
  670. struct nfsd_file *nf;
  671. __be32 status;
  672. status = nfsd_file_acquire(rqstp, &cstate->current_fh, NFSD_MAY_WRITE |
  673. NFSD_MAY_NOT_BREAK_LEASE, &nf);
  674. if (status != nfs_ok)
  675. return status;
  676. status = nfsd_commit(rqstp, &cstate->current_fh, nf, commit->co_offset,
  677. commit->co_count,
  678. (__be32 *)commit->co_verf.data);
  679. nfsd_file_put(nf);
  680. return status;
  681. }
  682. static __be32
  683. nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  684. union nfsd4_op_u *u)
  685. {
  686. struct nfsd4_create *create = &u->create;
  687. struct nfsd_attrs attrs = {
  688. .na_iattr = &create->cr_iattr,
  689. .na_seclabel = &create->cr_label,
  690. };
  691. struct svc_fh resfh;
  692. __be32 status;
  693. dev_t rdev;
  694. fh_init(&resfh, NFS4_FHSIZE);
  695. status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
  696. if (status)
  697. return status;
  698. status = check_attr_support(rqstp, cstate, create->cr_bmval,
  699. nfsd_attrmask);
  700. if (status)
  701. return status;
  702. status = nfsd4_acl_to_attr(create->cr_type, create->cr_acl, &attrs);
  703. current->fs->umask = create->cr_umask;
  704. switch (create->cr_type) {
  705. case NF4LNK:
  706. status = nfsd_symlink(rqstp, &cstate->current_fh,
  707. create->cr_name, create->cr_namelen,
  708. create->cr_data, &attrs, &resfh);
  709. break;
  710. case NF4BLK:
  711. status = nfserr_inval;
  712. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  713. if (MAJOR(rdev) != create->cr_specdata1 ||
  714. MINOR(rdev) != create->cr_specdata2)
  715. goto out_umask;
  716. status = nfsd_create(rqstp, &cstate->current_fh,
  717. create->cr_name, create->cr_namelen,
  718. &attrs, S_IFBLK, rdev, &resfh);
  719. break;
  720. case NF4CHR:
  721. status = nfserr_inval;
  722. rdev = MKDEV(create->cr_specdata1, create->cr_specdata2);
  723. if (MAJOR(rdev) != create->cr_specdata1 ||
  724. MINOR(rdev) != create->cr_specdata2)
  725. goto out_umask;
  726. status = nfsd_create(rqstp, &cstate->current_fh,
  727. create->cr_name, create->cr_namelen,
  728. &attrs, S_IFCHR, rdev, &resfh);
  729. break;
  730. case NF4SOCK:
  731. status = nfsd_create(rqstp, &cstate->current_fh,
  732. create->cr_name, create->cr_namelen,
  733. &attrs, S_IFSOCK, 0, &resfh);
  734. break;
  735. case NF4FIFO:
  736. status = nfsd_create(rqstp, &cstate->current_fh,
  737. create->cr_name, create->cr_namelen,
  738. &attrs, S_IFIFO, 0, &resfh);
  739. break;
  740. case NF4DIR:
  741. create->cr_iattr.ia_valid &= ~ATTR_SIZE;
  742. status = nfsd_create(rqstp, &cstate->current_fh,
  743. create->cr_name, create->cr_namelen,
  744. &attrs, S_IFDIR, 0, &resfh);
  745. break;
  746. default:
  747. status = nfserr_badtype;
  748. }
  749. if (status)
  750. goto out;
  751. if (attrs.na_labelerr)
  752. create->cr_bmval[2] &= ~FATTR4_WORD2_SECURITY_LABEL;
  753. if (attrs.na_aclerr)
  754. create->cr_bmval[0] &= ~FATTR4_WORD0_ACL;
  755. set_change_info(&create->cr_cinfo, &cstate->current_fh);
  756. fh_dup2(&cstate->current_fh, &resfh);
  757. out:
  758. fh_put(&resfh);
  759. out_umask:
  760. current->fs->umask = 0;
  761. nfsd_attrs_free(&attrs);
  762. return status;
  763. }
  764. static __be32
  765. nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  766. union nfsd4_op_u *u)
  767. {
  768. struct nfsd4_getattr *getattr = &u->getattr;
  769. __be32 status;
  770. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  771. if (status)
  772. return status;
  773. if (getattr->ga_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  774. return nfserr_inval;
  775. getattr->ga_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
  776. getattr->ga_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
  777. getattr->ga_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
  778. getattr->ga_fhp = &cstate->current_fh;
  779. return nfs_ok;
  780. }
  781. static __be32
  782. nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  783. union nfsd4_op_u *u)
  784. {
  785. struct nfsd4_link *link = &u->link;
  786. __be32 status;
  787. status = nfsd_link(rqstp, &cstate->current_fh,
  788. link->li_name, link->li_namelen, &cstate->save_fh);
  789. if (!status)
  790. set_change_info(&link->li_cinfo, &cstate->current_fh);
  791. return status;
  792. }
  793. static __be32 nfsd4_do_lookupp(struct svc_rqst *rqstp, struct svc_fh *fh)
  794. {
  795. struct svc_fh tmp_fh;
  796. __be32 ret;
  797. fh_init(&tmp_fh, NFS4_FHSIZE);
  798. ret = exp_pseudoroot(rqstp, &tmp_fh);
  799. if (ret)
  800. return ret;
  801. if (tmp_fh.fh_dentry == fh->fh_dentry) {
  802. fh_put(&tmp_fh);
  803. return nfserr_noent;
  804. }
  805. fh_put(&tmp_fh);
  806. return nfsd_lookup(rqstp, fh, "..", 2, fh);
  807. }
  808. static __be32
  809. nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  810. union nfsd4_op_u *u)
  811. {
  812. return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  813. }
  814. static __be32
  815. nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  816. union nfsd4_op_u *u)
  817. {
  818. return nfsd_lookup(rqstp, &cstate->current_fh,
  819. u->lookup.lo_name, u->lookup.lo_len,
  820. &cstate->current_fh);
  821. }
  822. static __be32
  823. nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  824. union nfsd4_op_u *u)
  825. {
  826. struct nfsd4_read *read = &u->read;
  827. __be32 status;
  828. read->rd_nf = NULL;
  829. trace_nfsd_read_start(rqstp, &cstate->current_fh,
  830. read->rd_offset, read->rd_length);
  831. read->rd_length = min_t(u32, read->rd_length, svc_max_payload(rqstp));
  832. if (read->rd_offset > (u64)OFFSET_MAX)
  833. read->rd_offset = (u64)OFFSET_MAX;
  834. if (read->rd_offset + read->rd_length > (u64)OFFSET_MAX)
  835. read->rd_length = (u64)OFFSET_MAX - read->rd_offset;
  836. /*
  837. * If we do a zero copy read, then a client will see read data
  838. * that reflects the state of the file *after* performing the
  839. * following compound.
  840. *
  841. * To ensure proper ordering, we therefore turn off zero copy if
  842. * the client wants us to do more in this compound:
  843. */
  844. if (!nfsd4_last_compound_op(rqstp)) {
  845. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  846. argp->splice_ok = false;
  847. }
  848. /* check stateid */
  849. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  850. &read->rd_stateid, RD_STATE,
  851. &read->rd_nf, NULL);
  852. read->rd_rqstp = rqstp;
  853. read->rd_fhp = &cstate->current_fh;
  854. return status;
  855. }
  856. static void
  857. nfsd4_read_release(union nfsd4_op_u *u)
  858. {
  859. if (u->read.rd_nf)
  860. nfsd_file_put(u->read.rd_nf);
  861. trace_nfsd_read_done(u->read.rd_rqstp, u->read.rd_fhp,
  862. u->read.rd_offset, u->read.rd_length);
  863. }
  864. static __be32
  865. nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  866. union nfsd4_op_u *u)
  867. {
  868. struct nfsd4_readdir *readdir = &u->readdir;
  869. u64 cookie = readdir->rd_cookie;
  870. static const nfs4_verifier zeroverf;
  871. /* no need to check permission - this will be done in nfsd_readdir() */
  872. if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
  873. return nfserr_inval;
  874. readdir->rd_bmval[0] &= nfsd_suppattrs[cstate->minorversion][0];
  875. readdir->rd_bmval[1] &= nfsd_suppattrs[cstate->minorversion][1];
  876. readdir->rd_bmval[2] &= nfsd_suppattrs[cstate->minorversion][2];
  877. if ((cookie == 1) || (cookie == 2) ||
  878. (cookie == 0 && memcmp(readdir->rd_verf.data, zeroverf.data, NFS4_VERIFIER_SIZE)))
  879. return nfserr_bad_cookie;
  880. readdir->rd_rqstp = rqstp;
  881. readdir->rd_fhp = &cstate->current_fh;
  882. return nfs_ok;
  883. }
  884. static __be32
  885. nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  886. union nfsd4_op_u *u)
  887. {
  888. u->readlink.rl_rqstp = rqstp;
  889. u->readlink.rl_fhp = &cstate->current_fh;
  890. return nfs_ok;
  891. }
  892. static __be32
  893. nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  894. union nfsd4_op_u *u)
  895. {
  896. struct nfsd4_remove *remove = &u->remove;
  897. __be32 status;
  898. if (opens_in_grace(SVC_NET(rqstp)))
  899. return nfserr_grace;
  900. status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
  901. remove->rm_name, remove->rm_namelen);
  902. if (!status)
  903. set_change_info(&remove->rm_cinfo, &cstate->current_fh);
  904. return status;
  905. }
  906. static __be32
  907. nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  908. union nfsd4_op_u *u)
  909. {
  910. struct nfsd4_rename *rename = &u->rename;
  911. __be32 status;
  912. if (opens_in_grace(SVC_NET(rqstp)))
  913. return nfserr_grace;
  914. status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
  915. rename->rn_snamelen, &cstate->current_fh,
  916. rename->rn_tname, rename->rn_tnamelen);
  917. if (status)
  918. return status;
  919. set_change_info(&rename->rn_sinfo, &cstate->save_fh);
  920. set_change_info(&rename->rn_tinfo, &cstate->current_fh);
  921. return nfs_ok;
  922. }
  923. static __be32
  924. nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  925. union nfsd4_op_u *u)
  926. {
  927. struct nfsd4_secinfo *secinfo = &u->secinfo;
  928. struct svc_export *exp;
  929. struct dentry *dentry;
  930. __be32 err;
  931. err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
  932. if (err)
  933. return err;
  934. err = nfsd_lookup_dentry(rqstp, &cstate->current_fh,
  935. secinfo->si_name, secinfo->si_namelen,
  936. &exp, &dentry);
  937. if (err)
  938. return err;
  939. if (d_really_is_negative(dentry)) {
  940. exp_put(exp);
  941. err = nfserr_noent;
  942. } else
  943. secinfo->si_exp = exp;
  944. dput(dentry);
  945. if (cstate->minorversion)
  946. /* See rfc 5661 section 2.6.3.1.1.8 */
  947. fh_put(&cstate->current_fh);
  948. return err;
  949. }
  950. static __be32
  951. nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  952. union nfsd4_op_u *u)
  953. {
  954. __be32 err;
  955. switch (u->secinfo_no_name.sin_style) {
  956. case NFS4_SECINFO_STYLE4_CURRENT_FH:
  957. break;
  958. case NFS4_SECINFO_STYLE4_PARENT:
  959. err = nfsd4_do_lookupp(rqstp, &cstate->current_fh);
  960. if (err)
  961. return err;
  962. break;
  963. default:
  964. return nfserr_inval;
  965. }
  966. u->secinfo_no_name.sin_exp = exp_get(cstate->current_fh.fh_export);
  967. fh_put(&cstate->current_fh);
  968. return nfs_ok;
  969. }
  970. static void
  971. nfsd4_secinfo_release(union nfsd4_op_u *u)
  972. {
  973. if (u->secinfo.si_exp)
  974. exp_put(u->secinfo.si_exp);
  975. }
  976. static void
  977. nfsd4_secinfo_no_name_release(union nfsd4_op_u *u)
  978. {
  979. if (u->secinfo_no_name.sin_exp)
  980. exp_put(u->secinfo_no_name.sin_exp);
  981. }
  982. static __be32
  983. nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  984. union nfsd4_op_u *u)
  985. {
  986. struct nfsd4_setattr *setattr = &u->setattr;
  987. struct nfsd_attrs attrs = {
  988. .na_iattr = &setattr->sa_iattr,
  989. .na_seclabel = &setattr->sa_label,
  990. };
  991. struct inode *inode;
  992. __be32 status = nfs_ok;
  993. bool save_no_wcc;
  994. int err;
  995. if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
  996. status = nfs4_preprocess_stateid_op(rqstp, cstate,
  997. &cstate->current_fh, &setattr->sa_stateid,
  998. WR_STATE, NULL, NULL);
  999. if (status)
  1000. return status;
  1001. }
  1002. err = fh_want_write(&cstate->current_fh);
  1003. if (err)
  1004. return nfserrno(err);
  1005. status = nfs_ok;
  1006. status = check_attr_support(rqstp, cstate, setattr->sa_bmval,
  1007. nfsd_attrmask);
  1008. if (status)
  1009. goto out;
  1010. inode = cstate->current_fh.fh_dentry->d_inode;
  1011. status = nfsd4_acl_to_attr(S_ISDIR(inode->i_mode) ? NF4DIR : NF4REG,
  1012. setattr->sa_acl, &attrs);
  1013. if (status)
  1014. goto out;
  1015. save_no_wcc = cstate->current_fh.fh_no_wcc;
  1016. cstate->current_fh.fh_no_wcc = true;
  1017. status = nfsd_setattr(rqstp, &cstate->current_fh, &attrs, NULL);
  1018. cstate->current_fh.fh_no_wcc = save_no_wcc;
  1019. if (!status)
  1020. status = nfserrno(attrs.na_labelerr);
  1021. if (!status)
  1022. status = nfserrno(attrs.na_aclerr);
  1023. out:
  1024. nfsd_attrs_free(&attrs);
  1025. fh_drop_write(&cstate->current_fh);
  1026. return status;
  1027. }
  1028. static __be32
  1029. nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1030. union nfsd4_op_u *u)
  1031. {
  1032. struct nfsd4_write *write = &u->write;
  1033. stateid_t *stateid = &write->wr_stateid;
  1034. struct nfsd_file *nf = NULL;
  1035. __be32 status = nfs_ok;
  1036. unsigned long cnt;
  1037. int nvecs;
  1038. if (write->wr_offset > (u64)OFFSET_MAX ||
  1039. write->wr_offset + write->wr_buflen > (u64)OFFSET_MAX)
  1040. return nfserr_fbig;
  1041. cnt = write->wr_buflen;
  1042. trace_nfsd_write_start(rqstp, &cstate->current_fh,
  1043. write->wr_offset, cnt);
  1044. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  1045. stateid, WR_STATE, &nf, NULL);
  1046. if (status)
  1047. return status;
  1048. write->wr_how_written = write->wr_stable_how;
  1049. nvecs = svc_fill_write_vector(rqstp, &write->wr_payload);
  1050. WARN_ON_ONCE(nvecs > ARRAY_SIZE(rqstp->rq_vec));
  1051. status = nfsd_vfs_write(rqstp, &cstate->current_fh, nf,
  1052. write->wr_offset, rqstp->rq_vec, nvecs, &cnt,
  1053. write->wr_how_written,
  1054. (__be32 *)write->wr_verifier.data);
  1055. nfsd_file_put(nf);
  1056. write->wr_bytes_written = cnt;
  1057. trace_nfsd_write_done(rqstp, &cstate->current_fh,
  1058. write->wr_offset, cnt);
  1059. return status;
  1060. }
  1061. static __be32
  1062. nfsd4_verify_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1063. stateid_t *src_stateid, struct nfsd_file **src,
  1064. stateid_t *dst_stateid, struct nfsd_file **dst)
  1065. {
  1066. __be32 status;
  1067. if (!cstate->save_fh.fh_dentry)
  1068. return nfserr_nofilehandle;
  1069. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->save_fh,
  1070. src_stateid, RD_STATE, src, NULL);
  1071. if (status)
  1072. goto out;
  1073. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  1074. dst_stateid, WR_STATE, dst, NULL);
  1075. if (status)
  1076. goto out_put_src;
  1077. /* fix up for NFS-specific error code */
  1078. if (!S_ISREG(file_inode((*src)->nf_file)->i_mode) ||
  1079. !S_ISREG(file_inode((*dst)->nf_file)->i_mode)) {
  1080. status = nfserr_wrong_type;
  1081. goto out_put_dst;
  1082. }
  1083. out:
  1084. return status;
  1085. out_put_dst:
  1086. nfsd_file_put(*dst);
  1087. *dst = NULL;
  1088. out_put_src:
  1089. nfsd_file_put(*src);
  1090. *src = NULL;
  1091. goto out;
  1092. }
  1093. static __be32
  1094. nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1095. union nfsd4_op_u *u)
  1096. {
  1097. struct nfsd4_clone *clone = &u->clone;
  1098. struct nfsd_file *src, *dst;
  1099. __be32 status;
  1100. status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
  1101. &clone->cl_dst_stateid, &dst);
  1102. if (status)
  1103. goto out;
  1104. status = nfsd4_clone_file_range(rqstp, src, clone->cl_src_pos,
  1105. dst, clone->cl_dst_pos, clone->cl_count,
  1106. EX_ISSYNC(cstate->current_fh.fh_export));
  1107. nfsd_file_put(dst);
  1108. nfsd_file_put(src);
  1109. out:
  1110. return status;
  1111. }
  1112. static void nfs4_put_copy(struct nfsd4_copy *copy)
  1113. {
  1114. if (!refcount_dec_and_test(&copy->refcount))
  1115. return;
  1116. atomic_dec(&copy->cp_nn->pending_async_copies);
  1117. kfree(copy->cp_src);
  1118. kfree(copy);
  1119. }
  1120. static void nfsd4_stop_copy(struct nfsd4_copy *copy)
  1121. {
  1122. if (!test_and_set_bit(NFSD4_COPY_F_STOPPED, &copy->cp_flags))
  1123. kthread_stop(copy->copy_task);
  1124. nfs4_put_copy(copy);
  1125. }
  1126. static struct nfsd4_copy *nfsd4_unhash_copy(struct nfs4_client *clp)
  1127. {
  1128. struct nfsd4_copy *copy = NULL;
  1129. spin_lock(&clp->async_lock);
  1130. if (!list_empty(&clp->async_copies)) {
  1131. copy = list_first_entry(&clp->async_copies, struct nfsd4_copy,
  1132. copies);
  1133. refcount_inc(&copy->refcount);
  1134. copy->cp_clp = NULL;
  1135. if (!list_empty(&copy->copies))
  1136. list_del_init(&copy->copies);
  1137. }
  1138. spin_unlock(&clp->async_lock);
  1139. return copy;
  1140. }
  1141. void nfsd4_shutdown_copy(struct nfs4_client *clp)
  1142. {
  1143. struct nfsd4_copy *copy;
  1144. while ((copy = nfsd4_unhash_copy(clp)) != NULL)
  1145. nfsd4_stop_copy(copy);
  1146. }
  1147. #ifdef CONFIG_NFSD_V4_2_INTER_SSC
  1148. extern struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
  1149. struct nfs_fh *src_fh,
  1150. nfs4_stateid *stateid);
  1151. extern void nfs42_ssc_close(struct file *filep);
  1152. extern void nfs_sb_deactive(struct super_block *sb);
  1153. #define NFSD42_INTERSSC_MOUNTOPS "vers=4.2,addr=%s,sec=sys"
  1154. /*
  1155. * setup a work entry in the ssc delayed unmount list.
  1156. */
  1157. static __be32 nfsd4_ssc_setup_dul(struct nfsd_net *nn, char *ipaddr,
  1158. struct nfsd4_ssc_umount_item **nsui,
  1159. struct svc_rqst *rqstp)
  1160. {
  1161. struct nfsd4_ssc_umount_item *ni = NULL;
  1162. struct nfsd4_ssc_umount_item *work = NULL;
  1163. struct nfsd4_ssc_umount_item *tmp;
  1164. DEFINE_WAIT(wait);
  1165. __be32 status = 0;
  1166. *nsui = NULL;
  1167. work = kzalloc(sizeof(*work), GFP_KERNEL);
  1168. try_again:
  1169. spin_lock(&nn->nfsd_ssc_lock);
  1170. list_for_each_entry_safe(ni, tmp, &nn->nfsd_ssc_mount_list, nsui_list) {
  1171. if (strncmp(ni->nsui_ipaddr, ipaddr, sizeof(ni->nsui_ipaddr)))
  1172. continue;
  1173. /* found a match */
  1174. if (ni->nsui_busy) {
  1175. /* wait - and try again */
  1176. prepare_to_wait(&nn->nfsd_ssc_waitq, &wait, TASK_IDLE);
  1177. spin_unlock(&nn->nfsd_ssc_lock);
  1178. /* allow 20secs for mount/unmount for now - revisit */
  1179. if (svc_thread_should_stop(rqstp) ||
  1180. (schedule_timeout(20*HZ) == 0)) {
  1181. finish_wait(&nn->nfsd_ssc_waitq, &wait);
  1182. kfree(work);
  1183. return nfserr_eagain;
  1184. }
  1185. finish_wait(&nn->nfsd_ssc_waitq, &wait);
  1186. goto try_again;
  1187. }
  1188. *nsui = ni;
  1189. refcount_inc(&ni->nsui_refcnt);
  1190. spin_unlock(&nn->nfsd_ssc_lock);
  1191. kfree(work);
  1192. /* return vfsmount in (*nsui)->nsui_vfsmount */
  1193. return 0;
  1194. }
  1195. if (work) {
  1196. strscpy(work->nsui_ipaddr, ipaddr, sizeof(work->nsui_ipaddr));
  1197. refcount_set(&work->nsui_refcnt, 2);
  1198. work->nsui_busy = true;
  1199. list_add_tail(&work->nsui_list, &nn->nfsd_ssc_mount_list);
  1200. *nsui = work;
  1201. } else
  1202. status = nfserr_resource;
  1203. spin_unlock(&nn->nfsd_ssc_lock);
  1204. return status;
  1205. }
  1206. static void nfsd4_ssc_update_dul(struct nfsd_net *nn,
  1207. struct nfsd4_ssc_umount_item *nsui,
  1208. struct vfsmount *ss_mnt)
  1209. {
  1210. spin_lock(&nn->nfsd_ssc_lock);
  1211. nsui->nsui_vfsmount = ss_mnt;
  1212. nsui->nsui_busy = false;
  1213. wake_up_all(&nn->nfsd_ssc_waitq);
  1214. spin_unlock(&nn->nfsd_ssc_lock);
  1215. }
  1216. static void nfsd4_ssc_cancel_dul(struct nfsd_net *nn,
  1217. struct nfsd4_ssc_umount_item *nsui)
  1218. {
  1219. spin_lock(&nn->nfsd_ssc_lock);
  1220. list_del(&nsui->nsui_list);
  1221. wake_up_all(&nn->nfsd_ssc_waitq);
  1222. spin_unlock(&nn->nfsd_ssc_lock);
  1223. kfree(nsui);
  1224. }
  1225. /*
  1226. * Support one copy source server for now.
  1227. */
  1228. static __be32
  1229. nfsd4_interssc_connect(struct nl4_server *nss, struct svc_rqst *rqstp,
  1230. struct nfsd4_ssc_umount_item **nsui)
  1231. {
  1232. struct file_system_type *type;
  1233. struct vfsmount *ss_mnt;
  1234. struct nfs42_netaddr *naddr;
  1235. struct sockaddr_storage tmp_addr;
  1236. size_t tmp_addrlen, match_netid_len = 3;
  1237. char *startsep = "", *endsep = "", *match_netid = "tcp";
  1238. char *ipaddr, *dev_name, *raw_data;
  1239. int len, raw_len;
  1240. __be32 status = nfserr_inval;
  1241. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  1242. naddr = &nss->u.nl4_addr;
  1243. tmp_addrlen = rpc_uaddr2sockaddr(SVC_NET(rqstp), naddr->addr,
  1244. naddr->addr_len,
  1245. (struct sockaddr *)&tmp_addr,
  1246. sizeof(tmp_addr));
  1247. *nsui = NULL;
  1248. if (tmp_addrlen == 0)
  1249. goto out_err;
  1250. if (tmp_addr.ss_family == AF_INET6) {
  1251. startsep = "[";
  1252. endsep = "]";
  1253. match_netid = "tcp6";
  1254. match_netid_len = 4;
  1255. }
  1256. if (naddr->netid_len != match_netid_len ||
  1257. strncmp(naddr->netid, match_netid, naddr->netid_len))
  1258. goto out_err;
  1259. /* Construct the raw data for the vfs_kern_mount call */
  1260. len = RPC_MAX_ADDRBUFLEN + 1;
  1261. ipaddr = kzalloc(len, GFP_KERNEL);
  1262. if (!ipaddr)
  1263. goto out_err;
  1264. rpc_ntop((struct sockaddr *)&tmp_addr, ipaddr, len);
  1265. /* 2 for ipv6 endsep and startsep. 3 for ":/" and trailing '/0'*/
  1266. raw_len = strlen(NFSD42_INTERSSC_MOUNTOPS) + strlen(ipaddr);
  1267. raw_data = kzalloc(raw_len, GFP_KERNEL);
  1268. if (!raw_data)
  1269. goto out_free_ipaddr;
  1270. snprintf(raw_data, raw_len, NFSD42_INTERSSC_MOUNTOPS, ipaddr);
  1271. status = nfserr_nodev;
  1272. type = get_fs_type("nfs");
  1273. if (!type)
  1274. goto out_free_rawdata;
  1275. /* Set the server:<export> for the vfs_kern_mount call */
  1276. dev_name = kzalloc(len + 5, GFP_KERNEL);
  1277. if (!dev_name)
  1278. goto out_free_rawdata;
  1279. snprintf(dev_name, len + 5, "%s%s%s:/", startsep, ipaddr, endsep);
  1280. status = nfsd4_ssc_setup_dul(nn, ipaddr, nsui, rqstp);
  1281. if (status)
  1282. goto out_free_devname;
  1283. if ((*nsui)->nsui_vfsmount)
  1284. goto out_done;
  1285. /* Use an 'internal' mount: SB_KERNMOUNT -> MNT_INTERNAL */
  1286. ss_mnt = vfs_kern_mount(type, SB_KERNMOUNT, dev_name, raw_data);
  1287. module_put(type->owner);
  1288. if (IS_ERR(ss_mnt)) {
  1289. status = nfserr_nodev;
  1290. nfsd4_ssc_cancel_dul(nn, *nsui);
  1291. goto out_free_devname;
  1292. }
  1293. nfsd4_ssc_update_dul(nn, *nsui, ss_mnt);
  1294. out_done:
  1295. status = 0;
  1296. out_free_devname:
  1297. kfree(dev_name);
  1298. out_free_rawdata:
  1299. kfree(raw_data);
  1300. out_free_ipaddr:
  1301. kfree(ipaddr);
  1302. out_err:
  1303. return status;
  1304. }
  1305. /*
  1306. * Verify COPY destination stateid.
  1307. *
  1308. * Connect to the source server with NFSv4.1.
  1309. * Create the source struct file for nfsd_copy_range.
  1310. * Called with COPY cstate:
  1311. * SAVED_FH: source filehandle
  1312. * CURRENT_FH: destination filehandle
  1313. */
  1314. static __be32
  1315. nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
  1316. struct nfsd4_compound_state *cstate,
  1317. struct nfsd4_copy *copy)
  1318. {
  1319. struct svc_fh *s_fh = NULL;
  1320. stateid_t *s_stid = &copy->cp_src_stateid;
  1321. __be32 status = nfserr_inval;
  1322. /* Verify the destination stateid and set dst struct file*/
  1323. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  1324. &copy->cp_dst_stateid,
  1325. WR_STATE, &copy->nf_dst, NULL);
  1326. if (status)
  1327. goto out;
  1328. status = nfsd4_interssc_connect(copy->cp_src, rqstp, &copy->ss_nsui);
  1329. if (status)
  1330. goto out;
  1331. s_fh = &cstate->save_fh;
  1332. copy->c_fh.size = s_fh->fh_handle.fh_size;
  1333. memcpy(copy->c_fh.data, &s_fh->fh_handle.fh_raw, copy->c_fh.size);
  1334. copy->stateid.seqid = cpu_to_be32(s_stid->si_generation);
  1335. memcpy(copy->stateid.other, (void *)&s_stid->si_opaque,
  1336. sizeof(stateid_opaque_t));
  1337. status = 0;
  1338. out:
  1339. return status;
  1340. }
  1341. static void
  1342. nfsd4_cleanup_inter_ssc(struct nfsd4_ssc_umount_item *nsui, struct file *filp,
  1343. struct nfsd_file *dst)
  1344. {
  1345. struct nfsd_net *nn = net_generic(dst->nf_net, nfsd_net_id);
  1346. long timeout = msecs_to_jiffies(nfsd4_ssc_umount_timeout);
  1347. nfs42_ssc_close(filp);
  1348. fput(filp);
  1349. spin_lock(&nn->nfsd_ssc_lock);
  1350. list_del(&nsui->nsui_list);
  1351. /*
  1352. * vfsmount can be shared by multiple exports,
  1353. * decrement refcnt. If the count drops to 1 it
  1354. * will be unmounted when nsui_expire expires.
  1355. */
  1356. refcount_dec(&nsui->nsui_refcnt);
  1357. nsui->nsui_expire = jiffies + timeout;
  1358. list_add_tail(&nsui->nsui_list, &nn->nfsd_ssc_mount_list);
  1359. spin_unlock(&nn->nfsd_ssc_lock);
  1360. }
  1361. #else /* CONFIG_NFSD_V4_2_INTER_SSC */
  1362. static __be32
  1363. nfsd4_setup_inter_ssc(struct svc_rqst *rqstp,
  1364. struct nfsd4_compound_state *cstate,
  1365. struct nfsd4_copy *copy)
  1366. {
  1367. return nfserr_inval;
  1368. }
  1369. static void
  1370. nfsd4_cleanup_inter_ssc(struct nfsd4_ssc_umount_item *nsui, struct file *filp,
  1371. struct nfsd_file *dst)
  1372. {
  1373. }
  1374. static struct file *nfs42_ssc_open(struct vfsmount *ss_mnt,
  1375. struct nfs_fh *src_fh,
  1376. nfs4_stateid *stateid)
  1377. {
  1378. return NULL;
  1379. }
  1380. #endif /* CONFIG_NFSD_V4_2_INTER_SSC */
  1381. static __be32
  1382. nfsd4_setup_intra_ssc(struct svc_rqst *rqstp,
  1383. struct nfsd4_compound_state *cstate,
  1384. struct nfsd4_copy *copy)
  1385. {
  1386. return nfsd4_verify_copy(rqstp, cstate, &copy->cp_src_stateid,
  1387. &copy->nf_src, &copy->cp_dst_stateid,
  1388. &copy->nf_dst);
  1389. }
  1390. static void nfsd4_cb_offload_release(struct nfsd4_callback *cb)
  1391. {
  1392. struct nfsd4_cb_offload *cbo =
  1393. container_of(cb, struct nfsd4_cb_offload, co_cb);
  1394. kfree(cbo);
  1395. }
  1396. static int nfsd4_cb_offload_done(struct nfsd4_callback *cb,
  1397. struct rpc_task *task)
  1398. {
  1399. struct nfsd4_cb_offload *cbo =
  1400. container_of(cb, struct nfsd4_cb_offload, co_cb);
  1401. trace_nfsd_cb_offload_done(&cbo->co_res.cb_stateid, task);
  1402. return 1;
  1403. }
  1404. static const struct nfsd4_callback_ops nfsd4_cb_offload_ops = {
  1405. .release = nfsd4_cb_offload_release,
  1406. .done = nfsd4_cb_offload_done,
  1407. .opcode = OP_CB_OFFLOAD,
  1408. };
  1409. static void nfsd4_init_copy_res(struct nfsd4_copy *copy, bool sync)
  1410. {
  1411. copy->cp_res.wr_stable_how =
  1412. test_bit(NFSD4_COPY_F_COMMITTED, &copy->cp_flags) ?
  1413. NFS_FILE_SYNC : NFS_UNSTABLE;
  1414. nfsd4_copy_set_sync(copy, sync);
  1415. }
  1416. static ssize_t _nfsd_copy_file_range(struct nfsd4_copy *copy,
  1417. struct file *dst,
  1418. struct file *src)
  1419. {
  1420. errseq_t since;
  1421. ssize_t bytes_copied = 0;
  1422. u64 bytes_total = copy->cp_count;
  1423. u64 src_pos = copy->cp_src_pos;
  1424. u64 dst_pos = copy->cp_dst_pos;
  1425. int status;
  1426. loff_t end;
  1427. /* See RFC 7862 p.67: */
  1428. if (bytes_total == 0)
  1429. bytes_total = ULLONG_MAX;
  1430. do {
  1431. /* Only async copies can be stopped here */
  1432. if (kthread_should_stop())
  1433. break;
  1434. bytes_copied = nfsd_copy_file_range(src, src_pos, dst, dst_pos,
  1435. bytes_total);
  1436. if (bytes_copied <= 0)
  1437. break;
  1438. bytes_total -= bytes_copied;
  1439. copy->cp_res.wr_bytes_written += bytes_copied;
  1440. src_pos += bytes_copied;
  1441. dst_pos += bytes_copied;
  1442. } while (bytes_total > 0 && nfsd4_copy_is_async(copy));
  1443. /* for a non-zero asynchronous copy do a commit of data */
  1444. if (nfsd4_copy_is_async(copy) && copy->cp_res.wr_bytes_written > 0) {
  1445. since = READ_ONCE(dst->f_wb_err);
  1446. end = copy->cp_dst_pos + copy->cp_res.wr_bytes_written - 1;
  1447. status = vfs_fsync_range(dst, copy->cp_dst_pos, end, 0);
  1448. if (!status)
  1449. status = filemap_check_wb_err(dst->f_mapping, since);
  1450. if (!status)
  1451. set_bit(NFSD4_COPY_F_COMMITTED, &copy->cp_flags);
  1452. }
  1453. return bytes_copied;
  1454. }
  1455. static __be32 nfsd4_do_copy(struct nfsd4_copy *copy,
  1456. struct file *src, struct file *dst,
  1457. bool sync)
  1458. {
  1459. __be32 status;
  1460. ssize_t bytes;
  1461. bytes = _nfsd_copy_file_range(copy, dst, src);
  1462. /* for async copy, we ignore the error, client can always retry
  1463. * to get the error
  1464. */
  1465. if (bytes < 0 && !copy->cp_res.wr_bytes_written)
  1466. status = nfserrno(bytes);
  1467. else {
  1468. nfsd4_init_copy_res(copy, sync);
  1469. status = nfs_ok;
  1470. }
  1471. return status;
  1472. }
  1473. static void dup_copy_fields(struct nfsd4_copy *src, struct nfsd4_copy *dst)
  1474. {
  1475. dst->cp_src_pos = src->cp_src_pos;
  1476. dst->cp_dst_pos = src->cp_dst_pos;
  1477. dst->cp_count = src->cp_count;
  1478. dst->cp_flags = src->cp_flags;
  1479. memcpy(&dst->cp_res, &src->cp_res, sizeof(src->cp_res));
  1480. memcpy(&dst->fh, &src->fh, sizeof(src->fh));
  1481. dst->cp_clp = src->cp_clp;
  1482. dst->nf_dst = nfsd_file_get(src->nf_dst);
  1483. /* for inter, nf_src doesn't exist yet */
  1484. if (!nfsd4_ssc_is_inter(src))
  1485. dst->nf_src = nfsd_file_get(src->nf_src);
  1486. memcpy(&dst->cp_stateid, &src->cp_stateid, sizeof(src->cp_stateid));
  1487. memcpy(dst->cp_src, src->cp_src, sizeof(struct nl4_server));
  1488. memcpy(&dst->stateid, &src->stateid, sizeof(src->stateid));
  1489. memcpy(&dst->c_fh, &src->c_fh, sizeof(src->c_fh));
  1490. dst->ss_nsui = src->ss_nsui;
  1491. }
  1492. static void release_copy_files(struct nfsd4_copy *copy)
  1493. {
  1494. if (copy->nf_src)
  1495. nfsd_file_put(copy->nf_src);
  1496. if (copy->nf_dst)
  1497. nfsd_file_put(copy->nf_dst);
  1498. }
  1499. static void cleanup_async_copy(struct nfsd4_copy *copy)
  1500. {
  1501. nfs4_free_copy_state(copy);
  1502. release_copy_files(copy);
  1503. if (copy->cp_clp) {
  1504. spin_lock(&copy->cp_clp->async_lock);
  1505. if (!list_empty(&copy->copies))
  1506. list_del_init(&copy->copies);
  1507. spin_unlock(&copy->cp_clp->async_lock);
  1508. }
  1509. nfs4_put_copy(copy);
  1510. }
  1511. static void nfsd4_send_cb_offload(struct nfsd4_copy *copy)
  1512. {
  1513. struct nfsd4_cb_offload *cbo;
  1514. cbo = kzalloc(sizeof(*cbo), GFP_KERNEL);
  1515. if (!cbo)
  1516. return;
  1517. memcpy(&cbo->co_res, &copy->cp_res, sizeof(copy->cp_res));
  1518. memcpy(&cbo->co_fh, &copy->fh, sizeof(copy->fh));
  1519. cbo->co_nfserr = copy->nfserr;
  1520. nfsd4_init_cb(&cbo->co_cb, copy->cp_clp, &nfsd4_cb_offload_ops,
  1521. NFSPROC4_CLNT_CB_OFFLOAD);
  1522. trace_nfsd_cb_offload(copy->cp_clp, &cbo->co_res.cb_stateid,
  1523. &cbo->co_fh, copy->cp_count, copy->nfserr);
  1524. nfsd4_run_cb(&cbo->co_cb);
  1525. }
  1526. /**
  1527. * nfsd4_do_async_copy - kthread function for background server-side COPY
  1528. * @data: arguments for COPY operation
  1529. *
  1530. * Return values:
  1531. * %0: Copy operation is done.
  1532. */
  1533. static int nfsd4_do_async_copy(void *data)
  1534. {
  1535. struct nfsd4_copy *copy = (struct nfsd4_copy *)data;
  1536. trace_nfsd_copy_async(copy);
  1537. if (nfsd4_ssc_is_inter(copy)) {
  1538. struct file *filp;
  1539. filp = nfs42_ssc_open(copy->ss_nsui->nsui_vfsmount,
  1540. &copy->c_fh, &copy->stateid);
  1541. if (IS_ERR(filp)) {
  1542. switch (PTR_ERR(filp)) {
  1543. case -EBADF:
  1544. copy->nfserr = nfserr_wrong_type;
  1545. break;
  1546. default:
  1547. copy->nfserr = nfserr_offload_denied;
  1548. }
  1549. /* ss_mnt will be unmounted by the laundromat */
  1550. goto do_callback;
  1551. }
  1552. copy->nfserr = nfsd4_do_copy(copy, filp, copy->nf_dst->nf_file,
  1553. false);
  1554. nfsd4_cleanup_inter_ssc(copy->ss_nsui, filp, copy->nf_dst);
  1555. } else {
  1556. copy->nfserr = nfsd4_do_copy(copy, copy->nf_src->nf_file,
  1557. copy->nf_dst->nf_file, false);
  1558. }
  1559. do_callback:
  1560. set_bit(NFSD4_COPY_F_COMPLETED, &copy->cp_flags);
  1561. trace_nfsd_copy_async_done(copy);
  1562. nfsd4_send_cb_offload(copy);
  1563. cleanup_async_copy(copy);
  1564. return 0;
  1565. }
  1566. static __be32
  1567. nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1568. union nfsd4_op_u *u)
  1569. {
  1570. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  1571. struct nfsd4_copy *async_copy = NULL;
  1572. struct nfsd4_copy *copy = &u->copy;
  1573. struct nfsd42_write_res *result;
  1574. __be32 status;
  1575. /*
  1576. * Currently, async COPY is not reliable. Force all COPY
  1577. * requests to be synchronous to avoid client application
  1578. * hangs waiting for COPY completion.
  1579. */
  1580. nfsd4_copy_set_sync(copy, true);
  1581. result = &copy->cp_res;
  1582. nfsd_copy_write_verifier((__be32 *)&result->wr_verifier.data, nn);
  1583. copy->cp_clp = cstate->clp;
  1584. if (nfsd4_ssc_is_inter(copy)) {
  1585. trace_nfsd_copy_inter(copy);
  1586. if (!inter_copy_offload_enable || nfsd4_copy_is_sync(copy)) {
  1587. status = nfserr_notsupp;
  1588. goto out;
  1589. }
  1590. status = nfsd4_setup_inter_ssc(rqstp, cstate, copy);
  1591. if (status) {
  1592. trace_nfsd_copy_done(copy, status);
  1593. return nfserr_offload_denied;
  1594. }
  1595. } else {
  1596. trace_nfsd_copy_intra(copy);
  1597. status = nfsd4_setup_intra_ssc(rqstp, cstate, copy);
  1598. if (status) {
  1599. trace_nfsd_copy_done(copy, status);
  1600. return status;
  1601. }
  1602. }
  1603. memcpy(&copy->fh, &cstate->current_fh.fh_handle,
  1604. sizeof(struct knfsd_fh));
  1605. if (nfsd4_copy_is_async(copy)) {
  1606. async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
  1607. if (!async_copy)
  1608. goto out_err;
  1609. async_copy->cp_nn = nn;
  1610. INIT_LIST_HEAD(&async_copy->copies);
  1611. refcount_set(&async_copy->refcount, 1);
  1612. /* Arbitrary cap on number of pending async copy operations */
  1613. if (atomic_inc_return(&nn->pending_async_copies) >
  1614. (int)rqstp->rq_pool->sp_nrthreads)
  1615. goto out_err;
  1616. async_copy->cp_src = kmalloc(sizeof(*async_copy->cp_src), GFP_KERNEL);
  1617. if (!async_copy->cp_src)
  1618. goto out_err;
  1619. if (!nfs4_init_copy_state(nn, copy))
  1620. goto out_err;
  1621. memcpy(&result->cb_stateid, &copy->cp_stateid.cs_stid,
  1622. sizeof(result->cb_stateid));
  1623. dup_copy_fields(copy, async_copy);
  1624. async_copy->copy_task = kthread_create(nfsd4_do_async_copy,
  1625. async_copy, "%s", "copy thread");
  1626. if (IS_ERR(async_copy->copy_task))
  1627. goto out_err;
  1628. spin_lock(&async_copy->cp_clp->async_lock);
  1629. list_add(&async_copy->copies,
  1630. &async_copy->cp_clp->async_copies);
  1631. spin_unlock(&async_copy->cp_clp->async_lock);
  1632. wake_up_process(async_copy->copy_task);
  1633. status = nfs_ok;
  1634. } else {
  1635. status = nfsd4_do_copy(copy, copy->nf_src->nf_file,
  1636. copy->nf_dst->nf_file, true);
  1637. }
  1638. out:
  1639. trace_nfsd_copy_done(copy, status);
  1640. release_copy_files(copy);
  1641. return status;
  1642. out_err:
  1643. if (nfsd4_ssc_is_inter(copy)) {
  1644. /*
  1645. * Source's vfsmount of inter-copy will be unmounted
  1646. * by the laundromat. Use copy instead of async_copy
  1647. * since async_copy->ss_nsui might not be set yet.
  1648. */
  1649. refcount_dec(&copy->ss_nsui->nsui_refcnt);
  1650. }
  1651. if (async_copy)
  1652. cleanup_async_copy(async_copy);
  1653. status = nfserr_jukebox;
  1654. goto out;
  1655. }
  1656. static struct nfsd4_copy *
  1657. find_async_copy_locked(struct nfs4_client *clp, stateid_t *stateid)
  1658. {
  1659. struct nfsd4_copy *copy;
  1660. lockdep_assert_held(&clp->async_lock);
  1661. list_for_each_entry(copy, &clp->async_copies, copies) {
  1662. if (memcmp(&copy->cp_stateid.cs_stid, stateid, NFS4_STATEID_SIZE))
  1663. continue;
  1664. return copy;
  1665. }
  1666. return NULL;
  1667. }
  1668. static struct nfsd4_copy *
  1669. find_async_copy(struct nfs4_client *clp, stateid_t *stateid)
  1670. {
  1671. struct nfsd4_copy *copy;
  1672. spin_lock(&clp->async_lock);
  1673. copy = find_async_copy_locked(clp, stateid);
  1674. if (copy)
  1675. refcount_inc(&copy->refcount);
  1676. spin_unlock(&clp->async_lock);
  1677. return copy;
  1678. }
  1679. static __be32
  1680. nfsd4_offload_cancel(struct svc_rqst *rqstp,
  1681. struct nfsd4_compound_state *cstate,
  1682. union nfsd4_op_u *u)
  1683. {
  1684. struct nfsd4_offload_status *os = &u->offload_status;
  1685. struct nfsd4_copy *copy;
  1686. struct nfs4_client *clp = cstate->clp;
  1687. copy = find_async_copy(clp, &os->stateid);
  1688. if (!copy) {
  1689. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  1690. return manage_cpntf_state(nn, &os->stateid, clp, NULL);
  1691. } else
  1692. nfsd4_stop_copy(copy);
  1693. return nfs_ok;
  1694. }
  1695. static __be32
  1696. nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1697. union nfsd4_op_u *u)
  1698. {
  1699. struct nfsd4_copy_notify *cn = &u->copy_notify;
  1700. __be32 status;
  1701. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  1702. struct nfs4_stid *stid = NULL;
  1703. struct nfs4_cpntf_state *cps;
  1704. struct nfs4_client *clp = cstate->clp;
  1705. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  1706. &cn->cpn_src_stateid, RD_STATE, NULL,
  1707. &stid);
  1708. if (status)
  1709. return status;
  1710. if (!stid)
  1711. return nfserr_bad_stateid;
  1712. cn->cpn_lease_time.tv_sec = nn->nfsd4_lease;
  1713. cn->cpn_lease_time.tv_nsec = 0;
  1714. status = nfserrno(-ENOMEM);
  1715. cps = nfs4_alloc_init_cpntf_state(nn, stid);
  1716. if (!cps)
  1717. goto out;
  1718. memcpy(&cn->cpn_cnr_stateid, &cps->cp_stateid.cs_stid, sizeof(stateid_t));
  1719. memcpy(&cps->cp_p_stateid, &stid->sc_stateid, sizeof(stateid_t));
  1720. memcpy(&cps->cp_p_clid, &clp->cl_clientid, sizeof(clientid_t));
  1721. /* For now, only return one server address in cpn_src, the
  1722. * address used by the client to connect to this server.
  1723. */
  1724. cn->cpn_src->nl4_type = NL4_NETADDR;
  1725. status = nfsd4_set_netaddr((struct sockaddr *)&rqstp->rq_daddr,
  1726. &cn->cpn_src->u.nl4_addr);
  1727. WARN_ON_ONCE(status);
  1728. if (status) {
  1729. nfs4_put_cpntf_state(nn, cps);
  1730. goto out;
  1731. }
  1732. out:
  1733. nfs4_put_stid(stid);
  1734. return status;
  1735. }
  1736. static __be32
  1737. nfsd4_fallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1738. struct nfsd4_fallocate *fallocate, int flags)
  1739. {
  1740. __be32 status;
  1741. struct nfsd_file *nf;
  1742. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  1743. &fallocate->falloc_stateid,
  1744. WR_STATE, &nf, NULL);
  1745. if (status != nfs_ok)
  1746. return status;
  1747. status = nfsd4_vfs_fallocate(rqstp, &cstate->current_fh, nf->nf_file,
  1748. fallocate->falloc_offset,
  1749. fallocate->falloc_length,
  1750. flags);
  1751. nfsd_file_put(nf);
  1752. return status;
  1753. }
  1754. static __be32
  1755. nfsd4_offload_status(struct svc_rqst *rqstp,
  1756. struct nfsd4_compound_state *cstate,
  1757. union nfsd4_op_u *u)
  1758. {
  1759. struct nfsd4_offload_status *os = &u->offload_status;
  1760. __be32 status = nfs_ok;
  1761. struct nfsd4_copy *copy;
  1762. struct nfs4_client *clp = cstate->clp;
  1763. os->completed = false;
  1764. spin_lock(&clp->async_lock);
  1765. copy = find_async_copy_locked(clp, &os->stateid);
  1766. if (copy) {
  1767. os->count = copy->cp_res.wr_bytes_written;
  1768. if (test_bit(NFSD4_COPY_F_COMPLETED, &copy->cp_flags)) {
  1769. os->completed = true;
  1770. os->status = copy->nfserr;
  1771. }
  1772. } else
  1773. status = nfserr_bad_stateid;
  1774. spin_unlock(&clp->async_lock);
  1775. return status;
  1776. }
  1777. static __be32
  1778. nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1779. union nfsd4_op_u *u)
  1780. {
  1781. return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0);
  1782. }
  1783. static __be32
  1784. nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1785. union nfsd4_op_u *u)
  1786. {
  1787. return nfsd4_fallocate(rqstp, cstate, &u->deallocate,
  1788. FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
  1789. }
  1790. static __be32
  1791. nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1792. union nfsd4_op_u *u)
  1793. {
  1794. struct nfsd4_seek *seek = &u->seek;
  1795. int whence;
  1796. __be32 status;
  1797. struct nfsd_file *nf;
  1798. status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
  1799. &seek->seek_stateid,
  1800. RD_STATE, &nf, NULL);
  1801. if (status)
  1802. return status;
  1803. switch (seek->seek_whence) {
  1804. case NFS4_CONTENT_DATA:
  1805. whence = SEEK_DATA;
  1806. break;
  1807. case NFS4_CONTENT_HOLE:
  1808. whence = SEEK_HOLE;
  1809. break;
  1810. default:
  1811. status = nfserr_union_notsupp;
  1812. goto out;
  1813. }
  1814. /*
  1815. * Note: This call does change file->f_pos, but nothing in NFSD
  1816. * should ever file->f_pos.
  1817. */
  1818. seek->seek_pos = vfs_llseek(nf->nf_file, seek->seek_offset, whence);
  1819. if (seek->seek_pos < 0)
  1820. status = nfserrno(seek->seek_pos);
  1821. else if (seek->seek_pos >= i_size_read(file_inode(nf->nf_file)))
  1822. seek->seek_eof = true;
  1823. out:
  1824. nfsd_file_put(nf);
  1825. return status;
  1826. }
  1827. /* This routine never returns NFS_OK! If there are no other errors, it
  1828. * will return NFSERR_SAME or NFSERR_NOT_SAME depending on whether the
  1829. * attributes matched. VERIFY is implemented by mapping NFSERR_SAME
  1830. * to NFS_OK after the call; NVERIFY by mapping NFSERR_NOT_SAME to NFS_OK.
  1831. */
  1832. static __be32
  1833. _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1834. struct nfsd4_verify *verify)
  1835. {
  1836. __be32 *buf, *p;
  1837. int count;
  1838. __be32 status;
  1839. status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
  1840. if (status)
  1841. return status;
  1842. status = check_attr_support(rqstp, cstate, verify->ve_bmval, NULL);
  1843. if (status)
  1844. return status;
  1845. if ((verify->ve_bmval[0] & FATTR4_WORD0_RDATTR_ERROR)
  1846. || (verify->ve_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1))
  1847. return nfserr_inval;
  1848. if (verify->ve_attrlen & 3)
  1849. return nfserr_inval;
  1850. /* count in words:
  1851. * bitmap_len(1) + bitmap(2) + attr_len(1) = 4
  1852. */
  1853. count = 4 + (verify->ve_attrlen >> 2);
  1854. buf = kmalloc(count << 2, GFP_KERNEL);
  1855. if (!buf)
  1856. return nfserr_jukebox;
  1857. p = buf;
  1858. status = nfsd4_encode_fattr_to_buf(&p, count, &cstate->current_fh,
  1859. cstate->current_fh.fh_export,
  1860. cstate->current_fh.fh_dentry,
  1861. verify->ve_bmval,
  1862. rqstp, 0);
  1863. /*
  1864. * If nfsd4_encode_fattr() ran out of space, assume that's because
  1865. * the attributes are longer (hence different) than those given:
  1866. */
  1867. if (status == nfserr_resource)
  1868. status = nfserr_not_same;
  1869. if (status)
  1870. goto out_kfree;
  1871. /* skip bitmap */
  1872. p = buf + 1 + ntohl(buf[0]);
  1873. status = nfserr_not_same;
  1874. if (ntohl(*p++) != verify->ve_attrlen)
  1875. goto out_kfree;
  1876. if (!memcmp(p, verify->ve_attrval, verify->ve_attrlen))
  1877. status = nfserr_same;
  1878. out_kfree:
  1879. kfree(buf);
  1880. return status;
  1881. }
  1882. static __be32
  1883. nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1884. union nfsd4_op_u *u)
  1885. {
  1886. __be32 status;
  1887. status = _nfsd4_verify(rqstp, cstate, &u->verify);
  1888. return status == nfserr_not_same ? nfs_ok : status;
  1889. }
  1890. static __be32
  1891. nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  1892. union nfsd4_op_u *u)
  1893. {
  1894. __be32 status;
  1895. status = _nfsd4_verify(rqstp, cstate, &u->nverify);
  1896. return status == nfserr_same ? nfs_ok : status;
  1897. }
  1898. static __be32
  1899. nfsd4_get_dir_delegation(struct svc_rqst *rqstp,
  1900. struct nfsd4_compound_state *cstate,
  1901. union nfsd4_op_u *u)
  1902. {
  1903. struct nfsd4_get_dir_delegation *gdd = &u->get_dir_delegation;
  1904. /*
  1905. * RFC 8881, section 18.39.3 says:
  1906. *
  1907. * "The server may refuse to grant the delegation. In that case, the
  1908. * server will return NFS4ERR_DIRDELEG_UNAVAIL."
  1909. *
  1910. * This is sub-optimal, since it means that the server would need to
  1911. * abort compound processing just because the delegation wasn't
  1912. * available. RFC8881bis should change this to allow the server to
  1913. * return NFS4_OK with a non-fatal status of GDD4_UNAVAIL in this
  1914. * situation.
  1915. */
  1916. gdd->gddrnf_status = GDD4_UNAVAIL;
  1917. return nfs_ok;
  1918. }
  1919. #ifdef CONFIG_NFSD_PNFS
  1920. static const struct nfsd4_layout_ops *
  1921. nfsd4_layout_verify(struct svc_export *exp, unsigned int layout_type)
  1922. {
  1923. if (!exp->ex_layout_types) {
  1924. dprintk("%s: export does not support pNFS\n", __func__);
  1925. return NULL;
  1926. }
  1927. if (layout_type >= LAYOUT_TYPE_MAX ||
  1928. !(exp->ex_layout_types & (1 << layout_type))) {
  1929. dprintk("%s: layout type %d not supported\n",
  1930. __func__, layout_type);
  1931. return NULL;
  1932. }
  1933. return nfsd4_layout_ops[layout_type];
  1934. }
  1935. static __be32
  1936. nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
  1937. struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
  1938. {
  1939. struct nfsd4_getdeviceinfo *gdp = &u->getdeviceinfo;
  1940. const struct nfsd4_layout_ops *ops;
  1941. struct nfsd4_deviceid_map *map;
  1942. struct svc_export *exp;
  1943. __be32 nfserr;
  1944. dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
  1945. __func__,
  1946. gdp->gd_layout_type,
  1947. gdp->gd_devid.fsid_idx, gdp->gd_devid.generation,
  1948. gdp->gd_maxcount);
  1949. map = nfsd4_find_devid_map(gdp->gd_devid.fsid_idx);
  1950. if (!map) {
  1951. dprintk("%s: couldn't find device ID to export mapping!\n",
  1952. __func__);
  1953. return nfserr_noent;
  1954. }
  1955. exp = rqst_exp_find(&rqstp->rq_chandle, SVC_NET(rqstp),
  1956. rqstp->rq_client, rqstp->rq_gssclient,
  1957. map->fsid_type, map->fsid);
  1958. if (IS_ERR(exp)) {
  1959. dprintk("%s: could not find device id\n", __func__);
  1960. return nfserr_noent;
  1961. }
  1962. nfserr = nfserr_layoutunavailable;
  1963. ops = nfsd4_layout_verify(exp, gdp->gd_layout_type);
  1964. if (!ops)
  1965. goto out;
  1966. nfserr = nfs_ok;
  1967. if (gdp->gd_maxcount != 0) {
  1968. nfserr = ops->proc_getdeviceinfo(exp->ex_path.mnt->mnt_sb,
  1969. rqstp, cstate->clp, gdp);
  1970. }
  1971. gdp->gd_notify_types &= ops->notify_types;
  1972. out:
  1973. exp_put(exp);
  1974. return nfserr;
  1975. }
  1976. static void
  1977. nfsd4_getdeviceinfo_release(union nfsd4_op_u *u)
  1978. {
  1979. kfree(u->getdeviceinfo.gd_device);
  1980. }
  1981. static __be32
  1982. nfsd4_layoutget(struct svc_rqst *rqstp,
  1983. struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
  1984. {
  1985. struct nfsd4_layoutget *lgp = &u->layoutget;
  1986. struct svc_fh *current_fh = &cstate->current_fh;
  1987. const struct nfsd4_layout_ops *ops;
  1988. struct nfs4_layout_stateid *ls;
  1989. __be32 nfserr;
  1990. int accmode = NFSD_MAY_READ_IF_EXEC | NFSD_MAY_OWNER_OVERRIDE;
  1991. switch (lgp->lg_seg.iomode) {
  1992. case IOMODE_READ:
  1993. accmode |= NFSD_MAY_READ;
  1994. break;
  1995. case IOMODE_RW:
  1996. accmode |= NFSD_MAY_READ | NFSD_MAY_WRITE;
  1997. break;
  1998. default:
  1999. dprintk("%s: invalid iomode %d\n",
  2000. __func__, lgp->lg_seg.iomode);
  2001. nfserr = nfserr_badiomode;
  2002. goto out;
  2003. }
  2004. nfserr = fh_verify(rqstp, current_fh, 0, accmode);
  2005. if (nfserr)
  2006. goto out;
  2007. nfserr = nfserr_layoutunavailable;
  2008. ops = nfsd4_layout_verify(current_fh->fh_export, lgp->lg_layout_type);
  2009. if (!ops)
  2010. goto out;
  2011. /*
  2012. * Verify minlength and range as per RFC5661:
  2013. * o If loga_length is less than loga_minlength,
  2014. * the metadata server MUST return NFS4ERR_INVAL.
  2015. * o If the sum of loga_offset and loga_minlength exceeds
  2016. * NFS4_UINT64_MAX, and loga_minlength is not
  2017. * NFS4_UINT64_MAX, the error NFS4ERR_INVAL MUST result.
  2018. * o If the sum of loga_offset and loga_length exceeds
  2019. * NFS4_UINT64_MAX, and loga_length is not NFS4_UINT64_MAX,
  2020. * the error NFS4ERR_INVAL MUST result.
  2021. */
  2022. nfserr = nfserr_inval;
  2023. if (lgp->lg_seg.length < lgp->lg_minlength ||
  2024. (lgp->lg_minlength != NFS4_MAX_UINT64 &&
  2025. lgp->lg_minlength > NFS4_MAX_UINT64 - lgp->lg_seg.offset) ||
  2026. (lgp->lg_seg.length != NFS4_MAX_UINT64 &&
  2027. lgp->lg_seg.length > NFS4_MAX_UINT64 - lgp->lg_seg.offset))
  2028. goto out;
  2029. if (lgp->lg_seg.length == 0)
  2030. goto out;
  2031. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
  2032. true, lgp->lg_layout_type, &ls);
  2033. if (nfserr) {
  2034. trace_nfsd_layout_get_lookup_fail(&lgp->lg_sid);
  2035. goto out;
  2036. }
  2037. nfserr = nfserr_recallconflict;
  2038. if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
  2039. goto out_put_stid;
  2040. nfserr = ops->proc_layoutget(d_inode(current_fh->fh_dentry),
  2041. current_fh, lgp);
  2042. if (nfserr)
  2043. goto out_put_stid;
  2044. nfserr = nfsd4_insert_layout(lgp, ls);
  2045. out_put_stid:
  2046. mutex_unlock(&ls->ls_mutex);
  2047. nfs4_put_stid(&ls->ls_stid);
  2048. out:
  2049. return nfserr;
  2050. }
  2051. static void
  2052. nfsd4_layoutget_release(union nfsd4_op_u *u)
  2053. {
  2054. kfree(u->layoutget.lg_content);
  2055. }
  2056. static __be32
  2057. nfsd4_layoutcommit(struct svc_rqst *rqstp,
  2058. struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
  2059. {
  2060. struct nfsd4_layoutcommit *lcp = &u->layoutcommit;
  2061. const struct nfsd4_layout_seg *seg = &lcp->lc_seg;
  2062. struct svc_fh *current_fh = &cstate->current_fh;
  2063. const struct nfsd4_layout_ops *ops;
  2064. struct inode *inode;
  2065. struct nfs4_layout_stateid *ls;
  2066. __be32 nfserr;
  2067. nfserr = fh_verify(rqstp, current_fh, 0,
  2068. NFSD_MAY_WRITE | NFSD_MAY_OWNER_OVERRIDE);
  2069. if (nfserr)
  2070. goto out;
  2071. nfserr = nfserr_layoutunavailable;
  2072. ops = nfsd4_layout_verify(current_fh->fh_export, lcp->lc_layout_type);
  2073. if (!ops)
  2074. goto out;
  2075. inode = d_inode(current_fh->fh_dentry);
  2076. lcp->lc_size_chg = false;
  2077. if (lcp->lc_newoffset) {
  2078. loff_t new_size = lcp->lc_last_wr + 1;
  2079. nfserr = nfserr_inval;
  2080. if (new_size <= seg->offset)
  2081. goto out;
  2082. if (new_size > seg->offset + seg->length)
  2083. goto out;
  2084. if (new_size > i_size_read(inode)) {
  2085. lcp->lc_size_chg = true;
  2086. lcp->lc_newsize = new_size;
  2087. }
  2088. }
  2089. nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lcp->lc_sid,
  2090. false, lcp->lc_layout_type,
  2091. &ls);
  2092. if (nfserr) {
  2093. trace_nfsd_layout_commit_lookup_fail(&lcp->lc_sid);
  2094. /* fixup error code as per RFC5661 */
  2095. if (nfserr == nfserr_bad_stateid)
  2096. nfserr = nfserr_badlayout;
  2097. goto out;
  2098. }
  2099. /* LAYOUTCOMMIT does not require any serialization */
  2100. mutex_unlock(&ls->ls_mutex);
  2101. nfserr = ops->proc_layoutcommit(inode, rqstp, lcp);
  2102. nfs4_put_stid(&ls->ls_stid);
  2103. out:
  2104. return nfserr;
  2105. }
  2106. static __be32
  2107. nfsd4_layoutreturn(struct svc_rqst *rqstp,
  2108. struct nfsd4_compound_state *cstate, union nfsd4_op_u *u)
  2109. {
  2110. struct nfsd4_layoutreturn *lrp = &u->layoutreturn;
  2111. struct svc_fh *current_fh = &cstate->current_fh;
  2112. __be32 nfserr;
  2113. nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
  2114. if (nfserr)
  2115. goto out;
  2116. nfserr = nfserr_layoutunavailable;
  2117. if (!nfsd4_layout_verify(current_fh->fh_export, lrp->lr_layout_type))
  2118. goto out;
  2119. switch (lrp->lr_seg.iomode) {
  2120. case IOMODE_READ:
  2121. case IOMODE_RW:
  2122. case IOMODE_ANY:
  2123. break;
  2124. default:
  2125. dprintk("%s: invalid iomode %d\n", __func__,
  2126. lrp->lr_seg.iomode);
  2127. nfserr = nfserr_inval;
  2128. goto out;
  2129. }
  2130. switch (lrp->lr_return_type) {
  2131. case RETURN_FILE:
  2132. nfserr = nfsd4_return_file_layouts(rqstp, cstate, lrp);
  2133. break;
  2134. case RETURN_FSID:
  2135. case RETURN_ALL:
  2136. nfserr = nfsd4_return_client_layouts(rqstp, cstate, lrp);
  2137. break;
  2138. default:
  2139. dprintk("%s: invalid return_type %d\n", __func__,
  2140. lrp->lr_return_type);
  2141. nfserr = nfserr_inval;
  2142. break;
  2143. }
  2144. out:
  2145. return nfserr;
  2146. }
  2147. #endif /* CONFIG_NFSD_PNFS */
  2148. static __be32
  2149. nfsd4_getxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  2150. union nfsd4_op_u *u)
  2151. {
  2152. struct nfsd4_getxattr *getxattr = &u->getxattr;
  2153. return nfsd_getxattr(rqstp, &cstate->current_fh,
  2154. getxattr->getxa_name, &getxattr->getxa_buf,
  2155. &getxattr->getxa_len);
  2156. }
  2157. static __be32
  2158. nfsd4_setxattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  2159. union nfsd4_op_u *u)
  2160. {
  2161. struct nfsd4_setxattr *setxattr = &u->setxattr;
  2162. __be32 ret;
  2163. if (opens_in_grace(SVC_NET(rqstp)))
  2164. return nfserr_grace;
  2165. ret = nfsd_setxattr(rqstp, &cstate->current_fh, setxattr->setxa_name,
  2166. setxattr->setxa_buf, setxattr->setxa_len,
  2167. setxattr->setxa_flags);
  2168. if (!ret)
  2169. set_change_info(&setxattr->setxa_cinfo, &cstate->current_fh);
  2170. return ret;
  2171. }
  2172. static __be32
  2173. nfsd4_listxattrs(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  2174. union nfsd4_op_u *u)
  2175. {
  2176. /*
  2177. * Get the entire list, then copy out only the user attributes
  2178. * in the encode function.
  2179. */
  2180. return nfsd_listxattr(rqstp, &cstate->current_fh,
  2181. &u->listxattrs.lsxa_buf, &u->listxattrs.lsxa_len);
  2182. }
  2183. static __be32
  2184. nfsd4_removexattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
  2185. union nfsd4_op_u *u)
  2186. {
  2187. struct nfsd4_removexattr *removexattr = &u->removexattr;
  2188. __be32 ret;
  2189. if (opens_in_grace(SVC_NET(rqstp)))
  2190. return nfserr_grace;
  2191. ret = nfsd_removexattr(rqstp, &cstate->current_fh,
  2192. removexattr->rmxa_name);
  2193. if (!ret)
  2194. set_change_info(&removexattr->rmxa_cinfo, &cstate->current_fh);
  2195. return ret;
  2196. }
  2197. /*
  2198. * NULL call.
  2199. */
  2200. static __be32
  2201. nfsd4_proc_null(struct svc_rqst *rqstp)
  2202. {
  2203. return rpc_success;
  2204. }
  2205. static inline void nfsd4_increment_op_stats(struct nfsd_net *nn, u32 opnum)
  2206. {
  2207. if (opnum >= FIRST_NFS4_OP && opnum <= LAST_NFS4_OP)
  2208. percpu_counter_inc(&nn->counter[NFSD_STATS_NFS4_OP(opnum)]);
  2209. }
  2210. static const struct nfsd4_operation nfsd4_ops[];
  2211. static const char *nfsd4_op_name(unsigned opnum);
  2212. /*
  2213. * Enforce NFSv4.1 COMPOUND ordering rules:
  2214. *
  2215. * Also note, enforced elsewhere:
  2216. * - SEQUENCE other than as first op results in
  2217. * NFS4ERR_SEQUENCE_POS. (Enforced in nfsd4_sequence().)
  2218. * - BIND_CONN_TO_SESSION must be the only op in its compound.
  2219. * (Enforced in nfsd4_bind_conn_to_session().)
  2220. * - DESTROY_SESSION must be the final operation in a compound, if
  2221. * sessionid's in SEQUENCE and DESTROY_SESSION are the same.
  2222. * (Enforced in nfsd4_destroy_session().)
  2223. */
  2224. static __be32 nfs41_check_op_ordering(struct nfsd4_compoundargs *args)
  2225. {
  2226. struct nfsd4_op *first_op = &args->ops[0];
  2227. /* These ordering requirements don't apply to NFSv4.0: */
  2228. if (args->minorversion == 0)
  2229. return nfs_ok;
  2230. /* This is weird, but OK, not our problem: */
  2231. if (args->opcnt == 0)
  2232. return nfs_ok;
  2233. if (first_op->status == nfserr_op_illegal)
  2234. return nfs_ok;
  2235. if (!(nfsd4_ops[first_op->opnum].op_flags & ALLOWED_AS_FIRST_OP))
  2236. return nfserr_op_not_in_session;
  2237. if (first_op->opnum == OP_SEQUENCE)
  2238. return nfs_ok;
  2239. /*
  2240. * So first_op is something allowed outside a session, like
  2241. * EXCHANGE_ID; but then it has to be the only op in the
  2242. * compound:
  2243. */
  2244. if (args->opcnt != 1)
  2245. return nfserr_not_only_op;
  2246. return nfs_ok;
  2247. }
  2248. const struct nfsd4_operation *OPDESC(struct nfsd4_op *op)
  2249. {
  2250. return &nfsd4_ops[op->opnum];
  2251. }
  2252. bool nfsd4_cache_this_op(struct nfsd4_op *op)
  2253. {
  2254. if (op->opnum == OP_ILLEGAL)
  2255. return false;
  2256. return OPDESC(op)->op_flags & OP_CACHEME;
  2257. }
  2258. static bool need_wrongsec_check(struct svc_rqst *rqstp)
  2259. {
  2260. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  2261. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  2262. struct nfsd4_op *this = &argp->ops[resp->opcnt - 1];
  2263. struct nfsd4_op *next = &argp->ops[resp->opcnt];
  2264. const struct nfsd4_operation *thisd = OPDESC(this);
  2265. const struct nfsd4_operation *nextd;
  2266. /*
  2267. * Most ops check wronsec on our own; only the putfh-like ops
  2268. * have special rules.
  2269. */
  2270. if (!(thisd->op_flags & OP_IS_PUTFH_LIKE))
  2271. return false;
  2272. /*
  2273. * rfc 5661 2.6.3.1.1.6: don't bother erroring out a
  2274. * put-filehandle operation if we're not going to use the
  2275. * result:
  2276. */
  2277. if (argp->opcnt == resp->opcnt)
  2278. return false;
  2279. if (next->opnum == OP_ILLEGAL)
  2280. return false;
  2281. nextd = OPDESC(next);
  2282. /*
  2283. * Rest of 2.6.3.1.1: certain operations will return WRONGSEC
  2284. * errors themselves as necessary; others should check for them
  2285. * now:
  2286. */
  2287. return !(nextd->op_flags & OP_HANDLES_WRONGSEC);
  2288. }
  2289. #ifdef CONFIG_NFSD_V4_2_INTER_SSC
  2290. static void
  2291. check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
  2292. {
  2293. struct nfsd4_op *op, *current_op = NULL, *saved_op = NULL;
  2294. struct nfsd4_copy *copy;
  2295. struct nfsd4_putfh *putfh;
  2296. int i;
  2297. /* traverse all operation and if it's a COPY compound, mark the
  2298. * source filehandle to skip verification
  2299. */
  2300. for (i = 0; i < args->opcnt; i++) {
  2301. op = &args->ops[i];
  2302. if (op->opnum == OP_PUTFH)
  2303. current_op = op;
  2304. else if (op->opnum == OP_SAVEFH)
  2305. saved_op = current_op;
  2306. else if (op->opnum == OP_RESTOREFH)
  2307. current_op = saved_op;
  2308. else if (op->opnum == OP_COPY) {
  2309. copy = (struct nfsd4_copy *)&op->u;
  2310. if (!saved_op) {
  2311. op->status = nfserr_nofilehandle;
  2312. return;
  2313. }
  2314. putfh = (struct nfsd4_putfh *)&saved_op->u;
  2315. if (nfsd4_ssc_is_inter(copy))
  2316. putfh->no_verify = true;
  2317. }
  2318. }
  2319. }
  2320. #else
  2321. static void
  2322. check_if_stalefh_allowed(struct nfsd4_compoundargs *args)
  2323. {
  2324. }
  2325. #endif
  2326. /*
  2327. * COMPOUND call.
  2328. */
  2329. static __be32
  2330. nfsd4_proc_compound(struct svc_rqst *rqstp)
  2331. {
  2332. struct nfsd4_compoundargs *args = rqstp->rq_argp;
  2333. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  2334. struct nfsd4_op *op;
  2335. struct nfsd4_compound_state *cstate = &resp->cstate;
  2336. struct svc_fh *current_fh = &cstate->current_fh;
  2337. struct svc_fh *save_fh = &cstate->save_fh;
  2338. struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
  2339. __be32 status;
  2340. resp->xdr = &rqstp->rq_res_stream;
  2341. resp->statusp = resp->xdr->p;
  2342. /* reserve space for: NFS status code */
  2343. xdr_reserve_space(resp->xdr, XDR_UNIT);
  2344. /* reserve space for: taglen, tag, and opcnt */
  2345. xdr_reserve_space(resp->xdr, XDR_UNIT * 2 + args->taglen);
  2346. resp->taglen = args->taglen;
  2347. resp->tag = args->tag;
  2348. resp->rqstp = rqstp;
  2349. cstate->minorversion = args->minorversion;
  2350. fh_init(current_fh, NFS4_FHSIZE);
  2351. fh_init(save_fh, NFS4_FHSIZE);
  2352. /*
  2353. * Don't use the deferral mechanism for NFSv4; compounds make it
  2354. * too hard to avoid non-idempotency problems.
  2355. */
  2356. clear_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  2357. /*
  2358. * According to RFC3010, this takes precedence over all other errors.
  2359. */
  2360. status = nfserr_minor_vers_mismatch;
  2361. if (nfsd_minorversion(nn, args->minorversion, NFSD_TEST) <= 0)
  2362. goto out;
  2363. status = nfs41_check_op_ordering(args);
  2364. if (status) {
  2365. op = &args->ops[0];
  2366. op->status = status;
  2367. resp->opcnt = 1;
  2368. goto encode_op;
  2369. }
  2370. check_if_stalefh_allowed(args);
  2371. rqstp->rq_lease_breaker = (void **)&cstate->clp;
  2372. trace_nfsd_compound(rqstp, args->tag, args->taglen, args->client_opcnt);
  2373. while (!status && resp->opcnt < args->opcnt) {
  2374. op = &args->ops[resp->opcnt++];
  2375. if (unlikely(resp->opcnt == NFSD_MAX_OPS_PER_COMPOUND)) {
  2376. /* If there are still more operations to process,
  2377. * stop here and report NFS4ERR_RESOURCE. */
  2378. if (cstate->minorversion == 0 &&
  2379. args->client_opcnt > resp->opcnt) {
  2380. op->status = nfserr_resource;
  2381. goto encode_op;
  2382. }
  2383. }
  2384. /*
  2385. * The XDR decode routines may have pre-set op->status;
  2386. * for example, if there is a miscellaneous XDR error
  2387. * it will be set to nfserr_bad_xdr.
  2388. */
  2389. if (op->status) {
  2390. if (op->opnum == OP_OPEN)
  2391. op->status = nfsd4_open_omfg(rqstp, cstate, op);
  2392. goto encode_op;
  2393. }
  2394. if (!current_fh->fh_dentry &&
  2395. !HAS_FH_FLAG(current_fh, NFSD4_FH_FOREIGN)) {
  2396. if (!(op->opdesc->op_flags & ALLOWED_WITHOUT_FH)) {
  2397. op->status = nfserr_nofilehandle;
  2398. goto encode_op;
  2399. }
  2400. } else if (current_fh->fh_export &&
  2401. current_fh->fh_export->ex_fslocs.migrated &&
  2402. !(op->opdesc->op_flags & ALLOWED_ON_ABSENT_FS)) {
  2403. op->status = nfserr_moved;
  2404. goto encode_op;
  2405. }
  2406. fh_clear_pre_post_attrs(current_fh);
  2407. /* If op is non-idempotent */
  2408. if (op->opdesc->op_flags & OP_MODIFIES_SOMETHING) {
  2409. /*
  2410. * Don't execute this op if we couldn't encode a
  2411. * successful reply:
  2412. */
  2413. u32 plen = op->opdesc->op_rsize_bop(rqstp, op);
  2414. /*
  2415. * Plus if there's another operation, make sure
  2416. * we'll have space to at least encode an error:
  2417. */
  2418. if (resp->opcnt < args->opcnt)
  2419. plen += COMPOUND_ERR_SLACK_SPACE;
  2420. op->status = nfsd4_check_resp_size(resp, plen);
  2421. }
  2422. if (op->status)
  2423. goto encode_op;
  2424. if (op->opdesc->op_get_currentstateid)
  2425. op->opdesc->op_get_currentstateid(cstate, &op->u);
  2426. op->status = op->opdesc->op_func(rqstp, cstate, &op->u);
  2427. /* Only from SEQUENCE */
  2428. if (cstate->status == nfserr_replay_cache) {
  2429. dprintk("%s NFS4.1 replay from cache\n", __func__);
  2430. status = op->status;
  2431. goto out;
  2432. }
  2433. if (!op->status) {
  2434. if (op->opdesc->op_set_currentstateid)
  2435. op->opdesc->op_set_currentstateid(cstate, &op->u);
  2436. if (op->opdesc->op_flags & OP_CLEAR_STATEID)
  2437. clear_current_stateid(cstate);
  2438. if (current_fh->fh_export &&
  2439. need_wrongsec_check(rqstp))
  2440. op->status = check_nfsd_access(current_fh->fh_export, rqstp, false);
  2441. }
  2442. encode_op:
  2443. if (op->status == nfserr_replay_me) {
  2444. op->replay = &cstate->replay_owner->so_replay;
  2445. nfsd4_encode_replay(resp->xdr, op);
  2446. status = op->status = op->replay->rp_status;
  2447. } else {
  2448. nfsd4_encode_operation(resp, op);
  2449. status = op->status;
  2450. }
  2451. trace_nfsd_compound_status(args->client_opcnt, resp->opcnt,
  2452. status, nfsd4_op_name(op->opnum));
  2453. nfsd4_cstate_clear_replay(cstate);
  2454. nfsd4_increment_op_stats(nn, op->opnum);
  2455. }
  2456. fh_put(current_fh);
  2457. fh_put(save_fh);
  2458. BUG_ON(cstate->replay_owner);
  2459. out:
  2460. cstate->status = status;
  2461. /* Reset deferral mechanism for RPC deferrals */
  2462. set_bit(RQ_USEDEFERRAL, &rqstp->rq_flags);
  2463. return rpc_success;
  2464. }
  2465. #define op_encode_hdr_size (2)
  2466. #define op_encode_stateid_maxsz (XDR_QUADLEN(NFS4_STATEID_SIZE))
  2467. #define op_encode_verifier_maxsz (XDR_QUADLEN(NFS4_VERIFIER_SIZE))
  2468. #define op_encode_change_info_maxsz (5)
  2469. #define nfs4_fattr_bitmap_maxsz (4)
  2470. /* We'll fall back on returning no lockowner if run out of space: */
  2471. #define op_encode_lockowner_maxsz (0)
  2472. #define op_encode_lock_denied_maxsz (8 + op_encode_lockowner_maxsz)
  2473. #define nfs4_owner_maxsz (1 + XDR_QUADLEN(IDMAP_NAMESZ))
  2474. #define op_encode_ace_maxsz (3 + nfs4_owner_maxsz)
  2475. #define op_encode_delegation_maxsz (1 + op_encode_stateid_maxsz + 1 + \
  2476. op_encode_ace_maxsz)
  2477. #define op_encode_channel_attrs_maxsz (6 + 1 + 1)
  2478. /*
  2479. * The _rsize() helpers are invoked by the NFSv4 COMPOUND decoder, which
  2480. * is called before sunrpc sets rq_res.buflen. Thus we have to compute
  2481. * the maximum payload size here, based on transport limits and the size
  2482. * of the remaining space in the rq_pages array.
  2483. */
  2484. static u32 nfsd4_max_payload(const struct svc_rqst *rqstp)
  2485. {
  2486. u32 buflen;
  2487. buflen = (rqstp->rq_page_end - rqstp->rq_next_page) * PAGE_SIZE;
  2488. buflen -= rqstp->rq_auth_slack;
  2489. buflen -= rqstp->rq_res.head[0].iov_len;
  2490. return min_t(u32, buflen, svc_max_payload(rqstp));
  2491. }
  2492. static u32 nfsd4_only_status_rsize(const struct svc_rqst *rqstp,
  2493. const struct nfsd4_op *op)
  2494. {
  2495. return (op_encode_hdr_size) * sizeof(__be32);
  2496. }
  2497. static u32 nfsd4_status_stateid_rsize(const struct svc_rqst *rqstp,
  2498. const struct nfsd4_op *op)
  2499. {
  2500. return (op_encode_hdr_size + op_encode_stateid_maxsz)* sizeof(__be32);
  2501. }
  2502. static u32 nfsd4_access_rsize(const struct svc_rqst *rqstp,
  2503. const struct nfsd4_op *op)
  2504. {
  2505. /* ac_supported, ac_resp_access */
  2506. return (op_encode_hdr_size + 2)* sizeof(__be32);
  2507. }
  2508. static u32 nfsd4_commit_rsize(const struct svc_rqst *rqstp,
  2509. const struct nfsd4_op *op)
  2510. {
  2511. return (op_encode_hdr_size + op_encode_verifier_maxsz) * sizeof(__be32);
  2512. }
  2513. static u32 nfsd4_create_rsize(const struct svc_rqst *rqstp,
  2514. const struct nfsd4_op *op)
  2515. {
  2516. return (op_encode_hdr_size + op_encode_change_info_maxsz
  2517. + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  2518. }
  2519. /*
  2520. * Note since this is an idempotent operation we won't insist on failing
  2521. * the op prematurely if the estimate is too large. We may turn off splice
  2522. * reads unnecessarily.
  2523. */
  2524. static u32 nfsd4_getattr_rsize(const struct svc_rqst *rqstp,
  2525. const struct nfsd4_op *op)
  2526. {
  2527. const u32 *bmap = op->u.getattr.ga_bmval;
  2528. u32 bmap0 = bmap[0], bmap1 = bmap[1], bmap2 = bmap[2];
  2529. u32 ret = 0;
  2530. if (bmap0 & FATTR4_WORD0_ACL)
  2531. return nfsd4_max_payload(rqstp);
  2532. if (bmap0 & FATTR4_WORD0_FS_LOCATIONS)
  2533. return nfsd4_max_payload(rqstp);
  2534. if (bmap1 & FATTR4_WORD1_OWNER) {
  2535. ret += IDMAP_NAMESZ + 4;
  2536. bmap1 &= ~FATTR4_WORD1_OWNER;
  2537. }
  2538. if (bmap1 & FATTR4_WORD1_OWNER_GROUP) {
  2539. ret += IDMAP_NAMESZ + 4;
  2540. bmap1 &= ~FATTR4_WORD1_OWNER_GROUP;
  2541. }
  2542. if (bmap0 & FATTR4_WORD0_FILEHANDLE) {
  2543. ret += NFS4_FHSIZE + 4;
  2544. bmap0 &= ~FATTR4_WORD0_FILEHANDLE;
  2545. }
  2546. if (bmap2 & FATTR4_WORD2_SECURITY_LABEL) {
  2547. ret += NFS4_MAXLABELLEN + 12;
  2548. bmap2 &= ~FATTR4_WORD2_SECURITY_LABEL;
  2549. }
  2550. /*
  2551. * Largest of remaining attributes are 16 bytes (e.g.,
  2552. * supported_attributes)
  2553. */
  2554. ret += 16 * (hweight32(bmap0) + hweight32(bmap1) + hweight32(bmap2));
  2555. /* bitmask, length */
  2556. ret += 20;
  2557. return ret;
  2558. }
  2559. static u32 nfsd4_getfh_rsize(const struct svc_rqst *rqstp,
  2560. const struct nfsd4_op *op)
  2561. {
  2562. return (op_encode_hdr_size + 1) * sizeof(__be32) + NFS4_FHSIZE;
  2563. }
  2564. static u32 nfsd4_link_rsize(const struct svc_rqst *rqstp,
  2565. const struct nfsd4_op *op)
  2566. {
  2567. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  2568. * sizeof(__be32);
  2569. }
  2570. static u32 nfsd4_lock_rsize(const struct svc_rqst *rqstp,
  2571. const struct nfsd4_op *op)
  2572. {
  2573. return (op_encode_hdr_size + op_encode_lock_denied_maxsz)
  2574. * sizeof(__be32);
  2575. }
  2576. static u32 nfsd4_open_rsize(const struct svc_rqst *rqstp,
  2577. const struct nfsd4_op *op)
  2578. {
  2579. return (op_encode_hdr_size + op_encode_stateid_maxsz
  2580. + op_encode_change_info_maxsz + 1
  2581. + nfs4_fattr_bitmap_maxsz
  2582. + op_encode_delegation_maxsz) * sizeof(__be32);
  2583. }
  2584. static u32 nfsd4_read_rsize(const struct svc_rqst *rqstp,
  2585. const struct nfsd4_op *op)
  2586. {
  2587. u32 rlen = min(op->u.read.rd_length, nfsd4_max_payload(rqstp));
  2588. return (op_encode_hdr_size + 2 + XDR_QUADLEN(rlen)) * sizeof(__be32);
  2589. }
  2590. static u32 nfsd4_read_plus_rsize(const struct svc_rqst *rqstp,
  2591. const struct nfsd4_op *op)
  2592. {
  2593. u32 rlen = min(op->u.read.rd_length, nfsd4_max_payload(rqstp));
  2594. /*
  2595. * If we detect that the file changed during hole encoding, then we
  2596. * recover by encoding the remaining reply as data. This means we need
  2597. * to set aside enough room to encode two data segments.
  2598. */
  2599. u32 seg_len = 2 * (1 + 2 + 1);
  2600. return (op_encode_hdr_size + 2 + seg_len + XDR_QUADLEN(rlen)) * sizeof(__be32);
  2601. }
  2602. static u32 nfsd4_readdir_rsize(const struct svc_rqst *rqstp,
  2603. const struct nfsd4_op *op)
  2604. {
  2605. u32 rlen = min(op->u.readdir.rd_maxcount, nfsd4_max_payload(rqstp));
  2606. return (op_encode_hdr_size + op_encode_verifier_maxsz +
  2607. XDR_QUADLEN(rlen)) * sizeof(__be32);
  2608. }
  2609. static u32 nfsd4_readlink_rsize(const struct svc_rqst *rqstp,
  2610. const struct nfsd4_op *op)
  2611. {
  2612. return (op_encode_hdr_size + 1) * sizeof(__be32) + PAGE_SIZE;
  2613. }
  2614. static u32 nfsd4_remove_rsize(const struct svc_rqst *rqstp,
  2615. const struct nfsd4_op *op)
  2616. {
  2617. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  2618. * sizeof(__be32);
  2619. }
  2620. static u32 nfsd4_rename_rsize(const struct svc_rqst *rqstp,
  2621. const struct nfsd4_op *op)
  2622. {
  2623. return (op_encode_hdr_size + op_encode_change_info_maxsz
  2624. + op_encode_change_info_maxsz) * sizeof(__be32);
  2625. }
  2626. static u32 nfsd4_sequence_rsize(const struct svc_rqst *rqstp,
  2627. const struct nfsd4_op *op)
  2628. {
  2629. return (op_encode_hdr_size
  2630. + XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + 5) * sizeof(__be32);
  2631. }
  2632. static u32 nfsd4_test_stateid_rsize(const struct svc_rqst *rqstp,
  2633. const struct nfsd4_op *op)
  2634. {
  2635. return (op_encode_hdr_size + 1 + op->u.test_stateid.ts_num_ids)
  2636. * sizeof(__be32);
  2637. }
  2638. static u32 nfsd4_setattr_rsize(const struct svc_rqst *rqstp,
  2639. const struct nfsd4_op *op)
  2640. {
  2641. return (op_encode_hdr_size + nfs4_fattr_bitmap_maxsz) * sizeof(__be32);
  2642. }
  2643. static u32 nfsd4_secinfo_rsize(const struct svc_rqst *rqstp,
  2644. const struct nfsd4_op *op)
  2645. {
  2646. return (op_encode_hdr_size + RPC_AUTH_MAXFLAVOR *
  2647. (4 + XDR_QUADLEN(GSS_OID_MAX_LEN))) * sizeof(__be32);
  2648. }
  2649. static u32 nfsd4_setclientid_rsize(const struct svc_rqst *rqstp,
  2650. const struct nfsd4_op *op)
  2651. {
  2652. return (op_encode_hdr_size + 2 + XDR_QUADLEN(NFS4_VERIFIER_SIZE)) *
  2653. sizeof(__be32);
  2654. }
  2655. static u32 nfsd4_write_rsize(const struct svc_rqst *rqstp,
  2656. const struct nfsd4_op *op)
  2657. {
  2658. return (op_encode_hdr_size + 2 + op_encode_verifier_maxsz) * sizeof(__be32);
  2659. }
  2660. static u32 nfsd4_exchange_id_rsize(const struct svc_rqst *rqstp,
  2661. const struct nfsd4_op *op)
  2662. {
  2663. return (op_encode_hdr_size + 2 + 1 + /* eir_clientid, eir_sequenceid */\
  2664. 1 + 1 + /* eir_flags, spr_how */\
  2665. 4 + /* spo_must_enforce & _allow with bitmap */\
  2666. 2 + /*eir_server_owner.so_minor_id */\
  2667. /* eir_server_owner.so_major_id<> */\
  2668. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  2669. /* eir_server_scope<> */\
  2670. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) + 1 +\
  2671. 1 + /* eir_server_impl_id array length */\
  2672. 0 /* ignored eir_server_impl_id contents */) * sizeof(__be32);
  2673. }
  2674. static u32 nfsd4_bind_conn_to_session_rsize(const struct svc_rqst *rqstp,
  2675. const struct nfsd4_op *op)
  2676. {
  2677. return (op_encode_hdr_size + \
  2678. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* bctsr_sessid */\
  2679. 2 /* bctsr_dir, use_conn_in_rdma_mode */) * sizeof(__be32);
  2680. }
  2681. static u32 nfsd4_create_session_rsize(const struct svc_rqst *rqstp,
  2682. const struct nfsd4_op *op)
  2683. {
  2684. return (op_encode_hdr_size + \
  2685. XDR_QUADLEN(NFS4_MAX_SESSIONID_LEN) + /* sessionid */\
  2686. 2 + /* csr_sequence, csr_flags */\
  2687. op_encode_channel_attrs_maxsz + \
  2688. op_encode_channel_attrs_maxsz) * sizeof(__be32);
  2689. }
  2690. static u32 nfsd4_copy_rsize(const struct svc_rqst *rqstp,
  2691. const struct nfsd4_op *op)
  2692. {
  2693. return (op_encode_hdr_size +
  2694. 1 /* wr_callback */ +
  2695. op_encode_stateid_maxsz /* wr_callback */ +
  2696. 2 /* wr_count */ +
  2697. 1 /* wr_committed */ +
  2698. op_encode_verifier_maxsz +
  2699. 1 /* cr_consecutive */ +
  2700. 1 /* cr_synchronous */) * sizeof(__be32);
  2701. }
  2702. static u32 nfsd4_offload_status_rsize(const struct svc_rqst *rqstp,
  2703. const struct nfsd4_op *op)
  2704. {
  2705. return (op_encode_hdr_size +
  2706. 2 /* osr_count */ +
  2707. 1 /* osr_complete<1> optional 0 for now */) * sizeof(__be32);
  2708. }
  2709. static u32 nfsd4_copy_notify_rsize(const struct svc_rqst *rqstp,
  2710. const struct nfsd4_op *op)
  2711. {
  2712. return (op_encode_hdr_size +
  2713. 3 /* cnr_lease_time */ +
  2714. 1 /* We support one cnr_source_server */ +
  2715. 1 /* cnr_stateid seq */ +
  2716. op_encode_stateid_maxsz /* cnr_stateid */ +
  2717. 1 /* num cnr_source_server*/ +
  2718. 1 /* nl4_type */ +
  2719. 1 /* nl4 size */ +
  2720. XDR_QUADLEN(NFS4_OPAQUE_LIMIT) /*nl4_loc + nl4_loc_sz */)
  2721. * sizeof(__be32);
  2722. }
  2723. static u32 nfsd4_get_dir_delegation_rsize(const struct svc_rqst *rqstp,
  2724. const struct nfsd4_op *op)
  2725. {
  2726. return (op_encode_hdr_size +
  2727. 1 /* gddr_status */ +
  2728. op_encode_verifier_maxsz +
  2729. op_encode_stateid_maxsz +
  2730. 2 /* gddr_notification */ +
  2731. 2 /* gddr_child_attributes */ +
  2732. 2 /* gddr_dir_attributes */);
  2733. }
  2734. #ifdef CONFIG_NFSD_PNFS
  2735. static u32 nfsd4_getdeviceinfo_rsize(const struct svc_rqst *rqstp,
  2736. const struct nfsd4_op *op)
  2737. {
  2738. u32 rlen = min(op->u.getdeviceinfo.gd_maxcount, nfsd4_max_payload(rqstp));
  2739. return (op_encode_hdr_size +
  2740. 1 /* gd_layout_type*/ +
  2741. XDR_QUADLEN(rlen) +
  2742. 2 /* gd_notify_types */) * sizeof(__be32);
  2743. }
  2744. /*
  2745. * At this stage we don't really know what layout driver will handle the request,
  2746. * so we need to define an arbitrary upper bound here.
  2747. */
  2748. #define MAX_LAYOUT_SIZE 128
  2749. static u32 nfsd4_layoutget_rsize(const struct svc_rqst *rqstp,
  2750. const struct nfsd4_op *op)
  2751. {
  2752. return (op_encode_hdr_size +
  2753. 1 /* logr_return_on_close */ +
  2754. op_encode_stateid_maxsz +
  2755. 1 /* nr of layouts */ +
  2756. MAX_LAYOUT_SIZE) * sizeof(__be32);
  2757. }
  2758. static u32 nfsd4_layoutcommit_rsize(const struct svc_rqst *rqstp,
  2759. const struct nfsd4_op *op)
  2760. {
  2761. return (op_encode_hdr_size +
  2762. 1 /* locr_newsize */ +
  2763. 2 /* ns_size */) * sizeof(__be32);
  2764. }
  2765. static u32 nfsd4_layoutreturn_rsize(const struct svc_rqst *rqstp,
  2766. const struct nfsd4_op *op)
  2767. {
  2768. return (op_encode_hdr_size +
  2769. 1 /* lrs_stateid */ +
  2770. op_encode_stateid_maxsz) * sizeof(__be32);
  2771. }
  2772. #endif /* CONFIG_NFSD_PNFS */
  2773. static u32 nfsd4_seek_rsize(const struct svc_rqst *rqstp,
  2774. const struct nfsd4_op *op)
  2775. {
  2776. return (op_encode_hdr_size + 3) * sizeof(__be32);
  2777. }
  2778. static u32 nfsd4_getxattr_rsize(const struct svc_rqst *rqstp,
  2779. const struct nfsd4_op *op)
  2780. {
  2781. u32 rlen = min_t(u32, XATTR_SIZE_MAX, nfsd4_max_payload(rqstp));
  2782. return (op_encode_hdr_size + 1 + XDR_QUADLEN(rlen)) * sizeof(__be32);
  2783. }
  2784. static u32 nfsd4_setxattr_rsize(const struct svc_rqst *rqstp,
  2785. const struct nfsd4_op *op)
  2786. {
  2787. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  2788. * sizeof(__be32);
  2789. }
  2790. static u32 nfsd4_listxattrs_rsize(const struct svc_rqst *rqstp,
  2791. const struct nfsd4_op *op)
  2792. {
  2793. u32 rlen = min(op->u.listxattrs.lsxa_maxcount, nfsd4_max_payload(rqstp));
  2794. return (op_encode_hdr_size + 4 + XDR_QUADLEN(rlen)) * sizeof(__be32);
  2795. }
  2796. static u32 nfsd4_removexattr_rsize(const struct svc_rqst *rqstp,
  2797. const struct nfsd4_op *op)
  2798. {
  2799. return (op_encode_hdr_size + op_encode_change_info_maxsz)
  2800. * sizeof(__be32);
  2801. }
  2802. static const struct nfsd4_operation nfsd4_ops[] = {
  2803. [OP_ACCESS] = {
  2804. .op_func = nfsd4_access,
  2805. .op_name = "OP_ACCESS",
  2806. .op_rsize_bop = nfsd4_access_rsize,
  2807. },
  2808. [OP_CLOSE] = {
  2809. .op_func = nfsd4_close,
  2810. .op_flags = OP_MODIFIES_SOMETHING,
  2811. .op_name = "OP_CLOSE",
  2812. .op_rsize_bop = nfsd4_status_stateid_rsize,
  2813. .op_get_currentstateid = nfsd4_get_closestateid,
  2814. .op_set_currentstateid = nfsd4_set_closestateid,
  2815. },
  2816. [OP_COMMIT] = {
  2817. .op_func = nfsd4_commit,
  2818. .op_flags = OP_MODIFIES_SOMETHING,
  2819. .op_name = "OP_COMMIT",
  2820. .op_rsize_bop = nfsd4_commit_rsize,
  2821. },
  2822. [OP_CREATE] = {
  2823. .op_func = nfsd4_create,
  2824. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME | OP_CLEAR_STATEID,
  2825. .op_name = "OP_CREATE",
  2826. .op_rsize_bop = nfsd4_create_rsize,
  2827. },
  2828. [OP_DELEGRETURN] = {
  2829. .op_func = nfsd4_delegreturn,
  2830. .op_flags = OP_MODIFIES_SOMETHING,
  2831. .op_name = "OP_DELEGRETURN",
  2832. .op_rsize_bop = nfsd4_only_status_rsize,
  2833. .op_get_currentstateid = nfsd4_get_delegreturnstateid,
  2834. },
  2835. [OP_GETATTR] = {
  2836. .op_func = nfsd4_getattr,
  2837. .op_flags = ALLOWED_ON_ABSENT_FS,
  2838. .op_rsize_bop = nfsd4_getattr_rsize,
  2839. .op_name = "OP_GETATTR",
  2840. },
  2841. [OP_GETFH] = {
  2842. .op_func = nfsd4_getfh,
  2843. .op_name = "OP_GETFH",
  2844. .op_rsize_bop = nfsd4_getfh_rsize,
  2845. },
  2846. [OP_LINK] = {
  2847. .op_func = nfsd4_link,
  2848. .op_flags = ALLOWED_ON_ABSENT_FS | OP_MODIFIES_SOMETHING
  2849. | OP_CACHEME,
  2850. .op_name = "OP_LINK",
  2851. .op_rsize_bop = nfsd4_link_rsize,
  2852. },
  2853. [OP_LOCK] = {
  2854. .op_func = nfsd4_lock,
  2855. .op_release = nfsd4_lock_release,
  2856. .op_flags = OP_MODIFIES_SOMETHING |
  2857. OP_NONTRIVIAL_ERROR_ENCODE,
  2858. .op_name = "OP_LOCK",
  2859. .op_rsize_bop = nfsd4_lock_rsize,
  2860. .op_set_currentstateid = nfsd4_set_lockstateid,
  2861. },
  2862. [OP_LOCKT] = {
  2863. .op_func = nfsd4_lockt,
  2864. .op_release = nfsd4_lockt_release,
  2865. .op_flags = OP_NONTRIVIAL_ERROR_ENCODE,
  2866. .op_name = "OP_LOCKT",
  2867. .op_rsize_bop = nfsd4_lock_rsize,
  2868. },
  2869. [OP_LOCKU] = {
  2870. .op_func = nfsd4_locku,
  2871. .op_flags = OP_MODIFIES_SOMETHING,
  2872. .op_name = "OP_LOCKU",
  2873. .op_rsize_bop = nfsd4_status_stateid_rsize,
  2874. .op_get_currentstateid = nfsd4_get_lockustateid,
  2875. },
  2876. [OP_LOOKUP] = {
  2877. .op_func = nfsd4_lookup,
  2878. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  2879. .op_name = "OP_LOOKUP",
  2880. .op_rsize_bop = nfsd4_only_status_rsize,
  2881. },
  2882. [OP_LOOKUPP] = {
  2883. .op_func = nfsd4_lookupp,
  2884. .op_flags = OP_HANDLES_WRONGSEC | OP_CLEAR_STATEID,
  2885. .op_name = "OP_LOOKUPP",
  2886. .op_rsize_bop = nfsd4_only_status_rsize,
  2887. },
  2888. [OP_NVERIFY] = {
  2889. .op_func = nfsd4_nverify,
  2890. .op_name = "OP_NVERIFY",
  2891. .op_rsize_bop = nfsd4_only_status_rsize,
  2892. },
  2893. [OP_OPEN] = {
  2894. .op_func = nfsd4_open,
  2895. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  2896. .op_name = "OP_OPEN",
  2897. .op_rsize_bop = nfsd4_open_rsize,
  2898. .op_set_currentstateid = nfsd4_set_openstateid,
  2899. },
  2900. [OP_OPEN_CONFIRM] = {
  2901. .op_func = nfsd4_open_confirm,
  2902. .op_flags = OP_MODIFIES_SOMETHING,
  2903. .op_name = "OP_OPEN_CONFIRM",
  2904. .op_rsize_bop = nfsd4_status_stateid_rsize,
  2905. },
  2906. [OP_OPEN_DOWNGRADE] = {
  2907. .op_func = nfsd4_open_downgrade,
  2908. .op_flags = OP_MODIFIES_SOMETHING,
  2909. .op_name = "OP_OPEN_DOWNGRADE",
  2910. .op_rsize_bop = nfsd4_status_stateid_rsize,
  2911. .op_get_currentstateid = nfsd4_get_opendowngradestateid,
  2912. .op_set_currentstateid = nfsd4_set_opendowngradestateid,
  2913. },
  2914. [OP_PUTFH] = {
  2915. .op_func = nfsd4_putfh,
  2916. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  2917. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  2918. .op_name = "OP_PUTFH",
  2919. .op_rsize_bop = nfsd4_only_status_rsize,
  2920. },
  2921. [OP_PUTPUBFH] = {
  2922. .op_func = nfsd4_putrootfh,
  2923. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  2924. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  2925. .op_name = "OP_PUTPUBFH",
  2926. .op_rsize_bop = nfsd4_only_status_rsize,
  2927. },
  2928. [OP_PUTROOTFH] = {
  2929. .op_func = nfsd4_putrootfh,
  2930. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  2931. | OP_IS_PUTFH_LIKE | OP_CLEAR_STATEID,
  2932. .op_name = "OP_PUTROOTFH",
  2933. .op_rsize_bop = nfsd4_only_status_rsize,
  2934. },
  2935. [OP_READ] = {
  2936. .op_func = nfsd4_read,
  2937. .op_release = nfsd4_read_release,
  2938. .op_name = "OP_READ",
  2939. .op_rsize_bop = nfsd4_read_rsize,
  2940. .op_get_currentstateid = nfsd4_get_readstateid,
  2941. },
  2942. [OP_READDIR] = {
  2943. .op_func = nfsd4_readdir,
  2944. .op_name = "OP_READDIR",
  2945. .op_rsize_bop = nfsd4_readdir_rsize,
  2946. },
  2947. [OP_READLINK] = {
  2948. .op_func = nfsd4_readlink,
  2949. .op_name = "OP_READLINK",
  2950. .op_rsize_bop = nfsd4_readlink_rsize,
  2951. },
  2952. [OP_REMOVE] = {
  2953. .op_func = nfsd4_remove,
  2954. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2955. .op_name = "OP_REMOVE",
  2956. .op_rsize_bop = nfsd4_remove_rsize,
  2957. },
  2958. [OP_RENAME] = {
  2959. .op_func = nfsd4_rename,
  2960. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  2961. .op_name = "OP_RENAME",
  2962. .op_rsize_bop = nfsd4_rename_rsize,
  2963. },
  2964. [OP_RENEW] = {
  2965. .op_func = nfsd4_renew,
  2966. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  2967. | OP_MODIFIES_SOMETHING,
  2968. .op_name = "OP_RENEW",
  2969. .op_rsize_bop = nfsd4_only_status_rsize,
  2970. },
  2971. [OP_RESTOREFH] = {
  2972. .op_func = nfsd4_restorefh,
  2973. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  2974. | OP_IS_PUTFH_LIKE | OP_MODIFIES_SOMETHING,
  2975. .op_name = "OP_RESTOREFH",
  2976. .op_rsize_bop = nfsd4_only_status_rsize,
  2977. },
  2978. [OP_SAVEFH] = {
  2979. .op_func = nfsd4_savefh,
  2980. .op_flags = OP_HANDLES_WRONGSEC | OP_MODIFIES_SOMETHING,
  2981. .op_name = "OP_SAVEFH",
  2982. .op_rsize_bop = nfsd4_only_status_rsize,
  2983. },
  2984. [OP_SECINFO] = {
  2985. .op_func = nfsd4_secinfo,
  2986. .op_release = nfsd4_secinfo_release,
  2987. .op_flags = OP_HANDLES_WRONGSEC,
  2988. .op_name = "OP_SECINFO",
  2989. .op_rsize_bop = nfsd4_secinfo_rsize,
  2990. },
  2991. [OP_SETATTR] = {
  2992. .op_func = nfsd4_setattr,
  2993. .op_name = "OP_SETATTR",
  2994. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME
  2995. | OP_NONTRIVIAL_ERROR_ENCODE,
  2996. .op_rsize_bop = nfsd4_setattr_rsize,
  2997. .op_get_currentstateid = nfsd4_get_setattrstateid,
  2998. },
  2999. [OP_SETCLIENTID] = {
  3000. .op_func = nfsd4_setclientid,
  3001. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  3002. | OP_MODIFIES_SOMETHING | OP_CACHEME
  3003. | OP_NONTRIVIAL_ERROR_ENCODE,
  3004. .op_name = "OP_SETCLIENTID",
  3005. .op_rsize_bop = nfsd4_setclientid_rsize,
  3006. },
  3007. [OP_SETCLIENTID_CONFIRM] = {
  3008. .op_func = nfsd4_setclientid_confirm,
  3009. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  3010. | OP_MODIFIES_SOMETHING | OP_CACHEME,
  3011. .op_name = "OP_SETCLIENTID_CONFIRM",
  3012. .op_rsize_bop = nfsd4_only_status_rsize,
  3013. },
  3014. [OP_VERIFY] = {
  3015. .op_func = nfsd4_verify,
  3016. .op_name = "OP_VERIFY",
  3017. .op_rsize_bop = nfsd4_only_status_rsize,
  3018. },
  3019. [OP_WRITE] = {
  3020. .op_func = nfsd4_write,
  3021. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  3022. .op_name = "OP_WRITE",
  3023. .op_rsize_bop = nfsd4_write_rsize,
  3024. .op_get_currentstateid = nfsd4_get_writestateid,
  3025. },
  3026. [OP_RELEASE_LOCKOWNER] = {
  3027. .op_func = nfsd4_release_lockowner,
  3028. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_ON_ABSENT_FS
  3029. | OP_MODIFIES_SOMETHING,
  3030. .op_name = "OP_RELEASE_LOCKOWNER",
  3031. .op_rsize_bop = nfsd4_only_status_rsize,
  3032. },
  3033. /* NFSv4.1 operations */
  3034. [OP_EXCHANGE_ID] = {
  3035. .op_func = nfsd4_exchange_id,
  3036. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  3037. | OP_MODIFIES_SOMETHING,
  3038. .op_name = "OP_EXCHANGE_ID",
  3039. .op_rsize_bop = nfsd4_exchange_id_rsize,
  3040. },
  3041. [OP_BACKCHANNEL_CTL] = {
  3042. .op_func = nfsd4_backchannel_ctl,
  3043. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  3044. .op_name = "OP_BACKCHANNEL_CTL",
  3045. .op_rsize_bop = nfsd4_only_status_rsize,
  3046. },
  3047. [OP_BIND_CONN_TO_SESSION] = {
  3048. .op_func = nfsd4_bind_conn_to_session,
  3049. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  3050. | OP_MODIFIES_SOMETHING,
  3051. .op_name = "OP_BIND_CONN_TO_SESSION",
  3052. .op_rsize_bop = nfsd4_bind_conn_to_session_rsize,
  3053. },
  3054. [OP_CREATE_SESSION] = {
  3055. .op_func = nfsd4_create_session,
  3056. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  3057. | OP_MODIFIES_SOMETHING,
  3058. .op_name = "OP_CREATE_SESSION",
  3059. .op_rsize_bop = nfsd4_create_session_rsize,
  3060. },
  3061. [OP_DESTROY_SESSION] = {
  3062. .op_func = nfsd4_destroy_session,
  3063. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  3064. | OP_MODIFIES_SOMETHING,
  3065. .op_name = "OP_DESTROY_SESSION",
  3066. .op_rsize_bop = nfsd4_only_status_rsize,
  3067. },
  3068. [OP_SEQUENCE] = {
  3069. .op_func = nfsd4_sequence,
  3070. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP,
  3071. .op_name = "OP_SEQUENCE",
  3072. .op_rsize_bop = nfsd4_sequence_rsize,
  3073. },
  3074. [OP_DESTROY_CLIENTID] = {
  3075. .op_func = nfsd4_destroy_clientid,
  3076. .op_flags = ALLOWED_WITHOUT_FH | ALLOWED_AS_FIRST_OP
  3077. | OP_MODIFIES_SOMETHING,
  3078. .op_name = "OP_DESTROY_CLIENTID",
  3079. .op_rsize_bop = nfsd4_only_status_rsize,
  3080. },
  3081. [OP_RECLAIM_COMPLETE] = {
  3082. .op_func = nfsd4_reclaim_complete,
  3083. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  3084. .op_name = "OP_RECLAIM_COMPLETE",
  3085. .op_rsize_bop = nfsd4_only_status_rsize,
  3086. },
  3087. [OP_SECINFO_NO_NAME] = {
  3088. .op_func = nfsd4_secinfo_no_name,
  3089. .op_release = nfsd4_secinfo_no_name_release,
  3090. .op_flags = OP_HANDLES_WRONGSEC,
  3091. .op_name = "OP_SECINFO_NO_NAME",
  3092. .op_rsize_bop = nfsd4_secinfo_rsize,
  3093. },
  3094. [OP_TEST_STATEID] = {
  3095. .op_func = nfsd4_test_stateid,
  3096. .op_flags = ALLOWED_WITHOUT_FH,
  3097. .op_name = "OP_TEST_STATEID",
  3098. .op_rsize_bop = nfsd4_test_stateid_rsize,
  3099. },
  3100. [OP_FREE_STATEID] = {
  3101. .op_func = nfsd4_free_stateid,
  3102. .op_flags = ALLOWED_WITHOUT_FH | OP_MODIFIES_SOMETHING,
  3103. .op_name = "OP_FREE_STATEID",
  3104. .op_get_currentstateid = nfsd4_get_freestateid,
  3105. .op_rsize_bop = nfsd4_only_status_rsize,
  3106. },
  3107. [OP_GET_DIR_DELEGATION] = {
  3108. .op_func = nfsd4_get_dir_delegation,
  3109. .op_flags = OP_MODIFIES_SOMETHING,
  3110. .op_name = "OP_GET_DIR_DELEGATION",
  3111. .op_rsize_bop = nfsd4_get_dir_delegation_rsize,
  3112. },
  3113. #ifdef CONFIG_NFSD_PNFS
  3114. [OP_GETDEVICEINFO] = {
  3115. .op_func = nfsd4_getdeviceinfo,
  3116. .op_release = nfsd4_getdeviceinfo_release,
  3117. .op_flags = ALLOWED_WITHOUT_FH,
  3118. .op_name = "OP_GETDEVICEINFO",
  3119. .op_rsize_bop = nfsd4_getdeviceinfo_rsize,
  3120. },
  3121. [OP_LAYOUTGET] = {
  3122. .op_func = nfsd4_layoutget,
  3123. .op_release = nfsd4_layoutget_release,
  3124. .op_flags = OP_MODIFIES_SOMETHING,
  3125. .op_name = "OP_LAYOUTGET",
  3126. .op_rsize_bop = nfsd4_layoutget_rsize,
  3127. },
  3128. [OP_LAYOUTCOMMIT] = {
  3129. .op_func = nfsd4_layoutcommit,
  3130. .op_flags = OP_MODIFIES_SOMETHING,
  3131. .op_name = "OP_LAYOUTCOMMIT",
  3132. .op_rsize_bop = nfsd4_layoutcommit_rsize,
  3133. },
  3134. [OP_LAYOUTRETURN] = {
  3135. .op_func = nfsd4_layoutreturn,
  3136. .op_flags = OP_MODIFIES_SOMETHING,
  3137. .op_name = "OP_LAYOUTRETURN",
  3138. .op_rsize_bop = nfsd4_layoutreturn_rsize,
  3139. },
  3140. #endif /* CONFIG_NFSD_PNFS */
  3141. /* NFSv4.2 operations */
  3142. [OP_ALLOCATE] = {
  3143. .op_func = nfsd4_allocate,
  3144. .op_flags = OP_MODIFIES_SOMETHING,
  3145. .op_name = "OP_ALLOCATE",
  3146. .op_rsize_bop = nfsd4_only_status_rsize,
  3147. },
  3148. [OP_DEALLOCATE] = {
  3149. .op_func = nfsd4_deallocate,
  3150. .op_flags = OP_MODIFIES_SOMETHING,
  3151. .op_name = "OP_DEALLOCATE",
  3152. .op_rsize_bop = nfsd4_only_status_rsize,
  3153. },
  3154. [OP_CLONE] = {
  3155. .op_func = nfsd4_clone,
  3156. .op_flags = OP_MODIFIES_SOMETHING,
  3157. .op_name = "OP_CLONE",
  3158. .op_rsize_bop = nfsd4_only_status_rsize,
  3159. },
  3160. [OP_COPY] = {
  3161. .op_func = nfsd4_copy,
  3162. .op_flags = OP_MODIFIES_SOMETHING,
  3163. .op_name = "OP_COPY",
  3164. .op_rsize_bop = nfsd4_copy_rsize,
  3165. },
  3166. [OP_READ_PLUS] = {
  3167. .op_func = nfsd4_read,
  3168. .op_release = nfsd4_read_release,
  3169. .op_name = "OP_READ_PLUS",
  3170. .op_rsize_bop = nfsd4_read_plus_rsize,
  3171. .op_get_currentstateid = nfsd4_get_readstateid,
  3172. },
  3173. [OP_SEEK] = {
  3174. .op_func = nfsd4_seek,
  3175. .op_name = "OP_SEEK",
  3176. .op_rsize_bop = nfsd4_seek_rsize,
  3177. },
  3178. [OP_OFFLOAD_STATUS] = {
  3179. .op_func = nfsd4_offload_status,
  3180. .op_name = "OP_OFFLOAD_STATUS",
  3181. .op_rsize_bop = nfsd4_offload_status_rsize,
  3182. },
  3183. [OP_OFFLOAD_CANCEL] = {
  3184. .op_func = nfsd4_offload_cancel,
  3185. .op_flags = OP_MODIFIES_SOMETHING,
  3186. .op_name = "OP_OFFLOAD_CANCEL",
  3187. .op_rsize_bop = nfsd4_only_status_rsize,
  3188. },
  3189. [OP_COPY_NOTIFY] = {
  3190. .op_func = nfsd4_copy_notify,
  3191. .op_flags = OP_MODIFIES_SOMETHING,
  3192. .op_name = "OP_COPY_NOTIFY",
  3193. .op_rsize_bop = nfsd4_copy_notify_rsize,
  3194. },
  3195. [OP_GETXATTR] = {
  3196. .op_func = nfsd4_getxattr,
  3197. .op_name = "OP_GETXATTR",
  3198. .op_rsize_bop = nfsd4_getxattr_rsize,
  3199. },
  3200. [OP_SETXATTR] = {
  3201. .op_func = nfsd4_setxattr,
  3202. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  3203. .op_name = "OP_SETXATTR",
  3204. .op_rsize_bop = nfsd4_setxattr_rsize,
  3205. },
  3206. [OP_LISTXATTRS] = {
  3207. .op_func = nfsd4_listxattrs,
  3208. .op_name = "OP_LISTXATTRS",
  3209. .op_rsize_bop = nfsd4_listxattrs_rsize,
  3210. },
  3211. [OP_REMOVEXATTR] = {
  3212. .op_func = nfsd4_removexattr,
  3213. .op_flags = OP_MODIFIES_SOMETHING | OP_CACHEME,
  3214. .op_name = "OP_REMOVEXATTR",
  3215. .op_rsize_bop = nfsd4_removexattr_rsize,
  3216. },
  3217. };
  3218. /**
  3219. * nfsd4_spo_must_allow - Determine if the compound op contains an
  3220. * operation that is allowed to be sent with machine credentials
  3221. *
  3222. * @rqstp: a pointer to the struct svc_rqst
  3223. *
  3224. * Checks to see if the compound contains a spo_must_allow op
  3225. * and confirms that it was sent with the proper machine creds.
  3226. */
  3227. bool nfsd4_spo_must_allow(struct svc_rqst *rqstp)
  3228. {
  3229. struct nfsd4_compoundres *resp = rqstp->rq_resp;
  3230. struct nfsd4_compoundargs *argp = rqstp->rq_argp;
  3231. struct nfsd4_op *this;
  3232. struct nfsd4_compound_state *cstate = &resp->cstate;
  3233. struct nfs4_op_map *allow = &cstate->clp->cl_spo_must_allow;
  3234. u32 opiter;
  3235. if (rqstp->rq_procinfo != &nfsd_version4.vs_proc[NFSPROC4_COMPOUND] ||
  3236. cstate->minorversion == 0)
  3237. return false;
  3238. if (cstate->spo_must_allowed)
  3239. return true;
  3240. opiter = resp->opcnt;
  3241. while (opiter < argp->opcnt) {
  3242. this = &argp->ops[opiter++];
  3243. if (test_bit(this->opnum, allow->u.longs) &&
  3244. cstate->clp->cl_mach_cred &&
  3245. nfsd4_mach_creds_match(cstate->clp, rqstp)) {
  3246. cstate->spo_must_allowed = true;
  3247. return true;
  3248. }
  3249. }
  3250. cstate->spo_must_allowed = false;
  3251. return false;
  3252. }
  3253. int nfsd4_max_reply(struct svc_rqst *rqstp, struct nfsd4_op *op)
  3254. {
  3255. if (op->opnum == OP_ILLEGAL || op->status == nfserr_notsupp)
  3256. return op_encode_hdr_size * sizeof(__be32);
  3257. BUG_ON(OPDESC(op)->op_rsize_bop == NULL);
  3258. return OPDESC(op)->op_rsize_bop(rqstp, op);
  3259. }
  3260. void warn_on_nonidempotent_op(struct nfsd4_op *op)
  3261. {
  3262. if (OPDESC(op)->op_flags & OP_MODIFIES_SOMETHING) {
  3263. pr_err("unable to encode reply to nonidempotent op %u (%s)\n",
  3264. op->opnum, nfsd4_op_name(op->opnum));
  3265. WARN_ON_ONCE(1);
  3266. }
  3267. }
  3268. static const char *nfsd4_op_name(unsigned opnum)
  3269. {
  3270. if (opnum < ARRAY_SIZE(nfsd4_ops))
  3271. return nfsd4_ops[opnum].op_name;
  3272. return "unknown_operation";
  3273. }
  3274. static const struct svc_procedure nfsd_procedures4[2] = {
  3275. [NFSPROC4_NULL] = {
  3276. .pc_func = nfsd4_proc_null,
  3277. .pc_decode = nfssvc_decode_voidarg,
  3278. .pc_encode = nfssvc_encode_voidres,
  3279. .pc_argsize = sizeof(struct nfsd_voidargs),
  3280. .pc_argzero = sizeof(struct nfsd_voidargs),
  3281. .pc_ressize = sizeof(struct nfsd_voidres),
  3282. .pc_cachetype = RC_NOCACHE,
  3283. .pc_xdrressize = 1,
  3284. .pc_name = "NULL",
  3285. },
  3286. [NFSPROC4_COMPOUND] = {
  3287. .pc_func = nfsd4_proc_compound,
  3288. .pc_decode = nfs4svc_decode_compoundargs,
  3289. .pc_encode = nfs4svc_encode_compoundres,
  3290. .pc_argsize = sizeof(struct nfsd4_compoundargs),
  3291. .pc_argzero = offsetof(struct nfsd4_compoundargs, iops),
  3292. .pc_ressize = sizeof(struct nfsd4_compoundres),
  3293. .pc_release = nfsd4_release_compoundargs,
  3294. .pc_cachetype = RC_NOCACHE,
  3295. .pc_xdrressize = NFSD_BUFSIZE/4,
  3296. .pc_name = "COMPOUND",
  3297. },
  3298. };
  3299. static DEFINE_PER_CPU_ALIGNED(unsigned long,
  3300. nfsd_count4[ARRAY_SIZE(nfsd_procedures4)]);
  3301. const struct svc_version nfsd_version4 = {
  3302. .vs_vers = 4,
  3303. .vs_nproc = ARRAY_SIZE(nfsd_procedures4),
  3304. .vs_proc = nfsd_procedures4,
  3305. .vs_count = nfsd_count4,
  3306. .vs_dispatch = nfsd_dispatch,
  3307. .vs_xdrsize = NFS4_SVC_XDRSIZE,
  3308. .vs_rpcb_optnl = true,
  3309. .vs_need_cong_ctrl = true,
  3310. };