From 5c83baf549ed243b81369640e7a56148df94443c Mon Sep 17 00:00:00 2001 From: Dave Kleikamp <shaggy@austin.ibm.com> Date: Fri, 7 May 2004 06:05:39 -0500 Subject: [PATCH] JFS: [CHECKER] More robust error recovery in add_index If an error is encountered in add_index, it now leaves the index table in a consistent state. Since the return value is stored in the directory entry regardless of add_index's success, return zero instead of -EPERM (which made no sense). --- fs/jfs/jfs_dtree.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c index fba3eb3c5767..1b49bbca6ab2 100644 --- a/fs/jfs/jfs_dtree.c +++ b/fs/jfs/jfs_dtree.c @@ -342,7 +342,6 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot) struct metapage *mp; s64 offset; uint page_offset; - int rc; struct tlock *tlck; s64 xaddr; @@ -396,11 +395,11 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot) * Allocate the first block & add it to the xtree */ xaddr = 0; - if ((rc = - xtInsert(tid, ip, 0, 0, sbi->nbperpage, - &xaddr, 0))) { + if (xtInsert(tid, ip, 0, 0, sbi->nbperpage, &xaddr, 0)) { jfs_warn("add_index: xtInsert failed!"); - return -EPERM; + memcpy(&jfs_ip->i_dirtable, temp_table, + sizeof (temp_table)); + goto clean_up; } ip->i_size = PSIZE; ip->i_blocks += LBLK2PBLK(sb, sbi->nbperpage); @@ -408,7 +407,9 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot) if ((mp = get_index_page(ip, 0)) == 0) { jfs_err("add_index: get_metapage failed!"); xtTruncate(tid, ip, 0, COMMIT_PWMAP); - return -EPERM; + memcpy(&jfs_ip->i_dirtable, temp_table, + sizeof (temp_table)); + goto clean_up; } tlck = txLock(tid, ip, mp, tlckDATA); llck = (struct linelock *) & tlck->lock; @@ -438,12 +439,9 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot) * This will be the beginning of a new page */ xaddr = 0; - if ((rc = - xtInsert(tid, ip, 0, blkno, sbi->nbperpage, - &xaddr, 0))) { + if (xtInsert(tid, ip, 0, blkno, sbi->nbperpage, &xaddr, 0)) { jfs_warn("add_index: xtInsert failed!"); - jfs_ip->next_index--; - return -EPERM; + goto clean_up; } ip->i_size += PSIZE; ip->i_blocks += LBLK2PBLK(sb, sbi->nbperpage); @@ -457,7 +455,7 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot) if (mp == 0) { jfs_err("add_index: get/read_metapage failed!"); - return -EPERM; + goto clean_up; } lock_index(tid, ip, mp, index); @@ -472,6 +470,12 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot) release_metapage(mp); return index; + + clean_up: + + jfs_ip->next_index--; + + return 0; } /* -- 2.30.9