diff mbox

[v2,1/4] Btrfs: fix wrong send_in_progress accounting

Message ID 20140108121609.GF6498@suse.cz (mailing list archive)
State Superseded
Headers show

Commit Message

David Sterba Jan. 8, 2014, 12:16 p.m. UTC
On Tue, Jan 07, 2014 at 05:25:18PM +0800, Wang Shilong wrote:
> Steps to reproduce:
>  # mkfs.btrfs -f /dev/sda8
>  # mount /dev/sda8 /mnt
>  # btrfs sub snapshot -r /mnt /mnt/snap1
>  # btrfs sub snapshot -r /mnt /mnt/snap2
>  # btrfs send /mnt/snap1 -p /mnt/snap2 -f /mnt/1
>  # dmesg
> 
> The problem is that we will sort clone roots(include @send_root), it
> might push @send_root before thus @send_root's @send_in_progress will
> be decreased twice.

Of course, the sort(). I think your fix adds some complexity that's not
necessary. Whether the clone_roots array is sorted is not important, we
just have to process each root once.

send_root becomes a clone_root member, so the missing part is to account
in the rollback counter:

---
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Wang Shilong Jan. 8, 2014, 3:09 p.m. UTC | #1
Hello David,

> On Tue, Jan 07, 2014 at 05:25:18PM +0800, Wang Shilong wrote:
>> Steps to reproduce:
>> # mkfs.btrfs -f /dev/sda8
>> # mount /dev/sda8 /mnt
>> # btrfs sub snapshot -r /mnt /mnt/snap1
>> # btrfs sub snapshot -r /mnt /mnt/snap2
>> # btrfs send /mnt/snap1 -p /mnt/snap2 -f /mnt/1
>> # dmesg
>> 
>> The problem is that we will sort clone roots(include @send_root), it
>> might push @send_root before thus @send_root's @send_in_progress will
>> be decreased twice.
> 
> Of course, the sort(). I think your fix adds some complexity that's not
> necessary. Whether the clone_roots array is sorted is not important, we
> just have to process each root once.
> 
> send_root becomes a clone_root member, so the missing part is to account
> in the rollback counter:
> 
> --- a/fs/btrfs/send.c
> +++ b/fs/btrfs/send.c
> @@ -4937,6 +4937,7 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_)
>         * for possible clone sources.
>         */
>        sctx->clone_roots[sctx->clone_roots_cnt++].root = sctx->send_root;
> +       clone_sources_to_rollback++;

Not really, If we fail to come here, we still need decrease @send_root.
Please correct me if i miss something here.^_^

Thanks,
Wang
> 
>        /* We do a bsearch later */
>        sort(sctx->clone_roots, sctx->clone_roots_cnt,
> @@ -4961,7 +4962,6 @@ out:
>                btrfs_root_dec_send_in_progress(sctx->clone_roots[i].root);
>        if (sctx && !IS_ERR_OR_NULL(sctx->parent_root))
>                btrfs_root_dec_send_in_progress(sctx->parent_root);
> -       btrfs_root_dec_send_in_progress(send_root);

> 
>        kfree(arg);
>        vfree(clone_sources_tmp);
> ---
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba Jan. 13, 2014, 6:40 p.m. UTC | #2
On Wed, Jan 08, 2014 at 11:09:02PM +0800, Wang Shilong wrote:
> 
> Hello David,
> 
> > On Tue, Jan 07, 2014 at 05:25:18PM +0800, Wang Shilong wrote:
> >> Steps to reproduce:
> >> # mkfs.btrfs -f /dev/sda8
> >> # mount /dev/sda8 /mnt
> >> # btrfs sub snapshot -r /mnt /mnt/snap1
> >> # btrfs sub snapshot -r /mnt /mnt/snap2
> >> # btrfs send /mnt/snap1 -p /mnt/snap2 -f /mnt/1
> >> # dmesg
> >> 
> >> The problem is that we will sort clone roots(include @send_root), it
> >> might push @send_root before thus @send_root's @send_in_progress will
> >> be decreased twice.
> > 
> > Of course, the sort(). I think your fix adds some complexity that's not
> > necessary. Whether the clone_roots array is sorted is not important, we
> > just have to process each root once.
> > 
> > send_root becomes a clone_root member, so the missing part is to account
> > in the rollback counter:
> > 
> > --- a/fs/btrfs/send.c
> > +++ b/fs/btrfs/send.c
> > @@ -4937,6 +4937,7 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_)
> >         * for possible clone sources.
> >         */
> >        sctx->clone_roots[sctx->clone_roots_cnt++].root = sctx->send_root;
> > +       clone_sources_to_rollback++;
> 
> Not really, If we fail to come here, we still need decrease @send_root.

