Skip to content

Commit 30bbfa0

Browse files
committed
vmm: Add backup status flag in VmInfo in the RPC
1 parent 6b5a390 commit 30bbfa0

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
@@ -684,6 +684,8 @@ impl App {
684684
};
685685

686686
let qmp_socket = work_dir.qmp_socket();
687+
let _lock = BackupLock::try_lock(work_dir.backup_lock_file())
688+
.context("Failed to lock for backup")?;
687689

688690
let id = id.to_string();
689691
tokio::task::spawn_blocking(move || {
@@ -896,6 +898,30 @@ impl App {
896898
}
897899
}
898900

901+
struct BackupLock {
902+
path: PathBuf,
903+
}
904+
905+
impl BackupLock {
906+
fn try_lock(path: impl AsRef<Path>) -> Result<Self> {
907+
let path = path.as_ref();
908+
let _file = fs::OpenOptions::new()
909+
.create_new(true)
910+
.write(true)
911+
.open(path)
912+
.context("Failed to create backup lock file")?;
913+
Ok(BackupLock {
914+
path: path.to_path_buf(),
915+
})
916+
}
917+
}
918+
919+
impl Drop for BackupLock {
920+
fn drop(&mut self) {
921+
fs::remove_file(&self.path).ok();
922+
}
923+
}
924+
899925
fn paginate<T>(items: Vec<T>, page: u32, page_size: u32) -> impl Iterator<Item = T> {
900926
let skip;
901927
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)