xfs_super.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844
  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_sb.h"
  24. #include "xfs_mount.h"
  25. #include "xfs_da_format.h"
  26. #include "xfs_inode.h"
  27. #include "xfs_btree.h"
  28. #include "xfs_bmap.h"
  29. #include "xfs_alloc.h"
  30. #include "xfs_error.h"
  31. #include "xfs_fsops.h"
  32. #include "xfs_trans.h"
  33. #include "xfs_buf_item.h"
  34. #include "xfs_log.h"
  35. #include "xfs_log_priv.h"
  36. #include "xfs_da_btree.h"
  37. #include "xfs_dir2.h"
  38. #include "xfs_extfree_item.h"
  39. #include "xfs_mru_cache.h"
  40. #include "xfs_inode_item.h"
  41. #include "xfs_icache.h"
  42. #include "xfs_trace.h"
  43. #include "xfs_icreate_item.h"
  44. #include "xfs_filestream.h"
  45. #include "xfs_quota.h"
  46. #include "xfs_sysfs.h"
  47. #include <linux/namei.h>
  48. #include <linux/init.h>
  49. #include <linux/slab.h>
  50. #include <linux/mount.h>
  51. #include <linux/mempool.h>
  52. #include <linux/writeback.h>
  53. #include <linux/kthread.h>
  54. #include <linux/freezer.h>
  55. #include <linux/parser.h>
  56. static const struct super_operations xfs_super_operations;
  57. static kmem_zone_t *xfs_ioend_zone;
  58. mempool_t *xfs_ioend_pool;
  59. static struct kset *xfs_kset; /* top-level xfs sysfs dir */
  60. #ifdef DEBUG
  61. static struct xfs_kobj xfs_dbg_kobj; /* global debug sysfs attrs */
  62. #endif
  63. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  64. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  65. #define MNTOPT_LOGDEV "logdev" /* log device */
  66. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  67. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  68. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  69. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  70. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  71. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  72. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  73. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  74. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  75. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  76. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  77. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  78. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  79. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  80. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  81. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  82. * unwritten extent conversion */
  83. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  84. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  85. #define MNTOPT_32BITINODE "inode32" /* inode allocation limited to
  86. * XFS_MAXINUMBER_32 */
  87. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  88. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  89. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  90. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  91. * in stat(). */
  92. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  93. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  94. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  95. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  96. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  97. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  98. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  99. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  100. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  101. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  102. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  103. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  104. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  105. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  106. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  107. #define MNTOPT_DELAYLOG "delaylog" /* Delayed logging enabled */
  108. #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed logging disabled */
  109. #define MNTOPT_DISCARD "discard" /* Discard unused blocks */
  110. #define MNTOPT_NODISCARD "nodiscard" /* Do not discard unused blocks */
  111. /*
  112. * Table driven mount option parser.
  113. *
  114. * Currently only used for remount, but it will be used for mount
  115. * in the future, too.
  116. */
  117. enum {
  118. Opt_barrier,
  119. Opt_nobarrier,
  120. Opt_inode64,
  121. Opt_inode32,
  122. Opt_err
  123. };
  124. static const match_table_t tokens = {
  125. {Opt_barrier, "barrier"},
  126. {Opt_nobarrier, "nobarrier"},
  127. {Opt_inode64, "inode64"},
  128. {Opt_inode32, "inode32"},
  129. {Opt_err, NULL}
  130. };
  131. STATIC unsigned long
  132. suffix_kstrtoint(char *s, unsigned int base, int *res)
  133. {
  134. int last, shift_left_factor = 0, _res;
  135. char *value = s;
  136. last = strlen(value) - 1;
  137. if (value[last] == 'K' || value[last] == 'k') {
  138. shift_left_factor = 10;
  139. value[last] = '\0';
  140. }
  141. if (value[last] == 'M' || value[last] == 'm') {
  142. shift_left_factor = 20;
  143. value[last] = '\0';
  144. }
  145. if (value[last] == 'G' || value[last] == 'g') {
  146. shift_left_factor = 30;
  147. value[last] = '\0';
  148. }
  149. if (kstrtoint(s, base, &_res))
  150. return -EINVAL;
  151. *res = _res << shift_left_factor;
  152. return 0;
  153. }
  154. /*
  155. * This function fills in xfs_mount_t fields based on mount args.
  156. * Note: the superblock has _not_ yet been read in.
  157. *
  158. * Note that this function leaks the various device name allocations on
  159. * failure. The caller takes care of them.
  160. */
  161. STATIC int
  162. xfs_parseargs(
  163. struct xfs_mount *mp,
  164. char *options)
  165. {
  166. struct super_block *sb = mp->m_super;
  167. char *this_char, *value;
  168. int dsunit = 0;
  169. int dswidth = 0;
  170. int iosize = 0;
  171. __uint8_t iosizelog = 0;
  172. /*
  173. * set up the mount name first so all the errors will refer to the
  174. * correct device.
  175. */
  176. mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
  177. if (!mp->m_fsname)
  178. return -ENOMEM;
  179. mp->m_fsname_len = strlen(mp->m_fsname) + 1;
  180. /*
  181. * Copy binary VFS mount flags we are interested in.
  182. */
  183. if (sb->s_flags & MS_RDONLY)
  184. mp->m_flags |= XFS_MOUNT_RDONLY;
  185. if (sb->s_flags & MS_DIRSYNC)
  186. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  187. if (sb->s_flags & MS_SYNCHRONOUS)
  188. mp->m_flags |= XFS_MOUNT_WSYNC;
  189. /*
  190. * Set some default flags that could be cleared by the mount option
  191. * parsing.
  192. */
  193. mp->m_flags |= XFS_MOUNT_BARRIER;
  194. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  195. /*
  196. * These can be overridden by the mount option parsing.
  197. */
  198. mp->m_logbufs = -1;
  199. mp->m_logbsize = -1;
  200. if (!options)
  201. goto done;
  202. while ((this_char = strsep(&options, ",")) != NULL) {
  203. if (!*this_char)
  204. continue;
  205. if ((value = strchr(this_char, '=')) != NULL)
  206. *value++ = 0;
  207. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  208. if (!value || !*value) {
  209. xfs_warn(mp, "%s option requires an argument",
  210. this_char);
  211. return -EINVAL;
  212. }
  213. if (kstrtoint(value, 10, &mp->m_logbufs))
  214. return -EINVAL;
  215. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  216. if (!value || !*value) {
  217. xfs_warn(mp, "%s option requires an argument",
  218. this_char);
  219. return -EINVAL;
  220. }
  221. if (suffix_kstrtoint(value, 10, &mp->m_logbsize))
  222. return -EINVAL;
  223. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  224. if (!value || !*value) {
  225. xfs_warn(mp, "%s option requires an argument",
  226. this_char);
  227. return -EINVAL;
  228. }
  229. mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  230. if (!mp->m_logname)
  231. return -ENOMEM;
  232. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  233. xfs_warn(mp, "%s option not allowed on this system",
  234. this_char);
  235. return -EINVAL;
  236. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  237. if (!value || !*value) {
  238. xfs_warn(mp, "%s option requires an argument",
  239. this_char);
  240. return -EINVAL;
  241. }
  242. mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  243. if (!mp->m_rtname)
  244. return -ENOMEM;
  245. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  246. if (!value || !*value) {
  247. xfs_warn(mp, "%s option requires an argument",
  248. this_char);
  249. return -EINVAL;
  250. }
  251. if (kstrtoint(value, 10, &iosize))
  252. return -EINVAL;
  253. iosizelog = ffs(iosize) - 1;
  254. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  255. if (!value || !*value) {
  256. xfs_warn(mp, "%s option requires an argument",
  257. this_char);
  258. return -EINVAL;
  259. }
  260. if (suffix_kstrtoint(value, 10, &iosize))
  261. return -EINVAL;
  262. iosizelog = ffs(iosize) - 1;
  263. } else if (!strcmp(this_char, MNTOPT_GRPID) ||
  264. !strcmp(this_char, MNTOPT_BSDGROUPS)) {
  265. mp->m_flags |= XFS_MOUNT_GRPID;
  266. } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
  267. !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
  268. mp->m_flags &= ~XFS_MOUNT_GRPID;
  269. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  270. mp->m_flags |= XFS_MOUNT_WSYNC;
  271. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  272. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  273. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  274. mp->m_flags |= XFS_MOUNT_NOALIGN;
  275. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  276. mp->m_flags |= XFS_MOUNT_SWALLOC;
  277. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  278. if (!value || !*value) {
  279. xfs_warn(mp, "%s option requires an argument",
  280. this_char);
  281. return -EINVAL;
  282. }
  283. if (kstrtoint(value, 10, &dsunit))
  284. return -EINVAL;
  285. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  286. if (!value || !*value) {
  287. xfs_warn(mp, "%s option requires an argument",
  288. this_char);
  289. return -EINVAL;
  290. }
  291. if (kstrtoint(value, 10, &dswidth))
  292. return -EINVAL;
  293. } else if (!strcmp(this_char, MNTOPT_32BITINODE)) {
  294. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  295. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  296. mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
  297. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  298. mp->m_flags |= XFS_MOUNT_NOUUID;
  299. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  300. mp->m_flags |= XFS_MOUNT_BARRIER;
  301. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  302. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  303. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  304. mp->m_flags |= XFS_MOUNT_IKEEP;
  305. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  306. mp->m_flags &= ~XFS_MOUNT_IKEEP;
  307. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  308. mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
  309. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  310. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  311. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  312. mp->m_flags |= XFS_MOUNT_ATTR2;
  313. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  314. mp->m_flags &= ~XFS_MOUNT_ATTR2;
  315. mp->m_flags |= XFS_MOUNT_NOATTR2;
  316. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  317. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  318. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  319. mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
  320. mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
  321. mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
  322. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  323. !strcmp(this_char, MNTOPT_UQUOTA) ||
  324. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  325. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
  326. XFS_UQUOTA_ENFD);
  327. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  328. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  329. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  330. mp->m_qflags &= ~XFS_UQUOTA_ENFD;
  331. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  332. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  333. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
  334. XFS_PQUOTA_ENFD);
  335. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  336. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  337. mp->m_qflags &= ~XFS_PQUOTA_ENFD;
  338. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  339. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  340. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
  341. XFS_GQUOTA_ENFD);
  342. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  343. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  344. mp->m_qflags &= ~XFS_GQUOTA_ENFD;
  345. } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
  346. xfs_warn(mp,
  347. "delaylog is the default now, option is deprecated.");
  348. } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
  349. xfs_warn(mp,
  350. "nodelaylog support has been removed, option is deprecated.");
  351. } else if (!strcmp(this_char, MNTOPT_DISCARD)) {
  352. mp->m_flags |= XFS_MOUNT_DISCARD;
  353. } else if (!strcmp(this_char, MNTOPT_NODISCARD)) {
  354. mp->m_flags &= ~XFS_MOUNT_DISCARD;
  355. } else if (!strcmp(this_char, "ihashsize")) {
  356. xfs_warn(mp,
  357. "ihashsize no longer used, option is deprecated.");
  358. } else if (!strcmp(this_char, "osyncisdsync")) {
  359. xfs_warn(mp,
  360. "osyncisdsync has no effect, option is deprecated.");
  361. } else if (!strcmp(this_char, "osyncisosync")) {
  362. xfs_warn(mp,
  363. "osyncisosync has no effect, option is deprecated.");
  364. } else if (!strcmp(this_char, "irixsgid")) {
  365. xfs_warn(mp,
  366. "irixsgid is now a sysctl(2) variable, option is deprecated.");
  367. } else {
  368. xfs_warn(mp, "unknown mount option [%s].", this_char);
  369. return -EINVAL;
  370. }
  371. }
  372. /*
  373. * no recovery flag requires a read-only mount
  374. */
  375. if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
  376. !(mp->m_flags & XFS_MOUNT_RDONLY)) {
  377. xfs_warn(mp, "no-recovery mounts must be read-only.");
  378. return -EINVAL;
  379. }
  380. if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
  381. xfs_warn(mp,
  382. "sunit and swidth options incompatible with the noalign option");
  383. return -EINVAL;
  384. }
  385. #ifndef CONFIG_XFS_QUOTA
  386. if (XFS_IS_QUOTA_RUNNING(mp)) {
  387. xfs_warn(mp, "quota support not available in this kernel.");
  388. return -EINVAL;
  389. }
  390. #endif
  391. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  392. xfs_warn(mp, "sunit and swidth must be specified together");
  393. return -EINVAL;
  394. }
  395. if (dsunit && (dswidth % dsunit != 0)) {
  396. xfs_warn(mp,
  397. "stripe width (%d) must be a multiple of the stripe unit (%d)",
  398. dswidth, dsunit);
  399. return -EINVAL;
  400. }
  401. done:
  402. if (dsunit && !(mp->m_flags & XFS_MOUNT_NOALIGN)) {
  403. /*
  404. * At this point the superblock has not been read
  405. * in, therefore we do not know the block size.
  406. * Before the mount call ends we will convert
  407. * these to FSBs.
  408. */
  409. mp->m_dalign = dsunit;
  410. mp->m_swidth = dswidth;
  411. }
  412. if (mp->m_logbufs != -1 &&
  413. mp->m_logbufs != 0 &&
  414. (mp->m_logbufs < XLOG_MIN_ICLOGS ||
  415. mp->m_logbufs > XLOG_MAX_ICLOGS)) {
  416. xfs_warn(mp, "invalid logbufs value: %d [not %d-%d]",
  417. mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  418. return -EINVAL;
  419. }
  420. if (mp->m_logbsize != -1 &&
  421. mp->m_logbsize != 0 &&
  422. (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
  423. mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
  424. !is_power_of_2(mp->m_logbsize))) {
  425. xfs_warn(mp,
  426. "invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  427. mp->m_logbsize);
  428. return -EINVAL;
  429. }
  430. if (iosizelog) {
  431. if (iosizelog > XFS_MAX_IO_LOG ||
  432. iosizelog < XFS_MIN_IO_LOG) {
  433. xfs_warn(mp, "invalid log iosize: %d [not %d-%d]",
  434. iosizelog, XFS_MIN_IO_LOG,
  435. XFS_MAX_IO_LOG);
  436. return -EINVAL;
  437. }
  438. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  439. mp->m_readio_log = iosizelog;
  440. mp->m_writeio_log = iosizelog;
  441. }
  442. return 0;
  443. }
  444. struct proc_xfs_info {
  445. int flag;
  446. char *str;
  447. };
  448. STATIC int
  449. xfs_showargs(
  450. struct xfs_mount *mp,
  451. struct seq_file *m)
  452. {
  453. static struct proc_xfs_info xfs_info_set[] = {
  454. /* the few simple ones we can get from the mount struct */
  455. { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
  456. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  457. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  458. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  459. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  460. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  461. { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
  462. { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
  463. { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
  464. { XFS_MOUNT_DISCARD, "," MNTOPT_DISCARD },
  465. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_32BITINODE },
  466. { 0, NULL }
  467. };
  468. static struct proc_xfs_info xfs_info_unset[] = {
  469. /* the few simple ones we can get from the mount struct */
  470. { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
  471. { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
  472. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
  473. { 0, NULL }
  474. };
  475. struct proc_xfs_info *xfs_infop;
  476. for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
  477. if (mp->m_flags & xfs_infop->flag)
  478. seq_puts(m, xfs_infop->str);
  479. }
  480. for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
  481. if (!(mp->m_flags & xfs_infop->flag))
  482. seq_puts(m, xfs_infop->str);
  483. }
  484. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  485. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  486. (int)(1 << mp->m_writeio_log) >> 10);
  487. if (mp->m_logbufs > 0)
  488. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  489. if (mp->m_logbsize > 0)
  490. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  491. if (mp->m_logname)
  492. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  493. if (mp->m_rtname)
  494. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  495. if (mp->m_dalign > 0)
  496. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  497. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  498. if (mp->m_swidth > 0)
  499. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  500. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  501. if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
  502. seq_puts(m, "," MNTOPT_USRQUOTA);
  503. else if (mp->m_qflags & XFS_UQUOTA_ACCT)
  504. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  505. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  506. if (mp->m_qflags & XFS_PQUOTA_ENFD)
  507. seq_puts(m, "," MNTOPT_PRJQUOTA);
  508. else
  509. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  510. }
  511. if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  512. if (mp->m_qflags & XFS_GQUOTA_ENFD)
  513. seq_puts(m, "," MNTOPT_GRPQUOTA);
  514. else
  515. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  516. }
  517. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  518. seq_puts(m, "," MNTOPT_NOQUOTA);
  519. return 0;
  520. }
  521. __uint64_t
  522. xfs_max_file_offset(
  523. unsigned int blockshift)
  524. {
  525. unsigned int pagefactor = 1;
  526. unsigned int bitshift = BITS_PER_LONG - 1;
  527. /* Figure out maximum filesize, on Linux this can depend on
  528. * the filesystem blocksize (on 32 bit platforms).
  529. * __block_write_begin does this in an [unsigned] long...
  530. * page->index << (PAGE_CACHE_SHIFT - bbits)
  531. * So, for page sized blocks (4K on 32 bit platforms),
  532. * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
  533. * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  534. * but for smaller blocksizes it is less (bbits = log2 bsize).
  535. * Note1: get_block_t takes a long (implicit cast from above)
  536. * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
  537. * can optionally convert the [unsigned] long from above into
  538. * an [unsigned] long long.
  539. */
  540. #if BITS_PER_LONG == 32
  541. # if defined(CONFIG_LBDAF)
  542. ASSERT(sizeof(sector_t) == 8);
  543. pagefactor = PAGE_CACHE_SIZE;
  544. bitshift = BITS_PER_LONG;
  545. # else
  546. pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
  547. # endif
  548. #endif
  549. return (((__uint64_t)pagefactor) << bitshift) - 1;
  550. }
  551. /*
  552. * xfs_set_inode32() and xfs_set_inode64() are passed an agcount
  553. * because in the growfs case, mp->m_sb.sb_agcount is not updated
  554. * yet to the potentially higher ag count.
  555. */
  556. xfs_agnumber_t
  557. xfs_set_inode32(struct xfs_mount *mp, xfs_agnumber_t agcount)
  558. {
  559. xfs_agnumber_t index = 0;
  560. xfs_agnumber_t maxagi = 0;
  561. xfs_sb_t *sbp = &mp->m_sb;
  562. xfs_agnumber_t max_metadata;
  563. xfs_agino_t agino;
  564. xfs_ino_t ino;
  565. xfs_perag_t *pag;
  566. /* Calculate how much should be reserved for inodes to meet
  567. * the max inode percentage.
  568. */
  569. if (mp->m_maxicount) {
  570. __uint64_t icount;
  571. icount = sbp->sb_dblocks * sbp->sb_imax_pct;
  572. do_div(icount, 100);
  573. icount += sbp->sb_agblocks - 1;
  574. do_div(icount, sbp->sb_agblocks);
  575. max_metadata = icount;
  576. } else {
  577. max_metadata = agcount;
  578. }
  579. agino = XFS_OFFBNO_TO_AGINO(mp, sbp->sb_agblocks - 1, 0);
  580. for (index = 0; index < 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, xfs_agnumber_t agcount)
  602. {
  603. xfs_agnumber_t index = 0;
  604. for (index = 0; index < 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);
  705. if (!mp->m_ddev_targp)
  706. goto out_close_rtdev;
  707. if (rtdev) {
  708. mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev);
  709. if (!mp->m_rtdev_targp)
  710. goto out_free_ddev_targ;
  711. }
  712. if (logdev && logdev != ddev) {
  713. mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev);
  714. if (!mp->m_logdev_targp)
  715. goto out_free_rtdev_targ;
  716. } else {
  717. mp->m_logdev_targp = mp->m_ddev_targp;
  718. }
  719. return 0;
  720. out_free_rtdev_targ:
  721. if (mp->m_rtdev_targp)
  722. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  723. out_free_ddev_targ:
  724. xfs_free_buftarg(mp, mp->m_ddev_targp);
  725. out_close_rtdev:
  726. xfs_blkdev_put(rtdev);
  727. out_close_logdev:
  728. if (logdev && logdev != ddev)
  729. xfs_blkdev_put(logdev);
  730. out:
  731. return error;
  732. }
  733. /*
  734. * Setup xfs_mount buffer target pointers based on superblock
  735. */
  736. STATIC int
  737. xfs_setup_devices(
  738. struct xfs_mount *mp)
  739. {
  740. int error;
  741. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
  742. if (error)
  743. return error;
  744. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  745. unsigned int log_sector_size = BBSIZE;
  746. if (xfs_sb_version_hassector(&mp->m_sb))
  747. log_sector_size = mp->m_sb.sb_logsectsize;
  748. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  749. log_sector_size);
  750. if (error)
  751. return error;
  752. }
  753. if (mp->m_rtdev_targp) {
  754. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  755. mp->m_sb.sb_sectsize);
  756. if (error)
  757. return error;
  758. }
  759. return 0;
  760. }
  761. STATIC int
  762. xfs_init_mount_workqueues(
  763. struct xfs_mount *mp)
  764. {
  765. mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
  766. WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_fsname);
  767. if (!mp->m_buf_workqueue)
  768. goto out;
  769. mp->m_data_workqueue = alloc_workqueue("xfs-data/%s",
  770. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  771. if (!mp->m_data_workqueue)
  772. goto out_destroy_buf;
  773. mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
  774. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  775. if (!mp->m_unwritten_workqueue)
  776. goto out_destroy_data_iodone_queue;
  777. mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
  778. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  779. if (!mp->m_cil_workqueue)
  780. goto out_destroy_unwritten;
  781. mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
  782. WQ_FREEZABLE, 0, mp->m_fsname);
  783. if (!mp->m_reclaim_workqueue)
  784. goto out_destroy_cil;
  785. mp->m_log_workqueue = alloc_workqueue("xfs-log/%s",
  786. WQ_FREEZABLE|WQ_HIGHPRI, 0, mp->m_fsname);
  787. if (!mp->m_log_workqueue)
  788. goto out_destroy_reclaim;
  789. mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
  790. WQ_FREEZABLE, 0, mp->m_fsname);
  791. if (!mp->m_eofblocks_workqueue)
  792. goto out_destroy_log;
  793. return 0;
  794. out_destroy_log:
  795. destroy_workqueue(mp->m_log_workqueue);
  796. out_destroy_reclaim:
  797. destroy_workqueue(mp->m_reclaim_workqueue);
  798. out_destroy_cil:
  799. destroy_workqueue(mp->m_cil_workqueue);
  800. out_destroy_unwritten:
  801. destroy_workqueue(mp->m_unwritten_workqueue);
  802. out_destroy_data_iodone_queue:
  803. destroy_workqueue(mp->m_data_workqueue);
  804. out_destroy_buf:
  805. destroy_workqueue(mp->m_buf_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. destroy_workqueue(mp->m_buf_workqueue);
  820. }
  821. /*
  822. * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
  823. * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
  824. * for IO to complete so that we effectively throttle multiple callers to the
  825. * rate at which IO is completing.
  826. */
  827. void
  828. xfs_flush_inodes(
  829. struct xfs_mount *mp)
  830. {
  831. struct super_block *sb = mp->m_super;
  832. if (down_read_trylock(&sb->s_umount)) {
  833. sync_inodes_sb(sb);
  834. up_read(&sb->s_umount);
  835. }
  836. }
  837. /* Catch misguided souls that try to use this interface on XFS */
  838. STATIC struct inode *
  839. xfs_fs_alloc_inode(
  840. struct super_block *sb)
  841. {
  842. BUG();
  843. return NULL;
  844. }
  845. /*
  846. * Now that the generic code is guaranteed not to be accessing
  847. * the linux inode, we can reclaim the inode.
  848. */
  849. STATIC void
  850. xfs_fs_destroy_inode(
  851. struct inode *inode)
  852. {
  853. struct xfs_inode *ip = XFS_I(inode);
  854. trace_xfs_destroy_inode(ip);
  855. XFS_STATS_INC(vn_reclaim);
  856. ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
  857. /*
  858. * We should never get here with one of the reclaim flags already set.
  859. */
  860. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
  861. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
  862. /*
  863. * We always use background reclaim here because even if the
  864. * inode is clean, it still may be under IO and hence we have
  865. * to take the flush lock. The background reclaim path handles
  866. * this more efficiently than we can here, so simply let background
  867. * reclaim tear down all inodes.
  868. */
  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 initialise
  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_pincount, 0);
  889. spin_lock_init(&ip->i_flags_lock);
  890. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  891. "xfsino", ip->i_ino);
  892. }
  893. STATIC void
  894. xfs_fs_evict_inode(
  895. struct inode *inode)
  896. {
  897. xfs_inode_t *ip = XFS_I(inode);
  898. ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
  899. trace_xfs_evict_inode(ip);
  900. truncate_inode_pages_final(&inode->i_data);
  901. clear_inode(inode);
  902. XFS_STATS_INC(vn_rele);
  903. XFS_STATS_INC(vn_remove);
  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. xfs_sb_t *sbp = &mp->m_sb;
  1066. substring_t args[MAX_OPT_ARGS];
  1067. char *p;
  1068. int error;
  1069. sync_filesystem(sb);
  1070. while ((p = strsep(&options, ",")) != NULL) {
  1071. int token;
  1072. if (!*p)
  1073. continue;
  1074. token = match_token(p, tokens, args);
  1075. switch (token) {
  1076. case Opt_barrier:
  1077. mp->m_flags |= XFS_MOUNT_BARRIER;
  1078. break;
  1079. case Opt_nobarrier:
  1080. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1081. break;
  1082. case Opt_inode64:
  1083. mp->m_maxagi = xfs_set_inode64(mp, sbp->sb_agcount);
  1084. break;
  1085. case Opt_inode32:
  1086. mp->m_maxagi = xfs_set_inode32(mp, sbp->sb_agcount);
  1087. break;
  1088. default:
  1089. /*
  1090. * Logically we would return an error here to prevent
  1091. * users from believing they might have changed
  1092. * mount options using remount which can't be changed.
  1093. *
  1094. * But unfortunately mount(8) adds all options from
  1095. * mtab and fstab to the mount arguments in some cases
  1096. * so we can't blindly reject options, but have to
  1097. * check for each specified option if it actually
  1098. * differs from the currently set option and only
  1099. * reject it if that's the case.
  1100. *
  1101. * Until that is implemented we return success for
  1102. * every remount request, and silently ignore all
  1103. * options that we can't actually change.
  1104. */
  1105. #if 0
  1106. xfs_info(mp,
  1107. "mount option \"%s\" not supported for remount", p);
  1108. return -EINVAL;
  1109. #else
  1110. break;
  1111. #endif
  1112. }
  1113. }
  1114. /* ro -> rw */
  1115. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1116. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1117. /*
  1118. * If this is the first remount to writeable state we
  1119. * might have some superblock changes to update.
  1120. */
  1121. if (mp->m_update_flags) {
  1122. error = xfs_mount_log_sb(mp, mp->m_update_flags);
  1123. if (error) {
  1124. xfs_warn(mp, "failed to write sb changes");
  1125. return error;
  1126. }
  1127. mp->m_update_flags = 0;
  1128. }
  1129. /*
  1130. * Fill out the reserve pool if it is empty. Use the stashed
  1131. * value if it is non-zero, otherwise go with the default.
  1132. */
  1133. xfs_restore_resvblks(mp);
  1134. xfs_log_work_queue(mp);
  1135. }
  1136. /* rw -> ro */
  1137. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1138. /*
  1139. * Before we sync the metadata, we need to free up the reserve
  1140. * block pool so that the used block count in the superblock on
  1141. * disk is correct at the end of the remount. Stash the current
  1142. * reserve pool size so that if we get remounted rw, we can
  1143. * return it to the same size.
  1144. */
  1145. xfs_save_resvblks(mp);
  1146. xfs_quiesce_attr(mp);
  1147. mp->m_flags |= XFS_MOUNT_RDONLY;
  1148. }
  1149. return 0;
  1150. }
  1151. /*
  1152. * Second stage of a freeze. The data is already frozen so we only
  1153. * need to take care of the metadata. Once that's done write a dummy
  1154. * record to dirty the log in case of a crash while frozen.
  1155. */
  1156. STATIC int
  1157. xfs_fs_freeze(
  1158. struct super_block *sb)
  1159. {
  1160. struct xfs_mount *mp = XFS_M(sb);
  1161. xfs_save_resvblks(mp);
  1162. xfs_quiesce_attr(mp);
  1163. return xfs_fs_log_dummy(mp);
  1164. }
  1165. STATIC int
  1166. xfs_fs_unfreeze(
  1167. struct super_block *sb)
  1168. {
  1169. struct xfs_mount *mp = XFS_M(sb);
  1170. xfs_restore_resvblks(mp);
  1171. xfs_log_work_queue(mp);
  1172. return 0;
  1173. }
  1174. STATIC int
  1175. xfs_fs_show_options(
  1176. struct seq_file *m,
  1177. struct dentry *root)
  1178. {
  1179. return xfs_showargs(XFS_M(root->d_sb), m);
  1180. }
  1181. /*
  1182. * This function fills in xfs_mount_t fields based on mount args.
  1183. * Note: the superblock _has_ now been read in.
  1184. */
  1185. STATIC int
  1186. xfs_finish_flags(
  1187. struct xfs_mount *mp)
  1188. {
  1189. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1190. /* Fail a mount where the logbuf is smaller than the log stripe */
  1191. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1192. if (mp->m_logbsize <= 0 &&
  1193. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  1194. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1195. } else if (mp->m_logbsize > 0 &&
  1196. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  1197. xfs_warn(mp,
  1198. "logbuf size must be greater than or equal to log stripe size");
  1199. return -EINVAL;
  1200. }
  1201. } else {
  1202. /* Fail a mount if the logbuf is larger than 32K */
  1203. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  1204. xfs_warn(mp,
  1205. "logbuf size for version 1 logs must be 16K or 32K");
  1206. return -EINVAL;
  1207. }
  1208. }
  1209. /*
  1210. * V5 filesystems always use attr2 format for attributes.
  1211. */
  1212. if (xfs_sb_version_hascrc(&mp->m_sb) &&
  1213. (mp->m_flags & XFS_MOUNT_NOATTR2)) {
  1214. xfs_warn(mp,
  1215. "Cannot mount a V5 filesystem as %s. %s is always enabled for V5 filesystems.",
  1216. MNTOPT_NOATTR2, MNTOPT_ATTR2);
  1217. return -EINVAL;
  1218. }
  1219. /*
  1220. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1221. * told by noattr2 to turn it off
  1222. */
  1223. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1224. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  1225. mp->m_flags |= XFS_MOUNT_ATTR2;
  1226. /*
  1227. * prohibit r/w mounts of read-only filesystems
  1228. */
  1229. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1230. xfs_warn(mp,
  1231. "cannot mount a read-only filesystem as read-write");
  1232. return -EROFS;
  1233. }
  1234. if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
  1235. (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
  1236. !xfs_sb_version_has_pquotino(&mp->m_sb)) {
  1237. xfs_warn(mp,
  1238. "Super block does not support project and group quota together");
  1239. return -EINVAL;
  1240. }
  1241. return 0;
  1242. }
  1243. STATIC int
  1244. xfs_fs_fill_super(
  1245. struct super_block *sb,
  1246. void *data,
  1247. int silent)
  1248. {
  1249. struct inode *root;
  1250. struct xfs_mount *mp = NULL;
  1251. int flags = 0, error = -ENOMEM;
  1252. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1253. if (!mp)
  1254. goto out;
  1255. spin_lock_init(&mp->m_sb_lock);
  1256. mutex_init(&mp->m_growlock);
  1257. atomic_set(&mp->m_active_trans, 0);
  1258. INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
  1259. INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
  1260. mp->m_kobj.kobject.kset = xfs_kset;
  1261. mp->m_super = sb;
  1262. sb->s_fs_info = mp;
  1263. error = xfs_parseargs(mp, (char *)data);
  1264. if (error)
  1265. goto out_free_fsname;
  1266. sb_min_blocksize(sb, BBSIZE);
  1267. sb->s_xattr = xfs_xattr_handlers;
  1268. sb->s_export_op = &xfs_export_operations;
  1269. #ifdef CONFIG_XFS_QUOTA
  1270. sb->s_qcop = &xfs_quotactl_operations;
  1271. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
  1272. #endif
  1273. sb->s_op = &xfs_super_operations;
  1274. if (silent)
  1275. flags |= XFS_MFSI_QUIET;
  1276. error = xfs_open_devices(mp);
  1277. if (error)
  1278. goto out_free_fsname;
  1279. error = xfs_init_mount_workqueues(mp);
  1280. if (error)
  1281. goto out_close_devices;
  1282. error = xfs_icsb_init_counters(mp);
  1283. if (error)
  1284. goto out_destroy_workqueues;
  1285. error = xfs_readsb(mp, flags);
  1286. if (error)
  1287. goto out_destroy_counters;
  1288. error = xfs_finish_flags(mp);
  1289. if (error)
  1290. goto out_free_sb;
  1291. error = xfs_setup_devices(mp);
  1292. if (error)
  1293. goto out_free_sb;
  1294. error = xfs_filestream_mount(mp);
  1295. if (error)
  1296. goto out_free_sb;
  1297. /*
  1298. * we must configure the block size in the superblock before we run the
  1299. * full mount process as the mount process can lookup and cache inodes.
  1300. */
  1301. sb->s_magic = XFS_SB_MAGIC;
  1302. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1303. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1304. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1305. sb->s_max_links = XFS_MAXLINK;
  1306. sb->s_time_gran = 1;
  1307. set_posix_acl_flag(sb);
  1308. /* version 5 superblocks support inode version counters. */
  1309. if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
  1310. sb->s_flags |= MS_I_VERSION;
  1311. error = xfs_mountfs(mp);
  1312. if (error)
  1313. goto out_filestream_unmount;
  1314. root = igrab(VFS_I(mp->m_rootip));
  1315. if (!root) {
  1316. error = -ENOENT;
  1317. goto out_unmount;
  1318. }
  1319. sb->s_root = d_make_root(root);
  1320. if (!sb->s_root) {
  1321. error = -ENOMEM;
  1322. goto out_unmount;
  1323. }
  1324. return 0;
  1325. out_filestream_unmount:
  1326. xfs_filestream_unmount(mp);
  1327. out_free_sb:
  1328. xfs_freesb(mp);
  1329. out_destroy_counters:
  1330. xfs_icsb_destroy_counters(mp);
  1331. out_destroy_workqueues:
  1332. xfs_destroy_mount_workqueues(mp);
  1333. out_close_devices:
  1334. xfs_close_devices(mp);
  1335. out_free_fsname:
  1336. xfs_free_fsname(mp);
  1337. kfree(mp);
  1338. out:
  1339. return error;
  1340. out_unmount:
  1341. xfs_filestream_unmount(mp);
  1342. xfs_unmountfs(mp);
  1343. goto out_free_sb;
  1344. }
  1345. STATIC struct dentry *
  1346. xfs_fs_mount(
  1347. struct file_system_type *fs_type,
  1348. int flags,
  1349. const char *dev_name,
  1350. void *data)
  1351. {
  1352. return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
  1353. }
  1354. static long
  1355. xfs_fs_nr_cached_objects(
  1356. struct super_block *sb,
  1357. int nid)
  1358. {
  1359. return xfs_reclaim_inodes_count(XFS_M(sb));
  1360. }
  1361. static long
  1362. xfs_fs_free_cached_objects(
  1363. struct super_block *sb,
  1364. long nr_to_scan,
  1365. int nid)
  1366. {
  1367. return xfs_reclaim_inodes_nr(XFS_M(sb), nr_to_scan);
  1368. }
  1369. static const struct super_operations xfs_super_operations = {
  1370. .alloc_inode = xfs_fs_alloc_inode,
  1371. .destroy_inode = xfs_fs_destroy_inode,
  1372. .evict_inode = xfs_fs_evict_inode,
  1373. .drop_inode = xfs_fs_drop_inode,
  1374. .put_super = xfs_fs_put_super,
  1375. .sync_fs = xfs_fs_sync_fs,
  1376. .freeze_fs = xfs_fs_freeze,
  1377. .unfreeze_fs = xfs_fs_unfreeze,
  1378. .statfs = xfs_fs_statfs,
  1379. .remount_fs = xfs_fs_remount,
  1380. .show_options = xfs_fs_show_options,
  1381. .nr_cached_objects = xfs_fs_nr_cached_objects,
  1382. .free_cached_objects = xfs_fs_free_cached_objects,
  1383. };
  1384. static struct file_system_type xfs_fs_type = {
  1385. .owner = THIS_MODULE,
  1386. .name = "xfs",
  1387. .mount = xfs_fs_mount,
  1388. .kill_sb = kill_block_super,
  1389. .fs_flags = FS_REQUIRES_DEV,
  1390. };
  1391. MODULE_ALIAS_FS("xfs");
  1392. STATIC int __init
  1393. xfs_init_zones(void)
  1394. {
  1395. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  1396. if (!xfs_ioend_zone)
  1397. goto out;
  1398. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  1399. xfs_ioend_zone);
  1400. if (!xfs_ioend_pool)
  1401. goto out_destroy_ioend_zone;
  1402. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1403. "xfs_log_ticket");
  1404. if (!xfs_log_ticket_zone)
  1405. goto out_destroy_ioend_pool;
  1406. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  1407. "xfs_bmap_free_item");
  1408. if (!xfs_bmap_free_item_zone)
  1409. goto out_destroy_log_ticket_zone;
  1410. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1411. "xfs_btree_cur");
  1412. if (!xfs_btree_cur_zone)
  1413. goto out_destroy_bmap_free_item_zone;
  1414. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1415. "xfs_da_state");
  1416. if (!xfs_da_state_zone)
  1417. goto out_destroy_btree_cur_zone;
  1418. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1419. if (!xfs_ifork_zone)
  1420. goto out_destroy_da_state_zone;
  1421. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1422. if (!xfs_trans_zone)
  1423. goto out_destroy_ifork_zone;
  1424. xfs_log_item_desc_zone =
  1425. kmem_zone_init(sizeof(struct xfs_log_item_desc),
  1426. "xfs_log_item_desc");
  1427. if (!xfs_log_item_desc_zone)
  1428. goto out_destroy_trans_zone;
  1429. /*
  1430. * The size of the zone allocated buf log item is the maximum
  1431. * size possible under XFS. This wastes a little bit of memory,
  1432. * but it is much faster.
  1433. */
  1434. xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
  1435. "xfs_buf_item");
  1436. if (!xfs_buf_item_zone)
  1437. goto out_destroy_log_item_desc_zone;
  1438. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1439. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1440. sizeof(xfs_extent_t))), "xfs_efd_item");
  1441. if (!xfs_efd_zone)
  1442. goto out_destroy_buf_item_zone;
  1443. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1444. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1445. sizeof(xfs_extent_t))), "xfs_efi_item");
  1446. if (!xfs_efi_zone)
  1447. goto out_destroy_efd_zone;
  1448. xfs_inode_zone =
  1449. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1450. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
  1451. xfs_fs_inode_init_once);
  1452. if (!xfs_inode_zone)
  1453. goto out_destroy_efi_zone;
  1454. xfs_ili_zone =
  1455. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1456. KM_ZONE_SPREAD, NULL);
  1457. if (!xfs_ili_zone)
  1458. goto out_destroy_inode_zone;
  1459. xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
  1460. "xfs_icr");
  1461. if (!xfs_icreate_zone)
  1462. goto out_destroy_ili_zone;
  1463. return 0;
  1464. out_destroy_ili_zone:
  1465. kmem_zone_destroy(xfs_ili_zone);
  1466. out_destroy_inode_zone:
  1467. kmem_zone_destroy(xfs_inode_zone);
  1468. out_destroy_efi_zone:
  1469. kmem_zone_destroy(xfs_efi_zone);
  1470. out_destroy_efd_zone:
  1471. kmem_zone_destroy(xfs_efd_zone);
  1472. out_destroy_buf_item_zone:
  1473. kmem_zone_destroy(xfs_buf_item_zone);
  1474. out_destroy_log_item_desc_zone:
  1475. kmem_zone_destroy(xfs_log_item_desc_zone);
  1476. out_destroy_trans_zone:
  1477. kmem_zone_destroy(xfs_trans_zone);
  1478. out_destroy_ifork_zone:
  1479. kmem_zone_destroy(xfs_ifork_zone);
  1480. out_destroy_da_state_zone:
  1481. kmem_zone_destroy(xfs_da_state_zone);
  1482. out_destroy_btree_cur_zone:
  1483. kmem_zone_destroy(xfs_btree_cur_zone);
  1484. out_destroy_bmap_free_item_zone:
  1485. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1486. out_destroy_log_ticket_zone:
  1487. kmem_zone_destroy(xfs_log_ticket_zone);
  1488. out_destroy_ioend_pool:
  1489. mempool_destroy(xfs_ioend_pool);
  1490. out_destroy_ioend_zone:
  1491. kmem_zone_destroy(xfs_ioend_zone);
  1492. out:
  1493. return -ENOMEM;
  1494. }
  1495. STATIC void
  1496. xfs_destroy_zones(void)
  1497. {
  1498. /*
  1499. * Make sure all delayed rcu free are flushed before we
  1500. * destroy caches.
  1501. */
  1502. rcu_barrier();
  1503. kmem_zone_destroy(xfs_icreate_zone);
  1504. kmem_zone_destroy(xfs_ili_zone);
  1505. kmem_zone_destroy(xfs_inode_zone);
  1506. kmem_zone_destroy(xfs_efi_zone);
  1507. kmem_zone_destroy(xfs_efd_zone);
  1508. kmem_zone_destroy(xfs_buf_item_zone);
  1509. kmem_zone_destroy(xfs_log_item_desc_zone);
  1510. kmem_zone_destroy(xfs_trans_zone);
  1511. kmem_zone_destroy(xfs_ifork_zone);
  1512. kmem_zone_destroy(xfs_da_state_zone);
  1513. kmem_zone_destroy(xfs_btree_cur_zone);
  1514. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1515. kmem_zone_destroy(xfs_log_ticket_zone);
  1516. mempool_destroy(xfs_ioend_pool);
  1517. kmem_zone_destroy(xfs_ioend_zone);
  1518. }
  1519. STATIC int __init
  1520. xfs_init_workqueues(void)
  1521. {
  1522. /*
  1523. * The allocation workqueue can be used in memory reclaim situations
  1524. * (writepage path), and parallelism is only limited by the number of
  1525. * AGs in all the filesystems mounted. Hence use the default large
  1526. * max_active value for this workqueue.
  1527. */
  1528. xfs_alloc_wq = alloc_workqueue("xfsalloc",
  1529. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
  1530. if (!xfs_alloc_wq)
  1531. return -ENOMEM;
  1532. return 0;
  1533. }
  1534. STATIC void
  1535. xfs_destroy_workqueues(void)
  1536. {
  1537. destroy_workqueue(xfs_alloc_wq);
  1538. }
  1539. STATIC int __init
  1540. init_xfs_fs(void)
  1541. {
  1542. int error;
  1543. printk(KERN_INFO XFS_VERSION_STRING " with "
  1544. XFS_BUILD_OPTIONS " enabled\n");
  1545. xfs_dir_startup();
  1546. error = xfs_init_zones();
  1547. if (error)
  1548. goto out;
  1549. error = xfs_init_workqueues();
  1550. if (error)
  1551. goto out_destroy_zones;
  1552. error = xfs_mru_cache_init();
  1553. if (error)
  1554. goto out_destroy_wq;
  1555. error = xfs_buf_init();
  1556. if (error)
  1557. goto out_mru_cache_uninit;
  1558. error = xfs_init_procfs();
  1559. if (error)
  1560. goto out_buf_terminate;
  1561. error = xfs_sysctl_register();
  1562. if (error)
  1563. goto out_cleanup_procfs;
  1564. xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
  1565. if (!xfs_kset) {
  1566. error = -ENOMEM;
  1567. goto out_sysctl_unregister;;
  1568. }
  1569. #ifdef DEBUG
  1570. xfs_dbg_kobj.kobject.kset = xfs_kset;
  1571. error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
  1572. if (error)
  1573. goto out_kset_unregister;
  1574. #endif
  1575. error = xfs_qm_init();
  1576. if (error)
  1577. goto out_remove_kobj;
  1578. error = register_filesystem(&xfs_fs_type);
  1579. if (error)
  1580. goto out_qm_exit;
  1581. return 0;
  1582. out_qm_exit:
  1583. xfs_qm_exit();
  1584. out_remove_kobj:
  1585. #ifdef DEBUG
  1586. xfs_sysfs_del(&xfs_dbg_kobj);
  1587. out_kset_unregister:
  1588. #endif
  1589. kset_unregister(xfs_kset);
  1590. out_sysctl_unregister:
  1591. xfs_sysctl_unregister();
  1592. out_cleanup_procfs:
  1593. xfs_cleanup_procfs();
  1594. out_buf_terminate:
  1595. xfs_buf_terminate();
  1596. out_mru_cache_uninit:
  1597. xfs_mru_cache_uninit();
  1598. out_destroy_wq:
  1599. xfs_destroy_workqueues();
  1600. out_destroy_zones:
  1601. xfs_destroy_zones();
  1602. out:
  1603. return error;
  1604. }
  1605. STATIC void __exit
  1606. exit_xfs_fs(void)
  1607. {
  1608. xfs_qm_exit();
  1609. unregister_filesystem(&xfs_fs_type);
  1610. #ifdef DEBUG
  1611. xfs_sysfs_del(&xfs_dbg_kobj);
  1612. #endif
  1613. kset_unregister(xfs_kset);
  1614. xfs_sysctl_unregister();
  1615. xfs_cleanup_procfs();
  1616. xfs_buf_terminate();
  1617. xfs_mru_cache_uninit();
  1618. xfs_destroy_workqueues();
  1619. xfs_destroy_zones();
  1620. }
  1621. module_init(init_xfs_fs);
  1622. module_exit(exit_xfs_fs);
  1623. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1624. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1625. MODULE_LICENSE("GPL");