xfs_super.c 49 KB

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