Skip to content

Commit eea4913

Browse files
gjoyce-ibmigaw
authored andcommitted
sed: add '--read-only' to lock/unlock commands
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]>
1 parent 48263a3 commit eea4913

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

plugins/sed/sed.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ OPT_ARGS(revert_opts) = {
4242
OPT_END()
4343
};
4444

45+
OPT_ARGS(lock_opts) = {
46+
OPT_FLAG("read-only", 'r', &sedopal_lock_ro,
47+
"Set locking range to read-only"),
48+
OPT_FLAG("ask-key", 'k', &sedopal_ask_key,
49+
"prompt for SED authentication key"),
50+
OPT_END()
51+
};
4552

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

133-
err = sed_opal_open_device(&dev, argc, argv, desc, key_opts);
140+
err = sed_opal_open_device(&dev, argc, argv, desc, lock_opts);
134141
if (err)
135142
return err;
136143

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

153-
err = sed_opal_open_device(&dev, argc, argv, desc, key_opts);
160+
err = sed_opal_open_device(&dev, argc, argv, desc, lock_opts);
154161
if (err)
155162
return err;
156163

plugins/sed/sedopal_cmd.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,12 @@ int sedopal_cmd_initialize(int fd)
248248
*/
249249
int sedopal_cmd_lock(int fd)
250250
{
251+
int lock_state = OPAL_LK;
251252

252-
return sedopal_lock_unlock(fd, OPAL_LK);
253+
if (sedopal_lock_ro)
254+
lock_state = OPAL_RO;
255+
256+
return sedopal_lock_unlock(fd, lock_state);
253257
}
254258

255259
/*
@@ -258,8 +262,12 @@ int sedopal_cmd_lock(int fd)
258262
int sedopal_cmd_unlock(int fd)
259263
{
260264
int rc;
265+
int lock_state = OPAL_RW;
266+
267+
if (sedopal_lock_ro)
268+
lock_state = OPAL_RO;
261269

262-
rc = sedopal_lock_unlock(fd, OPAL_RW);
270+
rc = sedopal_lock_unlock(fd, lock_state);
263271

264272
/*
265273
* If the unlock was successful, force a re-read of the

0 commit comments

Comments
 (0)