Skip to content

Commit 130a9dd

Browse files
author
gitlab
committed
Merge branch 'zsv-ldap-4@@2' into 'feature-zsv-5.0.0-vm-support-vtpm-and-secuceboot'
<feature>[kvm]: add VM host file periodic sync tracker See merge request zstackio/zstack!9462
2 parents 08119aa + 3039eb8 commit 130a9dd

2 files changed

Lines changed: 44 additions & 15 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,14 @@ public class KVMGlobalConfig {
166166
description = "Specify the EDK version to be used for the next VM startup. None indicates the use of the system's default EDK version")
167167
@BindResourceConfig(value = {VmInstanceVO.class, ClusterVO.class})
168168
public static GlobalConfig VM_EDK_VERSION_CONFIG = new GlobalConfig(CATEGORY, "vm.edk.version");
169+
170+
@GlobalConfigValidation(numberGreaterThan = 1, numberLessThan = 86400)
171+
@GlobalConfigDef(defaultValue = "1800", type = Long.class,
172+
description = "Interval in seconds for syncing VM host files (NvRam, TpmState) from KVM hosts")
173+
public static GlobalConfig VM_HOST_FILE_SYNC_INTERVAL = new GlobalConfig(CATEGORY, "vm.host.file.sync.interval");
174+
175+
@GlobalConfigValidation(numberGreaterThan = 1, numberLessThan = 30)
176+
@GlobalConfigDef(defaultValue = "5", type = Integer.class,
177+
description = "The concurrency level for syncing VM host files from KVM hosts")
178+
public static GlobalConfig VM_HOST_FILE_SYNC_CONCURRENCY = new GlobalConfig(CATEGORY, "vm.host.file.sync.concurrency");
169179
}

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

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.zstack.core.cloudbus.CloudBus;
77
import org.zstack.core.cloudbus.CloudBusCallBack;
88
import org.zstack.core.cloudbus.ResourceDestinationMaker;
9+
import org.zstack.core.config.GlobalConfigUpdateExtensionPoint;
910
import org.zstack.core.db.Q;
1011
import org.zstack.core.thread.PeriodicTask;
1112
import org.zstack.core.thread.ThreadFacade;
@@ -20,6 +21,7 @@
2021
import org.zstack.header.vm.additions.VmHostFileType;
2122
import org.zstack.header.vm.additions.VmHostFileVO;
2223
import org.zstack.header.vm.additions.VmHostFileVO_;
24+
import org.zstack.kvm.KVMGlobalConfig;
2325
import org.zstack.utils.Utils;
2426
import org.zstack.utils.logging.CLogger;
2527

@@ -33,9 +35,6 @@
3335
public class VmHostFileTracker implements Component {
3436
private static final CLogger logger = Utils.getLogger(VmHostFileTracker.class);
3537

36-
private static final long SYNC_INTERVAL_SECONDS = TimeUnit.MINUTES.toSeconds(30);
37-
private static final int SYNC_CONCURRENCY = 5;
38-
3938
@Autowired
4039
private ThreadFacade threadFacade;
4140
@Autowired
@@ -52,6 +51,34 @@ public boolean start() {
5251
return true;
5352
}
5453

54+
submitTrackerTask();
55+
56+
GlobalConfigUpdateExtensionPoint listener = (oldConfig, newConfig) -> {
57+
logger.debug(String.format("%s changed from %s to %s, restarting vm-host-file-tracker",
58+
newConfig.getCanonicalName(), oldConfig.value(), newConfig.value()));
59+
submitTrackerTask();
60+
};
61+
62+
KVMGlobalConfig.VM_HOST_FILE_SYNC_INTERVAL.installUpdateExtension(listener);
63+
KVMGlobalConfig.VM_HOST_FILE_SYNC_CONCURRENCY.installUpdateExtension(listener);
64+
65+
return true;
66+
}
67+
68+
@Override
69+
public boolean stop() {
70+
if (trackerThread != null) {
71+
trackerThread.cancel(true);
72+
}
73+
return true;
74+
}
75+
76+
private synchronized void submitTrackerTask() {
77+
if (trackerThread != null) {
78+
trackerThread.cancel(true);
79+
}
80+
81+
long interval = KVMGlobalConfig.VM_HOST_FILE_SYNC_INTERVAL.value(Long.class);
5582
trackerThread = threadFacade.submitPeriodicTask(new PeriodicTask() {
5683
@Override
5784
public TimeUnit getTimeUnit() {
@@ -60,7 +87,7 @@ public TimeUnit getTimeUnit() {
6087

6188
@Override
6289
public long getInterval() {
63-
return SYNC_INTERVAL_SECONDS;
90+
return interval;
6491
}
6592

6693
@Override
@@ -74,16 +101,6 @@ public void run() {
74101
syncVmHostFiles();
75102
}
76103
});
77-
78-
return true;
79-
}
80-
81-
@Override
82-
public boolean stop() {
83-
if (trackerThread != null) {
84-
trackerThread.cancel(true);
85-
}
86-
return true;
87104
}
88105

89106
private void syncVmHostFiles() {
@@ -104,6 +121,8 @@ private void syncVmHostFiles() {
104121
.collect(Collectors.groupingBy(f -> f.getVmInstanceUuid() + "::" + f.getHostUuid()));
105122
List<List<VmHostFileVO>> groups = new ArrayList<>(grouped.values());
106123

124+
int concurrency = KVMGlobalConfig.VM_HOST_FILE_SYNC_CONCURRENCY.value(Integer.class);
125+
107126
new While<>(groups).step((group, whileCompletion) -> {
108127
VmHostFileVO first = group.get(0);
109128
String vmUuid = first.getVmInstanceUuid();
@@ -137,7 +156,7 @@ public void run(MessageReply reply) {
137156
whileCompletion.done();
138157
}
139158
});
140-
}, SYNC_CONCURRENCY).run(new WhileDoneCompletion(null) {
159+
}, concurrency).run(new WhileDoneCompletion(null) {
141160
@Override
142161
public void done(ErrorCodeList errorCodeList) {
143162
// periodic sync round finished, empty callback

0 commit comments

Comments
 (0)