xfs: move declaration to header file
[safe/jmp/linux-2.6] / fs / xfs / xfs_mount.c
index 177976d..664961e 100644 (file)
@@ -45,7 +45,6 @@
 #include "xfs_fsops.h"
 #include "xfs_utils.h"
 
-STATIC int     xfs_mount_log_sb(xfs_mount_t *, __int64_t);
 STATIC int     xfs_uuid_mount(xfs_mount_t *);
 STATIC void    xfs_unmountfs_wait(xfs_mount_t *);
 
@@ -575,8 +574,7 @@ xfs_mount_common(xfs_mount_t *mp, xfs_sb_t *sbp)
        mp->m_sectbb_log = sbp->sb_sectlog - BBSHIFT;
        mp->m_agno_log = xfs_highbit32(sbp->sb_agcount - 1) + 1;
        mp->m_agino_log = sbp->sb_inopblog + sbp->sb_agblklog;
-       mp->m_litino = sbp->sb_inodesize -
-               ((uint)sizeof(xfs_dinode_core_t) + (uint)sizeof(xfs_agino_t));
+       mp->m_litino = sbp->sb_inodesize - sizeof(struct xfs_dinode);
        mp->m_blockmask = sbp->sb_blocksize - 1;
        mp->m_blockwsize = sbp->sb_blocksize >> XFS_WORDLOG;
        mp->m_blockwmask = mp->m_blockwsize - 1;
@@ -683,7 +681,7 @@ xfs_initialize_perag_data(xfs_mount_t *mp, xfs_agnumber_t agcount)
  * Update alignment values based on mount options and sb values
  */
 STATIC int
-xfs_update_alignment(xfs_mount_t *mp, __uint64_t *update_flags)
+xfs_update_alignment(xfs_mount_t *mp)
 {
        xfs_sb_t        *sbp = &(mp->m_sb);
 
@@ -737,11 +735,11 @@ xfs_update_alignment(xfs_mount_t *mp, __uint64_t *update_flags)
                if (xfs_sb_version_hasdalign(sbp)) {
                        if (sbp->sb_unit != mp->m_dalign) {
                                sbp->sb_unit = mp->m_dalign;
-                               *update_flags |= XFS_SB_UNIT;
+                               mp->m_update_flags |= XFS_SB_UNIT;
                        }
                        if (sbp->sb_width != mp->m_swidth) {
                                sbp->sb_width = mp->m_swidth;
-                               *update_flags |= XFS_SB_WIDTH;
+                               mp->m_update_flags |= XFS_SB_WIDTH;
                        }
                }
        } else if ((mp->m_flags & XFS_MOUNT_NOALIGN) != XFS_MOUNT_NOALIGN &&
@@ -888,8 +886,6 @@ xfs_check_sizes(xfs_mount_t *mp)
 }
 
 /*
- * xfs_mountfs
- *
  * 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
@@ -906,9 +902,7 @@ xfs_mountfs(
        xfs_sb_t        *sbp = &(mp->m_sb);
        xfs_inode_t     *rip;
        __uint64_t      resblks;
-       __int64_t       update_flags = 0LL;
        uint            quotamount, quotaflags;
-       int             uuid_mounted = 0;
        int             error = 0;
 
        xfs_mount_common(mp, sbp);
@@ -934,7 +928,7 @@ xfs_mountfs(
                        "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;
+               mp->m_update_flags |= XFS_SB_FEATURES2 | XFS_SB_BAD_FEATURES2;
 
                /*
                 * Re-check for ATTR2 in case it was found in bad_features2
@@ -948,11 +942,11 @@ xfs_mountfs(
        if (xfs_sb_version_hasattr2(&mp->m_sb) &&
           (mp->m_flags & XFS_MOUNT_NOATTR2)) {
                xfs_sb_version_removeattr2(&mp->m_sb);
-               update_flags |= XFS_SB_FEATURES2;
+               mp->m_update_flags |= XFS_SB_FEATURES2;
 
                /* update sb_versionnum for the clearing of the morebits */
                if (!sbp->sb_features2)
-                       update_flags |= XFS_SB_VERSIONNUM;
+                       mp->m_update_flags |= XFS_SB_VERSIONNUM;
        }
 
        /*
@@ -961,9 +955,9 @@ xfs_mountfs(
         * allocator alignment is within an ag, therefore ag has
         * to be aligned at stripe boundary.
         */
-       error = xfs_update_alignment(mp, &update_flags);
+       error = xfs_update_alignment(mp);
        if (error)
-               goto error1;
+               goto out;
 
        xfs_alloc_compute_maxlevels(mp);
        xfs_bmap_compute_maxlevels(mp, XFS_DATA_FORK);
