blob: 0f237f9f0c3a08fe49468262e2623672a097f4e9 [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(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 struct xfs_mount_args *ap,
215 struct xfs_mount *mp)
216{
217 /* Values are in BBs */
218 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
219 /*
220 * At this point the superblock has not been read
221 * in, therefore we do not know the block size.
222 * Before the mount call ends we will convert
223 * these to FSBs.
224 */
225 mp->m_dalign = ap->sunit;
226 mp->m_swidth = ap->swidth;
227 }
228
229 if (ap->logbufs != -1 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 ap->logbufs != 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 (ap->logbufs < XLOG_MIN_ICLOGS ||
232 ap->logbufs > XLOG_MAX_ICLOGS)) {
233 cmn_err(CE_WARN,
234 "XFS: invalid logbufs value: %d [not %d-%d]",
235 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
236 return XFS_ERROR(EINVAL);
237 }
238 mp->m_logbufs = ap->logbufs;
239 if (ap->logbufsize != -1 &&
Nathan Scottcfcbbbd2005-11-02 15:12:04 +1100240 ap->logbufsize != 0 &&
Eric Sandeendcb3b832007-08-16 16:25:33 +1000241 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
242 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
243 !is_power_of_2(ap->logbufsize))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 cmn_err(CE_WARN,
245 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
246 ap->logbufsize);
247 return XFS_ERROR(EINVAL);
248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 mp->m_logbsize = ap->logbufsize;
250 mp->m_fsname_len = strlen(ap->fsname) + 1;
251 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
252 strcpy(mp->m_fsname, ap->fsname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +1100253 if (ap->rtname[0]) {
254 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
255 strcpy(mp->m_rtname, ap->rtname);
256 }
257 if (ap->logname[0]) {
258 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
259 strcpy(mp->m_logname, ap->logname);
260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 if (ap->flags & XFSMNT_WSYNC)
263 mp->m_flags |= XFS_MOUNT_WSYNC;
264#if XFS_BIG_INUMS
265 if (ap->flags & XFSMNT_INO64) {
266 mp->m_flags |= XFS_MOUNT_INO64;
267 mp->m_inoadd = XFS_INO64_OFFSET;
268 }
269#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 if (ap->flags & XFSMNT_RETERR)
271 mp->m_flags |= XFS_MOUNT_RETERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (ap->flags & XFSMNT_NOALIGN)
273 mp->m_flags |= XFS_MOUNT_NOALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (ap->flags & XFSMNT_SWALLOC)
275 mp->m_flags |= XFS_MOUNT_SWALLOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (ap->flags & XFSMNT_OSYNCISOSYNC)
277 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 if (ap->flags & XFSMNT_32BITINODES)
Nathan Scottc11e2c32005-11-02 15:11:45 +1100279 mp->m_flags |= XFS_MOUNT_32BITINODES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 if (ap->flags & XFSMNT_IOSIZE) {
282 if (ap->iosizelog > XFS_MAX_IO_LOG ||
283 ap->iosizelog < XFS_MIN_IO_LOG) {
284 cmn_err(CE_WARN,
285 "XFS: invalid log iosize: %d [not %d-%d]",
286 ap->iosizelog, XFS_MIN_IO_LOG,
287 XFS_MAX_IO_LOG);
288 return XFS_ERROR(EINVAL);
289 }
290
291 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
292 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
293 }
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (ap->flags & XFSMNT_IDELETE)
296 mp->m_flags |= XFS_MOUNT_IDELETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 if (ap->flags & XFSMNT_DIRSYNC)
298 mp->m_flags |= XFS_MOUNT_DIRSYNC;
Nathan Scott13059ff2006-01-11 15:32:01 +1100299 if (ap->flags & XFSMNT_ATTR2)
300 mp->m_flags |= XFS_MOUNT_ATTR2;
David Chinnere8c8b3a2005-11-02 10:33:05 +1100301
Nathan Scotte718eeb42005-11-02 15:09:22 +1100302 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
303 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 /*
306 * no recovery flag requires a read-only mount
307 */
308 if (ap->flags & XFSMNT_NORECOVERY) {
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000309 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 cmn_err(CE_WARN,
311 "XFS: tried to mount a FS read-write without recovery!");
312 return XFS_ERROR(EINVAL);
313 }
314 mp->m_flags |= XFS_MOUNT_NORECOVERY;
315 }
316
317 if (ap->flags & XFSMNT_NOUUID)
318 mp->m_flags |= XFS_MOUNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100319 if (ap->flags & XFSMNT_BARRIER)
320 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100321 else
322 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
David Chinner2a82b8b2007-07-11 11:09:12 +1000324 if (ap->flags2 & XFSMNT2_FILESTREAMS)
325 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
326
Christoph Hellwig293688e2007-08-29 11:59:36 +1000327 if (ap->flags & XFSMNT_DMAPI)
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000328 mp->m_flags |= XFS_MOUNT_DMAPI;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 return 0;
330}
331
332/*
333 * This function fills in xfs_mount_t fields based on mount args.
334 * Note: the superblock _has_ now been read in.
335 */
336STATIC int
337xfs_finish_flags(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 struct xfs_mount_args *ap,
339 struct xfs_mount *mp)
340{
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000341 int ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 /* Fail a mount where the logbuf is smaller then the log stripe */
344 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
Nathan Scottc2cd2552006-01-11 15:35:32 +1100345 if ((ap->logbufsize <= 0) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
347 mp->m_logbsize = mp->m_sb.sb_logsunit;
Nathan Scottc2cd2552006-01-11 15:35:32 +1100348 } else if (ap->logbufsize > 0 &&
349 ap->logbufsize < mp->m_sb.sb_logsunit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 cmn_err(CE_WARN,
351 "XFS: logbuf size must be greater than or equal to log stripe size");
352 return XFS_ERROR(EINVAL);
353 }
354 } else {
355 /* Fail a mount if the logbuf is larger than 32K */
356 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
357 cmn_err(CE_WARN,
358 "XFS: logbuf size for version 1 logs must be 16K or 32K");
359 return XFS_ERROR(EINVAL);
360 }
361 }
362
Nathan Scott13059ff2006-01-11 15:32:01 +1100363 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
364 mp->m_flags |= XFS_MOUNT_ATTR2;
365 }
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /*
368 * prohibit r/w mounts of read-only filesystems
369 */
370 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
371 cmn_err(CE_WARN,
372 "XFS: cannot mount a read-only filesystem as read-write");
373 return XFS_ERROR(EROFS);
374 }
375
376 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 * check for shared mount.
378 */
379 if (ap->flags & XFSMNT_SHARED) {
380 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
381 return XFS_ERROR(EINVAL);
382
383 /*
384 * For IRIX 6.5, shared mounts must have the shared
385 * version bit set, have the persistent readonly
386 * field set, must be version 0 and can only be mounted
387 * read-only.
388 */
389 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
390 (mp->m_sb.sb_shared_vn != 0))
391 return XFS_ERROR(EINVAL);
392
393 mp->m_flags |= XFS_MOUNT_SHARED;
394
395 /*
396 * Shared XFS V0 can't deal with DMI. Return EINVAL.
397 */
398 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
399 return XFS_ERROR(EINVAL);
400 }
401
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000402 if (ap->flags & XFSMNT_UQUOTA) {
403 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
404 if (ap->flags & XFSMNT_UQUOTAENF)
405 mp->m_qflags |= XFS_UQUOTA_ENFD;
406 }
407
408 if (ap->flags & XFSMNT_GQUOTA) {
409 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
410 if (ap->flags & XFSMNT_GQUOTAENF)
411 mp->m_qflags |= XFS_OQUOTA_ENFD;
412 } else if (ap->flags & XFSMNT_PQUOTA) {
413 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
414 if (ap->flags & XFSMNT_PQUOTAENF)
415 mp->m_qflags |= XFS_OQUOTA_ENFD;
416 }
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return 0;
419}
420
421/*
422 * xfs_mount
423 *
424 * The file system configurations are:
425 * (1) device (partition) with data and internal log
426 * (2) logical volume with data and log subvolumes.
427 * (3) logical volume with data, log, and realtime subvolumes.
428 *
429 * We only have to handle opening the log and realtime volumes here if
430 * they are present. The data subvolume has already been opened by
431 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
432 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000433int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434xfs_mount(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000435 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 struct xfs_mount_args *args,
437 cred_t *credp)
438{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 struct block_device *ddev, *logdev, *rtdev;
440 int flags = 0, error;
441
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000442 ddev = mp->m_super->s_bdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 logdev = rtdev = NULL;
444
Christoph Hellwig293688e2007-08-29 11:59:36 +1000445 error = xfs_dmops_get(mp, args);
446 if (error)
447 return error;
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000448 error = xfs_qmops_get(mp, args);
449 if (error)
450 return error;
Christoph Hellwig293688e2007-08-29 11:59:36 +1000451
Christoph Hellwig745f6912007-08-30 17:20:39 +1000452 mp->m_io_ops = xfs_iocore_xfs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Nathan Scott764d1f82006-03-31 13:04:17 +1000454 if (args->flags & XFSMNT_QUIET)
455 flags |= XFS_MFSI_QUIET;
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 /*
458 * Open real time and log devices - order is important.
459 */
460 if (args->logname[0]) {
461 error = xfs_blkdev_get(mp, args->logname, &logdev);
462 if (error)
463 return error;
464 }
465 if (args->rtname[0]) {
466 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
467 if (error) {
468 xfs_blkdev_put(logdev);
469 return error;
470 }
471
472 if (rtdev == ddev || rtdev == logdev) {
473 cmn_err(CE_WARN,
474 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
475 xfs_blkdev_put(logdev);
476 xfs_blkdev_put(rtdev);
477 return EINVAL;
478 }
479 }
480
481 /*
482 * Setup xfs_mount buffer target pointers
483 */
484 error = ENOMEM;
485 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
486 if (!mp->m_ddev_targp) {
487 xfs_blkdev_put(logdev);
488 xfs_blkdev_put(rtdev);
489 return error;
490 }
491 if (rtdev) {
492 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000493 if (!mp->m_rtdev_targp) {
494 xfs_blkdev_put(logdev);
495 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499 mp->m_logdev_targp = (logdev && logdev != ddev) ?
500 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000501 if (!mp->m_logdev_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 /*
508 * Setup flags based on mount(2) options and then the superblock
509 */
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000510 error = xfs_start_flags(args, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 if (error)
512 goto error1;
Nathan Scott764d1f82006-03-31 13:04:17 +1000513 error = xfs_readsb(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 if (error)
515 goto error1;
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000516 error = xfs_finish_flags(args, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (error)
518 goto error2;
519
520 /*
521 * Setup xfs_mount buffer target pointers based on superblock
522 */
523 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
524 mp->m_sb.sb_sectsize);
525 if (!error && logdev && logdev != ddev) {
526 unsigned int log_sector_size = BBSIZE;
527
528 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
529 log_sector_size = mp->m_sb.sb_logsectsize;
530 error = xfs_setsize_buftarg(mp->m_logdev_targp,
531 mp->m_sb.sb_blocksize,
532 log_sector_size);
533 }
534 if (!error && rtdev)
535 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
536 mp->m_sb.sb_blocksize,
537 mp->m_sb.sb_sectsize);
538 if (error)
539 goto error2;
540
Nathan Scottb2ea4012006-07-28 17:05:13 +1000541 if (mp->m_flags & XFS_MOUNT_BARRIER)
Christoph Hellwigc7d437d2006-01-11 15:28:56 +1100542 xfs_mountfs_check_barriers(mp);
543
David Chinner2a82b8b2007-07-11 11:09:12 +1000544 if ((error = xfs_filestream_mount(mp)))
545 goto error2;
546
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000547 error = XFS_IOINIT(mp, args, flags);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100548 if (error)
549 goto error2;
550
Christoph Hellwig293688e2007-08-29 11:59:36 +1000551 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
552
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100553 return 0;
554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555error2:
556 if (mp->m_sb_bp)
557 xfs_freesb(mp);
558error1:
559 xfs_binval(mp->m_ddev_targp);
560 if (logdev && logdev != ddev)
561 xfs_binval(mp->m_logdev_targp);
562 if (rtdev)
563 xfs_binval(mp->m_rtdev_targp);
564error0:
565 xfs_unmountfs_close(mp, credp);
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000566 xfs_qmops_put(mp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000567 xfs_dmops_put(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 return error;
569}
570
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000571int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572xfs_unmount(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000573 xfs_mount_t *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 int flags,
575 cred_t *credp)
576{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 xfs_inode_t *rip;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000578 bhv_vnode_t *rvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 int unmount_event_wanted = 0;
580 int unmount_event_flags = 0;
581 int xfs_unmountfs_needed = 0;
582 int error;
583
584 rip = mp->m_rootip;
585 rvp = XFS_ITOV(rip);
586
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000587#ifdef HAVE_DMAPI
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000588 if (mp->m_flags & XFS_MOUNT_DMAPI) {
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000589 error = XFS_SEND_PREUNMOUNT(mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
591 NULL, NULL, 0, 0,
592 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
593 0:DM_FLAGS_UNWANTED);
594 if (error)
595 return XFS_ERROR(error);
596 unmount_event_wanted = 1;
597 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
598 0 : DM_FLAGS_UNWANTED;
599 }
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000600#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 /*
602 * First blow any referenced inode from this file system
603 * out of the reference cache, and delete the timer.
604 */
605 xfs_refcache_purge_mp(mp);
606
David Chinner2a82b8b2007-07-11 11:09:12 +1000607 /*
608 * Blow away any referenced inode in the filestreams cache.
609 * This can and will cause log traffic as inodes go inactive
610 * here.
611 */
612 xfs_filestream_unmount(mp);
613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 XFS_bflush(mp->m_ddev_targp);
615 error = xfs_unmount_flush(mp, 0);
616 if (error)
617 goto out;
618
619 ASSERT(vn_count(rvp) == 1);
620
621 /*
622 * Drop the reference count
623 */
624 VN_RELE(rvp);
625
626 /*
627 * If we're forcing a shutdown, typically because of a media error,
628 * we want to make sure we invalidate dirty pages that belong to
629 * referenced vnodes as well.
630 */
631 if (XFS_FORCED_SHUTDOWN(mp)) {
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000632 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 ASSERT(error != EFSCORRUPTED);
634 }
635 xfs_unmountfs_needed = 1;
636
637out:
638 /* Send DMAPI event, if required.
639 * Then do xfs_unmountfs() if needed.
640 * Then return error (or zero).
641 */
642 if (unmount_event_wanted) {
643 /* Note: mp structure must still exist for
644 * XFS_SEND_UNMOUNT() call.
645 */
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000646 XFS_SEND_UNMOUNT(mp, error == 0 ? rvp : NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 DM_RIGHT_NULL, 0, error, unmount_event_flags);
648 }
649 if (xfs_unmountfs_needed) {
650 /*
651 * Call common unmount function to flush to disk
652 * and free the super block buffer & mount structures.
653 */
654 xfs_unmountfs(mp, credp);
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000655 xfs_qmops_put(mp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000656 xfs_dmops_put(mp);
Christoph Hellwigf541d272007-08-29 11:53:22 +1000657 kmem_free(mp, sizeof(xfs_mount_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
659
660 return XFS_ERROR(error);
661}
662
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000663STATIC int
664xfs_quiesce_fs(
665 xfs_mount_t *mp)
666{
667 int count = 0, pincount;
Nathan Scott3758dee2006-03-22 12:47:28 +1100668
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000669 xfs_refcache_purge_mp(mp);
670 xfs_flush_buftarg(mp->m_ddev_targp, 0);
671 xfs_finish_reclaim_all(mp, 0);
672
673 /* This loop must run at least twice.
674 * The first instance of the loop will flush
675 * most meta data but that will generate more
676 * meta data (typically directory updates).
677 * Which then must be flushed and logged before
678 * we can write the unmount record.
Nathan Scott3758dee2006-03-22 12:47:28 +1100679 */
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000680 do {
David Chinner516b2e72007-06-18 16:50:48 +1000681 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000682 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
683 if (!pincount) {
684 delay(50);
685 count++;
686 }
687 } while (count < 2);
688
689 return 0;
690}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
David Chinner516b2e72007-06-18 16:50:48 +1000692/*
693 * Second stage of a quiesce. The data is already synced, now we have to take
694 * care of the metadata. New transactions are already blocked, so we need to
695 * wait for any remaining transactions to drain out before proceding.
696 */
697STATIC void
698xfs_attr_quiesce(
699 xfs_mount_t *mp)
700{
701 /* wait for all modifications to complete */
702 while (atomic_read(&mp->m_active_trans) > 0)
703 delay(100);
704
705 /* flush inodes and push all remaining buffers out to disk */
706 xfs_quiesce_fs(mp);
707
708 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
709
710 /* Push the superblock and write an unmount record */
711 xfs_log_sbcount(mp, 1);
712 xfs_log_unmount_write(mp);
713 xfs_unmountfs_writesb(mp);
714}
715
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000716int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717xfs_mntupdate(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000718 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 int *flags,
720 struct xfs_mount_args *args)
721{
Nathan Scottd08d3892006-05-08 19:51:28 +1000722 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000723 if (mp->m_flags & XFS_MOUNT_RDONLY)
724 mp->m_flags &= ~XFS_MOUNT_RDONLY;
Nathan Scottd08d3892006-05-08 19:51:28 +1000725 if (args->flags & XFSMNT_BARRIER) {
726 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100727 xfs_mountfs_check_barriers(mp);
Nathan Scottd08d3892006-05-08 19:51:28 +1000728 } else {
729 mp->m_flags &= ~XFS_MOUNT_BARRIER;
730 }
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000731 } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
David Chinner2a82b8b2007-07-11 11:09:12 +1000732 xfs_filestream_flush(mp);
Christoph Hellwig745f6912007-08-30 17:20:39 +1000733 xfs_sync(mp, SYNC_DATA_QUIESCE);
David Chinner516b2e72007-06-18 16:50:48 +1000734 xfs_attr_quiesce(mp);
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000735 mp->m_flags |= XFS_MOUNT_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 return 0;
738}
739
740/*
741 * xfs_unmount_flush implements a set of flush operation on special
742 * inodes, which are needed as a separate set of operations so that
743 * they can be called as part of relocation process.
744 */
745int
746xfs_unmount_flush(
747 xfs_mount_t *mp, /* Mount structure we are getting
748 rid of. */
749 int relocation) /* Called from vfs relocation. */
750{
751 xfs_inode_t *rip = mp->m_rootip;
752 xfs_inode_t *rbmip;
753 xfs_inode_t *rsumip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000754 bhv_vnode_t *rvp = XFS_ITOV(rip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 int error;
756
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000757 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 xfs_iflock(rip);
759
760 /*
761 * Flush out the real time inodes.
762 */
763 if ((rbmip = mp->m_rbmip) != NULL) {
764 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
765 xfs_iflock(rbmip);
766 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
767 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
768
769 if (error == EFSCORRUPTED)
770 goto fscorrupt_out;
771
772 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
773
774 rsumip = mp->m_rsumip;
775 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
776 xfs_iflock(rsumip);
777 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
778 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
779
780 if (error == EFSCORRUPTED)
781 goto fscorrupt_out;
782
783 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
784 }
785
786 /*
787 * Synchronously flush root inode to disk
788 */
789 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
790 if (error == EFSCORRUPTED)
791 goto fscorrupt_out2;
792
793 if (vn_count(rvp) != 1 && !relocation) {
794 xfs_iunlock(rip, XFS_ILOCK_EXCL);
795 return XFS_ERROR(EBUSY);
796 }
797
798 /*
799 * Release dquot that rootinode, rbmino and rsumino might be holding,
800 * flush and purge the quota inodes.
801 */
802 error = XFS_QM_UNMOUNT(mp);
803 if (error == EFSCORRUPTED)
804 goto fscorrupt_out2;
805
806 if (rbmip) {
807 VN_RELE(XFS_ITOV(rbmip));
808 VN_RELE(XFS_ITOV(rsumip));
809 }
810
811 xfs_iunlock(rip, XFS_ILOCK_EXCL);
812 return 0;
813
814fscorrupt_out:
815 xfs_ifunlock(rip);
816
817fscorrupt_out2:
818 xfs_iunlock(rip, XFS_ILOCK_EXCL);
819
820 return XFS_ERROR(EFSCORRUPTED);
821}
822
823/*
824 * xfs_root extracts the root vnode from a vfs.
825 *
826 * vfsp -- the vfs struct for the desired file system
827 * vpp -- address of the caller's vnode pointer which should be
828 * set to the desired fs root vnode
829 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000830int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831xfs_root(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000832 xfs_mount_t *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000833 bhv_vnode_t **vpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000835 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000837 vp = XFS_ITOV(mp->m_rootip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 VN_HOLD(vp);
839 *vpp = vp;
840 return 0;
841}
842
843/*
844 * xfs_statvfs
845 *
846 * Fill in the statvfs structure for the given file system. We use
847 * the superblock lock in the mount structure to ensure a consistent
848 * snapshot of the counters returned.
849 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000850int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851xfs_statvfs(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000852 xfs_mount_t *mp,
Nathan Scott8285fb52006-06-09 17:07:12 +1000853 bhv_statvfs_t *statp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000854 bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
856 __uint64_t fakeinos;
857 xfs_extlen_t lsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 xfs_sb_t *sbp;
859 unsigned long s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 sbp = &(mp->m_sb);
862
863 statp->f_type = XFS_SB_MAGIC;
864
David Chinnerdbcabad2007-02-10 18:36:17 +1100865 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 s = XFS_SB_LOCK(mp);
867 statp->f_bsize = sbp->sb_blocksize;
868 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
869 statp->f_blocks = sbp->sb_dblocks - lsize;
David Chinner4be536d2006-09-07 14:26:50 +1000870 statp->f_bfree = statp->f_bavail =
871 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 fakeinos = statp->f_bfree << sbp->sb_inopblog;
873#if XFS_BIG_INUMS
874 fakeinos += mp->m_inoadd;
875#endif
876 statp->f_files =
877 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
878 if (mp->m_maxicount)
879#if XFS_BIG_INUMS
880 if (!mp->m_inoadd)
881#endif
882 statp->f_files = min_t(typeof(statp->f_files),
883 statp->f_files,
884 mp->m_maxicount);
885 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
886 XFS_SB_UNLOCK(mp, s);
887
Nathan Scottcde410a2005-09-05 11:47:01 +1000888 xfs_statvfs_fsid(statp, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 statp->f_namelen = MAXNAMELEN - 1;
890
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000891 if (vp)
892 XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 return 0;
894}
895
896
897/*
898 * xfs_sync flushes any pending I/O to file system vfsp.
899 *
900 * This routine is called by vfs_sync() to make sure that things make it
901 * out to disk eventually, on sync() system calls to flush out everything,
902 * and when the file system is unmounted. For the vfs_sync() case, all
903 * we really need to do is sync out the log to make all of our meta-data
904 * updates permanent (except for timestamps). For calls from pflushd(),
905 * dirty pages are kept moving by calling pdflush() on the inodes
906 * containing them. We also flush the inodes that we can lock without
907 * sleeping and the superblock if we can lock it without sleeping from
908 * vfs_sync() so that items at the tail of the log are always moving out.
909 *
910 * Flags:
911 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
912 * to sleep if we can help it. All we really need
913 * to do is ensure that the log is synced at least
914 * periodically. We also push the inodes and
915 * superblock if we can lock them without sleeping
916 * and they are not pinned.
917 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
918 * set, then we really want to lock each inode and flush
919 * it.
920 * SYNC_WAIT - All the flushes that take place in this call should
921 * be synchronous.
922 * SYNC_DELWRI - This tells us to push dirty pages associated with
923 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
924 * determine if they should be flushed sync, async, or
925 * delwri.
926 * SYNC_CLOSE - This flag is passed when the system is being
Nathan Scottc41564b2006-03-29 08:55:14 +1000927 * unmounted. We should sync and invalidate everything.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 * SYNC_FSDATA - This indicates that the caller would like to make
929 * sure the superblock is safe on disk. We can ensure
Nathan Scottc41564b2006-03-29 08:55:14 +1000930 * this by simply making sure the log gets flushed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 * if SYNC_BDFLUSH is set, and by actually writing it
932 * out otherwise.
David Chinner3c0dc772007-02-10 18:37:22 +1100933 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
934 * before we return (including direct I/O). Forms the drain
935 * side of the write barrier needed to safely quiesce the
936 * filesystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 *
938 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000939int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940xfs_sync(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000941 xfs_mount_t *mp,
942 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000944 int error;
945
946 /*
947 * Get the Quota Manager to flush the dquots.
948 *
949 * If XFS quota support is not enabled or this filesystem
950 * instance does not use quotas XFS_QM_DQSYNC will always
951 * return zero.
952 */
953 error = XFS_QM_DQSYNC(mp, flags);
954 if (error) {
955 /*
956 * If we got an IO error, we will be shutting down.
957 * So, there's nothing more for us to do here.
958 */
959 ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
960 if (XFS_FORCED_SHUTDOWN(mp))
961 return XFS_ERROR(error);
962 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
David Chinner2a82b8b2007-07-11 11:09:12 +1000964 if (flags & SYNC_IOWAIT)
965 xfs_filestream_flush(mp);
966
David Chinner28239452007-02-10 18:36:40 +1100967 return xfs_syncsub(mp, flags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968}
969
970/*
971 * xfs sync routine for internal use
972 *
Nathan Scottb83bd132006-06-09 16:48:30 +1000973 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +1100974 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 *
976 */
Nathan Scottee348072005-11-02 10:32:38 +1100977int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978xfs_sync_inodes(
979 xfs_mount_t *mp,
980 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 int *bypassed)
982{
983 xfs_inode_t *ip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000984 bhv_vnode_t *vp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 int error;
986 int last_error;
987 uint64_t fflag;
988 uint lock_flags;
989 uint base_lock_flags;
990 boolean_t mount_locked;
991 boolean_t vnode_refed;
992 int preempt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 xfs_iptr_t *ipointer;
994#ifdef DEBUG
995 boolean_t ipointer_in = B_FALSE;
996
997#define IPOINTER_SET ipointer_in = B_TRUE
998#define IPOINTER_CLR ipointer_in = B_FALSE
999#else
1000#define IPOINTER_SET
1001#define IPOINTER_CLR
1002#endif
1003
1004
1005/* Insert a marker record into the inode list after inode ip. The list
1006 * must be locked when this is called. After the call the list will no
1007 * longer be locked.
1008 */
1009#define IPOINTER_INSERT(ip, mp) { \
1010 ASSERT(ipointer_in == B_FALSE); \
1011 ipointer->ip_mnext = ip->i_mnext; \
1012 ipointer->ip_mprev = ip; \
1013 ip->i_mnext = (xfs_inode_t *)ipointer; \
1014 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
1015 preempt = 0; \
1016 XFS_MOUNT_IUNLOCK(mp); \
1017 mount_locked = B_FALSE; \
1018 IPOINTER_SET; \
1019 }
1020
1021/* Remove the marker from the inode list. If the marker was the only item
1022 * in the list then there are no remaining inodes and we should zero out
1023 * the whole list. If we are the current head of the list then move the head
1024 * past us.
1025 */
1026#define IPOINTER_REMOVE(ip, mp) { \
1027 ASSERT(ipointer_in == B_TRUE); \
1028 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1029 ip = ipointer->ip_mnext; \
1030 ip->i_mprev = ipointer->ip_mprev; \
1031 ipointer->ip_mprev->i_mnext = ip; \
1032 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1033 mp->m_inodes = ip; \
1034 } \
1035 } else { \
1036 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1037 mp->m_inodes = NULL; \
1038 ip = NULL; \
1039 } \
1040 IPOINTER_CLR; \
1041 }
1042
1043#define XFS_PREEMPT_MASK 0x7f
1044
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001045 ASSERT(!(flags & SYNC_BDFLUSH));
1046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (bypassed)
1048 *bypassed = 0;
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001049 if (mp->m_flags & XFS_MOUNT_RDONLY)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 return 0;
1051 error = 0;
1052 last_error = 0;
1053 preempt = 0;
1054
1055 /* Allocate a reference marker */
1056 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1057
1058 fflag = XFS_B_ASYNC; /* default is don't wait */
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001059 if (flags & SYNC_DELWRI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 fflag = XFS_B_DELWRI;
1061 if (flags & SYNC_WAIT)
1062 fflag = 0; /* synchronous overrides all */
1063
1064 base_lock_flags = XFS_ILOCK_SHARED;
1065 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1066 /*
1067 * We need the I/O lock if we're going to call any of
1068 * the flush/inval routines.
1069 */
1070 base_lock_flags |= XFS_IOLOCK_SHARED;
1071 }
1072
1073 XFS_MOUNT_ILOCK(mp);
1074
1075 ip = mp->m_inodes;
1076
1077 mount_locked = B_TRUE;
1078 vnode_refed = B_FALSE;
1079
1080 IPOINTER_CLR;
1081
1082 do {
1083 ASSERT(ipointer_in == B_FALSE);
1084 ASSERT(vnode_refed == B_FALSE);
1085
1086 lock_flags = base_lock_flags;
1087
1088 /*
1089 * There were no inodes in the list, just break out
1090 * of the loop.
1091 */
1092 if (ip == NULL) {
1093 break;
1094 }
1095
1096 /*
1097 * We found another sync thread marker - skip it
1098 */
1099 if (ip->i_mount == NULL) {
1100 ip = ip->i_mnext;
1101 continue;
1102 }
1103
1104 vp = XFS_ITOV_NULL(ip);
1105
1106 /*
1107 * If the vnode is gone then this is being torn down,
1108 * call reclaim if it is flushed, else let regular flush
1109 * code deal with it later in the loop.
1110 */
1111
1112 if (vp == NULL) {
1113 /* Skip ones already in reclaim */
1114 if (ip->i_flags & XFS_IRECLAIM) {
1115 ip = ip->i_mnext;
1116 continue;
1117 }
1118 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1119 ip = ip->i_mnext;
1120 } else if ((xfs_ipincount(ip) == 0) &&
1121 xfs_iflock_nowait(ip)) {
1122 IPOINTER_INSERT(ip, mp);
1123
1124 xfs_finish_reclaim(ip, 1,
1125 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1126
1127 XFS_MOUNT_ILOCK(mp);
1128 mount_locked = B_TRUE;
1129 IPOINTER_REMOVE(ip, mp);
1130 } else {
1131 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1132 ip = ip->i_mnext;
1133 }
1134 continue;
1135 }
1136
1137 if (VN_BAD(vp)) {
1138 ip = ip->i_mnext;
1139 continue;
1140 }
1141
1142 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1143 XFS_MOUNT_IUNLOCK(mp);
1144 kmem_free(ipointer, sizeof(xfs_iptr_t));
1145 return 0;
1146 }
1147
1148 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 * Try to lock without sleeping. We're out of order with
1150 * the inode list lock here, so if we fail we need to drop
1151 * the mount lock and try again. If we're called from
1152 * bdflush() here, then don't bother.
1153 *
1154 * The inode lock here actually coordinates with the
1155 * almost spurious inode lock in xfs_ireclaim() to prevent
1156 * the vnode we handle here without a reference from
1157 * being freed while we reference it. If we lock the inode
1158 * while it's on the mount list here, then the spurious inode
1159 * lock in xfs_ireclaim() after the inode is pulled from
1160 * the mount list will sleep until we release it here.
1161 * This keeps the vnode from being freed while we reference
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001162 * it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 */
1164 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001165 if (vp == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 ip = ip->i_mnext;
1167 continue;
1168 }
1169
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001170 vp = vn_grab(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 if (vp == NULL) {
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001172 ip = ip->i_mnext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 continue;
1174 }
1175
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001176 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 xfs_ilock(ip, lock_flags);
1178
1179 ASSERT(vp == XFS_ITOV(ip));
1180 ASSERT(ip->i_mount == mp);
1181
1182 vnode_refed = B_TRUE;
1183 }
1184
1185 /* From here on in the loop we may have a marker record
1186 * in the inode list.
1187 */
1188
David Chinner40095b62007-05-14 18:24:09 +10001189 /*
1190 * If we have to flush data or wait for I/O completion
1191 * we need to drop the ilock that we currently hold.
1192 * If we need to drop the lock, insert a marker if we
1193 * have not already done so.
1194 */
1195 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1196 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1197 if (mount_locked) {
1198 IPOINTER_INSERT(ip, mp);
1199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1201
David Chinner40095b62007-05-14 18:24:09 +10001202 if (flags & SYNC_CLOSE) {
1203 /* Shutdown case. Flush and invalidate. */
1204 if (XFS_FORCED_SHUTDOWN(mp))
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001205 xfs_tosspages(ip, 0, -1,
1206 FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001207 else
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001208 error = xfs_flushinval_pages(ip,
1209 0, -1, FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001210 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001211 error = xfs_flush_pages(ip, 0,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001212 -1, fflag, FI_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
1214
David Chinner40095b62007-05-14 18:24:09 +10001215 /*
1216 * When freezing, we need to wait ensure all I/O (including direct
1217 * I/O) is complete to ensure no further data modification can take
1218 * place after this point
1219 */
1220 if (flags & SYNC_IOWAIT)
Christoph Hellwigb677c212007-08-29 11:46:28 +10001221 vn_iowait(ip);
David Chinner40095b62007-05-14 18:24:09 +10001222
1223 xfs_ilock(ip, XFS_ILOCK_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 }
1225
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001226 if ((flags & SYNC_ATTR) &&
1227 (ip->i_update_core ||
1228 (ip->i_itemp && ip->i_itemp->ili_format.ilf_fields))) {
1229 if (mount_locked)
1230 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001232 if (flags & SYNC_WAIT) {
1233 xfs_iflock(ip);
1234 error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001236 /*
1237 * If we can't acquire the flush lock, then the inode
1238 * is already being flushed so don't bother waiting.
1239 *
1240 * If we can lock it then do a delwri flush so we can
1241 * combine multiple inode flushes in each disk write.
1242 */
1243 } else if (xfs_iflock_nowait(ip)) {
1244 error = xfs_iflush(ip, XFS_IFLUSH_DELWRI);
1245 } else if (bypassed) {
1246 (*bypassed)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 }
1248 }
1249
1250 if (lock_flags != 0) {
1251 xfs_iunlock(ip, lock_flags);
1252 }
1253
1254 if (vnode_refed) {
1255 /*
1256 * If we had to take a reference on the vnode
1257 * above, then wait until after we've unlocked
1258 * the inode to release the reference. This is
1259 * because we can be already holding the inode
1260 * lock when VN_RELE() calls xfs_inactive().
1261 *
1262 * Make sure to drop the mount lock before calling
1263 * VN_RELE() so that we don't trip over ourselves if
1264 * we have to go for the mount lock again in the
1265 * inactive code.
1266 */
1267 if (mount_locked) {
1268 IPOINTER_INSERT(ip, mp);
1269 }
1270
1271 VN_RELE(vp);
1272
1273 vnode_refed = B_FALSE;
1274 }
1275
1276 if (error) {
1277 last_error = error;
1278 }
1279
1280 /*
1281 * bail out if the filesystem is corrupted.
1282 */
1283 if (error == EFSCORRUPTED) {
1284 if (!mount_locked) {
1285 XFS_MOUNT_ILOCK(mp);
1286 IPOINTER_REMOVE(ip, mp);
1287 }
1288 XFS_MOUNT_IUNLOCK(mp);
1289 ASSERT(ipointer_in == B_FALSE);
1290 kmem_free(ipointer, sizeof(xfs_iptr_t));
1291 return XFS_ERROR(error);
1292 }
1293
1294 /* Let other threads have a chance at the mount lock
1295 * if we have looped many times without dropping the
1296 * lock.
1297 */
1298 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1299 if (mount_locked) {
1300 IPOINTER_INSERT(ip, mp);
1301 }
1302 }
1303
1304 if (mount_locked == B_FALSE) {
1305 XFS_MOUNT_ILOCK(mp);
1306 mount_locked = B_TRUE;
1307 IPOINTER_REMOVE(ip, mp);
1308 continue;
1309 }
1310
1311 ASSERT(ipointer_in == B_FALSE);
1312 ip = ip->i_mnext;
1313
1314 } while (ip != mp->m_inodes);
1315
1316 XFS_MOUNT_IUNLOCK(mp);
1317
1318 ASSERT(ipointer_in == B_FALSE);
1319
1320 kmem_free(ipointer, sizeof(xfs_iptr_t));
1321 return XFS_ERROR(last_error);
1322}
1323
1324/*
1325 * xfs sync routine for internal use
1326 *
Nathan Scottb83bd132006-06-09 16:48:30 +10001327 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001328 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 *
1330 */
1331int
1332xfs_syncsub(
1333 xfs_mount_t *mp,
1334 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 int *bypassed)
1336{
1337 int error = 0;
1338 int last_error = 0;
1339 uint log_flags = XFS_LOG_FORCE;
1340 xfs_buf_t *bp;
1341 xfs_buf_log_item_t *bip;
1342
1343 /*
1344 * Sync out the log. This ensures that the log is periodically
1345 * flushed even if there is not enough activity to fill it up.
1346 */
1347 if (flags & SYNC_WAIT)
1348 log_flags |= XFS_LOG_SYNC;
1349
1350 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1351
1352 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1353 if (flags & SYNC_BDFLUSH)
1354 xfs_finish_reclaim_all(mp, 1);
1355 else
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001356 error = xfs_sync_inodes(mp, flags, bypassed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 }
1358
1359 /*
1360 * Flushing out dirty data above probably generated more
1361 * log activity, so if this isn't vfs_sync() then flush
1362 * the log again.
1363 */
1364 if (flags & SYNC_DELWRI) {
1365 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1366 }
1367
1368 if (flags & SYNC_FSDATA) {
1369 /*
1370 * If this is vfs_sync() then only sync the superblock
1371 * if we can lock it without sleeping and it is not pinned.
1372 */
1373 if (flags & SYNC_BDFLUSH) {
1374 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1375 if (bp != NULL) {
1376 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1377 if ((bip != NULL) &&
1378 xfs_buf_item_dirty(bip)) {
1379 if (!(XFS_BUF_ISPINNED(bp))) {
1380 XFS_BUF_ASYNC(bp);
1381 error = xfs_bwrite(mp, bp);
1382 } else {
1383 xfs_buf_relse(bp);
1384 }
1385 } else {
1386 xfs_buf_relse(bp);
1387 }
1388 }
1389 } else {
1390 bp = xfs_getsb(mp, 0);
1391 /*
1392 * If the buffer is pinned then push on the log so
1393 * we won't get stuck waiting in the write for
1394 * someone, maybe ourselves, to flush the log.
1395 * Even though we just pushed the log above, we
1396 * did not have the superblock buffer locked at
1397 * that point so it can become pinned in between
1398 * there and here.
1399 */
1400 if (XFS_BUF_ISPINNED(bp))
1401 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1402 if (flags & SYNC_WAIT)
1403 XFS_BUF_UNASYNC(bp);
1404 else
1405 XFS_BUF_ASYNC(bp);
1406 error = xfs_bwrite(mp, bp);
1407 }
1408 if (error) {
1409 last_error = error;
1410 }
1411 }
1412
1413 /*
1414 * If this is the periodic sync, then kick some entries out of
1415 * the reference cache. This ensures that idle entries are
1416 * eventually kicked out of the cache.
1417 */
1418 if (flags & SYNC_REFCACHE) {
Nathan Scottcde410a2005-09-05 11:47:01 +10001419 if (flags & SYNC_WAIT)
1420 xfs_refcache_purge_mp(mp);
1421 else
1422 xfs_refcache_purge_some(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 }
1424
1425 /*
David Chinner92821e22007-05-24 15:26:31 +10001426 * If asked, update the disk superblock with incore counter values if we
1427 * are using non-persistent counters so that they don't get too far out
1428 * of sync if we crash or get a forced shutdown. We don't want to force
1429 * this to disk, just get a transaction into the iclogs....
1430 */
1431 if (flags & SYNC_SUPER)
1432 xfs_log_sbcount(mp, 0);
1433
1434 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 * Now check to see if the log needs a "dummy" transaction.
1436 */
1437
1438 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1439 xfs_trans_t *tp;
1440 xfs_inode_t *ip;
1441
1442 /*
1443 * Put a dummy transaction in the log to tell
1444 * recovery that all others are OK.
1445 */
1446 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1447 if ((error = xfs_trans_reserve(tp, 0,
1448 XFS_ICHANGE_LOG_RES(mp),
1449 0, 0, 0))) {
1450 xfs_trans_cancel(tp, 0);
1451 return error;
1452 }
1453
1454 ip = mp->m_rootip;
1455 xfs_ilock(ip, XFS_ILOCK_EXCL);
1456
1457 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1458 xfs_trans_ihold(tp, ip);
1459 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
Eric Sandeen1c72bf92007-05-08 13:48:42 +10001460 error = xfs_trans_commit(tp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1462 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1463 }
1464
1465 /*
1466 * When shutting down, we need to insure that the AIL is pushed
1467 * to disk or the filesystem can appear corrupt from the PROM.
1468 */
1469 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1470 XFS_bflush(mp->m_ddev_targp);
1471 if (mp->m_rtdev_targp) {
1472 XFS_bflush(mp->m_rtdev_targp);
1473 }
1474 }
1475
1476 return XFS_ERROR(last_error);
1477}
1478
1479/*
1480 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1481 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001482int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483xfs_vget(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001484 xfs_mount_t *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001485 bhv_vnode_t **vpp,
Christoph Hellwigc6143912007-09-14 15:22:37 +10001486 xfs_fid_t *xfid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 xfs_inode_t *ip;
1489 int error;
1490 xfs_ino_t ino;
1491 unsigned int igen;
1492
1493 /*
1494 * Invalid. Since handles can be created in user space and passed in
1495 * via gethandle(), this is not cause for a panic.
1496 */
Christoph Hellwigc6143912007-09-14 15:22:37 +10001497 if (xfid->fid_len != sizeof(*xfid) - sizeof(xfid->fid_len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 return XFS_ERROR(EINVAL);
1499
Christoph Hellwigc6143912007-09-14 15:22:37 +10001500 ino = xfid->fid_ino;
1501 igen = xfid->fid_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502
1503 /*
1504 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1505 */
1506 if (ino == 0)
1507 return XFS_ERROR(ESTALE);
1508
1509 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1510 if (error) {
1511 *vpp = NULL;
1512 return error;
1513 }
1514
1515 if (ip == NULL) {
1516 *vpp = NULL;
1517 return XFS_ERROR(EIO);
1518 }
1519
1520 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1521 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1522 *vpp = NULL;
1523 return XFS_ERROR(ENOENT);
1524 }
1525
1526 *vpp = XFS_ITOV(ip);
1527 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1528 return 0;
1529}
1530
1531
1532#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1533#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1534#define MNTOPT_LOGDEV "logdev" /* log device */
1535#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1536#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1537#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1538#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1539#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1540#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1541#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1542#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1543#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1544#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
Nathan Scotte69a3332005-09-02 16:42:26 +10001545#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1546#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1547#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1548#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
Nathan Scott1f443ad2005-05-05 13:28:29 -07001549#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001551#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
Nathan Scottd8cc8902005-11-02 10:34:53 +11001552 * unwritten extent conversion */
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001553#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1555#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1556#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1557#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
David Chinnere8c8b3a2005-11-02 10:33:05 +11001558#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1559#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1560 * in stat(). */
Nathan Scottd8cc8902005-11-02 10:34:53 +11001561#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1562#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
David Chinner2a82b8b2007-07-11 11:09:12 +10001563#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001564#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
1565#define MNTOPT_NOQUOTA "noquota" /* no quotas */
1566#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
1567#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
1568#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
1569#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
1570#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
1571#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
1572#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
1573#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
1574#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
1575#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
Christoph Hellwig293688e2007-08-29 11:59:36 +10001576#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
1577#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
1578#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
Nathan Scott1f443ad2005-05-05 13:28:29 -07001580STATIC unsigned long
Nathan Scottb190f112006-06-09 17:13:15 +10001581suffix_strtoul(char *s, char **endp, unsigned int base)
Nathan Scott1f443ad2005-05-05 13:28:29 -07001582{
1583 int last, shift_left_factor = 0;
Nathan Scottb190f112006-06-09 17:13:15 +10001584 char *value = s;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001585
1586 last = strlen(value) - 1;
1587 if (value[last] == 'K' || value[last] == 'k') {
1588 shift_left_factor = 10;
1589 value[last] = '\0';
1590 }
1591 if (value[last] == 'M' || value[last] == 'm') {
1592 shift_left_factor = 20;
1593 value[last] = '\0';
1594 }
1595 if (value[last] == 'G' || value[last] == 'g') {
1596 shift_left_factor = 30;
1597 value[last] = '\0';
1598 }
1599
Nathan Scottb190f112006-06-09 17:13:15 +10001600 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001601}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001603int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604xfs_parseargs(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001605 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 char *options,
1607 struct xfs_mount_args *args,
1608 int update)
1609{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 char *this_char, *value, *eov;
1611 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1612 int iosize;
Vlad Apostolov574342f2007-09-14 15:23:44 +10001613 int ikeep = 0;
Vlad Apostolovb93bd202007-08-28 14:00:28 +10001614
Nathan Scott3bbcc8e2006-03-31 13:04:56 +10001615 args->flags |= XFSMNT_BARRIER;
1616 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
1618 if (!options)
Nathan Scott05db2182005-11-04 09:49:07 +11001619 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
1621 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1622
1623 while ((this_char = strsep(&options, ",")) != NULL) {
1624 if (!*this_char)
1625 continue;
1626 if ((value = strchr(this_char, '=')) != NULL)
1627 *value++ = 0;
1628
1629 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1630 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001631 cmn_err(CE_WARN,
1632 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001633 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 return EINVAL;
1635 }
1636 args->logbufs = simple_strtoul(value, &eov, 10);
1637 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001639 cmn_err(CE_WARN,
1640 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001641 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 return EINVAL;
1643 }
Nathan Scott1f443ad2005-05-05 13:28:29 -07001644 args->logbufsize = suffix_strtoul(value, &eov, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1646 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001647 cmn_err(CE_WARN,
1648 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001649 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 return EINVAL;
1651 }
1652 strncpy(args->logname, value, MAXNAMELEN);
1653 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1654 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001655 cmn_err(CE_WARN,
1656 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001657 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 return EINVAL;
1659 }
1660 strncpy(args->mtpt, value, MAXNAMELEN);
1661 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1662 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001663 cmn_err(CE_WARN,
1664 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001665 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 return EINVAL;
1667 }
1668 strncpy(args->rtname, value, MAXNAMELEN);
1669 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1670 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001671 cmn_err(CE_WARN,
1672 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001673 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 return EINVAL;
1675 }
1676 iosize = simple_strtoul(value, &eov, 10);
1677 args->flags |= XFSMNT_IOSIZE;
1678 args->iosizelog = (uint8_t) iosize;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001679 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1680 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001681 cmn_err(CE_WARN,
1682 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001683 this_char);
1684 return EINVAL;
1685 }
1686 iosize = suffix_strtoul(value, &eov, 10);
1687 args->flags |= XFSMNT_IOSIZE;
1688 args->iosizelog = ffs(iosize) - 1;
Nathan Scotte69a3332005-09-02 16:42:26 +10001689 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1690 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001691 mp->m_flags |= XFS_MOUNT_GRPID;
Nathan Scotte69a3332005-09-02 16:42:26 +10001692 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1693 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001694 mp->m_flags &= ~XFS_MOUNT_GRPID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1696 args->flags |= XFSMNT_WSYNC;
1697 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1698 args->flags |= XFSMNT_OSYNCISOSYNC;
1699 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1700 args->flags |= XFSMNT_NORECOVERY;
1701 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1702 args->flags |= XFSMNT_INO64;
1703#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001704 cmn_err(CE_WARN,
1705 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001706 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 return EINVAL;
1708#endif
1709 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1710 args->flags |= XFSMNT_NOALIGN;
1711 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1712 args->flags |= XFSMNT_SWALLOC;
1713 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1714 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001715 cmn_err(CE_WARN,
1716 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001717 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 return EINVAL;
1719 }
1720 dsunit = simple_strtoul(value, &eov, 10);
1721 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1722 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001723 cmn_err(CE_WARN,
1724 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001725 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 return EINVAL;
1727 }
1728 dswidth = simple_strtoul(value, &eov, 10);
1729 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1730 args->flags &= ~XFSMNT_32BITINODES;
1731#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001732 cmn_err(CE_WARN,
1733 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001734 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 return EINVAL;
1736#endif
1737 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1738 args->flags |= XFSMNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001739 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1740 args->flags |= XFSMNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001741 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1742 args->flags &= ~XFSMNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Vlad Apostolov574342f2007-09-14 15:23:44 +10001744 ikeep = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 args->flags &= ~XFSMNT_IDELETE;
1746 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1747 args->flags |= XFSMNT_IDELETE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001748 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001749 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001750 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001751 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001752 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001753 args->flags |= XFSMNT_ATTR2;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001754 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001755 args->flags &= ~XFSMNT_ATTR2;
David Chinner2a82b8b2007-07-11 11:09:12 +10001756 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1757 args->flags2 |= XFSMNT2_FILESTREAMS;
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001758 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
1759 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
1760 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
1761 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
1762 !strcmp(this_char, MNTOPT_UQUOTA) ||
1763 !strcmp(this_char, MNTOPT_USRQUOTA)) {
1764 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
1765 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
1766 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
1767 args->flags |= XFSMNT_UQUOTA;
1768 args->flags &= ~XFSMNT_UQUOTAENF;
1769 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
1770 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
1771 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
1772 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
1773 args->flags |= XFSMNT_PQUOTA;
1774 args->flags &= ~XFSMNT_PQUOTAENF;
1775 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
1776 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
1777 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
1778 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
1779 args->flags |= XFSMNT_GQUOTA;
1780 args->flags &= ~XFSMNT_GQUOTAENF;
Christoph Hellwig293688e2007-08-29 11:59:36 +10001781 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
1782 args->flags |= XFSMNT_DMAPI;
1783 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
1784 args->flags |= XFSMNT_DMAPI;
1785 } else if (!strcmp(this_char, MNTOPT_DMI)) {
1786 args->flags |= XFSMNT_DMAPI;
David Chinnerda353b02007-08-28 14:00:13 +10001787 } else if (!strcmp(this_char, "ihashsize")) {
1788 cmn_err(CE_WARN,
1789 "XFS: ihashsize no longer used, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 } else if (!strcmp(this_char, "osyncisdsync")) {
1791 /* no-op, this is now the default */
Nathan Scottb6574522006-06-09 15:29:40 +10001792 cmn_err(CE_WARN,
1793 "XFS: osyncisdsync is now the default, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 } else if (!strcmp(this_char, "irixsgid")) {
Nathan Scottb6574522006-06-09 15:29:40 +10001795 cmn_err(CE_WARN,
1796 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 } else {
Nathan Scottb6574522006-06-09 15:29:40 +10001798 cmn_err(CE_WARN,
1799 "XFS: unknown mount option [%s].", this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 return EINVAL;
1801 }
1802 }
1803
1804 if (args->flags & XFSMNT_NORECOVERY) {
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001805 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
Nathan Scottb6574522006-06-09 15:29:40 +10001806 cmn_err(CE_WARN,
1807 "XFS: no-recovery mounts must be read-only.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 return EINVAL;
1809 }
1810 }
1811
1812 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001813 cmn_err(CE_WARN,
1814 "XFS: sunit and swidth options incompatible with the noalign option");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 return EINVAL;
1816 }
1817
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001818 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
1819 cmn_err(CE_WARN,
1820 "XFS: cannot mount with both project and group quota");
1821 return EINVAL;
1822 }
1823
Christoph Hellwig293688e2007-08-29 11:59:36 +10001824 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
1825 printk("XFS: %s option needs the mount point option as well\n",
1826 MNTOPT_DMAPI);
1827 return EINVAL;
1828 }
1829
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001831 cmn_err(CE_WARN,
1832 "XFS: sunit and swidth must be specified together");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 return EINVAL;
1834 }
1835
1836 if (dsunit && (dswidth % dsunit != 0)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001837 cmn_err(CE_WARN,
1838 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 dswidth, dsunit);
1840 return EINVAL;
1841 }
1842
Vlad Apostolov574342f2007-09-14 15:23:44 +10001843 /*
1844 * Applications using DMI filesystems often expect the
1845 * inode generation number to be monotonically increasing.
1846 * If we delete inode chunks we break this assumption, so
1847 * keep unused inode chunks on disk for DMI filesystems
1848 * until we come up with a better solution.
1849 * Note that if "ikeep" or "noikeep" mount options are
1850 * supplied, then they are honored.
1851 */
1852 if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
1853 args->flags |= XFSMNT_IDELETE;
1854
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1856 if (dsunit) {
1857 args->sunit = dsunit;
1858 args->flags |= XFSMNT_RETERR;
1859 } else {
1860 args->sunit = vol_dsunit;
1861 }
1862 dswidth ? (args->swidth = dswidth) :
1863 (args->swidth = vol_dswidth);
1864 } else {
1865 args->sunit = args->swidth = 0;
1866 }
1867
Nathan Scott05db2182005-11-04 09:49:07 +11001868done:
Nathan Scottc11e2c32005-11-02 15:11:45 +11001869 if (args->flags & XFSMNT_32BITINODES)
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001870 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
Nathan Scotte718eeb42005-11-02 15:09:22 +11001871 if (args->flags2)
1872 args->flags |= XFSMNT_FLAGS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 return 0;
1874}
1875
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001876int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877xfs_showargs(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001878 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 struct seq_file *m)
1880{
1881 static struct proc_xfs_info {
1882 int flag;
1883 char *str;
1884 } xfs_info[] = {
1885 /* the few simple ones we can get from the mount struct */
1886 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1887 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1888 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1889 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1890 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1891 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1892 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 { 0, NULL }
1894 };
1895 struct proc_xfs_info *xfs_infop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
1897 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1898 if (mp->m_flags & xfs_infop->flag)
1899 seq_puts(m, xfs_infop->str);
1900 }
1901
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001903 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1904 (int)(1 << mp->m_writeio_log) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
1906 if (mp->m_logbufs > 0)
1907 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 if (mp->m_logbsize > 0)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001909 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001911 if (mp->m_logname)
1912 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001913 if (mp->m_rtname)
1914 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
1916 if (mp->m_dalign > 0)
1917 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1918 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 if (mp->m_swidth > 0)
1920 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1921 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1922
Nathan Scotte15f1952006-03-22 12:47:52 +11001923 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1924 seq_printf(m, "," MNTOPT_IKEEP);
Nathan Scottfa7e7d72005-11-02 15:00:48 +11001925 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1926 seq_printf(m, "," MNTOPT_LARGEIO);
1927
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001928 if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS))
Nathan Scottc11e2c32005-11-02 15:11:45 +11001929 seq_printf(m, "," MNTOPT_64BITINODE);
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001930 if (mp->m_flags & XFS_MOUNT_GRPID)
Nathan Scotte69a3332005-09-02 16:42:26 +10001931 seq_printf(m, "," MNTOPT_GRPID);
1932
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001933 if (mp->m_qflags & XFS_UQUOTA_ACCT) {
1934 if (mp->m_qflags & XFS_UQUOTA_ENFD)
1935 seq_puts(m, "," MNTOPT_USRQUOTA);
1936 else
1937 seq_puts(m, "," MNTOPT_UQUOTANOENF);
1938 }
1939
1940 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
1941 if (mp->m_qflags & XFS_OQUOTA_ENFD)
1942 seq_puts(m, "," MNTOPT_PRJQUOTA);
1943 else
1944 seq_puts(m, "," MNTOPT_PQUOTANOENF);
1945 }
1946
1947 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
1948 if (mp->m_qflags & XFS_OQUOTA_ENFD)
1949 seq_puts(m, "," MNTOPT_GRPQUOTA);
1950 else
1951 seq_puts(m, "," MNTOPT_GQUOTANOENF);
1952 }
1953
1954 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
1955 seq_puts(m, "," MNTOPT_NOQUOTA);
1956
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001957 if (mp->m_flags & XFS_MOUNT_DMAPI)
Christoph Hellwig293688e2007-08-29 11:59:36 +10001958 seq_puts(m, "," MNTOPT_DMAPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 return 0;
1960}
1961
David Chinner28239452007-02-10 18:36:40 +11001962/*
David Chinner516b2e72007-06-18 16:50:48 +10001963 * Second stage of a freeze. The data is already frozen so we only
1964 * need to take care of themetadata. Once that's done write a dummy
1965 * record to dirty the log in case of a crash while frozen.
David Chinner28239452007-02-10 18:36:40 +11001966 */
Tim Shimmin479ba362007-10-16 15:32:57 +10001967void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968xfs_freeze(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001969 xfs_mount_t *mp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970{
David Chinner516b2e72007-06-18 16:50:48 +10001971 xfs_attr_quiesce(mp);
Christoph Hellwige13a73f2006-01-11 15:30:08 +11001972 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973}