summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--btrfs-find-root.c5
-rw-r--r--disk-io.c5
-rw-r--r--volumes.c7
3 files changed, 12 insertions, 5 deletions
diff --git a/btrfs-find-root.c b/btrfs-find-root.c
index 810d8358..3e1396d3 100644
--- a/btrfs-find-root.c
+++ b/btrfs-find-root.c
@@ -76,7 +76,10 @@ static int close_all_devices(struct btrfs_fs_info *fs_info)
list = &fs_info->fs_devices->devices;
list_for_each(next, list) {
device = list_entry(next, struct btrfs_device, dev_list);
- close(device->fd);
+ if (device->fd != -1) {
+ close(device->fd);
+ device->fd = -1;
+ }
}
return 0;
}
diff --git a/disk-io.c b/disk-io.c
index 9ffe6e4e..40036366 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1270,12 +1270,13 @@ 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 != -1) {
fsync(device->fd);
if (posix_fadvise(device->fd, 0, 0, POSIX_FADV_DONTNEED))
fprintf(stderr, "Warning, could not drop caches\n");
+ close(device->fd);
+ device->fd = -1;
}
- close(device->fd);
kfree(device->name);
kfree(device->label);
kfree(device);
diff --git a/volumes.c b/volumes.c
index d6f81f87..b88385bb 100644
--- a/volumes.c
+++ b/volumes.c
@@ -116,6 +116,7 @@ static int device_list_add(const char *path,
/* we can safely leave the fs_devices entry around */
return -ENOMEM;
}
+ device->fd = -1;
device->devid = devid;
memcpy(device->uuid, disk_super->dev_item.uuid,
BTRFS_UUID_SIZE);
@@ -161,8 +162,10 @@ int btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
again:
list_for_each(cur, &fs_devices->devices) {
device = list_entry(cur, struct btrfs_device, dev_list);
- close(device->fd);
- device->fd = -1;
+ if (device->fd != -1) {
+ close(device->fd);
+ device->fd = -1;
+ }
device->writeable = 0;
}