summaryrefslogtreecommitdiffstats
path: root/sbin/geom/class/eli/geom_eli.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/geom/class/eli/geom_eli.c')
-rw-r--r--sbin/geom/class/eli/geom_eli.c66
1 files changed, 55 insertions, 11 deletions
diff --git a/sbin/geom/class/eli/geom_eli.c b/sbin/geom/class/eli/geom_eli.c
index 502303d..0c6ca2c 100644
--- a/sbin/geom/class/eli/geom_eli.c
+++ b/sbin/geom/class/eli/geom_eli.c
@@ -114,10 +114,11 @@ struct g_command class_commands[] = {
{ 'l', "keylen", "0", G_TYPE_NUMBER },
{ 'P', "nonewpassphrase", NULL, G_TYPE_BOOL },
{ 's', "sectorsize", "0", G_TYPE_NUMBER },
+ { 'T', "notrim", NULL, G_TYPE_BOOL },
{ 'V', "mdversion", "-1", G_TYPE_NUMBER },
G_OPT_SENTINEL
},
- "[-bPv] [-a aalgo] [-B backupfile] [-e ealgo] [-i iterations] [-l keylen] [-J newpassfile] [-K newkeyfile] [-s sectorsize] [-V version] prov"
+ "[-bPTv] [-a aalgo] [-B backupfile] [-e ealgo] [-i iterations] [-l keylen] [-J newpassfile] [-K newkeyfile] [-s sectorsize] [-V version] prov"
},
{ "label", G_FLAG_VERBOSE, eli_main,
{
@@ -170,17 +171,20 @@ struct g_command class_commands[] = {
{ 'e', "ealgo", GELI_ENC_ALGO, G_TYPE_STRING },
{ 'l', "keylen", "0", G_TYPE_NUMBER },
{ 's', "sectorsize", "0", G_TYPE_NUMBER },
+ { 'T', "notrim", NULL, G_TYPE_BOOL },
G_OPT_SENTINEL
},
- "[-d] [-a aalgo] [-e ealgo] [-l keylen] [-s sectorsize] prov"
+ "[-dT] [-a aalgo] [-e ealgo] [-l keylen] [-s sectorsize] prov"
},
{ "configure", G_FLAG_VERBOSE, eli_main,
{
{ 'b', "boot", NULL, G_TYPE_BOOL },
{ 'B', "noboot", NULL, G_TYPE_BOOL },
+ { 't', "trim", NULL, G_TYPE_BOOL },
+ { 'T', "notrim", NULL, G_TYPE_BOOL },
G_OPT_SENTINEL
},
- "[-bB] prov ..."
+ "[-bBtT] prov ..."
},
{ "setkey", G_FLAG_VERBOSE, eli_main,
{
@@ -698,6 +702,8 @@ eli_init(struct gctl_req *req)
md.md_flags = 0;
if (gctl_get_int(req, "boot"))
md.md_flags |= G_ELI_FLAG_BOOT;
+ if (gctl_get_int(req, "notrim"))
+ md.md_flags |= G_ELI_FLAG_NODELETE;
md.md_ealgo = CRYPTO_ALGORITHM_MIN - 1;
str = gctl_get_ascii(req, "aalgo");
if (*str != '\0') {
@@ -899,26 +905,45 @@ eli_attach(struct gctl_req *req)
}
static void
-eli_configure_detached(struct gctl_req *req, const char *prov, bool boot)
+eli_configure_detached(struct gctl_req *req, const char *prov, int boot,
+ int trim)
{
struct g_eli_metadata md;
+ bool changed = 0;
if (eli_metadata_read(req, prov, &md) == -1)
return;
- if (boot && (md.md_flags & G_ELI_FLAG_BOOT)) {
+ if (boot == 1 && (md.md_flags & G_ELI_FLAG_BOOT)) {
if (verbose)
printf("BOOT flag already configured for %s.\n", prov);
- } else if (!boot && !(md.md_flags & G_ELI_FLAG_BOOT)) {
+ } else if (boot == 0 && !(md.md_flags & G_ELI_FLAG_BOOT)) {
if (verbose)
printf("BOOT flag not configured for %s.\n", prov);
- } else {
+ } else if (boot >= 0) {
if (boot)
md.md_flags |= G_ELI_FLAG_BOOT;
else
md.md_flags &= ~G_ELI_FLAG_BOOT;
- eli_metadata_store(req, prov, &md);
+ changed = 1;
+ }
+
+ if (trim == 0 && (md.md_flags & G_ELI_FLAG_NODELETE)) {
+ if (verbose)
+ printf("TRIM disable flag already configured for %s.\n", prov);
+ } else if (trim == 1 && !(md.md_flags & G_ELI_FLAG_NODELETE)) {
+ if (verbose)
+ printf("TRIM disable flag not configured for %s.\n", prov);
+ } else if (trim >= 0) {
+ if (trim)
+ md.md_flags &= ~G_ELI_FLAG_NODELETE;
+ else
+ md.md_flags |= G_ELI_FLAG_NODELETE;
+ changed = 1;
}
+
+ if (changed)
+ eli_metadata_store(req, prov, &md);
bzero(&md, sizeof(md));
}
@@ -926,7 +951,8 @@ static void
eli_configure(struct gctl_req *req)
{
const char *prov;
- bool boot, noboot;
+ bool boot, noboot, trim, notrim;
+ int doboot, dotrim;
int i, nargs;
nargs = gctl_get_int(req, "nargs");
@@ -937,12 +963,30 @@ eli_configure(struct gctl_req *req)
boot = gctl_get_int(req, "boot");
noboot = gctl_get_int(req, "noboot");
+ trim = gctl_get_int(req, "trim");
+ notrim = gctl_get_int(req, "notrim");
+ doboot = -1;
if (boot && noboot) {
gctl_error(req, "Options -b and -B are mutually exclusive.");
return;
}
- if (!boot && !noboot) {
+ if (boot)
+ doboot = 1;
+ else if (noboot)
+ doboot = 0;
+
+ dotrim = -1;
+ if (trim && notrim) {
+ gctl_error(req, "Options -t and -T are mutually exclusive.");
+ return;
+ }
+ if (trim)
+ dotrim = 1;
+ else if (notrim)
+ dotrim = 0;
+
+ if (doboot == -1 && dotrim == -1) {
gctl_error(req, "No option given.");
return;
}
@@ -953,7 +997,7 @@ eli_configure(struct gctl_req *req)
for (i = 0; i < nargs; i++) {
prov = gctl_get_ascii(req, "arg%d", i);
if (!eli_is_attached(prov))
- eli_configure_detached(req, prov, boot);
+ eli_configure_detached(req, prov, doboot, dotrim);
}
}
OpenPOWER on IntegriCloud