From: Hugo Mills <hugo@carfax.org.uk> To: linux-btrfs@vger.kernel.org, Goffredo Baroncelli <kreijack@libero.it>, Chris Mason <chris.mason@oracle.com>, liubo <liubo2009@cn.fujitsu.com> Subject: [PATCH v2 2/2] Cancel filesystem balance. Date: Tue, 9 Nov 2010 22:52:59 +0000 Message-ID: <9b18b334410714aba2867f96e949f19243536ddc.1289522188.git.hugo@carfax.org.uk> (raw) In-Reply-To: <cover.1289522188.git.hugo@carfax.org.uk> This patch adds an ioctl for cancelling a btrfs balance operation mid-flight. The ioctl simply sets a flag, and the operation terminates after the current block group move has completed. Signed-off-by: Hugo Mills <hugo@carfax.org.uk> --- fs/btrfs/ctree.h | 1 + fs/btrfs/ioctl.c | 28 ++++++++++++++++++++++++++++ fs/btrfs/ioctl.h | 3 ++- fs/btrfs/volumes.c | 7 ++++++- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 67fb603..5fa7163 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -844,6 +844,7 @@ struct btrfs_block_group_cache { struct btrfs_balance_info { u64 expected; u64 completed; + int cancel_pending; }; struct reloc_control; diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index c247985..7e38856 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2252,6 +2252,32 @@ error: return ret; } +/* + * Cancel a running balance operation + */ +long btrfs_ioctl_balance_cancel(struct btrfs_fs_info *fs_info) +{ + int err = 0; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + spin_lock(&fs_info->balance_info_lock); + if(!fs_info->balance_info) { + err = -EINVAL; + goto error; + } + if(fs_info->balance_info->cancel_pending) { + err = -ECANCELED; + goto error; + } + fs_info->balance_info->cancel_pending = 1; + +error: + spin_unlock(&fs_info->balance_info_lock); + return err; +} + long btrfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { @@ -2289,6 +2315,8 @@ long btrfs_ioctl(struct file *file, unsigned int return btrfs_balance(root->fs_info->dev_root); case BTRFS_IOC_BALANCE_PROGRESS: return btrfs_ioctl_balance_progress(root->fs_info, argp); + case BTRFS_IOC_BALANCE_CANCEL: + return btrfs_ioctl_balance_cancel(root->fs_info); case BTRFS_IOC_CLONE: return btrfs_ioctl_clone(file, arg, 0, 0, 0); case BTRFS_IOC_CLONE_RANGE: diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h index b2103b2..76ae121 100644 --- a/fs/btrfs/ioctl.h +++ b/fs/btrfs/ioctl.h @@ -195,5 +195,6 @@ struct btrfs_ioctl_balance_progress { #define BTRFS_IOC_SNAP_CREATE_ASYNC _IOW(BTRFS_IOCTL_MAGIC, 23, \ struct btrfs_ioctl_async_vol_args) #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 25, \ - struct btrfs_ioctl_balance_progress) + struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 26) #endif diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index f00edc1..64b2f04 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1924,6 +1924,7 @@ int btrfs_balance(struct btrfs_root *dev_root) bal_info->expected = -1; /* One less than actually counted, because chunk 0 is special */ bal_info->completed = 0; + bal_info->cancel_pending = 0; spin_unlock(&dev_root->fs_info->balance_info_lock); /* step one make some room on all the devices */ @@ -1989,7 +1990,7 @@ int btrfs_balance(struct btrfs_root *dev_root) key.offset = (u64)-1; key.type = BTRFS_CHUNK_ITEM_KEY; - while (1) { + while (!bal_info->cancel_pending) { ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0); if (ret < 0) goto error; @@ -2029,6 +2030,10 @@ int btrfs_balance(struct btrfs_root *dev_root) bal_info->completed, bal_info->expected); } ret = 0; + if(bal_info->cancel_pending) { + printk(KERN_INFO "btrfs: balance cancelled\n"); + ret = -EINTR; + } error: btrfs_free_path(path); spin_lock(&dev_root->fs_info->balance_info_lock); -- 1.7.1
next prev parent reply index Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2010-11-12 0:36 [PATCH v2 0/2] Balance management, kernel side Hugo Mills 2010-11-09 22:43 ` [PATCH v2 1/2] Balance progress monitoring Hugo Mills 2010-11-09 22:52 ` Hugo Mills [this message] 2010-11-12 1:33 ` [PATCH v2 2/2] Cancel filesystem balance Li Zefan 2010-11-12 4:28 ` Chris Samuel 2010-11-12 8:08 ` Helmut Hullen 2010-11-12 9:07 ` Sander 2010-11-12 9:26 ` Andreas Philipp 2010-11-12 11:25 ` Helmut Hullen 2010-11-12 12:04 ` Sander 2010-11-12 11:36 ` Hugo Mills 2010-11-12 17:59 ` Hugo Mills 2011-03-20 8:52 ` [PATCH v2 0/2] Balance management, kernel side Andreas Philipp 2011-03-20 11:37 ` Hugo Mills
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=9b18b334410714aba2867f96e949f19243536ddc.1289522188.git.hugo@carfax.org.uk \ --to=hugo@carfax.org.uk \ --cc=chris.mason@oracle.com \ --cc=kreijack@libero.it \ --cc=linux-btrfs@vger.kernel.org \ --cc=liubo2009@cn.fujitsu.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
Linux-BTRFS Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/linux-btrfs/0 linux-btrfs/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 linux-btrfs linux-btrfs/ https://lore.kernel.org/linux-btrfs \ linux-btrfs@vger.kernel.org public-inbox-index linux-btrfs Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.linux-btrfs AGPL code for this site: git clone https://public-inbox.org/public-inbox.git