mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2026-01-05 15:05:32 +01:00
Fix udev support. Set flag to disable udev rules for temporary devices.
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@199 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
@@ -24,8 +24,13 @@ static struct crypt_device *_context = NULL;
|
||||
|
||||
/* Compatibility for old device-mapper without udev support */
|
||||
#ifndef HAVE_DM_TASK_SET_COOKIE
|
||||
#define CRYPT_TEMP_UDEV_FLAGS 0
|
||||
static int dm_task_set_cookie(struct dm_task *dmt, uint32_t *cookie, uint16_t flags) { return 0; }
|
||||
static int dm_udev_wait(uint32_t cookie) { return 0; };
|
||||
#else
|
||||
#define CRYPT_TEMP_UDEV_FLAGS DM_UDEV_DISABLE_SUBSYSTEM_RULES_FLAG | \
|
||||
DM_UDEV_DISABLE_DISK_RULES_FLAG | \
|
||||
DM_UDEV_DISABLE_OTHER_RULES_FLAG
|
||||
#endif
|
||||
|
||||
static int _dm_use_udev()
|
||||
@@ -238,11 +243,12 @@ static int _dm_simple(int task, const char *name, int udev_wait)
|
||||
if (name && !dm_task_set_name(dmt, name))
|
||||
goto out;
|
||||
|
||||
if (udev_wait && !dm_task_set_cookie(dmt, &cookie, 0));
|
||||
if (udev_wait && !dm_task_set_cookie(dmt, &cookie, 0))
|
||||
goto out;
|
||||
|
||||
r = dm_task_run(dmt);
|
||||
|
||||
if (r && udev_wait)
|
||||
if (udev_wait)
|
||||
(void)dm_udev_wait(cookie);
|
||||
|
||||
out:
|
||||
@@ -368,7 +374,6 @@ int dm_create_device(const char *name,
|
||||
int reload)
|
||||
{
|
||||
struct dm_task *dmt = NULL;
|
||||
struct dm_task *dmt_query = NULL;
|
||||
struct dm_info dmi;
|
||||
char *params = NULL;
|
||||
char *error = NULL;
|
||||
@@ -376,11 +381,15 @@ int dm_create_device(const char *name,
|
||||
int r = -EINVAL;
|
||||
uint32_t read_ahead = 0;
|
||||
uint32_t cookie = 0;
|
||||
uint16_t udev_flags = 0;
|
||||
|
||||
params = get_params(device, skip, offset, cipher, key_size, key);
|
||||
if (!params)
|
||||
goto out_no_removal;
|
||||
|
||||
if (type && !strncmp(type, "TEMP", 4))
|
||||
udev_flags = CRYPT_TEMP_UDEV_FLAGS;
|
||||
|
||||
/* All devices must have DM_UUID, only resize on old device is exception */
|
||||
if (reload) {
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_RELOAD)))
|
||||
@@ -400,7 +409,7 @@ int dm_create_device(const char *name,
|
||||
if (!dm_task_set_uuid(dmt, dev_uuid))
|
||||
goto out_no_removal;
|
||||
|
||||
if (_dm_use_udev() && !dm_task_set_cookie(dmt, &cookie, 0))
|
||||
if (_dm_use_udev() && !dm_task_set_cookie(dmt, &cookie, udev_flags))
|
||||
goto out_no_removal;
|
||||
}
|
||||
|
||||
@@ -426,20 +435,22 @@ int dm_create_device(const char *name,
|
||||
goto out;
|
||||
if (uuid && !dm_task_set_uuid(dmt, dev_uuid))
|
||||
goto out;
|
||||
if (_dm_use_udev() && !dm_task_set_cookie(dmt, &cookie, 0))
|
||||
if (_dm_use_udev() && !dm_task_set_cookie(dmt, &cookie, udev_flags))
|
||||
goto out;
|
||||
if (!dm_task_run(dmt))
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (_dm_use_udev())
|
||||
(void)dm_udev_wait(cookie);
|
||||
|
||||
if (!dm_task_get_info(dmt, &dmi))
|
||||
goto out;
|
||||
|
||||
r = 0;
|
||||
out:
|
||||
if (_dm_use_udev()) {
|
||||
(void)dm_udev_wait(cookie);
|
||||
cookie = 0;
|
||||
}
|
||||
|
||||
if (r < 0 && !reload) {
|
||||
if (get_error())
|
||||
error = strdup(get_error());
|
||||
@@ -453,12 +464,14 @@ out:
|
||||
}
|
||||
|
||||
out_no_removal:
|
||||
if (cookie && _dm_use_udev())
|
||||
(void)dm_udev_wait(cookie);
|
||||
|
||||
if (params)
|
||||
safe_free(params);
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
if(dmt_query)
|
||||
dm_task_destroy(dmt_query);
|
||||
|
||||
dm_task_update_nodes();
|
||||
return r;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user