mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Access the qcow header feature bits positionally
Convert the qcow header feature bit writes to positional access and drop the now unused Seek imports. The result is unchanged. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
43682e22b0
commit
aa4eb943f3
@@ -9,7 +9,6 @@
|
|||||||
//! QCOW2 header parsing, validation, and creation.
|
//! QCOW2 header parsing, validation, and creation.
|
||||||
|
|
||||||
use std::fmt::{Display, Formatter, Result as FmtResult};
|
use std::fmt::{Display, Formatter, Result as FmtResult};
|
||||||
use std::io::{Seek, SeekFrom, Write};
|
|
||||||
use std::os::unix::fs::FileExt;
|
use std::os::unix::fs::FileExt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
@@ -566,14 +565,15 @@ impl QcowHeader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write only the incompatible_features field to the file at its fixed offset.
|
/// Write only the incompatible_features field to the file at its fixed offset.
|
||||||
fn write_incompatible_features<F: Seek + Write>(&self, file: &mut F) -> BlockResult<()> {
|
fn write_incompatible_features(&self, file: &AlignedFile) -> BlockResult<()> {
|
||||||
if self.version != 3 {
|
if self.version != 3 {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
file.seek(SeekFrom::Start(V2_BARE_HEADER_SIZE as u64))
|
file.write_all_at(
|
||||||
.map_err(|e| BlockError::new(BlockErrorKind::Io, Error::WritingHeader(e)))?;
|
&self.incompatible_features.to_be_bytes(),
|
||||||
u64::write_be(file, self.incompatible_features)
|
V2_BARE_HEADER_SIZE as u64,
|
||||||
.map_err(|e| BlockError::new(BlockErrorKind::Io, Error::WritingHeader(e)))?;
|
)
|
||||||
|
.map_err(|e| BlockError::new(BlockErrorKind::Io, Error::WritingHeader(e)))?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -581,11 +581,7 @@ impl QcowHeader {
|
|||||||
///
|
///
|
||||||
/// When `dirty` is true, sets the bit to indicate the image is in use.
|
/// When `dirty` is true, sets the bit to indicate the image is in use.
|
||||||
/// When `dirty` is false, clears the bit to indicate a clean shutdown.
|
/// When `dirty` is false, clears the bit to indicate a clean shutdown.
|
||||||
pub fn set_dirty_bit<F: Seek + Write + FileSync>(
|
pub fn set_dirty_bit(&mut self, file: &mut AlignedFile, dirty: bool) -> BlockResult<()> {
|
||||||
&mut self,
|
|
||||||
file: &mut F,
|
|
||||||
dirty: bool,
|
|
||||||
) -> BlockResult<()> {
|
|
||||||
if self.version == 3 {
|
if self.version == 3 {
|
||||||
if dirty {
|
if dirty {
|
||||||
self.incompatible_features |= IncompatFeatures::DIRTY.bits();
|
self.incompatible_features |= IncompatFeatures::DIRTY.bits();
|
||||||
@@ -603,7 +599,7 @@ impl QcowHeader {
|
|||||||
///
|
///
|
||||||
/// This marks the image as corrupted. Once set, the image can only be
|
/// This marks the image as corrupted. Once set, the image can only be
|
||||||
/// opened read-only until repaired.
|
/// opened read-only until repaired.
|
||||||
pub fn set_corrupt_bit<F: Seek + Write + FileSync>(&mut self, file: &mut F) -> BlockResult<()> {
|
pub fn set_corrupt_bit(&mut self, file: &mut AlignedFile) -> BlockResult<()> {
|
||||||
if self.version == 3 {
|
if self.version == 3 {
|
||||||
self.incompatible_features |= IncompatFeatures::CORRUPT.bits();
|
self.incompatible_features |= IncompatFeatures::CORRUPT.bits();
|
||||||
self.write_incompatible_features(file)?;
|
self.write_incompatible_features(file)?;
|
||||||
@@ -622,15 +618,11 @@ impl QcowHeader {
|
|||||||
///
|
///
|
||||||
/// These bits indicate features that can be safely disabled when modified
|
/// These bits indicate features that can be safely disabled when modified
|
||||||
/// by software that doesn't understand them.
|
/// by software that doesn't understand them.
|
||||||
pub fn clear_autoclear_features<F: Seek + Write + FileSync>(
|
pub fn clear_autoclear_features(&mut self, file: &mut AlignedFile) -> Result<()> {
|
||||||
&mut self,
|
|
||||||
file: &mut F,
|
|
||||||
) -> Result<()> {
|
|
||||||
if self.version == 3 && self.autoclear_features != 0 {
|
if self.version == 3 && self.autoclear_features != 0 {
|
||||||
self.autoclear_features = 0;
|
self.autoclear_features = 0;
|
||||||
file.seek(SeekFrom::Start(AUTOCLEAR_FEATURES_OFFSET))
|
file.write_all_at(&0u64.to_be_bytes(), AUTOCLEAR_FEATURES_OFFSET)
|
||||||
.map_err(Error::WritingHeader)?;
|
.map_err(Error::WritingHeader)?;
|
||||||
u64::write_be(file, 0).map_err(Error::WritingHeader)?;
|
|
||||||
file.fsync().map_err(Error::SyncingHeader)?;
|
file.fsync().map_err(Error::SyncingHeader)?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user