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>
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;
}
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);
/* 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);
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;
}