xfs_super.c 46 KB

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