rust-vmm / vm-virtio

virtio implementation
Apache License 2.0
364 stars 87 forks source link

[virtio-queue] add events/metrics support #105

Open lauralt opened 2 years ago

lauralt commented 2 years ago

In case of a queue misconfiguration, we log an error by using the log crate. We can get rid of this dependency by defining a QueueEvents trait and let the backend decide how they want to handle different events, an example here for the serial console. Another option would be to return errors instead of logging an error. Related to: https://github.com/rust-vmm/vm-virtio/issues/94.

uran0sH commented 2 years ago

I will add trait QueueEvents in virtio-queue, like below:

/// Define a QueueEvents trait and let the backend decide how they want to handle different events
pub trait QueueEvents {
   // some methods
   ....
}

And the device in the devices crate will implement this trait.

lauralt commented 2 years ago

@uran0sH I assigned you to the issue. Thanks!

uran0sH commented 2 years ago

I try to add QueueEvents to QueueState as its field, like below. And I find some problems.

pub struct QueueState<EV: QueueEvents> {
    ...
    /// Queue Events
    pub queue_evts: EV,
}

pub struct Queue<M: GuestAddressSpace, EV: 'static + QueueEvents, S: QueueStateT<EV> = QueueState<EV>> {
    /// Guest memory object associated with the queue.
    pub mem: M,
    /// Virtio queue state.
    pub state: S,
    _marker: PhantomData<EV>,
}
  1. if we add queue_evts to QueueState , we need modify new method of QueueStateT, like fn new(max_size: u16, queue_evts: EV) -> Self
  2. And it will also affect virtio-queue-ser
    impl From<&QueueStateSer> for QueueState {
    fn from(state: &QueueStateSer) -> Self {
        QueueState {
            queue_evts: ?
        }
    }
    }

    What value should we assign to queue_evts?

  3. the struct implementing QueueState must be static, since pub trait QueueStateT<EV: 'static + QueueEvents>: for<'a> QueueStateGuard<'a, EV>. I can't find other methods to solve this. Maybe you have other methods?