xfs_super.c 52 KB

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