xfs_super.c 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115
  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. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  654. struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
  655. xfs_free_buftarg(mp, mp->m_logdev_targp);
  656. xfs_blkdev_put(logdev);
  657. }
  658. if (mp->m_rtdev_targp) {
  659. struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
  660. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  661. xfs_blkdev_put(rtdev);
  662. }
  663. xfs_free_buftarg(mp, mp->m_ddev_targp);
  664. }
  665. /*
  666. * The file system configurations are:
  667. * (1) device (partition) with data and internal log
  668. * (2) logical volume with data and log subvolumes.
  669. * (3) logical volume with data, log, and realtime subvolumes.
  670. *
  671. * We only have to handle opening the log and realtime volumes here if
  672. * they are present. The data subvolume has already been opened by
  673. * get_sb_bdev() and is stored in sb->s_bdev.
  674. */
  675. STATIC int
  676. xfs_open_devices(
  677. struct xfs_mount *mp)
  678. {
  679. struct block_device *ddev = mp->m_super->s_bdev;
  680. struct block_device *logdev = NULL, *rtdev = NULL;
  681. int error;
  682. /*
  683. * Open real time and log devices - order is important.
  684. */
  685. if (mp->m_logname) {
  686. error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
  687. if (error)
  688. goto out;
  689. }
  690. if (mp->m_rtname) {
  691. error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
  692. if (error)
  693. goto out_close_logdev;
  694. if (rtdev == ddev || rtdev == logdev) {
  695. xfs_warn(mp,
  696. "Cannot mount filesystem with identical rtdev and ddev/logdev.");
  697. error = -EINVAL;
  698. goto out_close_rtdev;
  699. }
  700. }
  701. /*
  702. * Setup xfs_mount buffer target pointers
  703. */
  704. error = -ENOMEM;
  705. mp->m_ddev_targp = xfs_alloc_buftarg(mp, ddev);
  706. if (!mp->m_ddev_targp)
  707. goto out_close_rtdev;
  708. if (rtdev) {
  709. mp->m_rtdev_targp = xfs_alloc_buftarg(mp, rtdev);
  710. if (!mp->m_rtdev_targp)
  711. goto out_free_ddev_targ;
  712. }
  713. if (logdev && logdev != ddev) {
  714. mp->m_logdev_targp = xfs_alloc_buftarg(mp, logdev);
  715. if (!mp->m_logdev_targp)
  716. goto out_free_rtdev_targ;
  717. } else {
  718. mp->m_logdev_targp = mp->m_ddev_targp;
  719. }
  720. return 0;
  721. out_free_rtdev_targ:
  722. if (mp->m_rtdev_targp)
  723. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  724. out_free_ddev_targ:
  725. xfs_free_buftarg(mp, mp->m_ddev_targp);
  726. out_close_rtdev:
  727. xfs_blkdev_put(rtdev);
  728. out_close_logdev:
  729. if (logdev && logdev != ddev)
  730. xfs_blkdev_put(logdev);
  731. out:
  732. return error;
  733. }
  734. /*
  735. * Setup xfs_mount buffer target pointers based on superblock
  736. */
  737. STATIC int
  738. xfs_setup_devices(
  739. struct xfs_mount *mp)
  740. {
  741. int error;
  742. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_sectsize);
  743. if (error)
  744. return error;
  745. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  746. unsigned int log_sector_size = BBSIZE;
  747. if (xfs_sb_version_hassector(&mp->m_sb))
  748. log_sector_size = mp->m_sb.sb_logsectsize;
  749. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  750. log_sector_size);
  751. if (error)
  752. return error;
  753. }
  754. if (mp->m_rtdev_targp) {
  755. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  756. mp->m_sb.sb_sectsize);
  757. if (error)
  758. return error;
  759. }
  760. return 0;
  761. }
  762. STATIC int
  763. xfs_init_mount_workqueues(
  764. struct xfs_mount *mp)
  765. {
  766. mp->m_buf_workqueue = alloc_workqueue("xfs-buf/%s",
  767. WQ_MEM_RECLAIM|WQ_FREEZABLE, 1, mp->m_fsname);
  768. if (!mp->m_buf_workqueue)
  769. goto out;
  770. mp->m_data_workqueue = alloc_workqueue("xfs-data/%s",
  771. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  772. if (!mp->m_data_workqueue)
  773. goto out_destroy_buf;
  774. mp->m_unwritten_workqueue = alloc_workqueue("xfs-conv/%s",
  775. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  776. if (!mp->m_unwritten_workqueue)
  777. goto out_destroy_data_iodone_queue;
  778. mp->m_cil_workqueue = alloc_workqueue("xfs-cil/%s",
  779. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  780. if (!mp->m_cil_workqueue)
  781. goto out_destroy_unwritten;
  782. mp->m_reclaim_workqueue = alloc_workqueue("xfs-reclaim/%s",
  783. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  784. if (!mp->m_reclaim_workqueue)
  785. goto out_destroy_cil;
  786. mp->m_log_workqueue = alloc_workqueue("xfs-log/%s",
  787. WQ_MEM_RECLAIM|WQ_FREEZABLE|WQ_HIGHPRI, 0,
  788. mp->m_fsname);
  789. if (!mp->m_log_workqueue)
  790. goto out_destroy_reclaim;
  791. mp->m_eofblocks_workqueue = alloc_workqueue("xfs-eofblocks/%s",
  792. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0, mp->m_fsname);
  793. if (!mp->m_eofblocks_workqueue)
  794. goto out_destroy_log;
  795. mp->m_sync_workqueue = alloc_workqueue("xfs-sync/%s", WQ_FREEZABLE, 0,
  796. mp->m_fsname);
  797. if (!mp->m_sync_workqueue)
  798. goto out_destroy_eofb;
  799. return 0;
  800. out_destroy_eofb:
  801. destroy_workqueue(mp->m_eofblocks_workqueue);
  802. out_destroy_log:
  803. destroy_workqueue(mp->m_log_workqueue);
  804. out_destroy_reclaim:
  805. destroy_workqueue(mp->m_reclaim_workqueue);
  806. out_destroy_cil:
  807. destroy_workqueue(mp->m_cil_workqueue);
  808. out_destroy_unwritten:
  809. destroy_workqueue(mp->m_unwritten_workqueue);
  810. out_destroy_data_iodone_queue:
  811. destroy_workqueue(mp->m_data_workqueue);
  812. out_destroy_buf:
  813. destroy_workqueue(mp->m_buf_workqueue);
  814. out:
  815. return -ENOMEM;
  816. }
  817. STATIC void
  818. xfs_destroy_mount_workqueues(
  819. struct xfs_mount *mp)
  820. {
  821. destroy_workqueue(mp->m_sync_workqueue);
  822. destroy_workqueue(mp->m_eofblocks_workqueue);
  823. destroy_workqueue(mp->m_log_workqueue);
  824. destroy_workqueue(mp->m_reclaim_workqueue);
  825. destroy_workqueue(mp->m_cil_workqueue);
  826. destroy_workqueue(mp->m_data_workqueue);
  827. destroy_workqueue(mp->m_unwritten_workqueue);
  828. destroy_workqueue(mp->m_buf_workqueue);
  829. }
  830. /*
  831. * Flush all dirty data to disk. Must not be called while holding an XFS_ILOCK
  832. * or a page lock. We use sync_inodes_sb() here to ensure we block while waiting
  833. * for IO to complete so that we effectively throttle multiple callers to the
  834. * rate at which IO is completing.
  835. */
  836. void
  837. xfs_flush_inodes(
  838. struct xfs_mount *mp)
  839. {
  840. struct super_block *sb = mp->m_super;
  841. if (down_read_trylock(&sb->s_umount)) {
  842. sync_inodes_sb(sb);
  843. up_read(&sb->s_umount);
  844. }
  845. }
  846. /* Catch misguided souls that try to use this interface on XFS */
  847. STATIC struct inode *
  848. xfs_fs_alloc_inode(
  849. struct super_block *sb)
  850. {
  851. BUG();
  852. return NULL;
  853. }
  854. /*
  855. * Now that the generic code is guaranteed not to be accessing
  856. * the linux inode, we can inactivate and reclaim the inode.
  857. */
  858. STATIC void
  859. xfs_fs_destroy_inode(
  860. struct inode *inode)
  861. {
  862. struct xfs_inode *ip = XFS_I(inode);
  863. int error;
  864. trace_xfs_destroy_inode(ip);
  865. ASSERT(!rwsem_is_locked(&inode->i_rwsem));
  866. XFS_STATS_INC(ip->i_mount, vn_rele);
  867. XFS_STATS_INC(ip->i_mount, vn_remove);
  868. if (xfs_is_reflink_inode(ip)) {
  869. error = xfs_reflink_cancel_cow_range(ip, 0, NULLFILEOFF, true);
  870. if (error && !XFS_FORCED_SHUTDOWN(ip->i_mount))
  871. xfs_warn(ip->i_mount,
  872. "Error %d while evicting CoW blocks for inode %llu.",
  873. error, ip->i_ino);
  874. }
  875. xfs_inactive(ip);
  876. ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
  877. XFS_STATS_INC(ip->i_mount, vn_reclaim);
  878. /*
  879. * We should never get here with one of the reclaim flags already set.
  880. */
  881. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
  882. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
  883. /*
  884. * We always use background reclaim here because even if the
  885. * inode is clean, it still may be under IO and hence we have
  886. * to take the flush lock. The background reclaim path handles
  887. * this more efficiently than we can here, so simply let background
  888. * reclaim tear down all inodes.
  889. */
  890. xfs_inode_set_reclaim_tag(ip);
  891. }
  892. /*
  893. * Slab object creation initialisation for the XFS inode.
  894. * This covers only the idempotent fields in the XFS inode;
  895. * all other fields need to be initialised on allocation
  896. * from the slab. This avoids the need to repeatedly initialise
  897. * fields in the xfs inode that left in the initialise state
  898. * when freeing the inode.
  899. */
  900. STATIC void
  901. xfs_fs_inode_init_once(
  902. void *inode)
  903. {
  904. struct xfs_inode *ip = inode;
  905. memset(ip, 0, sizeof(struct xfs_inode));
  906. /* vfs inode */
  907. inode_init_once(VFS_I(ip));
  908. /* xfs inode */
  909. atomic_set(&ip->i_pincount, 0);
  910. spin_lock_init(&ip->i_flags_lock);
  911. mrlock_init(&ip->i_mmaplock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  912. "xfsino", ip->i_ino);
  913. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  914. "xfsino", ip->i_ino);
  915. }
  916. /*
  917. * We do an unlocked check for XFS_IDONTCACHE here because we are already
  918. * serialised against cache hits here via the inode->i_lock and igrab() in
  919. * xfs_iget_cache_hit(). Hence a lookup that might clear this flag will not be
  920. * racing with us, and it avoids needing to grab a spinlock here for every inode
  921. * we drop the final reference on.
  922. */
  923. STATIC int
  924. xfs_fs_drop_inode(
  925. struct inode *inode)
  926. {
  927. struct xfs_inode *ip = XFS_I(inode);
  928. /*
  929. * If this unlinked inode is in the middle of recovery, don't
  930. * drop the inode just yet; log recovery will take care of
  931. * that. See the comment for this inode flag.
  932. */
  933. if (ip->i_flags & XFS_IRECOVERY) {
  934. ASSERT(ip->i_mount->m_log->l_flags & XLOG_RECOVERY_NEEDED);
  935. return 0;
  936. }
  937. return generic_drop_inode(inode) || (ip->i_flags & XFS_IDONTCACHE);
  938. }
  939. STATIC void
  940. xfs_free_fsname(
  941. struct xfs_mount *mp)
  942. {
  943. kfree(mp->m_fsname);
  944. kfree(mp->m_rtname);
  945. kfree(mp->m_logname);
  946. }
  947. STATIC int
  948. xfs_fs_sync_fs(
  949. struct super_block *sb,
  950. int wait)
  951. {
  952. struct xfs_mount *mp = XFS_M(sb);
  953. /*
  954. * Doing anything during the async pass would be counterproductive.
  955. */
  956. if (!wait)
  957. return 0;
  958. xfs_log_force(mp, XFS_LOG_SYNC);
  959. if (laptop_mode) {
  960. /*
  961. * The disk must be active because we're syncing.
  962. * We schedule log work now (now that the disk is
  963. * active) instead of later (when it might not be).
  964. */
  965. flush_delayed_work(&mp->m_log->l_work);
  966. }
  967. return 0;
  968. }
  969. STATIC int
  970. xfs_fs_statfs(
  971. struct dentry *dentry,
  972. struct kstatfs *statp)
  973. {
  974. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  975. xfs_sb_t *sbp = &mp->m_sb;
  976. struct xfs_inode *ip = XFS_I(d_inode(dentry));
  977. uint64_t fakeinos, id;
  978. uint64_t icount;
  979. uint64_t ifree;
  980. uint64_t fdblocks;
  981. xfs_extlen_t lsize;
  982. int64_t ffree;
  983. statp->f_type = XFS_SB_MAGIC;
  984. statp->f_namelen = MAXNAMELEN - 1;
  985. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  986. statp->f_fsid.val[0] = (u32)id;
  987. statp->f_fsid.val[1] = (u32)(id >> 32);
  988. icount = percpu_counter_sum(&mp->m_icount);
  989. ifree = percpu_counter_sum(&mp->m_ifree);
  990. fdblocks = percpu_counter_sum(&mp->m_fdblocks);
  991. spin_lock(&mp->m_sb_lock);
  992. statp->f_bsize = sbp->sb_blocksize;
  993. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  994. statp->f_blocks = sbp->sb_dblocks - lsize;
  995. spin_unlock(&mp->m_sb_lock);
  996. statp->f_bfree = fdblocks - mp->m_alloc_set_aside;
  997. statp->f_bavail = statp->f_bfree;
  998. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  999. statp->f_files = MIN(icount + fakeinos, (uint64_t)XFS_MAXINUMBER);
  1000. if (mp->m_maxicount)
  1001. statp->f_files = min_t(typeof(statp->f_files),
  1002. statp->f_files,
  1003. mp->m_maxicount);
  1004. /* If sb_icount overshot maxicount, report actual allocation */
  1005. statp->f_files = max_t(typeof(statp->f_files),
  1006. statp->f_files,
  1007. sbp->sb_icount);
  1008. /* make sure statp->f_ffree does not underflow */
  1009. ffree = statp->f_files - (icount - ifree);
  1010. statp->f_ffree = max_t(int64_t, ffree, 0);
  1011. if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
  1012. ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))) ==
  1013. (XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD))
  1014. xfs_qm_statvfs(ip, statp);
  1015. return 0;
  1016. }
  1017. STATIC void
  1018. xfs_save_resvblks(struct xfs_mount *mp)
  1019. {
  1020. uint64_t resblks = 0;
  1021. mp->m_resblks_save = mp->m_resblks;
  1022. xfs_reserve_blocks(mp, &resblks, NULL);
  1023. }
  1024. STATIC void
  1025. xfs_restore_resvblks(struct xfs_mount *mp)
  1026. {
  1027. uint64_t resblks;
  1028. if (mp->m_resblks_save) {
  1029. resblks = mp->m_resblks_save;
  1030. mp->m_resblks_save = 0;
  1031. } else
  1032. resblks = xfs_default_resblks(mp);
  1033. xfs_reserve_blocks(mp, &resblks, NULL);
  1034. }
  1035. /*
  1036. * Trigger writeback of all the dirty metadata in the file system.
  1037. *
  1038. * This ensures that the metadata is written to their location on disk rather
  1039. * than just existing in transactions in the log. This means after a quiesce
  1040. * there is no log replay required to write the inodes to disk - this is the
  1041. * primary difference between a sync and a quiesce.
  1042. *
  1043. * Note: xfs_log_quiesce() stops background log work - the callers must ensure
  1044. * it is started again when appropriate.
  1045. */
  1046. void
  1047. xfs_quiesce_attr(
  1048. struct xfs_mount *mp)
  1049. {
  1050. int error = 0;
  1051. /* wait for all modifications to complete */
  1052. while (atomic_read(&mp->m_active_trans) > 0)
  1053. delay(100);
  1054. /* force the log to unpin objects from the now complete transactions */
  1055. xfs_log_force(mp, XFS_LOG_SYNC);
  1056. /* reclaim inodes to do any IO before the freeze completes */
  1057. xfs_reclaim_inodes(mp, 0);
  1058. xfs_reclaim_inodes(mp, SYNC_WAIT);
  1059. /* Push the superblock and write an unmount record */
  1060. error = xfs_log_sbcount(mp);
  1061. if (error)
  1062. xfs_warn(mp, "xfs_attr_quiesce: failed to log sb changes. "
  1063. "Frozen image may not be consistent.");
  1064. /*
  1065. * Just warn here till VFS can correctly support
  1066. * read-only remount without racing.
  1067. */
  1068. WARN_ON(atomic_read(&mp->m_active_trans) != 0);
  1069. xfs_log_quiesce(mp);
  1070. }
  1071. STATIC int
  1072. xfs_test_remount_options(
  1073. struct super_block *sb,
  1074. struct xfs_mount *mp,
  1075. char *options)
  1076. {
  1077. int error = 0;
  1078. struct xfs_mount *tmp_mp;
  1079. tmp_mp = kmem_zalloc(sizeof(*tmp_mp), KM_MAYFAIL);
  1080. if (!tmp_mp)
  1081. return -ENOMEM;
  1082. tmp_mp->m_super = sb;
  1083. error = xfs_parseargs(tmp_mp, options);
  1084. xfs_free_fsname(tmp_mp);
  1085. kfree(tmp_mp);
  1086. return error;
  1087. }
  1088. STATIC int
  1089. xfs_fs_remount(
  1090. struct super_block *sb,
  1091. int *flags,
  1092. char *options)
  1093. {
  1094. struct xfs_mount *mp = XFS_M(sb);
  1095. xfs_sb_t *sbp = &mp->m_sb;
  1096. substring_t args[MAX_OPT_ARGS];
  1097. char *p;
  1098. int error;
  1099. /* First, check for complete junk; i.e. invalid options */
  1100. error = xfs_test_remount_options(sb, mp, options);
  1101. if (error)
  1102. return error;
  1103. sync_filesystem(sb);
  1104. while ((p = strsep(&options, ",")) != NULL) {
  1105. int token;
  1106. if (!*p)
  1107. continue;
  1108. token = match_token(p, tokens, args);
  1109. switch (token) {
  1110. case Opt_barrier:
  1111. xfs_warn(mp, "%s option is deprecated, ignoring.", p);
  1112. mp->m_flags |= XFS_MOUNT_BARRIER;
  1113. break;
  1114. case Opt_nobarrier:
  1115. xfs_warn(mp, "%s option is deprecated, ignoring.", p);
  1116. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1117. break;
  1118. case Opt_inode64:
  1119. mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
  1120. mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
  1121. break;
  1122. case Opt_inode32:
  1123. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  1124. mp->m_maxagi = xfs_set_inode_alloc(mp, sbp->sb_agcount);
  1125. break;
  1126. default:
  1127. /*
  1128. * Logically we would return an error here to prevent
  1129. * users from believing they might have changed
  1130. * mount options using remount which can't be changed.
  1131. *
  1132. * But unfortunately mount(8) adds all options from
  1133. * mtab and fstab to the mount arguments in some cases
  1134. * so we can't blindly reject options, but have to
  1135. * check for each specified option if it actually
  1136. * differs from the currently set option and only
  1137. * reject it if that's the case.
  1138. *
  1139. * Until that is implemented we return success for
  1140. * every remount request, and silently ignore all
  1141. * options that we can't actually change.
  1142. */
  1143. #if 0
  1144. xfs_info(mp,
  1145. "mount option \"%s\" not supported for remount", p);
  1146. return -EINVAL;
  1147. #else
  1148. break;
  1149. #endif
  1150. }
  1151. }
  1152. /* ro -> rw */
  1153. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1154. if (mp->m_flags & XFS_MOUNT_NORECOVERY) {
  1155. xfs_warn(mp,
  1156. "ro->rw transition prohibited on norecovery mount");
  1157. return -EINVAL;
  1158. }
  1159. if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
  1160. xfs_sb_has_ro_compat_feature(sbp,
  1161. XFS_SB_FEAT_RO_COMPAT_UNKNOWN)) {
  1162. xfs_warn(mp,
  1163. "ro->rw transition prohibited on unknown (0x%x) ro-compat filesystem",
  1164. (sbp->sb_features_ro_compat &
  1165. XFS_SB_FEAT_RO_COMPAT_UNKNOWN));
  1166. return -EINVAL;
  1167. }
  1168. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1169. /*
  1170. * If this is the first remount to writeable state we
  1171. * might have some superblock changes to update.
  1172. */
  1173. if (mp->m_update_sb) {
  1174. error = xfs_sync_sb(mp, false);
  1175. if (error) {
  1176. xfs_warn(mp, "failed to write sb changes");
  1177. return error;
  1178. }
  1179. mp->m_update_sb = false;
  1180. }
  1181. /*
  1182. * Fill out the reserve pool if it is empty. Use the stashed
  1183. * value if it is non-zero, otherwise go with the default.
  1184. */
  1185. xfs_restore_resvblks(mp);
  1186. xfs_log_work_queue(mp);
  1187. xfs_queue_eofblocks(mp);
  1188. /* Recover any CoW blocks that never got remapped. */
  1189. error = xfs_reflink_recover_cow(mp);
  1190. if (error) {
  1191. xfs_err(mp,
  1192. "Error %d recovering leftover CoW allocations.", error);
  1193. xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
  1194. return error;
  1195. }
  1196. /* Create the per-AG metadata reservation pool .*/
  1197. error = xfs_fs_reserve_ag_blocks(mp);
  1198. if (error && error != -ENOSPC)
  1199. return error;
  1200. }
  1201. /* rw -> ro */
  1202. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1203. /* Free the per-AG metadata reservation pool. */
  1204. error = xfs_fs_unreserve_ag_blocks(mp);
  1205. if (error) {
  1206. xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
  1207. return error;
  1208. }
  1209. /*
  1210. * Before we sync the metadata, we need to free up the reserve
  1211. * block pool so that the used block count in the superblock on
  1212. * disk is correct at the end of the remount. Stash the current
  1213. * reserve pool size so that if we get remounted rw, we can
  1214. * return it to the same size.
  1215. */
  1216. xfs_save_resvblks(mp);
  1217. /*
  1218. * Cancel background eofb scanning so it cannot race with the
  1219. * final log force+buftarg wait and deadlock the remount.
  1220. */
  1221. cancel_delayed_work_sync(&mp->m_eofblocks_work);
  1222. xfs_quiesce_attr(mp);
  1223. mp->m_flags |= XFS_MOUNT_RDONLY;
  1224. }
  1225. return 0;
  1226. }
  1227. /*
  1228. * Second stage of a freeze. The data is already frozen so we only
  1229. * need to take care of the metadata. Once that's done sync the superblock
  1230. * to the log to dirty it in case of a crash while frozen. This ensures that we
  1231. * will recover the unlinked inode lists on the next mount.
  1232. */
  1233. STATIC int
  1234. xfs_fs_freeze(
  1235. struct super_block *sb)
  1236. {
  1237. struct xfs_mount *mp = XFS_M(sb);
  1238. xfs_save_resvblks(mp);
  1239. xfs_quiesce_attr(mp);
  1240. return xfs_sync_sb(mp, true);
  1241. }
  1242. STATIC int
  1243. xfs_fs_unfreeze(
  1244. struct super_block *sb)
  1245. {
  1246. struct xfs_mount *mp = XFS_M(sb);
  1247. xfs_restore_resvblks(mp);
  1248. xfs_log_work_queue(mp);
  1249. return 0;
  1250. }
  1251. STATIC int
  1252. xfs_fs_show_options(
  1253. struct seq_file *m,
  1254. struct dentry *root)
  1255. {
  1256. return xfs_showargs(XFS_M(root->d_sb), m);
  1257. }
  1258. /*
  1259. * This function fills in xfs_mount_t fields based on mount args.
  1260. * Note: the superblock _has_ now been read in.
  1261. */
  1262. STATIC int
  1263. xfs_finish_flags(
  1264. struct xfs_mount *mp)
  1265. {
  1266. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1267. /* Fail a mount where the logbuf is smaller than the log stripe */
  1268. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1269. if (mp->m_logbsize <= 0 &&
  1270. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  1271. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1272. } else if (mp->m_logbsize > 0 &&
  1273. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  1274. xfs_warn(mp,
  1275. "logbuf size must be greater than or equal to log stripe size");
  1276. return -EINVAL;
  1277. }
  1278. } else {
  1279. /* Fail a mount if the logbuf is larger than 32K */
  1280. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  1281. xfs_warn(mp,
  1282. "logbuf size for version 1 logs must be 16K or 32K");
  1283. return -EINVAL;
  1284. }
  1285. }
  1286. /*
  1287. * V5 filesystems always use attr2 format for attributes.
  1288. */
  1289. if (xfs_sb_version_hascrc(&mp->m_sb) &&
  1290. (mp->m_flags & XFS_MOUNT_NOATTR2)) {
  1291. xfs_warn(mp, "Cannot mount a V5 filesystem as noattr2. "
  1292. "attr2 is always enabled for V5 filesystems.");
  1293. return -EINVAL;
  1294. }
  1295. /*
  1296. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1297. * told by noattr2 to turn it off
  1298. */
  1299. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1300. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  1301. mp->m_flags |= XFS_MOUNT_ATTR2;
  1302. /*
  1303. * prohibit r/w mounts of read-only filesystems
  1304. */
  1305. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1306. xfs_warn(mp,
  1307. "cannot mount a read-only filesystem as read-write");
  1308. return -EROFS;
  1309. }
  1310. if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
  1311. (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE)) &&
  1312. !xfs_sb_version_has_pquotino(&mp->m_sb)) {
  1313. xfs_warn(mp,
  1314. "Super block does not support project and group quota together");
  1315. return -EINVAL;
  1316. }
  1317. return 0;
  1318. }
  1319. static int
  1320. xfs_init_percpu_counters(
  1321. struct xfs_mount *mp)
  1322. {
  1323. int error;
  1324. error = percpu_counter_init(&mp->m_icount, 0, GFP_KERNEL);
  1325. if (error)
  1326. return -ENOMEM;
  1327. error = percpu_counter_init(&mp->m_ifree, 0, GFP_KERNEL);
  1328. if (error)
  1329. goto free_icount;
  1330. error = percpu_counter_init(&mp->m_fdblocks, 0, GFP_KERNEL);
  1331. if (error)
  1332. goto free_ifree;
  1333. return 0;
  1334. free_ifree:
  1335. percpu_counter_destroy(&mp->m_ifree);
  1336. free_icount:
  1337. percpu_counter_destroy(&mp->m_icount);
  1338. return -ENOMEM;
  1339. }
  1340. void
  1341. xfs_reinit_percpu_counters(
  1342. struct xfs_mount *mp)
  1343. {
  1344. percpu_counter_set(&mp->m_icount, mp->m_sb.sb_icount);
  1345. percpu_counter_set(&mp->m_ifree, mp->m_sb.sb_ifree);
  1346. percpu_counter_set(&mp->m_fdblocks, mp->m_sb.sb_fdblocks);
  1347. }
  1348. static void
  1349. xfs_destroy_percpu_counters(
  1350. struct xfs_mount *mp)
  1351. {
  1352. percpu_counter_destroy(&mp->m_icount);
  1353. percpu_counter_destroy(&mp->m_ifree);
  1354. percpu_counter_destroy(&mp->m_fdblocks);
  1355. }
  1356. STATIC int
  1357. xfs_fs_fill_super(
  1358. struct super_block *sb,
  1359. void *data,
  1360. int silent)
  1361. {
  1362. struct inode *root;
  1363. struct xfs_mount *mp = NULL;
  1364. int flags = 0, error = -ENOMEM;
  1365. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1366. if (!mp)
  1367. goto out;
  1368. spin_lock_init(&mp->m_sb_lock);
  1369. mutex_init(&mp->m_growlock);
  1370. atomic_set(&mp->m_active_trans, 0);
  1371. INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker);
  1372. INIT_DELAYED_WORK(&mp->m_eofblocks_work, xfs_eofblocks_worker);
  1373. INIT_DELAYED_WORK(&mp->m_cowblocks_work, xfs_cowblocks_worker);
  1374. mp->m_kobj.kobject.kset = xfs_kset;
  1375. mp->m_super = sb;
  1376. sb->s_fs_info = mp;
  1377. error = xfs_parseargs(mp, (char *)data);
  1378. if (error)
  1379. goto out_free_fsname;
  1380. sb_min_blocksize(sb, BBSIZE);
  1381. sb->s_xattr = xfs_xattr_handlers;
  1382. sb->s_export_op = &xfs_export_operations;
  1383. #ifdef CONFIG_XFS_QUOTA
  1384. sb->s_qcop = &xfs_quotactl_operations;
  1385. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
  1386. #endif
  1387. sb->s_op = &xfs_super_operations;
  1388. if (silent)
  1389. flags |= XFS_MFSI_QUIET;
  1390. error = xfs_open_devices(mp);
  1391. if (error)
  1392. goto out_free_fsname;
  1393. error = xfs_init_mount_workqueues(mp);
  1394. if (error)
  1395. goto out_close_devices;
  1396. error = xfs_init_percpu_counters(mp);
  1397. if (error)
  1398. goto out_destroy_workqueues;
  1399. /* Allocate stats memory before we do operations that might use it */
  1400. mp->m_stats.xs_stats = alloc_percpu(struct xfsstats);
  1401. if (!mp->m_stats.xs_stats) {
  1402. error = -ENOMEM;
  1403. goto out_destroy_counters;
  1404. }
  1405. error = xfs_readsb(mp, flags);
  1406. if (error)
  1407. goto out_free_stats;
  1408. error = xfs_finish_flags(mp);
  1409. if (error)
  1410. goto out_free_sb;
  1411. error = xfs_setup_devices(mp);
  1412. if (error)
  1413. goto out_free_sb;
  1414. error = xfs_filestream_mount(mp);
  1415. if (error)
  1416. goto out_free_sb;
  1417. /*
  1418. * we must configure the block size in the superblock before we run the
  1419. * full mount process as the mount process can lookup and cache inodes.
  1420. */
  1421. sb->s_magic = XFS_SB_MAGIC;
  1422. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1423. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1424. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1425. sb->s_max_links = XFS_MAXLINK;
  1426. sb->s_time_gran = 1;
  1427. set_posix_acl_flag(sb);
  1428. /* version 5 superblocks support inode version counters. */
  1429. if (XFS_SB_VERSION_NUM(&mp->m_sb) == XFS_SB_VERSION_5)
  1430. sb->s_flags |= MS_I_VERSION;
  1431. if (mp->m_flags & XFS_MOUNT_DAX) {
  1432. xfs_warn(mp,
  1433. "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
  1434. error = bdev_dax_supported(sb, sb->s_blocksize);
  1435. if (error) {
  1436. xfs_alert(mp,
  1437. "DAX unsupported by block device. Turning off DAX.");
  1438. mp->m_flags &= ~XFS_MOUNT_DAX;
  1439. }
  1440. if (xfs_sb_version_hasreflink(&mp->m_sb))
  1441. xfs_alert(mp,
  1442. "DAX and reflink have not been tested together!");
  1443. }
  1444. if (xfs_sb_version_hasrmapbt(&mp->m_sb)) {
  1445. if (mp->m_sb.sb_rblocks) {
  1446. xfs_alert(mp,
  1447. "EXPERIMENTAL reverse mapping btree not compatible with realtime device!");
  1448. error = -EINVAL;
  1449. goto out_filestream_unmount;
  1450. }
  1451. xfs_alert(mp,
  1452. "EXPERIMENTAL reverse mapping btree feature enabled. Use at your own risk!");
  1453. }
  1454. if (xfs_sb_version_hasreflink(&mp->m_sb))
  1455. xfs_alert(mp,
  1456. "EXPERIMENTAL reflink feature enabled. Use at your own risk!");
  1457. error = xfs_mountfs(mp);
  1458. if (error)
  1459. goto out_filestream_unmount;
  1460. root = igrab(VFS_I(mp->m_rootip));
  1461. if (!root) {
  1462. error = -ENOENT;
  1463. goto out_unmount;
  1464. }
  1465. sb->s_root = d_make_root(root);
  1466. if (!sb->s_root) {
  1467. error = -ENOMEM;
  1468. goto out_unmount;
  1469. }
  1470. return 0;
  1471. out_filestream_unmount:
  1472. xfs_filestream_unmount(mp);
  1473. out_free_sb:
  1474. xfs_freesb(mp);
  1475. out_free_stats:
  1476. free_percpu(mp->m_stats.xs_stats);
  1477. out_destroy_counters:
  1478. xfs_destroy_percpu_counters(mp);
  1479. out_destroy_workqueues:
  1480. xfs_destroy_mount_workqueues(mp);
  1481. out_close_devices:
  1482. xfs_close_devices(mp);
  1483. out_free_fsname:
  1484. xfs_free_fsname(mp);
  1485. kfree(mp);
  1486. out:
  1487. return error;
  1488. out_unmount:
  1489. xfs_filestream_unmount(mp);
  1490. xfs_unmountfs(mp);
  1491. goto out_free_sb;
  1492. }
  1493. STATIC void
  1494. xfs_fs_put_super(
  1495. struct super_block *sb)
  1496. {
  1497. struct xfs_mount *mp = XFS_M(sb);
  1498. xfs_notice(mp, "Unmounting Filesystem");
  1499. xfs_filestream_unmount(mp);
  1500. xfs_unmountfs(mp);
  1501. xfs_freesb(mp);
  1502. free_percpu(mp->m_stats.xs_stats);
  1503. xfs_destroy_percpu_counters(mp);
  1504. xfs_destroy_mount_workqueues(mp);
  1505. xfs_close_devices(mp);
  1506. xfs_free_fsname(mp);
  1507. kfree(mp);
  1508. }
  1509. STATIC struct dentry *
  1510. xfs_fs_mount(
  1511. struct file_system_type *fs_type,
  1512. int flags,
  1513. const char *dev_name,
  1514. void *data)
  1515. {
  1516. return mount_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super);
  1517. }
  1518. static long
  1519. xfs_fs_nr_cached_objects(
  1520. struct super_block *sb,
  1521. struct shrink_control *sc)
  1522. {
  1523. return xfs_reclaim_inodes_count(XFS_M(sb));
  1524. }
  1525. static long
  1526. xfs_fs_free_cached_objects(
  1527. struct super_block *sb,
  1528. struct shrink_control *sc)
  1529. {
  1530. return xfs_reclaim_inodes_nr(XFS_M(sb), sc->nr_to_scan);
  1531. }
  1532. static const struct super_operations xfs_super_operations = {
  1533. .alloc_inode = xfs_fs_alloc_inode,
  1534. .destroy_inode = xfs_fs_destroy_inode,
  1535. .drop_inode = xfs_fs_drop_inode,
  1536. .put_super = xfs_fs_put_super,
  1537. .sync_fs = xfs_fs_sync_fs,
  1538. .freeze_fs = xfs_fs_freeze,
  1539. .unfreeze_fs = xfs_fs_unfreeze,
  1540. .statfs = xfs_fs_statfs,
  1541. .remount_fs = xfs_fs_remount,
  1542. .show_options = xfs_fs_show_options,
  1543. .nr_cached_objects = xfs_fs_nr_cached_objects,
  1544. .free_cached_objects = xfs_fs_free_cached_objects,
  1545. };
  1546. static struct file_system_type xfs_fs_type = {
  1547. .owner = THIS_MODULE,
  1548. .name = "xfs",
  1549. .mount = xfs_fs_mount,
  1550. .kill_sb = kill_block_super,
  1551. .fs_flags = FS_REQUIRES_DEV,
  1552. };
  1553. MODULE_ALIAS_FS("xfs");
  1554. STATIC int __init
  1555. xfs_init_zones(void)
  1556. {
  1557. xfs_ioend_bioset = bioset_create(4 * MAX_BUF_PER_PAGE,
  1558. offsetof(struct xfs_ioend, io_inline_bio),
  1559. BIOSET_NEED_BVECS);
  1560. if (!xfs_ioend_bioset)
  1561. goto out;
  1562. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1563. "xfs_log_ticket");
  1564. if (!xfs_log_ticket_zone)
  1565. goto out_free_ioend_bioset;
  1566. xfs_bmap_free_item_zone = kmem_zone_init(
  1567. sizeof(struct xfs_extent_free_item),
  1568. "xfs_bmap_free_item");
  1569. if (!xfs_bmap_free_item_zone)
  1570. goto out_destroy_log_ticket_zone;
  1571. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1572. "xfs_btree_cur");
  1573. if (!xfs_btree_cur_zone)
  1574. goto out_destroy_bmap_free_item_zone;
  1575. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1576. "xfs_da_state");
  1577. if (!xfs_da_state_zone)
  1578. goto out_destroy_btree_cur_zone;
  1579. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1580. if (!xfs_ifork_zone)
  1581. goto out_destroy_da_state_zone;
  1582. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1583. if (!xfs_trans_zone)
  1584. goto out_destroy_ifork_zone;
  1585. xfs_log_item_desc_zone =
  1586. kmem_zone_init(sizeof(struct xfs_log_item_desc),
  1587. "xfs_log_item_desc");
  1588. if (!xfs_log_item_desc_zone)
  1589. goto out_destroy_trans_zone;
  1590. /*
  1591. * The size of the zone allocated buf log item is the maximum
  1592. * size possible under XFS. This wastes a little bit of memory,
  1593. * but it is much faster.
  1594. */
  1595. xfs_buf_item_zone = kmem_zone_init(sizeof(struct xfs_buf_log_item),
  1596. "xfs_buf_item");
  1597. if (!xfs_buf_item_zone)
  1598. goto out_destroy_log_item_desc_zone;
  1599. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1600. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1601. sizeof(xfs_extent_t))), "xfs_efd_item");
  1602. if (!xfs_efd_zone)
  1603. goto out_destroy_buf_item_zone;
  1604. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1605. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1606. sizeof(xfs_extent_t))), "xfs_efi_item");
  1607. if (!xfs_efi_zone)
  1608. goto out_destroy_efd_zone;
  1609. xfs_inode_zone =
  1610. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1611. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD |
  1612. KM_ZONE_ACCOUNT, xfs_fs_inode_init_once);
  1613. if (!xfs_inode_zone)
  1614. goto out_destroy_efi_zone;
  1615. xfs_ili_zone =
  1616. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1617. KM_ZONE_SPREAD, NULL);
  1618. if (!xfs_ili_zone)
  1619. goto out_destroy_inode_zone;
  1620. xfs_icreate_zone = kmem_zone_init(sizeof(struct xfs_icreate_item),
  1621. "xfs_icr");
  1622. if (!xfs_icreate_zone)
  1623. goto out_destroy_ili_zone;
  1624. xfs_rud_zone = kmem_zone_init(sizeof(struct xfs_rud_log_item),
  1625. "xfs_rud_item");
  1626. if (!xfs_rud_zone)
  1627. goto out_destroy_icreate_zone;
  1628. xfs_rui_zone = kmem_zone_init(
  1629. xfs_rui_log_item_sizeof(XFS_RUI_MAX_FAST_EXTENTS),
  1630. "xfs_rui_item");
  1631. if (!xfs_rui_zone)
  1632. goto out_destroy_rud_zone;
  1633. xfs_cud_zone = kmem_zone_init(sizeof(struct xfs_cud_log_item),
  1634. "xfs_cud_item");
  1635. if (!xfs_cud_zone)
  1636. goto out_destroy_rui_zone;
  1637. xfs_cui_zone = kmem_zone_init(
  1638. xfs_cui_log_item_sizeof(XFS_CUI_MAX_FAST_EXTENTS),
  1639. "xfs_cui_item");
  1640. if (!xfs_cui_zone)
  1641. goto out_destroy_cud_zone;
  1642. xfs_bud_zone = kmem_zone_init(sizeof(struct xfs_bud_log_item),
  1643. "xfs_bud_item");
  1644. if (!xfs_bud_zone)
  1645. goto out_destroy_cui_zone;
  1646. xfs_bui_zone = kmem_zone_init(
  1647. xfs_bui_log_item_sizeof(XFS_BUI_MAX_FAST_EXTENTS),
  1648. "xfs_bui_item");
  1649. if (!xfs_bui_zone)
  1650. goto out_destroy_bud_zone;
  1651. return 0;
  1652. out_destroy_bud_zone:
  1653. kmem_zone_destroy(xfs_bud_zone);
  1654. out_destroy_cui_zone:
  1655. kmem_zone_destroy(xfs_cui_zone);
  1656. out_destroy_cud_zone:
  1657. kmem_zone_destroy(xfs_cud_zone);
  1658. out_destroy_rui_zone:
  1659. kmem_zone_destroy(xfs_rui_zone);
  1660. out_destroy_rud_zone:
  1661. kmem_zone_destroy(xfs_rud_zone);
  1662. out_destroy_icreate_zone:
  1663. kmem_zone_destroy(xfs_icreate_zone);
  1664. out_destroy_ili_zone:
  1665. kmem_zone_destroy(xfs_ili_zone);
  1666. out_destroy_inode_zone:
  1667. kmem_zone_destroy(xfs_inode_zone);
  1668. out_destroy_efi_zone:
  1669. kmem_zone_destroy(xfs_efi_zone);
  1670. out_destroy_efd_zone:
  1671. kmem_zone_destroy(xfs_efd_zone);
  1672. out_destroy_buf_item_zone:
  1673. kmem_zone_destroy(xfs_buf_item_zone);
  1674. out_destroy_log_item_desc_zone:
  1675. kmem_zone_destroy(xfs_log_item_desc_zone);
  1676. out_destroy_trans_zone:
  1677. kmem_zone_destroy(xfs_trans_zone);
  1678. out_destroy_ifork_zone:
  1679. kmem_zone_destroy(xfs_ifork_zone);
  1680. out_destroy_da_state_zone:
  1681. kmem_zone_destroy(xfs_da_state_zone);
  1682. out_destroy_btree_cur_zone:
  1683. kmem_zone_destroy(xfs_btree_cur_zone);
  1684. out_destroy_bmap_free_item_zone:
  1685. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1686. out_destroy_log_ticket_zone:
  1687. kmem_zone_destroy(xfs_log_ticket_zone);
  1688. out_free_ioend_bioset:
  1689. bioset_free(xfs_ioend_bioset);
  1690. out:
  1691. return -ENOMEM;
  1692. }
  1693. STATIC void
  1694. xfs_destroy_zones(void)
  1695. {
  1696. /*
  1697. * Make sure all delayed rcu free are flushed before we
  1698. * destroy caches.
  1699. */
  1700. rcu_barrier();
  1701. kmem_zone_destroy(xfs_bui_zone);
  1702. kmem_zone_destroy(xfs_bud_zone);
  1703. kmem_zone_destroy(xfs_cui_zone);
  1704. kmem_zone_destroy(xfs_cud_zone);
  1705. kmem_zone_destroy(xfs_rui_zone);
  1706. kmem_zone_destroy(xfs_rud_zone);
  1707. kmem_zone_destroy(xfs_icreate_zone);
  1708. kmem_zone_destroy(xfs_ili_zone);
  1709. kmem_zone_destroy(xfs_inode_zone);
  1710. kmem_zone_destroy(xfs_efi_zone);
  1711. kmem_zone_destroy(xfs_efd_zone);
  1712. kmem_zone_destroy(xfs_buf_item_zone);
  1713. kmem_zone_destroy(xfs_log_item_desc_zone);
  1714. kmem_zone_destroy(xfs_trans_zone);
  1715. kmem_zone_destroy(xfs_ifork_zone);
  1716. kmem_zone_destroy(xfs_da_state_zone);
  1717. kmem_zone_destroy(xfs_btree_cur_zone);
  1718. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1719. kmem_zone_destroy(xfs_log_ticket_zone);
  1720. bioset_free(xfs_ioend_bioset);
  1721. }
  1722. STATIC int __init
  1723. xfs_init_workqueues(void)
  1724. {
  1725. /*
  1726. * The allocation workqueue can be used in memory reclaim situations
  1727. * (writepage path), and parallelism is only limited by the number of
  1728. * AGs in all the filesystems mounted. Hence use the default large
  1729. * max_active value for this workqueue.
  1730. */
  1731. xfs_alloc_wq = alloc_workqueue("xfsalloc",
  1732. WQ_MEM_RECLAIM|WQ_FREEZABLE, 0);
  1733. if (!xfs_alloc_wq)
  1734. return -ENOMEM;
  1735. xfs_discard_wq = alloc_workqueue("xfsdiscard", WQ_UNBOUND, 0);
  1736. if (!xfs_discard_wq)
  1737. goto out_free_alloc_wq;
  1738. return 0;
  1739. out_free_alloc_wq:
  1740. destroy_workqueue(xfs_alloc_wq);
  1741. return -ENOMEM;
  1742. }
  1743. STATIC void
  1744. xfs_destroy_workqueues(void)
  1745. {
  1746. destroy_workqueue(xfs_discard_wq);
  1747. destroy_workqueue(xfs_alloc_wq);
  1748. }
  1749. STATIC int __init
  1750. init_xfs_fs(void)
  1751. {
  1752. int error;
  1753. xfs_check_ondisk_structs();
  1754. printk(KERN_INFO XFS_VERSION_STRING " with "
  1755. XFS_BUILD_OPTIONS " enabled\n");
  1756. xfs_extent_free_init_defer_op();
  1757. xfs_rmap_update_init_defer_op();
  1758. xfs_refcount_update_init_defer_op();
  1759. xfs_bmap_update_init_defer_op();
  1760. xfs_dir_startup();
  1761. error = xfs_init_zones();
  1762. if (error)
  1763. goto out;
  1764. error = xfs_init_workqueues();
  1765. if (error)
  1766. goto out_destroy_zones;
  1767. error = xfs_mru_cache_init();
  1768. if (error)
  1769. goto out_destroy_wq;
  1770. error = xfs_buf_init();
  1771. if (error)
  1772. goto out_mru_cache_uninit;
  1773. error = xfs_init_procfs();
  1774. if (error)
  1775. goto out_buf_terminate;
  1776. error = xfs_sysctl_register();
  1777. if (error)
  1778. goto out_cleanup_procfs;
  1779. xfs_kset = kset_create_and_add("xfs", NULL, fs_kobj);
  1780. if (!xfs_kset) {
  1781. error = -ENOMEM;
  1782. goto out_sysctl_unregister;
  1783. }
  1784. xfsstats.xs_kobj.kobject.kset = xfs_kset;
  1785. xfsstats.xs_stats = alloc_percpu(struct xfsstats);
  1786. if (!xfsstats.xs_stats) {
  1787. error = -ENOMEM;
  1788. goto out_kset_unregister;
  1789. }
  1790. error = xfs_sysfs_init(&xfsstats.xs_kobj, &xfs_stats_ktype, NULL,
  1791. "stats");
  1792. if (error)
  1793. goto out_free_stats;
  1794. #ifdef DEBUG
  1795. xfs_dbg_kobj.kobject.kset = xfs_kset;
  1796. error = xfs_sysfs_init(&xfs_dbg_kobj, &xfs_dbg_ktype, NULL, "debug");
  1797. if (error)
  1798. goto out_remove_stats_kobj;
  1799. #endif
  1800. error = xfs_qm_init();
  1801. if (error)
  1802. goto out_remove_dbg_kobj;
  1803. error = register_filesystem(&xfs_fs_type);
  1804. if (error)
  1805. goto out_qm_exit;
  1806. return 0;
  1807. out_qm_exit:
  1808. xfs_qm_exit();
  1809. out_remove_dbg_kobj:
  1810. #ifdef DEBUG
  1811. xfs_sysfs_del(&xfs_dbg_kobj);
  1812. out_remove_stats_kobj:
  1813. #endif
  1814. xfs_sysfs_del(&xfsstats.xs_kobj);
  1815. out_free_stats:
  1816. free_percpu(xfsstats.xs_stats);
  1817. out_kset_unregister:
  1818. kset_unregister(xfs_kset);
  1819. out_sysctl_unregister:
  1820. xfs_sysctl_unregister();
  1821. out_cleanup_procfs:
  1822. xfs_cleanup_procfs();
  1823. out_buf_terminate:
  1824. xfs_buf_terminate();
  1825. out_mru_cache_uninit:
  1826. xfs_mru_cache_uninit();
  1827. out_destroy_wq:
  1828. xfs_destroy_workqueues();
  1829. out_destroy_zones:
  1830. xfs_destroy_zones();
  1831. out:
  1832. return error;
  1833. }
  1834. STATIC void __exit
  1835. exit_xfs_fs(void)
  1836. {
  1837. xfs_qm_exit();
  1838. unregister_filesystem(&xfs_fs_type);
  1839. #ifdef DEBUG
  1840. xfs_sysfs_del(&xfs_dbg_kobj);
  1841. #endif
  1842. xfs_sysfs_del(&xfsstats.xs_kobj);
  1843. free_percpu(xfsstats.xs_stats);
  1844. kset_unregister(xfs_kset);
  1845. xfs_sysctl_unregister();
  1846. xfs_cleanup_procfs();
  1847. xfs_buf_terminate();
  1848. xfs_mru_cache_uninit();
  1849. xfs_destroy_workqueues();
  1850. xfs_destroy_zones();
  1851. xfs_uuid_table_free();
  1852. }
  1853. module_init(init_xfs_fs);
  1854. module_exit(exit_xfs_fs);
  1855. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1856. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1857. MODULE_LICENSE("GPL");