xfs_super.c 49 KB

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