mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-17 13:50:06 +01:00
Move dm backend initialisation to library calls.
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@125 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
* Do not use internal lib functions in cryptsetup.
|
* Do not use internal lib functions in cryptsetup.
|
||||||
* Add crypt_log to library.
|
* Add crypt_log to library.
|
||||||
* Fix crypt_remove_device (remove, luksClose) implementation.
|
* Fix crypt_remove_device (remove, luksClose) implementation.
|
||||||
|
* Move dm backend initialisation to library calls.
|
||||||
|
|
||||||
2009-09-28 Milan Broz <mbroz@redhat.com>
|
2009-09-28 Milan Broz <mbroz@redhat.com>
|
||||||
* Add luksHeaderBackup and luksHeaderRestore commands.
|
* Add luksHeaderBackup and luksHeaderRestore commands.
|
||||||
|
|||||||
@@ -44,12 +44,15 @@ int dm_init(struct crypt_device *context, int check_kernel)
|
|||||||
if (!_dm_use_count++) {
|
if (!_dm_use_count++) {
|
||||||
log_dbg("Initialising device-mapper backend%s.",
|
log_dbg("Initialising device-mapper backend%s.",
|
||||||
check_kernel ? "" : " (NO kernel check requested)");
|
check_kernel ? "" : " (NO kernel check requested)");
|
||||||
if (check_kernel && !_dm_simple(DM_DEVICE_LIST_VERSIONS, NULL))
|
if (check_kernel && !_dm_simple(DM_DEVICE_LIST_VERSIONS, NULL)) {
|
||||||
|
log_err(context, _("Cannot initialize device-mapper. Is dm_mod kernel module loaded?\n"));
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
dm_log_init(set_dm_error);
|
dm_log_init(set_dm_error);
|
||||||
dm_log_init_verbose(10);
|
dm_log_init_verbose(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: global context is not safe
|
||||||
if (context)
|
if (context)
|
||||||
_context = context;
|
_context = context;
|
||||||
|
|
||||||
|
|||||||
56
lib/setup.c
56
lib/setup.c
@@ -643,6 +643,9 @@ int crypt_resize_device(struct crypt_options *options)
|
|||||||
uint64_t size, skip, offset;
|
uint64_t size, skip, offset;
|
||||||
int key_size, read_only, r;
|
int key_size, read_only, r;
|
||||||
|
|
||||||
|
if (dm_init(NULL, 1) < 0)
|
||||||
|
return -ENOSYS;
|
||||||
|
|
||||||
r = dm_query_device(options->name, &device, &size, &skip, &offset,
|
r = dm_query_device(options->name, &device, &size, &skip, &offset,
|
||||||
&cipher, &key_size, &key, &read_only, NULL, &uuid);
|
&cipher, &key_size, &key, &read_only, NULL, &uuid);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
@@ -676,6 +679,7 @@ out:
|
|||||||
free(device);
|
free(device);
|
||||||
free(uuid);
|
free(uuid);
|
||||||
crypt_free(cd);
|
crypt_free(cd);
|
||||||
|
dm_exit();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -684,14 +688,20 @@ int crypt_query_device(struct crypt_options *options)
|
|||||||
{
|
{
|
||||||
int read_only, r;
|
int read_only, r;
|
||||||
|
|
||||||
|
if (dm_init(NULL, 1) < 0)
|
||||||
|
return -ENOSYS;
|
||||||
|
|
||||||
r = dm_status_device(options->name);
|
r = dm_status_device(options->name);
|
||||||
if (r == -ENODEV)
|
if (r == -ENODEV) {
|
||||||
|
dm_exit();
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
r = dm_query_device(options->name, (char **)&options->device, &options->size,
|
r = dm_query_device(options->name, (char **)&options->device, &options->size,
|
||||||
&options->skip, &options->offset, (char **)&options->cipher,
|
&options->skip, &options->offset, (char **)&options->cipher,
|
||||||
&options->key_size, NULL, &read_only, NULL, NULL);
|
&options->key_size, NULL, &read_only, NULL, NULL);
|
||||||
|
|
||||||
|
dm_exit();
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
@@ -973,7 +983,7 @@ int crypt_init(struct crypt_device **cd, const char *device)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dm_init(h, 1) < 0) {
|
if (dm_init(h, 1) < 0) {
|
||||||
free(h);
|
free(h);
|
||||||
return -ENOSYS;
|
return -ENOSYS;
|
||||||
}
|
}
|
||||||
@@ -994,6 +1004,9 @@ int crypt_init_by_name(struct crypt_device **cd, const char *name)
|
|||||||
log_dbg("Allocating crypt device context by device %s.", name);
|
log_dbg("Allocating crypt device context by device %s.", name);
|
||||||
|
|
||||||
ci = crypt_status(NULL, name);
|
ci = crypt_status(NULL, name);
|
||||||
|
if (ci == INVALID)
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
if (ci < ACTIVE) {
|
if (ci < ACTIVE) {
|
||||||
log_err(NULL, _("Device %s is not active.\n"), name);
|
log_err(NULL, _("Device %s is not active.\n"), name);
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@@ -1211,20 +1224,26 @@ int crypt_suspend(struct crypt_device *cd,
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cd && dm_init(NULL, 1) < 0)
|
||||||
|
return -ENOSYS;
|
||||||
|
|
||||||
r = dm_query_device(name, NULL, NULL, NULL, NULL,
|
r = dm_query_device(name, NULL, NULL, NULL, NULL,
|
||||||
NULL, NULL, NULL, NULL, &suspended, NULL);
|
NULL, NULL, NULL, NULL, &suspended, NULL);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
goto out;
|
||||||
|
|
||||||
if (suspended) {
|
if (suspended) {
|
||||||
log_err(cd, _("Volume %s is already suspended.\n"), name);
|
log_err(cd, _("Volume %s is already suspended.\n"), name);
|
||||||
return -EINVAL;
|
r = -EINVAL;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = dm_suspend_and_wipe_key(name);
|
r = dm_suspend_and_wipe_key(name);
|
||||||
if (r)
|
if (r)
|
||||||
log_err(cd, "Error during suspending device %s.\n", name);
|
log_err(cd, "Error during suspending device %s.\n", name);
|
||||||
|
out:
|
||||||
|
if (!cd)
|
||||||
|
dm_exit();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1724,20 +1743,33 @@ int crypt_activate_by_volume_key(struct crypt_device *cd,
|
|||||||
|
|
||||||
int crypt_deactivate(struct crypt_device *cd, const char *name)
|
int crypt_deactivate(struct crypt_device *cd, const char *name)
|
||||||
{
|
{
|
||||||
|
int r;
|
||||||
|
|
||||||
if (!name)
|
if (!name)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
log_dbg("Deactivating volume %s.", name);
|
log_dbg("Deactivating volume %s.", name);
|
||||||
|
|
||||||
|
if (!cd && dm_init(NULL, 1) < 0)
|
||||||
|
return -ENOSYS;
|
||||||
|
|
||||||
switch (crypt_status(cd, name)) {
|
switch (crypt_status(cd, name)) {
|
||||||
case ACTIVE: return dm_remove_device(name, 0, 0);
|
case ACTIVE: r = dm_remove_device(name, 0, 0);
|
||||||
|
break;
|
||||||
case BUSY: log_err(cd, _("Device %s is busy."), name);
|
case BUSY: log_err(cd, _("Device %s is busy."), name);
|
||||||
return -EBUSY;
|
r = -EBUSY;
|
||||||
|
break;
|
||||||
case INACTIVE: log_err(cd, _("Device %s is not active."), name);
|
case INACTIVE: log_err(cd, _("Device %s is not active."), name);
|
||||||
return -ENODEV;
|
r = -ENODEV;
|
||||||
|
break;
|
||||||
default: log_err(cd, _("Invalid device %s."), name);
|
default: log_err(cd, _("Invalid device %s."), name);
|
||||||
return -EINVAL;
|
r = -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cd)
|
||||||
|
dm_exit();
|
||||||
|
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// misc helper functions
|
// misc helper functions
|
||||||
@@ -1848,8 +1880,14 @@ crypt_status_info crypt_status(struct crypt_device *cd, const char *name)
|
|||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
|
if (!cd && dm_init(NULL, 1) < 0)
|
||||||
|
return INVALID;
|
||||||
|
|
||||||
r = dm_status_device(name);
|
r = dm_status_device(name);
|
||||||
|
|
||||||
|
if (!cd)
|
||||||
|
dm_exit();
|
||||||
|
|
||||||
if (r < 0 && r != -ENODEV)
|
if (r < 0 && r != -ENODEV)
|
||||||
return INVALID;
|
return INVALID;
|
||||||
|
|
||||||
|
|||||||
@@ -64,32 +64,31 @@ static struct action_type {
|
|||||||
int (*handler)(int);
|
int (*handler)(int);
|
||||||
int arg;
|
int arg;
|
||||||
int required_action_argc;
|
int required_action_argc;
|
||||||
int required_dm_backend;
|
|
||||||
int required_memlock;
|
int required_memlock;
|
||||||
int show_status;
|
int show_status;
|
||||||
const char *arg_desc;
|
const char *arg_desc;
|
||||||
const char *desc;
|
const char *desc;
|
||||||
} action_types[] = {
|
} action_types[] = {
|
||||||
{ "create", action_create, 0, 2, 1, 1, 1, N_("<name> <device>"),N_("create device") },
|
{ "create", action_create, 0, 2, 1, 1, N_("<name> <device>"),N_("create device") },
|
||||||
{ "remove", action_remove, 0, 1, 1, 1, 1, N_("<name>"), N_("remove device") },
|
{ "remove", action_remove, 0, 1, 1, 1, N_("<name>"), N_("remove device") },
|
||||||
{ "resize", action_resize, 0, 1, 1, 1, 1, N_("<name>"), N_("resize active device") },
|
{ "resize", action_resize, 0, 1, 1, 1, N_("<name>"), N_("resize active device") },
|
||||||
{ "status", action_status, 0, 1, 1, 0, 1, N_("<name>"), N_("show device status") },
|
{ "status", action_status, 0, 1, 0, 1, N_("<name>"), N_("show device status") },
|
||||||
{ "luksFormat", action_luksFormat, 0, 1, 1, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
|
{ "luksFormat", action_luksFormat, 0, 1, 1, 1, N_("<device> [<new key file>]"), N_("formats a LUKS device") },
|
||||||
{ "luksOpen", action_luksOpen, 0, 2, 1, 1, 1, N_("<device> <name> "), N_("open LUKS device as mapping <name>") },
|
{ "luksOpen", action_luksOpen, 0, 2, 1, 1, N_("<device> <name> "), N_("open LUKS device as mapping <name>") },
|
||||||
{ "luksAddKey", action_luksAddKey, 0, 1, 1, 1, 1, N_("<device> [<new key file>]"), N_("add key to LUKS device") },
|
{ "luksAddKey", action_luksAddKey, 0, 1, 1, 1, N_("<device> [<new key file>]"), N_("add key to LUKS device") },
|
||||||
{ "luksRemoveKey",action_luksRemoveKey, 0, 1, 1, 1, 1, N_("<device> [<key file>]"), N_("removes supplied key or key file from LUKS device") },
|
{ "luksRemoveKey",action_luksRemoveKey, 0, 1, 1, 1, N_("<device> [<key file>]"), N_("removes supplied key or key file from LUKS device") },
|
||||||
{ "luksKillSlot", action_luksKillSlot, 0, 2, 1, 1, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
|
{ "luksKillSlot", action_luksKillSlot, 0, 2, 1, 1, N_("<device> <key slot>"), N_("wipes key with number <key slot> from LUKS device") },
|
||||||
{ "luksUUID", action_luksUUID, 0, 1, 0, 0, 1, N_("<device>"), N_("print UUID of LUKS device") },
|
{ "luksUUID", action_luksUUID, 0, 1, 0, 1, N_("<device>"), N_("print UUID of LUKS device") },
|
||||||
{ "isLuks", action_isLuks, 0, 1, 0, 0, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
|
{ "isLuks", action_isLuks, 0, 1, 0, 0, N_("<device>"), N_("tests <device> for LUKS partition header") },
|
||||||
{ "luksClose", action_remove, 0, 1, 1, 1, 1, N_("<name>"), N_("remove LUKS mapping") },
|
{ "luksClose", action_remove, 0, 1, 1, 1, N_("<name>"), N_("remove LUKS mapping") },
|
||||||
{ "luksDump", action_luksDump, 0, 1, 0, 0, 1, N_("<device>"), N_("dump LUKS partition information") },
|
{ "luksDump", action_luksDump, 0, 1, 0, 1, N_("<device>"), N_("dump LUKS partition information") },
|
||||||
{ "luksSuspend",action_luksSuspend, 0, 1, 1, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
|
{ "luksSuspend",action_luksSuspend, 0, 1, 1, 1, N_("<device>"), N_("Suspend LUKS device and wipe key (all IOs are frozen).") },
|
||||||
{ "luksResume", action_luksResume, 0, 1, 1, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
|
{ "luksResume", action_luksResume, 0, 1, 1, 1, N_("<device>"), N_("Resume suspended LUKS device.") },
|
||||||
{ "luksHeaderBackup",action_luksBackup, 0, 1, 1, 1, 1, N_("<device>"), N_("Backup LUKS device header and keyslots") },
|
{ "luksHeaderBackup",action_luksBackup, 0, 1, 1, 1, N_("<device>"), N_("Backup LUKS device header and keyslots") },
|
||||||
{ "luksHeaderRestore",action_luksRestore,0,1, 1, 1, 1, N_("<device>"), N_("Restore LUKS device header and keyslots") },
|
{ "luksHeaderRestore",action_luksRestore,0,1, 1, 1, N_("<device>"), N_("Restore LUKS device header and keyslots") },
|
||||||
{ "luksDelKey", action_luksDelKey, 0, 2, 1, 1, 1, N_("<device> <key slot>"), N_("identical to luksKillSlot - DEPRECATED - see man page") },
|
{ "luksDelKey", action_luksDelKey, 0, 2, 1, 1, N_("<device> <key slot>"), N_("identical to luksKillSlot - DEPRECATED - see man page") },
|
||||||
{ "reload", action_create, 1, 2, 1, 1, 1, N_("<name> <device>"), N_("modify active device - DEPRECATED - see man page") },
|
{ "reload", action_create, 1, 2, 1, 1, N_("<name> <device>"), N_("modify active device - DEPRECATED - see man page") },
|
||||||
{ NULL, NULL, 0, 0, 0, 0, 0, NULL, NULL }
|
{ NULL, NULL, 0, 0, 0, 0, NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void clogger(struct crypt_device *cd, int class, const char *file,
|
static void clogger(struct crypt_device *cd, int class, const char *file,
|
||||||
|
|||||||
Reference in New Issue
Block a user