forked from linux-nvme/nvme-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sed: Add plugin for basic SED Opal operations
A new plugin 'sed' is developed to provide basic SED Opal CLI operations. These include: discover Discover drive locking features intialize Initialize a drive for SED Opal password Change the authorization key revert Revert drive to SED Opal disabled lock Lock a SED Opal drive unlock Unlock a SED Opal drive Signed-off-by: Greg Joyce <[email protected]>
- Loading branch information
1 parent
d088264
commit 83aad43
Showing
8 changed files
with
865 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,4 +29,7 @@ if json_c_dep.found() | |
] | ||
subdir('solidigm') | ||
subdir('ocp') | ||
if conf.has('HAVE_SED_OPAL') | ||
subdir('sed') | ||
endif | ||
endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources += [ | ||
'plugins/sed/sed.c', | ||
'plugins/sed/sedopal_cmd.c', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <stdbool.h> | ||
#include <inttypes.h> | ||
#include <linux/fs.h> | ||
#include <sys/stat.h> | ||
|
||
#include "common.h" | ||
#include "nvme.h" | ||
#include "libnvme.h" | ||
#include "nvme-print.h" | ||
#include "sedopal_cmd.h" | ||
#include <linux/sed-opal.h> | ||
|
||
#define CREATE_CMD | ||
#include "sed.h" | ||
|
||
OPT_ARGS(no_opts) = { | ||
OPT_END() | ||
}; | ||
|
||
OPT_ARGS(key_opts) = { | ||
OPT_FLAG("ask-key", 'k', &sedopal_ask_key, | ||
"prompt for SED authentication key"), | ||
OPT_END() | ||
}; | ||
|
||
OPT_ARGS(revert_opts) = { | ||
OPT_FLAG("destructive", 'e', &sedopal_destructive_revert, | ||
"destructive revert"), | ||
OPT_FLAG("psid", 'p', &sedopal_psid_revert, "PSID revert"), | ||
OPT_END() | ||
}; | ||
|
||
|
||
/* | ||
* Open the NVMe device specified on the command line. It must be the | ||
* NVMe block device (e.g. /dev/nvme0n1). | ||
*/ | ||
static int sed_opal_open_device(struct nvme_dev **dev, int argc, char **argv, | ||
const char *desc, struct argconfig_commandline_options *opts) | ||
{ | ||
int err; | ||
|
||
err = parse_and_open(dev, argc, argv, desc, opts); | ||
if (err) | ||
return err; | ||
|
||
if (!S_ISBLK((*dev)->direct.stat.st_mode)) { | ||
fprintf(stderr, | ||
"ERROR : The NVMe block device must be specified\n"); | ||
err = -EINVAL; | ||
dev_close(*dev); | ||
} | ||
|
||
return err; | ||
} | ||
|
||
static int sed_opal_discover(int argc, char **argv, struct command *cmd, | ||
struct plugin *plugin) | ||
{ | ||
int err; | ||
const char *desc = "Query SED device and display locking features"; | ||
struct nvme_dev *dev; | ||
|
||
err = sed_opal_open_device(&dev, argc, argv, desc, no_opts); | ||
if (err) | ||
return err; | ||
|
||
err = sedopal_cmd_discover(dev->direct.fd); | ||
|
||
dev_close(dev); | ||
return err; | ||
} | ||
|
||
static int sed_opal_initialize(int argc, char **argv, struct command *cmd, | ||
struct plugin *plugin) | ||
{ | ||
int err; | ||
const char *desc = "Initialize a SED device for locking"; | ||
struct nvme_dev *dev; | ||
|
||
err = sed_opal_open_device(&dev, argc, argv, desc, no_opts); | ||
if (err) | ||
return err; | ||
|
||
err = sedopal_cmd_initialize(dev->direct.fd); | ||
if (err != 0) | ||
fprintf(stderr, "initialize: SED error - %s\n", | ||
sedopal_error_to_text(err)); | ||
|
||
dev_close(dev); | ||
return err; | ||
} | ||
|
||
static int sed_opal_revert(int argc, char **argv, struct command *cmd, | ||
struct plugin *plugin) | ||
{ | ||
int err; | ||
const char *desc = "Revert a SED device from locking state"; | ||
struct nvme_dev *dev; | ||
|
||
err = sed_opal_open_device(&dev, argc, argv, desc, revert_opts); | ||
if (err) | ||
return err; | ||
|
||
err = sedopal_cmd_revert(dev->direct.fd); | ||
if (err != 0) | ||
fprintf(stderr, "revert: SED error - %s\n", | ||
sedopal_error_to_text(err)); | ||
|
||
dev_close(dev); | ||
return err; | ||
} | ||
|
||
static int sed_opal_lock(int argc, char **argv, struct command *cmd, | ||
struct plugin *plugin) | ||
{ | ||
int err; | ||
const char *desc = "Lock a SED device"; | ||
struct nvme_dev *dev; | ||
|
||
err = sed_opal_open_device(&dev, argc, argv, desc, key_opts); | ||
if (err) | ||
return err; | ||
|
||
err = sedopal_cmd_lock(dev->direct.fd); | ||
if (err != 0) | ||
fprintf(stderr, "lock: SED error - %s\n", | ||
sedopal_error_to_text(err)); | ||
|
||
dev_close(dev); | ||
return err; | ||
} | ||
|
||
static int sed_opal_unlock(int argc, char **argv, struct command *cmd, | ||
struct plugin *plugin) | ||
{ | ||
int err; | ||
const char *desc = "Unlock a SED device"; | ||
struct nvme_dev *dev; | ||
|
||
err = sed_opal_open_device(&dev, argc, argv, desc, key_opts); | ||
if (err) | ||
return err; | ||
|
||
err = sedopal_cmd_unlock(dev->direct.fd); | ||
if (err != 0) | ||
fprintf(stderr, "unlock: SED error - %s\n", | ||
sedopal_error_to_text(err)); | ||
|
||
dev_close(dev); | ||
return err; | ||
} | ||
|
||
static int sed_opal_password(int argc, char **argv, struct command *cmd, | ||
struct plugin *plugin) | ||
{ | ||
int err; | ||
const char *desc = "Change the locking password of a SED device"; | ||
struct nvme_dev *dev; | ||
|
||
err = sed_opal_open_device(&dev, argc, argv, desc, no_opts); | ||
if (err) | ||
return err; | ||
|
||
err = sedopal_cmd_password(dev->direct.fd); | ||
if (err != 0) | ||
fprintf(stderr, "password: SED error - %s\n", | ||
sedopal_error_to_text(err)); | ||
|
||
dev_close(dev); | ||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
#undef CMD_INC_FILE | ||
#define CMD_INC_FILE plugins/sed/sed | ||
|
||
#include "cmd.h" | ||
#include <linux/sed-opal.h> | ||
|
||
PLUGIN(NAME("sed", "SED Opal Command Set", NVME_VERSION), | ||
COMMAND_LIST( | ||
ENTRY("discover", "Discover SED Opal Locking Features", sed_opal_discover, "1") | ||
ENTRY("initialize", "Initialize a SED Opal Device for locking", sed_opal_initialize) | ||
ENTRY("revert", "Revert a SED Opal Device from locking", sed_opal_revert) | ||
ENTRY("lock", "Lock a SED Opal Device", sed_opal_lock) | ||
ENTRY("unlock", "Unlock a SED Opal Device", sed_opal_unlock) | ||
ENTRY("password", "Change the SED Opal Device password", sed_opal_password) | ||
) | ||
); | ||
|
||
#include "define_cmd.h" |
Oops, something went wrong.