Lines 306-327
Link Here
|
306 |
} |
306 |
} |
307 |
|
307 |
|
308 |
/* http://code.google.com/p/cryptsetup/wiki/DMCrypt */ |
308 |
/* http://code.google.com/p/cryptsetup/wiki/DMCrypt */ |
309 |
static char *get_dm_crypt_params(struct crypt_dm_active_device *dmd) |
309 |
static char *get_dm_crypt_params(struct crypt_dm_active_device *dmd, uint32_t flags) |
310 |
{ |
310 |
{ |
311 |
int r, max_size, null_cipher = 0; |
311 |
int r, max_size, null_cipher = 0; |
312 |
char *params, *hexkey; |
312 |
char *params, *hexkey; |
313 |
const char *features = ""; |
313 |
const char *features; |
314 |
|
314 |
|
315 |
if (!dmd) |
315 |
if (!dmd) |
316 |
return NULL; |
316 |
return NULL; |
317 |
|
317 |
|
318 |
if (dmd->flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) { |
318 |
if (flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) |
319 |
if (dm_flags() & DM_DISCARDS_SUPPORTED) { |
319 |
features = " 1 allow_discards"; |
320 |
features = " 1 allow_discards"; |
320 |
else |
321 |
log_dbg("Discard/TRIM is allowed."); |
321 |
features = ""; |
322 |
} else |
|
|
323 |
log_dbg("Discard/TRIM is not supported by the kernel."); |
324 |
} |
325 |
|
322 |
|
326 |
if (!strncmp(dmd->u.crypt.cipher, "cipher_null-", 12)) |
323 |
if (!strncmp(dmd->u.crypt.cipher, "cipher_null-", 12)) |
327 |
null_cipher = 1; |
324 |
null_cipher = 1; |
Lines 657-662
Link Here
|
657 |
int reload) |
654 |
int reload) |
658 |
{ |
655 |
{ |
659 |
char *table_params = NULL; |
656 |
char *table_params = NULL; |
|
|
657 |
uint32_t dmd_flags; |
660 |
int r = -EINVAL; |
658 |
int r = -EINVAL; |
661 |
|
659 |
|
662 |
if (!type) |
660 |
if (!type) |
Lines 665-679
Link Here
|
665 |
if (dm_init_context(cd)) |
663 |
if (dm_init_context(cd)) |
666 |
return -ENOTSUP; |
664 |
return -ENOTSUP; |
667 |
|
665 |
|
|
|
666 |
dmd_flags = dmd->flags; |
667 |
|
668 |
|
668 |
if (dmd->target == DM_CRYPT) |
669 |
if (dmd->target == DM_CRYPT) |
669 |
table_params = get_dm_crypt_params(dmd); |
670 |
table_params = get_dm_crypt_params(dmd, dmd_flags); |
670 |
else if (dmd->target == DM_VERITY) |
671 |
else if (dmd->target == DM_VERITY) |
671 |
table_params = get_dm_verity_params(dmd->u.verity.vp, dmd); |
672 |
table_params = get_dm_verity_params(dmd->u.verity.vp, dmd); |
672 |
|
673 |
|
673 |
if (table_params) |
674 |
if (table_params) |
674 |
r = _dm_create_device(name, type, dmd->data_device, |
675 |
r = _dm_create_device(name, type, dmd->data_device, dmd_flags, |
675 |
dmd->flags, dmd->uuid, dmd->size, |
676 |
dmd->uuid, dmd->size, table_params, reload); |
676 |
table_params, reload); |
677 |
|
|
|
678 |
/* If discard not supported try to load without discard */ |
679 |
if (!reload && r && dmd->target == DM_CRYPT && |
680 |
(dmd->flags & CRYPT_ACTIVATE_ALLOW_DISCARDS) && |
681 |
!(dm_flags() & DM_DISCARDS_SUPPORTED)) { |
682 |
log_dbg("Discard/TRIM is not supported, retrying activation."); |
683 |
dmd_flags = dmd_flags & ~CRYPT_ACTIVATE_ALLOW_DISCARDS; |
684 |
crypt_safe_free(table_params); |
685 |
table_params = get_dm_crypt_params(dmd, dmd_flags); |
686 |
r = _dm_create_device(name, type, dmd->data_device, dmd_flags, |
687 |
dmd->uuid, dmd->size, table_params, reload); |
688 |
} |
677 |
dm_exit_context(); |
689 |
dm_exit_context(); |
678 |
return r; |
690 |
return r; |
679 |
} |
691 |
} |