xfs_super.c 48 KB

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