linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: dsterba@suse.cz, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 8/9] btrfs: user requsted replace cancel is not an error
Date: Fri, 16 Nov 2018 19:05:15 +0800	[thread overview]
Message-ID: <3362ce34-ed38-980d-e867-5892afc1b5bc@oracle.com> (raw)
In-Reply-To: <5e7d6012-5231-a6ed-ddd3-c9e104b536bd@oracle.com>



On 11/16/2018 06:29 PM, Anand Jain wrote:
> 
> 
> On 11/15/2018 11:31 PM, David Sterba wrote:
>> On Sun, Nov 11, 2018 at 10:22:23PM +0800, Anand Jain wrote:
>>> As of now only user requested replace cancel can cancel the 
>>> replace-scrub
>>> so no need to log error for it.
>>
>> This has probably some user visible effect or threre are steps to
>> reproduce the message even if it's not expected (ie. the case that this
>> patch fixes). Please update the changelog, thanks.
>>
> 
> 
> 
> before the patch [1]
>    [1]
>      btrfs: fix use-after-free due to race between replace start and cancel
> 
>   We used to set the replace_state to CANCELED [2] and then call
>   btrfs_scrub_cancel(), but the problem with this approach is
>   if the scrub isn't running yet, then things get messier.
> 
> [2]
> -       dev_replace->replace_state = 
> BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED;
> 
>   So to fix, [1] shall set replace_state to CANCELED only after the
>   replace cancel thread has successfully canceled the replace using
>   btrfs_scrub_cancel().
> 
>   And about the cleanup process for the replace target..
>   we call
>     btrfs_dev_replace_finishing(.. ret)
>   after
>    ret= btrfs_scrub_dev()
> 
>   now ret is -ECANCELED due to replace cancel request by the user.
>   (its not set to -ECANCELED for any other reason).
> 
>   btrfs_dev_replace_finishing() has the following code [3] which it
>   earlier blocked processing of the cleanup process after the cancel,
>   because the replace_state was already updated to
>   BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED.
> 
> 
> [3]
> --------------
> static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
>                                         int scrub_ret)
> {
> 
> ::
>          /* was the operation canceled, or is it finished? */
>          if (dev_replace->replace_state !=
>              BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED) {
>                  btrfs_dev_replace_read_unlock(dev_replace);
>                  mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
>                  return 0;
>          }
> -----------
> 
>   In fact before this patch [1] the code wasn't sync-ing the IO
>   when replace was canceled. Which this patch also fixes by using
>   the  btrfs_dev_replace_finishing()
> 
> 
> -----------
> btrfs_dev_replace_finishing
> ::
>          /*
>           * flush all outstanding I/O and inode extent mappings before the
>           * copy operation is declared as being finished
>           */
>          ret = btrfs_start_delalloc_roots(fs_info, -1);
>          if (ret) {
>                  mutex_unlock(&dev_replace->lock_finishing_cancel_unmount);
>                  return ret;
>          }
>          btrfs_wait_ordered_roots(fs_info, U64_MAX, 0, (u64)-1);
> -----------
> 
>   So to answer above question... these warn and error log wasn't
>   reported before when replace was canceled and now since I am
>   using the btrfs_dev_replace_finishing() to finish the job
>   of cancel.. it shall be reported which is ok to quite.
> 
>   Do you think we still need to update the change log?

  OR I think more appropriately this patch should be merged with

  [PATCH 4/9] btrfs: fix UAF due to race between replace start and cancel

-Anand
> HTH.
> 
> Thanks, Anand

  reply	other threads:[~2018-11-16 11:05 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-11 14:22 [PATCH 0/9 v2] fix replace-start and replace-cancel racing Anand Jain
2018-11-11 14:22 ` [PATCH 1/9] btrfs: mark btrfs_dev_replace_start() as static Anand Jain
2018-11-11 14:22 ` [PATCH 2/9] btrfs: replace go back to suspended if target missing Anand Jain
2018-11-11 14:22 ` [PATCH 3/9] btrfs: replace back to suspend state if EXCL OP is running Anand Jain
2018-11-11 14:22 ` [PATCH 4/9] btrfs: fix UAF due to race between replace start and cancel Anand Jain
2018-11-13 17:24   ` David Sterba
2018-11-14  1:28     ` Anand Jain
2018-11-15 14:00       ` David Sterba
2018-11-15 15:25         ` David Sterba
2018-11-16  6:37           ` Anand Jain
2018-11-14  5:50   ` [PATCH 4/9 v2.1] " Anand Jain
2018-11-11 14:22 ` [PATCH 5/9] btrfs: replace cancel is successful if scrub cancel is successful Anand Jain
2018-11-15 15:27   ` David Sterba
2018-11-16  6:38     ` Anand Jain
2018-11-11 14:22 ` [PATCH 6/9] btrfs: replace's scrub must not be running in replace suspended state Anand Jain
2018-11-11 14:22 ` [PATCH 7/9] btrfs: quiten warn if the replace is canceled at finish Anand Jain
2018-11-15 15:35   ` David Sterba
2018-11-16 12:06     ` Anand Jain
2018-11-16 18:49       ` David Sterba
2018-11-11 14:22 ` [PATCH 8/9] btrfs: user requsted replace cancel is not an error Anand Jain
2018-11-15 15:31   ` David Sterba
2018-11-16 10:29     ` Anand Jain
2018-11-16 11:05       ` Anand Jain [this message]
2018-11-11 14:22 ` [PATCH 9/9] btrfs: add explicit check for replace result no error Anand Jain
2018-11-13 17:33 ` [PATCH 0/9 v2] fix replace-start and replace-cancel racing David Sterba
2018-11-15 15:41 ` David Sterba
2018-11-16  9:32   ` Anand Jain
  -- strict thread matches above, loose matches on Subject: below --
2018-11-07 11:43 [PATCH 0/9] " Anand Jain
2018-11-07 11:43 ` [PATCH 8/9] btrfs: user requsted replace cancel is not an error Anand Jain

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=3362ce34-ed38-980d-e867-5892afc1b5bc@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    /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).