From patchwork Tue Nov 23 07:58:58 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 72634 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id CFD18B70F1 for ; Tue, 23 Nov 2010 18:59:01 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752180Ab0KWH67 (ORCPT ); Tue, 23 Nov 2010 02:58:59 -0500 Received: from mail-qw0-f46.google.com ([209.85.216.46]:52497 "EHLO mail-qw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752078Ab0KWH67 convert rfc822-to-8bit (ORCPT ); Tue, 23 Nov 2010 02:58:59 -0500 Received: by qwd6 with SMTP id 6so152792qwd.19 for ; Mon, 22 Nov 2010 23:58:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=6SEIIrRIBCkhxlig+tTGc/VvrKlWONHbVBzVA86hmHY=; b=ZzVz5jeA5Z4opsOBVrd8kwTdNF80uDF9XUY4MLGGdTxSlL1MQG2YIF98zY7EBxlM1o /Aih/FGPdm34cOkLla9wojU5HPrsuTRi1iHH8XUAwffUy8n4b2Ij3NTI53zSl6h7lqJ0 PEIveKKBf47asVbDnRmEJP2WB25z+ahl5PHQk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=EbyRSgWTl/cTHQ3Fo6Pk5UwXAy59BckvtHHbB3eSI+0g4lKn9zqyaJmr4Y4tsECBAS b0XA5ZCxCX7ePwKBLEB1vwq+ypyuw4U3lNz9UADUnQ0YsEpPLWS7eT6uIF4NS7G/VNUv yf3TAQqUi5485VUo9VyXz/cUFfnCYMn5NuJo4= MIME-Version: 1.0 Received: by 10.229.249.20 with SMTP id mi20mr5931195qcb.117.1290499138349; Mon, 22 Nov 2010 23:58:58 -0800 (PST) Received: by 10.229.38.72 with HTTP; Mon, 22 Nov 2010 23:58:58 -0800 (PST) In-Reply-To: <1290486633-4534-1-git-send-email-namhyung@gmail.com> References: <1290486633-4534-1-git-send-email-namhyung@gmail.com> Date: Tue, 23 Nov 2010 09:58:58 +0200 Message-ID: Subject: Re: [PATCH v2] ext3: Add journal error check into ext3_rename() From: Amir Goldstein To: Namhyung Kim Cc: Jan Kara , Andrew Morton , Andreas Dilger , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue, Nov 23, 2010 at 6:30 AM, Namhyung Kim wrote: > Check return value of ext3_journal_get_write_access() and > ext3_journal_dirty_metadata(). > > Signed-off-by: Namhyung Kim > --- >  fs/ext3/namei.c |   19 +++++++++++++++---- >  1 files changed, 15 insertions(+), 4 deletions(-) > > diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c > index 672cea1..c8415e7 100644 > --- a/fs/ext3/namei.c > +++ b/fs/ext3/namei.c > @@ -2371,7 +2371,9 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, >                        goto end_rename; >        } else { >                BUFFER_TRACE(new_bh, "get write access"); > -               ext3_journal_get_write_access(handle, new_bh); > +               retval = ext3_journal_get_write_access(handle, new_bh); > +               if (retval) > +                       goto journal_error; >                new_de->inode = cpu_to_le32(old_inode->i_ino); >                if (EXT3_HAS_INCOMPAT_FEATURE(new_dir->i_sb, >                                              EXT3_FEATURE_INCOMPAT_FILETYPE)) > @@ -2380,7 +2382,9 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, >                new_dir->i_ctime = new_dir->i_mtime = CURRENT_TIME_SEC; >                ext3_mark_inode_dirty(handle, new_dir); >                BUFFER_TRACE(new_bh, "call ext3_journal_dirty_metadata"); > -               ext3_journal_dirty_metadata(handle, new_bh); > +               retval = ext3_journal_dirty_metadata(handle, new_bh); > +               if (retval) > +                       goto journal_error; >                brelse(new_bh); >                new_bh = NULL; >        } > @@ -2429,10 +2433,17 @@ static int ext3_rename (struct inode * old_dir, struct dentry *old_dentry, >        ext3_update_dx_flag(old_dir); >        if (dir_bh) { >                BUFFER_TRACE(dir_bh, "get_write_access"); > -               ext3_journal_get_write_access(handle, dir_bh); > +               retval = ext3_journal_get_write_access(handle, dir_bh); > +               if (retval) > +                       goto journal_error; >                PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino); >                BUFFER_TRACE(dir_bh, "call ext3_journal_dirty_metadata"); > -               ext3_journal_dirty_metadata(handle, dir_bh); > +               retval = ext3_journal_dirty_metadata(handle, dir_bh); > +               if (retval) { > +journal_error: > +                       ext3_std_error(new_dir->i_sb, retval); > +                       goto end_rename; > +               } Hi Kim, A better way to handle this situation is to get_write_access much sooner, when things can still be rolled back properly. Please find below a patch I am using in next3 to fix some un-handled journal errors and see if you can/want to use any of it as reference for your patches. Amir. Some places in Ext3 original code don't check for return value of JBD functions. Check for snapshot/journal errors in those places. Signed-off-by: Amir Goldstein -------------------------------------------------------------------------------- @@ -2337,6 +2350,10 @@ static int ext3_rename (struct inode * if (!new_inode && new_dir!=old_dir && new_dir->i_nlink >= EXT3_LINK_MAX) goto end_rename; + BUFFER_TRACE(dir_bh, "get_write_access"); + retval = ext3_journal_get_write_access(handle, dir_bh); + if (retval) + goto end_rename; } if (!new_bh) { retval = ext3_add_entry (handle, new_dentry, old_inode); @@ -2344,7 +2361,9 @@ static int ext3_rename (struct inode * goto end_rename; } else { BUFFER_TRACE(new_bh, "get write access"); - ext3_journal_get_write_access(handle, new_bh); + retval = ext3_journal_get_write_access(handle, new_bh); + if (retval) + goto end_rename; new_de->inode = cpu_to_le32(old_inode->i_ino); if (EXT3_HAS_INCOMPAT_FEATURE(new_dir->i_sb, EXT3_FEATURE_INCOMPAT_FILETYPE)) @@ -2401,8 +2420,6 @@ static int ext3_rename (struct inode * old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME_SEC; ext3_update_dx_flag(old_dir); if (dir_bh) { - BUFFER_TRACE(dir_bh, "get_write_access"); - ext3_journal_get_write_access(handle, dir_bh); PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino); BUFFER_TRACE(dir_bh, "call ext3_journal_dirty_metadata"); ext3_journal_dirty_metadata(handle, dir_bh); --- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff -Nuarp a/fs/ext3/balloc.c b/fs/ext3/balloc.c --- a/fs/ext3/balloc.c 2010-11-23 09:38:13.395922811 +0200 +++ b/fs/ext3/balloc.c 2010-11-23 09:38:13.185923236 +0200 @@ -674,7 +674,9 @@ do_more: /* We dirtied the bitmap block */ BUFFER_TRACE(bitmap_bh, "dirtied bitmap block"); - err = ext3_journal_dirty_metadata(handle, bitmap_bh); + ret = ext3_journal_dirty_metadata(handle, bitmap_bh); + if (!err) + err = ret; /* And the group descriptor block */ BUFFER_TRACE(gd_bh, "dirtied group descriptor block"); diff -Nuarp a/fs/ext3/inode.c b/fs/ext3/inode.c --- a/fs/ext3/inode.c 2010-11-23 09:38:13.405923214 +0200 +++ b/fs/ext3/inode.c 2010-11-23 09:38:13.195922747 +0200 @@ -2362,6 +2362,9 @@ static void ext3_clear_blocks(handle_t if (bh) { BUFFER_TRACE(bh, "retaking write access"); ext3_journal_get_write_access_inode(handle, inode, bh); + /* we may have lost write_access on bh */ + if (is_handle_aborted(handle)) + return; } } @@ -2444,6 +2447,9 @@ static void ext3_free_data(handle_t *ha ext3_clear_blocks(handle, inode, this_bh, block_to_free, count, block_to_free_p, p); + /* we may have lost write_access on this_bh */ + if (is_handle_aborted(handle)) + return; block_to_free = nr; block_to_free_p = p; count = 1; @@ -2454,6 +2460,9 @@ static void ext3_free_data(handle_t *ha if (count > 0) ext3_clear_blocks(handle, inode, this_bh, block_to_free, count, block_to_free_p, p); + /* we may have lost write_access on this_bh */ + if (is_handle_aborted(handle)) + return; if (this_bh) { BUFFER_TRACE(this_bh, "call ext3_journal_dirty_metadata"); diff -Nuarp a/fs/ext3/namei.c b/fs/ext3/namei.c --- a/fs/ext3/namei.c 2010-11-23 09:38:13.415922664 +0200 +++ b/fs/ext3/namei.c 2010-11-23 09:38:13.205923227 +0200 @@ -1649,8 +1649,12 @@ static int ext3_delete_entry (handle_t if (!ext3_check_dir_entry("ext3_delete_entry", dir, de, bh, i)) return -EIO; if (de == de_del) { + int err; + BUFFER_TRACE(bh, "get_write_access"); - ext3_journal_get_write_access(handle, bh); + err = ext3_journal_get_write_access(handle, bh); + if (err) + return err; if (pde) pde->rec_len = ext3_rec_len_to_disk( ext3_rec_len_from_disk(pde->rec_len) + @@ -1797,7 +1801,16 @@ retry: goto out_stop; } BUFFER_TRACE(dir_block, "get_write_access"); - ext3_journal_get_write_access(handle, dir_block); + err = ext3_journal_get_write_access(handle, dir_block); + if (err) { + drop_nlink(inode); /* is this nlink == 0? */ + unlock_new_inode(inode); + /* no need to check for errors - we failed anyway */ + (void) ext3_mark_inode_dirty(handle, inode); + iput(inode); + brelse(dir_block); + goto out_stop; + } de = (struct ext3_dir_entry_2 *) dir_block->b_data; de->inode = cpu_to_le32(inode->i_ino); de->name_len = 1;