Right. I was thinking if the code can be simplified somehow, but don't
have anything vastly better. Can you please add a comment to the first
branch that send_root is processed in the loop and not missed? It looks
unabalanced when it's handled just a few lines below and not in the 1st
loop.

thanks,
david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Wang Shilong Jan. 14, 2014, 11:52 a.m. UTC | #3
On 01/14/2014 02:40 AM, David Sterba wrote:
> On Wed, Jan 08, 2014 at 11:09:02PM +0800, Wang Shilong wrote:
>> Hello David,
>>
>>> On Tue, Jan 07, 2014 at 05:25:18PM +0800, Wang Shilong wrote:
>>>> Steps to reproduce:
>>>> # mkfs.btrfs -f /dev/sda8
>>>> # mount /dev/sda8 /mnt
>>>> # btrfs sub snapshot -r /mnt /mnt/snap1
>>>> # btrfs sub snapshot -r /mnt /mnt/snap2
>>>> # btrfs send /mnt/snap1 -p /mnt/snap2 -f /mnt/1
>>>> # dmesg
>>>>
>>>> The problem is that we will sort clone roots(include @send_root), it
>>>> might push @send_root before thus @send_root's @send_in_progress will
>>>> be decreased twice.
>>> Of course, the sort(). I think your fix adds some complexity that's not
>>> necessary. Whether the clone_roots array is sorted is not important, we
>>> just have to process each root once.
>>>
>>> send_root becomes a clone_root member, so the missing part is to account
>>> in the rollback counter:
>>>
>>> --- a/fs/btrfs/send.c
>>> +++ b/fs/btrfs/send.c
>>> @@ -4937,6 +4937,7 @@ long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_)
>>>          * for possible clone sources.
>>>          */
>>>         sctx->clone_roots[sctx->clone_roots_cnt++].root = sctx->send_root;
>>> +       clone_sources_to_rollback++;
>> Not really, If we fail to come here, we still need decrease @send_root.
> Right. I was thinking if the code can be simplified somehow, but don't
> have anything vastly better. Can you please add a comment to the first
> branch that send_root is processed in the loop and not missed? It looks
> unabalanced when it's handled just a few lines below and not in the 1st
> loop.
Reasonable, i will send v3 for this patch and add some comments.
David, really thanks for you costing time to review and correct me.^_^

Thanks,
Wang
>
> thanks,
> david
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

--- a/fs/btrfs/send.c
+++ b/fs/btrfs/send.c
@@ -4937,6 +4937,7 @@  long btrfs_ioctl_send(struct file *mnt_file, void __user *arg_)
         * for possible clone sources.
         */
        sctx->clone_roots[sctx->clone_roots_cnt++].root = sctx->send_root;
+       clone_sources_to_rollback++;

        /* We do a bsearch later */
        sort(sctx->clone_roots, sctx->clone_roots_cnt,
@@ -4961,7 +4962,6 @@  out:
                btrfs_root_dec_send_in_progress(sctx->clone_roots[i].root);
        if (sctx && !IS_ERR_OR_NULL(sctx->parent_root))
                btrfs_root_dec_send_in_progress(sctx->parent_root);
-       btrfs_root_dec_send_in_progress(send_root);

        kfree(arg);
        vfree(clone_sources_tmp);