xfs_super.c 57 KB

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