xfs_super.c 50 KB

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