-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
346 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mod shared; | ||
pub mod v1; | ||
|
||
pub use shared::Backstore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,333 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
use std::collections::HashMap; | ||
|
||
use chrono::{DateTime, Utc}; | ||
use serde_json::Value; | ||
|
||
use devicemapper::{Device, Sectors}; | ||
|
||
use crate::{ | ||
engine::{ | ||
strat_engine::{ | ||
backstore::{ | ||
backstore::v1, blockdev::StratBlockDev, devices::UnownedDevices, | ||
shared::BlockSizeSummary, transaction::RequestTransaction, | ||
}, | ||
metadata::{MDADataSize, BDA}, | ||
serde_structs::{BackstoreSave, Recordable}, | ||
types::BDARecordResult, | ||
}, | ||
types::{ | ||
ActionAvailability, BlockDevTier, DevUuid, EncryptionInfo, KeyDescription, Name, | ||
PoolEncryptionInfo, PoolUuid, | ||
}, | ||
}, | ||
stratis::StratisResult, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub enum Backstore { | ||
V1(v1::Backstore), | ||
} | ||
|
||
impl Backstore { | ||
pub fn setup_v1( | ||
pool_uuid: PoolUuid, | ||
backstore_save: &BackstoreSave, | ||
datadevs: Vec<StratBlockDev>, | ||
cachedevs: Vec<StratBlockDev>, | ||
last_update_time: DateTime<Utc>, | ||
) -> BDARecordResult<Backstore> { | ||
v1::Backstore::setup( | ||
pool_uuid, | ||
backstore_save, | ||
datadevs, | ||
cachedevs, | ||
last_update_time, | ||
) | ||
.map(Backstore::V1) | ||
} | ||
|
||
pub fn initialize_v1( | ||
pool_name: Name, | ||
pool_uuid: PoolUuid, | ||
devices: UnownedDevices, | ||
mda_data_size: MDADataSize, | ||
encryption_info: Option<&EncryptionInfo>, | ||
) -> StratisResult<Backstore> { | ||
v1::Backstore::initialize( | ||
pool_name, | ||
pool_uuid, | ||
devices, | ||
mda_data_size, | ||
encryption_info, | ||
) | ||
.map(Backstore::V1) | ||
} | ||
|
||
pub fn init_cache( | ||
&mut self, | ||
pool_name: Name, | ||
pool_uuid: PoolUuid, | ||
devices: UnownedDevices, | ||
) -> StratisResult<Vec<DevUuid>> { | ||
match self { | ||
Backstore::V1(b) => b.init_cache(pool_name, pool_uuid, devices), | ||
} | ||
} | ||
|
||
pub fn add_cachedevs( | ||
&mut self, | ||
pool_name: Name, | ||
pool_uuid: PoolUuid, | ||
devices: UnownedDevices, | ||
) -> StratisResult<Vec<DevUuid>> { | ||
match self { | ||
Backstore::V1(b) => b.add_cachedevs(pool_name, pool_uuid, devices), | ||
} | ||
} | ||
|
||
/// Add datadevs to the backstore. The data tier always exists if the | ||
/// backstore exists at all, so there is no need to create it. | ||
pub fn add_datadevs( | ||
&mut self, | ||
pool_name: Name, | ||
pool_uuid: PoolUuid, | ||
devices: UnownedDevices, | ||
) -> StratisResult<Vec<DevUuid>> { | ||
match self { | ||
Backstore::V1(b) => b.add_datadevs(pool_name, pool_uuid, devices), | ||
} | ||
} | ||
|
||
pub fn request_alloc( | ||
&mut self, | ||
sizes: &[Sectors], | ||
) -> StratisResult<Option<RequestTransaction>> { | ||
match self { | ||
Backstore::V1(b) => b.request_alloc(sizes), | ||
} | ||
} | ||
|
||
pub fn commit_alloc( | ||
&mut self, | ||
pool_uuid: PoolUuid, | ||
transaction: RequestTransaction, | ||
) -> StratisResult<()> { | ||
match self { | ||
Backstore::V1(b) => b.commit_alloc(pool_uuid, transaction), | ||
} | ||
} | ||
|
||
pub fn datadevs(&self) -> Vec<(DevUuid, &StratBlockDev)> { | ||
match self { | ||
Backstore::V1(b) => b.datadevs(), | ||
} | ||
} | ||
|
||
pub fn cachedevs(&self) -> Vec<(DevUuid, &StratBlockDev)> { | ||
match self { | ||
Backstore::V1(b) => b.cachedevs(), | ||
} | ||
} | ||
|
||
pub fn blockdevs(&self) -> Vec<(DevUuid, BlockDevTier, &StratBlockDev)> { | ||
match self { | ||
Backstore::V1(b) => b.blockdevs(), | ||
} | ||
} | ||
|
||
pub fn blockdevs_mut(&mut self) -> Vec<(DevUuid, BlockDevTier, &mut StratBlockDev)> { | ||
match self { | ||
Backstore::V1(b) => b.blockdevs_mut(), | ||
} | ||
} | ||
|
||
pub fn datatier_size(&self) -> Sectors { | ||
match self { | ||
Backstore::V1(b) => b.datatier_size(), | ||
} | ||
} | ||
|
||
pub fn datatier_allocated_size(&self) -> Sectors { | ||
match self { | ||
Backstore::V1(b) => b.datatier_allocated_size(), | ||
} | ||
} | ||
|
||
pub fn datatier_usable_size(&self) -> Sectors { | ||
match self { | ||
Backstore::V1(b) => b.datatier_usable_size(), | ||
} | ||
} | ||
|
||
pub fn available_in_backstore(&self) -> Sectors { | ||
match self { | ||
Backstore::V1(b) => b.available_in_backstore(), | ||
} | ||
} | ||
|
||
pub fn destroy(&mut self, pool_uuid: PoolUuid) -> StratisResult<()> { | ||
match self { | ||
Backstore::V1(b) => b.destroy(pool_uuid), | ||
} | ||
} | ||
|
||
pub fn teardown(&mut self, pool_uuid: PoolUuid) -> StratisResult<()> { | ||
match self { | ||
Backstore::V1(b) => b.teardown(pool_uuid), | ||
} | ||
} | ||
|
||
pub fn into_bdas(self) -> HashMap<DevUuid, BDA> { | ||
match self { | ||
Backstore::V1(b) => b.into_bdas(), | ||
} | ||
} | ||
|
||
pub fn drain_bds(&mut self) -> Vec<StratBlockDev> { | ||
match self { | ||
Backstore::V1(b) => b.drain_bds(), | ||
} | ||
} | ||
|
||
pub fn device(&self) -> Option<Device> { | ||
match self { | ||
Backstore::V1(b) => b.device(), | ||
} | ||
} | ||
|
||
pub fn get_blockdev_by_uuid(&self, uuid: DevUuid) -> Option<(BlockDevTier, &StratBlockDev)> { | ||
match self { | ||
Backstore::V1(b) => b.get_blockdev_by_uuid(uuid), | ||
} | ||
} | ||
|
||
pub fn get_mut_blockdev_by_uuid( | ||
&mut self, | ||
uuid: DevUuid, | ||
) -> Option<(BlockDevTier, &mut StratBlockDev)> { | ||
match self { | ||
Backstore::V1(b) => b.get_mut_blockdev_by_uuid(uuid), | ||
} | ||
} | ||
|
||
pub fn datatier_metadata_size(&self) -> Sectors { | ||
match self { | ||
Backstore::V1(b) => b.datatier_metadata_size(), | ||
} | ||
} | ||
|
||
pub fn save_state(&mut self, metadata: &[u8]) -> StratisResult<()> { | ||
match self { | ||
Backstore::V1(b) => b.save_state(metadata), | ||
} | ||
} | ||
|
||
pub fn set_blockdev_user_info( | ||
&mut self, | ||
uuid: DevUuid, | ||
user_info: Option<&str>, | ||
) -> StratisResult<Option<DevUuid>> { | ||
match self { | ||
Backstore::V1(b) => b.set_blockdev_user_info(uuid, user_info), | ||
} | ||
} | ||
|
||
pub fn is_encrypted(&self) -> bool { | ||
match self { | ||
Backstore::V1(b) => b.is_encrypted(), | ||
} | ||
} | ||
|
||
pub fn encryption_info(&self) -> Option<PoolEncryptionInfo> { | ||
match self { | ||
Backstore::V1(b) => b.encryption_info(), | ||
} | ||
} | ||
|
||
pub fn has_cache(&self) -> bool { | ||
match self { | ||
Backstore::V1(b) => b.has_cache(), | ||
} | ||
} | ||
|
||
pub fn bind_clevis(&mut self, pin: &str, clevis_info: &Value) -> StratisResult<bool> { | ||
match self { | ||
Backstore::V1(b) => b.bind_clevis(pin, clevis_info), | ||
} | ||
} | ||
|
||
pub fn unbind_clevis(&mut self) -> StratisResult<bool> { | ||
match self { | ||
Backstore::V1(b) => b.unbind_clevis(), | ||
} | ||
} | ||
|
||
pub fn bind_keyring(&mut self, key_desc: &KeyDescription) -> StratisResult<bool> { | ||
match self { | ||
Backstore::V1(b) => b.bind_keyring(key_desc), | ||
} | ||
} | ||
|
||
pub fn unbind_keyring(&mut self) -> StratisResult<bool> { | ||
match self { | ||
Backstore::V1(b) => b.unbind_keyring(), | ||
} | ||
} | ||
|
||
pub fn rebind_keyring(&mut self, key_desc: &KeyDescription) -> StratisResult<Option<bool>> { | ||
match self { | ||
Backstore::V1(b) => b.rebind_keyring(key_desc), | ||
} | ||
} | ||
|
||
pub fn rebind_clevis(&mut self) -> StratisResult<()> { | ||
match self { | ||
Backstore::V1(b) => b.rebind_clevis(), | ||
} | ||
} | ||
|
||
pub fn grow(&mut self, dev: DevUuid) -> StratisResult<bool> { | ||
match self { | ||
Backstore::V1(b) => b.grow(dev), | ||
} | ||
} | ||
|
||
pub fn rename_pool(&mut self, new_name: &Name) -> StratisResult<()> { | ||
match self { | ||
Backstore::V1(b) => b.rename_pool(new_name), | ||
} | ||
} | ||
|
||
pub fn block_size_summary(&self, tier: BlockDevTier) -> Option<BlockSizeSummary> { | ||
match self { | ||
Backstore::V1(b) => b.block_size_summary(tier), | ||
} | ||
} | ||
|
||
pub fn action_availability(&self) -> ActionAvailability { | ||
match self { | ||
Backstore::V1(b) => b.action_availability(), | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Into<Value> for &'a Backstore { | ||
fn into(self) -> Value { | ||
match self { | ||
Backstore::V1(b) => b.into(), | ||
} | ||
} | ||
} | ||
|
||
impl Recordable<BackstoreSave> for Backstore { | ||
fn record(&self) -> BackstoreSave { | ||
match self { | ||
Backstore::V1(b) => b.record(), | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.