diff --git a/device_mapper/ioctl/libdm-iface.c b/device_mapper/ioctl/libdm-iface.c index 00e2eb9e9..a17a4e468 100644 --- a/device_mapper/ioctl/libdm-iface.c +++ b/device_mapper/ioctl/libdm-iface.c @@ -1620,7 +1620,7 @@ static int _check_uevent_generated(struct dm_ioctl *dmi) static int _create_and_load_v4(struct dm_task *dmt) { struct dm_task *task; - int r; + int r, ioctl_errno = 0; uint32_t cookie; /* Use new task struct to create the device */ @@ -1646,8 +1646,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; + } dm_task_destroy(task); @@ -1673,6 +1675,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; @@ -1719,12 +1723,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; }