xfs_super.c 51 KB

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