xfs_vfsops.c 52 KB

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