blob: 2d672f317110eceb67cf3e35c61b5fd4638f7008 [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"
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +100058#include "xfs_vfsops.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100059
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Linus Torvalds1da177e2005-04-16 15:20:36 -070061int
62xfs_init(void)
63{
64 extern kmem_zone_t *xfs_bmap_free_item_zone;
65 extern kmem_zone_t *xfs_btree_cur_zone;
66 extern kmem_zone_t *xfs_trans_zone;
67 extern kmem_zone_t *xfs_buf_item_zone;
68 extern kmem_zone_t *xfs_dabuf_zone;
69#ifdef XFS_DABUF_DEBUG
70 extern lock_t xfs_dabuf_global_lock;
71 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
72#endif
73
74 /*
75 * Initialize all of the zone allocators we use.
76 */
77 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
78 "xfs_bmap_free_item");
79 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
80 "xfs_btree_cur");
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
82 xfs_da_state_zone =
83 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
84 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
Nathan Scott87582802006-03-14 13:18:19 +110085 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
86 xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
David Chinner2a82b8b2007-07-11 11:09:12 +100087 xfs_mru_cache_init();
88 xfs_filestream_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 /*
91 * The size of the zone allocated buf log item is the maximum
92 * size possible under XFS. This wastes a little bit of memory,
93 * but it is much faster.
94 */
95 xfs_buf_item_zone =
96 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
97 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
98 NBWORD) * sizeof(int))),
99 "xfs_buf_item");
Nathan Scott87582802006-03-14 13:18:19 +1100100 xfs_efd_zone =
101 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
102 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
103 sizeof(xfs_extent_t))),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 "xfs_efd_item");
Nathan Scott87582802006-03-14 13:18:19 +1100105 xfs_efi_zone =
106 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
107 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
108 sizeof(xfs_extent_t))),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 "xfs_efi_item");
Nathan Scott87582802006-03-14 13:18:19 +1100110
111 /*
112 * These zones warrant special memory allocator hints
113 */
114 xfs_inode_zone =
115 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
116 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
117 KM_ZONE_SPREAD, NULL);
118 xfs_ili_zone =
119 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
120 KM_ZONE_SPREAD, NULL);
David Chinnerda353b02007-08-28 14:00:13 +1000121 xfs_icluster_zone =
122 kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster",
Nathan Scott87582802006-03-14 13:18:19 +1100123 KM_ZONE_SPREAD, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125 /*
126 * Allocate global trace buffers.
127 */
128#ifdef XFS_ALLOC_TRACE
129 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
130#endif
131#ifdef XFS_BMAP_TRACE
132 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
133#endif
134#ifdef XFS_BMBT_TRACE
135 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
136#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137#ifdef XFS_ATTR_TRACE
138 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
139#endif
140#ifdef XFS_DIR2_TRACE
141 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
142#endif
143
144 xfs_dir_startup();
145
146#if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
147 xfs_error_test_init();
148#endif /* DEBUG || INDUCE_IO_ERROR */
149
150 xfs_init_procfs();
151 xfs_sysctl_register();
152 return 0;
153}
154
155void
156xfs_cleanup(void)
157{
158 extern kmem_zone_t *xfs_bmap_free_item_zone;
159 extern kmem_zone_t *xfs_btree_cur_zone;
160 extern kmem_zone_t *xfs_inode_zone;
161 extern kmem_zone_t *xfs_trans_zone;
162 extern kmem_zone_t *xfs_da_state_zone;
163 extern kmem_zone_t *xfs_dabuf_zone;
164 extern kmem_zone_t *xfs_efd_zone;
165 extern kmem_zone_t *xfs_efi_zone;
166 extern kmem_zone_t *xfs_buf_item_zone;
David Chinnerda353b02007-08-28 14:00:13 +1000167 extern kmem_zone_t *xfs_icluster_zone;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 xfs_cleanup_procfs();
170 xfs_sysctl_unregister();
171 xfs_refcache_destroy();
David Chinner2a82b8b2007-07-11 11:09:12 +1000172 xfs_filestream_uninit();
173 xfs_mru_cache_uninit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 xfs_acl_zone_destroy(xfs_acl_zone);
175
176#ifdef XFS_DIR2_TRACE
177 ktrace_free(xfs_dir2_trace_buf);
178#endif
179#ifdef XFS_ATTR_TRACE
180 ktrace_free(xfs_attr_trace_buf);
181#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#ifdef XFS_BMBT_TRACE
183 ktrace_free(xfs_bmbt_trace_buf);
184#endif
185#ifdef XFS_BMAP_TRACE
186 ktrace_free(xfs_bmap_trace_buf);
187#endif
188#ifdef XFS_ALLOC_TRACE
189 ktrace_free(xfs_alloc_trace_buf);
190#endif
191
Nathan Scott3758dee2006-03-22 12:47:28 +1100192 kmem_zone_destroy(xfs_bmap_free_item_zone);
193 kmem_zone_destroy(xfs_btree_cur_zone);
194 kmem_zone_destroy(xfs_inode_zone);
195 kmem_zone_destroy(xfs_trans_zone);
196 kmem_zone_destroy(xfs_da_state_zone);
197 kmem_zone_destroy(xfs_dabuf_zone);
198 kmem_zone_destroy(xfs_buf_item_zone);
199 kmem_zone_destroy(xfs_efd_zone);
200 kmem_zone_destroy(xfs_efi_zone);
201 kmem_zone_destroy(xfs_ifork_zone);
202 kmem_zone_destroy(xfs_ili_zone);
David Chinnerda353b02007-08-28 14:00:13 +1000203 kmem_zone_destroy(xfs_icluster_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204}
205
206/*
207 * xfs_start_flags
208 *
209 * This function fills in xfs_mount_t fields based on mount args.
210 * Note: the superblock has _not_ yet been read in.
211 */
212STATIC int
213xfs_start_flags(
Nathan Scottb83bd132006-06-09 16:48:30 +1000214 struct bhv_vfs *vfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 struct xfs_mount_args *ap,
216 struct xfs_mount *mp)
217{
218 /* Values are in BBs */
219 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
220 /*
221 * At this point the superblock has not been read
222 * in, therefore we do not know the block size.
223 * Before the mount call ends we will convert
224 * these to FSBs.
225 */
226 mp->m_dalign = ap->sunit;
227 mp->m_swidth = ap->swidth;
228 }
229
230 if (ap->logbufs != -1 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 ap->logbufs != 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 (ap->logbufs < XLOG_MIN_ICLOGS ||
233 ap->logbufs > XLOG_MAX_ICLOGS)) {
234 cmn_err(CE_WARN,
235 "XFS: invalid logbufs value: %d [not %d-%d]",
236 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
237 return XFS_ERROR(EINVAL);
238 }
239 mp->m_logbufs = ap->logbufs;
240 if (ap->logbufsize != -1 &&
Nathan Scottcfcbbbd2005-11-02 15:12:04 +1100241 ap->logbufsize != 0 &&
Eric Sandeendcb3b832007-08-16 16:25:33 +1000242 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
243 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
244 !is_power_of_2(ap->logbufsize))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 cmn_err(CE_WARN,
246 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
247 ap->logbufsize);
248 return XFS_ERROR(EINVAL);
249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 mp->m_logbsize = ap->logbufsize;
251 mp->m_fsname_len = strlen(ap->fsname) + 1;
252 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
253 strcpy(mp->m_fsname, ap->fsname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +1100254 if (ap->rtname[0]) {
255 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
256 strcpy(mp->m_rtname, ap->rtname);
257 }
258 if (ap->logname[0]) {
259 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
260 strcpy(mp->m_logname, ap->logname);
261 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 if (ap->flags & XFSMNT_WSYNC)
264 mp->m_flags |= XFS_MOUNT_WSYNC;
265#if XFS_BIG_INUMS
266 if (ap->flags & XFSMNT_INO64) {
267 mp->m_flags |= XFS_MOUNT_INO64;
268 mp->m_inoadd = XFS_INO64_OFFSET;
269 }
270#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 if (ap->flags & XFSMNT_RETERR)
272 mp->m_flags |= XFS_MOUNT_RETERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 if (ap->flags & XFSMNT_NOALIGN)
274 mp->m_flags |= XFS_MOUNT_NOALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 if (ap->flags & XFSMNT_SWALLOC)
276 mp->m_flags |= XFS_MOUNT_SWALLOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 if (ap->flags & XFSMNT_OSYNCISOSYNC)
278 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 if (ap->flags & XFSMNT_32BITINODES)
Nathan Scottc11e2c32005-11-02 15:11:45 +1100280 mp->m_flags |= XFS_MOUNT_32BITINODES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
282 if (ap->flags & XFSMNT_IOSIZE) {
283 if (ap->iosizelog > XFS_MAX_IO_LOG ||
284 ap->iosizelog < XFS_MIN_IO_LOG) {
285 cmn_err(CE_WARN,
286 "XFS: invalid log iosize: %d [not %d-%d]",
287 ap->iosizelog, XFS_MIN_IO_LOG,
288 XFS_MAX_IO_LOG);
289 return XFS_ERROR(EINVAL);
290 }
291
292 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
293 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
294 }
295
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 if (ap->flags & XFSMNT_IDELETE)
297 mp->m_flags |= XFS_MOUNT_IDELETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 if (ap->flags & XFSMNT_DIRSYNC)
299 mp->m_flags |= XFS_MOUNT_DIRSYNC;
Nathan Scott13059ff2006-01-11 15:32:01 +1100300 if (ap->flags & XFSMNT_ATTR2)
301 mp->m_flags |= XFS_MOUNT_ATTR2;
David Chinnere8c8b3a2005-11-02 10:33:05 +1100302
Nathan Scotte718eeb42005-11-02 15:09:22 +1100303 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
304 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 /*
307 * no recovery flag requires a read-only mount
308 */
309 if (ap->flags & XFSMNT_NORECOVERY) {
310 if (!(vfs->vfs_flag & VFS_RDONLY)) {
311 cmn_err(CE_WARN,
312 "XFS: tried to mount a FS read-write without recovery!");
313 return XFS_ERROR(EINVAL);
314 }
315 mp->m_flags |= XFS_MOUNT_NORECOVERY;
316 }
317
318 if (ap->flags & XFSMNT_NOUUID)
319 mp->m_flags |= XFS_MOUNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100320 if (ap->flags & XFSMNT_BARRIER)
321 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100322 else
323 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
David Chinner2a82b8b2007-07-11 11:09:12 +1000325 if (ap->flags2 & XFSMNT2_FILESTREAMS)
326 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
327
Christoph Hellwig293688e2007-08-29 11:59:36 +1000328 if (ap->flags & XFSMNT_DMAPI)
329 vfs->vfs_flag |= VFS_DMI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 return 0;
331}
332
333/*
334 * This function fills in xfs_mount_t fields based on mount args.
335 * Note: the superblock _has_ now been read in.
336 */
337STATIC int
338xfs_finish_flags(
Nathan Scottb83bd132006-06-09 16:48:30 +1000339 struct bhv_vfs *vfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 struct xfs_mount_args *ap,
341 struct xfs_mount *mp)
342{
343 int ronly = (vfs->vfs_flag & VFS_RDONLY);
344
345 /* Fail a mount where the logbuf is smaller then the log stripe */
346 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
Nathan Scottc2cd2552006-01-11 15:35:32 +1100347 if ((ap->logbufsize <= 0) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
349 mp->m_logbsize = mp->m_sb.sb_logsunit;
Nathan Scottc2cd2552006-01-11 15:35:32 +1100350 } else if (ap->logbufsize > 0 &&
351 ap->logbufsize < mp->m_sb.sb_logsunit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 cmn_err(CE_WARN,
353 "XFS: logbuf size must be greater than or equal to log stripe size");
354 return XFS_ERROR(EINVAL);
355 }
356 } else {
357 /* Fail a mount if the logbuf is larger than 32K */
358 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
359 cmn_err(CE_WARN,
360 "XFS: logbuf size for version 1 logs must be 16K or 32K");
361 return XFS_ERROR(EINVAL);
362 }
363 }
364
Nathan Scott13059ff2006-01-11 15:32:01 +1100365 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
366 mp->m_flags |= XFS_MOUNT_ATTR2;
367 }
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 /*
370 * prohibit r/w mounts of read-only filesystems
371 */
372 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
373 cmn_err(CE_WARN,
374 "XFS: cannot mount a read-only filesystem as read-write");
375 return XFS_ERROR(EROFS);
376 }
377
378 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 * check for shared mount.
380 */
381 if (ap->flags & XFSMNT_SHARED) {
382 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
383 return XFS_ERROR(EINVAL);
384
385 /*
386 * For IRIX 6.5, shared mounts must have the shared
387 * version bit set, have the persistent readonly
388 * field set, must be version 0 and can only be mounted
389 * read-only.
390 */
391 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
392 (mp->m_sb.sb_shared_vn != 0))
393 return XFS_ERROR(EINVAL);
394
395 mp->m_flags |= XFS_MOUNT_SHARED;
396
397 /*
398 * Shared XFS V0 can't deal with DMI. Return EINVAL.
399 */
400 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
401 return XFS_ERROR(EINVAL);
402 }
403
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000404 if (ap->flags & XFSMNT_UQUOTA) {
405 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
406 if (ap->flags & XFSMNT_UQUOTAENF)
407 mp->m_qflags |= XFS_UQUOTA_ENFD;
408 }
409
410 if (ap->flags & XFSMNT_GQUOTA) {
411 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
412 if (ap->flags & XFSMNT_GQUOTAENF)
413 mp->m_qflags |= XFS_OQUOTA_ENFD;
414 } else if (ap->flags & XFSMNT_PQUOTA) {
415 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
416 if (ap->flags & XFSMNT_PQUOTAENF)
417 mp->m_qflags |= XFS_OQUOTA_ENFD;
418 }
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return 0;
421}
422
423/*
424 * xfs_mount
425 *
426 * The file system configurations are:
427 * (1) device (partition) with data and internal log
428 * (2) logical volume with data and log subvolumes.
429 * (3) logical volume with data, log, and realtime subvolumes.
430 *
431 * We only have to handle opening the log and realtime volumes here if
432 * they are present. The data subvolume has already been opened by
433 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
434 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000435int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436xfs_mount(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000437 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 struct xfs_mount_args *args,
439 cred_t *credp)
440{
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000441 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 struct bhv_desc *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 struct block_device *ddev, *logdev, *rtdev;
444 int flags = 0, error;
445
446 ddev = vfsp->vfs_super->s_bdev;
447 logdev = rtdev = NULL;
448
Christoph Hellwig293688e2007-08-29 11:59:36 +1000449 error = xfs_dmops_get(mp, args);
450 if (error)
451 return error;
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000452 error = xfs_qmops_get(mp, args);
453 if (error)
454 return error;
Christoph Hellwig293688e2007-08-29 11:59:36 +1000455
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 /*
457 * Setup xfs_mount function vectors from available behaviors
458 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
460 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
461
Nathan Scott764d1f82006-03-31 13:04:17 +1000462 if (args->flags & XFSMNT_QUIET)
463 flags |= XFS_MFSI_QUIET;
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 /*
466 * Open real time and log devices - order is important.
467 */
468 if (args->logname[0]) {
469 error = xfs_blkdev_get(mp, args->logname, &logdev);
470 if (error)
471 return error;
472 }
473 if (args->rtname[0]) {
474 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
475 if (error) {
476 xfs_blkdev_put(logdev);
477 return error;
478 }
479
480 if (rtdev == ddev || rtdev == logdev) {
481 cmn_err(CE_WARN,
482 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
483 xfs_blkdev_put(logdev);
484 xfs_blkdev_put(rtdev);
485 return EINVAL;
486 }
487 }
488
489 /*
490 * Setup xfs_mount buffer target pointers
491 */
492 error = ENOMEM;
493 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
494 if (!mp->m_ddev_targp) {
495 xfs_blkdev_put(logdev);
496 xfs_blkdev_put(rtdev);
497 return error;
498 }
499 if (rtdev) {
500 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000501 if (!mp->m_rtdev_targp) {
502 xfs_blkdev_put(logdev);
503 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000505 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507 mp->m_logdev_targp = (logdev && logdev != ddev) ?
508 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000509 if (!mp->m_logdev_targp) {
510 xfs_blkdev_put(logdev);
511 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 /*
516 * Setup flags based on mount(2) options and then the superblock
517 */
518 error = xfs_start_flags(vfsp, args, mp);
519 if (error)
520 goto error1;
Nathan Scott764d1f82006-03-31 13:04:17 +1000521 error = xfs_readsb(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 if (error)
523 goto error1;
524 error = xfs_finish_flags(vfsp, args, mp);
525 if (error)
526 goto error2;
527
528 /*
529 * Setup xfs_mount buffer target pointers based on superblock
530 */
531 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
532 mp->m_sb.sb_sectsize);
533 if (!error && logdev && logdev != ddev) {
534 unsigned int log_sector_size = BBSIZE;
535
536 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
537 log_sector_size = mp->m_sb.sb_logsectsize;
538 error = xfs_setsize_buftarg(mp->m_logdev_targp,
539 mp->m_sb.sb_blocksize,
540 log_sector_size);
541 }
542 if (!error && rtdev)
543 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
544 mp->m_sb.sb_blocksize,
545 mp->m_sb.sb_sectsize);
546 if (error)
547 goto error2;
548
Nathan Scottb2ea4012006-07-28 17:05:13 +1000549 if (mp->m_flags & XFS_MOUNT_BARRIER)
Christoph Hellwigc7d437d2006-01-11 15:28:56 +1100550 xfs_mountfs_check_barriers(mp);
551
David Chinner2a82b8b2007-07-11 11:09:12 +1000552 if ((error = xfs_filestream_mount(mp)))
553 goto error2;
554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 error = XFS_IOINIT(vfsp, args, flags);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100556 if (error)
557 goto error2;
558
Christoph Hellwig293688e2007-08-29 11:59:36 +1000559 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
560
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100561 return 0;
562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563error2:
564 if (mp->m_sb_bp)
565 xfs_freesb(mp);
566error1:
567 xfs_binval(mp->m_ddev_targp);
568 if (logdev && logdev != ddev)
569 xfs_binval(mp->m_logdev_targp);
570 if (rtdev)
571 xfs_binval(mp->m_rtdev_targp);
572error0:
573 xfs_unmountfs_close(mp, credp);
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000574 xfs_qmops_put(mp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000575 xfs_dmops_put(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 return error;
577}
578
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000579int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580xfs_unmount(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000581 xfs_mount_t *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 int flags,
583 cred_t *credp)
584{
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000585 bhv_vfs_t *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 xfs_inode_t *rip;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000587 bhv_vnode_t *rvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 int unmount_event_wanted = 0;
589 int unmount_event_flags = 0;
590 int xfs_unmountfs_needed = 0;
591 int error;
592
593 rip = mp->m_rootip;
594 rvp = XFS_ITOV(rip);
595
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000596#ifdef HAVE_DMAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 if (vfsp->vfs_flag & VFS_DMI) {
598 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
599 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
600 NULL, NULL, 0, 0,
601 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
602 0:DM_FLAGS_UNWANTED);
603 if (error)
604 return XFS_ERROR(error);
605 unmount_event_wanted = 1;
606 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
607 0 : DM_FLAGS_UNWANTED;
608 }
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000609#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 /*
611 * First blow any referenced inode from this file system
612 * out of the reference cache, and delete the timer.
613 */
614 xfs_refcache_purge_mp(mp);
615
David Chinner2a82b8b2007-07-11 11:09:12 +1000616 /*
617 * Blow away any referenced inode in the filestreams cache.
618 * This can and will cause log traffic as inodes go inactive
619 * here.
620 */
621 xfs_filestream_unmount(mp);
622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 XFS_bflush(mp->m_ddev_targp);
624 error = xfs_unmount_flush(mp, 0);
625 if (error)
626 goto out;
627
628 ASSERT(vn_count(rvp) == 1);
629
630 /*
631 * Drop the reference count
632 */
633 VN_RELE(rvp);
634
635 /*
636 * If we're forcing a shutdown, typically because of a media error,
637 * we want to make sure we invalidate dirty pages that belong to
638 * referenced vnodes as well.
639 */
640 if (XFS_FORCED_SHUTDOWN(mp)) {
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000641 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 ASSERT(error != EFSCORRUPTED);
643 }
644 xfs_unmountfs_needed = 1;
645
646out:
647 /* Send DMAPI event, if required.
648 * Then do xfs_unmountfs() if needed.
649 * Then return error (or zero).
650 */
651 if (unmount_event_wanted) {
652 /* Note: mp structure must still exist for
653 * XFS_SEND_UNMOUNT() call.
654 */
655 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
656 DM_RIGHT_NULL, 0, error, unmount_event_flags);
657 }
658 if (xfs_unmountfs_needed) {
659 /*
660 * Call common unmount function to flush to disk
661 * and free the super block buffer & mount structures.
662 */
663 xfs_unmountfs(mp, credp);
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000664 xfs_qmops_put(mp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000665 xfs_dmops_put(mp);
Christoph Hellwigf541d272007-08-29 11:53:22 +1000666 kmem_free(mp, sizeof(xfs_mount_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
668
669 return XFS_ERROR(error);
670}
671
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000672STATIC int
673xfs_quiesce_fs(
674 xfs_mount_t *mp)
675{
676 int count = 0, pincount;
Nathan Scott3758dee2006-03-22 12:47:28 +1100677
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000678 xfs_refcache_purge_mp(mp);
679 xfs_flush_buftarg(mp->m_ddev_targp, 0);
680 xfs_finish_reclaim_all(mp, 0);
681
682 /* This loop must run at least twice.
683 * The first instance of the loop will flush
684 * most meta data but that will generate more
685 * meta data (typically directory updates).
686 * Which then must be flushed and logged before
687 * we can write the unmount record.
Nathan Scott3758dee2006-03-22 12:47:28 +1100688 */
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000689 do {
David Chinner516b2e72007-06-18 16:50:48 +1000690 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000691 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
692 if (!pincount) {
693 delay(50);
694 count++;
695 }
696 } while (count < 2);
697
698 return 0;
699}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
David Chinner516b2e72007-06-18 16:50:48 +1000701/*
702 * Second stage of a quiesce. The data is already synced, now we have to take
703 * care of the metadata. New transactions are already blocked, so we need to
704 * wait for any remaining transactions to drain out before proceding.
705 */
706STATIC void
707xfs_attr_quiesce(
708 xfs_mount_t *mp)
709{
710 /* wait for all modifications to complete */
711 while (atomic_read(&mp->m_active_trans) > 0)
712 delay(100);
713
714 /* flush inodes and push all remaining buffers out to disk */
715 xfs_quiesce_fs(mp);
716
717 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
718
719 /* Push the superblock and write an unmount record */
720 xfs_log_sbcount(mp, 1);
721 xfs_log_unmount_write(mp);
722 xfs_unmountfs_writesb(mp);
723}
724
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000725int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726xfs_mntupdate(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000727 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 int *flags,
729 struct xfs_mount_args *args)
730{
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000731 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
Nathan Scottd08d3892006-05-08 19:51:28 +1000733 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
734 if (vfsp->vfs_flag & VFS_RDONLY)
735 vfsp->vfs_flag &= ~VFS_RDONLY;
736 if (args->flags & XFSMNT_BARRIER) {
737 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100738 xfs_mountfs_check_barriers(mp);
Nathan Scottd08d3892006-05-08 19:51:28 +1000739 } else {
740 mp->m_flags &= ~XFS_MOUNT_BARRIER;
741 }
742 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
David Chinner2a82b8b2007-07-11 11:09:12 +1000743 xfs_filestream_flush(mp);
David Chinner516b2e72007-06-18 16:50:48 +1000744 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
745 xfs_attr_quiesce(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 vfsp->vfs_flag |= VFS_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 return 0;
749}
750
751/*
752 * xfs_unmount_flush implements a set of flush operation on special
753 * inodes, which are needed as a separate set of operations so that
754 * they can be called as part of relocation process.
755 */
756int
757xfs_unmount_flush(
758 xfs_mount_t *mp, /* Mount structure we are getting
759 rid of. */
760 int relocation) /* Called from vfs relocation. */
761{
762 xfs_inode_t *rip = mp->m_rootip;
763 xfs_inode_t *rbmip;
764 xfs_inode_t *rsumip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000765 bhv_vnode_t *rvp = XFS_ITOV(rip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 int error;
767
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000768 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 xfs_iflock(rip);
770
771 /*
772 * Flush out the real time inodes.
773 */
774 if ((rbmip = mp->m_rbmip) != NULL) {
775 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
776 xfs_iflock(rbmip);
777 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
778 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
779
780 if (error == EFSCORRUPTED)
781 goto fscorrupt_out;
782
783 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
784
785 rsumip = mp->m_rsumip;
786 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
787 xfs_iflock(rsumip);
788 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
789 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
790
791 if (error == EFSCORRUPTED)
792 goto fscorrupt_out;
793
794 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
795 }
796
797 /*
798 * Synchronously flush root inode to disk
799 */
800 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
801 if (error == EFSCORRUPTED)
802 goto fscorrupt_out2;
803
804 if (vn_count(rvp) != 1 && !relocation) {
805 xfs_iunlock(rip, XFS_ILOCK_EXCL);
806 return XFS_ERROR(EBUSY);
807 }
808
809 /*
810 * Release dquot that rootinode, rbmino and rsumino might be holding,
811 * flush and purge the quota inodes.
812 */
813 error = XFS_QM_UNMOUNT(mp);
814 if (error == EFSCORRUPTED)
815 goto fscorrupt_out2;
816
817 if (rbmip) {
818 VN_RELE(XFS_ITOV(rbmip));
819 VN_RELE(XFS_ITOV(rsumip));
820 }
821
822 xfs_iunlock(rip, XFS_ILOCK_EXCL);
823 return 0;
824
825fscorrupt_out:
826 xfs_ifunlock(rip);
827
828fscorrupt_out2:
829 xfs_iunlock(rip, XFS_ILOCK_EXCL);
830
831 return XFS_ERROR(EFSCORRUPTED);
832}
833
834/*
835 * xfs_root extracts the root vnode from a vfs.
836 *
837 * vfsp -- the vfs struct for the desired file system
838 * vpp -- address of the caller's vnode pointer which should be
839 * set to the desired fs root vnode
840 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000841int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842xfs_root(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000843 xfs_mount_t *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000844 bhv_vnode_t **vpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000846 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000848 vp = XFS_ITOV(mp->m_rootip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 VN_HOLD(vp);
850 *vpp = vp;
851 return 0;
852}
853
854/*
855 * xfs_statvfs
856 *
857 * Fill in the statvfs structure for the given file system. We use
858 * the superblock lock in the mount structure to ensure a consistent
859 * snapshot of the counters returned.
860 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000861int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862xfs_statvfs(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000863 xfs_mount_t *mp,
Nathan Scott8285fb52006-06-09 17:07:12 +1000864 bhv_statvfs_t *statp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000865 bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866{
867 __uint64_t fakeinos;
868 xfs_extlen_t lsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 xfs_sb_t *sbp;
870 unsigned long s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 sbp = &(mp->m_sb);
873
874 statp->f_type = XFS_SB_MAGIC;
875
David Chinnerdbcabad2007-02-10 18:36:17 +1100876 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 s = XFS_SB_LOCK(mp);
878 statp->f_bsize = sbp->sb_blocksize;
879 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
880 statp->f_blocks = sbp->sb_dblocks - lsize;
David Chinner4be536d2006-09-07 14:26:50 +1000881 statp->f_bfree = statp->f_bavail =
882 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 fakeinos = statp->f_bfree << sbp->sb_inopblog;
884#if XFS_BIG_INUMS
885 fakeinos += mp->m_inoadd;
886#endif
887 statp->f_files =
888 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
889 if (mp->m_maxicount)
890#if XFS_BIG_INUMS
891 if (!mp->m_inoadd)
892#endif
893 statp->f_files = min_t(typeof(statp->f_files),
894 statp->f_files,
895 mp->m_maxicount);
896 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
897 XFS_SB_UNLOCK(mp, s);
898
Nathan Scottcde410a2005-09-05 11:47:01 +1000899 xfs_statvfs_fsid(statp, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 statp->f_namelen = MAXNAMELEN - 1;
901
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000902 if (vp)
903 XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 return 0;
905}
906
907
908/*
909 * xfs_sync flushes any pending I/O to file system vfsp.
910 *
911 * This routine is called by vfs_sync() to make sure that things make it
912 * out to disk eventually, on sync() system calls to flush out everything,
913 * and when the file system is unmounted. For the vfs_sync() case, all
914 * we really need to do is sync out the log to make all of our meta-data
915 * updates permanent (except for timestamps). For calls from pflushd(),
916 * dirty pages are kept moving by calling pdflush() on the inodes
917 * containing them. We also flush the inodes that we can lock without
918 * sleeping and the superblock if we can lock it without sleeping from
919 * vfs_sync() so that items at the tail of the log are always moving out.
920 *
921 * Flags:
922 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
923 * to sleep if we can help it. All we really need
924 * to do is ensure that the log is synced at least
925 * periodically. We also push the inodes and
926 * superblock if we can lock them without sleeping
927 * and they are not pinned.
928 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
929 * set, then we really want to lock each inode and flush
930 * it.
931 * SYNC_WAIT - All the flushes that take place in this call should
932 * be synchronous.
933 * SYNC_DELWRI - This tells us to push dirty pages associated with
934 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
935 * determine if they should be flushed sync, async, or
936 * delwri.
937 * SYNC_CLOSE - This flag is passed when the system is being
Nathan Scottc41564b2006-03-29 08:55:14 +1000938 * unmounted. We should sync and invalidate everything.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 * SYNC_FSDATA - This indicates that the caller would like to make
940 * sure the superblock is safe on disk. We can ensure
Nathan Scottc41564b2006-03-29 08:55:14 +1000941 * this by simply making sure the log gets flushed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 * if SYNC_BDFLUSH is set, and by actually writing it
943 * out otherwise.
David Chinner3c0dc772007-02-10 18:37:22 +1100944 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
945 * before we return (including direct I/O). Forms the drain
946 * side of the write barrier needed to safely quiesce the
947 * filesystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 *
949 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000950int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951xfs_sync(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000952 xfs_mount_t *mp,
953 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000955 int error;
956
957 /*
958 * Get the Quota Manager to flush the dquots.
959 *
960 * If XFS quota support is not enabled or this filesystem
961 * instance does not use quotas XFS_QM_DQSYNC will always
962 * return zero.
963 */
964 error = XFS_QM_DQSYNC(mp, flags);
965 if (error) {
966 /*
967 * If we got an IO error, we will be shutting down.
968 * So, there's nothing more for us to do here.
969 */
970 ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
971 if (XFS_FORCED_SHUTDOWN(mp))
972 return XFS_ERROR(error);
973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
David Chinner2a82b8b2007-07-11 11:09:12 +1000975 if (flags & SYNC_IOWAIT)
976 xfs_filestream_flush(mp);
977
David Chinner28239452007-02-10 18:36:40 +1100978 return xfs_syncsub(mp, flags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979}
980
981/*
982 * xfs sync routine for internal use
983 *
Nathan Scottb83bd132006-06-09 16:48:30 +1000984 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +1100985 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 *
987 */
Nathan Scottee348072005-11-02 10:32:38 +1100988int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989xfs_sync_inodes(
990 xfs_mount_t *mp,
991 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 int *bypassed)
993{
994 xfs_inode_t *ip = NULL;
995 xfs_inode_t *ip_next;
996 xfs_buf_t *bp;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000997 bhv_vnode_t *vp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 int error;
999 int last_error;
1000 uint64_t fflag;
1001 uint lock_flags;
1002 uint base_lock_flags;
1003 boolean_t mount_locked;
1004 boolean_t vnode_refed;
1005 int preempt;
1006 xfs_dinode_t *dip;
1007 xfs_iptr_t *ipointer;
1008#ifdef DEBUG
1009 boolean_t ipointer_in = B_FALSE;
1010
1011#define IPOINTER_SET ipointer_in = B_TRUE
1012#define IPOINTER_CLR ipointer_in = B_FALSE
1013#else
1014#define IPOINTER_SET
1015#define IPOINTER_CLR
1016#endif
1017
1018
1019/* Insert a marker record into the inode list after inode ip. The list
1020 * must be locked when this is called. After the call the list will no
1021 * longer be locked.
1022 */
1023#define IPOINTER_INSERT(ip, mp) { \
1024 ASSERT(ipointer_in == B_FALSE); \
1025 ipointer->ip_mnext = ip->i_mnext; \
1026 ipointer->ip_mprev = ip; \
1027 ip->i_mnext = (xfs_inode_t *)ipointer; \
1028 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
1029 preempt = 0; \
1030 XFS_MOUNT_IUNLOCK(mp); \
1031 mount_locked = B_FALSE; \
1032 IPOINTER_SET; \
1033 }
1034
1035/* Remove the marker from the inode list. If the marker was the only item
1036 * in the list then there are no remaining inodes and we should zero out
1037 * the whole list. If we are the current head of the list then move the head
1038 * past us.
1039 */
1040#define IPOINTER_REMOVE(ip, mp) { \
1041 ASSERT(ipointer_in == B_TRUE); \
1042 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1043 ip = ipointer->ip_mnext; \
1044 ip->i_mprev = ipointer->ip_mprev; \
1045 ipointer->ip_mprev->i_mnext = ip; \
1046 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1047 mp->m_inodes = ip; \
1048 } \
1049 } else { \
1050 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1051 mp->m_inodes = NULL; \
1052 ip = NULL; \
1053 } \
1054 IPOINTER_CLR; \
1055 }
1056
1057#define XFS_PREEMPT_MASK 0x7f
1058
1059 if (bypassed)
1060 *bypassed = 0;
1061 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1062 return 0;
1063 error = 0;
1064 last_error = 0;
1065 preempt = 0;
1066
1067 /* Allocate a reference marker */
1068 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1069
1070 fflag = XFS_B_ASYNC; /* default is don't wait */
Nathan Scottee348072005-11-02 10:32:38 +11001071 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 fflag = XFS_B_DELWRI;
1073 if (flags & SYNC_WAIT)
1074 fflag = 0; /* synchronous overrides all */
1075
1076 base_lock_flags = XFS_ILOCK_SHARED;
1077 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1078 /*
1079 * We need the I/O lock if we're going to call any of
1080 * the flush/inval routines.
1081 */
1082 base_lock_flags |= XFS_IOLOCK_SHARED;
1083 }
1084
1085 XFS_MOUNT_ILOCK(mp);
1086
1087 ip = mp->m_inodes;
1088
1089 mount_locked = B_TRUE;
1090 vnode_refed = B_FALSE;
1091
1092 IPOINTER_CLR;
1093
1094 do {
1095 ASSERT(ipointer_in == B_FALSE);
1096 ASSERT(vnode_refed == B_FALSE);
1097
1098 lock_flags = base_lock_flags;
1099
1100 /*
1101 * There were no inodes in the list, just break out
1102 * of the loop.
1103 */
1104 if (ip == NULL) {
1105 break;
1106 }
1107
1108 /*
1109 * We found another sync thread marker - skip it
1110 */
1111 if (ip->i_mount == NULL) {
1112 ip = ip->i_mnext;
1113 continue;
1114 }
1115
1116 vp = XFS_ITOV_NULL(ip);
1117
1118 /*
1119 * If the vnode is gone then this is being torn down,
1120 * call reclaim if it is flushed, else let regular flush
1121 * code deal with it later in the loop.
1122 */
1123
1124 if (vp == NULL) {
1125 /* Skip ones already in reclaim */
1126 if (ip->i_flags & XFS_IRECLAIM) {
1127 ip = ip->i_mnext;
1128 continue;
1129 }
1130 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1131 ip = ip->i_mnext;
1132 } else if ((xfs_ipincount(ip) == 0) &&
1133 xfs_iflock_nowait(ip)) {
1134 IPOINTER_INSERT(ip, mp);
1135
1136 xfs_finish_reclaim(ip, 1,
1137 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1138
1139 XFS_MOUNT_ILOCK(mp);
1140 mount_locked = B_TRUE;
1141 IPOINTER_REMOVE(ip, mp);
1142 } else {
1143 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1144 ip = ip->i_mnext;
1145 }
1146 continue;
1147 }
1148
1149 if (VN_BAD(vp)) {
1150 ip = ip->i_mnext;
1151 continue;
1152 }
1153
1154 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1155 XFS_MOUNT_IUNLOCK(mp);
1156 kmem_free(ipointer, sizeof(xfs_iptr_t));
1157 return 0;
1158 }
1159
1160 /*
1161 * If this is just vfs_sync() or pflushd() calling
1162 * then we can skip inodes for which it looks like
1163 * there is nothing to do. Since we don't have the
Nathan Scottc41564b2006-03-29 08:55:14 +10001164 * inode locked this is racy, but these are periodic
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 * calls so it doesn't matter. For the others we want
1166 * to know for sure, so we at least try to lock them.
1167 */
1168 if (flags & SYNC_BDFLUSH) {
1169 if (((ip->i_itemp == NULL) ||
1170 !(ip->i_itemp->ili_format.ilf_fields &
1171 XFS_ILOG_ALL)) &&
1172 (ip->i_update_core == 0)) {
1173 ip = ip->i_mnext;
1174 continue;
1175 }
1176 }
1177
1178 /*
1179 * Try to lock without sleeping. We're out of order with
1180 * the inode list lock here, so if we fail we need to drop
1181 * the mount lock and try again. If we're called from
1182 * bdflush() here, then don't bother.
1183 *
1184 * The inode lock here actually coordinates with the
1185 * almost spurious inode lock in xfs_ireclaim() to prevent
1186 * the vnode we handle here without a reference from
1187 * being freed while we reference it. If we lock the inode
1188 * while it's on the mount list here, then the spurious inode
1189 * lock in xfs_ireclaim() after the inode is pulled from
1190 * the mount list will sleep until we release it here.
1191 * This keeps the vnode from being freed while we reference
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001192 * it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 */
1194 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1196 ip = ip->i_mnext;
1197 continue;
1198 }
1199
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001200 vp = vn_grab(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 if (vp == NULL) {
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001202 ip = ip->i_mnext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 continue;
1204 }
1205
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001206 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 xfs_ilock(ip, lock_flags);
1208
1209 ASSERT(vp == XFS_ITOV(ip));
1210 ASSERT(ip->i_mount == mp);
1211
1212 vnode_refed = B_TRUE;
1213 }
1214
1215 /* From here on in the loop we may have a marker record
1216 * in the inode list.
1217 */
1218
David Chinner40095b62007-05-14 18:24:09 +10001219 /*
1220 * If we have to flush data or wait for I/O completion
1221 * we need to drop the ilock that we currently hold.
1222 * If we need to drop the lock, insert a marker if we
1223 * have not already done so.
1224 */
1225 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1226 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1227 if (mount_locked) {
1228 IPOINTER_INSERT(ip, mp);
1229 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1231
David Chinner40095b62007-05-14 18:24:09 +10001232 if (flags & SYNC_CLOSE) {
1233 /* Shutdown case. Flush and invalidate. */
1234 if (XFS_FORCED_SHUTDOWN(mp))
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001235 xfs_tosspages(ip, 0, -1,
1236 FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001237 else
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001238 error = xfs_flushinval_pages(ip,
1239 0, -1, FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001240 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001241 error = xfs_flush_pages(ip, 0,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001242 -1, fflag, FI_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 }
1244
David Chinner40095b62007-05-14 18:24:09 +10001245 /*
1246 * When freezing, we need to wait ensure all I/O (including direct
1247 * I/O) is complete to ensure no further data modification can take
1248 * place after this point
1249 */
1250 if (flags & SYNC_IOWAIT)
Christoph Hellwigb677c212007-08-29 11:46:28 +10001251 vn_iowait(ip);
David Chinner40095b62007-05-14 18:24:09 +10001252
1253 xfs_ilock(ip, XFS_ILOCK_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 }
1255
1256 if (flags & SYNC_BDFLUSH) {
1257 if ((flags & SYNC_ATTR) &&
1258 ((ip->i_update_core) ||
1259 ((ip->i_itemp != NULL) &&
1260 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1261
1262 /* Insert marker and drop lock if not already
1263 * done.
1264 */
1265 if (mount_locked) {
1266 IPOINTER_INSERT(ip, mp);
1267 }
1268
1269 /*
1270 * We don't want the periodic flushing of the
1271 * inodes by vfs_sync() to interfere with
1272 * I/O to the file, especially read I/O
1273 * where it is only the access time stamp
1274 * that is being flushed out. To prevent
1275 * long periods where we have both inode
1276 * locks held shared here while reading the
1277 * inode's buffer in from disk, we drop the
1278 * inode lock while reading in the inode
1279 * buffer. We have to release the buffer
1280 * and reacquire the inode lock so that they
1281 * are acquired in the proper order (inode
1282 * locks first). The buffer will go at the
1283 * end of the lru chain, though, so we can
1284 * expect it to still be there when we go
1285 * for it again in xfs_iflush().
1286 */
1287 if ((xfs_ipincount(ip) == 0) &&
1288 xfs_iflock_nowait(ip)) {
1289
1290 xfs_ifunlock(ip);
1291 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1292
1293 error = xfs_itobp(mp, NULL, ip,
Nathan Scottb12dd342006-03-17 17:26:04 +11001294 &dip, &bp, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 if (!error) {
1296 xfs_buf_relse(bp);
1297 } else {
1298 /* Bailing out, remove the
1299 * marker and free it.
1300 */
1301 XFS_MOUNT_ILOCK(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 IPOINTER_REMOVE(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 XFS_MOUNT_IUNLOCK(mp);
1304
1305 ASSERT(!(lock_flags &
1306 XFS_IOLOCK_SHARED));
1307
1308 kmem_free(ipointer,
1309 sizeof(xfs_iptr_t));
1310 return (0);
1311 }
1312
1313 /*
1314 * Since we dropped the inode lock,
1315 * the inode may have been reclaimed.
1316 * Therefore, we reacquire the mount
1317 * lock and check to see if we were the
1318 * inode reclaimed. If this happened
1319 * then the ipointer marker will no
1320 * longer point back at us. In this
1321 * case, move ip along to the inode
1322 * after the marker, remove the marker
1323 * and continue.
1324 */
1325 XFS_MOUNT_ILOCK(mp);
1326 mount_locked = B_TRUE;
1327
1328 if (ip != ipointer->ip_mprev) {
1329 IPOINTER_REMOVE(ip, mp);
1330
1331 ASSERT(!vnode_refed);
1332 ASSERT(!(lock_flags &
1333 XFS_IOLOCK_SHARED));
1334 continue;
1335 }
1336
1337 ASSERT(ip->i_mount == mp);
1338
1339 if (xfs_ilock_nowait(ip,
1340 XFS_ILOCK_SHARED) == 0) {
1341 ASSERT(ip->i_mount == mp);
1342 /*
1343 * We failed to reacquire
1344 * the inode lock without
1345 * sleeping, so just skip
1346 * the inode for now. We
1347 * clear the ILOCK bit from
1348 * the lock_flags so that we
1349 * won't try to drop a lock
1350 * we don't hold below.
1351 */
1352 lock_flags &= ~XFS_ILOCK_SHARED;
1353 IPOINTER_REMOVE(ip_next, mp);
1354 } else if ((xfs_ipincount(ip) == 0) &&
1355 xfs_iflock_nowait(ip)) {
1356 ASSERT(ip->i_mount == mp);
1357 /*
1358 * Since this is vfs_sync()
1359 * calling we only flush the
1360 * inode out if we can lock
1361 * it without sleeping and
1362 * it is not pinned. Drop
1363 * the mount lock here so
1364 * that we don't hold it for
1365 * too long. We already have
1366 * a marker in the list here.
1367 */
1368 XFS_MOUNT_IUNLOCK(mp);
1369 mount_locked = B_FALSE;
1370 error = xfs_iflush(ip,
1371 XFS_IFLUSH_DELWRI);
1372 } else {
1373 ASSERT(ip->i_mount == mp);
1374 IPOINTER_REMOVE(ip_next, mp);
1375 }
1376 }
1377
1378 }
1379
1380 } else {
1381 if ((flags & SYNC_ATTR) &&
1382 ((ip->i_update_core) ||
1383 ((ip->i_itemp != NULL) &&
1384 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1385 if (mount_locked) {
1386 IPOINTER_INSERT(ip, mp);
1387 }
1388
1389 if (flags & SYNC_WAIT) {
1390 xfs_iflock(ip);
1391 error = xfs_iflush(ip,
1392 XFS_IFLUSH_SYNC);
1393 } else {
1394 /*
1395 * If we can't acquire the flush
1396 * lock, then the inode is already
1397 * being flushed so don't bother
1398 * waiting. If we can lock it then
1399 * do a delwri flush so we can
1400 * combine multiple inode flushes
1401 * in each disk write.
1402 */
1403 if (xfs_iflock_nowait(ip)) {
1404 error = xfs_iflush(ip,
1405 XFS_IFLUSH_DELWRI);
1406 }
1407 else if (bypassed)
1408 (*bypassed)++;
1409 }
1410 }
1411 }
1412
1413 if (lock_flags != 0) {
1414 xfs_iunlock(ip, lock_flags);
1415 }
1416
1417 if (vnode_refed) {
1418 /*
1419 * If we had to take a reference on the vnode
1420 * above, then wait until after we've unlocked
1421 * the inode to release the reference. This is
1422 * because we can be already holding the inode
1423 * lock when VN_RELE() calls xfs_inactive().
1424 *
1425 * Make sure to drop the mount lock before calling
1426 * VN_RELE() so that we don't trip over ourselves if
1427 * we have to go for the mount lock again in the
1428 * inactive code.
1429 */
1430 if (mount_locked) {
1431 IPOINTER_INSERT(ip, mp);
1432 }
1433
1434 VN_RELE(vp);
1435
1436 vnode_refed = B_FALSE;
1437 }
1438
1439 if (error) {
1440 last_error = error;
1441 }
1442
1443 /*
1444 * bail out if the filesystem is corrupted.
1445 */
1446 if (error == EFSCORRUPTED) {
1447 if (!mount_locked) {
1448 XFS_MOUNT_ILOCK(mp);
1449 IPOINTER_REMOVE(ip, mp);
1450 }
1451 XFS_MOUNT_IUNLOCK(mp);
1452 ASSERT(ipointer_in == B_FALSE);
1453 kmem_free(ipointer, sizeof(xfs_iptr_t));
1454 return XFS_ERROR(error);
1455 }
1456
1457 /* Let other threads have a chance at the mount lock
1458 * if we have looped many times without dropping the
1459 * lock.
1460 */
1461 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1462 if (mount_locked) {
1463 IPOINTER_INSERT(ip, mp);
1464 }
1465 }
1466
1467 if (mount_locked == B_FALSE) {
1468 XFS_MOUNT_ILOCK(mp);
1469 mount_locked = B_TRUE;
1470 IPOINTER_REMOVE(ip, mp);
1471 continue;
1472 }
1473
1474 ASSERT(ipointer_in == B_FALSE);
1475 ip = ip->i_mnext;
1476
1477 } while (ip != mp->m_inodes);
1478
1479 XFS_MOUNT_IUNLOCK(mp);
1480
1481 ASSERT(ipointer_in == B_FALSE);
1482
1483 kmem_free(ipointer, sizeof(xfs_iptr_t));
1484 return XFS_ERROR(last_error);
1485}
1486
1487/*
1488 * xfs sync routine for internal use
1489 *
Nathan Scottb83bd132006-06-09 16:48:30 +10001490 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001491 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 *
1493 */
1494int
1495xfs_syncsub(
1496 xfs_mount_t *mp,
1497 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 int *bypassed)
1499{
1500 int error = 0;
1501 int last_error = 0;
1502 uint log_flags = XFS_LOG_FORCE;
1503 xfs_buf_t *bp;
1504 xfs_buf_log_item_t *bip;
1505
1506 /*
1507 * Sync out the log. This ensures that the log is periodically
1508 * flushed even if there is not enough activity to fill it up.
1509 */
1510 if (flags & SYNC_WAIT)
1511 log_flags |= XFS_LOG_SYNC;
1512
1513 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1514
1515 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1516 if (flags & SYNC_BDFLUSH)
1517 xfs_finish_reclaim_all(mp, 1);
1518 else
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001519 error = xfs_sync_inodes(mp, flags, bypassed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
1521
1522 /*
1523 * Flushing out dirty data above probably generated more
1524 * log activity, so if this isn't vfs_sync() then flush
1525 * the log again.
1526 */
1527 if (flags & SYNC_DELWRI) {
1528 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1529 }
1530
1531 if (flags & SYNC_FSDATA) {
1532 /*
1533 * If this is vfs_sync() then only sync the superblock
1534 * if we can lock it without sleeping and it is not pinned.
1535 */
1536 if (flags & SYNC_BDFLUSH) {
1537 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1538 if (bp != NULL) {
1539 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1540 if ((bip != NULL) &&
1541 xfs_buf_item_dirty(bip)) {
1542 if (!(XFS_BUF_ISPINNED(bp))) {
1543 XFS_BUF_ASYNC(bp);
1544 error = xfs_bwrite(mp, bp);
1545 } else {
1546 xfs_buf_relse(bp);
1547 }
1548 } else {
1549 xfs_buf_relse(bp);
1550 }
1551 }
1552 } else {
1553 bp = xfs_getsb(mp, 0);
1554 /*
1555 * If the buffer is pinned then push on the log so
1556 * we won't get stuck waiting in the write for
1557 * someone, maybe ourselves, to flush the log.
1558 * Even though we just pushed the log above, we
1559 * did not have the superblock buffer locked at
1560 * that point so it can become pinned in between
1561 * there and here.
1562 */
1563 if (XFS_BUF_ISPINNED(bp))
1564 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1565 if (flags & SYNC_WAIT)
1566 XFS_BUF_UNASYNC(bp);
1567 else
1568 XFS_BUF_ASYNC(bp);
1569 error = xfs_bwrite(mp, bp);
1570 }
1571 if (error) {
1572 last_error = error;
1573 }
1574 }
1575
1576 /*
1577 * If this is the periodic sync, then kick some entries out of
1578 * the reference cache. This ensures that idle entries are
1579 * eventually kicked out of the cache.
1580 */
1581 if (flags & SYNC_REFCACHE) {
Nathan Scottcde410a2005-09-05 11:47:01 +10001582 if (flags & SYNC_WAIT)
1583 xfs_refcache_purge_mp(mp);
1584 else
1585 xfs_refcache_purge_some(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 }
1587
1588 /*
David Chinner92821e22007-05-24 15:26:31 +10001589 * If asked, update the disk superblock with incore counter values if we
1590 * are using non-persistent counters so that they don't get too far out
1591 * of sync if we crash or get a forced shutdown. We don't want to force
1592 * this to disk, just get a transaction into the iclogs....
1593 */
1594 if (flags & SYNC_SUPER)
1595 xfs_log_sbcount(mp, 0);
1596
1597 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 * Now check to see if the log needs a "dummy" transaction.
1599 */
1600
1601 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1602 xfs_trans_t *tp;
1603 xfs_inode_t *ip;
1604
1605 /*
1606 * Put a dummy transaction in the log to tell
1607 * recovery that all others are OK.
1608 */
1609 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1610 if ((error = xfs_trans_reserve(tp, 0,
1611 XFS_ICHANGE_LOG_RES(mp),
1612 0, 0, 0))) {
1613 xfs_trans_cancel(tp, 0);
1614 return error;
1615 }
1616
1617 ip = mp->m_rootip;
1618 xfs_ilock(ip, XFS_ILOCK_EXCL);
1619
1620 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1621 xfs_trans_ihold(tp, ip);
1622 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
Eric Sandeen1c72bf92007-05-08 13:48:42 +10001623 error = xfs_trans_commit(tp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1625 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1626 }
1627
1628 /*
1629 * When shutting down, we need to insure that the AIL is pushed
1630 * to disk or the filesystem can appear corrupt from the PROM.
1631 */
1632 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1633 XFS_bflush(mp->m_ddev_targp);
1634 if (mp->m_rtdev_targp) {
1635 XFS_bflush(mp->m_rtdev_targp);
1636 }
1637 }
1638
1639 return XFS_ERROR(last_error);
1640}
1641
1642/*
1643 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1644 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001645int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646xfs_vget(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001647 xfs_mount_t *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001648 bhv_vnode_t **vpp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 fid_t *fidp)
1650{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1652 xfs_inode_t *ip;
1653 int error;
1654 xfs_ino_t ino;
1655 unsigned int igen;
1656
1657 /*
1658 * Invalid. Since handles can be created in user space and passed in
1659 * via gethandle(), this is not cause for a panic.
1660 */
1661 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1662 return XFS_ERROR(EINVAL);
1663
1664 ino = xfid->xfs_fid_ino;
1665 igen = xfid->xfs_fid_gen;
1666
1667 /*
1668 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1669 */
1670 if (ino == 0)
1671 return XFS_ERROR(ESTALE);
1672
1673 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1674 if (error) {
1675 *vpp = NULL;
1676 return error;
1677 }
1678
1679 if (ip == NULL) {
1680 *vpp = NULL;
1681 return XFS_ERROR(EIO);
1682 }
1683
1684 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1685 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1686 *vpp = NULL;
1687 return XFS_ERROR(ENOENT);
1688 }
1689
1690 *vpp = XFS_ITOV(ip);
1691 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1692 return 0;
1693}
1694
1695
1696#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1697#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1698#define MNTOPT_LOGDEV "logdev" /* log device */
1699#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1700#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1701#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1702#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1703#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1704#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1705#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1706#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1707#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1708#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
Nathan Scotte69a3332005-09-02 16:42:26 +10001709#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1710#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1711#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1712#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
Nathan Scott1f443ad2005-05-05 13:28:29 -07001713#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001715#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
Nathan Scottd8cc8902005-11-02 10:34:53 +11001716 * unwritten extent conversion */
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001717#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1719#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1720#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1721#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
David Chinnere8c8b3a2005-11-02 10:33:05 +11001722#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1723#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1724 * in stat(). */
Nathan Scottd8cc8902005-11-02 10:34:53 +11001725#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1726#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
David Chinner2a82b8b2007-07-11 11:09:12 +10001727#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001728#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
1729#define MNTOPT_NOQUOTA "noquota" /* no quotas */
1730#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
1731#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
1732#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
1733#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
1734#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
1735#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
1736#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
1737#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
1738#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
1739#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
Christoph Hellwig293688e2007-08-29 11:59:36 +10001740#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
1741#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
1742#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
Nathan Scott1f443ad2005-05-05 13:28:29 -07001744STATIC unsigned long
Nathan Scottb190f112006-06-09 17:13:15 +10001745suffix_strtoul(char *s, char **endp, unsigned int base)
Nathan Scott1f443ad2005-05-05 13:28:29 -07001746{
1747 int last, shift_left_factor = 0;
Nathan Scottb190f112006-06-09 17:13:15 +10001748 char *value = s;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001749
1750 last = strlen(value) - 1;
1751 if (value[last] == 'K' || value[last] == 'k') {
1752 shift_left_factor = 10;
1753 value[last] = '\0';
1754 }
1755 if (value[last] == 'M' || value[last] == 'm') {
1756 shift_left_factor = 20;
1757 value[last] = '\0';
1758 }
1759 if (value[last] == 'G' || value[last] == 'g') {
1760 shift_left_factor = 30;
1761 value[last] = '\0';
1762 }
1763
Nathan Scottb190f112006-06-09 17:13:15 +10001764 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001765}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001767int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768xfs_parseargs(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001769 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 char *options,
1771 struct xfs_mount_args *args,
1772 int update)
1773{
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001774 bhv_vfs_t *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 char *this_char, *value, *eov;
1776 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1777 int iosize;
1778
Vlad Apostolovb93bd202007-08-28 14:00:28 +10001779 /*
1780 * Applications using DMI filesystems often expect the
1781 * inode generation number to be monotonically increasing.
1782 * If we delete inode chunks we break this assumption, so
1783 * keep unused inode chunks on disk for DMI filesystems
1784 * until we come up with a better solution.
1785 * Note that if "ikeep" or "noikeep" mount options are
1786 * supplied, then they are honored.
1787 */
1788 if (!(args->flags & XFSMNT_DMAPI))
1789 args->flags |= XFSMNT_IDELETE;
1790
Nathan Scott3bbcc8e2006-03-31 13:04:56 +10001791 args->flags |= XFSMNT_BARRIER;
1792 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
1794 if (!options)
Nathan Scott05db2182005-11-04 09:49:07 +11001795 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
1797 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1798
1799 while ((this_char = strsep(&options, ",")) != NULL) {
1800 if (!*this_char)
1801 continue;
1802 if ((value = strchr(this_char, '=')) != NULL)
1803 *value++ = 0;
1804
1805 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1806 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001807 cmn_err(CE_WARN,
1808 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001809 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 return EINVAL;
1811 }
1812 args->logbufs = simple_strtoul(value, &eov, 10);
1813 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001815 cmn_err(CE_WARN,
1816 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001817 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 return EINVAL;
1819 }
Nathan Scott1f443ad2005-05-05 13:28:29 -07001820 args->logbufsize = suffix_strtoul(value, &eov, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1822 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001823 cmn_err(CE_WARN,
1824 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001825 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 return EINVAL;
1827 }
1828 strncpy(args->logname, value, MAXNAMELEN);
1829 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1830 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001831 cmn_err(CE_WARN,
1832 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001833 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 return EINVAL;
1835 }
1836 strncpy(args->mtpt, value, MAXNAMELEN);
1837 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1838 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001839 cmn_err(CE_WARN,
1840 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001841 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 return EINVAL;
1843 }
1844 strncpy(args->rtname, value, MAXNAMELEN);
1845 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1846 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001847 cmn_err(CE_WARN,
1848 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001849 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 return EINVAL;
1851 }
1852 iosize = simple_strtoul(value, &eov, 10);
1853 args->flags |= XFSMNT_IOSIZE;
1854 args->iosizelog = (uint8_t) iosize;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001855 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1856 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001857 cmn_err(CE_WARN,
1858 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001859 this_char);
1860 return EINVAL;
1861 }
1862 iosize = suffix_strtoul(value, &eov, 10);
1863 args->flags |= XFSMNT_IOSIZE;
1864 args->iosizelog = ffs(iosize) - 1;
Nathan Scotte69a3332005-09-02 16:42:26 +10001865 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1866 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1867 vfsp->vfs_flag |= VFS_GRPID;
1868 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1869 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1870 vfsp->vfs_flag &= ~VFS_GRPID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1872 args->flags |= XFSMNT_WSYNC;
1873 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1874 args->flags |= XFSMNT_OSYNCISOSYNC;
1875 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1876 args->flags |= XFSMNT_NORECOVERY;
1877 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1878 args->flags |= XFSMNT_INO64;
1879#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001880 cmn_err(CE_WARN,
1881 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001882 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 return EINVAL;
1884#endif
1885 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1886 args->flags |= XFSMNT_NOALIGN;
1887 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1888 args->flags |= XFSMNT_SWALLOC;
1889 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1890 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001891 cmn_err(CE_WARN,
1892 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001893 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 return EINVAL;
1895 }
1896 dsunit = simple_strtoul(value, &eov, 10);
1897 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1898 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001899 cmn_err(CE_WARN,
1900 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001901 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 return EINVAL;
1903 }
1904 dswidth = simple_strtoul(value, &eov, 10);
1905 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1906 args->flags &= ~XFSMNT_32BITINODES;
1907#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001908 cmn_err(CE_WARN,
1909 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001910 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 return EINVAL;
1912#endif
1913 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1914 args->flags |= XFSMNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001915 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1916 args->flags |= XFSMNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001917 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1918 args->flags &= ~XFSMNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1920 args->flags &= ~XFSMNT_IDELETE;
1921 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1922 args->flags |= XFSMNT_IDELETE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001923 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001924 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001925 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001926 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001927 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001928 args->flags |= XFSMNT_ATTR2;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001929 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001930 args->flags &= ~XFSMNT_ATTR2;
David Chinner2a82b8b2007-07-11 11:09:12 +10001931 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1932 args->flags2 |= XFSMNT2_FILESTREAMS;
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001933 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
1934 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
1935 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
1936 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
1937 !strcmp(this_char, MNTOPT_UQUOTA) ||
1938 !strcmp(this_char, MNTOPT_USRQUOTA)) {
1939 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
1940 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
1941 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
1942 args->flags |= XFSMNT_UQUOTA;
1943 args->flags &= ~XFSMNT_UQUOTAENF;
1944 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
1945 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
1946 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
1947 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
1948 args->flags |= XFSMNT_PQUOTA;
1949 args->flags &= ~XFSMNT_PQUOTAENF;
1950 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
1951 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
1952 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
1953 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
1954 args->flags |= XFSMNT_GQUOTA;
1955 args->flags &= ~XFSMNT_GQUOTAENF;
Christoph Hellwig293688e2007-08-29 11:59:36 +10001956 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
1957 args->flags |= XFSMNT_DMAPI;
1958 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
1959 args->flags |= XFSMNT_DMAPI;
1960 } else if (!strcmp(this_char, MNTOPT_DMI)) {
1961 args->flags |= XFSMNT_DMAPI;
David Chinnerda353b02007-08-28 14:00:13 +10001962 } else if (!strcmp(this_char, "ihashsize")) {
1963 cmn_err(CE_WARN,
1964 "XFS: ihashsize no longer used, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 } else if (!strcmp(this_char, "osyncisdsync")) {
1966 /* no-op, this is now the default */
Nathan Scottb6574522006-06-09 15:29:40 +10001967 cmn_err(CE_WARN,
1968 "XFS: osyncisdsync is now the default, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 } else if (!strcmp(this_char, "irixsgid")) {
Nathan Scottb6574522006-06-09 15:29:40 +10001970 cmn_err(CE_WARN,
1971 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 } else {
Nathan Scottb6574522006-06-09 15:29:40 +10001973 cmn_err(CE_WARN,
1974 "XFS: unknown mount option [%s].", this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 return EINVAL;
1976 }
1977 }
1978
1979 if (args->flags & XFSMNT_NORECOVERY) {
1980 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
Nathan Scottb6574522006-06-09 15:29:40 +10001981 cmn_err(CE_WARN,
1982 "XFS: no-recovery mounts must be read-only.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 return EINVAL;
1984 }
1985 }
1986
1987 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001988 cmn_err(CE_WARN,
1989 "XFS: sunit and swidth options incompatible with the noalign option");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 return EINVAL;
1991 }
1992
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001993 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
1994 cmn_err(CE_WARN,
1995 "XFS: cannot mount with both project and group quota");
1996 return EINVAL;
1997 }
1998
Christoph Hellwig293688e2007-08-29 11:59:36 +10001999 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
2000 printk("XFS: %s option needs the mount point option as well\n",
2001 MNTOPT_DMAPI);
2002 return EINVAL;
2003 }
2004
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10002006 cmn_err(CE_WARN,
2007 "XFS: sunit and swidth must be specified together");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 return EINVAL;
2009 }
2010
2011 if (dsunit && (dswidth % dsunit != 0)) {
Nathan Scottb6574522006-06-09 15:29:40 +10002012 cmn_err(CE_WARN,
2013 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014 dswidth, dsunit);
2015 return EINVAL;
2016 }
2017
2018 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
2019 if (dsunit) {
2020 args->sunit = dsunit;
2021 args->flags |= XFSMNT_RETERR;
2022 } else {
2023 args->sunit = vol_dsunit;
2024 }
2025 dswidth ? (args->swidth = dswidth) :
2026 (args->swidth = vol_dswidth);
2027 } else {
2028 args->sunit = args->swidth = 0;
2029 }
2030
Nathan Scott05db2182005-11-04 09:49:07 +11002031done:
Nathan Scottc11e2c32005-11-02 15:11:45 +11002032 if (args->flags & XFSMNT_32BITINODES)
2033 vfsp->vfs_flag |= VFS_32BITINODES;
Nathan Scotte718eeb42005-11-02 15:09:22 +11002034 if (args->flags2)
2035 args->flags |= XFSMNT_FLAGS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 return 0;
2037}
2038
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10002039int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040xfs_showargs(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10002041 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 struct seq_file *m)
2043{
2044 static struct proc_xfs_info {
2045 int flag;
2046 char *str;
2047 } xfs_info[] = {
2048 /* the few simple ones we can get from the mount struct */
2049 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
2050 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
2051 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
2052 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
2053 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
2054 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
2055 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 { 0, NULL }
2057 };
2058 struct proc_xfs_info *xfs_infop;
Nathan Scottb83bd132006-06-09 16:48:30 +10002059 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
2062 if (mp->m_flags & xfs_infop->flag)
2063 seq_puts(m, xfs_infop->str);
2064 }
2065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11002067 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
2068 (int)(1 << mp->m_writeio_log) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
2070 if (mp->m_logbufs > 0)
2071 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 if (mp->m_logbsize > 0)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11002073 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Nathan Scottfc1f8c12005-11-02 11:44:33 +11002075 if (mp->m_logname)
2076 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +11002077 if (mp->m_rtname)
2078 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079
2080 if (mp->m_dalign > 0)
2081 seq_printf(m, "," MNTOPT_SUNIT "=%d",
2082 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 if (mp->m_swidth > 0)
2084 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
2085 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
2086
Nathan Scotte15f1952006-03-22 12:47:52 +11002087 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
2088 seq_printf(m, "," MNTOPT_IKEEP);
Nathan Scottfa7e7d72005-11-02 15:00:48 +11002089 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
2090 seq_printf(m, "," MNTOPT_LARGEIO);
2091
Nathan Scottc11e2c32005-11-02 15:11:45 +11002092 if (!(vfsp->vfs_flag & VFS_32BITINODES))
2093 seq_printf(m, "," MNTOPT_64BITINODE);
Nathan Scotte69a3332005-09-02 16:42:26 +10002094 if (vfsp->vfs_flag & VFS_GRPID)
2095 seq_printf(m, "," MNTOPT_GRPID);
2096
Christoph Hellwigb09cc772007-08-30 17:19:57 +10002097 if (mp->m_qflags & XFS_UQUOTA_ACCT) {
2098 if (mp->m_qflags & XFS_UQUOTA_ENFD)
2099 seq_puts(m, "," MNTOPT_USRQUOTA);
2100 else
2101 seq_puts(m, "," MNTOPT_UQUOTANOENF);
2102 }
2103
2104 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
2105 if (mp->m_qflags & XFS_OQUOTA_ENFD)
2106 seq_puts(m, "," MNTOPT_PRJQUOTA);
2107 else
2108 seq_puts(m, "," MNTOPT_PQUOTANOENF);
2109 }
2110
2111 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
2112 if (mp->m_qflags & XFS_OQUOTA_ENFD)
2113 seq_puts(m, "," MNTOPT_GRPQUOTA);
2114 else
2115 seq_puts(m, "," MNTOPT_GQUOTANOENF);
2116 }
2117
2118 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
2119 seq_puts(m, "," MNTOPT_NOQUOTA);
2120
Christoph Hellwig293688e2007-08-29 11:59:36 +10002121 if (vfsp->vfs_flag & VFS_DMI)
2122 seq_puts(m, "," MNTOPT_DMAPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 return 0;
2124}
2125
David Chinner28239452007-02-10 18:36:40 +11002126/*
David Chinner516b2e72007-06-18 16:50:48 +10002127 * Second stage of a freeze. The data is already frozen so we only
2128 * need to take care of themetadata. Once that's done write a dummy
2129 * record to dirty the log in case of a crash while frozen.
David Chinner28239452007-02-10 18:36:40 +11002130 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131STATIC void
2132xfs_freeze(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10002133 xfs_mount_t *mp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
David Chinner516b2e72007-06-18 16:50:48 +10002135 xfs_attr_quiesce(mp);
Christoph Hellwige13a73f2006-01-11 15:30:08 +11002136 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137}