Re: [PATCHv2] btrfs: Introduce new BTRFS_IOC_SNAP_DESTROY_V2 ioctl

From: David Sterba
Date: Wed Jan 29 2020 - 11:12:38 EST


On Wed, Jan 29, 2020 at 12:07:40PM -0300, Marcos Paulo de Souza wrote:
> > > - vol_args->name[BTRFS_PATH_NAME_MAX] = '\0';
> > > - namelen = strlen(vol_args->name);
> > > - if (strchr(vol_args->name, '/') ||
> > > - strncmp(vol_args->name, "..", namelen) == 0) {
> > > - err = -EINVAL;
> > > - goto out;
> > > + if (!(vol_args2->flags & BTRFS_SUBVOL_BY_ID)) {
> > > + err = -EINVAL;
> > > + goto out;
> >
> > The flag validation needs to be factored out of the if. First
> > validate,
> > then do the rest. For backward compatibility, the v1 ioctl must take
> > no
> > flags, so if theres BTRFS_SUBVOL_BY_ID for v1, it needs to fail. For
> > v2
> > the flag is optional.
>
> Only vol_args_v2 has the flags field, so for current
> BTRFS_IOC_SNAP_DESTORY there won't be any flags. If we drop the check
> for BTRFS_SUBVOL_BY_ID in BTRFS_IOC_SNAP_DESTORY_V2, so won't check for
> this flag at all, making it meaningless.

Oh right, so the validation applies only to v2 and in that case it's
fine to keep it in the place you have it.

> What do you think? Should we drop this flag at all and just rely in the
> ioctl number + subvolid being informed?

No, v2 should work for both deletion by name and by id. It's going to
supersede v1 that has to stay for backward compatibility, but must
provide complete functionality of v1 to keep the usability sane.