mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-09 01:18:39 +03:00
pvscan: add error checking for write of online files
When there is any write failure during writting file, report this upward as error and fail command instead of continuing futher.
This commit is contained in:
parent
c171211254
commit
64e62167f0
@ -256,40 +256,52 @@ static void _online_pvid_files_remove(void)
|
||||
log_sys_debug("closedir", _pvs_online_dir);
|
||||
}
|
||||
|
||||
static void _online_pvid_file_create(struct device *dev)
|
||||
static int _online_pvid_file_create(struct device *dev)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
char buf[32];
|
||||
int major, minor;
|
||||
int fd;
|
||||
int rv;
|
||||
|
||||
memset(path, 0, sizeof(path));
|
||||
int len;
|
||||
|
||||
major = (int)MAJOR(dev->dev);
|
||||
minor = (int)MINOR(dev->dev);
|
||||
|
||||
snprintf(path, sizeof(path), "%s/%s", _pvs_online_dir, dev->pvid);
|
||||
if (dm_snprintf(path, sizeof(path), "%s/%s", _pvs_online_dir, dev->pvid) < 0) {
|
||||
log_error("Path %s/%s is too long.", _pvs_online_dir, dev->pvid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(buf, sizeof(buf), "%d:%d\n", major, minor);
|
||||
if ((len = dm_snprintf(buf, sizeof(buf), "%d:%d\n", major, minor)) < 0) {
|
||||
log_error("Device %d:%d is too long.", major, minor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_debug("Create pv online: %s %d:%d %s", path, major, minor, dev_name(dev));
|
||||
|
||||
fd = open(path, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
|
||||
if (fd < 0) {
|
||||
log_warn("Failed to open %s: %d", path, errno);
|
||||
return;
|
||||
log_error("Failed to open %s: %d", path, errno);
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = write(fd, buf, strlen(buf));
|
||||
if (!rv || rv < 0)
|
||||
log_warn("Failed to write fd %d buf %s dev %s to %s: %d",
|
||||
fd, buf, dev_name(dev), path, errno);
|
||||
while (len > 0) {
|
||||
rv = write(fd, buf, len);
|
||||
if (rv < 0) {
|
||||
log_error("Failed to write fd %d buf %s dev %s to %s: %d",
|
||||
fd, buf, dev_name(dev), path, errno);
|
||||
return 0;
|
||||
}
|
||||
len -= rv;
|
||||
}
|
||||
|
||||
/* We don't care about syncing, these files are not even persistent. */
|
||||
|
||||
if (close(fd))
|
||||
log_sys_debug("close", path);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _online_pvid_file_exists(const char *pvid)
|
||||
@ -364,7 +376,8 @@ static int _online_pv_found(struct cmd_context *cmd,
|
||||
* Create file named for pvid to record this PV is online.
|
||||
*/
|
||||
|
||||
_online_pvid_file_create(dev);
|
||||
if (!_online_pvid_file_create(dev))
|
||||
return_0;
|
||||
|
||||
if (!vg || !found_vgnames)
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user