xfs_super.c 47 KB

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