diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c index 38b9533a9..ac5fb3add 100644 --- a/libdm/ioctl/libdm-iface.c +++ b/libdm/ioctl/libdm-iface.c @@ -1478,7 +1478,7 @@ static int _create_and_load_v4(struct dm_task *dmt) { struct dm_info info; struct dm_task *task; - int r; + int r, ioctl_errno = 0; uint32_t cookie; /* Use new task struct to create the device */ @@ -1504,8 +1504,10 @@ static int _create_and_load_v4(struct dm_task *dmt) task->cookie_set = dmt->cookie_set; task->add_node = dmt->add_node; - if (!dm_task_run(task)) + if (!dm_task_run(task)) { + ioctl_errno = task->ioctl_errno; goto_bad; + } if (!dm_task_get_info(task, &info) || !info.exists) goto_bad; @@ -1536,6 +1538,8 @@ static int _create_and_load_v4(struct dm_task *dmt) task->ima_measurement = dmt->ima_measurement; r = dm_task_run(task); + if (!r) + ioctl_errno = task->ioctl_errno; task->head = NULL; task->tail = NULL; @@ -1582,12 +1586,18 @@ static int _create_and_load_v4(struct dm_task *dmt) if (!dm_task_run(dmt)) log_error("Failed to revert device creation."); + if (ioctl_errno != 0) + dmt->ioctl_errno = ioctl_errno; + return 0; bad: dm_task_destroy(task); _udev_complete(dmt); + if (ioctl_errno != 0) + dmt->ioctl_errno = ioctl_errno; + return 0; }