Commit f720affe authored by Milan Broz's avatar Milan Broz

Relax --shared test, allow mapping even for overlapping segments.

Support shared flag for LUKS devices (dangerous).
parent a7183693
2012-05-02 Milan Broz <gmazyland@gmail.com>
* Fix loop mapping on readonly file.
* Relax --shared test, allow mapping even for overlapping segments.
* Support shared flag for LUKS devices (dangerous).
2012-04-09 Milan Broz <gmazyland@gmail.com>
* Fix header check to support old (cryptsetup 1.0.0) header alignment. (1.4.0)
......
......@@ -636,7 +636,7 @@ int crypt_keyslot_destroy(struct crypt_device *cd, int keyslot);
#define CRYPT_ACTIVATE_READONLY (1 << 0)
/** only reported for device without uuid */
#define CRYPT_ACTIVATE_NO_UUID (1 << 1)
/** activate more non-overlapping mapping to the same device */
/** activate even if cannot grant exclusive access (DANGEROUS) */
#define CRYPT_ACTIVATE_SHARED (1 << 2)
/** enable discards aka TRIM */
#define CRYPT_ACTIVATE_ALLOW_DISCARDS (1 << 3)
......
......@@ -1031,6 +1031,7 @@ int LUKS1_activate(struct crypt_device *cd,
{
int r;
char *dm_cipher = NULL;
enum devcheck device_check;
struct crypt_dm_active_device dmd = {
.device = crypt_get_device_name(cd),
.cipher = NULL,
......@@ -1042,7 +1043,12 @@ int LUKS1_activate(struct crypt_device *cd,
.flags = flags
};
r = device_check_and_adjust(cd, dmd.device, DEV_EXCL,
if (dmd.flags & CRYPT_ACTIVATE_SHARED)
device_check = DEV_SHARED;
else
device_check = DEV_EXCL;
r = device_check_and_adjust(cd, dmd.device, device_check,
&dmd.size, &dmd.offset, &flags);
if (r)
return r;
......
......@@ -285,6 +285,7 @@ int PLAIN_activate(struct crypt_device *cd,
{
int r;
char *dm_cipher = NULL;
enum devcheck device_check;
struct crypt_dm_active_device dmd = {
.device = crypt_get_device_name(cd),
.cipher = NULL,
......@@ -296,8 +297,12 @@ int PLAIN_activate(struct crypt_device *cd,
.flags = flags
};
r = device_check_and_adjust(cd, dmd.device,
(dmd.flags & CRYPT_ACTIVATE_SHARED) ? DEV_SHARED : DEV_EXCL,
if (dmd.flags & CRYPT_ACTIVATE_SHARED)
device_check = DEV_SHARED;
else
device_check = DEV_EXCL;
r = device_check_and_adjust(cd, dmd.device, device_check,
&dmd.size, &dmd.offset, &flags);
if (r)
return r;
......
......@@ -416,17 +416,6 @@ int device_check_and_adjust(struct crypt_device *cd,
return -EINVAL;
}
if (device_check == DEV_SHARED) {
log_dbg("Checking crypt segments for device %s.", device);
r = crypt_sysfs_check_crypt_segment(device, *offset, *size);
if (r < 0) {
log_err(cd, _("Cannot use device %s (crypt segments "
"overlaps or in use by another device).\n"),
device);
return r;
}
}
if (real_readonly)
*flags |= CRYPT_ACTIVATE_READONLY;
......
......@@ -428,15 +428,10 @@ $CRYPTSETUP luksChangeKey $LOOPDEV -i1 -d $KEY2 --keyfile-offset 1 $KEY2 --new-k
$CRYPTSETUP luksOpen -d $KEY2 $LOOPDEV $DEV_NAME || fail
$CRYPTSETUP luksClose $DEV_NAME || fail
prepare "[25] Create non-overlapping segments" wipe
prepare "[25] Create shared segments" wipe
echo "key0" | $CRYPTSETUP create $DEV_NAME $LOOPDEV --hash sha1 --offset 0 --size 256 || fail
echo "key0" | $CRYPTSETUP create $DEV_NAME2 $LOOPDEV --hash sha1 --offset 512 --size 256 2>/dev/null && fail
echo "key0" | $CRYPTSETUP create $DEV_NAME2 $LOOPDEV --hash sha1 --offset 512 --size 256 --shared || fail
echo "key0" | $CRYPTSETUP create $DEV_NAME3 $LOOPDEV --hash sha1 --offset 255 --size 256 --shared 2>/dev/null && fail
echo "key0" | $CRYPTSETUP create $DEV_NAME3 $LOOPDEV --hash sha1 --offset 256 --size 257 --shared 2>/dev/null && fail
echo "key0" | $CRYPTSETUP create $DEV_NAME3 $LOOPDEV --hash sha1 --offset 256 --size 1024 --shared 2>/dev/null && fail
echo "key0" | $CRYPTSETUP create $DEV_NAME3 $LOOPDEV --hash sha1 --offset 256 --size 256 --shared || fail
$CRYPTSETUP -q remove $DEV_NAME3 || fail
$CRYPTSETUP -q remove $DEV_NAME2 || fail
$CRYPTSETUP -q remove $DEV_NAME || fail
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment