xfs_super.c 48 KB

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