mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
filesystem: move stat after open check
To avoid time-of-check-time-of-use clash, take the stat() after successful open with fstat(). Also add some debugs for failing sys calls.
This commit is contained in:
parent
29630b2d7f
commit
cb61d2294a
@ -155,26 +155,26 @@ int fs_get_info(struct cmd_context *cmd, struct logical_volume *lv,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(crypt_path, &st_crypt) < 0) {
|
|
||||||
log_error("Failed to get crypt path %s", crypt_path);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
memset(&info, 0, sizeof(info));
|
memset(&info, 0, sizeof(info));
|
||||||
|
|
||||||
log_print_unless_silent("Checking crypt device %s on LV %s.",
|
log_print_unless_silent("Checking crypt device %s on LV %s.",
|
||||||
crypt_path, display_lvname(lv));
|
crypt_path, display_lvname(lv));
|
||||||
|
|
||||||
if ((fd = open(crypt_path, O_RDONLY)) < 0) {
|
if ((fd = open(crypt_path, O_RDONLY)) < 0) {
|
||||||
log_error("Failed to open crypt path %s", crypt_path);
|
log_error("Failed to open crypt path %s.", crypt_path);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (ioctl(fd, BLKGETSIZE64, &info.crypt_dev_size_bytes) < 0) {
|
|
||||||
log_error("Failed to get crypt device size %s", crypt_path);
|
if ((ret = fstat(fd, &st_crypt)) < 0)
|
||||||
close(fd);
|
log_sys_error("fstat", crypt_path);
|
||||||
|
else if ((ret = ioctl(fd, BLKGETSIZE64, &info.crypt_dev_size_bytes)) < 0)
|
||||||
|
log_error("Failed to get crypt device size %s.", crypt_path);
|
||||||
|
|
||||||
|
if (close(fd))
|
||||||
|
log_sys_debug("close", crypt_path);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
close(fd);
|
|
||||||
|
|
||||||
if (!fs_get_blkid(crypt_path, &info)) {
|
if (!fs_get_blkid(crypt_path, &info)) {
|
||||||
log_error("No file system info from blkid for dm-crypt device %s on LV %s.",
|
log_error("No file system info from blkid for dm-crypt device %s on LV %s.",
|
||||||
|
Loading…
Reference in New Issue
Block a user