@@ -980,12 +974,11 @@ xfs_mountfs(
         * since a single partition filesystem is identical to a single
         * partition volume/filesystem.
         */
-       if ((mp->m_flags & XFS_MOUNT_NOUUID) == 0) {
+       if (!(mp->m_flags & XFS_MOUNT_NOUUID)) {
                if (xfs_uuid_mount(mp)) {
                        error = XFS_ERROR(EINVAL);
-                       goto error1;
+                       goto out;
                }
-               uuid_mounted=1;
        }
 
        /*
@@ -1010,7 +1003,7 @@ xfs_mountfs(
         */
        error = xfs_check_sizes(mp);
        if (error)
-               goto error1;
+               goto out_remove_uuid;
 
        /*
         * Initialize realtime fields in the mount structure
@@ -1018,7 +1011,7 @@ xfs_mountfs(
        error = xfs_rtmount_init(mp);
        if (error) {
                cmn_err(CE_WARN, "XFS: RT mount failed");
-               goto error1;
+               goto out_remove_uuid;
        }
 
        /*
@@ -1048,26 +1041,26 @@ xfs_mountfs(
        mp->m_perag = kmem_zalloc(sbp->sb_agcount * sizeof(xfs_perag_t),
                                  KM_MAYFAIL);
        if (!mp->m_perag)
-               goto error1;
+               goto out_remove_uuid;
 
        mp->m_maxagi = xfs_initialize_perag(mp, sbp->sb_agcount);
 
+       if (!sbp->sb_logblocks) {
+               cmn_err(CE_WARN, "XFS: no log defined");
+               XFS_ERROR_REPORT("xfs_mountfs", XFS_ERRLEVEL_LOW, mp);
+               error = XFS_ERROR(EFSCORRUPTED);
+               goto out_free_perag;
+       }
+
        /*
         * log's mount-time initialization. Perform 1st part recovery if needed
         */
-       if (likely(sbp->sb_logblocks > 0)) {    /* check for volume case */
-               error = xfs_log_mount(mp, mp->m_logdev_targp,
-                                     XFS_FSB_TO_DADDR(mp, sbp->sb_logstart),
-                                     XFS_FSB_TO_BB(mp, sbp->sb_logblocks));
-               if (error) {
-                       cmn_err(CE_WARN, "XFS: log mount failed");
-                       goto error2;
-               }
-       } else {        /* No log has been defined */
-               cmn_err(CE_WARN, "XFS: no log defined");
-               XFS_ERROR_REPORT("xfs_mountfs_int(1)", XFS_ERRLEVEL_LOW, mp);
-               error = XFS_ERROR(EFSCORRUPTED);
-               goto error2;
+       error = xfs_log_mount(mp, mp->m_logdev_targp,
+                             XFS_FSB_TO_DADDR(mp, sbp->sb_logstart),
+                             XFS_FSB_TO_BB(mp, sbp->sb_logblocks));
+       if (error) {
+               cmn_err(CE_WARN, "XFS: log mount failed");
+               goto out_free_perag;
        }
 
        /*
@@ -1089,15 +1082,14 @@ xfs_mountfs(
         * If we are currently making the filesystem, the initialisation will
         * fail as the perag data is in an undefined state.
         */
-
        if (xfs_sb_version_haslazysbcount(&mp->m_sb) &&
            !XFS_LAST_UNMOUNT_WAS_CLEAN(mp) &&
             !mp->m_sb.sb_inprogress) {
                error = xfs_initialize_perag_data(mp, sbp->sb_agcount);
-               if (error) {
-                       goto error2;
-               }
+               if (error)
+                       goto out_free_perag;
        }
+
        /*
         * Get and sanity-check the root inode.
         * Save the pointer to it in the mount structure.
@@ -1105,7 +1097,7 @@ xfs_mountfs(
        error = xfs_iget(mp, NULL, sbp->sb_rootino, 0, XFS_ILOCK_EXCL, &rip, 0);
        if (error) {
                cmn_err(CE_WARN, "XFS: failed to read root inode");
-               goto error3;
+               goto out_log_dealloc;
        }
 
        ASSERT(rip != NULL);
@@ -1119,7 +1111,7 @@ xfs_mountfs(
                XFS_ERROR_REPORT("xfs_mountfs_int(2)", XFS_ERRLEVEL_LOW,
                                 mp);
                error = XFS_ERROR(EFSCORRUPTED);
-               goto error4;
+               goto out_rele_rip;
        }
        mp->m_rootip = rip;     /* save it */
 
@@ -1134,17 +1126,19 @@ xfs_mountfs(
                 * Free up the root inode.
                 */
                cmn_err(CE_WARN, "XFS: failed to read RT inodes");
-               goto error4;
+               goto out_rele_rip;
        }
 
        /*
-        * If fs is not mounted readonly, then update the superblock changes.
+        * If this is a read-only mount defer the superblock updates until
+        * the next remount into writeable mode.  Otherwise we would never
+        * perform the update e.g. for the root filesystem.
         */
-       if (update_flags && !(mp->m_flags & XFS_MOUNT_RDONLY)) {
-               error = xfs_mount_log_sb(mp, update_flags);
+       if (mp->m_update_flags && !(mp->m_flags & XFS_MOUNT_RDONLY)) {
+               error = xfs_mount_log_sb(mp, mp->m_update_flags);
                if (error) {
                        cmn_err(CE_WARN, "XFS: failed to write sb changes");
-                       goto error4;
+                       goto out_rtunmount;
                }
        }
 
@@ -1153,7 +1147,7 @@ xfs_mountfs(
         */
        error = XFS_QM_INIT(mp, &quotamount, &quotaflags);
        if (error)
-               goto error4;
+               goto out_rtunmount;
 
        /*
         * Finish recovering the file system.  This part needed to be
@@ -1163,7 +1157,7 @@ xfs_mountfs(
        error = xfs_log_mount_finish(mp);
        if (error) {
                cmn_err(CE_WARN, "XFS: log mount finish failed");
-               goto error4;
+               goto out_rtunmount;
        }
 
        /*
@@ -1171,7 +1165,7 @@ xfs_mountfs(
         */
        error = XFS_QM_MOUNT(mp, quotamount, quotaflags);
        if (error)
-               goto error4;
+               goto out_rtunmount;
 
        /*
         * Now we are mounted, reserve a small amount of unused space for
@@ -1195,18 +1189,18 @@ xfs_mountfs(
 
        return 0;
 
- error4:
-       /*
-        * Free up the root inode.
-        */
+ out_rtunmount:
+       xfs_rtunmount_inodes(mp);
+ out_rele_rip:
        IRELE(rip);
error3:
out_log_dealloc:
        xfs_log_unmount_dealloc(mp);
error2:
out_free_perag:
        xfs_free_perag(mp);
error1:
-       if (uuid_mounted)
out_remove_uuid:
+       if (!(mp->m_flags & XFS_MOUNT_NOUUID))
                uuid_table_remove(&mp->m_sb.sb_uuid);
+ out:
        return error;
 }
 
@@ -1221,6 +1215,13 @@ 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_rtunmount_inodes(mp);
        IRELE(mp->m_rootip);
 
        /*
@@ -1353,24 +1354,6 @@ xfs_log_sbcount(
        return error;
 }
 
-STATIC void
-xfs_mark_shared_ro(
-       xfs_mount_t     *mp,
-       xfs_buf_t       *bp)
-{
-       xfs_dsb_t       *sb = XFS_BUF_TO_SBP(bp);
-       __uint16_t      version;
-
-       if (!(sb->sb_flags & XFS_SBF_READONLY))
-               sb->sb_flags |= XFS_SBF_READONLY;
-
-       version = be16_to_cpu(sb->sb_versionnum);
-       if ((version & XFS_SB_VERSION_NUMBITS) != XFS_SB_VERSION_4 ||
-           !(version & XFS_SB_VERSION_SHAREDBIT))
-               version |= XFS_SB_VERSION_SHAREDBIT;
-       sb->sb_versionnum = cpu_to_be16(version);
-}
-
 int
 xfs_unmountfs_writesb(xfs_mount_t *mp)
 {
@@ -1386,12 +1369,6 @@ xfs_unmountfs_writesb(xfs_mount_t *mp)
 
                sbp = xfs_getsb(mp, 0);
 
-               /*
-                * mark shared-readonly if desired
-                */
-               if (mp->m_mk_sharedro)
-                       xfs_mark_shared_ro(mp, sbp);
-
                XFS_BUF_UNDONE(sbp);
                XFS_BUF_UNREAD(sbp);
                XFS_BUF_UNDELAYWRITE(sbp);
@@ -1403,8 +1380,6 @@ xfs_unmountfs_writesb(xfs_mount_t *mp)
                if (error)
                        xfs_ioerror_alert("xfs_unmountfs_writesb",
                                          mp, sbp, XFS_BUF_ADDR(sbp));
-               if (error && mp->m_mk_sharedro)
-                       xfs_fs_cmn_err(CE_ALERT, mp, "Superblock write error detected while unmounting.  Filesystem may not be marked shared readonly");
                xfs_buf_relse(sbp);
        }
        return error;
@@ -1837,7 +1812,7 @@ xfs_uuid_mount(
  * be altered by the mount options, as well as any potential sb_features2
  * fixup. Only the first superblock is updated.
  */
-STATIC int
+int
 xfs_mount_log_sb(
        xfs_mount_t     *mp,
        __int64_t       fields)