xfs_super.c 56 KB

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