blob: f62f6e486f23eeaf289eb88127b38c1baf310921 [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 Scotte718eeb2005-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
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000405 if (ap->flags & XFSMNT_UQUOTA) {
406 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
407 if (ap->flags & XFSMNT_UQUOTAENF)
408 mp->m_qflags |= XFS_UQUOTA_ENFD;
409 }
410
411 if (ap->flags & XFSMNT_GQUOTA) {
412 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
413 if (ap->flags & XFSMNT_GQUOTAENF)
414 mp->m_qflags |= XFS_OQUOTA_ENFD;
415 } else if (ap->flags & XFSMNT_PQUOTA) {
416 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
417 if (ap->flags & XFSMNT_PQUOTAENF)
418 mp->m_qflags |= XFS_OQUOTA_ENFD;
419 }
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return 0;
422}
423
424/*
425 * xfs_mount
426 *
427 * The file system configurations are:
428 * (1) device (partition) with data and internal log
429 * (2) logical volume with data and log subvolumes.
430 * (3) logical volume with data, log, and realtime subvolumes.
431 *
432 * We only have to handle opening the log and realtime volumes here if
433 * they are present. The data subvolume has already been opened by
434 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
435 */
436STATIC int
437xfs_mount(
438 struct bhv_desc *bhvp,
439 struct xfs_mount_args *args,
440 cred_t *credp)
441{
Nathan Scottb83bd132006-06-09 16:48:30 +1000442 struct bhv_vfs *vfsp = bhvtovfs(bhvp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 struct bhv_desc *p;
444 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
445 struct block_device *ddev, *logdev, *rtdev;
446 int flags = 0, error;
447
448 ddev = vfsp->vfs_super->s_bdev;
449 logdev = rtdev = NULL;
450
Christoph Hellwig293688e2007-08-29 11:59:36 +1000451 error = xfs_dmops_get(mp, args);
452 if (error)
453 return error;
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000454 error = xfs_qmops_get(mp, args);
455 if (error)
456 return error;
Christoph Hellwig293688e2007-08-29 11:59:36 +1000457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 /*
459 * Setup xfs_mount function vectors from available behaviors
460 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
462 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
463
Nathan Scott764d1f82006-03-31 13:04:17 +1000464 if (args->flags & XFSMNT_QUIET)
465 flags |= XFS_MFSI_QUIET;
466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 /*
468 * Open real time and log devices - order is important.
469 */
470 if (args->logname[0]) {
471 error = xfs_blkdev_get(mp, args->logname, &logdev);
472 if (error)
473 return error;
474 }
475 if (args->rtname[0]) {
476 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
477 if (error) {
478 xfs_blkdev_put(logdev);
479 return error;
480 }
481
482 if (rtdev == ddev || rtdev == logdev) {
483 cmn_err(CE_WARN,
484 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
485 xfs_blkdev_put(logdev);
486 xfs_blkdev_put(rtdev);
487 return EINVAL;
488 }
489 }
490
491 /*
492 * Setup xfs_mount buffer target pointers
493 */
494 error = ENOMEM;
495 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
496 if (!mp->m_ddev_targp) {
497 xfs_blkdev_put(logdev);
498 xfs_blkdev_put(rtdev);
499 return error;
500 }
501 if (rtdev) {
502 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000503 if (!mp->m_rtdev_targp) {
504 xfs_blkdev_put(logdev);
505 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000507 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 }
509 mp->m_logdev_targp = (logdev && logdev != ddev) ?
510 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000511 if (!mp->m_logdev_targp) {
512 xfs_blkdev_put(logdev);
513 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000515 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 /*
518 * Setup flags based on mount(2) options and then the superblock
519 */
520 error = xfs_start_flags(vfsp, args, mp);
521 if (error)
522 goto error1;
Nathan Scott764d1f82006-03-31 13:04:17 +1000523 error = xfs_readsb(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 if (error)
525 goto error1;
526 error = xfs_finish_flags(vfsp, args, mp);
527 if (error)
528 goto error2;
529
530 /*
531 * Setup xfs_mount buffer target pointers based on superblock
532 */
533 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
534 mp->m_sb.sb_sectsize);
535 if (!error && logdev && logdev != ddev) {
536 unsigned int log_sector_size = BBSIZE;
537
538 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
539 log_sector_size = mp->m_sb.sb_logsectsize;
540 error = xfs_setsize_buftarg(mp->m_logdev_targp,
541 mp->m_sb.sb_blocksize,
542 log_sector_size);
543 }
544 if (!error && rtdev)
545 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
546 mp->m_sb.sb_blocksize,
547 mp->m_sb.sb_sectsize);
548 if (error)
549 goto error2;
550
Nathan Scottb2ea4012006-07-28 17:05:13 +1000551 if (mp->m_flags & XFS_MOUNT_BARRIER)
Christoph Hellwigc7d437d2006-01-11 15:28:56 +1100552 xfs_mountfs_check_barriers(mp);
553
David Chinner2a82b8b2007-07-11 11:09:12 +1000554 if ((error = xfs_filestream_mount(mp)))
555 goto error2;
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 error = XFS_IOINIT(vfsp, args, flags);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100558 if (error)
559 goto error2;
560
Christoph Hellwig293688e2007-08-29 11:59:36 +1000561 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
562
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100563 return 0;
564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565error2:
566 if (mp->m_sb_bp)
567 xfs_freesb(mp);
568error1:
569 xfs_binval(mp->m_ddev_targp);
570 if (logdev && logdev != ddev)
571 xfs_binval(mp->m_logdev_targp);
572 if (rtdev)
573 xfs_binval(mp->m_rtdev_targp);
574error0:
575 xfs_unmountfs_close(mp, credp);
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000576 xfs_qmops_put(mp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000577 xfs_dmops_put(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 return error;
579}
580
581STATIC int
582xfs_unmount(
583 bhv_desc_t *bdp,
584 int flags,
585 cred_t *credp)
586{
Nathan Scottb83bd132006-06-09 16:48:30 +1000587 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 xfs_mount_t *mp = XFS_BHVTOM(bdp);
589 xfs_inode_t *rip;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000590 bhv_vnode_t *rvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 int unmount_event_wanted = 0;
592 int unmount_event_flags = 0;
593 int xfs_unmountfs_needed = 0;
594 int error;
595
596 rip = mp->m_rootip;
597 rvp = XFS_ITOV(rip);
598
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000599#ifdef HAVE_DMAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 if (vfsp->vfs_flag & VFS_DMI) {
601 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
602 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
603 NULL, NULL, 0, 0,
604 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
605 0:DM_FLAGS_UNWANTED);
606 if (error)
607 return XFS_ERROR(error);
608 unmount_event_wanted = 1;
609 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
610 0 : DM_FLAGS_UNWANTED;
611 }
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000612#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 /*
614 * First blow any referenced inode from this file system
615 * out of the reference cache, and delete the timer.
616 */
617 xfs_refcache_purge_mp(mp);
618
David Chinner2a82b8b2007-07-11 11:09:12 +1000619 /*
620 * Blow away any referenced inode in the filestreams cache.
621 * This can and will cause log traffic as inodes go inactive
622 * here.
623 */
624 xfs_filestream_unmount(mp);
625
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 XFS_bflush(mp->m_ddev_targp);
627 error = xfs_unmount_flush(mp, 0);
628 if (error)
629 goto out;
630
631 ASSERT(vn_count(rvp) == 1);
632
633 /*
634 * Drop the reference count
635 */
636 VN_RELE(rvp);
637
638 /*
639 * If we're forcing a shutdown, typically because of a media error,
640 * we want to make sure we invalidate dirty pages that belong to
641 * referenced vnodes as well.
642 */
643 if (XFS_FORCED_SHUTDOWN(mp)) {
644 error = xfs_sync(&mp->m_bhv,
645 (SYNC_WAIT | SYNC_CLOSE), credp);
646 ASSERT(error != EFSCORRUPTED);
647 }
648 xfs_unmountfs_needed = 1;
649
650out:
651 /* Send DMAPI event, if required.
652 * Then do xfs_unmountfs() if needed.
653 * Then return error (or zero).
654 */
655 if (unmount_event_wanted) {
656 /* Note: mp structure must still exist for
657 * XFS_SEND_UNMOUNT() call.
658 */
659 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
660 DM_RIGHT_NULL, 0, error, unmount_event_flags);
661 }
662 if (xfs_unmountfs_needed) {
663 /*
664 * Call common unmount function to flush to disk
665 * and free the super block buffer & mount structures.
666 */
667 xfs_unmountfs(mp, credp);
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000668 xfs_qmops_put(mp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000669 xfs_dmops_put(mp);
Christoph Hellwigf541d272007-08-29 11:53:22 +1000670 kmem_free(mp, sizeof(xfs_mount_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 }
672
673 return XFS_ERROR(error);
674}
675
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000676STATIC int
677xfs_quiesce_fs(
678 xfs_mount_t *mp)
679{
680 int count = 0, pincount;
Nathan Scott3758dee2006-03-22 12:47:28 +1100681
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000682 xfs_refcache_purge_mp(mp);
683 xfs_flush_buftarg(mp->m_ddev_targp, 0);
684 xfs_finish_reclaim_all(mp, 0);
685
686 /* This loop must run at least twice.
687 * The first instance of the loop will flush
688 * most meta data but that will generate more
689 * meta data (typically directory updates).
690 * Which then must be flushed and logged before
691 * we can write the unmount record.
Nathan Scott3758dee2006-03-22 12:47:28 +1100692 */
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000693 do {
David Chinner516b2e72007-06-18 16:50:48 +1000694 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000695 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
696 if (!pincount) {
697 delay(50);
698 count++;
699 }
700 } while (count < 2);
701
702 return 0;
703}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
David Chinner516b2e72007-06-18 16:50:48 +1000705/*
706 * Second stage of a quiesce. The data is already synced, now we have to take
707 * care of the metadata. New transactions are already blocked, so we need to
708 * wait for any remaining transactions to drain out before proceding.
709 */
710STATIC void
711xfs_attr_quiesce(
712 xfs_mount_t *mp)
713{
714 /* wait for all modifications to complete */
715 while (atomic_read(&mp->m_active_trans) > 0)
716 delay(100);
717
718 /* flush inodes and push all remaining buffers out to disk */
719 xfs_quiesce_fs(mp);
720
721 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
722
723 /* Push the superblock and write an unmount record */
724 xfs_log_sbcount(mp, 1);
725 xfs_log_unmount_write(mp);
726 xfs_unmountfs_writesb(mp);
727}
728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729STATIC int
730xfs_mntupdate(
731 bhv_desc_t *bdp,
732 int *flags,
733 struct xfs_mount_args *args)
734{
Nathan Scottb83bd132006-06-09 16:48:30 +1000735 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Nathan Scottd08d3892006-05-08 19:51:28 +1000738 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
739 if (vfsp->vfs_flag & VFS_RDONLY)
740 vfsp->vfs_flag &= ~VFS_RDONLY;
741 if (args->flags & XFSMNT_BARRIER) {
742 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100743 xfs_mountfs_check_barriers(mp);
Nathan Scottd08d3892006-05-08 19:51:28 +1000744 } else {
745 mp->m_flags &= ~XFS_MOUNT_BARRIER;
746 }
747 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
David Chinner2a82b8b2007-07-11 11:09:12 +1000748 xfs_filestream_flush(mp);
David Chinner516b2e72007-06-18 16:50:48 +1000749 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
750 xfs_attr_quiesce(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 vfsp->vfs_flag |= VFS_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 return 0;
754}
755
756/*
757 * xfs_unmount_flush implements a set of flush operation on special
758 * inodes, which are needed as a separate set of operations so that
759 * they can be called as part of relocation process.
760 */
761int
762xfs_unmount_flush(
763 xfs_mount_t *mp, /* Mount structure we are getting
764 rid of. */
765 int relocation) /* Called from vfs relocation. */
766{
767 xfs_inode_t *rip = mp->m_rootip;
768 xfs_inode_t *rbmip;
769 xfs_inode_t *rsumip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000770 bhv_vnode_t *rvp = XFS_ITOV(rip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 int error;
772
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000773 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 xfs_iflock(rip);
775
776 /*
777 * Flush out the real time inodes.
778 */
779 if ((rbmip = mp->m_rbmip) != NULL) {
780 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
781 xfs_iflock(rbmip);
782 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
783 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
784
785 if (error == EFSCORRUPTED)
786 goto fscorrupt_out;
787
788 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
789
790 rsumip = mp->m_rsumip;
791 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
792 xfs_iflock(rsumip);
793 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
794 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
795
796 if (error == EFSCORRUPTED)
797 goto fscorrupt_out;
798
799 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
800 }
801
802 /*
803 * Synchronously flush root inode to disk
804 */
805 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
806 if (error == EFSCORRUPTED)
807 goto fscorrupt_out2;
808
809 if (vn_count(rvp) != 1 && !relocation) {
810 xfs_iunlock(rip, XFS_ILOCK_EXCL);
811 return XFS_ERROR(EBUSY);
812 }
813
814 /*
815 * Release dquot that rootinode, rbmino and rsumino might be holding,
816 * flush and purge the quota inodes.
817 */
818 error = XFS_QM_UNMOUNT(mp);
819 if (error == EFSCORRUPTED)
820 goto fscorrupt_out2;
821
822 if (rbmip) {
823 VN_RELE(XFS_ITOV(rbmip));
824 VN_RELE(XFS_ITOV(rsumip));
825 }
826
827 xfs_iunlock(rip, XFS_ILOCK_EXCL);
828 return 0;
829
830fscorrupt_out:
831 xfs_ifunlock(rip);
832
833fscorrupt_out2:
834 xfs_iunlock(rip, XFS_ILOCK_EXCL);
835
836 return XFS_ERROR(EFSCORRUPTED);
837}
838
839/*
840 * xfs_root extracts the root vnode from a vfs.
841 *
842 * vfsp -- the vfs struct for the desired file system
843 * vpp -- address of the caller's vnode pointer which should be
844 * set to the desired fs root vnode
845 */
846STATIC int
847xfs_root(
848 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000849 bhv_vnode_t **vpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000851 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
854 VN_HOLD(vp);
855 *vpp = vp;
856 return 0;
857}
858
859/*
860 * xfs_statvfs
861 *
862 * Fill in the statvfs structure for the given file system. We use
863 * the superblock lock in the mount structure to ensure a consistent
864 * snapshot of the counters returned.
865 */
866STATIC int
867xfs_statvfs(
868 bhv_desc_t *bdp,
Nathan Scott8285fb52006-06-09 17:07:12 +1000869 bhv_statvfs_t *statp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000870 bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871{
872 __uint64_t fakeinos;
873 xfs_extlen_t lsize;
874 xfs_mount_t *mp;
875 xfs_sb_t *sbp;
876 unsigned long s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 mp = XFS_BHVTOM(bdp);
879 sbp = &(mp->m_sb);
880
881 statp->f_type = XFS_SB_MAGIC;
882
David Chinnerdbcabad2007-02-10 18:36:17 +1100883 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 s = XFS_SB_LOCK(mp);
885 statp->f_bsize = sbp->sb_blocksize;
886 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
887 statp->f_blocks = sbp->sb_dblocks - lsize;
David Chinner4be536d2006-09-07 14:26:50 +1000888 statp->f_bfree = statp->f_bavail =
889 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 fakeinos = statp->f_bfree << sbp->sb_inopblog;
891#if XFS_BIG_INUMS
892 fakeinos += mp->m_inoadd;
893#endif
894 statp->f_files =
895 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
896 if (mp->m_maxicount)
897#if XFS_BIG_INUMS
898 if (!mp->m_inoadd)
899#endif
900 statp->f_files = min_t(typeof(statp->f_files),
901 statp->f_files,
902 mp->m_maxicount);
903 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
904 XFS_SB_UNLOCK(mp, s);
905
Nathan Scottcde410a2005-09-05 11:47:01 +1000906 xfs_statvfs_fsid(statp, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 statp->f_namelen = MAXNAMELEN - 1;
908
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000909 if (vp)
910 XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 return 0;
912}
913
914
915/*
916 * xfs_sync flushes any pending I/O to file system vfsp.
917 *
918 * This routine is called by vfs_sync() to make sure that things make it
919 * out to disk eventually, on sync() system calls to flush out everything,
920 * and when the file system is unmounted. For the vfs_sync() case, all
921 * we really need to do is sync out the log to make all of our meta-data
922 * updates permanent (except for timestamps). For calls from pflushd(),
923 * dirty pages are kept moving by calling pdflush() on the inodes
924 * containing them. We also flush the inodes that we can lock without
925 * sleeping and the superblock if we can lock it without sleeping from
926 * vfs_sync() so that items at the tail of the log are always moving out.
927 *
928 * Flags:
929 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
930 * to sleep if we can help it. All we really need
931 * to do is ensure that the log is synced at least
932 * periodically. We also push the inodes and
933 * superblock if we can lock them without sleeping
934 * and they are not pinned.
935 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
936 * set, then we really want to lock each inode and flush
937 * it.
938 * SYNC_WAIT - All the flushes that take place in this call should
939 * be synchronous.
940 * SYNC_DELWRI - This tells us to push dirty pages associated with
941 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
942 * determine if they should be flushed sync, async, or
943 * delwri.
944 * SYNC_CLOSE - This flag is passed when the system is being
Nathan Scottc41564b2006-03-29 08:55:14 +1000945 * unmounted. We should sync and invalidate everything.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 * SYNC_FSDATA - This indicates that the caller would like to make
947 * sure the superblock is safe on disk. We can ensure
Nathan Scottc41564b2006-03-29 08:55:14 +1000948 * this by simply making sure the log gets flushed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 * if SYNC_BDFLUSH is set, and by actually writing it
950 * out otherwise.
David Chinner3c0dc772007-02-10 18:37:22 +1100951 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
952 * before we return (including direct I/O). Forms the drain
953 * side of the write barrier needed to safely quiesce the
954 * filesystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 *
956 */
957/*ARGSUSED*/
958STATIC int
959xfs_sync(
960 bhv_desc_t *bdp,
961 int flags,
962 cred_t *credp)
963{
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000964 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000965 int error;
966
967 /*
968 * Get the Quota Manager to flush the dquots.
969 *
970 * If XFS quota support is not enabled or this filesystem
971 * instance does not use quotas XFS_QM_DQSYNC will always
972 * return zero.
973 */
974 error = XFS_QM_DQSYNC(mp, flags);
975 if (error) {
976 /*
977 * If we got an IO error, we will be shutting down.
978 * So, there's nothing more for us to do here.
979 */
980 ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
981 if (XFS_FORCED_SHUTDOWN(mp))
982 return XFS_ERROR(error);
983 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
David Chinner2a82b8b2007-07-11 11:09:12 +1000985 if (flags & SYNC_IOWAIT)
986 xfs_filestream_flush(mp);
987
David Chinner28239452007-02-10 18:36:40 +1100988 return xfs_syncsub(mp, flags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
991/*
992 * xfs sync routine for internal use
993 *
Nathan Scottb83bd132006-06-09 16:48:30 +1000994 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +1100995 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 *
997 */
Nathan Scottee348072005-11-02 10:32:38 +1100998int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999xfs_sync_inodes(
1000 xfs_mount_t *mp,
1001 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002 int *bypassed)
1003{
1004 xfs_inode_t *ip = NULL;
1005 xfs_inode_t *ip_next;
1006 xfs_buf_t *bp;
Nathan Scott67fcaa72006-06-09 17:00:52 +10001007 bhv_vnode_t *vp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 int error;
1009 int last_error;
1010 uint64_t fflag;
1011 uint lock_flags;
1012 uint base_lock_flags;
1013 boolean_t mount_locked;
1014 boolean_t vnode_refed;
1015 int preempt;
1016 xfs_dinode_t *dip;
1017 xfs_iptr_t *ipointer;
1018#ifdef DEBUG
1019 boolean_t ipointer_in = B_FALSE;
1020
1021#define IPOINTER_SET ipointer_in = B_TRUE
1022#define IPOINTER_CLR ipointer_in = B_FALSE
1023#else
1024#define IPOINTER_SET
1025#define IPOINTER_CLR
1026#endif
1027
1028
1029/* Insert a marker record into the inode list after inode ip. The list
1030 * must be locked when this is called. After the call the list will no
1031 * longer be locked.
1032 */
1033#define IPOINTER_INSERT(ip, mp) { \
1034 ASSERT(ipointer_in == B_FALSE); \
1035 ipointer->ip_mnext = ip->i_mnext; \
1036 ipointer->ip_mprev = ip; \
1037 ip->i_mnext = (xfs_inode_t *)ipointer; \
1038 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
1039 preempt = 0; \
1040 XFS_MOUNT_IUNLOCK(mp); \
1041 mount_locked = B_FALSE; \
1042 IPOINTER_SET; \
1043 }
1044
1045/* Remove the marker from the inode list. If the marker was the only item
1046 * in the list then there are no remaining inodes and we should zero out
1047 * the whole list. If we are the current head of the list then move the head
1048 * past us.
1049 */
1050#define IPOINTER_REMOVE(ip, mp) { \
1051 ASSERT(ipointer_in == B_TRUE); \
1052 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1053 ip = ipointer->ip_mnext; \
1054 ip->i_mprev = ipointer->ip_mprev; \
1055 ipointer->ip_mprev->i_mnext = ip; \
1056 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1057 mp->m_inodes = ip; \
1058 } \
1059 } else { \
1060 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1061 mp->m_inodes = NULL; \
1062 ip = NULL; \
1063 } \
1064 IPOINTER_CLR; \
1065 }
1066
1067#define XFS_PREEMPT_MASK 0x7f
1068
1069 if (bypassed)
1070 *bypassed = 0;
1071 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1072 return 0;
1073 error = 0;
1074 last_error = 0;
1075 preempt = 0;
1076
1077 /* Allocate a reference marker */
1078 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1079
1080 fflag = XFS_B_ASYNC; /* default is don't wait */
Nathan Scottee348072005-11-02 10:32:38 +11001081 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 fflag = XFS_B_DELWRI;
1083 if (flags & SYNC_WAIT)
1084 fflag = 0; /* synchronous overrides all */
1085
1086 base_lock_flags = XFS_ILOCK_SHARED;
1087 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1088 /*
1089 * We need the I/O lock if we're going to call any of
1090 * the flush/inval routines.
1091 */
1092 base_lock_flags |= XFS_IOLOCK_SHARED;
1093 }
1094
1095 XFS_MOUNT_ILOCK(mp);
1096
1097 ip = mp->m_inodes;
1098
1099 mount_locked = B_TRUE;
1100 vnode_refed = B_FALSE;
1101
1102 IPOINTER_CLR;
1103
1104 do {
1105 ASSERT(ipointer_in == B_FALSE);
1106 ASSERT(vnode_refed == B_FALSE);
1107
1108 lock_flags = base_lock_flags;
1109
1110 /*
1111 * There were no inodes in the list, just break out
1112 * of the loop.
1113 */
1114 if (ip == NULL) {
1115 break;
1116 }
1117
1118 /*
1119 * We found another sync thread marker - skip it
1120 */
1121 if (ip->i_mount == NULL) {
1122 ip = ip->i_mnext;
1123 continue;
1124 }
1125
1126 vp = XFS_ITOV_NULL(ip);
1127
1128 /*
1129 * If the vnode is gone then this is being torn down,
1130 * call reclaim if it is flushed, else let regular flush
1131 * code deal with it later in the loop.
1132 */
1133
1134 if (vp == NULL) {
1135 /* Skip ones already in reclaim */
1136 if (ip->i_flags & XFS_IRECLAIM) {
1137 ip = ip->i_mnext;
1138 continue;
1139 }
1140 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1141 ip = ip->i_mnext;
1142 } else if ((xfs_ipincount(ip) == 0) &&
1143 xfs_iflock_nowait(ip)) {
1144 IPOINTER_INSERT(ip, mp);
1145
1146 xfs_finish_reclaim(ip, 1,
1147 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1148
1149 XFS_MOUNT_ILOCK(mp);
1150 mount_locked = B_TRUE;
1151 IPOINTER_REMOVE(ip, mp);
1152 } else {
1153 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1154 ip = ip->i_mnext;
1155 }
1156 continue;
1157 }
1158
1159 if (VN_BAD(vp)) {
1160 ip = ip->i_mnext;
1161 continue;
1162 }
1163
1164 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1165 XFS_MOUNT_IUNLOCK(mp);
1166 kmem_free(ipointer, sizeof(xfs_iptr_t));
1167 return 0;
1168 }
1169
1170 /*
1171 * If this is just vfs_sync() or pflushd() calling
1172 * then we can skip inodes for which it looks like
1173 * there is nothing to do. Since we don't have the
Nathan Scottc41564b2006-03-29 08:55:14 +10001174 * inode locked this is racy, but these are periodic
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 * calls so it doesn't matter. For the others we want
1176 * to know for sure, so we at least try to lock them.
1177 */
1178 if (flags & SYNC_BDFLUSH) {
1179 if (((ip->i_itemp == NULL) ||
1180 !(ip->i_itemp->ili_format.ilf_fields &
1181 XFS_ILOG_ALL)) &&
1182 (ip->i_update_core == 0)) {
1183 ip = ip->i_mnext;
1184 continue;
1185 }
1186 }
1187
1188 /*
1189 * Try to lock without sleeping. We're out of order with
1190 * the inode list lock here, so if we fail we need to drop
1191 * the mount lock and try again. If we're called from
1192 * bdflush() here, then don't bother.
1193 *
1194 * The inode lock here actually coordinates with the
1195 * almost spurious inode lock in xfs_ireclaim() to prevent
1196 * the vnode we handle here without a reference from
1197 * being freed while we reference it. If we lock the inode
1198 * while it's on the mount list here, then the spurious inode
1199 * lock in xfs_ireclaim() after the inode is pulled from
1200 * the mount list will sleep until we release it here.
1201 * This keeps the vnode from being freed while we reference
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001202 * it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 */
1204 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1206 ip = ip->i_mnext;
1207 continue;
1208 }
1209
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001210 vp = vn_grab(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 if (vp == NULL) {
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001212 ip = ip->i_mnext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 continue;
1214 }
1215
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001216 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 xfs_ilock(ip, lock_flags);
1218
1219 ASSERT(vp == XFS_ITOV(ip));
1220 ASSERT(ip->i_mount == mp);
1221
1222 vnode_refed = B_TRUE;
1223 }
1224
1225 /* From here on in the loop we may have a marker record
1226 * in the inode list.
1227 */
1228
David Chinner40095b62007-05-14 18:24:09 +10001229 /*
1230 * If we have to flush data or wait for I/O completion
1231 * we need to drop the ilock that we currently hold.
1232 * If we need to drop the lock, insert a marker if we
1233 * have not already done so.
1234 */
1235 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1236 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1237 if (mount_locked) {
1238 IPOINTER_INSERT(ip, mp);
1239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1241
David Chinner40095b62007-05-14 18:24:09 +10001242 if (flags & SYNC_CLOSE) {
1243 /* Shutdown case. Flush and invalidate. */
1244 if (XFS_FORCED_SHUTDOWN(mp))
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001245 xfs_tosspages(ip, 0, -1,
1246 FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001247 else
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001248 error = xfs_flushinval_pages(ip,
1249 0, -1, FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001250 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001251 error = xfs_flush_pages(ip, 0,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001252 -1, fflag, FI_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 }
1254
David Chinner40095b62007-05-14 18:24:09 +10001255 /*
1256 * When freezing, we need to wait ensure all I/O (including direct
1257 * I/O) is complete to ensure no further data modification can take
1258 * place after this point
1259 */
1260 if (flags & SYNC_IOWAIT)
Christoph Hellwigb677c212007-08-29 11:46:28 +10001261 vn_iowait(ip);
David Chinner40095b62007-05-14 18:24:09 +10001262
1263 xfs_ilock(ip, XFS_ILOCK_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 }
1265
1266 if (flags & SYNC_BDFLUSH) {
1267 if ((flags & SYNC_ATTR) &&
1268 ((ip->i_update_core) ||
1269 ((ip->i_itemp != NULL) &&
1270 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1271
1272 /* Insert marker and drop lock if not already
1273 * done.
1274 */
1275 if (mount_locked) {
1276 IPOINTER_INSERT(ip, mp);
1277 }
1278
1279 /*
1280 * We don't want the periodic flushing of the
1281 * inodes by vfs_sync() to interfere with
1282 * I/O to the file, especially read I/O
1283 * where it is only the access time stamp
1284 * that is being flushed out. To prevent
1285 * long periods where we have both inode
1286 * locks held shared here while reading the
1287 * inode's buffer in from disk, we drop the
1288 * inode lock while reading in the inode
1289 * buffer. We have to release the buffer
1290 * and reacquire the inode lock so that they
1291 * are acquired in the proper order (inode
1292 * locks first). The buffer will go at the
1293 * end of the lru chain, though, so we can
1294 * expect it to still be there when we go
1295 * for it again in xfs_iflush().
1296 */
1297 if ((xfs_ipincount(ip) == 0) &&
1298 xfs_iflock_nowait(ip)) {
1299
1300 xfs_ifunlock(ip);
1301 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1302
1303 error = xfs_itobp(mp, NULL, ip,
Nathan Scottb12dd342006-03-17 17:26:04 +11001304 &dip, &bp, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 if (!error) {
1306 xfs_buf_relse(bp);
1307 } else {
1308 /* Bailing out, remove the
1309 * marker and free it.
1310 */
1311 XFS_MOUNT_ILOCK(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 IPOINTER_REMOVE(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 XFS_MOUNT_IUNLOCK(mp);
1314
1315 ASSERT(!(lock_flags &
1316 XFS_IOLOCK_SHARED));
1317
1318 kmem_free(ipointer,
1319 sizeof(xfs_iptr_t));
1320 return (0);
1321 }
1322
1323 /*
1324 * Since we dropped the inode lock,
1325 * the inode may have been reclaimed.
1326 * Therefore, we reacquire the mount
1327 * lock and check to see if we were the
1328 * inode reclaimed. If this happened
1329 * then the ipointer marker will no
1330 * longer point back at us. In this
1331 * case, move ip along to the inode
1332 * after the marker, remove the marker
1333 * and continue.
1334 */
1335 XFS_MOUNT_ILOCK(mp);
1336 mount_locked = B_TRUE;
1337
1338 if (ip != ipointer->ip_mprev) {
1339 IPOINTER_REMOVE(ip, mp);
1340
1341 ASSERT(!vnode_refed);
1342 ASSERT(!(lock_flags &
1343 XFS_IOLOCK_SHARED));
1344 continue;
1345 }
1346
1347 ASSERT(ip->i_mount == mp);
1348
1349 if (xfs_ilock_nowait(ip,
1350 XFS_ILOCK_SHARED) == 0) {
1351 ASSERT(ip->i_mount == mp);
1352 /*
1353 * We failed to reacquire
1354 * the inode lock without
1355 * sleeping, so just skip
1356 * the inode for now. We
1357 * clear the ILOCK bit from
1358 * the lock_flags so that we
1359 * won't try to drop a lock
1360 * we don't hold below.
1361 */
1362 lock_flags &= ~XFS_ILOCK_SHARED;
1363 IPOINTER_REMOVE(ip_next, mp);
1364 } else if ((xfs_ipincount(ip) == 0) &&
1365 xfs_iflock_nowait(ip)) {
1366 ASSERT(ip->i_mount == mp);
1367 /*
1368 * Since this is vfs_sync()
1369 * calling we only flush the
1370 * inode out if we can lock
1371 * it without sleeping and
1372 * it is not pinned. Drop
1373 * the mount lock here so
1374 * that we don't hold it for
1375 * too long. We already have
1376 * a marker in the list here.
1377 */
1378 XFS_MOUNT_IUNLOCK(mp);
1379 mount_locked = B_FALSE;
1380 error = xfs_iflush(ip,
1381 XFS_IFLUSH_DELWRI);
1382 } else {
1383 ASSERT(ip->i_mount == mp);
1384 IPOINTER_REMOVE(ip_next, mp);
1385 }
1386 }
1387
1388 }
1389
1390 } else {
1391 if ((flags & SYNC_ATTR) &&
1392 ((ip->i_update_core) ||
1393 ((ip->i_itemp != NULL) &&
1394 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1395 if (mount_locked) {
1396 IPOINTER_INSERT(ip, mp);
1397 }
1398
1399 if (flags & SYNC_WAIT) {
1400 xfs_iflock(ip);
1401 error = xfs_iflush(ip,
1402 XFS_IFLUSH_SYNC);
1403 } else {
1404 /*
1405 * If we can't acquire the flush
1406 * lock, then the inode is already
1407 * being flushed so don't bother
1408 * waiting. If we can lock it then
1409 * do a delwri flush so we can
1410 * combine multiple inode flushes
1411 * in each disk write.
1412 */
1413 if (xfs_iflock_nowait(ip)) {
1414 error = xfs_iflush(ip,
1415 XFS_IFLUSH_DELWRI);
1416 }
1417 else if (bypassed)
1418 (*bypassed)++;
1419 }
1420 }
1421 }
1422
1423 if (lock_flags != 0) {
1424 xfs_iunlock(ip, lock_flags);
1425 }
1426
1427 if (vnode_refed) {
1428 /*
1429 * If we had to take a reference on the vnode
1430 * above, then wait until after we've unlocked
1431 * the inode to release the reference. This is
1432 * because we can be already holding the inode
1433 * lock when VN_RELE() calls xfs_inactive().
1434 *
1435 * Make sure to drop the mount lock before calling
1436 * VN_RELE() so that we don't trip over ourselves if
1437 * we have to go for the mount lock again in the
1438 * inactive code.
1439 */
1440 if (mount_locked) {
1441 IPOINTER_INSERT(ip, mp);
1442 }
1443
1444 VN_RELE(vp);
1445
1446 vnode_refed = B_FALSE;
1447 }
1448
1449 if (error) {
1450 last_error = error;
1451 }
1452
1453 /*
1454 * bail out if the filesystem is corrupted.
1455 */
1456 if (error == EFSCORRUPTED) {
1457 if (!mount_locked) {
1458 XFS_MOUNT_ILOCK(mp);
1459 IPOINTER_REMOVE(ip, mp);
1460 }
1461 XFS_MOUNT_IUNLOCK(mp);
1462 ASSERT(ipointer_in == B_FALSE);
1463 kmem_free(ipointer, sizeof(xfs_iptr_t));
1464 return XFS_ERROR(error);
1465 }
1466
1467 /* Let other threads have a chance at the mount lock
1468 * if we have looped many times without dropping the
1469 * lock.
1470 */
1471 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1472 if (mount_locked) {
1473 IPOINTER_INSERT(ip, mp);
1474 }
1475 }
1476
1477 if (mount_locked == B_FALSE) {
1478 XFS_MOUNT_ILOCK(mp);
1479 mount_locked = B_TRUE;
1480 IPOINTER_REMOVE(ip, mp);
1481 continue;
1482 }
1483
1484 ASSERT(ipointer_in == B_FALSE);
1485 ip = ip->i_mnext;
1486
1487 } while (ip != mp->m_inodes);
1488
1489 XFS_MOUNT_IUNLOCK(mp);
1490
1491 ASSERT(ipointer_in == B_FALSE);
1492
1493 kmem_free(ipointer, sizeof(xfs_iptr_t));
1494 return XFS_ERROR(last_error);
1495}
1496
1497/*
1498 * xfs sync routine for internal use
1499 *
Nathan Scottb83bd132006-06-09 16:48:30 +10001500 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001501 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 *
1503 */
1504int
1505xfs_syncsub(
1506 xfs_mount_t *mp,
1507 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 int *bypassed)
1509{
1510 int error = 0;
1511 int last_error = 0;
1512 uint log_flags = XFS_LOG_FORCE;
1513 xfs_buf_t *bp;
1514 xfs_buf_log_item_t *bip;
1515
1516 /*
1517 * Sync out the log. This ensures that the log is periodically
1518 * flushed even if there is not enough activity to fill it up.
1519 */
1520 if (flags & SYNC_WAIT)
1521 log_flags |= XFS_LOG_SYNC;
1522
1523 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1524
1525 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1526 if (flags & SYNC_BDFLUSH)
1527 xfs_finish_reclaim_all(mp, 1);
1528 else
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001529 error = xfs_sync_inodes(mp, flags, bypassed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 }
1531
1532 /*
1533 * Flushing out dirty data above probably generated more
1534 * log activity, so if this isn't vfs_sync() then flush
1535 * the log again.
1536 */
1537 if (flags & SYNC_DELWRI) {
1538 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1539 }
1540
1541 if (flags & SYNC_FSDATA) {
1542 /*
1543 * If this is vfs_sync() then only sync the superblock
1544 * if we can lock it without sleeping and it is not pinned.
1545 */
1546 if (flags & SYNC_BDFLUSH) {
1547 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1548 if (bp != NULL) {
1549 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1550 if ((bip != NULL) &&
1551 xfs_buf_item_dirty(bip)) {
1552 if (!(XFS_BUF_ISPINNED(bp))) {
1553 XFS_BUF_ASYNC(bp);
1554 error = xfs_bwrite(mp, bp);
1555 } else {
1556 xfs_buf_relse(bp);
1557 }
1558 } else {
1559 xfs_buf_relse(bp);
1560 }
1561 }
1562 } else {
1563 bp = xfs_getsb(mp, 0);
1564 /*
1565 * If the buffer is pinned then push on the log so
1566 * we won't get stuck waiting in the write for
1567 * someone, maybe ourselves, to flush the log.
1568 * Even though we just pushed the log above, we
1569 * did not have the superblock buffer locked at
1570 * that point so it can become pinned in between
1571 * there and here.
1572 */
1573 if (XFS_BUF_ISPINNED(bp))
1574 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1575 if (flags & SYNC_WAIT)
1576 XFS_BUF_UNASYNC(bp);
1577 else
1578 XFS_BUF_ASYNC(bp);
1579 error = xfs_bwrite(mp, bp);
1580 }
1581 if (error) {
1582 last_error = error;
1583 }
1584 }
1585
1586 /*
1587 * If this is the periodic sync, then kick some entries out of
1588 * the reference cache. This ensures that idle entries are
1589 * eventually kicked out of the cache.
1590 */
1591 if (flags & SYNC_REFCACHE) {
Nathan Scottcde410a2005-09-05 11:47:01 +10001592 if (flags & SYNC_WAIT)
1593 xfs_refcache_purge_mp(mp);
1594 else
1595 xfs_refcache_purge_some(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 }
1597
1598 /*
David Chinner92821e22007-05-24 15:26:31 +10001599 * If asked, update the disk superblock with incore counter values if we
1600 * are using non-persistent counters so that they don't get too far out
1601 * of sync if we crash or get a forced shutdown. We don't want to force
1602 * this to disk, just get a transaction into the iclogs....
1603 */
1604 if (flags & SYNC_SUPER)
1605 xfs_log_sbcount(mp, 0);
1606
1607 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 * Now check to see if the log needs a "dummy" transaction.
1609 */
1610
1611 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1612 xfs_trans_t *tp;
1613 xfs_inode_t *ip;
1614
1615 /*
1616 * Put a dummy transaction in the log to tell
1617 * recovery that all others are OK.
1618 */
1619 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1620 if ((error = xfs_trans_reserve(tp, 0,
1621 XFS_ICHANGE_LOG_RES(mp),
1622 0, 0, 0))) {
1623 xfs_trans_cancel(tp, 0);
1624 return error;
1625 }
1626
1627 ip = mp->m_rootip;
1628 xfs_ilock(ip, XFS_ILOCK_EXCL);
1629
1630 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1631 xfs_trans_ihold(tp, ip);
1632 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
Eric Sandeen1c72bf92007-05-08 13:48:42 +10001633 error = xfs_trans_commit(tp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1635 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1636 }
1637
1638 /*
1639 * When shutting down, we need to insure that the AIL is pushed
1640 * to disk or the filesystem can appear corrupt from the PROM.
1641 */
1642 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1643 XFS_bflush(mp->m_ddev_targp);
1644 if (mp->m_rtdev_targp) {
1645 XFS_bflush(mp->m_rtdev_targp);
1646 }
1647 }
1648
1649 return XFS_ERROR(last_error);
1650}
1651
1652/*
1653 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1654 */
1655STATIC int
1656xfs_vget(
1657 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001658 bhv_vnode_t **vpp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 fid_t *fidp)
1660{
1661 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1662 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1663 xfs_inode_t *ip;
1664 int error;
1665 xfs_ino_t ino;
1666 unsigned int igen;
1667
1668 /*
1669 * Invalid. Since handles can be created in user space and passed in
1670 * via gethandle(), this is not cause for a panic.
1671 */
1672 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1673 return XFS_ERROR(EINVAL);
1674
1675 ino = xfid->xfs_fid_ino;
1676 igen = xfid->xfs_fid_gen;
1677
1678 /*
1679 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1680 */
1681 if (ino == 0)
1682 return XFS_ERROR(ESTALE);
1683
1684 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1685 if (error) {
1686 *vpp = NULL;
1687 return error;
1688 }
1689
1690 if (ip == NULL) {
1691 *vpp = NULL;
1692 return XFS_ERROR(EIO);
1693 }
1694
1695 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1696 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1697 *vpp = NULL;
1698 return XFS_ERROR(ENOENT);
1699 }
1700
1701 *vpp = XFS_ITOV(ip);
1702 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1703 return 0;
1704}
1705
1706
1707#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1708#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1709#define MNTOPT_LOGDEV "logdev" /* log device */
1710#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1711#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1712#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1713#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1714#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1715#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1716#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1717#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1718#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1719#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
Nathan Scotte69a3332005-09-02 16:42:26 +10001720#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1721#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1722#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1723#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
Nathan Scott1f443ad2005-05-05 13:28:29 -07001724#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001726#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
Nathan Scottd8cc8902005-11-02 10:34:53 +11001727 * unwritten extent conversion */
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001728#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1730#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1731#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1732#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
David Chinnere8c8b3a2005-11-02 10:33:05 +11001733#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1734#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1735 * in stat(). */
Nathan Scottd8cc8902005-11-02 10:34:53 +11001736#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1737#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
David Chinner2a82b8b2007-07-11 11:09:12 +10001738#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001739#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
1740#define MNTOPT_NOQUOTA "noquota" /* no quotas */
1741#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
1742#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
1743#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
1744#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
1745#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
1746#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
1747#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
1748#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
1749#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
1750#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
Christoph Hellwig293688e2007-08-29 11:59:36 +10001751#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
1752#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
1753#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Nathan Scott1f443ad2005-05-05 13:28:29 -07001755STATIC unsigned long
Nathan Scottb190f112006-06-09 17:13:15 +10001756suffix_strtoul(char *s, char **endp, unsigned int base)
Nathan Scott1f443ad2005-05-05 13:28:29 -07001757{
1758 int last, shift_left_factor = 0;
Nathan Scottb190f112006-06-09 17:13:15 +10001759 char *value = s;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001760
1761 last = strlen(value) - 1;
1762 if (value[last] == 'K' || value[last] == 'k') {
1763 shift_left_factor = 10;
1764 value[last] = '\0';
1765 }
1766 if (value[last] == 'M' || value[last] == 'm') {
1767 shift_left_factor = 20;
1768 value[last] = '\0';
1769 }
1770 if (value[last] == 'G' || value[last] == 'g') {
1771 shift_left_factor = 30;
1772 value[last] = '\0';
1773 }
1774
Nathan Scottb190f112006-06-09 17:13:15 +10001775 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001776}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10001778STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779xfs_parseargs(
1780 struct bhv_desc *bhv,
1781 char *options,
1782 struct xfs_mount_args *args,
1783 int update)
1784{
Nathan Scottb83bd132006-06-09 16:48:30 +10001785 bhv_vfs_t *vfsp = bhvtovfs(bhv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 char *this_char, *value, *eov;
1787 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1788 int iosize;
1789
Vlad Apostolovb93bd202007-08-28 14:00:28 +10001790 /*
1791 * Applications using DMI filesystems often expect the
1792 * inode generation number to be monotonically increasing.
1793 * If we delete inode chunks we break this assumption, so
1794 * keep unused inode chunks on disk for DMI filesystems
1795 * until we come up with a better solution.
1796 * Note that if "ikeep" or "noikeep" mount options are
1797 * supplied, then they are honored.
1798 */
1799 if (!(args->flags & XFSMNT_DMAPI))
1800 args->flags |= XFSMNT_IDELETE;
1801
Nathan Scott3bbcc8e2006-03-31 13:04:56 +10001802 args->flags |= XFSMNT_BARRIER;
1803 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 if (!options)
Nathan Scott05db2182005-11-04 09:49:07 +11001806 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
1808 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1809
1810 while ((this_char = strsep(&options, ",")) != NULL) {
1811 if (!*this_char)
1812 continue;
1813 if ((value = strchr(this_char, '=')) != NULL)
1814 *value++ = 0;
1815
1816 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1817 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001818 cmn_err(CE_WARN,
1819 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001820 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 return EINVAL;
1822 }
1823 args->logbufs = simple_strtoul(value, &eov, 10);
1824 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001826 cmn_err(CE_WARN,
1827 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001828 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 return EINVAL;
1830 }
Nathan Scott1f443ad2005-05-05 13:28:29 -07001831 args->logbufsize = suffix_strtoul(value, &eov, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1833 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001834 cmn_err(CE_WARN,
1835 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001836 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 return EINVAL;
1838 }
1839 strncpy(args->logname, value, MAXNAMELEN);
1840 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1841 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001842 cmn_err(CE_WARN,
1843 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001844 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 return EINVAL;
1846 }
1847 strncpy(args->mtpt, value, MAXNAMELEN);
1848 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
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 strncpy(args->rtname, value, MAXNAMELEN);
1856 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
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 iosize = simple_strtoul(value, &eov, 10);
1864 args->flags |= XFSMNT_IOSIZE;
1865 args->iosizelog = (uint8_t) iosize;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001866 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1867 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001868 cmn_err(CE_WARN,
1869 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001870 this_char);
1871 return EINVAL;
1872 }
1873 iosize = suffix_strtoul(value, &eov, 10);
1874 args->flags |= XFSMNT_IOSIZE;
1875 args->iosizelog = ffs(iosize) - 1;
Nathan Scotte69a3332005-09-02 16:42:26 +10001876 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1877 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1878 vfsp->vfs_flag |= VFS_GRPID;
1879 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1880 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1881 vfsp->vfs_flag &= ~VFS_GRPID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1883 args->flags |= XFSMNT_WSYNC;
1884 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1885 args->flags |= XFSMNT_OSYNCISOSYNC;
1886 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1887 args->flags |= XFSMNT_NORECOVERY;
1888 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1889 args->flags |= XFSMNT_INO64;
1890#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001891 cmn_err(CE_WARN,
1892 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001893 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 return EINVAL;
1895#endif
1896 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1897 args->flags |= XFSMNT_NOALIGN;
1898 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1899 args->flags |= XFSMNT_SWALLOC;
1900 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1901 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001902 cmn_err(CE_WARN,
1903 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001904 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 return EINVAL;
1906 }
1907 dsunit = simple_strtoul(value, &eov, 10);
1908 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1909 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001910 cmn_err(CE_WARN,
1911 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001912 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 return EINVAL;
1914 }
1915 dswidth = simple_strtoul(value, &eov, 10);
1916 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1917 args->flags &= ~XFSMNT_32BITINODES;
1918#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001919 cmn_err(CE_WARN,
1920 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001921 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 return EINVAL;
1923#endif
1924 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1925 args->flags |= XFSMNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001926 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1927 args->flags |= XFSMNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001928 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1929 args->flags &= ~XFSMNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1931 args->flags &= ~XFSMNT_IDELETE;
1932 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1933 args->flags |= XFSMNT_IDELETE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001934 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Nathan Scotte718eeb2005-11-02 15:09:22 +11001935 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001936 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Nathan Scotte718eeb2005-11-02 15:09:22 +11001937 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001938 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001939 args->flags |= XFSMNT_ATTR2;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001940 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001941 args->flags &= ~XFSMNT_ATTR2;
David Chinner2a82b8b2007-07-11 11:09:12 +10001942 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1943 args->flags2 |= XFSMNT2_FILESTREAMS;
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001944 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
1945 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
1946 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
1947 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
1948 !strcmp(this_char, MNTOPT_UQUOTA) ||
1949 !strcmp(this_char, MNTOPT_USRQUOTA)) {
1950 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
1951 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
1952 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
1953 args->flags |= XFSMNT_UQUOTA;
1954 args->flags &= ~XFSMNT_UQUOTAENF;
1955 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
1956 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
1957 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
1958 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
1959 args->flags |= XFSMNT_PQUOTA;
1960 args->flags &= ~XFSMNT_PQUOTAENF;
1961 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
1962 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
1963 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
1964 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
1965 args->flags |= XFSMNT_GQUOTA;
1966 args->flags &= ~XFSMNT_GQUOTAENF;
Christoph Hellwig293688e2007-08-29 11:59:36 +10001967 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
1968 args->flags |= XFSMNT_DMAPI;
1969 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
1970 args->flags |= XFSMNT_DMAPI;
1971 } else if (!strcmp(this_char, MNTOPT_DMI)) {
1972 args->flags |= XFSMNT_DMAPI;
David Chinnerda353b02007-08-28 14:00:13 +10001973 } else if (!strcmp(this_char, "ihashsize")) {
1974 cmn_err(CE_WARN,
1975 "XFS: ihashsize no longer used, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 } else if (!strcmp(this_char, "osyncisdsync")) {
1977 /* no-op, this is now the default */
Nathan Scottb6574522006-06-09 15:29:40 +10001978 cmn_err(CE_WARN,
1979 "XFS: osyncisdsync is now the default, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 } else if (!strcmp(this_char, "irixsgid")) {
Nathan Scottb6574522006-06-09 15:29:40 +10001981 cmn_err(CE_WARN,
1982 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 } else {
Nathan Scottb6574522006-06-09 15:29:40 +10001984 cmn_err(CE_WARN,
1985 "XFS: unknown mount option [%s].", this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 return EINVAL;
1987 }
1988 }
1989
1990 if (args->flags & XFSMNT_NORECOVERY) {
1991 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
Nathan Scottb6574522006-06-09 15:29:40 +10001992 cmn_err(CE_WARN,
1993 "XFS: no-recovery mounts must be read-only.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 return EINVAL;
1995 }
1996 }
1997
1998 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001999 cmn_err(CE_WARN,
2000 "XFS: sunit and swidth options incompatible with the noalign option");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 return EINVAL;
2002 }
2003
Christoph Hellwigb09cc772007-08-30 17:19:57 +10002004 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
2005 cmn_err(CE_WARN,
2006 "XFS: cannot mount with both project and group quota");
2007 return EINVAL;
2008 }
2009
Christoph Hellwig293688e2007-08-29 11:59:36 +10002010 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
2011 printk("XFS: %s option needs the mount point option as well\n",
2012 MNTOPT_DMAPI);
2013 return EINVAL;
2014 }
2015
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10002017 cmn_err(CE_WARN,
2018 "XFS: sunit and swidth must be specified together");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 return EINVAL;
2020 }
2021
2022 if (dsunit && (dswidth % dsunit != 0)) {
Nathan Scottb6574522006-06-09 15:29:40 +10002023 cmn_err(CE_WARN,
2024 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 dswidth, dsunit);
2026 return EINVAL;
2027 }
2028
2029 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
2030 if (dsunit) {
2031 args->sunit = dsunit;
2032 args->flags |= XFSMNT_RETERR;
2033 } else {
2034 args->sunit = vol_dsunit;
2035 }
2036 dswidth ? (args->swidth = dswidth) :
2037 (args->swidth = vol_dswidth);
2038 } else {
2039 args->sunit = args->swidth = 0;
2040 }
2041
Nathan Scott05db2182005-11-04 09:49:07 +11002042done:
Nathan Scottc11e2c32005-11-02 15:11:45 +11002043 if (args->flags & XFSMNT_32BITINODES)
2044 vfsp->vfs_flag |= VFS_32BITINODES;
Nathan Scotte718eeb2005-11-02 15:09:22 +11002045 if (args->flags2)
2046 args->flags |= XFSMNT_FLAGS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 return 0;
2048}
2049
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10002050STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051xfs_showargs(
2052 struct bhv_desc *bhv,
2053 struct seq_file *m)
2054{
2055 static struct proc_xfs_info {
2056 int flag;
2057 char *str;
2058 } xfs_info[] = {
2059 /* the few simple ones we can get from the mount struct */
2060 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
2061 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
2062 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
2063 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
2064 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
2065 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
2066 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 { 0, NULL }
2068 };
2069 struct proc_xfs_info *xfs_infop;
2070 struct xfs_mount *mp = XFS_BHVTOM(bhv);
Nathan Scottb83bd132006-06-09 16:48:30 +10002071 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072
2073 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
2074 if (mp->m_flags & xfs_infop->flag)
2075 seq_puts(m, xfs_infop->str);
2076 }
2077
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11002079 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
2080 (int)(1 << mp->m_writeio_log) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
2082 if (mp->m_logbufs > 0)
2083 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 if (mp->m_logbsize > 0)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11002085 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086
Nathan Scottfc1f8c12005-11-02 11:44:33 +11002087 if (mp->m_logname)
2088 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +11002089 if (mp->m_rtname)
2090 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
2092 if (mp->m_dalign > 0)
2093 seq_printf(m, "," MNTOPT_SUNIT "=%d",
2094 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 if (mp->m_swidth > 0)
2096 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
2097 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
2098
Nathan Scotte15f1952006-03-22 12:47:52 +11002099 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
2100 seq_printf(m, "," MNTOPT_IKEEP);
Nathan Scottfa7e7d72005-11-02 15:00:48 +11002101 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
2102 seq_printf(m, "," MNTOPT_LARGEIO);
2103
Nathan Scottc11e2c32005-11-02 15:11:45 +11002104 if (!(vfsp->vfs_flag & VFS_32BITINODES))
2105 seq_printf(m, "," MNTOPT_64BITINODE);
Nathan Scotte69a3332005-09-02 16:42:26 +10002106 if (vfsp->vfs_flag & VFS_GRPID)
2107 seq_printf(m, "," MNTOPT_GRPID);
2108
Christoph Hellwigb09cc772007-08-30 17:19:57 +10002109 if (mp->m_qflags & XFS_UQUOTA_ACCT) {
2110 if (mp->m_qflags & XFS_UQUOTA_ENFD)
2111 seq_puts(m, "," MNTOPT_USRQUOTA);
2112 else
2113 seq_puts(m, "," MNTOPT_UQUOTANOENF);
2114 }
2115
2116 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
2117 if (mp->m_qflags & XFS_OQUOTA_ENFD)
2118 seq_puts(m, "," MNTOPT_PRJQUOTA);
2119 else
2120 seq_puts(m, "," MNTOPT_PQUOTANOENF);
2121 }
2122
2123 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
2124 if (mp->m_qflags & XFS_OQUOTA_ENFD)
2125 seq_puts(m, "," MNTOPT_GRPQUOTA);
2126 else
2127 seq_puts(m, "," MNTOPT_GQUOTANOENF);
2128 }
2129
2130 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
2131 seq_puts(m, "," MNTOPT_NOQUOTA);
2132
Christoph Hellwig293688e2007-08-29 11:59:36 +10002133 if (vfsp->vfs_flag & VFS_DMI)
2134 seq_puts(m, "," MNTOPT_DMAPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 return 0;
2136}
2137
David Chinner28239452007-02-10 18:36:40 +11002138/*
David Chinner516b2e72007-06-18 16:50:48 +10002139 * Second stage of a freeze. The data is already frozen so we only
2140 * need to take care of themetadata. Once that's done write a dummy
2141 * record to dirty the log in case of a crash while frozen.
David Chinner28239452007-02-10 18:36:40 +11002142 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143STATIC void
2144xfs_freeze(
2145 bhv_desc_t *bdp)
2146{
2147 xfs_mount_t *mp = XFS_BHVTOM(bdp);
2148
David Chinner516b2e72007-06-18 16:50:48 +10002149 xfs_attr_quiesce(mp);
Christoph Hellwige13a73f2006-01-11 15:30:08 +11002150 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151}
2152
2153
Nathan Scottb83bd132006-06-09 16:48:30 +10002154bhv_vfsops_t xfs_vfsops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
2156 .vfs_parseargs = xfs_parseargs,
2157 .vfs_showargs = xfs_showargs,
2158 .vfs_mount = xfs_mount,
2159 .vfs_unmount = xfs_unmount,
2160 .vfs_mntupdate = xfs_mntupdate,
2161 .vfs_root = xfs_root,
2162 .vfs_statvfs = xfs_statvfs,
2163 .vfs_sync = xfs_sync,
2164 .vfs_vget = xfs_vget,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
2166 .vfs_init_vnode = xfs_initialize_vnode,
2167 .vfs_force_shutdown = xfs_do_force_shutdown,
2168 .vfs_freeze = xfs_freeze,
2169};