xfs_super.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  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 = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
  563. if (IS_ERR(*bdevp)) {
  564. error = PTR_ERR(*bdevp);
  565. printk("XFS: Invalid device [%s], error=%d\n", name, error);
  566. }
  567. return -error;
  568. }
  569. STATIC void
  570. xfs_blkdev_put(
  571. struct block_device *bdev)
  572. {
  573. if (bdev)
  574. close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
  575. }
  576. /*
  577. * Try to write out the superblock using barriers.
  578. */
  579. STATIC int
  580. xfs_barrier_test(
  581. xfs_mount_t *mp)
  582. {
  583. xfs_buf_t *sbp = xfs_getsb(mp, 0);
  584. int error;
  585. XFS_BUF_UNDONE(sbp);
  586. XFS_BUF_UNREAD(sbp);
  587. XFS_BUF_UNDELAYWRITE(sbp);
  588. XFS_BUF_WRITE(sbp);
  589. XFS_BUF_UNASYNC(sbp);
  590. XFS_BUF_ORDERED(sbp);
  591. xfsbdstrat(mp, sbp);
  592. error = xfs_buf_iowait(sbp);
  593. /*
  594. * Clear all the flags we set and possible error state in the
  595. * buffer. We only did the write to try out whether barriers
  596. * worked and shouldn't leave any traces in the superblock
  597. * buffer.
  598. */
  599. XFS_BUF_DONE(sbp);
  600. XFS_BUF_ERROR(sbp, 0);
  601. XFS_BUF_UNORDERED(sbp);
  602. xfs_buf_relse(sbp);
  603. return error;
  604. }
  605. STATIC void
  606. xfs_mountfs_check_barriers(xfs_mount_t *mp)
  607. {
  608. int error;
  609. if (mp->m_logdev_targp != mp->m_ddev_targp) {
  610. xfs_fs_cmn_err(CE_NOTE, mp,
  611. "Disabling barriers, not supported with external log device");
  612. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  613. return;
  614. }
  615. if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
  616. xfs_fs_cmn_err(CE_NOTE, mp,
  617. "Disabling barriers, underlying device is readonly");
  618. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  619. return;
  620. }
  621. error = xfs_barrier_test(mp);
  622. if (error) {
  623. xfs_fs_cmn_err(CE_NOTE, mp,
  624. "Disabling barriers, trial barrier write failed");
  625. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  626. return;
  627. }
  628. }
  629. void
  630. xfs_blkdev_issue_flush(
  631. xfs_buftarg_t *buftarg)
  632. {
  633. blkdev_issue_flush(buftarg->bt_bdev, GFP_KERNEL, NULL);
  634. }
  635. STATIC void
  636. xfs_close_devices(
  637. struct xfs_mount *mp)
  638. {
  639. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  640. struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
  641. xfs_free_buftarg(mp, mp->m_logdev_targp);
  642. xfs_blkdev_put(logdev);
  643. }
  644. if (mp->m_rtdev_targp) {
  645. struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
  646. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  647. xfs_blkdev_put(rtdev);
  648. }
  649. xfs_free_buftarg(mp, mp->m_ddev_targp);
  650. }
  651. /*
  652. * The file system configurations are:
  653. * (1) device (partition) with data and internal log
  654. * (2) logical volume with data and log subvolumes.
  655. * (3) logical volume with data, log, and realtime subvolumes.
  656. *
  657. * We only have to handle opening the log and realtime volumes here if
  658. * they are present. The data subvolume has already been opened by
  659. * get_sb_bdev() and is stored in sb->s_bdev.
  660. */
  661. STATIC int
  662. xfs_open_devices(
  663. struct xfs_mount *mp)
  664. {
  665. struct block_device *ddev = mp->m_super->s_bdev;
  666. struct block_device *logdev = NULL, *rtdev = NULL;
  667. int error;
  668. /*
  669. * Open real time and log devices - order is important.
  670. */
  671. if (mp->m_logname) {
  672. error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
  673. if (error)
  674. goto out;
  675. }
  676. if (mp->m_rtname) {
  677. error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
  678. if (error)
  679. goto out_close_logdev;
  680. if (rtdev == ddev || rtdev == logdev) {
  681. cmn_err(CE_WARN,
  682. "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
  683. error = EINVAL;
  684. goto out_close_rtdev;
  685. }
  686. }
  687. /*
  688. * Setup xfs_mount buffer target pointers
  689. */
  690. error = ENOMEM;
  691. mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, 0, mp->m_fsname);
  692. if (!mp->m_ddev_targp)
  693. goto out_close_rtdev;
  694. if (rtdev) {
  695. mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, 1,
  696. mp->m_fsname);
  697. if (!mp->m_rtdev_targp)
  698. goto out_free_ddev_targ;
  699. }
  700. if (logdev && logdev != ddev) {
  701. mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, 1,
  702. mp->m_fsname);
  703. if (!mp->m_logdev_targp)
  704. goto out_free_rtdev_targ;
  705. } else {
  706. mp->m_logdev_targp = mp->m_ddev_targp;
  707. }
  708. return 0;
  709. out_free_rtdev_targ:
  710. if (mp->m_rtdev_targp)
  711. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  712. out_free_ddev_targ:
  713. xfs_free_buftarg(mp, mp->m_ddev_targp);
  714. out_close_rtdev:
  715. if (rtdev)
  716. xfs_blkdev_put(rtdev);
  717. out_close_logdev:
  718. if (logdev && logdev != ddev)
  719. xfs_blkdev_put(logdev);
  720. out:
  721. return error;
  722. }
  723. /*
  724. * Setup xfs_mount buffer target pointers based on superblock
  725. */
  726. STATIC int
  727. xfs_setup_devices(
  728. struct xfs_mount *mp)
  729. {
  730. int error;
  731. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  732. mp->m_sb.sb_sectsize);
  733. if (error)
  734. return error;
  735. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  736. unsigned int log_sector_size = BBSIZE;
  737. if (xfs_sb_version_hassector(&mp->m_sb))
  738. log_sector_size = mp->m_sb.sb_logsectsize;
  739. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  740. mp->m_sb.sb_blocksize,
  741. log_sector_size);
  742. if (error)
  743. return error;
  744. }
  745. if (mp->m_rtdev_targp) {
  746. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  747. mp->m_sb.sb_blocksize,
  748. mp->m_sb.sb_sectsize);
  749. if (error)
  750. return error;
  751. }
  752. return 0;
  753. }
  754. /*
  755. * XFS AIL push thread support
  756. */
  757. void
  758. xfsaild_wakeup(
  759. struct xfs_ail *ailp,
  760. xfs_lsn_t threshold_lsn)
  761. {
  762. ailp->xa_target = threshold_lsn;
  763. wake_up_process(ailp->xa_task);
  764. }
  765. STATIC int
  766. xfsaild(
  767. void *data)
  768. {
  769. struct xfs_ail *ailp = data;
  770. xfs_lsn_t last_pushed_lsn = 0;
  771. long tout = 0; /* milliseconds */
  772. while (!kthread_should_stop()) {
  773. schedule_timeout_interruptible(tout ?
  774. msecs_to_jiffies(tout) : MAX_SCHEDULE_TIMEOUT);
  775. /* swsusp */
  776. try_to_freeze();
  777. ASSERT(ailp->xa_mount->m_log);
  778. if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
  779. continue;
  780. tout = xfsaild_push(ailp, &last_pushed_lsn);
  781. }
  782. return 0;
  783. } /* xfsaild */
  784. int
  785. xfsaild_start(
  786. struct xfs_ail *ailp)
  787. {
  788. ailp->xa_target = 0;
  789. ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild/%s",
  790. ailp->xa_mount->m_fsname);
  791. if (IS_ERR(ailp->xa_task))
  792. return -PTR_ERR(ailp->xa_task);
  793. return 0;
  794. }
  795. void
  796. xfsaild_stop(
  797. struct xfs_ail *ailp)
  798. {
  799. kthread_stop(ailp->xa_task);
  800. }
  801. /* Catch misguided souls that try to use this interface on XFS */
  802. STATIC struct inode *
  803. xfs_fs_alloc_inode(
  804. struct super_block *sb)
  805. {
  806. BUG();
  807. return NULL;
  808. }
  809. /*
  810. * Now that the generic code is guaranteed not to be accessing
  811. * the linux inode, we can reclaim the inode.
  812. */
  813. STATIC void
  814. xfs_fs_destroy_inode(
  815. struct inode *inode)
  816. {
  817. struct xfs_inode *ip = XFS_I(inode);
  818. trace_xfs_destroy_inode(ip);
  819. XFS_STATS_INC(vn_reclaim);
  820. /* bad inode, get out here ASAP */
  821. if (is_bad_inode(inode))
  822. goto out_reclaim;
  823. xfs_ioend_wait(ip);
  824. ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
  825. /*
  826. * We should never get here with one of the reclaim flags already set.
  827. */
  828. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
  829. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
  830. /*
  831. * We always use background reclaim here because even if the
  832. * inode is clean, it still may be under IO and hence we have
  833. * to take the flush lock. The background reclaim path handles
  834. * this more efficiently than we can here, so simply let background
  835. * reclaim tear down all inodes.
  836. */
  837. out_reclaim:
  838. xfs_inode_set_reclaim_tag(ip);
  839. }
  840. /*
  841. * Slab object creation initialisation for the XFS inode.
  842. * This covers only the idempotent fields in the XFS inode;
  843. * all other fields need to be initialised on allocation
  844. * from the slab. This avoids the need to repeatedly intialise
  845. * fields in the xfs inode that left in the initialise state
  846. * when freeing the inode.
  847. */
  848. STATIC void
  849. xfs_fs_inode_init_once(
  850. void *inode)
  851. {
  852. struct xfs_inode *ip = inode;
  853. memset(ip, 0, sizeof(struct xfs_inode));
  854. /* vfs inode */
  855. inode_init_once(VFS_I(ip));
  856. /* xfs inode */
  857. atomic_set(&ip->i_iocount, 0);
  858. atomic_set(&ip->i_pincount, 0);
  859. spin_lock_init(&ip->i_flags_lock);
  860. init_waitqueue_head(&ip->i_ipin_wait);
  861. /*
  862. * Because we want to use a counting completion, complete
  863. * the flush completion once to allow a single access to
  864. * the flush completion without blocking.
  865. */
  866. init_completion(&ip->i_flush);
  867. complete(&ip->i_flush);
  868. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  869. "xfsino", ip->i_ino);
  870. }
  871. /*
  872. * Dirty the XFS inode when mark_inode_dirty_sync() is called so that
  873. * we catch unlogged VFS level updates to the inode.
  874. *
  875. * We need the barrier() to maintain correct ordering between unlogged
  876. * updates and the transaction commit code that clears the i_update_core
  877. * field. This requires all updates to be completed before marking the
  878. * inode dirty.
  879. */
  880. STATIC void
  881. xfs_fs_dirty_inode(
  882. struct inode *inode)
  883. {
  884. barrier();
  885. XFS_I(inode)->i_update_core = 1;
  886. }
  887. STATIC int
  888. xfs_log_inode(
  889. struct xfs_inode *ip)
  890. {
  891. struct xfs_mount *mp = ip->i_mount;
  892. struct xfs_trans *tp;
  893. int error;
  894. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  895. tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS);
  896. error = xfs_trans_reserve(tp, 0, XFS_FSYNC_TS_LOG_RES(mp), 0, 0, 0);
  897. if (error) {
  898. xfs_trans_cancel(tp, 0);
  899. /* we need to return with the lock hold shared */
  900. xfs_ilock(ip, XFS_ILOCK_SHARED);
  901. return error;
  902. }
  903. xfs_ilock(ip, XFS_ILOCK_EXCL);
  904. /*
  905. * Note - it's possible that we might have pushed ourselves out of the
  906. * way during trans_reserve which would flush the inode. But there's
  907. * no guarantee that the inode buffer has actually gone out yet (it's
  908. * delwri). Plus the buffer could be pinned anyway if it's part of
  909. * an inode in another recent transaction. So we play it safe and
  910. * fire off the transaction anyway.
  911. */
  912. xfs_trans_ijoin(tp, ip);
  913. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  914. error = xfs_trans_commit(tp, 0);
  915. xfs_ilock_demote(ip, XFS_ILOCK_EXCL);
  916. return error;
  917. }
  918. STATIC int
  919. xfs_fs_write_inode(
  920. struct inode *inode,
  921. struct writeback_control *wbc)
  922. {
  923. struct xfs_inode *ip = XFS_I(inode);
  924. struct xfs_mount *mp = ip->i_mount;
  925. int error = EAGAIN;
  926. trace_xfs_write_inode(ip);
  927. if (XFS_FORCED_SHUTDOWN(mp))
  928. return XFS_ERROR(EIO);
  929. if (wbc->sync_mode == WB_SYNC_ALL) {
  930. /*
  931. * Make sure the inode has made it it into the log. Instead
  932. * of forcing it all the way to stable storage using a
  933. * synchronous transaction we let the log force inside the
  934. * ->sync_fs call do that for thus, which reduces the number
  935. * of synchronous log foces dramatically.
  936. */
  937. xfs_ioend_wait(ip);
  938. xfs_ilock(ip, XFS_ILOCK_SHARED);
  939. if (ip->i_update_core) {
  940. error = xfs_log_inode(ip);
  941. if (error)
  942. goto out_unlock;
  943. }
  944. } else {
  945. /*
  946. * We make this non-blocking if the inode is contended, return
  947. * EAGAIN to indicate to the caller that they did not succeed.
  948. * This prevents the flush path from blocking on inodes inside
  949. * another operation right now, they get caught later by
  950. * xfs_sync.
  951. */
  952. if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
  953. goto out;
  954. if (xfs_ipincount(ip) || !xfs_iflock_nowait(ip))
  955. goto out_unlock;
  956. /*
  957. * Now we have the flush lock and the inode is not pinned, we
  958. * can check if the inode is really clean as we know that
  959. * there are no pending transaction completions, it is not
  960. * waiting on the delayed write queue and there is no IO in
  961. * progress.
  962. */
  963. if (xfs_inode_clean(ip)) {
  964. xfs_ifunlock(ip);
  965. error = 0;
  966. goto out_unlock;
  967. }
  968. error = xfs_iflush(ip, 0);
  969. }
  970. out_unlock:
  971. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  972. out:
  973. /*
  974. * if we failed to write out the inode then mark
  975. * it dirty again so we'll try again later.
  976. */
  977. if (error)
  978. xfs_mark_inode_dirty_sync(ip);
  979. return -error;
  980. }
  981. STATIC void
  982. xfs_fs_evict_inode(
  983. struct inode *inode)
  984. {
  985. xfs_inode_t *ip = XFS_I(inode);
  986. trace_xfs_evict_inode(ip);
  987. truncate_inode_pages(&inode->i_data, 0);
  988. end_writeback(inode);
  989. XFS_STATS_INC(vn_rele);
  990. XFS_STATS_INC(vn_remove);
  991. XFS_STATS_DEC(vn_active);
  992. /*
  993. * The iolock is used by the file system to coordinate reads,
  994. * writes, and block truncates. Up to this point the lock
  995. * protected concurrent accesses by users of the inode. But
  996. * from here forward we're doing some final processing of the
  997. * inode because we're done with it, and although we reuse the
  998. * iolock for protection it is really a distinct lock class
  999. * (in the lockdep sense) from before. To keep lockdep happy
  1000. * (and basically indicate what we are doing), we explicitly
  1001. * re-init the iolock here.
  1002. */
  1003. ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
  1004. mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
  1005. xfs_inactive(ip);
  1006. }
  1007. STATIC void
  1008. xfs_free_fsname(
  1009. struct xfs_mount *mp)
  1010. {
  1011. kfree(mp->m_fsname);
  1012. kfree(mp->m_rtname);
  1013. kfree(mp->m_logname);
  1014. }
  1015. STATIC void
  1016. xfs_fs_put_super(
  1017. struct super_block *sb)
  1018. {
  1019. struct xfs_mount *mp = XFS_M(sb);
  1020. /*
  1021. * Unregister the memory shrinker before we tear down the mount
  1022. * structure so we don't have memory reclaim racing with us here.
  1023. */
  1024. xfs_inode_shrinker_unregister(mp);
  1025. xfs_syncd_stop(mp);
  1026. /*
  1027. * Blow away any referenced inode in the filestreams cache.
  1028. * This can and will cause log traffic as inodes go inactive
  1029. * here.
  1030. */
  1031. xfs_filestream_unmount(mp);
  1032. XFS_bflush(mp->m_ddev_targp);
  1033. xfs_unmountfs(mp);
  1034. xfs_freesb(mp);
  1035. xfs_icsb_destroy_counters(mp);
  1036. xfs_close_devices(mp);
  1037. xfs_free_fsname(mp);
  1038. kfree(mp);
  1039. }
  1040. STATIC int
  1041. xfs_fs_sync_fs(
  1042. struct super_block *sb,
  1043. int wait)
  1044. {
  1045. struct xfs_mount *mp = XFS_M(sb);
  1046. int error;
  1047. /*
  1048. * Not much we can do for the first async pass. Writing out the
  1049. * superblock would be counter-productive as we are going to redirty
  1050. * when writing out other data and metadata (and writing out a single
  1051. * block is quite fast anyway).
  1052. *
  1053. * Try to asynchronously kick off quota syncing at least.
  1054. */
  1055. if (!wait) {
  1056. xfs_qm_sync(mp, SYNC_TRYLOCK);
  1057. return 0;
  1058. }
  1059. error = xfs_quiesce_data(mp);
  1060. if (error)
  1061. return -error;
  1062. if (laptop_mode) {
  1063. int prev_sync_seq = mp->m_sync_seq;
  1064. /*
  1065. * The disk must be active because we're syncing.
  1066. * We schedule xfssyncd now (now that the disk is
  1067. * active) instead of later (when it might not be).
  1068. */
  1069. wake_up_process(mp->m_sync_task);
  1070. /*
  1071. * We have to wait for the sync iteration to complete.
  1072. * If we don't, the disk activity caused by the sync
  1073. * will come after the sync is completed, and that
  1074. * triggers another sync from laptop mode.
  1075. */
  1076. wait_event(mp->m_wait_single_sync_task,
  1077. mp->m_sync_seq != prev_sync_seq);
  1078. }
  1079. return 0;
  1080. }
  1081. STATIC int
  1082. xfs_fs_statfs(
  1083. struct dentry *dentry,
  1084. struct kstatfs *statp)
  1085. {
  1086. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  1087. xfs_sb_t *sbp = &mp->m_sb;
  1088. struct xfs_inode *ip = XFS_I(dentry->d_inode);
  1089. __uint64_t fakeinos, id;
  1090. xfs_extlen_t lsize;
  1091. __int64_t ffree;
  1092. statp->f_type = XFS_SB_MAGIC;
  1093. statp->f_namelen = MAXNAMELEN - 1;
  1094. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  1095. statp->f_fsid.val[0] = (u32)id;
  1096. statp->f_fsid.val[1] = (u32)(id >> 32);
  1097. xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
  1098. spin_lock(&mp->m_sb_lock);
  1099. statp->f_bsize = sbp->sb_blocksize;
  1100. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  1101. statp->f_blocks = sbp->sb_dblocks - lsize;
  1102. statp->f_bfree = statp->f_bavail =
  1103. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  1104. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  1105. statp->f_files =
  1106. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  1107. if (mp->m_maxicount)
  1108. statp->f_files = min_t(typeof(statp->f_files),
  1109. statp->f_files,
  1110. mp->m_maxicount);
  1111. /* make sure statp->f_ffree does not underflow */
  1112. ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  1113. statp->f_ffree = max_t(__int64_t, ffree, 0);
  1114. spin_unlock(&mp->m_sb_lock);
  1115. if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) ||
  1116. ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))) ==
  1117. (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
  1118. xfs_qm_statvfs(ip, statp);
  1119. return 0;
  1120. }
  1121. STATIC void
  1122. xfs_save_resvblks(struct xfs_mount *mp)
  1123. {
  1124. __uint64_t resblks = 0;
  1125. mp->m_resblks_save = mp->m_resblks;
  1126. xfs_reserve_blocks(mp, &resblks, NULL);
  1127. }
  1128. STATIC void
  1129. xfs_restore_resvblks(struct xfs_mount *mp)
  1130. {
  1131. __uint64_t resblks;
  1132. if (mp->m_resblks_save) {
  1133. resblks = mp->m_resblks_save;
  1134. mp->m_resblks_save = 0;
  1135. } else
  1136. resblks = xfs_default_resblks(mp);
  1137. xfs_reserve_blocks(mp, &resblks, NULL);
  1138. }
  1139. STATIC int
  1140. xfs_fs_remount(
  1141. struct super_block *sb,
  1142. int *flags,
  1143. char *options)
  1144. {
  1145. struct xfs_mount *mp = XFS_M(sb);
  1146. substring_t args[MAX_OPT_ARGS];
  1147. char *p;
  1148. int error;
  1149. while ((p = strsep(&options, ",")) != NULL) {
  1150. int token;
  1151. if (!*p)
  1152. continue;
  1153. token = match_token(p, tokens, args);
  1154. switch (token) {
  1155. case Opt_barrier:
  1156. mp->m_flags |= XFS_MOUNT_BARRIER;
  1157. /*
  1158. * Test if barriers are actually working if we can,
  1159. * else delay this check until the filesystem is
  1160. * marked writeable.
  1161. */
  1162. if (!(mp->m_flags & XFS_MOUNT_RDONLY))
  1163. xfs_mountfs_check_barriers(mp);
  1164. break;
  1165. case Opt_nobarrier:
  1166. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1167. break;
  1168. default:
  1169. /*
  1170. * Logically we would return an error here to prevent
  1171. * users from believing they might have changed
  1172. * mount options using remount which can't be changed.
  1173. *
  1174. * But unfortunately mount(8) adds all options from
  1175. * mtab and fstab to the mount arguments in some cases
  1176. * so we can't blindly reject options, but have to
  1177. * check for each specified option if it actually
  1178. * differs from the currently set option and only
  1179. * reject it if that's the case.
  1180. *
  1181. * Until that is implemented we return success for
  1182. * every remount request, and silently ignore all
  1183. * options that we can't actually change.
  1184. */
  1185. #if 0
  1186. printk(KERN_INFO
  1187. "XFS: mount option \"%s\" not supported for remount\n", p);
  1188. return -EINVAL;
  1189. #else
  1190. break;
  1191. #endif
  1192. }
  1193. }
  1194. /* ro -> rw */
  1195. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1196. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1197. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1198. xfs_mountfs_check_barriers(mp);
  1199. /*
  1200. * If this is the first remount to writeable state we
  1201. * might have some superblock changes to update.
  1202. */
  1203. if (mp->m_update_flags) {
  1204. error = xfs_mount_log_sb(mp, mp->m_update_flags);
  1205. if (error) {
  1206. cmn_err(CE_WARN,
  1207. "XFS: failed to write sb changes");
  1208. return error;
  1209. }
  1210. mp->m_update_flags = 0;
  1211. }
  1212. /*
  1213. * Fill out the reserve pool if it is empty. Use the stashed
  1214. * value if it is non-zero, otherwise go with the default.
  1215. */
  1216. xfs_restore_resvblks(mp);
  1217. }
  1218. /* rw -> ro */
  1219. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1220. /*
  1221. * After we have synced the data but before we sync the
  1222. * metadata, we need to free up the reserve block pool so that
  1223. * the used block count in the superblock on disk is correct at
  1224. * the end of the remount. Stash the current reserve pool size
  1225. * so that if we get remounted rw, we can return it to the same
  1226. * size.
  1227. */
  1228. xfs_quiesce_data(mp);
  1229. xfs_save_resvblks(mp);
  1230. xfs_quiesce_attr(mp);
  1231. mp->m_flags |= XFS_MOUNT_RDONLY;
  1232. }
  1233. return 0;
  1234. }
  1235. /*
  1236. * Second stage of a freeze. The data is already frozen so we only
  1237. * need to take care of the metadata. Once that's done write a dummy
  1238. * record to dirty the log in case of a crash while frozen.
  1239. */
  1240. STATIC int
  1241. xfs_fs_freeze(
  1242. struct super_block *sb)
  1243. {
  1244. struct xfs_mount *mp = XFS_M(sb);
  1245. xfs_save_resvblks(mp);
  1246. xfs_quiesce_attr(mp);
  1247. return -xfs_fs_log_dummy(mp, SYNC_WAIT);
  1248. }
  1249. STATIC int
  1250. xfs_fs_unfreeze(
  1251. struct super_block *sb)
  1252. {
  1253. struct xfs_mount *mp = XFS_M(sb);
  1254. xfs_restore_resvblks(mp);
  1255. return 0;
  1256. }
  1257. STATIC int
  1258. xfs_fs_show_options(
  1259. struct seq_file *m,
  1260. struct vfsmount *mnt)
  1261. {
  1262. return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
  1263. }
  1264. /*
  1265. * This function fills in xfs_mount_t fields based on mount args.
  1266. * Note: the superblock _has_ now been read in.
  1267. */
  1268. STATIC int
  1269. xfs_finish_flags(
  1270. struct xfs_mount *mp)
  1271. {
  1272. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1273. /* Fail a mount where the logbuf is smaller than the log stripe */
  1274. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1275. if (mp->m_logbsize <= 0 &&
  1276. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  1277. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1278. } else if (mp->m_logbsize > 0 &&
  1279. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  1280. cmn_err(CE_WARN,
  1281. "XFS: logbuf size must be greater than or equal to log stripe size");
  1282. return XFS_ERROR(EINVAL);
  1283. }
  1284. } else {
  1285. /* Fail a mount if the logbuf is larger than 32K */
  1286. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  1287. cmn_err(CE_WARN,
  1288. "XFS: logbuf size for version 1 logs must be 16K or 32K");
  1289. return XFS_ERROR(EINVAL);
  1290. }
  1291. }
  1292. /*
  1293. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1294. * told by noattr2 to turn it off
  1295. */
  1296. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1297. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  1298. mp->m_flags |= XFS_MOUNT_ATTR2;
  1299. /*
  1300. * prohibit r/w mounts of read-only filesystems
  1301. */
  1302. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1303. cmn_err(CE_WARN,
  1304. "XFS: cannot mount a read-only filesystem as read-write");
  1305. return XFS_ERROR(EROFS);
  1306. }
  1307. return 0;
  1308. }
  1309. STATIC int
  1310. xfs_fs_fill_super(
  1311. struct super_block *sb,
  1312. void *data,
  1313. int silent)
  1314. {
  1315. struct inode *root;
  1316. struct xfs_mount *mp = NULL;
  1317. int flags = 0, error = ENOMEM;
  1318. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1319. if (!mp)
  1320. goto out;
  1321. spin_lock_init(&mp->m_sb_lock);
  1322. mutex_init(&mp->m_growlock);
  1323. atomic_set(&mp->m_active_trans, 0);
  1324. INIT_LIST_HEAD(&mp->m_sync_list);
  1325. spin_lock_init(&mp->m_sync_lock);
  1326. init_waitqueue_head(&mp->m_wait_single_sync_task);
  1327. mp->m_super = sb;
  1328. sb->s_fs_info = mp;
  1329. error = xfs_parseargs(mp, (char *)data);
  1330. if (error)
  1331. goto out_free_fsname;
  1332. sb_min_blocksize(sb, BBSIZE);
  1333. sb->s_xattr = xfs_xattr_handlers;
  1334. sb->s_export_op = &xfs_export_operations;
  1335. #ifdef CONFIG_XFS_QUOTA
  1336. sb->s_qcop = &xfs_quotactl_operations;
  1337. #endif
  1338. sb->s_op = &xfs_super_operations;
  1339. if (silent)
  1340. flags |= XFS_MFSI_QUIET;
  1341. error = xfs_open_devices(mp);
  1342. if (error)
  1343. goto out_free_fsname;
  1344. error = xfs_icsb_init_counters(mp);
  1345. if (error)
  1346. goto out_close_devices;
  1347. error = xfs_readsb(mp, flags);
  1348. if (error)
  1349. goto out_destroy_counters;
  1350. error = xfs_finish_flags(mp);
  1351. if (error)
  1352. goto out_free_sb;
  1353. error = xfs_setup_devices(mp);
  1354. if (error)
  1355. goto out_free_sb;
  1356. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1357. xfs_mountfs_check_barriers(mp);
  1358. error = xfs_filestream_mount(mp);
  1359. if (error)
  1360. goto out_free_sb;
  1361. error = xfs_mountfs(mp);
  1362. if (error)
  1363. goto out_filestream_unmount;
  1364. sb->s_magic = XFS_SB_MAGIC;
  1365. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1366. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1367. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1368. sb->s_time_gran = 1;
  1369. set_posix_acl_flag(sb);
  1370. root = igrab(VFS_I(mp->m_rootip));
  1371. if (!root) {
  1372. error = ENOENT;
  1373. goto fail_unmount;
  1374. }
  1375. if (is_bad_inode(root)) {
  1376. error = EINVAL;
  1377. goto fail_vnrele;
  1378. }
  1379. sb->s_root = d_alloc_root(root);
  1380. if (!sb->s_root) {
  1381. error = ENOMEM;
  1382. goto fail_vnrele;
  1383. }
  1384. error = xfs_syncd_init(mp);
  1385. if (error)
  1386. goto fail_vnrele;
  1387. xfs_inode_shrinker_register(mp);
  1388. return 0;
  1389. out_filestream_unmount:
  1390. xfs_filestream_unmount(mp);
  1391. out_free_sb:
  1392. xfs_freesb(mp);
  1393. out_destroy_counters:
  1394. xfs_icsb_destroy_counters(mp);
  1395. out_close_devices:
  1396. xfs_close_devices(mp);
  1397. out_free_fsname:
  1398. xfs_free_fsname(mp);
  1399. kfree(mp);
  1400. out:
  1401. return -error;
  1402. fail_vnrele:
  1403. if (sb->s_root) {
  1404. dput(sb->s_root);
  1405. sb->s_root = NULL;
  1406. } else {
  1407. iput(root);
  1408. }
  1409. fail_unmount:
  1410. /*
  1411. * Blow away any referenced inode in the filestreams cache.
  1412. * This can and will cause log traffic as inodes go inactive
  1413. * here.
  1414. */
  1415. xfs_filestream_unmount(mp);
  1416. XFS_bflush(mp->m_ddev_targp);
  1417. xfs_unmountfs(mp);
  1418. goto out_free_sb;
  1419. }
  1420. STATIC struct dentry *
  1421. xfs_fs_mount(
  1422. struct file_system_type *fs_type,
  1423. int flags,
  1424. const char *dev_name,
  1425. void *data)
  1426. {
  1427. return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
  1428. }
  1429. static const struct super_operations xfs_super_operations = {
  1430. .alloc_inode = xfs_fs_alloc_inode,
  1431. .destroy_inode = xfs_fs_destroy_inode,
  1432. .dirty_inode = xfs_fs_dirty_inode,
  1433. .write_inode = xfs_fs_write_inode,
  1434. .evict_inode = xfs_fs_evict_inode,
  1435. .put_super = xfs_fs_put_super,
  1436. .sync_fs = xfs_fs_sync_fs,
  1437. .freeze_fs = xfs_fs_freeze,
  1438. .unfreeze_fs = xfs_fs_unfreeze,
  1439. .statfs = xfs_fs_statfs,
  1440. .remount_fs = xfs_fs_remount,
  1441. .show_options = xfs_fs_show_options,
  1442. };
  1443. static struct file_system_type xfs_fs_type = {
  1444. .owner = THIS_MODULE,
  1445. .name = "xfs",
  1446. .mount = xfs_fs_mount,
  1447. .kill_sb = kill_block_super,
  1448. .fs_flags = FS_REQUIRES_DEV,
  1449. };
  1450. STATIC int __init
  1451. xfs_init_zones(void)
  1452. {
  1453. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  1454. if (!xfs_ioend_zone)
  1455. goto out;
  1456. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  1457. xfs_ioend_zone);
  1458. if (!xfs_ioend_pool)
  1459. goto out_destroy_ioend_zone;
  1460. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1461. "xfs_log_ticket");
  1462. if (!xfs_log_ticket_zone)
  1463. goto out_destroy_ioend_pool;
  1464. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  1465. "xfs_bmap_free_item");
  1466. if (!xfs_bmap_free_item_zone)
  1467. goto out_destroy_log_ticket_zone;
  1468. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1469. "xfs_btree_cur");
  1470. if (!xfs_btree_cur_zone)
  1471. goto out_destroy_bmap_free_item_zone;
  1472. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1473. "xfs_da_state");
  1474. if (!xfs_da_state_zone)
  1475. goto out_destroy_btree_cur_zone;
  1476. xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
  1477. if (!xfs_dabuf_zone)
  1478. goto out_destroy_da_state_zone;
  1479. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1480. if (!xfs_ifork_zone)
  1481. goto out_destroy_dabuf_zone;
  1482. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1483. if (!xfs_trans_zone)
  1484. goto out_destroy_ifork_zone;
  1485. xfs_log_item_desc_zone =
  1486. kmem_zone_init(sizeof(struct xfs_log_item_desc),
  1487. "xfs_log_item_desc");
  1488. if (!xfs_log_item_desc_zone)
  1489. goto out_destroy_trans_zone;
  1490. /*
  1491. * The size of the zone allocated buf log item is the maximum
  1492. * size possible under XFS. This wastes a little bit of memory,
  1493. * but it is much faster.
  1494. */
  1495. xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
  1496. (((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) /
  1497. NBWORD) * sizeof(int))), "xfs_buf_item");
  1498. if (!xfs_buf_item_zone)
  1499. goto out_destroy_log_item_desc_zone;
  1500. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1501. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1502. sizeof(xfs_extent_t))), "xfs_efd_item");
  1503. if (!xfs_efd_zone)
  1504. goto out_destroy_buf_item_zone;
  1505. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1506. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1507. sizeof(xfs_extent_t))), "xfs_efi_item");
  1508. if (!xfs_efi_zone)
  1509. goto out_destroy_efd_zone;
  1510. xfs_inode_zone =
  1511. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1512. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
  1513. xfs_fs_inode_init_once);
  1514. if (!xfs_inode_zone)
  1515. goto out_destroy_efi_zone;
  1516. xfs_ili_zone =
  1517. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1518. KM_ZONE_SPREAD, NULL);
  1519. if (!xfs_ili_zone)
  1520. goto out_destroy_inode_zone;
  1521. return 0;
  1522. out_destroy_inode_zone:
  1523. kmem_zone_destroy(xfs_inode_zone);
  1524. out_destroy_efi_zone:
  1525. kmem_zone_destroy(xfs_efi_zone);
  1526. out_destroy_efd_zone:
  1527. kmem_zone_destroy(xfs_efd_zone);
  1528. out_destroy_buf_item_zone:
  1529. kmem_zone_destroy(xfs_buf_item_zone);
  1530. out_destroy_log_item_desc_zone:
  1531. kmem_zone_destroy(xfs_log_item_desc_zone);
  1532. out_destroy_trans_zone:
  1533. kmem_zone_destroy(xfs_trans_zone);
  1534. out_destroy_ifork_zone:
  1535. kmem_zone_destroy(xfs_ifork_zone);
  1536. out_destroy_dabuf_zone:
  1537. kmem_zone_destroy(xfs_dabuf_zone);
  1538. out_destroy_da_state_zone:
  1539. kmem_zone_destroy(xfs_da_state_zone);
  1540. out_destroy_btree_cur_zone:
  1541. kmem_zone_destroy(xfs_btree_cur_zone);
  1542. out_destroy_bmap_free_item_zone:
  1543. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1544. out_destroy_log_ticket_zone:
  1545. kmem_zone_destroy(xfs_log_ticket_zone);
  1546. out_destroy_ioend_pool:
  1547. mempool_destroy(xfs_ioend_pool);
  1548. out_destroy_ioend_zone:
  1549. kmem_zone_destroy(xfs_ioend_zone);
  1550. out:
  1551. return -ENOMEM;
  1552. }
  1553. STATIC void
  1554. xfs_destroy_zones(void)
  1555. {
  1556. kmem_zone_destroy(xfs_ili_zone);
  1557. kmem_zone_destroy(xfs_inode_zone);
  1558. kmem_zone_destroy(xfs_efi_zone);
  1559. kmem_zone_destroy(xfs_efd_zone);
  1560. kmem_zone_destroy(xfs_buf_item_zone);
  1561. kmem_zone_destroy(xfs_log_item_desc_zone);
  1562. kmem_zone_destroy(xfs_trans_zone);
  1563. kmem_zone_destroy(xfs_ifork_zone);
  1564. kmem_zone_destroy(xfs_dabuf_zone);
  1565. kmem_zone_destroy(xfs_da_state_zone);
  1566. kmem_zone_destroy(xfs_btree_cur_zone);
  1567. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1568. kmem_zone_destroy(xfs_log_ticket_zone);
  1569. mempool_destroy(xfs_ioend_pool);
  1570. kmem_zone_destroy(xfs_ioend_zone);
  1571. }
  1572. STATIC int __init
  1573. init_xfs_fs(void)
  1574. {
  1575. int error;
  1576. printk(KERN_INFO XFS_VERSION_STRING " with "
  1577. XFS_BUILD_OPTIONS " enabled\n");
  1578. xfs_ioend_init();
  1579. xfs_dir_startup();
  1580. error = xfs_init_zones();
  1581. if (error)
  1582. goto out;
  1583. error = xfs_mru_cache_init();
  1584. if (error)
  1585. goto out_destroy_zones;
  1586. error = xfs_filestream_init();
  1587. if (error)
  1588. goto out_mru_cache_uninit;
  1589. error = xfs_buf_init();
  1590. if (error)
  1591. goto out_filestream_uninit;
  1592. error = xfs_init_procfs();
  1593. if (error)
  1594. goto out_buf_terminate;
  1595. error = xfs_sysctl_register();
  1596. if (error)
  1597. goto out_cleanup_procfs;
  1598. vfs_initquota();
  1599. error = register_filesystem(&xfs_fs_type);
  1600. if (error)
  1601. goto out_sysctl_unregister;
  1602. return 0;
  1603. out_sysctl_unregister:
  1604. xfs_sysctl_unregister();
  1605. out_cleanup_procfs:
  1606. xfs_cleanup_procfs();
  1607. out_buf_terminate:
  1608. xfs_buf_terminate();
  1609. out_filestream_uninit:
  1610. xfs_filestream_uninit();
  1611. out_mru_cache_uninit:
  1612. xfs_mru_cache_uninit();
  1613. out_destroy_zones:
  1614. xfs_destroy_zones();
  1615. out:
  1616. return error;
  1617. }
  1618. STATIC void __exit
  1619. exit_xfs_fs(void)
  1620. {
  1621. vfs_exitquota();
  1622. unregister_filesystem(&xfs_fs_type);
  1623. xfs_sysctl_unregister();
  1624. xfs_cleanup_procfs();
  1625. xfs_buf_terminate();
  1626. xfs_filestream_uninit();
  1627. xfs_mru_cache_uninit();
  1628. xfs_destroy_zones();
  1629. }
  1630. module_init(init_xfs_fs);
  1631. module_exit(exit_xfs_fs);
  1632. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1633. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1634. MODULE_LICENSE("GPL");