Skip to content

Commit 9e32bb6

Browse files
committed
vmm: Add backup status flag in VmInfo in the RPC
1 parent 3caa6cc commit 9e32bb6

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

vmm/rpc/proto/vmm_rpc.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ message VmInfo {
3131
string shutdown_progress = 12;
3232
// Image version
3333
string image_version = 13;
34+
// Backup in progress
35+
bool backup_in_progress = 14;
3436
}
3537

3638
message Id {

vmm/src/app.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@ impl App {
678678
};
679679

680680
let qmp_socket = work_dir.qmp_socket();
681+
let _lock = BackupLock::try_lock(work_dir.backup_lock_file())
682+
.context("Failed to lock for backup")?;
681683

682684
let id = id.to_string();
683685
tokio::task::spawn_blocking(move || {
@@ -890,6 +892,30 @@ impl App {
890892
}
891893
}
892894

895+
struct BackupLock {
896+
path: PathBuf,
897+
}
898+
899+
impl BackupLock {
900+
fn try_lock(path: impl AsRef<Path>) -> Result<Self> {
901+
let path = path.as_ref();
902+
let _file = fs::OpenOptions::new()
903+
.create_new(true)
904+
.write(true)
905+
.open(path)
906+
.context("Failed to create backup lock file")?;
907+
Ok(BackupLock {
908+
path: path.to_path_buf(),
909+
})
910+
}
911+
}
912+
913+
impl Drop for BackupLock {
914+
fn drop(&mut self) {
915+
fs::remove_file(&self.path).ok();
916+
}
917+
}
918+
893919
fn paginate<T>(items: Vec<T>, page: u32, page_size: u32) -> impl Iterator<Item = T> {
894920
let skip;
895921
let take;

vmm/src/app/qemu.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ impl VmInfo {
168168
app_id: self.manifest.app_id.clone(),
169169
instance_id: self.instance_id.as_deref().map(Into::into),
170170
exited_at: self.exited_at.clone(),
171+
backup_in_progress: workdir.backup_lock_file().exists(),
171172
}
172173
}
173174
}
@@ -731,6 +732,10 @@ impl VmWorkDir {
731732
pub fn path(&self) -> &Path {
732733
&self.workdir
733734
}
735+
736+
pub fn backup_lock_file(&self) -> PathBuf {
737+
self.workdir.join("backup.lock")
738+
}
734739
}
735740

736741
impl VmWorkDir {

vmm/src/console.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2503,6 +2503,14 @@ <h5>Backup ID: {{ group.backup_id }}</h5>
25032503
};
25042504

25052505
const vmStatus = (vm) => {
2506+
const status = vmStatus0(vm);
2507+
if (vm.backup_in_progress) {
2508+
return status + ' (backing up)';
2509+
}
2510+
return status;
2511+
}
2512+
2513+
const vmStatus0 = (vm) => {
25062514
const features = imageFeatures(vm);
25072515
if (!features.progress) {
25082516
return vm.status;

0 commit comments

Comments
 (0)