xfs_vfsops.c 51 KB

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