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 <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-06-30 17:38:05 +02:00
committed by Rob Bradford
parent 6a1dee64e7
commit 3937c224a7

View File

@@ -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 => {