]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/xfs_mount.c
[XFS] Add xfs_icsb_sync_counters_locked for when m_sb_lock already held
[linux-2.6-omap-h63xx.git] / fs / xfs / xfs_mount.c
index 99bab1e372b1ce03e7932781a446577c00c8ce04..a2fad07fd844045cdd30611c1362ee707df33c53 100644 (file)
@@ -43,8 +43,9 @@
 #include "xfs_rw.h"
 #include "xfs_quota.h"
 #include "xfs_fsops.h"
+#include "xfs_utils.h"
 
-STATIC void    xfs_mount_log_sbunit(xfs_mount_t *, __int64_t);
+STATIC int     xfs_mount_log_sb(xfs_mount_t *, __int64_t);
 STATIC int     xfs_uuid_mount(xfs_mount_t *);
 STATIC void    xfs_uuid_unmount(xfs_mount_t *mp);
 STATIC void    xfs_unmountfs_wait(xfs_mount_t *);
@@ -54,16 +55,14 @@ STATIC void xfs_unmountfs_wait(xfs_mount_t *);
 STATIC void    xfs_icsb_destroy_counters(xfs_mount_t *);
 STATIC void    xfs_icsb_balance_counter(xfs_mount_t *, xfs_sb_field_t,
                                                int, int);
-STATIC void    xfs_icsb_sync_counters(xfs_mount_t *);
 STATIC int     xfs_icsb_modify_counters(xfs_mount_t *, xfs_sb_field_t,
                                                int64_t, int);
-STATIC int     xfs_icsb_disable_counter(xfs_mount_t *, xfs_sb_field_t);
+STATIC void    xfs_icsb_disable_counter(xfs_mount_t *, xfs_sb_field_t);
 
 #else
 
 #define xfs_icsb_destroy_counters(mp)                  do { } while (0)
 #define xfs_icsb_balance_counter(mp, a, b, c)          do { } while (0)
-#define xfs_icsb_sync_counters(mp)                     do { } while (0)
 #define xfs_icsb_modify_counters(mp, a, b, c)          do { } while (0)
 
 #endif
@@ -119,6 +118,7 @@ static const struct {
     { offsetof(xfs_sb_t, sb_logsectsize),0 },
     { offsetof(xfs_sb_t, sb_logsunit),  0 },
     { offsetof(xfs_sb_t, sb_features2),         0 },
+    { offsetof(xfs_sb_t, sb_bad_features2), 0 },
     { sizeof(xfs_sb_t),                         0 }
 };
 
@@ -449,6 +449,7 @@ xfs_sb_from_disk(
        to->sb_logsectsize = be16_to_cpu(from->sb_logsectsize);
        to->sb_logsunit = be32_to_cpu(from->sb_logsunit);
        to->sb_features2 = be32_to_cpu(from->sb_features2);
+       to->sb_bad_features2 = be32_to_cpu(from->sb_bad_features2);
 }
 
 /*
@@ -954,7 +955,6 @@ xfs_mountfs(
 {
        xfs_sb_t        *sbp = &(mp->m_sb);
        xfs_inode_t     *rip;
-       bhv_vnode_t     *rvp = NULL;
        __uint64_t      resblks;
        __int64_t       update_flags = 0LL;
        uint            quotamount, quotaflags;
@@ -962,13 +962,40 @@ xfs_mountfs(
        int             uuid_mounted = 0;
        int             error = 0;
 
-       if (mp->m_sb_bp == NULL) {
-               error = xfs_readsb(mp, mfsi_flags);
-               if (error)
-                       return error;
-       }
        xfs_mount_common(mp, sbp);
 
+       /*
+        * Check for a mismatched features2 values.  Older kernels
+        * read & wrote into the wrong sb offset for sb_features2
+        * on some platforms due to xfs_sb_t not being 64bit size aligned
+        * when sb_features2 was added, which made older superblock
+        * reading/writing routines swap it as a 64-bit value.
+        *
+        * For backwards compatibility, we make both slots equal.
+        *
+        * If we detect a mismatched field, we OR the set bits into the
+        * existing features2 field in case it has already been modified; we
+        * don't want to lose any features.  We then update the bad location
+        * with the ORed value so that older kernels will see any features2
+        * flags, and mark the two fields as needing updates once the
+        * transaction subsystem is online.
+        */
+       if (xfs_sb_has_mismatched_features2(sbp)) {
+               cmn_err(CE_WARN,
+                       "XFS: correcting sb_features alignment problem");
+               sbp->sb_features2 |= sbp->sb_bad_features2;
+               sbp->sb_bad_features2 = sbp->sb_features2;
+               update_flags |= XFS_SB_FEATURES2 | XFS_SB_BAD_FEATURES2;
+
+               /*
+                * Re-check for ATTR2 in case it was found in bad_features2
+                * slot.
+                */
+               if (xfs_sb_version_hasattr2(&mp->m_sb))
+                       mp->m_flags |= XFS_MOUNT_ATTR2;
+
+       }
+
        /*
         * Check if sb_agblocks is aligned at stripe boundary
         * If sb_agblocks is NOT aligned turn off m_dalign since
@@ -1129,7 +1156,6 @@ xfs_mountfs(
        }
 
        ASSERT(rip != NULL);
-       rvp = XFS_ITOV(rip);
 
        if (unlikely((rip->i_d.di_mode & S_IFMT) != S_IFDIR)) {
                cmn_err(CE_WARN, "XFS: corrupted root inode");
@@ -1159,11 +1185,15 @@ xfs_mountfs(
        }
 
        /*
-        * If fs is not mounted readonly, then update the superblock
-        * unit and width changes.
+        * If fs is not mounted readonly, then update the superblock changes.
         */
