Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions plugins/sed/sed.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ OPT_ARGS(revert_opts) = {
OPT_END()
};

OPT_ARGS(lock_opts) = {
OPT_FLAG("read-only", 'r', &sedopal_lock_ro,
"Set locking range to read-only"),
OPT_FLAG("ask-key", 'k', &sedopal_ask_key,
"prompt for SED authentication key"),
OPT_END()
};

/*
* Open the NVMe device specified on the command line. It must be the
Expand Down Expand Up @@ -130,7 +137,7 @@ static int sed_opal_lock(int argc, char **argv, struct command *cmd,
const char *desc = "Lock a SED device";
struct nvme_dev *dev;

err = sed_opal_open_device(&dev, argc, argv, desc, key_opts);
err = sed_opal_open_device(&dev, argc, argv, desc, lock_opts);
if (err)
return err;

Expand All @@ -150,7 +157,7 @@ static int sed_opal_unlock(int argc, char **argv, struct command *cmd,
const char *desc = "Unlock a SED device";
struct nvme_dev *dev;

err = sed_opal_open_device(&dev, argc, argv, desc, key_opts);
err = sed_opal_open_device(&dev, argc, argv, desc, lock_opts);
if (err)
return err;

Expand Down
12 changes: 10 additions & 2 deletions plugins/sed/sedopal_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,12 @@ int sedopal_cmd_initialize(int fd)
*/
int sedopal_cmd_lock(int fd)
{
int lock_state = OPAL_LK;

return sedopal_lock_unlock(fd, OPAL_LK);
if (sedopal_lock_ro)
lock_state = OPAL_RO;

return sedopal_lock_unlock(fd, lock_state);
}

/*
Expand All @@ -258,8 +262,12 @@ int sedopal_cmd_lock(int fd)
int sedopal_cmd_unlock(int fd)
{
int rc;
int lock_state = OPAL_RW;

if (sedopal_lock_ro)
lock_state = OPAL_RO;

rc = sedopal_lock_unlock(fd, OPAL_RW);
rc = sedopal_lock_unlock(fd, lock_state);

/*
* If the unlock was successful, force a re-read of the
Expand Down