xfs_super.c 48 KB

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