xfs_super.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820
  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_shared.h"
  20. #include "xfs_format.h"
  21. #include "xfs_log_format.h"
  22. #include "xfs_trans_resv.h"
  23. #include "xfs_inum.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_ag.h"
  26. #include "xfs_mount.h"
  27. #include "xfs_da_format.h"
  28. #include "xfs_inode.h"
  29. #include "xfs_btree.h"
  30. #include "xfs_bmap.h"
  31. #include "xfs_alloc.h"
  32. #include "xfs_error.h"
  33. #include "xfs_fsops.h"
  34. #include "xfs_trans.h"
  35. #include "xfs_buf_item.h"
  36. #include "xfs_log.h"
  37. #include "xfs_log_priv.h"
  38. #include "xfs_da_btree.h"
  39. #include "xfs_dir2.h"
  40. #include "xfs_extfree_item.h"
  41. #include "xfs_mru_cache.h"
  42. #include "xfs_inode_item.h"
  43. #include "xfs_icache.h"
  44. #include "xfs_trace.h"
  45. #include "xfs_icreate_item.h"
  46. #include "xfs_dinode.h"
  47. #include "xfs_filestream.h"
  48. #include "xfs_quota.h"
  49. #include <linux/namei.h>
  50. #include <linux/init.h>
  51. #include <linux/slab.h>
  52. #include <linux/mount.h>
  53. #include <linux/mempool.h>
  54. #include <linux/writeback.h>
  55. #include <linux/kthread.h>
  56. #include <linux/freezer.h>
  57. #include <linux/parser.h>
  58. static const struct super_operations xfs_super_operations;
  59. static kmem_zone_t *xfs_ioend_zone;
  60. mempool_t *xfs_ioend_pool;
  61. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  62. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  63. #define MNTOPT_LOGDEV "logdev" /* log device */
  64. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  65. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  66. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  67. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  68. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  69. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  70. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  71. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  72. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  73. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  74. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  75. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  76. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  77. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  78. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  79. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  80. * unwritten extent conversion */
  81. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  82. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  83. #define MNTOPT_32BITINODE "inode32" /* inode allocation limited to
  84. * XFS_MAXINUMBER_32 */
  85. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  86. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  87. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  88. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  89. * in stat(). */
  90. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  91. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  92. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  93. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  94. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  95. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  96. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  97. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  98. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  99. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  100. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  101. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  102. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  103. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  104. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  105. #define MNTOPT_DELAYLOG "delaylog" /* Delayed logging enabled */
  106. #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
  107. #define MNTOPT_DISCARD "discard" /* Discard unused blocks */
  108. #define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
  109. /*
  110. * Table driven mount option parser.
  111. *
  112. * Currently only used for remount, but it will be used for mount
  113. * in the future, too.
  114. */
  115. enum {
  116. Opt_barrier,
  117. Opt_nobarrier,
  118. Opt_inode64,
  119. Opt_inode32,
  120. Opt_err
  121. };
  122. static const match_table_t tokens = {
  123. {Opt_barrier, "barrier"},
  124. {Opt_nobarrier, "nobarrier"},
  125. {Opt_inode64, "inode64"},
  126. {Opt_inode32, "inode32"},
  127. {Opt_err, NULL}
  128. };
  129. STATIC unsigned long
  130. suffix_kstrtoint(char *s, unsigned int base, int *res)
  131. {
  132. int last, shift_left_factor = 0, _res;
  133. char *value = s;
  134. last = strlen(value) - 1;
  135. if (value[last] == 'K' || value[last] == 'k') {
  136. shift_left_factor = 10;
  137. value[last] = '\0';
  138. }
  139. if (value[last] == 'M' || value[last] == 'm') {
  140. shift_left_factor = 20;
  141. value[last] = '\0';
  142. }
  143. if (value[last] == 'G' || value[last] == 'g') {
  144. shift_left_factor = 30;
  145. value[last] = '\0';
  146. }
  147. if (kstrtoint(s, base, &_res))
  148. return -EINVAL;
  149. *res = _res << shift_left_factor;
  150. return 0;
  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. {
  164. struct super_block *sb = mp->m_super;
  165. char *this_char, *value;
  166. int dsunit = 0;
  167. int dswidth = 0;
  168. int iosize = 0;
  169. __uint8_t iosizelog = 0;
  170. /*
  171. * set up the mount name first so all the errors will refer to the
  172. * correct device.
  173. */
  174. mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
  175. if (!mp->m_fsname)
  176. return ENOMEM;
  177. mp->m_fsname_len = strlen(mp->m_fsname) + 1;
  178. /*
  179. * Copy binary VFS mount flags we are interested in.
  180. */
  181. if (sb->s_flags & MS_RDONLY)
  182. mp->m_flags |= XFS_MOUNT_RDONLY;
  183. if (sb->s_flags & MS_DIRSYNC)
  184. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  185. if (sb->s_flags & MS_SYNCHRONOUS)
  186. mp->m_flags |= XFS_MOUNT_WSYNC;
  187. /*
  188. * Set some default flags that could be cleared by the mount option
  189. * parsing.
  190. */
  191. mp->m_flags |= XFS_MOUNT_BARRIER;
  192. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  193. #if !XFS_BIG_INUMS
  194. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  195. #endif
  196. /*
  197. * These can be overridden by the mount option parsing.
  198. */
  199. mp->m_logbufs = -1;
  200. mp->m_logbsize = -1;
  201. if (!options)
  202. goto done;
  203. while ((this_char = strsep(&options, ",")) != NULL) {
  204. if (!*this_char)
  205. continue;
  206. if ((value = strchr(this_char, '=')) != NULL)
  207. *value++ = 0;
  208. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  209. if (!value || !*value) {
  210. xfs_warn(mp, "%s option requires an argument",
  211. this_char);
  212. return EINVAL;
  213. }
  214. if (kstrtoint(value, 10, &mp->m_logbufs))
  215. return EINVAL;
  216. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  217. if (!value || !*value) {
  218. xfs_warn(mp, "%s option requires an argument",
  219. this_char);
  220. return EINVAL;
  221. }
  222. if (suffix_kstrtoint(value, 10, &mp->m_logbsize))
  223. return EINVAL;
  224. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  225. if (!value || !*value) {
  226. xfs_warn(mp, "%s option requires an argument",
  227. this_char);
  228. return EINVAL;
  229. }
  230. mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  231. if (!mp->m_logname)
  232. return ENOMEM;
  233. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  234. xfs_warn(mp, "%s option not allowed on this system",
  235. this_char);
  236. return EINVAL;
  237. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  238. if (!value || !*value) {
  239. xfs_warn(mp, "%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. xfs_warn(mp, "%s option requires an argument",
  249. this_char);
  250. return EINVAL;
  251. }
  252. if (kstrtoint(value, 10, &iosize))
  253. return EINVAL;
  254. iosizelog = ffs(iosize) - 1;
  255. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  256. if (!value || !*value) {
  257. xfs_warn(mp, "%s option requires an argument",
  258. this_char);
  259. return EINVAL;
  260. }
  261. if (suffix_kstrtoint(value, 10, &iosize))
  262. return EINVAL;
  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_NORECOVERY)) {
  273. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  274. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  275. mp->m_flags |= XFS_MOUNT_NOALIGN;
  276. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  277. mp->m_flags |= XFS_MOUNT_SWALLOC;
  278. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  279. if (!value || !*value) {
  280. xfs_warn(mp, "%s option requires an argument",
  281. this_char);
  282. return EINVAL;
  283. }
  284. if (kstrtoint(value, 10, &dsunit))
  285. return EINVAL;
  286. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  287. if (!value || !*value) {
  288. xfs_warn(mp, "%s option requires an argument",
  289. this_char);
  290. return EINVAL;
  291. }
  292. if (kstrtoint(value, 10, &dswidth))
  293. return EINVAL;
  294. } else if (!strcmp(this_char, MNTOPT_32BITINODE)) {
  295. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  296. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  297. mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
  298. #if !XFS_BIG_INUMS
  299. xfs_warn(mp, "%s option not allowed on this system",
  300. this_char);
  301. return EINVAL;
  302. #endif
  303. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  304. mp->m_flags |= XFS_MOUNT_NOUUID;
  305. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  306. mp->m_flags |= XFS_MOUNT_BARRIER;
  307. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  308. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  309. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  310. mp->m_flags |= XFS_MOUNT_IKEEP;
  311. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  312. mp->m_flags &= ~XFS_MOUNT_IKEEP;
  313. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  314. mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
  315. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  316. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  317. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  318. mp->m_flags |= XFS_MOUNT_ATTR2;
  319. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  320. mp->m_flags &= ~XFS_MOUNT_ATTR2;
  321. mp->m_flags |= XFS_MOUNT_NOATTR2;
  322. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  323. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  324. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  325. mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
  326. mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
  327. mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
  328. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  329. !strcmp(this_char, MNTOPT_UQUOTA) ||
  330. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  331. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
  332. XFS_UQUOTA_ENFD);
  333. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  334. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  335. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  336. mp->m_qflags &= ~XFS_UQUOTA_ENFD;
  337. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  338. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  339. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
  340. XFS_PQUOTA_ENFD);
  341. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  342. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  343. mp->m_qflags &= ~XFS_PQUOTA_ENFD;
  344. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  345. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  346. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
  347. XFS_GQUOTA_ENFD);
  348. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  349. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  350. mp->m_qflags &= ~XFS_GQUOTA_ENFD;
  351. } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
  352. xfs_warn(mp,
  353. "delaylog is the default now, option is deprecated.");
  354. } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
  355. xfs_warn(mp,
  356. "nodelaylog support has been removed, option is deprecated.");
  357. } else if (!strcmp(this_char, MNTOPT_DISCARD)) {
  358. mp->m_flags |= XFS_MOUNT_DISCARD;
  359. } else if (!strcmp(this_char, MNTOPT_NODISCARD)) {
  360. mp->m_flags &= ~XFS_MOUNT_DISCARD;
  361. } else if (!strcmp(this_char, "ihashsize")) {
  362. xfs_warn(mp,
  363. "ihashsize no longer used, option is deprecated.");
  364. } else if (!strcmp(this_char, "osyncisdsync")) {
  365. xfs_warn(mp,
  366. "osyncisdsync has no effect, option is deprecated.");
  367. } else if (!strcmp(this_char, "osyncisosync")) {
  368. xfs_warn(mp,
  369. "osyncisosync has no effect, option is deprecated.");
  370. } else if (!strcmp(this_char, "irixsgid")) {
  371. xfs_warn(mp,
  372. "irixsgid is now a sysctl(2) variable, option is deprecated.");
  373. } else {
  374. xfs_warn(mp, "unknown mount option [%s].", this_char);
  375. return EINVAL;
  376. }
  377. }
  378. /*
  379. * no recovery flag requires a read-only mount
  380. */
  381. if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
  382. !(mp->m_flags & XFS_MOUNT_RDONLY)) {
  383. xfs_warn(mp, "no-recovery mounts must be read-only.");
  384. return EINVAL;
  385. }
  386. if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
  387. xfs_warn(mp,
  388. "sunit and swidth options incompatible with the noalign option");
  389. return EINVAL;
  390. }
  391. #ifndef CONFIG_XFS_QUOTA
  392. if (XFS_IS_QUOTA_RUNNING(mp)) {
  393. xfs_warn(mp, "quota support not available in this kernel.");
  394. return EINVAL;
  395. }
  396. #endif
  397. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  398. xfs_warn(mp, "sunit and swidth must be specified together");
  399. return EINVAL;
  400. }
  401. if (dsunit && (dswidth % dsunit != 0)) {
  402. xfs_warn(mp,
  403. "stripe width (%d) must be a multiple of the stripe unit (%d)",
  404. dswidth, dsunit);
  405. return EINVAL;
  406. }
  407. done:
  408. if (dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
  409. /*
  410. * At this point the superblock has not been read
  411. * in, therefore we do not know the block size.
  412. * Before the mount call ends we will convert
  413. * these to FSBs.
  414. */
  415. mp->m_dalign = dsunit;
  416. mp->m_swidth = dswidth;
  417. }
  418. if (mp->m_logbufs != -1 &&
  419. mp->m_logbufs != 0 &&
  420. (mp->m_logbufs < XLOG_MIN_ICLOGS ||
  421. mp->m_logbufs > XLOG_MAX_ICLOGS)) {
  422. xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
  423. mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  424. return XFS_ERROR(EINVAL);
  425. }
  426. if (mp->m_logbsize != -1 &&
  427. mp->m_logbsize != 0 &&
  428. (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
  429. mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
  430. !is_power_of_2(mp->m_logbsize))) {
  431. xfs_warn(mp,
  432. "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  433. mp->m_logbsize);
  434. return XFS_ERROR(EINVAL);
  435. }
  436. if (iosizelog) {
  437. if (iosizelog > XFS_MAX_IO_LOG ||
  438. iosizelog < XFS_MIN_IO_LOG) {
  439. xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
  440. iosizelog, XFS_MIN_IO_LOG,
  441. XFS_MAX_IO_LOG);
  442. return XFS_ERROR(EINVAL);
  443. }
  444. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  445. mp->m_readio_log = iosizelog;
  446. mp->m_writeio_log = iosizelog;
  447. }
  448. return 0;
  449. }
  450. struct proc_xfs_info {
  451. int flag;
  452. char *str;
  453. };
  454. STATIC int
  455. xfs_showargs(
  456. struct xfs_mount *mp,
  457. struct seq_file *m)
  458. {
  459. static struct proc_xfs_info xfs_info_set[] = {
  460. /* the few simple ones we can get from the mount struct */
  461. { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
  462. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  463. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  464. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  465. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  466. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  467. { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
  468. { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
  469. { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
  470. { XFS_MOUNT_DISCARD, "," MNTOPT_DISCARD },
  471. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_32BITINODE },
  472. { 0, NULL }
  473. };
  474. static struct proc_xfs_info xfs_info_unset[] = {
  475. /* the few simple ones we can get from the mount struct */
  476. { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
  477. { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
  478. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
  479. { 0, NULL }
  480. };
  481. struct proc_xfs_info *xfs_infop;
  482. for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
  483. if (mp->m_flags & xfs_infop->flag)
  484. seq_puts(m, xfs_infop->str);
  485. }
  486. for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
  487. if (!(mp->m_flags & xfs_infop->flag))
  488. seq_puts(m, xfs_infop->str);
  489. }
  490. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  491. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  492. (int)(1 << mp->m_writeio_log) >> 10);
  493. if (mp->m_logbufs > 0)
  494. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  495. if (mp->m_logbsize > 0)
  496. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  497. if (mp->m_logname)
  498. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  499. if (mp->m_rtname)
  500. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  501. if (mp->m_dalign > 0)
  502. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  503. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  504. if (mp->m_swidth > 0)
  505. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  506. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  507. if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
  508. seq_puts(m, "," MNTOPT_USRQUOTA);
  509. else if (mp->m_qflags & XFS_UQUOTA_ACCT)
  510. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  511. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  512. if (mp->m_qflags & XFS_PQUOTA_ENFD)
  513. seq_puts(m, "," MNTOPT_PRJQUOTA);
  514. else
  515. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  516. }
  517. if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  518. if (mp->m_qflags & XFS_GQUOTA_ENFD)
  519. seq_puts(m, "," MNTOPT_GRPQUOTA);
  520. else
  521. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  522. }
  523. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  524. seq_puts(m, "," MNTOPT_NOQUOTA);
  525. return 0;
  526. }
  527. __uint64_t
  528. xfs_max_file_offset(
  529. unsigned int blockshift)
  530. {
  531. unsigned int pagefactor = 1;
  532. unsigned int bitshift = BITS_PER_LONG - 1;
  533. /* Figure out maximum filesize, on Linux this can depend on
  534. * the filesystem blocksize (on 32 bit platforms).
  535. * __block_write_begin does this in an [unsigned] long...
  536. * page->index << (PAGE_CACHE_SHIFT - bbits)
  537. * So, for page sized blocks (4K on 32 bit platforms),
  538. * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
  539. * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  540. * but for smaller blocksizes it is less (bbits = log2 bsize).
  541. * Note1: get_block_t takes a long (implicit cast from above)
  542. * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
  543. * can optionally convert the [unsigned] long from above into
  544. * an [unsigned] long long.
  545. */
  546. #if BITS_PER_LONG == 32
  547. # if defined(CONFIG_LBDAF)
  548. ASSERT(sizeof(sector_t) == 8);
  549. pagefactor = PAGE_CACHE_SIZE;
  550. bitshift = BITS_PER_LONG;
  551. # else
  552. pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
  553. # endif
  554. #endif
  555. return (((__uint64_t)pagefactor) << bitshift) - 1;
  556. }
  557. xfs_agnumber_t
  558. xfs_set_inode32(struct xfs_mount *mp)
  559. {
  560. xfs_agnumber_t index = 0;
  561. xfs_agnumber_t maxagi = 0;
  562. xfs_sb_t *sbp = &mp->m_sb;
  563. xfs_agnumber_t max_metadata;
  564. xfs_agino_t agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks -1, 0);
  565. xfs_ino_t ino = XFS_AGINO_TO_INO(mp, sbp->sb_agcount -1, agino);
  566. xfs_perag_t *pag;
  567. /* Calculate how much should be reserved for inodes to meet
  568. * the max inode percentage.
  569. */
  570. if (mp->m_maxicount) {
  571. __uint64_t icount;
  572. icount = sbp->sb_dblocks * sbp->sb_imax_pct;
  573. do_div(icount, 100);
  574. icount += sbp->sb_agblocks - 1;
  575. do_div(icount, sbp->sb_agblocks);
  576. max_metadata = icount;
  577. } else {
  578. max_metadata = sbp->sb_agcount;
  579. }
  580. for (index = 0; index < sbp->sb_agcount; index++) {
  581. ino = XFS_AGINO_TO_INO(mp, index, agino);
  582. if (ino > XFS_MAXINUMBER_32) {
  583. pag = xfs_perag_get(mp, index);
  584. pag->pagi_inodeok = 0;
  585. pag->pagf_metadata = 0;
  586. xfs_perag_put(pag);
  587. continue;
  588. }
  589. pag = xfs_perag_get(mp, index);
  590. pag->pagi_inodeok = 1;
  591. maxagi++;
  592. if (index < max_metadata)
  593. pag->pagf_metadata = 1;
  594. xfs_perag_put(pag);
  595. }
  596. mp->m_flags |= (XFS_MOUNT_32BITINODES |
  597. XFS_MOUNT_SMALL_INUMS);
  598. return maxagi;
  599. }
  600. xfs_agnumber_t
  601. xfs_set_inode64(struct xfs_mount *mp)
  602. {
  603. xfs_agnumber_t index = 0;
  604. for (index = 0; index < mp->m_sb.sb_agcount; index++) {
  605. struct xfs_perag *pag;
  606. pag = xfs_perag_get(mp, index);
  607. pag->pagi_inodeok = 1;
  608. pag->pagf_metadata = 0;
  609. xfs_perag_put(pag);
  610. }
  611. /* There is no need for lock protection on m_flags,
  612. * the rw_semaphore of the VFS superblock is locked
  613. * during mount/umount/remount operations, so this is
  614. * enough to avoid concurency on the m_flags field
  615. */
  616. mp->m_flags &= ~(XFS_MOUNT_32BITINODES |
  617. XFS_MOUNT_SMALL_INUMS);
  618. return index;
  619. }
  620. STATIC int
  621. xfs_blkdev_get(
  622. xfs_mount_t *mp,
  623. const char *name,
  624. struct block_device **bdevp)
  625. {
  626. int error = 0;
  627. *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
  628. mp);
  629. if (IS_ERR(*bdevp)) {
  630. error = PTR_ERR(*bdevp);
  631. xfs_warn(mp, "Invalid device [%s], error=%d\n", name, error);
  632. }
  633. return -error;
  634. }
  635. STATIC void
  636. xfs_blkdev_put(
  637. struct block_device *bdev)
  638. {
  639. if (bdev)
  640. blkdev_put(bdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL);
  641. }
  642. void
  643. xfs_blkdev_issue_flush(
  644. xfs_buftarg_t *buftarg)
  645. {
  646. blkdev_issue_flush(buftarg->bt_bdev, GFP_NOFS, NULL);
  647. }
  648. STATIC void
  649. xfs_close_devices(
  650. struct xfs_mount *mp)
  651. {
  652. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  653. struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
  654. xfs_free_buftarg(mp, mp->m_logdev_targp);
  655. xfs_blkdev_put(logdev);
  656. }
  657. if (mp->m_rtdev_targp) {
  658. struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
  659. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  660. xfs_blkdev_put(rtdev);
  661. }
  662. xfs_free_buftarg(mp, mp->m_ddev_targp);
  663. }
  664. /*
  665. * The file system configurations are:
  666. * (1) device (partition) with data and internal log
  667. * (2) logical volume with data and log subvolumes.
  668. * (3) logical volume with data, log, and realtime subvolumes.
  669. *
  670. * We only have to handle opening the log and realtime volumes here if
  671. * they are present. The data subvolume has already been opened by
  672. * get_sb_bdev() and is stored in sb->s_bdev.
  673. */
  674. STATIC int
  675. xfs_open_devices(
  676. struct xfs_mount *mp)
  677. {
  678. struct block_device *ddev = mp->m_super->s_bdev;
  679. struct block_device *logdev = NULL, *rtdev = NULL;
  680. int error;
  681. /*
  682. * Open real time and log devices - order is important.
  683. */
  684. if (mp->m_logname) {
  685. error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
  686. if (error)
  687. goto out;
  688. }
  689. if (mp->m_rtname) {
  690. error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
  691. if (error)
  692. goto out_close_logdev;
  693. if (rtdev == ddev || rtdev == logdev) {
  694. xfs_warn(mp,
  695. "Cannot mount filesystem with identical rtdev and ddev/logdev.");
  696. error = EINVAL;
  697. goto out_close_rtdev;
  698. }
  699. }
  700. /*
  701. * Setup xfs_mount buffer target pointers
  702. */
  703. error = ENOMEM;
  704. mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev, 0, mp->m_fsname);
  705. if (!mp->m_ddev_targp)
  706. goto out_close_rtdev;
  707. if (rtdev) {
  708. mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev, 1,
  709. mp->m_fsname);
  710. if (!mp->m_rtdev_targp)
  711. goto out_free_ddev_targ;
  712. }
  713. if (logdev && logdev != ddev) {
  714. mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev, 1,
  715. mp->m_fsname);
  716. if (!mp->m_logdev_targp)
  717. goto out_free_rtdev_targ;
  718. } else {
  719. mp->m_logdev_targp = mp->m_ddev_targp;
  720. }
  721. return 0;
  722. out_free_rtdev_targ:
  723. if (mp->m_rtdev_targp)
  724. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  725. out_free_ddev_targ:
  726. xfs_free_buftarg(mp, mp->m_ddev_targp);
  727. out_close_rtdev:
  728. if (rtdev)
  729. xfs_blkdev_put(rtdev);
  730. out_close_logdev:
  731. if (logdev && logdev != ddev)
  732. xfs_blkdev_put(logdev);
  733. out:
  734. return error;
  735. }
  736. /*
  737. * Setup xfs_mount buffer target pointers based on superblock
  738. */
  739. STATIC int
  740. xfs_setup_devices(
  741. struct xfs_mount *mp)
  742. {
  743. int error;
  744. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  745. mp->m_sb.sb_sectsize);
  746. if (error)
  747. return error;
  748. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  749. unsigned int log_sector_size = BBSIZE;
  750. if (xfs_sb_version_hassector(&mp->m_sb))
  751. log_sector_size = mp->m_sb.sb_logsectsize;
  752. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  753. mp->m_sb.sb_blocksize,
  754. log_sector_size);
  755. if (error)
  756. return error;
  757. }
  758. if (mp->m_rtdev_targp) {
  759. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  760. mp->m_sb.sb_blocksize,
  761. mp->m_sb.sb_sectsize);
  762. if (error)
  763. return error;
  764. }
  765. return 0;
  766. }
  767. STATIC int
  768. xfs_init_mount_workqueues(
  769. struct xfs_mount *mp)
  770. {
  771. mp->m_data_workqueue = alloc_workqueue("xfs-data/%s",
  772. WQ_MEM_RECLAIM, 0, mp->m_fsname);
  773. if (!mp->m_data_workqueue)
  774. goto out;
  775. mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
  776. WQ_MEM_RECLAIM, 0, mp->m_fsname);
  777. if (!mp->m_unwritten_workqueue)
  778. goto out_destroy_data_iodone_queue;
  779. mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
  780. WQ_MEM_RECLAIM, 0, mp->m_fsname);
  781. if (!mp->m_cil_workqueue)
  782. goto out_destroy_unwritten;
  783. mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
  784. 0, 0, mp->m_fsname);
  785. if (!mp->m_reclaim_workqueue)
  786. goto out_destroy_cil;
  787. mp->m_log_workqueue = alloc_workqueue("xfs-log/%s",
  788. 0, 0, mp->m_fsname);
  789. if (!mp->m_log_workqueue)
  790. goto out_destroy_reclaim;
  791. mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
  792. 0, 0, mp->m_fsname);
  793. if (!mp->m_eofblocks_workqueue)
  794. goto out_destroy_log;
  795. return 0;
  796. out_destroy_log:
  797. destroy_workqueue(mp->m_log_workqueue);
  798. out_destroy_reclaim:
  799. destroy_workqueue(mp->m_reclaim_workqueue);
  800. out_destroy_cil:
  801. destroy_workqueue(mp->m_cil_workqueue);
  802. out_destroy_unwritten:
  803. destroy_workqueue(mp->m_unwritten_workqueue);
  804. out_destroy_data_iodone_queue:
  805. destroy_workqueue(mp->m_data_workqueue);
  806. out:
  807. return -ENOMEM;
  808. }
  809. STATIC void
  810. xfs_destroy_mount_workqueues(
  811. struct xfs_mount *mp)
  812. {
  813. destroy_workqueue(mp->m_eofblocks_workqueue);
  814. destroy_workqueue(mp->m_log_workqueue);
  815. destroy_workqueue(mp->m_reclaim_workqueue);
  816. destroy_workqueue(mp->m_cil_workqueue);
  817. destroy_workqueue(mp->m_data_workqueue);
  818. destroy_workqueue(mp->m_unwritten_workqueue);
  819. }
  820. /*
  821. * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
  822. * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
  823. * for IO to complete so that we effectively throttle multiple callers to the
  824. * rate at which IO is completing.
  825. */
  826. void
  827. xfs_flush_inodes(
  828. struct xfs_mount *mp)
  829. {
  830. struct super_block *sb = mp->m_super;
  831. if (down_read_trylock(&sb->s_umount)) {
  832. sync_inodes_sb(sb, jiffies);
  833. up_read(&sb->s_umount);
  834. }
  835. }
  836. /* Catch misguided souls that try to use this interface on XFS */
  837. STATIC struct inode *
  838. xfs_fs_alloc_inode(
  839. struct super_block *sb)
  840. {
  841. BUG();
  842. return NULL;
  843. }
  844. /*
  845. * Now that the generic code is guaranteed not to be accessing
  846. * the linux inode, we can reclaim the inode.
  847. */
  848. STATIC void
  849. xfs_fs_destroy_inode(
  850. struct inode *inode)
  851. {
  852. struct xfs_inode *ip = XFS_I(inode);
  853. trace_xfs_destroy_inode(ip);
  854. XFS_STATS_INC(vn_reclaim);
  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. xfs_inode_set_reclaim_tag(ip);
  869. }
  870. /*
  871. * Slab object creation initialisation for the XFS inode.
  872. * This covers only the idempotent fields in the XFS inode;
  873. * all other fields need to be initialised on allocation
  874. * from the slab. This avoids the need to repeatedly initialise
  875. * fields in the xfs inode that left in the initialise state
  876. * when freeing the inode.
  877. */
  878. STATIC void
  879. xfs_fs_inode_init_once(
  880. void *inode)
  881. {
  882. struct xfs_inode *ip = inode;
  883. memset(ip, 0, sizeof(struct xfs_inode));
  884. /* vfs inode */
  885. inode_init_once(VFS_I(ip));
  886. /* xfs inode */
  887. atomic_set(&ip->i_pincount, 0);
  888. spin_lock_init(&ip->i_flags_lock);
  889. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  890. "xfsino", ip->i_ino);
  891. }
  892. STATIC void
  893. xfs_fs_evict_inode(
  894. struct inode *inode)
  895. {
  896. xfs_inode_t *ip = XFS_I(inode);
  897. ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
  898. trace_xfs_evict_inode(ip);
  899. truncate_inode_pages(&inode->i_data, 0);
  900. clear_inode(inode);
  901. XFS_STATS_INC(vn_rele);
  902. XFS_STATS_INC(vn_remove);
  903. XFS_STATS_DEC(vn_active);
  904. xfs_inactive(ip);
  905. }
  906. /*
  907. * We do an unlocked check for XFS_IDONTCACHE here because we are already
  908. * serialised against cache hits here via the inode->i_lock and igrab() in
  909. * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
  910. * racing with us, and it avoids needing to grab a spinlock here for every inode
  911. * we drop the final reference on.
  912. */
  913. STATIC int
  914. xfs_fs_drop_inode(
  915. struct inode *inode)
  916. {
  917. struct xfs_inode *ip = XFS_I(inode);
  918. return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
  919. }
  920. STATIC void
  921. xfs_free_fsname(
  922. struct xfs_mount *mp)
  923. {
  924. kfree(mp->m_fsname);
  925. kfree(mp->m_rtname);
  926. kfree(mp->m_logname);
  927. }
  928. STATIC void
  929. xfs_fs_put_super(
  930. struct super_block *sb)
  931. {
  932. struct xfs_mount *mp = XFS_M(sb);
  933. xfs_filestream_unmount(mp);
  934. xfs_unmountfs(mp);
  935. xfs_freesb(mp);
  936. xfs_icsb_destroy_counters(mp);
  937. xfs_destroy_mount_workqueues(mp);
  938. xfs_close_devices(mp);
  939. xfs_free_fsname(mp);
  940. kfree(mp);
  941. }
  942. STATIC int
  943. xfs_fs_sync_fs(
  944. struct super_block *sb,
  945. int wait)
  946. {
  947. struct xfs_mount *mp = XFS_M(sb);
  948. /*
  949. * Doing anything during the async pass would be counterproductive.
  950. */
  951. if (!wait)
  952. return 0;
  953. xfs_log_force(mp, XFS_LOG_SYNC);
  954. if (laptop_mode) {
  955. /*
  956. * The disk must be active because we're syncing.
  957. * We schedule log work now (now that the disk is
  958. * active) instead of later (when it might not be).
  959. */
  960. flush_delayed_work(&mp->m_log->l_work);
  961. }
  962. return 0;
  963. }
  964. STATIC int
  965. xfs_fs_statfs(
  966. struct dentry *dentry,
  967. struct kstatfs *statp)
  968. {
  969. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  970. xfs_sb_t *sbp = &mp->m_sb;
  971. struct xfs_inode *ip = XFS_I(dentry->d_inode);
  972. __uint64_t fakeinos, id;
  973. xfs_extlen_t lsize;
  974. __int64_t ffree;
  975. statp->f_type = XFS_SB_MAGIC;
  976. statp->f_namelen = MAXNAMELEN - 1;
  977. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  978. statp->f_fsid.val[0] = (u32)id;
  979. statp->f_fsid.val[1] = (u32)(id >> 32);
  980. xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
  981. spin_lock(&mp->m_sb_lock);
  982. statp->f_bsize = sbp->sb_blocksize;
  983. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  984. statp->f_blocks = sbp->sb_dblocks - lsize;
  985. statp->f_bfree = statp->f_bavail =
  986. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  987. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  988. statp->f_files =
  989. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  990. if (mp->m_maxicount)
  991. statp->f_files = min_t(typeof(statp->f_files),
  992. statp->f_files,
  993. mp->m_maxicount);
  994. /* make sure statp->f_ffree does not underflow */
  995. ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  996. statp->f_ffree = max_t(__int64_t, ffree, 0);
  997. spin_unlock(&mp->m_sb_lock);
  998. if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
  999. ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
  1000. (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
  1001. xfs_qm_statvfs(ip, statp);
  1002. return 0;
  1003. }
  1004. STATIC void
  1005. xfs_save_resvblks(struct xfs_mount *mp)
  1006. {
  1007. __uint64_t resblks = 0;
  1008. mp->m_resblks_save = mp->m_resblks;
  1009. xfs_reserve_blocks(mp, &resblks, NULL);
  1010. }
  1011. STATIC void
  1012. xfs_restore_resvblks(struct xfs_mount *mp)
  1013. {
  1014. __uint64_t resblks;
  1015. if (mp->m_resblks_save) {
  1016. resblks = mp->m_resblks_save;
  1017. mp->m_resblks_save = 0;
  1018. } else
  1019. resblks = xfs_default_resblks(mp);
  1020. xfs_reserve_blocks(mp, &resblks, NULL);
  1021. }
  1022. /*
  1023. * Trigger writeback of all the dirty metadata in the file system.
  1024. *
  1025. * This ensures that the metadata is written to their location on disk rather
  1026. * than just existing in transactions in the log. This means after a quiesce
  1027. * there is no log replay required to write the inodes to disk - this is the
  1028. * primary difference between a sync and a quiesce.
  1029. *
  1030. * Note: xfs_log_quiesce() stops background log work - the callers must ensure
  1031. * it is started again when appropriate.
  1032. */
  1033. static void
  1034. xfs_quiesce_attr(
  1035. struct xfs_mount *mp)
  1036. {
  1037. int error = 0;
  1038. /* wait for all modifications to complete */
  1039. while (atomic_read(&mp->m_active_trans) > 0)
  1040. delay(100);
  1041. /* force the log to unpin objects from the now complete transactions */
  1042. xfs_log_force(mp, XFS_LOG_SYNC);
  1043. /* reclaim inodes to do any IO before the freeze completes */
  1044. xfs_reclaim_inodes(mp, 0);
  1045. xfs_reclaim_inodes(mp, SYNC_WAIT);
  1046. /* Push the superblock and write an unmount record */
  1047. error = xfs_log_sbcount(mp);
  1048. if (error)
  1049. xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
  1050. "Frozen image may not be consistent.");
  1051. /*
  1052. * Just warn here till VFS can correctly support
  1053. * read-only remount without racing.
  1054. */
  1055. WARN_ON(atomic_read(&mp->m_active_trans) != 0);
  1056. xfs_log_quiesce(mp);
  1057. }
  1058. STATIC int
  1059. xfs_fs_remount(
  1060. struct super_block *sb,
  1061. int *flags,
  1062. char *options)
  1063. {
  1064. struct xfs_mount *mp = XFS_M(sb);
  1065. substring_t args[MAX_OPT_ARGS];
  1066. char *p;
  1067. int error;
  1068. while ((p = strsep(&options, ",")) != NULL) {
  1069. int token;
  1070. if (!*p)
  1071. continue;
  1072. token = match_token(p, tokens, args);
  1073. switch (token) {
  1074. case Opt_barrier:
  1075. mp->m_flags |= XFS_MOUNT_BARRIER;
  1076. break;
  1077. case Opt_nobarrier:
  1078. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1079. break;
  1080. case Opt_inode64:
  1081. mp->m_maxagi = xfs_set_inode64(mp);
  1082. break;
  1083. case Opt_inode32:
  1084. mp->m_maxagi = xfs_set_inode32(mp);
  1085. break;
  1086. default:
  1087. /*
  1088. * Logically we would return an error here to prevent
  1089. * users from believing they might have changed
  1090. * mount options using remount which can't be changed.
  1091. *
  1092. * But unfortunately mount(8) adds all options from
  1093. * mtab and fstab to the mount arguments in some cases
  1094. * so we can't blindly reject options, but have to
  1095. * check for each specified option if it actually
  1096. * differs from the currently set option and only
  1097. * reject it if that's the case.
  1098. *
  1099. * Until that is implemented we return success for
  1100. * every remount request, and silently ignore all
  1101. * options that we can't actually change.
  1102. */
  1103. #if 0
  1104. xfs_info(mp,
  1105. "mount option \"%s\" not supported for remount", p);
  1106. return -EINVAL;
  1107. #else
  1108. break;
  1109. #endif
  1110. }
  1111. }
  1112. /* ro -> rw */
  1113. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1114. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1115. /*
  1116. * If this is the first remount to writeable state we
  1117. * might have some superblock changes to update.
  1118. */
  1119. if (mp->m_update_flags) {
  1120. error = xfs_mount_log_sb(mp, mp->m_update_flags);
  1121. if (error) {
  1122. xfs_warn(mp, "failed to write sb changes");
  1123. return error;
  1124. }
  1125. mp->m_update_flags = 0;
  1126. }
  1127. /*
  1128. * Fill out the reserve pool if it is empty. Use the stashed
  1129. * value if it is non-zero, otherwise go with the default.
  1130. */
  1131. xfs_restore_resvblks(mp);
  1132. xfs_log_work_queue(mp);
  1133. }
  1134. /* rw -> ro */
  1135. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1136. /*
  1137. * Before we sync the metadata, we need to free up the reserve
  1138. * block pool so that the used block count in the superblock on
  1139. * disk is correct at the end of the remount. Stash the current
  1140. * reserve pool size so that if we get remounted rw, we can
  1141. * return it to the same size.
  1142. */
  1143. xfs_save_resvblks(mp);
  1144. xfs_quiesce_attr(mp);
  1145. mp->m_flags |= XFS_MOUNT_RDONLY;
  1146. }
  1147. return 0;
  1148. }
  1149. /*
  1150. * Second stage of a freeze. The data is already frozen so we only
  1151. * need to take care of the metadata. Once that's done write a dummy
  1152. * record to dirty the log in case of a crash while frozen.
  1153. */
  1154. STATIC int
  1155. xfs_fs_freeze(
  1156. struct super_block *sb)
  1157. {
  1158. struct xfs_mount *mp = XFS_M(sb);
  1159. xfs_save_resvblks(mp);
  1160. xfs_quiesce_attr(mp);
  1161. return -xfs_fs_log_dummy(mp);
  1162. }
  1163. STATIC int
  1164. xfs_fs_unfreeze(
  1165. struct super_block *sb)
  1166. {
  1167. struct xfs_mount *mp = XFS_M(sb);
  1168. xfs_restore_resvblks(mp);
  1169. xfs_log_work_queue(mp);
  1170. return 0;
  1171. }
  1172. STATIC int
  1173. xfs_fs_show_options(
  1174. struct seq_file *m,
  1175. struct dentry *root)
  1176. {
  1177. return -xfs_showargs(XFS_M(root->d_sb), m);
  1178. }
  1179. /*
  1180. * This function fills in xfs_mount_t fields based on mount args.
  1181. * Note: the superblock _has_ now been read in.
  1182. */
  1183. STATIC int
  1184. xfs_finish_flags(
  1185. struct xfs_mount *mp)
  1186. {
  1187. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1188. /* Fail a mount where the logbuf is smaller than the log stripe */
  1189. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1190. if (mp->m_logbsize <= 0 &&
  1191. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  1192. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1193. } else if (mp->m_logbsize > 0 &&
  1194. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  1195. xfs_warn(mp,
  1196. "logbuf size must be greater than or equal to log stripe size");
  1197. return XFS_ERROR(EINVAL);
  1198. }
  1199. } else {
  1200. /* Fail a mount if the logbuf is larger than 32K */
  1201. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  1202. xfs_warn(mp,
  1203. "logbuf size for version 1 logs must be 16K or 32K");
  1204. return XFS_ERROR(EINVAL);
  1205. }
  1206. }
  1207. /*
  1208. * V5 filesystems always use attr2 format for attributes.
  1209. */
  1210. if (xfs_sb_version_hascrc(&mp->m_sb) &&
  1211. (mp->m_flags & XFS_MOUNT_NOATTR2)) {
  1212. xfs_warn(mp,
  1213. "Cannot mount a V5 filesystem as %s. %s is always enabled for V5 filesystems.",
  1214. MNTOPT_NOATTR2, MNTOPT_ATTR2);
  1215. return XFS_ERROR(EINVAL);
  1216. }
  1217. /*
  1218. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1219. * told by noattr2 to turn it off
  1220. */
  1221. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1222. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  1223. mp->m_flags |= XFS_MOUNT_ATTR2;
  1224. /*
  1225. * prohibit r/w mounts of read-only filesystems
  1226. */
  1227. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1228. xfs_warn(mp,
  1229. "cannot mount a read-only filesystem as read-write");
  1230. return XFS_ERROR(EROFS);
  1231. }
  1232. if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
  1233. (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
  1234. !xfs_sb_version_has_pquotino(&mp->m_sb)) {
  1235. xfs_warn(mp,
  1236. "Super block does not support project and group quota together");
  1237. return XFS_ERROR(EINVAL);
  1238. }
  1239. return 0;
  1240. }
  1241. STATIC int
  1242. xfs_fs_fill_super(
  1243. struct super_block *sb,
  1244. void *data,
  1245. int silent)
  1246. {
  1247. struct inode *root;
  1248. struct xfs_mount *mp = NULL;
  1249. int flags = 0, error = ENOMEM;
  1250. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1251. if (!mp)
  1252. goto out;
  1253. spin_lock_init(&mp->m_sb_lock);
  1254. mutex_init(&mp->m_growlock);
  1255. atomic_set(&mp->m_active_trans, 0);
  1256. INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
  1257. INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
  1258. mp->m_super = sb;
  1259. sb->s_fs_info = mp;
  1260. error = xfs_parseargs(mp, (char *)data);
  1261. if (error)
  1262. goto out_free_fsname;
  1263. sb_min_blocksize(sb, BBSIZE);
  1264. sb->s_xattr = xfs_xattr_handlers;
  1265. sb->s_export_op = &xfs_export_operations;
  1266. #ifdef CONFIG_XFS_QUOTA
  1267. sb->s_qcop = &xfs_quotactl_operations;
  1268. #endif
  1269. sb->s_op = &xfs_super_operations;
  1270. if (silent)
  1271. flags |= XFS_MFSI_QUIET;
  1272. error = xfs_open_devices(mp);
  1273. if (error)
  1274. goto out_free_fsname;
  1275. error = xfs_init_mount_workqueues(mp);
  1276. if (error)
  1277. goto out_close_devices;
  1278. error = xfs_icsb_init_counters(mp);
  1279. if (error)
  1280. goto out_destroy_workqueues;
  1281. error = xfs_readsb(mp, flags);
  1282. if (error)
  1283. goto out_destroy_counters;
  1284. error = xfs_finish_flags(mp);
  1285. if (error)
  1286. goto out_free_sb;
  1287. error = xfs_setup_devices(mp);
  1288. if (error)
  1289. goto out_free_sb;
  1290. error = xfs_filestream_mount(mp);
  1291. if (error)
  1292. goto out_free_sb;
  1293. /*
  1294. * we must configure the block size in the superblock before we run the
  1295. * full mount process as the mount process can lookup and cache inodes.
  1296. */
  1297. sb->s_magic = XFS_SB_MAGIC;
  1298. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1299. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1300. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1301. sb->s_max_links = XFS_MAXLINK;
  1302. sb->s_time_gran = 1;
  1303. set_posix_acl_flag(sb);
  1304. /* version 5 superblocks support inode version counters. */
  1305. if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
  1306. sb->s_flags |= MS_I_VERSION;
  1307. error = xfs_mountfs(mp);
  1308. if (error)
  1309. goto out_filestream_unmount;
  1310. root = igrab(VFS_I(mp->m_rootip));
  1311. if (!root) {
  1312. error = ENOENT;
  1313. goto out_unmount;
  1314. }
  1315. sb->s_root = d_make_root(root);
  1316. if (!sb->s_root) {
  1317. error = ENOMEM;
  1318. goto out_unmount;
  1319. }
  1320. return 0;
  1321. out_filestream_unmount:
  1322. xfs_filestream_unmount(mp);
  1323. out_free_sb:
  1324. xfs_freesb(mp);
  1325. out_destroy_counters:
  1326. xfs_icsb_destroy_counters(mp);
  1327. out_destroy_workqueues:
  1328. xfs_destroy_mount_workqueues(mp);
  1329. out_close_devices:
  1330. xfs_close_devices(mp);
  1331. out_free_fsname:
  1332. xfs_free_fsname(mp);
  1333. kfree(mp);
  1334. out:
  1335. return -error;
  1336. out_unmount:
  1337. xfs_filestream_unmount(mp);
  1338. xfs_unmountfs(mp);
  1339. goto out_free_sb;
  1340. }
  1341. STATIC struct dentry *
  1342. xfs_fs_mount(
  1343. struct file_system_type *fs_type,
  1344. int flags,
  1345. const char *dev_name,
  1346. void *data)
  1347. {
  1348. return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
  1349. }
  1350. static long
  1351. xfs_fs_nr_cached_objects(
  1352. struct super_block *sb,
  1353. int nid)
  1354. {
  1355. return xfs_reclaim_inodes_count(XFS_M(sb));
  1356. }
  1357. static long
  1358. xfs_fs_free_cached_objects(
  1359. struct super_block *sb,
  1360. long nr_to_scan,
  1361. int nid)
  1362. {
  1363. return xfs_reclaim_inodes_nr(XFS_M(sb), nr_to_scan);
  1364. }
  1365. static const struct super_operations xfs_super_operations = {
  1366. .alloc_inode = xfs_fs_alloc_inode,
  1367. .destroy_inode = xfs_fs_destroy_inode,
  1368. .evict_inode = xfs_fs_evict_inode,
  1369. .drop_inode = xfs_fs_drop_inode,
  1370. .put_super = xfs_fs_put_super,
  1371. .sync_fs = xfs_fs_sync_fs,
  1372. .freeze_fs = xfs_fs_freeze,
  1373. .unfreeze_fs = xfs_fs_unfreeze,
  1374. .statfs = xfs_fs_statfs,
  1375. .remount_fs = xfs_fs_remount,
  1376. .show_options = xfs_fs_show_options,
  1377. .nr_cached_objects = xfs_fs_nr_cached_objects,
  1378. .free_cached_objects = xfs_fs_free_cached_objects,
  1379. };
  1380. static struct file_system_type xfs_fs_type = {
  1381. .owner = THIS_MODULE,
  1382. .name = "xfs",
  1383. .mount = xfs_fs_mount,
  1384. .kill_sb = kill_block_super,
  1385. .fs_flags = FS_REQUIRES_DEV,
  1386. };
  1387. MODULE_ALIAS_FS("xfs");
  1388. STATIC int __init
  1389. xfs_init_zones(void)
  1390. {
  1391. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  1392. if (!xfs_ioend_zone)
  1393. goto out;
  1394. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  1395. xfs_ioend_zone);
  1396. if (!xfs_ioend_pool)
  1397. goto out_destroy_ioend_zone;
  1398. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1399. "xfs_log_ticket");
  1400. if (!xfs_log_ticket_zone)
  1401. goto out_destroy_ioend_pool;
  1402. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  1403. "xfs_bmap_free_item");
  1404. if (!xfs_bmap_free_item_zone)
  1405. goto out_destroy_log_ticket_zone;
  1406. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1407. "xfs_btree_cur");
  1408. if (!xfs_btree_cur_zone)
  1409. goto out_destroy_bmap_free_item_zone;
  1410. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1411. "xfs_da_state");
  1412. if (!xfs_da_state_zone)
  1413. goto out_destroy_btree_cur_zone;
  1414. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1415. if (!xfs_ifork_zone)
  1416. goto out_destroy_da_state_zone;
  1417. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1418. if (!xfs_trans_zone)
  1419. goto out_destroy_ifork_zone;
  1420. xfs_log_item_desc_zone =
  1421. kmem_zone_init(sizeof(struct xfs_log_item_desc),
  1422. "xfs_log_item_desc");
  1423. if (!xfs_log_item_desc_zone)
  1424. goto out_destroy_trans_zone;
  1425. /*
  1426. * The size of the zone allocated buf log item is the maximum
  1427. * size possible under XFS. This wastes a little bit of memory,
  1428. * but it is much faster.
  1429. */
  1430. xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
  1431. "xfs_buf_item");
  1432. if (!xfs_buf_item_zone)
  1433. goto out_destroy_log_item_desc_zone;
  1434. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1435. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1436. sizeof(xfs_extent_t))), "xfs_efd_item");
  1437. if (!xfs_efd_zone)
  1438. goto out_destroy_buf_item_zone;
  1439. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1440. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1441. sizeof(xfs_extent_t))), "xfs_efi_item");
  1442. if (!xfs_efi_zone)
  1443. goto out_destroy_efd_zone;
  1444. xfs_inode_zone =
  1445. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1446. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
  1447. xfs_fs_inode_init_once);
  1448. if (!xfs_inode_zone)
  1449. goto out_destroy_efi_zone;
  1450. xfs_ili_zone =
  1451. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1452. KM_ZONE_SPREAD, NULL);
  1453. if (!xfs_ili_zone)
  1454. goto out_destroy_inode_zone;
  1455. xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
  1456. "xfs_icr");
  1457. if (!xfs_icreate_zone)
  1458. goto out_destroy_ili_zone;
  1459. return 0;
  1460. out_destroy_ili_zone:
  1461. kmem_zone_destroy(xfs_ili_zone);
  1462. out_destroy_inode_zone:
  1463. kmem_zone_destroy(xfs_inode_zone);
  1464. out_destroy_efi_zone:
  1465. kmem_zone_destroy(xfs_efi_zone);
  1466. out_destroy_efd_zone:
  1467. kmem_zone_destroy(xfs_efd_zone);
  1468. out_destroy_buf_item_zone:
  1469. kmem_zone_destroy(xfs_buf_item_zone);
  1470. out_destroy_log_item_desc_zone:
  1471. kmem_zone_destroy(xfs_log_item_desc_zone);
  1472. out_destroy_trans_zone:
  1473. kmem_zone_destroy(xfs_trans_zone);
  1474. out_destroy_ifork_zone:
  1475. kmem_zone_destroy(xfs_ifork_zone);
  1476. out_destroy_da_state_zone:
  1477. kmem_zone_destroy(xfs_da_state_zone);
  1478. out_destroy_btree_cur_zone:
  1479. kmem_zone_destroy(xfs_btree_cur_zone);
  1480. out_destroy_bmap_free_item_zone:
  1481. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1482. out_destroy_log_ticket_zone:
  1483. kmem_zone_destroy(xfs_log_ticket_zone);
  1484. out_destroy_ioend_pool:
  1485. mempool_destroy(xfs_ioend_pool);
  1486. out_destroy_ioend_zone:
  1487. kmem_zone_destroy(xfs_ioend_zone);
  1488. out:
  1489. return -ENOMEM;
  1490. }
  1491. STATIC void
  1492. xfs_destroy_zones(void)
  1493. {
  1494. /*
  1495. * Make sure all delayed rcu free are flushed before we
  1496. * destroy caches.
  1497. */
  1498. rcu_barrier();
  1499. kmem_zone_destroy(xfs_icreate_zone);
  1500. kmem_zone_destroy(xfs_ili_zone);
  1501. kmem_zone_destroy(xfs_inode_zone);
  1502. kmem_zone_destroy(xfs_efi_zone);
  1503. kmem_zone_destroy(xfs_efd_zone);
  1504. kmem_zone_destroy(xfs_buf_item_zone);
  1505. kmem_zone_destroy(xfs_log_item_desc_zone);
  1506. kmem_zone_destroy(xfs_trans_zone);
  1507. kmem_zone_destroy(xfs_ifork_zone);
  1508. kmem_zone_destroy(xfs_da_state_zone);
  1509. kmem_zone_destroy(xfs_btree_cur_zone);
  1510. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1511. kmem_zone_destroy(xfs_log_ticket_zone);
  1512. mempool_destroy(xfs_ioend_pool);
  1513. kmem_zone_destroy(xfs_ioend_zone);
  1514. }
  1515. STATIC int __init
  1516. xfs_init_workqueues(void)
  1517. {
  1518. /*
  1519. * The allocation workqueue can be used in memory reclaim situations
  1520. * (writepage path), and parallelism is only limited by the number of
  1521. * AGs in all the filesystems mounted. Hence use the default large
  1522. * max_active value for this workqueue.
  1523. */
  1524. xfs_alloc_wq = alloc_workqueue("xfsalloc", WQ_MEM_RECLAIM, 0);
  1525. if (!xfs_alloc_wq)
  1526. return -ENOMEM;
  1527. return 0;
  1528. }
  1529. STATIC void
  1530. xfs_destroy_workqueues(void)
  1531. {
  1532. destroy_workqueue(xfs_alloc_wq);
  1533. }
  1534. STATIC int __init
  1535. init_xfs_fs(void)
  1536. {
  1537. int error;
  1538. printk(KERN_INFO XFS_VERSION_STRING " with "
  1539. XFS_BUILD_OPTIONS " enabled\n");
  1540. xfs_dir_startup();
  1541. error = xfs_init_zones();
  1542. if (error)
  1543. goto out;
  1544. error = xfs_init_workqueues();
  1545. if (error)
  1546. goto out_destroy_zones;
  1547. error = xfs_mru_cache_init();
  1548. if (error)
  1549. goto out_destroy_wq;
  1550. error = xfs_filestream_init();
  1551. if (error)
  1552. goto out_mru_cache_uninit;
  1553. error = xfs_buf_init();
  1554. if (error)
  1555. goto out_filestream_uninit;
  1556. error = xfs_init_procfs();
  1557. if (error)
  1558. goto out_buf_terminate;
  1559. error = xfs_sysctl_register();
  1560. if (error)
  1561. goto out_cleanup_procfs;
  1562. error = xfs_qm_init();
  1563. if (error)
  1564. goto out_sysctl_unregister;
  1565. error = register_filesystem(&xfs_fs_type);
  1566. if (error)
  1567. goto out_qm_exit;
  1568. return 0;
  1569. out_qm_exit:
  1570. xfs_qm_exit();
  1571. out_sysctl_unregister:
  1572. xfs_sysctl_unregister();
  1573. out_cleanup_procfs:
  1574. xfs_cleanup_procfs();
  1575. out_buf_terminate:
  1576. xfs_buf_terminate();
  1577. out_filestream_uninit:
  1578. xfs_filestream_uninit();
  1579. out_mru_cache_uninit:
  1580. xfs_mru_cache_uninit();
  1581. out_destroy_wq:
  1582. xfs_destroy_workqueues();
  1583. out_destroy_zones:
  1584. xfs_destroy_zones();
  1585. out:
  1586. return error;
  1587. }
  1588. STATIC void __exit
  1589. exit_xfs_fs(void)
  1590. {
  1591. xfs_qm_exit();
  1592. unregister_filesystem(&xfs_fs_type);
  1593. xfs_sysctl_unregister();
  1594. xfs_cleanup_procfs();
  1595. xfs_buf_terminate();
  1596. xfs_filestream_uninit();
  1597. xfs_mru_cache_uninit();
  1598. xfs_destroy_workqueues();
  1599. xfs_destroy_zones();
  1600. }
  1601. module_init(init_xfs_fs);
  1602. module_exit(exit_xfs_fs);
  1603. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1604. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1605. MODULE_LICENSE("GPL");