blob: 11f5ea29a0388e62abc4a69507171db69214183c [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);
120 xfs_chashlist_zone =
121 kmem_zone_init_flags(sizeof(xfs_chashlist_t), "xfs_chashlist",
122 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;
166 extern kmem_zone_t *xfs_chashlist_zone;
167
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);
202 kmem_zone_destroy(xfs_chashlist_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 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 ap->logbufsize != 16 * 1024 &&
242 ap->logbufsize != 32 * 1024 &&
243 ap->logbufsize != 64 * 1024 &&
244 ap->logbufsize != 128 * 1024 &&
245 ap->logbufsize != 256 * 1024) {
246 cmn_err(CE_WARN,
247 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
248 ap->logbufsize);
249 return XFS_ERROR(EINVAL);
250 }
251 mp->m_ihsize = ap->ihashsize;
252 mp->m_logbsize = ap->logbufsize;
253 mp->m_fsname_len = strlen(ap->fsname) + 1;
254 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
255 strcpy(mp->m_fsname, ap->fsname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +1100256 if (ap->rtname[0]) {
257 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
258 strcpy(mp->m_rtname, ap->rtname);
259 }
260 if (ap->logname[0]) {
261 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
262 strcpy(mp->m_logname, ap->logname);
263 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 if (ap->flags & XFSMNT_WSYNC)
266 mp->m_flags |= XFS_MOUNT_WSYNC;
267#if XFS_BIG_INUMS
268 if (ap->flags & XFSMNT_INO64) {
269 mp->m_flags |= XFS_MOUNT_INO64;
270 mp->m_inoadd = XFS_INO64_OFFSET;
271 }
272#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (ap->flags & XFSMNT_RETERR)
274 mp->m_flags |= XFS_MOUNT_RETERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if (ap->flags & XFSMNT_NOALIGN)
276 mp->m_flags |= XFS_MOUNT_NOALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 if (ap->flags & XFSMNT_SWALLOC)
278 mp->m_flags |= XFS_MOUNT_SWALLOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (ap->flags & XFSMNT_OSYNCISOSYNC)
280 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 if (ap->flags & XFSMNT_32BITINODES)
Nathan Scottc11e2c32005-11-02 15:11:45 +1100282 mp->m_flags |= XFS_MOUNT_32BITINODES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 if (ap->flags & XFSMNT_IOSIZE) {
285 if (ap->iosizelog > XFS_MAX_IO_LOG ||
286 ap->iosizelog < XFS_MIN_IO_LOG) {
287 cmn_err(CE_WARN,
288 "XFS: invalid log iosize: %d [not %d-%d]",
289 ap->iosizelog, XFS_MIN_IO_LOG,
290 XFS_MAX_IO_LOG);
291 return XFS_ERROR(EINVAL);
292 }
293
294 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
295 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
296 }
297
298 if (ap->flags & XFSMNT_IHASHSIZE)
299 mp->m_flags |= XFS_MOUNT_IHASHSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 if (ap->flags & XFSMNT_IDELETE)
301 mp->m_flags |= XFS_MOUNT_IDELETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 if (ap->flags & XFSMNT_DIRSYNC)
303 mp->m_flags |= XFS_MOUNT_DIRSYNC;
Nathan Scott13059ff2006-01-11 15:32:01 +1100304 if (ap->flags & XFSMNT_ATTR2)
305 mp->m_flags |= XFS_MOUNT_ATTR2;
David Chinnere8c8b3a2005-11-02 10:33:05 +1100306
Nathan Scotte718eeb2005-11-02 15:09:22 +1100307 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
308 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 /*
311 * no recovery flag requires a read-only mount
312 */
313 if (ap->flags & XFSMNT_NORECOVERY) {
314 if (!(vfs->vfs_flag & VFS_RDONLY)) {
315 cmn_err(CE_WARN,
316 "XFS: tried to mount a FS read-write without recovery!");
317 return XFS_ERROR(EINVAL);
318 }
319 mp->m_flags |= XFS_MOUNT_NORECOVERY;
320 }
321
322 if (ap->flags & XFSMNT_NOUUID)
323 mp->m_flags |= XFS_MOUNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100324 if (ap->flags & XFSMNT_BARRIER)
325 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100326 else
327 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
David Chinner2a82b8b2007-07-11 11:09:12 +1000329 if (ap->flags2 & XFSMNT2_FILESTREAMS)
330 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 return 0;
333}
334
335/*
336 * This function fills in xfs_mount_t fields based on mount args.
337 * Note: the superblock _has_ now been read in.
338 */
339STATIC int
340xfs_finish_flags(
Nathan Scottb83bd132006-06-09 16:48:30 +1000341 struct bhv_vfs *vfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 struct xfs_mount_args *ap,
343 struct xfs_mount *mp)
344{
345 int ronly = (vfs->vfs_flag & VFS_RDONLY);
346
347 /* Fail a mount where the logbuf is smaller then the log stripe */
348 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
Nathan Scottc2cd2552006-01-11 15:35:32 +1100349 if ((ap->logbufsize <= 0) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
351 mp->m_logbsize = mp->m_sb.sb_logsunit;
Nathan Scottc2cd2552006-01-11 15:35:32 +1100352 } else if (ap->logbufsize > 0 &&
353 ap->logbufsize < mp->m_sb.sb_logsunit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 cmn_err(CE_WARN,
355 "XFS: logbuf size must be greater than or equal to log stripe size");
356 return XFS_ERROR(EINVAL);
357 }
358 } else {
359 /* Fail a mount if the logbuf is larger than 32K */
360 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
361 cmn_err(CE_WARN,
362 "XFS: logbuf size for version 1 logs must be 16K or 32K");
363 return XFS_ERROR(EINVAL);
364 }
365 }
366
Nathan Scott13059ff2006-01-11 15:32:01 +1100367 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
368 mp->m_flags |= XFS_MOUNT_ATTR2;
369 }
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /*
372 * prohibit r/w mounts of read-only filesystems
373 */
374 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
375 cmn_err(CE_WARN,
376 "XFS: cannot mount a read-only filesystem as read-write");
377 return XFS_ERROR(EROFS);
378 }
379
380 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 * check for shared mount.
382 */
383 if (ap->flags & XFSMNT_SHARED) {
384 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
385 return XFS_ERROR(EINVAL);
386
387 /*
388 * For IRIX 6.5, shared mounts must have the shared
389 * version bit set, have the persistent readonly
390 * field set, must be version 0 and can only be mounted
391 * read-only.
392 */
393 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
394 (mp->m_sb.sb_shared_vn != 0))
395 return XFS_ERROR(EINVAL);
396
397 mp->m_flags |= XFS_MOUNT_SHARED;
398
399 /*
400 * Shared XFS V0 can't deal with DMI. Return EINVAL.
401 */
402 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
403 return XFS_ERROR(EINVAL);
404 }
405
406 return 0;
407}
408
409/*
410 * xfs_mount
411 *
412 * The file system configurations are:
413 * (1) device (partition) with data and internal log
414 * (2) logical volume with data and log subvolumes.
415 * (3) logical volume with data, log, and realtime subvolumes.
416 *
417 * We only have to handle opening the log and realtime volumes here if
418 * they are present. The data subvolume has already been opened by
419 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
420 */
421STATIC int
422xfs_mount(
423 struct bhv_desc *bhvp,
424 struct xfs_mount_args *args,
425 cred_t *credp)
426{
Nathan Scottb83bd132006-06-09 16:48:30 +1000427 struct bhv_vfs *vfsp = bhvtovfs(bhvp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 struct bhv_desc *p;
429 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
430 struct block_device *ddev, *logdev, *rtdev;
431 int flags = 0, error;
432
433 ddev = vfsp->vfs_super->s_bdev;
434 logdev = rtdev = NULL;
435
436 /*
437 * Setup xfs_mount function vectors from available behaviors
438 */
439 p = vfs_bhv_lookup(vfsp, VFS_POSITION_DM);
440 mp->m_dm_ops = p ? *(xfs_dmops_t *) vfs_bhv_custom(p) : xfs_dmcore_stub;
441 p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM);
442 mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub;
443 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
444 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
445
Nathan Scott764d1f82006-03-31 13:04:17 +1000446 if (args->flags & XFSMNT_QUIET)
447 flags |= XFS_MFSI_QUIET;
448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 /*
450 * Open real time and log devices - order is important.
451 */
452 if (args->logname[0]) {
453 error = xfs_blkdev_get(mp, args->logname, &logdev);
454 if (error)
455 return error;
456 }
457 if (args->rtname[0]) {
458 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
459 if (error) {
460 xfs_blkdev_put(logdev);
461 return error;
462 }
463
464 if (rtdev == ddev || rtdev == logdev) {
465 cmn_err(CE_WARN,
466 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
467 xfs_blkdev_put(logdev);
468 xfs_blkdev_put(rtdev);
469 return EINVAL;
470 }
471 }
472
473 /*
474 * Setup xfs_mount buffer target pointers
475 */
476 error = ENOMEM;
477 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
478 if (!mp->m_ddev_targp) {
479 xfs_blkdev_put(logdev);
480 xfs_blkdev_put(rtdev);
481 return error;
482 }
483 if (rtdev) {
484 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
485 if (!mp->m_rtdev_targp)
486 goto error0;
487 }
488 mp->m_logdev_targp = (logdev && logdev != ddev) ?
489 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
490 if (!mp->m_logdev_targp)
491 goto error0;
492
493 /*
494 * Setup flags based on mount(2) options and then the superblock
495 */
496 error = xfs_start_flags(vfsp, args, mp);
497 if (error)
498 goto error1;
Nathan Scott764d1f82006-03-31 13:04:17 +1000499 error = xfs_readsb(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if (error)
501 goto error1;
502 error = xfs_finish_flags(vfsp, args, mp);
503 if (error)
504 goto error2;
505
506 /*
507 * Setup xfs_mount buffer target pointers based on superblock
508 */
509 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
510 mp->m_sb.sb_sectsize);
511 if (!error && logdev && logdev != ddev) {
512 unsigned int log_sector_size = BBSIZE;
513
514 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
515 log_sector_size = mp->m_sb.sb_logsectsize;
516 error = xfs_setsize_buftarg(mp->m_logdev_targp,
517 mp->m_sb.sb_blocksize,
518 log_sector_size);
519 }
520 if (!error && rtdev)
521 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
522 mp->m_sb.sb_blocksize,
523 mp->m_sb.sb_sectsize);
524 if (error)
525 goto error2;
526
Nathan Scottb2ea4012006-07-28 17:05:13 +1000527 if (mp->m_flags & XFS_MOUNT_BARRIER)
Christoph Hellwigc7d437d2006-01-11 15:28:56 +1100528 xfs_mountfs_check_barriers(mp);
529
David Chinner2a82b8b2007-07-11 11:09:12 +1000530 if ((error = xfs_filestream_mount(mp)))
531 goto error2;
532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 error = XFS_IOINIT(vfsp, args, flags);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100534 if (error)
535 goto error2;
536
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100537 return 0;
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539error2:
540 if (mp->m_sb_bp)
541 xfs_freesb(mp);
542error1:
543 xfs_binval(mp->m_ddev_targp);
544 if (logdev && logdev != ddev)
545 xfs_binval(mp->m_logdev_targp);
546 if (rtdev)
547 xfs_binval(mp->m_rtdev_targp);
548error0:
549 xfs_unmountfs_close(mp, credp);
550 return error;
551}
552
553STATIC int
554xfs_unmount(
555 bhv_desc_t *bdp,
556 int flags,
557 cred_t *credp)
558{
Nathan Scottb83bd132006-06-09 16:48:30 +1000559 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 xfs_mount_t *mp = XFS_BHVTOM(bdp);
561 xfs_inode_t *rip;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000562 bhv_vnode_t *rvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 int unmount_event_wanted = 0;
564 int unmount_event_flags = 0;
565 int xfs_unmountfs_needed = 0;
566 int error;
567
568 rip = mp->m_rootip;
569 rvp = XFS_ITOV(rip);
570
571 if (vfsp->vfs_flag & VFS_DMI) {
572 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
573 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
574 NULL, NULL, 0, 0,
575 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
576 0:DM_FLAGS_UNWANTED);
577 if (error)
578 return XFS_ERROR(error);
579 unmount_event_wanted = 1;
580 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
581 0 : DM_FLAGS_UNWANTED;
582 }
583
584 /*
585 * First blow any referenced inode from this file system
586 * out of the reference cache, and delete the timer.
587 */
588 xfs_refcache_purge_mp(mp);
589
David Chinner2a82b8b2007-07-11 11:09:12 +1000590 /*
591 * Blow away any referenced inode in the filestreams cache.
592 * This can and will cause log traffic as inodes go inactive
593 * here.
594 */
595 xfs_filestream_unmount(mp);
596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 XFS_bflush(mp->m_ddev_targp);
598 error = xfs_unmount_flush(mp, 0);
599 if (error)
600 goto out;
601
602 ASSERT(vn_count(rvp) == 1);
603
604 /*
605 * Drop the reference count
606 */
607 VN_RELE(rvp);
608
609 /*
610 * If we're forcing a shutdown, typically because of a media error,
611 * we want to make sure we invalidate dirty pages that belong to
612 * referenced vnodes as well.
613 */
614 if (XFS_FORCED_SHUTDOWN(mp)) {
615 error = xfs_sync(&mp->m_bhv,
616 (SYNC_WAIT | SYNC_CLOSE), credp);
617 ASSERT(error != EFSCORRUPTED);
618 }
619 xfs_unmountfs_needed = 1;
620
621out:
622 /* Send DMAPI event, if required.
623 * Then do xfs_unmountfs() if needed.
624 * Then return error (or zero).
625 */
626 if (unmount_event_wanted) {
627 /* Note: mp structure must still exist for
628 * XFS_SEND_UNMOUNT() call.
629 */
630 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
631 DM_RIGHT_NULL, 0, error, unmount_event_flags);
632 }
633 if (xfs_unmountfs_needed) {
634 /*
635 * Call common unmount function to flush to disk
636 * and free the super block buffer & mount structures.
637 */
638 xfs_unmountfs(mp, credp);
639 }
640
641 return XFS_ERROR(error);
642}
643
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000644STATIC int
645xfs_quiesce_fs(
646 xfs_mount_t *mp)
647{
648 int count = 0, pincount;
Nathan Scott3758dee2006-03-22 12:47:28 +1100649
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000650 xfs_refcache_purge_mp(mp);
651 xfs_flush_buftarg(mp->m_ddev_targp, 0);
652 xfs_finish_reclaim_all(mp, 0);
653
654 /* This loop must run at least twice.
655 * The first instance of the loop will flush
656 * most meta data but that will generate more
657 * meta data (typically directory updates).
658 * Which then must be flushed and logged before
659 * we can write the unmount record.
Nathan Scott3758dee2006-03-22 12:47:28 +1100660 */
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000661 do {
David Chinner516b2e72007-06-18 16:50:48 +1000662 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000663 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
664 if (!pincount) {
665 delay(50);
666 count++;
667 }
668 } while (count < 2);
669
670 return 0;
671}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
David Chinner516b2e72007-06-18 16:50:48 +1000673/*
674 * Second stage of a quiesce. The data is already synced, now we have to take
675 * care of the metadata. New transactions are already blocked, so we need to
676 * wait for any remaining transactions to drain out before proceding.
677 */
678STATIC void
679xfs_attr_quiesce(
680 xfs_mount_t *mp)
681{
682 /* wait for all modifications to complete */
683 while (atomic_read(&mp->m_active_trans) > 0)
684 delay(100);
685
686 /* flush inodes and push all remaining buffers out to disk */
687 xfs_quiesce_fs(mp);
688
689 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
690
691 /* Push the superblock and write an unmount record */
692 xfs_log_sbcount(mp, 1);
693 xfs_log_unmount_write(mp);
694 xfs_unmountfs_writesb(mp);
695}
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697STATIC int
698xfs_mntupdate(
699 bhv_desc_t *bdp,
700 int *flags,
701 struct xfs_mount_args *args)
702{
Nathan Scottb83bd132006-06-09 16:48:30 +1000703 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Nathan Scottd08d3892006-05-08 19:51:28 +1000706 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
707 if (vfsp->vfs_flag & VFS_RDONLY)
708 vfsp->vfs_flag &= ~VFS_RDONLY;
709 if (args->flags & XFSMNT_BARRIER) {
710 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100711 xfs_mountfs_check_barriers(mp);
Nathan Scottd08d3892006-05-08 19:51:28 +1000712 } else {
713 mp->m_flags &= ~XFS_MOUNT_BARRIER;
714 }
715 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
David Chinner2a82b8b2007-07-11 11:09:12 +1000716 xfs_filestream_flush(mp);
David Chinner516b2e72007-06-18 16:50:48 +1000717 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
718 xfs_attr_quiesce(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 vfsp->vfs_flag |= VFS_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 return 0;
722}
723
724/*
725 * xfs_unmount_flush implements a set of flush operation on special
726 * inodes, which are needed as a separate set of operations so that
727 * they can be called as part of relocation process.
728 */
729int
730xfs_unmount_flush(
731 xfs_mount_t *mp, /* Mount structure we are getting
732 rid of. */
733 int relocation) /* Called from vfs relocation. */
734{
735 xfs_inode_t *rip = mp->m_rootip;
736 xfs_inode_t *rbmip;
737 xfs_inode_t *rsumip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000738 bhv_vnode_t *rvp = XFS_ITOV(rip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 int error;
740
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000741 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 xfs_iflock(rip);
743
744 /*
745 * Flush out the real time inodes.
746 */
747 if ((rbmip = mp->m_rbmip) != NULL) {
748 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
749 xfs_iflock(rbmip);
750 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
751 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
752
753 if (error == EFSCORRUPTED)
754 goto fscorrupt_out;
755
756 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
757
758 rsumip = mp->m_rsumip;
759 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
760 xfs_iflock(rsumip);
761 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
762 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
763
764 if (error == EFSCORRUPTED)
765 goto fscorrupt_out;
766
767 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
768 }
769
770 /*
771 * Synchronously flush root inode to disk
772 */
773 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
774 if (error == EFSCORRUPTED)
775 goto fscorrupt_out2;
776
777 if (vn_count(rvp) != 1 && !relocation) {
778 xfs_iunlock(rip, XFS_ILOCK_EXCL);
779 return XFS_ERROR(EBUSY);
780 }
781
782 /*
783 * Release dquot that rootinode, rbmino and rsumino might be holding,
784 * flush and purge the quota inodes.
785 */
786 error = XFS_QM_UNMOUNT(mp);
787 if (error == EFSCORRUPTED)
788 goto fscorrupt_out2;
789
790 if (rbmip) {
791 VN_RELE(XFS_ITOV(rbmip));
792 VN_RELE(XFS_ITOV(rsumip));
793 }
794
795 xfs_iunlock(rip, XFS_ILOCK_EXCL);
796 return 0;
797
798fscorrupt_out:
799 xfs_ifunlock(rip);
800
801fscorrupt_out2:
802 xfs_iunlock(rip, XFS_ILOCK_EXCL);
803
804 return XFS_ERROR(EFSCORRUPTED);
805}
806
807/*
808 * xfs_root extracts the root vnode from a vfs.
809 *
810 * vfsp -- the vfs struct for the desired file system
811 * vpp -- address of the caller's vnode pointer which should be
812 * set to the desired fs root vnode
813 */
814STATIC int
815xfs_root(
816 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000817 bhv_vnode_t **vpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000819 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820
821 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
822 VN_HOLD(vp);
823 *vpp = vp;
824 return 0;
825}
826
827/*
828 * xfs_statvfs
829 *
830 * Fill in the statvfs structure for the given file system. We use
831 * the superblock lock in the mount structure to ensure a consistent
832 * snapshot of the counters returned.
833 */
834STATIC int
835xfs_statvfs(
836 bhv_desc_t *bdp,
Nathan Scott8285fb52006-06-09 17:07:12 +1000837 bhv_statvfs_t *statp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000838 bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839{
840 __uint64_t fakeinos;
841 xfs_extlen_t lsize;
842 xfs_mount_t *mp;
843 xfs_sb_t *sbp;
844 unsigned long s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845
846 mp = XFS_BHVTOM(bdp);
847 sbp = &(mp->m_sb);
848
849 statp->f_type = XFS_SB_MAGIC;
850
David Chinnerdbcabad2007-02-10 18:36:17 +1100851 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 s = XFS_SB_LOCK(mp);
853 statp->f_bsize = sbp->sb_blocksize;
854 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
855 statp->f_blocks = sbp->sb_dblocks - lsize;
David Chinner4be536d2006-09-07 14:26:50 +1000856 statp->f_bfree = statp->f_bavail =
857 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 fakeinos = statp->f_bfree << sbp->sb_inopblog;
859#if XFS_BIG_INUMS
860 fakeinos += mp->m_inoadd;
861#endif
862 statp->f_files =
863 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
864 if (mp->m_maxicount)
865#if XFS_BIG_INUMS
866 if (!mp->m_inoadd)
867#endif
868 statp->f_files = min_t(typeof(statp->f_files),
869 statp->f_files,
870 mp->m_maxicount);
871 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
872 XFS_SB_UNLOCK(mp, s);
873
Nathan Scottcde410a2005-09-05 11:47:01 +1000874 xfs_statvfs_fsid(statp, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 statp->f_namelen = MAXNAMELEN - 1;
876
877 return 0;
878}
879
880
881/*
882 * xfs_sync flushes any pending I/O to file system vfsp.
883 *
884 * This routine is called by vfs_sync() to make sure that things make it
885 * out to disk eventually, on sync() system calls to flush out everything,
886 * and when the file system is unmounted. For the vfs_sync() case, all
887 * we really need to do is sync out the log to make all of our meta-data
888 * updates permanent (except for timestamps). For calls from pflushd(),
889 * dirty pages are kept moving by calling pdflush() on the inodes
890 * containing them. We also flush the inodes that we can lock without
891 * sleeping and the superblock if we can lock it without sleeping from
892 * vfs_sync() so that items at the tail of the log are always moving out.
893 *
894 * Flags:
895 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
896 * to sleep if we can help it. All we really need
897 * to do is ensure that the log is synced at least
898 * periodically. We also push the inodes and
899 * superblock if we can lock them without sleeping
900 * and they are not pinned.
901 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
902 * set, then we really want to lock each inode and flush
903 * it.
904 * SYNC_WAIT - All the flushes that take place in this call should
905 * be synchronous.
906 * SYNC_DELWRI - This tells us to push dirty pages associated with
907 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
908 * determine if they should be flushed sync, async, or
909 * delwri.
910 * SYNC_CLOSE - This flag is passed when the system is being
Nathan Scottc41564b2006-03-29 08:55:14 +1000911 * unmounted. We should sync and invalidate everything.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 * SYNC_FSDATA - This indicates that the caller would like to make
913 * sure the superblock is safe on disk. We can ensure
Nathan Scottc41564b2006-03-29 08:55:14 +1000914 * this by simply making sure the log gets flushed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 * if SYNC_BDFLUSH is set, and by actually writing it
916 * out otherwise.
David Chinner3c0dc772007-02-10 18:37:22 +1100917 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
918 * before we return (including direct I/O). Forms the drain
919 * side of the write barrier needed to safely quiesce the
920 * filesystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 *
922 */
923/*ARGSUSED*/
924STATIC int
925xfs_sync(
926 bhv_desc_t *bdp,
927 int flags,
928 cred_t *credp)
929{
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000930 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
David Chinner2a82b8b2007-07-11 11:09:12 +1000932 if (flags & SYNC_IOWAIT)
933 xfs_filestream_flush(mp);
934
David Chinner28239452007-02-10 18:36:40 +1100935 return xfs_syncsub(mp, flags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
938/*
939 * xfs sync routine for internal use
940 *
Nathan Scottb83bd132006-06-09 16:48:30 +1000941 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +1100942 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943 *
944 */
Nathan Scottee348072005-11-02 10:32:38 +1100945int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946xfs_sync_inodes(
947 xfs_mount_t *mp,
948 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 int *bypassed)
950{
951 xfs_inode_t *ip = NULL;
952 xfs_inode_t *ip_next;
953 xfs_buf_t *bp;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000954 bhv_vnode_t *vp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 int error;
956 int last_error;
957 uint64_t fflag;
958 uint lock_flags;
959 uint base_lock_flags;
960 boolean_t mount_locked;
961 boolean_t vnode_refed;
962 int preempt;
963 xfs_dinode_t *dip;
964 xfs_iptr_t *ipointer;
965#ifdef DEBUG
966 boolean_t ipointer_in = B_FALSE;
967
968#define IPOINTER_SET ipointer_in = B_TRUE
969#define IPOINTER_CLR ipointer_in = B_FALSE
970#else
971#define IPOINTER_SET
972#define IPOINTER_CLR
973#endif
974
975
976/* Insert a marker record into the inode list after inode ip. The list
977 * must be locked when this is called. After the call the list will no
978 * longer be locked.
979 */
980#define IPOINTER_INSERT(ip, mp) { \
981 ASSERT(ipointer_in == B_FALSE); \
982 ipointer->ip_mnext = ip->i_mnext; \
983 ipointer->ip_mprev = ip; \
984 ip->i_mnext = (xfs_inode_t *)ipointer; \
985 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
986 preempt = 0; \
987 XFS_MOUNT_IUNLOCK(mp); \
988 mount_locked = B_FALSE; \
989 IPOINTER_SET; \
990 }
991
992/* Remove the marker from the inode list. If the marker was the only item
993 * in the list then there are no remaining inodes and we should zero out
994 * the whole list. If we are the current head of the list then move the head
995 * past us.
996 */
997#define IPOINTER_REMOVE(ip, mp) { \
998 ASSERT(ipointer_in == B_TRUE); \
999 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1000 ip = ipointer->ip_mnext; \
1001 ip->i_mprev = ipointer->ip_mprev; \
1002 ipointer->ip_mprev->i_mnext = ip; \
1003 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1004 mp->m_inodes = ip; \
1005 } \
1006 } else { \
1007 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1008 mp->m_inodes = NULL; \
1009 ip = NULL; \
1010 } \
1011 IPOINTER_CLR; \
1012 }
1013
1014#define XFS_PREEMPT_MASK 0x7f
1015
1016 if (bypassed)
1017 *bypassed = 0;
1018 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1019 return 0;
1020 error = 0;
1021 last_error = 0;
1022 preempt = 0;
1023
1024 /* Allocate a reference marker */
1025 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1026
1027 fflag = XFS_B_ASYNC; /* default is don't wait */
Nathan Scottee348072005-11-02 10:32:38 +11001028 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 fflag = XFS_B_DELWRI;
1030 if (flags & SYNC_WAIT)
1031 fflag = 0; /* synchronous overrides all */
1032
1033 base_lock_flags = XFS_ILOCK_SHARED;
1034 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1035 /*
1036 * We need the I/O lock if we're going to call any of
1037 * the flush/inval routines.
1038 */
1039 base_lock_flags |= XFS_IOLOCK_SHARED;
1040 }
1041
1042 XFS_MOUNT_ILOCK(mp);
1043
1044 ip = mp->m_inodes;
1045
1046 mount_locked = B_TRUE;
1047 vnode_refed = B_FALSE;
1048
1049 IPOINTER_CLR;
1050
1051 do {
1052 ASSERT(ipointer_in == B_FALSE);
1053 ASSERT(vnode_refed == B_FALSE);
1054
1055 lock_flags = base_lock_flags;
1056
1057 /*
1058 * There were no inodes in the list, just break out
1059 * of the loop.
1060 */
1061 if (ip == NULL) {
1062 break;
1063 }
1064
1065 /*
1066 * We found another sync thread marker - skip it
1067 */
1068 if (ip->i_mount == NULL) {
1069 ip = ip->i_mnext;
1070 continue;
1071 }
1072
1073 vp = XFS_ITOV_NULL(ip);
1074
1075 /*
1076 * If the vnode is gone then this is being torn down,
1077 * call reclaim if it is flushed, else let regular flush
1078 * code deal with it later in the loop.
1079 */
1080
1081 if (vp == NULL) {
1082 /* Skip ones already in reclaim */
1083 if (ip->i_flags & XFS_IRECLAIM) {
1084 ip = ip->i_mnext;
1085 continue;
1086 }
1087 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1088 ip = ip->i_mnext;
1089 } else if ((xfs_ipincount(ip) == 0) &&
1090 xfs_iflock_nowait(ip)) {
1091 IPOINTER_INSERT(ip, mp);
1092
1093 xfs_finish_reclaim(ip, 1,
1094 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1095
1096 XFS_MOUNT_ILOCK(mp);
1097 mount_locked = B_TRUE;
1098 IPOINTER_REMOVE(ip, mp);
1099 } else {
1100 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1101 ip = ip->i_mnext;
1102 }
1103 continue;
1104 }
1105
1106 if (VN_BAD(vp)) {
1107 ip = ip->i_mnext;
1108 continue;
1109 }
1110
1111 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1112 XFS_MOUNT_IUNLOCK(mp);
1113 kmem_free(ipointer, sizeof(xfs_iptr_t));
1114 return 0;
1115 }
1116
1117 /*
1118 * If this is just vfs_sync() or pflushd() calling
1119 * then we can skip inodes for which it looks like
1120 * there is nothing to do. Since we don't have the
Nathan Scottc41564b2006-03-29 08:55:14 +10001121 * inode locked this is racy, but these are periodic
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 * calls so it doesn't matter. For the others we want
1123 * to know for sure, so we at least try to lock them.
1124 */
1125 if (flags & SYNC_BDFLUSH) {
1126 if (((ip->i_itemp == NULL) ||
1127 !(ip->i_itemp->ili_format.ilf_fields &
1128 XFS_ILOG_ALL)) &&
1129 (ip->i_update_core == 0)) {
1130 ip = ip->i_mnext;
1131 continue;
1132 }
1133 }
1134
1135 /*
1136 * Try to lock without sleeping. We're out of order with
1137 * the inode list lock here, so if we fail we need to drop
1138 * the mount lock and try again. If we're called from
1139 * bdflush() here, then don't bother.
1140 *
1141 * The inode lock here actually coordinates with the
1142 * almost spurious inode lock in xfs_ireclaim() to prevent
1143 * the vnode we handle here without a reference from
1144 * being freed while we reference it. If we lock the inode
1145 * while it's on the mount list here, then the spurious inode
1146 * lock in xfs_ireclaim() after the inode is pulled from
1147 * the mount list will sleep until we release it here.
1148 * This keeps the vnode from being freed while we reference
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001149 * it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 */
1151 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1153 ip = ip->i_mnext;
1154 continue;
1155 }
1156
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001157 vp = vn_grab(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 if (vp == NULL) {
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001159 ip = ip->i_mnext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 continue;
1161 }
1162
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001163 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 xfs_ilock(ip, lock_flags);
1165
1166 ASSERT(vp == XFS_ITOV(ip));
1167 ASSERT(ip->i_mount == mp);
1168
1169 vnode_refed = B_TRUE;
1170 }
1171
1172 /* From here on in the loop we may have a marker record
1173 * in the inode list.
1174 */
1175
David Chinner40095b62007-05-14 18:24:09 +10001176 /*
1177 * If we have to flush data or wait for I/O completion
1178 * we need to drop the ilock that we currently hold.
1179 * If we need to drop the lock, insert a marker if we
1180 * have not already done so.
1181 */
1182 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1183 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1184 if (mount_locked) {
1185 IPOINTER_INSERT(ip, mp);
1186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1188
David Chinner40095b62007-05-14 18:24:09 +10001189 if (flags & SYNC_CLOSE) {
1190 /* Shutdown case. Flush and invalidate. */
1191 if (XFS_FORCED_SHUTDOWN(mp))
1192 bhv_vop_toss_pages(vp, 0, -1, FI_REMAPF);
1193 else
1194 error = bhv_vop_flushinval_pages(vp, 0,
1195 -1, FI_REMAPF);
1196 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
Nathan Scott67fcaa72006-06-09 17:00:52 +10001197 error = bhv_vop_flush_pages(vp, (xfs_off_t)0,
1198 -1, fflag, FI_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
1200
David Chinner40095b62007-05-14 18:24:09 +10001201 /*
1202 * When freezing, we need to wait ensure all I/O (including direct
1203 * I/O) is complete to ensure no further data modification can take
1204 * place after this point
1205 */
1206 if (flags & SYNC_IOWAIT)
1207 vn_iowait(vp);
1208
1209 xfs_ilock(ip, XFS_ILOCK_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 }
1211
1212 if (flags & SYNC_BDFLUSH) {
1213 if ((flags & SYNC_ATTR) &&
1214 ((ip->i_update_core) ||
1215 ((ip->i_itemp != NULL) &&
1216 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1217
1218 /* Insert marker and drop lock if not already
1219 * done.
1220 */
1221 if (mount_locked) {
1222 IPOINTER_INSERT(ip, mp);
1223 }
1224
1225 /*
1226 * We don't want the periodic flushing of the
1227 * inodes by vfs_sync() to interfere with
1228 * I/O to the file, especially read I/O
1229 * where it is only the access time stamp
1230 * that is being flushed out. To prevent
1231 * long periods where we have both inode
1232 * locks held shared here while reading the
1233 * inode's buffer in from disk, we drop the
1234 * inode lock while reading in the inode
1235 * buffer. We have to release the buffer
1236 * and reacquire the inode lock so that they
1237 * are acquired in the proper order (inode
1238 * locks first). The buffer will go at the
1239 * end of the lru chain, though, so we can
1240 * expect it to still be there when we go
1241 * for it again in xfs_iflush().
1242 */
1243 if ((xfs_ipincount(ip) == 0) &&
1244 xfs_iflock_nowait(ip)) {
1245
1246 xfs_ifunlock(ip);
1247 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1248
1249 error = xfs_itobp(mp, NULL, ip,
Nathan Scottb12dd342006-03-17 17:26:04 +11001250 &dip, &bp, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 if (!error) {
1252 xfs_buf_relse(bp);
1253 } else {
1254 /* Bailing out, remove the
1255 * marker and free it.
1256 */
1257 XFS_MOUNT_ILOCK(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 IPOINTER_REMOVE(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 XFS_MOUNT_IUNLOCK(mp);
1260
1261 ASSERT(!(lock_flags &
1262 XFS_IOLOCK_SHARED));
1263
1264 kmem_free(ipointer,
1265 sizeof(xfs_iptr_t));
1266 return (0);
1267 }
1268
1269 /*
1270 * Since we dropped the inode lock,
1271 * the inode may have been reclaimed.
1272 * Therefore, we reacquire the mount
1273 * lock and check to see if we were the
1274 * inode reclaimed. If this happened
1275 * then the ipointer marker will no
1276 * longer point back at us. In this
1277 * case, move ip along to the inode
1278 * after the marker, remove the marker
1279 * and continue.
1280 */
1281 XFS_MOUNT_ILOCK(mp);
1282 mount_locked = B_TRUE;
1283
1284 if (ip != ipointer->ip_mprev) {
1285 IPOINTER_REMOVE(ip, mp);
1286
1287 ASSERT(!vnode_refed);
1288 ASSERT(!(lock_flags &
1289 XFS_IOLOCK_SHARED));
1290 continue;
1291 }
1292
1293 ASSERT(ip->i_mount == mp);
1294
1295 if (xfs_ilock_nowait(ip,
1296 XFS_ILOCK_SHARED) == 0) {
1297 ASSERT(ip->i_mount == mp);
1298 /*
1299 * We failed to reacquire
1300 * the inode lock without
1301 * sleeping, so just skip
1302 * the inode for now. We
1303 * clear the ILOCK bit from
1304 * the lock_flags so that we
1305 * won't try to drop a lock
1306 * we don't hold below.
1307 */
1308 lock_flags &= ~XFS_ILOCK_SHARED;
1309 IPOINTER_REMOVE(ip_next, mp);
1310 } else if ((xfs_ipincount(ip) == 0) &&
1311 xfs_iflock_nowait(ip)) {
1312 ASSERT(ip->i_mount == mp);
1313 /*
1314 * Since this is vfs_sync()
1315 * calling we only flush the
1316 * inode out if we can lock
1317 * it without sleeping and
1318 * it is not pinned. Drop
1319 * the mount lock here so
1320 * that we don't hold it for
1321 * too long. We already have
1322 * a marker in the list here.
1323 */
1324 XFS_MOUNT_IUNLOCK(mp);
1325 mount_locked = B_FALSE;
1326 error = xfs_iflush(ip,
1327 XFS_IFLUSH_DELWRI);
1328 } else {
1329 ASSERT(ip->i_mount == mp);
1330 IPOINTER_REMOVE(ip_next, mp);
1331 }
1332 }
1333
1334 }
1335
1336 } else {
1337 if ((flags & SYNC_ATTR) &&
1338 ((ip->i_update_core) ||
1339 ((ip->i_itemp != NULL) &&
1340 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1341 if (mount_locked) {
1342 IPOINTER_INSERT(ip, mp);
1343 }
1344
1345 if (flags & SYNC_WAIT) {
1346 xfs_iflock(ip);
1347 error = xfs_iflush(ip,
1348 XFS_IFLUSH_SYNC);
1349 } else {
1350 /*
1351 * If we can't acquire the flush
1352 * lock, then the inode is already
1353 * being flushed so don't bother
1354 * waiting. If we can lock it then
1355 * do a delwri flush so we can
1356 * combine multiple inode flushes
1357 * in each disk write.
1358 */
1359 if (xfs_iflock_nowait(ip)) {
1360 error = xfs_iflush(ip,
1361 XFS_IFLUSH_DELWRI);
1362 }
1363 else if (bypassed)
1364 (*bypassed)++;
1365 }
1366 }
1367 }
1368
1369 if (lock_flags != 0) {
1370 xfs_iunlock(ip, lock_flags);
1371 }
1372
1373 if (vnode_refed) {
1374 /*
1375 * If we had to take a reference on the vnode
1376 * above, then wait until after we've unlocked
1377 * the inode to release the reference. This is
1378 * because we can be already holding the inode
1379 * lock when VN_RELE() calls xfs_inactive().
1380 *
1381 * Make sure to drop the mount lock before calling
1382 * VN_RELE() so that we don't trip over ourselves if
1383 * we have to go for the mount lock again in the
1384 * inactive code.
1385 */
1386 if (mount_locked) {
1387 IPOINTER_INSERT(ip, mp);
1388 }
1389
1390 VN_RELE(vp);
1391
1392 vnode_refed = B_FALSE;
1393 }
1394
1395 if (error) {
1396 last_error = error;
1397 }
1398
1399 /*
1400 * bail out if the filesystem is corrupted.
1401 */
1402 if (error == EFSCORRUPTED) {
1403 if (!mount_locked) {
1404 XFS_MOUNT_ILOCK(mp);
1405 IPOINTER_REMOVE(ip, mp);
1406 }
1407 XFS_MOUNT_IUNLOCK(mp);
1408 ASSERT(ipointer_in == B_FALSE);
1409 kmem_free(ipointer, sizeof(xfs_iptr_t));
1410 return XFS_ERROR(error);
1411 }
1412
1413 /* Let other threads have a chance at the mount lock
1414 * if we have looped many times without dropping the
1415 * lock.
1416 */
1417 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1418 if (mount_locked) {
1419 IPOINTER_INSERT(ip, mp);
1420 }
1421 }
1422
1423 if (mount_locked == B_FALSE) {
1424 XFS_MOUNT_ILOCK(mp);
1425 mount_locked = B_TRUE;
1426 IPOINTER_REMOVE(ip, mp);
1427 continue;
1428 }
1429
1430 ASSERT(ipointer_in == B_FALSE);
1431 ip = ip->i_mnext;
1432
1433 } while (ip != mp->m_inodes);
1434
1435 XFS_MOUNT_IUNLOCK(mp);
1436
1437 ASSERT(ipointer_in == B_FALSE);
1438
1439 kmem_free(ipointer, sizeof(xfs_iptr_t));
1440 return XFS_ERROR(last_error);
1441}
1442
1443/*
1444 * xfs sync routine for internal use
1445 *
Nathan Scottb83bd132006-06-09 16:48:30 +10001446 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001447 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 *
1449 */
1450int
1451xfs_syncsub(
1452 xfs_mount_t *mp,
1453 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 int *bypassed)
1455{
1456 int error = 0;
1457 int last_error = 0;
1458 uint log_flags = XFS_LOG_FORCE;
1459 xfs_buf_t *bp;
1460 xfs_buf_log_item_t *bip;
1461
1462 /*
1463 * Sync out the log. This ensures that the log is periodically
1464 * flushed even if there is not enough activity to fill it up.
1465 */
1466 if (flags & SYNC_WAIT)
1467 log_flags |= XFS_LOG_SYNC;
1468
1469 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1470
1471 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1472 if (flags & SYNC_BDFLUSH)
1473 xfs_finish_reclaim_all(mp, 1);
1474 else
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001475 error = xfs_sync_inodes(mp, flags, bypassed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 }
1477
1478 /*
1479 * Flushing out dirty data above probably generated more
1480 * log activity, so if this isn't vfs_sync() then flush
1481 * the log again.
1482 */
1483 if (flags & SYNC_DELWRI) {
1484 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1485 }
1486
1487 if (flags & SYNC_FSDATA) {
1488 /*
1489 * If this is vfs_sync() then only sync the superblock
1490 * if we can lock it without sleeping and it is not pinned.
1491 */
1492 if (flags & SYNC_BDFLUSH) {
1493 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1494 if (bp != NULL) {
1495 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1496 if ((bip != NULL) &&
1497 xfs_buf_item_dirty(bip)) {
1498 if (!(XFS_BUF_ISPINNED(bp))) {
1499 XFS_BUF_ASYNC(bp);
1500 error = xfs_bwrite(mp, bp);
1501 } else {
1502 xfs_buf_relse(bp);
1503 }
1504 } else {
1505 xfs_buf_relse(bp);
1506 }
1507 }
1508 } else {
1509 bp = xfs_getsb(mp, 0);
1510 /*
1511 * If the buffer is pinned then push on the log so
1512 * we won't get stuck waiting in the write for
1513 * someone, maybe ourselves, to flush the log.
1514 * Even though we just pushed the log above, we
1515 * did not have the superblock buffer locked at
1516 * that point so it can become pinned in between
1517 * there and here.
1518 */
1519 if (XFS_BUF_ISPINNED(bp))
1520 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1521 if (flags & SYNC_WAIT)
1522 XFS_BUF_UNASYNC(bp);
1523 else
1524 XFS_BUF_ASYNC(bp);
1525 error = xfs_bwrite(mp, bp);
1526 }
1527 if (error) {
1528 last_error = error;
1529 }
1530 }
1531
1532 /*
1533 * If this is the periodic sync, then kick some entries out of
1534 * the reference cache. This ensures that idle entries are
1535 * eventually kicked out of the cache.
1536 */
1537 if (flags & SYNC_REFCACHE) {
Nathan Scottcde410a2005-09-05 11:47:01 +10001538 if (flags & SYNC_WAIT)
1539 xfs_refcache_purge_mp(mp);
1540 else
1541 xfs_refcache_purge_some(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 }
1543
1544 /*
David Chinner92821e22007-05-24 15:26:31 +10001545 * If asked, update the disk superblock with incore counter values if we
1546 * are using non-persistent counters so that they don't get too far out
1547 * of sync if we crash or get a forced shutdown. We don't want to force
1548 * this to disk, just get a transaction into the iclogs....
1549 */
1550 if (flags & SYNC_SUPER)
1551 xfs_log_sbcount(mp, 0);
1552
1553 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 * Now check to see if the log needs a "dummy" transaction.
1555 */
1556
1557 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1558 xfs_trans_t *tp;
1559 xfs_inode_t *ip;
1560
1561 /*
1562 * Put a dummy transaction in the log to tell
1563 * recovery that all others are OK.
1564 */
1565 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1566 if ((error = xfs_trans_reserve(tp, 0,
1567 XFS_ICHANGE_LOG_RES(mp),
1568 0, 0, 0))) {
1569 xfs_trans_cancel(tp, 0);
1570 return error;
1571 }
1572
1573 ip = mp->m_rootip;
1574 xfs_ilock(ip, XFS_ILOCK_EXCL);
1575
1576 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1577 xfs_trans_ihold(tp, ip);
1578 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
Eric Sandeen1c72bf92007-05-08 13:48:42 +10001579 error = xfs_trans_commit(tp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1581 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1582 }
1583
1584 /*
1585 * When shutting down, we need to insure that the AIL is pushed
1586 * to disk or the filesystem can appear corrupt from the PROM.
1587 */
1588 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1589 XFS_bflush(mp->m_ddev_targp);
1590 if (mp->m_rtdev_targp) {
1591 XFS_bflush(mp->m_rtdev_targp);
1592 }
1593 }
1594
1595 return XFS_ERROR(last_error);
1596}
1597
1598/*
1599 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1600 */
1601STATIC int
1602xfs_vget(
1603 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001604 bhv_vnode_t **vpp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 fid_t *fidp)
1606{
1607 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1608 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1609 xfs_inode_t *ip;
1610 int error;
1611 xfs_ino_t ino;
1612 unsigned int igen;
1613
1614 /*
1615 * Invalid. Since handles can be created in user space and passed in
1616 * via gethandle(), this is not cause for a panic.
1617 */
1618 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1619 return XFS_ERROR(EINVAL);
1620
1621 ino = xfid->xfs_fid_ino;
1622 igen = xfid->xfs_fid_gen;
1623
1624 /*
1625 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1626 */
1627 if (ino == 0)
1628 return XFS_ERROR(ESTALE);
1629
1630 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1631 if (error) {
1632 *vpp = NULL;
1633 return error;
1634 }
1635
1636 if (ip == NULL) {
1637 *vpp = NULL;
1638 return XFS_ERROR(EIO);
1639 }
1640
1641 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1642 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1643 *vpp = NULL;
1644 return XFS_ERROR(ENOENT);
1645 }
1646
1647 *vpp = XFS_ITOV(ip);
1648 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1649 return 0;
1650}
1651
1652
1653#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1654#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1655#define MNTOPT_LOGDEV "logdev" /* log device */
1656#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1657#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1658#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1659#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1660#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1661#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1662#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1663#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1664#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1665#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
Nathan Scotte69a3332005-09-02 16:42:26 +10001666#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1667#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1668#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1669#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
Nathan Scott1f443ad2005-05-05 13:28:29 -07001670#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671#define MNTOPT_IHASHSIZE "ihashsize" /* size of inode hash table */
1672#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001673#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
Nathan Scottd8cc8902005-11-02 10:34:53 +11001674 * unwritten extent conversion */
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001675#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1677#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1678#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1679#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
David Chinnere8c8b3a2005-11-02 10:33:05 +11001680#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1681#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1682 * in stat(). */
Nathan Scottd8cc8902005-11-02 10:34:53 +11001683#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1684#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
David Chinner2a82b8b2007-07-11 11:09:12 +10001685#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Nathan Scott1f443ad2005-05-05 13:28:29 -07001687STATIC unsigned long
Nathan Scottb190f112006-06-09 17:13:15 +10001688suffix_strtoul(char *s, char **endp, unsigned int base)
Nathan Scott1f443ad2005-05-05 13:28:29 -07001689{
1690 int last, shift_left_factor = 0;
Nathan Scottb190f112006-06-09 17:13:15 +10001691 char *value = s;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001692
1693 last = strlen(value) - 1;
1694 if (value[last] == 'K' || value[last] == 'k') {
1695 shift_left_factor = 10;
1696 value[last] = '\0';
1697 }
1698 if (value[last] == 'M' || value[last] == 'm') {
1699 shift_left_factor = 20;
1700 value[last] = '\0';
1701 }
1702 if (value[last] == 'G' || value[last] == 'g') {
1703 shift_left_factor = 30;
1704 value[last] = '\0';
1705 }
1706
Nathan Scottb190f112006-06-09 17:13:15 +10001707 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001708}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10001710STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711xfs_parseargs(
1712 struct bhv_desc *bhv,
1713 char *options,
1714 struct xfs_mount_args *args,
1715 int update)
1716{
Nathan Scottb83bd132006-06-09 16:48:30 +10001717 bhv_vfs_t *vfsp = bhvtovfs(bhv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 char *this_char, *value, *eov;
1719 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1720 int iosize;
1721
Nathan Scotte15f1952006-03-22 12:47:52 +11001722 args->flags |= XFSMNT_IDELETE;
Nathan Scott3bbcc8e2006-03-31 13:04:56 +10001723 args->flags |= XFSMNT_BARRIER;
1724 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
1726 if (!options)
Nathan Scott05db2182005-11-04 09:49:07 +11001727 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
1729 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1730
1731 while ((this_char = strsep(&options, ",")) != NULL) {
1732 if (!*this_char)
1733 continue;
1734 if ((value = strchr(this_char, '=')) != NULL)
1735 *value++ = 0;
1736
1737 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1738 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001739 cmn_err(CE_WARN,
1740 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001741 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 return EINVAL;
1743 }
1744 args->logbufs = simple_strtoul(value, &eov, 10);
1745 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001747 cmn_err(CE_WARN,
1748 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001749 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 return EINVAL;
1751 }
Nathan Scott1f443ad2005-05-05 13:28:29 -07001752 args->logbufsize = suffix_strtoul(value, &eov, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1754 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001755 cmn_err(CE_WARN,
1756 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001757 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 return EINVAL;
1759 }
1760 strncpy(args->logname, value, MAXNAMELEN);
1761 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1762 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001763 cmn_err(CE_WARN,
1764 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001765 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 return EINVAL;
1767 }
1768 strncpy(args->mtpt, value, MAXNAMELEN);
1769 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1770 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001771 cmn_err(CE_WARN,
1772 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001773 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 return EINVAL;
1775 }
1776 strncpy(args->rtname, value, MAXNAMELEN);
1777 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1778 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001779 cmn_err(CE_WARN,
1780 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001781 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 return EINVAL;
1783 }
1784 iosize = simple_strtoul(value, &eov, 10);
1785 args->flags |= XFSMNT_IOSIZE;
1786 args->iosizelog = (uint8_t) iosize;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001787 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1788 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001789 cmn_err(CE_WARN,
1790 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001791 this_char);
1792 return EINVAL;
1793 }
1794 iosize = suffix_strtoul(value, &eov, 10);
1795 args->flags |= XFSMNT_IOSIZE;
1796 args->iosizelog = ffs(iosize) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 } else if (!strcmp(this_char, MNTOPT_IHASHSIZE)) {
1798 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001799 cmn_err(CE_WARN,
1800 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001801 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 return EINVAL;
1803 }
1804 args->flags |= XFSMNT_IHASHSIZE;
1805 args->ihashsize = simple_strtoul(value, &eov, 10);
Nathan Scotte69a3332005-09-02 16:42:26 +10001806 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1807 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1808 vfsp->vfs_flag |= VFS_GRPID;
1809 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1810 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1811 vfsp->vfs_flag &= ~VFS_GRPID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1813 args->flags |= XFSMNT_WSYNC;
1814 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1815 args->flags |= XFSMNT_OSYNCISOSYNC;
1816 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1817 args->flags |= XFSMNT_NORECOVERY;
1818 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1819 args->flags |= XFSMNT_INO64;
1820#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001821 cmn_err(CE_WARN,
1822 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001823 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 return EINVAL;
1825#endif
1826 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1827 args->flags |= XFSMNT_NOALIGN;
1828 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1829 args->flags |= XFSMNT_SWALLOC;
1830 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
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 dsunit = simple_strtoul(value, &eov, 10);
1838 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1839 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001840 cmn_err(CE_WARN,
1841 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001842 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 return EINVAL;
1844 }
1845 dswidth = simple_strtoul(value, &eov, 10);
1846 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1847 args->flags &= ~XFSMNT_32BITINODES;
1848#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001849 cmn_err(CE_WARN,
1850 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001851 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 return EINVAL;
1853#endif
1854 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1855 args->flags |= XFSMNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001856 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1857 args->flags |= XFSMNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001858 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1859 args->flags &= ~XFSMNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1861 args->flags &= ~XFSMNT_IDELETE;
1862 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1863 args->flags |= XFSMNT_IDELETE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001864 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Nathan Scotte718eeb2005-11-02 15:09:22 +11001865 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001866 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Nathan Scotte718eeb2005-11-02 15:09:22 +11001867 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001868 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001869 args->flags |= XFSMNT_ATTR2;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001870 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001871 args->flags &= ~XFSMNT_ATTR2;
David Chinner2a82b8b2007-07-11 11:09:12 +10001872 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1873 args->flags2 |= XFSMNT2_FILESTREAMS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 } else if (!strcmp(this_char, "osyncisdsync")) {
1875 /* no-op, this is now the default */
Nathan Scottb6574522006-06-09 15:29:40 +10001876 cmn_err(CE_WARN,
1877 "XFS: osyncisdsync is now the default, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 } else if (!strcmp(this_char, "irixsgid")) {
Nathan Scottb6574522006-06-09 15:29:40 +10001879 cmn_err(CE_WARN,
1880 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 } else {
Nathan Scottb6574522006-06-09 15:29:40 +10001882 cmn_err(CE_WARN,
1883 "XFS: unknown mount option [%s].", this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 return EINVAL;
1885 }
1886 }
1887
1888 if (args->flags & XFSMNT_NORECOVERY) {
1889 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
Nathan Scottb6574522006-06-09 15:29:40 +10001890 cmn_err(CE_WARN,
1891 "XFS: no-recovery mounts must be read-only.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 return EINVAL;
1893 }
1894 }
1895
1896 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001897 cmn_err(CE_WARN,
1898 "XFS: sunit and swidth options incompatible with the noalign option");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 return EINVAL;
1900 }
1901
1902 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001903 cmn_err(CE_WARN,
1904 "XFS: sunit and swidth must be specified together");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 return EINVAL;
1906 }
1907
1908 if (dsunit && (dswidth % dsunit != 0)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001909 cmn_err(CE_WARN,
1910 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 dswidth, dsunit);
1912 return EINVAL;
1913 }
1914
1915 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1916 if (dsunit) {
1917 args->sunit = dsunit;
1918 args->flags |= XFSMNT_RETERR;
1919 } else {
1920 args->sunit = vol_dsunit;
1921 }
1922 dswidth ? (args->swidth = dswidth) :
1923 (args->swidth = vol_dswidth);
1924 } else {
1925 args->sunit = args->swidth = 0;
1926 }
1927
Nathan Scott05db2182005-11-04 09:49:07 +11001928done:
Nathan Scottc11e2c32005-11-02 15:11:45 +11001929 if (args->flags & XFSMNT_32BITINODES)
1930 vfsp->vfs_flag |= VFS_32BITINODES;
Nathan Scotte718eeb2005-11-02 15:09:22 +11001931 if (args->flags2)
1932 args->flags |= XFSMNT_FLAGS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 return 0;
1934}
1935
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10001936STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937xfs_showargs(
1938 struct bhv_desc *bhv,
1939 struct seq_file *m)
1940{
1941 static struct proc_xfs_info {
1942 int flag;
1943 char *str;
1944 } xfs_info[] = {
1945 /* the few simple ones we can get from the mount struct */
1946 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1947 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1948 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1949 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1950 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1951 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1952 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 { 0, NULL }
1954 };
1955 struct proc_xfs_info *xfs_infop;
1956 struct xfs_mount *mp = XFS_BHVTOM(bhv);
Nathan Scottb83bd132006-06-09 16:48:30 +10001957 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
1959 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1960 if (mp->m_flags & xfs_infop->flag)
1961 seq_puts(m, xfs_infop->str);
1962 }
1963
1964 if (mp->m_flags & XFS_MOUNT_IHASHSIZE)
Nathan Scott215101c2006-09-28 11:04:43 +10001965 seq_printf(m, "," MNTOPT_IHASHSIZE "=%d", (int)mp->m_ihsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
1967 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001968 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1969 (int)(1 << mp->m_writeio_log) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970
1971 if (mp->m_logbufs > 0)
1972 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973 if (mp->m_logbsize > 0)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001974 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001976 if (mp->m_logname)
1977 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001978 if (mp->m_rtname)
1979 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981 if (mp->m_dalign > 0)
1982 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1983 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 if (mp->m_swidth > 0)
1985 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1986 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1987
Nathan Scotte15f1952006-03-22 12:47:52 +11001988 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1989 seq_printf(m, "," MNTOPT_IKEEP);
Nathan Scottfa7e7d72005-11-02 15:00:48 +11001990 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1991 seq_printf(m, "," MNTOPT_LARGEIO);
1992
Nathan Scottc11e2c32005-11-02 15:11:45 +11001993 if (!(vfsp->vfs_flag & VFS_32BITINODES))
1994 seq_printf(m, "," MNTOPT_64BITINODE);
Nathan Scotte69a3332005-09-02 16:42:26 +10001995 if (vfsp->vfs_flag & VFS_GRPID)
1996 seq_printf(m, "," MNTOPT_GRPID);
1997
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 return 0;
1999}
2000
David Chinner28239452007-02-10 18:36:40 +11002001/*
David Chinner516b2e72007-06-18 16:50:48 +10002002 * Second stage of a freeze. The data is already frozen so we only
2003 * need to take care of themetadata. Once that's done write a dummy
2004 * record to dirty the log in case of a crash while frozen.
David Chinner28239452007-02-10 18:36:40 +11002005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006STATIC void
2007xfs_freeze(
2008 bhv_desc_t *bdp)
2009{
2010 xfs_mount_t *mp = XFS_BHVTOM(bdp);
2011
David Chinner516b2e72007-06-18 16:50:48 +10002012 xfs_attr_quiesce(mp);
Christoph Hellwige13a73f2006-01-11 15:30:08 +11002013 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014}
2015
2016
Nathan Scottb83bd132006-06-09 16:48:30 +10002017bhv_vfsops_t xfs_vfsops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
2019 .vfs_parseargs = xfs_parseargs,
2020 .vfs_showargs = xfs_showargs,
2021 .vfs_mount = xfs_mount,
2022 .vfs_unmount = xfs_unmount,
2023 .vfs_mntupdate = xfs_mntupdate,
2024 .vfs_root = xfs_root,
2025 .vfs_statvfs = xfs_statvfs,
2026 .vfs_sync = xfs_sync,
2027 .vfs_vget = xfs_vget,
2028 .vfs_dmapiops = (vfs_dmapiops_t)fs_nosys,
2029 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
2030 .vfs_init_vnode = xfs_initialize_vnode,
2031 .vfs_force_shutdown = xfs_do_force_shutdown,
2032 .vfs_freeze = xfs_freeze,
2033};