From 8e52bf251bf61bf18d8fa08d05adfdea9388a60c Mon Sep 17 00:00:00 2001 From: Thomas Prescher Date: Mon, 10 Nov 2025 14:22:48 +0100 Subject: [PATCH] block: virtio-devices: make disk_nsectors a shared atomic This change is a prerequisite for live disk resizing. Before this commit, the epoll-handler threads just got a copy of the sector size which we cannot update during runtime. On-behalf-of: SAP thomas.prescher@sap.com Signed-off-by: Thomas Prescher --- virtio-devices/src/block.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/virtio-devices/src/block.rs b/virtio-devices/src/block.rs index 0f46ce389..2ede4c15a 100644 --- a/virtio-devices/src/block.rs +++ b/virtio-devices/src/block.rs @@ -137,7 +137,7 @@ struct BlockEpollHandler { queue: Queue, mem: GuestMemoryAtomic, disk_image: Box, - disk_nsectors: u64, + disk_nsectors: Arc, interrupt_cb: Arc, serial: Vec, kill_evt: EventFd, @@ -234,7 +234,7 @@ impl BlockEpollHandler { let result = request.execute_async( desc_chain.memory(), - self.disk_nsectors, + self.disk_nsectors.load(Ordering::SeqCst), self.disk_image.as_mut(), &self.serial, desc_chain.head_index() as u64, @@ -625,7 +625,7 @@ pub struct Block { id: String, disk_image: Box, disk_path: PathBuf, - disk_nsectors: u64, + disk_nsectors: Arc, config: VirtioBlockConfig, writeback: Arc, counters: BlockCounters, @@ -753,7 +753,7 @@ impl Block { id, disk_image, disk_path, - disk_nsectors, + disk_nsectors: Arc::new(AtomicU64::new(disk_nsectors)), config, writeback: Arc::new(AtomicBool::new(true)), counters: BlockCounters::default(), @@ -843,7 +843,7 @@ impl Block { fn state(&self) -> BlockState { BlockState { disk_path: self.disk_path.to_str().unwrap().to_owned(), - disk_nsectors: self.disk_nsectors, + disk_nsectors: self.disk_nsectors.load(Ordering::SeqCst), avail_features: self.common.avail_features, acked_features: self.common.acked_features, config: self.config, @@ -957,7 +957,7 @@ impl VirtioDevice for Block { error!("failed to create new AsyncIo: {e}"); ActivateError::BadActivate })?, - disk_nsectors: self.disk_nsectors, + disk_nsectors: self.disk_nsectors.clone(), interrupt_cb: interrupt_cb.clone(), serial: self.serial.clone(), kill_evt,