xfs_vfsops.c 52 KB

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