xfs_super.c 49 KB

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