mirror of
https://git.proxmox.com/git/proxmox-backup-qemu
synced 2025-10-04 22:11:27 +00:00
make Registry generic and add ImageAccessInfo
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
parent
6a125fbc6c
commit
06c101f73f
@ -21,7 +21,7 @@ lazy_static!{
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ImageUploadInfo {
|
pub struct ImageUploadInfo {
|
||||||
wid: u64,
|
wid: u64,
|
||||||
device_name: String,
|
device_name: String,
|
||||||
zero_chunk_digest: [u8; 32],
|
zero_chunk_digest: [u8; 32],
|
||||||
@ -30,34 +30,34 @@ struct ImageUploadInfo {
|
|||||||
upload_result: Option<UploadResultReceiver>,
|
upload_result: Option<UploadResultReceiver>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub (crate) struct ImageRegistry {
|
pub struct Registry<T> {
|
||||||
upload_info: Vec<ImageUploadInfo>,
|
pub info_list: Vec<T>,
|
||||||
file_list: Vec<Value>,
|
file_list: Vec<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageRegistry {
|
impl<T> Registry<T> {
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
upload_info: Vec::new(),
|
info_list: Vec::new(),
|
||||||
file_list: Vec::new(),
|
file_list: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register(&mut self, info: ImageUploadInfo) -> Result<u8, Error> {
|
pub fn register(&mut self, info: T) -> Result<u8, Error> {
|
||||||
let dev_id = self.upload_info.len();
|
let dev_id = self.info_list.len();
|
||||||
if dev_id > 255 {
|
if dev_id > 255 {
|
||||||
bail!("register image faild - to many images (limit is 255)");
|
bail!("register failed - too many images/archives (limit is 255)");
|
||||||
}
|
}
|
||||||
self.upload_info.push(info);
|
self.info_list.push(info);
|
||||||
Ok(dev_id as u8)
|
Ok(dev_id as u8)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup(&mut self, dev_id: u8) -> Result<&mut ImageUploadInfo, Error> {
|
pub fn lookup(&mut self, id: u8) -> Result<&mut T, Error> {
|
||||||
if dev_id as usize >= self.upload_info.len() {
|
if id as usize >= self.info_list.len() {
|
||||||
bail!("image lookup failed for dev_id = {}", dev_id);
|
bail!("lookup failed for id = {}", id);
|
||||||
}
|
}
|
||||||
Ok(&mut self.upload_info[dev_id as usize])
|
Ok(&mut self.info_list[id as usize])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ async fn register_zero_chunk(
|
|||||||
|
|
||||||
pub(crate) async fn add_config(
|
pub(crate) async fn add_config(
|
||||||
client: Arc<BackupWriter>,
|
client: Arc<BackupWriter>,
|
||||||
registry: Arc<Mutex<ImageRegistry>>,
|
registry: Arc<Mutex<Registry<ImageUploadInfo>>>,
|
||||||
name: String,
|
name: String,
|
||||||
data: Vec<u8>,
|
data: Vec<u8>,
|
||||||
) -> Result<c_int, Error> {
|
) -> Result<c_int, Error> {
|
||||||
@ -114,7 +114,7 @@ pub(crate) async fn register_image(
|
|||||||
client: Arc<BackupWriter>,
|
client: Arc<BackupWriter>,
|
||||||
crypt_config: Option<Arc<CryptConfig>>,
|
crypt_config: Option<Arc<CryptConfig>>,
|
||||||
manifest: Option<Arc<BackupManifest>>,
|
manifest: Option<Arc<BackupManifest>>,
|
||||||
registry: Arc<Mutex<ImageRegistry>>,
|
registry: Arc<Mutex<Registry<ImageUploadInfo>>>,
|
||||||
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
|
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
|
||||||
device_name: String,
|
device_name: String,
|
||||||
device_size: u64,
|
device_size: u64,
|
||||||
@ -197,7 +197,7 @@ pub(crate) async fn register_image(
|
|||||||
|
|
||||||
pub(crate) async fn close_image(
|
pub(crate) async fn close_image(
|
||||||
client: Arc<BackupWriter>,
|
client: Arc<BackupWriter>,
|
||||||
registry: Arc<Mutex<ImageRegistry>>,
|
registry: Arc<Mutex<Registry<ImageUploadInfo>>>,
|
||||||
dev_id: u8,
|
dev_id: u8,
|
||||||
) -> Result<c_int, Error> {
|
) -> Result<c_int, Error> {
|
||||||
|
|
||||||
@ -255,7 +255,7 @@ pub(crate) async fn close_image(
|
|||||||
pub(crate) async fn write_data(
|
pub(crate) async fn write_data(
|
||||||
client: Arc<BackupWriter>,
|
client: Arc<BackupWriter>,
|
||||||
crypt_config: Option<Arc<CryptConfig>>,
|
crypt_config: Option<Arc<CryptConfig>>,
|
||||||
registry: Arc<Mutex<ImageRegistry>>,
|
registry: Arc<Mutex<Registry<ImageUploadInfo>>>,
|
||||||
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
|
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
|
||||||
dev_id: u8,
|
dev_id: u8,
|
||||||
data: DataPointer,
|
data: DataPointer,
|
||||||
@ -372,7 +372,7 @@ pub(crate) async fn write_data(
|
|||||||
|
|
||||||
pub(crate) async fn finish_backup(
|
pub(crate) async fn finish_backup(
|
||||||
client: Arc<BackupWriter>,
|
client: Arc<BackupWriter>,
|
||||||
registry: Arc<Mutex<ImageRegistry>>,
|
registry: Arc<Mutex<Registry<ImageUploadInfo>>>,
|
||||||
setup: BackupSetup,
|
setup: BackupSetup,
|
||||||
) -> Result<c_int, Error> {
|
) -> Result<c_int, Error> {
|
||||||
|
|
||||||
|
@ -1,17 +1,26 @@
|
|||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use proxmox_backup::tools::runtime::{get_runtime, block_on};
|
use proxmox_backup::tools::runtime::{get_runtime, block_on};
|
||||||
use proxmox_backup::backup::*;
|
use proxmox_backup::backup::*;
|
||||||
use proxmox_backup::client::{HttpClient, HttpClientOptions, BackupReader, RemoteChunkReader};
|
use proxmox_backup::client::{HttpClient, HttpClientOptions, BackupReader, RemoteChunkReader};
|
||||||
|
|
||||||
use super::BackupSetup;
|
use super::BackupSetup;
|
||||||
|
use crate::commands::Registry;
|
||||||
|
|
||||||
|
pub struct ImageAccessInfo {
|
||||||
|
pub reader: Arc<RemoteChunkReader>,
|
||||||
|
pub index: Arc<FixedIndexReader>,
|
||||||
|
pub archive_name: String,
|
||||||
|
pub archive_size: u64,
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) struct ProxmoxRestore {
|
pub(crate) struct ProxmoxRestore {
|
||||||
_runtime: Arc<tokio::runtime::Runtime>,
|
_runtime: Arc<tokio::runtime::Runtime>,
|
||||||
pub client: Arc<BackupReader>,
|
pub client: Arc<BackupReader>,
|
||||||
pub crypt_config: Option<Arc<CryptConfig>>,
|
pub crypt_config: Option<Arc<CryptConfig>>,
|
||||||
pub manifest: BackupManifest,
|
pub manifest: BackupManifest,
|
||||||
|
pub registry: Arc<Mutex<Registry<ImageAccessInfo>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProxmoxRestore {
|
impl ProxmoxRestore {
|
||||||
@ -64,6 +73,7 @@ impl ProxmoxRestore {
|
|||||||
manifest,
|
manifest,
|
||||||
client,
|
client,
|
||||||
crypt_config,
|
crypt_config,
|
||||||
|
registry: Arc::new(Mutex::new(Registry::<ImageAccessInfo>::new())),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ pub(crate) struct BackupTask {
|
|||||||
crypt_config: Option<Arc<CryptConfig>>,
|
crypt_config: Option<Arc<CryptConfig>>,
|
||||||
writer: Mutex<Option<Arc<BackupWriter>>>,
|
writer: Mutex<Option<Arc<BackupWriter>>>,
|
||||||
last_manifest: Mutex<Option<Arc<BackupManifest>>>,
|
last_manifest: Mutex<Option<Arc<BackupManifest>>>,
|
||||||
registry: Arc<Mutex<ImageRegistry>>,
|
registry: Arc<Mutex<Registry<ImageUploadInfo>>>,
|
||||||
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
|
known_chunks: Arc<Mutex<HashSet<[u8;32]>>>,
|
||||||
abort: tokio::sync::broadcast::Sender<()>,
|
abort: tokio::sync::broadcast::Sender<()>,
|
||||||
aborted: Mutex<Option<String>>, // set on abort, conatins abort reason
|
aborted: Mutex<Option<String>>, // set on abort, conatins abort reason
|
||||||
@ -52,7 +52,7 @@ impl BackupTask {
|
|||||||
|
|
||||||
let (abort, _) = tokio::sync::broadcast::channel(16);
|
let (abort, _) = tokio::sync::broadcast::channel(16);
|
||||||
|
|
||||||
let registry = Arc::new(Mutex::new(ImageRegistry::new()));
|
let registry = Arc::new(Mutex::new(Registry::<ImageUploadInfo>::new()));
|
||||||
let known_chunks = Arc::new(Mutex::new(HashSet::new()));
|
let known_chunks = Arc::new(Mutex::new(HashSet::new()));
|
||||||
|
|
||||||
Ok(Self { runtime, setup, crypt_config, abort, registry, known_chunks,
|
Ok(Self { runtime, setup, crypt_config, abort, registry, known_chunks,
|
||||||
|
Loading…
Reference in New Issue
Block a user