xfs_super.c 53 KB

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