]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
btrfs: allocate raid type kobjects dynamically
authorJeff Mahoney <jeffm@suse.com>
Tue, 27 May 2014 16:59:57 +0000 (12:59 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 1 Jul 2014 03:14:03 +0000 (20:14 -0700)
commit80693a87ae519cdab6b4c2a31bbadf55ec8cade9
tree41b542a2b06064923cd1351d93008b31d69c2546
parent69a109b2cec03ef6ce93ad08e3c01665213579e3
btrfs: allocate raid type kobjects dynamically

commit c1895442be01c58449e3bf9272f22062a670e08f upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/ctree.h
fs/btrfs/extent-tree.c
fs/btrfs/sysfs.c