xfs_super.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #include "xfs.h"
  7. #include "xfs_shared.h"
  8. #include "xfs_format.h"
  9. #include "xfs_log_format.h"
  10. #include "xfs_trans_resv.h"
  11. #include "xfs_sb.h"
  12. #include "xfs_mount.h"
  13. #include "xfs_inode.h"
  14. #include "xfs_btree.h"
  15. #include "xfs_bmap.h"
  16. #include "xfs_alloc.h"
  17. #include "xfs_fsops.h"
  18. #include "xfs_trans.h"
  19. #include "xfs_buf_item.h"
  20. #include "xfs_log.h"
  21. #include "xfs_log_priv.h"
  22. #include "xfs_dir2.h"
  23. #include "xfs_extfree_item.h"
  24. #include "xfs_mru_cache.h"
  25. #include "xfs_inode_item.h"
  26. #include "xfs_icache.h"
  27. #include "xfs_trace.h"
  28. #include "xfs_icreate_item.h"
  29. #include "xfs_filestream.h"
  30. #include "xfs_quota.h"
  31. #include "xfs_sysfs.h"
  32. #include "xfs_ondisk.h"
  33. #include "xfs_rmap_item.h"
  34. #include "xfs_refcount_item.h"
  35. #include "xfs_bmap_item.h"
  36. #include "xfs_reflink.h"
  37. #include "xfs_pwork.h"
  38. #include "xfs_ag.h"
  39. #include "xfs_defer.h"
  40. #include "xfs_attr_item.h"
  41. #include "xfs_xattr.h"
  42. #include "xfs_iunlink_item.h"
  43. #include <linux/magic.h>
  44. #include <linux/fs_context.h>
  45. #include <linux/fs_parser.h>
  46. static const struct super_operations xfs_super_operations;
  47. static struct kset *xfs_kset; /* top-level xfs sysfs dir */
  48. #ifdef DEBUG
  49. static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
  50. #endif
  51. #ifdef CONFIG_HOTPLUG_CPU
  52. static LIST_HEAD(xfs_mount_list);
  53. static DEFINE_SPINLOCK(xfs_mount_list_lock);
  54. static inline void xfs_mount_list_add(struct xfs_mount *mp)
  55. {
  56. spin_lock(&xfs_mount_list_lock);
  57. list_add(&mp->m_mount_list, &xfs_mount_list);
  58. spin_unlock(&xfs_mount_list_lock);
  59. }
  60. static inline void xfs_mount_list_del(struct xfs_mount *mp)
  61. {
  62. spin_lock(&xfs_mount_list_lock);
  63. list_del(&mp->m_mount_list);
  64. spin_unlock(&xfs_mount_list_lock);
  65. }
  66. #else /* !CONFIG_HOTPLUG_CPU */
  67. static inline void xfs_mount_list_add(struct xfs_mount *mp) {}
  68. static inline void xfs_mount_list_del(struct xfs_mount *mp) {}
  69. #endif
  70. enum xfs_dax_mode {
  71. XFS_DAX_INODE = 0,
  72. XFS_DAX_ALWAYS = 1,
  73. XFS_DAX_NEVER = 2,
  74. };
  75. static void
  76. xfs_mount_set_dax_mode(
  77. struct xfs_mount *mp,
  78. enum xfs_dax_mode mode)
  79. {
  80. switch (mode) {
  81. case XFS_DAX_INODE:
  82. mp->m_features &= ~(XFS_FEAT_DAX_ALWAYS | XFS_FEAT_DAX_NEVER);
  83. break;
  84. case XFS_DAX_ALWAYS:
  85. mp->m_features |= XFS_FEAT_DAX_ALWAYS;
  86. mp->m_features &= ~XFS_FEAT_DAX_NEVER;
  87. break;
  88. case XFS_DAX_NEVER:
  89. mp->m_features |= XFS_FEAT_DAX_NEVER;
  90. mp->m_features &= ~XFS_FEAT_DAX_ALWAYS;
  91. break;
  92. }
  93. }
  94. static const struct constant_table dax_param_enums[] = {
  95. {"inode", XFS_DAX_INODE },
  96. {"always", XFS_DAX_ALWAYS },
  97. {"never", XFS_DAX_NEVER },
  98. {}
  99. };
  100. /*
  101. * Table driven mount option parser.
  102. */
  103. enum {
  104. Opt_logbufs, Opt_logbsize, Opt_logdev, Opt_rtdev,
  105. Opt_wsync, Opt_noalign, Opt_swalloc, Opt_sunit, Opt_swidth, Opt_nouuid,
  106. Opt_grpid, Opt_nogrpid, Opt_bsdgroups, Opt_sysvgroups,
  107. Opt_allocsize, Opt_norecovery, Opt_inode64, Opt_inode32, Opt_ikeep,
  108. Opt_noikeep, Opt_largeio, Opt_nolargeio, Opt_attr2, Opt_noattr2,
  109. Opt_filestreams, Opt_quota, Opt_noquota, Opt_usrquota, Opt_grpquota,
  110. Opt_prjquota, Opt_uquota, Opt_gquota, Opt_pquota,
  111. Opt_uqnoenforce, Opt_gqnoenforce, Opt_pqnoenforce, Opt_qnoenforce,
  112. Opt_discard, Opt_nodiscard, Opt_dax, Opt_dax_enum,
  113. };
  114. static const struct fs_parameter_spec xfs_fs_parameters[] = {
  115. fsparam_u32("logbufs", Opt_logbufs),
  116. fsparam_string("logbsize", Opt_logbsize),
  117. fsparam_string("logdev", Opt_logdev),
  118. fsparam_string("rtdev", Opt_rtdev),
  119. fsparam_flag("wsync", Opt_wsync),
  120. fsparam_flag("noalign", Opt_noalign),
  121. fsparam_flag("swalloc", Opt_swalloc),
  122. fsparam_u32("sunit", Opt_sunit),
  123. fsparam_u32("swidth", Opt_swidth),
  124. fsparam_flag("nouuid", Opt_nouuid),
  125. fsparam_flag("grpid", Opt_grpid),
  126. fsparam_flag("nogrpid", Opt_nogrpid),
  127. fsparam_flag("bsdgroups", Opt_bsdgroups),
  128. fsparam_flag("sysvgroups", Opt_sysvgroups),
  129. fsparam_string("allocsize", Opt_allocsize),
  130. fsparam_flag("norecovery", Opt_norecovery),
  131. fsparam_flag("inode64", Opt_inode64),
  132. fsparam_flag("inode32", Opt_inode32),
  133. fsparam_flag("ikeep", Opt_ikeep),
  134. fsparam_flag("noikeep", Opt_noikeep),
  135. fsparam_flag("largeio", Opt_largeio),
  136. fsparam_flag("nolargeio", Opt_nolargeio),
  137. fsparam_flag("attr2", Opt_attr2),
  138. fsparam_flag("noattr2", Opt_noattr2),
  139. fsparam_flag("filestreams", Opt_filestreams),
  140. fsparam_flag("quota", Opt_quota),
  141. fsparam_flag("noquota", Opt_noquota),
  142. fsparam_flag("usrquota", Opt_usrquota),
  143. fsparam_flag("grpquota", Opt_grpquota),
  144. fsparam_flag("prjquota", Opt_prjquota),
  145. fsparam_flag("uquota", Opt_uquota),
  146. fsparam_flag("gquota", Opt_gquota),
  147. fsparam_flag("pquota", Opt_pquota),
  148. fsparam_flag("uqnoenforce", Opt_uqnoenforce),
  149. fsparam_flag("gqnoenforce", Opt_gqnoenforce),
  150. fsparam_flag("pqnoenforce", Opt_pqnoenforce),
  151. fsparam_flag("qnoenforce", Opt_qnoenforce),
  152. fsparam_flag("discard", Opt_discard),
  153. fsparam_flag("nodiscard", Opt_nodiscard),
  154. fsparam_flag("dax", Opt_dax),
  155. fsparam_enum("dax", Opt_dax_enum, dax_param_enums),
  156. {}
  157. };
  158. struct proc_xfs_info {
  159. uint64_t flag;
  160. char *str;
  161. };
  162. static int
  163. xfs_fs_show_options(
  164. struct seq_file *m,
  165. struct dentry *root)
  166. {
  167. static struct proc_xfs_info xfs_info_set[] = {
  168. /* the few simple ones we can get from the mount struct */
  169. { XFS_FEAT_IKEEP, ",ikeep" },
  170. { XFS_FEAT_WSYNC, ",wsync" },
  171. { XFS_FEAT_NOALIGN, ",noalign" },
  172. { XFS_FEAT_SWALLOC, ",swalloc" },
  173. { XFS_FEAT_NOUUID, ",nouuid" },
  174. { XFS_FEAT_NORECOVERY, ",norecovery" },
  175. { XFS_FEAT_ATTR2, ",attr2" },
  176. { XFS_FEAT_FILESTREAMS, ",filestreams" },
  177. { XFS_FEAT_GRPID, ",grpid" },
  178. { XFS_FEAT_DISCARD, ",discard" },
  179. { XFS_FEAT_LARGE_IOSIZE, ",largeio" },
  180. { XFS_FEAT_DAX_ALWAYS, ",dax=always" },
  181. { XFS_FEAT_DAX_NEVER, ",dax=never" },
  182. { 0, NULL }
  183. };
  184. struct xfs_mount *mp = XFS_M(root->d_sb);
  185. struct proc_xfs_info *xfs_infop;
  186. for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
  187. if (mp->m_features & xfs_infop->flag)
  188. seq_puts(m, xfs_infop->str);
  189. }
  190. seq_printf(m, ",inode%d", xfs_has_small_inums(mp) ? 32 : 64);
  191. if (xfs_has_allocsize(mp))
  192. seq_printf(m, ",allocsize=%dk",
  193. (1 << mp->m_allocsize_log) >> 10);
  194. if (mp->m_logbufs > 0)
  195. seq_printf(m, ",logbufs=%d", mp->m_logbufs);
  196. if (mp->m_logbsize > 0)
  197. seq_printf(m, ",logbsize=%dk", mp->m_logbsize >> 10);
  198. if (mp->m_logname)
  199. seq_show_option(m, "logdev", mp->m_logname);
  200. if (mp->m_rtname)
  201. seq_show_option(m, "rtdev", mp->m_rtname);
  202. if (mp->m_dalign > 0)
  203. seq_printf(m, ",sunit=%d",
  204. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  205. if (mp->m_swidth > 0)
  206. seq_printf(m, ",swidth=%d",
  207. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  208. if (mp->m_qflags & XFS_UQUOTA_ENFD)
  209. seq_puts(m, ",usrquota");
  210. else if (mp->m_qflags & XFS_UQUOTA_ACCT)
  211. seq_puts(m, ",uqnoenforce");
  212. if (mp->m_qflags & XFS_PQUOTA_ENFD)
  213. seq_puts(m, ",prjquota");
  214. else if (mp->m_qflags & XFS_PQUOTA_ACCT)
  215. seq_puts(m, ",pqnoenforce");
  216. if (mp->m_qflags & XFS_GQUOTA_ENFD)
  217. seq_puts(m, ",grpquota");
  218. else if (mp->m_qflags & XFS_GQUOTA_ACCT)
  219. seq_puts(m, ",gqnoenforce");
  220. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  221. seq_puts(m, ",noquota");
  222. return 0;
  223. }
  224. /*
  225. * Set parameters for inode allocation heuristics, taking into account
  226. * filesystem size and inode32/inode64 mount options; i.e. specifically
  227. * whether or not XFS_FEAT_SMALL_INUMS is set.
  228. *
  229. * Inode allocation patterns are altered only if inode32 is requested
  230. * (XFS_FEAT_SMALL_INUMS), and the filesystem is sufficiently large.
  231. * If altered, XFS_OPSTATE_INODE32 is set as well.
  232. *
  233. * An agcount independent of that in the mount structure is provided
  234. * because in the growfs case, mp->m_sb.sb_agcount is not yet updated
  235. * to the potentially higher ag count.
  236. *
  237. * Returns the maximum AG index which may contain inodes.
  238. */
  239. xfs_agnumber_t
  240. xfs_set_inode_alloc(
  241. struct xfs_mount *mp,
  242. xfs_agnumber_t agcount)
  243. {
  244. xfs_agnumber_t index;
  245. xfs_agnumber_t maxagi = 0;
  246. xfs_sb_t *sbp = &mp->m_sb;
  247. xfs_agnumber_t max_metadata;
  248. xfs_agino_t agino;
  249. xfs_ino_t ino;
  250. /*
  251. * Calculate how much should be reserved for inodes to meet
  252. * the max inode percentage. Used only for inode32.
  253. */
  254. if (M_IGEO(mp)->maxicount) {
  255. uint64_t icount;
  256. icount = sbp->sb_dblocks * sbp->sb_imax_pct;
  257. do_div(icount, 100);
  258. icount += sbp->sb_agblocks - 1;
  259. do_div(icount, sbp->sb_agblocks);
  260. max_metadata = icount;
  261. } else {
  262. max_metadata = agcount;
  263. }
  264. /* Get the last possible inode in the filesystem */
  265. agino = XFS_AGB_TO_AGINO(mp, sbp->sb_agblocks - 1);
  266. ino = XFS_AGINO_TO_INO(mp, agcount - 1, agino);
  267. /*
  268. * If user asked for no more than 32-bit inodes, and the fs is
  269. * sufficiently large, set XFS_OPSTATE_INODE32 if we must alter
  270. * the allocator to accommodate the request.
  271. */
  272. if (xfs_has_small_inums(mp) && ino > XFS_MAXINUMBER_32)
  273. set_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
  274. else
  275. clear_bit(XFS_OPSTATE_INODE32, &mp->m_opstate);
  276. for (index = 0; index < agcount; index++) {
  277. struct xfs_perag *pag;
  278. ino = XFS_AGINO_TO_INO(mp, index, agino);
  279. pag = xfs_perag_get(mp, index);
  280. if (xfs_is_inode32(mp)) {
  281. if (ino > XFS_MAXINUMBER_32) {
  282. pag->pagi_inodeok = 0;
  283. pag->pagf_metadata = 0;
  284. } else {
  285. pag->pagi_inodeok = 1;
  286. maxagi++;
  287. if (index < max_metadata)
  288. pag->pagf_metadata = 1;
  289. else
  290. pag->pagf_metadata = 0;
  291. }
  292. } else {
  293. pag->pagi_inodeok = 1;
  294. pag->pagf_metadata = 0;
  295. }
  296. xfs_perag_put(pag);
  297. }
  298. return xfs_is_inode32(mp) ? maxagi : agcount;
  299. }
  300. static int
  301. xfs_setup_dax_always(
  302. struct xfs_mount *mp)
  303. {
  304. if (!mp->m_ddev_targp->bt_daxdev &&
  305. (!mp->m_rtdev_targp || !mp->m_rtdev_targp->bt_daxdev)) {
  306. xfs_alert(mp,
  307. "DAX unsupported by block device. Turning off DAX.");
  308. goto disable_dax;
  309. }
  310. if (mp->m_super->s_blocksize != PAGE_SIZE) {
  311. xfs_alert(mp,
  312. "DAX not supported for blocksize. Turning off DAX.");
  313. goto disable_dax;
  314. }
  315. if (xfs_has_reflink(mp) &&
  316. bdev_is_partition(mp->m_ddev_targp->bt_bdev)) {
  317. xfs_alert(mp,
  318. "DAX and reflink cannot work with multi-partitions!");
  319. return -EINVAL;
  320. }
  321. xfs_warn(mp, "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
  322. return 0;
  323. disable_dax:
  324. xfs_mount_set_dax_mode(mp, XFS_DAX_NEVER);
  325. return 0;
  326. }
  327. STATIC int
  328. xfs_blkdev_get(
  329. xfs_mount_t *mp,
  330. const char *name,
  331. struct block_device **bdevp)
  332. {
  333. int error = 0;
  334. *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
  335. mp);
  336. if (IS_ERR(*bdevp)) {
  337. error = PTR_ERR(*bdevp);
  338. xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
  339. }
  340. return error;
  341. }
  342. STATIC void
  343. xfs_blkdev_put(
  344. struct block_device *bdev)
  345. {
  346. if (bdev)
  347. blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
  348. }
  349. STATIC void
  350. xfs_close_devices(
  351. struct xfs_mount *mp)
  352. {
  353. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  354. struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
  355. xfs_free_buftarg(mp->m_logdev_targp);
  356. xfs_blkdev_put(logdev);
  357. }
  358. if (mp->m_rtdev_targp) {
  359. struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
  360. xfs_free_buftarg(mp->m_rtdev_targp);
  361. xfs_blkdev_put(rtdev);
  362. }
  363. xfs_free_buftarg(mp->m_ddev_targp);
  364. }
  365. /*
  366. * The file system configurations are:
  367. * (1) device (partition) with data and internal log
  368. * (2) logical volume with data and log subvolumes.
  369. * (3) logical volume with data, log, and realtime subvolumes.
  370. *
  371. * We only have to handle opening the log and realtime volumes here if
  372. * they are present. The data subvolume has already been opened by
  373. * get_sb_bdev() and is stored in sb->s_bdev.
  374. */
  375. STATIC int
  376. xfs_open_devices(
  377. struct xfs_mount *mp)
  378. {
  379. struct block_device *ddev = mp->m_super->s_bdev;
  380. struct block_device *logdev = NULL, *rtdev = NULL;
  381. int error;
  382. /*
  383. * Open real time and log devices - order is important.
  384. */
  385. if (mp->m_logname) {
  386. error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
  387. if (error)
  388. return error;
  389. }
  390. if (mp->m_rtname) {
  391. error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
  392. if (error)
  393. goto out_close_logdev;
  394. if (rtdev == ddev || rtdev == logdev) {
  395. xfs_warn(mp,
  396. "Cannot mount filesystem with identical rtdev and ddev/logdev.");
  397. error = -EINVAL;
  398. goto out_close_rtdev;
  399. }
  400. }
  401. /*
  402. * Setup xfs_mount buffer target pointers
  403. */
  404. error = -ENOMEM;
  405. mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev);
  406. if (!mp->m_ddev_targp)
  407. goto out_close_rtdev;
  408. if (rtdev) {
  409. mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev);
  410. if (!mp->m_rtdev_targp)
  411. goto out_free_ddev_targ;
  412. }
  413. if (logdev && logdev != ddev) {
  414. mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev);
  415. if (!mp->m_logdev_targp)
  416. goto out_free_rtdev_targ;
  417. } else {
  418. mp->m_logdev_targp = mp->m_ddev_targp;
  419. }
  420. return 0;
  421. out_free_rtdev_targ:
  422. if (mp->m_rtdev_targp)
  423. xfs_free_buftarg(mp->m_rtdev_targp);
  424. out_free_ddev_targ:
  425. xfs_free_buftarg(mp->m_ddev_targp);
  426. out_close_rtdev:
  427. xfs_blkdev_put(rtdev);
  428. out_close_logdev:
  429. if (logdev && logdev != ddev)
  430. xfs_blkdev_put(logdev);
  431. return error;
  432. }
  433. /*
  434. * Setup xfs_mount buffer target pointers based on superblock
  435. */
  436. STATIC int
  437. xfs_setup_devices(
  438. struct xfs_mount *mp)
  439. {
  440. int error;
  441. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
  442. if (error)
  443. return error;
  444. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  445. unsigned int log_sector_size = BBSIZE;
  446. if (xfs_has_sector(mp))
  447. log_sector_size = mp->m_sb.sb_logsectsize;
  448. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  449. log_sector_size);
  450. if (error)
  451. return error;
  452. }
  453. if (mp->m_rtdev_targp) {
  454. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  455. mp->m_sb.sb_sectsize);
  456. if (error)
  457. return error;
  458. }
  459. return 0;
  460. }
  461. STATIC int
  462. xfs_init_mount_workqueues(
  463. struct xfs_mount *mp)
  464. {
  465. mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
  466. XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
  467. 1, mp->m_super->s_id);
  468. if (!mp->m_buf_workqueue)
  469. goto out;
  470. mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
  471. XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
  472. 0, mp->m_super->s_id);
  473. if (!mp->m_unwritten_workqueue)
  474. goto out_destroy_buf;
  475. mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
  476. XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
  477. 0, mp->m_super->s_id);
  478. if (!mp->m_reclaim_workqueue)
  479. goto out_destroy_unwritten;
  480. mp->m_blockgc_wq = alloc_workqueue("xfs-blockgc/%s",
  481. XFS_WQFLAGS(WQ_UNBOUND | WQ_FREEZABLE | WQ_MEM_RECLAIM),
  482. 0, mp->m_super->s_id);
  483. if (!mp->m_blockgc_wq)
  484. goto out_destroy_reclaim;
  485. mp->m_inodegc_wq = alloc_workqueue("xfs-inodegc/%s",
  486. XFS_WQFLAGS(WQ_FREEZABLE | WQ_MEM_RECLAIM),
  487. 1, mp->m_super->s_id);
  488. if (!mp->m_inodegc_wq)
  489. goto out_destroy_blockgc;
  490. mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s",
  491. XFS_WQFLAGS(WQ_FREEZABLE), 0, mp->m_super->s_id);
  492. if (!mp->m_sync_workqueue)
  493. goto out_destroy_inodegc;
  494. return 0;
  495. out_destroy_inodegc:
  496. destroy_workqueue(mp->m_inodegc_wq);
  497. out_destroy_blockgc:
  498. destroy_workqueue(mp->m_blockgc_wq);
  499. out_destroy_reclaim:
  500. destroy_workqueue(mp->m_reclaim_workqueue);
  501. out_destroy_unwritten:
  502. destroy_workqueue(mp->m_unwritten_workqueue);
  503. out_destroy_buf:
  504. destroy_workqueue(mp->m_buf_workqueue);
  505. out:
  506. return -ENOMEM;
  507. }
  508. STATIC void
  509. xfs_destroy_mount_workqueues(
  510. struct xfs_mount *mp)
  511. {
  512. destroy_workqueue(mp->m_sync_workqueue);
  513. destroy_workqueue(mp->m_blockgc_wq);
  514. destroy_workqueue(mp->m_inodegc_wq);
  515. destroy_workqueue(mp->m_reclaim_workqueue);
  516. destroy_workqueue(mp->m_unwritten_workqueue);
  517. destroy_workqueue(mp->m_buf_workqueue);
  518. }
  519. static void
  520. xfs_flush_inodes_worker(
  521. struct work_struct *work)
  522. {
  523. struct xfs_mount *mp = container_of(work, struct xfs_mount,
  524. m_flush_inodes_work);
  525. struct super_block *sb = mp->m_super;
  526. if (down_read_trylock(&sb->s_umount)) {
  527. sync_inodes_sb(sb);
  528. up_read(&sb->s_umount);
  529. }
  530. }
  531. /*
  532. * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
  533. * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
  534. * for IO to complete so that we effectively throttle multiple callers to the
  535. * rate at which IO is completing.
  536. */
  537. void
  538. xfs_flush_inodes(
  539. struct xfs_mount *mp)
  540. {
  541. /*
  542. * If flush_work() returns true then that means we waited for a flush
  543. * which was already in progress. Don't bother running another scan.
  544. */
  545. if (flush_work(&mp->m_flush_inodes_work))
  546. return;
  547. queue_work(mp->m_sync_workqueue, &mp->m_flush_inodes_work);
  548. flush_work(&mp->m_flush_inodes_work);
  549. }
  550. /* Catch misguided souls that try to use this interface on XFS */
  551. STATIC struct inode *
  552. xfs_fs_alloc_inode(
  553. struct super_block *sb)
  554. {
  555. BUG();
  556. return NULL;
  557. }
  558. /*
  559. * Now that the generic code is guaranteed not to be accessing
  560. * the linux inode, we can inactivate and reclaim the inode.
  561. */
  562. STATIC void
  563. xfs_fs_destroy_inode(
  564. struct inode *inode)
  565. {
  566. struct xfs_inode *ip = XFS_I(inode);
  567. trace_xfs_destroy_inode(ip);
  568. ASSERT(!rwsem_is_locked(&inode->i_rwsem));
  569. XFS_STATS_INC(ip->i_mount, vn_rele);
  570. XFS_STATS_INC(ip->i_mount, vn_remove);
  571. xfs_inode_mark_reclaimable(ip);
  572. }
  573. static void
  574. xfs_fs_dirty_inode(
  575. struct inode *inode,
  576. int flags)
  577. {
  578. struct xfs_inode *ip = XFS_I(inode);
  579. struct xfs_mount *mp = ip->i_mount;
  580. struct xfs_trans *tp;
  581. if (!(inode->i_sb->s_flags & SB_LAZYTIME))
  582. return;
  583. /*
  584. * Only do the timestamp update if the inode is dirty (I_DIRTY_SYNC)
  585. * and has dirty timestamp (I_DIRTY_TIME). I_DIRTY_TIME can be passed
  586. * in flags possibly together with I_DIRTY_SYNC.
  587. */
  588. if ((flags & ~I_DIRTY_TIME) != I_DIRTY_SYNC || !(flags & I_DIRTY_TIME))
  589. return;
  590. if (xfs_trans_alloc(mp, &M_RES(mp)->tr_fsyncts, 0, 0, 0, &tp))
  591. return;
  592. xfs_ilock(ip, XFS_ILOCK_EXCL);
  593. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  594. xfs_trans_log_inode(tp, ip, XFS_ILOG_TIMESTAMP);
  595. xfs_trans_commit(tp);
  596. }
  597. /*
  598. * Slab object creation initialisation for the XFS inode.
  599. * This covers only the idempotent fields in the XFS inode;
  600. * all other fields need to be initialised on allocation
  601. * from the slab. This avoids the need to repeatedly initialise
  602. * fields in the xfs inode that left in the initialise state
  603. * when freeing the inode.
  604. */
  605. STATIC void
  606. xfs_fs_inode_init_once(
  607. void *inode)
  608. {
  609. struct xfs_inode *ip = inode;
  610. memset(ip, 0, sizeof(struct xfs_inode));
  611. /* vfs inode */
  612. inode_init_once(VFS_I(ip));
  613. /* xfs inode */
  614. atomic_set(&ip->i_pincount, 0);
  615. spin_lock_init(&ip->i_flags_lock);
  616. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  617. "xfsino", ip->i_ino);
  618. }
  619. /*
  620. * We do an unlocked check for XFS_IDONTCACHE here because we are already
  621. * serialised against cache hits here via the inode->i_lock and igrab() in
  622. * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
  623. * racing with us, and it avoids needing to grab a spinlock here for every inode
  624. * we drop the final reference on.
  625. */
  626. STATIC int
  627. xfs_fs_drop_inode(
  628. struct inode *inode)
  629. {
  630. struct xfs_inode *ip = XFS_I(inode);
  631. /*
  632. * If this unlinked inode is in the middle of recovery, don't
  633. * drop the inode just yet; log recovery will take care of
  634. * that. See the comment for this inode flag.
  635. */
  636. if (ip->i_flags & XFS_IRECOVERY) {
  637. ASSERT(xlog_recovery_needed(ip->i_mount->m_log));
  638. return 0;
  639. }
  640. return generic_drop_inode(inode);
  641. }
  642. static void
  643. xfs_mount_free(
  644. struct xfs_mount *mp)
  645. {
  646. kfree(mp->m_rtname);
  647. kfree(mp->m_logname);
  648. kmem_free(mp);
  649. }
  650. STATIC int
  651. xfs_fs_sync_fs(
  652. struct super_block *sb,
  653. int wait)
  654. {
  655. struct xfs_mount *mp = XFS_M(sb);
  656. int error;
  657. trace_xfs_fs_sync_fs(mp, __return_address);
  658. /*
  659. * Doing anything during the async pass would be counterproductive.
  660. */
  661. if (!wait)
  662. return 0;
  663. error = xfs_log_force(mp, XFS_LOG_SYNC);
  664. if (error)
  665. return error;
  666. if (laptop_mode) {
  667. /*
  668. * The disk must be active because we're syncing.
  669. * We schedule log work now (now that the disk is
  670. * active) instead of later (when it might not be).
  671. */
  672. flush_delayed_work(&mp->m_log->l_work);
  673. }
  674. /*
  675. * If we are called with page faults frozen out, it means we are about
  676. * to freeze the transaction subsystem. Take the opportunity to shut
  677. * down inodegc because once SB_FREEZE_FS is set it's too late to
  678. * prevent inactivation races with freeze. The fs doesn't get called
  679. * again by the freezing process until after SB_FREEZE_FS has been set,
  680. * so it's now or never. Same logic applies to speculative allocation
  681. * garbage collection.
  682. *
  683. * We don't care if this is a normal syncfs call that does this or
  684. * freeze that does this - we can run this multiple times without issue
  685. * and we won't race with a restart because a restart can only occur
  686. * when the state is either SB_FREEZE_FS or SB_FREEZE_COMPLETE.
  687. */
  688. if (sb->s_writers.frozen == SB_FREEZE_PAGEFAULT) {
  689. xfs_inodegc_stop(mp);
  690. xfs_blockgc_stop(mp);
  691. }
  692. return 0;
  693. }
  694. STATIC int
  695. xfs_fs_statfs(
  696. struct dentry *dentry,
  697. struct kstatfs *statp)
  698. {
  699. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  700. xfs_sb_t *sbp = &mp->m_sb;
  701. struct xfs_inode *ip = XFS_I(d_inode(dentry));
  702. uint64_t fakeinos, id;
  703. uint64_t icount;
  704. uint64_t ifree;
  705. uint64_t fdblocks;
  706. xfs_extlen_t lsize;
  707. int64_t ffree;
  708. /*
  709. * Expedite background inodegc but don't wait. We do not want to block
  710. * here waiting hours for a billion extent file to be truncated.
  711. */
  712. xfs_inodegc_push(mp);
  713. statp->f_type = XFS_SUPER_MAGIC;
  714. statp->f_namelen = MAXNAMELEN - 1;
  715. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  716. statp->f_fsid = u64_to_fsid(id);
  717. icount = percpu_counter_sum(&mp->m_icount);
  718. ifree = percpu_counter_sum(&mp->m_ifree);
  719. fdblocks = percpu_counter_sum(&mp->m_fdblocks);
  720. spin_lock(&mp->m_sb_lock);
  721. statp->f_bsize = sbp->sb_blocksize;
  722. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  723. statp->f_blocks = sbp->sb_dblocks - lsize;
  724. spin_unlock(&mp->m_sb_lock);
  725. /* make sure statp->f_bfree does not underflow */
  726. statp->f_bfree = max_t(int64_t, 0,
  727. fdblocks - xfs_fdblocks_unavailable(mp));
  728. statp->f_bavail = statp->f_bfree;
  729. fakeinos = XFS_FSB_TO_INO(mp, statp->f_bfree);
  730. statp->f_files = min(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
  731. if (M_IGEO(mp)->maxicount)
  732. statp->f_files = min_t(typeof(statp->f_files),
  733. statp->f_files,
  734. M_IGEO(mp)->maxicount);
  735. /* If sb_icount overshot maxicount, report actual allocation */
  736. statp->f_files = max_t(typeof(statp->f_files),
  737. statp->f_files,
  738. sbp->sb_icount);
  739. /* make sure statp->f_ffree does not underflow */
  740. ffree = statp->f_files - (icount - ifree);
  741. statp->f_ffree = max_t(int64_t, ffree, 0);
  742. if ((ip->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
  743. ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
  744. (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
  745. xfs_qm_statvfs(ip, statp);
  746. if (XFS_IS_REALTIME_MOUNT(mp) &&
  747. (ip->i_diflags & (XFS_DIFLAG_RTINHERIT | XFS_DIFLAG_REALTIME))) {
  748. s64 freertx;
  749. statp->f_blocks = sbp->sb_rblocks;
  750. freertx = percpu_counter_sum_positive(&mp->m_frextents);
  751. statp->f_bavail = statp->f_bfree = freertx * sbp->sb_rextsize;
  752. }
  753. return 0;
  754. }
  755. STATIC void
  756. xfs_save_resvblks(struct xfs_mount *mp)
  757. {
  758. uint64_t resblks = 0;
  759. mp->m_resblks_save = mp->m_resblks;
  760. xfs_reserve_blocks(mp, &resblks, NULL);
  761. }
  762. STATIC void
  763. xfs_restore_resvblks(struct xfs_mount *mp)
  764. {
  765. uint64_t resblks;
  766. if (mp->m_resblks_save) {
  767. resblks = mp->m_resblks_save;
  768. mp->m_resblks_save = 0;
  769. } else
  770. resblks = xfs_default_resblks(mp);
  771. xfs_reserve_blocks(mp, &resblks, NULL);
  772. }
  773. /*
  774. * Second stage of a freeze. The data is already frozen so we only
  775. * need to take care of the metadata. Once that's done sync the superblock
  776. * to the log to dirty it in case of a crash while frozen. This ensures that we
  777. * will recover the unlinked inode lists on the next mount.
  778. */
  779. STATIC int
  780. xfs_fs_freeze(
  781. struct super_block *sb)
  782. {
  783. struct xfs_mount *mp = XFS_M(sb);
  784. unsigned int flags;
  785. int ret;
  786. /*
  787. * The filesystem is now frozen far enough that memory reclaim
  788. * cannot safely operate on the filesystem. Hence we need to
  789. * set a GFP_NOFS context here to avoid recursion deadlocks.
  790. */
  791. flags = memalloc_nofs_save();
  792. xfs_save_resvblks(mp);
  793. ret = xfs_log_quiesce(mp);
  794. memalloc_nofs_restore(flags);
  795. /*
  796. * For read-write filesystems, we need to restart the inodegc on error
  797. * because we stopped it at SB_FREEZE_PAGEFAULT level and a thaw is not
  798. * going to be run to restart it now. We are at SB_FREEZE_FS level
  799. * here, so we can restart safely without racing with a stop in
  800. * xfs_fs_sync_fs().
  801. */
  802. if (ret && !xfs_is_readonly(mp)) {
  803. xfs_blockgc_start(mp);
  804. xfs_inodegc_start(mp);
  805. }
  806. return ret;
  807. }
  808. STATIC int
  809. xfs_fs_unfreeze(
  810. struct super_block *sb)
  811. {
  812. struct xfs_mount *mp = XFS_M(sb);
  813. xfs_restore_resvblks(mp);
  814. xfs_log_work_queue(mp);
  815. /*
  816. * Don't reactivate the inodegc worker on a readonly filesystem because
  817. * inodes are sent directly to reclaim. Don't reactivate the blockgc
  818. * worker because there are no speculative preallocations on a readonly
  819. * filesystem.
  820. */
  821. if (!xfs_is_readonly(mp)) {
  822. xfs_blockgc_start(mp);
  823. xfs_inodegc_start(mp);
  824. }
  825. return 0;
  826. }
  827. /*
  828. * This function fills in xfs_mount_t fields based on mount args.
  829. * Note: the superblock _has_ now been read in.
  830. */
  831. STATIC int
  832. xfs_finish_flags(
  833. struct xfs_mount *mp)
  834. {
  835. /* Fail a mount where the logbuf is smaller than the log stripe */
  836. if (xfs_has_logv2(mp)) {
  837. if (mp->m_logbsize <= 0 &&
  838. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  839. mp->m_logbsize = mp->m_sb.sb_logsunit;
  840. } else if (mp->m_logbsize > 0 &&
  841. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  842. xfs_warn(mp,
  843. "logbuf size must be greater than or equal to log stripe size");
  844. return -EINVAL;
  845. }
  846. } else {
  847. /* Fail a mount if the logbuf is larger than 32K */
  848. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  849. xfs_warn(mp,
  850. "logbuf size for version 1 logs must be 16K or 32K");
  851. return -EINVAL;
  852. }
  853. }
  854. /*
  855. * V5 filesystems always use attr2 format for attributes.
  856. */
  857. if (xfs_has_crc(mp) && xfs_has_noattr2(mp)) {
  858. xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
  859. "attr2 is always enabled for V5 filesystems.");
  860. return -EINVAL;
  861. }
  862. /*
  863. * prohibit r/w mounts of read-only filesystems
  864. */
  865. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !xfs_is_readonly(mp)) {
  866. xfs_warn(mp,
  867. "cannot mount a read-only filesystem as read-write");
  868. return -EROFS;
  869. }
  870. if ((mp->m_qflags & XFS_GQUOTA_ACCT) &&
  871. (mp->m_qflags & XFS_PQUOTA_ACCT) &&
  872. !xfs_has_pquotino(mp)) {
  873. xfs_warn(mp,
  874. "Super block does not support project and group quota together");
  875. return -EINVAL;
  876. }
  877. return 0;
  878. }
  879. static int
  880. xfs_init_percpu_counters(
  881. struct xfs_mount *mp)
  882. {
  883. int error;
  884. error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
  885. if (error)
  886. return -ENOMEM;
  887. error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
  888. if (error)
  889. goto free_icount;
  890. error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
  891. if (error)
  892. goto free_ifree;
  893. error = percpu_counter_init(&mp->m_delalloc_blks, 0, GFP_KERNEL);
  894. if (error)
  895. goto free_fdblocks;
  896. error = percpu_counter_init(&mp->m_frextents, 0, GFP_KERNEL);
  897. if (error)
  898. goto free_delalloc;
  899. return 0;
  900. free_delalloc:
  901. percpu_counter_destroy(&mp->m_delalloc_blks);
  902. free_fdblocks:
  903. percpu_counter_destroy(&mp->m_fdblocks);
  904. free_ifree:
  905. percpu_counter_destroy(&mp->m_ifree);
  906. free_icount:
  907. percpu_counter_destroy(&mp->m_icount);
  908. return -ENOMEM;
  909. }
  910. void
  911. xfs_reinit_percpu_counters(
  912. struct xfs_mount *mp)
  913. {
  914. percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
  915. percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
  916. percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
  917. percpu_counter_set(&mp->m_frextents, mp->m_sb.sb_frextents);
  918. }
  919. static void
  920. xfs_destroy_percpu_counters(
  921. struct xfs_mount *mp)
  922. {
  923. percpu_counter_destroy(&mp->m_icount);
  924. percpu_counter_destroy(&mp->m_ifree);
  925. percpu_counter_destroy(&mp->m_fdblocks);
  926. ASSERT(xfs_is_shutdown(mp) ||
  927. percpu_counter_sum(&mp->m_delalloc_blks) == 0);
  928. percpu_counter_destroy(&mp->m_delalloc_blks);
  929. percpu_counter_destroy(&mp->m_frextents);
  930. }
  931. static int
  932. xfs_inodegc_init_percpu(
  933. struct xfs_mount *mp)
  934. {
  935. struct xfs_inodegc *gc;
  936. int cpu;
  937. mp->m_inodegc = alloc_percpu(struct xfs_inodegc);
  938. if (!mp->m_inodegc)
  939. return -ENOMEM;
  940. for_each_possible_cpu(cpu) {
  941. gc = per_cpu_ptr(mp->m_inodegc, cpu);
  942. #if defined(DEBUG) || defined(XFS_WARN)
  943. gc->cpu = cpu;
  944. #endif
  945. init_llist_head(&gc->list);
  946. gc->items = 0;
  947. INIT_DELAYED_WORK(&gc->work, xfs_inodegc_worker);
  948. }
  949. return 0;
  950. }
  951. static void
  952. xfs_inodegc_free_percpu(
  953. struct xfs_mount *mp)
  954. {
  955. if (!mp->m_inodegc)
  956. return;
  957. free_percpu(mp->m_inodegc);
  958. }
  959. static void
  960. xfs_fs_put_super(
  961. struct super_block *sb)
  962. {
  963. struct xfs_mount *mp = XFS_M(sb);
  964. /* if ->fill_super failed, we have no mount to tear down */
  965. if (!sb->s_fs_info)
  966. return;
  967. xfs_notice(mp, "Unmounting Filesystem");
  968. xfs_filestream_unmount(mp);
  969. xfs_unmountfs(mp);
  970. xfs_freesb(mp);
  971. free_percpu(mp->m_stats.xs_stats);
  972. xfs_mount_list_del(mp);
  973. xfs_inodegc_free_percpu(mp);
  974. xfs_destroy_percpu_counters(mp);
  975. xfs_destroy_mount_workqueues(mp);
  976. xfs_close_devices(mp);
  977. sb->s_fs_info = NULL;
  978. xfs_mount_free(mp);
  979. }
  980. static long
  981. xfs_fs_nr_cached_objects(
  982. struct super_block *sb,
  983. struct shrink_control *sc)
  984. {
  985. /* Paranoia: catch incorrect calls during mount setup or teardown */
  986. if (WARN_ON_ONCE(!sb->s_fs_info))
  987. return 0;
  988. return xfs_reclaim_inodes_count(XFS_M(sb));
  989. }
  990. static long
  991. xfs_fs_free_cached_objects(
  992. struct super_block *sb,
  993. struct shrink_control *sc)
  994. {
  995. return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
  996. }
  997. static const struct super_operations xfs_super_operations = {
  998. .alloc_inode = xfs_fs_alloc_inode,
  999. .destroy_inode = xfs_fs_destroy_inode,
  1000. .dirty_inode = xfs_fs_dirty_inode,
  1001. .drop_inode = xfs_fs_drop_inode,
  1002. .put_super = xfs_fs_put_super,
  1003. .sync_fs = xfs_fs_sync_fs,
  1004. .freeze_fs = xfs_fs_freeze,
  1005. .unfreeze_fs = xfs_fs_unfreeze,
  1006. .statfs = xfs_fs_statfs,
  1007. .show_options = xfs_fs_show_options,
  1008. .nr_cached_objects = xfs_fs_nr_cached_objects,
  1009. .free_cached_objects = xfs_fs_free_cached_objects,
  1010. };
  1011. static int
  1012. suffix_kstrtoint(
  1013. const char *s,
  1014. unsigned int base,
  1015. int *res)
  1016. {
  1017. int last, shift_left_factor = 0, _res;
  1018. char *value;
  1019. int ret = 0;
  1020. value = kstrdup(s, GFP_KERNEL);
  1021. if (!value)
  1022. return -ENOMEM;
  1023. last = strlen(value) - 1;
  1024. if (value[last] == 'K' || value[last] == 'k') {
  1025. shift_left_factor = 10;
  1026. value[last] = '\0';
  1027. }
  1028. if (value[last] == 'M' || value[last] == 'm') {
  1029. shift_left_factor = 20;
  1030. value[last] = '\0';
  1031. }
  1032. if (value[last] == 'G' || value[last] == 'g') {
  1033. shift_left_factor = 30;
  1034. value[last] = '\0';
  1035. }
  1036. if (kstrtoint(value, base, &_res))
  1037. ret = -EINVAL;
  1038. kfree(value);
  1039. *res = _res << shift_left_factor;
  1040. return ret;
  1041. }
  1042. static inline void
  1043. xfs_fs_warn_deprecated(
  1044. struct fs_context *fc,
  1045. struct fs_parameter *param,
  1046. uint64_t flag,
  1047. bool value)
  1048. {
  1049. /* Don't print the warning if reconfiguring and current mount point
  1050. * already had the flag set
  1051. */
  1052. if ((fc->purpose & FS_CONTEXT_FOR_RECONFIGURE) &&
  1053. !!(XFS_M(fc->root->d_sb)->m_features & flag) == value)
  1054. return;
  1055. xfs_warn(fc->s_fs_info, "%s mount option is deprecated.", param->key);
  1056. }
  1057. /*
  1058. * Set mount state from a mount option.
  1059. *
  1060. * NOTE: mp->m_super is NULL here!
  1061. */
  1062. static int
  1063. xfs_fs_parse_param(
  1064. struct fs_context *fc,
  1065. struct fs_parameter *param)
  1066. {
  1067. struct xfs_mount *parsing_mp = fc->s_fs_info;
  1068. struct fs_parse_result result;
  1069. int size = 0;
  1070. int opt;
  1071. opt = fs_parse(fc, xfs_fs_parameters, param, &result);
  1072. if (opt < 0)
  1073. return opt;
  1074. switch (opt) {
  1075. case Opt_logbufs:
  1076. parsing_mp->m_logbufs = result.uint_32;
  1077. return 0;
  1078. case Opt_logbsize:
  1079. if (suffix_kstrtoint(param->string, 10, &parsing_mp->m_logbsize))
  1080. return -EINVAL;
  1081. return 0;
  1082. case Opt_logdev:
  1083. kfree(parsing_mp->m_logname);
  1084. parsing_mp->m_logname = kstrdup(param->string, GFP_KERNEL);
  1085. if (!parsing_mp->m_logname)
  1086. return -ENOMEM;
  1087. return 0;
  1088. case Opt_rtdev:
  1089. kfree(parsing_mp->m_rtname);
  1090. parsing_mp->m_rtname = kstrdup(param->string, GFP_KERNEL);
  1091. if (!parsing_mp->m_rtname)
  1092. return -ENOMEM;
  1093. return 0;
  1094. case Opt_allocsize:
  1095. if (suffix_kstrtoint(param->string, 10, &size))
  1096. return -EINVAL;
  1097. parsing_mp->m_allocsize_log = ffs(size) - 1;
  1098. parsing_mp->m_features |= XFS_FEAT_ALLOCSIZE;
  1099. return 0;
  1100. case Opt_grpid:
  1101. case Opt_bsdgroups:
  1102. parsing_mp->m_features |= XFS_FEAT_GRPID;
  1103. return 0;
  1104. case Opt_nogrpid:
  1105. case Opt_sysvgroups:
  1106. parsing_mp->m_features &= ~XFS_FEAT_GRPID;
  1107. return 0;
  1108. case Opt_wsync:
  1109. parsing_mp->m_features |= XFS_FEAT_WSYNC;
  1110. return 0;
  1111. case Opt_norecovery:
  1112. parsing_mp->m_features |= XFS_FEAT_NORECOVERY;
  1113. return 0;
  1114. case Opt_noalign:
  1115. parsing_mp->m_features |= XFS_FEAT_NOALIGN;
  1116. return 0;
  1117. case Opt_swalloc:
  1118. parsing_mp->m_features |= XFS_FEAT_SWALLOC;
  1119. return 0;
  1120. case Opt_sunit:
  1121. parsing_mp->m_dalign = result.uint_32;
  1122. return 0;
  1123. case Opt_swidth:
  1124. parsing_mp->m_swidth = result.uint_32;
  1125. return 0;
  1126. case Opt_inode32:
  1127. parsing_mp->m_features |= XFS_FEAT_SMALL_INUMS;
  1128. return 0;
  1129. case Opt_inode64:
  1130. parsing_mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
  1131. return 0;
  1132. case Opt_nouuid:
  1133. parsing_mp->m_features |= XFS_FEAT_NOUUID;
  1134. return 0;
  1135. case Opt_largeio:
  1136. parsing_mp->m_features |= XFS_FEAT_LARGE_IOSIZE;
  1137. return 0;
  1138. case Opt_nolargeio:
  1139. parsing_mp->m_features &= ~XFS_FEAT_LARGE_IOSIZE;
  1140. return 0;
  1141. case Opt_filestreams:
  1142. parsing_mp->m_features |= XFS_FEAT_FILESTREAMS;
  1143. return 0;
  1144. case Opt_noquota:
  1145. parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
  1146. parsing_mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
  1147. return 0;
  1148. case Opt_quota:
  1149. case Opt_uquota:
  1150. case Opt_usrquota:
  1151. parsing_mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ENFD);
  1152. return 0;
  1153. case Opt_qnoenforce:
  1154. case Opt_uqnoenforce:
  1155. parsing_mp->m_qflags |= XFS_UQUOTA_ACCT;
  1156. parsing_mp->m_qflags &= ~XFS_UQUOTA_ENFD;
  1157. return 0;
  1158. case Opt_pquota:
  1159. case Opt_prjquota:
  1160. parsing_mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ENFD);
  1161. return 0;
  1162. case Opt_pqnoenforce:
  1163. parsing_mp->m_qflags |= XFS_PQUOTA_ACCT;
  1164. parsing_mp->m_qflags &= ~XFS_PQUOTA_ENFD;
  1165. return 0;
  1166. case Opt_gquota:
  1167. case Opt_grpquota:
  1168. parsing_mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ENFD);
  1169. return 0;
  1170. case Opt_gqnoenforce:
  1171. parsing_mp->m_qflags |= XFS_GQUOTA_ACCT;
  1172. parsing_mp->m_qflags &= ~XFS_GQUOTA_ENFD;
  1173. return 0;
  1174. case Opt_discard:
  1175. parsing_mp->m_features |= XFS_FEAT_DISCARD;
  1176. return 0;
  1177. case Opt_nodiscard:
  1178. parsing_mp->m_features &= ~XFS_FEAT_DISCARD;
  1179. return 0;
  1180. #ifdef CONFIG_FS_DAX
  1181. case Opt_dax:
  1182. xfs_mount_set_dax_mode(parsing_mp, XFS_DAX_ALWAYS);
  1183. return 0;
  1184. case Opt_dax_enum:
  1185. xfs_mount_set_dax_mode(parsing_mp, result.uint_32);
  1186. return 0;
  1187. #endif
  1188. /* Following mount options will be removed in September 2025 */
  1189. case Opt_ikeep:
  1190. xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, true);
  1191. parsing_mp->m_features |= XFS_FEAT_IKEEP;
  1192. return 0;
  1193. case Opt_noikeep:
  1194. xfs_fs_warn_deprecated(fc, param, XFS_FEAT_IKEEP, false);
  1195. parsing_mp->m_features &= ~XFS_FEAT_IKEEP;
  1196. return 0;
  1197. case Opt_attr2:
  1198. xfs_fs_warn_deprecated(fc, param, XFS_FEAT_ATTR2, true);
  1199. parsing_mp->m_features |= XFS_FEAT_ATTR2;
  1200. return 0;
  1201. case Opt_noattr2:
  1202. xfs_fs_warn_deprecated(fc, param, XFS_FEAT_NOATTR2, true);
  1203. parsing_mp->m_features |= XFS_FEAT_NOATTR2;
  1204. return 0;
  1205. default:
  1206. xfs_warn(parsing_mp, "unknown mount option [%s].", param->key);
  1207. return -EINVAL;
  1208. }
  1209. return 0;
  1210. }
  1211. static int
  1212. xfs_fs_validate_params(
  1213. struct xfs_mount *mp)
  1214. {
  1215. /* No recovery flag requires a read-only mount */
  1216. if (xfs_has_norecovery(mp) && !xfs_is_readonly(mp)) {
  1217. xfs_warn(mp, "no-recovery mounts must be read-only.");
  1218. return -EINVAL;
  1219. }
  1220. /*
  1221. * We have not read the superblock at this point, so only the attr2
  1222. * mount option can set the attr2 feature by this stage.
  1223. */
  1224. if (xfs_has_attr2(mp) && xfs_has_noattr2(mp)) {
  1225. xfs_warn(mp, "attr2 and noattr2 cannot both be specified.");
  1226. return -EINVAL;
  1227. }
  1228. if (xfs_has_noalign(mp) && (mp->m_dalign || mp->m_swidth)) {
  1229. xfs_warn(mp,
  1230. "sunit and swidth options incompatible with the noalign option");
  1231. return -EINVAL;
  1232. }
  1233. if (!IS_ENABLED(CONFIG_XFS_QUOTA) && mp->m_qflags != 0) {
  1234. xfs_warn(mp, "quota support not available in this kernel.");
  1235. return -EINVAL;
  1236. }
  1237. if ((mp->m_dalign && !mp->m_swidth) ||
  1238. (!mp->m_dalign && mp->m_swidth)) {
  1239. xfs_warn(mp, "sunit and swidth must be specified together");
  1240. return -EINVAL;
  1241. }
  1242. if (mp->m_dalign && (mp->m_swidth % mp->m_dalign != 0)) {
  1243. xfs_warn(mp,
  1244. "stripe width (%d) must be a multiple of the stripe unit (%d)",
  1245. mp->m_swidth, mp->m_dalign);
  1246. return -EINVAL;
  1247. }
  1248. if (mp->m_logbufs != -1 &&
  1249. mp->m_logbufs != 0 &&
  1250. (mp->m_logbufs < XLOG_MIN_ICLOGS ||
  1251. mp->m_logbufs > XLOG_MAX_ICLOGS)) {
  1252. xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
  1253. mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  1254. return -EINVAL;
  1255. }
  1256. if (mp->m_logbsize != -1 &&
  1257. mp->m_logbsize != 0 &&
  1258. (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
  1259. mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
  1260. !is_power_of_2(mp->m_logbsize))) {
  1261. xfs_warn(mp,
  1262. "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  1263. mp->m_logbsize);
  1264. return -EINVAL;
  1265. }
  1266. if (xfs_has_allocsize(mp) &&
  1267. (mp->m_allocsize_log > XFS_MAX_IO_LOG ||
  1268. mp->m_allocsize_log < XFS_MIN_IO_LOG)) {
  1269. xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
  1270. mp->m_allocsize_log, XFS_MIN_IO_LOG, XFS_MAX_IO_LOG);
  1271. return -EINVAL;
  1272. }
  1273. return 0;
  1274. }
  1275. static int
  1276. xfs_fs_fill_super(
  1277. struct super_block *sb,
  1278. struct fs_context *fc)
  1279. {
  1280. struct xfs_mount *mp = sb->s_fs_info;
  1281. struct inode *root;
  1282. int flags = 0, error;
  1283. mp->m_super = sb;
  1284. error = xfs_fs_validate_params(mp);
  1285. if (error)
  1286. goto out_free_names;
  1287. sb_min_blocksize(sb, BBSIZE);
  1288. sb->s_xattr = xfs_xattr_handlers;
  1289. sb->s_export_op = &xfs_export_operations;
  1290. #ifdef CONFIG_XFS_QUOTA
  1291. sb->s_qcop = &xfs_quotactl_operations;
  1292. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
  1293. #endif
  1294. sb->s_op = &xfs_super_operations;
  1295. /*
  1296. * Delay mount work if the debug hook is set. This is debug
  1297. * instrumention to coordinate simulation of xfs mount failures with
  1298. * VFS superblock operations
  1299. */
  1300. if (xfs_globals.mount_delay) {
  1301. xfs_notice(mp, "Delaying mount for %d seconds.",
  1302. xfs_globals.mount_delay);
  1303. msleep(xfs_globals.mount_delay * 1000);
  1304. }
  1305. if (fc->sb_flags & SB_SILENT)
  1306. flags |= XFS_MFSI_QUIET;
  1307. error = xfs_open_devices(mp);
  1308. if (error)
  1309. goto out_free_names;
  1310. error = xfs_init_mount_workqueues(mp);
  1311. if (error)
  1312. goto out_close_devices;
  1313. error = xfs_init_percpu_counters(mp);
  1314. if (error)
  1315. goto out_destroy_workqueues;
  1316. error = xfs_inodegc_init_percpu(mp);
  1317. if (error)
  1318. goto out_destroy_counters;
  1319. /*
  1320. * All percpu data structures requiring cleanup when a cpu goes offline
  1321. * must be allocated before adding this @mp to the cpu-dead handler's
  1322. * mount list.
  1323. */
  1324. xfs_mount_list_add(mp);
  1325. /* Allocate stats memory before we do operations that might use it */
  1326. mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
  1327. if (!mp->m_stats.xs_stats) {
  1328. error = -ENOMEM;
  1329. goto out_destroy_inodegc;
  1330. }
  1331. error = xfs_readsb(mp, flags);
  1332. if (error)
  1333. goto out_free_stats;
  1334. error = xfs_finish_flags(mp);
  1335. if (error)
  1336. goto out_free_sb;
  1337. error = xfs_setup_devices(mp);
  1338. if (error)
  1339. goto out_free_sb;
  1340. /* V4 support is undergoing deprecation. */
  1341. if (!xfs_has_crc(mp)) {
  1342. #ifdef CONFIG_XFS_SUPPORT_V4
  1343. xfs_warn_once(mp,
  1344. "Deprecated V4 format (crc=0) will not be supported after September 2030.");
  1345. #else
  1346. xfs_warn(mp,
  1347. "Deprecated V4 format (crc=0) not supported by kernel.");
  1348. error = -EINVAL;
  1349. goto out_free_sb;
  1350. #endif
  1351. }
  1352. /* Filesystem claims it needs repair, so refuse the mount. */
  1353. if (xfs_has_needsrepair(mp)) {
  1354. xfs_warn(mp, "Filesystem needs repair. Please run xfs_repair.");
  1355. error = -EFSCORRUPTED;
  1356. goto out_free_sb;
  1357. }
  1358. /*
  1359. * Don't touch the filesystem if a user tool thinks it owns the primary
  1360. * superblock. mkfs doesn't clear the flag from secondary supers, so
  1361. * we don't check them at all.
  1362. */
  1363. if (mp->m_sb.sb_inprogress) {
  1364. xfs_warn(mp, "Offline file system operation in progress!");
  1365. error = -EFSCORRUPTED;
  1366. goto out_free_sb;
  1367. }
  1368. /*
  1369. * Until this is fixed only page-sized or smaller data blocks work.
  1370. */
  1371. if (mp->m_sb.sb_blocksize > PAGE_SIZE) {
  1372. xfs_warn(mp,
  1373. "File system with blocksize %d bytes. "
  1374. "Only pagesize (%ld) or less will currently work.",
  1375. mp->m_sb.sb_blocksize, PAGE_SIZE);
  1376. error = -ENOSYS;
  1377. goto out_free_sb;
  1378. }
  1379. /* Ensure this filesystem fits in the page cache limits */
  1380. if (xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_dblocks) ||
  1381. xfs_sb_validate_fsb_count(&mp->m_sb, mp->m_sb.sb_rblocks)) {
  1382. xfs_warn(mp,
  1383. "file system too large to be mounted on this system.");
  1384. error = -EFBIG;
  1385. goto out_free_sb;
  1386. }
  1387. /*
  1388. * XFS block mappings use 54 bits to store the logical block offset.
  1389. * This should suffice to handle the maximum file size that the VFS
  1390. * supports (currently 2^63 bytes on 64-bit and ULONG_MAX << PAGE_SHIFT
  1391. * bytes on 32-bit), but as XFS and VFS have gotten the s_maxbytes
  1392. * calculation wrong on 32-bit kernels in the past, we'll add a WARN_ON
  1393. * to check this assertion.
  1394. *
  1395. * Avoid integer overflow by comparing the maximum bmbt offset to the
  1396. * maximum pagecache offset in units of fs blocks.
  1397. */
  1398. if (!xfs_verify_fileoff(mp, XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE))) {
  1399. xfs_warn(mp,
  1400. "MAX_LFS_FILESIZE block offset (%llu) exceeds extent map maximum (%llu)!",
  1401. XFS_B_TO_FSBT(mp, MAX_LFS_FILESIZE),
  1402. XFS_MAX_FILEOFF);
  1403. error = -EINVAL;
  1404. goto out_free_sb;
  1405. }
  1406. error = xfs_filestream_mount(mp);
  1407. if (error)
  1408. goto out_free_sb;
  1409. /*
  1410. * we must configure the block size in the superblock before we run the
  1411. * full mount process as the mount process can lookup and cache inodes.
  1412. */
  1413. sb->s_magic = XFS_SUPER_MAGIC;
  1414. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1415. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1416. sb->s_maxbytes = MAX_LFS_FILESIZE;
  1417. sb->s_max_links = XFS_MAXLINK;
  1418. sb->s_time_gran = 1;
  1419. if (xfs_has_bigtime(mp)) {
  1420. sb->s_time_min = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MIN);
  1421. sb->s_time_max = xfs_bigtime_to_unix(XFS_BIGTIME_TIME_MAX);
  1422. } else {
  1423. sb->s_time_min = XFS_LEGACY_TIME_MIN;
  1424. sb->s_time_max = XFS_LEGACY_TIME_MAX;
  1425. }
  1426. trace_xfs_inode_timestamp_range(mp, sb->s_time_min, sb->s_time_max);
  1427. sb->s_iflags |= SB_I_CGROUPWB;
  1428. set_posix_acl_flag(sb);
  1429. /* version 5 superblocks support inode version counters. */
  1430. if (xfs_has_crc(mp))
  1431. sb->s_flags |= SB_I_VERSION;
  1432. if (xfs_has_dax_always(mp)) {
  1433. error = xfs_setup_dax_always(mp);
  1434. if (error)
  1435. goto out_filestream_unmount;
  1436. }
  1437. if (xfs_has_discard(mp) && !bdev_max_discard_sectors(sb->s_bdev)) {
  1438. xfs_warn(mp,
  1439. "mounting with \"discard\" option, but the device does not support discard");
  1440. mp->m_features &= ~XFS_FEAT_DISCARD;
  1441. }
  1442. if (xfs_has_reflink(mp)) {
  1443. if (mp->m_sb.sb_rblocks) {
  1444. xfs_alert(mp,
  1445. "reflink not compatible with realtime device!");
  1446. error = -EINVAL;
  1447. goto out_filestream_unmount;
  1448. }
  1449. if (xfs_globals.always_cow) {
  1450. xfs_info(mp, "using DEBUG-only always_cow mode.");
  1451. mp->m_always_cow = true;
  1452. }
  1453. }
  1454. if (xfs_has_rmapbt(mp) && mp->m_sb.sb_rblocks) {
  1455. xfs_alert(mp,
  1456. "reverse mapping btree not compatible with realtime device!");
  1457. error = -EINVAL;
  1458. goto out_filestream_unmount;
  1459. }
  1460. if (xfs_has_large_extent_counts(mp))
  1461. xfs_warn(mp,
  1462. "EXPERIMENTAL Large extent counts feature in use. Use at your own risk!");
  1463. error = xfs_mountfs(mp);
  1464. if (error)
  1465. goto out_filestream_unmount;
  1466. root = igrab(VFS_I(mp->m_rootip));
  1467. if (!root) {
  1468. error = -ENOENT;
  1469. goto out_unmount;
  1470. }
  1471. sb->s_root = d_make_root(root);
  1472. if (!sb->s_root) {
  1473. error = -ENOMEM;
  1474. goto out_unmount;
  1475. }
  1476. return 0;
  1477. out_filestream_unmount:
  1478. xfs_filestream_unmount(mp);
  1479. out_free_sb:
  1480. xfs_freesb(mp);
  1481. out_free_stats:
  1482. free_percpu(mp->m_stats.xs_stats);
  1483. out_destroy_inodegc:
  1484. xfs_mount_list_del(mp);
  1485. xfs_inodegc_free_percpu(mp);
  1486. out_destroy_counters:
  1487. xfs_destroy_percpu_counters(mp);
  1488. out_destroy_workqueues:
  1489. xfs_destroy_mount_workqueues(mp);
  1490. out_close_devices:
  1491. xfs_close_devices(mp);
  1492. out_free_names:
  1493. sb->s_fs_info = NULL;
  1494. xfs_mount_free(mp);
  1495. return error;
  1496. out_unmount:
  1497. xfs_filestream_unmount(mp);
  1498. xfs_unmountfs(mp);
  1499. goto out_free_sb;
  1500. }
  1501. static int
  1502. xfs_fs_get_tree(
  1503. struct fs_context *fc)
  1504. {
  1505. return get_tree_bdev(fc, xfs_fs_fill_super);
  1506. }
  1507. static int
  1508. xfs_remount_rw(
  1509. struct xfs_mount *mp)
  1510. {
  1511. struct xfs_sb *sbp = &mp->m_sb;
  1512. int error;
  1513. if (xfs_has_norecovery(mp)) {
  1514. xfs_warn(mp,
  1515. "ro->rw transition prohibited on norecovery mount");
  1516. return -EINVAL;
  1517. }
  1518. if (xfs_sb_is_v5(sbp) &&
  1519. xfs_sb_has_ro_compat_feature(sbp, XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
  1520. xfs_warn(mp,
  1521. "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
  1522. (sbp->sb_features_ro_compat &
  1523. XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
  1524. return -EINVAL;
  1525. }
  1526. clear_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
  1527. /*
  1528. * If this is the first remount to writeable state we might have some
  1529. * superblock changes to update.
  1530. */
  1531. if (mp->m_update_sb) {
  1532. error = xfs_sync_sb(mp, false);
  1533. if (error) {
  1534. xfs_warn(mp, "failed to write sb changes");
  1535. return error;
  1536. }
  1537. mp->m_update_sb = false;
  1538. }
  1539. /*
  1540. * Fill out the reserve pool if it is empty. Use the stashed value if
  1541. * it is non-zero, otherwise go with the default.
  1542. */
  1543. xfs_restore_resvblks(mp);
  1544. xfs_log_work_queue(mp);
  1545. xfs_blockgc_start(mp);
  1546. /* Create the per-AG metadata reservation pool .*/
  1547. error = xfs_fs_reserve_ag_blocks(mp);
  1548. if (error && error != -ENOSPC)
  1549. return error;
  1550. /* Re-enable the background inode inactivation worker. */
  1551. xfs_inodegc_start(mp);
  1552. return 0;
  1553. }
  1554. static int
  1555. xfs_remount_ro(
  1556. struct xfs_mount *mp)
  1557. {
  1558. struct xfs_icwalk icw = {
  1559. .icw_flags = XFS_ICWALK_FLAG_SYNC,
  1560. };
  1561. int error;
  1562. /* Flush all the dirty data to disk. */
  1563. error = sync_filesystem(mp->m_super);
  1564. if (error)
  1565. return error;
  1566. /*
  1567. * Cancel background eofb scanning so it cannot race with the final
  1568. * log force+buftarg wait and deadlock the remount.
  1569. */
  1570. xfs_blockgc_stop(mp);
  1571. /*
  1572. * Clear out all remaining COW staging extents and speculative post-EOF
  1573. * preallocations so that we don't leave inodes requiring inactivation
  1574. * cleanups during reclaim on a read-only mount. We must process every
  1575. * cached inode, so this requires a synchronous cache scan.
  1576. */
  1577. error = xfs_blockgc_free_space(mp, &icw);
  1578. if (error) {
  1579. xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
  1580. return error;
  1581. }
  1582. /*
  1583. * Stop the inodegc background worker. xfs_fs_reconfigure already
  1584. * flushed all pending inodegc work when it sync'd the filesystem.
  1585. * The VFS holds s_umount, so we know that inodes cannot enter
  1586. * xfs_fs_destroy_inode during a remount operation. In readonly mode
  1587. * we send inodes straight to reclaim, so no inodes will be queued.
  1588. */
  1589. xfs_inodegc_stop(mp);
  1590. /* Free the per-AG metadata reservation pool. */
  1591. error = xfs_fs_unreserve_ag_blocks(mp);
  1592. if (error) {
  1593. xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
  1594. return error;
  1595. }
  1596. /*
  1597. * Before we sync the metadata, we need to free up the reserve block
  1598. * pool so that the used block count in the superblock on disk is
  1599. * correct at the end of the remount. Stash the current* reserve pool
  1600. * size so that if we get remounted rw, we can return it to the same
  1601. * size.
  1602. */
  1603. xfs_save_resvblks(mp);
  1604. xfs_log_clean(mp);
  1605. set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
  1606. return 0;
  1607. }
  1608. /*
  1609. * Logically we would return an error here to prevent users from believing
  1610. * they might have changed mount options using remount which can't be changed.
  1611. *
  1612. * But unfortunately mount(8) adds all options from mtab and fstab to the mount
  1613. * arguments in some cases so we can't blindly reject options, but have to
  1614. * check for each specified option if it actually differs from the currently
  1615. * set option and only reject it if that's the case.
  1616. *
  1617. * Until that is implemented we return success for every remount request, and
  1618. * silently ignore all options that we can't actually change.
  1619. */
  1620. static int
  1621. xfs_fs_reconfigure(
  1622. struct fs_context *fc)
  1623. {
  1624. struct xfs_mount *mp = XFS_M(fc->root->d_sb);
  1625. struct xfs_mount *new_mp = fc->s_fs_info;
  1626. int flags = fc->sb_flags;
  1627. int error;
  1628. /* version 5 superblocks always support version counters. */
  1629. if (xfs_has_crc(mp))
  1630. fc->sb_flags |= SB_I_VERSION;
  1631. error = xfs_fs_validate_params(new_mp);
  1632. if (error)
  1633. return error;
  1634. /* inode32 -> inode64 */
  1635. if (xfs_has_small_inums(mp) && !xfs_has_small_inums(new_mp)) {
  1636. mp->m_features &= ~XFS_FEAT_SMALL_INUMS;
  1637. mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
  1638. }
  1639. /* inode64 -> inode32 */
  1640. if (!xfs_has_small_inums(mp) && xfs_has_small_inums(new_mp)) {
  1641. mp->m_features |= XFS_FEAT_SMALL_INUMS;
  1642. mp->m_maxagi = xfs_set_inode_alloc(mp, mp->m_sb.sb_agcount);
  1643. }
  1644. /* ro -> rw */
  1645. if (xfs_is_readonly(mp) && !(flags & SB_RDONLY)) {
  1646. error = xfs_remount_rw(mp);
  1647. if (error)
  1648. return error;
  1649. }
  1650. /* rw -> ro */
  1651. if (!xfs_is_readonly(mp) && (flags & SB_RDONLY)) {
  1652. error = xfs_remount_ro(mp);
  1653. if (error)
  1654. return error;
  1655. }
  1656. return 0;
  1657. }
  1658. static void xfs_fs_free(
  1659. struct fs_context *fc)
  1660. {
  1661. struct xfs_mount *mp = fc->s_fs_info;
  1662. /*
  1663. * mp is stored in the fs_context when it is initialized.
  1664. * mp is transferred to the superblock on a successful mount,
  1665. * but if an error occurs before the transfer we have to free
  1666. * it here.
  1667. */
  1668. if (mp)
  1669. xfs_mount_free(mp);
  1670. }
  1671. static const struct fs_context_operations xfs_context_ops = {
  1672. .parse_param = xfs_fs_parse_param,
  1673. .get_tree = xfs_fs_get_tree,
  1674. .reconfigure = xfs_fs_reconfigure,
  1675. .free = xfs_fs_free,
  1676. };
  1677. static int xfs_init_fs_context(
  1678. struct fs_context *fc)
  1679. {
  1680. struct xfs_mount *mp;
  1681. mp = kmem_alloc(sizeof(struct xfs_mount), KM_ZERO);
  1682. if (!mp)
  1683. return -ENOMEM;
  1684. spin_lock_init(&mp->m_sb_lock);
  1685. spin_lock_init(&mp->m_agirotor_lock);
  1686. INIT_RADIX_TREE(&mp->m_perag_tree, GFP_ATOMIC);
  1687. spin_lock_init(&mp->m_perag_lock);
  1688. mutex_init(&mp->m_growlock);
  1689. INIT_WORK(&mp->m_flush_inodes_work, xfs_flush_inodes_worker);
  1690. INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
  1691. mp->m_kobj.kobject.kset = xfs_kset;
  1692. /*
  1693. * We don't create the finobt per-ag space reservation until after log
  1694. * recovery, so we must set this to true so that an ifree transaction
  1695. * started during log recovery will not depend on space reservations
  1696. * for finobt expansion.
  1697. */
  1698. mp->m_finobt_nores = true;
  1699. /*
  1700. * These can be overridden by the mount option parsing.
  1701. */
  1702. mp->m_logbufs = -1;
  1703. mp->m_logbsize = -1;
  1704. mp->m_allocsize_log = 16; /* 64k */
  1705. /*
  1706. * Copy binary VFS mount flags we are interested in.
  1707. */
  1708. if (fc->sb_flags & SB_RDONLY)
  1709. set_bit(XFS_OPSTATE_READONLY, &mp->m_opstate);
  1710. if (fc->sb_flags & SB_DIRSYNC)
  1711. mp->m_features |= XFS_FEAT_DIRSYNC;
  1712. if (fc->sb_flags & SB_SYNCHRONOUS)
  1713. mp->m_features |= XFS_FEAT_WSYNC;
  1714. fc->s_fs_info = mp;
  1715. fc->ops = &xfs_context_ops;
  1716. return 0;
  1717. }
  1718. static struct file_system_type xfs_fs_type = {
  1719. .owner = THIS_MODULE,
  1720. .name = "xfs",
  1721. .init_fs_context = xfs_init_fs_context,
  1722. .parameters = xfs_fs_parameters,
  1723. .kill_sb = kill_block_super,
  1724. .fs_flags = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
  1725. };
  1726. MODULE_ALIAS_FS("xfs");
  1727. STATIC int __init
  1728. xfs_init_caches(void)
  1729. {
  1730. int error;
  1731. xfs_buf_cache = kmem_cache_create("xfs_buf", sizeof(struct xfs_buf), 0,
  1732. SLAB_HWCACHE_ALIGN |
  1733. SLAB_RECLAIM_ACCOUNT |
  1734. SLAB_MEM_SPREAD,
  1735. NULL);
  1736. if (!xfs_buf_cache)
  1737. goto out;
  1738. xfs_log_ticket_cache = kmem_cache_create("xfs_log_ticket",
  1739. sizeof(struct xlog_ticket),
  1740. 0, 0, NULL);
  1741. if (!xfs_log_ticket_cache)
  1742. goto out_destroy_buf_cache;
  1743. error = xfs_btree_init_cur_caches();
  1744. if (error)
  1745. goto out_destroy_log_ticket_cache;
  1746. error = xfs_defer_init_item_caches();
  1747. if (error)
  1748. goto out_destroy_btree_cur_cache;
  1749. xfs_da_state_cache = kmem_cache_create("xfs_da_state",
  1750. sizeof(struct xfs_da_state),
  1751. 0, 0, NULL);
  1752. if (!xfs_da_state_cache)
  1753. goto out_destroy_defer_item_cache;
  1754. xfs_ifork_cache = kmem_cache_create("xfs_ifork",
  1755. sizeof(struct xfs_ifork),
  1756. 0, 0, NULL);
  1757. if (!xfs_ifork_cache)
  1758. goto out_destroy_da_state_cache;
  1759. xfs_trans_cache = kmem_cache_create("xfs_trans",
  1760. sizeof(struct xfs_trans),
  1761. 0, 0, NULL);
  1762. if (!xfs_trans_cache)
  1763. goto out_destroy_ifork_cache;
  1764. /*
  1765. * The size of the cache-allocated buf log item is the maximum
  1766. * size possible under XFS. This wastes a little bit of memory,
  1767. * but it is much faster.
  1768. */
  1769. xfs_buf_item_cache = kmem_cache_create("xfs_buf_item",
  1770. sizeof(struct xfs_buf_log_item),
  1771. 0, 0, NULL);
  1772. if (!xfs_buf_item_cache)
  1773. goto out_destroy_trans_cache;
  1774. xfs_efd_cache = kmem_cache_create("xfs_efd_item",
  1775. xfs_efd_log_item_sizeof(XFS_EFD_MAX_FAST_EXTENTS),
  1776. 0, 0, NULL);
  1777. if (!xfs_efd_cache)
  1778. goto out_destroy_buf_item_cache;
  1779. xfs_efi_cache = kmem_cache_create("xfs_efi_item",
  1780. xfs_efi_log_item_sizeof(XFS_EFI_MAX_FAST_EXTENTS),
  1781. 0, 0, NULL);
  1782. if (!xfs_efi_cache)
  1783. goto out_destroy_efd_cache;
  1784. xfs_inode_cache = kmem_cache_create("xfs_inode",
  1785. sizeof(struct xfs_inode), 0,
  1786. (SLAB_HWCACHE_ALIGN |
  1787. SLAB_RECLAIM_ACCOUNT |
  1788. SLAB_MEM_SPREAD | SLAB_ACCOUNT),
  1789. xfs_fs_inode_init_once);
  1790. if (!xfs_inode_cache)
  1791. goto out_destroy_efi_cache;
  1792. xfs_ili_cache = kmem_cache_create("xfs_ili",
  1793. sizeof(struct xfs_inode_log_item), 0,
  1794. SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
  1795. NULL);
  1796. if (!xfs_ili_cache)
  1797. goto out_destroy_inode_cache;
  1798. xfs_icreate_cache = kmem_cache_create("xfs_icr",
  1799. sizeof(struct xfs_icreate_item),
  1800. 0, 0, NULL);
  1801. if (!xfs_icreate_cache)
  1802. goto out_destroy_ili_cache;
  1803. xfs_rud_cache = kmem_cache_create("xfs_rud_item",
  1804. sizeof(struct xfs_rud_log_item),
  1805. 0, 0, NULL);
  1806. if (!xfs_rud_cache)
  1807. goto out_destroy_icreate_cache;
  1808. xfs_rui_cache = kmem_cache_create("xfs_rui_item",
  1809. xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
  1810. 0, 0, NULL);
  1811. if (!xfs_rui_cache)
  1812. goto out_destroy_rud_cache;
  1813. xfs_cud_cache = kmem_cache_create("xfs_cud_item",
  1814. sizeof(struct xfs_cud_log_item),
  1815. 0, 0, NULL);
  1816. if (!xfs_cud_cache)
  1817. goto out_destroy_rui_cache;
  1818. xfs_cui_cache = kmem_cache_create("xfs_cui_item",
  1819. xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
  1820. 0, 0, NULL);
  1821. if (!xfs_cui_cache)
  1822. goto out_destroy_cud_cache;
  1823. xfs_bud_cache = kmem_cache_create("xfs_bud_item",
  1824. sizeof(struct xfs_bud_log_item),
  1825. 0, 0, NULL);
  1826. if (!xfs_bud_cache)
  1827. goto out_destroy_cui_cache;
  1828. xfs_bui_cache = kmem_cache_create("xfs_bui_item",
  1829. xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
  1830. 0, 0, NULL);
  1831. if (!xfs_bui_cache)
  1832. goto out_destroy_bud_cache;
  1833. xfs_attrd_cache = kmem_cache_create("xfs_attrd_item",
  1834. sizeof(struct xfs_attrd_log_item),
  1835. 0, 0, NULL);
  1836. if (!xfs_attrd_cache)
  1837. goto out_destroy_bui_cache;
  1838. xfs_attri_cache = kmem_cache_create("xfs_attri_item",
  1839. sizeof(struct xfs_attri_log_item),
  1840. 0, 0, NULL);
  1841. if (!xfs_attri_cache)
  1842. goto out_destroy_attrd_cache;
  1843. xfs_iunlink_cache = kmem_cache_create("xfs_iul_item",
  1844. sizeof(struct xfs_iunlink_item),
  1845. 0, 0, NULL);
  1846. if (!xfs_iunlink_cache)
  1847. goto out_destroy_attri_cache;
  1848. return 0;
  1849. out_destroy_attri_cache:
  1850. kmem_cache_destroy(xfs_attri_cache);
  1851. out_destroy_attrd_cache:
  1852. kmem_cache_destroy(xfs_attrd_cache);
  1853. out_destroy_bui_cache:
  1854. kmem_cache_destroy(xfs_bui_cache);
  1855. out_destroy_bud_cache:
  1856. kmem_cache_destroy(xfs_bud_cache);
  1857. out_destroy_cui_cache:
  1858. kmem_cache_destroy(xfs_cui_cache);
  1859. out_destroy_cud_cache:
  1860. kmem_cache_destroy(xfs_cud_cache);
  1861. out_destroy_rui_cache:
  1862. kmem_cache_destroy(xfs_rui_cache);
  1863. out_destroy_rud_cache:
  1864. kmem_cache_destroy(xfs_rud_cache);
  1865. out_destroy_icreate_cache:
  1866. kmem_cache_destroy(xfs_icreate_cache);
  1867. out_destroy_ili_cache:
  1868. kmem_cache_destroy(xfs_ili_cache);
  1869. out_destroy_inode_cache:
  1870. kmem_cache_destroy(xfs_inode_cache);
  1871. out_destroy_efi_cache:
  1872. kmem_cache_destroy(xfs_efi_cache);
  1873. out_destroy_efd_cache:
  1874. kmem_cache_destroy(xfs_efd_cache);
  1875. out_destroy_buf_item_cache:
  1876. kmem_cache_destroy(xfs_buf_item_cache);
  1877. out_destroy_trans_cache:
  1878. kmem_cache_destroy(xfs_trans_cache);
  1879. out_destroy_ifork_cache:
  1880. kmem_cache_destroy(xfs_ifork_cache);
  1881. out_destroy_da_state_cache:
  1882. kmem_cache_destroy(xfs_da_state_cache);
  1883. out_destroy_defer_item_cache:
  1884. xfs_defer_destroy_item_caches();
  1885. out_destroy_btree_cur_cache:
  1886. xfs_btree_destroy_cur_caches();
  1887. out_destroy_log_ticket_cache:
  1888. kmem_cache_destroy(xfs_log_ticket_cache);
  1889. out_destroy_buf_cache:
  1890. kmem_cache_destroy(xfs_buf_cache);
  1891. out:
  1892. return -ENOMEM;
  1893. }
  1894. STATIC void
  1895. xfs_destroy_caches(void)
  1896. {
  1897. /*
  1898. * Make sure all delayed rcu free are flushed before we
  1899. * destroy caches.
  1900. */
  1901. rcu_barrier();
  1902. kmem_cache_destroy(xfs_iunlink_cache);
  1903. kmem_cache_destroy(xfs_attri_cache);
  1904. kmem_cache_destroy(xfs_attrd_cache);
  1905. kmem_cache_destroy(xfs_bui_cache);
  1906. kmem_cache_destroy(xfs_bud_cache);
  1907. kmem_cache_destroy(xfs_cui_cache);
  1908. kmem_cache_destroy(xfs_cud_cache);
  1909. kmem_cache_destroy(xfs_rui_cache);
  1910. kmem_cache_destroy(xfs_rud_cache);
  1911. kmem_cache_destroy(xfs_icreate_cache);
  1912. kmem_cache_destroy(xfs_ili_cache);
  1913. kmem_cache_destroy(xfs_inode_cache);
  1914. kmem_cache_destroy(xfs_efi_cache);
  1915. kmem_cache_destroy(xfs_efd_cache);
  1916. kmem_cache_destroy(xfs_buf_item_cache);
  1917. kmem_cache_destroy(xfs_trans_cache);
  1918. kmem_cache_destroy(xfs_ifork_cache);
  1919. kmem_cache_destroy(xfs_da_state_cache);
  1920. xfs_defer_destroy_item_caches();
  1921. xfs_btree_destroy_cur_caches();
  1922. kmem_cache_destroy(xfs_log_ticket_cache);
  1923. kmem_cache_destroy(xfs_buf_cache);
  1924. }
  1925. STATIC int __init
  1926. xfs_init_workqueues(void)
  1927. {
  1928. /*
  1929. * The allocation workqueue can be used in memory reclaim situations
  1930. * (writepage path), and parallelism is only limited by the number of
  1931. * AGs in all the filesystems mounted. Hence use the default large
  1932. * max_active value for this workqueue.
  1933. */
  1934. xfs_alloc_wq = alloc_workqueue("xfsalloc",
  1935. XFS_WQFLAGS(WQ_MEM_RECLAIM | WQ_FREEZABLE), 0);
  1936. if (!xfs_alloc_wq)
  1937. return -ENOMEM;
  1938. xfs_discard_wq = alloc_workqueue("xfsdiscard", XFS_WQFLAGS(WQ_UNBOUND),
  1939. 0);
  1940. if (!xfs_discard_wq)
  1941. goto out_free_alloc_wq;
  1942. return 0;
  1943. out_free_alloc_wq:
  1944. destroy_workqueue(xfs_alloc_wq);
  1945. return -ENOMEM;
  1946. }
  1947. STATIC void
  1948. xfs_destroy_workqueues(void)
  1949. {
  1950. destroy_workqueue(xfs_discard_wq);
  1951. destroy_workqueue(xfs_alloc_wq);
  1952. }
  1953. #ifdef CONFIG_HOTPLUG_CPU
  1954. static int
  1955. xfs_cpu_dead(
  1956. unsigned int cpu)
  1957. {
  1958. struct xfs_mount *mp, *n;
  1959. spin_lock(&xfs_mount_list_lock);
  1960. list_for_each_entry_safe(mp, n, &xfs_mount_list, m_mount_list) {
  1961. spin_unlock(&xfs_mount_list_lock);
  1962. xfs_inodegc_cpu_dead(mp, cpu);
  1963. xlog_cil_pcp_dead(mp->m_log, cpu);
  1964. spin_lock(&xfs_mount_list_lock);
  1965. }
  1966. spin_unlock(&xfs_mount_list_lock);
  1967. return 0;
  1968. }
  1969. static int __init
  1970. xfs_cpu_hotplug_init(void)
  1971. {
  1972. int error;
  1973. error = cpuhp_setup_state_nocalls(CPUHP_XFS_DEAD, "xfs:dead", NULL,
  1974. xfs_cpu_dead);
  1975. if (error < 0)
  1976. xfs_alert(NULL,
  1977. "Failed to initialise CPU hotplug, error %d. XFS is non-functional.",
  1978. error);
  1979. return error;
  1980. }
  1981. static void
  1982. xfs_cpu_hotplug_destroy(void)
  1983. {
  1984. cpuhp_remove_state_nocalls(CPUHP_XFS_DEAD);
  1985. }
  1986. #else /* !CONFIG_HOTPLUG_CPU */
  1987. static inline int xfs_cpu_hotplug_init(void) { return 0; }
  1988. static inline void xfs_cpu_hotplug_destroy(void) {}
  1989. #endif
  1990. STATIC int __init
  1991. init_xfs_fs(void)
  1992. {
  1993. int error;
  1994. xfs_check_ondisk_structs();
  1995. printk(KERN_INFO XFS_VERSION_STRING " with "
  1996. XFS_BUILD_OPTIONS " enabled\n");
  1997. xfs_dir_startup();
  1998. error = xfs_cpu_hotplug_init();
  1999. if (error)
  2000. goto out;
  2001. error = xfs_init_caches();
  2002. if (error)
  2003. goto out_destroy_hp;
  2004. error = xfs_init_workqueues();
  2005. if (error)
  2006. goto out_destroy_caches;
  2007. error = xfs_mru_cache_init();
  2008. if (error)
  2009. goto out_destroy_wq;
  2010. error = xfs_init_procfs();
  2011. if (error)
  2012. goto out_mru_cache_uninit;
  2013. error = xfs_sysctl_register();
  2014. if (error)
  2015. goto out_cleanup_procfs;
  2016. xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
  2017. if (!xfs_kset) {
  2018. error = -ENOMEM;
  2019. goto out_sysctl_unregister;
  2020. }
  2021. xfsstats.xs_kobj.kobject.kset = xfs_kset;
  2022. xfsstats.xs_stats = alloc_percpu(struct xfsstats);
  2023. if (!xfsstats.xs_stats) {
  2024. error = -ENOMEM;
  2025. goto out_kset_unregister;
  2026. }
  2027. error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
  2028. "stats");
  2029. if (error)
  2030. goto out_free_stats;
  2031. #ifdef DEBUG
  2032. xfs_dbg_kobj.kobject.kset = xfs_kset;
  2033. error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
  2034. if (error)
  2035. goto out_remove_stats_kobj;
  2036. #endif
  2037. error = xfs_qm_init();
  2038. if (error)
  2039. goto out_remove_dbg_kobj;
  2040. error = register_filesystem(&xfs_fs_type);
  2041. if (error)
  2042. goto out_qm_exit;
  2043. return 0;
  2044. out_qm_exit:
  2045. xfs_qm_exit();
  2046. out_remove_dbg_kobj:
  2047. #ifdef DEBUG
  2048. xfs_sysfs_del(&xfs_dbg_kobj);
  2049. out_remove_stats_kobj:
  2050. #endif
  2051. xfs_sysfs_del(&xfsstats.xs_kobj);
  2052. out_free_stats:
  2053. free_percpu(xfsstats.xs_stats);
  2054. out_kset_unregister:
  2055. kset_unregister(xfs_kset);
  2056. out_sysctl_unregister:
  2057. xfs_sysctl_unregister();
  2058. out_cleanup_procfs:
  2059. xfs_cleanup_procfs();
  2060. out_mru_cache_uninit:
  2061. xfs_mru_cache_uninit();
  2062. out_destroy_wq:
  2063. xfs_destroy_workqueues();
  2064. out_destroy_caches:
  2065. xfs_destroy_caches();
  2066. out_destroy_hp:
  2067. xfs_cpu_hotplug_destroy();
  2068. out:
  2069. return error;
  2070. }
  2071. STATIC void __exit
  2072. exit_xfs_fs(void)
  2073. {
  2074. xfs_qm_exit();
  2075. unregister_filesystem(&xfs_fs_type);
  2076. #ifdef DEBUG
  2077. xfs_sysfs_del(&xfs_dbg_kobj);
  2078. #endif
  2079. xfs_sysfs_del(&xfsstats.xs_kobj);
  2080. free_percpu(xfsstats.xs_stats);
  2081. kset_unregister(xfs_kset);
  2082. xfs_sysctl_unregister();
  2083. xfs_cleanup_procfs();
  2084. xfs_mru_cache_uninit();
  2085. xfs_destroy_workqueues();
  2086. xfs_destroy_caches();
  2087. xfs_uuid_table_free();
  2088. xfs_cpu_hotplug_destroy();
  2089. }
  2090. module_init(init_xfs_fs);
  2091. module_exit(exit_xfs_fs);
  2092. MODULE_AUTHOR("Silicon Graphics, Inc.");
  2093. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  2094. MODULE_LICENSE("GPL");