Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Cc: Filipe Manana <fdmanana@suse.com>, David Sterba <dsterba@suse.com>
Subject: Re: [PATCH] btrfs: qgroup: don't commit transaction when we already hold the handle
Date: Fri, 4 Dec 2020 09:37:17 +0200	[thread overview]
Message-ID: <4fce0773-a0ba-4c74-0134-8bc22a95d23e@suse.com> (raw)
In-Reply-To: <20201204012448.26546-2-wqu@suse.com>



On 4.12.20 г. 3:24 ч., Qu Wenruo wrote:
> [BUG]
> When running the following script, btrfs will trigger an ASSERT():
> 
>   #/bin/bash
>   mkfs.btrfs -f $dev
>   mount $dev $mnt
>   xfs_io -f -c "pwrite 0 1G" $mnt/file
>   sync
>   btrfs quota enable $mnt
>   btrfs quota rescan -w $mnt
> 
>   # Manually set the limit below current usage
>   btrfs qgroup limit 512M $mnt $mnt
> 
>   # Crash happens
>   touch $mnt/file
> 
> The dmesg looks like this:
> 
>   assertion failed: refcount_read(&trans->use_count) == 1, in fs/btrfs/transaction.c:2022
>   ------------[ cut here ]------------
>   kernel BUG at fs/btrfs/ctree.h:3230!
>   invalid opcode: 0000 [#1] SMP PTI
>   RIP: 0010:assertfail.constprop.0+0x18/0x1a [btrfs]
>    btrfs_commit_transaction.cold+0x11/0x5d [btrfs]
>    try_flush_qgroup+0x67/0x100 [btrfs]
>    __btrfs_qgroup_reserve_meta+0x3a/0x60 [btrfs]
>    btrfs_delayed_update_inode+0xaa/0x350 [btrfs]
>    btrfs_update_inode+0x9d/0x110 [btrfs]
>    btrfs_dirty_inode+0x5d/0xd0 [btrfs]
>    touch_atime+0xb5/0x100
>    iterate_dir+0xf1/0x1b0
>    __x64_sys_getdents64+0x78/0x110
>    do_syscall_64+0x33/0x80
>    entry_SYSCALL_64_after_hwframe+0x44/0xa9
>   RIP: 0033:0x7fb5afe588db
> 
> [CAUSE]
> In try_flush_qgroup(), we assume we don't hold a transaction handle at
> all.  This is true for data reservation and mostly true for metadata.
> Since data space reservation always happens before we start a
> transaction, and for most metadata operation we reserve space in
> start_transaction().
> 
> But there is an exception, btrfs_delayed_inode_reserve_metadata().
> It holds a transaction handle, while still trying to reserve extra
> metadata space.
> 
> When we hit EDQUOT inside btrfs_delayed_inode_reserve_metadata(), we
> will join current transaction and commit, while we still have
> transaction handle from qgroup code.
> 
> [FIX]
> Let's check current->journal before we join the transaction.
> 
> If current->journal is unset or BTRFS_SEND_TRANS_STUB, it means
> we are not holding a transaction, thus are able to join and then commit
> transaction.
> 
> If current->journal is a valid transaction handle, we avoid committing
> transaction and just end it
> 
> This is less effective than committing current transaction, as it won't
> free metadata reserved space, but we may still free some data space
> before new data writes.
> 
> Bugzilla: https://bugzilla.suse.com/show_bug.cgi?id=1178634
> Fixes: c53e9653605d ("btrfs: qgroup: try to flush qgroup space when we get -EDQUOT")
> Reviewed-by: Filipe Manana <fdmanana@suse.com>
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> Signed-off-by: David Sterba <dsterba@suse.com>

Wasn't this submitted already? Also are you going to turn the example
script into a fstest?

  reply	other threads:[~2020-12-04  7:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-04  1:24 [PATCH] btrfs: qgroup: don't try to wait flushing if we're already holding a transaction Qu Wenruo
2020-12-04  1:24 ` [PATCH] btrfs: qgroup: don't commit transaction when we already hold the handle Qu Wenruo
2020-12-04  7:37   ` Nikolay Borisov [this message]
2020-12-04  7:46     ` Qu Wenruo
2020-12-04 11:48 ` [PATCH] btrfs: qgroup: don't try to wait flushing if we're already holding a transaction Filipe Manana
2020-12-04 17:28 ` David Sterba
2020-12-05  2:55   ` Qu Wenruo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4fce0773-a0ba-4c74-0134-8bc22a95d23e@suse.com \
    --to=nborisov@suse.com \
    --cc=dsterba@suse.com \
    --cc=fdmanana@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox