aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
authorJeff Mahoney <jeffm@suse.com>2014-05-27 12:59:57 -0400
committerChris Mason <clm@fb.com>2014-06-09 20:21:01 -0400
commitc1895442be01c58449e3bf9272f22062a670e08f (patch)
tree8a09bb69c59dfdbcff5869cb82490487ec0bf86e /fs/btrfs/ctree.h
parent7e3ae33efad1490d01040f552ef50e58ed6376ca (diff)
btrfs: allocate raid type kobjects dynamically
We are currently allocating space_info objects in an array when we allocate space_info. When a user does something like: # btrfs balance start -mconvert=raid1 -dconvert=raid1 /mnt # btrfs balance start -mconvert=single -dconvert=single /mnt -f # btrfs balance start -mconvert=raid1 -dconvert=raid1 / We can end up with memory corruption since the kobject hasn't been reinitialized properly and the name pointer was left set. The rationale behind allocating them statically was to avoid creating a separate kobject container that just contained the raid type. It used the index in the array to determine the index. Ultimately, though, this wastes more memory than it saves in all but the most complex scenarios and introduces kobject lifetime questions. This patch allocates the kobjects dynamically instead. Note that we also remove the kobject_get/put of the parent kobject since kobject_add and kobject_del do that internally. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Reported-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h8
1 files changed, 7 insertions, 1 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 02895a126ab9..af523d695432 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1123,6 +1123,12 @@ struct btrfs_qgroup_limit_item {
1123 __le64 rsv_excl; 1123 __le64 rsv_excl;
1124} __attribute__ ((__packed__)); 1124} __attribute__ ((__packed__));
1125 1125
1126/* For raid type sysfs entries */
1127struct raid_kobject {
1128 int raid_type;
1129 struct kobject kobj;
1130};
1131
1126struct btrfs_space_info { 1132struct btrfs_space_info {
1127 spinlock_t lock; 1133 spinlock_t lock;
1128 1134
@@ -1173,7 +1179,7 @@ struct btrfs_space_info {
1173 wait_queue_head_t wait; 1179 wait_queue_head_t wait;
1174 1180
1175 struct kobject kobj; 1181 struct kobject kobj;
1176 struct kobject block_group_kobjs[BTRFS_NR_RAID_TYPES]; 1182 struct kobject *block_group_kobjs[BTRFS_NR_RAID_TYPES];
1177}; 1183};
1178 1184
1179#define BTRFS_BLOCK_RSV_GLOBAL 1 1185#define BTRFS_BLOCK_RSV_GLOBAL 1