xfs_super.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  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_shared.h"
  20. #include "xfs_format.h"
  21. #include "xfs_log_format.h"
  22. #include "xfs_trans_resv.h"
  23. #include "xfs_sb.h"
  24. #include "xfs_mount.h"
  25. #include "xfs_da_format.h"
  26. #include "xfs_inode.h"
  27. #include "xfs_btree.h"
  28. #include "xfs_bmap.h"
  29. #include "xfs_alloc.h"
  30. #include "xfs_error.h"
  31. #include "xfs_fsops.h"
  32. #include "xfs_trans.h"
  33. #include "xfs_buf_item.h"
  34. #include "xfs_log.h"
  35. #include "xfs_log_priv.h"
  36. #include "xfs_da_btree.h"
  37. #include "xfs_dir2.h"
  38. #include "xfs_extfree_item.h"
  39. #include "xfs_mru_cache.h"
  40. #include "xfs_inode_item.h"
  41. #include "xfs_icache.h"
  42. #include "xfs_trace.h"
  43. #include "xfs_icreate_item.h"
  44. #include "xfs_filestream.h"
  45. #include "xfs_quota.h"
  46. #include "xfs_sysfs.h"
  47. #include <linux/namei.h>
  48. #include <linux/init.h>
  49. #include <linux/slab.h>
  50. #include <linux/mount.h>
  51. #include <linux/mempool.h>
  52. #include <linux/writeback.h>
  53. #include <linux/kthread.h>
  54. #include <linux/freezer.h>
  55. #include <linux/parser.h>
  56. static const struct super_operations xfs_super_operations;
  57. static kmem_zone_t *xfs_ioend_zone;
  58. mempool_t *xfs_ioend_pool;
  59. static struct kset *xfs_kset; /* top-level xfs sysfs dir */
  60. #ifdef DEBUG
  61. static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
  62. #endif
  63. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  64. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  65. #define MNTOPT_LOGDEV "logdev" /* log device */
  66. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  67. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  68. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  69. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  70. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  71. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  72. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  73. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  74. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  75. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  76. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  77. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  78. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  79. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  80. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  81. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  82. * unwritten extent conversion */
  83. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  84. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  85. #define MNTOPT_32BITINODE "inode32" /* inode allocation limited to
  86. * XFS_MAXINUMBER_32 */
  87. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  88. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  89. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  90. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  91. * in stat(). */
  92. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  93. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  94. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  95. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  96. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  97. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  98. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  99. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  100. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  101. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  102. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  103. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  104. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  105. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  106. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  107. #define MNTOPT_DISCARD "discard" /* Discard unused blocks */
  108. #define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
  109. #define MNTOPT_DAX "dax" /* Enable direct access to bdev pages */
  110. /*
  111. * Table driven mount option parser.
  112. *
  113. * Currently only used for remount, but it will be used for mount
  114. * in the future, too.
  115. */
  116. enum {
  117. Opt_barrier,
  118. Opt_nobarrier,
  119. Opt_inode64,
  120. Opt_inode32,
  121. Opt_err
  122. };
  123. static const match_table_t tokens = {
  124. {Opt_barrier, "barrier"},
  125. {Opt_nobarrier, "nobarrier"},
  126. {Opt_inode64, "inode64"},
  127. {Opt_inode32, "inode32"},
  128. {Opt_err, NULL}
  129. };
  130. STATIC unsigned long
  131. suffix_kstrtoint(char *s, unsigned int base, int *res)
  132. {
  133. int last, shift_left_factor = 0, _res;
  134. char *value = s;
  135. last = strlen(value) - 1;
  136. if (value[last] == 'K' || value[last] == 'k') {
  137. shift_left_factor = 10;
  138. value[last] = '\0';
  139. }
  140. if (value[last] == 'M' || value[last] == 'm') {
  141. shift_left_factor = 20;
  142. value[last] = '\0';
  143. }
  144. if (value[last] == 'G' || value[last] == 'g') {
  145. shift_left_factor = 30;
  146. value[last] = '\0';
  147. }
  148. if (kstrtoint(s, base, &_res))
  149. return -EINVAL;
  150. *res = _res << shift_left_factor;
  151. return 0;
  152. }
  153. /*
  154. * This function fills in xfs_mount_t fields based on mount args.
  155. * Note: the superblock has _not_ yet been read in.
  156. *
  157. * Note that this function leaks the various device name allocations on
  158. * failure. The caller takes care of them.
  159. */
  160. STATIC int
  161. xfs_parseargs(
  162. struct xfs_mount *mp,
  163. char *options)
  164. {
  165. struct super_block *sb = mp->m_super;
  166. char *this_char, *value;
  167. int dsunit = 0;
  168. int dswidth = 0;
  169. int iosize = 0;
  170. __uint8_t iosizelog = 0;
  171. /*
  172. * set up the mount name first so all the errors will refer to the
  173. * correct device.
  174. */
  175. mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
  176. if (!mp->m_fsname)
  177. return -ENOMEM;
  178. mp->m_fsname_len = strlen(mp->m_fsname) + 1;
  179. /*
  180. * Copy binary VFS mount flags we are interested in.
  181. */
  182. if (sb->s_flags & MS_RDONLY)
  183. mp->m_flags |= XFS_MOUNT_RDONLY;
  184. if (sb->s_flags & MS_DIRSYNC)
  185. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  186. if (sb->s_flags & MS_SYNCHRONOUS)
  187. mp->m_flags |= XFS_MOUNT_WSYNC;
  188. /*
  189. * Set some default flags that could be cleared by the mount option
  190. * parsing.
  191. */
  192. mp->m_flags |= XFS_MOUNT_BARRIER;
  193. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  194. /*
  195. * These can be overridden by the mount option parsing.
  196. */
  197. mp->m_logbufs = -1;
  198. mp->m_logbsize = -1;
  199. if (!options)
  200. goto done;
  201. while ((this_char = strsep(&options, ",")) != NULL) {
  202. if (!*this_char)
  203. continue;
  204. if ((value = strchr(this_char, '=')) != NULL)
  205. *value++ = 0;
  206. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  207. if (!value || !*value) {
  208. xfs_warn(mp, "%s option requires an argument",
  209. this_char);
  210. return -EINVAL;
  211. }
  212. if (kstrtoint(value, 10, &mp->m_logbufs))
  213. return -EINVAL;
  214. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  215. if (!value || !*value) {
  216. xfs_warn(mp, "%s option requires an argument",
  217. this_char);
  218. return -EINVAL;
  219. }
  220. if (suffix_kstrtoint(value, 10, &mp->m_logbsize))
  221. return -EINVAL;
  222. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  223. if (!value || !*value) {
  224. xfs_warn(mp, "%s option requires an argument",
  225. this_char);
  226. return -EINVAL;
  227. }
  228. mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  229. if (!mp->m_logname)
  230. return -ENOMEM;
  231. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  232. xfs_warn(mp, "%s option not allowed on this system",
  233. this_char);
  234. return -EINVAL;
  235. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  236. if (!value || !*value) {
  237. xfs_warn(mp, "%s option requires an argument",
  238. this_char);
  239. return -EINVAL;
  240. }
  241. mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  242. if (!mp->m_rtname)
  243. return -ENOMEM;
  244. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  245. if (!value || !*value) {
  246. xfs_warn(mp, "%s option requires an argument",
  247. this_char);
  248. return -EINVAL;
  249. }
  250. if (kstrtoint(value, 10, &iosize))
  251. return -EINVAL;
  252. iosizelog = ffs(iosize) - 1;
  253. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  254. if (!value || !*value) {
  255. xfs_warn(mp, "%s option requires an argument",
  256. this_char);
  257. return -EINVAL;
  258. }
  259. if (suffix_kstrtoint(value, 10, &iosize))
  260. return -EINVAL;
  261. iosizelog = ffs(iosize) - 1;
  262. } else if (!strcmp(this_char, MNTOPT_GRPID) ||
  263. !strcmp(this_char, MNTOPT_BSDGROUPS)) {
  264. mp->m_flags |= XFS_MOUNT_GRPID;
  265. } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
  266. !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
  267. mp->m_flags &= ~XFS_MOUNT_GRPID;
  268. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  269. mp->m_flags |= XFS_MOUNT_WSYNC;
  270. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  271. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  272. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  273. mp->m_flags |= XFS_MOUNT_NOALIGN;
  274. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  275. mp->m_flags |= XFS_MOUNT_SWALLOC;
  276. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  277. if (!value || !*value) {
  278. xfs_warn(mp, "%s option requires an argument",
  279. this_char);
  280. return -EINVAL;
  281. }
  282. if (kstrtoint(value, 10, &dsunit))
  283. return -EINVAL;
  284. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  285. if (!value || !*value) {
  286. xfs_warn(mp, "%s option requires an argument",
  287. this_char);
  288. return -EINVAL;
  289. }
  290. if (kstrtoint(value, 10, &dswidth))
  291. return -EINVAL;
  292. } else if (!strcmp(this_char, MNTOPT_32BITINODE)) {
  293. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  294. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  295. mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
  296. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  297. mp->m_flags |= XFS_MOUNT_NOUUID;
  298. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  299. mp->m_flags |= XFS_MOUNT_BARRIER;
  300. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  301. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  302. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  303. mp->m_flags |= XFS_MOUNT_IKEEP;
  304. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  305. mp->m_flags &= ~XFS_MOUNT_IKEEP;
  306. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  307. mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
  308. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  309. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  310. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  311. mp->m_flags |= XFS_MOUNT_ATTR2;
  312. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  313. mp->m_flags &= ~XFS_MOUNT_ATTR2;
  314. mp->m_flags |= XFS_MOUNT_NOATTR2;
  315. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  316. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  317. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  318. mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
  319. mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
  320. mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
  321. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  322. !strcmp(this_char, MNTOPT_UQUOTA) ||
  323. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  324. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
  325. XFS_UQUOTA_ENFD);
  326. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  327. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  328. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  329. mp->m_qflags &= ~XFS_UQUOTA_ENFD;
  330. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  331. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  332. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
  333. XFS_PQUOTA_ENFD);
  334. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  335. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  336. mp->m_qflags &= ~XFS_PQUOTA_ENFD;
  337. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  338. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  339. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
  340. XFS_GQUOTA_ENFD);
  341. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  342. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  343. mp->m_qflags &= ~XFS_GQUOTA_ENFD;
  344. } else if (!strcmp(this_char, MNTOPT_DISCARD)) {
  345. mp->m_flags |= XFS_MOUNT_DISCARD;
  346. } else if (!strcmp(this_char, MNTOPT_NODISCARD)) {
  347. mp->m_flags &= ~XFS_MOUNT_DISCARD;
  348. #ifdef CONFIG_FS_DAX
  349. } else if (!strcmp(this_char, MNTOPT_DAX)) {
  350. mp->m_flags |= XFS_MOUNT_DAX;
  351. #endif
  352. } else {
  353. xfs_warn(mp, "unknown mount option [%s].", this_char);
  354. return -EINVAL;
  355. }
  356. }
  357. /*
  358. * no recovery flag requires a read-only mount
  359. */
  360. if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
  361. !(mp->m_flags & XFS_MOUNT_RDONLY)) {
  362. xfs_warn(mp, "no-recovery mounts must be read-only.");
  363. return -EINVAL;
  364. }
  365. if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
  366. xfs_warn(mp,
  367. "sunit and swidth options incompatible with the noalign option");
  368. return -EINVAL;
  369. }
  370. #ifndef CONFIG_XFS_QUOTA
  371. if (XFS_IS_QUOTA_RUNNING(mp)) {
  372. xfs_warn(mp, "quota support not available in this kernel.");
  373. return -EINVAL;
  374. }
  375. #endif
  376. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  377. xfs_warn(mp, "sunit and swidth must be specified together");
  378. return -EINVAL;
  379. }
  380. if (dsunit && (dswidth % dsunit != 0)) {
  381. xfs_warn(mp,
  382. "stripe width (%d) must be a multiple of the stripe unit (%d)",
  383. dswidth, dsunit);
  384. return -EINVAL;
  385. }
  386. done:
  387. if (dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
  388. /*
  389. * At this point the superblock has not been read
  390. * in, therefore we do not know the block size.
  391. * Before the mount call ends we will convert
  392. * these to FSBs.
  393. */
  394. mp->m_dalign = dsunit;
  395. mp->m_swidth = dswidth;
  396. }
  397. if (mp->m_logbufs != -1 &&
  398. mp->m_logbufs != 0 &&
  399. (mp->m_logbufs < XLOG_MIN_ICLOGS ||
  400. mp->m_logbufs > XLOG_MAX_ICLOGS)) {
  401. xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
  402. mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  403. return -EINVAL;
  404. }
  405. if (mp->m_logbsize != -1 &&
  406. mp->m_logbsize != 0 &&
  407. (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
  408. mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
  409. !is_power_of_2(mp->m_logbsize))) {
  410. xfs_warn(mp,
  411. "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  412. mp->m_logbsize);
  413. return -EINVAL;
  414. }
  415. if (iosizelog) {
  416. if (iosizelog > XFS_MAX_IO_LOG ||
  417. iosizelog < XFS_MIN_IO_LOG) {
  418. xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
  419. iosizelog, XFS_MIN_IO_LOG,
  420. XFS_MAX_IO_LOG);
  421. return -EINVAL;
  422. }
  423. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  424. mp->m_readio_log = iosizelog;
  425. mp->m_writeio_log = iosizelog;
  426. }
  427. return 0;
  428. }
  429. struct proc_xfs_info {
  430. uint64_t flag;
  431. char *str;
  432. };
  433. STATIC int
  434. xfs_showargs(
  435. struct xfs_mount *mp,
  436. struct seq_file *m)
  437. {
  438. static struct proc_xfs_info xfs_info_set[] = {
  439. /* the few simple ones we can get from the mount struct */
  440. { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
  441. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  442. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  443. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  444. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  445. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  446. { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
  447. { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
  448. { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
  449. { XFS_MOUNT_DISCARD, "," MNTOPT_DISCARD },
  450. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_32BITINODE },
  451. { XFS_MOUNT_DAX, "," MNTOPT_DAX },
  452. { 0, NULL }
  453. };
  454. static struct proc_xfs_info xfs_info_unset[] = {
  455. /* the few simple ones we can get from the mount struct */
  456. { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
  457. { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
  458. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
  459. { 0, NULL }
  460. };
  461. struct proc_xfs_info *xfs_infop;
  462. for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
  463. if (mp->m_flags & xfs_infop->flag)
  464. seq_puts(m, xfs_infop->str);
  465. }
  466. for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
  467. if (!(mp->m_flags & xfs_infop->flag))
  468. seq_puts(m, xfs_infop->str);
  469. }
  470. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  471. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  472. (int)(1 << mp->m_writeio_log) >> 10);
  473. if (mp->m_logbufs > 0)
  474. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  475. if (mp->m_logbsize > 0)
  476. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  477. if (mp->m_logname)
  478. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  479. if (mp->m_rtname)
  480. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  481. if (mp->m_dalign > 0)
  482. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  483. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  484. if (mp->m_swidth > 0)
  485. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  486. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  487. if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
  488. seq_puts(m, "," MNTOPT_USRQUOTA);
  489. else if (mp->m_qflags & XFS_UQUOTA_ACCT)
  490. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  491. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  492. if (mp->m_qflags & XFS_PQUOTA_ENFD)
  493. seq_puts(m, "," MNTOPT_PRJQUOTA);
  494. else
  495. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  496. }
  497. if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  498. if (mp->m_qflags & XFS_GQUOTA_ENFD)
  499. seq_puts(m, "," MNTOPT_GRPQUOTA);
  500. else
  501. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  502. }
  503. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  504. seq_puts(m, "," MNTOPT_NOQUOTA);
  505. return 0;
  506. }
  507. __uint64_t
  508. xfs_max_file_offset(
  509. unsigned int blockshift)
  510. {
  511. unsigned int pagefactor = 1;
  512. unsigned int bitshift = BITS_PER_LONG - 1;
  513. /* Figure out maximum filesize, on Linux this can depend on
  514. * the filesystem blocksize (on 32 bit platforms).
  515. * __block_write_begin does this in an [unsigned] long...
  516. * page->index << (PAGE_CACHE_SHIFT - bbits)
  517. * So, for page sized blocks (4K on 32 bit platforms),
  518. * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
  519. * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  520. * but for smaller blocksizes it is less (bbits = log2 bsize).
  521. * Note1: get_block_t takes a long (implicit cast from above)
  522. * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
  523. * can optionally convert the [unsigned] long from above into
  524. * an [unsigned] long long.
  525. */
  526. #if BITS_PER_LONG == 32
  527. # if defined(CONFIG_LBDAF)
  528. ASSERT(sizeof(sector_t) == 8);
  529. pagefactor = PAGE_CACHE_SIZE;
  530. bitshift = BITS_PER_LONG;
  531. # else
  532. pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
  533. # endif
  534. #endif
  535. return (((__uint64_t)pagefactor) << bitshift) - 1;
  536. }
  537. /*
  538. * xfs_set_inode32() and xfs_set_inode64() are passed an agcount
  539. * because in the growfs case, mp->m_sb.sb_agcount is not updated
  540. * yet to the potentially higher ag count.
  541. */
  542. xfs_agnumber_t
  543. xfs_set_inode32(struct xfs_mount *mp, xfs_agnumber_t agcount)
  544. {
  545. xfs_agnumber_t index = 0;
  546. xfs_agnumber_t maxagi = 0;
  547. xfs_sb_t *sbp = &mp->m_sb;
  548. xfs_agnumber_t max_metadata;
  549. xfs_agino_t agino;
  550. xfs_ino_t ino;
  551. xfs_perag_t *pag;
  552. /* Calculate how much should be reserved for inodes to meet
  553. * the max inode percentage.
  554. */
  555. if (mp->m_maxicount) {
  556. __uint64_t icount;
  557. icount = sbp->sb_dblocks * sbp->sb_imax_pct;
  558. do_div(icount, 100);
  559. icount += sbp->sb_agblocks - 1;
  560. do_div(icount, sbp->sb_agblocks);
  561. max_metadata = icount;
  562. } else {
  563. max_metadata = agcount;
  564. }
  565. agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0);
  566. for (index = 0; index < agcount; index++) {
  567. ino = XFS_AGINO_TO_INO(mp, index, agino);
  568. if (ino > XFS_MAXINUMBER_32) {
  569. pag = xfs_perag_get(mp, index);
  570. pag->pagi_inodeok = 0;
  571. pag->pagf_metadata = 0;
  572. xfs_perag_put(pag);
  573. continue;
  574. }
  575. pag = xfs_perag_get(mp, index);
  576. pag->pagi_inodeok = 1;
  577. maxagi++;
  578. if (index < max_metadata)
  579. pag->pagf_metadata = 1;
  580. xfs_perag_put(pag);
  581. }
  582. mp->m_flags |= (XFS_MOUNT_32BITINODES |
  583. XFS_MOUNT_SMALL_INUMS);
  584. return maxagi;
  585. }
  586. xfs_agnumber_t
  587. xfs_set_inode64(struct xfs_mount *mp, xfs_agnumber_t agcount)
  588. {
  589. xfs_agnumber_t index = 0;
  590. for (index = 0; index < agcount; index++) {
  591. struct xfs_perag *pag;
  592. pag = xfs_perag_get(mp, index);
  593. pag->pagi_inodeok = 1;
  594. pag->pagf_metadata = 0;
  595. xfs_perag_put(pag);
  596. }
  597. /* There is no need for lock protection on m_flags,
  598. * the rw_semaphore of the VFS superblock is locked
  599. * during mount/umount/remount operations, so this is
  600. * enough to avoid concurency on the m_flags field
  601. */
  602. mp->m_flags &= ~(XFS_MOUNT_32BITINODES |
  603. XFS_MOUNT_SMALL_INUMS);
  604. return index;
  605. }
  606. STATIC int
  607. xfs_blkdev_get(
  608. xfs_mount_t *mp,
  609. const char *name,
  610. struct block_device **bdevp)
  611. {
  612. int error = 0;
  613. *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
  614. mp);
  615. if (IS_ERR(*bdevp)) {
  616. error = PTR_ERR(*bdevp);
  617. xfs_warn(mp, "Invalid device [%s], error=%d", name, error);
  618. }
  619. return error;
  620. }
  621. STATIC void
  622. xfs_blkdev_put(
  623. struct block_device *bdev)
  624. {
  625. if (bdev)
  626. blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
  627. }
  628. void
  629. xfs_blkdev_issue_flush(
  630. xfs_buftarg_t *buftarg)
  631. {
  632. blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
  633. }
  634. STATIC void
  635. xfs_close_devices(
  636. struct xfs_mount *mp)
  637. {
  638. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  639. struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
  640. xfs_free_buftarg(mp, mp->m_logdev_targp);
  641. xfs_blkdev_put(logdev);
  642. }
  643. if (mp->m_rtdev_targp) {
  644. struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
  645. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  646. xfs_blkdev_put(rtdev);
  647. }
  648. xfs_free_buftarg(mp, mp->m_ddev_targp);
  649. }
  650. /*
  651. * The file system configurations are:
  652. * (1) device (partition) with data and internal log
  653. * (2) logical volume with data and log subvolumes.
  654. * (3) logical volume with data, log, and realtime subvolumes.
  655. *
  656. * We only have to handle opening the log and realtime volumes here if
  657. * they are present. The data subvolume has already been opened by
  658. * get_sb_bdev() and is stored in sb->s_bdev.
  659. */
  660. STATIC int
  661. xfs_open_devices(
  662. struct xfs_mount *mp)
  663. {
  664. struct block_device *ddev = mp->m_super->s_bdev;
  665. struct block_device *logdev = NULL, *rtdev = NULL;
  666. int error;
  667. /*
  668. * Open real time and log devices - order is important.
  669. */
  670. if (mp->m_logname) {
  671. error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
  672. if (error)
  673. goto out;
  674. }
  675. if (mp->m_rtname) {
  676. error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
  677. if (error)
  678. goto out_close_logdev;
  679. if (rtdev == ddev || rtdev == logdev) {
  680. xfs_warn(mp,
  681. "Cannot mount filesystem with identical rtdev and ddev/logdev.");
  682. error = -EINVAL;
  683. goto out_close_rtdev;
  684. }
  685. }
  686. /*
  687. * Setup xfs_mount buffer target pointers
  688. */
  689. error = -ENOMEM;
  690. mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev);
  691. if (!mp->m_ddev_targp)
  692. goto out_close_rtdev;
  693. if (rtdev) {
  694. mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev);
  695. if (!mp->m_rtdev_targp)
  696. goto out_free_ddev_targ;
  697. }
  698. if (logdev && logdev != ddev) {
  699. mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev);
  700. if (!mp->m_logdev_targp)
  701. goto out_free_rtdev_targ;
  702. } else {
  703. mp->m_logdev_targp = mp->m_ddev_targp;
  704. }
  705. return 0;
  706. out_free_rtdev_targ:
  707. if (mp->m_rtdev_targp)
  708. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  709. out_free_ddev_targ:
  710. xfs_free_buftarg(mp, mp->m_ddev_targp);
  711. out_close_rtdev:
  712. xfs_blkdev_put(rtdev);
  713. out_close_logdev:
  714. if (logdev && logdev != ddev)
  715. xfs_blkdev_put(logdev);
  716. out:
  717. return error;
  718. }
  719. /*
  720. * Setup xfs_mount buffer target pointers based on superblock
  721. */
  722. STATIC int
  723. xfs_setup_devices(
  724. struct xfs_mount *mp)
  725. {
  726. int error;
  727. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
  728. if (error)
  729. return error;
  730. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  731. unsigned int log_sector_size = BBSIZE;
  732. if (xfs_sb_version_hassector(&mp->m_sb))
  733. log_sector_size = mp->m_sb.sb_logsectsize;
  734. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  735. log_sector_size);
  736. if (error)
  737. return error;
  738. }
  739. if (mp->m_rtdev_targp) {
  740. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  741. mp->m_sb.sb_sectsize);
  742. if (error)
  743. return error;
  744. }
  745. return 0;
  746. }
  747. STATIC int
  748. xfs_init_mount_workqueues(
  749. struct xfs_mount *mp)
  750. {
  751. mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
  752. WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_fsname);
  753. if (!mp->m_buf_workqueue)
  754. goto out;
  755. mp->m_data_workqueue = alloc_workqueue("xfs-data/%s",
  756. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  757. if (!mp->m_data_workqueue)
  758. goto out_destroy_buf;
  759. mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
  760. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  761. if (!mp->m_unwritten_workqueue)
  762. goto out_destroy_data_iodone_queue;
  763. mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
  764. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  765. if (!mp->m_cil_workqueue)
  766. goto out_destroy_unwritten;
  767. mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
  768. WQ_FREEZABLE, 0, mp->m_fsname);
  769. if (!mp->m_reclaim_workqueue)
  770. goto out_destroy_cil;
  771. mp->m_log_workqueue = alloc_workqueue("xfs-log/%s",
  772. WQ_FREEZABLE|WQ_HIGHPRI, 0, mp->m_fsname);
  773. if (!mp->m_log_workqueue)
  774. goto out_destroy_reclaim;
  775. mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
  776. WQ_FREEZABLE, 0, mp->m_fsname);
  777. if (!mp->m_eofblocks_workqueue)
  778. goto out_destroy_log;
  779. return 0;
  780. out_destroy_log:
  781. destroy_workqueue(mp->m_log_workqueue);
  782. out_destroy_reclaim:
  783. destroy_workqueue(mp->m_reclaim_workqueue);
  784. out_destroy_cil:
  785. destroy_workqueue(mp->m_cil_workqueue);
  786. out_destroy_unwritten:
  787. destroy_workqueue(mp->m_unwritten_workqueue);
  788. out_destroy_data_iodone_queue:
  789. destroy_workqueue(mp->m_data_workqueue);
  790. out_destroy_buf:
  791. destroy_workqueue(mp->m_buf_workqueue);
  792. out:
  793. return -ENOMEM;
  794. }
  795. STATIC void
  796. xfs_destroy_mount_workqueues(
  797. struct xfs_mount *mp)
  798. {
  799. destroy_workqueue(mp->m_eofblocks_workqueue);
  800. destroy_workqueue(mp->m_log_workqueue);
  801. destroy_workqueue(mp->m_reclaim_workqueue);
  802. destroy_workqueue(mp->m_cil_workqueue);
  803. destroy_workqueue(mp->m_data_workqueue);
  804. destroy_workqueue(mp->m_unwritten_workqueue);
  805. destroy_workqueue(mp->m_buf_workqueue);
  806. }
  807. /*
  808. * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
  809. * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
  810. * for IO to complete so that we effectively throttle multiple callers to the
  811. * rate at which IO is completing.
  812. */
  813. void
  814. xfs_flush_inodes(
  815. struct xfs_mount *mp)
  816. {
  817. struct super_block *sb = mp->m_super;
  818. if (down_read_trylock(&sb->s_umount)) {
  819. sync_inodes_sb(sb);
  820. up_read(&sb->s_umount);
  821. }
  822. }
  823. /* Catch misguided souls that try to use this interface on XFS */
  824. STATIC struct inode *
  825. xfs_fs_alloc_inode(
  826. struct super_block *sb)
  827. {
  828. BUG();
  829. return NULL;
  830. }
  831. /*
  832. * Now that the generic code is guaranteed not to be accessing
  833. * the linux inode, we can reclaim the inode.
  834. */
  835. STATIC void
  836. xfs_fs_destroy_inode(
  837. struct inode *inode)
  838. {
  839. struct xfs_inode *ip = XFS_I(inode);
  840. trace_xfs_destroy_inode(ip);
  841. XFS_STATS_INC(vn_reclaim);
  842. ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
  843. /*
  844. * We should never get here with one of the reclaim flags already set.
  845. */
  846. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
  847. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
  848. /*
  849. * We always use background reclaim here because even if the
  850. * inode is clean, it still may be under IO and hence we have
  851. * to take the flush lock. The background reclaim path handles
  852. * this more efficiently than we can here, so simply let background
  853. * reclaim tear down all inodes.
  854. */
  855. xfs_inode_set_reclaim_tag(ip);
  856. }
  857. /*
  858. * Slab object creation initialisation for the XFS inode.
  859. * This covers only the idempotent fields in the XFS inode;
  860. * all other fields need to be initialised on allocation
  861. * from the slab. This avoids the need to repeatedly initialise
  862. * fields in the xfs inode that left in the initialise state
  863. * when freeing the inode.
  864. */
  865. STATIC void
  866. xfs_fs_inode_init_once(
  867. void *inode)
  868. {
  869. struct xfs_inode *ip = inode;
  870. memset(ip, 0, sizeof(struct xfs_inode));
  871. /* vfs inode */
  872. inode_init_once(VFS_I(ip));
  873. /* xfs inode */
  874. atomic_set(&ip->i_pincount, 0);
  875. spin_lock_init(&ip->i_flags_lock);
  876. mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  877. "xfsino", ip->i_ino);
  878. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  879. "xfsino", ip->i_ino);
  880. }
  881. STATIC void
  882. xfs_fs_evict_inode(
  883. struct inode *inode)
  884. {
  885. xfs_inode_t *ip = XFS_I(inode);
  886. ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
  887. trace_xfs_evict_inode(ip);
  888. truncate_inode_pages_final(&inode->i_data);
  889. clear_inode(inode);
  890. XFS_STATS_INC(vn_rele);
  891. XFS_STATS_INC(vn_remove);
  892. xfs_inactive(ip);
  893. }
  894. /*
  895. * We do an unlocked check for XFS_IDONTCACHE here because we are already
  896. * serialised against cache hits here via the inode->i_lock and igrab() in
  897. * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
  898. * racing with us, and it avoids needing to grab a spinlock here for every inode
  899. * we drop the final reference on.
  900. */
  901. STATIC int
  902. xfs_fs_drop_inode(
  903. struct inode *inode)
  904. {
  905. struct xfs_inode *ip = XFS_I(inode);
  906. return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
  907. }
  908. STATIC void
  909. xfs_free_fsname(
  910. struct xfs_mount *mp)
  911. {
  912. kfree(mp->m_fsname);
  913. kfree(mp->m_rtname);
  914. kfree(mp->m_logname);
  915. }
  916. STATIC int
  917. xfs_fs_sync_fs(
  918. struct super_block *sb,
  919. int wait)
  920. {
  921. struct xfs_mount *mp = XFS_M(sb);
  922. /*
  923. * Doing anything during the async pass would be counterproductive.
  924. */
  925. if (!wait)
  926. return 0;
  927. xfs_log_force(mp, XFS_LOG_SYNC);
  928. if (laptop_mode) {
  929. /*
  930. * The disk must be active because we're syncing.
  931. * We schedule log work now (now that the disk is
  932. * active) instead of later (when it might not be).
  933. */
  934. flush_delayed_work(&mp->m_log->l_work);
  935. }
  936. return 0;
  937. }
  938. STATIC int
  939. xfs_fs_statfs(
  940. struct dentry *dentry,
  941. struct kstatfs *statp)
  942. {
  943. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  944. xfs_sb_t *sbp = &mp->m_sb;
  945. struct xfs_inode *ip = XFS_I(d_inode(dentry));
  946. __uint64_t fakeinos, id;
  947. __uint64_t icount;
  948. __uint64_t ifree;
  949. __uint64_t fdblocks;
  950. xfs_extlen_t lsize;
  951. __int64_t ffree;
  952. statp->f_type = XFS_SB_MAGIC;
  953. statp->f_namelen = MAXNAMELEN - 1;
  954. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  955. statp->f_fsid.val[0] = (u32)id;
  956. statp->f_fsid.val[1] = (u32)(id >> 32);
  957. icount = percpu_counter_sum(&mp->m_icount);
  958. ifree = percpu_counter_sum(&mp->m_ifree);
  959. fdblocks = percpu_counter_sum(&mp->m_fdblocks);
  960. spin_lock(&mp->m_sb_lock);
  961. statp->f_bsize = sbp->sb_blocksize;
  962. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  963. statp->f_blocks = sbp->sb_dblocks - lsize;
  964. spin_unlock(&mp->m_sb_lock);
  965. statp->f_bfree = fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  966. statp->f_bavail = statp->f_bfree;
  967. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  968. statp->f_files = MIN(icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  969. if (mp->m_maxicount)
  970. statp->f_files = min_t(typeof(statp->f_files),
  971. statp->f_files,
  972. mp->m_maxicount);
  973. /* If sb_icount overshot maxicount, report actual allocation */
  974. statp->f_files = max_t(typeof(statp->f_files),
  975. statp->f_files,
  976. sbp->sb_icount);
  977. /* make sure statp->f_ffree does not underflow */
  978. ffree = statp->f_files - (icount - ifree);
  979. statp->f_ffree = max_t(__int64_t, ffree, 0);
  980. if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
  981. ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
  982. (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
  983. xfs_qm_statvfs(ip, statp);
  984. return 0;
  985. }
  986. STATIC void
  987. xfs_save_resvblks(struct xfs_mount *mp)
  988. {
  989. __uint64_t resblks = 0;
  990. mp->m_resblks_save = mp->m_resblks;
  991. xfs_reserve_blocks(mp, &resblks, NULL);
  992. }
  993. STATIC void
  994. xfs_restore_resvblks(struct xfs_mount *mp)
  995. {
  996. __uint64_t resblks;
  997. if (mp->m_resblks_save) {
  998. resblks = mp->m_resblks_save;
  999. mp->m_resblks_save = 0;
  1000. } else
  1001. resblks = xfs_default_resblks(mp);
  1002. xfs_reserve_blocks(mp, &resblks, NULL);
  1003. }
  1004. /*
  1005. * Trigger writeback of all the dirty metadata in the file system.
  1006. *
  1007. * This ensures that the metadata is written to their location on disk rather
  1008. * than just existing in transactions in the log. This means after a quiesce
  1009. * there is no log replay required to write the inodes to disk - this is the
  1010. * primary difference between a sync and a quiesce.
  1011. *
  1012. * Note: xfs_log_quiesce() stops background log work - the callers must ensure
  1013. * it is started again when appropriate.
  1014. */
  1015. static void
  1016. xfs_quiesce_attr(
  1017. struct xfs_mount *mp)
  1018. {
  1019. int error = 0;
  1020. /* wait for all modifications to complete */
  1021. while (atomic_read(&mp->m_active_trans) > 0)
  1022. delay(100);
  1023. /* force the log to unpin objects from the now complete transactions */
  1024. xfs_log_force(mp, XFS_LOG_SYNC);
  1025. /* reclaim inodes to do any IO before the freeze completes */
  1026. xfs_reclaim_inodes(mp, 0);
  1027. xfs_reclaim_inodes(mp, SYNC_WAIT);
  1028. /* Push the superblock and write an unmount record */
  1029. error = xfs_log_sbcount(mp);
  1030. if (error)
  1031. xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
  1032. "Frozen image may not be consistent.");
  1033. /*
  1034. * Just warn here till VFS can correctly support
  1035. * read-only remount without racing.
  1036. */
  1037. WARN_ON(atomic_read(&mp->m_active_trans) != 0);
  1038. xfs_log_quiesce(mp);
  1039. }
  1040. STATIC int
  1041. xfs_fs_remount(
  1042. struct super_block *sb,
  1043. int *flags,
  1044. char *options)
  1045. {
  1046. struct xfs_mount *mp = XFS_M(sb);
  1047. xfs_sb_t *sbp = &mp->m_sb;
  1048. substring_t args[MAX_OPT_ARGS];
  1049. char *p;
  1050. int error;
  1051. sync_filesystem(sb);
  1052. while ((p = strsep(&options, ",")) != NULL) {
  1053. int token;
  1054. if (!*p)
  1055. continue;
  1056. token = match_token(p, tokens, args);
  1057. switch (token) {
  1058. case Opt_barrier:
  1059. mp->m_flags |= XFS_MOUNT_BARRIER;
  1060. break;
  1061. case Opt_nobarrier:
  1062. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1063. break;
  1064. case Opt_inode64:
  1065. mp->m_maxagi = xfs_set_inode64(mp, sbp->sb_agcount);
  1066. break;
  1067. case Opt_inode32:
  1068. mp->m_maxagi = xfs_set_inode32(mp, sbp->sb_agcount);
  1069. break;
  1070. default:
  1071. /*
  1072. * Logically we would return an error here to prevent
  1073. * users from believing they might have changed
  1074. * mount options using remount which can't be changed.
  1075. *
  1076. * But unfortunately mount(8) adds all options from
  1077. * mtab and fstab to the mount arguments in some cases
  1078. * so we can't blindly reject options, but have to
  1079. * check for each specified option if it actually
  1080. * differs from the currently set option and only
  1081. * reject it if that's the case.
  1082. *
  1083. * Until that is implemented we return success for
  1084. * every remount request, and silently ignore all
  1085. * options that we can't actually change.
  1086. */
  1087. #if 0
  1088. xfs_info(mp,
  1089. "mount option \"%s\" not supported for remount", p);
  1090. return -EINVAL;
  1091. #else
  1092. break;
  1093. #endif
  1094. }
  1095. }
  1096. /* ro -> rw */
  1097. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1098. if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
  1099. xfs_warn(mp,
  1100. "ro->rw transition prohibited on norecovery mount");
  1101. return -EINVAL;
  1102. }
  1103. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1104. /*
  1105. * If this is the first remount to writeable state we
  1106. * might have some superblock changes to update.
  1107. */
  1108. if (mp->m_update_sb) {
  1109. error = xfs_sync_sb(mp, false);
  1110. if (error) {
  1111. xfs_warn(mp, "failed to write sb changes");
  1112. return error;
  1113. }
  1114. mp->m_update_sb = false;
  1115. }
  1116. /*
  1117. * Fill out the reserve pool if it is empty. Use the stashed
  1118. * value if it is non-zero, otherwise go with the default.
  1119. */
  1120. xfs_restore_resvblks(mp);
  1121. xfs_log_work_queue(mp);
  1122. }
  1123. /* rw -> ro */
  1124. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1125. /*
  1126. * Before we sync the metadata, we need to free up the reserve
  1127. * block pool so that the used block count in the superblock on
  1128. * disk is correct at the end of the remount. Stash the current
  1129. * reserve pool size so that if we get remounted rw, we can
  1130. * return it to the same size.
  1131. */
  1132. xfs_save_resvblks(mp);
  1133. xfs_quiesce_attr(mp);
  1134. mp->m_flags |= XFS_MOUNT_RDONLY;
  1135. }
  1136. return 0;
  1137. }
  1138. /*
  1139. * Second stage of a freeze. The data is already frozen so we only
  1140. * need to take care of the metadata. Once that's done sync the superblock
  1141. * to the log to dirty it in case of a crash while frozen. This ensures that we
  1142. * will recover the unlinked inode lists on the next mount.
  1143. */
  1144. STATIC int
  1145. xfs_fs_freeze(
  1146. struct super_block *sb)
  1147. {
  1148. struct xfs_mount *mp = XFS_M(sb);
  1149. xfs_save_resvblks(mp);
  1150. xfs_quiesce_attr(mp);
  1151. return xfs_sync_sb(mp, true);
  1152. }
  1153. STATIC int
  1154. xfs_fs_unfreeze(
  1155. struct super_block *sb)
  1156. {
  1157. struct xfs_mount *mp = XFS_M(sb);
  1158. xfs_restore_resvblks(mp);
  1159. xfs_log_work_queue(mp);
  1160. return 0;
  1161. }
  1162. STATIC int
  1163. xfs_fs_show_options(
  1164. struct seq_file *m,
  1165. struct dentry *root)
  1166. {
  1167. return xfs_showargs(XFS_M(root->d_sb), m);
  1168. }
  1169. /*
  1170. * This function fills in xfs_mount_t fields based on mount args.
  1171. * Note: the superblock _has_ now been read in.
  1172. */
  1173. STATIC int
  1174. xfs_finish_flags(
  1175. struct xfs_mount *mp)
  1176. {
  1177. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1178. /* Fail a mount where the logbuf is smaller than the log stripe */
  1179. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1180. if (mp->m_logbsize <= 0 &&
  1181. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  1182. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1183. } else if (mp->m_logbsize > 0 &&
  1184. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  1185. xfs_warn(mp,
  1186. "logbuf size must be greater than or equal to log stripe size");
  1187. return -EINVAL;
  1188. }
  1189. } else {
  1190. /* Fail a mount if the logbuf is larger than 32K */
  1191. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  1192. xfs_warn(mp,
  1193. "logbuf size for version 1 logs must be 16K or 32K");
  1194. return -EINVAL;
  1195. }
  1196. }
  1197. /*
  1198. * V5 filesystems always use attr2 format for attributes.
  1199. */
  1200. if (xfs_sb_version_hascrc(&mp->m_sb) &&
  1201. (mp->m_flags & XFS_MOUNT_NOATTR2)) {
  1202. xfs_warn(mp,
  1203. "Cannot mount a V5 filesystem as %s. %s is always enabled for V5 filesystems.",
  1204. MNTOPT_NOATTR2, MNTOPT_ATTR2);
  1205. return -EINVAL;
  1206. }
  1207. /*
  1208. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1209. * told by noattr2 to turn it off
  1210. */
  1211. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1212. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  1213. mp->m_flags |= XFS_MOUNT_ATTR2;
  1214. /*
  1215. * prohibit r/w mounts of read-only filesystems
  1216. */
  1217. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1218. xfs_warn(mp,
  1219. "cannot mount a read-only filesystem as read-write");
  1220. return -EROFS;
  1221. }
  1222. if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
  1223. (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
  1224. !xfs_sb_version_has_pquotino(&mp->m_sb)) {
  1225. xfs_warn(mp,
  1226. "Super block does not support project and group quota together");
  1227. return -EINVAL;
  1228. }
  1229. return 0;
  1230. }
  1231. static int
  1232. xfs_init_percpu_counters(
  1233. struct xfs_mount *mp)
  1234. {
  1235. int error;
  1236. error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
  1237. if (error)
  1238. return -ENOMEM;
  1239. error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
  1240. if (error)
  1241. goto free_icount;
  1242. error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
  1243. if (error)
  1244. goto free_ifree;
  1245. return 0;
  1246. free_ifree:
  1247. percpu_counter_destroy(&mp->m_ifree);
  1248. free_icount:
  1249. percpu_counter_destroy(&mp->m_icount);
  1250. return -ENOMEM;
  1251. }
  1252. void
  1253. xfs_reinit_percpu_counters(
  1254. struct xfs_mount *mp)
  1255. {
  1256. percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
  1257. percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
  1258. percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
  1259. }
  1260. static void
  1261. xfs_destroy_percpu_counters(
  1262. struct xfs_mount *mp)
  1263. {
  1264. percpu_counter_destroy(&mp->m_icount);
  1265. percpu_counter_destroy(&mp->m_ifree);
  1266. percpu_counter_destroy(&mp->m_fdblocks);
  1267. }
  1268. STATIC int
  1269. xfs_fs_fill_super(
  1270. struct super_block *sb,
  1271. void *data,
  1272. int silent)
  1273. {
  1274. struct inode *root;
  1275. struct xfs_mount *mp = NULL;
  1276. int flags = 0, error = -ENOMEM;
  1277. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1278. if (!mp)
  1279. goto out;
  1280. spin_lock_init(&mp->m_sb_lock);
  1281. mutex_init(&mp->m_growlock);
  1282. atomic_set(&mp->m_active_trans, 0);
  1283. INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
  1284. INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
  1285. mp->m_kobj.kobject.kset = xfs_kset;
  1286. mp->m_super = sb;
  1287. sb->s_fs_info = mp;
  1288. error = xfs_parseargs(mp, (char *)data);
  1289. if (error)
  1290. goto out_free_fsname;
  1291. sb_min_blocksize(sb, BBSIZE);
  1292. sb->s_xattr = xfs_xattr_handlers;
  1293. sb->s_export_op = &xfs_export_operations;
  1294. #ifdef CONFIG_XFS_QUOTA
  1295. sb->s_qcop = &xfs_quotactl_operations;
  1296. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
  1297. #endif
  1298. sb->s_op = &xfs_super_operations;
  1299. if (silent)
  1300. flags |= XFS_MFSI_QUIET;
  1301. error = xfs_open_devices(mp);
  1302. if (error)
  1303. goto out_free_fsname;
  1304. error = xfs_init_mount_workqueues(mp);
  1305. if (error)
  1306. goto out_close_devices;
  1307. error = xfs_init_percpu_counters(mp);
  1308. if (error)
  1309. goto out_destroy_workqueues;
  1310. error = xfs_readsb(mp, flags);
  1311. if (error)
  1312. goto out_destroy_counters;
  1313. error = xfs_finish_flags(mp);
  1314. if (error)
  1315. goto out_free_sb;
  1316. error = xfs_setup_devices(mp);
  1317. if (error)
  1318. goto out_free_sb;
  1319. error = xfs_filestream_mount(mp);
  1320. if (error)
  1321. goto out_free_sb;
  1322. /*
  1323. * we must configure the block size in the superblock before we run the
  1324. * full mount process as the mount process can lookup and cache inodes.
  1325. */
  1326. sb->s_magic = XFS_SB_MAGIC;
  1327. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1328. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1329. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1330. sb->s_max_links = XFS_MAXLINK;
  1331. sb->s_time_gran = 1;
  1332. set_posix_acl_flag(sb);
  1333. /* version 5 superblocks support inode version counters. */
  1334. if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
  1335. sb->s_flags |= MS_I_VERSION;
  1336. if (mp->m_flags & XFS_MOUNT_DAX) {
  1337. xfs_warn(mp,
  1338. "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
  1339. if (sb->s_blocksize != PAGE_SIZE) {
  1340. xfs_alert(mp,
  1341. "Filesystem block size invalid for DAX Turning DAX off.");
  1342. mp->m_flags &= ~XFS_MOUNT_DAX;
  1343. } else if (!sb->s_bdev->bd_disk->fops->direct_access) {
  1344. xfs_alert(mp,
  1345. "Block device does not support DAX Turning DAX off.");
  1346. mp->m_flags &= ~XFS_MOUNT_DAX;
  1347. }
  1348. }
  1349. error = xfs_mountfs(mp);
  1350. if (error)
  1351. goto out_filestream_unmount;
  1352. root = igrab(VFS_I(mp->m_rootip));
  1353. if (!root) {
  1354. error = -ENOENT;
  1355. goto out_unmount;
  1356. }
  1357. sb->s_root = d_make_root(root);
  1358. if (!sb->s_root) {
  1359. error = -ENOMEM;
  1360. goto out_unmount;
  1361. }
  1362. return 0;
  1363. out_filestream_unmount:
  1364. xfs_filestream_unmount(mp);
  1365. out_free_sb:
  1366. xfs_freesb(mp);
  1367. out_destroy_counters:
  1368. xfs_destroy_percpu_counters(mp);
  1369. out_destroy_workqueues:
  1370. xfs_destroy_mount_workqueues(mp);
  1371. out_close_devices:
  1372. xfs_close_devices(mp);
  1373. out_free_fsname:
  1374. xfs_free_fsname(mp);
  1375. kfree(mp);
  1376. out:
  1377. return error;
  1378. out_unmount:
  1379. xfs_filestream_unmount(mp);
  1380. xfs_unmountfs(mp);
  1381. goto out_free_sb;
  1382. }
  1383. STATIC void
  1384. xfs_fs_put_super(
  1385. struct super_block *sb)
  1386. {
  1387. struct xfs_mount *mp = XFS_M(sb);
  1388. xfs_notice(mp, "Unmounting Filesystem");
  1389. xfs_filestream_unmount(mp);
  1390. xfs_unmountfs(mp);
  1391. xfs_freesb(mp);
  1392. xfs_destroy_percpu_counters(mp);
  1393. xfs_destroy_mount_workqueues(mp);
  1394. xfs_close_devices(mp);
  1395. xfs_free_fsname(mp);
  1396. kfree(mp);
  1397. }
  1398. STATIC struct dentry *
  1399. xfs_fs_mount(
  1400. struct file_system_type *fs_type,
  1401. int flags,
  1402. const char *dev_name,
  1403. void *data)
  1404. {
  1405. return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
  1406. }
  1407. static long
  1408. xfs_fs_nr_cached_objects(
  1409. struct super_block *sb,
  1410. struct shrink_control *sc)
  1411. {
  1412. return xfs_reclaim_inodes_count(XFS_M(sb));
  1413. }
  1414. static long
  1415. xfs_fs_free_cached_objects(
  1416. struct super_block *sb,
  1417. struct shrink_control *sc)
  1418. {
  1419. return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
  1420. }
  1421. static const struct super_operations xfs_super_operations = {
  1422. .alloc_inode = xfs_fs_alloc_inode,
  1423. .destroy_inode = xfs_fs_destroy_inode,
  1424. .evict_inode = xfs_fs_evict_inode,
  1425. .drop_inode = xfs_fs_drop_inode,
  1426. .put_super = xfs_fs_put_super,
  1427. .sync_fs = xfs_fs_sync_fs,
  1428. .freeze_fs = xfs_fs_freeze,
  1429. .unfreeze_fs = xfs_fs_unfreeze,
  1430. .statfs = xfs_fs_statfs,
  1431. .remount_fs = xfs_fs_remount,
  1432. .show_options = xfs_fs_show_options,
  1433. .nr_cached_objects = xfs_fs_nr_cached_objects,
  1434. .free_cached_objects = xfs_fs_free_cached_objects,
  1435. };
  1436. static struct file_system_type xfs_fs_type = {
  1437. .owner = THIS_MODULE,
  1438. .name = "xfs",
  1439. .mount = xfs_fs_mount,
  1440. .kill_sb = kill_block_super,
  1441. .fs_flags = FS_REQUIRES_DEV,
  1442. };
  1443. MODULE_ALIAS_FS("xfs");
  1444. STATIC int __init
  1445. xfs_init_zones(void)
  1446. {
  1447. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  1448. if (!xfs_ioend_zone)
  1449. goto out;
  1450. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  1451. xfs_ioend_zone);
  1452. if (!xfs_ioend_pool)
  1453. goto out_destroy_ioend_zone;
  1454. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1455. "xfs_log_ticket");
  1456. if (!xfs_log_ticket_zone)
  1457. goto out_destroy_ioend_pool;
  1458. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  1459. "xfs_bmap_free_item");
  1460. if (!xfs_bmap_free_item_zone)
  1461. goto out_destroy_log_ticket_zone;
  1462. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1463. "xfs_btree_cur");
  1464. if (!xfs_btree_cur_zone)
  1465. goto out_destroy_bmap_free_item_zone;
  1466. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1467. "xfs_da_state");
  1468. if (!xfs_da_state_zone)
  1469. goto out_destroy_btree_cur_zone;
  1470. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1471. if (!xfs_ifork_zone)
  1472. goto out_destroy_da_state_zone;
  1473. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1474. if (!xfs_trans_zone)
  1475. goto out_destroy_ifork_zone;
  1476. xfs_log_item_desc_zone =
  1477. kmem_zone_init(sizeof(struct xfs_log_item_desc),
  1478. "xfs_log_item_desc");
  1479. if (!xfs_log_item_desc_zone)
  1480. goto out_destroy_trans_zone;
  1481. /*
  1482. * The size of the zone allocated buf log item is the maximum
  1483. * size possible under XFS. This wastes a little bit of memory,
  1484. * but it is much faster.
  1485. */
  1486. xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
  1487. "xfs_buf_item");
  1488. if (!xfs_buf_item_zone)
  1489. goto out_destroy_log_item_desc_zone;
  1490. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1491. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1492. sizeof(xfs_extent_t))), "xfs_efd_item");
  1493. if (!xfs_efd_zone)
  1494. goto out_destroy_buf_item_zone;
  1495. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1496. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1497. sizeof(xfs_extent_t))), "xfs_efi_item");
  1498. if (!xfs_efi_zone)
  1499. goto out_destroy_efd_zone;
  1500. xfs_inode_zone =
  1501. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1502. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
  1503. xfs_fs_inode_init_once);
  1504. if (!xfs_inode_zone)
  1505. goto out_destroy_efi_zone;
  1506. xfs_ili_zone =
  1507. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1508. KM_ZONE_SPREAD, NULL);
  1509. if (!xfs_ili_zone)
  1510. goto out_destroy_inode_zone;
  1511. xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
  1512. "xfs_icr");
  1513. if (!xfs_icreate_zone)
  1514. goto out_destroy_ili_zone;
  1515. return 0;
  1516. out_destroy_ili_zone:
  1517. kmem_zone_destroy(xfs_ili_zone);
  1518. out_destroy_inode_zone:
  1519. kmem_zone_destroy(xfs_inode_zone);
  1520. out_destroy_efi_zone:
  1521. kmem_zone_destroy(xfs_efi_zone);
  1522. out_destroy_efd_zone:
  1523. kmem_zone_destroy(xfs_efd_zone);
  1524. out_destroy_buf_item_zone:
  1525. kmem_zone_destroy(xfs_buf_item_zone);
  1526. out_destroy_log_item_desc_zone:
  1527. kmem_zone_destroy(xfs_log_item_desc_zone);
  1528. out_destroy_trans_zone:
  1529. kmem_zone_destroy(xfs_trans_zone);
  1530. out_destroy_ifork_zone:
  1531. kmem_zone_destroy(xfs_ifork_zone);
  1532. out_destroy_da_state_zone:
  1533. kmem_zone_destroy(xfs_da_state_zone);
  1534. out_destroy_btree_cur_zone:
  1535. kmem_zone_destroy(xfs_btree_cur_zone);
  1536. out_destroy_bmap_free_item_zone:
  1537. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1538. out_destroy_log_ticket_zone:
  1539. kmem_zone_destroy(xfs_log_ticket_zone);
  1540. out_destroy_ioend_pool:
  1541. mempool_destroy(xfs_ioend_pool);
  1542. out_destroy_ioend_zone:
  1543. kmem_zone_destroy(xfs_ioend_zone);
  1544. out:
  1545. return -ENOMEM;
  1546. }
  1547. STATIC void
  1548. xfs_destroy_zones(void)
  1549. {
  1550. /*
  1551. * Make sure all delayed rcu free are flushed before we
  1552. * destroy caches.
  1553. */
  1554. rcu_barrier();
  1555. kmem_zone_destroy(xfs_icreate_zone);
  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_da_state_zone);
  1565. kmem_zone_destroy(xfs_btree_cur_zone);
  1566. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1567. kmem_zone_destroy(xfs_log_ticket_zone);
  1568. mempool_destroy(xfs_ioend_pool);
  1569. kmem_zone_destroy(xfs_ioend_zone);
  1570. }
  1571. STATIC int __init
  1572. xfs_init_workqueues(void)
  1573. {
  1574. /*
  1575. * The allocation workqueue can be used in memory reclaim situations
  1576. * (writepage path), and parallelism is only limited by the number of
  1577. * AGs in all the filesystems mounted. Hence use the default large
  1578. * max_active value for this workqueue.
  1579. */
  1580. xfs_alloc_wq = alloc_workqueue("xfsalloc",
  1581. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
  1582. if (!xfs_alloc_wq)
  1583. return -ENOMEM;
  1584. return 0;
  1585. }
  1586. STATIC void
  1587. xfs_destroy_workqueues(void)
  1588. {
  1589. destroy_workqueue(xfs_alloc_wq);
  1590. }
  1591. STATIC int __init
  1592. init_xfs_fs(void)
  1593. {
  1594. int error;
  1595. printk(KERN_INFO XFS_VERSION_STRING " with "
  1596. XFS_BUILD_OPTIONS " enabled\n");
  1597. xfs_dir_startup();
  1598. error = xfs_init_zones();
  1599. if (error)
  1600. goto out;
  1601. error = xfs_init_workqueues();
  1602. if (error)
  1603. goto out_destroy_zones;
  1604. error = xfs_mru_cache_init();
  1605. if (error)
  1606. goto out_destroy_wq;
  1607. error = xfs_buf_init();
  1608. if (error)
  1609. goto out_mru_cache_uninit;
  1610. error = xfs_init_procfs();
  1611. if (error)
  1612. goto out_buf_terminate;
  1613. error = xfs_sysctl_register();
  1614. if (error)
  1615. goto out_cleanup_procfs;
  1616. xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
  1617. if (!xfs_kset) {
  1618. error = -ENOMEM;
  1619. goto out_sysctl_unregister;;
  1620. }
  1621. #ifdef DEBUG
  1622. xfs_dbg_kobj.kobject.kset = xfs_kset;
  1623. error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
  1624. if (error)
  1625. goto out_kset_unregister;
  1626. #endif
  1627. error = xfs_qm_init();
  1628. if (error)
  1629. goto out_remove_kobj;
  1630. error = register_filesystem(&xfs_fs_type);
  1631. if (error)
  1632. goto out_qm_exit;
  1633. return 0;
  1634. out_qm_exit:
  1635. xfs_qm_exit();
  1636. out_remove_kobj:
  1637. #ifdef DEBUG
  1638. xfs_sysfs_del(&xfs_dbg_kobj);
  1639. out_kset_unregister:
  1640. #endif
  1641. kset_unregister(xfs_kset);
  1642. out_sysctl_unregister:
  1643. xfs_sysctl_unregister();
  1644. out_cleanup_procfs:
  1645. xfs_cleanup_procfs();
  1646. out_buf_terminate:
  1647. xfs_buf_terminate();
  1648. out_mru_cache_uninit:
  1649. xfs_mru_cache_uninit();
  1650. out_destroy_wq:
  1651. xfs_destroy_workqueues();
  1652. out_destroy_zones:
  1653. xfs_destroy_zones();
  1654. out:
  1655. return error;
  1656. }
  1657. STATIC void __exit
  1658. exit_xfs_fs(void)
  1659. {
  1660. xfs_qm_exit();
  1661. unregister_filesystem(&xfs_fs_type);
  1662. #ifdef DEBUG
  1663. xfs_sysfs_del(&xfs_dbg_kobj);
  1664. #endif
  1665. kset_unregister(xfs_kset);
  1666. xfs_sysctl_unregister();
  1667. xfs_cleanup_procfs();
  1668. xfs_buf_terminate();
  1669. xfs_mru_cache_uninit();
  1670. xfs_destroy_workqueues();
  1671. xfs_destroy_zones();
  1672. }
  1673. module_init(init_xfs_fs);
  1674. module_exit(exit_xfs_fs);
  1675. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1676. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1677. MODULE_LICENSE("GPL");