Skip to content

Commit

Permalink
xfs: cleanup error handling in xfs_mountfs:
Browse files Browse the repository at this point in the history
Clean up the error handling in xfs_mountfs.  Use readable goto label names,
simplify the uuid handling and other error conditions.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Felix Blyakher <felixb@sgi.com>
  • Loading branch information
Christoph Hellwig authored and Christoph Hellwig committed Feb 4, 2009
1 parent 3228149 commit f9057e3
Showing 1 changed file with 35 additions and 42 deletions.
77 changes: 35 additions & 42 deletions fs/xfs/xfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -886,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
Expand All @@ -905,7 +903,6 @@ xfs_mountfs(
xfs_inode_t *rip;
__uint64_t resblks;
uint quotamount, quotaflags;
int uuid_mounted = 0;
int error = 0;

xfs_mount_common(mp, sbp);
Expand Down Expand Up @@ -960,7 +957,7 @@ xfs_mountfs(
*/
error = xfs_update_alignment(mp);
if (error)
goto error1;
goto out;

xfs_alloc_compute_maxlevels(mp);
xfs_bmap_compute_maxlevels(mp, XFS_DATA_FORK);
Expand All @@ -977,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;
}

/*
Expand All @@ -1007,15 +1003,15 @@ xfs_mountfs(
*/
error = xfs_check_sizes(mp);
if (error)
goto error1;
goto out_remove_uuid;

/*
* Initialize realtime fields in the mount structure
*/
error = xfs_rtmount_init(mp);
if (error) {
cmn_err(CE_WARN, "XFS: RT mount failed");
goto error1;
goto out_remove_uuid;
}

/*
Expand Down Expand Up @@ -1045,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;
}

/*
Expand All @@ -1086,23 +1082,22 @@ 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.
*/
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);
Expand All @@ -1116,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 */

Expand All @@ -1131,7 +1126,7 @@ xfs_mountfs(
* Free up the root inode.
*/
cmn_err(CE_WARN, "XFS: failed to read RT inodes");
goto error4;
goto out_rele_rip;
}

/*
Expand All @@ -1143,7 +1138,7 @@ xfs_mountfs(
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_rele_rip;
}
}

Expand All @@ -1152,7 +1147,7 @@ xfs_mountfs(
*/
error = XFS_QM_INIT(mp, &quotamount, &quotaflags);
if (error)
goto error4;
goto out_rele_rip;

/*
* Finish recovering the file system. This part needed to be
Expand All @@ -1162,15 +1157,15 @@ xfs_mountfs(
error = xfs_log_mount_finish(mp);
if (error) {
cmn_err(CE_WARN, "XFS: log mount finish failed");
goto error4;
goto out_rele_rip;
}

/*
* Complete the quota initialisation, post-log-replay component.
*/
error = XFS_QM_MOUNT(mp, quotamount, quotaflags);
if (error)
goto error4;
goto out_rele_rip;

/*
* Now we are mounted, reserve a small amount of unused space for
Expand All @@ -1194,18 +1189,16 @@ xfs_mountfs(

return 0;

error4:
/*
* Free up the root inode.
*/
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;
}

Expand Down

0 comments on commit f9057e3

Please sign in to comment.