From 3937c224a7cadc6cfe5b8b7d7b7bfc7c26a14850 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Tue, 30 Jun 2026 17:38:05 +0200 Subject: [PATCH] block: qcow: Query backing raw size without the cursor Opening a raw backing file issued a seek to the end for its size and then rewound the cursor. RawBacking reads through read_exact_at, so the cursor reset was dead. Query the size through query_device_size, matching the crate convention and returning the right size for a block device backing file as well, and drop the rewind. The now unused SeekFrom import is removed. The result is unchanged. Signed-off-by: Anatol Belski --- block/src/formats/qcow/internal/mod.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/block/src/formats/qcow/internal/mod.rs b/block/src/formats/qcow/internal/mod.rs index 707de87d1..53fe9eb4a 100644 --- a/block/src/formats/qcow/internal/mod.rs +++ b/block/src/formats/qcow/internal/mod.rs @@ -16,7 +16,7 @@ mod vec_cache; use std::cmp::{max, min}; use std::fmt::{Debug, Formatter, Result as FmtResult}; use std::fs::{OpenOptions, read_link}; -use std::io::{self, Seek, SeekFrom}; +use std::io::{self, Seek}; use std::os::fd::AsRawFd; use std::os::unix::fs::FileExt; use std::path::Path; @@ -42,6 +42,7 @@ use vec_cache::{CacheMap, VecCache}; use crate::aligned_file::AlignedFile; use crate::error::{BlockError, BlockErrorKind, BlockResult}; +use crate::query_device_size; #[sorted] #[derive(Debug, Error)] @@ -215,18 +216,14 @@ impl BackingFile { let (kind, virtual_size) = match backing_format { ImageType::Raw => { - let size = raw_file.seek(SeekFrom::End(0)).map_err(|e| { - BlockError::new( - BlockErrorKind::Io, - Error::BackingFileIo(config.path.clone(), e), - ) - })?; - raw_file.rewind().map_err(|e| { - BlockError::new( - BlockErrorKind::Io, - Error::BackingFileIo(config.path.clone(), e), - ) - })?; + let size = query_device_size(raw_file.file()) + .map_err(|e| { + BlockError::new( + BlockErrorKind::Io, + Error::BackingFileIo(config.path.clone(), e), + ) + })? + .0; (BackingKind::Raw(raw_file), size) } ImageType::Qcow2 => {