Skip to content

Commit c57b552

Browse files
committed
Add pre_backup/post_backup guest api
1 parent 14db101 commit c57b552

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

guest-agent/src/guest_api_service.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ use tracing::error;
1818

1919
use crate::{rpc_service::ExternalRpcHandler, AppState};
2020

21+
const BACKUP_LOCK_FILE: &str = "/run/dstack-backup.lock";
22+
2123
pub struct GuestApiHandler {
2224
state: AppState,
2325
}
@@ -43,6 +45,7 @@ impl GuestApiRpc for GuestApiHandler {
4345
device_id: info.device_id,
4446
app_cert: info.app_cert,
4547
tcb_info: info.tcb_info,
48+
backup_in_progress: fs::metadata(BACKUP_LOCK_FILE).is_ok(),
4649
})
4750
}
4851

@@ -112,6 +115,20 @@ impl GuestApiRpc for GuestApiHandler {
112115
async fn list_containers(self) -> Result<ListContainersResponse> {
113116
list_containers().await
114117
}
118+
119+
async fn pre_backup(self) -> Result<()> {
120+
fs::OpenOptions::new()
121+
.create_new(true)
122+
.write(true)
123+
.open(BACKUP_LOCK_FILE)
124+
.context("Failed to create backup lock file, there is another backup in progress")?;
125+
Ok(())
126+
}
127+
128+
async fn post_backup(self) -> Result<()> {
129+
fs::remove_file(BACKUP_LOCK_FILE).context("Failed to remove backup lock file")?;
130+
Ok(())
131+
}
115132
}
116133

117134
pub(crate) async fn list_containers() -> Result<ListContainersResponse> {

guest-api/proto/guest_api.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ message GuestInfo {
2222
string tcb_info = 5;
2323
// Device ID
2424
bytes device_id = 6;
25+
// true if backup is in progress
26+
bool backup_in_progress = 7;
2527
}
2628

2729
message IpAddress {
@@ -123,6 +125,8 @@ service GuestApi {
123125
rpc NetworkInfo(google.protobuf.Empty) returns (NetworkInformation);
124126
rpc ListContainers(google.protobuf.Empty) returns (ListContainersResponse);
125127
rpc Shutdown(google.protobuf.Empty) returns (google.protobuf.Empty);
128+
rpc PreBackup(google.protobuf.Empty) returns (google.protobuf.Empty);
129+
rpc PostBackup(google.protobuf.Empty) returns (google.protobuf.Empty);
126130
}
127131

128132
service ProxiedGuestApi {
@@ -131,4 +135,6 @@ service ProxiedGuestApi {
131135
rpc NetworkInfo(Id) returns (NetworkInformation);
132136
rpc ListContainers(Id) returns (ListContainersResponse);
133137
rpc Shutdown(Id) returns (google.protobuf.Empty);
138+
rpc PreBackup(Id) returns (google.protobuf.Empty);
139+
rpc PostBackup(Id) returns (google.protobuf.Empty);
134140
}

vmm/src/guest_api_service.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@ impl ProxiedGuestApiRpc for GuestApiHandler {
5151
async fn shutdown(self, request: Id) -> Result<()> {
5252
self.guest_agent_client(&request.id)?.shutdown().await
5353
}
54+
55+
async fn pre_backup(self, request: Id) -> Result<()> {
56+
self.guest_agent_client(&request.id)?.pre_backup().await
57+
}
58+
59+
async fn post_backup(self, request: Id) -> Result<()> {
60+
self.guest_agent_client(&request.id)?.post_backup().await
61+
}
5462
}

0 commit comments

Comments
 (0)