xfs_vfsops.c 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125
  1. /*
  2. * Copyright (c) 2000-2005 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_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_bit.h"
  22. #include "xfs_log.h"
  23. #include "xfs_inum.h"
  24. #include "xfs_trans.h"
  25. #include "xfs_sb.h"
  26. #include "xfs_ag.h"
  27. #include "xfs_dir2.h"
  28. #include "xfs_dmapi.h"
  29. #include "xfs_mount.h"
  30. #include "xfs_da_btree.h"
  31. #include "xfs_bmap_btree.h"
  32. #include "xfs_ialloc_btree.h"
  33. #include "xfs_alloc_btree.h"
  34. #include "xfs_dir2_sf.h"
  35. #include "xfs_attr_sf.h"
  36. #include "xfs_dinode.h"
  37. #include "xfs_inode.h"
  38. #include "xfs_inode_item.h"
  39. #include "xfs_btree.h"
  40. #include "xfs_alloc.h"
  41. #include "xfs_ialloc.h"
  42. #include "xfs_quota.h"
  43. #include "xfs_error.h"
  44. #include "xfs_bmap.h"
  45. #include "xfs_rw.h"
  46. #include "xfs_refcache.h"
  47. #include "xfs_buf_item.h"
  48. #include "xfs_log_priv.h"
  49. #include "xfs_dir2_trace.h"
  50. #include "xfs_extfree_item.h"
  51. #include "xfs_acl.h"
  52. #include "xfs_attr.h"
  53. #include "xfs_clnt.h"
  54. #include "xfs_mru_cache.h"
  55. #include "xfs_filestream.h"
  56. #include "xfs_fsops.h"
  57. #include "xfs_vnodeops.h"
  58. #include "xfs_vfsops.h"
  59. int
  60. xfs_init(void)
  61. {
  62. extern kmem_zone_t *xfs_bmap_free_item_zone;
  63. extern kmem_zone_t *xfs_btree_cur_zone;
  64. extern kmem_zone_t *xfs_trans_zone;
  65. extern kmem_zone_t *xfs_buf_item_zone;
  66. extern kmem_zone_t *xfs_dabuf_zone;
  67. #ifdef XFS_DABUF_DEBUG
  68. extern lock_t xfs_dabuf_global_lock;
  69. spinlock_init(&xfs_dabuf_global_lock, "xfsda");
  70. #endif
  71. /*
  72. * Initialize all of the zone allocators we use.
  73. */
  74. xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
  75. "xfs_bmap_free_item");
  76. xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
  77. "xfs_btree_cur");
  78. xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
  79. xfs_da_state_zone =
  80. kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
  81. xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
  82. xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
  83. xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
  84. xfs_mru_cache_init();
  85. xfs_filestream_init();
  86. /*
  87. * The size of the zone allocated buf log item is the maximum
  88. * size possible under XFS. This wastes a little bit of memory,
  89. * but it is much faster.
  90. */
  91. xfs_buf_item_zone =
  92. kmem_zone_init((sizeof(xfs_buf_log_item_t) +
  93. (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
  94. NBWORD) * sizeof(int))),
  95. "xfs_buf_item");
  96. xfs_efd_zone =
  97. kmem_zone_init((sizeof(xfs_efd_log_item_t) +
  98. ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
  99. sizeof(xfs_extent_t))),
  100. "xfs_efd_item");
  101. xfs_efi_zone =
  102. kmem_zone_init((sizeof(xfs_efi_log_item_t) +
  103. ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
  104. sizeof(xfs_extent_t))),
  105. "xfs_efi_item");
  106. /*
  107. * These zones warrant special memory allocator hints
  108. */
  109. xfs_inode_zone =
  110. kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
  111. KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
  112. KM_ZONE_SPREAD, NULL);
  113. xfs_ili_zone =
  114. kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
  115. KM_ZONE_SPREAD, NULL);
  116. xfs_icluster_zone =
  117. kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster",
  118. KM_ZONE_SPREAD, NULL);
  119. /*
  120. * Allocate global trace buffers.
  121. */
  122. #ifdef XFS_ALLOC_TRACE
  123. xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
  124. #endif
  125. #ifdef XFS_BMAP_TRACE
  126. xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
  127. #endif
  128. #ifdef XFS_BMBT_TRACE
  129. xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
  130. #endif
  131. #ifdef XFS_ATTR_TRACE
  132. xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
  133. #endif
  134. #ifdef XFS_DIR2_TRACE
  135. xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
  136. #endif
  137. xfs_dir_startup();
  138. #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
  139. xfs_error_test_init();
  140. #endif /* DEBUG || INDUCE_IO_ERROR */
  141. xfs_init_procfs();
  142. xfs_sysctl_register();
  143. return 0;
  144. }
  145. void
  146. xfs_cleanup(void)
  147. {
  148. extern kmem_zone_t *xfs_bmap_free_item_zone;
  149. extern kmem_zone_t *xfs_btree_cur_zone;
  150. extern kmem_zone_t *xfs_inode_zone;
  151. extern kmem_zone_t *xfs_trans_zone;
  152. extern kmem_zone_t *xfs_da_state_zone;
  153. extern kmem_zone_t *xfs_dabuf_zone;
  154. extern kmem_zone_t *xfs_efd_zone;
  155. extern kmem_zone_t *xfs_efi_zone;
  156. extern kmem_zone_t *xfs_buf_item_zone;
  157. extern kmem_zone_t *xfs_icluster_zone;
  158. xfs_cleanup_procfs();
  159. xfs_sysctl_unregister();
  160. xfs_refcache_destroy();
  161. xfs_filestream_uninit();
  162. xfs_mru_cache_uninit();
  163. xfs_acl_zone_destroy(xfs_acl_zone);
  164. #ifdef XFS_DIR2_TRACE
  165. ktrace_free(xfs_dir2_trace_buf);
  166. #endif
  167. #ifdef XFS_ATTR_TRACE
  168. ktrace_free(xfs_attr_trace_buf);
  169. #endif
  170. #ifdef XFS_BMBT_TRACE
  171. ktrace_free(xfs_bmbt_trace_buf);
  172. #endif
  173. #ifdef XFS_BMAP_TRACE
  174. ktrace_free(xfs_bmap_trace_buf);
  175. #endif
  176. #ifdef XFS_ALLOC_TRACE
  177. ktrace_free(xfs_alloc_trace_buf);
  178. #endif
  179. kmem_zone_destroy(xfs_bmap_free_item_zone);
  180. kmem_zone_destroy(xfs_btree_cur_zone);
  181. kmem_zone_destroy(xfs_inode_zone);
  182. kmem_zone_destroy(xfs_trans_zone);
  183. kmem_zone_destroy(xfs_da_state_zone);
  184. kmem_zone_destroy(xfs_dabuf_zone);
  185. kmem_zone_destroy(xfs_buf_item_zone);
  186. kmem_zone_destroy(xfs_efd_zone);
  187. kmem_zone_destroy(xfs_efi_zone);
  188. kmem_zone_destroy(xfs_ifork_zone);
  189. kmem_zone_destroy(xfs_ili_zone);
  190. kmem_zone_destroy(xfs_icluster_zone);
  191. }
  192. /*
  193. * xfs_start_flags
  194. *
  195. * This function fills in xfs_mount_t fields based on mount args.
  196. * Note: the superblock has _not_ yet been read in.
  197. */
  198. STATIC int
  199. xfs_start_flags(
  200. struct xfs_mount_args *ap,
  201. struct xfs_mount *mp)
  202. {
  203. /* Values are in BBs */
  204. if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
  205. /*
  206. * At this point the superblock has not been read
  207. * in, therefore we do not know the block size.
  208. * Before the mount call ends we will convert
  209. * these to FSBs.
  210. */
  211. mp->m_dalign = ap->sunit;
  212. mp->m_swidth = ap->swidth;
  213. }
  214. if (ap->logbufs != -1 &&
  215. ap->logbufs != 0 &&
  216. (ap->logbufs < XLOG_MIN_ICLOGS ||
  217. ap->logbufs > XLOG_MAX_ICLOGS)) {
  218. cmn_err(CE_WARN,
  219. "XFS: invalid logbufs value: %d [not %d-%d]",
  220. ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
  221. return XFS_ERROR(EINVAL);
  222. }
  223. mp->m_logbufs = ap->logbufs;
  224. if (ap->logbufsize != -1 &&
  225. ap->logbufsize != 0 &&
  226. (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
  227. ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
  228. !is_power_of_2(ap->logbufsize))) {
  229. cmn_err(CE_WARN,
  230. "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
  231. ap->logbufsize);
  232. return XFS_ERROR(EINVAL);
  233. }
  234. mp->m_logbsize = ap->logbufsize;
  235. mp->m_fsname_len = strlen(ap->fsname) + 1;
  236. mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
  237. strcpy(mp->m_fsname, ap->fsname);
  238. if (ap->rtname[0]) {
  239. mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
  240. strcpy(mp->m_rtname, ap->rtname);
  241. }
  242. if (ap->logname[0]) {
  243. mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
  244. strcpy(mp->m_logname, ap->logname);
  245. }
  246. if (ap->flags & XFSMNT_WSYNC)
  247. mp->m_flags |= XFS_MOUNT_WSYNC;
  248. #if XFS_BIG_INUMS
  249. if (ap->flags & XFSMNT_INO64) {
  250. mp->m_flags |= XFS_MOUNT_INO64;
  251. mp->m_inoadd = XFS_INO64_OFFSET;
  252. }
  253. #endif
  254. if (ap->flags & XFSMNT_RETERR)
  255. mp->m_flags |= XFS_MOUNT_RETERR;
  256. if (ap->flags & XFSMNT_NOALIGN)
  257. mp->m_flags |= XFS_MOUNT_NOALIGN;
  258. if (ap->flags & XFSMNT_SWALLOC)
  259. mp->m_flags |= XFS_MOUNT_SWALLOC;
  260. if (ap->flags & XFSMNT_OSYNCISOSYNC)
  261. mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
  262. if (ap->flags & XFSMNT_32BITINODES)
  263. mp->m_flags |= XFS_MOUNT_32BITINODES;
  264. if (ap->flags & XFSMNT_IOSIZE) {
  265. if (ap->iosizelog > XFS_MAX_IO_LOG ||
  266. ap->iosizelog < XFS_MIN_IO_LOG) {
  267. cmn_err(CE_WARN,
  268. "XFS: invalid log iosize: %d [not %d-%d]",
  269. ap->iosizelog, XFS_MIN_IO_LOG,
  270. XFS_MAX_IO_LOG);
  271. return XFS_ERROR(EINVAL);
  272. }
  273. mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
  274. mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
  275. }
  276. if (ap->flags & XFSMNT_IDELETE)
  277. mp->m_flags |= XFS_MOUNT_IDELETE;
  278. if (ap->flags & XFSMNT_DIRSYNC)
  279. mp->m_flags |= XFS_MOUNT_DIRSYNC;
  280. if (ap->flags & XFSMNT_ATTR2)
  281. mp->m_flags |= XFS_MOUNT_ATTR2;
  282. if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
  283. mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
  284. /*
  285. * no recovery flag requires a read-only mount
  286. */
  287. if (ap->flags & XFSMNT_NORECOVERY) {
  288. if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
  289. cmn_err(CE_WARN,
  290. "XFS: tried to mount a FS read-write without recovery!");
  291. return XFS_ERROR(EINVAL);
  292. }
  293. mp->m_flags |= XFS_MOUNT_NORECOVERY;
  294. }
  295. if (ap->flags & XFSMNT_NOUUID)
  296. mp->m_flags |= XFS_MOUNT_NOUUID;
  297. if (ap->flags & XFSMNT_BARRIER)
  298. mp->m_flags |= XFS_MOUNT_BARRIER;
  299. else
  300. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  301. if (ap->flags2 & XFSMNT2_FILESTREAMS)
  302. mp->m_flags |= XFS_MOUNT_FILESTREAMS;
  303. if (ap->flags & XFSMNT_DMAPI)
  304. mp->m_flags |= XFS_MOUNT_DMAPI;
  305. return 0;
  306. }
  307. /*
  308. * This function fills in xfs_mount_t fields based on mount args.
  309. * Note: the superblock _has_ now been read in.
  310. */
  311. STATIC int
  312. xfs_finish_flags(
  313. struct xfs_mount_args *ap,
  314. struct xfs_mount *mp)
  315. {
  316. int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
  317. /* Fail a mount where the logbuf is smaller then the log stripe */
  318. if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
  319. if ((ap->logbufsize <= 0) &&
  320. (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
  321. mp->m_logbsize = mp->m_sb.sb_logsunit;
  322. } else if (ap->logbufsize > 0 &&
  323. ap->logbufsize < mp->m_sb.sb_logsunit) {
  324. cmn_err(CE_WARN,
  325. "XFS: logbuf size must be greater than or equal to log stripe size");
  326. return XFS_ERROR(EINVAL);
  327. }
  328. } else {
  329. /* Fail a mount if the logbuf is larger than 32K */
  330. if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
  331. cmn_err(CE_WARN,
  332. "XFS: logbuf size for version 1 logs must be 16K or 32K");
  333. return XFS_ERROR(EINVAL);
  334. }
  335. }
  336. if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
  337. mp->m_flags |= XFS_MOUNT_ATTR2;
  338. }
  339. /*
  340. * prohibit r/w mounts of read-only filesystems
  341. */
  342. if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
  343. cmn_err(CE_WARN,
  344. "XFS: cannot mount a read-only filesystem as read-write");
  345. return XFS_ERROR(EROFS);
  346. }
  347. /*
  348. * check for shared mount.
  349. */
  350. if (ap->flags & XFSMNT_SHARED) {
  351. if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
  352. return XFS_ERROR(EINVAL);
  353. /*
  354. * For IRIX 6.5, shared mounts must have the shared
  355. * version bit set, have the persistent readonly
  356. * field set, must be version 0 and can only be mounted
  357. * read-only.
  358. */
  359. if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
  360. (mp->m_sb.sb_shared_vn != 0))
  361. return XFS_ERROR(EINVAL);
  362. mp->m_flags |= XFS_MOUNT_SHARED;
  363. /*
  364. * Shared XFS V0 can't deal with DMI. Return EINVAL.
  365. */
  366. if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
  367. return XFS_ERROR(EINVAL);
  368. }
  369. if (ap->flags & XFSMNT_UQUOTA) {
  370. mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
  371. if (ap->flags & XFSMNT_UQUOTAENF)
  372. mp->m_qflags |= XFS_UQUOTA_ENFD;
  373. }
  374. if (ap->flags & XFSMNT_GQUOTA) {
  375. mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
  376. if (ap->flags & XFSMNT_GQUOTAENF)
  377. mp->m_qflags |= XFS_OQUOTA_ENFD;
  378. } else if (ap->flags & XFSMNT_PQUOTA) {
  379. mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
  380. if (ap->flags & XFSMNT_PQUOTAENF)
  381. mp->m_qflags |= XFS_OQUOTA_ENFD;
  382. }
  383. return 0;
  384. }
  385. /*
  386. * xfs_mount
  387. *
  388. * The file system configurations are:
  389. * (1) device (partition) with data and internal log
  390. * (2) logical volume with data and log subvolumes.
  391. * (3) logical volume with data, log, and realtime subvolumes.
  392. *
  393. * We only have to handle opening the log and realtime volumes here if
  394. * they are present. The data subvolume has already been opened by
  395. * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
  396. */
  397. int
  398. xfs_mount(
  399. struct xfs_mount *mp,
  400. struct xfs_mount_args *args,
  401. cred_t *credp)
  402. {
  403. struct block_device *ddev, *logdev, *rtdev;
  404. int flags = 0, error;
  405. ddev = mp->m_super->s_bdev;
  406. logdev = rtdev = NULL;
  407. error = xfs_dmops_get(mp, args);
  408. if (error)
  409. return error;
  410. error = xfs_qmops_get(mp, args);
  411. if (error)
  412. return error;
  413. mp->m_io_ops = xfs_iocore_xfs;
  414. if (args->flags & XFSMNT_QUIET)
  415. flags |= XFS_MFSI_QUIET;
  416. /*
  417. * Open real time and log devices - order is important.
  418. */
  419. if (args->logname[0]) {
  420. error = xfs_blkdev_get(mp, args->logname, &logdev);
  421. if (error)
  422. return error;
  423. }
  424. if (args->rtname[0]) {
  425. error = xfs_blkdev_get(mp, args->rtname, &rtdev);
  426. if (error) {
  427. xfs_blkdev_put(logdev);
  428. return error;
  429. }
  430. if (rtdev == ddev || rtdev == logdev) {
  431. cmn_err(CE_WARN,
  432. "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
  433. xfs_blkdev_put(logdev);
  434. xfs_blkdev_put(rtdev);
  435. return EINVAL;
  436. }
  437. }
  438. /*
  439. * Setup xfs_mount buffer target pointers
  440. */
  441. error = ENOMEM;
  442. mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
  443. if (!mp->m_ddev_targp) {
  444. xfs_blkdev_put(logdev);
  445. xfs_blkdev_put(rtdev);
  446. return error;
  447. }
  448. if (rtdev) {
  449. mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
  450. if (!mp->m_rtdev_targp) {
  451. xfs_blkdev_put(logdev);
  452. xfs_blkdev_put(rtdev);
  453. goto error0;
  454. }
  455. }
  456. mp->m_logdev_targp = (logdev && logdev != ddev) ?
  457. xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
  458. if (!mp->m_logdev_targp) {
  459. xfs_blkdev_put(logdev);
  460. xfs_blkdev_put(rtdev);
  461. goto error0;
  462. }
  463. /*
  464. * Setup flags based on mount(2) options and then the superblock
  465. */
  466. error = xfs_start_flags(args, mp);
  467. if (error)
  468. goto error1;
  469. error = xfs_readsb(mp, flags);
  470. if (error)
  471. goto error1;
  472. error = xfs_finish_flags(args, mp);
  473. if (error)
  474. goto error2;
  475. /*
  476. * Setup xfs_mount buffer target pointers based on superblock
  477. */
  478. error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
  479. mp->m_sb.sb_sectsize);
  480. if (!error && logdev && logdev != ddev) {
  481. unsigned int log_sector_size = BBSIZE;
  482. if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
  483. log_sector_size = mp->m_sb.sb_logsectsize;
  484. error = xfs_setsize_buftarg(mp->m_logdev_targp,
  485. mp->m_sb.sb_blocksize,
  486. log_sector_size);
  487. }
  488. if (!error && rtdev)
  489. error = xfs_setsize_buftarg(mp->m_rtdev_targp,
  490. mp->m_sb.sb_blocksize,
  491. mp->m_sb.sb_sectsize);
  492. if (error)
  493. goto error2;
  494. if (mp->m_flags & XFS_MOUNT_BARRIER)
  495. xfs_mountfs_check_barriers(mp);
  496. if ((error = xfs_filestream_mount(mp)))
  497. goto error2;
  498. error = XFS_IOINIT(mp, args, flags);
  499. if (error)
  500. goto error2;
  501. XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
  502. return 0;
  503. error2:
  504. if (mp->m_sb_bp)
  505. xfs_freesb(mp);
  506. error1:
  507. xfs_binval(mp->m_ddev_targp);
  508. if (logdev && logdev != ddev)
  509. xfs_binval(mp->m_logdev_targp);
  510. if (rtdev)
  511. xfs_binval(mp->m_rtdev_targp);
  512. error0:
  513. xfs_unmountfs_close(mp, credp);
  514. xfs_qmops_put(mp);
  515. xfs_dmops_put(mp);
  516. return error;
  517. }
  518. int
  519. xfs_unmount(
  520. xfs_mount_t *mp,
  521. int flags,
  522. cred_t *credp)
  523. {
  524. xfs_inode_t *rip;
  525. bhv_vnode_t *rvp;
  526. int unmount_event_wanted = 0;
  527. int unmount_event_flags = 0;
  528. int xfs_unmountfs_needed = 0;
  529. int error;
  530. rip = mp->m_rootip;
  531. rvp = XFS_ITOV(rip);
  532. #ifdef HAVE_DMAPI
  533. if (mp->m_flags & XFS_MOUNT_DMAPI) {
  534. error = XFS_SEND_PREUNMOUNT(mp,
  535. rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
  536. NULL, NULL, 0, 0,
  537. (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
  538. 0:DM_FLAGS_UNWANTED);
  539. if (error)
  540. return XFS_ERROR(error);
  541. unmount_event_wanted = 1;
  542. unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
  543. 0 : DM_FLAGS_UNWANTED;
  544. }
  545. #endif
  546. /*
  547. * First blow any referenced inode from this file system
  548. * out of the reference cache, and delete the timer.
  549. */
  550. xfs_refcache_purge_mp(mp);
  551. /*
  552. * Blow away any referenced inode in the filestreams cache.
  553. * This can and will cause log traffic as inodes go inactive
  554. * here.
  555. */
  556. xfs_filestream_unmount(mp);
  557. XFS_bflush(mp->m_ddev_targp);
  558. error = xfs_unmount_flush(mp, 0);
  559. if (error)
  560. goto out;
  561. ASSERT(vn_count(rvp) == 1);
  562. /*
  563. * Drop the reference count
  564. */
  565. VN_RELE(rvp);
  566. /*
  567. * If we're forcing a shutdown, typically because of a media error,
  568. * we want to make sure we invalidate dirty pages that belong to
  569. * referenced vnodes as well.
  570. */
  571. if (XFS_FORCED_SHUTDOWN(mp)) {
  572. error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
  573. ASSERT(error != EFSCORRUPTED);
  574. }
  575. xfs_unmountfs_needed = 1;
  576. out:
  577. /* Send DMAPI event, if required.
  578. * Then do xfs_unmountfs() if needed.
  579. * Then return error (or zero).
  580. */
  581. if (unmount_event_wanted) {
  582. /* Note: mp structure must still exist for
  583. * XFS_SEND_UNMOUNT() call.
  584. */
  585. XFS_SEND_UNMOUNT(mp, error == 0 ? rvp : NULL,
  586. DM_RIGHT_NULL, 0, error, unmount_event_flags);
  587. }
  588. if (xfs_unmountfs_needed) {
  589. /*
  590. * Call common unmount function to flush to disk
  591. * and free the super block buffer & mount structures.
  592. */
  593. xfs_unmountfs(mp, credp);
  594. xfs_qmops_put(mp);
  595. xfs_dmops_put(mp);
  596. kmem_free(mp, sizeof(xfs_mount_t));
  597. }
  598. return XFS_ERROR(error);
  599. }
  600. STATIC int
  601. xfs_quiesce_fs(
  602. xfs_mount_t *mp)
  603. {
  604. int count = 0, pincount;
  605. xfs_refcache_purge_mp(mp);
  606. xfs_flush_buftarg(mp->m_ddev_targp, 0);
  607. xfs_finish_reclaim_all(mp, 0);
  608. /* This loop must run at least twice.
  609. * The first instance of the loop will flush
  610. * most meta data but that will generate more
  611. * meta data (typically directory updates).
  612. * Which then must be flushed and logged before
  613. * we can write the unmount record.
  614. */
  615. do {
  616. xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
  617. pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
  618. if (!pincount) {
  619. delay(50);
  620. count++;
  621. }
  622. } while (count < 2);
  623. return 0;
  624. }
  625. /*
  626. * Second stage of a quiesce. The data is already synced, now we have to take
  627. * care of the metadata. New transactions are already blocked, so we need to
  628. * wait for any remaining transactions to drain out before proceding.
  629. */
  630. STATIC void
  631. xfs_attr_quiesce(
  632. xfs_mount_t *mp)
  633. {
  634. /* wait for all modifications to complete */
  635. while (atomic_read(&mp->m_active_trans) > 0)
  636. delay(100);
  637. /* flush inodes and push all remaining buffers out to disk */
  638. xfs_quiesce_fs(mp);
  639. ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
  640. /* Push the superblock and write an unmount record */
  641. xfs_log_sbcount(mp, 1);
  642. xfs_log_unmount_write(mp);
  643. xfs_unmountfs_writesb(mp);
  644. }
  645. int
  646. xfs_mntupdate(
  647. struct xfs_mount *mp,
  648. int *flags,
  649. struct xfs_mount_args *args)
  650. {
  651. if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
  652. if (mp->m_flags & XFS_MOUNT_RDONLY)
  653. mp->m_flags &= ~XFS_MOUNT_RDONLY;
  654. if (args->flags & XFSMNT_BARRIER) {
  655. mp->m_flags |= XFS_MOUNT_BARRIER;
  656. xfs_mountfs_check_barriers(mp);
  657. } else {
  658. mp->m_flags &= ~XFS_MOUNT_BARRIER;
  659. }
  660. } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
  661. xfs_filestream_flush(mp);
  662. xfs_sync(mp, SYNC_DATA_QUIESCE);
  663. xfs_attr_quiesce(mp);
  664. mp->m_flags |= XFS_MOUNT_RDONLY;
  665. }
  666. return 0;
  667. }
  668. /*
  669. * xfs_unmount_flush implements a set of flush operation on special
  670. * inodes, which are needed as a separate set of operations so that
  671. * they can be called as part of relocation process.
  672. */
  673. int
  674. xfs_unmount_flush(
  675. xfs_mount_t *mp, /* Mount structure we are getting
  676. rid of. */
  677. int relocation) /* Called from vfs relocation. */
  678. {
  679. xfs_inode_t *rip = mp->m_rootip;
  680. xfs_inode_t *rbmip;
  681. xfs_inode_t *rsumip = NULL;
  682. bhv_vnode_t *rvp = XFS_ITOV(rip);
  683. int error;
  684. xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
  685. xfs_iflock(rip);
  686. /*
  687. * Flush out the real time inodes.
  688. */
  689. if ((rbmip = mp->m_rbmip) != NULL) {
  690. xfs_ilock(rbmip, XFS_ILOCK_EXCL);
  691. xfs_iflock(rbmip);
  692. error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
  693. xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
  694. if (error == EFSCORRUPTED)
  695. goto fscorrupt_out;
  696. ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
  697. rsumip = mp->m_rsumip;
  698. xfs_ilock(rsumip, XFS_ILOCK_EXCL);
  699. xfs_iflock(rsumip);
  700. error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
  701. xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
  702. if (error == EFSCORRUPTED)
  703. goto fscorrupt_out;
  704. ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
  705. }
  706. /*
  707. * Synchronously flush root inode to disk
  708. */
  709. error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
  710. if (error == EFSCORRUPTED)
  711. goto fscorrupt_out2;
  712. if (vn_count(rvp) != 1 && !relocation) {
  713. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  714. return XFS_ERROR(EBUSY);
  715. }
  716. /*
  717. * Release dquot that rootinode, rbmino and rsumino might be holding,
  718. * flush and purge the quota inodes.
  719. */
  720. error = XFS_QM_UNMOUNT(mp);
  721. if (error == EFSCORRUPTED)
  722. goto fscorrupt_out2;
  723. if (rbmip) {
  724. VN_RELE(XFS_ITOV(rbmip));
  725. VN_RELE(XFS_ITOV(rsumip));
  726. }
  727. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  728. return 0;
  729. fscorrupt_out:
  730. xfs_ifunlock(rip);
  731. fscorrupt_out2:
  732. xfs_iunlock(rip, XFS_ILOCK_EXCL);
  733. return XFS_ERROR(EFSCORRUPTED);
  734. }
  735. /*
  736. * xfs_root extracts the root vnode from a vfs.
  737. *
  738. * vfsp -- the vfs struct for the desired file system
  739. * vpp -- address of the caller's vnode pointer which should be
  740. * set to the desired fs root vnode
  741. */
  742. int
  743. xfs_root(
  744. xfs_mount_t *mp,
  745. bhv_vnode_t **vpp)
  746. {
  747. bhv_vnode_t *vp;
  748. vp = XFS_ITOV(mp->m_rootip);
  749. VN_HOLD(vp);
  750. *vpp = vp;
  751. return 0;
  752. }
  753. /*
  754. * xfs_statvfs
  755. *
  756. * Fill in the statvfs structure for the given file system. We use
  757. * the superblock lock in the mount structure to ensure a consistent
  758. * snapshot of the counters returned.
  759. */
  760. int
  761. xfs_statvfs(
  762. xfs_mount_t *mp,
  763. bhv_statvfs_t *statp,
  764. bhv_vnode_t *vp)
  765. {
  766. __uint64_t fakeinos;
  767. xfs_extlen_t lsize;
  768. xfs_sb_t *sbp;
  769. unsigned long s;
  770. sbp = &(mp->m_sb);
  771. statp->f_type = XFS_SB_MAGIC;
  772. xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
  773. s = XFS_SB_LOCK(mp);
  774. statp->f_bsize = sbp->sb_blocksize;
  775. lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
  776. statp->f_blocks = sbp->sb_dblocks - lsize;
  777. statp->f_bfree = statp->f_bavail =
  778. sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
  779. fakeinos = statp->f_bfree << sbp->sb_inopblog;
  780. #if XFS_BIG_INUMS
  781. fakeinos += mp->m_inoadd;
  782. #endif
  783. statp->f_files =
  784. MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
  785. if (mp->m_maxicount)
  786. #if XFS_BIG_INUMS
  787. if (!mp->m_inoadd)
  788. #endif
  789. statp->f_files = min_t(typeof(statp->f_files),
  790. statp->f_files,
  791. mp->m_maxicount);
  792. statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
  793. XFS_SB_UNLOCK(mp, s);
  794. xfs_statvfs_fsid(statp, mp);
  795. statp->f_namelen = MAXNAMELEN - 1;
  796. if (vp)
  797. XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
  798. return 0;
  799. }
  800. /*
  801. * xfs_sync flushes any pending I/O to file system vfsp.
  802. *
  803. * This routine is called by vfs_sync() to make sure that things make it
  804. * out to disk eventually, on sync() system calls to flush out everything,
  805. * and when the file system is unmounted. For the vfs_sync() case, all
  806. * we really need to do is sync out the log to make all of our meta-data
  807. * updates permanent (except for timestamps). For calls from pflushd(),
  808. * dirty pages are kept moving by calling pdflush() on the inodes
  809. * containing them. We also flush the inodes that we can lock without
  810. * sleeping and the superblock if we can lock it without sleeping from
  811. * vfs_sync() so that items at the tail of the log are always moving out.
  812. *
  813. * Flags:
  814. * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
  815. * to sleep if we can help it. All we really need
  816. * to do is ensure that the log is synced at least
  817. * periodically. We also push the inodes and
  818. * superblock if we can lock them without sleeping
  819. * and they are not pinned.
  820. * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
  821. * set, then we really want to lock each inode and flush
  822. * it.
  823. * SYNC_WAIT - All the flushes that take place in this call should
  824. * be synchronous.
  825. * SYNC_DELWRI - This tells us to push dirty pages associated with
  826. * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
  827. * determine if they should be flushed sync, async, or
  828. * delwri.
  829. * SYNC_CLOSE - This flag is passed when the system is being
  830. * unmounted. We should sync and invalidate everything.
  831. * SYNC_FSDATA - This indicates that the caller would like to make
  832. * sure the superblock is safe on disk. We can ensure
  833. * this by simply making sure the log gets flushed
  834. * if SYNC_BDFLUSH is set, and by actually writing it
  835. * out otherwise.
  836. * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
  837. * before we return (including direct I/O). Forms the drain
  838. * side of the write barrier needed to safely quiesce the
  839. * filesystem.
  840. *
  841. */
  842. int
  843. xfs_sync(
  844. xfs_mount_t *mp,
  845. int flags)
  846. {
  847. int error;
  848. /*
  849. * Get the Quota Manager to flush the dquots.
  850. *
  851. * If XFS quota support is not enabled or this filesystem
  852. * instance does not use quotas XFS_QM_DQSYNC will always
  853. * return zero.
  854. */
  855. error = XFS_QM_DQSYNC(mp, flags);
  856. if (error) {
  857. /*
  858. * If we got an IO error, we will be shutting down.
  859. * So, there's nothing more for us to do here.
  860. */
  861. ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
  862. if (XFS_FORCED_SHUTDOWN(mp))
  863. return XFS_ERROR(error);
  864. }
  865. if (flags & SYNC_IOWAIT)
  866. xfs_filestream_flush(mp);
  867. return xfs_syncsub(mp, flags, NULL);
  868. }
  869. /*
  870. * xfs sync routine for internal use
  871. *
  872. * This routine supports all of the flags defined for the generic vfs_sync
  873. * interface as explained above under xfs_sync.
  874. *
  875. */
  876. int
  877. xfs_sync_inodes(
  878. xfs_mount_t *mp,
  879. int flags,
  880. int *bypassed)
  881. {
  882. xfs_inode_t *ip = NULL;
  883. xfs_inode_t *ip_next;
  884. xfs_buf_t *bp;
  885. bhv_vnode_t *vp = NULL;
  886. int error;
  887. int last_error;
  888. uint64_t fflag;
  889. uint lock_flags;
  890. uint base_lock_flags;
  891. boolean_t mount_locked;
  892. boolean_t vnode_refed;
  893. int preempt;
  894. xfs_dinode_t *dip;
  895. xfs_iptr_t *ipointer;
  896. #ifdef DEBUG
  897. boolean_t ipointer_in = B_FALSE;
  898. #define IPOINTER_SET ipointer_in = B_TRUE
  899. #define IPOINTER_CLR ipointer_in = B_FALSE
  900. #else
  901. #define IPOINTER_SET
  902. #define IPOINTER_CLR
  903. #endif
  904. /* Insert a marker record into the inode list after inode ip. The list
  905. * must be locked when this is called. After the call the list will no
  906. * longer be locked.
  907. */
  908. #define IPOINTER_INSERT(ip, mp) { \
  909. ASSERT(ipointer_in == B_FALSE); \
  910. ipointer->ip_mnext = ip->i_mnext; \
  911. ipointer->ip_mprev = ip; \
  912. ip->i_mnext = (xfs_inode_t *)ipointer; \
  913. ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
  914. preempt = 0; \
  915. XFS_MOUNT_IUNLOCK(mp); \
  916. mount_locked = B_FALSE; \
  917. IPOINTER_SET; \
  918. }
  919. /* Remove the marker from the inode list. If the marker was the only item
  920. * in the list then there are no remaining inodes and we should zero out
  921. * the whole list. If we are the current head of the list then move the head
  922. * past us.
  923. */
  924. #define IPOINTER_REMOVE(ip, mp) { \
  925. ASSERT(ipointer_in == B_TRUE); \
  926. if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
  927. ip = ipointer->ip_mnext; \
  928. ip->i_mprev = ipointer->ip_mprev; \
  929. ipointer->ip_mprev->i_mnext = ip; \
  930. if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
  931. mp->m_inodes = ip; \
  932. } \
  933. } else { \
  934. ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
  935. mp->m_inodes = NULL; \
  936. ip = NULL; \
  937. } \
  938. IPOINTER_CLR; \
  939. }
  940. #define XFS_PREEMPT_MASK 0x7f
  941. if (bypassed)
  942. *bypassed = 0;
  943. if (mp->m_flags & XFS_MOUNT_RDONLY)
  944. return 0;
  945. error = 0;
  946. last_error = 0;
  947. preempt = 0;
  948. /* Allocate a reference marker */
  949. ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
  950. fflag = XFS_B_ASYNC; /* default is don't wait */
  951. if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
  952. fflag = XFS_B_DELWRI;
  953. if (flags & SYNC_WAIT)
  954. fflag = 0; /* synchronous overrides all */
  955. base_lock_flags = XFS_ILOCK_SHARED;
  956. if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
  957. /*
  958. * We need the I/O lock if we're going to call any of
  959. * the flush/inval routines.
  960. */
  961. base_lock_flags |= XFS_IOLOCK_SHARED;
  962. }
  963. XFS_MOUNT_ILOCK(mp);
  964. ip = mp->m_inodes;
  965. mount_locked = B_TRUE;
  966. vnode_refed = B_FALSE;
  967. IPOINTER_CLR;
  968. do {
  969. ASSERT(ipointer_in == B_FALSE);
  970. ASSERT(vnode_refed == B_FALSE);
  971. lock_flags = base_lock_flags;
  972. /*
  973. * There were no inodes in the list, just break out
  974. * of the loop.
  975. */
  976. if (ip == NULL) {
  977. break;
  978. }
  979. /*
  980. * We found another sync thread marker - skip it
  981. */
  982. if (ip->i_mount == NULL) {
  983. ip = ip->i_mnext;
  984. continue;
  985. }
  986. vp = XFS_ITOV_NULL(ip);
  987. /*
  988. * If the vnode is gone then this is being torn down,
  989. * call reclaim if it is flushed, else let regular flush
  990. * code deal with it later in the loop.
  991. */
  992. if (vp == NULL) {
  993. /* Skip ones already in reclaim */
  994. if (ip->i_flags & XFS_IRECLAIM) {
  995. ip = ip->i_mnext;
  996. continue;
  997. }
  998. if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
  999. ip = ip->i_mnext;
  1000. } else if ((xfs_ipincount(ip) == 0) &&
  1001. xfs_iflock_nowait(ip)) {
  1002. IPOINTER_INSERT(ip, mp);
  1003. xfs_finish_reclaim(ip, 1,
  1004. XFS_IFLUSH_DELWRI_ELSE_ASYNC);
  1005. XFS_MOUNT_ILOCK(mp);
  1006. mount_locked = B_TRUE;
  1007. IPOINTER_REMOVE(ip, mp);
  1008. } else {
  1009. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  1010. ip = ip->i_mnext;
  1011. }
  1012. continue;
  1013. }
  1014. if (VN_BAD(vp)) {
  1015. ip = ip->i_mnext;
  1016. continue;
  1017. }
  1018. if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
  1019. XFS_MOUNT_IUNLOCK(mp);
  1020. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1021. return 0;
  1022. }
  1023. /*
  1024. * If this is just vfs_sync() or pflushd() calling
  1025. * then we can skip inodes for which it looks like
  1026. * there is nothing to do. Since we don't have the
  1027. * inode locked this is racy, but these are periodic
  1028. * calls so it doesn't matter. For the others we want
  1029. * to know for sure, so we at least try to lock them.
  1030. */
  1031. if (flags & SYNC_BDFLUSH) {
  1032. if (((ip->i_itemp == NULL) ||
  1033. !(ip->i_itemp->ili_format.ilf_fields &
  1034. XFS_ILOG_ALL)) &&
  1035. (ip->i_update_core == 0)) {
  1036. ip = ip->i_mnext;
  1037. continue;
  1038. }
  1039. }
  1040. /*
  1041. * Try to lock without sleeping. We're out of order with
  1042. * the inode list lock here, so if we fail we need to drop
  1043. * the mount lock and try again. If we're called from
  1044. * bdflush() here, then don't bother.
  1045. *
  1046. * The inode lock here actually coordinates with the
  1047. * almost spurious inode lock in xfs_ireclaim() to prevent
  1048. * the vnode we handle here without a reference from
  1049. * being freed while we reference it. If we lock the inode
  1050. * while it's on the mount list here, then the spurious inode
  1051. * lock in xfs_ireclaim() after the inode is pulled from
  1052. * the mount list will sleep until we release it here.
  1053. * This keeps the vnode from being freed while we reference
  1054. * it.
  1055. */
  1056. if (xfs_ilock_nowait(ip, lock_flags) == 0) {
  1057. if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
  1058. ip = ip->i_mnext;
  1059. continue;
  1060. }
  1061. vp = vn_grab(vp);
  1062. if (vp == NULL) {
  1063. ip = ip->i_mnext;
  1064. continue;
  1065. }
  1066. IPOINTER_INSERT(ip, mp);
  1067. xfs_ilock(ip, lock_flags);
  1068. ASSERT(vp == XFS_ITOV(ip));
  1069. ASSERT(ip->i_mount == mp);
  1070. vnode_refed = B_TRUE;
  1071. }
  1072. /* From here on in the loop we may have a marker record
  1073. * in the inode list.
  1074. */
  1075. /*
  1076. * If we have to flush data or wait for I/O completion
  1077. * we need to drop the ilock that we currently hold.
  1078. * If we need to drop the lock, insert a marker if we
  1079. * have not already done so.
  1080. */
  1081. if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
  1082. ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
  1083. if (mount_locked) {
  1084. IPOINTER_INSERT(ip, mp);
  1085. }
  1086. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1087. if (flags & SYNC_CLOSE) {
  1088. /* Shutdown case. Flush and invalidate. */
  1089. if (XFS_FORCED_SHUTDOWN(mp))
  1090. xfs_tosspages(ip, 0, -1,
  1091. FI_REMAPF);
  1092. else
  1093. error = xfs_flushinval_pages(ip,
  1094. 0, -1, FI_REMAPF);
  1095. } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
  1096. error = xfs_flush_pages(ip, 0,
  1097. -1, fflag, FI_NONE);
  1098. }
  1099. /*
  1100. * When freezing, we need to wait ensure all I/O (including direct
  1101. * I/O) is complete to ensure no further data modification can take
  1102. * place after this point
  1103. */
  1104. if (flags & SYNC_IOWAIT)
  1105. vn_iowait(ip);
  1106. xfs_ilock(ip, XFS_ILOCK_SHARED);
  1107. }
  1108. if (flags & SYNC_BDFLUSH) {
  1109. if ((flags & SYNC_ATTR) &&
  1110. ((ip->i_update_core) ||
  1111. ((ip->i_itemp != NULL) &&
  1112. (ip->i_itemp->ili_format.ilf_fields != 0)))) {
  1113. /* Insert marker and drop lock if not already
  1114. * done.
  1115. */
  1116. if (mount_locked) {
  1117. IPOINTER_INSERT(ip, mp);
  1118. }
  1119. /*
  1120. * We don't want the periodic flushing of the
  1121. * inodes by vfs_sync() to interfere with
  1122. * I/O to the file, especially read I/O
  1123. * where it is only the access time stamp
  1124. * that is being flushed out. To prevent
  1125. * long periods where we have both inode
  1126. * locks held shared here while reading the
  1127. * inode's buffer in from disk, we drop the
  1128. * inode lock while reading in the inode
  1129. * buffer. We have to release the buffer
  1130. * and reacquire the inode lock so that they
  1131. * are acquired in the proper order (inode
  1132. * locks first). The buffer will go at the
  1133. * end of the lru chain, though, so we can
  1134. * expect it to still be there when we go
  1135. * for it again in xfs_iflush().
  1136. */
  1137. if ((xfs_ipincount(ip) == 0) &&
  1138. xfs_iflock_nowait(ip)) {
  1139. xfs_ifunlock(ip);
  1140. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1141. error = xfs_itobp(mp, NULL, ip,
  1142. &dip, &bp, 0, 0);
  1143. if (!error) {
  1144. xfs_buf_relse(bp);
  1145. } else {
  1146. /* Bailing out, remove the
  1147. * marker and free it.
  1148. */
  1149. XFS_MOUNT_ILOCK(mp);
  1150. IPOINTER_REMOVE(ip, mp);
  1151. XFS_MOUNT_IUNLOCK(mp);
  1152. ASSERT(!(lock_flags &
  1153. XFS_IOLOCK_SHARED));
  1154. kmem_free(ipointer,
  1155. sizeof(xfs_iptr_t));
  1156. return (0);
  1157. }
  1158. /*
  1159. * Since we dropped the inode lock,
  1160. * the inode may have been reclaimed.
  1161. * Therefore, we reacquire the mount
  1162. * lock and check to see if we were the
  1163. * inode reclaimed. If this happened
  1164. * then the ipointer marker will no
  1165. * longer point back at us. In this
  1166. * case, move ip along to the inode
  1167. * after the marker, remove the marker
  1168. * and continue.
  1169. */
  1170. XFS_MOUNT_ILOCK(mp);
  1171. mount_locked = B_TRUE;
  1172. if (ip != ipointer->ip_mprev) {
  1173. IPOINTER_REMOVE(ip, mp);
  1174. ASSERT(!vnode_refed);
  1175. ASSERT(!(lock_flags &
  1176. XFS_IOLOCK_SHARED));
  1177. continue;
  1178. }
  1179. ASSERT(ip->i_mount == mp);
  1180. if (xfs_ilock_nowait(ip,
  1181. XFS_ILOCK_SHARED) == 0) {
  1182. ASSERT(ip->i_mount == mp);
  1183. /*
  1184. * We failed to reacquire
  1185. * the inode lock without
  1186. * sleeping, so just skip
  1187. * the inode for now. We
  1188. * clear the ILOCK bit from
  1189. * the lock_flags so that we
  1190. * won't try to drop a lock
  1191. * we don't hold below.
  1192. */
  1193. lock_flags &= ~XFS_ILOCK_SHARED;
  1194. IPOINTER_REMOVE(ip_next, mp);
  1195. } else if ((xfs_ipincount(ip) == 0) &&
  1196. xfs_iflock_nowait(ip)) {
  1197. ASSERT(ip->i_mount == mp);
  1198. /*
  1199. * Since this is vfs_sync()
  1200. * calling we only flush the
  1201. * inode out if we can lock
  1202. * it without sleeping and
  1203. * it is not pinned. Drop
  1204. * the mount lock here so
  1205. * that we don't hold it for
  1206. * too long. We already have
  1207. * a marker in the list here.
  1208. */
  1209. XFS_MOUNT_IUNLOCK(mp);
  1210. mount_locked = B_FALSE;
  1211. error = xfs_iflush(ip,
  1212. XFS_IFLUSH_DELWRI);
  1213. } else {
  1214. ASSERT(ip->i_mount == mp);
  1215. IPOINTER_REMOVE(ip_next, mp);
  1216. }
  1217. }
  1218. }
  1219. } else {
  1220. if ((flags & SYNC_ATTR) &&
  1221. ((ip->i_update_core) ||
  1222. ((ip->i_itemp != NULL) &&
  1223. (ip->i_itemp->ili_format.ilf_fields != 0)))) {
  1224. if (mount_locked) {
  1225. IPOINTER_INSERT(ip, mp);
  1226. }
  1227. if (flags & SYNC_WAIT) {
  1228. xfs_iflock(ip);
  1229. error = xfs_iflush(ip,
  1230. XFS_IFLUSH_SYNC);
  1231. } else {
  1232. /*
  1233. * If we can't acquire the flush
  1234. * lock, then the inode is already
  1235. * being flushed so don't bother
  1236. * waiting. If we can lock it then
  1237. * do a delwri flush so we can
  1238. * combine multiple inode flushes
  1239. * in each disk write.
  1240. */
  1241. if (xfs_iflock_nowait(ip)) {
  1242. error = xfs_iflush(ip,
  1243. XFS_IFLUSH_DELWRI);
  1244. }
  1245. else if (bypassed)
  1246. (*bypassed)++;
  1247. }
  1248. }
  1249. }
  1250. if (lock_flags != 0) {
  1251. xfs_iunlock(ip, lock_flags);
  1252. }
  1253. if (vnode_refed) {
  1254. /*
  1255. * If we had to take a reference on the vnode
  1256. * above, then wait until after we've unlocked
  1257. * the inode to release the reference. This is
  1258. * because we can be already holding the inode
  1259. * lock when VN_RELE() calls xfs_inactive().
  1260. *
  1261. * Make sure to drop the mount lock before calling
  1262. * VN_RELE() so that we don't trip over ourselves if
  1263. * we have to go for the mount lock again in the
  1264. * inactive code.
  1265. */
  1266. if (mount_locked) {
  1267. IPOINTER_INSERT(ip, mp);
  1268. }
  1269. VN_RELE(vp);
  1270. vnode_refed = B_FALSE;
  1271. }
  1272. if (error) {
  1273. last_error = error;
  1274. }
  1275. /*
  1276. * bail out if the filesystem is corrupted.
  1277. */
  1278. if (error == EFSCORRUPTED) {
  1279. if (!mount_locked) {
  1280. XFS_MOUNT_ILOCK(mp);
  1281. IPOINTER_REMOVE(ip, mp);
  1282. }
  1283. XFS_MOUNT_IUNLOCK(mp);
  1284. ASSERT(ipointer_in == B_FALSE);
  1285. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1286. return XFS_ERROR(error);
  1287. }
  1288. /* Let other threads have a chance at the mount lock
  1289. * if we have looped many times without dropping the
  1290. * lock.
  1291. */
  1292. if ((++preempt & XFS_PREEMPT_MASK) == 0) {
  1293. if (mount_locked) {
  1294. IPOINTER_INSERT(ip, mp);
  1295. }
  1296. }
  1297. if (mount_locked == B_FALSE) {
  1298. XFS_MOUNT_ILOCK(mp);
  1299. mount_locked = B_TRUE;
  1300. IPOINTER_REMOVE(ip, mp);
  1301. continue;
  1302. }
  1303. ASSERT(ipointer_in == B_FALSE);
  1304. ip = ip->i_mnext;
  1305. } while (ip != mp->m_inodes);
  1306. XFS_MOUNT_IUNLOCK(mp);
  1307. ASSERT(ipointer_in == B_FALSE);
  1308. kmem_free(ipointer, sizeof(xfs_iptr_t));
  1309. return XFS_ERROR(last_error);
  1310. }
  1311. /*
  1312. * xfs sync routine for internal use
  1313. *
  1314. * This routine supports all of the flags defined for the generic vfs_sync
  1315. * interface as explained above under xfs_sync.
  1316. *
  1317. */
  1318. int
  1319. xfs_syncsub(
  1320. xfs_mount_t *mp,
  1321. int flags,
  1322. int *bypassed)
  1323. {
  1324. int error = 0;
  1325. int last_error = 0;
  1326. uint log_flags = XFS_LOG_FORCE;
  1327. xfs_buf_t *bp;
  1328. xfs_buf_log_item_t *bip;
  1329. /*
  1330. * Sync out the log. This ensures that the log is periodically
  1331. * flushed even if there is not enough activity to fill it up.
  1332. */
  1333. if (flags & SYNC_WAIT)
  1334. log_flags |= XFS_LOG_SYNC;
  1335. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1336. if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
  1337. if (flags & SYNC_BDFLUSH)
  1338. xfs_finish_reclaim_all(mp, 1);
  1339. else
  1340. error = xfs_sync_inodes(mp, flags, bypassed);
  1341. }
  1342. /*
  1343. * Flushing out dirty data above probably generated more
  1344. * log activity, so if this isn't vfs_sync() then flush
  1345. * the log again.
  1346. */
  1347. if (flags & SYNC_DELWRI) {
  1348. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1349. }
  1350. if (flags & SYNC_FSDATA) {
  1351. /*
  1352. * If this is vfs_sync() then only sync the superblock
  1353. * if we can lock it without sleeping and it is not pinned.
  1354. */
  1355. if (flags & SYNC_BDFLUSH) {
  1356. bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
  1357. if (bp != NULL) {
  1358. bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
  1359. if ((bip != NULL) &&
  1360. xfs_buf_item_dirty(bip)) {
  1361. if (!(XFS_BUF_ISPINNED(bp))) {
  1362. XFS_BUF_ASYNC(bp);
  1363. error = xfs_bwrite(mp, bp);
  1364. } else {
  1365. xfs_buf_relse(bp);
  1366. }
  1367. } else {
  1368. xfs_buf_relse(bp);
  1369. }
  1370. }
  1371. } else {
  1372. bp = xfs_getsb(mp, 0);
  1373. /*
  1374. * If the buffer is pinned then push on the log so
  1375. * we won't get stuck waiting in the write for
  1376. * someone, maybe ourselves, to flush the log.
  1377. * Even though we just pushed the log above, we
  1378. * did not have the superblock buffer locked at
  1379. * that point so it can become pinned in between
  1380. * there and here.
  1381. */
  1382. if (XFS_BUF_ISPINNED(bp))
  1383. xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
  1384. if (flags & SYNC_WAIT)
  1385. XFS_BUF_UNASYNC(bp);
  1386. else
  1387. XFS_BUF_ASYNC(bp);
  1388. error = xfs_bwrite(mp, bp);
  1389. }
  1390. if (error) {
  1391. last_error = error;
  1392. }
  1393. }
  1394. /*
  1395. * If this is the periodic sync, then kick some entries out of
  1396. * the reference cache. This ensures that idle entries are
  1397. * eventually kicked out of the cache.
  1398. */
  1399. if (flags & SYNC_REFCACHE) {
  1400. if (flags & SYNC_WAIT)
  1401. xfs_refcache_purge_mp(mp);
  1402. else
  1403. xfs_refcache_purge_some(mp);
  1404. }
  1405. /*
  1406. * If asked, update the disk superblock with incore counter values if we
  1407. * are using non-persistent counters so that they don't get too far out
  1408. * of sync if we crash or get a forced shutdown. We don't want to force
  1409. * this to disk, just get a transaction into the iclogs....
  1410. */
  1411. if (flags & SYNC_SUPER)
  1412. xfs_log_sbcount(mp, 0);
  1413. /*
  1414. * Now check to see if the log needs a "dummy" transaction.
  1415. */
  1416. if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
  1417. xfs_trans_t *tp;
  1418. xfs_inode_t *ip;
  1419. /*
  1420. * Put a dummy transaction in the log to tell
  1421. * recovery that all others are OK.
  1422. */
  1423. tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
  1424. if ((error = xfs_trans_reserve(tp, 0,
  1425. XFS_ICHANGE_LOG_RES(mp),
  1426. 0, 0, 0))) {
  1427. xfs_trans_cancel(tp, 0);
  1428. return error;
  1429. }
  1430. ip = mp->m_rootip;
  1431. xfs_ilock(ip, XFS_ILOCK_EXCL);
  1432. xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
  1433. xfs_trans_ihold(tp, ip);
  1434. xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
  1435. error = xfs_trans_commit(tp, 0);
  1436. xfs_iunlock(ip, XFS_ILOCK_EXCL);
  1437. xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
  1438. }
  1439. /*
  1440. * When shutting down, we need to insure that the AIL is pushed
  1441. * to disk or the filesystem can appear corrupt from the PROM.
  1442. */
  1443. if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
  1444. XFS_bflush(mp->m_ddev_targp);
  1445. if (mp->m_rtdev_targp) {
  1446. XFS_bflush(mp->m_rtdev_targp);
  1447. }
  1448. }
  1449. return XFS_ERROR(last_error);
  1450. }
  1451. /*
  1452. * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
  1453. */
  1454. int
  1455. xfs_vget(
  1456. xfs_mount_t *mp,
  1457. bhv_vnode_t **vpp,
  1458. xfs_fid_t *xfid)
  1459. {
  1460. xfs_inode_t *ip;
  1461. int error;
  1462. xfs_ino_t ino;
  1463. unsigned int igen;
  1464. /*
  1465. * Invalid. Since handles can be created in user space and passed in
  1466. * via gethandle(), this is not cause for a panic.
  1467. */
  1468. if (xfid->fid_len != sizeof(*xfid) - sizeof(xfid->fid_len))
  1469. return XFS_ERROR(EINVAL);
  1470. ino = xfid->fid_ino;
  1471. igen = xfid->fid_gen;
  1472. /*
  1473. * NFS can sometimes send requests for ino 0. Fail them gracefully.
  1474. */
  1475. if (ino == 0)
  1476. return XFS_ERROR(ESTALE);
  1477. error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
  1478. if (error) {
  1479. *vpp = NULL;
  1480. return error;
  1481. }
  1482. if (ip == NULL) {
  1483. *vpp = NULL;
  1484. return XFS_ERROR(EIO);
  1485. }
  1486. if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
  1487. xfs_iput_new(ip, XFS_ILOCK_SHARED);
  1488. *vpp = NULL;
  1489. return XFS_ERROR(ENOENT);
  1490. }
  1491. *vpp = XFS_ITOV(ip);
  1492. xfs_iunlock(ip, XFS_ILOCK_SHARED);
  1493. return 0;
  1494. }
  1495. #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
  1496. #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
  1497. #define MNTOPT_LOGDEV "logdev" /* log device */
  1498. #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
  1499. #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
  1500. #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
  1501. #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
  1502. #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
  1503. #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
  1504. #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
  1505. #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
  1506. #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
  1507. #define MNTOPT_MTPT "mtpt" /* filesystem mount point */
  1508. #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
  1509. #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
  1510. #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
  1511. #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
  1512. #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
  1513. #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
  1514. #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
  1515. * unwritten extent conversion */
  1516. #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
  1517. #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
  1518. #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
  1519. #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
  1520. #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
  1521. #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
  1522. #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
  1523. * in stat(). */
  1524. #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
  1525. #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
  1526. #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
  1527. #define MNTOPT_QUOTA "quota" /* disk quotas (user) */
  1528. #define MNTOPT_NOQUOTA "noquota" /* no quotas */
  1529. #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
  1530. #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
  1531. #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
  1532. #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
  1533. #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
  1534. #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
  1535. #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
  1536. #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
  1537. #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
  1538. #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
  1539. #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
  1540. #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
  1541. #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
  1542. STATIC unsigned long
  1543. suffix_strtoul(char *s, char **endp, unsigned int base)
  1544. {
  1545. int last, shift_left_factor = 0;
  1546. char *value = s;
  1547. last = strlen(value) - 1;
  1548. if (value[last] == 'K' || value[last] == 'k') {
  1549. shift_left_factor = 10;
  1550. value[last] = '\0';
  1551. }
  1552. if (value[last] == 'M' || value[last] == 'm') {
  1553. shift_left_factor = 20;
  1554. value[last] = '\0';
  1555. }
  1556. if (value[last] == 'G' || value[last] == 'g') {
  1557. shift_left_factor = 30;
  1558. value[last] = '\0';
  1559. }
  1560. return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
  1561. }
  1562. int
  1563. xfs_parseargs(
  1564. struct xfs_mount *mp,
  1565. char *options,
  1566. struct xfs_mount_args *args,
  1567. int update)
  1568. {
  1569. char *this_char, *value, *eov;
  1570. int dsunit, dswidth, vol_dsunit, vol_dswidth;
  1571. int iosize;
  1572. int ikeep = 0;
  1573. args->flags |= XFSMNT_BARRIER;
  1574. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  1575. if (!options)
  1576. goto done;
  1577. iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
  1578. while ((this_char = strsep(&options, ",")) != NULL) {
  1579. if (!*this_char)
  1580. continue;
  1581. if ((value = strchr(this_char, '=')) != NULL)
  1582. *value++ = 0;
  1583. if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
  1584. if (!value || !*value) {
  1585. cmn_err(CE_WARN,
  1586. "XFS: %s option requires an argument",
  1587. this_char);
  1588. return EINVAL;
  1589. }
  1590. args->logbufs = simple_strtoul(value, &eov, 10);
  1591. } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
  1592. if (!value || !*value) {
  1593. cmn_err(CE_WARN,
  1594. "XFS: %s option requires an argument",
  1595. this_char);
  1596. return EINVAL;
  1597. }
  1598. args->logbufsize = suffix_strtoul(value, &eov, 10);
  1599. } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
  1600. if (!value || !*value) {
  1601. cmn_err(CE_WARN,
  1602. "XFS: %s option requires an argument",
  1603. this_char);
  1604. return EINVAL;
  1605. }
  1606. strncpy(args->logname, value, MAXNAMELEN);
  1607. } else if (!strcmp(this_char, MNTOPT_MTPT)) {
  1608. if (!value || !*value) {
  1609. cmn_err(CE_WARN,
  1610. "XFS: %s option requires an argument",
  1611. this_char);
  1612. return EINVAL;
  1613. }
  1614. strncpy(args->mtpt, value, MAXNAMELEN);
  1615. } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
  1616. if (!value || !*value) {
  1617. cmn_err(CE_WARN,
  1618. "XFS: %s option requires an argument",
  1619. this_char);
  1620. return EINVAL;
  1621. }
  1622. strncpy(args->rtname, value, MAXNAMELEN);
  1623. } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
  1624. if (!value || !*value) {
  1625. cmn_err(CE_WARN,
  1626. "XFS: %s option requires an argument",
  1627. this_char);
  1628. return EINVAL;
  1629. }
  1630. iosize = simple_strtoul(value, &eov, 10);
  1631. args->flags |= XFSMNT_IOSIZE;
  1632. args->iosizelog = (uint8_t) iosize;
  1633. } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
  1634. if (!value || !*value) {
  1635. cmn_err(CE_WARN,
  1636. "XFS: %s option requires an argument",
  1637. this_char);
  1638. return EINVAL;
  1639. }
  1640. iosize = suffix_strtoul(value, &eov, 10);
  1641. args->flags |= XFSMNT_IOSIZE;
  1642. args->iosizelog = ffs(iosize) - 1;
  1643. } else if (!strcmp(this_char, MNTOPT_GRPID) ||
  1644. !strcmp(this_char, MNTOPT_BSDGROUPS)) {
  1645. mp->m_flags |= XFS_MOUNT_GRPID;
  1646. } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
  1647. !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
  1648. mp->m_flags &= ~XFS_MOUNT_GRPID;
  1649. } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
  1650. args->flags |= XFSMNT_WSYNC;
  1651. } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
  1652. args->flags |= XFSMNT_OSYNCISOSYNC;
  1653. } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
  1654. args->flags |= XFSMNT_NORECOVERY;
  1655. } else if (!strcmp(this_char, MNTOPT_INO64)) {
  1656. args->flags |= XFSMNT_INO64;
  1657. #if !XFS_BIG_INUMS
  1658. cmn_err(CE_WARN,
  1659. "XFS: %s option not allowed on this system",
  1660. this_char);
  1661. return EINVAL;
  1662. #endif
  1663. } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
  1664. args->flags |= XFSMNT_NOALIGN;
  1665. } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
  1666. args->flags |= XFSMNT_SWALLOC;
  1667. } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
  1668. if (!value || !*value) {
  1669. cmn_err(CE_WARN,
  1670. "XFS: %s option requires an argument",
  1671. this_char);
  1672. return EINVAL;
  1673. }
  1674. dsunit = simple_strtoul(value, &eov, 10);
  1675. } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
  1676. if (!value || !*value) {
  1677. cmn_err(CE_WARN,
  1678. "XFS: %s option requires an argument",
  1679. this_char);
  1680. return EINVAL;
  1681. }
  1682. dswidth = simple_strtoul(value, &eov, 10);
  1683. } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
  1684. args->flags &= ~XFSMNT_32BITINODES;
  1685. #if !XFS_BIG_INUMS
  1686. cmn_err(CE_WARN,
  1687. "XFS: %s option not allowed on this system",
  1688. this_char);
  1689. return EINVAL;
  1690. #endif
  1691. } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
  1692. args->flags |= XFSMNT_NOUUID;
  1693. } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
  1694. args->flags |= XFSMNT_BARRIER;
  1695. } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
  1696. args->flags &= ~XFSMNT_BARRIER;
  1697. } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
  1698. ikeep = 1;
  1699. args->flags &= ~XFSMNT_IDELETE;
  1700. } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
  1701. args->flags |= XFSMNT_IDELETE;
  1702. } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
  1703. args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
  1704. } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
  1705. args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
  1706. } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
  1707. args->flags |= XFSMNT_ATTR2;
  1708. } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
  1709. args->flags &= ~XFSMNT_ATTR2;
  1710. } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
  1711. args->flags2 |= XFSMNT2_FILESTREAMS;
  1712. } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
  1713. args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
  1714. args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
  1715. } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
  1716. !strcmp(this_char, MNTOPT_UQUOTA) ||
  1717. !strcmp(this_char, MNTOPT_USRQUOTA)) {
  1718. args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
  1719. } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
  1720. !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
  1721. args->flags |= XFSMNT_UQUOTA;
  1722. args->flags &= ~XFSMNT_UQUOTAENF;
  1723. } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
  1724. !strcmp(this_char, MNTOPT_PRJQUOTA)) {
  1725. args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
  1726. } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
  1727. args->flags |= XFSMNT_PQUOTA;
  1728. args->flags &= ~XFSMNT_PQUOTAENF;
  1729. } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
  1730. !strcmp(this_char, MNTOPT_GRPQUOTA)) {
  1731. args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
  1732. } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
  1733. args->flags |= XFSMNT_GQUOTA;
  1734. args->flags &= ~XFSMNT_GQUOTAENF;
  1735. } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
  1736. args->flags |= XFSMNT_DMAPI;
  1737. } else if (!strcmp(this_char, MNTOPT_XDSM)) {
  1738. args->flags |= XFSMNT_DMAPI;
  1739. } else if (!strcmp(this_char, MNTOPT_DMI)) {
  1740. args->flags |= XFSMNT_DMAPI;
  1741. } else if (!strcmp(this_char, "ihashsize")) {
  1742. cmn_err(CE_WARN,
  1743. "XFS: ihashsize no longer used, option is deprecated.");
  1744. } else if (!strcmp(this_char, "osyncisdsync")) {
  1745. /* no-op, this is now the default */
  1746. cmn_err(CE_WARN,
  1747. "XFS: osyncisdsync is now the default, option is deprecated.");
  1748. } else if (!strcmp(this_char, "irixsgid")) {
  1749. cmn_err(CE_WARN,
  1750. "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
  1751. } else {
  1752. cmn_err(CE_WARN,
  1753. "XFS: unknown mount option [%s].", this_char);
  1754. return EINVAL;
  1755. }
  1756. }
  1757. if (args->flags & XFSMNT_NORECOVERY) {
  1758. if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
  1759. cmn_err(CE_WARN,
  1760. "XFS: no-recovery mounts must be read-only.");
  1761. return EINVAL;
  1762. }
  1763. }
  1764. if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
  1765. cmn_err(CE_WARN,
  1766. "XFS: sunit and swidth options incompatible with the noalign option");
  1767. return EINVAL;
  1768. }
  1769. if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
  1770. cmn_err(CE_WARN,
  1771. "XFS: cannot mount with both project and group quota");
  1772. return EINVAL;
  1773. }
  1774. if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
  1775. printk("XFS: %s option needs the mount point option as well\n",
  1776. MNTOPT_DMAPI);
  1777. return EINVAL;
  1778. }
  1779. if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
  1780. cmn_err(CE_WARN,
  1781. "XFS: sunit and swidth must be specified together");
  1782. return EINVAL;
  1783. }
  1784. if (dsunit && (dswidth % dsunit != 0)) {
  1785. cmn_err(CE_WARN,
  1786. "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
  1787. dswidth, dsunit);
  1788. return EINVAL;
  1789. }
  1790. /*
  1791. * Applications using DMI filesystems often expect the
  1792. * inode generation number to be monotonically increasing.
  1793. * If we delete inode chunks we break this assumption, so
  1794. * keep unused inode chunks on disk for DMI filesystems
  1795. * until we come up with a better solution.
  1796. * Note that if "ikeep" or "noikeep" mount options are
  1797. * supplied, then they are honored.
  1798. */
  1799. if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
  1800. args->flags |= XFSMNT_IDELETE;
  1801. if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
  1802. if (dsunit) {
  1803. args->sunit = dsunit;
  1804. args->flags |= XFSMNT_RETERR;
  1805. } else {
  1806. args->sunit = vol_dsunit;
  1807. }
  1808. dswidth ? (args->swidth = dswidth) :
  1809. (args->swidth = vol_dswidth);
  1810. } else {
  1811. args->sunit = args->swidth = 0;
  1812. }
  1813. done:
  1814. if (args->flags & XFSMNT_32BITINODES)
  1815. mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
  1816. if (args->flags2)
  1817. args->flags |= XFSMNT_FLAGS2;
  1818. return 0;
  1819. }
  1820. int
  1821. xfs_showargs(
  1822. struct xfs_mount *mp,
  1823. struct seq_file *m)
  1824. {
  1825. static struct proc_xfs_info {
  1826. int flag;
  1827. char *str;
  1828. } xfs_info[] = {
  1829. /* the few simple ones we can get from the mount struct */
  1830. { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
  1831. { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
  1832. { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
  1833. { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
  1834. { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
  1835. { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
  1836. { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
  1837. { 0, NULL }
  1838. };
  1839. struct proc_xfs_info *xfs_infop;
  1840. for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
  1841. if (mp->m_flags & xfs_infop->flag)
  1842. seq_puts(m, xfs_infop->str);
  1843. }
  1844. if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
  1845. seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
  1846. (int)(1 << mp->m_writeio_log) >> 10);
  1847. if (mp->m_logbufs > 0)
  1848. seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
  1849. if (mp->m_logbsize > 0)
  1850. seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
  1851. if (mp->m_logname)
  1852. seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
  1853. if (mp->m_rtname)
  1854. seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
  1855. if (mp->m_dalign > 0)
  1856. seq_printf(m, "," MNTOPT_SUNIT "=%d",
  1857. (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
  1858. if (mp->m_swidth > 0)
  1859. seq_printf(m, "," MNTOPT_SWIDTH "=%d",
  1860. (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
  1861. if (!(mp->m_flags & XFS_MOUNT_IDELETE))
  1862. seq_printf(m, "," MNTOPT_IKEEP);
  1863. if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
  1864. seq_printf(m, "," MNTOPT_LARGEIO);
  1865. if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS))
  1866. seq_printf(m, "," MNTOPT_64BITINODE);
  1867. if (mp->m_flags & XFS_MOUNT_GRPID)
  1868. seq_printf(m, "," MNTOPT_GRPID);
  1869. if (mp->m_qflags & XFS_UQUOTA_ACCT) {
  1870. if (mp->m_qflags & XFS_UQUOTA_ENFD)
  1871. seq_puts(m, "," MNTOPT_USRQUOTA);
  1872. else
  1873. seq_puts(m, "," MNTOPT_UQUOTANOENF);
  1874. }
  1875. if (mp->m_qflags & XFS_PQUOTA_ACCT) {
  1876. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  1877. seq_puts(m, "," MNTOPT_PRJQUOTA);
  1878. else
  1879. seq_puts(m, "," MNTOPT_PQUOTANOENF);
  1880. }
  1881. if (mp->m_qflags & XFS_GQUOTA_ACCT) {
  1882. if (mp->m_qflags & XFS_OQUOTA_ENFD)
  1883. seq_puts(m, "," MNTOPT_GRPQUOTA);
  1884. else
  1885. seq_puts(m, "," MNTOPT_GQUOTANOENF);
  1886. }
  1887. if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
  1888. seq_puts(m, "," MNTOPT_NOQUOTA);
  1889. if (mp->m_flags & XFS_MOUNT_DMAPI)
  1890. seq_puts(m, "," MNTOPT_DMAPI);
  1891. return 0;
  1892. }
  1893. /*
  1894. * Second stage of a freeze. The data is already frozen so we only
  1895. * need to take care of themetadata. Once that's done write a dummy
  1896. * record to dirty the log in case of a crash while frozen.
  1897. */
  1898. void
  1899. xfs_freeze(
  1900. xfs_mount_t *mp)
  1901. {
  1902. xfs_attr_quiesce(mp);
  1903. xfs_fs_log_dummy(mp);
  1904. }