Skip to content

Commit

Permalink
sed: add '--read-only' to lock/unlock commands
Browse files Browse the repository at this point in the history
This change allows a user to specify that a drive is to be locked
read-only rather than just read-write. Also a drive that is locked
read-write can be "unlocked" to locked read-only.

The flag '--read-only' is used so the locking type can be specified.

Signed-off-by: Greg Joyce <[email protected]>
  • Loading branch information
gjoyce-ibm committed Jan 31, 2025
1 parent 56cf51b commit d0e5029
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
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
11 changes: 9 additions & 2 deletions plugins/sed/sedopal_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,11 @@ int sedopal_cmd_initialize(int fd)
*/
int sedopal_cmd_lock(int fd)
{
int lock_state = OPAL_LK;
if (sedopal_lock_ro)

Check failure on line 252 in plugins/sed/sedopal_cmd.c

View workflow job for this annotation

GitHub Actions / checkpatch review

WARNING: Missing a blank line after declarations
lock_state = OPAL_RO;

return sedopal_lock_unlock(fd, OPAL_LK);
return sedopal_lock_unlock(fd, lock_state);
}

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

rc = sedopal_lock_unlock(fd, OPAL_RW);
if (sedopal_lock_ro)
lock_state = OPAL_RO;

rc = sedopal_lock_unlock(fd, lock_state);

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

0 comments on commit d0e5029

Please sign in to comment.