Add --enable-discards option to allow discards/TRIM requests.

git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@572 36d66b0a-2a48-0410-832c-cd162a569da5
This commit is contained in:
Milan Broz
2011-07-17 22:35:40 +00:00
parent 39e6cfcb8a
commit 9c71c74d59
9 changed files with 188 additions and 26 deletions

View File

@@ -62,6 +62,7 @@ static int opt_random = 0;
static int opt_urandom = 0;
static int opt_dump_master_key = 0;
static int opt_shared = 0;
static int opt_allow_discards = 0;
static const char **action_argv;
static int action_argc;
@@ -271,6 +272,9 @@ static int action_create(int arg __attribute__((unused)))
if (opt_shared)
activate_flags |= CRYPT_ACTIVATE_SHARED;
if (opt_allow_discards)
activate_flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS;
if (opt_key_file)
/* With hashing, read the whole keyfile */
r = crypt_activate_by_keyfile(cd, action_argv[0],
@@ -304,6 +308,7 @@ static int action_loopaesOpen(int arg __attribute__((unused)))
.skip = opt_skip_valid ? opt_skip : opt_offset,
};
unsigned int key_size = (opt_key_size ?: DEFAULT_LOOPAES_KEYBITS) / 8;
uint32_t activate_flags = 0;
int r;
if (!opt_key_file) {
@@ -311,6 +316,12 @@ static int action_loopaesOpen(int arg __attribute__((unused)))
return -EINVAL;
}
if (opt_readonly)
activate_flags |= CRYPT_ACTIVATE_READONLY;
if (opt_allow_discards)
activate_flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS;
if ((r = crypt_init(&cd, action_argv[0])))
goto out;
@@ -319,9 +330,8 @@ static int action_loopaesOpen(int arg __attribute__((unused)))
if (r < 0)
goto out;
r = crypt_activate_by_keyfile(cd, action_argv[1],
CRYPT_ANY_SLOT, opt_key_file, opt_keyfile_size,
opt_readonly ? CRYPT_ACTIVATE_READONLY : 0);
r = crypt_activate_by_keyfile(cd, action_argv[1], CRYPT_ANY_SLOT,
opt_key_file, opt_keyfile_size, activate_flags);
out:
crypt_free(cd);
@@ -401,6 +411,8 @@ static int action_status(int arg __attribute__((unused)))
log_std(" skipped: %" PRIu64 " sectors\n", cad.iv_offset);
log_std(" mode: %s\n", cad.flags & CRYPT_ACTIVATE_READONLY ?
"readonly" : "read/write");
if (cad.flags & CRYPT_ACTIVATE_ALLOW_DISCARDS)
log_std(" flags: discards\n");
}
out:
crypt_free(cd);
@@ -522,9 +534,13 @@ static int action_luksOpen(int arg __attribute__((unused)))
if (opt_iteration_time)
crypt_set_iterarion_time(cd, opt_iteration_time);
if (opt_readonly)
flags |= CRYPT_ACTIVATE_READONLY;
if (opt_allow_discards)
flags |= CRYPT_ACTIVATE_ALLOW_DISCARDS;
if (opt_key_file) {
crypt_set_password_retry(cd, 1);
r = crypt_activate_by_keyfile(cd, action_argv[1],
@@ -1138,7 +1154,8 @@ int main(int argc, const char **argv)
{ "use-random", '\0', POPT_ARG_NONE, &opt_random, 0, N_("Use /dev/random for generating volume key."), NULL },
{ "use-urandom", '\0', POPT_ARG_NONE, &opt_urandom, 0, N_("Use /dev/urandom for generating volume key."), NULL },
{ "shared", '\0', POPT_ARG_NONE, &opt_shared, 0, N_("Share device with another non-overlapping crypt segment."), NULL },
{ "uuid", '\0', POPT_ARG_STRING, &opt_uuid, 0, N_("UUID for device to use."), NULL },
{ "uuid", '\0', POPT_ARG_STRING, &opt_uuid, 0, N_("UUID for device to use."), NULL },
{ "allow-discards", '\0', POPT_ARG_NONE, &opt_allow_discards, 0, N_("Allow discards (aka TRIM) requests for device."), NULL },
POPT_TABLEEND
};
poptContext popt_context;
@@ -1225,6 +1242,15 @@ int main(int argc, const char **argv)
poptGetInvocationName(popt_context));
}
if (opt_allow_discards &&
strcmp(aname, "luksOpen") &&
strcmp(aname, "create") &&
strcmp(aname, "loopaesOpen")) {
usage(popt_context, EXIT_FAILURE,
_("Option --allow-discards is allowed only for luksOpen, loopaesOpen and create operation.\n"),
poptGetInvocationName(popt_context));
}
if (opt_key_size &&
strcmp(aname, "luksFormat") &&
strcmp(aname, "create") &&