xfs_vfsops.c 52 KB

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