mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust/pv: Provide default for UvCmd::cmd
Provides a default for the cmd function for an UvCmd. This is enabled by requiring an associated constant for the IOCTL nr of the command. Signed-off-by: Steffen Eiden <seiden@linux.ibm.com> Reviewed-by: Julian Ruess <julianr@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
8f89234f1a
commit
81a1e13f3b
@@ -83,15 +83,20 @@ fn rc_fmt<C: UvCmd>(rc: u16, rrc: u16, cmd: &mut C) -> &'static str {
|
||||
|
||||
/// Ultravisor Command.
|
||||
pub trait UvCmd {
|
||||
/// The UV IOCTL number of the UV call
|
||||
const UV_IOCTL_NR: u8;
|
||||
/// Returns the uvdevice IOCTL command that his command uses.
|
||||
///
|
||||
/// # Returns
|
||||
/// The IOCTL cmd for this UvCmd usually sth like `uv_ioctl!(CMD_NR)`
|
||||
fn cmd(&self) -> u64;
|
||||
fn cmd(&self) -> u64 {
|
||||
uv_ioctl(Self::UV_IOCTL_NR)
|
||||
}
|
||||
/// Converts UV return codes into human readable error messages
|
||||
///
|
||||
/// no need to handle `0x0000, 0x0001, 0x0002, 0x0005, 0x0030, 0x0031, 0x0032, 0x0100`
|
||||
fn rc_fmt(&self, rc: u16, rrc: u16) -> Option<&'static str>;
|
||||
|
||||
/// Returns data used by this command if available.
|
||||
fn data(&mut self) -> Option<&mut [u8]> {
|
||||
None
|
||||
|
||||
@@ -72,9 +72,7 @@ impl From<uvio_uvdev_info> for UvDeviceInfo {
|
||||
}
|
||||
|
||||
impl UvCmd for uvio_uvdev_info {
|
||||
fn cmd(&self) -> u64 {
|
||||
uv_ioctl(UvDevice::INFO_NR)
|
||||
}
|
||||
const UV_IOCTL_NR: u8 = UvDevice::INFO_NR;
|
||||
|
||||
fn data(&mut self) -> Option<&mut [u8]> {
|
||||
Some(self.as_bytes_mut())
|
||||
|
||||
@@ -42,14 +42,12 @@ impl Default for ListCmd {
|
||||
}
|
||||
|
||||
impl UvCmd for ListCmd {
|
||||
const UV_IOCTL_NR: u8 = UvDevice::LIST_SECRET_NR;
|
||||
|
||||
fn data(&mut self) -> Option<&mut [u8]> {
|
||||
Some(self.0.as_mut_slice())
|
||||
}
|
||||
|
||||
fn cmd(&self) -> u64 {
|
||||
uv_ioctl(UvDevice::LIST_SECRET_NR)
|
||||
}
|
||||
|
||||
fn rc_fmt(&self, _rc: u16, _rrc: u16) -> Option<&'static str> {
|
||||
None
|
||||
}
|
||||
@@ -80,14 +78,12 @@ impl AddCmd {
|
||||
}
|
||||
|
||||
impl UvCmd for AddCmd {
|
||||
const UV_IOCTL_NR: u8 = UvDevice::ADD_SECRET_NR;
|
||||
|
||||
fn data(&mut self) -> Option<&mut [u8]> {
|
||||
Some(&mut self.0)
|
||||
}
|
||||
|
||||
fn cmd(&self) -> u64 {
|
||||
uv_ioctl(UvDevice::ADD_SECRET_NR)
|
||||
}
|
||||
|
||||
fn rc_fmt(&self, rc: u16, _rrc: u16) -> Option<&'static str> {
|
||||
match rc {
|
||||
0x0101 => Some("not allowed to modify the secret store"),
|
||||
@@ -116,9 +112,7 @@ impl UvCmd for AddCmd {
|
||||
/// request to modify the secret store will fail.
|
||||
pub struct LockCmd;
|
||||
impl UvCmd for LockCmd {
|
||||
fn cmd(&self) -> u64 {
|
||||
uv_ioctl(UvDevice::LOCK_SECRET_NR)
|
||||
}
|
||||
const UV_IOCTL_NR: u8 = UvDevice::LOCK_SECRET_NR;
|
||||
|
||||
fn rc_fmt(&self, rc: u16, _rrc: u16) -> Option<&'static str> {
|
||||
match rc {
|
||||
|
||||
@@ -107,6 +107,8 @@ impl ffi::uvio_ioctl_cb {
|
||||
const TEST_CMD: u64 = 17;
|
||||
struct TestCmd(Option<Vec<u8>>);
|
||||
impl UvCmd for TestCmd {
|
||||
const UV_IOCTL_NR: u8 = 42;
|
||||
|
||||
fn cmd(&self) -> u64 {
|
||||
TEST_CMD
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user