xfs_super.c 48 KB

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