xfs_super.c 47 KB

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