blob: 1cf8f54d8aa9d919ae0a181b877c413e67c28979 [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"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100057#include "xfs_vnodeops.h"
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
David Chinner8d280b92006-03-14 13:13:09 +110060STATIC int xfs_sync(bhv_desc_t *, int, cred_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62int
63xfs_init(void)
64{
65 extern kmem_zone_t *xfs_bmap_free_item_zone;
66 extern kmem_zone_t *xfs_btree_cur_zone;
67 extern kmem_zone_t *xfs_trans_zone;
68 extern kmem_zone_t *xfs_buf_item_zone;
69 extern kmem_zone_t *xfs_dabuf_zone;
70#ifdef XFS_DABUF_DEBUG
71 extern lock_t xfs_dabuf_global_lock;
72 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
73#endif
74
75 /*
76 * Initialize all of the zone allocators we use.
77 */
78 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
79 "xfs_bmap_free_item");
80 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
81 "xfs_btree_cur");
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
83 xfs_da_state_zone =
84 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
85 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
Nathan Scott87582802006-03-14 13:18:19 +110086 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
87 xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
David Chinner2a82b8b2007-07-11 11:09:12 +100088 xfs_mru_cache_init();
89 xfs_filestream_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 /*
92 * The size of the zone allocated buf log item is the maximum
93 * size possible under XFS. This wastes a little bit of memory,
94 * but it is much faster.
95 */
96 xfs_buf_item_zone =
97 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
98 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
99 NBWORD) * sizeof(int))),
100 "xfs_buf_item");
Nathan Scott87582802006-03-14 13:18:19 +1100101 xfs_efd_zone =
102 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
103 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
104 sizeof(xfs_extent_t))),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 "xfs_efd_item");
Nathan Scott87582802006-03-14 13:18:19 +1100106 xfs_efi_zone =
107 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
108 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
109 sizeof(xfs_extent_t))),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 "xfs_efi_item");
Nathan Scott87582802006-03-14 13:18:19 +1100111
112 /*
113 * These zones warrant special memory allocator hints
114 */
115 xfs_inode_zone =
116 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
117 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
118 KM_ZONE_SPREAD, NULL);
119 xfs_ili_zone =
120 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
121 KM_ZONE_SPREAD, NULL);
David Chinnerda353b02007-08-28 14:00:13 +1000122 xfs_icluster_zone =
123 kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster",
Nathan Scott87582802006-03-14 13:18:19 +1100124 KM_ZONE_SPREAD, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 /*
127 * Allocate global trace buffers.
128 */
129#ifdef XFS_ALLOC_TRACE
130 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
131#endif
132#ifdef XFS_BMAP_TRACE
133 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
134#endif
135#ifdef XFS_BMBT_TRACE
136 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
137#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#ifdef XFS_ATTR_TRACE
139 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
140#endif
141#ifdef XFS_DIR2_TRACE
142 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
143#endif
144
145 xfs_dir_startup();
146
147#if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
148 xfs_error_test_init();
149#endif /* DEBUG || INDUCE_IO_ERROR */
150
151 xfs_init_procfs();
152 xfs_sysctl_register();
153 return 0;
154}
155
156void
157xfs_cleanup(void)
158{
159 extern kmem_zone_t *xfs_bmap_free_item_zone;
160 extern kmem_zone_t *xfs_btree_cur_zone;
161 extern kmem_zone_t *xfs_inode_zone;
162 extern kmem_zone_t *xfs_trans_zone;
163 extern kmem_zone_t *xfs_da_state_zone;
164 extern kmem_zone_t *xfs_dabuf_zone;
165 extern kmem_zone_t *xfs_efd_zone;
166 extern kmem_zone_t *xfs_efi_zone;
167 extern kmem_zone_t *xfs_buf_item_zone;
David Chinnerda353b02007-08-28 14:00:13 +1000168 extern kmem_zone_t *xfs_icluster_zone;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 xfs_cleanup_procfs();
171 xfs_sysctl_unregister();
172 xfs_refcache_destroy();
David Chinner2a82b8b2007-07-11 11:09:12 +1000173 xfs_filestream_uninit();
174 xfs_mru_cache_uninit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 xfs_acl_zone_destroy(xfs_acl_zone);
176
177#ifdef XFS_DIR2_TRACE
178 ktrace_free(xfs_dir2_trace_buf);
179#endif
180#ifdef XFS_ATTR_TRACE
181 ktrace_free(xfs_attr_trace_buf);
182#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183#ifdef XFS_BMBT_TRACE
184 ktrace_free(xfs_bmbt_trace_buf);
185#endif
186#ifdef XFS_BMAP_TRACE
187 ktrace_free(xfs_bmap_trace_buf);
188#endif
189#ifdef XFS_ALLOC_TRACE
190 ktrace_free(xfs_alloc_trace_buf);
191#endif
192
Nathan Scott3758dee2006-03-22 12:47:28 +1100193 kmem_zone_destroy(xfs_bmap_free_item_zone);
194 kmem_zone_destroy(xfs_btree_cur_zone);
195 kmem_zone_destroy(xfs_inode_zone);
196 kmem_zone_destroy(xfs_trans_zone);
197 kmem_zone_destroy(xfs_da_state_zone);
198 kmem_zone_destroy(xfs_dabuf_zone);
199 kmem_zone_destroy(xfs_buf_item_zone);
200 kmem_zone_destroy(xfs_efd_zone);
201 kmem_zone_destroy(xfs_efi_zone);
202 kmem_zone_destroy(xfs_ifork_zone);
203 kmem_zone_destroy(xfs_ili_zone);
David Chinnerda353b02007-08-28 14:00:13 +1000204 kmem_zone_destroy(xfs_icluster_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
207/*
208 * xfs_start_flags
209 *
210 * This function fills in xfs_mount_t fields based on mount args.
211 * Note: the superblock has _not_ yet been read in.
212 */
213STATIC int
214xfs_start_flags(
Nathan Scottb83bd132006-06-09 16:48:30 +1000215 struct bhv_vfs *vfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 struct xfs_mount_args *ap,
217 struct xfs_mount *mp)
218{
219 /* Values are in BBs */
220 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
221 /*
222 * At this point the superblock has not been read
223 * in, therefore we do not know the block size.
224 * Before the mount call ends we will convert
225 * these to FSBs.
226 */
227 mp->m_dalign = ap->sunit;
228 mp->m_swidth = ap->swidth;
229 }
230
231 if (ap->logbufs != -1 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 ap->logbufs != 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 (ap->logbufs < XLOG_MIN_ICLOGS ||
234 ap->logbufs > XLOG_MAX_ICLOGS)) {
235 cmn_err(CE_WARN,
236 "XFS: invalid logbufs value: %d [not %d-%d]",
237 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
238 return XFS_ERROR(EINVAL);
239 }
240 mp->m_logbufs = ap->logbufs;
241 if (ap->logbufsize != -1 &&
Nathan Scottcfcbbbd2005-11-02 15:12:04 +1100242 ap->logbufsize != 0 &&
Eric Sandeendcb3b832007-08-16 16:25:33 +1000243 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
244 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
245 !is_power_of_2(ap->logbufsize))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 mp->m_logbsize = ap->logbufsize;
252 mp->m_fsname_len = strlen(ap->fsname) + 1;
253 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
254 strcpy(mp->m_fsname, ap->fsname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +1100255 if (ap->rtname[0]) {
256 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
257 strcpy(mp->m_rtname, ap->rtname);
258 }
259 if (ap->logname[0]) {
260 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
261 strcpy(mp->m_logname, ap->logname);
262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 if (ap->flags & XFSMNT_WSYNC)
265 mp->m_flags |= XFS_MOUNT_WSYNC;
266#if XFS_BIG_INUMS
267 if (ap->flags & XFSMNT_INO64) {
268 mp->m_flags |= XFS_MOUNT_INO64;
269 mp->m_inoadd = XFS_INO64_OFFSET;
270 }
271#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (ap->flags & XFSMNT_RETERR)
273 mp->m_flags |= XFS_MOUNT_RETERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (ap->flags & XFSMNT_NOALIGN)
275 mp->m_flags |= XFS_MOUNT_NOALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (ap->flags & XFSMNT_SWALLOC)
277 mp->m_flags |= XFS_MOUNT_SWALLOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 if (ap->flags & XFSMNT_OSYNCISOSYNC)
279 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 if (ap->flags & XFSMNT_32BITINODES)
Nathan Scottc11e2c32005-11-02 15:11:45 +1100281 mp->m_flags |= XFS_MOUNT_32BITINODES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 if (ap->flags & XFSMNT_IOSIZE) {
284 if (ap->iosizelog > XFS_MAX_IO_LOG ||
285 ap->iosizelog < XFS_MIN_IO_LOG) {
286 cmn_err(CE_WARN,
287 "XFS: invalid log iosize: %d [not %d-%d]",
288 ap->iosizelog, XFS_MIN_IO_LOG,
289 XFS_MAX_IO_LOG);
290 return XFS_ERROR(EINVAL);
291 }
292
293 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
294 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
295 }
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 if (ap->flags & XFSMNT_IDELETE)
298 mp->m_flags |= XFS_MOUNT_IDELETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (ap->flags & XFSMNT_DIRSYNC)
300 mp->m_flags |= XFS_MOUNT_DIRSYNC;
Nathan Scott13059ff2006-01-11 15:32:01 +1100301 if (ap->flags & XFSMNT_ATTR2)
302 mp->m_flags |= XFS_MOUNT_ATTR2;
David Chinnere8c8b3a2005-11-02 10:33:05 +1100303
Nathan Scotte718eeb42005-11-02 15:09:22 +1100304 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
305 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 /*
308 * no recovery flag requires a read-only mount
309 */
310 if (ap->flags & XFSMNT_NORECOVERY) {
311 if (!(vfs->vfs_flag & VFS_RDONLY)) {
312 cmn_err(CE_WARN,
313 "XFS: tried to mount a FS read-write without recovery!");
314 return XFS_ERROR(EINVAL);
315 }
316 mp->m_flags |= XFS_MOUNT_NORECOVERY;
317 }
318
319 if (ap->flags & XFSMNT_NOUUID)
320 mp->m_flags |= XFS_MOUNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100321 if (ap->flags & XFSMNT_BARRIER)
322 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100323 else
324 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
David Chinner2a82b8b2007-07-11 11:09:12 +1000326 if (ap->flags2 & XFSMNT2_FILESTREAMS)
327 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
328
Christoph Hellwig293688e2007-08-29 11:59:36 +1000329 if (ap->flags & XFSMNT_DMAPI)
330 vfs->vfs_flag |= VFS_DMI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 return 0;
332}
333
334/*
335 * This function fills in xfs_mount_t fields based on mount args.
336 * Note: the superblock _has_ now been read in.
337 */
338STATIC int
339xfs_finish_flags(
Nathan Scottb83bd132006-06-09 16:48:30 +1000340 struct bhv_vfs *vfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 struct xfs_mount_args *ap,
342 struct xfs_mount *mp)
343{
344 int ronly = (vfs->vfs_flag & VFS_RDONLY);
345
346 /* Fail a mount where the logbuf is smaller then the log stripe */
347 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
Nathan Scottc2cd2552006-01-11 15:35:32 +1100348 if ((ap->logbufsize <= 0) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
350 mp->m_logbsize = mp->m_sb.sb_logsunit;
Nathan Scottc2cd2552006-01-11 15:35:32 +1100351 } else if (ap->logbufsize > 0 &&
352 ap->logbufsize < mp->m_sb.sb_logsunit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 cmn_err(CE_WARN,
354 "XFS: logbuf size must be greater than or equal to log stripe size");
355 return XFS_ERROR(EINVAL);
356 }
357 } else {
358 /* Fail a mount if the logbuf is larger than 32K */
359 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
360 cmn_err(CE_WARN,
361 "XFS: logbuf size for version 1 logs must be 16K or 32K");
362 return XFS_ERROR(EINVAL);
363 }
364 }
365
Nathan Scott13059ff2006-01-11 15:32:01 +1100366 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
367 mp->m_flags |= XFS_MOUNT_ATTR2;
368 }
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 /*
371 * prohibit r/w mounts of read-only filesystems
372 */
373 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
374 cmn_err(CE_WARN,
375 "XFS: cannot mount a read-only filesystem as read-write");
376 return XFS_ERROR(EROFS);
377 }
378
379 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 * check for shared mount.
381 */
382 if (ap->flags & XFSMNT_SHARED) {
383 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
384 return XFS_ERROR(EINVAL);
385
386 /*
387 * For IRIX 6.5, shared mounts must have the shared
388 * version bit set, have the persistent readonly
389 * field set, must be version 0 and can only be mounted
390 * read-only.
391 */
392 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
393 (mp->m_sb.sb_shared_vn != 0))
394 return XFS_ERROR(EINVAL);
395
396 mp->m_flags |= XFS_MOUNT_SHARED;
397
398 /*
399 * Shared XFS V0 can't deal with DMI. Return EINVAL.
400 */
401 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
402 return XFS_ERROR(EINVAL);
403 }
404
405 return 0;
406}
407
408/*
409 * xfs_mount
410 *
411 * The file system configurations are:
412 * (1) device (partition) with data and internal log
413 * (2) logical volume with data and log subvolumes.
414 * (3) logical volume with data, log, and realtime subvolumes.
415 *
416 * We only have to handle opening the log and realtime volumes here if
417 * they are present. The data subvolume has already been opened by
418 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
419 */
420STATIC int
421xfs_mount(
422 struct bhv_desc *bhvp,
423 struct xfs_mount_args *args,
424 cred_t *credp)
425{
Nathan Scottb83bd132006-06-09 16:48:30 +1000426 struct bhv_vfs *vfsp = bhvtovfs(bhvp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 struct bhv_desc *p;
428 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
429 struct block_device *ddev, *logdev, *rtdev;
430 int flags = 0, error;
431
432 ddev = vfsp->vfs_super->s_bdev;
433 logdev = rtdev = NULL;
434
Christoph Hellwig293688e2007-08-29 11:59:36 +1000435 error = xfs_dmops_get(mp, args);
436 if (error)
437 return error;
438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 /*
440 * Setup xfs_mount function vectors from available behaviors
441 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM);
443 mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub;
444 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
445 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
446
Nathan Scott764d1f82006-03-31 13:04:17 +1000447 if (args->flags & XFSMNT_QUIET)
448 flags |= XFS_MFSI_QUIET;
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /*
451 * Open real time and log devices - order is important.
452 */
453 if (args->logname[0]) {
454 error = xfs_blkdev_get(mp, args->logname, &logdev);
455 if (error)
456 return error;
457 }
458 if (args->rtname[0]) {
459 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
460 if (error) {
461 xfs_blkdev_put(logdev);
462 return error;
463 }
464
465 if (rtdev == ddev || rtdev == logdev) {
466 cmn_err(CE_WARN,
467 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
468 xfs_blkdev_put(logdev);
469 xfs_blkdev_put(rtdev);
470 return EINVAL;
471 }
472 }
473
474 /*
475 * Setup xfs_mount buffer target pointers
476 */
477 error = ENOMEM;
478 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
479 if (!mp->m_ddev_targp) {
480 xfs_blkdev_put(logdev);
481 xfs_blkdev_put(rtdev);
482 return error;
483 }
484 if (rtdev) {
485 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000486 if (!mp->m_rtdev_targp) {
487 xfs_blkdev_put(logdev);
488 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492 mp->m_logdev_targp = (logdev && logdev != ddev) ?
493 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000494 if (!mp->m_logdev_targp) {
495 xfs_blkdev_put(logdev);
496 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000498 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 /*
501 * Setup flags based on mount(2) options and then the superblock
502 */
503 error = xfs_start_flags(vfsp, args, mp);
504 if (error)
505 goto error1;
Nathan Scott764d1f82006-03-31 13:04:17 +1000506 error = xfs_readsb(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 if (error)
508 goto error1;
509 error = xfs_finish_flags(vfsp, args, mp);
510 if (error)
511 goto error2;
512
513 /*
514 * Setup xfs_mount buffer target pointers based on superblock
515 */
516 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
517 mp->m_sb.sb_sectsize);
518 if (!error && logdev && logdev != ddev) {
519 unsigned int log_sector_size = BBSIZE;
520
521 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
522 log_sector_size = mp->m_sb.sb_logsectsize;
523 error = xfs_setsize_buftarg(mp->m_logdev_targp,
524 mp->m_sb.sb_blocksize,
525 log_sector_size);
526 }
527 if (!error && rtdev)
528 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
529 mp->m_sb.sb_blocksize,
530 mp->m_sb.sb_sectsize);
531 if (error)
532 goto error2;
533
Nathan Scottb2ea4012006-07-28 17:05:13 +1000534 if (mp->m_flags & XFS_MOUNT_BARRIER)
Christoph Hellwigc7d437d2006-01-11 15:28:56 +1100535 xfs_mountfs_check_barriers(mp);
536
David Chinner2a82b8b2007-07-11 11:09:12 +1000537 if ((error = xfs_filestream_mount(mp)))
538 goto error2;
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 error = XFS_IOINIT(vfsp, args, flags);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100541 if (error)
542 goto error2;
543
Christoph Hellwig293688e2007-08-29 11:59:36 +1000544 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
545
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100546 return 0;
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548error2:
549 if (mp->m_sb_bp)
550 xfs_freesb(mp);
551error1:
552 xfs_binval(mp->m_ddev_targp);
553 if (logdev && logdev != ddev)
554 xfs_binval(mp->m_logdev_targp);
555 if (rtdev)
556 xfs_binval(mp->m_rtdev_targp);
557error0:
558 xfs_unmountfs_close(mp, credp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000559 xfs_dmops_put(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 return error;
561}
562
563STATIC int
564xfs_unmount(
565 bhv_desc_t *bdp,
566 int flags,
567 cred_t *credp)
568{
Nathan Scottb83bd132006-06-09 16:48:30 +1000569 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 xfs_mount_t *mp = XFS_BHVTOM(bdp);
571 xfs_inode_t *rip;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000572 bhv_vnode_t *rvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 int unmount_event_wanted = 0;
574 int unmount_event_flags = 0;
575 int xfs_unmountfs_needed = 0;
576 int error;
577
578 rip = mp->m_rootip;
579 rvp = XFS_ITOV(rip);
580
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000581#ifdef HAVE_DMAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 if (vfsp->vfs_flag & VFS_DMI) {
583 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
584 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
585 NULL, NULL, 0, 0,
586 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
587 0:DM_FLAGS_UNWANTED);
588 if (error)
589 return XFS_ERROR(error);
590 unmount_event_wanted = 1;
591 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
592 0 : DM_FLAGS_UNWANTED;
593 }
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000594#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 /*
596 * First blow any referenced inode from this file system
597 * out of the reference cache, and delete the timer.
598 */
599 xfs_refcache_purge_mp(mp);
600
David Chinner2a82b8b2007-07-11 11:09:12 +1000601 /*
602 * Blow away any referenced inode in the filestreams cache.
603 * This can and will cause log traffic as inodes go inactive
604 * here.
605 */
606 xfs_filestream_unmount(mp);
607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 XFS_bflush(mp->m_ddev_targp);
609 error = xfs_unmount_flush(mp, 0);
610 if (error)
611 goto out;
612
613 ASSERT(vn_count(rvp) == 1);
614
615 /*
616 * Drop the reference count
617 */
618 VN_RELE(rvp);
619
620 /*
621 * If we're forcing a shutdown, typically because of a media error,
622 * we want to make sure we invalidate dirty pages that belong to
623 * referenced vnodes as well.
624 */
625 if (XFS_FORCED_SHUTDOWN(mp)) {
626 error = xfs_sync(&mp->m_bhv,
627 (SYNC_WAIT | SYNC_CLOSE), credp);
628 ASSERT(error != EFSCORRUPTED);
629 }
630 xfs_unmountfs_needed = 1;
631
632out:
633 /* Send DMAPI event, if required.
634 * Then do xfs_unmountfs() if needed.
635 * Then return error (or zero).
636 */
637 if (unmount_event_wanted) {
638 /* Note: mp structure must still exist for
639 * XFS_SEND_UNMOUNT() call.
640 */
641 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
642 DM_RIGHT_NULL, 0, error, unmount_event_flags);
643 }
644 if (xfs_unmountfs_needed) {
645 /*
646 * Call common unmount function to flush to disk
647 * and free the super block buffer & mount structures.
648 */
649 xfs_unmountfs(mp, credp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000650 xfs_dmops_put(mp);
Christoph Hellwigf541d272007-08-29 11:53:22 +1000651 kmem_free(mp, sizeof(xfs_mount_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
654 return XFS_ERROR(error);
655}
656
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000657STATIC int
658xfs_quiesce_fs(
659 xfs_mount_t *mp)
660{
661 int count = 0, pincount;
Nathan Scott3758dee2006-03-22 12:47:28 +1100662
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000663 xfs_refcache_purge_mp(mp);
664 xfs_flush_buftarg(mp->m_ddev_targp, 0);
665 xfs_finish_reclaim_all(mp, 0);
666
667 /* This loop must run at least twice.
668 * The first instance of the loop will flush
669 * most meta data but that will generate more
670 * meta data (typically directory updates).
671 * Which then must be flushed and logged before
672 * we can write the unmount record.
Nathan Scott3758dee2006-03-22 12:47:28 +1100673 */
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000674 do {
David Chinner516b2e72007-06-18 16:50:48 +1000675 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000676 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
677 if (!pincount) {
678 delay(50);
679 count++;
680 }
681 } while (count < 2);
682
683 return 0;
684}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
David Chinner516b2e72007-06-18 16:50:48 +1000686/*
687 * Second stage of a quiesce. The data is already synced, now we have to take
688 * care of the metadata. New transactions are already blocked, so we need to
689 * wait for any remaining transactions to drain out before proceding.
690 */
691STATIC void
692xfs_attr_quiesce(
693 xfs_mount_t *mp)
694{
695 /* wait for all modifications to complete */
696 while (atomic_read(&mp->m_active_trans) > 0)
697 delay(100);
698
699 /* flush inodes and push all remaining buffers out to disk */
700 xfs_quiesce_fs(mp);
701
702 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
703
704 /* Push the superblock and write an unmount record */
705 xfs_log_sbcount(mp, 1);
706 xfs_log_unmount_write(mp);
707 xfs_unmountfs_writesb(mp);
708}
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710STATIC int
711xfs_mntupdate(
712 bhv_desc_t *bdp,
713 int *flags,
714 struct xfs_mount_args *args)
715{
Nathan Scottb83bd132006-06-09 16:48:30 +1000716 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Nathan Scottd08d3892006-05-08 19:51:28 +1000719 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
720 if (vfsp->vfs_flag & VFS_RDONLY)
721 vfsp->vfs_flag &= ~VFS_RDONLY;
722 if (args->flags & XFSMNT_BARRIER) {
723 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100724 xfs_mountfs_check_barriers(mp);
Nathan Scottd08d3892006-05-08 19:51:28 +1000725 } else {
726 mp->m_flags &= ~XFS_MOUNT_BARRIER;
727 }
728 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
David Chinner2a82b8b2007-07-11 11:09:12 +1000729 xfs_filestream_flush(mp);
David Chinner516b2e72007-06-18 16:50:48 +1000730 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
731 xfs_attr_quiesce(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 vfsp->vfs_flag |= VFS_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return 0;
735}
736
737/*
738 * xfs_unmount_flush implements a set of flush operation on special
739 * inodes, which are needed as a separate set of operations so that
740 * they can be called as part of relocation process.
741 */
742int
743xfs_unmount_flush(
744 xfs_mount_t *mp, /* Mount structure we are getting
745 rid of. */
746 int relocation) /* Called from vfs relocation. */
747{
748 xfs_inode_t *rip = mp->m_rootip;
749 xfs_inode_t *rbmip;
750 xfs_inode_t *rsumip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000751 bhv_vnode_t *rvp = XFS_ITOV(rip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 int error;
753
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000754 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 xfs_iflock(rip);
756
757 /*
758 * Flush out the real time inodes.
759 */
760 if ((rbmip = mp->m_rbmip) != NULL) {
761 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
762 xfs_iflock(rbmip);
763 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
764 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
765
766 if (error == EFSCORRUPTED)
767 goto fscorrupt_out;
768
769 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
770
771 rsumip = mp->m_rsumip;
772 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
773 xfs_iflock(rsumip);
774 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
775 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
776
777 if (error == EFSCORRUPTED)
778 goto fscorrupt_out;
779
780 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
781 }
782
783 /*
784 * Synchronously flush root inode to disk
785 */
786 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
787 if (error == EFSCORRUPTED)
788 goto fscorrupt_out2;
789
790 if (vn_count(rvp) != 1 && !relocation) {
791 xfs_iunlock(rip, XFS_ILOCK_EXCL);
792 return XFS_ERROR(EBUSY);
793 }
794
795 /*
796 * Release dquot that rootinode, rbmino and rsumino might be holding,
797 * flush and purge the quota inodes.
798 */
799 error = XFS_QM_UNMOUNT(mp);
800 if (error == EFSCORRUPTED)
801 goto fscorrupt_out2;
802
803 if (rbmip) {
804 VN_RELE(XFS_ITOV(rbmip));
805 VN_RELE(XFS_ITOV(rsumip));
806 }
807
808 xfs_iunlock(rip, XFS_ILOCK_EXCL);
809 return 0;
810
811fscorrupt_out:
812 xfs_ifunlock(rip);
813
814fscorrupt_out2:
815 xfs_iunlock(rip, XFS_ILOCK_EXCL);
816
817 return XFS_ERROR(EFSCORRUPTED);
818}
819
820/*
821 * xfs_root extracts the root vnode from a vfs.
822 *
823 * vfsp -- the vfs struct for the desired file system
824 * vpp -- address of the caller's vnode pointer which should be
825 * set to the desired fs root vnode
826 */
827STATIC int
828xfs_root(
829 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000830 bhv_vnode_t **vpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000832 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
835 VN_HOLD(vp);
836 *vpp = vp;
837 return 0;
838}
839
840/*
841 * xfs_statvfs
842 *
843 * Fill in the statvfs structure for the given file system. We use
844 * the superblock lock in the mount structure to ensure a consistent
845 * snapshot of the counters returned.
846 */
847STATIC int
848xfs_statvfs(
849 bhv_desc_t *bdp,
Nathan Scott8285fb52006-06-09 17:07:12 +1000850 bhv_statvfs_t *statp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000851 bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
853 __uint64_t fakeinos;
854 xfs_extlen_t lsize;
855 xfs_mount_t *mp;
856 xfs_sb_t *sbp;
857 unsigned long s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
859 mp = XFS_BHVTOM(bdp);
860 sbp = &(mp->m_sb);
861
862 statp->f_type = XFS_SB_MAGIC;
863
David Chinnerdbcabad2007-02-10 18:36:17 +1100864 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 s = XFS_SB_LOCK(mp);
866 statp->f_bsize = sbp->sb_blocksize;
867 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
868 statp->f_blocks = sbp->sb_dblocks - lsize;
David Chinner4be536d2006-09-07 14:26:50 +1000869 statp->f_bfree = statp->f_bavail =
870 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 fakeinos = statp->f_bfree << sbp->sb_inopblog;
872#if XFS_BIG_INUMS
873 fakeinos += mp->m_inoadd;
874#endif
875 statp->f_files =
876 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
877 if (mp->m_maxicount)
878#if XFS_BIG_INUMS
879 if (!mp->m_inoadd)
880#endif
881 statp->f_files = min_t(typeof(statp->f_files),
882 statp->f_files,
883 mp->m_maxicount);
884 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
885 XFS_SB_UNLOCK(mp, s);
886
Nathan Scottcde410a2005-09-05 11:47:01 +1000887 xfs_statvfs_fsid(statp, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 statp->f_namelen = MAXNAMELEN - 1;
889
890 return 0;
891}
892
893
894/*
895 * xfs_sync flushes any pending I/O to file system vfsp.
896 *
897 * This routine is called by vfs_sync() to make sure that things make it
898 * out to disk eventually, on sync() system calls to flush out everything,
899 * and when the file system is unmounted. For the vfs_sync() case, all
900 * we really need to do is sync out the log to make all of our meta-data
901 * updates permanent (except for timestamps). For calls from pflushd(),
902 * dirty pages are kept moving by calling pdflush() on the inodes
903 * containing them. We also flush the inodes that we can lock without
904 * sleeping and the superblock if we can lock it without sleeping from
905 * vfs_sync() so that items at the tail of the log are always moving out.
906 *
907 * Flags:
908 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
909 * to sleep if we can help it. All we really need
910 * to do is ensure that the log is synced at least
911 * periodically. We also push the inodes and
912 * superblock if we can lock them without sleeping
913 * and they are not pinned.
914 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
915 * set, then we really want to lock each inode and flush
916 * it.
917 * SYNC_WAIT - All the flushes that take place in this call should
918 * be synchronous.
919 * SYNC_DELWRI - This tells us to push dirty pages associated with
920 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
921 * determine if they should be flushed sync, async, or
922 * delwri.
923 * SYNC_CLOSE - This flag is passed when the system is being
Nathan Scottc41564b2006-03-29 08:55:14 +1000924 * unmounted. We should sync and invalidate everything.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 * SYNC_FSDATA - This indicates that the caller would like to make
926 * sure the superblock is safe on disk. We can ensure
Nathan Scottc41564b2006-03-29 08:55:14 +1000927 * this by simply making sure the log gets flushed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 * if SYNC_BDFLUSH is set, and by actually writing it
929 * out otherwise.
David Chinner3c0dc772007-02-10 18:37:22 +1100930 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
931 * before we return (including direct I/O). Forms the drain
932 * side of the write barrier needed to safely quiesce the
933 * filesystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 *
935 */
936/*ARGSUSED*/
937STATIC int
938xfs_sync(
939 bhv_desc_t *bdp,
940 int flags,
941 cred_t *credp)
942{
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000943 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
David Chinner2a82b8b2007-07-11 11:09:12 +1000945 if (flags & SYNC_IOWAIT)
946 xfs_filestream_flush(mp);
947
David Chinner28239452007-02-10 18:36:40 +1100948 return xfs_syncsub(mp, flags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949}
950
951/*
952 * xfs sync routine for internal use
953 *
Nathan Scottb83bd132006-06-09 16:48:30 +1000954 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +1100955 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 *
957 */
Nathan Scottee348072005-11-02 10:32:38 +1100958int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959xfs_sync_inodes(
960 xfs_mount_t *mp,
961 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 int *bypassed)
963{
964 xfs_inode_t *ip = NULL;
965 xfs_inode_t *ip_next;
966 xfs_buf_t *bp;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000967 bhv_vnode_t *vp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 int error;
969 int last_error;
970 uint64_t fflag;
971 uint lock_flags;
972 uint base_lock_flags;
973 boolean_t mount_locked;
974 boolean_t vnode_refed;
975 int preempt;
976 xfs_dinode_t *dip;
977 xfs_iptr_t *ipointer;
978#ifdef DEBUG
979 boolean_t ipointer_in = B_FALSE;
980
981#define IPOINTER_SET ipointer_in = B_TRUE
982#define IPOINTER_CLR ipointer_in = B_FALSE
983#else
984#define IPOINTER_SET
985#define IPOINTER_CLR
986#endif
987
988
989/* Insert a marker record into the inode list after inode ip. The list
990 * must be locked when this is called. After the call the list will no
991 * longer be locked.
992 */
993#define IPOINTER_INSERT(ip, mp) { \
994 ASSERT(ipointer_in == B_FALSE); \
995 ipointer->ip_mnext = ip->i_mnext; \
996 ipointer->ip_mprev = ip; \
997 ip->i_mnext = (xfs_inode_t *)ipointer; \
998 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
999 preempt = 0; \
1000 XFS_MOUNT_IUNLOCK(mp); \
1001 mount_locked = B_FALSE; \
1002 IPOINTER_SET; \
1003 }
1004
1005/* Remove the marker from the inode list. If the marker was the only item
1006 * in the list then there are no remaining inodes and we should zero out
1007 * the whole list. If we are the current head of the list then move the head
1008 * past us.
1009 */
1010#define IPOINTER_REMOVE(ip, mp) { \
1011 ASSERT(ipointer_in == B_TRUE); \
1012 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1013 ip = ipointer->ip_mnext; \
1014 ip->i_mprev = ipointer->ip_mprev; \
1015 ipointer->ip_mprev->i_mnext = ip; \
1016 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1017 mp->m_inodes = ip; \
1018 } \
1019 } else { \
1020 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1021 mp->m_inodes = NULL; \
1022 ip = NULL; \
1023 } \
1024 IPOINTER_CLR; \
1025 }
1026
1027#define XFS_PREEMPT_MASK 0x7f
1028
1029 if (bypassed)
1030 *bypassed = 0;
1031 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1032 return 0;
1033 error = 0;
1034 last_error = 0;
1035 preempt = 0;
1036
1037 /* Allocate a reference marker */
1038 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1039
1040 fflag = XFS_B_ASYNC; /* default is don't wait */
Nathan Scottee348072005-11-02 10:32:38 +11001041 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 fflag = XFS_B_DELWRI;
1043 if (flags & SYNC_WAIT)
1044 fflag = 0; /* synchronous overrides all */
1045
1046 base_lock_flags = XFS_ILOCK_SHARED;
1047 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1048 /*
1049 * We need the I/O lock if we're going to call any of
1050 * the flush/inval routines.
1051 */
1052 base_lock_flags |= XFS_IOLOCK_SHARED;
1053 }
1054
1055 XFS_MOUNT_ILOCK(mp);
1056
1057 ip = mp->m_inodes;
1058
1059 mount_locked = B_TRUE;
1060 vnode_refed = B_FALSE;
1061
1062 IPOINTER_CLR;
1063
1064 do {
1065 ASSERT(ipointer_in == B_FALSE);
1066 ASSERT(vnode_refed == B_FALSE);
1067
1068 lock_flags = base_lock_flags;
1069
1070 /*
1071 * There were no inodes in the list, just break out
1072 * of the loop.
1073 */
1074 if (ip == NULL) {
1075 break;
1076 }
1077
1078 /*
1079 * We found another sync thread marker - skip it
1080 */
1081 if (ip->i_mount == NULL) {
1082 ip = ip->i_mnext;
1083 continue;
1084 }
1085
1086 vp = XFS_ITOV_NULL(ip);
1087
1088 /*
1089 * If the vnode is gone then this is being torn down,
1090 * call reclaim if it is flushed, else let regular flush
1091 * code deal with it later in the loop.
1092 */
1093
1094 if (vp == NULL) {
1095 /* Skip ones already in reclaim */
1096 if (ip->i_flags & XFS_IRECLAIM) {
1097 ip = ip->i_mnext;
1098 continue;
1099 }
1100 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1101 ip = ip->i_mnext;
1102 } else if ((xfs_ipincount(ip) == 0) &&
1103 xfs_iflock_nowait(ip)) {
1104 IPOINTER_INSERT(ip, mp);
1105
1106 xfs_finish_reclaim(ip, 1,
1107 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1108
1109 XFS_MOUNT_ILOCK(mp);
1110 mount_locked = B_TRUE;
1111 IPOINTER_REMOVE(ip, mp);
1112 } else {
1113 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1114 ip = ip->i_mnext;
1115 }
1116 continue;
1117 }
1118
1119 if (VN_BAD(vp)) {
1120 ip = ip->i_mnext;
1121 continue;
1122 }
1123
1124 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1125 XFS_MOUNT_IUNLOCK(mp);
1126 kmem_free(ipointer, sizeof(xfs_iptr_t));
1127 return 0;
1128 }
1129
1130 /*
1131 * If this is just vfs_sync() or pflushd() calling
1132 * then we can skip inodes for which it looks like
1133 * there is nothing to do. Since we don't have the
Nathan Scottc41564b2006-03-29 08:55:14 +10001134 * inode locked this is racy, but these are periodic
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 * calls so it doesn't matter. For the others we want
1136 * to know for sure, so we at least try to lock them.
1137 */
1138 if (flags & SYNC_BDFLUSH) {
1139 if (((ip->i_itemp == NULL) ||
1140 !(ip->i_itemp->ili_format.ilf_fields &
1141 XFS_ILOG_ALL)) &&
1142 (ip->i_update_core == 0)) {
1143 ip = ip->i_mnext;
1144 continue;
1145 }
1146 }
1147
1148 /*
1149 * Try to lock without sleeping. We're out of order with
1150 * the inode list lock here, so if we fail we need to drop
1151 * the mount lock and try again. If we're called from
1152 * bdflush() here, then don't bother.
1153 *
1154 * The inode lock here actually coordinates with the
1155 * almost spurious inode lock in xfs_ireclaim() to prevent
1156 * the vnode we handle here without a reference from
1157 * being freed while we reference it. If we lock the inode
1158 * while it's on the mount list here, then the spurious inode
1159 * lock in xfs_ireclaim() after the inode is pulled from
1160 * the mount list will sleep until we release it here.
1161 * This keeps the vnode from being freed while we reference
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001162 * it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 */
1164 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1166 ip = ip->i_mnext;
1167 continue;
1168 }
1169
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001170 vp = vn_grab(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 if (vp == NULL) {
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001172 ip = ip->i_mnext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 continue;
1174 }
1175
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001176 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 xfs_ilock(ip, lock_flags);
1178
1179 ASSERT(vp == XFS_ITOV(ip));
1180 ASSERT(ip->i_mount == mp);
1181
1182 vnode_refed = B_TRUE;
1183 }
1184
1185 /* From here on in the loop we may have a marker record
1186 * in the inode list.
1187 */
1188
David Chinner40095b62007-05-14 18:24:09 +10001189 /*
1190 * If we have to flush data or wait for I/O completion
1191 * we need to drop the ilock that we currently hold.
1192 * If we need to drop the lock, insert a marker if we
1193 * have not already done so.
1194 */
1195 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1196 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1197 if (mount_locked) {
1198 IPOINTER_INSERT(ip, mp);
1199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1201
David Chinner40095b62007-05-14 18:24:09 +10001202 if (flags & SYNC_CLOSE) {
1203 /* Shutdown case. Flush and invalidate. */
1204 if (XFS_FORCED_SHUTDOWN(mp))
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001205 xfs_tosspages(ip, 0, -1,
1206 FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001207 else
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001208 error = xfs_flushinval_pages(ip,
1209 0, -1, FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001210 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001211 error = xfs_flush_pages(ip, 0,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001212 -1, fflag, FI_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
1214
David Chinner40095b62007-05-14 18:24:09 +10001215 /*
1216 * When freezing, we need to wait ensure all I/O (including direct
1217 * I/O) is complete to ensure no further data modification can take
1218 * place after this point
1219 */
1220 if (flags & SYNC_IOWAIT)
Christoph Hellwigb677c212007-08-29 11:46:28 +10001221 vn_iowait(ip);
David Chinner40095b62007-05-14 18:24:09 +10001222
1223 xfs_ilock(ip, XFS_ILOCK_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 }
1225
1226 if (flags & SYNC_BDFLUSH) {
1227 if ((flags & SYNC_ATTR) &&
1228 ((ip->i_update_core) ||
1229 ((ip->i_itemp != NULL) &&
1230 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1231
1232 /* Insert marker and drop lock if not already
1233 * done.
1234 */
1235 if (mount_locked) {
1236 IPOINTER_INSERT(ip, mp);
1237 }
1238
1239 /*
1240 * We don't want the periodic flushing of the
1241 * inodes by vfs_sync() to interfere with
1242 * I/O to the file, especially read I/O
1243 * where it is only the access time stamp
1244 * that is being flushed out. To prevent
1245 * long periods where we have both inode
1246 * locks held shared here while reading the
1247 * inode's buffer in from disk, we drop the
1248 * inode lock while reading in the inode
1249 * buffer. We have to release the buffer
1250 * and reacquire the inode lock so that they
1251 * are acquired in the proper order (inode
1252 * locks first). The buffer will go at the
1253 * end of the lru chain, though, so we can
1254 * expect it to still be there when we go
1255 * for it again in xfs_iflush().
1256 */
1257 if ((xfs_ipincount(ip) == 0) &&
1258 xfs_iflock_nowait(ip)) {
1259
1260 xfs_ifunlock(ip);
1261 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1262
1263 error = xfs_itobp(mp, NULL, ip,
Nathan Scottb12dd342006-03-17 17:26:04 +11001264 &dip, &bp, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if (!error) {
1266 xfs_buf_relse(bp);
1267 } else {
1268 /* Bailing out, remove the
1269 * marker and free it.
1270 */
1271 XFS_MOUNT_ILOCK(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 IPOINTER_REMOVE(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 XFS_MOUNT_IUNLOCK(mp);
1274
1275 ASSERT(!(lock_flags &
1276 XFS_IOLOCK_SHARED));
1277
1278 kmem_free(ipointer,
1279 sizeof(xfs_iptr_t));
1280 return (0);
1281 }
1282
1283 /*
1284 * Since we dropped the inode lock,
1285 * the inode may have been reclaimed.
1286 * Therefore, we reacquire the mount
1287 * lock and check to see if we were the
1288 * inode reclaimed. If this happened
1289 * then the ipointer marker will no
1290 * longer point back at us. In this
1291 * case, move ip along to the inode
1292 * after the marker, remove the marker
1293 * and continue.
1294 */
1295 XFS_MOUNT_ILOCK(mp);
1296 mount_locked = B_TRUE;
1297
1298 if (ip != ipointer->ip_mprev) {
1299 IPOINTER_REMOVE(ip, mp);
1300
1301 ASSERT(!vnode_refed);
1302 ASSERT(!(lock_flags &
1303 XFS_IOLOCK_SHARED));
1304 continue;
1305 }
1306
1307 ASSERT(ip->i_mount == mp);
1308
1309 if (xfs_ilock_nowait(ip,
1310 XFS_ILOCK_SHARED) == 0) {
1311 ASSERT(ip->i_mount == mp);
1312 /*
1313 * We failed to reacquire
1314 * the inode lock without
1315 * sleeping, so just skip
1316 * the inode for now. We
1317 * clear the ILOCK bit from
1318 * the lock_flags so that we
1319 * won't try to drop a lock
1320 * we don't hold below.
1321 */
1322 lock_flags &= ~XFS_ILOCK_SHARED;
1323 IPOINTER_REMOVE(ip_next, mp);
1324 } else if ((xfs_ipincount(ip) == 0) &&
1325 xfs_iflock_nowait(ip)) {
1326 ASSERT(ip->i_mount == mp);
1327 /*
1328 * Since this is vfs_sync()
1329 * calling we only flush the
1330 * inode out if we can lock
1331 * it without sleeping and
1332 * it is not pinned. Drop
1333 * the mount lock here so
1334 * that we don't hold it for
1335 * too long. We already have
1336 * a marker in the list here.
1337 */
1338 XFS_MOUNT_IUNLOCK(mp);
1339 mount_locked = B_FALSE;
1340 error = xfs_iflush(ip,
1341 XFS_IFLUSH_DELWRI);
1342 } else {
1343 ASSERT(ip->i_mount == mp);
1344 IPOINTER_REMOVE(ip_next, mp);
1345 }
1346 }
1347
1348 }
1349
1350 } else {
1351 if ((flags & SYNC_ATTR) &&
1352 ((ip->i_update_core) ||
1353 ((ip->i_itemp != NULL) &&
1354 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1355 if (mount_locked) {
1356 IPOINTER_INSERT(ip, mp);
1357 }
1358
1359 if (flags & SYNC_WAIT) {
1360 xfs_iflock(ip);
1361 error = xfs_iflush(ip,
1362 XFS_IFLUSH_SYNC);
1363 } else {
1364 /*
1365 * If we can't acquire the flush
1366 * lock, then the inode is already
1367 * being flushed so don't bother
1368 * waiting. If we can lock it then
1369 * do a delwri flush so we can
1370 * combine multiple inode flushes
1371 * in each disk write.
1372 */
1373 if (xfs_iflock_nowait(ip)) {
1374 error = xfs_iflush(ip,
1375 XFS_IFLUSH_DELWRI);
1376 }
1377 else if (bypassed)
1378 (*bypassed)++;
1379 }
1380 }
1381 }
1382
1383 if (lock_flags != 0) {
1384 xfs_iunlock(ip, lock_flags);
1385 }
1386
1387 if (vnode_refed) {
1388 /*
1389 * If we had to take a reference on the vnode
1390 * above, then wait until after we've unlocked
1391 * the inode to release the reference. This is
1392 * because we can be already holding the inode
1393 * lock when VN_RELE() calls xfs_inactive().
1394 *
1395 * Make sure to drop the mount lock before calling
1396 * VN_RELE() so that we don't trip over ourselves if
1397 * we have to go for the mount lock again in the
1398 * inactive code.
1399 */
1400 if (mount_locked) {
1401 IPOINTER_INSERT(ip, mp);
1402 }
1403
1404 VN_RELE(vp);
1405
1406 vnode_refed = B_FALSE;
1407 }
1408
1409 if (error) {
1410 last_error = error;
1411 }
1412
1413 /*
1414 * bail out if the filesystem is corrupted.
1415 */
1416 if (error == EFSCORRUPTED) {
1417 if (!mount_locked) {
1418 XFS_MOUNT_ILOCK(mp);
1419 IPOINTER_REMOVE(ip, mp);
1420 }
1421 XFS_MOUNT_IUNLOCK(mp);
1422 ASSERT(ipointer_in == B_FALSE);
1423 kmem_free(ipointer, sizeof(xfs_iptr_t));
1424 return XFS_ERROR(error);
1425 }
1426
1427 /* Let other threads have a chance at the mount lock
1428 * if we have looped many times without dropping the
1429 * lock.
1430 */
1431 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1432 if (mount_locked) {
1433 IPOINTER_INSERT(ip, mp);
1434 }
1435 }
1436
1437 if (mount_locked == B_FALSE) {
1438 XFS_MOUNT_ILOCK(mp);
1439 mount_locked = B_TRUE;
1440 IPOINTER_REMOVE(ip, mp);
1441 continue;
1442 }
1443
1444 ASSERT(ipointer_in == B_FALSE);
1445 ip = ip->i_mnext;
1446
1447 } while (ip != mp->m_inodes);
1448
1449 XFS_MOUNT_IUNLOCK(mp);
1450
1451 ASSERT(ipointer_in == B_FALSE);
1452
1453 kmem_free(ipointer, sizeof(xfs_iptr_t));
1454 return XFS_ERROR(last_error);
1455}
1456
1457/*
1458 * xfs sync routine for internal use
1459 *
Nathan Scottb83bd132006-06-09 16:48:30 +10001460 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001461 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 *
1463 */
1464int
1465xfs_syncsub(
1466 xfs_mount_t *mp,
1467 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 int *bypassed)
1469{
1470 int error = 0;
1471 int last_error = 0;
1472 uint log_flags = XFS_LOG_FORCE;
1473 xfs_buf_t *bp;
1474 xfs_buf_log_item_t *bip;
1475
1476 /*
1477 * Sync out the log. This ensures that the log is periodically
1478 * flushed even if there is not enough activity to fill it up.
1479 */
1480 if (flags & SYNC_WAIT)
1481 log_flags |= XFS_LOG_SYNC;
1482
1483 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1484
1485 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1486 if (flags & SYNC_BDFLUSH)
1487 xfs_finish_reclaim_all(mp, 1);
1488 else
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001489 error = xfs_sync_inodes(mp, flags, bypassed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 }
1491
1492 /*
1493 * Flushing out dirty data above probably generated more
1494 * log activity, so if this isn't vfs_sync() then flush
1495 * the log again.
1496 */
1497 if (flags & SYNC_DELWRI) {
1498 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1499 }
1500
1501 if (flags & SYNC_FSDATA) {
1502 /*
1503 * If this is vfs_sync() then only sync the superblock
1504 * if we can lock it without sleeping and it is not pinned.
1505 */
1506 if (flags & SYNC_BDFLUSH) {
1507 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1508 if (bp != NULL) {
1509 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1510 if ((bip != NULL) &&
1511 xfs_buf_item_dirty(bip)) {
1512 if (!(XFS_BUF_ISPINNED(bp))) {
1513 XFS_BUF_ASYNC(bp);
1514 error = xfs_bwrite(mp, bp);
1515 } else {
1516 xfs_buf_relse(bp);
1517 }
1518 } else {
1519 xfs_buf_relse(bp);
1520 }
1521 }
1522 } else {
1523 bp = xfs_getsb(mp, 0);
1524 /*
1525 * If the buffer is pinned then push on the log so
1526 * we won't get stuck waiting in the write for
1527 * someone, maybe ourselves, to flush the log.
1528 * Even though we just pushed the log above, we
1529 * did not have the superblock buffer locked at
1530 * that point so it can become pinned in between
1531 * there and here.
1532 */
1533 if (XFS_BUF_ISPINNED(bp))
1534 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1535 if (flags & SYNC_WAIT)
1536 XFS_BUF_UNASYNC(bp);
1537 else
1538 XFS_BUF_ASYNC(bp);
1539 error = xfs_bwrite(mp, bp);
1540 }
1541 if (error) {
1542 last_error = error;
1543 }
1544 }
1545
1546 /*
1547 * If this is the periodic sync, then kick some entries out of
1548 * the reference cache. This ensures that idle entries are
1549 * eventually kicked out of the cache.
1550 */
1551 if (flags & SYNC_REFCACHE) {
Nathan Scottcde410a2005-09-05 11:47:01 +10001552 if (flags & SYNC_WAIT)
1553 xfs_refcache_purge_mp(mp);
1554 else
1555 xfs_refcache_purge_some(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 }
1557
1558 /*
David Chinner92821e22007-05-24 15:26:31 +10001559 * If asked, update the disk superblock with incore counter values if we
1560 * are using non-persistent counters so that they don't get too far out
1561 * of sync if we crash or get a forced shutdown. We don't want to force
1562 * this to disk, just get a transaction into the iclogs....
1563 */
1564 if (flags & SYNC_SUPER)
1565 xfs_log_sbcount(mp, 0);
1566
1567 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 * Now check to see if the log needs a "dummy" transaction.
1569 */
1570
1571 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1572 xfs_trans_t *tp;
1573 xfs_inode_t *ip;
1574
1575 /*
1576 * Put a dummy transaction in the log to tell
1577 * recovery that all others are OK.
1578 */
1579 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1580 if ((error = xfs_trans_reserve(tp, 0,
1581 XFS_ICHANGE_LOG_RES(mp),
1582 0, 0, 0))) {
1583 xfs_trans_cancel(tp, 0);
1584 return error;
1585 }
1586
1587 ip = mp->m_rootip;
1588 xfs_ilock(ip, XFS_ILOCK_EXCL);
1589
1590 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1591 xfs_trans_ihold(tp, ip);
1592 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
Eric Sandeen1c72bf92007-05-08 13:48:42 +10001593 error = xfs_trans_commit(tp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1595 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1596 }
1597
1598 /*
1599 * When shutting down, we need to insure that the AIL is pushed
1600 * to disk or the filesystem can appear corrupt from the PROM.
1601 */
1602 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1603 XFS_bflush(mp->m_ddev_targp);
1604 if (mp->m_rtdev_targp) {
1605 XFS_bflush(mp->m_rtdev_targp);
1606 }
1607 }
1608
1609 return XFS_ERROR(last_error);
1610}
1611
1612/*
1613 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1614 */
1615STATIC int
1616xfs_vget(
1617 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001618 bhv_vnode_t **vpp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 fid_t *fidp)
1620{
1621 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1622 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1623 xfs_inode_t *ip;
1624 int error;
1625 xfs_ino_t ino;
1626 unsigned int igen;
1627
1628 /*
1629 * Invalid. Since handles can be created in user space and passed in
1630 * via gethandle(), this is not cause for a panic.
1631 */
1632 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1633 return XFS_ERROR(EINVAL);
1634
1635 ino = xfid->xfs_fid_ino;
1636 igen = xfid->xfs_fid_gen;
1637
1638 /*
1639 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1640 */
1641 if (ino == 0)
1642 return XFS_ERROR(ESTALE);
1643
1644 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1645 if (error) {
1646 *vpp = NULL;
1647 return error;
1648 }
1649
1650 if (ip == NULL) {
1651 *vpp = NULL;
1652 return XFS_ERROR(EIO);
1653 }
1654
1655 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1656 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1657 *vpp = NULL;
1658 return XFS_ERROR(ENOENT);
1659 }
1660
1661 *vpp = XFS_ITOV(ip);
1662 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1663 return 0;
1664}
1665
1666
1667#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1668#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1669#define MNTOPT_LOGDEV "logdev" /* log device */
1670#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1671#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1672#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1673#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1674#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1675#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1676#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1677#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1678#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1679#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
Nathan Scotte69a3332005-09-02 16:42:26 +10001680#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1681#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1682#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1683#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
Nathan Scott1f443ad2005-05-05 13:28:29 -07001684#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001686#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
Nathan Scottd8cc8902005-11-02 10:34:53 +11001687 * unwritten extent conversion */
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001688#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1690#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1691#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1692#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
David Chinnere8c8b3a2005-11-02 10:33:05 +11001693#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1694#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1695 * in stat(). */
Nathan Scottd8cc8902005-11-02 10:34:53 +11001696#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1697#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
David Chinner2a82b8b2007-07-11 11:09:12 +10001698#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
Christoph Hellwig293688e2007-08-29 11:59:36 +10001699#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
1700#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
1701#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
Nathan Scott1f443ad2005-05-05 13:28:29 -07001703STATIC unsigned long
Nathan Scottb190f112006-06-09 17:13:15 +10001704suffix_strtoul(char *s, char **endp, unsigned int base)
Nathan Scott1f443ad2005-05-05 13:28:29 -07001705{
1706 int last, shift_left_factor = 0;
Nathan Scottb190f112006-06-09 17:13:15 +10001707 char *value = s;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001708
1709 last = strlen(value) - 1;
1710 if (value[last] == 'K' || value[last] == 'k') {
1711 shift_left_factor = 10;
1712 value[last] = '\0';
1713 }
1714 if (value[last] == 'M' || value[last] == 'm') {
1715 shift_left_factor = 20;
1716 value[last] = '\0';
1717 }
1718 if (value[last] == 'G' || value[last] == 'g') {
1719 shift_left_factor = 30;
1720 value[last] = '\0';
1721 }
1722
Nathan Scottb190f112006-06-09 17:13:15 +10001723 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001724}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10001726STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727xfs_parseargs(
1728 struct bhv_desc *bhv,
1729 char *options,
1730 struct xfs_mount_args *args,
1731 int update)
1732{
Nathan Scottb83bd132006-06-09 16:48:30 +10001733 bhv_vfs_t *vfsp = bhvtovfs(bhv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 char *this_char, *value, *eov;
1735 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1736 int iosize;
1737
Vlad Apostolovb93bd202007-08-28 14:00:28 +10001738 /*
1739 * Applications using DMI filesystems often expect the
1740 * inode generation number to be monotonically increasing.
1741 * If we delete inode chunks we break this assumption, so
1742 * keep unused inode chunks on disk for DMI filesystems
1743 * until we come up with a better solution.
1744 * Note that if "ikeep" or "noikeep" mount options are
1745 * supplied, then they are honored.
1746 */
1747 if (!(args->flags & XFSMNT_DMAPI))
1748 args->flags |= XFSMNT_IDELETE;
1749
Nathan Scott3bbcc8e2006-03-31 13:04:56 +10001750 args->flags |= XFSMNT_BARRIER;
1751 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 if (!options)
Nathan Scott05db2182005-11-04 09:49:07 +11001754 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1757
1758 while ((this_char = strsep(&options, ",")) != NULL) {
1759 if (!*this_char)
1760 continue;
1761 if ((value = strchr(this_char, '=')) != NULL)
1762 *value++ = 0;
1763
1764 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1765 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001766 cmn_err(CE_WARN,
1767 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001768 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 return EINVAL;
1770 }
1771 args->logbufs = simple_strtoul(value, &eov, 10);
1772 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001774 cmn_err(CE_WARN,
1775 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001776 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 return EINVAL;
1778 }
Nathan Scott1f443ad2005-05-05 13:28:29 -07001779 args->logbufsize = suffix_strtoul(value, &eov, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1781 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001782 cmn_err(CE_WARN,
1783 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001784 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 return EINVAL;
1786 }
1787 strncpy(args->logname, value, MAXNAMELEN);
1788 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 return EINVAL;
1794 }
1795 strncpy(args->mtpt, value, MAXNAMELEN);
1796 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1797 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001798 cmn_err(CE_WARN,
1799 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001800 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 return EINVAL;
1802 }
1803 strncpy(args->rtname, value, MAXNAMELEN);
1804 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1805 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001806 cmn_err(CE_WARN,
1807 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001808 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 return EINVAL;
1810 }
1811 iosize = simple_strtoul(value, &eov, 10);
1812 args->flags |= XFSMNT_IOSIZE;
1813 args->iosizelog = (uint8_t) iosize;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001814 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1815 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001816 cmn_err(CE_WARN,
1817 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001818 this_char);
1819 return EINVAL;
1820 }
1821 iosize = suffix_strtoul(value, &eov, 10);
1822 args->flags |= XFSMNT_IOSIZE;
1823 args->iosizelog = ffs(iosize) - 1;
Nathan Scotte69a3332005-09-02 16:42:26 +10001824 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1825 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1826 vfsp->vfs_flag |= VFS_GRPID;
1827 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1828 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1829 vfsp->vfs_flag &= ~VFS_GRPID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1831 args->flags |= XFSMNT_WSYNC;
1832 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1833 args->flags |= XFSMNT_OSYNCISOSYNC;
1834 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1835 args->flags |= XFSMNT_NORECOVERY;
1836 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1837 args->flags |= XFSMNT_INO64;
1838#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001839 cmn_err(CE_WARN,
1840 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001841 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 return EINVAL;
1843#endif
1844 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1845 args->flags |= XFSMNT_NOALIGN;
1846 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1847 args->flags |= XFSMNT_SWALLOC;
1848 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1849 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001850 cmn_err(CE_WARN,
1851 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001852 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 return EINVAL;
1854 }
1855 dsunit = simple_strtoul(value, &eov, 10);
1856 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1857 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001858 cmn_err(CE_WARN,
1859 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001860 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 return EINVAL;
1862 }
1863 dswidth = simple_strtoul(value, &eov, 10);
1864 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1865 args->flags &= ~XFSMNT_32BITINODES;
1866#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001867 cmn_err(CE_WARN,
1868 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001869 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 return EINVAL;
1871#endif
1872 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1873 args->flags |= XFSMNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001874 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1875 args->flags |= XFSMNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001876 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1877 args->flags &= ~XFSMNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1879 args->flags &= ~XFSMNT_IDELETE;
1880 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1881 args->flags |= XFSMNT_IDELETE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001882 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001883 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001884 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001885 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001886 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001887 args->flags |= XFSMNT_ATTR2;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001888 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001889 args->flags &= ~XFSMNT_ATTR2;
David Chinner2a82b8b2007-07-11 11:09:12 +10001890 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1891 args->flags2 |= XFSMNT2_FILESTREAMS;
Christoph Hellwig293688e2007-08-29 11:59:36 +10001892 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
1893 args->flags |= XFSMNT_DMAPI;
1894 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
1895 args->flags |= XFSMNT_DMAPI;
1896 } else if (!strcmp(this_char, MNTOPT_DMI)) {
1897 args->flags |= XFSMNT_DMAPI;
David Chinnerda353b02007-08-28 14:00:13 +10001898 } else if (!strcmp(this_char, "ihashsize")) {
1899 cmn_err(CE_WARN,
1900 "XFS: ihashsize no longer used, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 } else if (!strcmp(this_char, "osyncisdsync")) {
1902 /* no-op, this is now the default */
Nathan Scottb6574522006-06-09 15:29:40 +10001903 cmn_err(CE_WARN,
1904 "XFS: osyncisdsync is now the default, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 } else if (!strcmp(this_char, "irixsgid")) {
Nathan Scottb6574522006-06-09 15:29:40 +10001906 cmn_err(CE_WARN,
1907 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 } else {
Nathan Scottb6574522006-06-09 15:29:40 +10001909 cmn_err(CE_WARN,
1910 "XFS: unknown mount option [%s].", this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 return EINVAL;
1912 }
1913 }
1914
1915 if (args->flags & XFSMNT_NORECOVERY) {
1916 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
Nathan Scottb6574522006-06-09 15:29:40 +10001917 cmn_err(CE_WARN,
1918 "XFS: no-recovery mounts must be read-only.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 return EINVAL;
1920 }
1921 }
1922
1923 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001924 cmn_err(CE_WARN,
1925 "XFS: sunit and swidth options incompatible with the noalign option");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 return EINVAL;
1927 }
1928
Christoph Hellwig293688e2007-08-29 11:59:36 +10001929 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
1930 printk("XFS: %s option needs the mount point option as well\n",
1931 MNTOPT_DMAPI);
1932 return EINVAL;
1933 }
1934
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001936 cmn_err(CE_WARN,
1937 "XFS: sunit and swidth must be specified together");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 return EINVAL;
1939 }
1940
1941 if (dsunit && (dswidth % dsunit != 0)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001942 cmn_err(CE_WARN,
1943 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 dswidth, dsunit);
1945 return EINVAL;
1946 }
1947
1948 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1949 if (dsunit) {
1950 args->sunit = dsunit;
1951 args->flags |= XFSMNT_RETERR;
1952 } else {
1953 args->sunit = vol_dsunit;
1954 }
1955 dswidth ? (args->swidth = dswidth) :
1956 (args->swidth = vol_dswidth);
1957 } else {
1958 args->sunit = args->swidth = 0;
1959 }
1960
Nathan Scott05db2182005-11-04 09:49:07 +11001961done:
Nathan Scottc11e2c32005-11-02 15:11:45 +11001962 if (args->flags & XFSMNT_32BITINODES)
1963 vfsp->vfs_flag |= VFS_32BITINODES;
Nathan Scotte718eeb42005-11-02 15:09:22 +11001964 if (args->flags2)
1965 args->flags |= XFSMNT_FLAGS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 return 0;
1967}
1968
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10001969STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970xfs_showargs(
1971 struct bhv_desc *bhv,
1972 struct seq_file *m)
1973{
1974 static struct proc_xfs_info {
1975 int flag;
1976 char *str;
1977 } xfs_info[] = {
1978 /* the few simple ones we can get from the mount struct */
1979 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1980 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1981 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1982 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1983 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1984 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1985 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 { 0, NULL }
1987 };
1988 struct proc_xfs_info *xfs_infop;
1989 struct xfs_mount *mp = XFS_BHVTOM(bhv);
Nathan Scottb83bd132006-06-09 16:48:30 +10001990 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
1992 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1993 if (mp->m_flags & xfs_infop->flag)
1994 seq_puts(m, xfs_infop->str);
1995 }
1996
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001998 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1999 (int)(1 << mp->m_writeio_log) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000
2001 if (mp->m_logbufs > 0)
2002 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 if (mp->m_logbsize > 0)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11002004 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
Nathan Scottfc1f8c12005-11-02 11:44:33 +11002006 if (mp->m_logname)
2007 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +11002008 if (mp->m_rtname)
2009 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
2011 if (mp->m_dalign > 0)
2012 seq_printf(m, "," MNTOPT_SUNIT "=%d",
2013 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 if (mp->m_swidth > 0)
2015 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
2016 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
2017
Nathan Scotte15f1952006-03-22 12:47:52 +11002018 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
2019 seq_printf(m, "," MNTOPT_IKEEP);
Nathan Scottfa7e7d72005-11-02 15:00:48 +11002020 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
2021 seq_printf(m, "," MNTOPT_LARGEIO);
2022
Nathan Scottc11e2c32005-11-02 15:11:45 +11002023 if (!(vfsp->vfs_flag & VFS_32BITINODES))
2024 seq_printf(m, "," MNTOPT_64BITINODE);
Nathan Scotte69a3332005-09-02 16:42:26 +10002025 if (vfsp->vfs_flag & VFS_GRPID)
2026 seq_printf(m, "," MNTOPT_GRPID);
2027
Christoph Hellwig293688e2007-08-29 11:59:36 +10002028 if (vfsp->vfs_flag & VFS_DMI)
2029 seq_puts(m, "," MNTOPT_DMAPI);
2030
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 return 0;
2032}
2033
David Chinner28239452007-02-10 18:36:40 +11002034/*
David Chinner516b2e72007-06-18 16:50:48 +10002035 * Second stage of a freeze. The data is already frozen so we only
2036 * need to take care of themetadata. Once that's done write a dummy
2037 * record to dirty the log in case of a crash while frozen.
David Chinner28239452007-02-10 18:36:40 +11002038 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039STATIC void
2040xfs_freeze(
2041 bhv_desc_t *bdp)
2042{
2043 xfs_mount_t *mp = XFS_BHVTOM(bdp);
2044
David Chinner516b2e72007-06-18 16:50:48 +10002045 xfs_attr_quiesce(mp);
Christoph Hellwige13a73f2006-01-11 15:30:08 +11002046 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047}
2048
2049
Nathan Scottb83bd132006-06-09 16:48:30 +10002050bhv_vfsops_t xfs_vfsops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
2052 .vfs_parseargs = xfs_parseargs,
2053 .vfs_showargs = xfs_showargs,
2054 .vfs_mount = xfs_mount,
2055 .vfs_unmount = xfs_unmount,
2056 .vfs_mntupdate = xfs_mntupdate,
2057 .vfs_root = xfs_root,
2058 .vfs_statvfs = xfs_statvfs,
2059 .vfs_sync = xfs_sync,
2060 .vfs_vget = xfs_vget,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
2062 .vfs_init_vnode = xfs_initialize_vnode,
2063 .vfs_force_shutdown = xfs_do_force_shutdown,
2064 .vfs_freeze = xfs_freeze,
2065};