xfs_super.c 48 KB

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