From: Eric Sandeen <sandeen@redhat.com>
To: David Sterba <dsterba@suse.cz>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs: add cancellation points to defrag
Date: Mon, 11 Feb 2013 10:59:54 -0600 [thread overview]
Message-ID: <5119238A.9080306@redhat.com> (raw)
In-Reply-To: <1360453086-10683-1-git-send-email-dsterba@suse.cz>
On 2/9/13 5:38 PM, David Sterba wrote:
> The defrag operation can take very long, we want to have a way how to
> cancel it. The code checks for a pending signal at safe points in the
> defrag loops and returns EAGAIN. This means a user can press ^C after
> running 'btrfs fi defrag', woks for both defrag modes, files and root.
>
> Returning from the command was instant in my light tests, but may take
> longer depending on the aging factor of the filesystem.
When __btrfs_run_defrag_inode() calls btrfs_defrag_file() and gets
-EAGAIN back due to the cancellation, will it reset the defrag->
counters and call btrfs_requeue_inode_defrag()? Is that ok?
Should __btrfs_run_defrag_inode explicitly check for and handle
an actual error returned to it?
Thanks,
-Eric
> Signed-off-by: David Sterba <dsterba@suse.cz>
> ---
> fs/btrfs/ctree.h | 7 +++++++
> fs/btrfs/ioctl.c | 6 ++++++
> fs/btrfs/transaction.c | 6 ++++++
> 3 files changed, 19 insertions(+), 0 deletions(-)
>
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index 547b7b0..4b41d7c 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -3745,4 +3745,11 @@ static inline int is_fstree(u64 rootid)
> return 1;
> return 0;
> }
> +
> +static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
> +{
> + return signal_pending(current);
> +}
> +
> +
> #endif
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 338f259..78a5580 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1206,6 +1206,12 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
> if (!(inode->i_sb->s_flags & MS_ACTIVE))
> break;
>
> + if (btrfs_defrag_cancelled(root->fs_info)) {
> + printk(KERN_DEBUG "btrfs: defrag_file cancelled\n");
> + ret = -EAGAIN;
> + break;
> + }
> +
> if (!should_defrag_range(inode, (u64)i << PAGE_CACHE_SHIFT,
> extent_thresh, &last_len, &skip,
> &defrag_end, range->flags &
> diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
> index fc03aa6..2c509c4 100644
> --- a/fs/btrfs/transaction.c
> +++ b/fs/btrfs/transaction.c
> @@ -986,6 +986,12 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly)
>
> if (btrfs_fs_closing(root->fs_info) || ret != -EAGAIN)
> break;
> +
> + if (btrfs_defrag_cancelled(root->fs_info)) {
> + printk(KERN_DEBUG "btrfs: defrag_root cancelled\n");
> + ret = -EAGAIN;
> + break;
> + }
> }
> root->defrag_running = 0;
> return ret;
>
next prev parent reply other threads:[~2013-02-11 17:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-09 23:38 [PATCH] btrfs: add cancellation points to defrag David Sterba
2013-02-11 16:59 ` Eric Sandeen [this message]
2013-02-11 17:45 ` David Sterba
2013-02-11 17:48 ` Eric Sandeen
2013-02-11 18:14 ` 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=5119238A.9080306@redhat.com \
--to=sandeen@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.