xfs_super.c 48 KB

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