From patchwork Fri Nov 30 03:40:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Brandenburger X-Patchwork-Id: 1823481 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 5CF7FDF264 for ; Fri, 30 Nov 2012 03:41:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754808Ab2K3Dkz (ORCPT ); Thu, 29 Nov 2012 22:40:55 -0500 Received: from mail-fa0-f74.google.com ([209.85.161.74]:45639 "EHLO mail-fa0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754613Ab2K3Dkx (ORCPT ); Thu, 29 Nov 2012 22:40:53 -0500 Received: by mail-fa0-f74.google.com with SMTP id t1so2145fae.1 for ; Thu, 29 Nov 2012 19:40:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=e9xGASK7qfUc4zLji/Q+0osotk3qduePS4BPs0uSHj0=; b=GvQrnvjzTTb2FF5w1U44r1WZowkjcQWgIR5iDyGFDULGONIanjDgHfHBC43HO3F0AH /3T5dQXmo7IvhHSFOfYBEOF0jdtxeYSrhjjpxuJhR/DXOy23LU2Ux7Vr0j60eDYiZIXp Z4fUcjAZ0Tnl/La5S6nUAmCtatKzE08j3+71BO+Ji4ogDUxdKavfT7I8aIrM/neNU9zQ 7k6niPcYV/PUho6za/tr9zbm6yf5keTqKM+qCZ17LoXI99YWiQ/oRJoROObTArG5cp+u Ehdjbo1oKK5c/dKvZsvpTIksNwQbiZKb/zWDmF2iKzy+ZGKxSJxe+CdqMjbsPhztV0cQ PoKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=e9xGASK7qfUc4zLji/Q+0osotk3qduePS4BPs0uSHj0=; b=RGqC+SVhq2//CK8dInkPFlp6z1ozdHdkIqma/J9I15ZPatUcKEJcaVgtuC/usPebvi SDVvHrCNdILNOob+DDs+LeP+UsZFEpNoNaBSxt/JzNF3x5HaaU1mK7a3JMPpndGyWMzW k3BNwPUcFvC5bYq3PJKk4R8w9zsL9V9crGTHlL1Xre/gz2JVkEne3AeyRsWG6gjhJxFv wtXt6NRz8bP8s9OzARas0aqykPrmoYrxonm78eRTGhMyt4Wn77kzvCk5S3E7B+yxlWb4 UpoihafW5HEhnttC9LEtACdkqRQXMJNd9z9wDv33WBCtGAer3MD+h36mUYV9YvU706C7 qpdw== Received: by 10.14.208.198 with SMTP id q46mr17591990eeo.0.1354246851774; Thu, 29 Nov 2012 19:40:51 -0800 (PST) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id u8si860063een.1.2012.11.29.19.40.51 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 29 Nov 2012 19:40:51 -0800 (PST) Received: from obelix.sbo.corp.google.com (obelix.sbo.corp.google.com [172.31.172.210]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id 6900720004E; Thu, 29 Nov 2012 19:40:51 -0800 (PST) Received: by obelix.sbo.corp.google.com (Postfix, from userid 180819) id A3667200D59; Thu, 29 Nov 2012 19:40:50 -0800 (PST) From: Filipe Brandenburger To: Chris Mason , linux-btrfs@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Filipe Brandenburger Subject: [PATCH 2/2] Btrfs: refactor error handling to drop inode in btrfs_create() Date: Thu, 29 Nov 2012 19:40:09 -0800 Message-Id: <1354246809-32339-3-git-send-email-filbranden@google.com> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1354246809-32339-2-git-send-email-filbranden@google.com> References: <1354246809-32339-1-git-send-email-filbranden@google.com> <1354246809-32339-2-git-send-email-filbranden@google.com> X-Gm-Message-State: ALoCoQkRWmUgbOb5sW3+lHgJaiIfn/bKRSMQxDPXnGCFQZFGkOijaAwPqItWjNQ2RzNPQhVt7fA2UKiruMQeMOdJyUdfbQyJRGo6dbEvEBv+ezmIQ25bTZBvfZWHLtgmIX/GbCNc8FEBZXVTHdMWROsIA0mtiCVoO8xRv+PKb5vfHgD692SscC8a6OyEYHH9DRFSXS6qPaEyH/LD4IkgjDXUFJ25sEriow== Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Refactor it by checking whether the inode has been created and needs to be dropped (drop_inode_on_err) and also if the err variable is set. That way the variable doesn't need to be set on each and every error handling block. Signed-off-by: Filipe Brandenburger --- fs/btrfs/inode.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index caf9d76..1d66c9e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4963,7 +4963,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, struct btrfs_trans_handle *trans; struct btrfs_root *root = BTRFS_I(dir)->root; struct inode *inode = NULL; - int drop_inode = 0; + int drop_inode_on_err = 0; int err; unsigned long nr = 0; u64 objectid; @@ -4989,18 +4989,15 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, err = PTR_ERR(inode); goto out_unlock; } + drop_inode_on_err = 1; err = btrfs_init_inode_security(trans, inode, dir, &dentry->d_name); - if (err) { - drop_inode = 1; + if (err) goto out_unlock; - } err = btrfs_update_inode(trans, root, inode); - if (err) { - drop_inode = 1; + if (err) goto out_unlock; - } /* * If the active LSM wants to access the inode during @@ -5013,17 +5010,17 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, err = btrfs_add_nondir(trans, dir, dentry, inode, 0, index); if (err) - drop_inode = 1; - else { - inode->i_mapping->a_ops = &btrfs_aops; - inode->i_mapping->backing_dev_info = &root->fs_info->bdi; - BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; - d_instantiate(dentry, inode); - } + goto out_unlock; + + inode->i_mapping->a_ops = &btrfs_aops; + inode->i_mapping->backing_dev_info = &root->fs_info->bdi; + BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops; + d_instantiate(dentry, inode); + out_unlock: nr = trans->blocks_used; btrfs_end_transaction(trans, root); - if (drop_inode) { + if (err && drop_inode_on_err) { inode_dec_link_count(inode); iput(inode); }