blob: 1644be14a144c1e6a0b77a137dccd56f06588baf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_types.h"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110023#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_trans.h"
25#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110026#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "xfs_dir2.h"
28#include "xfs_dmapi.h"
29#include "xfs_mount.h"
Nathan Scotta844f452005-11-02 14:38:42 +110030#include "xfs_da_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_bmap_btree.h"
32#include "xfs_ialloc_btree.h"
33#include "xfs_alloc_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110034#include "xfs_dir2_sf.h"
35#include "xfs_attr_sf.h"
36#include "xfs_dinode.h"
37#include "xfs_inode.h"
38#include "xfs_inode_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "xfs_btree.h"
40#include "xfs_alloc.h"
41#include "xfs_ialloc.h"
Nathan Scotta844f452005-11-02 14:38:42 +110042#include "xfs_quota.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include "xfs_error.h"
44#include "xfs_bmap.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include "xfs_rw.h"
46#include "xfs_refcache.h"
47#include "xfs_buf_item.h"
Nathan Scotta844f452005-11-02 14:38:42 +110048#include "xfs_log_priv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include "xfs_dir2_trace.h"
Nathan Scotta844f452005-11-02 14:38:42 +110050#include "xfs_extfree_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include "xfs_acl.h"
52#include "xfs_attr.h"
53#include "xfs_clnt.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100054#include "xfs_mru_cache.h"
55#include "xfs_filestream.h"
Christoph Hellwige13a73f2006-01-11 15:30:08 +110056#include "xfs_fsops.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070057
David Chinner8d280b92006-03-14 13:13:09 +110058STATIC int xfs_sync(bhv_desc_t *, int, cred_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60int
61xfs_init(void)
62{
63 extern kmem_zone_t *xfs_bmap_free_item_zone;
64 extern kmem_zone_t *xfs_btree_cur_zone;
65 extern kmem_zone_t *xfs_trans_zone;
66 extern kmem_zone_t *xfs_buf_item_zone;
67 extern kmem_zone_t *xfs_dabuf_zone;
68#ifdef XFS_DABUF_DEBUG
69 extern lock_t xfs_dabuf_global_lock;
70 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
71#endif
72
73 /*
74 * Initialize all of the zone allocators we use.
75 */
76 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
77 "xfs_bmap_free_item");
78 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
79 "xfs_btree_cur");
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
81 xfs_da_state_zone =
82 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
83 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
Nathan Scott87582802006-03-14 13:18:19 +110084 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
85 xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
David Chinner2a82b8b2007-07-11 11:09:12 +100086 xfs_mru_cache_init();
87 xfs_filestream_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89 /*
90 * The size of the zone allocated buf log item is the maximum
91 * size possible under XFS. This wastes a little bit of memory,
92 * but it is much faster.
93 */
94 xfs_buf_item_zone =
95 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
96 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
97 NBWORD) * sizeof(int))),
98 "xfs_buf_item");
Nathan Scott87582802006-03-14 13:18:19 +110099 xfs_efd_zone =
100 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
101 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
102 sizeof(xfs_extent_t))),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 "xfs_efd_item");
Nathan Scott87582802006-03-14 13:18:19 +1100104 xfs_efi_zone =
105 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
106 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
107 sizeof(xfs_extent_t))),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 "xfs_efi_item");
Nathan Scott87582802006-03-14 13:18:19 +1100109
110 /*
111 * These zones warrant special memory allocator hints
112 */
113 xfs_inode_zone =
114 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
115 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
116 KM_ZONE_SPREAD, NULL);
117 xfs_ili_zone =
118 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
119 KM_ZONE_SPREAD, NULL);
David Chinnerda353b02007-08-28 14:00:13 +1000120 xfs_icluster_zone =
121 kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster",
Nathan Scott87582802006-03-14 13:18:19 +1100122 KM_ZONE_SPREAD, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /*
125 * Allocate global trace buffers.
126 */
127#ifdef XFS_ALLOC_TRACE
128 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
129#endif
130#ifdef XFS_BMAP_TRACE
131 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
132#endif
133#ifdef XFS_BMBT_TRACE
134 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
135#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136#ifdef XFS_ATTR_TRACE
137 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
138#endif
139#ifdef XFS_DIR2_TRACE
140 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
141#endif
142
143 xfs_dir_startup();
144
145#if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
146 xfs_error_test_init();
147#endif /* DEBUG || INDUCE_IO_ERROR */
148
149 xfs_init_procfs();
150 xfs_sysctl_register();
151 return 0;
152}
153
154void
155xfs_cleanup(void)
156{
157 extern kmem_zone_t *xfs_bmap_free_item_zone;
158 extern kmem_zone_t *xfs_btree_cur_zone;
159 extern kmem_zone_t *xfs_inode_zone;
160 extern kmem_zone_t *xfs_trans_zone;
161 extern kmem_zone_t *xfs_da_state_zone;
162 extern kmem_zone_t *xfs_dabuf_zone;
163 extern kmem_zone_t *xfs_efd_zone;
164 extern kmem_zone_t *xfs_efi_zone;
165 extern kmem_zone_t *xfs_buf_item_zone;
David Chinnerda353b02007-08-28 14:00:13 +1000166 extern kmem_zone_t *xfs_icluster_zone;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 xfs_cleanup_procfs();
169 xfs_sysctl_unregister();
170 xfs_refcache_destroy();
David Chinner2a82b8b2007-07-11 11:09:12 +1000171 xfs_filestream_uninit();
172 xfs_mru_cache_uninit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 xfs_acl_zone_destroy(xfs_acl_zone);
174
175#ifdef XFS_DIR2_TRACE
176 ktrace_free(xfs_dir2_trace_buf);
177#endif
178#ifdef XFS_ATTR_TRACE
179 ktrace_free(xfs_attr_trace_buf);
180#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181#ifdef XFS_BMBT_TRACE
182 ktrace_free(xfs_bmbt_trace_buf);
183#endif
184#ifdef XFS_BMAP_TRACE
185 ktrace_free(xfs_bmap_trace_buf);
186#endif
187#ifdef XFS_ALLOC_TRACE
188 ktrace_free(xfs_alloc_trace_buf);
189#endif
190
Nathan Scott3758dee2006-03-22 12:47:28 +1100191 kmem_zone_destroy(xfs_bmap_free_item_zone);
192 kmem_zone_destroy(xfs_btree_cur_zone);
193 kmem_zone_destroy(xfs_inode_zone);
194 kmem_zone_destroy(xfs_trans_zone);
195 kmem_zone_destroy(xfs_da_state_zone);
196 kmem_zone_destroy(xfs_dabuf_zone);
197 kmem_zone_destroy(xfs_buf_item_zone);
198 kmem_zone_destroy(xfs_efd_zone);
199 kmem_zone_destroy(xfs_efi_zone);
200 kmem_zone_destroy(xfs_ifork_zone);
201 kmem_zone_destroy(xfs_ili_zone);
David Chinnerda353b02007-08-28 14:00:13 +1000202 kmem_zone_destroy(xfs_icluster_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203}
204
205/*
206 * xfs_start_flags
207 *
208 * This function fills in xfs_mount_t fields based on mount args.
209 * Note: the superblock has _not_ yet been read in.
210 */
211STATIC int
212xfs_start_flags(
Nathan Scottb83bd132006-06-09 16:48:30 +1000213 struct bhv_vfs *vfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 struct xfs_mount_args *ap,
215 struct xfs_mount *mp)
216{
217 /* Values are in BBs */
218 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
219 /*
220 * At this point the superblock has not been read
221 * in, therefore we do not know the block size.
222 * Before the mount call ends we will convert
223 * these to FSBs.
224 */
225 mp->m_dalign = ap->sunit;
226 mp->m_swidth = ap->swidth;
227 }
228
229 if (ap->logbufs != -1 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 ap->logbufs != 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 (ap->logbufs < XLOG_MIN_ICLOGS ||
232 ap->logbufs > XLOG_MAX_ICLOGS)) {
233 cmn_err(CE_WARN,
234 "XFS: invalid logbufs value: %d [not %d-%d]",
235 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
236 return XFS_ERROR(EINVAL);
237 }
238 mp->m_logbufs = ap->logbufs;
239 if (ap->logbufsize != -1 &&
Nathan Scottcfcbbbd2005-11-02 15:12:04 +1100240 ap->logbufsize != 0 &&
Eric Sandeendcb3b832007-08-16 16:25:33 +1000241 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
242 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
243 !is_power_of_2(ap->logbufsize))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 cmn_err(CE_WARN,
245 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
246 ap->logbufsize);
247 return XFS_ERROR(EINVAL);
248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 mp->m_logbsize = ap->logbufsize;
250 mp->m_fsname_len = strlen(ap->fsname) + 1;
251 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
252 strcpy(mp->m_fsname, ap->fsname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +1100253 if (ap->rtname[0]) {
254 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
255 strcpy(mp->m_rtname, ap->rtname);
256 }
257 if (ap->logname[0]) {
258 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
259 strcpy(mp->m_logname, ap->logname);
260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 if (ap->flags & XFSMNT_WSYNC)
263 mp->m_flags |= XFS_MOUNT_WSYNC;
264#if XFS_BIG_INUMS
265 if (ap->flags & XFSMNT_INO64) {
266 mp->m_flags |= XFS_MOUNT_INO64;
267 mp->m_inoadd = XFS_INO64_OFFSET;
268 }
269#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (ap->flags & XFSMNT_RETERR)
271 mp->m_flags |= XFS_MOUNT_RETERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (ap->flags & XFSMNT_NOALIGN)
273 mp->m_flags |= XFS_MOUNT_NOALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (ap->flags & XFSMNT_SWALLOC)
275 mp->m_flags |= XFS_MOUNT_SWALLOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (ap->flags & XFSMNT_OSYNCISOSYNC)
277 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 if (ap->flags & XFSMNT_32BITINODES)
Nathan Scottc11e2c32005-11-02 15:11:45 +1100279 mp->m_flags |= XFS_MOUNT_32BITINODES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 if (ap->flags & XFSMNT_IOSIZE) {
282 if (ap->iosizelog > XFS_MAX_IO_LOG ||
283 ap->iosizelog < XFS_MIN_IO_LOG) {
284 cmn_err(CE_WARN,
285 "XFS: invalid log iosize: %d [not %d-%d]",
286 ap->iosizelog, XFS_MIN_IO_LOG,
287 XFS_MAX_IO_LOG);
288 return XFS_ERROR(EINVAL);
289 }
290
291 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
292 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
293 }
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (ap->flags & XFSMNT_IDELETE)
296 mp->m_flags |= XFS_MOUNT_IDELETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 if (ap->flags & XFSMNT_DIRSYNC)
298 mp->m_flags |= XFS_MOUNT_DIRSYNC;
Nathan Scott13059ff2006-01-11 15:32:01 +1100299 if (ap->flags & XFSMNT_ATTR2)
300 mp->m_flags |= XFS_MOUNT_ATTR2;
David Chinnere8c8b3a2005-11-02 10:33:05 +1100301
Nathan Scotte718eeb42005-11-02 15:09:22 +1100302 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
303 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 /*
306 * no recovery flag requires a read-only mount
307 */
308 if (ap->flags & XFSMNT_NORECOVERY) {
309 if (!(vfs->vfs_flag & VFS_RDONLY)) {
310 cmn_err(CE_WARN,
311 "XFS: tried to mount a FS read-write without recovery!");
312 return XFS_ERROR(EINVAL);
313 }
314 mp->m_flags |= XFS_MOUNT_NORECOVERY;
315 }
316
317 if (ap->flags & XFSMNT_NOUUID)
318 mp->m_flags |= XFS_MOUNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100319 if (ap->flags & XFSMNT_BARRIER)
320 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100321 else
322 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
David Chinner2a82b8b2007-07-11 11:09:12 +1000324 if (ap->flags2 & XFSMNT2_FILESTREAMS)
325 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 return 0;
328}
329
330/*
331 * This function fills in xfs_mount_t fields based on mount args.
332 * Note: the superblock _has_ now been read in.
333 */
334STATIC int
335xfs_finish_flags(
Nathan Scottb83bd132006-06-09 16:48:30 +1000336 struct bhv_vfs *vfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 struct xfs_mount_args *ap,
338 struct xfs_mount *mp)
339{
340 int ronly = (vfs->vfs_flag & VFS_RDONLY);
341
342 /* Fail a mount where the logbuf is smaller then the log stripe */
343 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
Nathan Scottc2cd2552006-01-11 15:35:32 +1100344 if ((ap->logbufsize <= 0) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
346 mp->m_logbsize = mp->m_sb.sb_logsunit;
Nathan Scottc2cd2552006-01-11 15:35:32 +1100347 } else if (ap->logbufsize > 0 &&
348 ap->logbufsize < mp->m_sb.sb_logsunit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 cmn_err(CE_WARN,
350 "XFS: logbuf size must be greater than or equal to log stripe size");
351 return XFS_ERROR(EINVAL);
352 }
353 } else {
354 /* Fail a mount if the logbuf is larger than 32K */
355 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
356 cmn_err(CE_WARN,
357 "XFS: logbuf size for version 1 logs must be 16K or 32K");
358 return XFS_ERROR(EINVAL);
359 }
360 }
361
Nathan Scott13059ff2006-01-11 15:32:01 +1100362 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
363 mp->m_flags |= XFS_MOUNT_ATTR2;
364 }
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 /*
367 * prohibit r/w mounts of read-only filesystems
368 */
369 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
370 cmn_err(CE_WARN,
371 "XFS: cannot mount a read-only filesystem as read-write");
372 return XFS_ERROR(EROFS);
373 }
374
375 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 * check for shared mount.
377 */
378 if (ap->flags & XFSMNT_SHARED) {
379 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
380 return XFS_ERROR(EINVAL);
381
382 /*
383 * For IRIX 6.5, shared mounts must have the shared
384 * version bit set, have the persistent readonly
385 * field set, must be version 0 and can only be mounted
386 * read-only.
387 */
388 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
389 (mp->m_sb.sb_shared_vn != 0))
390 return XFS_ERROR(EINVAL);
391
392 mp->m_flags |= XFS_MOUNT_SHARED;
393
394 /*
395 * Shared XFS V0 can't deal with DMI. Return EINVAL.
396 */
397 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
398 return XFS_ERROR(EINVAL);
399 }
400
401 return 0;
402}
403
404/*
405 * xfs_mount
406 *
407 * The file system configurations are:
408 * (1) device (partition) with data and internal log
409 * (2) logical volume with data and log subvolumes.
410 * (3) logical volume with data, log, and realtime subvolumes.
411 *
412 * We only have to handle opening the log and realtime volumes here if
413 * they are present. The data subvolume has already been opened by
414 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
415 */
416STATIC int
417xfs_mount(
418 struct bhv_desc *bhvp,
419 struct xfs_mount_args *args,
420 cred_t *credp)
421{
Nathan Scottb83bd132006-06-09 16:48:30 +1000422 struct bhv_vfs *vfsp = bhvtovfs(bhvp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 struct bhv_desc *p;
424 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
425 struct block_device *ddev, *logdev, *rtdev;
426 int flags = 0, error;
427
428 ddev = vfsp->vfs_super->s_bdev;
429 logdev = rtdev = NULL;
430
431 /*
432 * Setup xfs_mount function vectors from available behaviors
433 */
434 p = vfs_bhv_lookup(vfsp, VFS_POSITION_DM);
435 mp->m_dm_ops = p ? *(xfs_dmops_t *) vfs_bhv_custom(p) : xfs_dmcore_stub;
436 p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM);
437 mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub;
438 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
439 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
440
Nathan Scott764d1f82006-03-31 13:04:17 +1000441 if (args->flags & XFSMNT_QUIET)
442 flags |= XFS_MFSI_QUIET;
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 /*
445 * Open real time and log devices - order is important.
446 */
447 if (args->logname[0]) {
448 error = xfs_blkdev_get(mp, args->logname, &logdev);
449 if (error)
450 return error;
451 }
452 if (args->rtname[0]) {
453 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
454 if (error) {
455 xfs_blkdev_put(logdev);
456 return error;
457 }
458
459 if (rtdev == ddev || rtdev == logdev) {
460 cmn_err(CE_WARN,
461 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
462 xfs_blkdev_put(logdev);
463 xfs_blkdev_put(rtdev);
464 return EINVAL;
465 }
466 }
467
468 /*
469 * Setup xfs_mount buffer target pointers
470 */
471 error = ENOMEM;
472 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
473 if (!mp->m_ddev_targp) {
474 xfs_blkdev_put(logdev);
475 xfs_blkdev_put(rtdev);
476 return error;
477 }
478 if (rtdev) {
479 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000480 if (!mp->m_rtdev_targp) {
481 xfs_blkdev_put(logdev);
482 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 }
486 mp->m_logdev_targp = (logdev && logdev != ddev) ?
487 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000488 if (!mp->m_logdev_targp) {
489 xfs_blkdev_put(logdev);
490 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000492 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 /*
495 * Setup flags based on mount(2) options and then the superblock
496 */
497 error = xfs_start_flags(vfsp, args, mp);
498 if (error)
499 goto error1;
Nathan Scott764d1f82006-03-31 13:04:17 +1000500 error = xfs_readsb(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 if (error)
502 goto error1;
503 error = xfs_finish_flags(vfsp, args, mp);
504 if (error)
505 goto error2;
506
507 /*
508 * Setup xfs_mount buffer target pointers based on superblock
509 */
510 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
511 mp->m_sb.sb_sectsize);
512 if (!error && logdev && logdev != ddev) {
513 unsigned int log_sector_size = BBSIZE;
514
515 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
516 log_sector_size = mp->m_sb.sb_logsectsize;
517 error = xfs_setsize_buftarg(mp->m_logdev_targp,
518 mp->m_sb.sb_blocksize,
519 log_sector_size);
520 }
521 if (!error && rtdev)
522 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
523 mp->m_sb.sb_blocksize,
524 mp->m_sb.sb_sectsize);
525 if (error)
526 goto error2;
527
Nathan Scottb2ea4012006-07-28 17:05:13 +1000528 if (mp->m_flags & XFS_MOUNT_BARRIER)
Christoph Hellwigc7d437d2006-01-11 15:28:56 +1100529 xfs_mountfs_check_barriers(mp);
530
David Chinner2a82b8b2007-07-11 11:09:12 +1000531 if ((error = xfs_filestream_mount(mp)))
532 goto error2;
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 error = XFS_IOINIT(vfsp, args, flags);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100535 if (error)
536 goto error2;
537
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100538 return 0;
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540error2:
541 if (mp->m_sb_bp)
542 xfs_freesb(mp);
543error1:
544 xfs_binval(mp->m_ddev_targp);
545 if (logdev && logdev != ddev)
546 xfs_binval(mp->m_logdev_targp);
547 if (rtdev)
548 xfs_binval(mp->m_rtdev_targp);
549error0:
550 xfs_unmountfs_close(mp, credp);
551 return error;
552}
553
554STATIC int
555xfs_unmount(
556 bhv_desc_t *bdp,
557 int flags,
558 cred_t *credp)
559{
Nathan Scottb83bd132006-06-09 16:48:30 +1000560 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 xfs_mount_t *mp = XFS_BHVTOM(bdp);
562 xfs_inode_t *rip;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000563 bhv_vnode_t *rvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 int unmount_event_wanted = 0;
565 int unmount_event_flags = 0;
566 int xfs_unmountfs_needed = 0;
567 int error;
568
569 rip = mp->m_rootip;
570 rvp = XFS_ITOV(rip);
571
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000572#ifdef HAVE_DMAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 if (vfsp->vfs_flag & VFS_DMI) {
574 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
575 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
576 NULL, NULL, 0, 0,
577 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
578 0:DM_FLAGS_UNWANTED);
579 if (error)
580 return XFS_ERROR(error);
581 unmount_event_wanted = 1;
582 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
583 0 : DM_FLAGS_UNWANTED;
584 }
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000585#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 /*
587 * First blow any referenced inode from this file system
588 * out of the reference cache, and delete the timer.
589 */
590 xfs_refcache_purge_mp(mp);
591
David Chinner2a82b8b2007-07-11 11:09:12 +1000592 /*
593 * Blow away any referenced inode in the filestreams cache.
594 * This can and will cause log traffic as inodes go inactive
595 * here.
596 */
597 xfs_filestream_unmount(mp);
598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 XFS_bflush(mp->m_ddev_targp);
600 error = xfs_unmount_flush(mp, 0);
601 if (error)
602 goto out;
603
604 ASSERT(vn_count(rvp) == 1);
605
606 /*
607 * Drop the reference count
608 */
609 VN_RELE(rvp);
610
611 /*
612 * If we're forcing a shutdown, typically because of a media error,
613 * we want to make sure we invalidate dirty pages that belong to
614 * referenced vnodes as well.
615 */
616 if (XFS_FORCED_SHUTDOWN(mp)) {
617 error = xfs_sync(&mp->m_bhv,
618 (SYNC_WAIT | SYNC_CLOSE), credp);
619 ASSERT(error != EFSCORRUPTED);
620 }
621 xfs_unmountfs_needed = 1;
622
623out:
624 /* Send DMAPI event, if required.
625 * Then do xfs_unmountfs() if needed.
626 * Then return error (or zero).
627 */
628 if (unmount_event_wanted) {
629 /* Note: mp structure must still exist for
630 * XFS_SEND_UNMOUNT() call.
631 */
632 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
633 DM_RIGHT_NULL, 0, error, unmount_event_flags);
634 }
635 if (xfs_unmountfs_needed) {
636 /*
637 * Call common unmount function to flush to disk
638 * and free the super block buffer & mount structures.
639 */
640 xfs_unmountfs(mp, credp);
641 }
642
643 return XFS_ERROR(error);
644}
645
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000646STATIC int
647xfs_quiesce_fs(
648 xfs_mount_t *mp)
649{
650 int count = 0, pincount;
Nathan Scott3758dee2006-03-22 12:47:28 +1100651
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000652 xfs_refcache_purge_mp(mp);
653 xfs_flush_buftarg(mp->m_ddev_targp, 0);
654 xfs_finish_reclaim_all(mp, 0);
655
656 /* This loop must run at least twice.
657 * The first instance of the loop will flush
658 * most meta data but that will generate more
659 * meta data (typically directory updates).
660 * Which then must be flushed and logged before
661 * we can write the unmount record.
Nathan Scott3758dee2006-03-22 12:47:28 +1100662 */
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000663 do {
David Chinner516b2e72007-06-18 16:50:48 +1000664 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000665 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
666 if (!pincount) {
667 delay(50);
668 count++;
669 }
670 } while (count < 2);
671
672 return 0;
673}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
David Chinner516b2e72007-06-18 16:50:48 +1000675/*
676 * Second stage of a quiesce. The data is already synced, now we have to take
677 * care of the metadata. New transactions are already blocked, so we need to
678 * wait for any remaining transactions to drain out before proceding.
679 */
680STATIC void
681xfs_attr_quiesce(
682 xfs_mount_t *mp)
683{
684 /* wait for all modifications to complete */
685 while (atomic_read(&mp->m_active_trans) > 0)
686 delay(100);
687
688 /* flush inodes and push all remaining buffers out to disk */
689 xfs_quiesce_fs(mp);
690
691 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
692
693 /* Push the superblock and write an unmount record */
694 xfs_log_sbcount(mp, 1);
695 xfs_log_unmount_write(mp);
696 xfs_unmountfs_writesb(mp);
697}
698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699STATIC int
700xfs_mntupdate(
701 bhv_desc_t *bdp,
702 int *flags,
703 struct xfs_mount_args *args)
704{
Nathan Scottb83bd132006-06-09 16:48:30 +1000705 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707
Nathan Scottd08d3892006-05-08 19:51:28 +1000708 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
709 if (vfsp->vfs_flag & VFS_RDONLY)
710 vfsp->vfs_flag &= ~VFS_RDONLY;
711 if (args->flags & XFSMNT_BARRIER) {
712 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100713 xfs_mountfs_check_barriers(mp);
Nathan Scottd08d3892006-05-08 19:51:28 +1000714 } else {
715 mp->m_flags &= ~XFS_MOUNT_BARRIER;
716 }
717 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
David Chinner2a82b8b2007-07-11 11:09:12 +1000718 xfs_filestream_flush(mp);
David Chinner516b2e72007-06-18 16:50:48 +1000719 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
720 xfs_attr_quiesce(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 vfsp->vfs_flag |= VFS_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 return 0;
724}
725
726/*
727 * xfs_unmount_flush implements a set of flush operation on special
728 * inodes, which are needed as a separate set of operations so that
729 * they can be called as part of relocation process.
730 */
731int
732xfs_unmount_flush(
733 xfs_mount_t *mp, /* Mount structure we are getting
734 rid of. */
735 int relocation) /* Called from vfs relocation. */
736{
737 xfs_inode_t *rip = mp->m_rootip;
738 xfs_inode_t *rbmip;
739 xfs_inode_t *rsumip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000740 bhv_vnode_t *rvp = XFS_ITOV(rip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 int error;
742
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000743 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 xfs_iflock(rip);
745
746 /*
747 * Flush out the real time inodes.
748 */
749 if ((rbmip = mp->m_rbmip) != NULL) {
750 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
751 xfs_iflock(rbmip);
752 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
753 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
754
755 if (error == EFSCORRUPTED)
756 goto fscorrupt_out;
757
758 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
759
760 rsumip = mp->m_rsumip;
761 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
762 xfs_iflock(rsumip);
763 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
764 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
765
766 if (error == EFSCORRUPTED)
767 goto fscorrupt_out;
768
769 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
770 }
771
772 /*
773 * Synchronously flush root inode to disk
774 */
775 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
776 if (error == EFSCORRUPTED)
777 goto fscorrupt_out2;
778
779 if (vn_count(rvp) != 1 && !relocation) {
780 xfs_iunlock(rip, XFS_ILOCK_EXCL);
781 return XFS_ERROR(EBUSY);
782 }
783
784 /*
785 * Release dquot that rootinode, rbmino and rsumino might be holding,
786 * flush and purge the quota inodes.
787 */
788 error = XFS_QM_UNMOUNT(mp);
789 if (error == EFSCORRUPTED)
790 goto fscorrupt_out2;
791
792 if (rbmip) {
793 VN_RELE(XFS_ITOV(rbmip));
794 VN_RELE(XFS_ITOV(rsumip));
795 }
796
797 xfs_iunlock(rip, XFS_ILOCK_EXCL);
798 return 0;
799
800fscorrupt_out:
801 xfs_ifunlock(rip);
802
803fscorrupt_out2:
804 xfs_iunlock(rip, XFS_ILOCK_EXCL);
805
806 return XFS_ERROR(EFSCORRUPTED);
807}
808
809/*
810 * xfs_root extracts the root vnode from a vfs.
811 *
812 * vfsp -- the vfs struct for the desired file system
813 * vpp -- address of the caller's vnode pointer which should be
814 * set to the desired fs root vnode
815 */
816STATIC int
817xfs_root(
818 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000819 bhv_vnode_t **vpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000821 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822
823 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
824 VN_HOLD(vp);
825 *vpp = vp;
826 return 0;
827}
828
829/*
830 * xfs_statvfs
831 *
832 * Fill in the statvfs structure for the given file system. We use
833 * the superblock lock in the mount structure to ensure a consistent
834 * snapshot of the counters returned.
835 */
836STATIC int
837xfs_statvfs(
838 bhv_desc_t *bdp,
Nathan Scott8285fb52006-06-09 17:07:12 +1000839 bhv_statvfs_t *statp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000840 bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
842 __uint64_t fakeinos;
843 xfs_extlen_t lsize;
844 xfs_mount_t *mp;
845 xfs_sb_t *sbp;
846 unsigned long s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 mp = XFS_BHVTOM(bdp);
849 sbp = &(mp->m_sb);
850
851 statp->f_type = XFS_SB_MAGIC;
852
David Chinnerdbcabad2007-02-10 18:36:17 +1100853 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 s = XFS_SB_LOCK(mp);
855 statp->f_bsize = sbp->sb_blocksize;
856 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
857 statp->f_blocks = sbp->sb_dblocks - lsize;
David Chinner4be536d2006-09-07 14:26:50 +1000858 statp->f_bfree = statp->f_bavail =
859 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 fakeinos = statp->f_bfree << sbp->sb_inopblog;
861#if XFS_BIG_INUMS
862 fakeinos += mp->m_inoadd;
863#endif
864 statp->f_files =
865 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
866 if (mp->m_maxicount)
867#if XFS_BIG_INUMS
868 if (!mp->m_inoadd)
869#endif
870 statp->f_files = min_t(typeof(statp->f_files),
871 statp->f_files,
872 mp->m_maxicount);
873 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
874 XFS_SB_UNLOCK(mp, s);
875
Nathan Scottcde410a2005-09-05 11:47:01 +1000876 xfs_statvfs_fsid(statp, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 statp->f_namelen = MAXNAMELEN - 1;
878
879 return 0;
880}
881
882
883/*
884 * xfs_sync flushes any pending I/O to file system vfsp.
885 *
886 * This routine is called by vfs_sync() to make sure that things make it
887 * out to disk eventually, on sync() system calls to flush out everything,
888 * and when the file system is unmounted. For the vfs_sync() case, all
889 * we really need to do is sync out the log to make all of our meta-data
890 * updates permanent (except for timestamps). For calls from pflushd(),
891 * dirty pages are kept moving by calling pdflush() on the inodes
892 * containing them. We also flush the inodes that we can lock without
893 * sleeping and the superblock if we can lock it without sleeping from
894 * vfs_sync() so that items at the tail of the log are always moving out.
895 *
896 * Flags:
897 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
898 * to sleep if we can help it. All we really need
899 * to do is ensure that the log is synced at least
900 * periodically. We also push the inodes and
901 * superblock if we can lock them without sleeping
902 * and they are not pinned.
903 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
904 * set, then we really want to lock each inode and flush
905 * it.
906 * SYNC_WAIT - All the flushes that take place in this call should
907 * be synchronous.
908 * SYNC_DELWRI - This tells us to push dirty pages associated with
909 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
910 * determine if they should be flushed sync, async, or
911 * delwri.
912 * SYNC_CLOSE - This flag is passed when the system is being
Nathan Scottc41564b2006-03-29 08:55:14 +1000913 * unmounted. We should sync and invalidate everything.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 * SYNC_FSDATA - This indicates that the caller would like to make
915 * sure the superblock is safe on disk. We can ensure
Nathan Scottc41564b2006-03-29 08:55:14 +1000916 * this by simply making sure the log gets flushed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 * if SYNC_BDFLUSH is set, and by actually writing it
918 * out otherwise.
David Chinner3c0dc772007-02-10 18:37:22 +1100919 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
920 * before we return (including direct I/O). Forms the drain
921 * side of the write barrier needed to safely quiesce the
922 * filesystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 *
924 */
925/*ARGSUSED*/
926STATIC int
927xfs_sync(
928 bhv_desc_t *bdp,
929 int flags,
930 cred_t *credp)
931{
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000932 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
David Chinner2a82b8b2007-07-11 11:09:12 +1000934 if (flags & SYNC_IOWAIT)
935 xfs_filestream_flush(mp);
936
David Chinner28239452007-02-10 18:36:40 +1100937 return xfs_syncsub(mp, flags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938}
939
940/*
941 * xfs sync routine for internal use
942 *
Nathan Scottb83bd132006-06-09 16:48:30 +1000943 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +1100944 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 *
946 */
Nathan Scottee348072005-11-02 10:32:38 +1100947int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948xfs_sync_inodes(
949 xfs_mount_t *mp,
950 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 int *bypassed)
952{
953 xfs_inode_t *ip = NULL;
954 xfs_inode_t *ip_next;
955 xfs_buf_t *bp;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000956 bhv_vnode_t *vp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 int error;
958 int last_error;
959 uint64_t fflag;
960 uint lock_flags;
961 uint base_lock_flags;
962 boolean_t mount_locked;
963 boolean_t vnode_refed;
964 int preempt;
965 xfs_dinode_t *dip;
966 xfs_iptr_t *ipointer;
967#ifdef DEBUG
968 boolean_t ipointer_in = B_FALSE;
969
970#define IPOINTER_SET ipointer_in = B_TRUE
971#define IPOINTER_CLR ipointer_in = B_FALSE
972#else
973#define IPOINTER_SET
974#define IPOINTER_CLR
975#endif
976
977
978/* Insert a marker record into the inode list after inode ip. The list
979 * must be locked when this is called. After the call the list will no
980 * longer be locked.
981 */
982#define IPOINTER_INSERT(ip, mp) { \
983 ASSERT(ipointer_in == B_FALSE); \
984 ipointer->ip_mnext = ip->i_mnext; \
985 ipointer->ip_mprev = ip; \
986 ip->i_mnext = (xfs_inode_t *)ipointer; \
987 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
988 preempt = 0; \
989 XFS_MOUNT_IUNLOCK(mp); \
990 mount_locked = B_FALSE; \
991 IPOINTER_SET; \
992 }
993
994/* Remove the marker from the inode list. If the marker was the only item
995 * in the list then there are no remaining inodes and we should zero out
996 * the whole list. If we are the current head of the list then move the head
997 * past us.
998 */
999#define IPOINTER_REMOVE(ip, mp) { \
1000 ASSERT(ipointer_in == B_TRUE); \
1001 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1002 ip = ipointer->ip_mnext; \
1003 ip->i_mprev = ipointer->ip_mprev; \
1004 ipointer->ip_mprev->i_mnext = ip; \
1005 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1006 mp->m_inodes = ip; \
1007 } \
1008 } else { \
1009 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1010 mp->m_inodes = NULL; \
1011 ip = NULL; \
1012 } \
1013 IPOINTER_CLR; \
1014 }
1015
1016#define XFS_PREEMPT_MASK 0x7f
1017
1018 if (bypassed)
1019 *bypassed = 0;
1020 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1021 return 0;
1022 error = 0;
1023 last_error = 0;
1024 preempt = 0;
1025
1026 /* Allocate a reference marker */
1027 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1028
1029 fflag = XFS_B_ASYNC; /* default is don't wait */
Nathan Scottee348072005-11-02 10:32:38 +11001030 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 fflag = XFS_B_DELWRI;
1032 if (flags & SYNC_WAIT)
1033 fflag = 0; /* synchronous overrides all */
1034
1035 base_lock_flags = XFS_ILOCK_SHARED;
1036 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1037 /*
1038 * We need the I/O lock if we're going to call any of
1039 * the flush/inval routines.
1040 */
1041 base_lock_flags |= XFS_IOLOCK_SHARED;
1042 }
1043
1044 XFS_MOUNT_ILOCK(mp);
1045
1046 ip = mp->m_inodes;
1047
1048 mount_locked = B_TRUE;
1049 vnode_refed = B_FALSE;
1050
1051 IPOINTER_CLR;
1052
1053 do {
1054 ASSERT(ipointer_in == B_FALSE);
1055 ASSERT(vnode_refed == B_FALSE);
1056
1057 lock_flags = base_lock_flags;
1058
1059 /*
1060 * There were no inodes in the list, just break out
1061 * of the loop.
1062 */
1063 if (ip == NULL) {
1064 break;
1065 }
1066
1067 /*
1068 * We found another sync thread marker - skip it
1069 */
1070 if (ip->i_mount == NULL) {
1071 ip = ip->i_mnext;
1072 continue;
1073 }
1074
1075 vp = XFS_ITOV_NULL(ip);
1076
1077 /*
1078 * If the vnode is gone then this is being torn down,
1079 * call reclaim if it is flushed, else let regular flush
1080 * code deal with it later in the loop.
1081 */
1082
1083 if (vp == NULL) {
1084 /* Skip ones already in reclaim */
1085 if (ip->i_flags & XFS_IRECLAIM) {
1086 ip = ip->i_mnext;
1087 continue;
1088 }
1089 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1090 ip = ip->i_mnext;
1091 } else if ((xfs_ipincount(ip) == 0) &&
1092 xfs_iflock_nowait(ip)) {
1093 IPOINTER_INSERT(ip, mp);
1094
1095 xfs_finish_reclaim(ip, 1,
1096 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1097
1098 XFS_MOUNT_ILOCK(mp);
1099 mount_locked = B_TRUE;
1100 IPOINTER_REMOVE(ip, mp);
1101 } else {
1102 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1103 ip = ip->i_mnext;
1104 }
1105 continue;
1106 }
1107
1108 if (VN_BAD(vp)) {
1109 ip = ip->i_mnext;
1110 continue;
1111 }
1112
1113 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1114 XFS_MOUNT_IUNLOCK(mp);
1115 kmem_free(ipointer, sizeof(xfs_iptr_t));
1116 return 0;
1117 }
1118
1119 /*
1120 * If this is just vfs_sync() or pflushd() calling
1121 * then we can skip inodes for which it looks like
1122 * there is nothing to do. Since we don't have the
Nathan Scottc41564b2006-03-29 08:55:14 +10001123 * inode locked this is racy, but these are periodic
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 * calls so it doesn't matter. For the others we want
1125 * to know for sure, so we at least try to lock them.
1126 */
1127 if (flags & SYNC_BDFLUSH) {
1128 if (((ip->i_itemp == NULL) ||
1129 !(ip->i_itemp->ili_format.ilf_fields &
1130 XFS_ILOG_ALL)) &&
1131 (ip->i_update_core == 0)) {
1132 ip = ip->i_mnext;
1133 continue;
1134 }
1135 }
1136
1137 /*
1138 * Try to lock without sleeping. We're out of order with
1139 * the inode list lock here, so if we fail we need to drop
1140 * the mount lock and try again. If we're called from
1141 * bdflush() here, then don't bother.
1142 *
1143 * The inode lock here actually coordinates with the
1144 * almost spurious inode lock in xfs_ireclaim() to prevent
1145 * the vnode we handle here without a reference from
1146 * being freed while we reference it. If we lock the inode
1147 * while it's on the mount list here, then the spurious inode
1148 * lock in xfs_ireclaim() after the inode is pulled from
1149 * the mount list will sleep until we release it here.
1150 * This keeps the vnode from being freed while we reference
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001151 * it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 */
1153 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1155 ip = ip->i_mnext;
1156 continue;
1157 }
1158
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001159 vp = vn_grab(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 if (vp == NULL) {
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001161 ip = ip->i_mnext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 continue;
1163 }
1164
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001165 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 xfs_ilock(ip, lock_flags);
1167
1168 ASSERT(vp == XFS_ITOV(ip));
1169 ASSERT(ip->i_mount == mp);
1170
1171 vnode_refed = B_TRUE;
1172 }
1173
1174 /* From here on in the loop we may have a marker record
1175 * in the inode list.
1176 */
1177
David Chinner40095b62007-05-14 18:24:09 +10001178 /*
1179 * If we have to flush data or wait for I/O completion
1180 * we need to drop the ilock that we currently hold.
1181 * If we need to drop the lock, insert a marker if we
1182 * have not already done so.
1183 */
1184 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1185 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1186 if (mount_locked) {
1187 IPOINTER_INSERT(ip, mp);
1188 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1190
David Chinner40095b62007-05-14 18:24:09 +10001191 if (flags & SYNC_CLOSE) {
1192 /* Shutdown case. Flush and invalidate. */
1193 if (XFS_FORCED_SHUTDOWN(mp))
1194 bhv_vop_toss_pages(vp, 0, -1, FI_REMAPF);
1195 else
1196 error = bhv_vop_flushinval_pages(vp, 0,
1197 -1, FI_REMAPF);
1198 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
Nathan Scott67fcaa72006-06-09 17:00:52 +10001199 error = bhv_vop_flush_pages(vp, (xfs_off_t)0,
1200 -1, fflag, FI_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 }
1202
David Chinner40095b62007-05-14 18:24:09 +10001203 /*
1204 * When freezing, we need to wait ensure all I/O (including direct
1205 * I/O) is complete to ensure no further data modification can take
1206 * place after this point
1207 */
1208 if (flags & SYNC_IOWAIT)
1209 vn_iowait(vp);
1210
1211 xfs_ilock(ip, XFS_ILOCK_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 }
1213
1214 if (flags & SYNC_BDFLUSH) {
1215 if ((flags & SYNC_ATTR) &&
1216 ((ip->i_update_core) ||
1217 ((ip->i_itemp != NULL) &&
1218 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1219
1220 /* Insert marker and drop lock if not already
1221 * done.
1222 */
1223 if (mount_locked) {
1224 IPOINTER_INSERT(ip, mp);
1225 }
1226
1227 /*
1228 * We don't want the periodic flushing of the
1229 * inodes by vfs_sync() to interfere with
1230 * I/O to the file, especially read I/O
1231 * where it is only the access time stamp
1232 * that is being flushed out. To prevent
1233 * long periods where we have both inode
1234 * locks held shared here while reading the
1235 * inode's buffer in from disk, we drop the
1236 * inode lock while reading in the inode
1237 * buffer. We have to release the buffer
1238 * and reacquire the inode lock so that they
1239 * are acquired in the proper order (inode
1240 * locks first). The buffer will go at the
1241 * end of the lru chain, though, so we can
1242 * expect it to still be there when we go
1243 * for it again in xfs_iflush().
1244 */
1245 if ((xfs_ipincount(ip) == 0) &&
1246 xfs_iflock_nowait(ip)) {
1247
1248 xfs_ifunlock(ip);
1249 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1250
1251 error = xfs_itobp(mp, NULL, ip,
Nathan Scottb12dd342006-03-17 17:26:04 +11001252 &dip, &bp, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 if (!error) {
1254 xfs_buf_relse(bp);
1255 } else {
1256 /* Bailing out, remove the
1257 * marker and free it.
1258 */
1259 XFS_MOUNT_ILOCK(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 IPOINTER_REMOVE(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 XFS_MOUNT_IUNLOCK(mp);
1262
1263 ASSERT(!(lock_flags &
1264 XFS_IOLOCK_SHARED));
1265
1266 kmem_free(ipointer,
1267 sizeof(xfs_iptr_t));
1268 return (0);
1269 }
1270
1271 /*
1272 * Since we dropped the inode lock,
1273 * the inode may have been reclaimed.
1274 * Therefore, we reacquire the mount
1275 * lock and check to see if we were the
1276 * inode reclaimed. If this happened
1277 * then the ipointer marker will no
1278 * longer point back at us. In this
1279 * case, move ip along to the inode
1280 * after the marker, remove the marker
1281 * and continue.
1282 */
1283 XFS_MOUNT_ILOCK(mp);
1284 mount_locked = B_TRUE;
1285
1286 if (ip != ipointer->ip_mprev) {
1287 IPOINTER_REMOVE(ip, mp);
1288
1289 ASSERT(!vnode_refed);
1290 ASSERT(!(lock_flags &
1291 XFS_IOLOCK_SHARED));
1292 continue;
1293 }
1294
1295 ASSERT(ip->i_mount == mp);
1296
1297 if (xfs_ilock_nowait(ip,
1298 XFS_ILOCK_SHARED) == 0) {
1299 ASSERT(ip->i_mount == mp);
1300 /*
1301 * We failed to reacquire
1302 * the inode lock without
1303 * sleeping, so just skip
1304 * the inode for now. We
1305 * clear the ILOCK bit from
1306 * the lock_flags so that we
1307 * won't try to drop a lock
1308 * we don't hold below.
1309 */
1310 lock_flags &= ~XFS_ILOCK_SHARED;
1311 IPOINTER_REMOVE(ip_next, mp);
1312 } else if ((xfs_ipincount(ip) == 0) &&
1313 xfs_iflock_nowait(ip)) {
1314 ASSERT(ip->i_mount == mp);
1315 /*
1316 * Since this is vfs_sync()
1317 * calling we only flush the
1318 * inode out if we can lock
1319 * it without sleeping and
1320 * it is not pinned. Drop
1321 * the mount lock here so
1322 * that we don't hold it for
1323 * too long. We already have
1324 * a marker in the list here.
1325 */
1326 XFS_MOUNT_IUNLOCK(mp);
1327 mount_locked = B_FALSE;
1328 error = xfs_iflush(ip,
1329 XFS_IFLUSH_DELWRI);
1330 } else {
1331 ASSERT(ip->i_mount == mp);
1332 IPOINTER_REMOVE(ip_next, mp);
1333 }
1334 }
1335
1336 }
1337
1338 } else {
1339 if ((flags & SYNC_ATTR) &&
1340 ((ip->i_update_core) ||
1341 ((ip->i_itemp != NULL) &&
1342 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1343 if (mount_locked) {
1344 IPOINTER_INSERT(ip, mp);
1345 }
1346
1347 if (flags & SYNC_WAIT) {
1348 xfs_iflock(ip);
1349 error = xfs_iflush(ip,
1350 XFS_IFLUSH_SYNC);
1351 } else {
1352 /*
1353 * If we can't acquire the flush
1354 * lock, then the inode is already
1355 * being flushed so don't bother
1356 * waiting. If we can lock it then
1357 * do a delwri flush so we can
1358 * combine multiple inode flushes
1359 * in each disk write.
1360 */
1361 if (xfs_iflock_nowait(ip)) {
1362 error = xfs_iflush(ip,
1363 XFS_IFLUSH_DELWRI);
1364 }
1365 else if (bypassed)
1366 (*bypassed)++;
1367 }
1368 }
1369 }
1370
1371 if (lock_flags != 0) {
1372 xfs_iunlock(ip, lock_flags);
1373 }
1374
1375 if (vnode_refed) {
1376 /*
1377 * If we had to take a reference on the vnode
1378 * above, then wait until after we've unlocked
1379 * the inode to release the reference. This is
1380 * because we can be already holding the inode
1381 * lock when VN_RELE() calls xfs_inactive().
1382 *
1383 * Make sure to drop the mount lock before calling
1384 * VN_RELE() so that we don't trip over ourselves if
1385 * we have to go for the mount lock again in the
1386 * inactive code.
1387 */
1388 if (mount_locked) {
1389 IPOINTER_INSERT(ip, mp);
1390 }
1391
1392 VN_RELE(vp);
1393
1394 vnode_refed = B_FALSE;
1395 }
1396
1397 if (error) {
1398 last_error = error;
1399 }
1400
1401 /*
1402 * bail out if the filesystem is corrupted.
1403 */
1404 if (error == EFSCORRUPTED) {
1405 if (!mount_locked) {
1406 XFS_MOUNT_ILOCK(mp);
1407 IPOINTER_REMOVE(ip, mp);
1408 }
1409 XFS_MOUNT_IUNLOCK(mp);
1410 ASSERT(ipointer_in == B_FALSE);
1411 kmem_free(ipointer, sizeof(xfs_iptr_t));
1412 return XFS_ERROR(error);
1413 }
1414
1415 /* Let other threads have a chance at the mount lock
1416 * if we have looped many times without dropping the
1417 * lock.
1418 */
1419 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1420 if (mount_locked) {
1421 IPOINTER_INSERT(ip, mp);
1422 }
1423 }
1424
1425 if (mount_locked == B_FALSE) {
1426 XFS_MOUNT_ILOCK(mp);
1427 mount_locked = B_TRUE;
1428 IPOINTER_REMOVE(ip, mp);
1429 continue;
1430 }
1431
1432 ASSERT(ipointer_in == B_FALSE);
1433 ip = ip->i_mnext;
1434
1435 } while (ip != mp->m_inodes);
1436
1437 XFS_MOUNT_IUNLOCK(mp);
1438
1439 ASSERT(ipointer_in == B_FALSE);
1440
1441 kmem_free(ipointer, sizeof(xfs_iptr_t));
1442 return XFS_ERROR(last_error);
1443}
1444
1445/*
1446 * xfs sync routine for internal use
1447 *
Nathan Scottb83bd132006-06-09 16:48:30 +10001448 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001449 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 *
1451 */
1452int
1453xfs_syncsub(
1454 xfs_mount_t *mp,
1455 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 int *bypassed)
1457{
1458 int error = 0;
1459 int last_error = 0;
1460 uint log_flags = XFS_LOG_FORCE;
1461 xfs_buf_t *bp;
1462 xfs_buf_log_item_t *bip;
1463
1464 /*
1465 * Sync out the log. This ensures that the log is periodically
1466 * flushed even if there is not enough activity to fill it up.
1467 */
1468 if (flags & SYNC_WAIT)
1469 log_flags |= XFS_LOG_SYNC;
1470
1471 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1472
1473 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1474 if (flags & SYNC_BDFLUSH)
1475 xfs_finish_reclaim_all(mp, 1);
1476 else
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001477 error = xfs_sync_inodes(mp, flags, bypassed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 }
1479
1480 /*
1481 * Flushing out dirty data above probably generated more
1482 * log activity, so if this isn't vfs_sync() then flush
1483 * the log again.
1484 */
1485 if (flags & SYNC_DELWRI) {
1486 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1487 }
1488
1489 if (flags & SYNC_FSDATA) {
1490 /*
1491 * If this is vfs_sync() then only sync the superblock
1492 * if we can lock it without sleeping and it is not pinned.
1493 */
1494 if (flags & SYNC_BDFLUSH) {
1495 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1496 if (bp != NULL) {
1497 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1498 if ((bip != NULL) &&
1499 xfs_buf_item_dirty(bip)) {
1500 if (!(XFS_BUF_ISPINNED(bp))) {
1501 XFS_BUF_ASYNC(bp);
1502 error = xfs_bwrite(mp, bp);
1503 } else {
1504 xfs_buf_relse(bp);
1505 }
1506 } else {
1507 xfs_buf_relse(bp);
1508 }
1509 }
1510 } else {
1511 bp = xfs_getsb(mp, 0);
1512 /*
1513 * If the buffer is pinned then push on the log so
1514 * we won't get stuck waiting in the write for
1515 * someone, maybe ourselves, to flush the log.
1516 * Even though we just pushed the log above, we
1517 * did not have the superblock buffer locked at
1518 * that point so it can become pinned in between
1519 * there and here.
1520 */
1521 if (XFS_BUF_ISPINNED(bp))
1522 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1523 if (flags & SYNC_WAIT)
1524 XFS_BUF_UNASYNC(bp);
1525 else
1526 XFS_BUF_ASYNC(bp);
1527 error = xfs_bwrite(mp, bp);
1528 }
1529 if (error) {
1530 last_error = error;
1531 }
1532 }
1533
1534 /*
1535 * If this is the periodic sync, then kick some entries out of
1536 * the reference cache. This ensures that idle entries are
1537 * eventually kicked out of the cache.
1538 */
1539 if (flags & SYNC_REFCACHE) {
Nathan Scottcde410a2005-09-05 11:47:01 +10001540 if (flags & SYNC_WAIT)
1541 xfs_refcache_purge_mp(mp);
1542 else
1543 xfs_refcache_purge_some(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 }
1545
1546 /*
David Chinner92821e22007-05-24 15:26:31 +10001547 * If asked, update the disk superblock with incore counter values if we
1548 * are using non-persistent counters so that they don't get too far out
1549 * of sync if we crash or get a forced shutdown. We don't want to force
1550 * this to disk, just get a transaction into the iclogs....
1551 */
1552 if (flags & SYNC_SUPER)
1553 xfs_log_sbcount(mp, 0);
1554
1555 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 * Now check to see if the log needs a "dummy" transaction.
1557 */
1558
1559 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1560 xfs_trans_t *tp;
1561 xfs_inode_t *ip;
1562
1563 /*
1564 * Put a dummy transaction in the log to tell
1565 * recovery that all others are OK.
1566 */
1567 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1568 if ((error = xfs_trans_reserve(tp, 0,
1569 XFS_ICHANGE_LOG_RES(mp),
1570 0, 0, 0))) {
1571 xfs_trans_cancel(tp, 0);
1572 return error;
1573 }
1574
1575 ip = mp->m_rootip;
1576 xfs_ilock(ip, XFS_ILOCK_EXCL);
1577
1578 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1579 xfs_trans_ihold(tp, ip);
1580 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
Eric Sandeen1c72bf92007-05-08 13:48:42 +10001581 error = xfs_trans_commit(tp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1583 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1584 }
1585
1586 /*
1587 * When shutting down, we need to insure that the AIL is pushed
1588 * to disk or the filesystem can appear corrupt from the PROM.
1589 */
1590 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1591 XFS_bflush(mp->m_ddev_targp);
1592 if (mp->m_rtdev_targp) {
1593 XFS_bflush(mp->m_rtdev_targp);
1594 }
1595 }
1596
1597 return XFS_ERROR(last_error);
1598}
1599
1600/*
1601 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1602 */
1603STATIC int
1604xfs_vget(
1605 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001606 bhv_vnode_t **vpp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 fid_t *fidp)
1608{
1609 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1610 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1611 xfs_inode_t *ip;
1612 int error;
1613 xfs_ino_t ino;
1614 unsigned int igen;
1615
1616 /*
1617 * Invalid. Since handles can be created in user space and passed in
1618 * via gethandle(), this is not cause for a panic.
1619 */
1620 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1621 return XFS_ERROR(EINVAL);
1622
1623 ino = xfid->xfs_fid_ino;
1624 igen = xfid->xfs_fid_gen;
1625
1626 /*
1627 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1628 */
1629 if (ino == 0)
1630 return XFS_ERROR(ESTALE);
1631
1632 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1633 if (error) {
1634 *vpp = NULL;
1635 return error;
1636 }
1637
1638 if (ip == NULL) {
1639 *vpp = NULL;
1640 return XFS_ERROR(EIO);
1641 }
1642
1643 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1644 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1645 *vpp = NULL;
1646 return XFS_ERROR(ENOENT);
1647 }
1648
1649 *vpp = XFS_ITOV(ip);
1650 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1651 return 0;
1652}
1653
1654
1655#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1656#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1657#define MNTOPT_LOGDEV "logdev" /* log device */
1658#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1659#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1660#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1661#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1662#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1663#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1664#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1665#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1666#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1667#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
Nathan Scotte69a3332005-09-02 16:42:26 +10001668#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1669#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1670#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1671#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
Nathan Scott1f443ad2005-05-05 13:28:29 -07001672#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001674#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
Nathan Scottd8cc8902005-11-02 10:34:53 +11001675 * unwritten extent conversion */
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001676#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1678#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1679#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1680#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
David Chinnere8c8b3a2005-11-02 10:33:05 +11001681#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1682#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1683 * in stat(). */
Nathan Scottd8cc8902005-11-02 10:34:53 +11001684#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1685#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
David Chinner2a82b8b2007-07-11 11:09:12 +10001686#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
Nathan Scott1f443ad2005-05-05 13:28:29 -07001688STATIC unsigned long
Nathan Scottb190f112006-06-09 17:13:15 +10001689suffix_strtoul(char *s, char **endp, unsigned int base)
Nathan Scott1f443ad2005-05-05 13:28:29 -07001690{
1691 int last, shift_left_factor = 0;
Nathan Scottb190f112006-06-09 17:13:15 +10001692 char *value = s;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001693
1694 last = strlen(value) - 1;
1695 if (value[last] == 'K' || value[last] == 'k') {
1696 shift_left_factor = 10;
1697 value[last] = '\0';
1698 }
1699 if (value[last] == 'M' || value[last] == 'm') {
1700 shift_left_factor = 20;
1701 value[last] = '\0';
1702 }
1703 if (value[last] == 'G' || value[last] == 'g') {
1704 shift_left_factor = 30;
1705 value[last] = '\0';
1706 }
1707
Nathan Scottb190f112006-06-09 17:13:15 +10001708 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001709}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10001711STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712xfs_parseargs(
1713 struct bhv_desc *bhv,
1714 char *options,
1715 struct xfs_mount_args *args,
1716 int update)
1717{
Nathan Scottb83bd132006-06-09 16:48:30 +10001718 bhv_vfs_t *vfsp = bhvtovfs(bhv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 char *this_char, *value, *eov;
1720 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1721 int iosize;
1722
Nathan Scotte15f1952006-03-22 12:47:52 +11001723 args->flags |= XFSMNT_IDELETE;
Nathan Scott3bbcc8e2006-03-31 13:04:56 +10001724 args->flags |= XFSMNT_BARRIER;
1725 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726
1727 if (!options)
Nathan Scott05db2182005-11-04 09:49:07 +11001728 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
1730 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1731
1732 while ((this_char = strsep(&options, ",")) != NULL) {
1733 if (!*this_char)
1734 continue;
1735 if ((value = strchr(this_char, '=')) != NULL)
1736 *value++ = 0;
1737
1738 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1739 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001740 cmn_err(CE_WARN,
1741 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001742 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 return EINVAL;
1744 }
1745 args->logbufs = simple_strtoul(value, &eov, 10);
1746 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001748 cmn_err(CE_WARN,
1749 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001750 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 return EINVAL;
1752 }
Nathan Scott1f443ad2005-05-05 13:28:29 -07001753 args->logbufsize = suffix_strtoul(value, &eov, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1755 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001756 cmn_err(CE_WARN,
1757 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001758 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 return EINVAL;
1760 }
1761 strncpy(args->logname, value, MAXNAMELEN);
1762 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1763 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001764 cmn_err(CE_WARN,
1765 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001766 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 return EINVAL;
1768 }
1769 strncpy(args->mtpt, value, MAXNAMELEN);
1770 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1771 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001772 cmn_err(CE_WARN,
1773 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001774 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 return EINVAL;
1776 }
1777 strncpy(args->rtname, value, MAXNAMELEN);
1778 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1779 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001780 cmn_err(CE_WARN,
1781 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001782 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 return EINVAL;
1784 }
1785 iosize = simple_strtoul(value, &eov, 10);
1786 args->flags |= XFSMNT_IOSIZE;
1787 args->iosizelog = (uint8_t) iosize;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001788 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1789 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001790 cmn_err(CE_WARN,
1791 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001792 this_char);
1793 return EINVAL;
1794 }
1795 iosize = suffix_strtoul(value, &eov, 10);
1796 args->flags |= XFSMNT_IOSIZE;
1797 args->iosizelog = ffs(iosize) - 1;
Nathan Scotte69a3332005-09-02 16:42:26 +10001798 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1799 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1800 vfsp->vfs_flag |= VFS_GRPID;
1801 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1802 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1803 vfsp->vfs_flag &= ~VFS_GRPID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1805 args->flags |= XFSMNT_WSYNC;
1806 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1807 args->flags |= XFSMNT_OSYNCISOSYNC;
1808 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1809 args->flags |= XFSMNT_NORECOVERY;
1810 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1811 args->flags |= XFSMNT_INO64;
1812#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001813 cmn_err(CE_WARN,
1814 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001815 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 return EINVAL;
1817#endif
1818 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1819 args->flags |= XFSMNT_NOALIGN;
1820 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1821 args->flags |= XFSMNT_SWALLOC;
1822 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1823 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001824 cmn_err(CE_WARN,
1825 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001826 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 return EINVAL;
1828 }
1829 dsunit = simple_strtoul(value, &eov, 10);
1830 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1831 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001832 cmn_err(CE_WARN,
1833 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001834 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 return EINVAL;
1836 }
1837 dswidth = simple_strtoul(value, &eov, 10);
1838 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1839 args->flags &= ~XFSMNT_32BITINODES;
1840#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001841 cmn_err(CE_WARN,
1842 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001843 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 return EINVAL;
1845#endif
1846 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1847 args->flags |= XFSMNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001848 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1849 args->flags |= XFSMNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001850 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1851 args->flags &= ~XFSMNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1853 args->flags &= ~XFSMNT_IDELETE;
1854 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1855 args->flags |= XFSMNT_IDELETE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001856 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001857 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001858 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001859 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001860 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001861 args->flags |= XFSMNT_ATTR2;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001862 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001863 args->flags &= ~XFSMNT_ATTR2;
David Chinner2a82b8b2007-07-11 11:09:12 +10001864 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1865 args->flags2 |= XFSMNT2_FILESTREAMS;
David Chinnerda353b02007-08-28 14:00:13 +10001866 } else if (!strcmp(this_char, "ihashsize")) {
1867 cmn_err(CE_WARN,
1868 "XFS: ihashsize no longer used, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 } else if (!strcmp(this_char, "osyncisdsync")) {
1870 /* no-op, this is now the default */
Nathan Scottb6574522006-06-09 15:29:40 +10001871 cmn_err(CE_WARN,
1872 "XFS: osyncisdsync is now the default, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 } else if (!strcmp(this_char, "irixsgid")) {
Nathan Scottb6574522006-06-09 15:29:40 +10001874 cmn_err(CE_WARN,
1875 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 } else {
Nathan Scottb6574522006-06-09 15:29:40 +10001877 cmn_err(CE_WARN,
1878 "XFS: unknown mount option [%s].", this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 return EINVAL;
1880 }
1881 }
1882
1883 if (args->flags & XFSMNT_NORECOVERY) {
1884 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
Nathan Scottb6574522006-06-09 15:29:40 +10001885 cmn_err(CE_WARN,
1886 "XFS: no-recovery mounts must be read-only.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 return EINVAL;
1888 }
1889 }
1890
1891 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001892 cmn_err(CE_WARN,
1893 "XFS: sunit and swidth options incompatible with the noalign option");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 return EINVAL;
1895 }
1896
1897 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001898 cmn_err(CE_WARN,
1899 "XFS: sunit and swidth must be specified together");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 return EINVAL;
1901 }
1902
1903 if (dsunit && (dswidth % dsunit != 0)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001904 cmn_err(CE_WARN,
1905 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 dswidth, dsunit);
1907 return EINVAL;
1908 }
1909
1910 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1911 if (dsunit) {
1912 args->sunit = dsunit;
1913 args->flags |= XFSMNT_RETERR;
1914 } else {
1915 args->sunit = vol_dsunit;
1916 }
1917 dswidth ? (args->swidth = dswidth) :
1918 (args->swidth = vol_dswidth);
1919 } else {
1920 args->sunit = args->swidth = 0;
1921 }
1922
Nathan Scott05db2182005-11-04 09:49:07 +11001923done:
Nathan Scottc11e2c32005-11-02 15:11:45 +11001924 if (args->flags & XFSMNT_32BITINODES)
1925 vfsp->vfs_flag |= VFS_32BITINODES;
Nathan Scotte718eeb42005-11-02 15:09:22 +11001926 if (args->flags2)
1927 args->flags |= XFSMNT_FLAGS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 return 0;
1929}
1930
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10001931STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932xfs_showargs(
1933 struct bhv_desc *bhv,
1934 struct seq_file *m)
1935{
1936 static struct proc_xfs_info {
1937 int flag;
1938 char *str;
1939 } xfs_info[] = {
1940 /* the few simple ones we can get from the mount struct */
1941 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1942 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1943 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1944 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1945 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1946 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1947 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 { 0, NULL }
1949 };
1950 struct proc_xfs_info *xfs_infop;
1951 struct xfs_mount *mp = XFS_BHVTOM(bhv);
Nathan Scottb83bd132006-06-09 16:48:30 +10001952 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
1954 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1955 if (mp->m_flags & xfs_infop->flag)
1956 seq_puts(m, xfs_infop->str);
1957 }
1958
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001960 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1961 (int)(1 << mp->m_writeio_log) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
1963 if (mp->m_logbufs > 0)
1964 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 if (mp->m_logbsize > 0)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001966 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001968 if (mp->m_logname)
1969 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001970 if (mp->m_rtname)
1971 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972
1973 if (mp->m_dalign > 0)
1974 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1975 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 if (mp->m_swidth > 0)
1977 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1978 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1979
Nathan Scotte15f1952006-03-22 12:47:52 +11001980 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1981 seq_printf(m, "," MNTOPT_IKEEP);
Nathan Scottfa7e7d72005-11-02 15:00:48 +11001982 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1983 seq_printf(m, "," MNTOPT_LARGEIO);
1984
Nathan Scottc11e2c32005-11-02 15:11:45 +11001985 if (!(vfsp->vfs_flag & VFS_32BITINODES))
1986 seq_printf(m, "," MNTOPT_64BITINODE);
Nathan Scotte69a3332005-09-02 16:42:26 +10001987 if (vfsp->vfs_flag & VFS_GRPID)
1988 seq_printf(m, "," MNTOPT_GRPID);
1989
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 return 0;
1991}
1992
David Chinner28239452007-02-10 18:36:40 +11001993/*
David Chinner516b2e72007-06-18 16:50:48 +10001994 * Second stage of a freeze. The data is already frozen so we only
1995 * need to take care of themetadata. Once that's done write a dummy
1996 * record to dirty the log in case of a crash while frozen.
David Chinner28239452007-02-10 18:36:40 +11001997 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998STATIC void
1999xfs_freeze(
2000 bhv_desc_t *bdp)
2001{
2002 xfs_mount_t *mp = XFS_BHVTOM(bdp);
2003
David Chinner516b2e72007-06-18 16:50:48 +10002004 xfs_attr_quiesce(mp);
Christoph Hellwige13a73f2006-01-11 15:30:08 +11002005 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006}
2007
2008
Nathan Scottb83bd132006-06-09 16:48:30 +10002009bhv_vfsops_t xfs_vfsops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
2011 .vfs_parseargs = xfs_parseargs,
2012 .vfs_showargs = xfs_showargs,
2013 .vfs_mount = xfs_mount,
2014 .vfs_unmount = xfs_unmount,
2015 .vfs_mntupdate = xfs_mntupdate,
2016 .vfs_root = xfs_root,
2017 .vfs_statvfs = xfs_statvfs,
2018 .vfs_sync = xfs_sync,
2019 .vfs_vget = xfs_vget,
2020 .vfs_dmapiops = (vfs_dmapiops_t)fs_nosys,
2021 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
2022 .vfs_init_vnode = xfs_initialize_vnode,
2023 .vfs_force_shutdown = xfs_do_force_shutdown,
2024 .vfs_freeze = xfs_freeze,
2025};