xfs_super.c 49 KB

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