Balance management
v6 cover Balance management
Hi, Chris,
One more round of the balance management patches. There's very
little changed from last time -- a compilation issue spotted by David, two minor checkpatch failures, and a re-spin against the latest btrfs-unstable. Could you consider these patches for 2.6.40, please?
Hugo.
Hugo Mills (8):
btrfs: Balance progress monitoring
btrfs: Cancel filesystem balance
btrfs: Factor out enumeration of chunks to a separate function
btrfs: Implement filtered balance ioctl
btrfs: Balance filter for device ID
btrfs: Balance filter for virtual address ranges
btrfs: Replication-type information
btrfs: Balance filter for physical device address
fs/btrfs/ctree.h | 10 ++ fs/btrfs/disk-io.c | 2 + fs/btrfs/ioctl.c | 104 +++++++++++++++- fs/btrfs/ioctl.h | 49 +++++++ fs/btrfs/super.c | 16 +-- fs/btrfs/volumes.c | 354 +++++++++++++++++++++++++++++++++++++++++----------- fs/btrfs/volumes.h | 21 +++- 7 files changed, 468 insertions(+), 88 deletions(-)
Signature · 1 line
1.7.2.5
PATCH v6 1/8 btrfs: Balance progress monitoring
This patch introduces a basic form of progress monitoring for balance operations, by counting the number of block groups remaining. The information is exposed to userspace by an ioctl.
--- fs/btrfs/ctree.h | 9 ++++++++ fs/btrfs/disk-io.c | 2 + fs/btrfs/ioctl.c | 34 +++++++++++++++++++++++++++++++ fs/btrfs/ioctl.h | 7 ++++++ fs/btrfs/volumes.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 106 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +9 -0
@@ -866,6 +866,11 @@ struct btrfs_block_group_cache {struct list_head cluster_list; }; +struct btrfs_balance_info { +u32 expected; +u32 completed; +}; +struct reloc_control ;struct btrfs_device ;struct btrfs_fs_devices ;
@@ -1079,6 +1084,10 @@ struct btrfs_fs_info {/* filesystem state */ u64 fs_state; + +/* Keep track of any rebalance operations on this FS */ +spinlock_t balance_info_lock; +struct btrfs_balance_info *balance_info; };/*
fs/btrfs/disk-io.c +2 -0
@@ -1741,6 +1741,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,spin_lock_init (&fs_info->ref_cache_lock);spin_lock_init (&fs_info->fs_roots_radix_lock);spin_lock_init (&fs_info->delayed_iput_lock); +spin_lock_init (&fs_info->balance_info_lock);init_completion (&fs_info->kobj_unregister); fs_info->tree_root = tree_root;
@@ -1766,6 +1767,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, fs_info->sb = sb; fs_info->max_inline =8192 *1024 ; fs_info->metadata_ratio =0 ; + fs_info->balance_info =NULL ; fs_info->thread_pool_size = min_t(unsigned long,num_online_cpus () +2 ,8 );
fs/btrfs/ioctl.c +34 -0
@@ -2465,6 +2465,38 @@ static noinline long btrfs_ioctl_wait_sync(struct file *file, void __user *argp)return btrfs_wait_for_commit (root, transid); } +/* +* Return the current status of any balance operation +*/ +long btrfs_ioctl_balance_progress ( +struct btrfs_fs_info *fs_info, +struct btrfs_ioctl_balance_progress __user *user_dest) +{ +int ret =0 ; +struct btrfs_ioctl_balance_progress dest; + +spin_lock (&fs_info->balance_info_lock); +if (!fs_info->balance_info) { + ret = -EINVAL ; + goto error; + } + + dest.expected = fs_info->balance_info->expected; + dest.completed = fs_info->balance_info->completed; + +spin_unlock (&fs_info->balance_info_lock); + +if (copy_to_user (user_dest, &dest, +sizeof (struct btrfs_ioctl_balance_progress ))) +return -EFAULT ; + +return 0 ; + +error: +spin_unlock (&fs_info->balance_info_lock); +return ret; +} +long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {
@@ -2506,6 +2538,8 @@ long btrfs_ioctl(struct file *file, unsigned intreturn btrfs_ioctl_rm_dev (root, argp);case BTRFS_IOC_BALANCE :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_CLONE :return btrfs_ioctl_clone (file, arg,0 ,0 ,0 );case BTRFS_IOC_CLONE_RANGE :
fs/btrfs/ioctl.h +7 -0
@@ -157,6 +157,11 @@ struct btrfs_ioctl_space_args {struct btrfs_ioctl_space_info spaces[0 ]; }; +struct btrfs_ioctl_balance_progress { +__u32 expected; +__u32 completed; +}; +#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args)#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -203,4 +208,6 @@ struct btrfs_ioctl_space_args { struct btrfs_ioctl_vol_args_v2)#define BTRFS_IOC_SUBVOL_GETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 25, __u64)#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64) +#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ + struct btrfs_ioctl_balance_progress)#endif
fs/btrfs/volumes.c +54 -2
86 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v6 2/8 btrfs: Cancel filesystem balance
In reply to Hugo MillsThis 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.
--- fs/btrfs/ctree.h | 1 + fs/btrfs/ioctl.c | 28 ++++++++++++++++++++++++++++ fs/btrfs/ioctl.h | 1 + fs/btrfs/volumes.c | 7 ++++++- 4 files changed, 36 insertions(+), 1 deletions(-)
fs/btrfs/ctree.h +1 -0
@@ -869,6 +869,7 @@ struct btrfs_block_group_cache {struct btrfs_balance_info {u32 expected;u32 completed; +int cancel_pending; };struct reloc_control ;
fs/btrfs/ioctl.c +28 -0
@@ -2497,6 +2497,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) {
@@ -2540,6 +2566,8 @@ long btrfs_ioctl(struct file *file, unsigned intreturn 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 :
fs/btrfs/ioctl.h +1 -0
@@ -210,4 +210,5 @@ struct btrfs_ioctl_balance_progress {#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ struct btrfs_ioctl_balance_progress) +#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)#endif
fs/btrfs/volumes.c +6 -1
@@ -2055,6 +2055,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 */
@@ -2115,7 +2116,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;
@@ -2155,6 +2156,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);
Signature · 1 line
1.7.2.5
Re: [PATCH v6 2/8] btrfs: Cancel filesystem balance
Hi,
I was thinking about the EINTR or ECANCELED retcode from balance:
CANCELED is returned from ioctl call if a cancel has been already requested
EINTR is returned from btrfs_balance after all the processing if the cancel_request is set.
I don't see a reason to have 2 retcodes here, how will this help the ioctl caller?
david
Quoted 15 lines · Hugo Mills
fs/btrfs/ioctl.c +7
-0@@ -2497,6 +2497,32 @@ error:return ret; } +/* +* Cancel a running balance operation +*/ +long btrfs_ioctl_balance_cancel (struct btrfs_fs_info *fs_info) +{ +int err =0 ; +
fs/btrfs/ioctl.c error: · line 2516
Quoted 10 lines
fs/btrfs/ioctl.c +10
-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 ;
^^^^^^^^^
Quoted 17 lines
fs/btrfs/ioctl.c +9
-0+ 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) {fs/btrfs/volumes.c +0
-0
fs/btrfs/volumes.c int btrfs_balance(struct btrfs_root *dev_root) · line 2161
Quoted 6 lines
fs/btrfs/volumes.c +3
-0@@ -2155,6 +2156,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 ;
^^^^^
Quoted 4 lines
fs/btrfs/volumes.c +1
-0+ } error:btrfs_free_path (path);spin_lock (&dev_root->fs_info->balance_info_lock);
PATCH v6 3/8 btrfs: Factor out enumeration of chunks to a separate function
In reply to Hugo MillsThe main balance function has two loops which are functionally identical in their looping mechanism, but which perform a different operation on the chunks they loop over. To avoid repeating code more than necessary, factor this loop out into a separate iterator function which takes a function parameter for the action to be performed.
--- fs/btrfs/volumes.c | 174 +++++++++++++++++++++++++++++---------------------- 1 files changed, 99 insertions(+), 75 deletions(-)
fs/btrfs/volumes.c +99 -75
@@ -2020,6 +2020,97 @@ static u64 div_factor(u64 num, int factor)return num; } +/* Define a type, and two functions which can be used for the two +* phases of the balance operation: one for counting chunks, and one +* for actually moving them. */ +typedef void (*balance_iterator_function )(struct btrfs_root *, +struct btrfs_balance_info *, +struct btrfs_path *, +struct btrfs_key *); + +static void balance_count_chunks (struct btrfs_root *chunk_root, +struct btrfs_balance_info *bal_info, +struct btrfs_path *path, +struct btrfs_key *key) +{ +spin_lock (&chunk_root->fs_info->balance_info_lock); + bal_info->expected++; +spin_unlock (&chunk_root->fs_info->balance_info_lock); +} + +static void balance_move_chunks (struct btrfs_root *chunk_root, +struct btrfs_balance_info *bal_info, +struct btrfs_path *path, +struct btrfs_key *key) +{ +int ret; + + ret =btrfs_relocate_chunk (chunk_root, + chunk_root->root_key.objectid, + key->objectid, + key->offset); +BUG_ON (ret && ret != -ENOSPC ); +spin_lock (&chunk_root->fs_info->balance_info_lock); + bal_info->completed++; +spin_unlock (&chunk_root->fs_info->balance_info_lock); +printk (KERN_INFO "btrfs: balance: %u/%u block groups completed\n" , + bal_info->completed, bal_info->expected); +} + +/* Iterate through all chunks, performing some function on each one. */ +static int balance_iterate_chunks (struct btrfs_root *chunk_root, +struct btrfs_balance_info *bal_info, +balance_iterator_function iterator_fn) +{ +int ret =0 ; +struct btrfs_path *path; +struct btrfs_key key; +struct btrfs_key found_key; + + path =btrfs_alloc_path (); +if (!path) +return -ENOMEM ; + + key.objectid =BTRFS_FIRST_CHUNK_TREE_OBJECTID ; + key.offset = (u64)-1 ; + key.type =BTRFS_CHUNK_ITEM_KEY ; + +while (!bal_info->cancel_pending) { + ret =btrfs_search_slot (NULL , chunk_root, &key, path,0 ,0 ); +if (ret <0 ) +break ; +/* +* this shouldn't happen, it means the last relocate +* failed +*/ +if (ret ==0 ) +break ; + + ret =btrfs_previous_item (chunk_root, path,0 , +BTRFS_CHUNK_ITEM_KEY ); +if (ret) +break ; + +btrfs_item_key_to_cpu (path->nodes[0 ], &found_key, + path->slots[0 ]); +if (found_key.objectid != key.objectid) +break ; + +/* chunk zero is special */ +if (found_key.offset ==0 ) +break ; + +/* Call the function to do the work for this chunk */ +btrfs_release_path (chunk_root, path); +iterator_fn (chunk_root, bal_info, path, &found_key); + + key.offset = found_key.offset -1 ; + } + +btrfs_free_path (path); +return ret; +} +int btrfs_balance (struct btrfs_root *dev_root) {int ret;
@@ -2027,11 +2118,8 @@ int btrfs_balance(struct btrfs_root *dev_root)struct btrfs_device *device;u64 old_size;u64 size_to_free; -struct btrfs_path *path; -struct btrfs_key key;struct btrfs_root *chunk_root = dev_root->fs_info->chunk_root;struct btrfs_trans_handle *trans; -struct btrfs_key found_key;struct btrfs_balance_info *bal_info;if (dev_root->fs_info->sb->s_flags &MS_RDONLY )
@@ -2052,8 +2140,7 @@ int btrfs_balance(struct btrfs_root *dev_root) }spin_lock (&dev_root->fs_info->balance_info_lock); dev_root->fs_info->balance_info = bal_info; - bal_info->expected =-1 ;/* One less than actually counted, -because chunk 0 is special */ + bal_info->expected =0 ; bal_info->completed =0 ; bal_info->cancel_pending =0 ;spin_unlock (&dev_root->fs_info->balance_info_lock);
@@ -2082,86 +2169,23 @@ int btrfs_balance(struct btrfs_root *dev_root) }/* step two, count the chunks */ - path =btrfs_alloc_path (); -if (!path) { - ret = -ENOMEM ; + ret =balance_iterate_chunks (chunk_root, bal_info, + balance_count_chunks); +if (ret) goto error; - } - - key.objectid =BTRFS_FIRST_CHUNK_TREE_OBJECTID ; - key.offset = (u64)-1 ; - key.type =BTRFS_CHUNK_ITEM_KEY ; - - ret =btrfs_search_slot (NULL , chunk_root, &key, path,0 ,0 ); -if (ret <=0 ) { -printk (KERN_ERR "btrfs: Failed to find the last chunk.\n" ); -BUG (); - } - -while (1 ) { - ret =btrfs_previous_item (chunk_root, path,0 , -BTRFS_CHUNK_ITEM_KEY ); -if (ret) -break ; - -spin_lock (&dev_root->fs_info->balance_info_lock); - bal_info->expected++; -spin_unlock (&dev_root->fs_info->balance_info_lock); - } - -btrfs_release_path (chunk_root, path);/* step three, relocate all the chunks */ - key.objectid =BTRFS_FIRST_CHUNK_TREE_OBJECTID ; - key.offset = (u64)-1 ; - key.type =BTRFS_CHUNK_ITEM_KEY ; - -while (!bal_info->cancel_pending) { - ret =btrfs_search_slot (NULL , chunk_root, &key, path,0 ,0 ); -if (ret <0 ) - goto error; - -/* -* this shouldn't happen, it means the last relocate -* failed -*/ -if (ret ==0 ) -break ; - - ret =btrfs_previous_item (chunk_root, path,0 , -BTRFS_CHUNK_ITEM_KEY ); -if (ret) -break ; - -btrfs_item_key_to_cpu (path->nodes[0 ], &found_key, - path->slots[0 ]); -if (found_key.objectid != key.objectid) -break ; - -/* chunk zero is special */ -if (found_key.offset ==0 ) -break ; + ret =balance_iterate_chunks (chunk_root, bal_info, + balance_move_chunks); +if (ret) + goto error; -btrfs_release_path (chunk_root, path); - ret =btrfs_relocate_chunk (chunk_root, - chunk_root->root_key.objectid, - found_key.objectid, - found_key.offset); -BUG_ON (ret && ret != -ENOSPC ); - key.offset = found_key.offset -1 ; -spin_lock (&dev_root->fs_info->balance_info_lock); - bal_info->completed++; -spin_unlock (&dev_root->fs_info->balance_info_lock); -printk (KERN_INFO "btrfs: balance: %u/%u block groups completed\n" , - 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);kfree (dev_root->fs_info->balance_info); dev_root->fs_info->balance_info =NULL ;
Signature · 1 line
1.7.2.5
PATCH v6 4/8 btrfs: Implement filtered balance ioctl
In reply to Hugo MillsThe filtered balance ioctl provides a facility to perform a balance operation on a subset of the chunks in the filesystem. This patch implements the base ioctl for this operation, and one filter type. The filter in this patch selects chunks on the basis of their chunk flags field, and can select any combination of bits set or unset.
--- fs/btrfs/ioctl.c | 42 +++++++++++++++++++++++++++++++++- fs/btrfs/ioctl.h | 27 ++++++++++++++++++++++ fs/btrfs/volumes.c | 64 +++++++++++++++++++++++++++++++++++++++++++++------ fs/btrfs/volumes.h | 4 ++- 4 files changed, 127 insertions(+), 10 deletions(-)
fs/btrfs/ioctl.c +41 -1
@@ -2523,6 +2523,44 @@ error:return err; } +long btrfs_ioctl_balance (struct btrfs_root *dev_root, +struct btrfs_ioctl_balance_start __user *user_filters) +{ +int ret =0 ; +struct btrfs_ioctl_balance_start *dest; + + dest =kmalloc (sizeof (struct btrfs_ioctl_balance_start ),GFP_KERNEL ); +if (!dest) +return -ENOMEM ; + +if (copy_from_user (dest, user_filters, +sizeof (struct btrfs_ioctl_balance_start ))) { + ret = -EFAULT ; + goto error; + } + +/* Basic sanity checking: has the user requested anything outside +* the range we know about? */ +if (dest->flags & ~BTRFS_BALANCE_FILTER_MASK ) { + ret = -ENOTSUPP ; + goto error; + } + +/* Do the balance */ + ret =btrfs_balance (dev_root, dest); +if (ret) + goto error; + +if (copy_to_user (user_filters, dest, +sizeof (struct btrfs_ioctl_balance_start ))) { + ret = -EFAULT ; + } + +error: +kfree (dest); +return ret; +} +long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg) {
@@ -2563,11 +2601,13 @@ long btrfs_ioctl(struct file *file, unsigned intcase BTRFS_IOC_RM_DEV :return btrfs_ioctl_rm_dev (root, argp);case BTRFS_IOC_BALANCE : -return btrfs_balance (root->fs_info->dev_root); +return btrfs_ioctl_balance (root->fs_info->dev_root,NULL );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_BALANCE_FILTERED : +return btrfs_ioctl_balance (root->fs_info->dev_root, argp);case BTRFS_IOC_CLONE :return btrfs_ioctl_clone (file, arg,0 ,0 ,0 );case BTRFS_IOC_CLONE_RANGE :
fs/btrfs/ioctl.h +27 -0
@@ -162,6 +162,31 @@ struct btrfs_ioctl_balance_progress {__u32 completed; }; +/* Types of balance filter */ +#define BTRFS_BALANCE_FILTER_COUNT_ONLY (1 << 0) + +#define BTRFS_BALANCE_FILTER_CHUNK_TYPE (1 << 1) +#define BTRFS_BALANCE_FILTER_MASK ((1 << 2) - 1)/* Logical or of all filter +* flags -- effectively versions +* the filtered balance ioctl */ + +/* All the possible options for a filter */ +struct btrfs_ioctl_balance_start { +__u64 flags;/* Bit field indicating which fields of this struct +are filled */ + +/* Output values: chunk counts */ +__u32 examined; +__u32 balanced; + +/* For FILTER_CHUNK_TYPE */ +__u64 chunk_type;/* Flag bits required */ +__u64 chunk_type_mask;/* Mask of bits to examine */ + +__u64 spare[507 ];/* Make up the size of the structure to 4088 +* bytes for future expansion */ +}; +#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ struct btrfs_ioctl_vol_args)#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
@@ -211,4 +236,6 @@ struct btrfs_ioctl_balance_progress {#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 27, \ struct btrfs_ioctl_balance_progress)#define BTRFS_IOC_BALANCE_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28) +#define BTRFS_IOC_BALANCE_FILTERED _IOWR(BTRFS_IOCTL_MAGIC, 29, \ + struct btrfs_ioctl_balance_start)#endif
fs/btrfs/volumes.c +56 -8
106 lines not on this page · raw message
fs/btrfs/volumes.h +3 -1
@@ -22,6 +22,7 @@#include <linux/bio.h> #include <linux/sort.h> #include "async-thread.h" +#include "ioctl.h" #define BTRFS_STRIPE_LEN (64 * 1024)
@@ -217,7 +218,8 @@ struct btrfs_device *btrfs_find_device(struct btrfs_root *root, u64 devid, u8 *uuid, u8 *fsid);int btrfs_shrink_device (struct btrfs_device *device,u64 new_size);int btrfs_init_new_device (struct btrfs_root *root,char *path); -int btrfs_balance (struct btrfs_root *dev_root); +int btrfs_balance (struct btrfs_root *dev_root, +struct btrfs_ioctl_balance_start *filters);void btrfs_unlock_volumes (void );void btrfs_lock_volumes (void );int btrfs_chunk_readonly (struct btrfs_root *root,u64 chunk_offset);
Signature · 1 line
1.7.2.5
PATCH v6 5/8 btrfs: Balance filter for device ID
In reply to Hugo MillsBalance filter to take only chunks which have (or had) a stripe on the given device. Useful if a device has been forcibly removed from the filesystem, and the data from that device needs rebuilding.
--- fs/btrfs/ioctl.h | 8 ++++++-- fs/btrfs/volumes.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-)
fs/btrfs/ioctl.h +6 -2
@@ -166,7 +166,8 @@ struct btrfs_ioctl_balance_progress {#define BTRFS_BALANCE_FILTER_COUNT_ONLY (1 << 0)#define BTRFS_BALANCE_FILTER_CHUNK_TYPE (1 << 1) -#define BTRFS_BALANCE_FILTER_MASK ((1 << 2) - 1)/* Logical or of all filter +#define BTRFS_BALANCE_FILTER_DEVID (1 << 2) +#define BTRFS_BALANCE_FILTER_MASK ((1 << 3) - 1)/* Logical or of all filter * flags -- effectively versions * the filtered balance ioctl */
@@ -183,7 +184,10 @@ struct btrfs_ioctl_balance_start {__u64 chunk_type;/* Flag bits required */ __u64 chunk_type_mask;/* Mask of bits to examine */ -__u64 spare[507 ];/* Make up the size of the structure to 4088 +/* For FILTER_DEVID */ +__u64 devid; + +__u64 spare[506 ];/* Make up the size of the structure to 4088 * bytes for future expansion */ };
fs/btrfs/volumes.c +14 -0
@@ -2027,6 +2027,7 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter, {struct extent_buffer *eb;struct btrfs_chunk *chunk; +int i;/* No filter defined, everything matches */ if (!filter)
@@ -2046,6 +2047,19 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter,return 0 ; } } +if (filter->flags &BTRFS_BALANCE_FILTER_DEVID ) { +int num_stripes =btrfs_chunk_num_stripes (eb, chunk); +int res =0 ; +for (i =0 ; i < num_stripes; i++) { +struct btrfs_stripe *stripe =btrfs_stripe_nr (chunk, i); +if (btrfs_stripe_devid (eb, stripe) == filter->devid) { + res =1 ; +break ; + } + } +if (!res) +return 0 ; + }return 1 ; }
Signature · 1 line
1.7.2.5
PATCH v6 6/8 btrfs: Balance filter for virtual address ranges
In reply to Hugo MillsAllow the balancing of chunks where some part of the chunk lies within the virtual (i.e. btrfs-internal) address range passed.
--- fs/btrfs/ioctl.h | 9 +++++++-- fs/btrfs/volumes.c | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-)
fs/btrfs/ioctl.h +7 -2
@@ -167,7 +167,8 @@ struct btrfs_ioctl_balance_progress {#define BTRFS_BALANCE_FILTER_CHUNK_TYPE (1 << 1)#define BTRFS_BALANCE_FILTER_DEVID (1 << 2) -#define BTRFS_BALANCE_FILTER_MASK ((1 << 3) - 1)/* Logical or of all filter +#define BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE (1 << 3) +#define BTRFS_BALANCE_FILTER_MASK ((1 << 4) - 1)/* Logical or of all filter * flags -- effectively versions * the filtered balance ioctl */
@@ -187,7 +188,11 @@ struct btrfs_ioctl_balance_start {/* For FILTER_DEVID */ __u64 devid; -__u64 spare[506 ];/* Make up the size of the structure to 4088 +/* For FILTER_VIRTUAL_ADDRESS_RANGE */ +__u64 vrange_start; +__u64 vrange_end; + +__u64 spare[504 ];/* Make up the size of the structure to 4088 * bytes for future expansion */ };
fs/btrfs/volumes.c +6 -0
@@ -2060,6 +2060,12 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter,if (!res)return 0 ; } +if (filter->flags &BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE ) { +u64 start = key->offset; +u64 end = start +btrfs_chunk_length (eb, chunk); +if (filter->vrange_start >= end || start >= filter->vrange_end) +return 0 ; + }return 1 ; }
Signature · 1 line
1.7.2.5
PATCH v6 7/8 btrfs: Replication-type information
In reply to Hugo MillsThere are a few places in btrfs where knowledge of the various parameters of a replication type is needed. Factor this out into a single function which can supply all the relevant information.
--- fs/btrfs/super.c | 16 +++----- fs/btrfs/volumes.c | 97 +++++++++++++++++++++++++++++++++++----------------- fs/btrfs/volumes.h | 17 +++++++++ 3 files changed, 88 insertions(+), 42 deletions(-)
fs/btrfs/super.c +6 -10
@@ -923,12 +923,12 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)struct btrfs_device_info *devices_info;struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;struct btrfs_device *device; +struct btrfs_replication_info repl_info;u64 skip_space;u64 type;u64 avail_space;u64 used_space;u64 min_stripe_size; -int min_stripes =1 ;int i =0 , nr_devices;int ret;
@@ -942,12 +942,7 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)/* calc min stripe number for data space alloction */ type =btrfs_get_alloc_profile (root,1 ); -if (type &BTRFS_BLOCK_GROUP_RAID0 ) - min_stripes =2 ; -else if (type &BTRFS_BLOCK_GROUP_RAID1 ) - min_stripes =2 ; -else if (type &BTRFS_BLOCK_GROUP_RAID10 ) - min_stripes =4 ; +btrfs_get_replication_info (&repl_info, type);if (type &BTRFS_BLOCK_GROUP_DUP ) min_stripe_size =2 *BTRFS_STRIPE_LEN ;
@@ -1015,14 +1010,15 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes) i = nr_devices -1 ; avail_space =0 ; -while (nr_devices >= min_stripes) { +while (nr_devices >= repl_info.devs_min) {if (devices_info[i].max_avail >= min_stripe_size) {int j;u64 alloc_size; - avail_space += devices_info[i].max_avail * min_stripes; + avail_space += devices_info[i].max_avail + * repl_info.devs_min; alloc_size = devices_info[i].max_avail; -for (j = i +1 - min_stripes; j <= i; j++) +for (j = i +1 - repl_info.devs_min; j <= i; j++) devices_info[j].max_avail -= alloc_size; } i--;
fs/btrfs/volumes.c +65 -32
148 lines not on this page · raw message
fs/btrfs/volumes.h +17 -0
@@ -158,6 +158,22 @@ struct map_lookup {struct btrfs_bio_stripe stripes[]; }; +/* +* Information about a the parameters of a replication strategy (RAID +* level) +*/ +struct btrfs_replication_info { +u32 sub_stripes; +u32 dev_stripes; +u32 devs_increment; +u32 num_copies; +u32 devs_max; +u32 devs_min; +u64 max_stripe_size; +u64 min_stripe_size; +u64 max_chunk_size; +}; +/* Used to sort the devices by max_avail(descending sort) */ int btrfs_cmp_device_free_bytes (const void *dev_info1,const void *dev_info2);
@@ -226,4 +242,5 @@ int btrfs_chunk_readonly(struct btrfs_root *root, u64 chunk_offset);int find_free_dev_extent (struct btrfs_trans_handle *trans,struct btrfs_device *device,u64 num_bytes,u64 *start,u64 *max_avail); +void btrfs_get_replication_info (struct btrfs_replication_info *info,u64 type);#endif
Signature · 1 line
1.7.2.5
PATCH v6 8/8 btrfs: Balance filter for physical device address
In reply to Hugo MillsAdd a filter for balancing which allows the selection of chunks with data in the given byte range on any block device in the filesystem. On its own, this filter is of little use, but when used with the devid filter, it can be used to rebalance all chunks which lie on a part of a specific device.
--- fs/btrfs/ioctl.h | 9 +++++++-- fs/btrfs/volumes.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-)
fs/btrfs/ioctl.h +7 -2
@@ -168,7 +168,8 @@ struct btrfs_ioctl_balance_progress {#define BTRFS_BALANCE_FILTER_CHUNK_TYPE (1 << 1)#define BTRFS_BALANCE_FILTER_DEVID (1 << 2)#define BTRFS_BALANCE_FILTER_VIRTUAL_ADDRESS_RANGE (1 << 3) -#define BTRFS_BALANCE_FILTER_MASK ((1 << 4) - 1)/* Logical or of all filter +#define BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE (1 << 4) +#define BTRFS_BALANCE_FILTER_MASK ((1 << 5) - 1)/* Logical or of all filter * flags -- effectively versions * the filtered balance ioctl */
@@ -192,7 +193,11 @@ struct btrfs_ioctl_balance_start {__u64 vrange_start;__u64 vrange_end; -__u64 spare[504 ];/* Make up the size of the structure to 4088 +/* For FILTER_DEVICE_ADDRESS_RANGE */ +__u64 drange_start; +__u64 drange_end; + +__u64 spare[502 ];/* Make up the size of the structure to 4088 * bytes for future expansion */ };
fs/btrfs/volumes.c +19 -0
@@ -2114,6 +2114,25 @@ int balance_chunk_filter(struct btrfs_ioctl_balance_start *filter,if (filter->vrange_start >= end || start >= filter->vrange_end)return 0 ; } +if (filter->flags &BTRFS_BALANCE_FILTER_DEVICE_ADDRESS_RANGE ) { +int num_stripes =btrfs_chunk_num_stripes (eb, chunk); +int stripe_length =btrfs_chunk_length (eb, chunk) + * num_stripes / replinfo.num_copies; +int res =0 ; + +for (i =0 ; i < num_stripes; i++) { +struct btrfs_stripe *stripe =btrfs_stripe_nr (chunk, i); +u64 start =btrfs_stripe_offset (eb, stripe); +u64 end = start + stripe_length; +if (filter->drange_start < end + && start < filter->drange_end) { + res =1 ; +break ; + } + } +if (!res) +return 0 ; + }return 1 ; }
Signature · 1 line
1.7.2.5
Hi,
Quoted 4 lines · Hugo Mills
One more round of the balance management patches. There's very
little changed from last time -- a compilation issue spotted by David, two minor checkpatch failures, and a re-spin against the latest btrfs-unstable. Could you consider these patches for 2.6.40, please?
just went through the patches again, all my comments are in and I'm giving it a
david