]> err.no Git - linux-2.6/blobdiff - fs/xfs/linux-2.6/xfs_super.c
Merge branch 'for-linus' of git://oss.sgi.com:8090/xfs/xfs-2.6
[linux-2.6] / fs / xfs / linux-2.6 / xfs_super.c
index 24bc0afb003cfca83adb04a03fd11af1ac67bc03..8cb63c60c04880e4395c3eace8c033de19d32038 100644 (file)
@@ -303,6 +303,14 @@ xfs_mountfs_check_barriers(xfs_mount_t *mp)
                return;
        }
 
+       if (mp->m_ddev_targp->bt_bdev->bd_disk->queue->ordered ==
+                                       QUEUE_ORDERED_NONE) {
+               xfs_fs_cmn_err(CE_NOTE, mp,
+                 "Disabling barriers, not supported by the underlying device");
+               mp->m_flags &= ~XFS_MOUNT_BARRIER;
+               return;
+       }
+
        if (xfs_readonly_buftarg(mp->m_ddev_targp)) {
                xfs_fs_cmn_err(CE_NOTE, mp,
                  "Disabling barriers, underlying device is readonly");
@@ -347,9 +355,8 @@ xfs_fs_destroy_inode(
 
 STATIC void
 xfs_fs_inode_init_once(
-       void                    *vnode,
        kmem_zone_t             *zonep,
-       unsigned long           flags)
+       void                    *vnode)
 {
        inode_init_once(vn_to_inode((bhv_vnode_t *)vnode));
 }
@@ -410,13 +417,12 @@ xfs_fs_write_inode(
                flags |= FLUSH_SYNC;
        }
        error = xfs_inode_flush(XFS_I(inode), flags);
-       if (error == EAGAIN) {
-               if (sync)
-                       error = xfs_inode_flush(XFS_I(inode),
-                                                      flags | FLUSH_LOG);
-               else
-                       error = 0;
-       }
+       /*
+        * if we failed to write out the inode then mark
+        * it dirty again so we'll try again later.
+        */
+       if (error)
+               mark_inode_dirty_sync(inode);
 
        return -error;
 }
@@ -457,9 +463,9 @@ xfs_fs_clear_inode(
  */
 STATIC void
 xfs_syncd_queue_work(
-       struct bhv_vfs  *vfs,
+       struct xfs_mount *mp,
        void            *data,
-       void            (*syncer)(bhv_vfs_t *, void *))
+       void            (*syncer)(struct xfs_mount *, void *))
 {
        struct bhv_vfs_sync_work *work;
 
@@ -467,11 +473,11 @@ xfs_syncd_queue_work(
        INIT_LIST_HEAD(&work->w_list);
        work->w_syncer = syncer;
        work->w_data = data;
-       work->w_vfs = vfs;
-       spin_lock(&vfs->vfs_sync_lock);
-       list_add_tail(&work->w_list, &vfs->vfs_sync_list);
-       spin_unlock(&vfs->vfs_sync_lock);
-       wake_up_process(vfs->vfs_sync_task);
+       work->w_mount = mp;
+       spin_lock(&mp->m_sync_lock);
+       list_add_tail(&work->w_list, &mp->m_sync_list);
+       spin_unlock(&mp->m_sync_lock);
+       wake_up_process(mp->m_sync_task);
 }
 
 /*
@@ -482,22 +488,22 @@ xfs_syncd_queue_work(
  */
 STATIC void
 xfs_flush_inode_work(
-       bhv_vfs_t       *vfs,
-       void            *inode)
+       struct xfs_mount *mp,
+       void            *arg)
 {
-       filemap_flush(((struct inode *)inode)->i_mapping);
-       iput((struct inode *)inode);
+       struct inode    *inode = arg;
+       filemap_flush(inode->i_mapping);
+       iput(inode);
 }
 
 void
 xfs_flush_inode(
        xfs_inode_t     *ip)
 {
-       struct inode    *inode = vn_to_inode(XFS_ITOV(ip));
-       struct bhv_vfs  *vfs = XFS_MTOVFS(ip->i_mount);
+       struct inode    *inode = ip->i_vnode;
 
        igrab(inode);
-       xfs_syncd_queue_work(vfs, inode, xfs_flush_inode_work);
+       xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inode_work);
        delay(msecs_to_jiffies(500));
 }
 
@@ -507,11 +513,12 @@ xfs_flush_inode(
  */
 STATIC void
 xfs_flush_device_work(
-       bhv_vfs_t       *vfs,
-       void            *inode)
+       struct xfs_mount *mp,
+       void            *arg)
 {
-       sync_blockdev(vfs->vfs_super->s_bdev);
-       iput((struct inode *)inode);
+       struct inode    *inode = arg;
+       sync_blockdev(mp->m_super->s_bdev);
+       iput(inode);
 }
 
 void
