mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
devtype: simplify code
Update code with simpler form and check for fclose().
This commit is contained in:
parent
33c8e4de33
commit
43f149526d
@ -42,7 +42,6 @@ int dev_is_pmem(struct device *dev)
|
|||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char buffer[64];
|
|
||||||
int is_pmem = 0;
|
int is_pmem = 0;
|
||||||
|
|
||||||
if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d/queue/dax",
|
if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d/queue/dax",
|
||||||
@ -56,27 +55,16 @@ int dev_is_pmem(struct device *dev)
|
|||||||
if (!(fp = fopen(path, "r")))
|
if (!(fp = fopen(path, "r")))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!fgets(buffer, sizeof(buffer), fp)) {
|
if (fscanf(fp, "%d", &is_pmem) != 1)
|
||||||
log_warn("Failed to read %s.", path);
|
log_warn("Failed to parse DAX %s.", path);
|
||||||
if (fclose(fp))
|
|
||||||
log_sys_debug("fclose", path);
|
if (is_pmem)
|
||||||
return 0;
|
log_debug("%s is pmem", dev_name(dev));
|
||||||
} else if (sscanf(buffer, "%d", &is_pmem) != 1) {
|
|
||||||
log_warn("Failed to parse %s '%s'.", path, buffer);
|
|
||||||
if (fclose(fp))
|
|
||||||
log_sys_debug("fclose", path);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fclose(fp))
|
if (fclose(fp))
|
||||||
log_sys_debug("fclose", path);
|
log_sys_debug("fclose", path);
|
||||||
|
|
||||||
if (is_pmem) {
|
return is_pmem ? 1 : 0;
|
||||||
log_debug("%s is pmem", dev_name(dev));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int dev_is_lv(struct device *dev)
|
int dev_is_lv(struct device *dev)
|
||||||
@ -84,6 +72,7 @@ int dev_is_lv(struct device *dev)
|
|||||||
FILE *fp;
|
FILE *fp;
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d/dm/uuid",
|
if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d/dm/uuid",
|
||||||
dm_sysfs_dir(),
|
dm_sysfs_dir(),
|
||||||
@ -96,17 +85,15 @@ int dev_is_lv(struct device *dev)
|
|||||||
if (!(fp = fopen(path, "r")))
|
if (!(fp = fopen(path, "r")))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!fgets(buffer, sizeof(buffer), fp)) {
|
if (!fgets(buffer, sizeof(buffer), fp))
|
||||||
log_warn("Failed to read %s.", path);
|
log_warn("Failed to read %s.", path);
|
||||||
fclose(fp);
|
else if (!strncmp(buffer, "LVM-", 4))
|
||||||
return 0;
|
ret = 1;
|
||||||
}
|
|
||||||
|
|
||||||
fclose(fp);
|
if (fclose(fp))
|
||||||
|
log_sys_debug("fclose", path);
|
||||||
|
|
||||||
if (!strncmp(buffer, "LVM-", 4))
|
return ret;
|
||||||
return 1;
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dev_types *create_dev_types(const char *proc_dir,
|
struct dev_types *create_dev_types(const char *proc_dir,
|
||||||
|
Loading…
Reference in New Issue
Block a user