-       if (update_flags && !(mp->m_flags & XFS_MOUNT_RDONLY))
-               xfs_mount_log_sbunit(mp, update_flags);
+       if (update_flags && !(mp->m_flags & XFS_MOUNT_RDONLY)) {
+               error = xfs_mount_log_sb(mp, update_flags);
+               if (error) {
+                       cmn_err(CE_WARN, "XFS: failed to write sb changes");
+                       goto error4;
+               }
+       }
 
        /*
         * Initialise the XFS quota management subsystem for this mount
@@ -1200,12 +1230,15 @@ xfs_mountfs(
         *
         * We default to 5% or 1024 fsbs of space reserved, whichever is smaller.
         * This may drive us straight to ENOSPC on mount, but that implies
-        * we were already there on the last unmount.
+        * we were already there on the last unmount. Warn if this occurs.
         */
        resblks = mp->m_sb.sb_dblocks;
        do_div(resblks, 20);
        resblks = min_t(__uint64_t, resblks, 1024);
-       xfs_reserve_blocks(mp, &resblks, NULL);
+       error = xfs_reserve_blocks(mp, &resblks, NULL);
+       if (error)
+               cmn_err(CE_WARN, "XFS: Unable to allocate reserve blocks. "
+                               "Continuing without a reserve pool.");
 
        return 0;
 
@@ -1213,7 +1246,7 @@ xfs_mountfs(
        /*
         * Free up the root inode.
         */
-       VN_RELE(rvp);
+       IRELE(rip);
  error3:
        xfs_log_unmount_dealloc(mp);
  error2:
@@ -1241,6 +1274,7 @@ int
 xfs_unmountfs(xfs_mount_t *mp, struct cred *cr)
 {
        __uint64_t      resblks;
+       int             error = 0;
 
        /*
         * We can potentially deadlock here if we have an inode cluster
@@ -1284,9 +1318,15 @@ xfs_unmountfs(xfs_mount_t *mp, struct cred *cr)
         * value does not matter....
         */
        resblks = 0;
-       xfs_reserve_blocks(mp, &resblks, NULL);
+       error = xfs_reserve_blocks(mp, &resblks, NULL);
+       if (error)
+               cmn_err(CE_WARN, "XFS: Unable to free reserved block pool. "
+                               "Freespace may not be correct on next mount.");
 
-       xfs_log_sbcount(mp, 1);
+       error = xfs_log_sbcount(mp, 1);
+       if (error)
+               cmn_err(CE_WARN, "XFS: Unable to update superblock counters. "
+                               "Freespace may not be correct on next mount.");
        xfs_unmountfs_writesb(mp);
        xfs_unmountfs_wait(mp);                 /* wait for async bufs */
        xfs_log_unmount(mp);                    /* Done! No more fs ops. */
@@ -1358,7 +1398,7 @@ xfs_log_sbcount(
        if (!xfs_fs_writable(mp))
                return 0;
 
-       xfs_icsb_sync_counters(mp);
+       xfs_icsb_sync_counters(mp, 0);
 
        /*
         * we don't need to do this if we are updating the superblock
@@ -1378,9 +1418,8 @@ xfs_log_sbcount(
        xfs_mod_sb(tp, XFS_SB_IFREE | XFS_SB_ICOUNT | XFS_SB_FDBLOCKS);
        if (sync)
                xfs_trans_set_sync(tp);
-       xfs_trans_commit(tp, 0);
-
-       return 0;
+       error = xfs_trans_commit(tp, 0);
+       return error;
 }
 
 STATIC void
@@ -1429,7 +1468,6 @@ xfs_unmountfs_writesb(xfs_mount_t *mp)
                XFS_BUF_UNASYNC(sbp);
                ASSERT(XFS_BUF_TARGET(sbp) == mp->m_ddev_targp);
                xfsbdstrat(mp, sbp);
-               /* Nevermind errors we might get here. */
                error = xfs_iowait(sbp);
                if (error)
                        xfs_ioerror_alert("xfs_unmountfs_writesb",
@@ -1875,25 +1913,30 @@ xfs_uuid_unmount(
 
 /*
  * Used to log changes to the superblock unit and width fields which could
- * be altered by the mount options. Only the first superblock is updated.
+ * be altered by the mount options, as well as any potential sb_features2
+ * fixup. Only the first superblock is updated.
  */
-STATIC void
-xfs_mount_log_sbunit(
+STATIC int
+xfs_mount_log_sb(
        xfs_mount_t     *mp,
        __int64_t       fields)
 {
        xfs_trans_t     *tp;
+       int             error;
 
-       ASSERT(fields & (XFS_SB_UNIT|XFS_SB_WIDTH|XFS_SB_UUID));
+       ASSERT(fields & (XFS_SB_UNIT | XFS_SB_WIDTH | XFS_SB_UUID |
+                        XFS_SB_FEATURES2 | XFS_SB_BAD_FEATURES2));
 
        tp = xfs_trans_alloc(mp, XFS_TRANS_SB_UNIT);
-       if (xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0,
-                               XFS_DEFAULT_LOG_COUNT)) {
+       error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0,
+                               XFS_DEFAULT_LOG_COUNT);
+       if (error) {
                xfs_trans_cancel(tp, 0);
-               return;
+               return error;
        }
        xfs_mod_sb(tp, fields);
-       xfs_trans_commit(tp, 0);
+       error = xfs_trans_commit(tp, 0);
+       return error;
 }
 
 
@@ -2154,7 +2197,7 @@ xfs_icsb_counter_disabled(
        return test_bit(field, &mp->m_icsb_counters);
 }
 
-STATIC int
+STATIC void
 xfs_icsb_disable_counter(
        xfs_mount_t     *mp,
        xfs_sb_field_t  field)
@@ -2172,7 +2215,7 @@ xfs_icsb_disable_counter(
         * the m_icsb_mutex.
         */
        if (xfs_icsb_counter_disabled(mp, field))
-               return 0;
+               return;
 
        xfs_icsb_lock_all_counters(mp);
        if (!test_and_set_bit(field, &mp->m_icsb_counters)) {
@@ -2195,8 +2238,6 @@ xfs_icsb_disable_counter(
        }
 
        xfs_icsb_unlock_all_counters(mp);
-
-       return 0;
 }
 
 STATIC void
@@ -2235,38 +2276,33 @@ xfs_icsb_enable_counter(
 }
 
 void
-xfs_icsb_sync_counters_flags(
+xfs_icsb_sync_counters_locked(
        xfs_mount_t     *mp,
        int             flags)
 {
        xfs_icsb_cnts_t cnt;
 
-       /* Pass 1: lock all counters */
-       if ((flags & XFS_ICSB_SB_LOCKED) == 0)
-               spin_lock(&mp->m_sb_lock);
-
        xfs_icsb_count(mp, &cnt, flags);
 
-       /* Step 3: update mp->m_sb fields */
        if (!xfs_icsb_counter_disabled(mp, XFS_SBS_ICOUNT))
                mp->m_sb.sb_icount = cnt.icsb_icount;
        if (!xfs_icsb_counter_disabled(mp, XFS_SBS_IFREE))
                mp->m_sb.sb_ifree = cnt.icsb_ifree;
        if (!xfs_icsb_counter_disabled(mp, XFS_SBS_FDBLOCKS))
                mp->m_sb.sb_fdblocks = cnt.icsb_fdblocks;
-
-       if ((flags & XFS_ICSB_SB_LOCKED) == 0)
-               spin_unlock(&mp->m_sb_lock);
 }
 
 /*
  * Accurate update of per-cpu counters to incore superblock
  */
-STATIC void
+void
 xfs_icsb_sync_counters(
-       xfs_mount_t     *mp)
+       xfs_mount_t     *mp,
+       int             flags)
 {
-       xfs_icsb_sync_counters_flags(mp, 0);
+       spin_lock(&mp->m_sb_lock);
+       xfs_icsb_sync_counters_locked(mp, flags);
+       spin_unlock(&mp->m_sb_lock);
 }
 
 /*