xfs_super.c 50 KB

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