xfs_super.c 48 KB

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