linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Filipe Manana <fdmanana@gmail.com>
To: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
Cc: linux-kernel@vger.kernel.org, Chris Mason <clm@fb.com>,
	Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>,
	linux-btrfs <linux-btrfs@vger.kernel.org>,
	mpdesouza@suse.com
Subject: Re: [PATCH 4/5] btrfs: ctree.h: Add btrfs_is_snapshot function
Date: Fri, 25 Oct 2019 11:02:33 +0100	[thread overview]
Message-ID: <CAL3q7H63xK8DP84gUFjuK02tsUt_RX_R310Gdw6wjA6FD5rbwA@mail.gmail.com> (raw)
In-Reply-To: <20191024023636.21124-5-marcos.souza.org@gmail.com>

On Thu, Oct 24, 2019 at 7:56 PM Marcos Paulo de Souza
<marcos.souza.org@gmail.com> wrote:
>
> From: Marcos Paulo de Souza <mpdesouza@suse.com>
>
> This new function takes a btrfs_root as argument, and returns true is
> root_key.offset is bigger than 0, meaning that this tree is a snapshot.
>
> This new function will be used by the next patch.
>
> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
> ---
>  fs/btrfs/ctree.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 19d669d12ca1..8502e9082914 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -3411,6 +3411,20 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
>         return signal_pending(current);
>  }
>
> +/*
> + * btrfs_is_snapshot() - Verify is a tree is a snapshot
> + * @root: btrfs_root
> + *
> + * When the key.offset field of btrfs_root is bigger than 0 it means the referred
> + * tree is a snapshot.
> + *
> + * Returns true if @root refers to a snapshot.
> + */
> +static inline bool btrfs_is_snapshot(struct btrfs_root *root)
> +{
> +       return root->root_key.offset > 0;

So this is not true for all roots. For log roots and relocation roots
for example, which are not snapshots,
the offset corresponds to the objectid of the root they are associated to.
So this isn't generic enough to have in ctree.h, and will create
confusion or potential bugs if anyone tries to use it in the future.

Since you only use this function in a later patch at the
subvolume/deletion ioctl, I would suggest using this directly in that
code only,
as there this assumption is true, since user space can't reference a
log or relocation tree in the ioctl call.

Thanks.


> +}
> +
>  #define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
>
>  /* Sanity test specific functions */
> --
> 2.23.0
>


-- 
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”

  reply	other threads:[~2019-10-25 10:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24  2:36 [PATCH 0/5] btrfs: send uevent on subvolume add/remove Marcos Paulo de Souza
2019-10-24  2:36 ` [PATCH 1/5] btrfs: sysfs: Add envp argument to btrfs_kobject_uevent Marcos Paulo de Souza
2019-10-24  2:36 ` [PATCH 2/5] btrfs: ioctl: Introduce btrfs_vol_uevent Marcos Paulo de Souza
2019-10-24  2:36 ` [PATCH 3/5] btrfs: ioctl: Call btrfs_vol_uevent on subvol creation Marcos Paulo de Souza
2019-10-24  2:36 ` [PATCH 4/5] btrfs: ctree.h: Add btrfs_is_snapshot function Marcos Paulo de Souza
2019-10-25 10:02   ` Filipe Manana [this message]
2019-10-24  2:36 ` [PATCH 5/5] btrfs: ioctl: Call btrfs_vol_uevent on subvolume deletion Marcos Paulo de Souza
2019-10-25 12:00   ` Graham Cobb
2019-10-25 15:44     ` Marcos Paulo de Souza
2019-11-18 20:50 ` [PATCH 0/5] btrfs: send uevent on subvolume add/remove David Sterba

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=CAL3q7H63xK8DP84gUFjuK02tsUt_RX_R310Gdw6wjA6FD5rbwA@mail.gmail.com \
    --to=fdmanana@gmail.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcos.souza.org@gmail.com \
    --cc=mpdesouza@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;
as well as URLs for NNTP newsgroup(s).