xfs_super.c 48 KB

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