mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-21 15:31:15 +00:00
Revert "vhost_rs: add config messge support"
This reverts commit 3e99098bf3
because we
realized there was no need for those extra functions to be introduced as
the existing one from the vhost crate are sufficient for the vhost-user
configuration use case.
This commit is contained in:
parent
0a0c7358a2
commit
c347f84d74
@ -197,45 +197,6 @@ impl<R: Req> Endpoint<R> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Send a message with header, body and config info. Optional file descriptors may be attached to
|
|
||||||
/// the message.
|
|
||||||
///
|
|
||||||
/// # Return:
|
|
||||||
/// * - number of bytes sent on success
|
|
||||||
/// * - SocketRetry: temporary error caused by signals or short of resources.
|
|
||||||
/// * - SocketBroken: the underline socket is broken.
|
|
||||||
/// * - SocketError: other socket related errors.
|
|
||||||
/// * - PartialMessage: received a partial message.
|
|
||||||
pub fn send_config_message(
|
|
||||||
&mut self,
|
|
||||||
hdr: &VhostUserMsgHeader<R>,
|
|
||||||
user_config: &VhostUserConfig,
|
|
||||||
buf: &mut [u8],
|
|
||||||
fds: Option<&[RawFd]>,
|
|
||||||
) -> Result<()> {
|
|
||||||
// Safe because there can't be other mutable referance to hdr and body.
|
|
||||||
let iovs = unsafe {
|
|
||||||
[
|
|
||||||
slice::from_raw_parts(
|
|
||||||
hdr as *const VhostUserMsgHeader<R> as *const u8,
|
|
||||||
mem::size_of::<VhostUserMsgHeader<R>>(),
|
|
||||||
),
|
|
||||||
slice::from_raw_parts(
|
|
||||||
user_config as *const VhostUserConfig as *const u8,
|
|
||||||
mem::size_of::<VhostUserConfig>(),
|
|
||||||
),
|
|
||||||
slice::from_raw_parts(buf.as_ptr() as *const u8, buf.len()),
|
|
||||||
]
|
|
||||||
};
|
|
||||||
let bytes = self.send_iovec(&iovs[..], fds)?;
|
|
||||||
let total =
|
|
||||||
mem::size_of::<VhostUserMsgHeader<R>>() + mem::size_of::<VhostUserConfig>() + buf.len();
|
|
||||||
if bytes != total {
|
|
||||||
return Err(Error::PartialMessage);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Send a message with header, body and payload. Optional file descriptors
|
/// Send a message with header, body and payload. Optional file descriptors
|
||||||
/// may also be attached to the message.
|
/// may also be attached to the message.
|
||||||
///
|
///
|
||||||
|
@ -360,7 +360,7 @@ impl VhostUserMaster for Master {
|
|||||||
// "Master payload: virtio device config space"
|
// "Master payload: virtio device config space"
|
||||||
// But what content should the payload contains for a get_config() request?
|
// But what content should the payload contains for a get_config() request?
|
||||||
// So current implementation doesn't conform to the spec.
|
// So current implementation doesn't conform to the spec.
|
||||||
let hdr = node.send_request_with_config_body(MasterReq::GET_CONFIG, &body, None)?;
|
let hdr = node.send_request_with_body(MasterReq::GET_CONFIG, &body, None)?;
|
||||||
let (reply, buf, rfds) = node.recv_reply_with_payload::<VhostUserConfig>(&hdr)?;
|
let (reply, buf, rfds) = node.recv_reply_with_payload::<VhostUserConfig>(&hdr)?;
|
||||||
if rfds.is_some() {
|
if rfds.is_some() {
|
||||||
Endpoint::<MasterReq>::close_rfds(rfds);
|
Endpoint::<MasterReq>::close_rfds(rfds);
|
||||||
@ -480,27 +480,6 @@ impl MasterInternal {
|
|||||||
Ok(hdr)
|
Ok(hdr)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_request_with_config_body(
|
|
||||||
&mut self,
|
|
||||||
code: MasterReq,
|
|
||||||
user_config: &VhostUserConfig,
|
|
||||||
fds: Option<&[RawFd]>,
|
|
||||||
) -> VhostUserResult<VhostUserMsgHeader<MasterReq>> {
|
|
||||||
if mem::size_of::<VhostUserConfig>() + user_config.size as usize > MAX_MSG_SIZE {
|
|
||||||
return Err(VhostUserError::InvalidParam);
|
|
||||||
}
|
|
||||||
self.check_state()?;
|
|
||||||
|
|
||||||
let hdr = Self::new_request_header(
|
|
||||||
code,
|
|
||||||
mem::size_of::<VhostUserConfig>() as u32 + user_config.size,
|
|
||||||
);
|
|
||||||
let mut buf = vec![0; user_config.size as usize];
|
|
||||||
self.main_sock
|
|
||||||
.send_config_message(&hdr, user_config, &mut buf, fds)?;
|
|
||||||
Ok(hdr)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_request_with_payload<T: Sized, P: Sized>(
|
fn send_request_with_payload<T: Sized, P: Sized>(
|
||||||
&mut self,
|
&mut self,
|
||||||
code: MasterReq,
|
code: MasterReq,
|
||||||
@ -576,7 +555,7 @@ impl MasterInternal {
|
|||||||
if !reply.is_reply_for(hdr)
|
if !reply.is_reply_for(hdr)
|
||||||
|| reply.get_size() as usize != mem::size_of::<T>() + bytes
|
|| reply.get_size() as usize != mem::size_of::<T>() + bytes
|
||||||
|| rfds.is_some()
|
|| rfds.is_some()
|
||||||
|| !body.is_valid()
|
|| body.is_valid()
|
||||||
{
|
{
|
||||||
Endpoint::<MasterReq>::close_rfds(rfds);
|
Endpoint::<MasterReq>::close_rfds(rfds);
|
||||||
return Err(VhostUserError::InvalidMessage);
|
return Err(VhostUserError::InvalidMessage);
|
||||||
|
Loading…
Reference in New Issue
Block a user