[PATCH 10/11] ocfs2: Less function calls in ocfs2_replay_journal() after error detection

From: SF Markus Elfring
Date: Sun Jul 05 2015 - 09:40:56 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 5 Jul 2015 12:23:37 +0200

The functions brelse() and iput() were called in one case by the
ocfs2_replay_journal() function during error handling even
if the passed variables contained still a pointer which did not refer
to valid data.

* Return directly if a call of the ocfs2_read_journal_inode() function
failed at the beginning.

* Rename jump labels according to the Linux coding style convention.

* Delete the variable "got_lock" then.

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
fs/ocfs2/journal.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index c343e36..7bb50f4 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -1544,7 +1544,6 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
int slot_num)
{
int status;
- int got_lock = 0;
unsigned int flags;
struct inode *inode = NULL;
struct ocfs2_dinode *fe;
@@ -1555,7 +1554,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
status = ocfs2_read_journal_inode(osb, slot_num, &bh, &inode);
if (status) {
mlog_errno(status);
- goto done;
+ return status;
}

fe = (struct ocfs2_dinode *)bh->b_data;
@@ -1576,7 +1575,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
osb->slot_recovery_generations[slot_num], slot_reco_gen);
osb->slot_recovery_generations[slot_num] = slot_reco_gen;
status = -EBUSY;
- goto done;
+ goto put_inode;
}

/* Continue with recovery as the journal has not yet been recovered */
@@ -1586,9 +1585,8 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
trace_ocfs2_replay_journal_lock_err(status);
if (status != -ERESTARTSYS)
mlog(ML_ERROR, "Could not lock journal!\n");
- goto done;
+ goto put_inode;
}
- got_lock = 1;

fe = (struct ocfs2_dinode *) bh->b_data;

@@ -1599,7 +1597,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
trace_ocfs2_replay_journal_skip(node_num);
/* Refresh recovery generation for the slot */
osb->slot_recovery_generations[slot_num] = slot_reco_gen;
- goto done;
+ goto unlock_inode;
}

/* we need to run complete recovery for offline orphan slots */
@@ -1614,14 +1612,14 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
status = ocfs2_force_read_journal(inode);
if (status < 0) {
mlog_errno(status);
- goto done;
+ goto unlock_inode;
}

journal = jbd2_journal_init_inode(inode);
if (journal == NULL) {
mlog(ML_ERROR, "Linux journal layer error\n");
status = -EIO;
- goto done;
+ goto unlock_inode;
}

status = jbd2_journal_load(journal);
@@ -1630,7 +1628,7 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
if (!igrab(inode))
BUG();
jbd2_journal_destroy(journal);
- goto done;
+ goto unlock_inode;
}

ocfs2_clear_journal_error(osb->sb, journal, slot_num);
@@ -1665,11 +1663,10 @@ static int ocfs2_replay_journal(struct ocfs2_super *osb,
printk(KERN_NOTICE "ocfs2: End replay journal (node %d, slot %d) on "\
"device (%u,%u)\n", node_num, slot_num, MAJOR(osb->sb->s_dev),
MINOR(osb->sb->s_dev));
-done:
+unlock_inode:
/* drop the lock on this nodes journal */
- if (got_lock)
- ocfs2_inode_unlock(inode, 1);
-
+ ocfs2_inode_unlock(inode, 1);
+put_inode:
iput(inode);
brelse(bh);

--
2.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/