From: Filipe David Borba Manana <fdmanana@gmail.com>
To: linux-btrfs@vger.kernel.org
Cc: Filipe David Borba Manana <fdmanana@gmail.com>
Subject: [PATCH 1/5] Btrfs-progs: fix closing of devices
Date: Mon, 10 Jun 2013 20:51:31 +0100 [thread overview]
Message-ID: <1370893895-24884-2-git-send-email-fdmanana@gmail.com> (raw)
In-Reply-To: <1370893895-24884-1-git-send-email-fdmanana@gmail.com>
If a device could not be opened in volumes.c:read_one_dev(), a
btrfs_device instance was allocated and added to the list of
devices of the fs - however this device instance had its fd,
name and label fields not initialized. This is problematic in
disk-io.c:close_all_devices() as it tries to close the (invalid)
fd of the device and kfree() its name and label, which point
to random memory locations.
Thread 1 (Thread 0x7f0a3d2d1740 (LWP 23585)):
#0 __GI___libc_free (mem=0xa5a5a5a5a5a5a5a5) at malloc.c:2970
#1 0x000000000042054b in close_all_devices (fs_info=0x1e92bf0) at disk-io.c:1276
#2 0x0000000000421dcd in close_ctree (root=<optimized out>) at disk-io.c:1336
#3 0x0000000000418cfa in cmd_check (argc=<optimized out>, argv=<optimized out>) at cmds-check.c:4171
#4 0x0000000000403ed4 in main (argc=2, argv=0x7fff9a583d28) at btrfs.c:295
Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
---
disk-io.c | 4 ++--
volumes.c | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/disk-io.c b/disk-io.c
index 21b410d..bd9cf4e 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1267,12 +1267,12 @@ static int close_all_devices(struct btrfs_fs_info *fs_info)
while (!list_empty(list)) {
device = list_entry(list->next, struct btrfs_device, dev_list);
list_del_init(&device->dev_list);
- if (device->fd) {
+ if (device->fd >= 0) {
fsync(device->fd);
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
fprintf(stderr, "Warning, could not drop caches\n");
+ close(device->fd);
}
- close(device->fd);
kfree(device->name);
kfree(device->label);
kfree(device);
diff --git a/volumes.c b/volumes.c
index d6f81f8..a84ded7 100644
--- a/volumes.c
+++ b/volumes.c
@@ -1628,10 +1628,10 @@ static int read_one_dev(struct btrfs_root *root,
if (!device) {
printk("warning devid %llu not found already\n",
(unsigned long long)devid);
- device = kmalloc(sizeof(*device), GFP_NOFS);
+ device = kzalloc(sizeof(*device), GFP_NOFS);
if (!device)
return -ENOMEM;
- device->total_ios = 0;
+ device->fd = -1;
list_add(&device->dev_list,
&root->fs_info->fs_devices->devices);
}
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-
next prev parent reply other threads:[~2013-06-10 19:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-10 19:51 [PATCH 0/5] Btrfs-progs: coalesce of patches Filipe David Borba Manana
2013-06-10 19:51 ` Filipe David Borba Manana [this message]
2013-06-10 20:07 ` [PATCH 1/5] Btrfs-progs: fix closing of devices Filipe David Borba Manana
2013-06-11 15:00 ` David Sterba
2013-06-11 16:09 ` Filipe Manana
2013-06-10 19:51 ` [PATCH 2/5] Btrfs-progs: Add missing free_extent_buffer() call to debug-tree Filipe David Borba Manana
2013-06-10 19:51 ` [PATCH 3/5] Btrfs-progs: Add missing close_ctree() calls " Filipe David Borba Manana
2013-06-10 19:51 ` [PATCH 4/5] Btrfs-progs: pretty print dir_item type Filipe David Borba Manana
2013-06-10 19:51 ` [PATCH 5/5] Btrfs-progs: Validate super block checksum Filipe David Borba Manana
2013-06-20 17:08 ` Filipe David Manana
2013-06-21 16:18 ` David Sterba
2013-06-21 16:38 ` Filipe David Manana
2013-06-10 23:52 ` [PATCH 1/5 v2] Btrfs-progs: fix closing of devices Filipe David Borba Manana
2013-06-21 16:03 ` Liu Bo
2013-06-21 16:11 ` Liu Bo
2013-06-21 16:46 ` Filipe David Manana
2013-06-26 16:41 ` [PATCH v2 1/5] " Filipe David Borba Manana
2013-06-26 16:42 ` [PATCH v2 5/5] Btrfs-progs: Validate super block checksum Filipe David Borba Manana
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=1370893895-24884-2-git-send-email-fdmanana@gmail.com \
--to=fdmanana@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).