blob: 8c0e02279249afc9e2482d341a276bb26ac4c177 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_types.h"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110023#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_trans.h"
25#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110026#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "xfs_dir2.h"
28#include "xfs_dmapi.h"
29#include "xfs_mount.h"
Nathan Scotta844f452005-11-02 14:38:42 +110030#include "xfs_da_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "xfs_bmap_btree.h"
32#include "xfs_ialloc_btree.h"
33#include "xfs_alloc_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110034#include "xfs_dir2_sf.h"
35#include "xfs_attr_sf.h"
36#include "xfs_dinode.h"
37#include "xfs_inode.h"
38#include "xfs_inode_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include "xfs_btree.h"
40#include "xfs_alloc.h"
41#include "xfs_ialloc.h"
Nathan Scotta844f452005-11-02 14:38:42 +110042#include "xfs_quota.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include "xfs_error.h"
44#include "xfs_bmap.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include "xfs_rw.h"
46#include "xfs_refcache.h"
47#include "xfs_buf_item.h"
Nathan Scotta844f452005-11-02 14:38:42 +110048#include "xfs_log_priv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include "xfs_dir2_trace.h"
Nathan Scotta844f452005-11-02 14:38:42 +110050#include "xfs_extfree_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#include "xfs_acl.h"
52#include "xfs_attr.h"
53#include "xfs_clnt.h"
David Chinner2a82b8b2007-07-11 11:09:12 +100054#include "xfs_mru_cache.h"
55#include "xfs_filestream.h"
Christoph Hellwige13a73f2006-01-11 15:30:08 +110056#include "xfs_fsops.h"
Christoph Hellwig739bfb22007-08-29 10:58:01 +100057#include "xfs_vnodeops.h"
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
David Chinner8d280b92006-03-14 13:13:09 +110060STATIC int xfs_sync(bhv_desc_t *, int, cred_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62int
63xfs_init(void)
64{
65 extern kmem_zone_t *xfs_bmap_free_item_zone;
66 extern kmem_zone_t *xfs_btree_cur_zone;
67 extern kmem_zone_t *xfs_trans_zone;
68 extern kmem_zone_t *xfs_buf_item_zone;
69 extern kmem_zone_t *xfs_dabuf_zone;
70#ifdef XFS_DABUF_DEBUG
71 extern lock_t xfs_dabuf_global_lock;
72 spinlock_init(&xfs_dabuf_global_lock, "xfsda");
73#endif
74
75 /*
76 * Initialize all of the zone allocators we use.
77 */
78 xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
79 "xfs_bmap_free_item");
80 xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
81 "xfs_btree_cur");
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
83 xfs_da_state_zone =
84 kmem_zone_init(sizeof(xfs_da_state_t), "xfs_da_state");
85 xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
Nathan Scott87582802006-03-14 13:18:19 +110086 xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
87 xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
David Chinner2a82b8b2007-07-11 11:09:12 +100088 xfs_mru_cache_init();
89 xfs_filestream_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 /*
92 * The size of the zone allocated buf log item is the maximum
93 * size possible under XFS. This wastes a little bit of memory,
94 * but it is much faster.
95 */
96 xfs_buf_item_zone =
97 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
98 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
99 NBWORD) * sizeof(int))),
100 "xfs_buf_item");
Nathan Scott87582802006-03-14 13:18:19 +1100101 xfs_efd_zone =
102 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
103 ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
104 sizeof(xfs_extent_t))),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 "xfs_efd_item");
Nathan Scott87582802006-03-14 13:18:19 +1100106 xfs_efi_zone =
107 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
108 ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
109 sizeof(xfs_extent_t))),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 "xfs_efi_item");
Nathan Scott87582802006-03-14 13:18:19 +1100111
112 /*
113 * These zones warrant special memory allocator hints
114 */
115 xfs_inode_zone =
116 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
117 KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
118 KM_ZONE_SPREAD, NULL);
119 xfs_ili_zone =
120 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
121 KM_ZONE_SPREAD, NULL);
David Chinnerda353b02007-08-28 14:00:13 +1000122 xfs_icluster_zone =
123 kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster",
Nathan Scott87582802006-03-14 13:18:19 +1100124 KM_ZONE_SPREAD, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 /*
127 * Allocate global trace buffers.
128 */
129#ifdef XFS_ALLOC_TRACE
130 xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
131#endif
132#ifdef XFS_BMAP_TRACE
133 xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
134#endif
135#ifdef XFS_BMBT_TRACE
136 xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
137#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#ifdef XFS_ATTR_TRACE
139 xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
140#endif
141#ifdef XFS_DIR2_TRACE
142 xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
143#endif
144
145 xfs_dir_startup();
146
147#if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
148 xfs_error_test_init();
149#endif /* DEBUG || INDUCE_IO_ERROR */
150
151 xfs_init_procfs();
152 xfs_sysctl_register();
153 return 0;
154}
155
156void
157xfs_cleanup(void)
158{
159 extern kmem_zone_t *xfs_bmap_free_item_zone;
160 extern kmem_zone_t *xfs_btree_cur_zone;
161 extern kmem_zone_t *xfs_inode_zone;
162 extern kmem_zone_t *xfs_trans_zone;
163 extern kmem_zone_t *xfs_da_state_zone;
164 extern kmem_zone_t *xfs_dabuf_zone;
165 extern kmem_zone_t *xfs_efd_zone;
166 extern kmem_zone_t *xfs_efi_zone;
167 extern kmem_zone_t *xfs_buf_item_zone;
David Chinnerda353b02007-08-28 14:00:13 +1000168 extern kmem_zone_t *xfs_icluster_zone;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 xfs_cleanup_procfs();
171 xfs_sysctl_unregister();
172 xfs_refcache_destroy();
David Chinner2a82b8b2007-07-11 11:09:12 +1000173 xfs_filestream_uninit();
174 xfs_mru_cache_uninit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 xfs_acl_zone_destroy(xfs_acl_zone);
176
177#ifdef XFS_DIR2_TRACE
178 ktrace_free(xfs_dir2_trace_buf);
179#endif
180#ifdef XFS_ATTR_TRACE
181 ktrace_free(xfs_attr_trace_buf);
182#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183#ifdef XFS_BMBT_TRACE
184 ktrace_free(xfs_bmbt_trace_buf);
185#endif
186#ifdef XFS_BMAP_TRACE
187 ktrace_free(xfs_bmap_trace_buf);
188#endif
189#ifdef XFS_ALLOC_TRACE
190 ktrace_free(xfs_alloc_trace_buf);
191#endif
192
Nathan Scott3758dee2006-03-22 12:47:28 +1100193 kmem_zone_destroy(xfs_bmap_free_item_zone);
194 kmem_zone_destroy(xfs_btree_cur_zone);
195 kmem_zone_destroy(xfs_inode_zone);
196 kmem_zone_destroy(xfs_trans_zone);
197 kmem_zone_destroy(xfs_da_state_zone);
198 kmem_zone_destroy(xfs_dabuf_zone);
199 kmem_zone_destroy(xfs_buf_item_zone);
200 kmem_zone_destroy(xfs_efd_zone);
201 kmem_zone_destroy(xfs_efi_zone);
202 kmem_zone_destroy(xfs_ifork_zone);
203 kmem_zone_destroy(xfs_ili_zone);
David Chinnerda353b02007-08-28 14:00:13 +1000204 kmem_zone_destroy(xfs_icluster_zone);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
207/*
208 * xfs_start_flags
209 *
210 * This function fills in xfs_mount_t fields based on mount args.
211 * Note: the superblock has _not_ yet been read in.
212 */
213STATIC int
214xfs_start_flags(
Nathan Scottb83bd132006-06-09 16:48:30 +1000215 struct bhv_vfs *vfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 struct xfs_mount_args *ap,
217 struct xfs_mount *mp)
218{
219 /* Values are in BBs */
220 if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
221 /*
222 * At this point the superblock has not been read
223 * in, therefore we do not know the block size.
224 * Before the mount call ends we will convert
225 * these to FSBs.
226 */
227 mp->m_dalign = ap->sunit;
228 mp->m_swidth = ap->swidth;
229 }
230
231 if (ap->logbufs != -1 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 ap->logbufs != 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 (ap->logbufs < XLOG_MIN_ICLOGS ||
234 ap->logbufs > XLOG_MAX_ICLOGS)) {
235 cmn_err(CE_WARN,
236 "XFS: invalid logbufs value: %d [not %d-%d]",
237 ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
238 return XFS_ERROR(EINVAL);
239 }
240 mp->m_logbufs = ap->logbufs;
241 if (ap->logbufsize != -1 &&
Nathan Scottcfcbbbd2005-11-02 15:12:04 +1100242 ap->logbufsize != 0 &&
Eric Sandeendcb3b832007-08-16 16:25:33 +1000243 (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
244 ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
245 !is_power_of_2(ap->logbufsize))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 cmn_err(CE_WARN,
247 "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
248 ap->logbufsize);
249 return XFS_ERROR(EINVAL);
250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 mp->m_logbsize = ap->logbufsize;
252 mp->m_fsname_len = strlen(ap->fsname) + 1;
253 mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
254 strcpy(mp->m_fsname, ap->fsname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +1100255 if (ap->rtname[0]) {
256 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
257 strcpy(mp->m_rtname, ap->rtname);
258 }
259 if (ap->logname[0]) {
260 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
261 strcpy(mp->m_logname, ap->logname);
262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 if (ap->flags & XFSMNT_WSYNC)
265 mp->m_flags |= XFS_MOUNT_WSYNC;
266#if XFS_BIG_INUMS
267 if (ap->flags & XFSMNT_INO64) {
268 mp->m_flags |= XFS_MOUNT_INO64;
269 mp->m_inoadd = XFS_INO64_OFFSET;
270 }
271#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 if (ap->flags & XFSMNT_RETERR)
273 mp->m_flags |= XFS_MOUNT_RETERR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 if (ap->flags & XFSMNT_NOALIGN)
275 mp->m_flags |= XFS_MOUNT_NOALIGN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 if (ap->flags & XFSMNT_SWALLOC)
277 mp->m_flags |= XFS_MOUNT_SWALLOC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 if (ap->flags & XFSMNT_OSYNCISOSYNC)
279 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 if (ap->flags & XFSMNT_32BITINODES)
Nathan Scottc11e2c32005-11-02 15:11:45 +1100281 mp->m_flags |= XFS_MOUNT_32BITINODES;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283 if (ap->flags & XFSMNT_IOSIZE) {
284 if (ap->iosizelog > XFS_MAX_IO_LOG ||
285 ap->iosizelog < XFS_MIN_IO_LOG) {
286 cmn_err(CE_WARN,
287 "XFS: invalid log iosize: %d [not %d-%d]",
288 ap->iosizelog, XFS_MIN_IO_LOG,
289 XFS_MAX_IO_LOG);
290 return XFS_ERROR(EINVAL);
291 }
292
293 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
294 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
295 }
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 if (ap->flags & XFSMNT_IDELETE)
298 mp->m_flags |= XFS_MOUNT_IDELETE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (ap->flags & XFSMNT_DIRSYNC)
300 mp->m_flags |= XFS_MOUNT_DIRSYNC;
Nathan Scott13059ff2006-01-11 15:32:01 +1100301 if (ap->flags & XFSMNT_ATTR2)
302 mp->m_flags |= XFS_MOUNT_ATTR2;
David Chinnere8c8b3a2005-11-02 10:33:05 +1100303
Nathan Scotte718eeb42005-11-02 15:09:22 +1100304 if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
305 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 /*
308 * no recovery flag requires a read-only mount
309 */
310 if (ap->flags & XFSMNT_NORECOVERY) {
311 if (!(vfs->vfs_flag & VFS_RDONLY)) {
312 cmn_err(CE_WARN,
313 "XFS: tried to mount a FS read-write without recovery!");
314 return XFS_ERROR(EINVAL);
315 }
316 mp->m_flags |= XFS_MOUNT_NORECOVERY;
317 }
318
319 if (ap->flags & XFSMNT_NOUUID)
320 mp->m_flags |= XFS_MOUNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100321 if (ap->flags & XFSMNT_BARRIER)
322 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +1100323 else
324 mp->m_flags &= ~XFS_MOUNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
David Chinner2a82b8b2007-07-11 11:09:12 +1000326 if (ap->flags2 & XFSMNT2_FILESTREAMS)
327 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
328
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(
Nathan Scottb83bd132006-06-09 16:48:30 +1000338 struct bhv_vfs *vfs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 struct xfs_mount_args *ap,
340 struct xfs_mount *mp)
341{
342 int ronly = (vfs->vfs_flag & VFS_RDONLY);
343
344 /* Fail a mount where the logbuf is smaller then the log stripe */
345 if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) {
Nathan Scottc2cd2552006-01-11 15:35:32 +1100346 if ((ap->logbufsize <= 0) &&
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
348 mp->m_logbsize = mp->m_sb.sb_logsunit;
Nathan Scottc2cd2552006-01-11 15:35:32 +1100349 } else if (ap->logbufsize > 0 &&
350 ap->logbufsize < mp->m_sb.sb_logsunit) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 cmn_err(CE_WARN,
352 "XFS: logbuf size must be greater than or equal to log stripe size");
353 return XFS_ERROR(EINVAL);
354 }
355 } else {
356 /* Fail a mount if the logbuf is larger than 32K */
357 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
358 cmn_err(CE_WARN,
359 "XFS: logbuf size for version 1 logs must be 16K or 32K");
360 return XFS_ERROR(EINVAL);
361 }
362 }
363
Nathan Scott13059ff2006-01-11 15:32:01 +1100364 if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) {
365 mp->m_flags |= XFS_MOUNT_ATTR2;
366 }
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /*
369 * prohibit r/w mounts of read-only filesystems
370 */
371 if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
372 cmn_err(CE_WARN,
373 "XFS: cannot mount a read-only filesystem as read-write");
374 return XFS_ERROR(EROFS);
375 }
376
377 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 * check for shared mount.
379 */
380 if (ap->flags & XFSMNT_SHARED) {
381 if (!XFS_SB_VERSION_HASSHARED(&mp->m_sb))
382 return XFS_ERROR(EINVAL);
383
384 /*
385 * For IRIX 6.5, shared mounts must have the shared
386 * version bit set, have the persistent readonly
387 * field set, must be version 0 and can only be mounted
388 * read-only.
389 */
390 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
391 (mp->m_sb.sb_shared_vn != 0))
392 return XFS_ERROR(EINVAL);
393
394 mp->m_flags |= XFS_MOUNT_SHARED;
395
396 /*
397 * Shared XFS V0 can't deal with DMI. Return EINVAL.
398 */
399 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
400 return XFS_ERROR(EINVAL);
401 }
402
403 return 0;
404}
405
406/*
407 * xfs_mount
408 *
409 * The file system configurations are:
410 * (1) device (partition) with data and internal log
411 * (2) logical volume with data and log subvolumes.
412 * (3) logical volume with data, log, and realtime subvolumes.
413 *
414 * We only have to handle opening the log and realtime volumes here if
415 * they are present. The data subvolume has already been opened by
416 * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
417 */
418STATIC int
419xfs_mount(
420 struct bhv_desc *bhvp,
421 struct xfs_mount_args *args,
422 cred_t *credp)
423{
Nathan Scottb83bd132006-06-09 16:48:30 +1000424 struct bhv_vfs *vfsp = bhvtovfs(bhvp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 struct bhv_desc *p;
426 struct xfs_mount *mp = XFS_BHVTOM(bhvp);
427 struct block_device *ddev, *logdev, *rtdev;
428 int flags = 0, error;
429
430 ddev = vfsp->vfs_super->s_bdev;
431 logdev = rtdev = NULL;
432
433 /*
434 * Setup xfs_mount function vectors from available behaviors
435 */
436 p = vfs_bhv_lookup(vfsp, VFS_POSITION_DM);
437 mp->m_dm_ops = p ? *(xfs_dmops_t *) vfs_bhv_custom(p) : xfs_dmcore_stub;
438 p = vfs_bhv_lookup(vfsp, VFS_POSITION_QM);
439 mp->m_qm_ops = p ? *(xfs_qmops_t *) vfs_bhv_custom(p) : xfs_qmcore_stub;
440 p = vfs_bhv_lookup(vfsp, VFS_POSITION_IO);
441 mp->m_io_ops = p ? *(xfs_ioops_t *) vfs_bhv_custom(p) : xfs_iocore_xfs;
442
Nathan Scott764d1f82006-03-31 13:04:17 +1000443 if (args->flags & XFSMNT_QUIET)
444 flags |= XFS_MFSI_QUIET;
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 /*
447 * Open real time and log devices - order is important.
448 */
449 if (args->logname[0]) {
450 error = xfs_blkdev_get(mp, args->logname, &logdev);
451 if (error)
452 return error;
453 }
454 if (args->rtname[0]) {
455 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
456 if (error) {
457 xfs_blkdev_put(logdev);
458 return error;
459 }
460
461 if (rtdev == ddev || rtdev == logdev) {
462 cmn_err(CE_WARN,
463 "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
464 xfs_blkdev_put(logdev);
465 xfs_blkdev_put(rtdev);
466 return EINVAL;
467 }
468 }
469
470 /*
471 * Setup xfs_mount buffer target pointers
472 */
473 error = ENOMEM;
474 mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
475 if (!mp->m_ddev_targp) {
476 xfs_blkdev_put(logdev);
477 xfs_blkdev_put(rtdev);
478 return error;
479 }
480 if (rtdev) {
481 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000482 if (!mp->m_rtdev_targp) {
483 xfs_blkdev_put(logdev);
484 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
488 mp->m_logdev_targp = (logdev && logdev != ddev) ?
489 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000490 if (!mp->m_logdev_targp) {
491 xfs_blkdev_put(logdev);
492 xfs_blkdev_put(rtdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 goto error0;
Jesper Juhl49ee6c92007-08-16 16:25:42 +1000494 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496 /*
497 * Setup flags based on mount(2) options and then the superblock
498 */
499 error = xfs_start_flags(vfsp, args, mp);
500 if (error)
501 goto error1;
Nathan Scott764d1f82006-03-31 13:04:17 +1000502 error = xfs_readsb(mp, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 if (error)
504 goto error1;
505 error = xfs_finish_flags(vfsp, args, mp);
506 if (error)
507 goto error2;
508
509 /*
510 * Setup xfs_mount buffer target pointers based on superblock
511 */
512 error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
513 mp->m_sb.sb_sectsize);
514 if (!error && logdev && logdev != ddev) {
515 unsigned int log_sector_size = BBSIZE;
516
517 if (XFS_SB_VERSION_HASSECTOR(&mp->m_sb))
518 log_sector_size = mp->m_sb.sb_logsectsize;
519 error = xfs_setsize_buftarg(mp->m_logdev_targp,
520 mp->m_sb.sb_blocksize,
521 log_sector_size);
522 }
523 if (!error && rtdev)
524 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
525 mp->m_sb.sb_blocksize,
526 mp->m_sb.sb_sectsize);
527 if (error)
528 goto error2;
529
Nathan Scottb2ea4012006-07-28 17:05:13 +1000530 if (mp->m_flags & XFS_MOUNT_BARRIER)
Christoph Hellwigc7d437d2006-01-11 15:28:56 +1100531 xfs_mountfs_check_barriers(mp);
532
David Chinner2a82b8b2007-07-11 11:09:12 +1000533 if ((error = xfs_filestream_mount(mp)))
534 goto error2;
535
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 error = XFS_IOINIT(vfsp, args, flags);
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100537 if (error)
538 goto error2;
539
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100540 return 0;
541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542error2:
543 if (mp->m_sb_bp)
544 xfs_freesb(mp);
545error1:
546 xfs_binval(mp->m_ddev_targp);
547 if (logdev && logdev != ddev)
548 xfs_binval(mp->m_logdev_targp);
549 if (rtdev)
550 xfs_binval(mp->m_rtdev_targp);
551error0:
552 xfs_unmountfs_close(mp, credp);
553 return error;
554}
555
556STATIC int
557xfs_unmount(
558 bhv_desc_t *bdp,
559 int flags,
560 cred_t *credp)
561{
Nathan Scottb83bd132006-06-09 16:48:30 +1000562 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 xfs_mount_t *mp = XFS_BHVTOM(bdp);
564 xfs_inode_t *rip;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000565 bhv_vnode_t *rvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 int unmount_event_wanted = 0;
567 int unmount_event_flags = 0;
568 int xfs_unmountfs_needed = 0;
569 int error;
570
571 rip = mp->m_rootip;
572 rvp = XFS_ITOV(rip);
573
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000574#ifdef HAVE_DMAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (vfsp->vfs_flag & VFS_DMI) {
576 error = XFS_SEND_PREUNMOUNT(mp, vfsp,
577 rvp, DM_RIGHT_NULL, rvp, DM_RIGHT_NULL,
578 NULL, NULL, 0, 0,
579 (mp->m_dmevmask & (1<<DM_EVENT_PREUNMOUNT))?
580 0:DM_FLAGS_UNWANTED);
581 if (error)
582 return XFS_ERROR(error);
583 unmount_event_wanted = 1;
584 unmount_event_flags = (mp->m_dmevmask & (1<<DM_EVENT_UNMOUNT))?
585 0 : DM_FLAGS_UNWANTED;
586 }
Eric Sandeen948c6d4f2007-08-23 16:19:57 +1000587#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 /*
589 * First blow any referenced inode from this file system
590 * out of the reference cache, and delete the timer.
591 */
592 xfs_refcache_purge_mp(mp);
593
David Chinner2a82b8b2007-07-11 11:09:12 +1000594 /*
595 * Blow away any referenced inode in the filestreams cache.
596 * This can and will cause log traffic as inodes go inactive
597 * here.
598 */
599 xfs_filestream_unmount(mp);
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 XFS_bflush(mp->m_ddev_targp);
602 error = xfs_unmount_flush(mp, 0);
603 if (error)
604 goto out;
605
606 ASSERT(vn_count(rvp) == 1);
607
608 /*
609 * Drop the reference count
610 */
611 VN_RELE(rvp);
612
613 /*
614 * If we're forcing a shutdown, typically because of a media error,
615 * we want to make sure we invalidate dirty pages that belong to
616 * referenced vnodes as well.
617 */
618 if (XFS_FORCED_SHUTDOWN(mp)) {
619 error = xfs_sync(&mp->m_bhv,
620 (SYNC_WAIT | SYNC_CLOSE), credp);
621 ASSERT(error != EFSCORRUPTED);
622 }
623 xfs_unmountfs_needed = 1;
624
625out:
626 /* Send DMAPI event, if required.
627 * Then do xfs_unmountfs() if needed.
628 * Then return error (or zero).
629 */
630 if (unmount_event_wanted) {
631 /* Note: mp structure must still exist for
632 * XFS_SEND_UNMOUNT() call.
633 */
634 XFS_SEND_UNMOUNT(mp, vfsp, error == 0 ? rvp : NULL,
635 DM_RIGHT_NULL, 0, error, unmount_event_flags);
636 }
637 if (xfs_unmountfs_needed) {
638 /*
639 * Call common unmount function to flush to disk
640 * and free the super block buffer & mount structures.
641 */
642 xfs_unmountfs(mp, credp);
Christoph Hellwigf541d272007-08-29 11:53:22 +1000643 kmem_free(mp, sizeof(xfs_mount_t));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
645
646 return XFS_ERROR(error);
647}
648
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000649STATIC int
650xfs_quiesce_fs(
651 xfs_mount_t *mp)
652{
653 int count = 0, pincount;
Nathan Scott3758dee2006-03-22 12:47:28 +1100654
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000655 xfs_refcache_purge_mp(mp);
656 xfs_flush_buftarg(mp->m_ddev_targp, 0);
657 xfs_finish_reclaim_all(mp, 0);
658
659 /* This loop must run at least twice.
660 * The first instance of the loop will flush
661 * most meta data but that will generate more
662 * meta data (typically directory updates).
663 * Which then must be flushed and logged before
664 * we can write the unmount record.
Nathan Scott3758dee2006-03-22 12:47:28 +1100665 */
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000666 do {
David Chinner516b2e72007-06-18 16:50:48 +1000667 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000668 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
669 if (!pincount) {
670 delay(50);
671 count++;
672 }
673 } while (count < 2);
674
675 return 0;
676}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
David Chinner516b2e72007-06-18 16:50:48 +1000678/*
679 * Second stage of a quiesce. The data is already synced, now we have to take
680 * care of the metadata. New transactions are already blocked, so we need to
681 * wait for any remaining transactions to drain out before proceding.
682 */
683STATIC void
684xfs_attr_quiesce(
685 xfs_mount_t *mp)
686{
687 /* wait for all modifications to complete */
688 while (atomic_read(&mp->m_active_trans) > 0)
689 delay(100);
690
691 /* flush inodes and push all remaining buffers out to disk */
692 xfs_quiesce_fs(mp);
693
694 ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
695
696 /* Push the superblock and write an unmount record */
697 xfs_log_sbcount(mp, 1);
698 xfs_log_unmount_write(mp);
699 xfs_unmountfs_writesb(mp);
700}
701
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702STATIC int
703xfs_mntupdate(
704 bhv_desc_t *bdp,
705 int *flags,
706 struct xfs_mount_args *args)
707{
Nathan Scottb83bd132006-06-09 16:48:30 +1000708 bhv_vfs_t *vfsp = bhvtovfs(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Nathan Scottd08d3892006-05-08 19:51:28 +1000711 if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */
712 if (vfsp->vfs_flag & VFS_RDONLY)
713 vfsp->vfs_flag &= ~VFS_RDONLY;
714 if (args->flags & XFSMNT_BARRIER) {
715 mp->m_flags |= XFS_MOUNT_BARRIER;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +1100716 xfs_mountfs_check_barriers(mp);
Nathan Scottd08d3892006-05-08 19:51:28 +1000717 } else {
718 mp->m_flags &= ~XFS_MOUNT_BARRIER;
719 }
720 } else if (!(vfsp->vfs_flag & VFS_RDONLY)) { /* rw -> ro */
David Chinner2a82b8b2007-07-11 11:09:12 +1000721 xfs_filestream_flush(mp);
David Chinner516b2e72007-06-18 16:50:48 +1000722 bhv_vfs_sync(vfsp, SYNC_DATA_QUIESCE, NULL);
723 xfs_attr_quiesce(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 vfsp->vfs_flag |= VFS_RDONLY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 return 0;
727}
728
729/*
730 * xfs_unmount_flush implements a set of flush operation on special
731 * inodes, which are needed as a separate set of operations so that
732 * they can be called as part of relocation process.
733 */
734int
735xfs_unmount_flush(
736 xfs_mount_t *mp, /* Mount structure we are getting
737 rid of. */
738 int relocation) /* Called from vfs relocation. */
739{
740 xfs_inode_t *rip = mp->m_rootip;
741 xfs_inode_t *rbmip;
742 xfs_inode_t *rsumip = NULL;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000743 bhv_vnode_t *rvp = XFS_ITOV(rip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 int error;
745
Lachlan McIlroyf7c66ce2007-05-08 13:50:19 +1000746 xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 xfs_iflock(rip);
748
749 /*
750 * Flush out the real time inodes.
751 */
752 if ((rbmip = mp->m_rbmip) != NULL) {
753 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
754 xfs_iflock(rbmip);
755 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
756 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
757
758 if (error == EFSCORRUPTED)
759 goto fscorrupt_out;
760
761 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
762
763 rsumip = mp->m_rsumip;
764 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
765 xfs_iflock(rsumip);
766 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
767 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
768
769 if (error == EFSCORRUPTED)
770 goto fscorrupt_out;
771
772 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
773 }
774
775 /*
776 * Synchronously flush root inode to disk
777 */
778 error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
779 if (error == EFSCORRUPTED)
780 goto fscorrupt_out2;
781
782 if (vn_count(rvp) != 1 && !relocation) {
783 xfs_iunlock(rip, XFS_ILOCK_EXCL);
784 return XFS_ERROR(EBUSY);
785 }
786
787 /*
788 * Release dquot that rootinode, rbmino and rsumino might be holding,
789 * flush and purge the quota inodes.
790 */
791 error = XFS_QM_UNMOUNT(mp);
792 if (error == EFSCORRUPTED)
793 goto fscorrupt_out2;
794
795 if (rbmip) {
796 VN_RELE(XFS_ITOV(rbmip));
797 VN_RELE(XFS_ITOV(rsumip));
798 }
799
800 xfs_iunlock(rip, XFS_ILOCK_EXCL);
801 return 0;
802
803fscorrupt_out:
804 xfs_ifunlock(rip);
805
806fscorrupt_out2:
807 xfs_iunlock(rip, XFS_ILOCK_EXCL);
808
809 return XFS_ERROR(EFSCORRUPTED);
810}
811
812/*
813 * xfs_root extracts the root vnode from a vfs.
814 *
815 * vfsp -- the vfs struct for the desired file system
816 * vpp -- address of the caller's vnode pointer which should be
817 * set to the desired fs root vnode
818 */
819STATIC int
820xfs_root(
821 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000822 bhv_vnode_t **vpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000824 bhv_vnode_t *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 vp = XFS_ITOV((XFS_BHVTOM(bdp))->m_rootip);
827 VN_HOLD(vp);
828 *vpp = vp;
829 return 0;
830}
831
832/*
833 * xfs_statvfs
834 *
835 * Fill in the statvfs structure for the given file system. We use
836 * the superblock lock in the mount structure to ensure a consistent
837 * snapshot of the counters returned.
838 */
839STATIC int
840xfs_statvfs(
841 bhv_desc_t *bdp,
Nathan Scott8285fb52006-06-09 17:07:12 +1000842 bhv_statvfs_t *statp,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000843 bhv_vnode_t *vp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844{
845 __uint64_t fakeinos;
846 xfs_extlen_t lsize;
847 xfs_mount_t *mp;
848 xfs_sb_t *sbp;
849 unsigned long s;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
851 mp = XFS_BHVTOM(bdp);
852 sbp = &(mp->m_sb);
853
854 statp->f_type = XFS_SB_MAGIC;
855
David Chinnerdbcabad2007-02-10 18:36:17 +1100856 xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 s = XFS_SB_LOCK(mp);
858 statp->f_bsize = sbp->sb_blocksize;
859 lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0;
860 statp->f_blocks = sbp->sb_dblocks - lsize;
David Chinner4be536d2006-09-07 14:26:50 +1000861 statp->f_bfree = statp->f_bavail =
862 sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 fakeinos = statp->f_bfree << sbp->sb_inopblog;
864#if XFS_BIG_INUMS
865 fakeinos += mp->m_inoadd;
866#endif
867 statp->f_files =
868 MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER);
869 if (mp->m_maxicount)
870#if XFS_BIG_INUMS
871 if (!mp->m_inoadd)
872#endif
873 statp->f_files = min_t(typeof(statp->f_files),
874 statp->f_files,
875 mp->m_maxicount);
876 statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree);
877 XFS_SB_UNLOCK(mp, s);
878
Nathan Scottcde410a2005-09-05 11:47:01 +1000879 xfs_statvfs_fsid(statp, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 statp->f_namelen = MAXNAMELEN - 1;
881
882 return 0;
883}
884
885
886/*
887 * xfs_sync flushes any pending I/O to file system vfsp.
888 *
889 * This routine is called by vfs_sync() to make sure that things make it
890 * out to disk eventually, on sync() system calls to flush out everything,
891 * and when the file system is unmounted. For the vfs_sync() case, all
892 * we really need to do is sync out the log to make all of our meta-data
893 * updates permanent (except for timestamps). For calls from pflushd(),
894 * dirty pages are kept moving by calling pdflush() on the inodes
895 * containing them. We also flush the inodes that we can lock without
896 * sleeping and the superblock if we can lock it without sleeping from
897 * vfs_sync() so that items at the tail of the log are always moving out.
898 *
899 * Flags:
900 * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
901 * to sleep if we can help it. All we really need
902 * to do is ensure that the log is synced at least
903 * periodically. We also push the inodes and
904 * superblock if we can lock them without sleeping
905 * and they are not pinned.
906 * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not
907 * set, then we really want to lock each inode and flush
908 * it.
909 * SYNC_WAIT - All the flushes that take place in this call should
910 * be synchronous.
911 * SYNC_DELWRI - This tells us to push dirty pages associated with
912 * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to
913 * determine if they should be flushed sync, async, or
914 * delwri.
915 * SYNC_CLOSE - This flag is passed when the system is being
Nathan Scottc41564b2006-03-29 08:55:14 +1000916 * unmounted. We should sync and invalidate everything.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 * SYNC_FSDATA - This indicates that the caller would like to make
918 * sure the superblock is safe on disk. We can ensure
Nathan Scottc41564b2006-03-29 08:55:14 +1000919 * this by simply making sure the log gets flushed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 * if SYNC_BDFLUSH is set, and by actually writing it
921 * out otherwise.
David Chinner3c0dc772007-02-10 18:37:22 +1100922 * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete
923 * before we return (including direct I/O). Forms the drain
924 * side of the write barrier needed to safely quiesce the
925 * filesystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 *
927 */
928/*ARGSUSED*/
929STATIC int
930xfs_sync(
931 bhv_desc_t *bdp,
932 int flags,
933 cred_t *credp)
934{
Christoph Hellwigf898d6c2005-06-21 15:40:48 +1000935 xfs_mount_t *mp = XFS_BHVTOM(bdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
David Chinner2a82b8b2007-07-11 11:09:12 +1000937 if (flags & SYNC_IOWAIT)
938 xfs_filestream_flush(mp);
939
David Chinner28239452007-02-10 18:36:40 +1100940 return xfs_syncsub(mp, flags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941}
942
943/*
944 * xfs sync routine for internal use
945 *
Nathan Scottb83bd132006-06-09 16:48:30 +1000946 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +1100947 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 *
949 */
Nathan Scottee348072005-11-02 10:32:38 +1100950int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951xfs_sync_inodes(
952 xfs_mount_t *mp,
953 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 int *bypassed)
955{
956 xfs_inode_t *ip = NULL;
957 xfs_inode_t *ip_next;
958 xfs_buf_t *bp;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000959 bhv_vnode_t *vp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 int error;
961 int last_error;
962 uint64_t fflag;
963 uint lock_flags;
964 uint base_lock_flags;
965 boolean_t mount_locked;
966 boolean_t vnode_refed;
967 int preempt;
968 xfs_dinode_t *dip;
969 xfs_iptr_t *ipointer;
970#ifdef DEBUG
971 boolean_t ipointer_in = B_FALSE;
972
973#define IPOINTER_SET ipointer_in = B_TRUE
974#define IPOINTER_CLR ipointer_in = B_FALSE
975#else
976#define IPOINTER_SET
977#define IPOINTER_CLR
978#endif
979
980
981/* Insert a marker record into the inode list after inode ip. The list
982 * must be locked when this is called. After the call the list will no
983 * longer be locked.
984 */
985#define IPOINTER_INSERT(ip, mp) { \
986 ASSERT(ipointer_in == B_FALSE); \
987 ipointer->ip_mnext = ip->i_mnext; \
988 ipointer->ip_mprev = ip; \
989 ip->i_mnext = (xfs_inode_t *)ipointer; \
990 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
991 preempt = 0; \
992 XFS_MOUNT_IUNLOCK(mp); \
993 mount_locked = B_FALSE; \
994 IPOINTER_SET; \
995 }
996
997/* Remove the marker from the inode list. If the marker was the only item
998 * in the list then there are no remaining inodes and we should zero out
999 * the whole list. If we are the current head of the list then move the head
1000 * past us.
1001 */
1002#define IPOINTER_REMOVE(ip, mp) { \
1003 ASSERT(ipointer_in == B_TRUE); \
1004 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
1005 ip = ipointer->ip_mnext; \
1006 ip->i_mprev = ipointer->ip_mprev; \
1007 ipointer->ip_mprev->i_mnext = ip; \
1008 if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
1009 mp->m_inodes = ip; \
1010 } \
1011 } else { \
1012 ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
1013 mp->m_inodes = NULL; \
1014 ip = NULL; \
1015 } \
1016 IPOINTER_CLR; \
1017 }
1018
1019#define XFS_PREEMPT_MASK 0x7f
1020
1021 if (bypassed)
1022 *bypassed = 0;
1023 if (XFS_MTOVFS(mp)->vfs_flag & VFS_RDONLY)
1024 return 0;
1025 error = 0;
1026 last_error = 0;
1027 preempt = 0;
1028
1029 /* Allocate a reference marker */
1030 ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
1031
1032 fflag = XFS_B_ASYNC; /* default is don't wait */
Nathan Scottee348072005-11-02 10:32:38 +11001033 if (flags & (SYNC_BDFLUSH | SYNC_DELWRI))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 fflag = XFS_B_DELWRI;
1035 if (flags & SYNC_WAIT)
1036 fflag = 0; /* synchronous overrides all */
1037
1038 base_lock_flags = XFS_ILOCK_SHARED;
1039 if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
1040 /*
1041 * We need the I/O lock if we're going to call any of
1042 * the flush/inval routines.
1043 */
1044 base_lock_flags |= XFS_IOLOCK_SHARED;
1045 }
1046
1047 XFS_MOUNT_ILOCK(mp);
1048
1049 ip = mp->m_inodes;
1050
1051 mount_locked = B_TRUE;
1052 vnode_refed = B_FALSE;
1053
1054 IPOINTER_CLR;
1055
1056 do {
1057 ASSERT(ipointer_in == B_FALSE);
1058 ASSERT(vnode_refed == B_FALSE);
1059
1060 lock_flags = base_lock_flags;
1061
1062 /*
1063 * There were no inodes in the list, just break out
1064 * of the loop.
1065 */
1066 if (ip == NULL) {
1067 break;
1068 }
1069
1070 /*
1071 * We found another sync thread marker - skip it
1072 */
1073 if (ip->i_mount == NULL) {
1074 ip = ip->i_mnext;
1075 continue;
1076 }
1077
1078 vp = XFS_ITOV_NULL(ip);
1079
1080 /*
1081 * If the vnode is gone then this is being torn down,
1082 * call reclaim if it is flushed, else let regular flush
1083 * code deal with it later in the loop.
1084 */
1085
1086 if (vp == NULL) {
1087 /* Skip ones already in reclaim */
1088 if (ip->i_flags & XFS_IRECLAIM) {
1089 ip = ip->i_mnext;
1090 continue;
1091 }
1092 if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
1093 ip = ip->i_mnext;
1094 } else if ((xfs_ipincount(ip) == 0) &&
1095 xfs_iflock_nowait(ip)) {
1096 IPOINTER_INSERT(ip, mp);
1097
1098 xfs_finish_reclaim(ip, 1,
1099 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
1100
1101 XFS_MOUNT_ILOCK(mp);
1102 mount_locked = B_TRUE;
1103 IPOINTER_REMOVE(ip, mp);
1104 } else {
1105 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1106 ip = ip->i_mnext;
1107 }
1108 continue;
1109 }
1110
1111 if (VN_BAD(vp)) {
1112 ip = ip->i_mnext;
1113 continue;
1114 }
1115
1116 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
1117 XFS_MOUNT_IUNLOCK(mp);
1118 kmem_free(ipointer, sizeof(xfs_iptr_t));
1119 return 0;
1120 }
1121
1122 /*
1123 * If this is just vfs_sync() or pflushd() calling
1124 * then we can skip inodes for which it looks like
1125 * there is nothing to do. Since we don't have the
Nathan Scottc41564b2006-03-29 08:55:14 +10001126 * inode locked this is racy, but these are periodic
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 * calls so it doesn't matter. For the others we want
1128 * to know for sure, so we at least try to lock them.
1129 */
1130 if (flags & SYNC_BDFLUSH) {
1131 if (((ip->i_itemp == NULL) ||
1132 !(ip->i_itemp->ili_format.ilf_fields &
1133 XFS_ILOG_ALL)) &&
1134 (ip->i_update_core == 0)) {
1135 ip = ip->i_mnext;
1136 continue;
1137 }
1138 }
1139
1140 /*
1141 * Try to lock without sleeping. We're out of order with
1142 * the inode list lock here, so if we fail we need to drop
1143 * the mount lock and try again. If we're called from
1144 * bdflush() here, then don't bother.
1145 *
1146 * The inode lock here actually coordinates with the
1147 * almost spurious inode lock in xfs_ireclaim() to prevent
1148 * the vnode we handle here without a reference from
1149 * being freed while we reference it. If we lock the inode
1150 * while it's on the mount list here, then the spurious inode
1151 * lock in xfs_ireclaim() after the inode is pulled from
1152 * the mount list will sleep until we release it here.
1153 * This keeps the vnode from being freed while we reference
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001154 * it.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 */
1156 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 if ((flags & SYNC_BDFLUSH) || (vp == NULL)) {
1158 ip = ip->i_mnext;
1159 continue;
1160 }
1161
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001162 vp = vn_grab(vp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 if (vp == NULL) {
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001164 ip = ip->i_mnext;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 continue;
1166 }
1167
Christoph Hellwigcdb62682005-09-02 16:24:19 +10001168 IPOINTER_INSERT(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 xfs_ilock(ip, lock_flags);
1170
1171 ASSERT(vp == XFS_ITOV(ip));
1172 ASSERT(ip->i_mount == mp);
1173
1174 vnode_refed = B_TRUE;
1175 }
1176
1177 /* From here on in the loop we may have a marker record
1178 * in the inode list.
1179 */
1180
David Chinner40095b62007-05-14 18:24:09 +10001181 /*
1182 * If we have to flush data or wait for I/O completion
1183 * we need to drop the ilock that we currently hold.
1184 * If we need to drop the lock, insert a marker if we
1185 * have not already done so.
1186 */
1187 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
1188 ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1189 if (mount_locked) {
1190 IPOINTER_INSERT(ip, mp);
1191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1193
David Chinner40095b62007-05-14 18:24:09 +10001194 if (flags & SYNC_CLOSE) {
1195 /* Shutdown case. Flush and invalidate. */
1196 if (XFS_FORCED_SHUTDOWN(mp))
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001197 xfs_tosspages(ip, 0, -1,
1198 FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001199 else
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001200 error = xfs_flushinval_pages(ip,
1201 0, -1, FI_REMAPF);
David Chinner40095b62007-05-14 18:24:09 +10001202 } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
Christoph Hellwig739bfb22007-08-29 10:58:01 +10001203 error = xfs_flush_pages(ip, 0,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001204 -1, fflag, FI_NONE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
1206
David Chinner40095b62007-05-14 18:24:09 +10001207 /*
1208 * When freezing, we need to wait ensure all I/O (including direct
1209 * I/O) is complete to ensure no further data modification can take
1210 * place after this point
1211 */
1212 if (flags & SYNC_IOWAIT)
Christoph Hellwigb677c212007-08-29 11:46:28 +10001213 vn_iowait(ip);
David Chinner40095b62007-05-14 18:24:09 +10001214
1215 xfs_ilock(ip, XFS_ILOCK_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 }
1217
1218 if (flags & SYNC_BDFLUSH) {
1219 if ((flags & SYNC_ATTR) &&
1220 ((ip->i_update_core) ||
1221 ((ip->i_itemp != NULL) &&
1222 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1223
1224 /* Insert marker and drop lock if not already
1225 * done.
1226 */
1227 if (mount_locked) {
1228 IPOINTER_INSERT(ip, mp);
1229 }
1230
1231 /*
1232 * We don't want the periodic flushing of the
1233 * inodes by vfs_sync() to interfere with
1234 * I/O to the file, especially read I/O
1235 * where it is only the access time stamp
1236 * that is being flushed out. To prevent
1237 * long periods where we have both inode
1238 * locks held shared here while reading the
1239 * inode's buffer in from disk, we drop the
1240 * inode lock while reading in the inode
1241 * buffer. We have to release the buffer
1242 * and reacquire the inode lock so that they
1243 * are acquired in the proper order (inode
1244 * locks first). The buffer will go at the
1245 * end of the lru chain, though, so we can
1246 * expect it to still be there when we go
1247 * for it again in xfs_iflush().
1248 */
1249 if ((xfs_ipincount(ip) == 0) &&
1250 xfs_iflock_nowait(ip)) {
1251
1252 xfs_ifunlock(ip);
1253 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1254
1255 error = xfs_itobp(mp, NULL, ip,
Nathan Scottb12dd342006-03-17 17:26:04 +11001256 &dip, &bp, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 if (!error) {
1258 xfs_buf_relse(bp);
1259 } else {
1260 /* Bailing out, remove the
1261 * marker and free it.
1262 */
1263 XFS_MOUNT_ILOCK(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 IPOINTER_REMOVE(ip, mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 XFS_MOUNT_IUNLOCK(mp);
1266
1267 ASSERT(!(lock_flags &
1268 XFS_IOLOCK_SHARED));
1269
1270 kmem_free(ipointer,
1271 sizeof(xfs_iptr_t));
1272 return (0);
1273 }
1274
1275 /*
1276 * Since we dropped the inode lock,
1277 * the inode may have been reclaimed.
1278 * Therefore, we reacquire the mount
1279 * lock and check to see if we were the
1280 * inode reclaimed. If this happened
1281 * then the ipointer marker will no
1282 * longer point back at us. In this
1283 * case, move ip along to the inode
1284 * after the marker, remove the marker
1285 * and continue.
1286 */
1287 XFS_MOUNT_ILOCK(mp);
1288 mount_locked = B_TRUE;
1289
1290 if (ip != ipointer->ip_mprev) {
1291 IPOINTER_REMOVE(ip, mp);
1292
1293 ASSERT(!vnode_refed);
1294 ASSERT(!(lock_flags &
1295 XFS_IOLOCK_SHARED));
1296 continue;
1297 }
1298
1299 ASSERT(ip->i_mount == mp);
1300
1301 if (xfs_ilock_nowait(ip,
1302 XFS_ILOCK_SHARED) == 0) {
1303 ASSERT(ip->i_mount == mp);
1304 /*
1305 * We failed to reacquire
1306 * the inode lock without
1307 * sleeping, so just skip
1308 * the inode for now. We
1309 * clear the ILOCK bit from
1310 * the lock_flags so that we
1311 * won't try to drop a lock
1312 * we don't hold below.
1313 */
1314 lock_flags &= ~XFS_ILOCK_SHARED;
1315 IPOINTER_REMOVE(ip_next, mp);
1316 } else if ((xfs_ipincount(ip) == 0) &&
1317 xfs_iflock_nowait(ip)) {
1318 ASSERT(ip->i_mount == mp);
1319 /*
1320 * Since this is vfs_sync()
1321 * calling we only flush the
1322 * inode out if we can lock
1323 * it without sleeping and
1324 * it is not pinned. Drop
1325 * the mount lock here so
1326 * that we don't hold it for
1327 * too long. We already have
1328 * a marker in the list here.
1329 */
1330 XFS_MOUNT_IUNLOCK(mp);
1331 mount_locked = B_FALSE;
1332 error = xfs_iflush(ip,
1333 XFS_IFLUSH_DELWRI);
1334 } else {
1335 ASSERT(ip->i_mount == mp);
1336 IPOINTER_REMOVE(ip_next, mp);
1337 }
1338 }
1339
1340 }
1341
1342 } else {
1343 if ((flags & SYNC_ATTR) &&
1344 ((ip->i_update_core) ||
1345 ((ip->i_itemp != NULL) &&
1346 (ip->i_itemp->ili_format.ilf_fields != 0)))) {
1347 if (mount_locked) {
1348 IPOINTER_INSERT(ip, mp);
1349 }
1350
1351 if (flags & SYNC_WAIT) {
1352 xfs_iflock(ip);
1353 error = xfs_iflush(ip,
1354 XFS_IFLUSH_SYNC);
1355 } else {
1356 /*
1357 * If we can't acquire the flush
1358 * lock, then the inode is already
1359 * being flushed so don't bother
1360 * waiting. If we can lock it then
1361 * do a delwri flush so we can
1362 * combine multiple inode flushes
1363 * in each disk write.
1364 */
1365 if (xfs_iflock_nowait(ip)) {
1366 error = xfs_iflush(ip,
1367 XFS_IFLUSH_DELWRI);
1368 }
1369 else if (bypassed)
1370 (*bypassed)++;
1371 }
1372 }
1373 }
1374
1375 if (lock_flags != 0) {
1376 xfs_iunlock(ip, lock_flags);
1377 }
1378
1379 if (vnode_refed) {
1380 /*
1381 * If we had to take a reference on the vnode
1382 * above, then wait until after we've unlocked
1383 * the inode to release the reference. This is
1384 * because we can be already holding the inode
1385 * lock when VN_RELE() calls xfs_inactive().
1386 *
1387 * Make sure to drop the mount lock before calling
1388 * VN_RELE() so that we don't trip over ourselves if
1389 * we have to go for the mount lock again in the
1390 * inactive code.
1391 */
1392 if (mount_locked) {
1393 IPOINTER_INSERT(ip, mp);
1394 }
1395
1396 VN_RELE(vp);
1397
1398 vnode_refed = B_FALSE;
1399 }
1400
1401 if (error) {
1402 last_error = error;
1403 }
1404
1405 /*
1406 * bail out if the filesystem is corrupted.
1407 */
1408 if (error == EFSCORRUPTED) {
1409 if (!mount_locked) {
1410 XFS_MOUNT_ILOCK(mp);
1411 IPOINTER_REMOVE(ip, mp);
1412 }
1413 XFS_MOUNT_IUNLOCK(mp);
1414 ASSERT(ipointer_in == B_FALSE);
1415 kmem_free(ipointer, sizeof(xfs_iptr_t));
1416 return XFS_ERROR(error);
1417 }
1418
1419 /* Let other threads have a chance at the mount lock
1420 * if we have looped many times without dropping the
1421 * lock.
1422 */
1423 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1424 if (mount_locked) {
1425 IPOINTER_INSERT(ip, mp);
1426 }
1427 }
1428
1429 if (mount_locked == B_FALSE) {
1430 XFS_MOUNT_ILOCK(mp);
1431 mount_locked = B_TRUE;
1432 IPOINTER_REMOVE(ip, mp);
1433 continue;
1434 }
1435
1436 ASSERT(ipointer_in == B_FALSE);
1437 ip = ip->i_mnext;
1438
1439 } while (ip != mp->m_inodes);
1440
1441 XFS_MOUNT_IUNLOCK(mp);
1442
1443 ASSERT(ipointer_in == B_FALSE);
1444
1445 kmem_free(ipointer, sizeof(xfs_iptr_t));
1446 return XFS_ERROR(last_error);
1447}
1448
1449/*
1450 * xfs sync routine for internal use
1451 *
Nathan Scottb83bd132006-06-09 16:48:30 +10001452 * This routine supports all of the flags defined for the generic vfs_sync
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001453 * interface as explained above under xfs_sync.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 *
1455 */
1456int
1457xfs_syncsub(
1458 xfs_mount_t *mp,
1459 int flags,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 int *bypassed)
1461{
1462 int error = 0;
1463 int last_error = 0;
1464 uint log_flags = XFS_LOG_FORCE;
1465 xfs_buf_t *bp;
1466 xfs_buf_log_item_t *bip;
1467
1468 /*
1469 * Sync out the log. This ensures that the log is periodically
1470 * flushed even if there is not enough activity to fill it up.
1471 */
1472 if (flags & SYNC_WAIT)
1473 log_flags |= XFS_LOG_SYNC;
1474
1475 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1476
1477 if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1478 if (flags & SYNC_BDFLUSH)
1479 xfs_finish_reclaim_all(mp, 1);
1480 else
Lachlan McIlroy1f9b3b62007-02-10 18:35:33 +11001481 error = xfs_sync_inodes(mp, flags, bypassed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 }
1483
1484 /*
1485 * Flushing out dirty data above probably generated more
1486 * log activity, so if this isn't vfs_sync() then flush
1487 * the log again.
1488 */
1489 if (flags & SYNC_DELWRI) {
1490 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1491 }
1492
1493 if (flags & SYNC_FSDATA) {
1494 /*
1495 * If this is vfs_sync() then only sync the superblock
1496 * if we can lock it without sleeping and it is not pinned.
1497 */
1498 if (flags & SYNC_BDFLUSH) {
1499 bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1500 if (bp != NULL) {
1501 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1502 if ((bip != NULL) &&
1503 xfs_buf_item_dirty(bip)) {
1504 if (!(XFS_BUF_ISPINNED(bp))) {
1505 XFS_BUF_ASYNC(bp);
1506 error = xfs_bwrite(mp, bp);
1507 } else {
1508 xfs_buf_relse(bp);
1509 }
1510 } else {
1511 xfs_buf_relse(bp);
1512 }
1513 }
1514 } else {
1515 bp = xfs_getsb(mp, 0);
1516 /*
1517 * If the buffer is pinned then push on the log so
1518 * we won't get stuck waiting in the write for
1519 * someone, maybe ourselves, to flush the log.
1520 * Even though we just pushed the log above, we
1521 * did not have the superblock buffer locked at
1522 * that point so it can become pinned in between
1523 * there and here.
1524 */
1525 if (XFS_BUF_ISPINNED(bp))
1526 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1527 if (flags & SYNC_WAIT)
1528 XFS_BUF_UNASYNC(bp);
1529 else
1530 XFS_BUF_ASYNC(bp);
1531 error = xfs_bwrite(mp, bp);
1532 }
1533 if (error) {
1534 last_error = error;
1535 }
1536 }
1537
1538 /*
1539 * If this is the periodic sync, then kick some entries out of
1540 * the reference cache. This ensures that idle entries are
1541 * eventually kicked out of the cache.
1542 */
1543 if (flags & SYNC_REFCACHE) {
Nathan Scottcde410a2005-09-05 11:47:01 +10001544 if (flags & SYNC_WAIT)
1545 xfs_refcache_purge_mp(mp);
1546 else
1547 xfs_refcache_purge_some(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
1549
1550 /*
David Chinner92821e22007-05-24 15:26:31 +10001551 * If asked, update the disk superblock with incore counter values if we
1552 * are using non-persistent counters so that they don't get too far out
1553 * of sync if we crash or get a forced shutdown. We don't want to force
1554 * this to disk, just get a transaction into the iclogs....
1555 */
1556 if (flags & SYNC_SUPER)
1557 xfs_log_sbcount(mp, 0);
1558
1559 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 * Now check to see if the log needs a "dummy" transaction.
1561 */
1562
1563 if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1564 xfs_trans_t *tp;
1565 xfs_inode_t *ip;
1566
1567 /*
1568 * Put a dummy transaction in the log to tell
1569 * recovery that all others are OK.
1570 */
1571 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1572 if ((error = xfs_trans_reserve(tp, 0,
1573 XFS_ICHANGE_LOG_RES(mp),
1574 0, 0, 0))) {
1575 xfs_trans_cancel(tp, 0);
1576 return error;
1577 }
1578
1579 ip = mp->m_rootip;
1580 xfs_ilock(ip, XFS_ILOCK_EXCL);
1581
1582 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1583 xfs_trans_ihold(tp, ip);
1584 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
Eric Sandeen1c72bf92007-05-08 13:48:42 +10001585 error = xfs_trans_commit(tp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1587 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1588 }
1589
1590 /*
1591 * When shutting down, we need to insure that the AIL is pushed
1592 * to disk or the filesystem can appear corrupt from the PROM.
1593 */
1594 if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1595 XFS_bflush(mp->m_ddev_targp);
1596 if (mp->m_rtdev_targp) {
1597 XFS_bflush(mp->m_rtdev_targp);
1598 }
1599 }
1600
1601 return XFS_ERROR(last_error);
1602}
1603
1604/*
1605 * xfs_vget - called by DMAPI and NFSD to get vnode from file handle
1606 */
1607STATIC int
1608xfs_vget(
1609 bhv_desc_t *bdp,
Nathan Scott67fcaa72006-06-09 17:00:52 +10001610 bhv_vnode_t **vpp,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 fid_t *fidp)
1612{
1613 xfs_mount_t *mp = XFS_BHVTOM(bdp);
1614 xfs_fid_t *xfid = (struct xfs_fid *)fidp;
1615 xfs_inode_t *ip;
1616 int error;
1617 xfs_ino_t ino;
1618 unsigned int igen;
1619
1620 /*
1621 * Invalid. Since handles can be created in user space and passed in
1622 * via gethandle(), this is not cause for a panic.
1623 */
1624 if (xfid->xfs_fid_len != sizeof(*xfid) - sizeof(xfid->xfs_fid_len))
1625 return XFS_ERROR(EINVAL);
1626
1627 ino = xfid->xfs_fid_ino;
1628 igen = xfid->xfs_fid_gen;
1629
1630 /*
1631 * NFS can sometimes send requests for ino 0. Fail them gracefully.
1632 */
1633 if (ino == 0)
1634 return XFS_ERROR(ESTALE);
1635
1636 error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0);
1637 if (error) {
1638 *vpp = NULL;
1639 return error;
1640 }
1641
1642 if (ip == NULL) {
1643 *vpp = NULL;
1644 return XFS_ERROR(EIO);
1645 }
1646
1647 if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) {
1648 xfs_iput_new(ip, XFS_ILOCK_SHARED);
1649 *vpp = NULL;
1650 return XFS_ERROR(ENOENT);
1651 }
1652
1653 *vpp = XFS_ITOV(ip);
1654 xfs_iunlock(ip, XFS_ILOCK_SHARED);
1655 return 0;
1656}
1657
1658
1659#define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */
1660#define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */
1661#define MNTOPT_LOGDEV "logdev" /* log device */
1662#define MNTOPT_RTDEV "rtdev" /* realtime I/O device */
1663#define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */
1664#define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */
1665#define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */
1666#define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */
1667#define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */
1668#define MNTOPT_SUNIT "sunit" /* data volume stripe unit */
1669#define MNTOPT_SWIDTH "swidth" /* data volume stripe width */
1670#define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */
1671#define MNTOPT_MTPT "mtpt" /* filesystem mount point */
Nathan Scotte69a3332005-09-02 16:42:26 +10001672#define MNTOPT_GRPID "grpid" /* group-ID from parent directory */
1673#define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */
1674#define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */
1675#define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */
Nathan Scott1f443ad2005-05-05 13:28:29 -07001676#define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677#define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001678#define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and
Nathan Scottd8cc8902005-11-02 10:34:53 +11001679 * unwritten extent conversion */
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001680#define MNTOPT_NOBARRIER "nobarrier" /* .. disable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
1682#define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */
1683#define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */
1684#define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */
David Chinnere8c8b3a2005-11-02 10:33:05 +11001685#define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */
1686#define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes
1687 * in stat(). */
Nathan Scottd8cc8902005-11-02 10:34:53 +11001688#define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */
1689#define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */
David Chinner2a82b8b2007-07-11 11:09:12 +10001690#define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
Nathan Scott1f443ad2005-05-05 13:28:29 -07001692STATIC unsigned long
Nathan Scottb190f112006-06-09 17:13:15 +10001693suffix_strtoul(char *s, char **endp, unsigned int base)
Nathan Scott1f443ad2005-05-05 13:28:29 -07001694{
1695 int last, shift_left_factor = 0;
Nathan Scottb190f112006-06-09 17:13:15 +10001696 char *value = s;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001697
1698 last = strlen(value) - 1;
1699 if (value[last] == 'K' || value[last] == 'k') {
1700 shift_left_factor = 10;
1701 value[last] = '\0';
1702 }
1703 if (value[last] == 'M' || value[last] == 'm') {
1704 shift_left_factor = 20;
1705 value[last] = '\0';
1706 }
1707 if (value[last] == 'G' || value[last] == 'g') {
1708 shift_left_factor = 30;
1709 value[last] = '\0';
1710 }
1711
Nathan Scottb190f112006-06-09 17:13:15 +10001712 return simple_strtoul((const char *)s, endp, base) << shift_left_factor;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001713}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10001715STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716xfs_parseargs(
1717 struct bhv_desc *bhv,
1718 char *options,
1719 struct xfs_mount_args *args,
1720 int update)
1721{
Nathan Scottb83bd132006-06-09 16:48:30 +10001722 bhv_vfs_t *vfsp = bhvtovfs(bhv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 char *this_char, *value, *eov;
1724 int dsunit, dswidth, vol_dsunit, vol_dswidth;
1725 int iosize;
1726
Vlad Apostolovb93bd202007-08-28 14:00:28 +10001727 /*
1728 * Applications using DMI filesystems often expect the
1729 * inode generation number to be monotonically increasing.
1730 * If we delete inode chunks we break this assumption, so
1731 * keep unused inode chunks on disk for DMI filesystems
1732 * until we come up with a better solution.
1733 * Note that if "ikeep" or "noikeep" mount options are
1734 * supplied, then they are honored.
1735 */
1736 if (!(args->flags & XFSMNT_DMAPI))
1737 args->flags |= XFSMNT_IDELETE;
1738
Nathan Scott3bbcc8e2006-03-31 13:04:56 +10001739 args->flags |= XFSMNT_BARRIER;
1740 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741
1742 if (!options)
Nathan Scott05db2182005-11-04 09:49:07 +11001743 goto done;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
1745 iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0;
1746
1747 while ((this_char = strsep(&options, ",")) != NULL) {
1748 if (!*this_char)
1749 continue;
1750 if ((value = strchr(this_char, '=')) != NULL)
1751 *value++ = 0;
1752
1753 if (!strcmp(this_char, MNTOPT_LOGBUFS)) {
1754 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001755 cmn_err(CE_WARN,
1756 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001757 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 return EINVAL;
1759 }
1760 args->logbufs = simple_strtoul(value, &eov, 10);
1761 } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001763 cmn_err(CE_WARN,
1764 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001765 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 return EINVAL;
1767 }
Nathan Scott1f443ad2005-05-05 13:28:29 -07001768 args->logbufsize = suffix_strtoul(value, &eov, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 } else if (!strcmp(this_char, MNTOPT_LOGDEV)) {
1770 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001771 cmn_err(CE_WARN,
1772 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001773 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 return EINVAL;
1775 }
1776 strncpy(args->logname, value, MAXNAMELEN);
1777 } else if (!strcmp(this_char, MNTOPT_MTPT)) {
1778 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001779 cmn_err(CE_WARN,
1780 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001781 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 return EINVAL;
1783 }
1784 strncpy(args->mtpt, value, MAXNAMELEN);
1785 } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
1786 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001787 cmn_err(CE_WARN,
1788 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001789 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 return EINVAL;
1791 }
1792 strncpy(args->rtname, value, MAXNAMELEN);
1793 } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) {
1794 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001795 cmn_err(CE_WARN,
1796 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001797 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 return EINVAL;
1799 }
1800 iosize = simple_strtoul(value, &eov, 10);
1801 args->flags |= XFSMNT_IOSIZE;
1802 args->iosizelog = (uint8_t) iosize;
Nathan Scott1f443ad2005-05-05 13:28:29 -07001803 } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) {
1804 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001805 cmn_err(CE_WARN,
1806 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001807 this_char);
1808 return EINVAL;
1809 }
1810 iosize = suffix_strtoul(value, &eov, 10);
1811 args->flags |= XFSMNT_IOSIZE;
1812 args->iosizelog = ffs(iosize) - 1;
Nathan Scotte69a3332005-09-02 16:42:26 +10001813 } else if (!strcmp(this_char, MNTOPT_GRPID) ||
1814 !strcmp(this_char, MNTOPT_BSDGROUPS)) {
1815 vfsp->vfs_flag |= VFS_GRPID;
1816 } else if (!strcmp(this_char, MNTOPT_NOGRPID) ||
1817 !strcmp(this_char, MNTOPT_SYSVGROUPS)) {
1818 vfsp->vfs_flag &= ~VFS_GRPID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
1820 args->flags |= XFSMNT_WSYNC;
1821 } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
1822 args->flags |= XFSMNT_OSYNCISOSYNC;
1823 } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
1824 args->flags |= XFSMNT_NORECOVERY;
1825 } else if (!strcmp(this_char, MNTOPT_INO64)) {
1826 args->flags |= XFSMNT_INO64;
1827#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001828 cmn_err(CE_WARN,
1829 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001830 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 return EINVAL;
1832#endif
1833 } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
1834 args->flags |= XFSMNT_NOALIGN;
1835 } else if (!strcmp(this_char, MNTOPT_SWALLOC)) {
1836 args->flags |= XFSMNT_SWALLOC;
1837 } else if (!strcmp(this_char, MNTOPT_SUNIT)) {
1838 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001839 cmn_err(CE_WARN,
1840 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001841 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 return EINVAL;
1843 }
1844 dsunit = simple_strtoul(value, &eov, 10);
1845 } else if (!strcmp(this_char, MNTOPT_SWIDTH)) {
1846 if (!value || !*value) {
Nathan Scottb6574522006-06-09 15:29:40 +10001847 cmn_err(CE_WARN,
1848 "XFS: %s option requires an argument",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001849 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 return EINVAL;
1851 }
1852 dswidth = simple_strtoul(value, &eov, 10);
1853 } else if (!strcmp(this_char, MNTOPT_64BITINODE)) {
1854 args->flags &= ~XFSMNT_32BITINODES;
1855#if !XFS_BIG_INUMS
Nathan Scottb6574522006-06-09 15:29:40 +10001856 cmn_err(CE_WARN,
1857 "XFS: %s option not allowed on this system",
Nathan Scott1f443ad2005-05-05 13:28:29 -07001858 this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 return EINVAL;
1860#endif
1861 } else if (!strcmp(this_char, MNTOPT_NOUUID)) {
1862 args->flags |= XFSMNT_NOUUID;
Christoph Hellwigf538d4d2005-11-02 10:26:59 +11001863 } else if (!strcmp(this_char, MNTOPT_BARRIER)) {
1864 args->flags |= XFSMNT_BARRIER;
Christoph Hellwig4ef19dd2006-01-11 15:27:18 +11001865 } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) {
1866 args->flags &= ~XFSMNT_BARRIER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
1868 args->flags &= ~XFSMNT_IDELETE;
1869 } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
1870 args->flags |= XFSMNT_IDELETE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001871 } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001872 args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE;
David Chinnere8c8b3a2005-11-02 10:33:05 +11001873 } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) {
Nathan Scotte718eeb42005-11-02 15:09:22 +11001874 args->flags2 |= XFSMNT2_COMPAT_IOSIZE;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001875 } else if (!strcmp(this_char, MNTOPT_ATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001876 args->flags |= XFSMNT_ATTR2;
Nathan Scottd8cc8902005-11-02 10:34:53 +11001877 } else if (!strcmp(this_char, MNTOPT_NOATTR2)) {
Nathan Scott13059ff2006-01-11 15:32:01 +11001878 args->flags &= ~XFSMNT_ATTR2;
David Chinner2a82b8b2007-07-11 11:09:12 +10001879 } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
1880 args->flags2 |= XFSMNT2_FILESTREAMS;
David Chinnerda353b02007-08-28 14:00:13 +10001881 } else if (!strcmp(this_char, "ihashsize")) {
1882 cmn_err(CE_WARN,
1883 "XFS: ihashsize no longer used, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 } else if (!strcmp(this_char, "osyncisdsync")) {
1885 /* no-op, this is now the default */
Nathan Scottb6574522006-06-09 15:29:40 +10001886 cmn_err(CE_WARN,
1887 "XFS: osyncisdsync is now the default, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 } else if (!strcmp(this_char, "irixsgid")) {
Nathan Scottb6574522006-06-09 15:29:40 +10001889 cmn_err(CE_WARN,
1890 "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 } else {
Nathan Scottb6574522006-06-09 15:29:40 +10001892 cmn_err(CE_WARN,
1893 "XFS: unknown mount option [%s].", this_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 return EINVAL;
1895 }
1896 }
1897
1898 if (args->flags & XFSMNT_NORECOVERY) {
1899 if ((vfsp->vfs_flag & VFS_RDONLY) == 0) {
Nathan Scottb6574522006-06-09 15:29:40 +10001900 cmn_err(CE_WARN,
1901 "XFS: no-recovery mounts must be read-only.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 return EINVAL;
1903 }
1904 }
1905
1906 if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001907 cmn_err(CE_WARN,
1908 "XFS: sunit and swidth options incompatible with the noalign option");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 return EINVAL;
1910 }
1911
1912 if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001913 cmn_err(CE_WARN,
1914 "XFS: sunit and swidth must be specified together");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 return EINVAL;
1916 }
1917
1918 if (dsunit && (dswidth % dsunit != 0)) {
Nathan Scottb6574522006-06-09 15:29:40 +10001919 cmn_err(CE_WARN,
1920 "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 dswidth, dsunit);
1922 return EINVAL;
1923 }
1924
1925 if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
1926 if (dsunit) {
1927 args->sunit = dsunit;
1928 args->flags |= XFSMNT_RETERR;
1929 } else {
1930 args->sunit = vol_dsunit;
1931 }
1932 dswidth ? (args->swidth = dswidth) :
1933 (args->swidth = vol_dswidth);
1934 } else {
1935 args->sunit = args->swidth = 0;
1936 }
1937
Nathan Scott05db2182005-11-04 09:49:07 +11001938done:
Nathan Scottc11e2c32005-11-02 15:11:45 +11001939 if (args->flags & XFSMNT_32BITINODES)
1940 vfsp->vfs_flag |= VFS_32BITINODES;
Nathan Scotte718eeb42005-11-02 15:09:22 +11001941 if (args->flags2)
1942 args->flags |= XFSMNT_FLAGS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 return 0;
1944}
1945
Christoph Hellwigba0f32d2005-06-21 15:36:52 +10001946STATIC int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947xfs_showargs(
1948 struct bhv_desc *bhv,
1949 struct seq_file *m)
1950{
1951 static struct proc_xfs_info {
1952 int flag;
1953 char *str;
1954 } xfs_info[] = {
1955 /* the few simple ones we can get from the mount struct */
1956 { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC },
1957 { XFS_MOUNT_INO64, "," MNTOPT_INO64 },
1958 { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN },
1959 { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC },
1960 { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID },
1961 { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY },
1962 { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC },
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 { 0, NULL }
1964 };
1965 struct proc_xfs_info *xfs_infop;
1966 struct xfs_mount *mp = XFS_BHVTOM(bhv);
Nathan Scottb83bd132006-06-09 16:48:30 +10001967 struct bhv_vfs *vfsp = XFS_MTOVFS(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
1969 for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) {
1970 if (mp->m_flags & xfs_infop->flag)
1971 seq_puts(m, xfs_infop->str);
1972 }
1973
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001975 seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk",
1976 (int)(1 << mp->m_writeio_log) >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
1978 if (mp->m_logbufs > 0)
1979 seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 if (mp->m_logbsize > 0)
Nathan Scottcfcbbbd2005-11-02 15:12:04 +11001981 seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001983 if (mp->m_logname)
1984 seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname);
Nathan Scottfc1f8c12005-11-02 11:44:33 +11001985 if (mp->m_rtname)
1986 seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987
1988 if (mp->m_dalign > 0)
1989 seq_printf(m, "," MNTOPT_SUNIT "=%d",
1990 (int)XFS_FSB_TO_BB(mp, mp->m_dalign));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 if (mp->m_swidth > 0)
1992 seq_printf(m, "," MNTOPT_SWIDTH "=%d",
1993 (int)XFS_FSB_TO_BB(mp, mp->m_swidth));
1994
Nathan Scotte15f1952006-03-22 12:47:52 +11001995 if (!(mp->m_flags & XFS_MOUNT_IDELETE))
1996 seq_printf(m, "," MNTOPT_IKEEP);
Nathan Scottfa7e7d72005-11-02 15:00:48 +11001997 if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE))
1998 seq_printf(m, "," MNTOPT_LARGEIO);
1999
Nathan Scottc11e2c32005-11-02 15:11:45 +11002000 if (!(vfsp->vfs_flag & VFS_32BITINODES))
2001 seq_printf(m, "," MNTOPT_64BITINODE);
Nathan Scotte69a3332005-09-02 16:42:26 +10002002 if (vfsp->vfs_flag & VFS_GRPID)
2003 seq_printf(m, "," MNTOPT_GRPID);
2004
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 return 0;
2006}
2007
David Chinner28239452007-02-10 18:36:40 +11002008/*
David Chinner516b2e72007-06-18 16:50:48 +10002009 * Second stage of a freeze. The data is already frozen so we only
2010 * need to take care of themetadata. Once that's done write a dummy
2011 * record to dirty the log in case of a crash while frozen.
David Chinner28239452007-02-10 18:36:40 +11002012 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013STATIC void
2014xfs_freeze(
2015 bhv_desc_t *bdp)
2016{
2017 xfs_mount_t *mp = XFS_BHVTOM(bdp);
2018
David Chinner516b2e72007-06-18 16:50:48 +10002019 xfs_attr_quiesce(mp);
Christoph Hellwige13a73f2006-01-11 15:30:08 +11002020 xfs_fs_log_dummy(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021}
2022
2023
Nathan Scottb83bd132006-06-09 16:48:30 +10002024bhv_vfsops_t xfs_vfsops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 BHV_IDENTITY_INIT(VFS_BHV_XFS,VFS_POSITION_XFS),
2026 .vfs_parseargs = xfs_parseargs,
2027 .vfs_showargs = xfs_showargs,
2028 .vfs_mount = xfs_mount,
2029 .vfs_unmount = xfs_unmount,
2030 .vfs_mntupdate = xfs_mntupdate,
2031 .vfs_root = xfs_root,
2032 .vfs_statvfs = xfs_statvfs,
2033 .vfs_sync = xfs_sync,
2034 .vfs_vget = xfs_vget,
2035 .vfs_dmapiops = (vfs_dmapiops_t)fs_nosys,
2036 .vfs_quotactl = (vfs_quotactl_t)fs_nosys,
2037 .vfs_init_vnode = xfs_initialize_vnode,
2038 .vfs_force_shutdown = xfs_do_force_shutdown,
2039 .vfs_freeze = xfs_freeze,
2040};