xfs_super.c 47 KB

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