@@ -519,34 +526,33 @@ xfs_flush_device(
        xfs_inode_t     *ip)
 {
        struct inode    *inode = vn_to_inode(XFS_ITOV(ip));
-       struct bhv_vfs  *vfs = XFS_MTOVFS(ip->i_mount);
 
        igrab(inode);
-       xfs_syncd_queue_work(vfs, inode, xfs_flush_device_work);
+       xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_device_work);
        delay(msecs_to_jiffies(500));
        xfs_log_force(ip->i_mount, (xfs_lsn_t)0, XFS_LOG_FORCE|XFS_LOG_SYNC);
 }
 
 STATIC void
-vfs_sync_worker(
-       bhv_vfs_t       *vfsp,
+xfs_sync_worker(
+       struct xfs_mount *mp,
        void            *unused)
 {
        int             error;
 
-       if (!(vfsp->vfs_flag & VFS_RDONLY))
-               error = xfs_sync(XFS_VFSTOM(vfsp), SYNC_FSDATA | SYNC_BDFLUSH | \
-                                       SYNC_ATTR | SYNC_REFCACHE | SYNC_SUPER);
-       vfsp->vfs_sync_seq++;
-       wake_up(&vfsp->vfs_wait_single_sync_task);
+       if (!(mp->m_flags & XFS_MOUNT_RDONLY))
+               error = xfs_sync(mp, SYNC_FSDATA | SYNC_BDFLUSH | SYNC_ATTR |
+                                    SYNC_REFCACHE | SYNC_SUPER);
+       mp->m_sync_seq++;
+       wake_up(&mp->m_wait_single_sync_task);
 }
 
 STATIC int
 xfssyncd(
        void                    *arg)
 {
+       struct xfs_mount        *mp = arg;
        long                    timeleft;
-       bhv_vfs_t               *vfsp = (bhv_vfs_t *) arg;
        bhv_vfs_sync_work_t     *work, *n;
        LIST_HEAD               (tmp);
 
@@ -556,31 +562,31 @@ xfssyncd(
                timeleft = schedule_timeout_interruptible(timeleft);
                /* swsusp */
                try_to_freeze();
-               if (kthread_should_stop() && list_empty(&vfsp->vfs_sync_list))
+               if (kthread_should_stop() && list_empty(&mp->m_sync_list))
                        break;
 
-               spin_lock(&vfsp->vfs_sync_lock);
+               spin_lock(&mp->m_sync_lock);
                /*
                 * We can get woken by laptop mode, to do a sync -
                 * that's the (only!) case where the list would be
                 * empty with time remaining.
                 */
-               if (!timeleft || list_empty(&vfsp->vfs_sync_list)) {
+               if (!timeleft || list_empty(&mp->m_sync_list)) {
                        if (!timeleft)
                                timeleft = xfs_syncd_centisecs *
                                                        msecs_to_jiffies(10);
-                       INIT_LIST_HEAD(&vfsp->vfs_sync_work.w_list);
-                       list_add_tail(&vfsp->vfs_sync_work.w_list,
-                                       &vfsp->vfs_sync_list);
+                       INIT_LIST_HEAD(&mp->m_sync_work.w_list);
+                       list_add_tail(&mp->m_sync_work.w_list,
+                                       &mp->m_sync_list);
                }
-               list_for_each_entry_safe(work, n, &vfsp->vfs_sync_list, w_list)
+               list_for_each_entry_safe(work, n, &mp->m_sync_list, w_list)
                        list_move(&work->w_list, &tmp);
-               spin_unlock(&vfsp->vfs_sync_lock);
+               spin_unlock(&mp->m_sync_lock);
 
                list_for_each_entry_safe(work, n, &tmp, w_list) {
-                       (*work->w_syncer)(vfsp, work->w_data);
+                       (*work->w_syncer)(mp, work->w_data);
                        list_del(&work->w_list);
-                       if (work == &vfsp->vfs_sync_work)
+                       if (work == &mp->m_sync_work)
                                continue;
                        kmem_free(work, sizeof(struct bhv_vfs_sync_work));
                }
@@ -589,42 +595,19 @@ xfssyncd(
        return 0;
 }
 
-STATIC int
-xfs_fs_start_syncd(
-       bhv_vfs_t               *vfsp)
-{
-       vfsp->vfs_sync_work.w_syncer = vfs_sync_worker;
-       vfsp->vfs_sync_work.w_vfs = vfsp;
-       vfsp->vfs_sync_task = kthread_run(xfssyncd, vfsp, "xfssyncd");
-       if (IS_ERR(vfsp->vfs_sync_task))
-               return -PTR_ERR(vfsp->vfs_sync_task);
-       return 0;
-}
-
-STATIC void
-xfs_fs_stop_syncd(
-       bhv_vfs_t               *vfsp)
-{
-       kthread_stop(vfsp->vfs_sync_task);
-}
-
 STATIC void
 xfs_fs_put_super(
        struct super_block      *sb)
 {
-       bhv_vfs_t               *vfsp = vfs_from_sb(sb);
        struct xfs_mount        *mp = XFS_M(sb);
        int                     error;
 
-       xfs_fs_stop_syncd(vfsp);
+       kthread_stop(mp->m_sync_task);
+
        xfs_sync(mp, SYNC_ATTR | SYNC_DELWRI);
        error = xfs_unmount(mp, 0, NULL);
-       if (error) {
+       if (error)
                printk("XFS: unmount got error=%d\n", error);
-               printk("%s: vfs=0x%p left dangling!\n", __FUNCTION__, vfsp);
-       } else {
-               vfs_deallocate(vfsp);
-       }
 }
 
 STATIC void
@@ -641,12 +624,23 @@ xfs_fs_sync_super(
        struct super_block      *sb,
        int                     wait)
 {
-       bhv_vfs_t               *vfsp = vfs_from_sb(sb);
        struct xfs_mount        *mp = XFS_M(sb);
        int                     error;
        int                     flags;
 
-       if (unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
+       /*
+        * Treat a sync operation like a freeze.  This is to work
+        * around a race in sync_inodes() which works in two phases
+        * - an asynchronous flush, which can write out an inode
+        * without waiting for file size updates to complete, and a
+        * synchronous flush, which wont do anything because the
+        * async flush removed the inode's dirty flag.  Also
+        * sync_inodes() will not see any files that just have
+        * outstanding transactions to be flushed because we don't
+        * dirty the Linux inode until after the transaction I/O
+        * completes.
+        */
+       if (wait || unlikely(sb->s_frozen == SB_FREEZE_WRITE)) {
                /*
                 * First stage of freeze - no more writers will make progress
                 * now we are here, so we flush delwri and delalloc buffers
@@ -657,28 +651,28 @@ xfs_fs_sync_super(
                 */
                flags = SYNC_DATA_QUIESCE;
        } else
-               flags = SYNC_FSDATA | (wait ? SYNC_WAIT : 0);
+               flags = SYNC_FSDATA;
 
        error = xfs_sync(mp, flags);
        sb->s_dirt = 0;
 
        if (unlikely(laptop_mode)) {
-               int     prev_sync_seq = vfsp->vfs_sync_seq;
+               int     prev_sync_seq = mp->m_sync_seq;
 
                /*
                 * The disk must be active because we're syncing.
                 * We schedule xfssyncd now (now that the disk is
                 * active) instead of later (when it might not be).
                 */
-               wake_up_process(vfsp->vfs_sync_task);
+               wake_up_process(mp->m_sync_task);
                /*
                 * We have to wait for the sync iteration to complete.
                 * If we don't, the disk activity caused by the sync
                 * will come after the sync is completed, and that
                 * triggers another sync from laptop mode.
                 */
-               wait_event(vfsp->vfs_wait_single_sync_task,
-                               vfsp->vfs_sync_seq != prev_sync_seq);
+               wait_event(mp->m_wait_single_sync_task,
+                               mp->m_sync_seq != prev_sync_seq);
        }
 
        return -error;
@@ -783,15 +777,22 @@ xfs_fs_fill_super(
        int                     silent)
 {
        struct inode            *rootvp;
-       struct bhv_vfs          *vfsp = vfs_allocate(sb);
        struct xfs_mount        *mp = NULL;
        struct xfs_mount_args   *args = xfs_args_allocate(sb, silent);
        struct kstatfs          statvfs;
        int                     error;
 
        mp = xfs_mount_init();
-       mp->m_vfsp = vfsp;
-       vfsp->vfs_mount = mp;
+
+       INIT_LIST_HEAD(&mp->m_sync_list);
+       spin_lock_init(&mp->m_sync_lock);
+       init_waitqueue_head(&mp->m_wait_single_sync_task);
+
+       mp->m_super = sb;
+       sb->s_fs_info = mp;
+
+       if (sb->s_flags & MS_RDONLY)
+               mp->m_flags |= XFS_MOUNT_RDONLY;
 
        error = xfs_parseargs(mp, (char *)data, args, 0);
        if (error)
@@ -831,8 +832,15 @@ xfs_fs_fill_super(
                error = EINVAL;
                goto fail_vnrele;
        }
-       if ((error = xfs_fs_start_syncd(vfsp)))
+
+       mp->m_sync_work.w_syncer = xfs_sync_worker;
+       mp->m_sync_work.w_mount = mp;
+       mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd");
+       if (IS_ERR(mp->m_sync_task)) {
+               error = -PTR_ERR(mp->m_sync_task);
                goto fail_vnrele;
+       }
+
        vn_trace_exit(XFS_I(sb->s_root->d_inode), __FUNCTION__,
                        (inst_t *)__return_address);
 
@@ -851,7 +859,6 @@ fail_unmount:
        xfs_unmount(mp, 0, NULL);
 
 fail_vfsop:
-       vfs_deallocate(vfsp);
        kmem_free(args, sizeof(*args));
        return -error;
 }