xfs_super.c 46 KB

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