xfs_vfsops.c 52 KB

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