diff options
author | Miao Xie <miaox@cn.fujitsu.com> | 2013-07-03 21:25:10 +0800 |
---|---|---|
committer | Chris Mason <chris.mason@fusionio.com> | 2013-07-03 14:06:54 -0400 |
commit | 0daa219ee1119e30059077da5be03c4506963fe2 (patch) | |
tree | 7fc42861f945e853321147bf7a4a0f0e556ef270 /disk-io.c | |
parent | 32a8c1dd905714e91b7d590aa7d833c475e737d4 (diff) | |
download | btrfs-progs-0daa219ee1119e30059077da5be03c4506963fe2.tar.gz btrfs-progs-0daa219ee1119e30059077da5be03c4506963fe2.tar.xz btrfs-progs-0daa219ee1119e30059077da5be03c4506963fe2.zip |
Btrfs-progs: don't close the file descriptor 0 when closing a device
As we know, the file descriptor 0 is a special number, so we shouldn't
use it to initialize the file descriptor of the devices, or we might
close this special file descriptor by mistake when we close the devices.
"-1" is a better choice.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'disk-io.c')
-rw-r--r-- | disk-io.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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); |