Skip to content

Commit 002a9f8

Browse files
author
gitlab
committed
Merge branch 'zsv-ldap-2@@2' into 'feature-zsv-5.0.0-vm-support-vtpm-and-secuceboot'
<feature>[kvm]: add hostfile backup agent command See merge request zstackio/zstack!9497
2 parents 91ffd37 + f5da724 commit 002a9f8

6 files changed

Lines changed: 774 additions & 689 deletions

File tree

plugin/kvm/src/main/java/org/zstack/kvm/KVMAgentCommands.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.zstack.header.host.VmNicRedirectConfig;
1212
import org.zstack.header.log.NoLogging;
1313
import org.zstack.header.vm.*;
14+
import org.zstack.header.vm.additions.VmHostFileBackupJob;
1415
import org.zstack.header.vm.devices.DeviceAddress;
1516
import org.zstack.header.vm.devices.VirtualDeviceInfo;
1617
import org.zstack.kvm.tpm.TpmTO;
@@ -3015,6 +3016,21 @@ public void setHostFiles(List<VmHostFileTO> hostFiles) {
30153016
public static class WriteVmHostFileContentResponse extends AgentResponse {
30163017
}
30173018

3019+
public static class BackupVmHostFileCmd extends AgentCommand {
3020+
private List<VmHostFileBackupJob> vmHostFileBackupJobs;
3021+
3022+
public List<VmHostFileBackupJob> getVmHostFileBackupJobs() {
3023+
return vmHostFileBackupJobs;
3024+
}
3025+
3026+
public void setVmHostFileBackupJobs(List<VmHostFileBackupJob> vmHostFileBackupJobs) {
3027+
this.vmHostFileBackupJobs = vmHostFileBackupJobs;
3028+
}
3029+
}
3030+
3031+
public static class BackupVmHostFileResponse extends AgentResponse {
3032+
}
3033+
30183034
public static class VmNicInfo {
30193035
private String macAddress;
30203036
private DeviceAddress deviceAddress;

plugin/kvm/src/main/java/org/zstack/kvm/KVMConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public interface KVMConstant {
8989
String FSTRIM_VM_PATH = "/vm/fstrim";
9090
String READ_VM_HOST_FILE_PATH = "/vm/hostfile/read";
9191
String WRITE_VM_HOST_FILE_PATH = "/vm/hostfile/write";
92+
String BACKUP_VM_HOST_FILE_PATH = "/vm/hostfile/backup";
9293

9394
String ISO_TO = "kvm.isoto";
9495
String ANSIBLE_PLAYBOOK_NAME = "kvm.py";
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.zstack.kvm.efi;
2+
3+
import org.zstack.header.host.HostMessage;
4+
import org.zstack.header.message.NeedReplyMessage;
5+
import org.zstack.header.vm.additions.VmHostFileBackupJob;
6+
7+
import java.util.List;
8+
9+
public class BackupVmHostFileOnHypervisorMsg extends NeedReplyMessage implements HostMessage {
10+
private String hostUuid;
11+
private List<VmHostFileBackupJob> vmHostFileBackupJobs;
12+
13+
@Override
14+
public String getHostUuid() {
15+
return hostUuid;
16+
}
17+
18+
public void setHostUuid(String hostUuid) {
19+
this.hostUuid = hostUuid;
20+
}
21+
22+
public List<VmHostFileBackupJob> getVmHostFileBackupJobs() {
23+
return vmHostFileBackupJobs;
24+
}
25+
26+
public void setVmHostFileBackupJobs(List<VmHostFileBackupJob> vmHostFileBackupJobs) {
27+
this.vmHostFileBackupJobs = vmHostFileBackupJobs;
28+
}
29+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.zstack.kvm.efi;
2+
3+
import org.zstack.header.message.MessageReply;
4+
5+
public class BackupVmHostFileOnHypervisorReply extends MessageReply {
6+
}

plugin/kvm/src/main/java/org/zstack/kvm/efi/KvmSecureBootManager.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ public void handleMessage(Message msg) {
178178
handle((BackupVmHostFileMsg) msg);
179179
} else if (msg instanceof RestoreVmHostFileMsg) {
180180
handle((RestoreVmHostFileMsg) msg);
181+
} else if (msg instanceof BackupVmHostFileOnHypervisorMsg) {
182+
handle((BackupVmHostFileOnHypervisorMsg) msg);
181183
} else {
182184
bus.dealWithUnknownMessage(msg);
183185
}
@@ -938,4 +940,31 @@ public void fail(ErrorCode errorCode) {
938940
})
939941
.start();
940942
}
943+
944+
private void handle(BackupVmHostFileOnHypervisorMsg msg) {
945+
KvmCommandSender sender = new KvmCommandSender(msg.getHostUuid());
946+
947+
KVMAgentCommands.BackupVmHostFileCmd cmd = new KVMAgentCommands.BackupVmHostFileCmd();
948+
cmd.setVmHostFileBackupJobs(msg.getVmHostFileBackupJobs());
949+
950+
BackupVmHostFileOnHypervisorReply reply = new BackupVmHostFileOnHypervisorReply();
951+
sender.send(cmd, BACKUP_VM_HOST_FILE_PATH, wrapper -> {
952+
KVMAgentCommands.BackupVmHostFileResponse rsp = wrapper.getResponse(KVMAgentCommands.BackupVmHostFileResponse.class);
953+
return rsp.isSuccess() ? null :
954+
operr("failed to backup vm host file on hypervisor[hostUuid=%s]", msg.getHostUuid())
955+
.withOpaque("host.uuid", msg.getHostUuid())
956+
.withException(rsp.getError());
957+
}, new ReturnValueCompletion<KvmResponseWrapper>(msg) {
958+
@Override
959+
public void success(KvmResponseWrapper wrapper) {
960+
bus.reply(msg, reply);
961+
}
962+
963+
@Override
964+
public void fail(ErrorCode errorCode) {
965+
reply.setError(errorCode);
966+
bus.reply(msg, reply);
967+
}
968+
});
969+
}
941970
}

0 commit comments

Comments
 (0)