xfs_super.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  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_bit.h"
  20. #include "xfs_log.h"
  21. #include "xfs_inum.h"
  22. #include "xfs_trans.h"
  23. #include "xfs_sb.h"
  24. #include "xfs_ag.h"
  25. #include "xfs_dir2.h"
  26. #include "xfs_alloc.h"
  27. #include "xfs_dmapi.h"
  28. #include "xfs_quota.h"
  29. #include "xfs_mount.h"
  30. #include "xfs_bmap_btree.h"
  31. #include "xfs_alloc_btree.h"
  32. #include "xfs_ialloc_btree.h"
  33. #include "xfs_dir2_sf.h"
  34. #include "xfs_attr_sf.h"
  35. #include "xfs_dinode.h"
  36. #include "xfs_inode.h"
  37. #include "xfs_btree.h"
  38. #include "xfs_btree_trace.h"
  39. #include "xfs_ialloc.h"
  40. #include "xfs_bmap.h"
  41. #include "xfs_rtalloc.h"
  42. #include "xfs_error.h"
  43. #include "xfs_itable.h"
  44. #include "xfs_fsops.h"
  45. #include "xfs_rw.h"
  46. #include "xfs_attr.h"
  47. #include "xfs_buf_item.h"
  48. #include "xfs_utils.h"
  49. #include "xfs_vnodeops.h"
  50. #include "xfs_version.h"
  51. #include "xfs_log_priv.h"
  52. #include "xfs_trans_priv.h"
  53. #include "xfs_filestream.h"
  54. #include "xfs_da_btree.h"
  55. #include "xfs_extfree_item.h"
  56. #include "xfs_mru_cache.h"
  57. #include "xfs_inode_item.h"
  58. #include "xfs_sync.h"
  59. #include "xfs_trace.h"
  60. #include <linux/namei.h>
  61. #include <linux/init.h>
  62. #include <linux/slab.h>
  63. #include <linux/mount.h>
  64. #include <linux/mempool.h>
  65. #include <linux/writeback.h>
  66. #include <linux/kthread.h>
  67. #include <linux/freezer.h>
  68. #include <linux/parser.h>
  69. static const struct super_operations xfs_super_operations;
  70. static kmem_zone_t *xfs_ioend_zone;
  71. mempool_t *xfs_ioend_pool;
  72. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  73. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  74. #define MNTOPT_LOGDEV "logdev" /* log device */
  75. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  76. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  77. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  78. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  79. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  80. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  81. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  82. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  83. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  84. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  85. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  86. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  87. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  88. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  89. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  90. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  91. * unwritten extent conversion */
  92. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  93. #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
  94. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  95. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  96. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  97. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  98. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  99. * in stat(). */
  100. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  101. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  102. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  103. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  104. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  105. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  106. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  107. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  108. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  109. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  110. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  111. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  112. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  113. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  114. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  115. #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
  116. #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
  117. #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
  118. #define MNTOPT_DELAYLOG "delaylog" /* Delayed loging enabled */
  119. #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
  120. /*
  121. * Table driven mount option parser.
  122. *
  123. * Currently only used for remount, but it will be used for mount
  124. * in the future, too.
  125. */
  126. enum {
  127. Opt_barrier, Opt_nobarrier, Opt_err
  128. };
  129. static const match_table_t tokens = {
  130. {Opt_barrier, "barrier"},
  131. {Opt_nobarrier, "nobarrier"},
  132. {Opt_err, NULL}
  133. };
  134. STATIC unsigned long
  135. suffix_strtoul(char *s, char **endp, unsigned int base)
  136. {
  137. int last, shift_left_factor = 0;
  138. char *value = s;
  139. last = strlen(value) - 1;
  140. if (value[last] == 'K' || value[last] == 'k') {
  141. shift_left_factor = 10;
  142. value[last] = '\0';
  143. }
  144. if (value[last] == 'M' || value[last] == 'm') {
  145. shift_left_factor = 20;
  146. value[last] = '\0';
  147. }
  148. if (value[last] == 'G' || value[last] == 'g') {
  149. shift_left_factor = 30;
  150. value[last] = '\0';
  151. }
  152. return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
  153. }
  154. /*
  155. * This function fills in xfs_mount_t fields based on mount args.
  156. * Note: the superblock has _not_ yet been read in.
  157. *
  158. * Note that this function leaks the various device name allocations on
  159. * failure. The caller takes care of them.
  160. */
  161. STATIC int
  162. xfs_parseargs(
  163. struct xfs_mount *mp,
  164. char *options,
  165. char **mtpt)
  166. {
  167. struct super_block *sb = mp->m_super;
  168. char *this_char, *value, *eov;
  169. int dsunit = 0;
  170. int dswidth = 0;
  171. int iosize = 0;
  172. int dmapi_implies_ikeep = 1;
  173. __uint8_t iosizelog = 0;
  174. /*
  175. * Copy binary VFS mount flags we are interested in.
  176. */
  177. if (sb->s_flags & MS_RDONLY)
  178. mp->m_flags |= XFS_MOUNT_RDONLY;
  179. if (sb->s_flags & MS_DIRSYNC)
  180. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  181. if (sb->s_flags & MS_SYNCHRONOUS)
  182. mp->m_flags |= XFS_MOUNT_WSYNC;
  183. /*
  184. * Set some default flags that could be cleared by the mount option
  185. * parsing.
  186. */
  187. mp->m_flags |= XFS_MOUNT_BARRIER;
  188. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  189. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  190. /*
  191. * These can be overridden by the mount option parsing.
  192. */
  193. mp->m_logbufs = -1;
  194. mp->m_logbsize = -1;
  195. if (!options)
  196. goto done;
  197. while ((this_char = strsep(&options, ",")) != NULL) {
  198. if (!*this_char)
  199. continue;
  200. if ((value = strchr(this_char, '=')) != NULL)
  201. *value++ = 0;
  202. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  203. if (!value || !*value) {
  204. cmn_err(CE_WARN,
  205. "XFS: %s option requires an argument",
  206. this_char);
  207. return EINVAL;
  208. }
  209. mp->m_logbufs = simple_strtoul(value, &eov, 10);
  210. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  211. if (!value || !*value) {
  212. cmn_err(CE_WARN,
  213. "XFS: %s option requires an argument",
  214. this_char);
  215. return EINVAL;
  216. }
  217. mp->m_logbsize = suffix_strtoul(value, &eov, 10);
  218. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  219. if (!value || !*value) {
  220. cmn_err(CE_WARN,
  221. "XFS: %s option requires an argument",
  222. this_char);
  223. return EINVAL;
  224. }
  225. mp->m_logname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  226. if (!mp->m_logname)
  227. return ENOMEM;
  228. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  229. if (!value || !*value) {
  230. cmn_err(CE_WARN,
  231. "XFS: %s option requires an argument",
  232. this_char);
  233. return EINVAL;
  234. }
  235. *mtpt = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  236. if (!*mtpt)
  237. return ENOMEM;
  238. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  239. if (!value || !*value) {
  240. cmn_err(CE_WARN,
  241. "XFS: %s option requires an argument",
  242. this_char);
  243. return EINVAL;
  244. }
  245. mp->m_rtname = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
  246. if (!mp->m_rtname)
  247. return ENOMEM;
  248. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  249. if (!value || !*value) {
  250. cmn_err(CE_WARN,
  251. "XFS: %s option requires an argument",
  252. this_char);
  253. return EINVAL;
  254. }
  255. iosize = simple_strtoul(value, &eov, 10);
  256. iosizelog = ffs(iosize) - 1;
  257. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  258. if (!value || !*value) {
  259. cmn_err(CE_WARN,
  260. "XFS: %s option requires an argument",
  261. this_char);
  262. return EINVAL;
  263. }
  264. iosize = suffix_strtoul(value, &eov, 10);
  265. iosizelog = ffs(iosize) - 1;
  266. } else if (!strcmp(this_char, MNTOPT_GRPID) ||
  267. !strcmp(this_char, MNTOPT_BSDGROUPS)) {
  268. mp->m_flags |= XFS_MOUNT_GRPID;
  269. } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
  270. !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
  271. mp->m_flags &= ~XFS_MOUNT_GRPID;
  272. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  273. mp->m_flags |= XFS_MOUNT_WSYNC;
  274. } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
  275. mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
  276. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  277. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  278. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  279. mp->m_flags |= XFS_MOUNT_NOALIGN;
  280. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  281. mp->m_flags |= XFS_MOUNT_SWALLOC;
  282. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  283. if (!value || !*value) {
  284. cmn_err(CE_WARN,
  285. "XFS: %s option requires an argument",
  286. this_char);
  287. return EINVAL;
  288. }
  289. dsunit = simple_strtoul(value, &eov, 10);
  290. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  291. if (!value || !*value) {
  292. cmn_err(CE_WARN,
  293. "XFS: %s option requires an argument",
  294. this_char);
  295. return EINVAL;
  296. }
  297. dswidth = simple_strtoul(value, &eov, 10);
  298. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  299. mp->m_flags &= ~XFS_MOUNT_SMALL_INUMS;
  300. #if !XFS_BIG_INUMS
  301. cmn_err(CE_WARN,
  302. "XFS: %s option not allowed on this system",
  303. this_char);
  304. return EINVAL;
  305. #endif
  306. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  307. mp->m_flags |= XFS_MOUNT_NOUUID;
  308. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  309. mp->m_flags |= XFS_MOUNT_BARRIER;
  310. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  311. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  312. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  313. mp->m_flags |= XFS_MOUNT_IKEEP;
  314. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  315. dmapi_implies_ikeep = 0;
  316. mp->m_flags &= ~XFS_MOUNT_IKEEP;
  317. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  318. mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
  319. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  320. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  321. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  322. mp->m_flags |= XFS_MOUNT_ATTR2;
  323. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  324. mp->m_flags &= ~XFS_MOUNT_ATTR2;
  325. mp->m_flags |= XFS_MOUNT_NOATTR2;
  326. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  327. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  328. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  329. mp->m_qflags &= ~(XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
  330. XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
  331. XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
  332. XFS_UQUOTA_ENFD | XFS_OQUOTA_ENFD);
  333. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  334. !strcmp(this_char, MNTOPT_UQUOTA) ||
  335. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  336. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
  337. XFS_UQUOTA_ENFD);
  338. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  339. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  340. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  341. mp->m_qflags &= ~XFS_UQUOTA_ENFD;
  342. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  343. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  344. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
  345. XFS_OQUOTA_ENFD);
  346. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  347. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  348. mp->m_qflags &= ~XFS_OQUOTA_ENFD;
  349. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  350. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  351. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
  352. XFS_OQUOTA_ENFD);
  353. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  354. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  355. mp->m_qflags &= ~XFS_OQUOTA_ENFD;
  356. } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
  357. mp->m_flags |= XFS_MOUNT_DMAPI;
  358. } else if (!strcmp(this_char, MNTOPT_XDSM)) {
  359. mp->m_flags |= XFS_MOUNT_DMAPI;
  360. } else if (!strcmp(this_char, MNTOPT_DMI)) {
  361. mp->m_flags |= XFS_MOUNT_DMAPI;
  362. } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
  363. mp->m_flags |= XFS_MOUNT_DELAYLOG;
  364. cmn_err(CE_WARN,
  365. "Enabling EXPERIMENTAL delayed logging feature "
  366. "- use at your own risk.\n");
  367. } else if (!strcmp(this_char, MNTOPT_NODELAYLOG)) {
  368. mp->m_flags &= ~XFS_MOUNT_DELAYLOG;
  369. } else if (!strcmp(this_char, "ihashsize")) {
  370. cmn_err(CE_WARN,
  371. "XFS: ihashsize no longer used, option is deprecated.");
  372. } else if (!strcmp(this_char, "osyncisdsync")) {
  373. /* no-op, this is now the default */
  374. cmn_err(CE_WARN,
  375. "XFS: osyncisdsync is now the default, option is deprecated.");
  376. } else if (!strcmp(this_char, "irixsgid")) {
  377. cmn_err(CE_WARN,
  378. "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
  379. } else {
  380. cmn_err(CE_WARN,
  381. "XFS: unknown mount option [%s].", this_char);
  382. return EINVAL;
  383. }
  384. }
  385. /*
  386. * no recovery flag requires a read-only mount
  387. */
  388. if ((mp->m_flags & XFS_MOUNT_NORECOVERY) &&
  389. !(mp->m_flags & XFS_MOUNT_RDONLY)) {
  390. cmn_err(CE_WARN, "XFS: no-recovery mounts must be read-only.");
  391. return EINVAL;
  392. }
  393. if ((mp->m_flags & XFS_MOUNT_NOALIGN) && (dsunit || dswidth)) {
  394. cmn_err(CE_WARN,
  395. "XFS: sunit and swidth options incompatible with the noalign option");
  396. return EINVAL;
  397. }
  398. #ifndef CONFIG_XFS_QUOTA
  399. if (XFS_IS_QUOTA_RUNNING(mp)) {
  400. cmn_err(CE_WARN,
  401. "XFS: quota support not available in this kernel.");
  402. return EINVAL;
  403. }
  404. #endif
  405. if ((mp->m_qflags & (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE)) &&
  406. (mp->m_qflags & (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE))) {
  407. cmn_err(CE_WARN,
  408. "XFS: cannot mount with both project and group quota");
  409. return EINVAL;
  410. }
  411. if ((mp->m_flags & XFS_MOUNT_DMAPI) && (!*mtpt || *mtpt[0] == '\0')) {
  412. printk("XFS: %s option needs the mount point option as well\n",
  413. MNTOPT_DMAPI);
  414. return EINVAL;
  415. }
  416. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  417. cmn_err(CE_WARN,
  418. "XFS: sunit and swidth must be specified together");
  419. return EINVAL;
  420. }
  421. if (dsunit && (dswidth % dsunit != 0)) {
  422. cmn_err(CE_WARN,
  423. "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
  424. dswidth, dsunit);
  425. return EINVAL;
  426. }
  427. /*
  428. * Applications using DMI filesystems often expect the
  429. * inode generation number to be monotonically increasing.
  430. * If we delete inode chunks we break this assumption, so
  431. * keep unused inode chunks on disk for DMI filesystems
  432. * until we come up with a better solution.
  433. * Note that if "ikeep" or "noikeep" mount options are
  434. * supplied, then they are honored.
  435. */
  436. if ((mp->m_flags & XFS_MOUNT_DMAPI) && dmapi_implies_ikeep)
  437. mp->m_flags |= XFS_MOUNT_IKEEP;
  438. done:
  439. if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
  440. /*
  441. * At this point the superblock has not been read
  442. * in, therefore we do not know the block size.
  443. * Before the mount call ends we will convert
  444. * these to FSBs.
  445. */
  446. if (dsunit) {
  447. mp->m_dalign = dsunit;
  448. mp->m_flags |= XFS_MOUNT_RETERR;
  449. }
  450. if (dswidth)
  451. mp->m_swidth = dswidth;
  452. }
  453. if (mp->m_logbufs != -1 &&
  454. mp->m_logbufs != 0 &&
  455. (mp->m_logbufs < XLOG_MIN_ICLOGS ||
  456. mp->m_logbufs > XLOG_MAX_ICLOGS)) {
  457. cmn_err(CE_WARN,
  458. "XFS: invalid logbufs value: %d [not %d-%d]",
  459. mp->m_logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  460. return XFS_ERROR(EINVAL);
  461. }
  462. if (mp->m_logbsize != -1 &&
  463. mp->m_logbsize != 0 &&
  464. (mp->m_logbsize < XLOG_MIN_RECORD_BSIZE ||
  465. mp->m_logbsize > XLOG_MAX_RECORD_BSIZE ||
  466. !is_power_of_2(mp->m_logbsize))) {
  467. cmn_err(CE_WARN,
  468. "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  469. mp->m_logbsize);
  470. return XFS_ERROR(EINVAL);
  471. }
  472. mp->m_fsname = kstrndup(sb->s_id, MAXNAMELEN, GFP_KERNEL);
  473. if (!mp->m_fsname)
  474. return ENOMEM;
  475. mp->m_fsname_len = strlen(mp->m_fsname) + 1;
  476. if (iosizelog) {
  477. if (iosizelog > XFS_MAX_IO_LOG ||
  478. iosizelog < XFS_MIN_IO_LOG) {
  479. cmn_err(CE_WARN,
  480. "XFS: invalid log iosize: %d [not %d-%d]",
  481. iosizelog, XFS_MIN_IO_LOG,
  482. XFS_MAX_IO_LOG);
  483. return XFS_ERROR(EINVAL);
  484. }
  485. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  486. mp->m_readio_log = iosizelog;
  487. mp->m_writeio_log = iosizelog;
  488. }
  489. return 0;
  490. }
  491. struct proc_xfs_info {
  492. int flag;
  493. char *str;
  494. };
  495. STATIC int
  496. xfs_showargs(
  497. struct xfs_mount *mp,
  498. struct seq_file *m)
  499. {
  500. static struct proc_xfs_info xfs_info_set[] = {
  501. /* the few simple ones we can get from the mount struct */
  502. { XFS_MOUNT_IKEEP, "," MNTOPT_IKEEP },
  503. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  504. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  505. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  506. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  507. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  508. { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
  509. { XFS_MOUNT_ATTR2, "," MNTOPT_ATTR2 },
  510. { XFS_MOUNT_FILESTREAMS, "," MNTOPT_FILESTREAM },
  511. { XFS_MOUNT_DMAPI, "," MNTOPT_DMAPI },
  512. { XFS_MOUNT_GRPID, "," MNTOPT_GRPID },
  513. { XFS_MOUNT_DELAYLOG, "," MNTOPT_DELAYLOG },
  514. { 0, NULL }
  515. };
  516. static struct proc_xfs_info xfs_info_unset[] = {
  517. /* the few simple ones we can get from the mount struct */
  518. { XFS_MOUNT_COMPAT_IOSIZE, "," MNTOPT_LARGEIO },
  519. { XFS_MOUNT_BARRIER, "," MNTOPT_NOBARRIER },
  520. { XFS_MOUNT_SMALL_INUMS, "," MNTOPT_64BITINODE },
  521. { 0, NULL }
  522. };
  523. struct proc_xfs_info *xfs_infop;
  524. for (xfs_infop = xfs_info_set; xfs_infop->flag; xfs_infop++) {
  525. if (mp->m_flags & xfs_infop->flag)
  526. seq_puts(m, xfs_infop->str);
  527. }
  528. for (xfs_infop = xfs_info_unset; xfs_infop->flag; xfs_infop++) {
  529. if (!(mp->m_flags & xfs_infop->flag))
  530. seq_puts(m, xfs_infop->str);
  531. }
  532. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  533. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  534. (int)(1 << mp->m_writeio_log) >> 10);
  535. if (mp->m_logbufs > 0)
  536. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  537. if (mp->m_logbsize > 0)
  538. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  539. if (mp->m_logname)
  540. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  541. if (mp->m_rtname)
  542. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  543. if (mp->m_dalign > 0)
  544. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  545. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  546. if (mp->m_swidth > 0)
  547. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  548. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  549. if (mp->m_qflags & (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD))
  550. seq_puts(m, "," MNTOPT_USRQUOTA);
  551. else if (mp->m_qflags & XFS_UQUOTA_ACCT)
  552. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  553. /* Either project or group quotas can be active, not both */
  554. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  555. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  556. seq_puts(m, "," MNTOPT_PRJQUOTA);
  557. else
  558. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  559. } else if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  560. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  561. seq_puts(m, "," MNTOPT_GRPQUOTA);
  562. else
  563. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  564. }
  565. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  566. seq_puts(m, "," MNTOPT_NOQUOTA);
  567. return 0;
  568. }
  569. __uint64_t
  570. xfs_max_file_offset(
  571. unsigned int blockshift)
  572. {
  573. unsigned int pagefactor = 1;
  574. unsigned int bitshift = BITS_PER_LONG - 1;
  575. /* Figure out maximum filesize, on Linux this can depend on
  576. * the filesystem blocksize (on 32 bit platforms).
  577. * __block_prepare_write does this in an [unsigned] long...
  578. * page->index << (PAGE_CACHE_SHIFT - bbits)
  579. * So, for page sized blocks (4K on 32 bit platforms),
  580. * this wraps at around 8Tb (hence MAX_LFS_FILESIZE which is
  581. * (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
  582. * but for smaller blocksizes it is less (bbits = log2 bsize).
  583. * Note1: get_block_t takes a long (implicit cast from above)
  584. * Note2: The Large Block Device (LBD and HAVE_SECTOR_T) patch
  585. * can optionally convert the [unsigned] long from above into
  586. * an [unsigned] long long.
  587. */
  588. #if BITS_PER_LONG == 32
  589. # if defined(CONFIG_LBDAF)
  590. ASSERT(sizeof(sector_t) == 8);
  591. pagefactor = PAGE_CACHE_SIZE;
  592. bitshift = BITS_PER_LONG;
  593. # else
  594. pagefactor = PAGE_CACHE_SIZE >> (PAGE_CACHE_SHIFT - blockshift);
  595. # endif
  596. #endif
  597. return (((__uint64_t)pagefactor) << bitshift) - 1;
  598. }
  599. STATIC int
  600. xfs_blkdev_get(
  601. xfs_mount_t *mp,
  602. const char *name,
  603. struct block_device **bdevp)
  604. {
  605. int error = 0;
  606. *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp);
  607. if (IS_ERR(*bdevp)) {
  608. error = PTR_ERR(*bdevp);
  609. printk("XFS: Invalid device [%s], error=%d\n", name, error);
  610. }
  611. return -error;
  612. }
  613. STATIC void
  614. xfs_blkdev_put(
  615. struct block_device *bdev)
  616. {
  617. if (bdev)
  618. close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE);
  619. }
  620. /*
  621. * Try to write out the superblock using barriers.
  622. */
  623. STATIC int
  624. xfs_barrier_test(
  625. xfs_mount_t *mp)
  626. {
  627. xfs_buf_t *sbp = xfs_getsb(mp, 0);
  628. int error;
  629. XFS_BUF_UNDONE(sbp);
  630. XFS_BUF_UNREAD(sbp);
  631. XFS_BUF_UNDELAYWRITE(sbp);
  632. XFS_BUF_WRITE(sbp);
  633. XFS_BUF_UNASYNC(sbp);
  634. XFS_BUF_ORDERED(sbp);
  635. xfsbdstrat(mp, sbp);
  636. error = xfs_iowait(sbp);
  637. /*
  638. * Clear all the flags we set and possible error state in the
  639. * buffer. We only did the write to try out whether barriers
  640. * worked and shouldn't leave any traces in the superblock
  641. * buffer.
  642. */
  643. XFS_BUF_DONE(sbp);
  644. XFS_BUF_ERROR(sbp, 0);
  645. XFS_BUF_UNORDERED(sbp);
  646. xfs_buf_relse(sbp);
  647. return error;
  648. }
  649. STATIC void
  650. xfs_mountfs_check_barriers(xfs_mount_t *mp)
  651. {
  652. int error;
  653. if (mp->m_logdev_targp != mp->m_ddev_targp) {
  654. xfs_fs_cmn_err(CE_NOTE, mp,
  655. "Disabling barriers, not supported with external log device");
  656. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  657. return;
  658. }
  659. if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
  660. xfs_fs_cmn_err(CE_NOTE, mp,
  661. "Disabling barriers, underlying device is readonly");
  662. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  663. return;
  664. }
  665. error = xfs_barrier_test(mp);
  666. if (error) {
  667. xfs_fs_cmn_err(CE_NOTE, mp,
  668. "Disabling barriers, trial barrier write failed");
  669. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  670. return;
  671. }
  672. }
  673. void
  674. xfs_blkdev_issue_flush(
  675. xfs_buftarg_t *buftarg)
  676. {
  677. blkdev_issue_flush(buftarg->bt_bdev, GFP_KERNEL, NULL,
  678. BLKDEV_IFL_WAIT);
  679. }
  680. STATIC void
  681. xfs_close_devices(
  682. struct xfs_mount *mp)
  683. {
  684. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  685. struct block_device *logdev = mp->m_logdev_targp->bt_bdev;
  686. xfs_free_buftarg(mp, mp->m_logdev_targp);
  687. xfs_blkdev_put(logdev);
  688. }
  689. if (mp->m_rtdev_targp) {
  690. struct block_device *rtdev = mp->m_rtdev_targp->bt_bdev;
  691. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  692. xfs_blkdev_put(rtdev);
  693. }
  694. xfs_free_buftarg(mp, mp->m_ddev_targp);
  695. }
  696. /*
  697. * The file system configurations are:
  698. * (1) device (partition) with data and internal log
  699. * (2) logical volume with data and log subvolumes.
  700. * (3) logical volume with data, log, and realtime subvolumes.
  701. *
  702. * We only have to handle opening the log and realtime volumes here if
  703. * they are present. The data subvolume has already been opened by
  704. * get_sb_bdev() and is stored in sb->s_bdev.
  705. */
  706. STATIC int
  707. xfs_open_devices(
  708. struct xfs_mount *mp)
  709. {
  710. struct block_device *ddev = mp->m_super->s_bdev;
  711. struct block_device *logdev = NULL, *rtdev = NULL;
  712. int error;
  713. /*
  714. * Open real time and log devices - order is important.
  715. */
  716. if (mp->m_logname) {
  717. error = xfs_blkdev_get(mp, mp->m_logname, &logdev);
  718. if (error)
  719. goto out;
  720. }
  721. if (mp->m_rtname) {
  722. error = xfs_blkdev_get(mp, mp->m_rtname, &rtdev);
  723. if (error)
  724. goto out_close_logdev;
  725. if (rtdev == ddev || rtdev == logdev) {
  726. cmn_err(CE_WARN,
  727. "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
  728. error = EINVAL;
  729. goto out_close_rtdev;
  730. }
  731. }
  732. /*
  733. * Setup xfs_mount buffer target pointers
  734. */
  735. error = ENOMEM;
  736. mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0, mp->m_fsname);
  737. if (!mp->m_ddev_targp)
  738. goto out_close_rtdev;
  739. if (rtdev) {
  740. mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1, mp->m_fsname);
  741. if (!mp->m_rtdev_targp)
  742. goto out_free_ddev_targ;
  743. }
  744. if (logdev && logdev != ddev) {
  745. mp->m_logdev_targp = xfs_alloc_buftarg(logdev, 1, mp->m_fsname);
  746. if (!mp->m_logdev_targp)
  747. goto out_free_rtdev_targ;
  748. } else {
  749. mp->m_logdev_targp = mp->m_ddev_targp;
  750. }
  751. return 0;
  752. out_free_rtdev_targ:
  753. if (mp->m_rtdev_targp)
  754. xfs_free_buftarg(mp, mp->m_rtdev_targp);
  755. out_free_ddev_targ:
  756. xfs_free_buftarg(mp, mp->m_ddev_targp);
  757. out_close_rtdev:
  758. if (rtdev)
  759. xfs_blkdev_put(rtdev);
  760. out_close_logdev:
  761. if (logdev && logdev != ddev)
  762. xfs_blkdev_put(logdev);
  763. out:
  764. return error;
  765. }
  766. /*
  767. * Setup xfs_mount buffer target pointers based on superblock
  768. */
  769. STATIC int
  770. xfs_setup_devices(
  771. struct xfs_mount *mp)
  772. {
  773. int error;
  774. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  775. mp->m_sb.sb_sectsize);
  776. if (error)
  777. return error;
  778. if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp) {
  779. unsigned int log_sector_size = BBSIZE;
  780. if (xfs_sb_version_hassector(&mp->m_sb))
  781. log_sector_size = mp->m_sb.sb_logsectsize;
  782. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  783. mp->m_sb.sb_blocksize,
  784. log_sector_size);
  785. if (error)
  786. return error;
  787. }
  788. if (mp->m_rtdev_targp) {
  789. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  790. mp->m_sb.sb_blocksize,
  791. mp->m_sb.sb_sectsize);
  792. if (error)
  793. return error;
  794. }
  795. return 0;
  796. }
  797. /*
  798. * XFS AIL push thread support
  799. */
  800. void
  801. xfsaild_wakeup(
  802. struct xfs_ail *ailp,
  803. xfs_lsn_t threshold_lsn)
  804. {
  805. ailp->xa_target = threshold_lsn;
  806. wake_up_process(ailp->xa_task);
  807. }
  808. STATIC int
  809. xfsaild(
  810. void *data)
  811. {
  812. struct xfs_ail *ailp = data;
  813. xfs_lsn_t last_pushed_lsn = 0;
  814. long tout = 0; /* milliseconds */
  815. while (!kthread_should_stop()) {
  816. schedule_timeout_interruptible(tout ?
  817. msecs_to_jiffies(tout) : MAX_SCHEDULE_TIMEOUT);
  818. /* swsusp */
  819. try_to_freeze();
  820. ASSERT(ailp->xa_mount->m_log);
  821. if (XFS_FORCED_SHUTDOWN(ailp->xa_mount))
  822. continue;
  823. tout = xfsaild_push(ailp, &last_pushed_lsn);
  824. }
  825. return 0;
  826. } /* xfsaild */
  827. int
  828. xfsaild_start(
  829. struct xfs_ail *ailp)
  830. {
  831. ailp->xa_target = 0;
  832. ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild/%s",
  833. ailp->xa_mount->m_fsname);
  834. if (IS_ERR(ailp->xa_task))
  835. return -PTR_ERR(ailp->xa_task);
  836. return 0;
  837. }
  838. void
  839. xfsaild_stop(
  840. struct xfs_ail *ailp)
  841. {
  842. kthread_stop(ailp->xa_task);
  843. }
  844. /* Catch misguided souls that try to use this interface on XFS */
  845. STATIC struct inode *
  846. xfs_fs_alloc_inode(
  847. struct super_block *sb)
  848. {
  849. BUG();
  850. return NULL;
  851. }
  852. /*
  853. * Now that the generic code is guaranteed not to be accessing
  854. * the linux inode, we can reclaim the inode.
  855. */
  856. STATIC void
  857. xfs_fs_destroy_inode(
  858. struct inode *inode)
  859. {
  860. struct xfs_inode *ip = XFS_I(inode);
  861. xfs_itrace_entry(ip);
  862. XFS_STATS_INC(vn_reclaim);
  863. /* bad inode, get out here ASAP */
  864. if (is_bad_inode(inode))
  865. goto out_reclaim;
  866. xfs_ioend_wait(ip);
  867. ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
  868. /*
  869. * We should never get here with one of the reclaim flags already set.
  870. */
  871. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
  872. ASSERT_ALWAYS(!xfs_iflags_test(ip, XFS_IRECLAIM));
  873. /*
  874. * We always use background reclaim here because even if the
  875. * inode is clean, it still may be under IO and hence we have
  876. * to take the flush lock. The background reclaim path handles
  877. * this more efficiently than we can here, so simply let background
  878. * reclaim tear down all inodes.
  879. */
  880. out_reclaim:
  881. xfs_inode_set_reclaim_tag(ip);
  882. }
  883. /*
  884. * Slab object creation initialisation for the XFS inode.
  885. * This covers only the idempotent fields in the XFS inode;
  886. * all other fields need to be initialised on allocation
  887. * from the slab. This avoids the need to repeatedly intialise
  888. * fields in the xfs inode that left in the initialise state
  889. * when freeing the inode.
  890. */
  891. STATIC void
  892. xfs_fs_inode_init_once(
  893. void *inode)
  894. {
  895. struct xfs_inode *ip = inode;
  896. memset(ip, 0, sizeof(struct xfs_inode));
  897. /* vfs inode */
  898. inode_init_once(VFS_I(ip));
  899. /* xfs inode */
  900. atomic_set(&ip->i_iocount, 0);
  901. atomic_set(&ip->i_pincount, 0);
  902. spin_lock_init(&ip->i_flags_lock);
  903. init_waitqueue_head(&ip->i_ipin_wait);
  904. /*
  905. * Because we want to use a counting completion, complete
  906. * the flush completion once to allow a single access to
  907. * the flush completion without blocking.
  908. */
  909. init_completion(&ip->i_flush);
  910. complete(&ip->i_flush);
  911. mrlock_init(&ip->i_lock, MRLOCK_ALLOW_EQUAL_PRI|MRLOCK_BARRIER,
  912. "xfsino", ip->i_ino);
  913. }
  914. /*
  915. * Dirty the XFS inode when mark_inode_dirty_sync() is called so that
  916. * we catch unlogged VFS level updates to the inode. Care must be taken
  917. * here - the transaction code calls mark_inode_dirty_sync() to mark the
  918. * VFS inode dirty in a transaction and clears the i_update_core field;
  919. * it must clear the field after calling mark_inode_dirty_sync() to
  920. * correctly indicate that the dirty state has been propagated into the
  921. * inode log item.
  922. *
  923. * We need the barrier() to maintain correct ordering between unlogged
  924. * updates and the transaction commit code that clears the i_update_core
  925. * field. This requires all updates to be completed before marking the
  926. * inode dirty.
  927. */
  928. STATIC void
  929. xfs_fs_dirty_inode(
  930. struct inode *inode)
  931. {
  932. barrier();
  933. XFS_I(inode)->i_update_core = 1;
  934. }
  935. STATIC int
  936. xfs_log_inode(
  937. struct xfs_inode *ip)
  938. {
  939. struct xfs_mount *mp = ip->i_mount;
  940. struct xfs_trans *tp;
  941. int error;
  942. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  943. tp = xfs_trans_alloc(mp, XFS_TRANS_FSYNC_TS);
  944. error = xfs_trans_reserve(tp, 0, XFS_FSYNC_TS_LOG_RES(mp), 0, 0, 0);
  945. if (error) {
  946. xfs_trans_cancel(tp, 0);
  947. /* we need to return with the lock hold shared */
  948. xfs_ilock(ip, XFS_ILOCK_SHARED);
  949. return error;
  950. }
  951. xfs_ilock(ip, XFS_ILOCK_EXCL);
  952. /*
  953. * Note - it's possible that we might have pushed ourselves out of the
  954. * way during trans_reserve which would flush the inode. But there's
  955. * no guarantee that the inode buffer has actually gone out yet (it's
  956. * delwri). Plus the buffer could be pinned anyway if it's part of
  957. * an inode in another recent transaction. So we play it safe and
  958. * fire off the transaction anyway.
  959. */
  960. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  961. xfs_trans_ihold(tp, ip);
  962. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  963. xfs_trans_set_sync(tp);
  964. error = xfs_trans_commit(tp, 0);
  965. xfs_ilock_demote(ip, XFS_ILOCK_EXCL);
  966. return error;
  967. }
  968. STATIC int
  969. xfs_fs_write_inode(
  970. struct inode *inode,
  971. struct writeback_control *wbc)
  972. {
  973. struct xfs_inode *ip = XFS_I(inode);
  974. struct xfs_mount *mp = ip->i_mount;
  975. int error = EAGAIN;
  976. xfs_itrace_entry(ip);
  977. if (XFS_FORCED_SHUTDOWN(mp))
  978. return XFS_ERROR(EIO);
  979. if (wbc->sync_mode == WB_SYNC_ALL) {
  980. /*
  981. * Make sure the inode has hit stable storage. By using the
  982. * log and the fsync transactions we reduce the IOs we have
  983. * to do here from two (log and inode) to just the log.
  984. *
  985. * Note: We still need to do a delwri write of the inode after
  986. * this to flush it to the backing buffer so that bulkstat
  987. * works properly if this is the first time the inode has been
  988. * written. Because we hold the ilock atomically over the
  989. * transaction commit and the inode flush we are guaranteed
  990. * that the inode is not pinned when it returns. If the flush
  991. * lock is already held, then the inode has already been
  992. * flushed once and we don't need to flush it again. Hence
  993. * the code will only flush the inode if it isn't already
  994. * being flushed.
  995. */
  996. xfs_ioend_wait(ip);
  997. xfs_ilock(ip, XFS_ILOCK_SHARED);
  998. if (ip->i_update_core) {
  999. error = xfs_log_inode(ip);
  1000. if (error)
  1001. goto out_unlock;
  1002. }
  1003. } else {
  1004. /*
  1005. * We make this non-blocking if the inode is contended, return
  1006. * EAGAIN to indicate to the caller that they did not succeed.
  1007. * This prevents the flush path from blocking on inodes inside
  1008. * another operation right now, they get caught later by xfs_sync.
  1009. */
  1010. if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
  1011. goto out;
  1012. }
  1013. if (xfs_ipincount(ip) || !xfs_iflock_nowait(ip))
  1014. goto out_unlock;
  1015. /*
  1016. * Now we have the flush lock and the inode is not pinned, we can check
  1017. * if the inode is really clean as we know that there are no pending
  1018. * transaction completions, it is not waiting on the delayed write
  1019. * queue and there is no IO in progress.
  1020. */
  1021. if (xfs_inode_clean(ip)) {
  1022. xfs_ifunlock(ip);
  1023. error = 0;
  1024. goto out_unlock;
  1025. }
  1026. error = xfs_iflush(ip, 0);
  1027. out_unlock:
  1028. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1029. out:
  1030. /*
  1031. * if we failed to write out the inode then mark
  1032. * it dirty again so we'll try again later.
  1033. */
  1034. if (error)
  1035. xfs_mark_inode_dirty_sync(ip);
  1036. return -error;
  1037. }
  1038. STATIC void
  1039. xfs_fs_clear_inode(
  1040. struct inode *inode)
  1041. {
  1042. xfs_inode_t *ip = XFS_I(inode);
  1043. xfs_itrace_entry(ip);
  1044. XFS_STATS_INC(vn_rele);
  1045. XFS_STATS_INC(vn_remove);
  1046. XFS_STATS_DEC(vn_active);
  1047. /*
  1048. * The iolock is used by the file system to coordinate reads,
  1049. * writes, and block truncates. Up to this point the lock
  1050. * protected concurrent accesses by users of the inode. But
  1051. * from here forward we're doing some final processing of the
  1052. * inode because we're done with it, and although we reuse the
  1053. * iolock for protection it is really a distinct lock class
  1054. * (in the lockdep sense) from before. To keep lockdep happy
  1055. * (and basically indicate what we are doing), we explicitly
  1056. * re-init the iolock here.
  1057. */
  1058. ASSERT(!rwsem_is_locked(&ip->i_iolock.mr_lock));
  1059. mrlock_init(&ip->i_iolock, MRLOCK_BARRIER, "xfsio", ip->i_ino);
  1060. xfs_inactive(ip);
  1061. }
  1062. STATIC void
  1063. xfs_free_fsname(
  1064. struct xfs_mount *mp)
  1065. {
  1066. kfree(mp->m_fsname);
  1067. kfree(mp->m_rtname);
  1068. kfree(mp->m_logname);
  1069. }
  1070. STATIC void
  1071. xfs_fs_put_super(
  1072. struct super_block *sb)
  1073. {
  1074. struct xfs_mount *mp = XFS_M(sb);
  1075. xfs_syncd_stop(mp);
  1076. if (!(sb->s_flags & MS_RDONLY)) {
  1077. /*
  1078. * XXX(hch): this should be SYNC_WAIT.
  1079. *
  1080. * Or more likely not needed at all because the VFS is already
  1081. * calling ->sync_fs after shutting down all filestem
  1082. * operations and just before calling ->put_super.
  1083. */
  1084. xfs_sync_data(mp, 0);
  1085. xfs_sync_attr(mp, 0);
  1086. }
  1087. XFS_SEND_PREUNMOUNT(mp);
  1088. /*
  1089. * Blow away any referenced inode in the filestreams cache.
  1090. * This can and will cause log traffic as inodes go inactive
  1091. * here.
  1092. */
  1093. xfs_filestream_unmount(mp);
  1094. XFS_bflush(mp->m_ddev_targp);
  1095. XFS_SEND_UNMOUNT(mp);
  1096. xfs_unmountfs(mp);
  1097. xfs_freesb(mp);
  1098. xfs_inode_shrinker_unregister(mp);
  1099. xfs_icsb_destroy_counters(mp);
  1100. xfs_close_devices(mp);
  1101. xfs_dmops_put(mp);
  1102. xfs_free_fsname(mp);
  1103. kfree(mp);
  1104. }
  1105. STATIC int
  1106. xfs_fs_sync_fs(
  1107. struct super_block *sb,
  1108. int wait)
  1109. {
  1110. struct xfs_mount *mp = XFS_M(sb);
  1111. int error;
  1112. /*
  1113. * Not much we can do for the first async pass. Writing out the
  1114. * superblock would be counter-productive as we are going to redirty
  1115. * when writing out other data and metadata (and writing out a single
  1116. * block is quite fast anyway).
  1117. *
  1118. * Try to asynchronously kick off quota syncing at least.
  1119. */
  1120. if (!wait) {
  1121. xfs_qm_sync(mp, SYNC_TRYLOCK);
  1122. return 0;
  1123. }
  1124. error = xfs_quiesce_data(mp);
  1125. if (error)
  1126. return -error;
  1127. if (laptop_mode) {
  1128. int prev_sync_seq = mp->m_sync_seq;
  1129. /*
  1130. * The disk must be active because we're syncing.
  1131. * We schedule xfssyncd now (now that the disk is
  1132. * active) instead of later (when it might not be).
  1133. */
  1134. wake_up_process(mp->m_sync_task);
  1135. /*
  1136. * We have to wait for the sync iteration to complete.
  1137. * If we don't, the disk activity caused by the sync
  1138. * will come after the sync is completed, and that
  1139. * triggers another sync from laptop mode.
  1140. */
  1141. wait_event(mp->m_wait_single_sync_task,
  1142. mp->m_sync_seq != prev_sync_seq);
  1143. }
  1144. return 0;
  1145. }
  1146. STATIC int
  1147. xfs_fs_statfs(
  1148. struct dentry *dentry,
  1149. struct kstatfs *statp)
  1150. {
  1151. struct xfs_mount *mp = XFS_M(dentry->d_sb);
  1152. xfs_sb_t *sbp = &mp->m_sb;
  1153. struct xfs_inode *ip = XFS_I(dentry->d_inode);
  1154. __uint64_t fakeinos, id;
  1155. xfs_extlen_t lsize;
  1156. statp->f_type = XFS_SB_MAGIC;
  1157. statp->f_namelen = MAXNAMELEN - 1;
  1158. id = huge_encode_dev(mp->m_ddev_targp->bt_dev);
  1159. statp->f_fsid.val[0] = (u32)id;
  1160. statp->f_fsid.val[1] = (u32)(id >> 32);
  1161. xfs_icsb_sync_counters(mp, XFS_ICSB_LAZY_COUNT);
  1162. spin_lock(&mp->m_sb_lock);
  1163. statp->f_bsize = sbp->sb_blocksize;
  1164. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  1165. statp->f_blocks = sbp->sb_dblocks - lsize;
  1166. statp->f_bfree = statp->f_bavail =
  1167. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  1168. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  1169. statp->f_files =
  1170. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  1171. if (mp->m_maxicount)
  1172. statp->f_files = min_t(typeof(statp->f_files),
  1173. statp->f_files,
  1174. mp->m_maxicount);
  1175. statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  1176. spin_unlock(&mp->m_sb_lock);
  1177. if ((ip->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) ||
  1178. ((mp->m_qflags & (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))) ==
  1179. (XFS_PQUOTA_ACCT|XFS_OQUOTA_ENFD))
  1180. xfs_qm_statvfs(ip, statp);
  1181. return 0;
  1182. }
  1183. STATIC void
  1184. xfs_save_resvblks(struct xfs_mount *mp)
  1185. {
  1186. __uint64_t resblks = 0;
  1187. mp->m_resblks_save = mp->m_resblks;
  1188. xfs_reserve_blocks(mp, &resblks, NULL);
  1189. }
  1190. STATIC void
  1191. xfs_restore_resvblks(struct xfs_mount *mp)
  1192. {
  1193. __uint64_t resblks;
  1194. if (mp->m_resblks_save) {
  1195. resblks = mp->m_resblks_save;
  1196. mp->m_resblks_save = 0;
  1197. } else
  1198. resblks = xfs_default_resblks(mp);
  1199. xfs_reserve_blocks(mp, &resblks, NULL);
  1200. }
  1201. STATIC int
  1202. xfs_fs_remount(
  1203. struct super_block *sb,
  1204. int *flags,
  1205. char *options)
  1206. {
  1207. struct xfs_mount *mp = XFS_M(sb);
  1208. substring_t args[MAX_OPT_ARGS];
  1209. char *p;
  1210. int error;
  1211. while ((p = strsep(&options, ",")) != NULL) {
  1212. int token;
  1213. if (!*p)
  1214. continue;
  1215. token = match_token(p, tokens, args);
  1216. switch (token) {
  1217. case Opt_barrier:
  1218. mp->m_flags |= XFS_MOUNT_BARRIER;
  1219. /*
  1220. * Test if barriers are actually working if we can,
  1221. * else delay this check until the filesystem is
  1222. * marked writeable.
  1223. */
  1224. if (!(mp->m_flags & XFS_MOUNT_RDONLY))
  1225. xfs_mountfs_check_barriers(mp);
  1226. break;
  1227. case Opt_nobarrier:
  1228. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  1229. break;
  1230. default:
  1231. /*
  1232. * Logically we would return an error here to prevent
  1233. * users from believing they might have changed
  1234. * mount options using remount which can't be changed.
  1235. *
  1236. * But unfortunately mount(8) adds all options from
  1237. * mtab and fstab to the mount arguments in some cases
  1238. * so we can't blindly reject options, but have to
  1239. * check for each specified option if it actually
  1240. * differs from the currently set option and only
  1241. * reject it if that's the case.
  1242. *
  1243. * Until that is implemented we return success for
  1244. * every remount request, and silently ignore all
  1245. * options that we can't actually change.
  1246. */
  1247. #if 0
  1248. printk(KERN_INFO
  1249. "XFS: mount option \"%s\" not supported for remount\n", p);
  1250. return -EINVAL;
  1251. #else
  1252. break;
  1253. #endif
  1254. }
  1255. }
  1256. /* ro -> rw */
  1257. if ((mp->m_flags & XFS_MOUNT_RDONLY) && !(*flags & MS_RDONLY)) {
  1258. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  1259. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1260. xfs_mountfs_check_barriers(mp);
  1261. /*
  1262. * If this is the first remount to writeable state we
  1263. * might have some superblock changes to update.
  1264. */
  1265. if (mp->m_update_flags) {
  1266. error = xfs_mount_log_sb(mp, mp->m_update_flags);
  1267. if (error) {
  1268. cmn_err(CE_WARN,
  1269. "XFS: failed to write sb changes");
  1270. return error;
  1271. }
  1272. mp->m_update_flags = 0;
  1273. }
  1274. /*
  1275. * Fill out the reserve pool if it is empty. Use the stashed
  1276. * value if it is non-zero, otherwise go with the default.
  1277. */
  1278. xfs_restore_resvblks(mp);
  1279. }
  1280. /* rw -> ro */
  1281. if (!(mp->m_flags & XFS_MOUNT_RDONLY) && (*flags & MS_RDONLY)) {
  1282. /*
  1283. * After we have synced the data but before we sync the
  1284. * metadata, we need to free up the reserve block pool so that
  1285. * the used block count in the superblock on disk is correct at
  1286. * the end of the remount. Stash the current reserve pool size
  1287. * so that if we get remounted rw, we can return it to the same
  1288. * size.
  1289. */
  1290. xfs_quiesce_data(mp);
  1291. xfs_save_resvblks(mp);
  1292. xfs_quiesce_attr(mp);
  1293. mp->m_flags |= XFS_MOUNT_RDONLY;
  1294. }
  1295. return 0;
  1296. }
  1297. /*
  1298. * Second stage of a freeze. The data is already frozen so we only
  1299. * need to take care of the metadata. Once that's done write a dummy
  1300. * record to dirty the log in case of a crash while frozen.
  1301. */
  1302. STATIC int
  1303. xfs_fs_freeze(
  1304. struct super_block *sb)
  1305. {
  1306. struct xfs_mount *mp = XFS_M(sb);
  1307. xfs_save_resvblks(mp);
  1308. xfs_quiesce_attr(mp);
  1309. return -xfs_fs_log_dummy(mp);
  1310. }
  1311. STATIC int
  1312. xfs_fs_unfreeze(
  1313. struct super_block *sb)
  1314. {
  1315. struct xfs_mount *mp = XFS_M(sb);
  1316. xfs_restore_resvblks(mp);
  1317. return 0;
  1318. }
  1319. STATIC int
  1320. xfs_fs_show_options(
  1321. struct seq_file *m,
  1322. struct vfsmount *mnt)
  1323. {
  1324. return -xfs_showargs(XFS_M(mnt->mnt_sb), m);
  1325. }
  1326. /*
  1327. * This function fills in xfs_mount_t fields based on mount args.
  1328. * Note: the superblock _has_ now been read in.
  1329. */
  1330. STATIC int
  1331. xfs_finish_flags(
  1332. struct xfs_mount *mp)
  1333. {
  1334. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  1335. /* Fail a mount where the logbuf is smaller than the log stripe */
  1336. if (xfs_sb_version_haslogv2(&mp->m_sb)) {
  1337. if (mp->m_logbsize <= 0 &&
  1338. mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE) {
  1339. mp->m_logbsize = mp->m_sb.sb_logsunit;
  1340. } else if (mp->m_logbsize > 0 &&
  1341. mp->m_logbsize < mp->m_sb.sb_logsunit) {
  1342. cmn_err(CE_WARN,
  1343. "XFS: logbuf size must be greater than or equal to log stripe size");
  1344. return XFS_ERROR(EINVAL);
  1345. }
  1346. } else {
  1347. /* Fail a mount if the logbuf is larger than 32K */
  1348. if (mp->m_logbsize > XLOG_BIG_RECORD_BSIZE) {
  1349. cmn_err(CE_WARN,
  1350. "XFS: logbuf size for version 1 logs must be 16K or 32K");
  1351. return XFS_ERROR(EINVAL);
  1352. }
  1353. }
  1354. /*
  1355. * mkfs'ed attr2 will turn on attr2 mount unless explicitly
  1356. * told by noattr2 to turn it off
  1357. */
  1358. if (xfs_sb_version_hasattr2(&mp->m_sb) &&
  1359. !(mp->m_flags & XFS_MOUNT_NOATTR2))
  1360. mp->m_flags |= XFS_MOUNT_ATTR2;
  1361. /*
  1362. * prohibit r/w mounts of read-only filesystems
  1363. */
  1364. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  1365. cmn_err(CE_WARN,
  1366. "XFS: cannot mount a read-only filesystem as read-write");
  1367. return XFS_ERROR(EROFS);
  1368. }
  1369. return 0;
  1370. }
  1371. STATIC int
  1372. xfs_fs_fill_super(
  1373. struct super_block *sb,
  1374. void *data,
  1375. int silent)
  1376. {
  1377. struct inode *root;
  1378. struct xfs_mount *mp = NULL;
  1379. int flags = 0, error = ENOMEM;
  1380. char *mtpt = NULL;
  1381. mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
  1382. if (!mp)
  1383. goto out;
  1384. spin_lock_init(&mp->m_sb_lock);
  1385. mutex_init(&mp->m_growlock);
  1386. atomic_set(&mp->m_active_trans, 0);
  1387. INIT_LIST_HEAD(&mp->m_sync_list);
  1388. spin_lock_init(&mp->m_sync_lock);
  1389. init_waitqueue_head(&mp->m_wait_single_sync_task);
  1390. mp->m_super = sb;
  1391. sb->s_fs_info = mp;
  1392. error = xfs_parseargs(mp, (char *)data, &mtpt);
  1393. if (error)
  1394. goto out_free_fsname;
  1395. sb_min_blocksize(sb, BBSIZE);
  1396. sb->s_xattr = xfs_xattr_handlers;
  1397. sb->s_export_op = &xfs_export_operations;
  1398. #ifdef CONFIG_XFS_QUOTA
  1399. sb->s_qcop = &xfs_quotactl_operations;
  1400. #endif
  1401. sb->s_op = &xfs_super_operations;
  1402. error = xfs_dmops_get(mp);
  1403. if (error)
  1404. goto out_free_fsname;
  1405. if (silent)
  1406. flags |= XFS_MFSI_QUIET;
  1407. error = xfs_open_devices(mp);
  1408. if (error)
  1409. goto out_put_dmops;
  1410. if (xfs_icsb_init_counters(mp))
  1411. mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
  1412. error = xfs_readsb(mp, flags);
  1413. if (error)
  1414. goto out_destroy_counters;
  1415. error = xfs_finish_flags(mp);
  1416. if (error)
  1417. goto out_free_sb;
  1418. error = xfs_setup_devices(mp);
  1419. if (error)
  1420. goto out_free_sb;
  1421. if (mp->m_flags & XFS_MOUNT_BARRIER)
  1422. xfs_mountfs_check_barriers(mp);
  1423. error = xfs_filestream_mount(mp);
  1424. if (error)
  1425. goto out_free_sb;
  1426. error = xfs_mountfs(mp);
  1427. if (error)
  1428. goto out_filestream_unmount;
  1429. XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
  1430. sb->s_magic = XFS_SB_MAGIC;
  1431. sb->s_blocksize = mp->m_sb.sb_blocksize;
  1432. sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
  1433. sb->s_maxbytes = xfs_max_file_offset(sb->s_blocksize_bits);
  1434. sb->s_time_gran = 1;
  1435. set_posix_acl_flag(sb);
  1436. root = igrab(VFS_I(mp->m_rootip));
  1437. if (!root) {
  1438. error = ENOENT;
  1439. goto fail_unmount;
  1440. }
  1441. if (is_bad_inode(root)) {
  1442. error = EINVAL;
  1443. goto fail_vnrele;
  1444. }
  1445. sb->s_root = d_alloc_root(root);
  1446. if (!sb->s_root) {
  1447. error = ENOMEM;
  1448. goto fail_vnrele;
  1449. }
  1450. error = xfs_syncd_init(mp);
  1451. if (error)
  1452. goto fail_vnrele;
  1453. xfs_inode_shrinker_register(mp);
  1454. kfree(mtpt);
  1455. return 0;
  1456. out_filestream_unmount:
  1457. xfs_filestream_unmount(mp);
  1458. out_free_sb:
  1459. xfs_freesb(mp);
  1460. out_destroy_counters:
  1461. xfs_icsb_destroy_counters(mp);
  1462. xfs_close_devices(mp);
  1463. out_put_dmops:
  1464. xfs_dmops_put(mp);
  1465. out_free_fsname:
  1466. xfs_free_fsname(mp);
  1467. kfree(mtpt);
  1468. kfree(mp);
  1469. out:
  1470. return -error;
  1471. fail_vnrele:
  1472. if (sb->s_root) {
  1473. dput(sb->s_root);
  1474. sb->s_root = NULL;
  1475. } else {
  1476. iput(root);
  1477. }
  1478. fail_unmount:
  1479. /*
  1480. * Blow away any referenced inode in the filestreams cache.
  1481. * This can and will cause log traffic as inodes go inactive
  1482. * here.
  1483. */
  1484. xfs_filestream_unmount(mp);
  1485. XFS_bflush(mp->m_ddev_targp);
  1486. xfs_unmountfs(mp);
  1487. goto out_free_sb;
  1488. }
  1489. STATIC int
  1490. xfs_fs_get_sb(
  1491. struct file_system_type *fs_type,
  1492. int flags,
  1493. const char *dev_name,
  1494. void *data,
  1495. struct vfsmount *mnt)
  1496. {
  1497. return get_sb_bdev(fs_type, flags, dev_name, data, xfs_fs_fill_super,
  1498. mnt);
  1499. }
  1500. static const struct super_operations xfs_super_operations = {
  1501. .alloc_inode = xfs_fs_alloc_inode,
  1502. .destroy_inode = xfs_fs_destroy_inode,
  1503. .dirty_inode = xfs_fs_dirty_inode,
  1504. .write_inode = xfs_fs_write_inode,
  1505. .clear_inode = xfs_fs_clear_inode,
  1506. .put_super = xfs_fs_put_super,
  1507. .sync_fs = xfs_fs_sync_fs,
  1508. .freeze_fs = xfs_fs_freeze,
  1509. .unfreeze_fs = xfs_fs_unfreeze,
  1510. .statfs = xfs_fs_statfs,
  1511. .remount_fs = xfs_fs_remount,
  1512. .show_options = xfs_fs_show_options,
  1513. };
  1514. static struct file_system_type xfs_fs_type = {
  1515. .owner = THIS_MODULE,
  1516. .name = "xfs",
  1517. .get_sb = xfs_fs_get_sb,
  1518. .kill_sb = kill_block_super,
  1519. .fs_flags = FS_REQUIRES_DEV,
  1520. };
  1521. STATIC int __init
  1522. xfs_init_zones(void)
  1523. {
  1524. xfs_ioend_zone = kmem_zone_init(sizeof(xfs_ioend_t), "xfs_ioend");
  1525. if (!xfs_ioend_zone)
  1526. goto out;
  1527. xfs_ioend_pool = mempool_create_slab_pool(4 * MAX_BUF_PER_PAGE,
  1528. xfs_ioend_zone);
  1529. if (!xfs_ioend_pool)
  1530. goto out_destroy_ioend_zone;
  1531. xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
  1532. "xfs_log_ticket");
  1533. if (!xfs_log_ticket_zone)
  1534. goto out_destroy_ioend_pool;
  1535. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  1536. "xfs_bmap_free_item");
  1537. if (!xfs_bmap_free_item_zone)
  1538. goto out_destroy_log_ticket_zone;
  1539. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  1540. "xfs_btree_cur");
  1541. if (!xfs_btree_cur_zone)
  1542. goto out_destroy_bmap_free_item_zone;
  1543. xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
  1544. "xfs_da_state");
  1545. if (!xfs_da_state_zone)
  1546. goto out_destroy_btree_cur_zone;
  1547. xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
  1548. if (!xfs_dabuf_zone)
  1549. goto out_destroy_da_state_zone;
  1550. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  1551. if (!xfs_ifork_zone)
  1552. goto out_destroy_dabuf_zone;
  1553. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  1554. if (!xfs_trans_zone)
  1555. goto out_destroy_ifork_zone;
  1556. /*
  1557. * The size of the zone allocated buf log item is the maximum
  1558. * size possible under XFS. This wastes a little bit of memory,
  1559. * but it is much faster.
  1560. */
  1561. xfs_buf_item_zone = kmem_zone_init((sizeof(xfs_buf_log_item_t) +
  1562. (((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) /
  1563. NBWORD) * sizeof(int))), "xfs_buf_item");
  1564. if (!xfs_buf_item_zone)
  1565. goto out_destroy_trans_zone;
  1566. xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  1567. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  1568. sizeof(xfs_extent_t))), "xfs_efd_item");
  1569. if (!xfs_efd_zone)
  1570. goto out_destroy_buf_item_zone;
  1571. xfs_efi_zone = kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  1572. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  1573. sizeof(xfs_extent_t))), "xfs_efi_item");
  1574. if (!xfs_efi_zone)
  1575. goto out_destroy_efd_zone;
  1576. xfs_inode_zone =
  1577. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  1578. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM | KM_ZONE_SPREAD,
  1579. xfs_fs_inode_init_once);
  1580. if (!xfs_inode_zone)
  1581. goto out_destroy_efi_zone;
  1582. xfs_ili_zone =
  1583. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  1584. KM_ZONE_SPREAD, NULL);
  1585. if (!xfs_ili_zone)
  1586. goto out_destroy_inode_zone;
  1587. return 0;
  1588. out_destroy_inode_zone:
  1589. kmem_zone_destroy(xfs_inode_zone);
  1590. out_destroy_efi_zone:
  1591. kmem_zone_destroy(xfs_efi_zone);
  1592. out_destroy_efd_zone:
  1593. kmem_zone_destroy(xfs_efd_zone);
  1594. out_destroy_buf_item_zone:
  1595. kmem_zone_destroy(xfs_buf_item_zone);
  1596. out_destroy_trans_zone:
  1597. kmem_zone_destroy(xfs_trans_zone);
  1598. out_destroy_ifork_zone:
  1599. kmem_zone_destroy(xfs_ifork_zone);
  1600. out_destroy_dabuf_zone:
  1601. kmem_zone_destroy(xfs_dabuf_zone);
  1602. out_destroy_da_state_zone:
  1603. kmem_zone_destroy(xfs_da_state_zone);
  1604. out_destroy_btree_cur_zone:
  1605. kmem_zone_destroy(xfs_btree_cur_zone);
  1606. out_destroy_bmap_free_item_zone:
  1607. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1608. out_destroy_log_ticket_zone:
  1609. kmem_zone_destroy(xfs_log_ticket_zone);
  1610. out_destroy_ioend_pool:
  1611. mempool_destroy(xfs_ioend_pool);
  1612. out_destroy_ioend_zone:
  1613. kmem_zone_destroy(xfs_ioend_zone);
  1614. out:
  1615. return -ENOMEM;
  1616. }
  1617. STATIC void
  1618. xfs_destroy_zones(void)
  1619. {
  1620. kmem_zone_destroy(xfs_ili_zone);
  1621. kmem_zone_destroy(xfs_inode_zone);
  1622. kmem_zone_destroy(xfs_efi_zone);
  1623. kmem_zone_destroy(xfs_efd_zone);
  1624. kmem_zone_destroy(xfs_buf_item_zone);
  1625. kmem_zone_destroy(xfs_trans_zone);
  1626. kmem_zone_destroy(xfs_ifork_zone);
  1627. kmem_zone_destroy(xfs_dabuf_zone);
  1628. kmem_zone_destroy(xfs_da_state_zone);
  1629. kmem_zone_destroy(xfs_btree_cur_zone);
  1630. kmem_zone_destroy(xfs_bmap_free_item_zone);
  1631. kmem_zone_destroy(xfs_log_ticket_zone);
  1632. mempool_destroy(xfs_ioend_pool);
  1633. kmem_zone_destroy(xfs_ioend_zone);
  1634. }
  1635. STATIC int __init
  1636. init_xfs_fs(void)
  1637. {
  1638. int error;
  1639. printk(KERN_INFO XFS_VERSION_STRING " with "
  1640. XFS_BUILD_OPTIONS " enabled\n");
  1641. xfs_ioend_init();
  1642. xfs_dir_startup();
  1643. error = xfs_init_zones();
  1644. if (error)
  1645. goto out;
  1646. error = xfs_mru_cache_init();
  1647. if (error)
  1648. goto out_destroy_zones;
  1649. error = xfs_filestream_init();
  1650. if (error)
  1651. goto out_mru_cache_uninit;
  1652. error = xfs_buf_init();
  1653. if (error)
  1654. goto out_filestream_uninit;
  1655. error = xfs_init_procfs();
  1656. if (error)
  1657. goto out_buf_terminate;
  1658. error = xfs_sysctl_register();
  1659. if (error)
  1660. goto out_cleanup_procfs;
  1661. vfs_initquota();
  1662. error = register_filesystem(&xfs_fs_type);
  1663. if (error)
  1664. goto out_sysctl_unregister;
  1665. return 0;
  1666. out_sysctl_unregister:
  1667. xfs_sysctl_unregister();
  1668. out_cleanup_procfs:
  1669. xfs_cleanup_procfs();
  1670. out_buf_terminate:
  1671. xfs_buf_terminate();
  1672. out_filestream_uninit:
  1673. xfs_filestream_uninit();
  1674. out_mru_cache_uninit:
  1675. xfs_mru_cache_uninit();
  1676. out_destroy_zones:
  1677. xfs_destroy_zones();
  1678. out:
  1679. return error;
  1680. }
  1681. STATIC void __exit
  1682. exit_xfs_fs(void)
  1683. {
  1684. vfs_exitquota();
  1685. unregister_filesystem(&xfs_fs_type);
  1686. xfs_sysctl_unregister();
  1687. xfs_cleanup_procfs();
  1688. xfs_buf_terminate();
  1689. xfs_filestream_uninit();
  1690. xfs_mru_cache_uninit();
  1691. xfs_destroy_zones();
  1692. }
  1693. module_init(init_xfs_fs);
  1694. module_exit(exit_xfs_fs);
  1695. MODULE_AUTHOR("Silicon Graphics, Inc.");
  1696. MODULE_DESCRIPTION(XFS_VERSION_STRING " with " XFS_BUILD_OPTIONS " enabled");
  1697. MODULE_LICENSE("GPL");