xfs_super.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910
  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_extfree_item.h"
  56. #include "xfs_mru_cache.h"
  57. #include "xfs_inode_item.h"
  58. #include "xfs_sync.h"
  59. #include "xfs_trace.h"
  60. #include <linux/namei.h>
  61. #include <linux/init.h>
  62. #include <linux/slab.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 const 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. #ifndef CONFIG_XFS_QUOTA
  390. if (XFS_IS_QUOTA_RUNNING(mp)) {
  391. cmn_err(CE_WARN,
  392. "XFS: quota support not available in this kernel.");
  393. return EINVAL;
  394. }
  395. #endif
  396. if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
  397. (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
  398. cmn_err(CE_WARN,
  399. "XFS: cannot mount with both project and group quota");
  400. return EINVAL;
  401. }
  402. if ((mp->m_flags & XFS_MOUNT_DMAPI) && (!*mtpt || *mtpt[0] == '\0')) {
  403. printk("XFS: %s option needs the mount point option as well\n",
  404. MNTOPT_DMAPI);
  405. return EINVAL;
  406. }
  407. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  408. cmn_err(CE_WARN,
  409. "XFS: sunit and swidth must be specified together");
  410. return EINVAL;
  411. }
  412. if (dsunit && (dswidth % dsunit != 0)) {
  413. cmn_err(CE_WARN,
  414. "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
  415. dswidth, dsunit);
  416. return EINVAL;
  417. }
  418. /*
  419. * Applications using DMI filesystems often expect the
  420. * inode generation number to be monotonically increasing.
  421. * If we delete inode chunks we break this assumption, so
  422. * keep unused inode chunks on disk for DMI filesystems
  423. * until we come up with a better solution.
  424. * Note that if "ikeep" or "noikeep" mount options are
  425. * supplied, then they are honored.
  426. */
  427. if ((mp->m_flags & XFS_MOUNT_DMAPI) && dmapi_implies_ikeep)
  428. mp->m_flags |= XFS_MOUNT_IKEEP;
  429. done:
  430. if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
  431. /*
  432. * At this point the superblock has not been read
  433. * in, therefore we do not know the block size.
  434. * Before the mount call ends we will convert
  435. * these to FSBs.
  436. */
  437. if (dsunit) {
  438. mp->m_dalign = dsunit;
  439. mp->m_flags |= XFS_MOUNT_RETERR;
  440. }
  441. if (dswidth)
  442. mp->m_swidth = dswidth;
  443. }
  444. if (mp->m_logbufs != -1 &&
  445. mp->m_logbufs != 0 &&
  446. (mp->m_logbufs < XLOG_MIN_ICLOGS ||
  447. mp->m_logbufs > XLOG_MAX_ICLOGS)) {
  448. cmn_err(CE_WARN,
  449. "XFS: invalid logbufs value: %d [not %d-%d]",
  450. mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  451. return XFS_ERROR(EINVAL);
  452. }
  453. if (mp->m_logbsize != -1 &&
  454. mp->m_logbsize != 0 &&
  455. (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
  456. mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
  457. !is_power_of_2(mp->m_logbsize))) {
  458. cmn_err(CE_WARN,
  459. "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  460. mp->m_logbsize);
  461. return XFS_ERROR(EINVAL);
  462. }
  463. mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
  464. if (!mp->m_fsname)
  465. return ENOMEM;
  466. mp->m_fsname_len = strlen(mp->m_fsname) + 1;
  467. if (iosizelog) {
  468. if (iosizelog > XFS_MAX_IO_LOG ||
  469. iosizelog < XFS_MIN_IO_LOG) {
  470. cmn_err(CE_WARN,
  471. "XFS: invalid log iosize: %d [not %d-%d]",
  472. iosizelog, XFS_MIN_IO_LOG,
  473. XFS_MAX_IO_LOG);
  474. return XFS_ERROR(EINVAL);
  475. }
  476. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  477. mp->m_readio_log = iosizelog;
  478. mp->m_writeio_log = iosizelog;
  479. }
  480. return 0;
  481. }
  482. struct proc_xfs_info {
  483. int flag;
  484. char *str;
  485. };
  486. STATIC int
  487. xfs_showargs(
  488. struct xfs_mount *mp,
  489. struct seq_file *m)
  490. {
  491. static struct proc_xfs_info xfs_info_set[] = {
  492. /* the few simple ones we can get from the mount struct */
  493. { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
  494. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  495. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  496. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  497. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  498. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  499. { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
  500. { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
  501. { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
  502. { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
  503. { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
  504. { 0, NULL }
  505. };
  506. static struct proc_xfs_info xfs_info_unset[] = {
  507. /* the few simple ones we can get from the mount struct */
  508. { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
  509. { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
  510. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
  511. { 0, NULL }
  512. };
  513. struct proc_xfs_info *xfs_infop;
  514. for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
  515. if (mp->m_flags & xfs_infop->flag)
  516. seq_puts(m, xfs_infop->str);
  517. }
  518. for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
  519. if (!(mp->m_flags & xfs_infop->flag))
  520. seq_puts(m, xfs_infop->str);
  521. }
  522. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  523. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  524. (int)(1 << mp->m_writeio_log) >> 10);
  525. if (mp->m_logbufs > 0)
  526. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  527. if (mp->m_logbsize > 0)
  528. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  529. if (mp->m_logname)
  530. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  531. if (mp->m_rtname)
  532. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  533. if (mp->m_dalign > 0)
  534. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  535. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  536. if (mp->m_swidth > 0)
  537. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  538. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  539. if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
  540. seq_puts(m, "," MNTOPT_USRQUOTA);
  541. else if (mp->m_qflags & XFS_UQUOTA_ACCT)
  542. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  543. /* Either project or group quotas can be active, not both */
  544. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  545. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  546. seq_puts(m, "," MNTOPT_PRJQUOTA);
  547. else
  548. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  549. } else if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  550. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  551. seq_puts(m, "," MNTOPT_GRPQUOTA);
  552. else
  553. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  554. }
  555. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  556. seq_puts(m, "," MNTOPT_NOQUOTA);
  557. return 0;
  558. }
  559. __uint64_t
  560. xfs_max_file_offset(
  561. unsigned int blockshift)
  562. {
  563. unsigned int pagefactor = 1;
  564. unsigned int bitshift = BITS_PER_LONG - 1;
  565. /* Figure out maximum filesize, on Linux this can depend on
  566. * the filesystem blocksize (on 32 bit platforms).
  567. * __block_prepare_write does this in an [unsigned] long...
  568. * page->index << (PAGE_CACHE_SHIFT - bbits)
  569. * So, for page sized blocks (4K on 32 bit platforms),
  570. * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
  571. * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  572. * but for smaller blocksizes it is less (bbits = log2 bsize).
  573. * Note1: get_block_t takes a long (implicit cast from above)
  574. * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
  575. * can optionally convert the [unsigned] long from above into
  576. * an [unsigned] long long.
  577. */
  578. #if BITS_PER_LONG == 32
  579. # if defined(CONFIG_LBDAF)
  580. ASSERT(sizeof(sector_t) == 8);
  581. pagefactor = PAGE_CACHE_SIZE;
  582. bitshift = BITS_PER_LONG;
  583. # else
  584. pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
  585. # endif
  586. #endif
  587. return (((__uint64_t)pagefactor) << bitshift) - 1;
  588. }
  589. STATIC int
  590. xfs_blkdev_get(
  591. xfs_mount_t *mp,
  592. const char *name,
  593. struct block_device **bdevp)
  594. {
  595. int error = 0;
  596. *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
  597. if (IS_ERR(*bdevp)) {
  598. error = PTR_ERR(*bdevp);
  599. printk("XFS: Invalid device [%s], error=%d\n", name, error);
  600. }
  601. return -error;
  602. }
  603. STATIC void
  604. xfs_blkdev_put(
  605. struct block_device *bdev)
  606. {
  607. if (bdev)
  608. close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
  609. }
  610. /*
  611. * Try to write out the superblock using barriers.
  612. */
  613. STATIC int
  614. xfs_barrier_test(
  615. xfs_mount_t *mp)
  616. {
  617. xfs_buf_t *sbp = xfs_getsb(mp, 0);
  618. int error;
  619. XFS_BUF_UNDONE(sbp);
  620. XFS_BUF_UNREAD(sbp);
  621. XFS_BUF_UNDELAYWRITE(sbp);
  622. XFS_BUF_WRITE(sbp);
  623. XFS_BUF_UNASYNC(sbp);
  624. XFS_BUF_ORDERED(sbp);
  625. xfsbdstrat(mp, sbp);
  626. error = xfs_iowait(sbp);
  627. /*
  628. * Clear all the flags we set and possible error state in the
  629. * buffer. We only did the write to try out whether barriers
  630. * worked and shouldn't leave any traces in the superblock
  631. * buffer.
  632. */
  633. XFS_BUF_DONE(sbp);
  634. XFS_BUF_ERROR(sbp, 0);
  635. XFS_BUF_UNORDERED(sbp);
  636. xfs_buf_relse(sbp);
  637. return error;
  638. }
  639. STATIC void
  640. xfs_mountfs_check_barriers(xfs_mount_t *mp)
  641. {
  642. int error;
  643. if (mp->m_logdev_targp != mp->m_ddev_targp) {
  644. xfs_fs_cmn_err(CE_NOTE, mp,
  645. "Disabling barriers, not supported with external log device");
  646. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  647. return;
  648. }
  649. if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
  650. xfs_fs_cmn_err(CE_NOTE, mp,
  651. "Disabling barriers, underlying device is readonly");
  652. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  653. return;
  654. }
  655. error = xfs_barrier_test(mp);
  656. if (error) {
  657. xfs_fs_cmn_err(CE_NOTE, mp,
  658. "Disabling barriers, trial barrier write failed");
  659. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  660. return;
  661. }
  662. }
  663. void
  664. xfs_blkdev_issue_flush(
  665. xfs_buftarg_t *buftarg)
  666. {
  667. blkdev_issue_flush(buftarg->bt_bdev, NULL);
  668. }
  669. STATIC void
  670. xfs_close_devices(
  671. struct xfs_mount *mp)
  672. {
  673. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  674. struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
  675. xfs_free_buftarg(mp, mp->m_logdev_targp);
  676. xfs_blkdev_put(logdev);
  677. }
  678. if (mp->m_rtdev_targp) {
  679. struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
  680. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  681. xfs_blkdev_put(rtdev);
  682. }
  683. xfs_free_buftarg(mp, mp->m_ddev_targp);
  684. }
  685. /*
  686. * The file system configurations are:
  687. * (1) device (partition) with data and internal log
  688. * (2) logical volume with data and log subvolumes.
  689. * (3) logical volume with data, log, and realtime subvolumes.
  690. *
  691. * We only have to handle opening the log and realtime volumes here if
  692. * they are present. The data subvolume has already been opened by
  693. * get_sb_bdev() and is stored in sb->s_bdev.
  694. */
  695. STATIC int
  696. xfs_open_devices(
  697. struct xfs_mount *mp)
  698. {
  699. struct block_device *ddev = mp->m_super->s_bdev;
  700. struct block_device *logdev = NULL, *rtdev = NULL;
  701. int error;
  702. /*
  703. * Open real time and log devices - order is important.
  704. */
  705. if (mp->m_logname) {
  706. error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
  707. if (error)
  708. goto out;
  709. }
  710. if (mp->m_rtname) {
  711. error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
  712. if (error)
  713. goto out_close_logdev;
  714. if (rtdev == ddev || rtdev == logdev) {
  715. cmn_err(CE_WARN,
  716. "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
  717. error = EINVAL;
  718. goto out_close_rtdev;
  719. }
  720. }
  721. /*
  722. * Setup xfs_mount buffer target pointers
  723. */
  724. error = ENOMEM;
  725. mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
  726. if (!mp->m_ddev_targp)
  727. goto out_close_rtdev;
  728. if (rtdev) {
  729. mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
  730. if (!mp->m_rtdev_targp)
  731. goto out_free_ddev_targ;
  732. }
  733. if (logdev && logdev != ddev) {
  734. mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1);
  735. if (!mp->m_logdev_targp)
  736. goto out_free_rtdev_targ;
  737. } else {
  738. mp->m_logdev_targp = mp->m_ddev_targp;
  739. }
  740. return 0;
  741. out_free_rtdev_targ:
  742. if (mp->m_rtdev_targp)
  743. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  744. out_free_ddev_targ:
  745. xfs_free_buftarg(mp, mp->m_ddev_targp);
  746. out_close_rtdev:
  747. if (rtdev)
  748. xfs_blkdev_put(rtdev);
  749. out_close_logdev:
  750. if (logdev && logdev != ddev)
  751. xfs_blkdev_put(logdev);
  752. out:
  753. return error;
  754. }
  755. /*
  756. * Setup xfs_mount buffer target pointers based on superblock
  757. */
  758. STATIC int
  759. xfs_setup_devices(
  760. struct xfs_mount *mp)
  761. {
  762. int error;
  763. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  764. mp->m_sb.sb_sectsize);
  765. if (error)
  766. return error;
  767. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  768. unsigned int log_sector_size = BBSIZE;
  769. if (xfs_sb_version_hassector(&mp->m_sb))
  770. log_sector_size = mp->m_sb.sb_logsectsize;
  771. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  772. mp->m_sb.sb_blocksize,
  773. log_sector_size);
  774. if (error)
  775. return error;
  776. }
  777. if (mp->m_rtdev_targp) {
  778. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  779. mp->m_sb.sb_blocksize,
  780. mp->m_sb.sb_sectsize);
  781. if (error)
  782. return error;
  783. }
  784. return 0;
  785. }
  786. /*
  787. * XFS AIL push thread support
  788. */
  789. void
  790. xfsaild_wakeup(
  791. struct xfs_ail *ailp,
  792. xfs_lsn_t threshold_lsn)
  793. {
  794. ailp->xa_target = threshold_lsn;
  795. wake_up_process(ailp->xa_task);
  796. }
  797. STATIC int
  798. xfsaild(
  799. void *data)
  800. {
  801. struct xfs_ail *ailp = data;
  802. xfs_lsn_t last_pushed_lsn = 0;
  803. long tout = 0; /* milliseconds */
  804. while (!kthread_should_stop()) {
  805. schedule_timeout_interruptible(tout ?
  806. msecs_to_jiffies(tout) : MAX_SCHEDULE_TIMEOUT);
  807. /* swsusp */
  808. try_to_freeze();
  809. ASSERT(ailp->xa_mount->m_log);
  810. if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
  811. continue;
  812. tout = xfsaild_push(ailp, &last_pushed_lsn);
  813. }
  814. return 0;
  815. } /* xfsaild */
  816. int
  817. xfsaild_start(
  818. struct xfs_ail *ailp)
  819. {
  820. ailp->xa_target = 0;
  821. ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild");
  822. if (IS_ERR(ailp->xa_task))
  823. return -PTR_ERR(ailp->xa_task);
  824. return 0;
  825. }
  826. void
  827. xfsaild_stop(
  828. struct xfs_ail *ailp)
  829. {
  830. kthread_stop(ailp->xa_task);
  831. }
  832. /* Catch misguided souls that try to use this interface on XFS */
  833. STATIC struct inode *
  834. xfs_fs_alloc_inode(
  835. struct super_block *sb)
  836. {
  837. BUG();
  838. return NULL;
  839. }
  840. /*
  841. * Now that the generic code is guaranteed not to be accessing
  842. * the linux inode, we can reclaim the inode.
  843. */
  844. STATIC void
  845. xfs_fs_destroy_inode(
  846. struct inode *inode)
  847. {
  848. struct xfs_inode *ip = XFS_I(inode);
  849. xfs_itrace_entry(ip);
  850. XFS_STATS_INC(vn_reclaim);
  851. /* bad inode, get out here ASAP */
  852. if (is_bad_inode(inode))
  853. goto out_reclaim;
  854. xfs_ioend_wait(ip);
  855. ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
  856. /*
  857. * We should never get here with one of the reclaim flags already set.
  858. */
  859. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
  860. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
  861. /*
  862. * We always use background reclaim here because even if the
  863. * inode is clean, it still may be under IO and hence we have
  864. * to take the flush lock. The background reclaim path handles
  865. * this more efficiently than we can here, so simply let background
  866. * reclaim tear down all inodes.
  867. */
  868. out_reclaim:
  869. xfs_inode_set_reclaim_tag(ip);
  870. }
  871. /*
  872. * Slab object creation initialisation for the XFS inode.
  873. * This covers only the idempotent fields in the XFS inode;
  874. * all other fields need to be initialised on allocation
  875. * from the slab. This avoids the need to repeatedly intialise
  876. * fields in the xfs inode that left in the initialise state
  877. * when freeing the inode.
  878. */
  879. STATIC void
  880. xfs_fs_inode_init_once(
  881. void *inode)
  882. {
  883. struct xfs_inode *ip = inode;
  884. memset(ip, 0, sizeof(struct xfs_inode));
  885. /* vfs inode */
  886. inode_init_once(VFS_I(ip));
  887. /* xfs inode */
  888. atomic_set(&ip->i_iocount, 0);
  889. atomic_set(&ip->i_pincount, 0);
  890. spin_lock_init(&ip->i_flags_lock);
  891. init_waitqueue_head(&ip->i_ipin_wait);
  892. /*
  893. * Because we want to use a counting completion, complete
  894. * the flush completion once to allow a single access to
  895. * the flush completion without blocking.
  896. */
  897. init_completion(&ip->i_flush);
  898. complete(&ip->i_flush);
  899. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  900. "xfsino", ip->i_ino);
  901. }
  902. /*
  903. * Dirty the XFS inode when mark_inode_dirty_sync() is called so that
  904. * we catch unlogged VFS level updates to the inode. Care must be taken
  905. * here - the transaction code calls mark_inode_dirty_sync() to mark the
  906. * VFS inode dirty in a transaction and clears the i_update_core field;
  907. * it must clear the field after calling mark_inode_dirty_sync() to
  908. * correctly indicate that the dirty state has been propagated into the
  909. * inode log item.
  910. *
  911. * We need the barrier() to maintain correct ordering between unlogged
  912. * updates and the transaction commit code that clears the i_update_core
  913. * field. This requires all updates to be completed before marking the
  914. * inode dirty.
  915. */
  916. STATIC void
  917. xfs_fs_dirty_inode(
  918. struct inode *inode)
  919. {
  920. barrier();
  921. XFS_I(inode)->i_update_core = 1;
  922. }
  923. STATIC int
  924. xfs_log_inode(
  925. struct xfs_inode *ip)
  926. {
  927. struct xfs_mount *mp = ip->i_mount;
  928. struct xfs_trans *tp;
  929. int error;
  930. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  931. tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS);
  932. error = xfs_trans_reserve(tp, 0, XFS_FSYNC_TS_LOG_RES(mp), 0, 0, 0);
  933. if (error) {
  934. xfs_trans_cancel(tp, 0);
  935. /* we need to return with the lock hold shared */
  936. xfs_ilock(ip, XFS_ILOCK_SHARED);
  937. return error;
  938. }
  939. xfs_ilock(ip, XFS_ILOCK_EXCL);
  940. /*
  941. * Note - it's possible that we might have pushed ourselves out of the
  942. * way during trans_reserve which would flush the inode. But there's
  943. * no guarantee that the inode buffer has actually gone out yet (it's
  944. * delwri). Plus the buffer could be pinned anyway if it's part of
  945. * an inode in another recent transaction. So we play it safe and
  946. * fire off the transaction anyway.
  947. */
  948. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  949. xfs_trans_ihold(tp, ip);
  950. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  951. xfs_trans_set_sync(tp);
  952. error = xfs_trans_commit(tp, 0);
  953. xfs_ilock_demote(ip, XFS_ILOCK_EXCL);
  954. return error;
  955. }
  956. STATIC int
  957. xfs_fs_write_inode(
  958. struct inode *inode,
  959. struct writeback_control *wbc)
  960. {
  961. struct xfs_inode *ip = XFS_I(inode);
  962. struct xfs_mount *mp = ip->i_mount;
  963. int error = EAGAIN;
  964. xfs_itrace_entry(ip);
  965. if (XFS_FORCED_SHUTDOWN(mp))
  966. return XFS_ERROR(EIO);
  967. if (wbc->sync_mode == WB_SYNC_ALL) {
  968. /*
  969. * Make sure the inode has hit stable storage. By using the
  970. * log and the fsync transactions we reduce the IOs we have
  971. * to do here from two (log and inode) to just the log.
  972. *
  973. * Note: We still need to do a delwri write of the inode after
  974. * this to flush it to the backing buffer so that bulkstat
  975. * works properly if this is the first time the inode has been
  976. * written. Because we hold the ilock atomically over the
  977. * transaction commit and the inode flush we are guaranteed
  978. * that the inode is not pinned when it returns. If the flush
  979. * lock is already held, then the inode has already been
  980. * flushed once and we don't need to flush it again. Hence
  981. * the code will only flush the inode if it isn't already
  982. * being flushed.
  983. */
  984. xfs_ilock(ip, XFS_ILOCK_SHARED);
  985. if (ip->i_update_core) {
  986. error = xfs_log_inode(ip);
  987. if (error)
  988. goto out_unlock;
  989. }
  990. } else {
  991. /*
  992. * We make this non-blocking if the inode is contended, return
  993. * EAGAIN to indicate to the caller that they did not succeed.
  994. * This prevents the flush path from blocking on inodes inside
  995. * another operation right now, they get caught later by xfs_sync.
  996. */
  997. if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
  998. goto out;
  999. }
  1000. if (xfs_ipincount(ip) || !xfs_iflock_nowait(ip))
  1001. goto out_unlock;
  1002. /*
  1003. * Now we have the flush lock and the inode is not pinned, we can check
  1004. * if the inode is really clean as we know that there are no pending
  1005. * transaction completions, it is not waiting on the delayed write
  1006. * queue and there is no IO in progress.
  1007. */
  1008. if (xfs_inode_clean(ip)) {
  1009. xfs_ifunlock(ip);
  1010. error = 0;
  1011. goto out_unlock;
  1012. }
  1013. error = xfs_iflush(ip, 0);
  1014. out_unlock:
  1015. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1016. out:
  1017. /*
  1018. * if we failed to write out the inode then mark
  1019. * it dirty again so we'll try again later.
  1020. */
  1021. if (error)
  1022. xfs_mark_inode_dirty_sync(ip);
  1023. return -error;
  1024. }
  1025. STATIC void
  1026. xfs_fs_clear_inode(
  1027. struct inode *inode)
  1028. {
  1029. xfs_inode_t *ip = XFS_I(inode);
  1030. xfs_itrace_entry(ip);
  1031. XFS_STATS_INC(vn_rele);
  1032. XFS_STATS_INC(vn_remove);
  1033. XFS_STATS_DEC(vn_active);
  1034. /*
  1035. * The iolock is used by the file system to coordinate reads,
  1036. * writes, and block truncates. Up to this point the lock
  1037. * protected concurrent accesses by users of the inode. But
  1038. * from here forward we're doing some final processing of the
  1039. * inode because we're done with it, and although we reuse the
  1040. * iolock for protection it is really a distinct lock class
  1041. * (in the lockdep sense) from before. To keep lockdep happy
  1042. * (and basically indicate what we are doing), we explicitly
  1043. * re-init the iolock here.
  1044. */
  1045. ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
  1046. mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
  1047. xfs_inactive(ip);
  1048. }
  1049. STATIC void
  1050. xfs_free_fsname(
  1051. struct xfs_mount *mp)
  1052. {
  1053. kfree(mp->m_fsname);
  1054. kfree(mp->m_rtname);
  1055. kfree(mp->m_logname);
  1056. }
  1057. STATIC void
  1058. xfs_fs_put_super(
  1059. struct super_block *sb)
  1060. {
  1061. struct xfs_mount *mp = XFS_M(sb);
  1062. xfs_syncd_stop(mp);
  1063. if (!(sb->s_flags & MS_RDONLY)) {
  1064. /*
  1065. * XXX(hch): this should be SYNC_WAIT.
  1066. *
  1067. * Or more likely not needed at all because the VFS is already
  1068. * calling ->sync_fs after shutting down all filestem
  1069. * operations and just before calling ->put_super.
  1070. */
  1071. xfs_sync_data(mp, 0);
  1072. xfs_sync_attr(mp, 0);
  1073. }
  1074. XFS_SEND_PREUNMOUNT(mp);
  1075. /*
  1076. * Blow away any referenced inode in the filestreams cache.
  1077. * This can and will cause log traffic as inodes go inactive
  1078. * here.
  1079. */
  1080. xfs_filestream_unmount(mp);
  1081. XFS_bflush(mp->m_ddev_targp);
  1082. XFS_SEND_UNMOUNT(mp);
  1083. xfs_unmountfs(mp);
  1084. xfs_freesb(mp);
  1085. xfs_icsb_destroy_counters(mp);
  1086. xfs_close_devices(mp);
  1087. xfs_dmops_put(mp);
  1088. xfs_free_fsname(mp);
  1089. kfree(mp);
  1090. }
  1091. STATIC int
  1092. xfs_fs_sync_fs(
  1093. struct super_block *sb,
  1094. int wait)
  1095. {
  1096. struct xfs_mount *mp = XFS_M(sb);
  1097. int error;
  1098. /*
  1099. * Not much we can do for the first async pass. Writing out the
  1100. * superblock would be counter-productive as we are going to redirty
  1101. * when writing out other data and metadata (and writing out a single
  1102. * block is quite fast anyway).
  1103. *
  1104. * Try to asynchronously kick off quota syncing at least.
  1105. */
  1106. if (!wait) {
  1107. xfs_qm_sync(mp, SYNC_TRYLOCK);
  1108. return 0;
  1109. }
  1110. error = xfs_quiesce_data(mp);
  1111. if (error)
  1112. return -error;
  1113. if (laptop_mode) {
  1114. int prev_sync_seq = mp->m_sync_seq;
  1115. /*
  1116. * The disk must be active because we're syncing.
  1117. * We schedule xfssyncd now (now that the disk is
  1118. * active) instead of later (when it might not be).
  1119. */
  1120. wake_up_process(mp->m_sync_task);
  1121. /*
  1122. * We have to wait for the sync iteration to complete.
  1123. * If we don't, the disk activity caused by the sync
  1124. * will come after the sync is completed, and that
  1125. * triggers another sync from laptop mode.
  1126. */
  1127. wait_event(mp->m_wait_single_sync_task,
  1128. mp->m_sync_seq != prev_sync_seq);
  1129. }
  1130. return 0;
  1131. }
  1132. STATIC int
  1133. xfs_fs_statfs(
  1134. struct dentry *dentry,
  1135. struct kstatfs *statp)
  1136. {
  1137. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  1138. xfs_sb_t *sbp = &mp->m_sb;
  1139. struct xfs_inode *ip = XFS_I(dentry->d_inode);
  1140. __uint64_t fakeinos, id;
  1141. xfs_extlen_t lsize;
  1142. statp->f_type = XFS_SB_MAGIC;
  1143. statp->f_namelen = MAXNAMELEN - 1;
  1144. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  1145. statp->f_fsid.val[0] = (u32)id;
  1146. statp->f_fsid.val[1] = (u32)(id >> 32);
  1147. xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
  1148. spin_lock(&mp->m_sb_lock);
  1149. statp->f_bsize = sbp->sb_blocksize;
  1150. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  1151. statp->f_blocks = sbp->sb_dblocks - lsize;
  1152. statp->f_bfree = statp->f_bavail =
  1153. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  1154. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  1155. statp->f_files =
  1156. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  1157. if (mp->m_maxicount)
  1158. statp->f_files = min_t(typeof(statp->f_files),
  1159. statp->f_files,
  1160. mp->m_maxicount);
  1161. statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  1162. spin_unlock(&mp->m_sb_lock);
  1163. if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) ||
  1164. ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))) ==
  1165. (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
  1166. xfs_qm_statvfs(ip, statp);
  1167. return 0;
  1168. }
  1169. STATIC void
  1170. xfs_save_resvblks(struct xfs_mount *mp)
  1171. {
  1172. __uint64_t resblks = 0;
  1173. mp->m_resblks_save = mp->m_resblks;
  1174. xfs_reserve_blocks(mp, &resblks, NULL);
  1175. }
  1176. STATIC void
  1177. xfs_restore_resvblks(struct xfs_mount *mp)
  1178. {
  1179. __uint64_t resblks;
  1180. if (mp->m_resblks_save) {
  1181. resblks = mp->m_resblks_save;
  1182. mp->m_resblks_save = 0;
  1183. } else
  1184. resblks = xfs_default_resblks(mp);
  1185. xfs_reserve_blocks(mp, &resblks, NULL);
  1186. }
  1187. STATIC int
  1188. xfs_fs_remount(
  1189. struct super_block *sb,
  1190. int *flags,
  1191. char *options)
  1192. {
  1193. struct xfs_mount *mp = XFS_M(sb);
  1194. substring_t args[MAX_OPT_ARGS];
  1195. char *p;
  1196. int error;
  1197. while ((p = strsep(&options, ",")) != NULL) {
  1198. int token;
  1199. if (!*p)
  1200. continue;
  1201. token = match_token(p, tokens, args);
  1202. switch (token) {
  1203. case Opt_barrier:
  1204. mp->m_flags |= XFS_MOUNT_BARRIER;
  1205. /*
  1206. * Test if barriers are actually working if we can,
  1207. * else delay this check until the filesystem is
  1208. * marked writeable.
  1209. */
  1210. if (!(mp->m_flags & XFS_MOUNT_RDONLY))
  1211. xfs_mountfs_check_barriers(mp);
  1212. break;
  1213. case Opt_nobarrier:
  1214. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1215. break;
  1216. default:
  1217. /*
  1218. * Logically we would return an error here to prevent
  1219. * users from believing they might have changed
  1220. * mount options using remount which can't be changed.
  1221. *
  1222. * But unfortunately mount(8) adds all options from
  1223. * mtab and fstab to the mount arguments in some cases
  1224. * so we can't blindly reject options, but have to
  1225. * check for each specified option if it actually
  1226. * differs from the currently set option and only
  1227. * reject it if that's the case.
  1228. *
  1229. * Until that is implemented we return success for
  1230. * every remount request, and silently ignore all
  1231. * options that we can't actually change.
  1232. */
  1233. #if 0
  1234. printk(KERN_INFO
  1235. "XFS: mount option \"%s\" not supported for remount\n", p);
  1236. return -EINVAL;
  1237. #else
  1238. break;
  1239. #endif
  1240. }
  1241. }
  1242. /* ro -> rw */
  1243. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1244. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1245. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1246. xfs_mountfs_check_barriers(mp);
  1247. /*
  1248. * If this is the first remount to writeable state we
  1249. * might have some superblock changes to update.
  1250. */
  1251. if (mp->m_update_flags) {
  1252. error = xfs_mount_log_sb(mp, mp->m_update_flags);
  1253. if (error) {
  1254. cmn_err(CE_WARN,
  1255. "XFS: failed to write sb changes");
  1256. return error;
  1257. }
  1258. mp->m_update_flags = 0;
  1259. }
  1260. /*
  1261. * Fill out the reserve pool if it is empty. Use the stashed
  1262. * value if it is non-zero, otherwise go with the default.
  1263. */
  1264. xfs_restore_resvblks(mp);
  1265. }
  1266. /* rw -> ro */
  1267. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1268. /*
  1269. * After we have synced the data but before we sync the
  1270. * metadata, we need to free up the reserve block pool so that
  1271. * the used block count in the superblock on disk is correct at
  1272. * the end of the remount. Stash the current reserve pool size
  1273. * so that if we get remounted rw, we can return it to the same
  1274. * size.
  1275. */
  1276. xfs_quiesce_data(mp);
  1277. xfs_save_resvblks(mp);
  1278. xfs_quiesce_attr(mp);
  1279. mp->m_flags |= XFS_MOUNT_RDONLY;
  1280. }
  1281. return 0;
  1282. }
  1283. /*
  1284. * Second stage of a freeze. The data is already frozen so we only
  1285. * need to take care of the metadata. Once that's done write a dummy
  1286. * record to dirty the log in case of a crash while frozen.
  1287. */
  1288. STATIC int
  1289. xfs_fs_freeze(
  1290. struct super_block *sb)
  1291. {
  1292. struct xfs_mount *mp = XFS_M(sb);
  1293. xfs_save_resvblks(mp);
  1294. xfs_quiesce_attr(mp);
  1295. return -xfs_fs_log_dummy(mp);
  1296. }
  1297. STATIC int
  1298. xfs_fs_unfreeze(
  1299. struct super_block *sb)
  1300. {
  1301. struct xfs_mount *mp = XFS_M(sb);
  1302. xfs_restore_resvblks(mp);
  1303. return 0;
  1304. }
  1305. STATIC int
  1306. xfs_fs_show_options(
  1307. struct seq_file *m,
  1308. struct vfsmount *mnt)
  1309. {
  1310. return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
  1311. }
  1312. /*
  1313. * This function fills in xfs_mount_t fields based on mount args.
  1314. * Note: the superblock _has_ now been read in.
  1315. */
  1316. STATIC int
  1317. xfs_finish_flags(
  1318. struct xfs_mount *mp)
  1319. {
  1320. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1321. /* Fail a mount where the logbuf is smaller than the log stripe */
  1322. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1323. if (mp->m_logbsize <= 0 &&
  1324. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  1325. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1326. } else if (mp->m_logbsize > 0 &&
  1327. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  1328. cmn_err(CE_WARN,
  1329. "XFS: logbuf size must be greater than or equal to log stripe size");
  1330. return XFS_ERROR(EINVAL);
  1331. }
  1332. } else {
  1333. /* Fail a mount if the logbuf is larger than 32K */
  1334. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  1335. cmn_err(CE_WARN,
  1336. "XFS: logbuf size for version 1 logs must be 16K or 32K");
  1337. return XFS_ERROR(EINVAL);
  1338. }
  1339. }
  1340. /*
  1341. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1342. * told by noattr2 to turn it off
  1343. */
  1344. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1345. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  1346. mp->m_flags |= XFS_MOUNT_ATTR2;
  1347. /*
  1348. * prohibit r/w mounts of read-only filesystems
  1349. */
  1350. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1351. cmn_err(CE_WARN,
  1352. "XFS: cannot mount a read-only filesystem as read-write");
  1353. return XFS_ERROR(EROFS);
  1354. }
  1355. return 0;
  1356. }
  1357. STATIC int
  1358. xfs_fs_fill_super(
  1359. struct super_block *sb,
  1360. void *data,
  1361. int silent)
  1362. {
  1363. struct inode *root;
  1364. struct xfs_mount *mp = NULL;
  1365. int flags = 0, error = ENOMEM;
  1366. char *mtpt = NULL;
  1367. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1368. if (!mp)
  1369. goto out;
  1370. spin_lock_init(&mp->m_sb_lock);
  1371. mutex_init(&mp->m_growlock);
  1372. atomic_set(&mp->m_active_trans, 0);
  1373. INIT_LIST_HEAD(&mp->m_sync_list);
  1374. spin_lock_init(&mp->m_sync_lock);
  1375. init_waitqueue_head(&mp->m_wait_single_sync_task);
  1376. mp->m_super = sb;
  1377. sb->s_fs_info = mp;
  1378. error = xfs_parseargs(mp, (char *)data, &mtpt);
  1379. if (error)
  1380. goto out_free_fsname;
  1381. sb_min_blocksize(sb, BBSIZE);
  1382. sb->s_xattr = xfs_xattr_handlers;
  1383. sb->s_export_op = &xfs_export_operations;
  1384. #ifdef CONFIG_XFS_QUOTA
  1385. sb->s_qcop = &xfs_quotactl_operations;
  1386. #endif
  1387. sb->s_op = &xfs_super_operations;
  1388. error = xfs_dmops_get(mp);
  1389. if (error)
  1390. goto out_free_fsname;
  1391. if (silent)
  1392. flags |= XFS_MFSI_QUIET;
  1393. error = xfs_open_devices(mp);
  1394. if (error)
  1395. goto out_put_dmops;
  1396. if (xfs_icsb_init_counters(mp))
  1397. mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
  1398. error = xfs_readsb(mp, flags);
  1399. if (error)
  1400. goto out_destroy_counters;
  1401. error = xfs_finish_flags(mp);
  1402. if (error)
  1403. goto out_free_sb;
  1404. error = xfs_setup_devices(mp);
  1405. if (error)
  1406. goto out_free_sb;
  1407. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1408. xfs_mountfs_check_barriers(mp);
  1409. error = xfs_filestream_mount(mp);
  1410. if (error)
  1411. goto out_free_sb;
  1412. error = xfs_mountfs(mp);
  1413. if (error)
  1414. goto out_filestream_unmount;
  1415. XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
  1416. sb->s_magic = XFS_SB_MAGIC;
  1417. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1418. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1419. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1420. sb->s_time_gran = 1;
  1421. set_posix_acl_flag(sb);
  1422. root = igrab(VFS_I(mp->m_rootip));
  1423. if (!root) {
  1424. error = ENOENT;
  1425. goto fail_unmount;
  1426. }
  1427. if (is_bad_inode(root)) {
  1428. error = EINVAL;
  1429. goto fail_vnrele;
  1430. }
  1431. sb->s_root = d_alloc_root(root);
  1432. if (!sb->s_root) {
  1433. error = ENOMEM;
  1434. goto fail_vnrele;
  1435. }
  1436. error = xfs_syncd_init(mp);
  1437. if (error)
  1438. goto fail_vnrele;
  1439. kfree(mtpt);
  1440. return 0;
  1441. out_filestream_unmount:
  1442. xfs_filestream_unmount(mp);
  1443. out_free_sb:
  1444. xfs_freesb(mp);
  1445. out_destroy_counters:
  1446. xfs_icsb_destroy_counters(mp);
  1447. xfs_close_devices(mp);
  1448. out_put_dmops:
  1449. xfs_dmops_put(mp);
  1450. out_free_fsname:
  1451. xfs_free_fsname(mp);
  1452. kfree(mtpt);
  1453. kfree(mp);
  1454. out:
  1455. return -error;
  1456. fail_vnrele:
  1457. if (sb->s_root) {
  1458. dput(sb->s_root);
  1459. sb->s_root = NULL;
  1460. } else {
  1461. iput(root);
  1462. }
  1463. fail_unmount:
  1464. /*
  1465. * Blow away any referenced inode in the filestreams cache.
  1466. * This can and will cause log traffic as inodes go inactive
  1467. * here.
  1468. */
  1469. xfs_filestream_unmount(mp);
  1470. XFS_bflush(mp->m_ddev_targp);
  1471. xfs_unmountfs(mp);
  1472. goto out_free_sb;
  1473. }
  1474. STATIC int
  1475. xfs_fs_get_sb(
  1476. struct file_system_type *fs_type,
  1477. int flags,
  1478. const char *dev_name,
  1479. void *data,
  1480. struct vfsmount *mnt)
  1481. {
  1482. return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
  1483. mnt);
  1484. }
  1485. static const struct super_operations xfs_super_operations = {
  1486. .alloc_inode = xfs_fs_alloc_inode,
  1487. .destroy_inode = xfs_fs_destroy_inode,
  1488. .dirty_inode = xfs_fs_dirty_inode,
  1489. .write_inode = xfs_fs_write_inode,
  1490. .clear_inode = xfs_fs_clear_inode,
  1491. .put_super = xfs_fs_put_super,
  1492. .sync_fs = xfs_fs_sync_fs,
  1493. .freeze_fs = xfs_fs_freeze,
  1494. .unfreeze_fs = xfs_fs_unfreeze,
  1495. .statfs = xfs_fs_statfs,
  1496. .remount_fs = xfs_fs_remount,
  1497. .show_options = xfs_fs_show_options,
  1498. };
  1499. static struct file_system_type xfs_fs_type = {
  1500. .owner = THIS_MODULE,
  1501. .name = "xfs",
  1502. .get_sb = xfs_fs_get_sb,
  1503. .kill_sb = kill_block_super,
  1504. .fs_flags = FS_REQUIRES_DEV,
  1505. };
  1506. STATIC int __init
  1507. xfs_init_zones(void)
  1508. {
  1509. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  1510. if (!xfs_ioend_zone)
  1511. goto out;
  1512. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  1513. xfs_ioend_zone);
  1514. if (!xfs_ioend_pool)
  1515. goto out_destroy_ioend_zone;
  1516. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1517. "xfs_log_ticket");
  1518. if (!xfs_log_ticket_zone)
  1519. goto out_destroy_ioend_pool;
  1520. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  1521. "xfs_bmap_free_item");
  1522. if (!xfs_bmap_free_item_zone)
  1523. goto out_destroy_log_ticket_zone;
  1524. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1525. "xfs_btree_cur");
  1526. if (!xfs_btree_cur_zone)
  1527. goto out_destroy_bmap_free_item_zone;
  1528. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1529. "xfs_da_state");
  1530. if (!xfs_da_state_zone)
  1531. goto out_destroy_btree_cur_zone;
  1532. xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
  1533. if (!xfs_dabuf_zone)
  1534. goto out_destroy_da_state_zone;
  1535. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1536. if (!xfs_ifork_zone)
  1537. goto out_destroy_dabuf_zone;
  1538. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1539. if (!xfs_trans_zone)
  1540. goto out_destroy_ifork_zone;
  1541. /*
  1542. * The size of the zone allocated buf log item is the maximum
  1543. * size possible under XFS. This wastes a little bit of memory,
  1544. * but it is much faster.
  1545. */
  1546. xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
  1547. (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
  1548. NBWORD) * sizeof(int))), "xfs_buf_item");
  1549. if (!xfs_buf_item_zone)
  1550. goto out_destroy_trans_zone;
  1551. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1552. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1553. sizeof(xfs_extent_t))), "xfs_efd_item");
  1554. if (!xfs_efd_zone)
  1555. goto out_destroy_buf_item_zone;
  1556. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1557. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1558. sizeof(xfs_extent_t))), "xfs_efi_item");
  1559. if (!xfs_efi_zone)
  1560. goto out_destroy_efd_zone;
  1561. xfs_inode_zone =
  1562. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1563. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
  1564. xfs_fs_inode_init_once);
  1565. if (!xfs_inode_zone)
  1566. goto out_destroy_efi_zone;
  1567. xfs_ili_zone =
  1568. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1569. KM_ZONE_SPREAD, NULL);
  1570. if (!xfs_ili_zone)
  1571. goto out_destroy_inode_zone;
  1572. return 0;
  1573. out_destroy_inode_zone:
  1574. kmem_zone_destroy(xfs_inode_zone);
  1575. out_destroy_efi_zone:
  1576. kmem_zone_destroy(xfs_efi_zone);
  1577. out_destroy_efd_zone:
  1578. kmem_zone_destroy(xfs_efd_zone);
  1579. out_destroy_buf_item_zone:
  1580. kmem_zone_destroy(xfs_buf_item_zone);
  1581. out_destroy_trans_zone:
  1582. kmem_zone_destroy(xfs_trans_zone);
  1583. out_destroy_ifork_zone:
  1584. kmem_zone_destroy(xfs_ifork_zone);
  1585. out_destroy_dabuf_zone:
  1586. kmem_zone_destroy(xfs_dabuf_zone);
  1587. out_destroy_da_state_zone:
  1588. kmem_zone_destroy(xfs_da_state_zone);
  1589. out_destroy_btree_cur_zone:
  1590. kmem_zone_destroy(xfs_btree_cur_zone);
  1591. out_destroy_bmap_free_item_zone:
  1592. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1593. out_destroy_log_ticket_zone:
  1594. kmem_zone_destroy(xfs_log_ticket_zone);
  1595. out_destroy_ioend_pool:
  1596. mempool_destroy(xfs_ioend_pool);
  1597. out_destroy_ioend_zone:
  1598. kmem_zone_destroy(xfs_ioend_zone);
  1599. out:
  1600. return -ENOMEM;
  1601. }
  1602. STATIC void
  1603. xfs_destroy_zones(void)
  1604. {
  1605. kmem_zone_destroy(xfs_ili_zone);
  1606. kmem_zone_destroy(xfs_inode_zone);
  1607. kmem_zone_destroy(xfs_efi_zone);
  1608. kmem_zone_destroy(xfs_efd_zone);
  1609. kmem_zone_destroy(xfs_buf_item_zone);
  1610. kmem_zone_destroy(xfs_trans_zone);
  1611. kmem_zone_destroy(xfs_ifork_zone);
  1612. kmem_zone_destroy(xfs_dabuf_zone);
  1613. kmem_zone_destroy(xfs_da_state_zone);
  1614. kmem_zone_destroy(xfs_btree_cur_zone);
  1615. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1616. kmem_zone_destroy(xfs_log_ticket_zone);
  1617. mempool_destroy(xfs_ioend_pool);
  1618. kmem_zone_destroy(xfs_ioend_zone);
  1619. }
  1620. STATIC int __init
  1621. init_xfs_fs(void)
  1622. {
  1623. int error;
  1624. printk(KERN_INFO XFS_VERSION_STRING " with "
  1625. XFS_BUILD_OPTIONS " enabled\n");
  1626. xfs_ioend_init();
  1627. xfs_dir_startup();
  1628. error = xfs_init_zones();
  1629. if (error)
  1630. goto out;
  1631. error = xfs_mru_cache_init();
  1632. if (error)
  1633. goto out_destroy_zones;
  1634. error = xfs_filestream_init();
  1635. if (error)
  1636. goto out_mru_cache_uninit;
  1637. error = xfs_buf_init();
  1638. if (error)
  1639. goto out_filestream_uninit;
  1640. error = xfs_init_procfs();
  1641. if (error)
  1642. goto out_buf_terminate;
  1643. error = xfs_sysctl_register();
  1644. if (error)
  1645. goto out_cleanup_procfs;
  1646. vfs_initquota();
  1647. error = register_filesystem(&xfs_fs_type);
  1648. if (error)
  1649. goto out_sysctl_unregister;
  1650. return 0;
  1651. out_sysctl_unregister:
  1652. xfs_sysctl_unregister();
  1653. out_cleanup_procfs:
  1654. xfs_cleanup_procfs();
  1655. out_buf_terminate:
  1656. xfs_buf_terminate();
  1657. out_filestream_uninit:
  1658. xfs_filestream_uninit();
  1659. out_mru_cache_uninit:
  1660. xfs_mru_cache_uninit();
  1661. out_destroy_zones:
  1662. xfs_destroy_zones();
  1663. out:
  1664. return error;
  1665. }
  1666. STATIC void __exit
  1667. exit_xfs_fs(void)
  1668. {
  1669. vfs_exitquota();
  1670. unregister_filesystem(&xfs_fs_type);
  1671. xfs_sysctl_unregister();
  1672. xfs_cleanup_procfs();
  1673. xfs_buf_terminate();
  1674. xfs_filestream_uninit();
  1675. xfs_mru_cache_uninit();
  1676. xfs_destroy_zones();
  1677. }
  1678. module_init(init_xfs_fs);
  1679. module_exit(exit_xfs_fs);
  1680. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1681. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1682. MODULE_LICENSE("GPL");