xfs_super.c 50 KB

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