xfs_super.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812
  1. /*
  2. * Copyright (c) 2000-2006 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_log.h"
  20. #include "xfs_inum.h"
  21. #include "xfs_trans.h"
  22. #include "xfs_sb.h"
  23. #include "xfs_ag.h"
  24. #include "xfs_dir2.h"
  25. #include "xfs_alloc.h"
  26. #include "xfs_quota.h"
  27. #include "xfs_mount.h"
  28. #include "xfs_bmap_btree.h"
  29. #include "xfs_alloc_btree.h"
  30. #include "xfs_ialloc_btree.h"
  31. #include "xfs_dinode.h"
  32. #include "xfs_inode.h"
  33. #include "xfs_btree.h"
  34. #include "xfs_ialloc.h"
  35. #include "xfs_bmap.h"
  36. #include "xfs_rtalloc.h"
  37. #include "xfs_error.h"
  38. #include "xfs_itable.h"
  39. #include "xfs_fsops.h"
  40. #include "xfs_attr.h"
  41. #include "xfs_buf_item.h"
  42. #include "xfs_utils.h"
  43. #include "xfs_vnodeops.h"
  44. #include "xfs_log_priv.h"
  45. #include "xfs_trans_priv.h"
  46. #include "xfs_filestream.h"
  47. #include "xfs_da_btree.h"
  48. #include "xfs_extfree_item.h"
  49. #include "xfs_mru_cache.h"
  50. #include "xfs_inode_item.h"
  51. #include "xfs_icache.h"
  52. #include "xfs_trace.h"
  53. #include <linux/namei.h>
  54. #include <linux/init.h>
  55. #include <linux/slab.h>
  56. #include <linux/mount.h>
  57. #include <linux/mempool.h>
  58. #include <linux/writeback.h>
  59. #include <linux/kthread.h>
  60. #include <linux/freezer.h>
  61. #include <linux/parser.h>
  62. static const struct super_operations xfs_super_operations;
  63. static kmem_zone_t *xfs_ioend_zone;
  64. mempool_t *xfs_ioend_pool;
  65. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  66. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  67. #define MNTOPT_LOGDEV "logdev" /* log device */
  68. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  69. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  70. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  71. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  72. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  73. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  74. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  75. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  76. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  77. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  78. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  79. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  80. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  81. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  82. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  83. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  84. * unwritten extent conversion */
  85. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  86. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  87. #define MNTOPT_32BITINODE "inode32" /* inode allocation limited to
  88. * XFS_MAXINUMBER_32 */
  89. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  90. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  91. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  92. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  93. * in stat(). */
  94. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  95. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  96. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  97. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  98. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  99. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  100. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  101. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  102. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  103. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  104. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  105. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  106. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  107. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  108. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  109. #define MNTOPT_DELAYLOG "delaylog" /* Delayed logging enabled */
  110. #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
  111. #define MNTOPT_DISCARD "discard" /* Discard unused blocks */
  112. #define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
  113. /*
  114. * Table driven mount option parser.
  115. *
  116. * Currently only used for remount, but it will be used for mount
  117. * in the future, too.
  118. */
  119. enum {
  120. Opt_barrier,
  121. Opt_nobarrier,
  122. Opt_inode64,
  123. Opt_inode32,
  124. Opt_err
  125. };
  126. static const match_table_t tokens = {
  127. {Opt_barrier, "barrier"},
  128. {Opt_nobarrier, "nobarrier"},
  129. {Opt_inode64, "inode64"},
  130. {Opt_inode32, "inode32"},
  131. {Opt_err, NULL}
  132. };
  133. STATIC unsigned long
  134. suffix_kstrtoint(char *s, unsigned int base, int *res)
  135. {
  136. int last, shift_left_factor = 0, _res;
  137. char *value = s;
  138. last = strlen(value) - 1;
  139. if (value[last] == 'K' || value[last] == 'k') {
  140. shift_left_factor = 10;
  141. value[last] = '\0';
  142. }
  143. if (value[last] == 'M' || value[last] == 'm') {
  144. shift_left_factor = 20;
  145. value[last] = '\0';
  146. }
  147. if (value[last] == 'G' || value[last] == 'g') {
  148. shift_left_factor = 30;
  149. value[last] = '\0';
  150. }
  151. if (kstrtoint(s, base, &_res))
  152. return -EINVAL;
  153. *res = _res << shift_left_factor;
  154. return 0;
  155. }
  156. /*
  157. * This function fills in xfs_mount_t fields based on mount args.
  158. * Note: the superblock has _not_ yet been read in.
  159. *
  160. * Note that this function leaks the various device name allocations on
  161. * failure. The caller takes care of them.
  162. */
  163. STATIC int
  164. xfs_parseargs(
  165. struct xfs_mount *mp,
  166. char *options)
  167. {
  168. struct super_block *sb = mp->m_super;
  169. char *this_char, *value;
  170. int dsunit = 0;
  171. int dswidth = 0;
  172. int iosize = 0;
  173. __uint8_t iosizelog = 0;
  174. /*
  175. * set up the mount name first so all the errors will refer to the
  176. * correct device.
  177. */
  178. mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
  179. if (!mp->m_fsname)
  180. return ENOMEM;
  181. mp->m_fsname_len = strlen(mp->m_fsname) + 1;
  182. /*
  183. * Copy binary VFS mount flags we are interested in.
  184. */
  185. if (sb->s_flags & MS_RDONLY)
  186. mp->m_flags |= XFS_MOUNT_RDONLY;
  187. if (sb->s_flags & MS_DIRSYNC)
  188. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  189. if (sb->s_flags & MS_SYNCHRONOUS)
  190. mp->m_flags |= XFS_MOUNT_WSYNC;
  191. /*
  192. * Set some default flags that could be cleared by the mount option
  193. * parsing.
  194. */
  195. mp->m_flags |= XFS_MOUNT_BARRIER;
  196. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  197. #if !XFS_BIG_INUMS
  198. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  199. #endif
  200. /*
  201. * These can be overridden by the mount option parsing.
  202. */
  203. mp->m_logbufs = -1;
  204. mp->m_logbsize = -1;
  205. if (!options)
  206. goto done;
  207. while ((this_char = strsep(&options, ",")) != NULL) {
  208. if (!*this_char)
  209. continue;
  210. if ((value = strchr(this_char, '=')) != NULL)
  211. *value++ = 0;
  212. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  213. if (!value || !*value) {
  214. xfs_warn(mp, "%s option requires an argument",
  215. this_char);
  216. return EINVAL;
  217. }
  218. if (kstrtoint(value, 10, &mp->m_logbufs))
  219. return EINVAL;
  220. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  221. if (!value || !*value) {
  222. xfs_warn(mp, "%s option requires an argument",
  223. this_char);
  224. return EINVAL;
  225. }
  226. if (suffix_kstrtoint(value, 10, &mp->m_logbsize))
  227. return EINVAL;
  228. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  229. if (!value || !*value) {
  230. xfs_warn(mp, "%s option requires an argument",
  231. this_char);
  232. return EINVAL;
  233. }
  234. mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  235. if (!mp->m_logname)
  236. return ENOMEM;
  237. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  238. xfs_warn(mp, "%s option not allowed on this system",
  239. this_char);
  240. return EINVAL;
  241. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  242. if (!value || !*value) {
  243. xfs_warn(mp, "%s option requires an argument",
  244. this_char);
  245. return EINVAL;
  246. }
  247. mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  248. if (!mp->m_rtname)
  249. return ENOMEM;
  250. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  251. if (!value || !*value) {
  252. xfs_warn(mp, "%s option requires an argument",
  253. this_char);
  254. return EINVAL;
  255. }
  256. if (kstrtoint(value, 10, &iosize))
  257. return EINVAL;
  258. iosizelog = ffs(iosize) - 1;
  259. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  260. if (!value || !*value) {
  261. xfs_warn(mp, "%s option requires an argument",
  262. this_char);
  263. return EINVAL;
  264. }
  265. if (suffix_kstrtoint(value, 10, &iosize))
  266. return EINVAL;
  267. iosizelog = ffs(iosize) - 1;
  268. } else if (!strcmp(this_char, MNTOPT_GRPID) ||
  269. !strcmp(this_char, MNTOPT_BSDGROUPS)) {
  270. mp->m_flags |= XFS_MOUNT_GRPID;
  271. } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
  272. !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
  273. mp->m_flags &= ~XFS_MOUNT_GRPID;
  274. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  275. mp->m_flags |= XFS_MOUNT_WSYNC;
  276. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  277. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  278. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  279. mp->m_flags |= XFS_MOUNT_NOALIGN;
  280. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  281. mp->m_flags |= XFS_MOUNT_SWALLOC;
  282. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  283. if (!value || !*value) {
  284. xfs_warn(mp, "%s option requires an argument",
  285. this_char);
  286. return EINVAL;
  287. }
  288. if (kstrtoint(value, 10, &dsunit))
  289. return EINVAL;
  290. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  291. if (!value || !*value) {
  292. xfs_warn(mp, "%s option requires an argument",
  293. this_char);
  294. return EINVAL;
  295. }
  296. if (kstrtoint(value, 10, &dswidth))
  297. return EINVAL;
  298. } else if (!strcmp(this_char, MNTOPT_32BITINODE)) {
  299. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  300. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  301. mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
  302. #if !XFS_BIG_INUMS
  303. xfs_warn(mp, "%s option not allowed on this system",
  304. this_char);
  305. return EINVAL;
  306. #endif
  307. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  308. mp->m_flags |= XFS_MOUNT_NOUUID;
  309. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  310. mp->m_flags |= XFS_MOUNT_BARRIER;
  311. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  312. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  313. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  314. mp->m_flags |= XFS_MOUNT_IKEEP;
  315. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  316. mp->m_flags &= ~XFS_MOUNT_IKEEP;
  317. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  318. mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
  319. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  320. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  321. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  322. mp->m_flags |= XFS_MOUNT_ATTR2;
  323. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  324. mp->m_flags &= ~XFS_MOUNT_ATTR2;
  325. mp->m_flags |= XFS_MOUNT_NOATTR2;
  326. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  327. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  328. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  329. mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
  330. mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
  331. mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
  332. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  333. !strcmp(this_char, MNTOPT_UQUOTA) ||
  334. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  335. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
  336. XFS_UQUOTA_ENFD);
  337. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  338. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  339. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  340. mp->m_qflags &= ~XFS_UQUOTA_ENFD;
  341. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  342. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  343. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
  344. XFS_OQUOTA_ENFD);
  345. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  346. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  347. mp->m_qflags &= ~XFS_OQUOTA_ENFD;
  348. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  349. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  350. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
  351. XFS_OQUOTA_ENFD);
  352. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  353. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  354. mp->m_qflags &= ~XFS_OQUOTA_ENFD;
  355. } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
  356. xfs_warn(mp,
  357. "delaylog is the default now, option is deprecated.");
  358. } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
  359. xfs_warn(mp,
  360. "nodelaylog support has been removed, option is deprecated.");
  361. } else if (!strcmp(this_char, MNTOPT_DISCARD)) {
  362. mp->m_flags |= XFS_MOUNT_DISCARD;
  363. } else if (!strcmp(this_char, MNTOPT_NODISCARD)) {
  364. mp->m_flags &= ~XFS_MOUNT_DISCARD;
  365. } else if (!strcmp(this_char, "ihashsize")) {
  366. xfs_warn(mp,
  367. "ihashsize no longer used, option is deprecated.");
  368. } else if (!strcmp(this_char, "osyncisdsync")) {
  369. xfs_warn(mp,
  370. "osyncisdsync has no effect, option is deprecated.");
  371. } else if (!strcmp(this_char, "osyncisosync")) {
  372. xfs_warn(mp,
  373. "osyncisosync has no effect, option is deprecated.");
  374. } else if (!strcmp(this_char, "irixsgid")) {
  375. xfs_warn(mp,
  376. "irixsgid is now a sysctl(2) variable, option is deprecated.");
  377. } else {
  378. xfs_warn(mp, "unknown mount option [%s].", this_char);
  379. return EINVAL;
  380. }
  381. }
  382. /*
  383. * no recovery flag requires a read-only mount
  384. */
  385. if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
  386. !(mp->m_flags & XFS_MOUNT_RDONLY)) {
  387. xfs_warn(mp, "no-recovery mounts must be read-only.");
  388. return EINVAL;
  389. }
  390. if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
  391. xfs_warn(mp,
  392. "sunit and swidth options incompatible with the noalign option");
  393. return EINVAL;
  394. }
  395. #ifndef CONFIG_XFS_QUOTA
  396. if (XFS_IS_QUOTA_RUNNING(mp)) {
  397. xfs_warn(mp, "quota support not available in this kernel.");
  398. return EINVAL;
  399. }
  400. #endif
  401. if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
  402. (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
  403. xfs_warn(mp, "cannot mount with both project and group quota");
  404. return EINVAL;
  405. }
  406. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  407. xfs_warn(mp, "sunit and swidth must be specified together");
  408. return EINVAL;
  409. }
  410. if (dsunit && (dswidth % dsunit != 0)) {
  411. xfs_warn(mp,
  412. "stripe width (%d) must be a multiple of the stripe unit (%d)",
  413. dswidth, dsunit);
  414. return EINVAL;
  415. }
  416. done:
  417. if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
  418. /*
  419. * At this point the superblock has not been read
  420. * in, therefore we do not know the block size.
  421. * Before the mount call ends we will convert
  422. * these to FSBs.
  423. */
  424. if (dsunit) {
  425. mp->m_dalign = dsunit;
  426. mp->m_flags |= XFS_MOUNT_RETERR;
  427. }
  428. if (dswidth)
  429. mp->m_swidth = dswidth;
  430. }
  431. if (mp->m_logbufs != -1 &&
  432. mp->m_logbufs != 0 &&
  433. (mp->m_logbufs < XLOG_MIN_ICLOGS ||
  434. mp->m_logbufs > XLOG_MAX_ICLOGS)) {
  435. xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
  436. mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  437. return XFS_ERROR(EINVAL);
  438. }
  439. if (mp->m_logbsize != -1 &&
  440. mp->m_logbsize != 0 &&
  441. (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
  442. mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
  443. !is_power_of_2(mp->m_logbsize))) {
  444. xfs_warn(mp,
  445. "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  446. mp->m_logbsize);
  447. return XFS_ERROR(EINVAL);
  448. }
  449. if (iosizelog) {
  450. if (iosizelog > XFS_MAX_IO_LOG ||
  451. iosizelog < XFS_MIN_IO_LOG) {
  452. xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
  453. iosizelog, XFS_MIN_IO_LOG,
  454. XFS_MAX_IO_LOG);
  455. return XFS_ERROR(EINVAL);
  456. }
  457. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  458. mp->m_readio_log = iosizelog;
  459. mp->m_writeio_log = iosizelog;
  460. }
  461. return 0;
  462. }
  463. struct proc_xfs_info {
  464. int flag;
  465. char *str;
  466. };
  467. STATIC int
  468. xfs_showargs(
  469. struct xfs_mount *mp,
  470. struct seq_file *m)
  471. {
  472. static struct proc_xfs_info xfs_info_set[] = {
  473. /* the few simple ones we can get from the mount struct */
  474. { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
  475. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  476. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  477. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  478. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  479. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  480. { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
  481. { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
  482. { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
  483. { XFS_MOUNT_DISCARD, "," MNTOPT_DISCARD },
  484. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_32BITINODE },
  485. { 0, NULL }
  486. };
  487. static struct proc_xfs_info xfs_info_unset[] = {
  488. /* the few simple ones we can get from the mount struct */
  489. { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
  490. { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
  491. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
  492. { 0, NULL }
  493. };
  494. struct proc_xfs_info *xfs_infop;
  495. for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
  496. if (mp->m_flags & xfs_infop->flag)
  497. seq_puts(m, xfs_infop->str);
  498. }
  499. for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
  500. if (!(mp->m_flags & xfs_infop->flag))
  501. seq_puts(m, xfs_infop->str);
  502. }
  503. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  504. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  505. (int)(1 << mp->m_writeio_log) >> 10);
  506. if (mp->m_logbufs > 0)
  507. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  508. if (mp->m_logbsize > 0)
  509. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  510. if (mp->m_logname)
  511. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  512. if (mp->m_rtname)
  513. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  514. if (mp->m_dalign > 0)
  515. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  516. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  517. if (mp->m_swidth > 0)
  518. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  519. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  520. if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
  521. seq_puts(m, "," MNTOPT_USRQUOTA);
  522. else if (mp->m_qflags & XFS_UQUOTA_ACCT)
  523. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  524. /* Either project or group quotas can be active, not both */
  525. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  526. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  527. seq_puts(m, "," MNTOPT_PRJQUOTA);
  528. else
  529. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  530. } else if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  531. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  532. seq_puts(m, "," MNTOPT_GRPQUOTA);
  533. else
  534. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  535. }
  536. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  537. seq_puts(m, "," MNTOPT_NOQUOTA);
  538. return 0;
  539. }
  540. __uint64_t
  541. xfs_max_file_offset(
  542. unsigned int blockshift)
  543. {
  544. unsigned int pagefactor = 1;
  545. unsigned int bitshift = BITS_PER_LONG - 1;
  546. /* Figure out maximum filesize, on Linux this can depend on
  547. * the filesystem blocksize (on 32 bit platforms).
  548. * __block_write_begin does this in an [unsigned] long...
  549. * page->index << (PAGE_CACHE_SHIFT - bbits)
  550. * So, for page sized blocks (4K on 32 bit platforms),
  551. * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
  552. * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  553. * but for smaller blocksizes it is less (bbits = log2 bsize).
  554. * Note1: get_block_t takes a long (implicit cast from above)
  555. * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
  556. * can optionally convert the [unsigned] long from above into
  557. * an [unsigned] long long.
  558. */
  559. #if BITS_PER_LONG == 32
  560. # if defined(CONFIG_LBDAF)
  561. ASSERT(sizeof(sector_t) == 8);
  562. pagefactor = PAGE_CACHE_SIZE;
  563. bitshift = BITS_PER_LONG;
  564. # else
  565. pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
  566. # endif
  567. #endif
  568. return (((__uint64_t)pagefactor) << bitshift) - 1;
  569. }
  570. xfs_agnumber_t
  571. xfs_set_inode32(struct xfs_mount *mp)
  572. {
  573. xfs_agnumber_t index = 0;
  574. xfs_agnumber_t maxagi = 0;
  575. xfs_sb_t *sbp = &mp->m_sb;
  576. xfs_agnumber_t max_metadata;
  577. xfs_agino_t agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks -1, 0);
  578. xfs_ino_t ino = XFS_AGINO_TO_INO(mp, sbp->sb_agcount -1, agino);
  579. xfs_perag_t *pag;
  580. /* Calculate how much should be reserved for inodes to meet
  581. * the max inode percentage.
  582. */
  583. if (mp->m_maxicount) {
  584. __uint64_t icount;
  585. icount = sbp->sb_dblocks * sbp->sb_imax_pct;
  586. do_div(icount, 100);
  587. icount += sbp->sb_agblocks - 1;
  588. do_div(icount, sbp->sb_agblocks);
  589. max_metadata = icount;
  590. } else {
  591. max_metadata = sbp->sb_agcount;
  592. }
  593. for (index = 0; index < sbp->sb_agcount; index++) {
  594. ino = XFS_AGINO_TO_INO(mp, index, agino);
  595. if (ino > XFS_MAXINUMBER_32) {
  596. pag = xfs_perag_get(mp, index);
  597. pag->pagi_inodeok = 0;
  598. pag->pagf_metadata = 0;
  599. xfs_perag_put(pag);
  600. continue;
  601. }
  602. pag = xfs_perag_get(mp, index);
  603. pag->pagi_inodeok = 1;
  604. maxagi++;
  605. if (index < max_metadata)
  606. pag->pagf_metadata = 1;
  607. xfs_perag_put(pag);
  608. }
  609. mp->m_flags |= (XFS_MOUNT_32BITINODES |
  610. XFS_MOUNT_SMALL_INUMS);
  611. return maxagi;
  612. }
  613. xfs_agnumber_t
  614. xfs_set_inode64(struct xfs_mount *mp)
  615. {
  616. xfs_agnumber_t index = 0;
  617. for (index = 0; index < mp->m_sb.sb_agcount; index++) {
  618. struct xfs_perag *pag;
  619. pag = xfs_perag_get(mp, index);
  620. pag->pagi_inodeok = 1;
  621. pag->pagf_metadata = 0;
  622. xfs_perag_put(pag);
  623. }
  624. /* There is no need for lock protection on m_flags,
  625. * the rw_semaphore of the VFS superblock is locked
  626. * during mount/umount/remount operations, so this is
  627. * enough to avoid concurency on the m_flags field
  628. */
  629. mp->m_flags &= ~(XFS_MOUNT_32BITINODES |
  630. XFS_MOUNT_SMALL_INUMS);
  631. return index;
  632. }
  633. STATIC int
  634. xfs_blkdev_get(
  635. xfs_mount_t *mp,
  636. const char *name,
  637. struct block_device **bdevp)
  638. {
  639. int error = 0;
  640. *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
  641. mp);
  642. if (IS_ERR(*bdevp)) {
  643. error = PTR_ERR(*bdevp);
  644. xfs_warn(mp, "Invalid device [%s], error=%d\n", name, error);
  645. }
  646. return -error;
  647. }
  648. STATIC void
  649. xfs_blkdev_put(
  650. struct block_device *bdev)
  651. {
  652. if (bdev)
  653. blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
  654. }
  655. void
  656. xfs_blkdev_issue_flush(
  657. xfs_buftarg_t *buftarg)
  658. {
  659. blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
  660. }
  661. STATIC void
  662. xfs_close_devices(
  663. struct xfs_mount *mp)
  664. {
  665. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  666. struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
  667. xfs_free_buftarg(mp, mp->m_logdev_targp);
  668. xfs_blkdev_put(logdev);
  669. }
  670. if (mp->m_rtdev_targp) {
  671. struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
  672. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  673. xfs_blkdev_put(rtdev);
  674. }
  675. xfs_free_buftarg(mp, mp->m_ddev_targp);
  676. }
  677. /*
  678. * The file system configurations are:
  679. * (1) device (partition) with data and internal log
  680. * (2) logical volume with data and log subvolumes.
  681. * (3) logical volume with data, log, and realtime subvolumes.
  682. *
  683. * We only have to handle opening the log and realtime volumes here if
  684. * they are present. The data subvolume has already been opened by
  685. * get_sb_bdev() and is stored in sb->s_bdev.
  686. */
  687. STATIC int
  688. xfs_open_devices(
  689. struct xfs_mount *mp)
  690. {
  691. struct block_device *ddev = mp->m_super->s_bdev;
  692. struct block_device *logdev = NULL, *rtdev = NULL;
  693. int error;
  694. /*
  695. * Open real time and log devices - order is important.
  696. */
  697. if (mp->m_logname) {
  698. error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
  699. if (error)
  700. goto out;
  701. }
  702. if (mp->m_rtname) {
  703. error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
  704. if (error)
  705. goto out_close_logdev;
  706. if (rtdev == ddev || rtdev == logdev) {
  707. xfs_warn(mp,
  708. "Cannot mount filesystem with identical rtdev and ddev/logdev.");
  709. error = EINVAL;
  710. goto out_close_rtdev;
  711. }
  712. }
  713. /*
  714. * Setup xfs_mount buffer target pointers
  715. */
  716. error = ENOMEM;
  717. mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, 0, mp->m_fsname);
  718. if (!mp->m_ddev_targp)
  719. goto out_close_rtdev;
  720. if (rtdev) {
  721. mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, 1,
  722. mp->m_fsname);
  723. if (!mp->m_rtdev_targp)
  724. goto out_free_ddev_targ;
  725. }
  726. if (logdev && logdev != ddev) {
  727. mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, 1,
  728. mp->m_fsname);
  729. if (!mp->m_logdev_targp)
  730. goto out_free_rtdev_targ;
  731. } else {
  732. mp->m_logdev_targp = mp->m_ddev_targp;
  733. }
  734. return 0;
  735. out_free_rtdev_targ:
  736. if (mp->m_rtdev_targp)
  737. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  738. out_free_ddev_targ:
  739. xfs_free_buftarg(mp, mp->m_ddev_targp);
  740. out_close_rtdev:
  741. if (rtdev)
  742. xfs_blkdev_put(rtdev);
  743. out_close_logdev:
  744. if (logdev && logdev != ddev)
  745. xfs_blkdev_put(logdev);
  746. out:
  747. return error;
  748. }
  749. /*
  750. * Setup xfs_mount buffer target pointers based on superblock
  751. */
  752. STATIC int
  753. xfs_setup_devices(
  754. struct xfs_mount *mp)
  755. {
  756. int error;
  757. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  758. mp->m_sb.sb_sectsize);
  759. if (error)
  760. return error;
  761. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  762. unsigned int log_sector_size = BBSIZE;
  763. if (xfs_sb_version_hassector(&mp->m_sb))
  764. log_sector_size = mp->m_sb.sb_logsectsize;
  765. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  766. mp->m_sb.sb_blocksize,
  767. log_sector_size);
  768. if (error)
  769. return error;
  770. }
  771. if (mp->m_rtdev_targp) {
  772. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  773. mp->m_sb.sb_blocksize,
  774. mp->m_sb.sb_sectsize);
  775. if (error)
  776. return error;
  777. }
  778. return 0;
  779. }
  780. STATIC int
  781. xfs_init_mount_workqueues(
  782. struct xfs_mount *mp)
  783. {
  784. mp->m_data_workqueue = alloc_workqueue("xfs-data/%s",
  785. WQ_MEM_RECLAIM, 0, mp->m_fsname);
  786. if (!mp->m_data_workqueue)
  787. goto out;
  788. mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
  789. WQ_MEM_RECLAIM, 0, mp->m_fsname);
  790. if (!mp->m_unwritten_workqueue)
  791. goto out_destroy_data_iodone_queue;
  792. mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
  793. WQ_MEM_RECLAIM, 0, mp->m_fsname);
  794. if (!mp->m_cil_workqueue)
  795. goto out_destroy_unwritten;
  796. mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
  797. WQ_NON_REENTRANT, 0, mp->m_fsname);
  798. if (!mp->m_reclaim_workqueue)
  799. goto out_destroy_cil;
  800. mp->m_log_workqueue = alloc_workqueue("xfs-log/%s",
  801. WQ_NON_REENTRANT, 0, mp->m_fsname);
  802. if (!mp->m_log_workqueue)
  803. goto out_destroy_reclaim;
  804. mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
  805. WQ_NON_REENTRANT, 0, mp->m_fsname);
  806. if (!mp->m_eofblocks_workqueue)
  807. goto out_destroy_log;
  808. return 0;
  809. out_destroy_log:
  810. destroy_workqueue(mp->m_log_workqueue);
  811. out_destroy_reclaim:
  812. destroy_workqueue(mp->m_reclaim_workqueue);
  813. out_destroy_cil:
  814. destroy_workqueue(mp->m_cil_workqueue);
  815. out_destroy_unwritten:
  816. destroy_workqueue(mp->m_unwritten_workqueue);
  817. out_destroy_data_iodone_queue:
  818. destroy_workqueue(mp->m_data_workqueue);
  819. out:
  820. return -ENOMEM;
  821. }
  822. STATIC void
  823. xfs_destroy_mount_workqueues(
  824. struct xfs_mount *mp)
  825. {
  826. destroy_workqueue(mp->m_eofblocks_workqueue);
  827. destroy_workqueue(mp->m_log_workqueue);
  828. destroy_workqueue(mp->m_reclaim_workqueue);
  829. destroy_workqueue(mp->m_cil_workqueue);
  830. destroy_workqueue(mp->m_data_workqueue);
  831. destroy_workqueue(mp->m_unwritten_workqueue);
  832. }
  833. /*
  834. * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
  835. * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
  836. * for IO to complete so that we effectively throttle multiple callers to the
  837. * rate at which IO is completing.
  838. */
  839. void
  840. xfs_flush_inodes(
  841. struct xfs_mount *mp)
  842. {
  843. struct super_block *sb = mp->m_super;
  844. if (down_read_trylock(&sb->s_umount)) {
  845. sync_inodes_sb(sb);
  846. up_read(&sb->s_umount);
  847. }
  848. }
  849. /* Catch misguided souls that try to use this interface on XFS */
  850. STATIC struct inode *
  851. xfs_fs_alloc_inode(
  852. struct super_block *sb)
  853. {
  854. BUG();
  855. return NULL;
  856. }
  857. /*
  858. * Now that the generic code is guaranteed not to be accessing
  859. * the linux inode, we can reclaim the inode.
  860. */
  861. STATIC void
  862. xfs_fs_destroy_inode(
  863. struct inode *inode)
  864. {
  865. struct xfs_inode *ip = XFS_I(inode);
  866. trace_xfs_destroy_inode(ip);
  867. XFS_STATS_INC(vn_reclaim);
  868. /* bad inode, get out here ASAP */
  869. if (is_bad_inode(inode))
  870. goto out_reclaim;
  871. ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
  872. /*
  873. * We should never get here with one of the reclaim flags already set.
  874. */
  875. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
  876. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
  877. /*
  878. * We always use background reclaim here because even if the
  879. * inode is clean, it still may be under IO and hence we have
  880. * to take the flush lock. The background reclaim path handles
  881. * this more efficiently than we can here, so simply let background
  882. * reclaim tear down all inodes.
  883. */
  884. out_reclaim:
  885. xfs_inode_set_reclaim_tag(ip);
  886. }
  887. /*
  888. * Slab object creation initialisation for the XFS inode.
  889. * This covers only the idempotent fields in the XFS inode;
  890. * all other fields need to be initialised on allocation
  891. * from the slab. This avoids the need to repeatedly initialise
  892. * fields in the xfs inode that left in the initialise state
  893. * when freeing the inode.
  894. */
  895. STATIC void
  896. xfs_fs_inode_init_once(
  897. void *inode)
  898. {
  899. struct xfs_inode *ip = inode;
  900. memset(ip, 0, sizeof(struct xfs_inode));
  901. /* vfs inode */
  902. inode_init_once(VFS_I(ip));
  903. /* xfs inode */
  904. atomic_set(&ip->i_pincount, 0);
  905. spin_lock_init(&ip->i_flags_lock);
  906. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  907. "xfsino", ip->i_ino);
  908. }
  909. STATIC void
  910. xfs_fs_evict_inode(
  911. struct inode *inode)
  912. {
  913. xfs_inode_t *ip = XFS_I(inode);
  914. ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
  915. trace_xfs_evict_inode(ip);
  916. truncate_inode_pages(&inode->i_data, 0);
  917. clear_inode(inode);
  918. XFS_STATS_INC(vn_rele);
  919. XFS_STATS_INC(vn_remove);
  920. XFS_STATS_DEC(vn_active);
  921. xfs_inactive(ip);
  922. }
  923. /*
  924. * We do an unlocked check for XFS_IDONTCACHE here because we are already
  925. * serialised against cache hits here via the inode->i_lock and igrab() in
  926. * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
  927. * racing with us, and it avoids needing to grab a spinlock here for every inode
  928. * we drop the final reference on.
  929. */
  930. STATIC int
  931. xfs_fs_drop_inode(
  932. struct inode *inode)
  933. {
  934. struct xfs_inode *ip = XFS_I(inode);
  935. return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
  936. }
  937. STATIC void
  938. xfs_free_fsname(
  939. struct xfs_mount *mp)
  940. {
  941. kfree(mp->m_fsname);
  942. kfree(mp->m_rtname);
  943. kfree(mp->m_logname);
  944. }
  945. STATIC void
  946. xfs_fs_put_super(
  947. struct super_block *sb)
  948. {
  949. struct xfs_mount *mp = XFS_M(sb);
  950. xfs_filestream_unmount(mp);
  951. xfs_unmountfs(mp);
  952. xfs_freesb(mp);
  953. xfs_icsb_destroy_counters(mp);
  954. xfs_destroy_mount_workqueues(mp);
  955. xfs_close_devices(mp);
  956. xfs_free_fsname(mp);
  957. kfree(mp);
  958. }
  959. STATIC int
  960. xfs_fs_sync_fs(
  961. struct super_block *sb,
  962. int wait)
  963. {
  964. struct xfs_mount *mp = XFS_M(sb);
  965. /*
  966. * Doing anything during the async pass would be counterproductive.
  967. */
  968. if (!wait)
  969. return 0;
  970. xfs_log_force(mp, XFS_LOG_SYNC);
  971. if (laptop_mode) {
  972. /*
  973. * The disk must be active because we're syncing.
  974. * We schedule log work now (now that the disk is
  975. * active) instead of later (when it might not be).
  976. */
  977. flush_delayed_work(&mp->m_log->l_work);
  978. }
  979. return 0;
  980. }
  981. STATIC int
  982. xfs_fs_statfs(
  983. struct dentry *dentry,
  984. struct kstatfs *statp)
  985. {
  986. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  987. xfs_sb_t *sbp = &mp->m_sb;
  988. struct xfs_inode *ip = XFS_I(dentry->d_inode);
  989. __uint64_t fakeinos, id;
  990. xfs_extlen_t lsize;
  991. __int64_t ffree;
  992. statp->f_type = XFS_SB_MAGIC;
  993. statp->f_namelen = MAXNAMELEN - 1;
  994. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  995. statp->f_fsid.val[0] = (u32)id;
  996. statp->f_fsid.val[1] = (u32)(id >> 32);
  997. xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
  998. spin_lock(&mp->m_sb_lock);
  999. statp->f_bsize = sbp->sb_blocksize;
  1000. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  1001. statp->f_blocks = sbp->sb_dblocks - lsize;
  1002. statp->f_bfree = statp->f_bavail =
  1003. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  1004. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  1005. statp->f_files =
  1006. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  1007. if (mp->m_maxicount)
  1008. statp->f_files = min_t(typeof(statp->f_files),
  1009. statp->f_files,
  1010. mp->m_maxicount);
  1011. /* make sure statp->f_ffree does not underflow */
  1012. ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  1013. statp->f_ffree = max_t(__int64_t, ffree, 0);
  1014. spin_unlock(&mp->m_sb_lock);
  1015. if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
  1016. ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))) ==
  1017. (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
  1018. xfs_qm_statvfs(ip, statp);
  1019. return 0;
  1020. }
  1021. STATIC void
  1022. xfs_save_resvblks(struct xfs_mount *mp)
  1023. {
  1024. __uint64_t resblks = 0;
  1025. mp->m_resblks_save = mp->m_resblks;
  1026. xfs_reserve_blocks(mp, &resblks, NULL);
  1027. }
  1028. STATIC void
  1029. xfs_restore_resvblks(struct xfs_mount *mp)
  1030. {
  1031. __uint64_t resblks;
  1032. if (mp->m_resblks_save) {
  1033. resblks = mp->m_resblks_save;
  1034. mp->m_resblks_save = 0;
  1035. } else
  1036. resblks = xfs_default_resblks(mp);
  1037. xfs_reserve_blocks(mp, &resblks, NULL);
  1038. }
  1039. /*
  1040. * Trigger writeback of all the dirty metadata in the file system.
  1041. *
  1042. * This ensures that the metadata is written to their location on disk rather
  1043. * than just existing in transactions in the log. This means after a quiesce
  1044. * there is no log replay required to write the inodes to disk - this is the
  1045. * primary difference between a sync and a quiesce.
  1046. *
  1047. * Note: xfs_log_quiesce() stops background log work - the callers must ensure
  1048. * it is started again when appropriate.
  1049. */
  1050. void
  1051. xfs_quiesce_attr(
  1052. struct xfs_mount *mp)
  1053. {
  1054. int error = 0;
  1055. /* wait for all modifications to complete */
  1056. while (atomic_read(&mp->m_active_trans) > 0)
  1057. delay(100);
  1058. /* force the log to unpin objects from the now complete transactions */
  1059. xfs_log_force(mp, XFS_LOG_SYNC);
  1060. /* reclaim inodes to do any IO before the freeze completes */
  1061. xfs_reclaim_inodes(mp, 0);
  1062. xfs_reclaim_inodes(mp, SYNC_WAIT);
  1063. /* Push the superblock and write an unmount record */
  1064. error = xfs_log_sbcount(mp);
  1065. if (error)
  1066. xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
  1067. "Frozen image may not be consistent.");
  1068. /*
  1069. * Just warn here till VFS can correctly support
  1070. * read-only remount without racing.
  1071. */
  1072. WARN_ON(atomic_read(&mp->m_active_trans) != 0);
  1073. xfs_log_quiesce(mp);
  1074. }
  1075. STATIC int
  1076. xfs_fs_remount(
  1077. struct super_block *sb,
  1078. int *flags,
  1079. char *options)
  1080. {
  1081. struct xfs_mount *mp = XFS_M(sb);
  1082. substring_t args[MAX_OPT_ARGS];
  1083. char *p;
  1084. int error;
  1085. while ((p = strsep(&options, ",")) != NULL) {
  1086. int token;
  1087. if (!*p)
  1088. continue;
  1089. token = match_token(p, tokens, args);
  1090. switch (token) {
  1091. case Opt_barrier:
  1092. mp->m_flags |= XFS_MOUNT_BARRIER;
  1093. break;
  1094. case Opt_nobarrier:
  1095. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1096. break;
  1097. case Opt_inode64:
  1098. mp->m_maxagi = xfs_set_inode64(mp);
  1099. break;
  1100. case Opt_inode32:
  1101. mp->m_maxagi = xfs_set_inode32(mp);
  1102. break;
  1103. default:
  1104. /*
  1105. * Logically we would return an error here to prevent
  1106. * users from believing they might have changed
  1107. * mount options using remount which can't be changed.
  1108. *
  1109. * But unfortunately mount(8) adds all options from
  1110. * mtab and fstab to the mount arguments in some cases
  1111. * so we can't blindly reject options, but have to
  1112. * check for each specified option if it actually
  1113. * differs from the currently set option and only
  1114. * reject it if that's the case.
  1115. *
  1116. * Until that is implemented we return success for
  1117. * every remount request, and silently ignore all
  1118. * options that we can't actually change.
  1119. */
  1120. #if 0
  1121. xfs_info(mp,
  1122. "mount option \"%s\" not supported for remount\n", p);
  1123. return -EINVAL;
  1124. #else
  1125. break;
  1126. #endif
  1127. }
  1128. }
  1129. /* ro -> rw */
  1130. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1131. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1132. /*
  1133. * If this is the first remount to writeable state we
  1134. * might have some superblock changes to update.
  1135. */
  1136. if (mp->m_update_flags) {
  1137. error = xfs_mount_log_sb(mp, mp->m_update_flags);
  1138. if (error) {
  1139. xfs_warn(mp, "failed to write sb changes");
  1140. return error;
  1141. }
  1142. mp->m_update_flags = 0;
  1143. }
  1144. /*
  1145. * Fill out the reserve pool if it is empty. Use the stashed
  1146. * value if it is non-zero, otherwise go with the default.
  1147. */
  1148. xfs_restore_resvblks(mp);
  1149. xfs_log_work_queue(mp);
  1150. }
  1151. /* rw -> ro */
  1152. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1153. /*
  1154. * Before we sync the metadata, we need to free up the reserve
  1155. * block pool so that the used block count in the superblock on
  1156. * disk is correct at the end of the remount. Stash the current
  1157. * reserve pool size so that if we get remounted rw, we can
  1158. * return it to the same size.
  1159. */
  1160. xfs_save_resvblks(mp);
  1161. xfs_quiesce_attr(mp);
  1162. mp->m_flags |= XFS_MOUNT_RDONLY;
  1163. }
  1164. return 0;
  1165. }
  1166. /*
  1167. * Second stage of a freeze. The data is already frozen so we only
  1168. * need to take care of the metadata. Once that's done write a dummy
  1169. * record to dirty the log in case of a crash while frozen.
  1170. */
  1171. STATIC int
  1172. xfs_fs_freeze(
  1173. struct super_block *sb)
  1174. {
  1175. struct xfs_mount *mp = XFS_M(sb);
  1176. xfs_save_resvblks(mp);
  1177. xfs_quiesce_attr(mp);
  1178. return -xfs_fs_log_dummy(mp);
  1179. }
  1180. STATIC int
  1181. xfs_fs_unfreeze(
  1182. struct super_block *sb)
  1183. {
  1184. struct xfs_mount *mp = XFS_M(sb);
  1185. xfs_restore_resvblks(mp);
  1186. xfs_log_work_queue(mp);
  1187. return 0;
  1188. }
  1189. STATIC int
  1190. xfs_fs_show_options(
  1191. struct seq_file *m,
  1192. struct dentry *root)
  1193. {
  1194. return -xfs_showargs(XFS_M(root->d_sb), m);
  1195. }
  1196. /*
  1197. * This function fills in xfs_mount_t fields based on mount args.
  1198. * Note: the superblock _has_ now been read in.
  1199. */
  1200. STATIC int
  1201. xfs_finish_flags(
  1202. struct xfs_mount *mp)
  1203. {
  1204. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1205. /* Fail a mount where the logbuf is smaller than the log stripe */
  1206. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1207. if (mp->m_logbsize <= 0 &&
  1208. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  1209. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1210. } else if (mp->m_logbsize > 0 &&
  1211. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  1212. xfs_warn(mp,
  1213. "logbuf size must be greater than or equal to log stripe size");
  1214. return XFS_ERROR(EINVAL);
  1215. }
  1216. } else {
  1217. /* Fail a mount if the logbuf is larger than 32K */
  1218. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  1219. xfs_warn(mp,
  1220. "logbuf size for version 1 logs must be 16K or 32K");
  1221. return XFS_ERROR(EINVAL);
  1222. }
  1223. }
  1224. /*
  1225. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1226. * told by noattr2 to turn it off
  1227. */
  1228. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1229. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  1230. mp->m_flags |= XFS_MOUNT_ATTR2;
  1231. /*
  1232. * prohibit r/w mounts of read-only filesystems
  1233. */
  1234. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1235. xfs_warn(mp,
  1236. "cannot mount a read-only filesystem as read-write");
  1237. return XFS_ERROR(EROFS);
  1238. }
  1239. return 0;
  1240. }
  1241. STATIC int
  1242. xfs_fs_fill_super(
  1243. struct super_block *sb,
  1244. void *data,
  1245. int silent)
  1246. {
  1247. struct inode *root;
  1248. struct xfs_mount *mp = NULL;
  1249. int flags = 0, error = ENOMEM;
  1250. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1251. if (!mp)
  1252. goto out;
  1253. spin_lock_init(&mp->m_sb_lock);
  1254. mutex_init(&mp->m_growlock);
  1255. atomic_set(&mp->m_active_trans, 0);
  1256. INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
  1257. INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
  1258. mp->m_super = sb;
  1259. sb->s_fs_info = mp;
  1260. error = xfs_parseargs(mp, (char *)data);
  1261. if (error)
  1262. goto out_free_fsname;
  1263. sb_min_blocksize(sb, BBSIZE);
  1264. sb->s_xattr = xfs_xattr_handlers;
  1265. sb->s_export_op = &xfs_export_operations;
  1266. #ifdef CONFIG_XFS_QUOTA
  1267. sb->s_qcop = &xfs_quotactl_operations;
  1268. #endif
  1269. sb->s_op = &xfs_super_operations;
  1270. if (silent)
  1271. flags |= XFS_MFSI_QUIET;
  1272. error = xfs_open_devices(mp);
  1273. if (error)
  1274. goto out_free_fsname;
  1275. error = xfs_init_mount_workqueues(mp);
  1276. if (error)
  1277. goto out_close_devices;
  1278. error = xfs_icsb_init_counters(mp);
  1279. if (error)
  1280. goto out_destroy_workqueues;
  1281. error = xfs_readsb(mp, flags);
  1282. if (error)
  1283. goto out_destroy_counters;
  1284. error = xfs_finish_flags(mp);
  1285. if (error)
  1286. goto out_free_sb;
  1287. error = xfs_setup_devices(mp);
  1288. if (error)
  1289. goto out_free_sb;
  1290. error = xfs_filestream_mount(mp);
  1291. if (error)
  1292. goto out_free_sb;
  1293. /*
  1294. * we must configure the block size in the superblock before we run the
  1295. * full mount process as the mount process can lookup and cache inodes.
  1296. */
  1297. sb->s_magic = XFS_SB_MAGIC;
  1298. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1299. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1300. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1301. sb->s_max_links = XFS_MAXLINK;
  1302. sb->s_time_gran = 1;
  1303. set_posix_acl_flag(sb);
  1304. error = xfs_mountfs(mp);
  1305. if (error)
  1306. goto out_filestream_unmount;
  1307. root = igrab(VFS_I(mp->m_rootip));
  1308. if (!root) {
  1309. error = ENOENT;
  1310. goto out_unmount;
  1311. }
  1312. if (is_bad_inode(root)) {
  1313. error = EINVAL;
  1314. goto out_unmount;
  1315. }
  1316. sb->s_root = d_make_root(root);
  1317. if (!sb->s_root) {
  1318. error = ENOMEM;
  1319. goto out_unmount;
  1320. }
  1321. return 0;
  1322. out_filestream_unmount:
  1323. xfs_filestream_unmount(mp);
  1324. out_free_sb:
  1325. xfs_freesb(mp);
  1326. out_destroy_counters:
  1327. xfs_icsb_destroy_counters(mp);
  1328. out_destroy_workqueues:
  1329. xfs_destroy_mount_workqueues(mp);
  1330. out_close_devices:
  1331. xfs_close_devices(mp);
  1332. out_free_fsname:
  1333. xfs_free_fsname(mp);
  1334. kfree(mp);
  1335. out:
  1336. return -error;
  1337. out_unmount:
  1338. xfs_filestream_unmount(mp);
  1339. xfs_unmountfs(mp);
  1340. goto out_free_sb;
  1341. }
  1342. STATIC struct dentry *
  1343. xfs_fs_mount(
  1344. struct file_system_type *fs_type,
  1345. int flags,
  1346. const char *dev_name,
  1347. void *data)
  1348. {
  1349. return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
  1350. }
  1351. static int
  1352. xfs_fs_nr_cached_objects(
  1353. struct super_block *sb)
  1354. {
  1355. return xfs_reclaim_inodes_count(XFS_M(sb));
  1356. }
  1357. static void
  1358. xfs_fs_free_cached_objects(
  1359. struct super_block *sb,
  1360. int nr_to_scan)
  1361. {
  1362. xfs_reclaim_inodes_nr(XFS_M(sb), nr_to_scan);
  1363. }
  1364. static const struct super_operations xfs_super_operations = {
  1365. .alloc_inode = xfs_fs_alloc_inode,
  1366. .destroy_inode = xfs_fs_destroy_inode,
  1367. .evict_inode = xfs_fs_evict_inode,
  1368. .drop_inode = xfs_fs_drop_inode,
  1369. .put_super = xfs_fs_put_super,
  1370. .sync_fs = xfs_fs_sync_fs,
  1371. .freeze_fs = xfs_fs_freeze,
  1372. .unfreeze_fs = xfs_fs_unfreeze,
  1373. .statfs = xfs_fs_statfs,
  1374. .remount_fs = xfs_fs_remount,
  1375. .show_options = xfs_fs_show_options,
  1376. .nr_cached_objects = xfs_fs_nr_cached_objects,
  1377. .free_cached_objects = xfs_fs_free_cached_objects,
  1378. };
  1379. static struct file_system_type xfs_fs_type = {
  1380. .owner = THIS_MODULE,
  1381. .name = "xfs",
  1382. .mount = xfs_fs_mount,
  1383. .kill_sb = kill_block_super,
  1384. .fs_flags = FS_REQUIRES_DEV,
  1385. };
  1386. STATIC int __init
  1387. xfs_init_zones(void)
  1388. {
  1389. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  1390. if (!xfs_ioend_zone)
  1391. goto out;
  1392. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  1393. xfs_ioend_zone);
  1394. if (!xfs_ioend_pool)
  1395. goto out_destroy_ioend_zone;
  1396. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1397. "xfs_log_ticket");
  1398. if (!xfs_log_ticket_zone)
  1399. goto out_destroy_ioend_pool;
  1400. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  1401. "xfs_bmap_free_item");
  1402. if (!xfs_bmap_free_item_zone)
  1403. goto out_destroy_log_ticket_zone;
  1404. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1405. "xfs_btree_cur");
  1406. if (!xfs_btree_cur_zone)
  1407. goto out_destroy_bmap_free_item_zone;
  1408. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1409. "xfs_da_state");
  1410. if (!xfs_da_state_zone)
  1411. goto out_destroy_btree_cur_zone;
  1412. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1413. if (!xfs_ifork_zone)
  1414. goto out_destroy_da_state_zone;
  1415. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1416. if (!xfs_trans_zone)
  1417. goto out_destroy_ifork_zone;
  1418. xfs_log_item_desc_zone =
  1419. kmem_zone_init(sizeof(struct xfs_log_item_desc),
  1420. "xfs_log_item_desc");
  1421. if (!xfs_log_item_desc_zone)
  1422. goto out_destroy_trans_zone;
  1423. /*
  1424. * The size of the zone allocated buf log item is the maximum
  1425. * size possible under XFS. This wastes a little bit of memory,
  1426. * but it is much faster.
  1427. */
  1428. xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
  1429. "xfs_buf_item");
  1430. if (!xfs_buf_item_zone)
  1431. goto out_destroy_log_item_desc_zone;
  1432. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1433. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1434. sizeof(xfs_extent_t))), "xfs_efd_item");
  1435. if (!xfs_efd_zone)
  1436. goto out_destroy_buf_item_zone;
  1437. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1438. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1439. sizeof(xfs_extent_t))), "xfs_efi_item");
  1440. if (!xfs_efi_zone)
  1441. goto out_destroy_efd_zone;
  1442. xfs_inode_zone =
  1443. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1444. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
  1445. xfs_fs_inode_init_once);
  1446. if (!xfs_inode_zone)
  1447. goto out_destroy_efi_zone;
  1448. xfs_ili_zone =
  1449. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1450. KM_ZONE_SPREAD, NULL);
  1451. if (!xfs_ili_zone)
  1452. goto out_destroy_inode_zone;
  1453. return 0;
  1454. out_destroy_inode_zone:
  1455. kmem_zone_destroy(xfs_inode_zone);
  1456. out_destroy_efi_zone:
  1457. kmem_zone_destroy(xfs_efi_zone);
  1458. out_destroy_efd_zone:
  1459. kmem_zone_destroy(xfs_efd_zone);
  1460. out_destroy_buf_item_zone:
  1461. kmem_zone_destroy(xfs_buf_item_zone);
  1462. out_destroy_log_item_desc_zone:
  1463. kmem_zone_destroy(xfs_log_item_desc_zone);
  1464. out_destroy_trans_zone:
  1465. kmem_zone_destroy(xfs_trans_zone);
  1466. out_destroy_ifork_zone:
  1467. kmem_zone_destroy(xfs_ifork_zone);
  1468. out_destroy_da_state_zone:
  1469. kmem_zone_destroy(xfs_da_state_zone);
  1470. out_destroy_btree_cur_zone:
  1471. kmem_zone_destroy(xfs_btree_cur_zone);
  1472. out_destroy_bmap_free_item_zone:
  1473. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1474. out_destroy_log_ticket_zone:
  1475. kmem_zone_destroy(xfs_log_ticket_zone);
  1476. out_destroy_ioend_pool:
  1477. mempool_destroy(xfs_ioend_pool);
  1478. out_destroy_ioend_zone:
  1479. kmem_zone_destroy(xfs_ioend_zone);
  1480. out:
  1481. return -ENOMEM;
  1482. }
  1483. STATIC void
  1484. xfs_destroy_zones(void)
  1485. {
  1486. /*
  1487. * Make sure all delayed rcu free are flushed before we
  1488. * destroy caches.
  1489. */
  1490. rcu_barrier();
  1491. kmem_zone_destroy(xfs_ili_zone);
  1492. kmem_zone_destroy(xfs_inode_zone);
  1493. kmem_zone_destroy(xfs_efi_zone);
  1494. kmem_zone_destroy(xfs_efd_zone);
  1495. kmem_zone_destroy(xfs_buf_item_zone);
  1496. kmem_zone_destroy(xfs_log_item_desc_zone);
  1497. kmem_zone_destroy(xfs_trans_zone);
  1498. kmem_zone_destroy(xfs_ifork_zone);
  1499. kmem_zone_destroy(xfs_da_state_zone);
  1500. kmem_zone_destroy(xfs_btree_cur_zone);
  1501. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1502. kmem_zone_destroy(xfs_log_ticket_zone);
  1503. mempool_destroy(xfs_ioend_pool);
  1504. kmem_zone_destroy(xfs_ioend_zone);
  1505. }
  1506. STATIC int __init
  1507. xfs_init_workqueues(void)
  1508. {
  1509. /*
  1510. * The allocation workqueue can be used in memory reclaim situations
  1511. * (writepage path), and parallelism is only limited by the number of
  1512. * AGs in all the filesystems mounted. Hence use the default large
  1513. * max_active value for this workqueue.
  1514. */
  1515. xfs_alloc_wq = alloc_workqueue("xfsalloc", WQ_MEM_RECLAIM, 0);
  1516. if (!xfs_alloc_wq)
  1517. return -ENOMEM;
  1518. return 0;
  1519. }
  1520. STATIC void
  1521. xfs_destroy_workqueues(void)
  1522. {
  1523. destroy_workqueue(xfs_alloc_wq);
  1524. }
  1525. STATIC int __init
  1526. init_xfs_fs(void)
  1527. {
  1528. int error;
  1529. printk(KERN_INFO XFS_VERSION_STRING " with "
  1530. XFS_BUILD_OPTIONS " enabled\n");
  1531. xfs_dir_startup();
  1532. error = xfs_init_zones();
  1533. if (error)
  1534. goto out;
  1535. error = xfs_init_workqueues();
  1536. if (error)
  1537. goto out_destroy_zones;
  1538. error = xfs_mru_cache_init();
  1539. if (error)
  1540. goto out_destroy_wq;
  1541. error = xfs_filestream_init();
  1542. if (error)
  1543. goto out_mru_cache_uninit;
  1544. error = xfs_buf_init();
  1545. if (error)
  1546. goto out_filestream_uninit;
  1547. error = xfs_init_procfs();
  1548. if (error)
  1549. goto out_buf_terminate;
  1550. error = xfs_sysctl_register();
  1551. if (error)
  1552. goto out_cleanup_procfs;
  1553. error = xfs_qm_init();
  1554. if (error)
  1555. goto out_sysctl_unregister;
  1556. error = register_filesystem(&xfs_fs_type);
  1557. if (error)
  1558. goto out_qm_exit;
  1559. return 0;
  1560. out_qm_exit:
  1561. xfs_qm_exit();
  1562. out_sysctl_unregister:
  1563. xfs_sysctl_unregister();
  1564. out_cleanup_procfs:
  1565. xfs_cleanup_procfs();
  1566. out_buf_terminate:
  1567. xfs_buf_terminate();
  1568. out_filestream_uninit:
  1569. xfs_filestream_uninit();
  1570. out_mru_cache_uninit:
  1571. xfs_mru_cache_uninit();
  1572. out_destroy_wq:
  1573. xfs_destroy_workqueues();
  1574. out_destroy_zones:
  1575. xfs_destroy_zones();
  1576. out:
  1577. return error;
  1578. }
  1579. STATIC void __exit
  1580. exit_xfs_fs(void)
  1581. {
  1582. xfs_qm_exit();
  1583. unregister_filesystem(&xfs_fs_type);
  1584. xfs_sysctl_unregister();
  1585. xfs_cleanup_procfs();
  1586. xfs_buf_terminate();
  1587. xfs_filestream_uninit();
  1588. xfs_mru_cache_uninit();
  1589. xfs_destroy_workqueues();
  1590. xfs_destroy_zones();
  1591. }
  1592. module_init(init_xfs_fs);
  1593. module_exit(exit_xfs_fs);
  1594. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1595. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1596. MODULE_LICENSE("GPL");