From patchwork Sat Oct 30 00:07:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugo Mills X-Patchwork-Id: 291492 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o9U09h5b007090 for ; Sat, 30 Oct 2010 00:09:44 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762177Ab0J3AJg (ORCPT ); Fri, 29 Oct 2010 20:09:36 -0400 Received: from frost.carfax.org.uk ([212.13.194.111]:2452 "EHLO frost.carfax.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1762193Ab0J3AJe (ORCPT ); Fri, 29 Oct 2010 20:09:34 -0400 Received: from intmx.carfax.org.uk ([10.0.0.5] helo=vlad.carfax.org.uk ident=Debian-exim) by frost.carfax.org.uk with esmtp (Exim 4.69) (envelope-from ) id 1PBz0m-0000cM-TZ for linux-btrfs@vger.kernel.org; Sat, 30 Oct 2010 00:09:33 +0000 Received: from hrm by vlad.carfax.org.uk with local (Exim 4.72) (envelope-from ) id 1PBz0m-0003gt-Dc; Sat, 30 Oct 2010 01:09:32 +0100 Message-Id: <20101030000741.915844791@carfax.org.uk> User-Agent: quilt/0.48-1 Date: Sat, 30 Oct 2010 01:07:28 +0100 From: Hugo Mills To: linux-btrfs@vger.kernel.org Cc: Hugo Mills Subject: [patch 2/2] Cancel filesystem balance. References: <20101030000726.286517546@carfax.org.uk> Content-Disposition: inline; filename=cancel-balance X-frost.carfax.org.uk-Spam-Score: -0.0 (/) X-frost.carfax.org.uk-Spam-Report: Spam detection software, running on the system "spamd1.lon.bitfolk.com", has identified this incoming email as possible spam. The original message has been attached to this so you can view it (if it isn't spam) or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 [...] Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sat, 30 Oct 2010 00:09:44 +0000 (UTC) Index: linux-mainline/fs/btrfs/ctree.h =================================================================== --- linux-mainline.orig/fs/btrfs/ctree.h 2010-10-29 17:20:43.860460761 +0100 +++ linux-mainline/fs/btrfs/ctree.h 2010-10-29 17:24:06.622214467 +0100 @@ -806,6 +806,7 @@ struct btrfs_balance_info { u64 expected; u64 completed; + int cancel_pending; }; struct reloc_control; Index: linux-mainline/fs/btrfs/ioctl.c =================================================================== --- linux-mainline.orig/fs/btrfs/ioctl.c 2010-10-29 17:21:26.128742389 +0100 +++ linux-mainline/fs/btrfs/ioctl.c 2010-10-29 17:27:51.933043374 +0100 @@ -2016,6 +2016,29 @@ return ret; } +/* + * Cancel a running balance operation + */ +long btrfs_ioctl_balance_cancel(struct btrfs_fs_info *fs_info) +{ + int err = 0; + + 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) { @@ -2051,6 +2074,8 @@ 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: Index: linux-mainline/fs/btrfs/ioctl.h =================================================================== --- linux-mainline.orig/fs/btrfs/ioctl.h 2010-10-29 17:05:44.447028825 +0100 +++ linux-mainline/fs/btrfs/ioctl.h 2010-10-29 17:24:06.642213653 +0100 @@ -185,4 +185,5 @@ struct btrfs_ioctl_space_args) #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 21, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 22) #endif Index: linux-mainline/fs/btrfs/volumes.c =================================================================== --- linux-mainline.orig/fs/btrfs/volumes.c 2010-10-29 17:23:40.463279287 +0100 +++ linux-mainline/fs/btrfs/volumes.c 2010-10-29 17:24:06.652213246 +0100 @@ -1921,6 +1921,7 @@ bal_info->expected = -1; /* One less than actually counted, because chunk 0 is special */ bal_info->completed = 0; + bal_info->cancel_pending = 0; /* step one make some room on all the devices */ list_for_each_entry(device, devices, dev_list) { @@ -1983,7 +1984,7 @@ 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; @@ -2024,6 +2025,10 @@ 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);