Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
7b718769 NS |
2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
1da177e4 | 4 | * |
7b718769 NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
1da177e4 LT |
7 | * published by the Free Software Foundation. |
8 | * | |
7b718769 NS |
9 | * 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. | |
1da177e4 | 13 | * |
7b718769 NS |
14 | * 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 | |
1da177e4 | 17 | */ |
1da177e4 | 18 | #include "xfs.h" |
a844f451 | 19 | #include "xfs_fs.h" |
1da177e4 | 20 | #include "xfs_types.h" |
a844f451 | 21 | #include "xfs_bit.h" |
1da177e4 | 22 | #include "xfs_log.h" |
a844f451 | 23 | #include "xfs_inum.h" |
1da177e4 LT |
24 | #include "xfs_trans.h" |
25 | #include "xfs_sb.h" | |
a844f451 | 26 | #include "xfs_ag.h" |
1da177e4 LT |
27 | #include "xfs_dir2.h" |
28 | #include "xfs_dmapi.h" | |
29 | #include "xfs_mount.h" | |
a844f451 | 30 | #include "xfs_da_btree.h" |
1da177e4 LT |
31 | #include "xfs_bmap_btree.h" |
32 | #include "xfs_ialloc_btree.h" | |
33 | #include "xfs_alloc_btree.h" | |
1da177e4 | 34 | #include "xfs_dir2_sf.h" |
a844f451 | 35 | #include "xfs_attr_sf.h" |
1da177e4 | 36 | #include "xfs_dinode.h" |
1da177e4 | 37 | #include "xfs_inode.h" |
a844f451 NS |
38 | #include "xfs_inode_item.h" |
39 | #include "xfs_btree.h" | |
40 | #include "xfs_alloc.h" | |
41 | #include "xfs_ialloc.h" | |
42 | #include "xfs_quota.h" | |
1da177e4 LT |
43 | #include "xfs_error.h" |
44 | #include "xfs_bmap.h" | |
1da177e4 LT |
45 | #include "xfs_rw.h" |
46 | #include "xfs_refcache.h" | |
47 | #include "xfs_buf_item.h" | |
a844f451 | 48 | #include "xfs_log_priv.h" |
1da177e4 | 49 | #include "xfs_dir2_trace.h" |
a844f451 | 50 | #include "xfs_extfree_item.h" |
1da177e4 LT |
51 | #include "xfs_acl.h" |
52 | #include "xfs_attr.h" | |
53 | #include "xfs_clnt.h" | |
2a82b8be DC |
54 | #include "xfs_mru_cache.h" |
55 | #include "xfs_filestream.h" | |
e13a73f0 | 56 | #include "xfs_fsops.h" |
739bfb2a | 57 | #include "xfs_vnodeops.h" |
48c872a9 | 58 | #include "xfs_vfsops.h" |
739bfb2a | 59 | |
1da177e4 | 60 | |
1da177e4 LT |
61 | int |
62 | xfs_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 | |
703e1f0f | 70 | extern spinlock_t xfs_dabuf_global_lock; |
007c61c6 | 71 | spin_lock_init(&xfs_dabuf_global_lock); |
1da177e4 LT |
72 | #endif |
73 | ||
74 | /* | |
75 | * Initialize all of the zone allocators we use. | |
76 | */ | |
77 | xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t), | |
78 | "xfs_bmap_free_item"); | |
79 | xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t), | |
80 | "xfs_btree_cur"); | |
1da177e4 LT |
81 | 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"); | |
8758280f NS |
85 | xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork"); |
86 | xfs_acl_zone_init(xfs_acl_zone, "xfs_acl"); | |
2a82b8be DC |
87 | xfs_mru_cache_init(); |
88 | xfs_filestream_init(); | |
1da177e4 LT |
89 | |
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"); | |
8758280f NS |
100 | 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))), | |
1da177e4 | 104 | "xfs_efd_item"); |
8758280f NS |
105 | 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))), | |
1da177e4 | 109 | "xfs_efi_item"); |
8758280f NS |
110 | |
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); | |
da353b0d DC |
121 | xfs_icluster_zone = |
122 | kmem_zone_init_flags(sizeof(xfs_icluster_t), "xfs_icluster", | |
8758280f | 123 | KM_ZONE_SPREAD, NULL); |
1da177e4 LT |
124 | |
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 | |
1da177e4 LT |
137 | #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 | ||
155 | void | |
156 | xfs_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; | |
da353b0d | 167 | extern kmem_zone_t *xfs_icluster_zone; |
1da177e4 LT |
168 | |
169 | xfs_cleanup_procfs(); | |
170 | xfs_sysctl_unregister(); | |
171 | xfs_refcache_destroy(); | |
2a82b8be DC |
172 | xfs_filestream_uninit(); |
173 | xfs_mru_cache_uninit(); | |
1da177e4 LT |
174 | 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 | |
1da177e4 LT |
182 | #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 | ||
3758dee9 NS |
192 | 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); | |
da353b0d | 203 | kmem_zone_destroy(xfs_icluster_zone); |
1da177e4 LT |
204 | } |
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 | */ | |
212 | STATIC int | |
213 | xfs_start_flags( | |
1da177e4 LT |
214 | 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 && | |
1da177e4 | 230 | ap->logbufs != 0 && |
1da177e4 LT |
231 | (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 && | |
cfcbbbd0 | 240 | ap->logbufsize != 0 && |
dcb3b83f ES |
241 | (ap->logbufsize < XLOG_MIN_RECORD_BSIZE || |
242 | ap->logbufsize > XLOG_MAX_RECORD_BSIZE || | |
243 | !is_power_of_2(ap->logbufsize))) { | |
1da177e4 LT |
244 | 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 | } | |
1da177e4 LT |
249 | 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); | |
fc1f8c1c NS |
253 | 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 | } | |
1da177e4 LT |
261 | |
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 | |
1da177e4 LT |
270 | if (ap->flags & XFSMNT_RETERR) |
271 | mp->m_flags |= XFS_MOUNT_RETERR; | |
1da177e4 LT |
272 | if (ap->flags & XFSMNT_NOALIGN) |
273 | mp->m_flags |= XFS_MOUNT_NOALIGN; | |
1da177e4 LT |
274 | if (ap->flags & XFSMNT_SWALLOC) |
275 | mp->m_flags |= XFS_MOUNT_SWALLOC; | |
1da177e4 LT |
276 | if (ap->flags & XFSMNT_OSYNCISOSYNC) |
277 | mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC; | |
1da177e4 | 278 | if (ap->flags & XFSMNT_32BITINODES) |
c11e2c36 | 279 | mp->m_flags |= XFS_MOUNT_32BITINODES; |
1da177e4 LT |
280 | |
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 | ||
1da177e4 LT |
295 | if (ap->flags & XFSMNT_IDELETE) |
296 | mp->m_flags |= XFS_MOUNT_IDELETE; | |
1da177e4 LT |
297 | if (ap->flags & XFSMNT_DIRSYNC) |
298 | mp->m_flags |= XFS_MOUNT_DIRSYNC; | |
13059ff0 NS |
299 | if (ap->flags & XFSMNT_ATTR2) |
300 | mp->m_flags |= XFS_MOUNT_ATTR2; | |
e8c8b3a7 | 301 | |
e718eeb4 NS |
302 | if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE) |
303 | mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE; | |
304 | ||
1da177e4 LT |
305 | /* |
306 | * no recovery flag requires a read-only mount | |
307 | */ | |
308 | if (ap->flags & XFSMNT_NORECOVERY) { | |
bd186aa9 | 309 | if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { |
1da177e4 LT |
310 | 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; | |
f538d4da CH |
319 | if (ap->flags & XFSMNT_BARRIER) |
320 | mp->m_flags |= XFS_MOUNT_BARRIER; | |
4ef19ddd CH |
321 | else |
322 | mp->m_flags &= ~XFS_MOUNT_BARRIER; | |
1da177e4 | 323 | |
2a82b8be DC |
324 | if (ap->flags2 & XFSMNT2_FILESTREAMS) |
325 | mp->m_flags |= XFS_MOUNT_FILESTREAMS; | |
326 | ||
293688ec | 327 | if (ap->flags & XFSMNT_DMAPI) |
bd186aa9 | 328 | mp->m_flags |= XFS_MOUNT_DMAPI; |
1da177e4 LT |
329 | 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 | */ | |
336 | STATIC int | |
337 | xfs_finish_flags( | |
1da177e4 LT |
338 | struct xfs_mount_args *ap, |
339 | struct xfs_mount *mp) | |
340 | { | |
bd186aa9 | 341 | int ronly = (mp->m_flags & XFS_MOUNT_RDONLY); |
1da177e4 LT |
342 | |
343 | /* Fail a mount where the logbuf is smaller then the log stripe */ | |
344 | if (XFS_SB_VERSION_HASLOGV2(&mp->m_sb)) { | |
c2cd2550 | 345 | if ((ap->logbufsize <= 0) && |
1da177e4 LT |
346 | (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) { |
347 | mp->m_logbsize = mp->m_sb.sb_logsunit; | |
c2cd2550 NS |
348 | } else if (ap->logbufsize > 0 && |
349 | ap->logbufsize < mp->m_sb.sb_logsunit) { | |
1da177e4 LT |
350 | 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 | ||
13059ff0 NS |
363 | if (XFS_SB_VERSION_HASATTR2(&mp->m_sb)) { |
364 | mp->m_flags |= XFS_MOUNT_ATTR2; | |
365 | } | |
366 | ||
1da177e4 LT |
367 | /* |
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 | ||
1da177e4 LT |
376 | /* |
377 | * 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 | ||
b09cc771 CH |
402 | 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 | ||
1da177e4 LT |
418 | 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 | */ | |
48c872a9 | 433 | int |
1da177e4 | 434 | xfs_mount( |
48c872a9 | 435 | struct xfs_mount *mp, |
1da177e4 LT |
436 | struct xfs_mount_args *args, |
437 | cred_t *credp) | |
438 | { | |
1da177e4 LT |
439 | struct block_device *ddev, *logdev, *rtdev; |
440 | int flags = 0, error; | |
441 | ||
b267ce99 | 442 | ddev = mp->m_super->s_bdev; |
1da177e4 LT |
443 | logdev = rtdev = NULL; |
444 | ||
293688ec | 445 | error = xfs_dmops_get(mp, args); |
b09cc771 CH |
446 | if (error) |
447 | return error; | |
448 | error = xfs_qmops_get(mp, args); | |
293688ec CH |
449 | if (error) |
450 | return error; | |
451 | ||
764d1f89 NS |
452 | if (args->flags & XFSMNT_QUIET) |
453 | flags |= XFS_MFSI_QUIET; | |
454 | ||
1da177e4 LT |
455 | /* |
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); | |
49ee6c91 JJ |
491 | if (!mp->m_rtdev_targp) { |
492 | xfs_blkdev_put(logdev); | |
493 | xfs_blkdev_put(rtdev); | |
1da177e4 | 494 | goto error0; |
49ee6c91 | 495 | } |
1da177e4 LT |
496 | } |
497 | mp->m_logdev_targp = (logdev && logdev != ddev) ? | |
498 | xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp; | |
49ee6c91 JJ |
499 | if (!mp->m_logdev_targp) { |
500 | xfs_blkdev_put(logdev); | |
501 | xfs_blkdev_put(rtdev); | |
1da177e4 | 502 | goto error0; |
49ee6c91 | 503 | } |
1da177e4 LT |
504 | |
505 | /* | |
506 | * Setup flags based on mount(2) options and then the superblock | |
507 | */ | |
b267ce99 | 508 | error = xfs_start_flags(args, mp); |
1da177e4 LT |
509 | if (error) |
510 | goto error1; | |
764d1f89 | 511 | error = xfs_readsb(mp, flags); |
1da177e4 LT |
512 | if (error) |
513 | goto error1; | |
b267ce99 | 514 | error = xfs_finish_flags(args, mp); |
1da177e4 LT |
515 | 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 | ||
b2ea401b | 539 | if (mp->m_flags & XFS_MOUNT_BARRIER) |
c7d437da CH |
540 | xfs_mountfs_check_barriers(mp); |
541 | ||
2a82b8be DC |
542 | if ((error = xfs_filestream_mount(mp))) |
543 | goto error2; | |
544 | ||
541d7d3c | 545 | error = xfs_mountfs(mp, flags); |
f538d4da CH |
546 | if (error) |
547 | goto error2; | |
548 | ||
293688ec CH |
549 | XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname); |
550 | ||
f538d4da CH |
551 | return 0; |
552 | ||
1da177e4 LT |
553 | error2: |
554 | if (mp->m_sb_bp) | |
555 | xfs_freesb(mp); | |
556 | error1: | |
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); | |
562 | error0: | |
563 | xfs_unmountfs_close(mp, credp); | |
b09cc771 | 564 | xfs_qmops_put(mp); |
293688ec | 565 | xfs_dmops_put(mp); |
1da177e4 LT |
566 | return error; |
567 | } | |
568 | ||
48c872a9 | 569 | int |
1da177e4 | 570 | xfs_unmount( |
48c872a9 | 571 | xfs_mount_t *mp, |
1da177e4 LT |
572 | int flags, |
573 | cred_t *credp) | |
574 | { | |
1da177e4 | 575 | xfs_inode_t *rip; |
67fcaa73 | 576 | bhv_vnode_t *rvp; |
1da177e4 LT |
577 | 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 | ||
948c6d4f | 585 | #ifdef HAVE_DMAPI |
bd186aa9 | 586 | if (mp->m_flags & XFS_MOUNT_DMAPI) { |
b267ce99 | 587 | error = XFS_SEND_PREUNMOUNT(mp, |
1da177e4 LT |
588 | 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 | } | |
948c6d4f | 598 | #endif |
1da177e4 LT |
599 | /* |
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 | ||
2a82b8be DC |
605 | /* |
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 | ||
1da177e4 LT |
612 | 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)) { | |
48c872a9 | 630 | error = xfs_sync(mp, SYNC_WAIT | SYNC_CLOSE); |
1da177e4 LT |
631 | ASSERT(error != EFSCORRUPTED); |
632 | } | |
633 | xfs_unmountfs_needed = 1; | |
634 | ||
635 | out: | |
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 | */ | |
b267ce99 | 644 | XFS_SEND_UNMOUNT(mp, error == 0 ? rvp : NULL, |
1da177e4 LT |
645 | 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); | |
b09cc771 | 653 | xfs_qmops_put(mp); |
293688ec | 654 | xfs_dmops_put(mp); |
f541d270 | 655 | kmem_free(mp, sizeof(xfs_mount_t)); |
1da177e4 LT |
656 | } |
657 | ||
658 | return XFS_ERROR(error); | |
659 | } | |
660 | ||
f898d6c0 CH |
661 | STATIC int |
662 | xfs_quiesce_fs( | |
663 | xfs_mount_t *mp) | |
664 | { | |
665 | int count = 0, pincount; | |
3758dee9 | 666 | |
f898d6c0 CH |
667 | 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. | |
3758dee9 | 677 | */ |
f898d6c0 | 678 | do { |
516b2e7c | 679 | xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL); |
f898d6c0 CH |
680 | 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 | } | |
1da177e4 | 689 | |
516b2e7c DC |
690 | /* |
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 | */ | |
695 | STATIC void | |
696 | xfs_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 | ||
48c872a9 | 714 | int |
1da177e4 | 715 | xfs_mntupdate( |
48c872a9 | 716 | struct xfs_mount *mp, |
1da177e4 LT |
717 | int *flags, |
718 | struct xfs_mount_args *args) | |
719 | { | |
d08d389d | 720 | if (!(*flags & MS_RDONLY)) { /* rw/ro -> rw */ |
bd186aa9 CH |
721 | if (mp->m_flags & XFS_MOUNT_RDONLY) |
722 | mp->m_flags &= ~XFS_MOUNT_RDONLY; | |
d08d389d NS |
723 | if (args->flags & XFSMNT_BARRIER) { |
724 | mp->m_flags |= XFS_MOUNT_BARRIER; | |
f538d4da | 725 | xfs_mountfs_check_barriers(mp); |
d08d389d NS |
726 | } else { |
727 | mp->m_flags &= ~XFS_MOUNT_BARRIER; | |
728 | } | |
bd186aa9 | 729 | } else if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { /* rw -> ro */ |
2a82b8be | 730 | xfs_filestream_flush(mp); |
745f6919 | 731 | xfs_sync(mp, SYNC_DATA_QUIESCE); |
516b2e7c | 732 | xfs_attr_quiesce(mp); |
bd186aa9 | 733 | mp->m_flags |= XFS_MOUNT_RDONLY; |
1da177e4 | 734 | } |
1da177e4 LT |
735 | 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 | */ | |
743 | int | |
744 | xfs_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; | |
67fcaa73 | 752 | bhv_vnode_t *rvp = XFS_ITOV(rip); |
1da177e4 LT |
753 | int error; |
754 | ||
f7c66ce3 | 755 | xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT); |
1da177e4 LT |
756 | 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 | ||
812 | fscorrupt_out: | |
813 | xfs_ifunlock(rip); | |
814 | ||
815 | fscorrupt_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 | */ | |
48c872a9 | 828 | int |
1da177e4 | 829 | xfs_root( |
48c872a9 | 830 | xfs_mount_t *mp, |
67fcaa73 | 831 | bhv_vnode_t **vpp) |
1da177e4 | 832 | { |
67fcaa73 | 833 | bhv_vnode_t *vp; |
1da177e4 | 834 | |
48c872a9 | 835 | vp = XFS_ITOV(mp->m_rootip); |
1da177e4 LT |
836 | VN_HOLD(vp); |
837 | *vpp = vp; | |
838 | return 0; | |
839 | } | |
840 | ||
841 | /* | |
842 | * xfs_statvfs | |
843 | * | |
844 | * Fill in the statvfs structure for the given file system. We use | |
845 | * the superblock lock in the mount structure to ensure a consistent | |
846 | * snapshot of the counters returned. | |
847 | */ | |
48c872a9 | 848 | int |
1da177e4 | 849 | xfs_statvfs( |
48c872a9 | 850 | xfs_mount_t *mp, |
8285fb58 | 851 | bhv_statvfs_t *statp, |
67fcaa73 | 852 | bhv_vnode_t *vp) |
1da177e4 LT |
853 | { |
854 | __uint64_t fakeinos; | |
855 | xfs_extlen_t lsize; | |
1da177e4 | 856 | xfs_sb_t *sbp; |
1da177e4 | 857 | |
1da177e4 LT |
858 | sbp = &(mp->m_sb); |
859 | ||
860 | statp->f_type = XFS_SB_MAGIC; | |
861 | ||
dbcabad1 | 862 | xfs_icsb_sync_counters_flags(mp, XFS_ICSB_LAZY_COUNT); |
3685c2a1 | 863 | spin_lock(&mp->m_sb_lock); |
1da177e4 LT |
864 | statp->f_bsize = sbp->sb_blocksize; |
865 | lsize = sbp->sb_logstart ? sbp->sb_logblocks : 0; | |
866 | statp->f_blocks = sbp->sb_dblocks - lsize; | |
4be536de DC |
867 | statp->f_bfree = statp->f_bavail = |
868 | sbp->sb_fdblocks - XFS_ALLOC_SET_ASIDE(mp); | |
1da177e4 LT |
869 | fakeinos = statp->f_bfree << sbp->sb_inopblog; |
870 | #if XFS_BIG_INUMS | |
871 | fakeinos += mp->m_inoadd; | |
872 | #endif | |
873 | statp->f_files = | |
874 | MIN(sbp->sb_icount + fakeinos, (__uint64_t)XFS_MAXINUMBER); | |
875 | if (mp->m_maxicount) | |
876 | #if XFS_BIG_INUMS | |
877 | if (!mp->m_inoadd) | |
878 | #endif | |
879 | statp->f_files = min_t(typeof(statp->f_files), | |
880 | statp->f_files, | |
881 | mp->m_maxicount); | |
882 | statp->f_ffree = statp->f_files - (sbp->sb_icount - sbp->sb_ifree); | |
3685c2a1 | 883 | spin_unlock(&mp->m_sb_lock); |
1da177e4 | 884 | |
cde410a9 | 885 | xfs_statvfs_fsid(statp, mp); |
1da177e4 LT |
886 | statp->f_namelen = MAXNAMELEN - 1; |
887 | ||
b09cc771 CH |
888 | if (vp) |
889 | XFS_QM_DQSTATVFS(xfs_vtoi(vp), statp); | |
1da177e4 LT |
890 | return 0; |
891 | } | |
892 | ||
893 | ||
894 | /* | |
895 | * xfs_sync flushes any pending I/O to file system vfsp. | |
896 | * | |
897 | * This routine is called by vfs_sync() to make sure that things make it | |
898 | * out to disk eventually, on sync() system calls to flush out everything, | |
899 | * and when the file system is unmounted. For the vfs_sync() case, all | |
900 | * we really need to do is sync out the log to make all of our meta-data | |
901 | * updates permanent (except for timestamps). For calls from pflushd(), | |
902 | * dirty pages are kept moving by calling pdflush() on the inodes | |
903 | * containing them. We also flush the inodes that we can lock without | |
904 | * sleeping and the superblock if we can lock it without sleeping from | |
905 | * vfs_sync() so that items at the tail of the log are always moving out. | |
906 | * | |
907 | * Flags: | |
908 | * SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want | |
909 | * to sleep if we can help it. All we really need | |
910 | * to do is ensure that the log is synced at least | |
911 | * periodically. We also push the inodes and | |
912 | * superblock if we can lock them without sleeping | |
913 | * and they are not pinned. | |
914 | * SYNC_ATTR - We need to flush the inodes. If SYNC_BDFLUSH is not | |
915 | * set, then we really want to lock each inode and flush | |
916 | * it. | |
917 | * SYNC_WAIT - All the flushes that take place in this call should | |
918 | * be synchronous. | |
919 | * SYNC_DELWRI - This tells us to push dirty pages associated with | |
920 | * inodes. SYNC_WAIT and SYNC_BDFLUSH are used to | |
921 | * determine if they should be flushed sync, async, or | |
922 | * delwri. | |
923 | * SYNC_CLOSE - This flag is passed when the system is being | |
c41564b5 | 924 | * unmounted. We should sync and invalidate everything. |
1da177e4 LT |
925 | * SYNC_FSDATA - This indicates that the caller would like to make |
926 | * sure the superblock is safe on disk. We can ensure | |
c41564b5 | 927 | * this by simply making sure the log gets flushed |
1da177e4 LT |
928 | * if SYNC_BDFLUSH is set, and by actually writing it |
929 | * out otherwise. | |
3c0dc77b DC |
930 | * SYNC_IOWAIT - The caller wants us to wait for all data I/O to complete |
931 | * before we return (including direct I/O). Forms the drain | |
932 | * side of the write barrier needed to safely quiesce the | |
933 | * filesystem. | |
1da177e4 LT |
934 | * |
935 | */ | |
48c872a9 | 936 | int |
1da177e4 | 937 | xfs_sync( |
48c872a9 CH |
938 | xfs_mount_t *mp, |
939 | int flags) | |
1da177e4 | 940 | { |
b09cc771 CH |
941 | int error; |
942 | ||
943 | /* | |
944 | * Get the Quota Manager to flush the dquots. | |
945 | * | |
946 | * If XFS quota support is not enabled or this filesystem | |
947 | * instance does not use quotas XFS_QM_DQSYNC will always | |
948 | * return zero. | |
949 | */ | |
950 | error = XFS_QM_DQSYNC(mp, flags); | |
951 | if (error) { | |
952 | /* | |
953 | * If we got an IO error, we will be shutting down. | |
954 | * So, there's nothing more for us to do here. | |
955 | */ | |
956 | ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp)); | |
957 | if (XFS_FORCED_SHUTDOWN(mp)) | |
958 | return XFS_ERROR(error); | |
959 | } | |
1da177e4 | 960 | |
2a82b8be DC |
961 | if (flags & SYNC_IOWAIT) |
962 | xfs_filestream_flush(mp); | |
963 | ||
2823945f | 964 | return xfs_syncsub(mp, flags, NULL); |
1da177e4 LT |
965 | } |
966 | ||
967 | /* | |
968 | * xfs sync routine for internal use | |
969 | * | |
b83bd138 | 970 | * This routine supports all of the flags defined for the generic vfs_sync |
1f9b3b64 | 971 | * interface as explained above under xfs_sync. |
1da177e4 LT |
972 | * |
973 | */ | |
ee34807a | 974 | int |
1da177e4 LT |
975 | xfs_sync_inodes( |
976 | xfs_mount_t *mp, | |
977 | int flags, | |
1da177e4 LT |
978 | int *bypassed) |
979 | { | |
980 | xfs_inode_t *ip = NULL; | |
67fcaa73 | 981 | bhv_vnode_t *vp = NULL; |
1da177e4 LT |
982 | int error; |
983 | int last_error; | |
984 | uint64_t fflag; | |
985 | uint lock_flags; | |
986 | uint base_lock_flags; | |
987 | boolean_t mount_locked; | |
988 | boolean_t vnode_refed; | |
989 | int preempt; | |
1da177e4 LT |
990 | xfs_iptr_t *ipointer; |
991 | #ifdef DEBUG | |
992 | boolean_t ipointer_in = B_FALSE; | |
993 | ||
994 | #define IPOINTER_SET ipointer_in = B_TRUE | |
995 | #define IPOINTER_CLR ipointer_in = B_FALSE | |
996 | #else | |
997 | #define IPOINTER_SET | |
998 | #define IPOINTER_CLR | |
999 | #endif | |
1000 | ||
1001 | ||
1002 | /* Insert a marker record into the inode list after inode ip. The list | |
1003 | * must be locked when this is called. After the call the list will no | |
1004 | * longer be locked. | |
1005 | */ | |
1006 | #define IPOINTER_INSERT(ip, mp) { \ | |
1007 | ASSERT(ipointer_in == B_FALSE); \ | |
1008 | ipointer->ip_mnext = ip->i_mnext; \ | |
1009 | ipointer->ip_mprev = ip; \ | |
1010 | ip->i_mnext = (xfs_inode_t *)ipointer; \ | |
1011 | ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \ | |
1012 | preempt = 0; \ | |
1013 | XFS_MOUNT_IUNLOCK(mp); \ | |
1014 | mount_locked = B_FALSE; \ | |
1015 | IPOINTER_SET; \ | |
1016 | } | |
1017 | ||
1018 | /* Remove the marker from the inode list. If the marker was the only item | |
1019 | * in the list then there are no remaining inodes and we should zero out | |
1020 | * the whole list. If we are the current head of the list then move the head | |
1021 | * past us. | |
1022 | */ | |
1023 | #define IPOINTER_REMOVE(ip, mp) { \ | |
1024 | ASSERT(ipointer_in == B_TRUE); \ | |
1025 | if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \ | |
1026 | ip = ipointer->ip_mnext; \ | |
1027 | ip->i_mprev = ipointer->ip_mprev; \ | |
1028 | ipointer->ip_mprev->i_mnext = ip; \ | |
1029 | if (mp->m_inodes == (xfs_inode_t *)ipointer) { \ | |
1030 | mp->m_inodes = ip; \ | |
1031 | } \ | |
1032 | } else { \ | |
1033 | ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \ | |
1034 | mp->m_inodes = NULL; \ | |
1035 | ip = NULL; \ | |
1036 | } \ | |
1037 | IPOINTER_CLR; \ | |
1038 | } | |
1039 | ||
1040 | #define XFS_PREEMPT_MASK 0x7f | |
1041 | ||
44866d39 LM |
1042 | ASSERT(!(flags & SYNC_BDFLUSH)); |
1043 | ||
1da177e4 LT |
1044 | if (bypassed) |
1045 | *bypassed = 0; | |
bd186aa9 | 1046 | if (mp->m_flags & XFS_MOUNT_RDONLY) |
1da177e4 LT |
1047 | return 0; |
1048 | error = 0; | |
1049 | last_error = 0; | |
1050 | preempt = 0; | |
1051 | ||
1052 | /* Allocate a reference marker */ | |
1053 | ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP); | |
1054 | ||
1055 | fflag = XFS_B_ASYNC; /* default is don't wait */ | |
44866d39 | 1056 | if (flags & SYNC_DELWRI) |
1da177e4 LT |
1057 | fflag = XFS_B_DELWRI; |
1058 | if (flags & SYNC_WAIT) | |
1059 | fflag = 0; /* synchronous overrides all */ | |
1060 | ||
1061 | base_lock_flags = XFS_ILOCK_SHARED; | |
1062 | if (flags & (SYNC_DELWRI | SYNC_CLOSE)) { | |
1063 | /* | |
1064 | * We need the I/O lock if we're going to call any of | |
1065 | * the flush/inval routines. | |
1066 | */ | |
1067 | base_lock_flags |= XFS_IOLOCK_SHARED; | |
1068 | } | |
1069 | ||
1070 | XFS_MOUNT_ILOCK(mp); | |
1071 | ||
1072 | ip = mp->m_inodes; | |
1073 | ||
1074 | mount_locked = B_TRUE; | |
1075 | vnode_refed = B_FALSE; | |
1076 | ||
1077 | IPOINTER_CLR; | |
1078 | ||
1079 | do { | |
1080 | ASSERT(ipointer_in == B_FALSE); | |
1081 | ASSERT(vnode_refed == B_FALSE); | |
1082 | ||
1083 | lock_flags = base_lock_flags; | |
1084 | ||
1085 | /* | |
1086 | * There were no inodes in the list, just break out | |
1087 | * of the loop. | |
1088 | */ | |
1089 | if (ip == NULL) { | |
1090 | break; | |
1091 | } | |
1092 | ||
1093 | /* | |
1094 | * We found another sync thread marker - skip it | |
1095 | */ | |
1096 | if (ip->i_mount == NULL) { | |
1097 | ip = ip->i_mnext; | |
1098 | continue; | |
1099 | } | |
1100 | ||
1101 | vp = XFS_ITOV_NULL(ip); | |
1102 | ||
1103 | /* | |
1104 | * If the vnode is gone then this is being torn down, | |
1105 | * call reclaim if it is flushed, else let regular flush | |
1106 | * code deal with it later in the loop. | |
1107 | */ | |
1108 | ||
1109 | if (vp == NULL) { | |
1110 | /* Skip ones already in reclaim */ | |
1111 | if (ip->i_flags & XFS_IRECLAIM) { | |
1112 | ip = ip->i_mnext; | |
1113 | continue; | |
1114 | } | |
1115 | if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) { | |
1116 | ip = ip->i_mnext; | |
1117 | } else if ((xfs_ipincount(ip) == 0) && | |
1118 | xfs_iflock_nowait(ip)) { | |
1119 | IPOINTER_INSERT(ip, mp); | |
1120 | ||
1121 | xfs_finish_reclaim(ip, 1, | |
1122 | XFS_IFLUSH_DELWRI_ELSE_ASYNC); | |
1123 | ||
1124 | XFS_MOUNT_ILOCK(mp); | |
1125 | mount_locked = B_TRUE; | |
1126 | IPOINTER_REMOVE(ip, mp); | |
1127 | } else { | |
1128 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | |
1129 | ip = ip->i_mnext; | |
1130 | } | |
1131 | continue; | |
1132 | } | |
1133 | ||
1134 | if (VN_BAD(vp)) { | |
1135 | ip = ip->i_mnext; | |
1136 | continue; | |
1137 | } | |
1138 | ||
1139 | if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) { | |
1140 | XFS_MOUNT_IUNLOCK(mp); | |
1141 | kmem_free(ipointer, sizeof(xfs_iptr_t)); | |
1142 | return 0; | |
1143 | } | |
1144 | ||
1da177e4 LT |
1145 | /* |
1146 | * Try to lock without sleeping. We're out of order with | |
1147 | * the inode list lock here, so if we fail we need to drop | |
1148 | * the mount lock and try again. If we're called from | |
1149 | * bdflush() here, then don't bother. | |
1150 | * | |
1151 | * The inode lock here actually coordinates with the | |
1152 | * almost spurious inode lock in xfs_ireclaim() to prevent | |
1153 | * the vnode we handle here without a reference from | |
1154 | * being freed while we reference it. If we lock the inode | |
1155 | * while it's on the mount list here, then the spurious inode | |
1156 | * lock in xfs_ireclaim() after the inode is pulled from | |
1157 | * the mount list will sleep until we release it here. | |
1158 | * This keeps the vnode from being freed while we reference | |
cdb62687 | 1159 | * it. |
1da177e4 LT |
1160 | */ |
1161 | if (xfs_ilock_nowait(ip, lock_flags) == 0) { | |
44866d39 | 1162 | if (vp == NULL) { |
1da177e4 LT |
1163 | ip = ip->i_mnext; |
1164 | continue; | |
1165 | } | |
1166 | ||
cdb62687 | 1167 | vp = vn_grab(vp); |
1da177e4 | 1168 | if (vp == NULL) { |
cdb62687 | 1169 | ip = ip->i_mnext; |
1da177e4 LT |
1170 | continue; |
1171 | } | |
1172 | ||
cdb62687 | 1173 | IPOINTER_INSERT(ip, mp); |
1da177e4 LT |
1174 | xfs_ilock(ip, lock_flags); |
1175 | ||
1176 | ASSERT(vp == XFS_ITOV(ip)); | |
1177 | ASSERT(ip->i_mount == mp); | |
1178 | ||
1179 | vnode_refed = B_TRUE; | |
1180 | } | |
1181 | ||
1182 | /* From here on in the loop we may have a marker record | |
1183 | * in the inode list. | |
1184 | */ | |
1185 | ||
40095b64 DC |
1186 | /* |
1187 | * If we have to flush data or wait for I/O completion | |
1188 | * we need to drop the ilock that we currently hold. | |
1189 | * If we need to drop the lock, insert a marker if we | |
1190 | * have not already done so. | |
1191 | */ | |
1192 | if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) || | |
1193 | ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) { | |
1194 | if (mount_locked) { | |
1195 | IPOINTER_INSERT(ip, mp); | |
1da177e4 | 1196 | } |
40095b64 | 1197 | xfs_iunlock(ip, XFS_ILOCK_SHARED); |
1da177e4 | 1198 | |
40095b64 DC |
1199 | if (flags & SYNC_CLOSE) { |
1200 | /* Shutdown case. Flush and invalidate. */ | |
1201 | if (XFS_FORCED_SHUTDOWN(mp)) | |
739bfb2a CH |
1202 | xfs_tosspages(ip, 0, -1, |
1203 | FI_REMAPF); | |
40095b64 | 1204 | else |
739bfb2a CH |
1205 | error = xfs_flushinval_pages(ip, |
1206 | 0, -1, FI_REMAPF); | |
40095b64 | 1207 | } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) { |
739bfb2a | 1208 | error = xfs_flush_pages(ip, 0, |
67fcaa73 | 1209 | -1, fflag, FI_NONE); |
1da177e4 LT |
1210 | } |
1211 | ||
40095b64 DC |
1212 | /* |
1213 | * When freezing, we need to wait ensure all I/O (including direct | |
1214 | * I/O) is complete to ensure no further data modification can take | |
1215 | * place after this point | |
1216 | */ | |
1217 | if (flags & SYNC_IOWAIT) | |
b677c210 | 1218 | vn_iowait(ip); |
40095b64 DC |
1219 | |
1220 | xfs_ilock(ip, XFS_ILOCK_SHARED); | |
1da177e4 LT |
1221 | } |
1222 | ||
44866d39 LM |
1223 | if ((flags & SYNC_ATTR) && |
1224 | (ip->i_update_core || | |
1225 | (ip->i_itemp && ip->i_itemp->ili_format.ilf_fields))) { | |
1226 | if (mount_locked) | |
1227 | IPOINTER_INSERT(ip, mp); | |
1da177e4 | 1228 | |
44866d39 LM |
1229 | if (flags & SYNC_WAIT) { |
1230 | xfs_iflock(ip); | |
1231 | error = xfs_iflush(ip, XFS_IFLUSH_SYNC); | |
1da177e4 | 1232 | |
44866d39 LM |
1233 | /* |
1234 | * If we can't acquire the flush lock, then the inode | |
1235 | * is already being flushed so don't bother waiting. | |
1236 | * | |
1237 | * If we can lock it then do a delwri flush so we can | |
1238 | * combine multiple inode flushes in each disk write. | |
1239 | */ | |
1240 | } else if (xfs_iflock_nowait(ip)) { | |
1241 | error = xfs_iflush(ip, XFS_IFLUSH_DELWRI); | |
1242 | } else if (bypassed) { | |
1243 | (*bypassed)++; | |
1da177e4 LT |
1244 | } |
1245 | } | |
1246 | ||
1247 | if (lock_flags != 0) { | |
1248 | xfs_iunlock(ip, lock_flags); | |
1249 | } | |
1250 | ||
1251 | if (vnode_refed) { | |
1252 | /* | |
1253 | * If we had to take a reference on the vnode | |
1254 | * above, then wait until after we've unlocked | |
1255 | * the inode to release the reference. This is | |
1256 | * because we can be already holding the inode | |
1257 | * lock when VN_RELE() calls xfs_inactive(). | |
1258 | * | |
1259 | * Make sure to drop the mount lock before calling | |
1260 | * VN_RELE() so that we don't trip over ourselves if | |
1261 | * we have to go for the mount lock again in the | |
1262 | * inactive code. | |
1263 | */ | |
1264 | if (mount_locked) { | |
1265 | IPOINTER_INSERT(ip, mp); | |
1266 | } | |
1267 | ||
1268 | VN_RELE(vp); | |
1269 | ||
1270 | vnode_refed = B_FALSE; | |
1271 | } | |
1272 | ||
1273 | if (error) { | |
1274 | last_error = error; | |
1275 | } | |
1276 | ||
1277 | /* | |
1278 | * bail out if the filesystem is corrupted. | |
1279 | */ | |
1280 | if (error == EFSCORRUPTED) { | |
1281 | if (!mount_locked) { | |
1282 | XFS_MOUNT_ILOCK(mp); | |
1283 | IPOINTER_REMOVE(ip, mp); | |
1284 | } | |
1285 | XFS_MOUNT_IUNLOCK(mp); | |
1286 | ASSERT(ipointer_in == B_FALSE); | |
1287 | kmem_free(ipointer, sizeof(xfs_iptr_t)); | |
1288 | return XFS_ERROR(error); | |
1289 | } | |
1290 | ||
1291 | /* Let other threads have a chance at the mount lock | |
1292 | * if we have looped many times without dropping the | |
1293 | * lock. | |
1294 | */ | |
1295 | if ((++preempt & XFS_PREEMPT_MASK) == 0) { | |
1296 | if (mount_locked) { | |
1297 | IPOINTER_INSERT(ip, mp); | |
1298 | } | |
1299 | } | |
1300 | ||
1301 | if (mount_locked == B_FALSE) { | |
1302 | XFS_MOUNT_ILOCK(mp); | |
1303 | mount_locked = B_TRUE; | |
1304 | IPOINTER_REMOVE(ip, mp); | |
1305 | continue; | |
1306 | } | |
1307 | ||
1308 | ASSERT(ipointer_in == B_FALSE); | |
1309 | ip = ip->i_mnext; | |
1310 | ||
1311 | } while (ip != mp->m_inodes); | |
1312 | ||
1313 | XFS_MOUNT_IUNLOCK(mp); | |
1314 | ||
1315 | ASSERT(ipointer_in == B_FALSE); | |
1316 | ||
1317 | kmem_free(ipointer, sizeof(xfs_iptr_t)); | |
1318 | return XFS_ERROR(last_error); | |
1319 | } | |
1320 | ||
1321 | /* | |
1322 | * xfs sync routine for internal use | |
1323 | * | |
b83bd138 | 1324 | * This routine supports all of the flags defined for the generic vfs_sync |
1f9b3b64 | 1325 | * interface as explained above under xfs_sync. |
1da177e4 LT |
1326 | * |
1327 | */ | |
1328 | int | |
1329 | xfs_syncsub( | |
1330 | xfs_mount_t *mp, | |
1331 | int flags, | |
1da177e4 LT |
1332 | int *bypassed) |
1333 | { | |
1334 | int error = 0; | |
1335 | int last_error = 0; | |
1336 | uint log_flags = XFS_LOG_FORCE; | |
1337 | xfs_buf_t *bp; | |
1338 | xfs_buf_log_item_t *bip; | |
1339 | ||
1340 | /* | |
1341 | * Sync out the log. This ensures that the log is periodically | |
1342 | * flushed even if there is not enough activity to fill it up. | |
1343 | */ | |
1344 | if (flags & SYNC_WAIT) | |
1345 | log_flags |= XFS_LOG_SYNC; | |
1346 | ||
1347 | xfs_log_force(mp, (xfs_lsn_t)0, log_flags); | |
1348 | ||
1349 | if (flags & (SYNC_ATTR|SYNC_DELWRI)) { | |
1350 | if (flags & SYNC_BDFLUSH) | |
1351 | xfs_finish_reclaim_all(mp, 1); | |
1352 | else | |
1f9b3b64 | 1353 | error = xfs_sync_inodes(mp, flags, bypassed); |
1da177e4 LT |
1354 | } |
1355 | ||
1356 | /* | |
1357 | * Flushing out dirty data above probably generated more | |
1358 | * log activity, so if this isn't vfs_sync() then flush | |
1359 | * the log again. | |
1360 | */ | |
1361 | if (flags & SYNC_DELWRI) { | |
1362 | xfs_log_force(mp, (xfs_lsn_t)0, log_flags); | |
1363 | } | |
1364 | ||
1365 | if (flags & SYNC_FSDATA) { | |
1366 | /* | |
1367 | * If this is vfs_sync() then only sync the superblock | |
1368 | * if we can lock it without sleeping and it is not pinned. | |
1369 | */ | |
1370 | if (flags & SYNC_BDFLUSH) { | |
1371 | bp = xfs_getsb(mp, XFS_BUF_TRYLOCK); | |
1372 | if (bp != NULL) { | |
1373 | bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*); | |
1374 | if ((bip != NULL) && | |
1375 | xfs_buf_item_dirty(bip)) { | |
1376 | if (!(XFS_BUF_ISPINNED(bp))) { | |
1377 | XFS_BUF_ASYNC(bp); | |
1378 | error = xfs_bwrite(mp, bp); | |
1379 | } else { | |
1380 | xfs_buf_relse(bp); | |
1381 | } | |
1382 | } else { | |
1383 | xfs_buf_relse(bp); | |
1384 | } | |
1385 | } | |
1386 | } else { | |
1387 | bp = xfs_getsb(mp, 0); | |
1388 | /* | |
1389 | * If the buffer is pinned then push on the log so | |
1390 | * we won't get stuck waiting in the write for | |
1391 | * someone, maybe ourselves, to flush the log. | |
1392 | * Even though we just pushed the log above, we | |
1393 | * did not have the superblock buffer locked at | |
1394 | * that point so it can become pinned in between | |
1395 | * there and here. | |
1396 | */ | |
1397 | if (XFS_BUF_ISPINNED(bp)) | |
1398 | xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE); | |
1399 | if (flags & SYNC_WAIT) | |
1400 | XFS_BUF_UNASYNC(bp); | |
1401 | else | |
1402 | XFS_BUF_ASYNC(bp); | |
1403 | error = xfs_bwrite(mp, bp); | |
1404 | } | |
1405 | if (error) { | |
1406 | last_error = error; | |
1407 | } | |
1408 | } | |
1409 | ||
1410 | /* | |
1411 | * If this is the periodic sync, then kick some entries out of | |
1412 | * the reference cache. This ensures that idle entries are | |
1413 | * eventually kicked out of the cache. | |
1414 | */ | |
1415 | if (flags & SYNC_REFCACHE) { | |
cde410a9 NS |
1416 | if (flags & SYNC_WAIT) |
1417 | xfs_refcache_purge_mp(mp); | |
1418 | else | |
1419 | xfs_refcache_purge_some(mp); | |
1da177e4 LT |
1420 | } |
1421 | ||
92821e2b DC |
1422 | /* |
1423 | * If asked, update the disk superblock with incore counter values if we | |
1424 | * are using non-persistent counters so that they don't get too far out | |
1425 | * of sync if we crash or get a forced shutdown. We don't want to force | |
1426 | * this to disk, just get a transaction into the iclogs.... | |
1427 | */ | |
1428 | if (flags & SYNC_SUPER) | |
1429 | xfs_log_sbcount(mp, 0); | |
1430 | ||
1da177e4 LT |
1431 | /* |
1432 | * Now check to see if the log needs a "dummy" transaction. | |
1433 | */ | |
1434 | ||
1435 | if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) { | |
1436 | xfs_trans_t *tp; | |
1437 | xfs_inode_t *ip; | |
1438 | ||
1439 | /* | |
1440 | * Put a dummy transaction in the log to tell | |
1441 | * recovery that all others are OK. | |
1442 | */ | |
1443 | tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1); | |
1444 | if ((error = xfs_trans_reserve(tp, 0, | |
1445 | XFS_ICHANGE_LOG_RES(mp), | |
1446 | 0, 0, 0))) { | |
1447 | xfs_trans_cancel(tp, 0); | |
1448 | return error; | |
1449 | } | |
1450 | ||
1451 | ip = mp->m_rootip; | |
1452 | xfs_ilock(ip, XFS_ILOCK_EXCL); | |
1453 | ||
1454 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); | |
1455 | xfs_trans_ihold(tp, ip); | |
1456 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); | |
1c72bf90 | 1457 | error = xfs_trans_commit(tp, 0); |
1da177e4 LT |
1458 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
1459 | xfs_log_force(mp, (xfs_lsn_t)0, log_flags); | |
1460 | } | |
1461 | ||
1462 | /* | |
1463 | * When shutting down, we need to insure that the AIL is pushed | |
1464 | * to disk or the filesystem can appear corrupt from the PROM. | |
1465 | */ | |
1466 | if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) { | |
1467 | XFS_bflush(mp->m_ddev_targp); | |
1468 | if (mp->m_rtdev_targp) { | |
1469 | XFS_bflush(mp->m_rtdev_targp); | |
1470 | } | |
1471 | } | |
1472 | ||
1473 | return XFS_ERROR(last_error); | |
1474 | } | |
1475 | ||
1476 | /* | |
1477 | * xfs_vget - called by DMAPI and NFSD to get vnode from file handle | |
1478 | */ | |
48c872a9 | 1479 | int |
1da177e4 | 1480 | xfs_vget( |
48c872a9 | 1481 | xfs_mount_t *mp, |
67fcaa73 | 1482 | bhv_vnode_t **vpp, |
c6143911 | 1483 | xfs_fid_t *xfid) |
1da177e4 | 1484 | { |
1da177e4 LT |
1485 | xfs_inode_t *ip; |
1486 | int error; | |
1487 | xfs_ino_t ino; | |
1488 | unsigned int igen; | |
1489 | ||
1490 | /* | |
1491 | * Invalid. Since handles can be created in user space and passed in | |
1492 | * via gethandle(), this is not cause for a panic. | |
1493 | */ | |
c6143911 | 1494 | if (xfid->fid_len != sizeof(*xfid) - sizeof(xfid->fid_len)) |
1da177e4 LT |
1495 | return XFS_ERROR(EINVAL); |
1496 | ||
c6143911 CH |
1497 | ino = xfid->fid_ino; |
1498 | igen = xfid->fid_gen; | |
1da177e4 LT |
1499 | |
1500 | /* | |
1501 | * NFS can sometimes send requests for ino 0. Fail them gracefully. | |
1502 | */ | |
1503 | if (ino == 0) | |
1504 | return XFS_ERROR(ESTALE); | |
1505 | ||
1506 | error = xfs_iget(mp, NULL, ino, 0, XFS_ILOCK_SHARED, &ip, 0); | |
1507 | if (error) { | |
1508 | *vpp = NULL; | |
1509 | return error; | |
1510 | } | |
1511 | ||
1512 | if (ip == NULL) { | |
1513 | *vpp = NULL; | |
1514 | return XFS_ERROR(EIO); | |
1515 | } | |
1516 | ||
1517 | if (ip->i_d.di_mode == 0 || ip->i_d.di_gen != igen) { | |
1518 | xfs_iput_new(ip, XFS_ILOCK_SHARED); | |
1519 | *vpp = NULL; | |
1520 | return XFS_ERROR(ENOENT); | |
1521 | } | |
1522 | ||
1523 | *vpp = XFS_ITOV(ip); | |
1524 | xfs_iunlock(ip, XFS_ILOCK_SHARED); | |
1525 | return 0; | |
1526 | } | |
1527 | ||
1528 | ||
1529 | #define MNTOPT_LOGBUFS "logbufs" /* number of XFS log buffers */ | |
1530 | #define MNTOPT_LOGBSIZE "logbsize" /* size of XFS log buffers */ | |
1531 | #define MNTOPT_LOGDEV "logdev" /* log device */ | |
1532 | #define MNTOPT_RTDEV "rtdev" /* realtime I/O device */ | |
1533 | #define MNTOPT_BIOSIZE "biosize" /* log2 of preferred buffered io size */ | |
1534 | #define MNTOPT_WSYNC "wsync" /* safe-mode nfs compatible mount */ | |
1535 | #define MNTOPT_INO64 "ino64" /* force inodes into 64-bit range */ | |
1536 | #define MNTOPT_NOALIGN "noalign" /* turn off stripe alignment */ | |
1537 | #define MNTOPT_SWALLOC "swalloc" /* turn on stripe width allocation */ | |
1538 | #define MNTOPT_SUNIT "sunit" /* data volume stripe unit */ | |
1539 | #define MNTOPT_SWIDTH "swidth" /* data volume stripe width */ | |
1540 | #define MNTOPT_NOUUID "nouuid" /* ignore filesystem UUID */ | |
1541 | #define MNTOPT_MTPT "mtpt" /* filesystem mount point */ | |
e69a333b NS |
1542 | #define MNTOPT_GRPID "grpid" /* group-ID from parent directory */ |
1543 | #define MNTOPT_NOGRPID "nogrpid" /* group-ID from current process */ | |
1544 | #define MNTOPT_BSDGROUPS "bsdgroups" /* group-ID from parent directory */ | |
1545 | #define MNTOPT_SYSVGROUPS "sysvgroups" /* group-ID from current process */ | |
1f443ad7 | 1546 | #define MNTOPT_ALLOCSIZE "allocsize" /* preferred allocation size */ |
1da177e4 | 1547 | #define MNTOPT_NORECOVERY "norecovery" /* don't run XFS recovery */ |
f538d4da | 1548 | #define MNTOPT_BARRIER "barrier" /* use writer barriers for log write and |
d8cc890d | 1549 | * unwritten extent conversion */ |
4ef19ddd | 1550 | #define MNTOPT_NOBARRIER "nobarrier" /* .. disable */ |
1da177e4 LT |
1551 | #define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */ |
1552 | #define MNTOPT_64BITINODE "inode64" /* inodes can be allocated anywhere */ | |
1553 | #define MNTOPT_IKEEP "ikeep" /* do not free empty inode clusters */ | |
1554 | #define MNTOPT_NOIKEEP "noikeep" /* free empty inode clusters */ | |
e8c8b3a7 DC |
1555 | #define MNTOPT_LARGEIO "largeio" /* report large I/O sizes in stat() */ |
1556 | #define MNTOPT_NOLARGEIO "nolargeio" /* do not report large I/O sizes | |
1557 | * in stat(). */ | |
d8cc890d NS |
1558 | #define MNTOPT_ATTR2 "attr2" /* do use attr2 attribute format */ |
1559 | #define MNTOPT_NOATTR2 "noattr2" /* do not use attr2 attribute format */ | |
2a82b8be | 1560 | #define MNTOPT_FILESTREAM "filestreams" /* use filestreams allocator */ |
b09cc771 CH |
1561 | #define MNTOPT_QUOTA "quota" /* disk quotas (user) */ |
1562 | #define MNTOPT_NOQUOTA "noquota" /* no quotas */ | |
1563 | #define MNTOPT_USRQUOTA "usrquota" /* user quota enabled */ | |
1564 | #define MNTOPT_GRPQUOTA "grpquota" /* group quota enabled */ | |
1565 | #define MNTOPT_PRJQUOTA "prjquota" /* project quota enabled */ | |
1566 | #define MNTOPT_UQUOTA "uquota" /* user quota (IRIX variant) */ | |
1567 | #define MNTOPT_GQUOTA "gquota" /* group quota (IRIX variant) */ | |
1568 | #define MNTOPT_PQUOTA "pquota" /* project quota (IRIX variant) */ | |
1569 | #define MNTOPT_UQUOTANOENF "uqnoenforce"/* user quota limit enforcement */ | |
1570 | #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */ | |
1571 | #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */ | |
1572 | #define MNTOPT_QUOTANOENF "qnoenforce" /* same as uqnoenforce */ | |
293688ec CH |
1573 | #define MNTOPT_DMAPI "dmapi" /* DMI enabled (DMAPI / XDSM) */ |
1574 | #define MNTOPT_XDSM "xdsm" /* DMI enabled (DMAPI / XDSM) */ | |
1575 | #define MNTOPT_DMI "dmi" /* DMI enabled (DMAPI / XDSM) */ | |
1da177e4 | 1576 | |
1f443ad7 | 1577 | STATIC unsigned long |
b190f113 | 1578 | suffix_strtoul(char *s, char **endp, unsigned int base) |
1f443ad7 NS |
1579 | { |
1580 | int last, shift_left_factor = 0; | |
b190f113 | 1581 | char *value = s; |
1f443ad7 NS |
1582 | |
1583 | last = strlen(value) - 1; | |
1584 | if (value[last] == 'K' || value[last] == 'k') { | |
1585 | shift_left_factor = 10; | |
1586 | value[last] = '\0'; | |
1587 | } | |
1588 | if (value[last] == 'M' || value[last] == 'm') { | |
1589 | shift_left_factor = 20; | |
1590 | value[last] = '\0'; | |
1591 | } | |
1592 | if (value[last] == 'G' || value[last] == 'g') { | |
1593 | shift_left_factor = 30; | |
1594 | value[last] = '\0'; | |
1595 | } | |
1596 | ||
b190f113 | 1597 | return simple_strtoul((const char *)s, endp, base) << shift_left_factor; |
1f443ad7 | 1598 | } |
1da177e4 | 1599 | |
48c872a9 | 1600 | int |
1da177e4 | 1601 | xfs_parseargs( |
48c872a9 | 1602 | struct xfs_mount *mp, |
1da177e4 LT |
1603 | char *options, |
1604 | struct xfs_mount_args *args, | |
1605 | int update) | |
1606 | { | |
1da177e4 LT |
1607 | char *this_char, *value, *eov; |
1608 | int dsunit, dswidth, vol_dsunit, vol_dswidth; | |
1609 | int iosize; | |
574342f4 | 1610 | int ikeep = 0; |
b93bd20c | 1611 | |
3bbcc8e3 NS |
1612 | args->flags |= XFSMNT_BARRIER; |
1613 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; | |
1da177e4 LT |
1614 | |
1615 | if (!options) | |
05db218a | 1616 | goto done; |
1da177e4 LT |
1617 | |
1618 | iosize = dsunit = dswidth = vol_dsunit = vol_dswidth = 0; | |
1619 | ||
1620 | while ((this_char = strsep(&options, ",")) != NULL) { | |
1621 | if (!*this_char) | |
1622 | continue; | |
1623 | if ((value = strchr(this_char, '=')) != NULL) | |
1624 | *value++ = 0; | |
1625 | ||
1626 | if (!strcmp(this_char, MNTOPT_LOGBUFS)) { | |
1627 | if (!value || !*value) { | |
b6574520 NS |
1628 | cmn_err(CE_WARN, |
1629 | "XFS: %s option requires an argument", | |
1f443ad7 | 1630 | this_char); |
1da177e4 LT |
1631 | return EINVAL; |
1632 | } | |
1633 | args->logbufs = simple_strtoul(value, &eov, 10); | |
1634 | } else if (!strcmp(this_char, MNTOPT_LOGBSIZE)) { | |
1da177e4 | 1635 | if (!value || !*value) { |
b6574520 NS |
1636 | cmn_err(CE_WARN, |
1637 | "XFS: %s option requires an argument", | |
1f443ad7 | 1638 | this_char); |
1da177e4 LT |
1639 | return EINVAL; |
1640 | } | |
1f443ad7 | 1641 | args->logbufsize = suffix_strtoul(value, &eov, 10); |
1da177e4 LT |
1642 | } else if (!strcmp(this_char, MNTOPT_LOGDEV)) { |
1643 | if (!value || !*value) { | |
b6574520 NS |
1644 | cmn_err(CE_WARN, |
1645 | "XFS: %s option requires an argument", | |
1f443ad7 | 1646 | this_char); |
1da177e4 LT |
1647 | return EINVAL; |
1648 | } | |
1649 | strncpy(args->logname, value, MAXNAMELEN); | |
1650 | } else if (!strcmp(this_char, MNTOPT_MTPT)) { | |
1651 | if (!value || !*value) { | |
b6574520 NS |
1652 | cmn_err(CE_WARN, |
1653 | "XFS: %s option requires an argument", | |
1f443ad7 | 1654 | this_char); |
1da177e4 LT |
1655 | return EINVAL; |
1656 | } | |
1657 | strncpy(args->mtpt, value, MAXNAMELEN); | |
1658 | } else if (!strcmp(this_char, MNTOPT_RTDEV)) { | |
1659 | if (!value || !*value) { | |
b6574520 NS |
1660 | cmn_err(CE_WARN, |
1661 | "XFS: %s option requires an argument", | |
1f443ad7 | 1662 | this_char); |
1da177e4 LT |
1663 | return EINVAL; |
1664 | } | |
1665 | strncpy(args->rtname, value, MAXNAMELEN); | |
1666 | } else if (!strcmp(this_char, MNTOPT_BIOSIZE)) { | |
1667 | if (!value || !*value) { | |
b6574520 NS |
1668 | cmn_err(CE_WARN, |
1669 | "XFS: %s option requires an argument", | |
1f443ad7 | 1670 | this_char); |
1da177e4 LT |
1671 | return EINVAL; |
1672 | } | |
1673 | iosize = simple_strtoul(value, &eov, 10); | |
1674 | args->flags |= XFSMNT_IOSIZE; | |
1675 | args->iosizelog = (uint8_t) iosize; | |
1f443ad7 NS |
1676 | } else if (!strcmp(this_char, MNTOPT_ALLOCSIZE)) { |
1677 | if (!value || !*value) { | |
b6574520 NS |
1678 | cmn_err(CE_WARN, |
1679 | "XFS: %s option requires an argument", | |
1f443ad7 NS |
1680 | this_char); |
1681 | return EINVAL; | |
1682 | } | |
1683 | iosize = suffix_strtoul(value, &eov, 10); | |
1684 | args->flags |= XFSMNT_IOSIZE; | |
1685 | args->iosizelog = ffs(iosize) - 1; | |
e69a333b NS |
1686 | } else if (!strcmp(this_char, MNTOPT_GRPID) || |
1687 | !strcmp(this_char, MNTOPT_BSDGROUPS)) { | |
bd186aa9 | 1688 | mp->m_flags |= XFS_MOUNT_GRPID; |
e69a333b NS |
1689 | } else if (!strcmp(this_char, MNTOPT_NOGRPID) || |
1690 | !strcmp(this_char, MNTOPT_SYSVGROUPS)) { | |
bd186aa9 | 1691 | mp->m_flags &= ~XFS_MOUNT_GRPID; |
1da177e4 LT |
1692 | } else if (!strcmp(this_char, MNTOPT_WSYNC)) { |
1693 | args->flags |= XFSMNT_WSYNC; | |
1694 | } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) { | |
1695 | args->flags |= XFSMNT_OSYNCISOSYNC; | |
1696 | } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) { | |
1697 | args->flags |= XFSMNT_NORECOVERY; | |
1698 | } else if (!strcmp(this_char, MNTOPT_INO64)) { | |
1699 | args->flags |= XFSMNT_INO64; | |
1700 | #if !XFS_BIG_INUMS | |
b6574520 NS |
1701 | cmn_err(CE_WARN, |
1702 | "XFS: %s option not allowed on this system", | |
1f443ad7 | 1703 | this_char); |
1da177e4 LT |
1704 | return EINVAL; |
1705 | #endif | |
1706 | } else if (!strcmp(this_char, MNTOPT_NOALIGN)) { | |
1707 | args->flags |= XFSMNT_NOALIGN; | |
1708 | } else if (!strcmp(this_char, MNTOPT_SWALLOC)) { | |
1709 | args->flags |= XFSMNT_SWALLOC; | |
1710 | } else if (!strcmp(this_char, MNTOPT_SUNIT)) { | |
1711 | if (!value || !*value) { | |
b6574520 NS |
1712 | cmn_err(CE_WARN, |
1713 | "XFS: %s option requires an argument", | |
1f443ad7 | 1714 | this_char); |
1da177e4 LT |
1715 | return EINVAL; |
1716 | } | |
1717 | dsunit = simple_strtoul(value, &eov, 10); | |
1718 | } else if (!strcmp(this_char, MNTOPT_SWIDTH)) { | |
1719 | if (!value || !*value) { | |
b6574520 NS |
1720 | cmn_err(CE_WARN, |
1721 | "XFS: %s option requires an argument", | |
1f443ad7 | 1722 | this_char); |
1da177e4 LT |
1723 | return EINVAL; |
1724 | } | |
1725 | dswidth = simple_strtoul(value, &eov, 10); | |
1726 | } else if (!strcmp(this_char, MNTOPT_64BITINODE)) { | |
1727 | args->flags &= ~XFSMNT_32BITINODES; | |
1728 | #if !XFS_BIG_INUMS | |
b6574520 NS |
1729 | cmn_err(CE_WARN, |
1730 | "XFS: %s option not allowed on this system", | |
1f443ad7 | 1731 | this_char); |
1da177e4 LT |
1732 | return EINVAL; |
1733 | #endif | |
1734 | } else if (!strcmp(this_char, MNTOPT_NOUUID)) { | |
1735 | args->flags |= XFSMNT_NOUUID; | |
f538d4da CH |
1736 | } else if (!strcmp(this_char, MNTOPT_BARRIER)) { |
1737 | args->flags |= XFSMNT_BARRIER; | |
4ef19ddd CH |
1738 | } else if (!strcmp(this_char, MNTOPT_NOBARRIER)) { |
1739 | args->flags &= ~XFSMNT_BARRIER; | |
1da177e4 | 1740 | } else if (!strcmp(this_char, MNTOPT_IKEEP)) { |
574342f4 | 1741 | ikeep = 1; |
1da177e4 LT |
1742 | args->flags &= ~XFSMNT_IDELETE; |
1743 | } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) { | |
1744 | args->flags |= XFSMNT_IDELETE; | |
e8c8b3a7 | 1745 | } else if (!strcmp(this_char, MNTOPT_LARGEIO)) { |
e718eeb4 | 1746 | args->flags2 &= ~XFSMNT2_COMPAT_IOSIZE; |
e8c8b3a7 | 1747 | } else if (!strcmp(this_char, MNTOPT_NOLARGEIO)) { |
e718eeb4 | 1748 | args->flags2 |= XFSMNT2_COMPAT_IOSIZE; |
d8cc890d | 1749 | } else if (!strcmp(this_char, MNTOPT_ATTR2)) { |
13059ff0 | 1750 | args->flags |= XFSMNT_ATTR2; |
d8cc890d | 1751 | } else if (!strcmp(this_char, MNTOPT_NOATTR2)) { |
13059ff0 | 1752 | args->flags &= ~XFSMNT_ATTR2; |
2a82b8be DC |
1753 | } else if (!strcmp(this_char, MNTOPT_FILESTREAM)) { |
1754 | args->flags2 |= XFSMNT2_FILESTREAMS; | |
b09cc771 CH |
1755 | } else if (!strcmp(this_char, MNTOPT_NOQUOTA)) { |
1756 | args->flags &= ~(XFSMNT_UQUOTAENF|XFSMNT_UQUOTA); | |
1757 | args->flags &= ~(XFSMNT_GQUOTAENF|XFSMNT_GQUOTA); | |
1758 | } else if (!strcmp(this_char, MNTOPT_QUOTA) || | |
1759 | !strcmp(this_char, MNTOPT_UQUOTA) || | |
1760 | !strcmp(this_char, MNTOPT_USRQUOTA)) { | |
1761 | args->flags |= XFSMNT_UQUOTA | XFSMNT_UQUOTAENF; | |
1762 | } else if (!strcmp(this_char, MNTOPT_QUOTANOENF) || | |
1763 | !strcmp(this_char, MNTOPT_UQUOTANOENF)) { | |
1764 | args->flags |= XFSMNT_UQUOTA; | |
1765 | args->flags &= ~XFSMNT_UQUOTAENF; | |
1766 | } else if (!strcmp(this_char, MNTOPT_PQUOTA) || | |
1767 | !strcmp(this_char, MNTOPT_PRJQUOTA)) { | |
1768 | args->flags |= XFSMNT_PQUOTA | XFSMNT_PQUOTAENF; | |
1769 | } else if (!strcmp(this_char, MNTOPT_PQUOTANOENF)) { | |
1770 | args->flags |= XFSMNT_PQUOTA; | |
1771 | args->flags &= ~XFSMNT_PQUOTAENF; | |
1772 | } else if (!strcmp(this_char, MNTOPT_GQUOTA) || | |
1773 | !strcmp(this_char, MNTOPT_GRPQUOTA)) { | |
1774 | args->flags |= XFSMNT_GQUOTA | XFSMNT_GQUOTAENF; | |
1775 | } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) { | |
1776 | args->flags |= XFSMNT_GQUOTA; | |
1777 | args->flags &= ~XFSMNT_GQUOTAENF; | |
293688ec CH |
1778 | } else if (!strcmp(this_char, MNTOPT_DMAPI)) { |
1779 | args->flags |= XFSMNT_DMAPI; | |
1780 | } else if (!strcmp(this_char, MNTOPT_XDSM)) { | |
1781 | args->flags |= XFSMNT_DMAPI; | |
1782 | } else if (!strcmp(this_char, MNTOPT_DMI)) { | |
1783 | args->flags |= XFSMNT_DMAPI; | |
da353b0d DC |
1784 | } else if (!strcmp(this_char, "ihashsize")) { |
1785 | cmn_err(CE_WARN, | |
1786 | "XFS: ihashsize no longer used, option is deprecated."); | |
1da177e4 LT |
1787 | } else if (!strcmp(this_char, "osyncisdsync")) { |
1788 | /* no-op, this is now the default */ | |
b6574520 NS |
1789 | cmn_err(CE_WARN, |
1790 | "XFS: osyncisdsync is now the default, option is deprecated."); | |
1da177e4 | 1791 | } else if (!strcmp(this_char, "irixsgid")) { |
b6574520 NS |
1792 | cmn_err(CE_WARN, |
1793 | "XFS: irixsgid is now a sysctl(2) variable, option is deprecated."); | |
1da177e4 | 1794 | } else { |
b6574520 NS |
1795 | cmn_err(CE_WARN, |
1796 | "XFS: unknown mount option [%s].", this_char); | |
1da177e4 LT |
1797 | return EINVAL; |
1798 | } | |
1799 | } | |
1800 | ||
1801 | if (args->flags & XFSMNT_NORECOVERY) { | |
bd186aa9 | 1802 | if ((mp->m_flags & XFS_MOUNT_RDONLY) == 0) { |
b6574520 NS |
1803 | cmn_err(CE_WARN, |
1804 | "XFS: no-recovery mounts must be read-only."); | |
1da177e4 LT |
1805 | return EINVAL; |
1806 | } | |
1807 | } | |
1808 | ||
1809 | if ((args->flags & XFSMNT_NOALIGN) && (dsunit || dswidth)) { | |
b6574520 NS |
1810 | cmn_err(CE_WARN, |
1811 | "XFS: sunit and swidth options incompatible with the noalign option"); | |
1da177e4 LT |
1812 | return EINVAL; |
1813 | } | |
1814 | ||
b09cc771 CH |
1815 | if ((args->flags & XFSMNT_GQUOTA) && (args->flags & XFSMNT_PQUOTA)) { |
1816 | cmn_err(CE_WARN, | |
1817 | "XFS: cannot mount with both project and group quota"); | |
1818 | return EINVAL; | |
1819 | } | |
1820 | ||
293688ec CH |
1821 | if ((args->flags & XFSMNT_DMAPI) && *args->mtpt == '\0') { |
1822 | printk("XFS: %s option needs the mount point option as well\n", | |
1823 | MNTOPT_DMAPI); | |
1824 | return EINVAL; | |
1825 | } | |
1826 | ||
1da177e4 | 1827 | if ((dsunit && !dswidth) || (!dsunit && dswidth)) { |
b6574520 NS |
1828 | cmn_err(CE_WARN, |
1829 | "XFS: sunit and swidth must be specified together"); | |
1da177e4 LT |
1830 | return EINVAL; |
1831 | } | |
1832 | ||
1833 | if (dsunit && (dswidth % dsunit != 0)) { | |
b6574520 NS |
1834 | cmn_err(CE_WARN, |
1835 | "XFS: stripe width (%d) must be a multiple of the stripe unit (%d)", | |
1da177e4 LT |
1836 | dswidth, dsunit); |
1837 | return EINVAL; | |
1838 | } | |
1839 | ||
574342f4 VA |
1840 | /* |
1841 | * Applications using DMI filesystems often expect the | |
1842 | * inode generation number to be monotonically increasing. | |
1843 | * If we delete inode chunks we break this assumption, so | |
1844 | * keep unused inode chunks on disk for DMI filesystems | |
1845 | * until we come up with a better solution. | |
1846 | * Note that if "ikeep" or "noikeep" mount options are | |
1847 | * supplied, then they are honored. | |
1848 | */ | |
1849 | if (!(args->flags & XFSMNT_DMAPI) && !ikeep) | |
1850 | args->flags |= XFSMNT_IDELETE; | |
1851 | ||
1da177e4 LT |
1852 | if ((args->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) { |
1853 | if (dsunit) { | |
1854 | args->sunit = dsunit; | |
1855 | args->flags |= XFSMNT_RETERR; | |
1856 | } else { | |
1857 | args->sunit = vol_dsunit; | |
1858 | } | |
1859 | dswidth ? (args->swidth = dswidth) : | |
1860 | (args->swidth = vol_dswidth); | |
1861 | } else { | |
1862 | args->sunit = args->swidth = 0; | |
1863 | } | |
1864 | ||
05db218a | 1865 | done: |
c11e2c36 | 1866 | if (args->flags & XFSMNT_32BITINODES) |
bd186aa9 | 1867 | mp->m_flags |= XFS_MOUNT_SMALL_INUMS; |
e718eeb4 NS |
1868 | if (args->flags2) |
1869 | args->flags |= XFSMNT_FLAGS2; | |
1da177e4 LT |
1870 | return 0; |
1871 | } | |
1872 | ||
48c872a9 | 1873 | int |
1da177e4 | 1874 | xfs_showargs( |
48c872a9 | 1875 | struct xfs_mount *mp, |
1da177e4 LT |
1876 | struct seq_file *m) |
1877 | { | |
1878 | static struct proc_xfs_info { | |
1879 | int flag; | |
1880 | char *str; | |
1881 | } xfs_info[] = { | |
1882 | /* the few simple ones we can get from the mount struct */ | |
1883 | { XFS_MOUNT_WSYNC, "," MNTOPT_WSYNC }, | |
1884 | { XFS_MOUNT_INO64, "," MNTOPT_INO64 }, | |
1885 | { XFS_MOUNT_NOALIGN, "," MNTOPT_NOALIGN }, | |
1886 | { XFS_MOUNT_SWALLOC, "," MNTOPT_SWALLOC }, | |
1887 | { XFS_MOUNT_NOUUID, "," MNTOPT_NOUUID }, | |
1888 | { XFS_MOUNT_NORECOVERY, "," MNTOPT_NORECOVERY }, | |
1889 | { XFS_MOUNT_OSYNCISOSYNC, "," MNTOPT_OSYNCISOSYNC }, | |
1da177e4 LT |
1890 | { 0, NULL } |
1891 | }; | |
1892 | struct proc_xfs_info *xfs_infop; | |
1da177e4 LT |
1893 | |
1894 | for (xfs_infop = xfs_info; xfs_infop->flag; xfs_infop++) { | |
1895 | if (mp->m_flags & xfs_infop->flag) | |
1896 | seq_puts(m, xfs_infop->str); | |
1897 | } | |
1898 | ||
1da177e4 | 1899 | if (mp->m_flags & XFS_MOUNT_DFLT_IOSIZE) |
cfcbbbd0 NS |
1900 | seq_printf(m, "," MNTOPT_ALLOCSIZE "=%dk", |
1901 | (int)(1 << mp->m_writeio_log) >> 10); | |
1da177e4 LT |
1902 | |
1903 | if (mp->m_logbufs > 0) | |
1904 | seq_printf(m, "," MNTOPT_LOGBUFS "=%d", mp->m_logbufs); | |
1da177e4 | 1905 | if (mp->m_logbsize > 0) |
cfcbbbd0 | 1906 | seq_printf(m, "," MNTOPT_LOGBSIZE "=%dk", mp->m_logbsize >> 10); |
1da177e4 | 1907 | |
fc1f8c1c NS |
1908 | if (mp->m_logname) |
1909 | seq_printf(m, "," MNTOPT_LOGDEV "=%s", mp->m_logname); | |
fc1f8c1c NS |
1910 | if (mp->m_rtname) |
1911 | seq_printf(m, "," MNTOPT_RTDEV "=%s", mp->m_rtname); | |
1da177e4 LT |
1912 | |
1913 | if (mp->m_dalign > 0) | |
1914 | seq_printf(m, "," MNTOPT_SUNIT "=%d", | |
1915 | (int)XFS_FSB_TO_BB(mp, mp->m_dalign)); | |
1da177e4 LT |
1916 | if (mp->m_swidth > 0) |
1917 | seq_printf(m, "," MNTOPT_SWIDTH "=%d", | |
1918 | (int)XFS_FSB_TO_BB(mp, mp->m_swidth)); | |
1919 | ||
e15f195c NS |
1920 | if (!(mp->m_flags & XFS_MOUNT_IDELETE)) |
1921 | seq_printf(m, "," MNTOPT_IKEEP); | |
fa7e7d71 NS |
1922 | if (!(mp->m_flags & XFS_MOUNT_COMPAT_IOSIZE)) |
1923 | seq_printf(m, "," MNTOPT_LARGEIO); | |
1924 | ||
bd186aa9 | 1925 | if (!(mp->m_flags & XFS_MOUNT_SMALL_INUMS)) |
c11e2c36 | 1926 | seq_printf(m, "," MNTOPT_64BITINODE); |
bd186aa9 | 1927 | if (mp->m_flags & XFS_MOUNT_GRPID) |
e69a333b NS |
1928 | seq_printf(m, "," MNTOPT_GRPID); |
1929 | ||
b09cc771 CH |
1930 | if (mp->m_qflags & XFS_UQUOTA_ACCT) { |
1931 | if (mp->m_qflags & XFS_UQUOTA_ENFD) | |
1932 | seq_puts(m, "," MNTOPT_USRQUOTA); | |
1933 | else | |
1934 | seq_puts(m, "," MNTOPT_UQUOTANOENF); | |
1935 | } | |
1936 | ||
1937 | if (mp->m_qflags & XFS_PQUOTA_ACCT) { | |
1938 | if (mp->m_qflags & XFS_OQUOTA_ENFD) | |
1939 | seq_puts(m, "," MNTOPT_PRJQUOTA); | |
1940 | else | |
1941 | seq_puts(m, "," MNTOPT_PQUOTANOENF); | |
1942 | } | |
1943 | ||
1944 | if (mp->m_qflags & XFS_GQUOTA_ACCT) { | |
1945 | if (mp->m_qflags & XFS_OQUOTA_ENFD) | |
1946 | seq_puts(m, "," MNTOPT_GRPQUOTA); | |
1947 | else | |
1948 | seq_puts(m, "," MNTOPT_GQUOTANOENF); | |
1949 | } | |
1950 | ||
1951 | if (!(mp->m_qflags & XFS_ALL_QUOTA_ACCT)) | |
1952 | seq_puts(m, "," MNTOPT_NOQUOTA); | |
1953 | ||
bd186aa9 | 1954 | if (mp->m_flags & XFS_MOUNT_DMAPI) |
293688ec | 1955 | seq_puts(m, "," MNTOPT_DMAPI); |
1da177e4 LT |
1956 | return 0; |
1957 | } | |
1958 | ||
2823945f | 1959 | /* |
516b2e7c DC |
1960 | * Second stage of a freeze. The data is already frozen so we only |
1961 | * need to take care of themetadata. Once that's done write a dummy | |
1962 | * record to dirty the log in case of a crash while frozen. | |
2823945f | 1963 | */ |
479ba36b | 1964 | void |
1da177e4 | 1965 | xfs_freeze( |
48c872a9 | 1966 | xfs_mount_t *mp) |
1da177e4 | 1967 | { |
516b2e7c | 1968 | xfs_attr_quiesce(mp); |
e13a73f0 | 1969 | xfs_fs_log_dummy(mp); |
1da177e4 | 1970 | } |