Re: [PATCH] btrfs: fix warn_on for send from readonly mount

Nikolay Borisov
2019-12-02T09:48:23Z

On 2.12.19 г. 11:44 ч., Anand Jain wrote:
> We log warning if root::orphan_cleanup_state is not set to
> ORPHAN_CLEANUP_DONE in btrfs_ioctl_send(). However if the filesystem is
> mounted as readonly we skip the orphan items cleanup during the lookup
> and root::orphan_cleanup_state remains at the init state 0 instead of
> ORPHAN_CLEANUP_DONE (2).
>
> WARNING: CPU: 0 PID: 2616 at /Volumes/ws/btrfs-devel/fs/btrfs/send.c:7090 btrfs_ioctl_send+0xb2f/0x18c0 [btrfs]
> ::
> RIP: 0010:btrfs_ioctl_send+0xb2f/0x18c0 [btrfs]
> ::
> Call Trace:
> ::
> _btrfs_ioctl_send+0x7b/0x110 [btrfs]
> btrfs_ioctl+0x150a/0x2b00 [btrfs]
> ::
> do_vfs_ioctl+0xa9/0x620
> ? __fget+0xac/0xe0
> ksys_ioctl+0x60/0x90
> __x64_sys_ioctl+0x16/0x20
> do_syscall_64+0x49/0x130
> entry_SYSCALL_64_after_hwframe+0x44/0xa9
>
> Reproducer:
> mkfs.btrfs -fq /dev/sdb && mount /dev/sdb /btrfs
> btrfs subvolume create /btrfs/sv1
> btrfs subvolume snapshot -r /btrfs/sv1 /btrfs/ss1
> umount /btrfs && mount -o ro /dev/sdb /btrfs
> btrfs send /btrfs/ss1 -f /tmp/f
>
> Fix this by checking for the expected ORPHAN_CLEANUP_DONE only if the
> filesystem is in writable state.
>
> Reported-by: Christoph Anton Mitterer <calestyo@scientia.net>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> fs/btrfs/send.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/send.c b/fs/btrfs/send.c
> index ae2db5eb1549..e3acec8aa8de 100644
> --- a/fs/btrfs/send.c
> +++ b/fs/btrfs/send.c
> @@ -7085,9 +7085,11 @@ long btrfs_ioctl_send(struct file *mnt_file, struct btrfs_ioctl_send_args *arg)
>
> /*
> * This is done when we lookup the root, it should already be complete
> - * by the time we get here.
> + * by the time we get here, unless the filesystem is readonly where the
> + * orphan_cleanup_state is never started.
> */
> - WARN_ON(send_root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE);
> + if (!sb_rdonly(file_inode(mnt_file)->i_sb))
> + WARN_ON(send_root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE);

nit: WARN_ON(!sb_rdonly() && send_root->orphan_cleanup_state != ORPHAN_CLEANUP_DONE) ?

>
> /*
> * Userspace tools do the checks and warn the user if it's
>