xfs_super.c 46 KB

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