Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp633082yba; Thu, 18 Apr 2019 07:09:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRAUegNIs66JIaayuC6391u7UGE4RahhwtuKQbOyPbwbqACm3I0+l9lOLKhxp+fCbMRvXJ X-Received: by 2002:a63:2b4c:: with SMTP id r73mr90525797pgr.181.1555596591236; Thu, 18 Apr 2019 07:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555596591; cv=none; d=google.com; s=arc-20160816; b=Q5FTepgFt1ZQ9F+qaR3EZlHL9jOtwlR4CP6Uh3KAf19EUB6TncjPDABZuzkpOKR4+L NoeitLywEQcNoggVk6NVVaZwWy2m7vOx+oNI+pWIoeweRzP5o2tb071gywa8CHe38zB8 aUYPoyvm04UmO4Xe8kFRwPxtJZK2HInn6mvtHLELBm0kF/7TUTkukrXVc+gOd0BpLvV3 kiWCQWL3KHWC4j9jacJGdO+pyqwOkg5x9ou45r74Zz+gerkZgY3CWR7jvkYTw1sU1Jgp aqiP4YT2vITCG5RCQOdVvUXcI9vLv5/JNBmfMlQsifINkjm2bZotA/Lm0C+tbg3V8Dky Cl5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=6Rhcg8fa2hBMufpf8gDXTuEh6jV1AGJyMm+dHB6jlq4=; b=pOlduf3ybKhetxNlSeCtb2Gh7/1At2OOKQry9JhKZzI8A2w8sVPHXuvuJpQopjzoi9 33p7aV5BRnaIsAnqTwCoPG8o3KLQSOrjxS+UjUKUkcI4D5ejxv7UrWReVYlcgXLE4U+7 5mcNbdyg2BhuVQFzW6rvM1jt/WjXUjkuFZStyOjYkpVmbD0hd90qGNxf/V/ic0iNef5B jkStSNzZWaPsGNsZhPMjtDjFYlSo9JKE+fUNwyWNM//ZDIBtVJJQTmmx6FEASgSAIgDR ioh/3ntwLhXUyj3EfBuOEAYvNySQNLH6fof8FBD4Rol32KT3U3ZZ4BXn/pQoinjZHbDs I8yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=aSzsIZeC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u193si2015576pgc.410.2019.04.18.07.09.35; Thu, 18 Apr 2019 07:09:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=aSzsIZeC; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389191AbfDROH6 (ORCPT + 99 others); Thu, 18 Apr 2019 10:07:58 -0400 Received: from mail-yb1-f196.google.com ([209.85.219.196]:33719 "EHLO mail-yb1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388369AbfDROH6 (ORCPT ); Thu, 18 Apr 2019 10:07:58 -0400 Received: by mail-yb1-f196.google.com with SMTP id i10so895580ybk.0 for ; Thu, 18 Apr 2019 07:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=6Rhcg8fa2hBMufpf8gDXTuEh6jV1AGJyMm+dHB6jlq4=; b=aSzsIZeC2VCOYFaY/wDpDMvbLd8r1hoayYjR2/SqvBGA8Ul2ndJltAlR14AdRgqOLk gDV+BjgrR4+ujUR6Fj4Tk8gavjnKDwGjSH6e6sjuK16ofjDlNdbG5prlG4QrrtPiBc5b 74Ub+tncarcPLNCMWo63r7yRdHeAew29F1hKSWxKlkZDynzt1h/SFqTXvIzPFkm1C8Qh bN/H05IsYlL2MhNswYE0ckoRiOafbLGdny4ap76ssH1JqXKIGZ7SmkH6sGQDbVmIMlSR Zyelji2JtsUq1SGrKUsOXSVu3KHTkXoXIJyDPK3TEe8GthHb5BePgRJGLY/cXWylxBRS 7qoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=6Rhcg8fa2hBMufpf8gDXTuEh6jV1AGJyMm+dHB6jlq4=; b=FJKWvrSU1iJ0/KB8M2R3UmgfPToLIMUZe2k5CS/MVVWSeJ0NEAEHLAnrCZIuyKGPC3 f+Bgrti497YXGLq5PQXPcQZMpDLgFE/7piNfDaQyUwyqbF9+warqyX0lbra153ik6cCx 9NTB/0mH3lOWIN219+Tw/qXIQ5Ou5TW8xT7IBozcBFYotl3ac96GcRGIO+UqC5kjdVpo flagB7GpCbOiMS19ODpsqnJO6l3yThXN0bY1PhYJtEv1CBUrJ/I6Zce+N64d5SRaitG5 FrY2IWBO48cwEoS3vmEN41P2BZ35z+3KHH1e98l+gGCcdrdIh/HpXedqr0MOJ0yFeVVY UvdA== X-Gm-Message-State: APjAAAWipAOgba6hf6D0Tpzw62S05dNKELR8AqG1QGLV0sn4qA6inIY5 /P8NQ4uYPemNLLF/gsfNB52G/Iu1ldV15w== X-Received: by 2002:a25:d7c1:: with SMTP id o184mr29496615ybg.147.1555596477100; Thu, 18 Apr 2019 07:07:57 -0700 (PDT) Received: from localhost ([2620:10d:c091:180::e445]) by smtp.gmail.com with ESMTPSA id 74sm746578ywe.81.2019.04.18.07.07.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 07:07:56 -0700 (PDT) Date: Thu, 18 Apr 2019 10:07:54 -0400 From: Josef Bacik To: Nikolay Borisov Cc: Pan Bian , Chris Mason , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [V2] btrfs: drop inode reference count on error path Message-ID: <20190418140749.h57y5kqz4s47sbuo@macbook-pro-91.dhcp.thefacebook.com> References: <1555585576-31045-1-git-send-email-bianpan2016@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 18, 2019 at 03:50:00PM +0300, Nikolay Borisov wrote: > > > On 18.04.19 г. 14:06 ч., Pan Bian wrote: > > The reference count of inode is incremented by ihold. It should be > > dropped if not used. However, the reference count is not dropped if > > error occurs during updating the inode or deleting orphan items. This > > patch fixes the bug. > > > > Signed-off-by: Pan Bian > > --- > > V2: move ihold just before device_initialize to make code clearer > > --- > > fs/btrfs/inode.c | 54 +++++++++++++++++++++++++----------------------------- > > 1 file changed, 25 insertions(+), 29 deletions(-) > > > > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > > index 82fdda8..d6630df 100644 > > --- a/fs/btrfs/inode.c > > +++ b/fs/btrfs/inode.c > > @@ -6579,7 +6579,7 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, > > struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); > > u64 index; > > int err; > > - int drop_inode = 0; > > + int log_mode; > > > > /* do not allow sys_link's with other subvols of the same device */ > > if (root->root_key.objectid != BTRFS_I(inode)->root->root_key.objectid) > > @@ -6616,41 +6616,37 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, > > err = btrfs_add_nondir(trans, BTRFS_I(dir), dentry, BTRFS_I(inode), > > 1, index); > > > > - if (err) { > > - drop_inode = 1; > > - } else { > > - struct dentry *parent = dentry->d_parent; > > - int ret; > > + if (err) > > + goto err_link; > > > > - err = btrfs_update_inode(trans, root, inode); > > + err = btrfs_update_inode(trans, root, inode); > > + if (err) > > + goto err_link; > > + if (inode->i_nlink == 1) { > > + /* > > + * If new hard link count is 1, it's a file created > > + * with open(2) O_TMPFILE flag. > > + */ > > + err = btrfs_orphan_del(trans, BTRFS_I(inode)); > > if (err) > > - goto fail; > > - if (inode->i_nlink == 1) { > > - /* > > - * If new hard link count is 1, it's a file created > > - * with open(2) O_TMPFILE flag. > > - */ > > - err = btrfs_orphan_del(trans, BTRFS_I(inode)); > > - if (err) > > - goto fail; > > - } > > - BTRFS_I(inode)->last_link_trans = trans->transid; > > - d_instantiate(dentry, inode); > > - ret = btrfs_log_new_name(trans, BTRFS_I(inode), NULL, parent, > > - true, NULL); > > - if (ret == BTRFS_NEED_TRANS_COMMIT) { > > - err = btrfs_commit_transaction(trans); > > - trans = NULL; > > - } > > + goto err_link; > > + } > > + BTRFS_I(inode)->last_link_trans = trans->transid; > > + ihold(inode); Where is the iput for this ihold? Josef