xfs_super.c 50 KB

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