compat_ioctl: Supress "unknown cmd" message on serial /dev/console
[safe/jmp/linux-2.6] / fs / xfs / xfs_mount.c
index 65a9972..eb403b4 100644 (file)
@@ -44,6 +44,8 @@
 #include "xfs_quota.h"
 #include "xfs_fsops.h"
 #include "xfs_utils.h"
+#include "xfs_trace.h"
+
 
 STATIC void    xfs_unmountfs_wait(xfs_mount_t *);
 
@@ -583,8 +585,8 @@ xfs_readsb(xfs_mount_t *mp, int flags)
        sector_size = xfs_getsize_buftarg(mp->m_ddev_targp);
        extra_flags = XFS_BUF_LOCK | XFS_BUF_MANAGE | XFS_BUF_MAPPED;
 
-       bp = xfs_buf_read_flags(mp->m_ddev_targp, XFS_SB_DADDR,
-                               BTOBB(sector_size), extra_flags);
+       bp = xfs_buf_read(mp->m_ddev_targp, XFS_SB_DADDR, BTOBB(sector_size),
+                         extra_flags);
        if (!bp || XFS_BUF_ISERROR(bp)) {
                xfs_fs_mount_cmn_err(flags, "SB read failed");
                error = bp ? XFS_BUF_GETERROR(bp) : ENOMEM;
@@ -624,8 +626,8 @@ xfs_readsb(xfs_mount_t *mp, int flags)
                XFS_BUF_UNMANAGE(bp);
                xfs_buf_relse(bp);
                sector_size = mp->m_sb.sb_sectsize;
-               bp = xfs_buf_read_flags(mp->m_ddev_targp, XFS_SB_DADDR,
-                                       BTOBB(sector_size), extra_flags);
+               bp = xfs_buf_read(mp->m_ddev_targp, XFS_SB_DADDR,
+                                 BTOBB(sector_size), extra_flags);
                if (!bp || XFS_BUF_ISERROR(bp)) {
                        xfs_fs_mount_cmn_err(flags, "SB re-read failed");
                        error = bp ? XFS_BUF_GETERROR(bp) : ENOMEM;
@@ -960,6 +962,53 @@ xfs_check_sizes(xfs_mount_t *mp)
 }
 
 /*
+ * Clear the quotaflags in memory and in the superblock.
+ */
+int
+xfs_mount_reset_sbqflags(
+       struct xfs_mount        *mp)
+{
+       int                     error;
+       struct xfs_trans        *tp;
+
+       mp->m_qflags = 0;
+
+       /*
+        * It is OK to look at sb_qflags here in mount path,
+        * without m_sb_lock.
+        */
+       if (mp->m_sb.sb_qflags == 0)
+               return 0;
+       spin_lock(&mp->m_sb_lock);
+       mp->m_sb.sb_qflags = 0;
+       spin_unlock(&mp->m_sb_lock);
+
+       /*
+        * If the fs is readonly, let the incore superblock run
+        * with quotas off but don't flush the update out to disk
+        */
+       if (mp->m_flags & XFS_MOUNT_RDONLY)
+               return 0;
+
+#ifdef QUOTADEBUG
+       xfs_fs_cmn_err(CE_NOTE, mp, "Writing superblock quota changes");
+#endif
+
+       tp = xfs_trans_alloc(mp, XFS_TRANS_QM_SBCHANGE);
+       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);
+               xfs_fs_cmn_err(CE_ALERT, mp,
+                       "xfs_mount_reset_sbqflags: Superblock update failed!");
+               return error;
+       }
+
+       xfs_mod_sb(tp, XFS_SB_QFLAGS);
+       return xfs_trans_commit(tp, 0);
+}
+
+/*
  * This function does the following on an initial mount of a file system:
  *     - reads the superblock from disk and init the mount struct
  *     - if we're a 32-bit kernel, do a size check on the superblock
@@ -976,7 +1025,8 @@ xfs_mountfs(
        xfs_sb_t        *sbp = &(mp->m_sb);
        xfs_inode_t     *rip;
        __uint64_t      resblks;
-       uint            quotamount, quotaflags;
+       uint            quotamount = 0;
+       uint            quotaflags = 0;
        int             error = 0;
 
        xfs_mount_common(mp, sbp);
@@ -1210,9 +1260,28 @@ xfs_mountfs(
        /*
         * Initialise the XFS quota management subsystem for this mount
         */
-       error = XFS_QM_INIT(mp, &quotamount, &quotaflags);
-       if (error)
-               goto out_rtunmount;
+       if (XFS_IS_QUOTA_RUNNING(mp)) {
+               error = xfs_qm_newmount(mp, &quotamount, &quotaflags);
+               if (error)
+                       goto out_rtunmount;
+       } else {
+               ASSERT(!XFS_IS_QUOTA_ON(mp));
+
+               /*
+                * If a file system had quotas running earlier, but decided to
+                * mount without -o uquota/pquota/gquota options, revoke the
+                * quotachecked license.
+                */
+               if (mp->m_sb.sb_qflags & XFS_ALL_QUOTA_ACCT) {
+                       cmn_err(CE_NOTE,
+                               "XFS: resetting qflags for filesystem %s",
+                               mp->m_fsname);
+
+                       error = xfs_mount_reset_sbqflags(mp);
+                       if (error)
+                               return error;
+               }
+       }
 
        /*
         * Finish recovering the file system.  This part needed to be
@@ -1228,9 +1297,19 @@ xfs_mountfs(
        /*
         * Complete the quota initialisation, post-log-replay component.
         */
