xfs_super.c 50 KB

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