Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 18190cc0 authored by Dave Kleikamp's avatar Dave Kleikamp
Browse files

JFS: Fix i_blocks accounting when allocation fails



A failure in dbAlloc caused a directory's i_blocks to be incorrectly
incremented, causing jfs_fsck to find the inode to be corrupt.

Signed-off-by: default avatarDave Kleikamp <shaggy@austin.ibm.com>
parent c2783f3a
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -381,9 +381,12 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot)
		 * It's time to move the inline table to an external
		 * It's time to move the inline table to an external
		 * page and begin to build the xtree
		 * page and begin to build the xtree
		 */
		 */
		if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage) ||
		if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
		    dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
			goto clean_up;
			goto clean_up;	/* No space */
		if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr)) {
			DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
			goto clean_up;
		}


		/*
		/*
		 * Save the table, we're going to overwrite it with the
		 * Save the table, we're going to overwrite it with the
@@ -397,13 +400,15 @@ static u32 add_index(tid_t tid, struct inode *ip, s64 bn, int slot)
		xtInitRoot(tid, ip);
		xtInitRoot(tid, ip);


		/*
		/*
		 * Allocate the first block & add it to the xtree
		 * Add the first block to the xtree
		 */
		 */
		if (xtInsert(tid, ip, 0, 0, sbi->nbperpage, &xaddr, 0)) {
		if (xtInsert(tid, ip, 0, 0, sbi->nbperpage, &xaddr, 0)) {
			/* This really shouldn't fail */
			/* This really shouldn't fail */
			jfs_warn("add_index: xtInsert failed!");
			jfs_warn("add_index: xtInsert failed!");
			memcpy(&jfs_ip->i_dirtable, temp_table,
			memcpy(&jfs_ip->i_dirtable, temp_table,
			       sizeof (temp_table));
			       sizeof (temp_table));
			dbFree(ip, xaddr, sbi->nbperpage);
			DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
			goto clean_up;
			goto clean_up;
		}
		}
		ip->i_size = PSIZE;
		ip->i_size = PSIZE;