xfs_super.c 49 KB

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