xfs_super.c 49 KB

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