xfs_super.c 48 KB

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