linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chandan Rajendra <chandan@linux.vnet.ibm.com>
To: Qu Wenruo <quwenruo@cn.fujitsu.com>
Cc: linux-btrfs@vger.kernel.org, dsterba@suse.cz
Subject: Re: [PATCH 2/2] btrfs: qgroup: Fix qgroup reserved space underflow by only freeing reserved ranges
Date: Tue, 13 Dec 2016 18:26:59 +0530	[thread overview]
Message-ID: <16662538.OxiIrCRCJe@localhost.localdomain> (raw)
In-Reply-To: <20161202020307.6025-2-quwenruo@cn.fujitsu.com>

On Friday, December 02, 2016 10:03:07 AM Qu Wenruo wrote:
> [BUG]
> For the following case, btrfs can underflow qgroup reserved space
> at error path:
> (Page size 4K, function name without "btrfs_" prefix)
> 
>          Task A                  |             Task B
> ----------------------------------------------------------------------
> Buffered_write [0, 2K)           |
> |- check_data_free_space()       |
> |  |- qgroup_reserve_data()      |
> |     Range aligned to page      |
> |     range [0, 4K)          <<< |
> |     4K bytes reserved      <<< |
> |- copy pages to page cache      |
>                                  | Buffered_write [2K, 4K)
>                                  | |- check_data_free_space()
>                                  | |  |- qgroup_reserved_data()
>                                  | |     Range alinged to page
>                                  | |     range [0, 4K)
>                                  | |     Already reserved by A <<<
>                                  | |     0 bytes reserved      <<<
>                                  | |- delalloc_reserve_metadata()
>                                  | |  And it *FAILED* (Maybe EQUOTA)
>                                  | |- free_reserved_data_space()
>                                       |- qgroup_free_data()
>                                          Range aligned to page range
>                                          [0, 4K)
>                                          Freeing 4K
> (Special thanks to Chandan for the detailed report and analyse)
> 
> [CAUSE]
> Above Task B is freeing reserved data range [0, 4K) which is actually
> reserved by Task A.
> 
> And at write back time, page dirty by Task A will go through writeback
> routine, which will free 4K reserved data space at file extent insert
> time, causing the qgroup underflow.
> 
> [FIX]
> For btrfs_qgroup_free_data(), add @reserved parameter to only free
> data ranges reserved by previous btrfs_qgroup_reserve_data().
> So in above case, Task B will try to free 0 byte, so no underflow.
>

The changes look good to me. Also, I did not notice any regressions when
executing fstests with the patch applied.

Reviewed-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
Tested-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>

-- 
chandan


  reply	other threads:[~2016-12-13 12:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-02  2:03 [PATCH 1/2] btrfs: qgroup: Introduce extent changeset for qgroup reserve functions Qu Wenruo
2016-12-02  2:03 ` [PATCH 2/2] btrfs: qgroup: Fix qgroup reserved space underflow by only freeing reserved ranges Qu Wenruo
2016-12-13 12:56   ` Chandan Rajendra [this message]
2016-12-08 14:29 ` [PATCH 1/2] btrfs: qgroup: Introduce extent changeset for qgroup reserve functions Chandan Rajendra
2016-12-09  0:39   ` Qu Wenruo
2016-12-13 12:54 ` Chandan Rajendra

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=16662538.OxiIrCRCJe@localhost.localdomain \
    --to=chandan@linux.vnet.ibm.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=quwenruo@cn.fujitsu.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;
as well as URLs for NNTP newsgroup(s).