-       error = XFS_QM_MOUNT(mp, quotamount, quotaflags);
-       if (error)
-               goto out_rtunmount;
+       if (quotamount) {
+               ASSERT(mp->m_qflags == 0);
+               mp->m_qflags = quotaflags;
+
+               xfs_qm_mount_quotas(mp);
+       }
+
+#if defined(DEBUG) && defined(XFS_LOUD_RECOVERY)
+       if (XFS_IS_QUOTA_ON(mp))
+               xfs_fs_cmn_err(CE_NOTE, mp, "Disk quotas turned on");
+       else
+               xfs_fs_cmn_err(CE_NOTE, mp, "Disk quotas not turned on");
+#endif
 
        /*
         * Now we are mounted, reserve a small amount of unused space for
@@ -1279,12 +1358,7 @@ xfs_unmountfs(
        __uint64_t              resblks;
        int                     error;
 
-       /*
-        * Release dquot that rootinode, rbmino and rsumino might be holding,
-        * and release the quota inodes.
-        */
-       XFS_QM_UNMOUNT(mp);
-
+       xfs_qm_unmount_quotas(mp);
        xfs_rtunmount_inodes(mp);
        IRELE(mp->m_rootip);
 
@@ -1299,12 +1373,9 @@ xfs_unmountfs(
         * need to force the log first.
         */
        xfs_log_force(mp, (xfs_lsn_t)0, XFS_LOG_FORCE | XFS_LOG_SYNC);
-       xfs_reclaim_inodes(mp, 0, XFS_IFLUSH_ASYNC);
+       xfs_reclaim_inodes(mp, XFS_IFLUSH_ASYNC);
 
-       XFS_QM_DQPURGEALL(mp, XFS_QMOPT_QUOTALL | XFS_QMOPT_UMOUNTING);
-
-       if (mp->m_quotainfo)
-               XFS_QM_DONE(mp);
+       xfs_qm_unmount(mp);
 
        /*
         * Flush out the log synchronously so that we know for sure
@@ -1402,7 +1473,7 @@ xfs_log_sbcount(
        if (!xfs_sb_version_haslazysbcount(&mp->m_sb))
                return 0;
 
-       tp = _xfs_trans_alloc(mp, XFS_TRANS_SB_COUNT);
+       tp = _xfs_trans_alloc(mp, XFS_TRANS_SB_COUNT, KM_SLEEP);
        error = xfs_trans_reserve(tp, 0, mp->m_sb.sb_sectsize + 128, 0, 0,
                                        XFS_DEFAULT_LOG_COUNT);
        if (error) {
@@ -1499,7 +1570,7 @@ xfs_mod_sb(xfs_trans_t *tp, __int64_t fields)
  *
  * The m_sb_lock must be held when this routine is called.
  */
-int
+STATIC int
 xfs_mod_incore_sb_unlocked(
        xfs_mount_t     *mp,
        xfs_sb_field_t  field,
@@ -2054,7 +2125,7 @@ xfs_icsb_destroy_counters(
        mutex_destroy(&mp->m_icsb_mutex);
 }
 
-STATIC_INLINE void
+STATIC void
 xfs_icsb_lock_cntr(
        xfs_icsb_cnts_t *icsbp)
 {
@@ -2063,7 +2134,7 @@ xfs_icsb_lock_cntr(
        }
 }
 
-STATIC_INLINE void
+STATIC void
 xfs_icsb_unlock_cntr(
        xfs_icsb_cnts_t *icsbp)
 {
@@ -2071,7 +2142,7 @@ xfs_icsb_unlock_cntr(
 }
 
 
-STATIC_INLINE void
+STATIC void
 xfs_icsb_lock_all_counters(
        xfs_mount_t     *mp)
 {
@@ -2084,7 +2155,7 @@ xfs_icsb_lock_all_counters(
        }
 }
 
-STATIC_INLINE void
+STATIC void
 xfs_icsb_unlock_all_counters(
        xfs_mount_t     *mp)
 {
@@ -2320,12 +2391,12 @@ xfs_icsb_modify_counters(
 {
        xfs_icsb_cnts_t *icsbp;
        long long       lcounter;       /* long counter for 64 bit fields */
-       int             cpu, ret = 0;
+       int             ret = 0;
 
        might_sleep();
 again:
-       cpu = get_cpu();
-       icsbp = (xfs_icsb_cnts_t *)per_cpu_ptr(mp->m_sb_cnts, cpu);
+       preempt_disable();
+       icsbp = this_cpu_ptr(mp->m_sb_cnts);
 
        /*
         * if the counter is disabled, go to slow path
@@ -2369,11 +2440,11 @@ again:
                break;
        }
        xfs_icsb_unlock_cntr(icsbp);
-       put_cpu();
+       preempt_enable();
        return 0;
 
 slow_path:
-       put_cpu();
+       preempt_enable();
 
        /*
         * serialise with a mutex so we don't burn lots of cpu on
@@ -2421,7 +2492,7 @@ slow_path:
 
 balance_counter:
        xfs_icsb_unlock_cntr(icsbp);
-       put_cpu();
+       preempt_enable();
 
        /*
         * We may have multiple threads here if multiple per-cpu