xfs_super.c 48 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_bit.h"
  20. #include "xfs_log.h"
  21. #include "xfs_inum.h"
  22. #include "xfs_trans.h"
  23. #include "xfs_sb.h"
  24. #include "xfs_ag.h"
  25. #include "xfs_dir2.h"
  26. #include "xfs_alloc.h"
  27. #include "xfs_dmapi.h"
  28. #include "xfs_quota.h"
  29. #include "xfs_mount.h"
  30. #include "xfs_bmap_btree.h"
  31. #include "xfs_alloc_btree.h"
  32. #include "xfs_ialloc_btree.h"
  33. #include "xfs_dir2_sf.h"
  34. #include "xfs_attr_sf.h"
  35. #include "xfs_dinode.h"
  36. #include "xfs_inode.h"
  37. #include "xfs_btree.h"
  38. #include "xfs_btree_trace.h"
  39. #include "xfs_ialloc.h"
  40. #include "xfs_bmap.h"
  41. #include "xfs_rtalloc.h"
  42. #include "xfs_error.h"
  43. #include "xfs_itable.h"
  44. #include "xfs_fsops.h"
  45. #include "xfs_rw.h"
  46. #include "xfs_acl.h"
  47. #include "xfs_attr.h"
  48. #include "xfs_buf_item.h"
  49. #include "xfs_utils.h"
  50. #include "xfs_vnodeops.h"
  51. #include "xfs_version.h"
  52. #include "xfs_log_priv.h"
  53. #include "xfs_trans_priv.h"
  54. #include "xfs_filestream.h"
  55. #include "xfs_da_btree.h"
  56. #include "xfs_dir2_trace.h"
  57. #include "xfs_extfree_item.h"
  58. #include "xfs_mru_cache.h"
  59. #include "xfs_inode_item.h"
  60. #include "xfs_sync.h"
  61. #include <linux/namei.h>
  62. #include <linux/init.h>
  63. #include <linux/mount.h>
  64. #include <linux/mempool.h>
  65. #include <linux/writeback.h>
  66. #include <linux/kthread.h>
  67. #include <linux/freezer.h>
  68. #include <linux/parser.h>
  69. static struct quotactl_ops xfs_quotactl_operations;
  70. static struct super_operations xfs_super_operations;
  71. static kmem_zone_t *xfs_ioend_zone;
  72. mempool_t *xfs_ioend_pool;
  73. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  74. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  75. #define MNTOPT_LOGDEV "logdev" /* log device */
  76. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  77. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  78. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  79. #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
  80. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  81. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  82. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  83. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  84. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  85. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  86. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  87. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  88. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  89. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  90. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  91. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  92. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  93. * unwritten extent conversion */
  94. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  95. #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
  96. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  97. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  98. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  99. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  100. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  101. * in stat(). */
  102. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  103. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  104. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  105. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  106. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  107. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  108. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  109. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  110. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  111. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  112. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  113. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  114. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  115. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  116. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  117. #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
  118. #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
  119. #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
  120. /*
  121. * Table driven mount option parser.
  122. *
  123. * Currently only used for remount, but it will be used for mount
  124. * in the future, too.
  125. */
  126. enum {
  127. Opt_barrier, Opt_nobarrier, Opt_err
  128. };
  129. static const match_table_t tokens = {
  130. {Opt_barrier, "barrier"},
  131. {Opt_nobarrier, "nobarrier"},
  132. {Opt_err, NULL}
  133. };
  134. STATIC unsigned long
  135. suffix_strtoul(char *s, char **endp, unsigned int base)
  136. {
  137. int last, shift_left_factor = 0;
  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. return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
  153. }
  154. /*
  155. * This function fills in xfs_mount_t fields based on mount args.
  156. * Note: the superblock has _not_ yet been read in.
  157. *
  158. * Note that this function leaks the various device name allocations on
  159. * failure. The caller takes care of them.
  160. */
  161. STATIC int
  162. xfs_parseargs(
  163. struct xfs_mount *mp,
  164. char *options,
  165. char **mtpt)
  166. {
  167. struct super_block *sb = mp->m_super;
  168. char *this_char, *value, *eov;
  169. int dsunit = 0;
  170. int dswidth = 0;
  171. int iosize = 0;
  172. int dmapi_implies_ikeep = 1;
  173. uchar_t iosizelog = 0;
  174. /*
  175. * Copy binary VFS mount flags we are interested in.
  176. */
  177. if (sb->s_flags & MS_RDONLY)
  178. mp->m_flags |= XFS_MOUNT_RDONLY;
  179. if (sb->s_flags & MS_DIRSYNC)
  180. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  181. if (sb->s_flags & MS_SYNCHRONOUS)
  182. mp->m_flags |= XFS_MOUNT_WSYNC;
  183. /*
  184. * Set some default flags that could be cleared by the mount option
  185. * parsing.
  186. */
  187. mp->m_flags |= XFS_MOUNT_BARRIER;
  188. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  189. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  190. /*
  191. * These can be overridden by the mount option parsing.
  192. */
  193. mp->m_logbufs = -1;
  194. mp->m_logbsize = -1;
  195. if (!options)
  196. goto done;
  197. while ((this_char = strsep(&options, ",")) != NULL) {
  198. if (!*this_char)
  199. continue;
  200. if ((value = strchr(this_char, '=')) != NULL)
  201. *value++ = 0;
  202. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  203. if (!value || !*value) {
  204. cmn_err(CE_WARN,
  205. "XFS: %s option requires an argument",
  206. this_char);
  207. return EINVAL;
  208. }
  209. mp->m_logbufs = simple_strtoul(value, &eov, 10);
  210. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  211. if (!value || !*value) {
  212. cmn_err(CE_WARN,
  213. "XFS: %s option requires an argument",
  214. this_char);
  215. return EINVAL;
  216. }
  217. mp->m_logbsize = suffix_strtoul(value, &eov, 10);
  218. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  219. if (!value || !*value) {
  220. cmn_err(CE_WARN,
  221. "XFS: %s option requires an argument",
  222. this_char);
  223. return EINVAL;
  224. }
  225. mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  226. if (!mp->m_logname)
  227. return ENOMEM;
  228. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  229. if (!value || !*value) {
  230. cmn_err(CE_WARN,
  231. "XFS: %s option requires an argument",
  232. this_char);
  233. return EINVAL;
  234. }
  235. *mtpt = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  236. if (!*mtpt)
  237. return ENOMEM;
  238. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  239. if (!value || !*value) {
  240. cmn_err(CE_WARN,
  241. "XFS: %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. cmn_err(CE_WARN,
  251. "XFS: %s option requires an argument",
  252. this_char);
  253. return EINVAL;
  254. }
  255. iosize = simple_strtoul(value, &eov, 10);
  256. iosizelog = ffs(iosize) - 1;
  257. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  258. if (!value || !*value) {
  259. cmn_err(CE_WARN,
  260. "XFS: %s option requires an argument",
  261. this_char);
  262. return EINVAL;
  263. }
  264. iosize = suffix_strtoul(value, &eov, 10);
  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_OSYNCISOSYNC)) {
  275. mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
  276. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  277. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  278. } else if (!strcmp(this_char, MNTOPT_INO64)) {
  279. #if XFS_BIG_INUMS
  280. mp->m_flags |= XFS_MOUNT_INO64;
  281. mp->m_inoadd = XFS_INO64_OFFSET;
  282. #else
  283. cmn_err(CE_WARN,
  284. "XFS: %s option not allowed on this system",
  285. this_char);
  286. return EINVAL;
  287. #endif
  288. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  289. mp->m_flags |= XFS_MOUNT_NOALIGN;
  290. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  291. mp->m_flags |= XFS_MOUNT_SWALLOC;
  292. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  293. if (!value || !*value) {
  294. cmn_err(CE_WARN,
  295. "XFS: %s option requires an argument",
  296. this_char);
  297. return EINVAL;
  298. }
  299. dsunit = simple_strtoul(value, &eov, 10);
  300. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  301. if (!value || !*value) {
  302. cmn_err(CE_WARN,
  303. "XFS: %s option requires an argument",
  304. this_char);
  305. return EINVAL;
  306. }
  307. dswidth = simple_strtoul(value, &eov, 10);
  308. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  309. mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
  310. #if !XFS_BIG_INUMS
  311. cmn_err(CE_WARN,
  312. "XFS: %s option not allowed on this system",
  313. this_char);
  314. return EINVAL;
  315. #endif
  316. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  317. mp->m_flags |= XFS_MOUNT_NOUUID;
  318. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  319. mp->m_flags |= XFS_MOUNT_BARRIER;
  320. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  321. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  322. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  323. mp->m_flags |= XFS_MOUNT_IKEEP;
  324. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  325. dmapi_implies_ikeep = 0;
  326. mp->m_flags &= ~XFS_MOUNT_IKEEP;
  327. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  328. mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
  329. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  330. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  331. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  332. mp->m_flags |= XFS_MOUNT_ATTR2;
  333. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  334. mp->m_flags &= ~XFS_MOUNT_ATTR2;
  335. mp->m_flags |= XFS_MOUNT_NOATTR2;
  336. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  337. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  338. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  339. mp->m_qflags &= ~(XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
  340. XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
  341. XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
  342. XFS_UQUOTA_ENFD | XFS_OQUOTA_ENFD);
  343. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  344. !strcmp(this_char, MNTOPT_UQUOTA) ||
  345. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  346. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
  347. XFS_UQUOTA_ENFD);
  348. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  349. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  350. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  351. mp->m_qflags &= ~XFS_UQUOTA_ENFD;
  352. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  353. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  354. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
  355. XFS_OQUOTA_ENFD);
  356. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  357. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  358. mp->m_qflags &= ~XFS_OQUOTA_ENFD;
  359. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  360. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  361. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
  362. XFS_OQUOTA_ENFD);
  363. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  364. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  365. mp->m_qflags &= ~XFS_OQUOTA_ENFD;
  366. } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
  367. mp->m_flags |= XFS_MOUNT_DMAPI;
  368. } else if (!strcmp(this_char, MNTOPT_XDSM)) {
  369. mp->m_flags |= XFS_MOUNT_DMAPI;
  370. } else if (!strcmp(this_char, MNTOPT_DMI)) {
  371. mp->m_flags |= XFS_MOUNT_DMAPI;
  372. } else if (!strcmp(this_char, "ihashsize")) {
  373. cmn_err(CE_WARN,
  374. "XFS: ihashsize no longer used, option is deprecated.");
  375. } else if (!strcmp(this_char, "osyncisdsync")) {
  376. /* no-op, this is now the default */
  377. cmn_err(CE_WARN,
  378. "XFS: osyncisdsync is now the default, option is deprecated.");
  379. } else if (!strcmp(this_char, "irixsgid")) {
  380. cmn_err(CE_WARN,
  381. "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
  382. } else {
  383. cmn_err(CE_WARN,
  384. "XFS: unknown mount option [%s].", this_char);
  385. return EINVAL;
  386. }
  387. }
  388. /*
  389. * no recovery flag requires a read-only mount
  390. */
  391. if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
  392. !(mp->m_flags & XFS_MOUNT_RDONLY)) {
  393. cmn_err(CE_WARN, "XFS: no-recovery mounts must be read-only.");
  394. return EINVAL;
  395. }
  396. if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
  397. cmn_err(CE_WARN,
  398. "XFS: sunit and swidth options incompatible with the noalign option");
  399. return EINVAL;
  400. }
  401. if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
  402. (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
  403. cmn_err(CE_WARN,
  404. "XFS: cannot mount with both project and group quota");
  405. return EINVAL;
  406. }
  407. if ((mp->m_flags & XFS_MOUNT_DMAPI) && (!*mtpt || *mtpt[0] == '\0')) {
  408. printk("XFS: %s option needs the mount point option as well\n",
  409. MNTOPT_DMAPI);
  410. return EINVAL;
  411. }
  412. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  413. cmn_err(CE_WARN,
  414. "XFS: sunit and swidth must be specified together");
  415. return EINVAL;
  416. }
  417. if (dsunit && (dswidth % dsunit != 0)) {
  418. cmn_err(CE_WARN,
  419. "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
  420. dswidth, dsunit);
  421. return EINVAL;
  422. }
  423. /*
  424. * Applications using DMI filesystems often expect the
  425. * inode generation number to be monotonically increasing.
  426. * If we delete inode chunks we break this assumption, so
  427. * keep unused inode chunks on disk for DMI filesystems
  428. * until we come up with a better solution.
  429. * Note that if "ikeep" or "noikeep" mount options are
  430. * supplied, then they are honored.
  431. */
  432. if ((mp->m_flags & XFS_MOUNT_DMAPI) && dmapi_implies_ikeep)
  433. mp->m_flags |= XFS_MOUNT_IKEEP;
  434. done:
  435. if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
  436. /*
  437. * At this point the superblock has not been read
  438. * in, therefore we do not know the block size.
  439. * Before the mount call ends we will convert
  440. * these to FSBs.
  441. */
  442. if (dsunit) {
  443. mp->m_dalign = dsunit;
  444. mp->m_flags |= XFS_MOUNT_RETERR;
  445. }
  446. if (dswidth)
  447. mp->m_swidth = dswidth;
  448. }
  449. if (mp->m_logbufs != -1 &&
  450. mp->m_logbufs != 0 &&
  451. (mp->m_logbufs < XLOG_MIN_ICLOGS ||
  452. mp->m_logbufs > XLOG_MAX_ICLOGS)) {
  453. cmn_err(CE_WARN,
  454. "XFS: invalid logbufs value: %d [not %d-%d]",
  455. mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  456. return XFS_ERROR(EINVAL);
  457. }
  458. if (mp->m_logbsize != -1 &&
  459. mp->m_logbsize != 0 &&
  460. (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
  461. mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
  462. !is_power_of_2(mp->m_logbsize))) {
  463. cmn_err(CE_WARN,
  464. "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  465. mp->m_logbsize);
  466. return XFS_ERROR(EINVAL);
  467. }
  468. mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
  469. if (!mp->m_fsname)
  470. return ENOMEM;
  471. mp->m_fsname_len = strlen(mp->m_fsname) + 1;
  472. if (iosizelog) {
  473. if (iosizelog > XFS_MAX_IO_LOG ||
  474. iosizelog < XFS_MIN_IO_LOG) {
  475. cmn_err(CE_WARN,
  476. "XFS: invalid log iosize: %d [not %d-%d]",
  477. iosizelog, XFS_MIN_IO_LOG,
  478. XFS_MAX_IO_LOG);
  479. return XFS_ERROR(EINVAL);
  480. }
  481. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  482. mp->m_readio_log = iosizelog;
  483. mp->m_writeio_log = iosizelog;
  484. }
  485. return 0;
  486. }
  487. struct proc_xfs_info {
  488. int flag;
  489. char *str;
  490. };
  491. STATIC int
  492. xfs_showargs(
  493. struct xfs_mount *mp,
  494. struct seq_file *m)
  495. {
  496. static struct proc_xfs_info xfs_info_set[] = {
  497. /* the few simple ones we can get from the mount struct */
  498. { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
  499. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  500. { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
  501. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  502. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  503. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  504. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  505. { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
  506. { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
  507. { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
  508. { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
  509. { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
  510. { 0, NULL }
  511. };
  512. static struct proc_xfs_info xfs_info_unset[] = {
  513. /* the few simple ones we can get from the mount struct */
  514. { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
  515. { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
  516. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
  517. { 0, NULL }
  518. };
  519. struct proc_xfs_info *xfs_infop;
  520. for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
  521. if (mp->m_flags & xfs_infop->flag)
  522. seq_puts(m, xfs_infop->str);
  523. }
  524. for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
  525. if (!(mp->m_flags & xfs_infop->flag))
  526. seq_puts(m, xfs_infop->str);
  527. }
  528. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  529. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  530. (int)(1 << mp->m_writeio_log) >> 10);
  531. if (mp->m_logbufs > 0)
  532. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  533. if (mp->m_logbsize > 0)
  534. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  535. if (mp->m_logname)
  536. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  537. if (mp->m_rtname)
  538. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  539. if (mp->m_dalign > 0)
  540. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  541. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  542. if (mp->m_swidth > 0)
  543. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  544. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  545. if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
  546. seq_puts(m, "," MNTOPT_USRQUOTA);
  547. else if (mp->m_qflags & XFS_UQUOTA_ACCT)
  548. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  549. if (mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
  550. seq_puts(m, "," MNTOPT_PRJQUOTA);
  551. else if (mp->m_qflags & XFS_PQUOTA_ACCT)
  552. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  553. if (mp->m_qflags & (XFS_GQUOTA_ACCT|XFS_OQUOTA_ENFD))
  554. seq_puts(m, "," MNTOPT_GRPQUOTA);
  555. else if (mp->m_qflags & XFS_GQUOTA_ACCT)
  556. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  557. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  558. seq_puts(m, "," MNTOPT_NOQUOTA);
  559. return 0;
  560. }
  561. __uint64_t
  562. xfs_max_file_offset(
  563. unsigned int blockshift)
  564. {
  565. unsigned int pagefactor = 1;
  566. unsigned int bitshift = BITS_PER_LONG - 1;
  567. /* Figure out maximum filesize, on Linux this can depend on
  568. * the filesystem blocksize (on 32 bit platforms).
  569. * __block_prepare_write does this in an [unsigned] long...
  570. * page->index << (PAGE_CACHE_SHIFT - bbits)
  571. * So, for page sized blocks (4K on 32 bit platforms),
  572. * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
  573. * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  574. * but for smaller blocksizes it is less (bbits = log2 bsize).
  575. * Note1: get_block_t takes a long (implicit cast from above)
  576. * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
  577. * can optionally convert the [unsigned] long from above into
  578. * an [unsigned] long long.
  579. */
  580. #if BITS_PER_LONG == 32
  581. # if defined(CONFIG_LBD)
  582. ASSERT(sizeof(sector_t) == 8);
  583. pagefactor = PAGE_CACHE_SIZE;
  584. bitshift = BITS_PER_LONG;
  585. # else
  586. pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
  587. # endif
  588. #endif
  589. return (((__uint64_t)pagefactor) << bitshift) - 1;
  590. }
  591. int
  592. xfs_blkdev_get(
  593. xfs_mount_t *mp,
  594. const char *name,
  595. struct block_device **bdevp)
  596. {
  597. int error = 0;
  598. *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
  599. if (IS_ERR(*bdevp)) {
  600. error = PTR_ERR(*bdevp);
  601. printk("XFS: Invalid device [%s], error=%d\n", name, error);
  602. }
  603. return -error;
  604. }
  605. void
  606. xfs_blkdev_put(
  607. struct block_device *bdev)
  608. {
  609. if (bdev)
  610. close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
  611. }
  612. /*
  613. * Try to write out the superblock using barriers.
  614. */
  615. STATIC int
  616. xfs_barrier_test(
  617. xfs_mount_t *mp)
  618. {
  619. xfs_buf_t *sbp = xfs_getsb(mp, 0);
  620. int error;
  621. XFS_BUF_UNDONE(sbp);
  622. XFS_BUF_UNREAD(sbp);
  623. XFS_BUF_UNDELAYWRITE(sbp);
  624. XFS_BUF_WRITE(sbp);
  625. XFS_BUF_UNASYNC(sbp);
  626. XFS_BUF_ORDERED(sbp);
  627. xfsbdstrat(mp, sbp);
  628. error = xfs_iowait(sbp);
  629. /*
  630. * Clear all the flags we set and possible error state in the
  631. * buffer. We only did the write to try out whether barriers
  632. * worked and shouldn't leave any traces in the superblock
  633. * buffer.
  634. */
  635. XFS_BUF_DONE(sbp);
  636. XFS_BUF_ERROR(sbp, 0);
  637. XFS_BUF_UNORDERED(sbp);
  638. xfs_buf_relse(sbp);
  639. return error;
  640. }
  641. void
  642. xfs_mountfs_check_barriers(xfs_mount_t *mp)
  643. {
  644. int error;
  645. if (mp->m_logdev_targp != mp->m_ddev_targp) {
  646. xfs_fs_cmn_err(CE_NOTE, mp,
  647. "Disabling barriers, not supported with external log device");
  648. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  649. return;
  650. }
  651. if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
  652. xfs_fs_cmn_err(CE_NOTE, mp,
  653. "Disabling barriers, underlying device is readonly");
  654. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  655. return;
  656. }
  657. error = xfs_barrier_test(mp);
  658. if (error) {
  659. xfs_fs_cmn_err(CE_NOTE, mp,
  660. "Disabling barriers, trial barrier write failed");
  661. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  662. return;
  663. }
  664. }
  665. void
  666. xfs_blkdev_issue_flush(
  667. xfs_buftarg_t *buftarg)
  668. {
  669. blkdev_issue_flush(buftarg->bt_bdev, NULL);
  670. }
  671. STATIC void
  672. xfs_close_devices(
  673. struct xfs_mount *mp)
  674. {
  675. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  676. struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
  677. xfs_free_buftarg(mp->m_logdev_targp);
  678. xfs_blkdev_put(logdev);
  679. }
  680. if (mp->m_rtdev_targp) {
  681. struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
  682. xfs_free_buftarg(mp->m_rtdev_targp);
  683. xfs_blkdev_put(rtdev);
  684. }
  685. xfs_free_buftarg(mp->m_ddev_targp);
  686. }
  687. /*
  688. * The file system configurations are:
  689. * (1) device (partition) with data and internal log
  690. * (2) logical volume with data and log subvolumes.
  691. * (3) logical volume with data, log, and realtime subvolumes.
  692. *
  693. * We only have to handle opening the log and realtime volumes here if
  694. * they are present. The data subvolume has already been opened by
  695. * get_sb_bdev() and is stored in sb->s_bdev.
  696. */
  697. STATIC int
  698. xfs_open_devices(
  699. struct xfs_mount *mp)
  700. {
  701. struct block_device *ddev = mp->m_super->s_bdev;
  702. struct block_device *logdev = NULL, *rtdev = NULL;
  703. int error;
  704. /*
  705. * Open real time and log devices - order is important.
  706. */
  707. if (mp->m_logname) {
  708. error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
  709. if (error)
  710. goto out;
  711. }
  712. if (mp->m_rtname) {
  713. error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
  714. if (error)
  715. goto out_close_logdev;
  716. if (rtdev == ddev || rtdev == logdev) {
  717. cmn_err(CE_WARN,
  718. "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
  719. error = EINVAL;
  720. goto out_close_rtdev;
  721. }
  722. }
  723. /*
  724. * Setup xfs_mount buffer target pointers
  725. */
  726. error = ENOMEM;
  727. mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
  728. if (!mp->m_ddev_targp)
  729. goto out_close_rtdev;
  730. if (rtdev) {
  731. mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
  732. if (!mp->m_rtdev_targp)
  733. goto out_free_ddev_targ;
  734. }
  735. if (logdev && logdev != ddev) {
  736. mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
  737. if (!mp->m_logdev_targp)
  738. goto out_free_rtdev_targ;
  739. } else {
  740. mp->m_logdev_targp = mp->m_ddev_targp;
  741. }
  742. return 0;
  743. out_free_rtdev_targ:
  744. if (mp->m_rtdev_targp)
  745. xfs_free_buftarg(mp->m_rtdev_targp);
  746. out_free_ddev_targ:
  747. xfs_free_buftarg(mp->m_ddev_targp);
  748. out_close_rtdev:
  749. if (rtdev)
  750. xfs_blkdev_put(rtdev);
  751. out_close_logdev:
  752. if (logdev && logdev != ddev)
  753. xfs_blkdev_put(logdev);
  754. out:
  755. return error;
  756. }
  757. /*
  758. * Setup xfs_mount buffer target pointers based on superblock
  759. */
  760. STATIC int
  761. xfs_setup_devices(
  762. struct xfs_mount *mp)
  763. {
  764. int error;
  765. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  766. mp->m_sb.sb_sectsize);
  767. if (error)
  768. return error;
  769. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  770. unsigned int log_sector_size = BBSIZE;
  771. if (xfs_sb_version_hassector(&mp->m_sb))
  772. log_sector_size = mp->m_sb.sb_logsectsize;
  773. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  774. mp->m_sb.sb_blocksize,
  775. log_sector_size);
  776. if (error)
  777. return error;
  778. }
  779. if (mp->m_rtdev_targp) {
  780. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  781. mp->m_sb.sb_blocksize,
  782. mp->m_sb.sb_sectsize);
  783. if (error)
  784. return error;
  785. }
  786. return 0;
  787. }
  788. /*
  789. * XFS AIL push thread support
  790. */
  791. void
  792. xfsaild_wakeup(
  793. struct xfs_ail *ailp,
  794. xfs_lsn_t threshold_lsn)
  795. {
  796. ailp->xa_target = threshold_lsn;
  797. wake_up_process(ailp->xa_task);
  798. }
  799. int
  800. xfsaild(
  801. void *data)
  802. {
  803. struct xfs_ail *ailp = data;
  804. xfs_lsn_t last_pushed_lsn = 0;
  805. long tout = 0;
  806. while (!kthread_should_stop()) {
  807. if (tout)
  808. schedule_timeout_interruptible(msecs_to_jiffies(tout));
  809. tout = 1000;
  810. /* swsusp */
  811. try_to_freeze();
  812. ASSERT(ailp->xa_mount->m_log);
  813. if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
  814. continue;
  815. tout = xfsaild_push(ailp, &last_pushed_lsn);
  816. }
  817. return 0;
  818. } /* xfsaild */
  819. int
  820. xfsaild_start(
  821. struct xfs_ail *ailp)
  822. {
  823. ailp->xa_target = 0;
  824. ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild");
  825. if (IS_ERR(ailp->xa_task))
  826. return -PTR_ERR(ailp->xa_task);
  827. return 0;
  828. }
  829. void
  830. xfsaild_stop(
  831. struct xfs_ail *ailp)
  832. {
  833. kthread_stop(ailp->xa_task);
  834. }
  835. /* Catch misguided souls that try to use this interface on XFS */
  836. STATIC struct inode *
  837. xfs_fs_alloc_inode(
  838. struct super_block *sb)
  839. {
  840. BUG();
  841. return NULL;
  842. }
  843. /*
  844. * Now that the generic code is guaranteed not to be accessing
  845. * the linux inode, we can reclaim the inode.
  846. */
  847. STATIC void
  848. xfs_fs_destroy_inode(
  849. struct inode *inode)
  850. {
  851. xfs_inode_t *ip = XFS_I(inode);
  852. XFS_STATS_INC(vn_reclaim);
  853. if (xfs_reclaim(ip))
  854. panic("%s: cannot reclaim 0x%p\n", __func__, inode);
  855. }
  856. /*
  857. * Slab object creation initialisation for the XFS inode.
  858. * This covers only the idempotent fields in the XFS inode;
  859. * all other fields need to be initialised on allocation
  860. * from the slab. This avoids the need to repeatedly intialise
  861. * fields in the xfs inode that left in the initialise state
  862. * when freeing the inode.
  863. */
  864. STATIC void
  865. xfs_fs_inode_init_once(
  866. void *inode)
  867. {
  868. struct xfs_inode *ip = inode;
  869. memset(ip, 0, sizeof(struct xfs_inode));
  870. /* vfs inode */
  871. inode_init_once(VFS_I(ip));
  872. /* xfs inode */
  873. atomic_set(&ip->i_iocount, 0);
  874. atomic_set(&ip->i_pincount, 0);
  875. spin_lock_init(&ip->i_flags_lock);
  876. init_waitqueue_head(&ip->i_ipin_wait);
  877. /*
  878. * Because we want to use a counting completion, complete
  879. * the flush completion once to allow a single access to
  880. * the flush completion without blocking.
  881. */
  882. init_completion(&ip->i_flush);
  883. complete(&ip->i_flush);
  884. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  885. "xfsino", ip->i_ino);
  886. mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
  887. }
  888. /*
  889. * Attempt to flush the inode, this will actually fail
  890. * if the inode is pinned, but we dirty the inode again
  891. * at the point when it is unpinned after a log write,
  892. * since this is when the inode itself becomes flushable.
  893. */
  894. STATIC int
  895. xfs_fs_write_inode(
  896. struct inode *inode,
  897. int sync)
  898. {
  899. struct xfs_inode *ip = XFS_I(inode);
  900. int error = 0;
  901. int flags = 0;
  902. xfs_itrace_entry(ip);
  903. if (sync) {
  904. error = xfs_wait_on_pages(ip, 0, -1);
  905. if (error)
  906. goto out_error;
  907. flags |= FLUSH_SYNC;
  908. }
  909. error = xfs_inode_flush(ip, flags);
  910. out_error:
  911. /*
  912. * if we failed to write out the inode then mark
  913. * it dirty again so we'll try again later.
  914. */
  915. if (error)
  916. xfs_mark_inode_dirty_sync(ip);
  917. return -error;
  918. }
  919. STATIC void
  920. xfs_fs_clear_inode(
  921. struct inode *inode)
  922. {
  923. xfs_inode_t *ip = XFS_I(inode);
  924. xfs_itrace_entry(ip);
  925. XFS_STATS_INC(vn_rele);
  926. XFS_STATS_INC(vn_remove);
  927. XFS_STATS_DEC(vn_active);
  928. xfs_inactive(ip);
  929. }
  930. STATIC void
  931. xfs_free_fsname(
  932. struct xfs_mount *mp)
  933. {
  934. kfree(mp->m_fsname);
  935. kfree(mp->m_rtname);
  936. kfree(mp->m_logname);
  937. }
  938. STATIC void
  939. xfs_fs_put_super(
  940. struct super_block *sb)
  941. {
  942. struct xfs_mount *mp = XFS_M(sb);
  943. struct xfs_inode *rip = mp->m_rootip;
  944. int unmount_event_flags = 0;
  945. int error;
  946. xfs_syncd_stop(mp);
  947. xfs_sync_inodes(mp, SYNC_ATTR|SYNC_DELWRI);
  948. #ifdef HAVE_DMAPI
  949. if (mp->m_flags & XFS_MOUNT_DMAPI) {
  950. unmount_event_flags =
  951. (mp->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ?
  952. 0 : DM_FLAGS_UNWANTED;
  953. /*
  954. * Ignore error from dmapi here, first unmount is not allowed
  955. * to fail anyway, and second we wouldn't want to fail a
  956. * unmount because of dmapi.
  957. */
  958. XFS_SEND_PREUNMOUNT(mp, rip, DM_RIGHT_NULL, rip, DM_RIGHT_NULL,
  959. NULL, NULL, 0, 0, unmount_event_flags);
  960. }
  961. #endif
  962. /*
  963. * Blow away any referenced inode in the filestreams cache.
  964. * This can and will cause log traffic as inodes go inactive
  965. * here.
  966. */
  967. xfs_filestream_unmount(mp);
  968. XFS_bflush(mp->m_ddev_targp);
  969. error = xfs_unmount_flush(mp, 0);
  970. WARN_ON(error);
  971. if (mp->m_flags & XFS_MOUNT_DMAPI) {
  972. XFS_SEND_UNMOUNT(mp, rip, DM_RIGHT_NULL, 0, 0,
  973. unmount_event_flags);
  974. }
  975. xfs_unmountfs(mp);
  976. xfs_freesb(mp);
  977. xfs_icsb_destroy_counters(mp);
  978. xfs_close_devices(mp);
  979. xfs_qmops_put(mp);
  980. xfs_dmops_put(mp);
  981. xfs_free_fsname(mp);
  982. kfree(mp);
  983. }
  984. STATIC void
  985. xfs_fs_write_super(
  986. struct super_block *sb)
  987. {
  988. if (!(sb->s_flags & MS_RDONLY))
  989. xfs_sync_fsdata(XFS_M(sb), 0);
  990. sb->s_dirt = 0;
  991. }
  992. STATIC int
  993. xfs_fs_sync_super(
  994. struct super_block *sb,
  995. int wait)
  996. {
  997. struct xfs_mount *mp = XFS_M(sb);
  998. int error;
  999. /*
  1000. * Treat a sync operation like a freeze. This is to work
  1001. * around a race in sync_inodes() which works in two phases
  1002. * - an asynchronous flush, which can write out an inode
  1003. * without waiting for file size updates to complete, and a
  1004. * synchronous flush, which wont do anything because the
  1005. * async flush removed the inode's dirty flag. Also
  1006. * sync_inodes() will not see any files that just have
  1007. * outstanding transactions to be flushed because we don't
  1008. * dirty the Linux inode until after the transaction I/O
  1009. * completes.
  1010. */
  1011. if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE))
  1012. error = xfs_quiesce_data(mp);
  1013. else
  1014. error = xfs_sync_fsdata(mp, 0);
  1015. sb->s_dirt = 0;
  1016. if (unlikely(laptop_mode)) {
  1017. int prev_sync_seq = mp->m_sync_seq;
  1018. /*
  1019. * The disk must be active because we're syncing.
  1020. * We schedule xfssyncd now (now that the disk is
  1021. * active) instead of later (when it might not be).
  1022. */
  1023. wake_up_process(mp->m_sync_task);
  1024. /*
  1025. * We have to wait for the sync iteration to complete.
  1026. * If we don't, the disk activity caused by the sync
  1027. * will come after the sync is completed, and that
  1028. * triggers another sync from laptop mode.
  1029. */
  1030. wait_event(mp->m_wait_single_sync_task,
  1031. mp->m_sync_seq != prev_sync_seq);
  1032. }
  1033. return -error;
  1034. }
  1035. STATIC int
  1036. xfs_fs_statfs(
  1037. struct dentry *dentry,
  1038. struct kstatfs *statp)
  1039. {
  1040. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  1041. xfs_sb_t *sbp = &mp->m_sb;
  1042. __uint64_t fakeinos, id;
  1043. xfs_extlen_t lsize;
  1044. statp->f_type = XFS_SB_MAGIC;
  1045. statp->f_namelen = MAXNAMELEN - 1;
  1046. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  1047. statp->f_fsid.val[0] = (u32)id;
  1048. statp->f_fsid.val[1] = (u32)(id >> 32);
  1049. xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
  1050. spin_lock(&mp->m_sb_lock);
  1051. statp->f_bsize = sbp->sb_blocksize;
  1052. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  1053. statp->f_blocks = sbp->sb_dblocks - lsize;
  1054. statp->f_bfree = statp->f_bavail =
  1055. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  1056. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  1057. #if XFS_BIG_INUMS
  1058. fakeinos += mp->m_inoadd;
  1059. #endif
  1060. statp->f_files =
  1061. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  1062. if (mp->m_maxicount)
  1063. #if XFS_BIG_INUMS
  1064. if (!mp->m_inoadd)
  1065. #endif
  1066. statp->f_files = min_t(typeof(statp->f_files),
  1067. statp->f_files,
  1068. mp->m_maxicount);
  1069. statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  1070. spin_unlock(&mp->m_sb_lock);
  1071. XFS_QM_DQSTATVFS(XFS_I(dentry->d_inode), statp);
  1072. return 0;
  1073. }
  1074. STATIC int
  1075. xfs_fs_remount(
  1076. struct super_block *sb,
  1077. int *flags,
  1078. char *options)
  1079. {
  1080. struct xfs_mount *mp = XFS_M(sb);
  1081. substring_t args[MAX_OPT_ARGS];
  1082. char *p;
  1083. while ((p = strsep(&options, ",")) != NULL) {
  1084. int token;
  1085. if (!*p)
  1086. continue;
  1087. token = match_token(p, tokens, args);
  1088. switch (token) {
  1089. case Opt_barrier:
  1090. mp->m_flags |= XFS_MOUNT_BARRIER;
  1091. /*
  1092. * Test if barriers are actually working if we can,
  1093. * else delay this check until the filesystem is
  1094. * marked writeable.
  1095. */
  1096. if (!(mp->m_flags & XFS_MOUNT_RDONLY))
  1097. xfs_mountfs_check_barriers(mp);
  1098. break;
  1099. case Opt_nobarrier:
  1100. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1101. break;
  1102. default:
  1103. /*
  1104. * Logically we would return an error here to prevent
  1105. * users from believing they might have changed
  1106. * mount options using remount which can't be changed.
  1107. *
  1108. * But unfortunately mount(8) adds all options from
  1109. * mtab and fstab to the mount arguments in some cases
  1110. * so we can't blindly reject options, but have to
  1111. * check for each specified option if it actually
  1112. * differs from the currently set option and only
  1113. * reject it if that's the case.
  1114. *
  1115. * Until that is implemented we return success for
  1116. * every remount request, and silently ignore all
  1117. * options that we can't actually change.
  1118. */
  1119. #if 0
  1120. printk(KERN_INFO
  1121. "XFS: mount option \"%s\" not supported for remount\n", p);
  1122. return -EINVAL;
  1123. #else
  1124. break;
  1125. #endif
  1126. }
  1127. }
  1128. /* rw/ro -> rw */
  1129. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1130. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1131. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1132. xfs_mountfs_check_barriers(mp);
  1133. }
  1134. /* rw -> ro */
  1135. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1136. xfs_quiesce_data(mp);
  1137. xfs_quiesce_attr(mp);
  1138. mp->m_flags |= XFS_MOUNT_RDONLY;
  1139. }
  1140. return 0;
  1141. }
  1142. /*
  1143. * Second stage of a freeze. The data is already frozen so we only
  1144. * need to take care of the metadata. Once that's done write a dummy
  1145. * record to dirty the log in case of a crash while frozen.
  1146. */
  1147. STATIC void
  1148. xfs_fs_lockfs(
  1149. struct super_block *sb)
  1150. {
  1151. struct xfs_mount *mp = XFS_M(sb);
  1152. xfs_quiesce_attr(mp);
  1153. xfs_fs_log_dummy(mp);
  1154. }
  1155. STATIC int
  1156. xfs_fs_show_options(
  1157. struct seq_file *m,
  1158. struct vfsmount *mnt)
  1159. {
  1160. return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
  1161. }
  1162. STATIC int
  1163. xfs_fs_quotasync(
  1164. struct super_block *sb,
  1165. int type)
  1166. {
  1167. return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XQUOTASYNC, 0, NULL);
  1168. }
  1169. STATIC int
  1170. xfs_fs_getxstate(
  1171. struct super_block *sb,
  1172. struct fs_quota_stat *fqs)
  1173. {
  1174. return -XFS_QM_QUOTACTL(XFS_M(sb), Q_XGETQSTAT, 0, (caddr_t)fqs);
  1175. }
  1176. STATIC int
  1177. xfs_fs_setxstate(
  1178. struct super_block *sb,
  1179. unsigned int flags,
  1180. int op)
  1181. {
  1182. return -XFS_QM_QUOTACTL(XFS_M(sb), op, 0, (caddr_t)&flags);
  1183. }
  1184. STATIC int
  1185. xfs_fs_getxquota(
  1186. struct super_block *sb,
  1187. int type,
  1188. qid_t id,
  1189. struct fs_disk_quota *fdq)
  1190. {
  1191. return -XFS_QM_QUOTACTL(XFS_M(sb),
  1192. (type == USRQUOTA) ? Q_XGETQUOTA :
  1193. ((type == GRPQUOTA) ? Q_XGETGQUOTA :
  1194. Q_XGETPQUOTA), id, (caddr_t)fdq);
  1195. }
  1196. STATIC int
  1197. xfs_fs_setxquota(
  1198. struct super_block *sb,
  1199. int type,
  1200. qid_t id,
  1201. struct fs_disk_quota *fdq)
  1202. {
  1203. return -XFS_QM_QUOTACTL(XFS_M(sb),
  1204. (type == USRQUOTA) ? Q_XSETQLIM :
  1205. ((type == GRPQUOTA) ? Q_XSETGQLIM :
  1206. Q_XSETPQLIM), id, (caddr_t)fdq);
  1207. }
  1208. /*
  1209. * This function fills in xfs_mount_t fields based on mount args.
  1210. * Note: the superblock _has_ now been read in.
  1211. */
  1212. STATIC int
  1213. xfs_finish_flags(
  1214. struct xfs_mount *mp)
  1215. {
  1216. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1217. /* Fail a mount where the logbuf is smaller then the log stripe */
  1218. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1219. if (mp->m_logbsize <= 0 &&
  1220. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  1221. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1222. } else if (mp->m_logbsize > 0 &&
  1223. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  1224. cmn_err(CE_WARN,
  1225. "XFS: logbuf size must be greater than or equal to log stripe size");
  1226. return XFS_ERROR(EINVAL);
  1227. }
  1228. } else {
  1229. /* Fail a mount if the logbuf is larger than 32K */
  1230. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  1231. cmn_err(CE_WARN,
  1232. "XFS: logbuf size for version 1 logs must be 16K or 32K");
  1233. return XFS_ERROR(EINVAL);
  1234. }
  1235. }
  1236. /*
  1237. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1238. * told by noattr2 to turn it off
  1239. */
  1240. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1241. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  1242. mp->m_flags |= XFS_MOUNT_ATTR2;
  1243. /*
  1244. * prohibit r/w mounts of read-only filesystems
  1245. */
  1246. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1247. cmn_err(CE_WARN,
  1248. "XFS: cannot mount a read-only filesystem as read-write");
  1249. return XFS_ERROR(EROFS);
  1250. }
  1251. return 0;
  1252. }
  1253. STATIC int
  1254. xfs_fs_fill_super(
  1255. struct super_block *sb,
  1256. void *data,
  1257. int silent)
  1258. {
  1259. struct inode *root;
  1260. struct xfs_mount *mp = NULL;
  1261. int flags = 0, error = ENOMEM;
  1262. char *mtpt = NULL;
  1263. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1264. if (!mp)
  1265. goto out;
  1266. spin_lock_init(&mp->m_sb_lock);
  1267. mutex_init(&mp->m_growlock);
  1268. atomic_set(&mp->m_active_trans, 0);
  1269. INIT_LIST_HEAD(&mp->m_sync_list);
  1270. spin_lock_init(&mp->m_sync_lock);
  1271. init_waitqueue_head(&mp->m_wait_single_sync_task);
  1272. mp->m_super = sb;
  1273. sb->s_fs_info = mp;
  1274. error = xfs_parseargs(mp, (char *)data, &mtpt);
  1275. if (error)
  1276. goto out_free_fsname;
  1277. sb_min_blocksize(sb, BBSIZE);
  1278. sb->s_xattr = xfs_xattr_handlers;
  1279. sb->s_export_op = &xfs_export_operations;
  1280. sb->s_qcop = &xfs_quotactl_operations;
  1281. sb->s_op = &xfs_super_operations;
  1282. error = xfs_dmops_get(mp);
  1283. if (error)
  1284. goto out_free_fsname;
  1285. error = xfs_qmops_get(mp);
  1286. if (error)
  1287. goto out_put_dmops;
  1288. if (silent)
  1289. flags |= XFS_MFSI_QUIET;
  1290. error = xfs_open_devices(mp);
  1291. if (error)
  1292. goto out_put_qmops;
  1293. if (xfs_icsb_init_counters(mp))
  1294. mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
  1295. error = xfs_readsb(mp, flags);
  1296. if (error)
  1297. goto out_destroy_counters;
  1298. error = xfs_finish_flags(mp);
  1299. if (error)
  1300. goto out_free_sb;
  1301. error = xfs_setup_devices(mp);
  1302. if (error)
  1303. goto out_free_sb;
  1304. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1305. xfs_mountfs_check_barriers(mp);
  1306. error = xfs_filestream_mount(mp);
  1307. if (error)
  1308. goto out_free_sb;
  1309. error = xfs_mountfs(mp);
  1310. if (error)
  1311. goto out_filestream_unmount;
  1312. XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
  1313. sb->s_dirt = 1;
  1314. sb->s_magic = XFS_SB_MAGIC;
  1315. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1316. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1317. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1318. sb->s_time_gran = 1;
  1319. set_posix_acl_flag(sb);
  1320. root = igrab(VFS_I(mp->m_rootip));
  1321. if (!root) {
  1322. error = ENOENT;
  1323. goto fail_unmount;
  1324. }
  1325. if (is_bad_inode(root)) {
  1326. error = EINVAL;
  1327. goto fail_vnrele;
  1328. }
  1329. sb->s_root = d_alloc_root(root);
  1330. if (!sb->s_root) {
  1331. error = ENOMEM;
  1332. goto fail_vnrele;
  1333. }
  1334. error = xfs_syncd_init(mp);
  1335. if (error)
  1336. goto fail_vnrele;
  1337. kfree(mtpt);
  1338. xfs_itrace_exit(XFS_I(sb->s_root->d_inode));
  1339. return 0;
  1340. out_filestream_unmount:
  1341. xfs_filestream_unmount(mp);
  1342. out_free_sb:
  1343. xfs_freesb(mp);
  1344. out_destroy_counters:
  1345. xfs_icsb_destroy_counters(mp);
  1346. xfs_close_devices(mp);
  1347. out_put_qmops:
  1348. xfs_qmops_put(mp);
  1349. out_put_dmops:
  1350. xfs_dmops_put(mp);
  1351. out_free_fsname:
  1352. xfs_free_fsname(mp);
  1353. kfree(mtpt);
  1354. kfree(mp);
  1355. out:
  1356. return -error;
  1357. fail_vnrele:
  1358. if (sb->s_root) {
  1359. dput(sb->s_root);
  1360. sb->s_root = NULL;
  1361. } else {
  1362. iput(root);
  1363. }
  1364. fail_unmount:
  1365. /*
  1366. * Blow away any referenced inode in the filestreams cache.
  1367. * This can and will cause log traffic as inodes go inactive
  1368. * here.
  1369. */
  1370. xfs_filestream_unmount(mp);
  1371. XFS_bflush(mp->m_ddev_targp);
  1372. error = xfs_unmount_flush(mp, 0);
  1373. WARN_ON(error);
  1374. xfs_unmountfs(mp);
  1375. goto out_free_sb;
  1376. }
  1377. STATIC int
  1378. xfs_fs_get_sb(
  1379. struct file_system_type *fs_type,
  1380. int flags,
  1381. const char *dev_name,
  1382. void *data,
  1383. struct vfsmount *mnt)
  1384. {
  1385. return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
  1386. mnt);
  1387. }
  1388. static struct super_operations xfs_super_operations = {
  1389. .alloc_inode = xfs_fs_alloc_inode,
  1390. .destroy_inode = xfs_fs_destroy_inode,
  1391. .write_inode = xfs_fs_write_inode,
  1392. .clear_inode = xfs_fs_clear_inode,
  1393. .put_super = xfs_fs_put_super,
  1394. .write_super = xfs_fs_write_super,
  1395. .sync_fs = xfs_fs_sync_super,
  1396. .write_super_lockfs = xfs_fs_lockfs,
  1397. .statfs = xfs_fs_statfs,
  1398. .remount_fs = xfs_fs_remount,
  1399. .show_options = xfs_fs_show_options,
  1400. };
  1401. static struct quotactl_ops xfs_quotactl_operations = {
  1402. .quota_sync = xfs_fs_quotasync,
  1403. .get_xstate = xfs_fs_getxstate,
  1404. .set_xstate = xfs_fs_setxstate,
  1405. .get_xquota = xfs_fs_getxquota,
  1406. .set_xquota = xfs_fs_setxquota,
  1407. };
  1408. static struct file_system_type xfs_fs_type = {
  1409. .owner = THIS_MODULE,
  1410. .name = "xfs",
  1411. .get_sb = xfs_fs_get_sb,
  1412. .kill_sb = kill_block_super,
  1413. .fs_flags = FS_REQUIRES_DEV,
  1414. };
  1415. STATIC int __init
  1416. xfs_alloc_trace_bufs(void)
  1417. {
  1418. #ifdef XFS_ALLOC_TRACE
  1419. xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_MAYFAIL);
  1420. if (!xfs_alloc_trace_buf)
  1421. goto out;
  1422. #endif
  1423. #ifdef XFS_BMAP_TRACE
  1424. xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_MAYFAIL);
  1425. if (!xfs_bmap_trace_buf)
  1426. goto out_free_alloc_trace;
  1427. #endif
  1428. #ifdef XFS_BTREE_TRACE
  1429. xfs_allocbt_trace_buf = ktrace_alloc(XFS_ALLOCBT_TRACE_SIZE,
  1430. KM_MAYFAIL);
  1431. if (!xfs_allocbt_trace_buf)
  1432. goto out_free_bmap_trace;
  1433. xfs_inobt_trace_buf = ktrace_alloc(XFS_INOBT_TRACE_SIZE, KM_MAYFAIL);
  1434. if (!xfs_inobt_trace_buf)
  1435. goto out_free_allocbt_trace;
  1436. xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_MAYFAIL);
  1437. if (!xfs_bmbt_trace_buf)
  1438. goto out_free_inobt_trace;
  1439. #endif
  1440. #ifdef XFS_ATTR_TRACE
  1441. xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_MAYFAIL);
  1442. if (!xfs_attr_trace_buf)
  1443. goto out_free_bmbt_trace;
  1444. #endif
  1445. #ifdef XFS_DIR2_TRACE
  1446. xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_MAYFAIL);
  1447. if (!xfs_dir2_trace_buf)
  1448. goto out_free_attr_trace;
  1449. #endif
  1450. return 0;
  1451. #ifdef XFS_DIR2_TRACE
  1452. out_free_attr_trace:
  1453. #endif
  1454. #ifdef XFS_ATTR_TRACE
  1455. ktrace_free(xfs_attr_trace_buf);
  1456. out_free_bmbt_trace:
  1457. #endif
  1458. #ifdef XFS_BTREE_TRACE
  1459. ktrace_free(xfs_bmbt_trace_buf);
  1460. out_free_inobt_trace:
  1461. ktrace_free(xfs_inobt_trace_buf);
  1462. out_free_allocbt_trace:
  1463. ktrace_free(xfs_allocbt_trace_buf);
  1464. out_free_bmap_trace:
  1465. #endif
  1466. #ifdef XFS_BMAP_TRACE
  1467. ktrace_free(xfs_bmap_trace_buf);
  1468. out_free_alloc_trace:
  1469. #endif
  1470. #ifdef XFS_ALLOC_TRACE
  1471. ktrace_free(xfs_alloc_trace_buf);
  1472. out:
  1473. #endif
  1474. return -ENOMEM;
  1475. }
  1476. STATIC void
  1477. xfs_free_trace_bufs(void)
  1478. {
  1479. #ifdef XFS_DIR2_TRACE
  1480. ktrace_free(xfs_dir2_trace_buf);
  1481. #endif
  1482. #ifdef XFS_ATTR_TRACE
  1483. ktrace_free(xfs_attr_trace_buf);
  1484. #endif
  1485. #ifdef XFS_BTREE_TRACE
  1486. ktrace_free(xfs_bmbt_trace_buf);
  1487. ktrace_free(xfs_inobt_trace_buf);
  1488. ktrace_free(xfs_allocbt_trace_buf);
  1489. #endif
  1490. #ifdef XFS_BMAP_TRACE
  1491. ktrace_free(xfs_bmap_trace_buf);
  1492. #endif
  1493. #ifdef XFS_ALLOC_TRACE
  1494. ktrace_free(xfs_alloc_trace_buf);
  1495. #endif
  1496. }
  1497. STATIC int __init
  1498. xfs_init_zones(void)
  1499. {
  1500. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  1501. if (!xfs_ioend_zone)
  1502. goto out;
  1503. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  1504. xfs_ioend_zone);
  1505. if (!xfs_ioend_pool)
  1506. goto out_destroy_ioend_zone;
  1507. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1508. "xfs_log_ticket");
  1509. if (!xfs_log_ticket_zone)
  1510. goto out_destroy_ioend_pool;
  1511. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  1512. "xfs_bmap_free_item");
  1513. if (!xfs_bmap_free_item_zone)
  1514. goto out_destroy_log_ticket_zone;
  1515. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1516. "xfs_btree_cur");
  1517. if (!xfs_btree_cur_zone)
  1518. goto out_destroy_bmap_free_item_zone;
  1519. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1520. "xfs_da_state");
  1521. if (!xfs_da_state_zone)
  1522. goto out_destroy_btree_cur_zone;
  1523. xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
  1524. if (!xfs_dabuf_zone)
  1525. goto out_destroy_da_state_zone;
  1526. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1527. if (!xfs_ifork_zone)
  1528. goto out_destroy_dabuf_zone;
  1529. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1530. if (!xfs_trans_zone)
  1531. goto out_destroy_ifork_zone;
  1532. /*
  1533. * The size of the zone allocated buf log item is the maximum
  1534. * size possible under XFS. This wastes a little bit of memory,
  1535. * but it is much faster.
  1536. */
  1537. xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
  1538. (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
  1539. NBWORD) * sizeof(int))), "xfs_buf_item");
  1540. if (!xfs_buf_item_zone)
  1541. goto out_destroy_trans_zone;
  1542. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1543. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1544. sizeof(xfs_extent_t))), "xfs_efd_item");
  1545. if (!xfs_efd_zone)
  1546. goto out_destroy_buf_item_zone;
  1547. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1548. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1549. sizeof(xfs_extent_t))), "xfs_efi_item");
  1550. if (!xfs_efi_zone)
  1551. goto out_destroy_efd_zone;
  1552. xfs_inode_zone =
  1553. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1554. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
  1555. xfs_fs_inode_init_once);
  1556. if (!xfs_inode_zone)
  1557. goto out_destroy_efi_zone;
  1558. xfs_ili_zone =
  1559. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1560. KM_ZONE_SPREAD, NULL);
  1561. if (!xfs_ili_zone)
  1562. goto out_destroy_inode_zone;
  1563. #ifdef CONFIG_XFS_POSIX_ACL
  1564. xfs_acl_zone = kmem_zone_init(sizeof(xfs_acl_t), "xfs_acl");
  1565. if (!xfs_acl_zone)
  1566. goto out_destroy_ili_zone;
  1567. #endif
  1568. return 0;
  1569. #ifdef CONFIG_XFS_POSIX_ACL
  1570. out_destroy_ili_zone:
  1571. #endif
  1572. kmem_zone_destroy(xfs_ili_zone);
  1573. out_destroy_inode_zone:
  1574. kmem_zone_destroy(xfs_inode_zone);
  1575. out_destroy_efi_zone:
  1576. kmem_zone_destroy(xfs_efi_zone);
  1577. out_destroy_efd_zone:
  1578. kmem_zone_destroy(xfs_efd_zone);
  1579. out_destroy_buf_item_zone:
  1580. kmem_zone_destroy(xfs_buf_item_zone);
  1581. out_destroy_trans_zone:
  1582. kmem_zone_destroy(xfs_trans_zone);
  1583. out_destroy_ifork_zone:
  1584. kmem_zone_destroy(xfs_ifork_zone);
  1585. out_destroy_dabuf_zone:
  1586. kmem_zone_destroy(xfs_dabuf_zone);
  1587. out_destroy_da_state_zone:
  1588. kmem_zone_destroy(xfs_da_state_zone);
  1589. out_destroy_btree_cur_zone:
  1590. kmem_zone_destroy(xfs_btree_cur_zone);
  1591. out_destroy_bmap_free_item_zone:
  1592. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1593. out_destroy_log_ticket_zone:
  1594. kmem_zone_destroy(xfs_log_ticket_zone);
  1595. out_destroy_ioend_pool:
  1596. mempool_destroy(xfs_ioend_pool);
  1597. out_destroy_ioend_zone:
  1598. kmem_zone_destroy(xfs_ioend_zone);
  1599. out:
  1600. return -ENOMEM;
  1601. }
  1602. STATIC void
  1603. xfs_destroy_zones(void)
  1604. {
  1605. #ifdef CONFIG_XFS_POSIX_ACL
  1606. kmem_zone_destroy(xfs_acl_zone);
  1607. #endif
  1608. kmem_zone_destroy(xfs_ili_zone);
  1609. kmem_zone_destroy(xfs_inode_zone);
  1610. kmem_zone_destroy(xfs_efi_zone);
  1611. kmem_zone_destroy(xfs_efd_zone);
  1612. kmem_zone_destroy(xfs_buf_item_zone);
  1613. kmem_zone_destroy(xfs_trans_zone);
  1614. kmem_zone_destroy(xfs_ifork_zone);
  1615. kmem_zone_destroy(xfs_dabuf_zone);
  1616. kmem_zone_destroy(xfs_da_state_zone);
  1617. kmem_zone_destroy(xfs_btree_cur_zone);
  1618. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1619. kmem_zone_destroy(xfs_log_ticket_zone);
  1620. mempool_destroy(xfs_ioend_pool);
  1621. kmem_zone_destroy(xfs_ioend_zone);
  1622. }
  1623. STATIC int __init
  1624. init_xfs_fs(void)
  1625. {
  1626. int error;
  1627. printk(KERN_INFO XFS_VERSION_STRING " with "
  1628. XFS_BUILD_OPTIONS " enabled\n");
  1629. ktrace_init(64);
  1630. vn_init();
  1631. xfs_dir_startup();
  1632. error = xfs_init_zones();
  1633. if (error)
  1634. goto out;
  1635. error = xfs_alloc_trace_bufs();
  1636. if (error)
  1637. goto out_destroy_zones;
  1638. error = xfs_mru_cache_init();
  1639. if (error)
  1640. goto out_free_trace_buffers;
  1641. error = xfs_filestream_init();
  1642. if (error)
  1643. goto out_mru_cache_uninit;
  1644. error = xfs_buf_init();
  1645. if (error)
  1646. goto out_filestream_uninit;
  1647. error = xfs_init_procfs();
  1648. if (error)
  1649. goto out_buf_terminate;
  1650. error = xfs_sysctl_register();
  1651. if (error)
  1652. goto out_cleanup_procfs;
  1653. vfs_initquota();
  1654. error = register_filesystem(&xfs_fs_type);
  1655. if (error)
  1656. goto out_sysctl_unregister;
  1657. return 0;
  1658. out_sysctl_unregister:
  1659. xfs_sysctl_unregister();
  1660. out_cleanup_procfs:
  1661. xfs_cleanup_procfs();
  1662. out_buf_terminate:
  1663. xfs_buf_terminate();
  1664. out_filestream_uninit:
  1665. xfs_filestream_uninit();
  1666. out_mru_cache_uninit:
  1667. xfs_mru_cache_uninit();
  1668. out_free_trace_buffers:
  1669. xfs_free_trace_bufs();
  1670. out_destroy_zones:
  1671. xfs_destroy_zones();
  1672. out:
  1673. return error;
  1674. }
  1675. STATIC void __exit
  1676. exit_xfs_fs(void)
  1677. {
  1678. vfs_exitquota();
  1679. unregister_filesystem(&xfs_fs_type);
  1680. xfs_sysctl_unregister();
  1681. xfs_cleanup_procfs();
  1682. xfs_buf_terminate();
  1683. xfs_filestream_uninit();
  1684. xfs_mru_cache_uninit();
  1685. xfs_free_trace_bufs();
  1686. xfs_destroy_zones();
  1687. ktrace_uninit();
  1688. }
  1689. module_init(init_xfs_fs);
  1690. module_exit(exit_xfs_fs);
  1691. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1692. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1693. MODULE_LICENSE("GPL");