]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/xfs/xfs_vfsops.c
[XFS] merge xfs_unmount into xfs_fs_put_super / xfs_fs_fill_super
[linux-2.6-omap-h63xx.git] / fs / xfs / xfs_vfsops.c
1 /*
2  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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
7  * published by the Free Software Foundation.
8  *
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.
13  *
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
17  */
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_types.h"
21 #include "xfs_bit.h"
22 #include "xfs_log.h"
23 #include "xfs_inum.h"
24 #include "xfs_trans.h"
25 #include "xfs_sb.h"
26 #include "xfs_ag.h"
27 #include "xfs_dir2.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_mount.h"
30 #include "xfs_da_btree.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_ialloc_btree.h"
33 #include "xfs_alloc_btree.h"
34 #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"
39 #include "xfs_btree.h"
40 #include "xfs_alloc.h"
41 #include "xfs_ialloc.h"
42 #include "xfs_quota.h"
43 #include "xfs_error.h"
44 #include "xfs_bmap.h"
45 #include "xfs_rw.h"
46 #include "xfs_buf_item.h"
47 #include "xfs_log_priv.h"
48 #include "xfs_dir2_trace.h"
49 #include "xfs_extfree_item.h"
50 #include "xfs_acl.h"
51 #include "xfs_attr.h"
52 #include "xfs_clnt.h"
53 #include "xfs_mru_cache.h"
54 #include "xfs_filestream.h"
55 #include "xfs_fsops.h"
56 #include "xfs_vnodeops.h"
57 #include "xfs_vfsops.h"
58 #include "xfs_utils.h"
59
60
61 int __init
62 xfs_init(void)
63 {
64 #ifdef XFS_DABUF_DEBUG
65         extern spinlock_t        xfs_dabuf_global_lock;
66         spin_lock_init(&xfs_dabuf_global_lock);
67 #endif
68
69         /*
70          * Initialize all of the zone allocators we use.
71          */
72         xfs_log_ticket_zone = kmem_zone_init(sizeof(xlog_ticket_t),
73                                                 "xfs_log_ticket");
74         xfs_bmap_free_item_zone = kmem_zone_init(sizeof(xfs_bmap_free_item_t),
75                                                 "xfs_bmap_free_item");
76         xfs_btree_cur_zone = kmem_zone_init(sizeof(xfs_btree_cur_t),
77                                                 "xfs_btree_cur");
78         xfs_da_state_zone = kmem_zone_init(sizeof(xfs_da_state_t),
79                                                 "xfs_da_state");
80         xfs_dabuf_zone = kmem_zone_init(sizeof(xfs_dabuf_t), "xfs_dabuf");
81         xfs_ifork_zone = kmem_zone_init(sizeof(xfs_ifork_t), "xfs_ifork");
82         xfs_trans_zone = kmem_zone_init(sizeof(xfs_trans_t), "xfs_trans");
83         xfs_acl_zone_init(xfs_acl_zone, "xfs_acl");
84         xfs_mru_cache_init();
85         xfs_filestream_init();
86
87         /*
88          * The size of the zone allocated buf log item is the maximum
89          * size possible under XFS.  This wastes a little bit of memory,
90          * but it is much faster.
91          */
92         xfs_buf_item_zone =
93                 kmem_zone_init((sizeof(xfs_buf_log_item_t) +
94                                 (((XFS_MAX_BLOCKSIZE / XFS_BLI_CHUNK) /
95                                   NBWORD) * sizeof(int))),
96                                "xfs_buf_item");
97         xfs_efd_zone =
98                 kmem_zone_init((sizeof(xfs_efd_log_item_t) +
99                                ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
100                                  sizeof(xfs_extent_t))),
101                                       "xfs_efd_item");
102         xfs_efi_zone =
103                 kmem_zone_init((sizeof(xfs_efi_log_item_t) +
104                                ((XFS_EFI_MAX_FAST_EXTENTS - 1) *
105                                  sizeof(xfs_extent_t))),
106                                       "xfs_efi_item");
107
108         /*
109          * These zones warrant special memory allocator hints
110          */
111         xfs_inode_zone =
112                 kmem_zone_init_flags(sizeof(xfs_inode_t), "xfs_inode",
113                                         KM_ZONE_HWALIGN | KM_ZONE_RECLAIM |
114                                         KM_ZONE_SPREAD, NULL);
115         xfs_ili_zone =
116                 kmem_zone_init_flags(sizeof(xfs_inode_log_item_t), "xfs_ili",
117                                         KM_ZONE_SPREAD, NULL);
118
119         /*
120          * Allocate global trace buffers.
121          */
122 #ifdef XFS_ALLOC_TRACE
123         xfs_alloc_trace_buf = ktrace_alloc(XFS_ALLOC_TRACE_SIZE, KM_SLEEP);
124 #endif
125 #ifdef XFS_BMAP_TRACE
126         xfs_bmap_trace_buf = ktrace_alloc(XFS_BMAP_TRACE_SIZE, KM_SLEEP);
127 #endif
128 #ifdef XFS_BMBT_TRACE
129         xfs_bmbt_trace_buf = ktrace_alloc(XFS_BMBT_TRACE_SIZE, KM_SLEEP);
130 #endif
131 #ifdef XFS_ATTR_TRACE
132         xfs_attr_trace_buf = ktrace_alloc(XFS_ATTR_TRACE_SIZE, KM_SLEEP);
133 #endif
134 #ifdef XFS_DIR2_TRACE
135         xfs_dir2_trace_buf = ktrace_alloc(XFS_DIR2_GTRACE_SIZE, KM_SLEEP);
136 #endif
137
138         xfs_dir_startup();
139
140 #if (defined(DEBUG) || defined(INDUCE_IO_ERROR))
141         xfs_error_test_init();
142 #endif /* DEBUG || INDUCE_IO_ERROR */
143
144         xfs_init_procfs();
145         xfs_sysctl_register();
146         return 0;
147 }
148
149 void __exit
150 xfs_cleanup(void)
151 {
152         extern kmem_zone_t      *xfs_inode_zone;
153         extern kmem_zone_t      *xfs_efd_zone;
154         extern kmem_zone_t      *xfs_efi_zone;
155
156         xfs_cleanup_procfs();
157         xfs_sysctl_unregister();
158         xfs_filestream_uninit();
159         xfs_mru_cache_uninit();
160         xfs_acl_zone_destroy(xfs_acl_zone);
161
162 #ifdef XFS_DIR2_TRACE
163         ktrace_free(xfs_dir2_trace_buf);
164 #endif
165 #ifdef XFS_ATTR_TRACE
166         ktrace_free(xfs_attr_trace_buf);
167 #endif
168 #ifdef XFS_BMBT_TRACE
169         ktrace_free(xfs_bmbt_trace_buf);
170 #endif
171 #ifdef XFS_BMAP_TRACE
172         ktrace_free(xfs_bmap_trace_buf);
173 #endif
174 #ifdef XFS_ALLOC_TRACE
175         ktrace_free(xfs_alloc_trace_buf);
176 #endif
177
178         kmem_zone_destroy(xfs_bmap_free_item_zone);
179         kmem_zone_destroy(xfs_btree_cur_zone);
180         kmem_zone_destroy(xfs_inode_zone);
181         kmem_zone_destroy(xfs_trans_zone);
182         kmem_zone_destroy(xfs_da_state_zone);
183         kmem_zone_destroy(xfs_dabuf_zone);
184         kmem_zone_destroy(xfs_buf_item_zone);
185         kmem_zone_destroy(xfs_efd_zone);
186         kmem_zone_destroy(xfs_efi_zone);
187         kmem_zone_destroy(xfs_ifork_zone);
188         kmem_zone_destroy(xfs_ili_zone);
189         kmem_zone_destroy(xfs_log_ticket_zone);
190 }
191
192 /*
193  * xfs_start_flags
194  *
195  * This function fills in xfs_mount_t fields based on mount args.
196  * Note: the superblock has _not_ yet been read in.
197  */
198 STATIC int
199 xfs_start_flags(
200         struct xfs_mount_args   *ap,
201         struct xfs_mount        *mp)
202 {
203         /* Values are in BBs */
204         if ((ap->flags & XFSMNT_NOALIGN) != XFSMNT_NOALIGN) {
205                 /*
206                  * At this point the superblock has not been read
207                  * in, therefore we do not know the block size.
208                  * Before the mount call ends we will convert
209                  * these to FSBs.
210                  */
211                 mp->m_dalign = ap->sunit;
212                 mp->m_swidth = ap->swidth;
213         }
214
215         if (ap->logbufs != -1 &&
216             ap->logbufs != 0 &&
217             (ap->logbufs < XLOG_MIN_ICLOGS ||
218              ap->logbufs > XLOG_MAX_ICLOGS)) {
219                 cmn_err(CE_WARN,
220                         "XFS: invalid logbufs value: %d [not %d-%d]",
221                         ap->logbufs, XLOG_MIN_ICLOGS, XLOG_MAX_ICLOGS);
222                 return XFS_ERROR(EINVAL);
223         }
224         mp->m_logbufs = ap->logbufs;
225         if (ap->logbufsize != -1 &&
226             ap->logbufsize !=  0 &&
227             (ap->logbufsize < XLOG_MIN_RECORD_BSIZE ||
228              ap->logbufsize > XLOG_MAX_RECORD_BSIZE ||
229              !is_power_of_2(ap->logbufsize))) {
230                 cmn_err(CE_WARN,
231         "XFS: invalid logbufsize: %d [not 16k,32k,64k,128k or 256k]",
232                         ap->logbufsize);
233                 return XFS_ERROR(EINVAL);
234         }
235         mp->m_logbsize = ap->logbufsize;
236         mp->m_fsname_len = strlen(ap->fsname) + 1;
237         mp->m_fsname = kmem_alloc(mp->m_fsname_len, KM_SLEEP);
238         strcpy(mp->m_fsname, ap->fsname);
239         if (ap->rtname[0]) {
240                 mp->m_rtname = kmem_alloc(strlen(ap->rtname) + 1, KM_SLEEP);
241                 strcpy(mp->m_rtname, ap->rtname);
242         }
243         if (ap->logname[0]) {
244                 mp->m_logname = kmem_alloc(strlen(ap->logname) + 1, KM_SLEEP);
245                 strcpy(mp->m_logname, ap->logname);
246         }
247
248         if (ap->flags & XFSMNT_WSYNC)
249                 mp->m_flags |= XFS_MOUNT_WSYNC;
250 #if XFS_BIG_INUMS
251         if (ap->flags & XFSMNT_INO64) {
252                 mp->m_flags |= XFS_MOUNT_INO64;
253                 mp->m_inoadd = XFS_INO64_OFFSET;
254         }
255 #endif
256         if (ap->flags & XFSMNT_RETERR)
257                 mp->m_flags |= XFS_MOUNT_RETERR;
258         if (ap->flags & XFSMNT_NOALIGN)
259                 mp->m_flags |= XFS_MOUNT_NOALIGN;
260         if (ap->flags & XFSMNT_SWALLOC)
261                 mp->m_flags |= XFS_MOUNT_SWALLOC;
262         if (ap->flags & XFSMNT_OSYNCISOSYNC)
263                 mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
264         if (ap->flags & XFSMNT_32BITINODES)
265                 mp->m_flags |= XFS_MOUNT_32BITINODES;
266
267         if (ap->flags & XFSMNT_IOSIZE) {
268                 if (ap->iosizelog > XFS_MAX_IO_LOG ||
269                     ap->iosizelog < XFS_MIN_IO_LOG) {
270                         cmn_err(CE_WARN,
271                 "XFS: invalid log iosize: %d [not %d-%d]",
272                                 ap->iosizelog, XFS_MIN_IO_LOG,
273                                 XFS_MAX_IO_LOG);
274                         return XFS_ERROR(EINVAL);
275                 }
276
277                 mp->m_flags |= XFS_MOUNT_DFLT_IOSIZE;
278                 mp->m_readio_log = mp->m_writeio_log = ap->iosizelog;
279         }
280
281         if (ap->flags & XFSMNT_IKEEP)
282                 mp->m_flags |= XFS_MOUNT_IKEEP;
283         if (ap->flags & XFSMNT_DIRSYNC)
284                 mp->m_flags |= XFS_MOUNT_DIRSYNC;
285         if (ap->flags & XFSMNT_ATTR2)
286                 mp->m_flags |= XFS_MOUNT_ATTR2;
287         if (ap->flags & XFSMNT_NOATTR2)
288                 mp->m_flags |= XFS_MOUNT_NOATTR2;
289
290         if (ap->flags2 & XFSMNT2_COMPAT_IOSIZE)
291                 mp->m_flags |= XFS_MOUNT_COMPAT_IOSIZE;
292
293         /*
294          * no recovery flag requires a read-only mount
295          */
296         if (ap->flags & XFSMNT_NORECOVERY) {
297                 if (!(mp->m_flags & XFS_MOUNT_RDONLY)) {
298                         cmn_err(CE_WARN,
299         "XFS: tried to mount a FS read-write without recovery!");
300                         return XFS_ERROR(EINVAL);
301                 }
302                 mp->m_flags |= XFS_MOUNT_NORECOVERY;
303         }
304
305         if (ap->flags & XFSMNT_NOUUID)
306                 mp->m_flags |= XFS_MOUNT_NOUUID;
307         if (ap->flags & XFSMNT_BARRIER)
308                 mp->m_flags |= XFS_MOUNT_BARRIER;
309         else
310                 mp->m_flags &= ~XFS_MOUNT_BARRIER;
311
312         if (ap->flags2 & XFSMNT2_FILESTREAMS)
313                 mp->m_flags |= XFS_MOUNT_FILESTREAMS;
314
315         if (ap->flags & XFSMNT_DMAPI)
316                 mp->m_flags |= XFS_MOUNT_DMAPI;
317         return 0;
318 }
319
320 /*
321  * This function fills in xfs_mount_t fields based on mount args.
322  * Note: the superblock _has_ now been read in.
323  */
324 STATIC int
325 xfs_finish_flags(
326         struct xfs_mount_args   *ap,
327         struct xfs_mount        *mp)
328 {
329         int                     ronly = (mp->m_flags & XFS_MOUNT_RDONLY);
330
331         /* Fail a mount where the logbuf is smaller then the log stripe */
332         if (xfs_sb_version_haslogv2(&mp->m_sb)) {
333                 if ((ap->logbufsize <= 0) &&
334                     (mp->m_sb.sb_logsunit > XLOG_BIG_RECORD_BSIZE)) {
335                         mp->m_logbsize = mp->m_sb.sb_logsunit;
336                 } else if (ap->logbufsize > 0 &&
337                            ap->logbufsize < mp->m_sb.sb_logsunit) {
338                         cmn_err(CE_WARN,
339         "XFS: logbuf size must be greater than or equal to log stripe size");
340                         return XFS_ERROR(EINVAL);
341                 }
342         } else {
343                 /* Fail a mount if the logbuf is larger than 32K */
344                 if (ap->logbufsize > XLOG_BIG_RECORD_BSIZE) {
345                         cmn_err(CE_WARN,
346         "XFS: logbuf size for version 1 logs must be 16K or 32K");
347                         return XFS_ERROR(EINVAL);
348                 }
349         }
350
351         /*
352          * mkfs'ed attr2 will turn on attr2 mount unless explicitly
353          * told by noattr2 to turn it off
354          */
355         if (xfs_sb_version_hasattr2(&mp->m_sb) &&
356             !(ap->flags & XFSMNT_NOATTR2))
357                 mp->m_flags |= XFS_MOUNT_ATTR2;
358
359         /*
360          * prohibit r/w mounts of read-only filesystems
361          */
362         if ((mp->m_sb.sb_flags & XFS_SBF_READONLY) && !ronly) {
363                 cmn_err(CE_WARN,
364         "XFS: cannot mount a read-only filesystem as read-write");
365                 return XFS_ERROR(EROFS);
366         }
367
368         /*
369          * check for shared mount.
370          */
371         if (ap->flags & XFSMNT_SHARED) {
372                 if (!xfs_sb_version_hasshared(&mp->m_sb))
373                         return XFS_ERROR(EINVAL);
374
375                 /*
376                  * For IRIX 6.5, shared mounts must have the shared
377                  * version bit set, have the persistent readonly
378                  * field set, must be version 0 and can only be mounted
379                  * read-only.
380                  */
381                 if (!ronly || !(mp->m_sb.sb_flags & XFS_SBF_READONLY) ||
382                      (mp->m_sb.sb_shared_vn != 0))
383                         return XFS_ERROR(EINVAL);
384
385                 mp->m_flags |= XFS_MOUNT_SHARED;
386
387                 /*
388                  * Shared XFS V0 can't deal with DMI.  Return EINVAL.
389                  */
390                 if (mp->m_sb.sb_shared_vn == 0 && (ap->flags & XFSMNT_DMAPI))
391                         return XFS_ERROR(EINVAL);
392         }
393
394         if (ap->flags & XFSMNT_UQUOTA) {
395                 mp->m_qflags |= (XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE);
396                 if (ap->flags & XFSMNT_UQUOTAENF)
397                         mp->m_qflags |= XFS_UQUOTA_ENFD;
398         }
399
400         if (ap->flags & XFSMNT_GQUOTA) {
401                 mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
402                 if (ap->flags & XFSMNT_GQUOTAENF)
403                         mp->m_qflags |= XFS_OQUOTA_ENFD;
404         } else if (ap->flags & XFSMNT_PQUOTA) {
405                 mp->m_qflags |= (XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE);
406                 if (ap->flags & XFSMNT_PQUOTAENF)
407                         mp->m_qflags |= XFS_OQUOTA_ENFD;
408         }
409
410         return 0;
411 }
412
413 /*
414  * xfs_mount
415  *
416  * The file system configurations are:
417  *      (1) device (partition) with data and internal log
418  *      (2) logical volume with data and log subvolumes.
419  *      (3) logical volume with data, log, and realtime subvolumes.
420  *
421  * We only have to handle opening the log and realtime volumes here if
422  * they are present.  The data subvolume has already been opened by
423  * get_sb_bdev() and is stored in vfsp->vfs_super->s_bdev.
424  */
425 int
426 xfs_mount(
427         struct xfs_mount        *mp,
428         struct xfs_mount_args   *args,
429         cred_t                  *credp)
430 {
431         struct block_device     *ddev, *logdev, *rtdev;
432         int                     flags = 0, error;
433
434         ddev = mp->m_super->s_bdev;
435         logdev = rtdev = NULL;
436
437         error = xfs_dmops_get(mp, args);
438         if (error)
439                 return error;
440         error = xfs_qmops_get(mp, args);
441         if (error)
442                 return error;
443
444         if (args->flags & XFSMNT_QUIET)
445                 flags |= XFS_MFSI_QUIET;
446
447         /*
448          * Open real time and log devices - order is important.
449          */
450         if (args->logname[0]) {
451                 error = xfs_blkdev_get(mp, args->logname, &logdev);
452                 if (error)
453                         return error;
454         }
455         if (args->rtname[0]) {
456                 error = xfs_blkdev_get(mp, args->rtname, &rtdev);
457                 if (error) {
458                         xfs_blkdev_put(logdev);
459                         return error;
460                 }
461
462                 if (rtdev == ddev || rtdev == logdev) {
463                         cmn_err(CE_WARN,
464         "XFS: Cannot mount filesystem with identical rtdev and ddev/logdev.");
465                         xfs_blkdev_put(logdev);
466                         xfs_blkdev_put(rtdev);
467                         return EINVAL;
468                 }
469         }
470
471         /*
472          * Setup xfs_mount buffer target pointers
473          */
474         error = ENOMEM;
475         mp->m_ddev_targp = xfs_alloc_buftarg(ddev, 0);
476         if (!mp->m_ddev_targp) {
477                 xfs_blkdev_put(logdev);
478                 xfs_blkdev_put(rtdev);
479                 return error;
480         }
481         if (rtdev) {
482                 mp->m_rtdev_targp = xfs_alloc_buftarg(rtdev, 1);
483                 if (!mp->m_rtdev_targp) {
484                         xfs_blkdev_put(logdev);
485                         xfs_blkdev_put(rtdev);
486                         goto error0;
487                 }
488         }
489         mp->m_logdev_targp = (logdev && logdev != ddev) ?
490                                 xfs_alloc_buftarg(logdev, 1) : mp->m_ddev_targp;
491         if (!mp->m_logdev_targp) {
492                 xfs_blkdev_put(logdev);
493                 xfs_blkdev_put(rtdev);
494                 goto error0;
495         }
496
497         /*
498          * Setup flags based on mount(2) options and then the superblock
499          */
500         error = xfs_start_flags(args, mp);
501         if (error)
502                 goto error1;
503         error = xfs_readsb(mp, flags);
504         if (error)
505                 goto error1;
506         error = xfs_finish_flags(args, mp);
507         if (error)
508                 goto error2;
509
510         /*
511          * Setup xfs_mount buffer target pointers based on superblock
512          */
513         error = xfs_setsize_buftarg(mp->m_ddev_targp, mp->m_sb.sb_blocksize,
514                                     mp->m_sb.sb_sectsize);
515         if (!error && logdev && logdev != ddev) {
516                 unsigned int    log_sector_size = BBSIZE;
517
518                 if (xfs_sb_version_hassector(&mp->m_sb))
519                         log_sector_size = mp->m_sb.sb_logsectsize;
520                 error = xfs_setsize_buftarg(mp->m_logdev_targp,
521                                             mp->m_sb.sb_blocksize,
522                                             log_sector_size);
523         }
524         if (!error && rtdev)
525                 error = xfs_setsize_buftarg(mp->m_rtdev_targp,
526                                             mp->m_sb.sb_blocksize,
527                                             mp->m_sb.sb_sectsize);
528         if (error)
529                 goto error2;
530
531         if (mp->m_flags & XFS_MOUNT_BARRIER)
532                 xfs_mountfs_check_barriers(mp);
533
534         if ((error = xfs_filestream_mount(mp)))
535                 goto error2;
536
537         error = xfs_mountfs(mp, flags);
538         if (error)
539                 goto error2;
540
541         XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, args->mtpt, args->fsname);
542
543         return 0;
544
545 error2:
546         if (mp->m_sb_bp)
547                 xfs_freesb(mp);
548 error1:
549         xfs_binval(mp->m_ddev_targp);
550         if (logdev && logdev != ddev)
551                 xfs_binval(mp->m_logdev_targp);
552         if (rtdev)
553                 xfs_binval(mp->m_rtdev_targp);
554 error0:
555         xfs_unmountfs_close(mp, credp);
556         xfs_qmops_put(mp);
557         xfs_dmops_put(mp);
558         return error;
559 }
560
561 STATIC void
562 xfs_quiesce_fs(
563         xfs_mount_t             *mp)
564 {
565         int                     count = 0, pincount;
566
567         xfs_flush_buftarg(mp->m_ddev_targp, 0);
568         xfs_finish_reclaim_all(mp, 0);
569
570         /* This loop must run at least twice.
571          * The first instance of the loop will flush
572          * most meta data but that will generate more
573          * meta data (typically directory updates).
574          * Which then must be flushed and logged before
575          * we can write the unmount record.
576          */
577         do {
578                 xfs_syncsub(mp, SYNC_INODE_QUIESCE, NULL);
579                 pincount = xfs_flush_buftarg(mp->m_ddev_targp, 1);
580                 if (!pincount) {
581                         delay(50);
582                         count++;
583                 }
584         } while (count < 2);
585 }
586
587 /*
588  * Second stage of a quiesce. The data is already synced, now we have to take
589  * care of the metadata. New transactions are already blocked, so we need to
590  * wait for any remaining transactions to drain out before proceding.
591  */
592 void
593 xfs_attr_quiesce(
594         xfs_mount_t     *mp)
595 {
596         int     error = 0;
597
598         /* wait for all modifications to complete */
599         while (atomic_read(&mp->m_active_trans) > 0)
600                 delay(100);
601
602         /* flush inodes and push all remaining buffers out to disk */
603         xfs_quiesce_fs(mp);
604
605         ASSERT_ALWAYS(atomic_read(&mp->m_active_trans) == 0);
606
607         /* Push the superblock and write an unmount record */
608         error = xfs_log_sbcount(mp, 1);
609         if (error)
610                 xfs_fs_cmn_err(CE_WARN, mp,
611                                 "xfs_attr_quiesce: failed to log sb changes. "
612                                 "Frozen image may not be consistent.");
613         xfs_log_unmount_write(mp);
614         xfs_unmountfs_writesb(mp);
615 }
616
617 /*
618  * xfs_unmount_flush implements a set of flush operation on special
619  * inodes, which are needed as a separate set of operations so that
620  * they can be called as part of relocation process.
621  */
622 int
623 xfs_unmount_flush(
624         xfs_mount_t     *mp,            /* Mount structure we are getting
625                                            rid of. */
626         int             relocation)     /* Called from vfs relocation. */
627 {
628         xfs_inode_t     *rip = mp->m_rootip;
629         xfs_inode_t     *rbmip;
630         xfs_inode_t     *rsumip = NULL;
631         bhv_vnode_t     *rvp = XFS_ITOV(rip);
632         int             error;
633
634         xfs_ilock(rip, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
635         xfs_iflock(rip);
636
637         /*
638          * Flush out the real time inodes.
639          */
640         if ((rbmip = mp->m_rbmip) != NULL) {
641                 xfs_ilock(rbmip, XFS_ILOCK_EXCL);
642                 xfs_iflock(rbmip);
643                 error = xfs_iflush(rbmip, XFS_IFLUSH_SYNC);
644                 xfs_iunlock(rbmip, XFS_ILOCK_EXCL);
645
646                 if (error == EFSCORRUPTED)
647                         goto fscorrupt_out;
648
649                 ASSERT(vn_count(XFS_ITOV(rbmip)) == 1);
650
651                 rsumip = mp->m_rsumip;
652                 xfs_ilock(rsumip, XFS_ILOCK_EXCL);
653                 xfs_iflock(rsumip);
654                 error = xfs_iflush(rsumip, XFS_IFLUSH_SYNC);
655                 xfs_iunlock(rsumip, XFS_ILOCK_EXCL);
656
657                 if (error == EFSCORRUPTED)
658                         goto fscorrupt_out;
659
660                 ASSERT(vn_count(XFS_ITOV(rsumip)) == 1);
661         }
662
663         /*
664          * Synchronously flush root inode to disk
665          */
666         error = xfs_iflush(rip, XFS_IFLUSH_SYNC);
667         if (error == EFSCORRUPTED)
668                 goto fscorrupt_out2;
669
670         if (vn_count(rvp) != 1 && !relocation) {
671                 xfs_iunlock(rip, XFS_ILOCK_EXCL);
672                 return XFS_ERROR(EBUSY);
673         }
674
675         /*
676          * Release dquot that rootinode, rbmino and rsumino might be holding,
677          * flush and purge the quota inodes.
678          */
679         error = XFS_QM_UNMOUNT(mp);
680         if (error == EFSCORRUPTED)
681                 goto fscorrupt_out2;
682
683         if (rbmip) {
684                 IRELE(rbmip);
685                 IRELE(rsumip);
686         }
687
688         xfs_iunlock(rip, XFS_ILOCK_EXCL);
689         return 0;
690
691 fscorrupt_out:
692         xfs_ifunlock(rip);
693
694 fscorrupt_out2:
695         xfs_iunlock(rip, XFS_ILOCK_EXCL);
696
697         return XFS_ERROR(EFSCORRUPTED);
698 }
699
700 /*
701  * xfs_sync flushes any pending I/O to file system vfsp.
702  *
703  * This routine is called by vfs_sync() to make sure that things make it
704  * out to disk eventually, on sync() system calls to flush out everything,
705  * and when the file system is unmounted.  For the vfs_sync() case, all
706  * we really need to do is sync out the log to make all of our meta-data
707  * updates permanent (except for timestamps).  For calls from pflushd(),
708  * dirty pages are kept moving by calling pdflush() on the inodes
709  * containing them.  We also flush the inodes that we can lock without
710  * sleeping and the superblock if we can lock it without sleeping from
711  * vfs_sync() so that items at the tail of the log are always moving out.
712  *
713  * Flags:
714  *      SYNC_BDFLUSH - We're being called from vfs_sync() so we don't want
715  *                     to sleep if we can help it.  All we really need
716  *                     to do is ensure that the log is synced at least
717  *                     periodically.  We also push the inodes and
718  *                     superblock if we can lock them without sleeping
719  *                      and they are not pinned.
720  *      SYNC_ATTR    - We need to flush the inodes.  If SYNC_BDFLUSH is not
721  *                     set, then we really want to lock each inode and flush
722  *                     it.
723  *      SYNC_WAIT    - All the flushes that take place in this call should
724  *                     be synchronous.
725  *      SYNC_DELWRI  - This tells us to push dirty pages associated with
726  *                     inodes.  SYNC_WAIT and SYNC_BDFLUSH are used to
727  *                     determine if they should be flushed sync, async, or
728  *                     delwri.
729  *      SYNC_CLOSE   - This flag is passed when the system is being
730  *                     unmounted.  We should sync and invalidate everything.
731  *      SYNC_FSDATA  - This indicates that the caller would like to make
732  *                     sure the superblock is safe on disk.  We can ensure
733  *                     this by simply making sure the log gets flushed
734  *                     if SYNC_BDFLUSH is set, and by actually writing it
735  *                     out otherwise.
736  *      SYNC_IOWAIT  - The caller wants us to wait for all data I/O to complete
737  *                     before we return (including direct I/O). Forms the drain
738  *                     side of the write barrier needed to safely quiesce the
739  *                     filesystem.
740  *
741  */
742 int
743 xfs_sync(
744         xfs_mount_t     *mp,
745         int             flags)
746 {
747         int             error;
748
749         /*
750          * Get the Quota Manager to flush the dquots.
751          *
752          * If XFS quota support is not enabled or this filesystem
753          * instance does not use quotas XFS_QM_DQSYNC will always
754          * return zero.
755          */
756         error = XFS_QM_DQSYNC(mp, flags);
757         if (error) {
758                 /*
759                  * If we got an IO error, we will be shutting down.
760                  * So, there's nothing more for us to do here.
761                  */
762                 ASSERT(error != EIO || XFS_FORCED_SHUTDOWN(mp));
763                 if (XFS_FORCED_SHUTDOWN(mp))
764                         return XFS_ERROR(error);
765         }
766
767         if (flags & SYNC_IOWAIT)
768                 xfs_filestream_flush(mp);
769
770         return xfs_syncsub(mp, flags, NULL);
771 }
772
773 /*
774  * xfs sync routine for internal use
775  *
776  * This routine supports all of the flags defined for the generic vfs_sync
777  * interface as explained above under xfs_sync.
778  *
779  */
780 int
781 xfs_sync_inodes(
782         xfs_mount_t     *mp,
783         int             flags,
784         int             *bypassed)
785 {
786         xfs_inode_t     *ip = NULL;
787         bhv_vnode_t     *vp = NULL;
788         int             error;
789         int             last_error;
790         uint64_t        fflag;
791         uint            lock_flags;
792         uint            base_lock_flags;
793         boolean_t       mount_locked;
794         boolean_t       vnode_refed;
795         int             preempt;
796         xfs_iptr_t      *ipointer;
797 #ifdef DEBUG
798         boolean_t       ipointer_in = B_FALSE;
799
800 #define IPOINTER_SET    ipointer_in = B_TRUE
801 #define IPOINTER_CLR    ipointer_in = B_FALSE
802 #else
803 #define IPOINTER_SET
804 #define IPOINTER_CLR
805 #endif
806
807
808 /* Insert a marker record into the inode list after inode ip. The list
809  * must be locked when this is called. After the call the list will no
810  * longer be locked.
811  */
812 #define IPOINTER_INSERT(ip, mp) { \
813                 ASSERT(ipointer_in == B_FALSE); \
814                 ipointer->ip_mnext = ip->i_mnext; \
815                 ipointer->ip_mprev = ip; \
816                 ip->i_mnext = (xfs_inode_t *)ipointer; \
817                 ipointer->ip_mnext->i_mprev = (xfs_inode_t *)ipointer; \
818                 preempt = 0; \
819                 XFS_MOUNT_IUNLOCK(mp); \
820                 mount_locked = B_FALSE; \
821                 IPOINTER_SET; \
822         }
823
824 /* Remove the marker from the inode list. If the marker was the only item
825  * in the list then there are no remaining inodes and we should zero out
826  * the whole list. If we are the current head of the list then move the head
827  * past us.
828  */
829 #define IPOINTER_REMOVE(ip, mp) { \
830                 ASSERT(ipointer_in == B_TRUE); \
831                 if (ipointer->ip_mnext != (xfs_inode_t *)ipointer) { \
832                         ip = ipointer->ip_mnext; \
833                         ip->i_mprev = ipointer->ip_mprev; \
834                         ipointer->ip_mprev->i_mnext = ip; \
835                         if (mp->m_inodes == (xfs_inode_t *)ipointer) { \
836                                 mp->m_inodes = ip; \
837                         } \
838                 } else { \
839                         ASSERT(mp->m_inodes == (xfs_inode_t *)ipointer); \
840                         mp->m_inodes = NULL; \
841                         ip = NULL; \
842                 } \
843                 IPOINTER_CLR; \
844         }
845
846 #define XFS_PREEMPT_MASK        0x7f
847
848         ASSERT(!(flags & SYNC_BDFLUSH));
849
850         if (bypassed)
851                 *bypassed = 0;
852         if (mp->m_flags & XFS_MOUNT_RDONLY)
853                 return 0;
854         error = 0;
855         last_error = 0;
856         preempt = 0;
857
858         /* Allocate a reference marker */
859         ipointer = (xfs_iptr_t *)kmem_zalloc(sizeof(xfs_iptr_t), KM_SLEEP);
860
861         fflag = XFS_B_ASYNC;            /* default is don't wait */
862         if (flags & SYNC_DELWRI)
863                 fflag = XFS_B_DELWRI;
864         if (flags & SYNC_WAIT)
865                 fflag = 0;              /* synchronous overrides all */
866
867         base_lock_flags = XFS_ILOCK_SHARED;
868         if (flags & (SYNC_DELWRI | SYNC_CLOSE)) {
869                 /*
870                  * We need the I/O lock if we're going to call any of
871                  * the flush/inval routines.
872                  */
873                 base_lock_flags |= XFS_IOLOCK_SHARED;
874         }
875
876         XFS_MOUNT_ILOCK(mp);
877
878         ip = mp->m_inodes;
879
880         mount_locked = B_TRUE;
881         vnode_refed  = B_FALSE;
882
883         IPOINTER_CLR;
884
885         do {
886                 ASSERT(ipointer_in == B_FALSE);
887                 ASSERT(vnode_refed == B_FALSE);
888
889                 lock_flags = base_lock_flags;
890
891                 /*
892                  * There were no inodes in the list, just break out
893                  * of the loop.
894                  */
895                 if (ip == NULL) {
896                         break;
897                 }
898
899                 /*
900                  * We found another sync thread marker - skip it
901                  */
902                 if (ip->i_mount == NULL) {
903                         ip = ip->i_mnext;
904                         continue;
905                 }
906
907                 vp = XFS_ITOV_NULL(ip);
908
909                 /*
910                  * If the vnode is gone then this is being torn down,
911                  * call reclaim if it is flushed, else let regular flush
912                  * code deal with it later in the loop.
913                  */
914
915                 if (vp == NULL) {
916                         /* Skip ones already in reclaim */
917                         if (ip->i_flags & XFS_IRECLAIM) {
918                                 ip = ip->i_mnext;
919                                 continue;
920                         }
921                         if (xfs_ilock_nowait(ip, XFS_ILOCK_EXCL) == 0) {
922                                 ip = ip->i_mnext;
923                         } else if ((xfs_ipincount(ip) == 0) &&
924                                     xfs_iflock_nowait(ip)) {
925                                 IPOINTER_INSERT(ip, mp);
926
927                                 xfs_finish_reclaim(ip, 1,
928                                                 XFS_IFLUSH_DELWRI_ELSE_ASYNC);
929
930                                 XFS_MOUNT_ILOCK(mp);
931                                 mount_locked = B_TRUE;
932                                 IPOINTER_REMOVE(ip, mp);
933                         } else {
934                                 xfs_iunlock(ip, XFS_ILOCK_EXCL);
935                                 ip = ip->i_mnext;
936                         }
937                         continue;
938                 }
939
940                 if (VN_BAD(vp)) {
941                         ip = ip->i_mnext;
942                         continue;
943                 }
944
945                 if (XFS_FORCED_SHUTDOWN(mp) && !(flags & SYNC_CLOSE)) {
946                         XFS_MOUNT_IUNLOCK(mp);
947                         kmem_free(ipointer);
948                         return 0;
949                 }
950
951                 /*
952                  * Try to lock without sleeping.  We're out of order with
953                  * the inode list lock here, so if we fail we need to drop
954                  * the mount lock and try again.  If we're called from
955                  * bdflush() here, then don't bother.
956                  *
957                  * The inode lock here actually coordinates with the
958                  * almost spurious inode lock in xfs_ireclaim() to prevent
959                  * the vnode we handle here without a reference from
960                  * being freed while we reference it.  If we lock the inode
961                  * while it's on the mount list here, then the spurious inode
962                  * lock in xfs_ireclaim() after the inode is pulled from
963                  * the mount list will sleep until we release it here.
964                  * This keeps the vnode from being freed while we reference
965                  * it.
966                  */
967                 if (xfs_ilock_nowait(ip, lock_flags) == 0) {
968                         if (vp == NULL) {
969                                 ip = ip->i_mnext;
970                                 continue;
971                         }
972
973                         vp = vn_grab(vp);
974                         if (vp == NULL) {
975                                 ip = ip->i_mnext;
976                                 continue;
977                         }
978
979                         IPOINTER_INSERT(ip, mp);
980                         xfs_ilock(ip, lock_flags);
981
982                         ASSERT(vp == XFS_ITOV(ip));
983                         ASSERT(ip->i_mount == mp);
984
985                         vnode_refed = B_TRUE;
986                 }
987
988                 /* From here on in the loop we may have a marker record
989                  * in the inode list.
990                  */
991
992                 /*
993                  * If we have to flush data or wait for I/O completion
994                  * we need to drop the ilock that we currently hold.
995                  * If we need to drop the lock, insert a marker if we
996                  * have not already done so.
997                  */
998                 if ((flags & (SYNC_CLOSE|SYNC_IOWAIT)) ||
999                     ((flags & SYNC_DELWRI) && VN_DIRTY(vp))) {
1000                         if (mount_locked) {
1001                                 IPOINTER_INSERT(ip, mp);
1002                         }
1003                         xfs_iunlock(ip, XFS_ILOCK_SHARED);
1004
1005                         if (flags & SYNC_CLOSE) {
1006                                 /* Shutdown case. Flush and invalidate. */
1007                                 if (XFS_FORCED_SHUTDOWN(mp))
1008                                         xfs_tosspages(ip, 0, -1,
1009                                                              FI_REMAPF);
1010                                 else
1011                                         error = xfs_flushinval_pages(ip,
1012                                                         0, -1, FI_REMAPF);
1013                         } else if ((flags & SYNC_DELWRI) && VN_DIRTY(vp)) {
1014                                 error = xfs_flush_pages(ip, 0,
1015                                                         -1, fflag, FI_NONE);
1016                         }
1017
1018                         /*
1019                          * When freezing, we need to wait ensure all I/O (including direct
1020                          * I/O) is complete to ensure no further data modification can take
1021                          * place after this point
1022                          */
1023                         if (flags & SYNC_IOWAIT)
1024                                 vn_iowait(ip);
1025
1026                         xfs_ilock(ip, XFS_ILOCK_SHARED);
1027                 }
1028
1029                 if ((flags & SYNC_ATTR) &&
1030                     (ip->i_update_core ||
1031                      (ip->i_itemp && ip->i_itemp->ili_format.ilf_fields))) {
1032                         if (mount_locked)
1033                                 IPOINTER_INSERT(ip, mp);
1034
1035                         if (flags & SYNC_WAIT) {
1036                                 xfs_iflock(ip);
1037                                 error = xfs_iflush(ip, XFS_IFLUSH_SYNC);
1038
1039                         /*
1040                          * If we can't acquire the flush lock, then the inode
1041                          * is already being flushed so don't bother waiting.
1042                          *
1043                          * If we can lock it then do a delwri flush so we can
1044                          * combine multiple inode flushes in each disk write.
1045                          */
1046                         } else if (xfs_iflock_nowait(ip)) {
1047                                 error = xfs_iflush(ip, XFS_IFLUSH_DELWRI);
1048                         } else if (bypassed) {
1049                                 (*bypassed)++;
1050                         }
1051                 }
1052
1053                 if (lock_flags != 0) {
1054                         xfs_iunlock(ip, lock_flags);
1055                 }
1056
1057                 if (vnode_refed) {
1058                         /*
1059                          * If we had to take a reference on the vnode
1060                          * above, then wait until after we've unlocked
1061                          * the inode to release the reference.  This is
1062                          * because we can be already holding the inode
1063                          * lock when IRELE() calls xfs_inactive().
1064                          *
1065                          * Make sure to drop the mount lock before calling
1066                          * IRELE() so that we don't trip over ourselves if
1067                          * we have to go for the mount lock again in the
1068                          * inactive code.
1069                          */
1070                         if (mount_locked) {
1071                                 IPOINTER_INSERT(ip, mp);
1072                         }
1073
1074                         IRELE(ip);
1075
1076                         vnode_refed = B_FALSE;
1077                 }
1078
1079                 if (error) {
1080                         last_error = error;
1081                 }
1082
1083                 /*
1084                  * bail out if the filesystem is corrupted.
1085                  */
1086                 if (error == EFSCORRUPTED)  {
1087                         if (!mount_locked) {
1088                                 XFS_MOUNT_ILOCK(mp);
1089                                 IPOINTER_REMOVE(ip, mp);
1090                         }
1091                         XFS_MOUNT_IUNLOCK(mp);
1092                         ASSERT(ipointer_in == B_FALSE);
1093                         kmem_free(ipointer);
1094                         return XFS_ERROR(error);
1095                 }
1096
1097                 /* Let other threads have a chance at the mount lock
1098                  * if we have looped many times without dropping the
1099                  * lock.
1100                  */
1101                 if ((++preempt & XFS_PREEMPT_MASK) == 0) {
1102                         if (mount_locked) {
1103                                 IPOINTER_INSERT(ip, mp);
1104                         }
1105                 }
1106
1107                 if (mount_locked == B_FALSE) {
1108                         XFS_MOUNT_ILOCK(mp);
1109                         mount_locked = B_TRUE;
1110                         IPOINTER_REMOVE(ip, mp);
1111                         continue;
1112                 }
1113
1114                 ASSERT(ipointer_in == B_FALSE);
1115                 ip = ip->i_mnext;
1116
1117         } while (ip != mp->m_inodes);
1118
1119         XFS_MOUNT_IUNLOCK(mp);
1120
1121         ASSERT(ipointer_in == B_FALSE);
1122
1123         kmem_free(ipointer);
1124         return XFS_ERROR(last_error);
1125 }
1126
1127 /*
1128  * xfs sync routine for internal use
1129  *
1130  * This routine supports all of the flags defined for the generic vfs_sync
1131  * interface as explained above under xfs_sync.
1132  *
1133  */
1134 int
1135 xfs_syncsub(
1136         xfs_mount_t     *mp,
1137         int             flags,
1138         int             *bypassed)
1139 {
1140         int             error = 0;
1141         int             last_error = 0;
1142         uint            log_flags = XFS_LOG_FORCE;
1143         xfs_buf_t       *bp;
1144         xfs_buf_log_item_t      *bip;
1145
1146         /*
1147          * Sync out the log.  This ensures that the log is periodically
1148          * flushed even if there is not enough activity to fill it up.
1149          */
1150         if (flags & SYNC_WAIT)
1151                 log_flags |= XFS_LOG_SYNC;
1152
1153         xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1154
1155         if (flags & (SYNC_ATTR|SYNC_DELWRI)) {
1156                 if (flags & SYNC_BDFLUSH)
1157                         xfs_finish_reclaim_all(mp, 1);
1158                 else
1159                         error = xfs_sync_inodes(mp, flags, bypassed);
1160         }
1161
1162         /*
1163          * Flushing out dirty data above probably generated more
1164          * log activity, so if this isn't vfs_sync() then flush
1165          * the log again.
1166          */
1167         if (flags & SYNC_DELWRI) {
1168                 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1169         }
1170
1171         if (flags & SYNC_FSDATA) {
1172                 /*
1173                  * If this is vfs_sync() then only sync the superblock
1174                  * if we can lock it without sleeping and it is not pinned.
1175                  */
1176                 if (flags & SYNC_BDFLUSH) {
1177                         bp = xfs_getsb(mp, XFS_BUF_TRYLOCK);
1178                         if (bp != NULL) {
1179                                 bip = XFS_BUF_FSPRIVATE(bp,xfs_buf_log_item_t*);
1180                                 if ((bip != NULL) &&
1181                                     xfs_buf_item_dirty(bip)) {
1182                                         if (!(XFS_BUF_ISPINNED(bp))) {
1183                                                 XFS_BUF_ASYNC(bp);
1184                                                 error = xfs_bwrite(mp, bp);
1185                                         } else {
1186                                                 xfs_buf_relse(bp);
1187                                         }
1188                                 } else {
1189                                         xfs_buf_relse(bp);
1190                                 }
1191                         }
1192                 } else {
1193                         bp = xfs_getsb(mp, 0);
1194                         /*
1195                          * If the buffer is pinned then push on the log so
1196                          * we won't get stuck waiting in the write for
1197                          * someone, maybe ourselves, to flush the log.
1198                          * Even though we just pushed the log above, we
1199                          * did not have the superblock buffer locked at
1200                          * that point so it can become pinned in between
1201                          * there and here.
1202                          */
1203                         if (XFS_BUF_ISPINNED(bp))
1204                                 xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE);
1205                         if (flags & SYNC_WAIT)
1206                                 XFS_BUF_UNASYNC(bp);
1207                         else
1208                                 XFS_BUF_ASYNC(bp);
1209                         error = xfs_bwrite(mp, bp);
1210                 }
1211                 if (error) {
1212                         last_error = error;
1213                 }
1214         }
1215
1216         /*
1217          * Now check to see if the log needs a "dummy" transaction.
1218          */
1219         if (!(flags & SYNC_REMOUNT) && xfs_log_need_covered(mp)) {
1220                 xfs_trans_t *tp;
1221                 xfs_inode_t *ip;
1222
1223                 /*
1224                  * Put a dummy transaction in the log to tell
1225                  * recovery that all others are OK.
1226                  */
1227                 tp = xfs_trans_alloc(mp, XFS_TRANS_DUMMY1);
1228                 if ((error = xfs_trans_reserve(tp, 0,
1229                                 XFS_ICHANGE_LOG_RES(mp),
1230                                 0, 0, 0)))  {
1231                         xfs_trans_cancel(tp, 0);
1232                         return error;
1233                 }
1234
1235                 ip = mp->m_rootip;
1236                 xfs_ilock(ip, XFS_ILOCK_EXCL);
1237
1238                 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
1239                 xfs_trans_ihold(tp, ip);
1240                 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
1241                 error = xfs_trans_commit(tp, 0);
1242                 xfs_iunlock(ip, XFS_ILOCK_EXCL);
1243                 xfs_log_force(mp, (xfs_lsn_t)0, log_flags);
1244         }
1245
1246         /*
1247          * When shutting down, we need to insure that the AIL is pushed
1248          * to disk or the filesystem can appear corrupt from the PROM.
1249          */
1250         if ((flags & (SYNC_CLOSE|SYNC_WAIT)) == (SYNC_CLOSE|SYNC_WAIT)) {
1251                 XFS_bflush(mp->m_ddev_targp);
1252                 if (mp->m_rtdev_targp) {
1253                         XFS_bflush(mp->m_rtdev_targp);
1254                 }
1255         }
1256
1257         return XFS_ERROR(last_error);
1258 }