xfs_super.c 48 KB

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