Skip to content

Commit c988844

Browse files
nonapodeDavid Kozub
authored andcommitted
block: sed-opal: add ioctl for done-mark of shadow mbr
Enable users to mark the shadow mbr as done without completely deactivating the shadow mbr feature. This may be useful on reboots, when the power to the disk is not disconnected in between and the shadow mbr stores the required boot files. Of course, this saves also the (few) commands required to enable the feature if it is already enabled and one only wants to mark the shadow mbr as done. Co-authored-by: David Kozub <zub@linux.fjfi.cvut.cz> Signed-off-by: Jonas Rabenstein <jonas.rabenstein@studium.uni-erlangen.de> Signed-off-by: David Kozub <zub@linux.fjfi.cvut.cz> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed by: Scott Bauer <sbauer@plzdonthack.me> Reviewed-by: Jon Derrick <jonathan.derrick@intel.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b620743 commit c988844

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

‎block/sed-opal.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,30 @@ static int opal_enable_disable_shadow_mbr(struct opal_dev *dev,
19891989
return ret;
19901990
}
19911991

1992+
static int opal_set_mbr_done(struct opal_dev *dev,
1993+
struct opal_mbr_done *mbr_done)
1994+
{
1995+
u8 mbr_done_tf = mbr_done->done_flag == OPAL_MBR_DONE ?
1996+
OPAL_TRUE : OPAL_FALSE;
1997+
1998+
const struct opal_step mbr_steps[] = {
1999+
{ start_admin1LSP_opal_session, &mbr_done->key },
2000+
{ set_mbr_done, &mbr_done_tf },
2001+
{ end_opal_session, }
2002+
};
2003+
int ret;
2004+
2005+
if (mbr_done->done_flag != OPAL_MBR_DONE &&
2006+
mbr_done->done_flag != OPAL_MBR_NOT_DONE)
2007+
return -EINVAL;
2008+
2009+
mutex_lock(&dev->dev_lock);
2010+
setup_opal_dev(dev);
2011+
ret = execute_steps(dev, mbr_steps, ARRAY_SIZE(mbr_steps));
2012+
mutex_unlock(&dev->dev_lock);
2013+
return ret;
2014+
}
2015+
19922016
static int opal_save(struct opal_dev *dev, struct opal_lock_unlock *lk_unlk)
19932017
{
19942018
struct opal_suspend_data *suspend;
@@ -2310,6 +2334,9 @@ int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *arg)
23102334
case IOC_OPAL_ENABLE_DISABLE_MBR:
23112335
ret = opal_enable_disable_shadow_mbr(dev, p);
23122336
break;
2337+
case IOC_OPAL_MBR_DONE:
2338+
ret = opal_set_mbr_done(dev, p);
2339+
break;
23132340
case IOC_OPAL_ERASE_LR:
23142341
ret = opal_erase_locking_range(dev, p);
23152342
break;

‎include/linux/sed-opal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static inline bool is_sed_ioctl(unsigned int cmd)
4040
case IOC_OPAL_ERASE_LR:
4141
case IOC_OPAL_SECURE_ERASE_LR:
4242
case IOC_OPAL_PSID_REVERT_TPR:
43+
case IOC_OPAL_MBR_DONE:
4344
return true;
4445
}
4546
return false;

‎include/uapi/linux/sed-opal.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ enum opal_mbr {
2020
OPAL_MBR_DISABLE = 0x01,
2121
};
2222

23+
enum opal_mbr_done_flag {
24+
OPAL_MBR_NOT_DONE = 0x0,
25+
OPAL_MBR_DONE = 0x01
26+
};
27+
2328
enum opal_user {
2429
OPAL_ADMIN1 = 0x0,
2530
OPAL_USER1 = 0x01,
@@ -95,6 +100,12 @@ struct opal_mbr_data {
95100
__u8 __align[7];
96101
};
97102

103+
struct opal_mbr_done {
104+
struct opal_key key;
105+
__u8 done_flag;
106+
__u8 __align[7];
107+
};
108+
98109
#define IOC_OPAL_SAVE _IOW('p', 220, struct opal_lock_unlock)
99110
#define IOC_OPAL_LOCK_UNLOCK _IOW('p', 221, struct opal_lock_unlock)
100111
#define IOC_OPAL_TAKE_OWNERSHIP _IOW('p', 222, struct opal_key)
@@ -108,5 +119,6 @@ struct opal_mbr_data {
108119
#define IOC_OPAL_ERASE_LR _IOW('p', 230, struct opal_session_info)
109120
#define IOC_OPAL_SECURE_ERASE_LR _IOW('p', 231, struct opal_session_info)
110121
#define IOC_OPAL_PSID_REVERT_TPR _IOW('p', 232, struct opal_key)
122+
#define IOC_OPAL_MBR_DONE _IOW('p', 233, struct opal_mbr_done)
111123

112124
#endif /* _UAPI_SED_OPAL_H */

0 commit comments

Comments
 (0)