xfs_super.c 53 KB

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