Skip to content

Commit 893db02

Browse files
committed
feat: teardown hooks, document storage transformer API
1 parent 0650d30 commit 893db02

3 files changed

Lines changed: 78 additions & 8 deletions

File tree

‎docs/storage.md‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Storage Integration
2+
3+
Orodobo adds a storage integration layer on top of Cloud Hypervisor's block device support, using config transformers to convert custom URI schemes into valid block device paths for Cloud Hypervisor.
4+
This allows users to specify storage devices in a more flexible way, and enables simpler integration with networked storage backends, by having Odorobo abstract and attach/detach storage devices on demand based on the VM's lifecycle and provisioning hooks.
5+
6+
Currently, Odorobo's Storage transformer supports the following backends:
7+
8+
- **Local Disk Images**: Specify a local disk image with the `file://` URI scheme, e.g. `file:///var/lib/odorobo/images/my-disk.qcow2`. This is simply passed through to Cloud Hypervisor as if the `file://` prefix was not there, implemented as a dummy transformer for validating the storage transformer API.
9+
- **Ceph RBD**: Specify a Ceph RBD image with the `rbd://` URI scheme, e.g. `rbd://my-pool/my-image`. Odorobo will use the `rbd` command line tool to map the RBD image to a local block device (e.g. `/dev/rbd0`), and then pass this block device path to Cloud Hypervisor.
10+
- **iSCSI**: Specify an iSCSI target with the `iscsi://` URI scheme, e.g. `iscsi://<target-ip>:<port>/<iqn>/<lun>`. Odorobo will use the `iscsiadm` command line tool to log in to the iSCSI target and map the specified LUN to a local block device (e.g. `/dev/disk/by-path/ip-<target-ip>:<port>-iscsi-<iqn>-lun-<lun>`), and then pass this block device path to Cloud Hypervisor.
11+
12+
To use the storage transformers, simply specify the desired URI in place of the `path` field for a block device in your VM config. For example:
13+
14+
```json
15+
{
16+
...
17+
"disks": [
18+
{
19+
"path": "rdb://my-pool/my-image",
20+
"id": "disk0",
21+
}
22+
],
23+
}
24+
```
25+
26+
Odorobo will automatically detect the `rbd://` scheme, map the RBD image to a local block device, and pass the block device path to Cloud Hypervisor when creating the VM, transforming them to:
27+
28+
```json
29+
{
30+
...
31+
"disks": [
32+
{
33+
"path": "/dev/rbd0",
34+
"id": "rdb://my-pool/my-image?id=disk0",
35+
}
36+
],
37+
}
38+
```
39+
40+
The `id` field is transformed to include the original URI for reference, and can be used in provisioning hooks to identify which disk is which when attaching/detaching storage devices on demand.
41+

‎odorobo-agent/src/state/instance.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use std::{
1818
use thiserror::Error;
1919
use tracing::{debug, error, info, trace, warn};
2020

21+
use crate::state::transform::{ConfigTransform, TransformChain};
22+
2123
use super::api::{call, call_request};
2224
use super::transform::apply_builtin_transforms;
2325

@@ -128,7 +130,13 @@ impl VMInstance {
128130
.wrap_err(eyre!(
129131
"Failed to send migration command for {}",
130132
self.vm_id()
131-
))
133+
))?;
134+
135+
// if migration is successful, we can assume the VM is effectively "gone" from this host, so we can clean up runtime state.
136+
self.purge_instance_data()
137+
.wrap_err("Failed to purge instance data after migration")?;
138+
139+
Ok(())
132140
}
133141

134142
/// Prepares the VM to receive a migration by starting a migration receiver in the background.
@@ -381,6 +389,8 @@ impl VMInstance {
381389
///
382390
/// This removes the runtime directory and all its contents if it exists.
383391
pub fn purge_instance_data(&self) -> Result<()> {
392+
let mut vm_config = self.load_config().unwrap_or_default();
393+
TransformChain::default().teardown(self.vm_id(), &mut vm_config)?;
384394
let runtime_dir = self.runtime_dir();
385395
if runtime_dir.exists() {
386396
fs::remove_dir_all(runtime_dir).wrap_err(eyre!(

‎odorobo-agent/src/state/transform/mod.rs‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@ use stable_eyre::Result;
33

44
pub trait ConfigTransform: Send + Sync {
55
fn transform(&self, vmid: &str, config: &mut VmConfig) -> Result<()>;
6+
7+
/// Optional teardown method to reverse transformations if needed,
8+
/// used for tearing down VMs
9+
fn teardown(&self, _vmid: &str, _config: &mut VmConfig) -> Result<()> {
10+
Ok(())
11+
}
612
}
713

814
mod console;
915
mod path_verify;
1016
mod storage;
1117
pub use console::ConsoleTransform;
1218
pub use path_verify::PathVerify;
19+
use tracing::trace;
1320

14-
#[derive(Default)]
1521
pub struct TransformChain(Vec<Box<dyn ConfigTransform>>);
1622

1723
impl TransformChain {
@@ -31,18 +37,31 @@ impl TransformChain {
3137

3238
impl ConfigTransform for TransformChain {
3339
fn transform(&self, vmid: &str, config: &mut VmConfig) -> Result<()> {
40+
trace!("Applying transform chain with {} transforms", self.0.len());
3441
for t in &self.0 {
3542
t.transform(vmid, config)?;
3643
}
3744
Ok(())
3845
}
46+
47+
fn teardown(&self, vmid: &str, config: &mut VmConfig) -> Result<()> {
48+
trace!("Teardown transform chain with {} transforms", self.0.len());
49+
for t in self.0.iter().rev() {
50+
t.teardown(vmid, config)?;
51+
}
52+
Ok(())
53+
}
54+
}
55+
56+
impl Default for TransformChain {
57+
fn default() -> Self {
58+
Self::new()
59+
.add(ConsoleTransform)
60+
.add(PathVerify)
61+
.add(storage::StorageChain::default())
62+
}
3963
}
4064

4165
pub fn apply_builtin_transforms(vmid: &str, config: &mut VmConfig) -> Result<()> {
42-
TransformChain::new()
43-
.add(ConsoleTransform)
44-
.add(PathVerify)
45-
.add(storage::StorageChain::default())
46-
.then()
47-
.transform(vmid, config)
66+
TransformChain::default().transform(vmid, config)
4867
}

0 commit comments

Comments
 (0)