Commit e6b96570 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: refactor xfs_log_force

Streamline the conditionals so that it is more obvious which specific case
form the top of the function comments is being handled.  Use gotos only
for early returns.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 656de4ff
...@@ -3318,99 +3318,81 @@ xfs_log_force( ...@@ -3318,99 +3318,81 @@ xfs_log_force(
xlog_cil_force(log); xlog_cil_force(log);
spin_lock(&log->l_icloglock); spin_lock(&log->l_icloglock);
iclog = log->l_iclog; iclog = log->l_iclog;
if (iclog->ic_state & XLOG_STATE_IOERROR) { if (iclog->ic_state & XLOG_STATE_IOERROR)
spin_unlock(&log->l_icloglock); goto out_error;
return -EIO;
}
/* If the head iclog is not active nor dirty, we just attach if (iclog->ic_state == XLOG_STATE_DIRTY ||
* ourselves to the head and go to sleep. (iclog->ic_state == XLOG_STATE_ACTIVE &&
*/ atomic_read(&iclog->ic_refcnt) == 0 && iclog->ic_offset == 0)) {
if (iclog->ic_state == XLOG_STATE_ACTIVE ||
iclog->ic_state == XLOG_STATE_DIRTY) {
/* /*
* If the head is dirty or (active and empty), then * If the head is dirty or (active and empty), then we need to
* we need to look at the previous iclog. If the previous * look at the previous iclog.
* iclog is active or dirty we are done. There is nothing *
* to sync out. Otherwise, we attach ourselves to the * If the previous iclog is active or dirty we are done. There
* is nothing to sync out. Otherwise, we attach ourselves to the
* previous iclog and go to sleep. * previous iclog and go to sleep.
*/ */
if (iclog->ic_state == XLOG_STATE_DIRTY || iclog = iclog->ic_prev;
(atomic_read(&iclog->ic_refcnt) == 0 if (iclog->ic_state == XLOG_STATE_ACTIVE ||
&& iclog->ic_offset == 0)) { iclog->ic_state == XLOG_STATE_DIRTY)
iclog = iclog->ic_prev; goto out_unlock;
if (iclog->ic_state == XLOG_STATE_ACTIVE || } else if (iclog->ic_state == XLOG_STATE_ACTIVE) {
iclog->ic_state == XLOG_STATE_DIRTY) if (atomic_read(&iclog->ic_refcnt) == 0) {
goto no_sleep; /*
else * We are the only one with access to this iclog.
goto maybe_sleep; *
} else { * Flush it out now. There should be a roundoff of zero
if (atomic_read(&iclog->ic_refcnt) == 0) { * to show that someone has already taken care of the
/* We are the only one with access to this * roundoff from the previous sync.
* iclog. Flush it out now. There should */
* be a roundoff of zero to show that someone atomic_inc(&iclog->ic_refcnt);
* has already taken care of the roundoff from lsn = be64_to_cpu(iclog->ic_header.h_lsn);
* the previous sync. xlog_state_switch_iclogs(log, iclog, 0);
*/ spin_unlock(&log->l_icloglock);
atomic_inc(&iclog->ic_refcnt);
lsn = be64_to_cpu(iclog->ic_header.h_lsn);
xlog_state_switch_iclogs(log, iclog, 0);
spin_unlock(&log->l_icloglock);
if (xlog_state_release_iclog(log, iclog))
return -EIO;
spin_lock(&log->l_icloglock); if (xlog_state_release_iclog(log, iclog))
if (be64_to_cpu(iclog->ic_header.h_lsn) == lsn && return -EIO;
iclog->ic_state != XLOG_STATE_DIRTY)
goto maybe_sleep;
else
goto no_sleep;
} else {
/* Someone else is writing to this iclog.
* Use its call to flush out the data. However,
* the other thread may not force out this LR,
* so we mark it WANT_SYNC.
*/
xlog_state_switch_iclogs(log, iclog, 0);
goto maybe_sleep;
}
}
}
/* By the time we come around again, the iclog could've been filled spin_lock(&log->l_icloglock);
* which would give it another lsn. If we have a new lsn, just if (be64_to_cpu(iclog->ic_header.h_lsn) != lsn ||
* return because the relevant data has been flushed. iclog->ic_state == XLOG_STATE_DIRTY)
*/ goto out_unlock;
maybe_sleep: } else {
if (flags & XFS_LOG_SYNC) { /*
/* * Someone else is writing to this iclog.
* We must check if we're shutting down here, before *
* we wait, while we're holding the l_icloglock. * Use its call to flush out the data. However, the
* Then we check again after waking up, in case our * other thread may not force out this LR, so we mark
* sleep was disturbed by a bad news. * it WANT_SYNC.
*/ */
if (iclog->ic_state & XLOG_STATE_IOERROR) { xlog_state_switch_iclogs(log, iclog, 0);
spin_unlock(&log->l_icloglock);
return -EIO;
} }
XFS_STATS_INC(mp, xs_log_force_sleep); } else {
xlog_wait(&iclog->ic_force_wait, &log->l_icloglock);
/* /*
* No need to grab the log lock here since we're * If the head iclog is not active nor dirty, we just attach
* only deciding whether or not to return EIO * ourselves to the head and go to sleep if necessary.
* and the memory read should be atomic.
*/ */
if (iclog->ic_state & XLOG_STATE_IOERROR) ;
return -EIO;
} else {
no_sleep:
spin_unlock(&log->l_icloglock);
} }
if (!(flags & XFS_LOG_SYNC))
goto out_unlock;
if (iclog->ic_state & XLOG_STATE_IOERROR)
goto out_error;
XFS_STATS_INC(mp, xs_log_force_sleep);
xlog_wait(&iclog->ic_force_wait, &log->l_icloglock);
if (iclog->ic_state & XLOG_STATE_IOERROR)
return -EIO;
return 0; return 0;
out_unlock:
spin_unlock(&log->l_icloglock);
return 0;
out_error:
spin_unlock(&log->l_icloglock);
return -EIO;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment