xfs_super.c 46 KB

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