blob: 1249548aa12ecdca5da2646b9945d15b155b5e7e [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
Eric Sandeen703e1f02007-10-11 17:41:21 +100070 extern spinlock_t xfs_dabuf_global_lock;
Eric Sandeen007c61c2007-10-11 17:43:56 +100071 spin_lock_init(&xfs_dabuf_global_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#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
Nathan Scott764d1f82006-03-31 13:04:17 +1000452 if (args->flags & XFSMNT_QUIET)
453 flags |= XFS_MFSI_QUIET;
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 /*
456 * Open real time and log devices - order is important.
457 */
458 if (args->logname[0]) {
459 error = xfs_blkdev_get(mp, args->logname, &logdev);
460 if (error)
461 return error;
462 }
463 if (args->rtname[0]) {
464 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
465 if (error) {
466 xfs_blkdev_put(logdev);
467 return error;
468 }
469
470 if (rtdev == ddev || rtdev == logdev) {
471 cmn_err(CE_WARN,
472 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
473 xfs_blkdev_put(logdev);
474 xfs_blkdev_put(rtdev);
475 return EINVAL;
476 }
477 }
478
479 /*
480 * Setup xfs_mount buffer target pointers
481 */
482 error = ENOMEM;
483 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
484 if (!mp->m_ddev_targp) {
485 xfs_blkdev_put(logdev);
486 xfs_blkdev_put(rtdev);
487 return error;
488 }
489 if (rtdev) {
490 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000491 if (!mp->m_rtdev_targp) {
492 xfs_blkdev_put(logdev);
493 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497 mp->m_logdev_targp = (logdev && logdev != ddev) ?
498 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000499 if (!mp->m_logdev_targp) {
500 xfs_blkdev_put(logdev);
501 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000503 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 /*
506 * Setup flags based on mount(2) options and then the superblock
507 */
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000508 error = xfs_start_flags(args, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if (error)
510 goto error1;
Nathan Scott764d1f82006-03-31 13:04:17 +1000511 error = xfs_readsb(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 if (error)
513 goto error1;
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000514 error = xfs_finish_flags(args, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (error)
516 goto error2;
517
518 /*
519 * Setup xfs_mount buffer target pointers based on superblock
520 */
521 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
522 mp->m_sb.sb_sectsize);
523 if (!error && logdev && logdev != ddev) {
524 unsigned int log_sector_size = BBSIZE;
525
526 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
527 log_sector_size = mp->m_sb.sb_logsectsize;
528 error = xfs_setsize_buftarg(mp->m_logdev_targp,
529 mp->m_sb.sb_blocksize,
530 log_sector_size);
531 }
532 if (!error && rtdev)
533 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
534 mp->m_sb.sb_blocksize,
535 mp->m_sb.sb_sectsize);
536 if (error)
537 goto error2;
538
Nathan Scottb2ea4012006-07-28 17:05:13 +1000539 if (mp->m_flags & XFS_MOUNT_BARRIER)
Christoph Hellwigc7d437d2006-01-11 15:28:56 +1100540 xfs_mountfs_check_barriers(mp);
541
David Chinner2a82b8b2007-07-11 11:09:12 +1000542 if ((error = xfs_filestream_mount(mp)))
543 goto error2;
544
Lachlan McIlroy541d7d32007-10-11 17:34:33 +1000545 error = xfs_mountfs(mp, flags);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100546 if (error)
547 goto error2;
548
Christoph Hellwig293688e2007-08-29 11:59:36 +1000549 XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
550
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100551 return 0;
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553error2:
554 if (mp->m_sb_bp)
555 xfs_freesb(mp);
556error1:
557 xfs_binval(mp->m_ddev_targp);
558 if (logdev && logdev != ddev)
559 xfs_binval(mp->m_logdev_targp);
560 if (rtdev)
561 xfs_binval(mp->m_rtdev_targp);
562error0:
563 xfs_unmountfs_close(mp, credp);
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000564 xfs_qmops_put(mp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000565 xfs_dmops_put(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 return error;
567}
568
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000569int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570xfs_unmount(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000571 xfs_mount_t *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 int flags,
573 cred_t *credp)
574{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 xfs_inode_t *rip;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000576 bhv_vnode_t *rvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 int unmount_event_wanted = 0;
578 int unmount_event_flags = 0;
579 int xfs_unmountfs_needed = 0;
580 int error;
581
582 rip = mp->m_rootip;
583 rvp = XFS_ITOV(rip);
584
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000585#ifdef HAVE_DMAPI
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000586 if (mp->m_flags & XFS_MOUNT_DMAPI) {
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000587 error = XFS_SEND_PREUNMOUNT(mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
589 NULL, NULL, 0, 0,
590 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
591 0:DM_FLAGS_UNWANTED);
592 if (error)
593 return XFS_ERROR(error);
594 unmount_event_wanted = 1;
595 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
596 0 : DM_FLAGS_UNWANTED;
597 }
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000598#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 /*
600 * First blow any referenced inode from this file system
601 * out of the reference cache, and delete the timer.
602 */
603 xfs_refcache_purge_mp(mp);
604
David Chinner2a82b8b2007-07-11 11:09:12 +1000605 /*
606 * Blow away any referenced inode in the filestreams cache.
607 * This can and will cause log traffic as inodes go inactive
608 * here.
609 */
610 xfs_filestream_unmount(mp);
611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 XFS_bflush(mp->m_ddev_targp);
613 error = xfs_unmount_flush(mp, 0);
614 if (error)
615 goto out;
616
617 ASSERT(vn_count(rvp) == 1);
618
619 /*
620 * Drop the reference count
621 */
622 VN_RELE(rvp);
623
624 /*
625 * If we're forcing a shutdown, typically because of a media error,
626 * we want to make sure we invalidate dirty pages that belong to
627 * referenced vnodes as well.
628 */
629 if (XFS_FORCED_SHUTDOWN(mp)) {
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000630 error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 ASSERT(error != EFSCORRUPTED);
632 }
633 xfs_unmountfs_needed = 1;
634
635out:
636 /* Send DMAPI event, if required.
637 * Then do xfs_unmountfs() if needed.
638 * Then return error (or zero).
639 */
640 if (unmount_event_wanted) {
641 /* Note: mp structure must still exist for
642 * XFS_SEND_UNMOUNT() call.
643 */
Christoph Hellwigb267ce92007-08-30 17:21:30 +1000644 XFS_SEND_UNMOUNT(mp, error == 0 ? rvp : NULL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 DM_RIGHT_NULL, 0, error, unmount_event_flags);
646 }
647 if (xfs_unmountfs_needed) {
648 /*
649 * Call common unmount function to flush to disk
650 * and free the super block buffer & mount structures.
651 */
652 xfs_unmountfs(mp, credp);
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000653 xfs_qmops_put(mp);
Christoph Hellwig293688e2007-08-29 11:59:36 +1000654 xfs_dmops_put(mp);
Christoph Hellwigf541d272007-08-29 11:53:22 +1000655 kmem_free(mp, sizeof(xfs_mount_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 }
657
658 return XFS_ERROR(error);
659}
660
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000661STATIC int
662xfs_quiesce_fs(
663 xfs_mount_t *mp)
664{
665 int count = 0, pincount;
Nathan Scott3758dee2006-03-22 12:47:28 +1100666
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000667 xfs_refcache_purge_mp(mp);
668 xfs_flush_buftarg(mp->m_ddev_targp, 0);
669 xfs_finish_reclaim_all(mp, 0);
670
671 /* This loop must run at least twice.
672 * The first instance of the loop will flush
673 * most meta data but that will generate more
674 * meta data (typically directory updates).
675 * Which then must be flushed and logged before
676 * we can write the unmount record.
Nathan Scott3758dee2006-03-22 12:47:28 +1100677 */
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000678 do {
David Chinner516b2e72007-06-18 16:50:48 +1000679 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000680 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
681 if (!pincount) {
682 delay(50);
683 count++;
684 }
685 } while (count < 2);
686
687 return 0;
688}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
David Chinner516b2e72007-06-18 16:50:48 +1000690/*
691 * Second stage of a quiesce. The data is already synced, now we have to take
692 * care of the metadata. New transactions are already blocked, so we need to
693 * wait for any remaining transactions to drain out before proceding.
694 */
695STATIC void
696xfs_attr_quiesce(
697 xfs_mount_t *mp)
698{
699 /* wait for all modifications to complete */
700 while (atomic_read(&mp->m_active_trans) > 0)
701 delay(100);
702
703 /* flush inodes and push all remaining buffers out to disk */
704 xfs_quiesce_fs(mp);
705
706 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
707
708 /* Push the superblock and write an unmount record */
709 xfs_log_sbcount(mp, 1);
710 xfs_log_unmount_write(mp);
711 xfs_unmountfs_writesb(mp);
712}
713
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000714int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715xfs_mntupdate(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000716 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 int *flags,
718 struct xfs_mount_args *args)
719{
Nathan Scottd08d3892006-05-08 19:51:28 +1000720 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000721 if (mp->m_flags & XFS_MOUNT_RDONLY)
722 mp->m_flags &= ~XFS_MOUNT_RDONLY;
Nathan Scottd08d3892006-05-08 19:51:28 +1000723 if (args->flags & XFSMNT_BARRIER) {
724 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100725 xfs_mountfs_check_barriers(mp);
Nathan Scottd08d3892006-05-08 19:51:28 +1000726 } else {
727 mp->m_flags &= ~XFS_MOUNT_BARRIER;
728 }
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000729 } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */
David Chinner2a82b8b2007-07-11 11:09:12 +1000730 xfs_filestream_flush(mp);
Christoph Hellwig745f6912007-08-30 17:20:39 +1000731 xfs_sync(mp, SYNC_DATA_QUIESCE);
David Chinner516b2e72007-06-18 16:50:48 +1000732 xfs_attr_quiesce(mp);
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000733 mp->m_flags |= XFS_MOUNT_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 return 0;
736}
737
738/*
739 * xfs_unmount_flush implements a set of flush operation on special
740 * inodes, which are needed as a separate set of operations so that
741 * they can be called as part of relocation process.
742 */
743int
744xfs_unmount_flush(
745 xfs_mount_t *mp, /* Mount structure we are getting
746 rid of. */
747 int relocation) /* Called from vfs relocation. */
748{
749 xfs_inode_t *rip = mp->m_rootip;
750 xfs_inode_t *rbmip;
751 xfs_inode_t *rsumip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000752 bhv_vnode_t *rvp = XFS_ITOV(rip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 int error;
754
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000755 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 xfs_iflock(rip);
757
758 /*
759 * Flush out the real time inodes.
760 */
761 if ((rbmip = mp->m_rbmip) != NULL) {
762 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
763 xfs_iflock(rbmip);
764 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
765 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
766
767 if (error == EFSCORRUPTED)
768 goto fscorrupt_out;
769
770 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
771
772 rsumip = mp->m_rsumip;
773 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
774 xfs_iflock(rsumip);
775 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
776 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
777
778 if (error == EFSCORRUPTED)
779 goto fscorrupt_out;
780
781 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
782 }
783
784 /*
785 * Synchronously flush root inode to disk
786 */
787 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
788 if (error == EFSCORRUPTED)
789 goto fscorrupt_out2;
790
791 if (vn_count(rvp) != 1 && !relocation) {
792 xfs_iunlock(rip, XFS_ILOCK_EXCL);
793 return XFS_ERROR(EBUSY);
794 }
795
796 /*
797 * Release dquot that rootinode, rbmino and rsumino might be holding,
798 * flush and purge the quota inodes.
799 */
800 error = XFS_QM_UNMOUNT(mp);
801 if (error == EFSCORRUPTED)
802 goto fscorrupt_out2;
803
804 if (rbmip) {
805 VN_RELE(XFS_ITOV(rbmip));
806 VN_RELE(XFS_ITOV(rsumip));
807 }
808
809 xfs_iunlock(rip, XFS_ILOCK_EXCL);
810 return 0;
811
812fscorrupt_out:
813 xfs_ifunlock(rip);
814
815fscorrupt_out2:
816 xfs_iunlock(rip, XFS_ILOCK_EXCL);
817
818 return XFS_ERROR(EFSCORRUPTED);
819}
820
821/*
822 * xfs_root extracts the root vnode from a vfs.
823 *
824 * vfsp -- the vfs struct for the desired file system
825 * vpp -- address of the caller's vnode pointer which should be
826 * set to the desired fs root vnode
827 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000828int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829xfs_root(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000830 xfs_mount_t *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000831 bhv_vnode_t **vpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000833 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000835 vp = XFS_ITOV(mp->m_rootip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 VN_HOLD(vp);
837 *vpp = vp;
838 return 0;
839}
840
841/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 * xfs_sync flushes any pending I/O to file system vfsp.
843 *
844 * This routine is called by vfs_sync() to make sure that things make it
845 * out to disk eventually, on sync() system calls to flush out everything,
846 * and when the file system is unmounted. For the vfs_sync() case, all
847 * we really need to do is sync out the log to make all of our meta-data
848 * updates permanent (except for timestamps). For calls from pflushd(),
849 * dirty pages are kept moving by calling pdflush() on the inodes
850 * containing them. We also flush the inodes that we can lock without
851 * sleeping and the superblock if we can lock it without sleeping from
852 * vfs_sync() so that items at the tail of the log are always moving out.
853 *
854 * Flags:
855 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
856 * to sleep if we can help it. All we really need
857 * to do is ensure that the log is synced at least
858 * periodically. We also push the inodes and
859 * superblock if we can lock them without sleeping
860 * and they are not pinned.
861 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
862 * set, then we really want to lock each inode and flush
863 * it.
864 * SYNC_WAIT - All the flushes that take place in this call should
865 * be synchronous.
866 * SYNC_DELWRI - This tells us to push dirty pages associated with
867 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
868 * determine if they should be flushed sync, async, or
869 * delwri.
870 * SYNC_CLOSE - This flag is passed when the system is being
Nathan Scottc41564b2006-03-29 08:55:14 +1000871 * unmounted. We should sync and invalidate everything.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 * SYNC_FSDATA - This indicates that the caller would like to make
873 * sure the superblock is safe on disk. We can ensure
Nathan Scottc41564b2006-03-29 08:55:14 +1000874 * this by simply making sure the log gets flushed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 * if SYNC_BDFLUSH is set, and by actually writing it
876 * out otherwise.
David Chinner3c0dc772007-02-10 18:37:22 +1100877 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
878 * before we return (including direct I/O). Forms the drain
879 * side of the write barrier needed to safely quiesce the
880 * filesystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 *
882 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000883int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884xfs_sync(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +1000885 xfs_mount_t *mp,
886 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
Christoph Hellwigb09cc772007-08-30 17:19:57 +1000888 int error;
889
890 /*
891 * Get the Quota Manager to flush the dquots.
892 *
893 * If XFS quota support is not enabled or this filesystem
894 * instance does not use quotas XFS_QM_DQSYNC will always
895 * return zero.
896 */
897 error = XFS_QM_DQSYNC(mp, flags);
898 if (error) {
899 /*
900 * If we got an IO error, we will be shutting down.
901 * So, there's nothing more for us to do here.
902 */
903 ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
904 if (XFS_FORCED_SHUTDOWN(mp))
905 return XFS_ERROR(error);
906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
David Chinner2a82b8b2007-07-11 11:09:12 +1000908 if (flags & SYNC_IOWAIT)
909 xfs_filestream_flush(mp);
910
David Chinner28239452007-02-10 18:36:40 +1100911 return xfs_syncsub(mp, flags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
914/*
915 * xfs sync routine for internal use
916 *
Nathan Scottb83bd132006-06-09 16:48:30 +1000917 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +1100918 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 *
920 */
Nathan Scottee348072005-11-02 10:32:38 +1100921int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922xfs_sync_inodes(
923 xfs_mount_t *mp,
924 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 int *bypassed)
926{
927 xfs_inode_t *ip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000928 bhv_vnode_t *vp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 int error;
930 int last_error;
931 uint64_t fflag;
932 uint lock_flags;
933 uint base_lock_flags;
934 boolean_t mount_locked;
935 boolean_t vnode_refed;
936 int preempt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 xfs_iptr_t *ipointer;
938#ifdef DEBUG
939 boolean_t ipointer_in = B_FALSE;
940
941#define IPOINTER_SET ipointer_in = B_TRUE
942#define IPOINTER_CLR ipointer_in = B_FALSE
943#else
944#define IPOINTER_SET
945#define IPOINTER_CLR
946#endif
947
948
949/* Insert a marker record into the inode list after inode ip. The list
950 * must be locked when this is called. After the call the list will no
951 * longer be locked.
952 */
953#define IPOINTER_INSERT(ip, mp) { \
954 ASSERT(ipointer_in == B_FALSE); \
955 ipointer->ip_mnext = ip->i_mnext; \
956 ipointer->ip_mprev = ip; \
957 ip->i_mnext = (xfs_inode_t *)ipointer; \
958 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
959 preempt = 0; \
960 XFS_MOUNT_IUNLOCK(mp); \
961 mount_locked = B_FALSE; \
962 IPOINTER_SET; \
963 }
964
965/* Remove the marker from the inode list. If the marker was the only item
966 * in the list then there are no remaining inodes and we should zero out
967 * the whole list. If we are the current head of the list then move the head
968 * past us.
969 */
970#define IPOINTER_REMOVE(ip, mp) { \
971 ASSERT(ipointer_in == B_TRUE); \
972 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
973 ip = ipointer->ip_mnext; \
974 ip->i_mprev = ipointer->ip_mprev; \
975 ipointer->ip_mprev->i_mnext = ip; \
976 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
977 mp->m_inodes = ip; \
978 } \
979 } else { \
980 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
981 mp->m_inodes = NULL; \
982 ip = NULL; \
983 } \
984 IPOINTER_CLR; \
985 }
986
987#define XFS_PREEMPT_MASK 0x7f
988
Lachlan McIlroy44866d32007-09-14 15:21:08 +1000989 ASSERT(!(flags & SYNC_BDFLUSH));
990
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (bypassed)
992 *bypassed = 0;
Christoph Hellwigbd186aa2007-08-30 17:21:12 +1000993 if (mp->m_flags & XFS_MOUNT_RDONLY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 return 0;
995 error = 0;
996 last_error = 0;
997 preempt = 0;
998
999 /* Allocate a reference marker */
1000 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1001
1002 fflag = XFS_B_ASYNC; /* default is don't wait */
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001003 if (flags & SYNC_DELWRI)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 fflag = XFS_B_DELWRI;
1005 if (flags & SYNC_WAIT)
1006 fflag = 0; /* synchronous overrides all */
1007
1008 base_lock_flags = XFS_ILOCK_SHARED;
1009 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1010 /*
1011 * We need the I/O lock if we're going to call any of
1012 * the flush/inval routines.
1013 */
1014 base_lock_flags |= XFS_IOLOCK_SHARED;
1015 }
1016
1017 XFS_MOUNT_ILOCK(mp);
1018
1019 ip = mp->m_inodes;
1020
1021 mount_locked = B_TRUE;
1022 vnode_refed = B_FALSE;
1023
1024 IPOINTER_CLR;
1025
1026 do {
1027 ASSERT(ipointer_in == B_FALSE);
1028 ASSERT(vnode_refed == B_FALSE);
1029
1030 lock_flags = base_lock_flags;
1031
1032 /*
1033 * There were no inodes in the list, just break out
1034 * of the loop.
1035 */
1036 if (ip == NULL) {
1037 break;
1038 }
1039
1040 /*
1041 * We found another sync thread marker - skip it
1042 */
1043 if (ip->i_mount == NULL) {
1044 ip = ip->i_mnext;
1045 continue;
1046 }
1047
1048 vp = XFS_ITOV_NULL(ip);
1049
1050 /*
1051 * If the vnode is gone then this is being torn down,
1052 * call reclaim if it is flushed, else let regular flush
1053 * code deal with it later in the loop.
1054 */
1055
1056 if (vp == NULL) {
1057 /* Skip ones already in reclaim */
1058 if (ip->i_flags & XFS_IRECLAIM) {
1059 ip = ip->i_mnext;
1060 continue;
1061 }
1062 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1063 ip = ip->i_mnext;
1064 } else if ((xfs_ipincount(ip) == 0) &&
1065 xfs_iflock_nowait(ip)) {
1066 IPOINTER_INSERT(ip, mp);
1067
1068 xfs_finish_reclaim(ip, 1,
1069 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1070
1071 XFS_MOUNT_ILOCK(mp);
1072 mount_locked = B_TRUE;
1073 IPOINTER_REMOVE(ip, mp);
1074 } else {
1075 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1076 ip = ip->i_mnext;
1077 }
1078 continue;
1079 }
1080
1081 if (VN_BAD(vp)) {
1082 ip = ip->i_mnext;
1083 continue;
1084 }
1085
1086 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1087 XFS_MOUNT_IUNLOCK(mp);
1088 kmem_free(ipointer, sizeof(xfs_iptr_t));
1089 return 0;
1090 }
1091
1092 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 * Try to lock without sleeping. We're out of order with
1094 * the inode list lock here, so if we fail we need to drop
1095 * the mount lock and try again. If we're called from
1096 * bdflush() here, then don't bother.
1097 *
1098 * The inode lock here actually coordinates with the
1099 * almost spurious inode lock in xfs_ireclaim() to prevent
1100 * the vnode we handle here without a reference from
1101 * being freed while we reference it. If we lock the inode
1102 * while it's on the mount list here, then the spurious inode
1103 * lock in xfs_ireclaim() after the inode is pulled from
1104 * the mount list will sleep until we release it here.
1105 * This keeps the vnode from being freed while we reference
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001106 * it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 */
1108 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001109 if (vp == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 ip = ip->i_mnext;
1111 continue;
1112 }
1113
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001114 vp = vn_grab(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if (vp == NULL) {
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001116 ip = ip->i_mnext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 continue;
1118 }
1119
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001120 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 xfs_ilock(ip, lock_flags);
1122
1123 ASSERT(vp == XFS_ITOV(ip));
1124 ASSERT(ip->i_mount == mp);
1125
1126 vnode_refed = B_TRUE;
1127 }
1128
1129 /* From here on in the loop we may have a marker record
1130 * in the inode list.
1131 */
1132
David Chinner40095b62007-05-14 18:24:09 +10001133 /*
1134 * If we have to flush data or wait for I/O completion
1135 * we need to drop the ilock that we currently hold.
1136 * If we need to drop the lock, insert a marker if we
1137 * have not already done so.
1138 */
1139 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1140 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1141 if (mount_locked) {
1142 IPOINTER_INSERT(ip, mp);
1143 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1145
David Chinner40095b62007-05-14 18:24:09 +10001146 if (flags & SYNC_CLOSE) {
1147 /* Shutdown case. Flush and invalidate. */
1148 if (XFS_FORCED_SHUTDOWN(mp))
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001149 xfs_tosspages(ip, 0, -1,
1150 FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001151 else
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001152 error = xfs_flushinval_pages(ip,
1153 0, -1, FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001154 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001155 error = xfs_flush_pages(ip, 0,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001156 -1, fflag, FI_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 }
1158
David Chinner40095b62007-05-14 18:24:09 +10001159 /*
1160 * When freezing, we need to wait ensure all I/O (including direct
1161 * I/O) is complete to ensure no further data modification can take
1162 * place after this point
1163 */
1164 if (flags & SYNC_IOWAIT)
Christoph Hellwigb677c212007-08-29 11:46:28 +10001165 vn_iowait(ip);
David Chinner40095b62007-05-14 18:24:09 +10001166
1167 xfs_ilock(ip, XFS_ILOCK_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 }
1169
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001170 if ((flags & SYNC_ATTR) &&
1171 (ip->i_update_core ||
1172 (ip->i_itemp && ip->i_itemp->ili_format.ilf_fields))) {
1173 if (mount_locked)
1174 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001176 if (flags & SYNC_WAIT) {
1177 xfs_iflock(ip);
1178 error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
Lachlan McIlroy44866d32007-09-14 15:21:08 +10001180 /*
1181 * If we can't acquire the flush lock, then the inode
1182 * is already being flushed so don't bother waiting.
1183 *
1184 * If we can lock it then do a delwri flush so we can
1185 * combine multiple inode flushes in each disk write.
1186 */
1187 } else if (xfs_iflock_nowait(ip)) {
1188 error = xfs_iflush(ip, XFS_IFLUSH_DELWRI);
1189 } else if (bypassed) {
1190 (*bypassed)++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 }
1192 }
1193
1194 if (lock_flags != 0) {
1195 xfs_iunlock(ip, lock_flags);
1196 }
1197
1198 if (vnode_refed) {
1199 /*
1200 * If we had to take a reference on the vnode
1201 * above, then wait until after we've unlocked
1202 * the inode to release the reference. This is
1203 * because we can be already holding the inode
1204 * lock when VN_RELE() calls xfs_inactive().
1205 *
1206 * Make sure to drop the mount lock before calling
1207 * VN_RELE() so that we don't trip over ourselves if
1208 * we have to go for the mount lock again in the
1209 * inactive code.
1210 */
1211 if (mount_locked) {
1212 IPOINTER_INSERT(ip, mp);
1213 }
1214
1215 VN_RELE(vp);
1216
1217 vnode_refed = B_FALSE;
1218 }
1219
1220 if (error) {
1221 last_error = error;
1222 }
1223
1224 /*
1225 * bail out if the filesystem is corrupted.
1226 */
1227 if (error == EFSCORRUPTED) {
1228 if (!mount_locked) {
1229 XFS_MOUNT_ILOCK(mp);
1230 IPOINTER_REMOVE(ip, mp);
1231 }
1232 XFS_MOUNT_IUNLOCK(mp);
1233 ASSERT(ipointer_in == B_FALSE);
1234 kmem_free(ipointer, sizeof(xfs_iptr_t));
1235 return XFS_ERROR(error);
1236 }
1237
1238 /* Let other threads have a chance at the mount lock
1239 * if we have looped many times without dropping the
1240 * lock.
1241 */
1242 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1243 if (mount_locked) {
1244 IPOINTER_INSERT(ip, mp);
1245 }
1246 }
1247
1248 if (mount_locked == B_FALSE) {
1249 XFS_MOUNT_ILOCK(mp);
1250 mount_locked = B_TRUE;
1251 IPOINTER_REMOVE(ip, mp);
1252 continue;
1253 }
1254
1255 ASSERT(ipointer_in == B_FALSE);
1256 ip = ip->i_mnext;
1257
1258 } while (ip != mp->m_inodes);
1259
1260 XFS_MOUNT_IUNLOCK(mp);
1261
1262 ASSERT(ipointer_in == B_FALSE);
1263
1264 kmem_free(ipointer, sizeof(xfs_iptr_t));
1265 return XFS_ERROR(last_error);
1266}
1267
1268/*
1269 * xfs sync routine for internal use
1270 *
Nathan Scottb83bd132006-06-09 16:48:30 +10001271 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001272 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 *
1274 */
1275int
1276xfs_syncsub(
1277 xfs_mount_t *mp,
1278 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 int *bypassed)
1280{
1281 int error = 0;
1282 int last_error = 0;
1283 uint log_flags = XFS_LOG_FORCE;
1284 xfs_buf_t *bp;
1285 xfs_buf_log_item_t *bip;
1286
1287 /*
1288 * Sync out the log. This ensures that the log is periodically
1289 * flushed even if there is not enough activity to fill it up.
1290 */
1291 if (flags & SYNC_WAIT)
1292 log_flags |= XFS_LOG_SYNC;
1293
1294 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1295
1296 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1297 if (flags & SYNC_BDFLUSH)
1298 xfs_finish_reclaim_all(mp, 1);
1299 else
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001300 error = xfs_sync_inodes(mp, flags, bypassed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 }
1302
1303 /*
1304 * Flushing out dirty data above probably generated more
1305 * log activity, so if this isn't vfs_sync() then flush
1306 * the log again.
1307 */
1308 if (flags & SYNC_DELWRI) {
1309 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1310 }
1311
1312 if (flags & SYNC_FSDATA) {
1313 /*
1314 * If this is vfs_sync() then only sync the superblock
1315 * if we can lock it without sleeping and it is not pinned.
1316 */
1317 if (flags & SYNC_BDFLUSH) {
1318 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1319 if (bp != NULL) {
1320 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1321 if ((bip != NULL) &&
1322 xfs_buf_item_dirty(bip)) {
1323 if (!(XFS_BUF_ISPINNED(bp))) {
1324 XFS_BUF_ASYNC(bp);
1325 error = xfs_bwrite(mp, bp);
1326 } else {
1327 xfs_buf_relse(bp);
1328 }
1329 } else {
1330 xfs_buf_relse(bp);
1331 }
1332 }
1333 } else {
1334 bp = xfs_getsb(mp, 0);
1335 /*
1336 * If the buffer is pinned then push on the log so
1337 * we won't get stuck waiting in the write for
1338 * someone, maybe ourselves, to flush the log.
1339 * Even though we just pushed the log above, we
1340 * did not have the superblock buffer locked at
1341 * that point so it can become pinned in between
1342 * there and here.
1343 */
1344 if (XFS_BUF_ISPINNED(bp))
1345 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1346 if (flags & SYNC_WAIT)
1347 XFS_BUF_UNASYNC(bp);
1348 else
1349 XFS_BUF_ASYNC(bp);
1350 error = xfs_bwrite(mp, bp);
1351 }
1352 if (error) {
1353 last_error = error;
1354 }
1355 }
1356
1357 /*
1358 * If this is the periodic sync, then kick some entries out of
1359 * the reference cache. This ensures that idle entries are
1360 * eventually kicked out of the cache.
1361 */
1362 if (flags & SYNC_REFCACHE) {
Nathan Scottcde410a2005-09-05 11:47:01 +10001363 if (flags & SYNC_WAIT)
1364 xfs_refcache_purge_mp(mp);
1365 else
1366 xfs_refcache_purge_some(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 }
1368
1369 /*
David Chinner92821e22007-05-24 15:26:31 +10001370 * If asked, update the disk superblock with incore counter values if we
1371 * are using non-persistent counters so that they don't get too far out
1372 * of sync if we crash or get a forced shutdown. We don't want to force
1373 * this to disk, just get a transaction into the iclogs....
1374 */
1375 if (flags & SYNC_SUPER)
1376 xfs_log_sbcount(mp, 0);
1377
1378 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 * Now check to see if the log needs a "dummy" transaction.
1380 */
1381
1382 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1383 xfs_trans_t *tp;
1384 xfs_inode_t *ip;
1385
1386 /*
1387 * Put a dummy transaction in the log to tell
1388 * recovery that all others are OK.
1389 */
1390 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1391 if ((error = xfs_trans_reserve(tp, 0,
1392 XFS_ICHANGE_LOG_RES(mp),
1393 0, 0, 0))) {
1394 xfs_trans_cancel(tp, 0);
1395 return error;
1396 }
1397
1398 ip = mp->m_rootip;
1399 xfs_ilock(ip, XFS_ILOCK_EXCL);
1400
1401 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1402 xfs_trans_ihold(tp, ip);
1403 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
Eric Sandeen1c72bf92007-05-08 13:48:42 +10001404 error = xfs_trans_commit(tp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1406 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1407 }
1408
1409 /*
1410 * When shutting down, we need to insure that the AIL is pushed
1411 * to disk or the filesystem can appear corrupt from the PROM.
1412 */
1413 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1414 XFS_bflush(mp->m_ddev_targp);
1415 if (mp->m_rtdev_targp) {
1416 XFS_bflush(mp->m_rtdev_targp);
1417 }
1418 }
1419
1420 return XFS_ERROR(last_error);
1421}
1422
1423/*
1424 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1425 */
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001426int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427xfs_vget(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001428 xfs_mount_t *mp,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001429 bhv_vnode_t **vpp,
Christoph Hellwigc6143912007-09-14 15:22:37 +10001430 xfs_fid_t *xfid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 xfs_inode_t *ip;
1433 int error;
1434 xfs_ino_t ino;
1435 unsigned int igen;
1436
1437 /*
1438 * Invalid. Since handles can be created in user space and passed in
1439 * via gethandle(), this is not cause for a panic.
1440 */
Christoph Hellwigc6143912007-09-14 15:22:37 +10001441 if (xfid->fid_len != sizeof(*xfid) - sizeof(xfid->fid_len))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 return XFS_ERROR(EINVAL);
1443
Christoph Hellwigc6143912007-09-14 15:22:37 +10001444 ino = xfid->fid_ino;
1445 igen = xfid->fid_gen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
1447 /*
1448 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1449 */
1450 if (ino == 0)
1451 return XFS_ERROR(ESTALE);
1452
1453 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1454 if (error) {
1455 *vpp = NULL;
1456 return error;
1457 }
1458
1459 if (ip == NULL) {
1460 *vpp = NULL;
1461 return XFS_ERROR(EIO);
1462 }
1463
1464 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1465 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1466 *vpp = NULL;
1467 return XFS_ERROR(ENOENT);
1468 }
1469
1470 *vpp = XFS_ITOV(ip);
1471 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1472 return 0;
1473}
1474
1475
1476#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1477#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1478#define MNTOPT_LOGDEV "logdev" /* log device */
1479#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1480#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1481#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1482#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1483#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1484#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1485#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1486#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1487#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1488#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
Nathan Scotte69a3332005-09-02 16:42:26 +10001489#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1490#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1491#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1492#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
Nathan Scott1f443ad2005-05-05 13:28:29 -07001493#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001495#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
Nathan Scottd8cc8902005-11-02 10:34:53 +11001496 * unwritten extent conversion */
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001497#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1499#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1500#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1501#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
David Chinnere8c8b3a2005-11-02 10:33:05 +11001502#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1503#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1504 * in stat(). */
Nathan Scottd8cc8902005-11-02 10:34:53 +11001505#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1506#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
David Chinner2a82b8b2007-07-11 11:09:12 +10001507#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001508#define MNTOPT_QUOTA "quota" /* disk quotas (user) */
1509#define MNTOPT_NOQUOTA "noquota" /* no quotas */
1510#define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */
1511#define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */
1512#define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */
1513#define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */
1514#define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */
1515#define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */
1516#define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */
1517#define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
1518#define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
1519#define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */
Christoph Hellwig293688e2007-08-29 11:59:36 +10001520#define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */
1521#define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */
1522#define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
Nathan Scott1f443ad2005-05-05 13:28:29 -07001524STATIC unsigned long
Nathan Scottb190f112006-06-09 17:13:15 +10001525suffix_strtoul(char *s, char **endp, unsigned int base)
Nathan Scott1f443ad2005-05-05 13:28:29 -07001526{
1527 int last, shift_left_factor = 0;
Nathan Scottb190f112006-06-09 17:13:15 +10001528 char *value = s;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001529
1530 last = strlen(value) - 1;
1531 if (value[last] == 'K' || value[last] == 'k') {
1532 shift_left_factor = 10;
1533 value[last] = '\0';
1534 }
1535 if (value[last] == 'M' || value[last] == 'm') {
1536 shift_left_factor = 20;
1537 value[last] = '\0';
1538 }
1539 if (value[last] == 'G' || value[last] == 'g') {
1540 shift_left_factor = 30;
1541 value[last] = '\0';
1542 }
1543
Nathan Scottb190f112006-06-09 17:13:15 +10001544 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001545}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001547int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548xfs_parseargs(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001549 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 char *options,
1551 struct xfs_mount_args *args,
1552 int update)
1553{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 char *this_char, *value, *eov;
1555 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1556 int iosize;
Vlad Apostolov574342f2007-09-14 15:23:44 +10001557 int ikeep = 0;
Vlad Apostolovb93bd202007-08-28 14:00:28 +10001558
Nathan Scott3bbcc8e2006-03-31 13:04:56 +10001559 args->flags |= XFSMNT_BARRIER;
1560 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
1562 if (!options)
Nathan Scott05db2182005-11-04 09:49:07 +11001563 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1566
1567 while ((this_char = strsep(&options, ",")) != NULL) {
1568 if (!*this_char)
1569 continue;
1570 if ((value = strchr(this_char, '=')) != NULL)
1571 *value++ = 0;
1572
1573 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1574 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001575 cmn_err(CE_WARN,
1576 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001577 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 return EINVAL;
1579 }
1580 args->logbufs = simple_strtoul(value, &eov, 10);
1581 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001583 cmn_err(CE_WARN,
1584 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001585 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 return EINVAL;
1587 }
Nathan Scott1f443ad2005-05-05 13:28:29 -07001588 args->logbufsize = suffix_strtoul(value, &eov, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1590 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001591 cmn_err(CE_WARN,
1592 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001593 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 return EINVAL;
1595 }
1596 strncpy(args->logname, value, MAXNAMELEN);
1597 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1598 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001599 cmn_err(CE_WARN,
1600 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001601 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 return EINVAL;
1603 }
1604 strncpy(args->mtpt, value, MAXNAMELEN);
1605 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1606 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001607 cmn_err(CE_WARN,
1608 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001609 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 return EINVAL;
1611 }
1612 strncpy(args->rtname, value, MAXNAMELEN);
1613 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1614 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001615 cmn_err(CE_WARN,
1616 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001617 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 return EINVAL;
1619 }
1620 iosize = simple_strtoul(value, &eov, 10);
1621 args->flags |= XFSMNT_IOSIZE;
1622 args->iosizelog = (uint8_t) iosize;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001623 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1624 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001625 cmn_err(CE_WARN,
1626 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001627 this_char);
1628 return EINVAL;
1629 }
1630 iosize = suffix_strtoul(value, &eov, 10);
1631 args->flags |= XFSMNT_IOSIZE;
1632 args->iosizelog = ffs(iosize) - 1;
Nathan Scotte69a3332005-09-02 16:42:26 +10001633 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1634 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001635 mp->m_flags |= XFS_MOUNT_GRPID;
Nathan Scotte69a3332005-09-02 16:42:26 +10001636 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1637 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001638 mp->m_flags &= ~XFS_MOUNT_GRPID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1640 args->flags |= XFSMNT_WSYNC;
1641 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1642 args->flags |= XFSMNT_OSYNCISOSYNC;
1643 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1644 args->flags |= XFSMNT_NORECOVERY;
1645 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1646 args->flags |= XFSMNT_INO64;
1647#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001648 cmn_err(CE_WARN,
1649 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001650 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 return EINVAL;
1652#endif
1653 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1654 args->flags |= XFSMNT_NOALIGN;
1655 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1656 args->flags |= XFSMNT_SWALLOC;
1657 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1658 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001659 cmn_err(CE_WARN,
1660 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001661 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 return EINVAL;
1663 }
1664 dsunit = simple_strtoul(value, &eov, 10);
1665 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1666 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001667 cmn_err(CE_WARN,
1668 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001669 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 return EINVAL;
1671 }
1672 dswidth = simple_strtoul(value, &eov, 10);
1673 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1674 args->flags &= ~XFSMNT_32BITINODES;
1675#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001676 cmn_err(CE_WARN,
1677 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001678 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 return EINVAL;
1680#endif
1681 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1682 args->flags |= XFSMNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001683 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1684 args->flags |= XFSMNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001685 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1686 args->flags &= ~XFSMNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
Vlad Apostolov574342f2007-09-14 15:23:44 +10001688 ikeep = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 args->flags &= ~XFSMNT_IDELETE;
1690 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1691 args->flags |= XFSMNT_IDELETE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001692 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001693 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001694 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001695 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001696 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001697 args->flags |= XFSMNT_ATTR2;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001698 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001699 args->flags &= ~XFSMNT_ATTR2;
David Chinner2a82b8b2007-07-11 11:09:12 +10001700 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1701 args->flags2 |= XFSMNT2_FILESTREAMS;
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001702 } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
1703 args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA);
1704 args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA);
1705 } else if (!strcmp(this_char, MNTOPT_QUOTA) ||
1706 !strcmp(this_char, MNTOPT_UQUOTA) ||
1707 !strcmp(this_char, MNTOPT_USRQUOTA)) {
1708 args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF;
1709 } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) ||
1710 !strcmp(this_char, MNTOPT_UQUOTANOENF)) {
1711 args->flags |= XFSMNT_UQUOTA;
1712 args->flags &= ~XFSMNT_UQUOTAENF;
1713 } else if (!strcmp(this_char, MNTOPT_PQUOTA) ||
1714 !strcmp(this_char, MNTOPT_PRJQUOTA)) {
1715 args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF;
1716 } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) {
1717 args->flags |= XFSMNT_PQUOTA;
1718 args->flags &= ~XFSMNT_PQUOTAENF;
1719 } else if (!strcmp(this_char, MNTOPT_GQUOTA) ||
1720 !strcmp(this_char, MNTOPT_GRPQUOTA)) {
1721 args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF;
1722 } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
1723 args->flags |= XFSMNT_GQUOTA;
1724 args->flags &= ~XFSMNT_GQUOTAENF;
Christoph Hellwig293688e2007-08-29 11:59:36 +10001725 } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
1726 args->flags |= XFSMNT_DMAPI;
1727 } else if (!strcmp(this_char, MNTOPT_XDSM)) {
1728 args->flags |= XFSMNT_DMAPI;
1729 } else if (!strcmp(this_char, MNTOPT_DMI)) {
1730 args->flags |= XFSMNT_DMAPI;
David Chinnerda353b02007-08-28 14:00:13 +10001731 } else if (!strcmp(this_char, "ihashsize")) {
1732 cmn_err(CE_WARN,
1733 "XFS: ihashsize no longer used, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 } else if (!strcmp(this_char, "osyncisdsync")) {
1735 /* no-op, this is now the default */
Nathan Scottb6574522006-06-09 15:29:40 +10001736 cmn_err(CE_WARN,
1737 "XFS: osyncisdsync is now the default, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 } else if (!strcmp(this_char, "irixsgid")) {
Nathan Scottb6574522006-06-09 15:29:40 +10001739 cmn_err(CE_WARN,
1740 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 } else {
Nathan Scottb6574522006-06-09 15:29:40 +10001742 cmn_err(CE_WARN,
1743 "XFS: unknown mount option [%s].", this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 return EINVAL;
1745 }
1746 }
1747
1748 if (args->flags & XFSMNT_NORECOVERY) {
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001749 if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) {
Nathan Scottb6574522006-06-09 15:29:40 +10001750 cmn_err(CE_WARN,
1751 "XFS: no-recovery mounts must be read-only.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 return EINVAL;
1753 }
1754 }
1755
1756 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001757 cmn_err(CE_WARN,
1758 "XFS: sunit and swidth options incompatible with the noalign option");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 return EINVAL;
1760 }
1761
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001762 if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) {
1763 cmn_err(CE_WARN,
1764 "XFS: cannot mount with both project and group quota");
1765 return EINVAL;
1766 }
1767
Christoph Hellwig293688e2007-08-29 11:59:36 +10001768 if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') {
1769 printk("XFS: %s option needs the mount point option as well\n",
1770 MNTOPT_DMAPI);
1771 return EINVAL;
1772 }
1773
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001775 cmn_err(CE_WARN,
1776 "XFS: sunit and swidth must be specified together");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 return EINVAL;
1778 }
1779
1780 if (dsunit && (dswidth % dsunit != 0)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001781 cmn_err(CE_WARN,
1782 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 dswidth, dsunit);
1784 return EINVAL;
1785 }
1786
Vlad Apostolov574342f2007-09-14 15:23:44 +10001787 /*
1788 * Applications using DMI filesystems often expect the
1789 * inode generation number to be monotonically increasing.
1790 * If we delete inode chunks we break this assumption, so
1791 * keep unused inode chunks on disk for DMI filesystems
1792 * until we come up with a better solution.
1793 * Note that if "ikeep" or "noikeep" mount options are
1794 * supplied, then they are honored.
1795 */
1796 if (!(args->flags & XFSMNT_DMAPI) && !ikeep)
1797 args->flags |= XFSMNT_IDELETE;
1798
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1800 if (dsunit) {
1801 args->sunit = dsunit;
1802 args->flags |= XFSMNT_RETERR;
1803 } else {
1804 args->sunit = vol_dsunit;
1805 }
1806 dswidth ? (args->swidth = dswidth) :
1807 (args->swidth = vol_dswidth);
1808 } else {
1809 args->sunit = args->swidth = 0;
1810 }
1811
Nathan Scott05db2182005-11-04 09:49:07 +11001812done:
Nathan Scottc11e2c32005-11-02 15:11:45 +11001813 if (args->flags & XFSMNT_32BITINODES)
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001814 mp->m_flags |= XFS_MOUNT_SMALL_INUMS;
Nathan Scotte718eeb42005-11-02 15:09:22 +11001815 if (args->flags2)
1816 args->flags |= XFSMNT_FLAGS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 return 0;
1818}
1819
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001820int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821xfs_showargs(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001822 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 struct seq_file *m)
1824{
1825 static struct proc_xfs_info {
1826 int flag;
1827 char *str;
1828 } xfs_info[] = {
1829 /* the few simple ones we can get from the mount struct */
1830 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1831 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1832 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1833 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1834 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1835 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1836 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 { 0, NULL }
1838 };
1839 struct proc_xfs_info *xfs_infop;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
1841 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1842 if (mp->m_flags & xfs_infop->flag)
1843 seq_puts(m, xfs_infop->str);
1844 }
1845
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001847 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1848 (int)(1 << mp->m_writeio_log) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
1850 if (mp->m_logbufs > 0)
1851 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 if (mp->m_logbsize > 0)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001853 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001855 if (mp->m_logname)
1856 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001857 if (mp->m_rtname)
1858 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
1860 if (mp->m_dalign > 0)
1861 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1862 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 if (mp->m_swidth > 0)
1864 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1865 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1866
Nathan Scotte15f1952006-03-22 12:47:52 +11001867 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1868 seq_printf(m, "," MNTOPT_IKEEP);
Nathan Scottfa7e7d72005-11-02 15:00:48 +11001869 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1870 seq_printf(m, "," MNTOPT_LARGEIO);
1871
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001872 if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS))
Nathan Scottc11e2c32005-11-02 15:11:45 +11001873 seq_printf(m, "," MNTOPT_64BITINODE);
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001874 if (mp->m_flags & XFS_MOUNT_GRPID)
Nathan Scotte69a3332005-09-02 16:42:26 +10001875 seq_printf(m, "," MNTOPT_GRPID);
1876
Christoph Hellwigb09cc772007-08-30 17:19:57 +10001877 if (mp->m_qflags & XFS_UQUOTA_ACCT) {
1878 if (mp->m_qflags & XFS_UQUOTA_ENFD)
1879 seq_puts(m, "," MNTOPT_USRQUOTA);
1880 else
1881 seq_puts(m, "," MNTOPT_UQUOTANOENF);
1882 }
1883
1884 if (mp->m_qflags & XFS_PQUOTA_ACCT) {
1885 if (mp->m_qflags & XFS_OQUOTA_ENFD)
1886 seq_puts(m, "," MNTOPT_PRJQUOTA);
1887 else
1888 seq_puts(m, "," MNTOPT_PQUOTANOENF);
1889 }
1890
1891 if (mp->m_qflags & XFS_GQUOTA_ACCT) {
1892 if (mp->m_qflags & XFS_OQUOTA_ENFD)
1893 seq_puts(m, "," MNTOPT_GRPQUOTA);
1894 else
1895 seq_puts(m, "," MNTOPT_GQUOTANOENF);
1896 }
1897
1898 if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT))
1899 seq_puts(m, "," MNTOPT_NOQUOTA);
1900
Christoph Hellwigbd186aa2007-08-30 17:21:12 +10001901 if (mp->m_flags & XFS_MOUNT_DMAPI)
Christoph Hellwig293688e2007-08-29 11:59:36 +10001902 seq_puts(m, "," MNTOPT_DMAPI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 return 0;
1904}
1905
David Chinner28239452007-02-10 18:36:40 +11001906/*
David Chinner516b2e72007-06-18 16:50:48 +10001907 * Second stage of a freeze. The data is already frozen so we only
1908 * need to take care of themetadata. Once that's done write a dummy
1909 * record to dirty the log in case of a crash while frozen.
David Chinner28239452007-02-10 18:36:40 +11001910 */
Tim Shimmin479ba362007-10-16 15:32:57 +10001911void
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912xfs_freeze(
Christoph Hellwig48c872a9f2007-08-30 17:20:31 +10001913 xfs_mount_t *mp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914{
David Chinner516b2e72007-06-18 16:50:48 +10001915 xfs_attr_quiesce(mp);
Christoph Hellwige13a73f2006-01-11 15:30:08 +11001916 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917}