xfs_super.c 55 KB

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