xfs_super.c 48 KB

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