From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C39E321E47D6C for ; Tue, 5 Sep 2017 15:33:27 -0700 (PDT) From: Ross Zwisler Subject: [PATCH 5/9] ext4: ext4_change_inode_journal_flag error handling Date: Tue, 5 Sep 2017 16:35:37 -0600 Message-Id: <20170905223541.20594-6-ross.zwisler@linux.intel.com> In-Reply-To: <20170905223541.20594-1-ross.zwisler@linux.intel.com> References: <20170905223541.20594-1-ross.zwisler@linux.intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" To: Andrew Morton , linux-kernel@vger.kernel.org Cc: Theodore Ts'o , "Darrick J. Wong" , Dave Chinner , linux-nvdimm@lists.01.org, stable@vger.kernel.org, linux-xfs@vger.kernel.org, Andreas Dilger , Jan Kara , linux-ext4@vger.kernel.org, Christoph Hellwig List-ID: Rework the error handling in ext4_change_inode_journal_flag() so that multiple paths can re-use portions of the same cleanup code via gotos instead of each path doing their own cleanup. This will benefit later patches that add more paths to this function that must be unwound on error. Signed-off-by: Ross Zwisler CC: stable@vger.kernel.org --- fs/ext4/inode.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 864fb94..d218991 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5953,11 +5953,8 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) if (val) { down_write(&EXT4_I(inode)->i_mmap_sem); err = filemap_write_and_wait(inode->i_mapping); - if (err < 0) { - up_write(&EXT4_I(inode)->i_mmap_sem); - ext4_inode_resume_unlocked_dio(inode); - return err; - } + if (err < 0) + goto out_unlock; } percpu_down_write(&sbi->s_journal_flag_rwsem); @@ -5975,12 +5972,8 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) ext4_set_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); else { err = jbd2_journal_flush(journal); - if (err < 0) { - jbd2_journal_unlock_updates(journal); - percpu_up_write(&sbi->s_journal_flag_rwsem); - ext4_inode_resume_unlocked_dio(inode); - return err; - } + if (err < 0) + goto out_journal_unlock; ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); } ext4_set_aops(inode); @@ -6009,6 +6002,15 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) ext4_std_error(inode->i_sb, err); return err; + +out_journal_unlock: + jbd2_journal_unlock_updates(journal); + percpu_up_write(&sbi->s_journal_flag_rwsem); +out_unlock: + if (val) + up_write(&EXT4_I(inode)->i_mmap_sem); + ext4_inode_resume_unlocked_dio(inode); + return err; } static int ext4_bh_unmapped(handle_t *handle, struct buffer_head *bh) -- 2.9.5 _______________________________________________ Linux-nvdimm mailing list Linux-nvdimm@lists.01.org https://lists.01.org/mailman/listinfo/linux-nvdimm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754530AbdIEWi0 (ORCPT ); Tue, 5 Sep 2017 18:38:26 -0400 Received: from mga01.intel.com ([192.55.52.88]:63245 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753802AbdIEWgT (ORCPT ); Tue, 5 Sep 2017 18:36:19 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,481,1498546800"; d="scan'208";a="308314878" From: Ross Zwisler To: Andrew Morton , linux-kernel@vger.kernel.org Cc: Ross Zwisler , "Darrick J. Wong" , "Theodore Ts'o" , Andreas Dilger , Christoph Hellwig , Dan Williams , Dave Chinner , Jan Kara , linux-ext4@vger.kernel.org, linux-nvdimm@lists.01.org, linux-xfs@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 5/9] ext4: ext4_change_inode_journal_flag error handling Date: Tue, 5 Sep 2017 16:35:37 -0600 Message-Id: <20170905223541.20594-6-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20170905223541.20594-1-ross.zwisler@linux.intel.com> References: <20170905223541.20594-1-ross.zwisler@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Rework the error handling in ext4_change_inode_journal_flag() so that multiple paths can re-use portions of the same cleanup code via gotos instead of each path doing their own cleanup. This will benefit later patches that add more paths to this function that must be unwound on error. Signed-off-by: Ross Zwisler CC: stable@vger.kernel.org --- fs/ext4/inode.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 864fb94..d218991 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5953,11 +5953,8 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) if (val) { down_write(&EXT4_I(inode)->i_mmap_sem); err = filemap_write_and_wait(inode->i_mapping); - if (err < 0) { - up_write(&EXT4_I(inode)->i_mmap_sem); - ext4_inode_resume_unlocked_dio(inode); - return err; - } + if (err < 0) + goto out_unlock; } percpu_down_write(&sbi->s_journal_flag_rwsem); @@ -5975,12 +5972,8 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) ext4_set_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); else { err = jbd2_journal_flush(journal); - if (err < 0) { - jbd2_journal_unlock_updates(journal); - percpu_up_write(&sbi->s_journal_flag_rwsem); - ext4_inode_resume_unlocked_dio(inode); - return err; - } + if (err < 0) + goto out_journal_unlock; ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); } ext4_set_aops(inode); @@ -6009,6 +6002,15 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) ext4_std_error(inode->i_sb, err); return err; + +out_journal_unlock: + jbd2_journal_unlock_updates(journal); + percpu_up_write(&sbi->s_journal_flag_rwsem); +out_unlock: + if (val) + up_write(&EXT4_I(inode)->i_mmap_sem); + ext4_inode_resume_unlocked_dio(inode); + return err; } static int ext4_bh_unmapped(handle_t *handle, struct buffer_head *bh) -- 2.9.5 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ross Zwisler Subject: [PATCH 5/9] ext4: ext4_change_inode_journal_flag error handling Date: Tue, 5 Sep 2017 16:35:37 -0600 Message-ID: <20170905223541.20594-6-ross.zwisler@linux.intel.com> References: <20170905223541.20594-1-ross.zwisler@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: Theodore Ts'o , "Darrick J. Wong" , Dave Chinner , linux-nvdimm-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org, stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-xfs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Andreas Dilger , Jan Kara , linux-ext4-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Christoph Hellwig To: Andrew Morton , linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Return-path: In-Reply-To: <20170905223541.20594-1-ross.zwisler-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org Sender: "Linux-nvdimm" List-Id: linux-ext4.vger.kernel.org Rework the error handling in ext4_change_inode_journal_flag() so that multiple paths can re-use portions of the same cleanup code via gotos instead of each path doing their own cleanup. This will benefit later patches that add more paths to this function that must be unwound on error. Signed-off-by: Ross Zwisler CC: stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org --- fs/ext4/inode.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 864fb94..d218991 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5953,11 +5953,8 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) if (val) { down_write(&EXT4_I(inode)->i_mmap_sem); err = filemap_write_and_wait(inode->i_mapping); - if (err < 0) { - up_write(&EXT4_I(inode)->i_mmap_sem); - ext4_inode_resume_unlocked_dio(inode); - return err; - } + if (err < 0) + goto out_unlock; } percpu_down_write(&sbi->s_journal_flag_rwsem); @@ -5975,12 +5972,8 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) ext4_set_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); else { err = jbd2_journal_flush(journal); - if (err < 0) { - jbd2_journal_unlock_updates(journal); - percpu_up_write(&sbi->s_journal_flag_rwsem); - ext4_inode_resume_unlocked_dio(inode); - return err; - } + if (err < 0) + goto out_journal_unlock; ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); } ext4_set_aops(inode); @@ -6009,6 +6002,15 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val) ext4_std_error(inode->i_sb, err); return err; + +out_journal_unlock: + jbd2_journal_unlock_updates(journal); + percpu_up_write(&sbi->s_journal_flag_rwsem); +out_unlock: + if (val) + up_write(&EXT4_I(inode)->i_mmap_sem); + ext4_inode_resume_unlocked_dio(inode); + return err; } static int ext4_bh_unmapped(handle_t *handle, struct buffer_head *bh) -- 2.9.5