Create a new vhost-user-blk device
(
id: String,
vu_cfg: VhostUserConfig,
seccomp_action: SeccompAction,
exit_evt: EventFd,
access_platform_enabled: bool,
state: Option<State>,
)
| 50 | impl Blk { |
| 51 | /// Create a new vhost-user-blk device |
| 52 | pub fn new( |
| 53 | id: String, |
| 54 | vu_cfg: VhostUserConfig, |
| 55 | seccomp_action: SeccompAction, |
| 56 | exit_evt: EventFd, |
| 57 | access_platform_enabled: bool, |
| 58 | state: Option<State>, |
| 59 | ) -> Result<Blk> { |
| 60 | let num_queues = vu_cfg.num_queues; |
| 61 | |
| 62 | let mut vu = VhostUserHandle::connect_vhost_user( |
| 63 | false, |
| 64 | &vu_cfg.socket, |
| 65 | num_queues as u64, |
| 66 | false, |
| 67 | None, |
| 68 | )?; |
| 69 | |
| 70 | let ( |
| 71 | avail_features, |
| 72 | acked_features, |
| 73 | acked_protocol_features, |
| 74 | vu_num_queues, |
| 75 | config, |
| 76 | paused, |
| 77 | vring_bases, |
| 78 | ) = if let Some(state) = state { |
| 79 | info!("Restoring vhost-user-block {id}"); |
| 80 | |
| 81 | vu.set_protocol_features_vhost_user( |
| 82 | state.acked_features, |
| 83 | state.acked_protocol_features, |
| 84 | )?; |
| 85 | |
| 86 | vu.restore_state(&state)?; |
| 87 | |
| 88 | ( |
| 89 | state.avail_features, |
| 90 | state.acked_features, |
| 91 | state.acked_protocol_features, |
| 92 | state.vu_num_queues, |
| 93 | state.config, |
| 94 | true, |
| 95 | state.vring_bases, |
| 96 | ) |
| 97 | } else { |
| 98 | // Filling device and vring features VMM supports. |
| 99 | let mut avail_features = (1 << VIRTIO_BLK_F_SIZE_MAX) |
| 100 | | (1 << VIRTIO_BLK_F_SEG_MAX) |
| 101 | | (1 << VIRTIO_BLK_F_GEOMETRY) |
| 102 | | (1 << VIRTIO_BLK_F_RO) |
| 103 | | (1 << VIRTIO_BLK_F_BLK_SIZE) |
| 104 | | (1 << VIRTIO_BLK_F_FLUSH) |
| 105 | | (1 << VIRTIO_BLK_F_TOPOLOGY) |
| 106 | | (1 << VIRTIO_BLK_F_CONFIG_WCE) |
| 107 | | (1 << VIRTIO_BLK_F_DISCARD) |
| 108 | | (1 << VIRTIO_BLK_F_WRITE_ZEROES) |
| 109 | | DEFAULT_VIRTIO_FEATURES; |
nothing calls this directly
no test coverage detected