Skip to content

Commit c144d09

Browse files
committed
nasbackup: carry the backup method separately from the mode
The content-based path overloaded ChainDecision.mode with content-full and content-incremental, and apache#14386 is adding rbd-full and rbd-incremental the same way. Split the two concerns as suggested in review: mode stays full or incremental, and a new method field says how the backup is taken -- qcow2 (push mode with dirty bitmaps) or content (pull mode). Further methods such as an RBD diff can be added without new mode tokens. TakeBackupCommand gets a method field and nasbackup.sh a --method option. Both default to qcow2 when absent, so a management server that does not send a method keeps working against an upgraded agent. legacy-full is unchanged: rewriting it as full plus a "none" method would break incremental-disabled backups on agents that have not been upgraded yet.
1 parent 2171023 commit c144d09

7 files changed

Lines changed: 169 additions & 75 deletions

File tree

‎core/src/main/java/org/apache/cloudstack/backup/TakeBackupCommand.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public class TakeBackupCommand extends Command {
3939

4040
// Incremental backup fields (NAS provider; null/empty for legacy full-only callers).
4141
private String mode; // "full" or "incremental"; null => legacy behaviour (script default)
42+
private String method; // "qcow2" (bitmaps, push mode) or "content" (pull mode); null => "qcow2"
4243
private String bitmapNew; // Checkpoint/bitmap name to create with this backup (timestamp-based)
4344
private String bitmapParent; // Incremental: parent bitmap to read changes since
4445

@@ -134,6 +135,14 @@ public void setMode(String mode) {
134135
this.mode = mode;
135136
}
136137

138+
public String getMethod() {
139+
return method;
140+
}
141+
142+
public void setMethod(String method) {
143+
this.method = method;
144+
}
145+
137146
public String getBitmapNew() {
138147
return bitmapNew;
139148
}

‎plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupChainKeys.java‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,22 @@ public final class NASBackupChainKeys {
4949
public static final String TYPE_LEGACY_FULL = "legacy-full";
5050

5151
/**
52-
* Backup taken through the content-based (libvirt pull mode) path, used for raw
53-
* block-device storage such as LINSTOR/DRBD which cannot carry QEMU persistent dirty
54-
* bitmaps. A full standalone qcow2, written sparse in a single pass.
52+
* In-memory backup-method sentinels used by {@code ChainDecision.method}: how a backup is
53+
* taken, independent of whether it is a full or an incremental ({@code ChainDecision.mode}).
54+
* Both methods write the same chain of qcow2 files, so restore and delete do not care.
55+
*
56+
* <p>{@link #METHOD_QCOW2}: libvirt push-mode backup; incrementals come from QEMU persistent
57+
* dirty bitmaps (libvirt checkpoints), which only qcow2 volumes can carry.</p>
5558
*/
56-
public static final String TYPE_CONTENT_FULL = "content-full";
59+
public static final String METHOD_QCOW2 = "qcow2";
5760

5861
/**
59-
* Delta backup produced by content comparison rather than dirty bitmaps: a qcow2 overlay
60-
* on the disk's NBD export, safe-rebased onto the parent so it holds only the clusters
61-
* that differ. Same chain shape as {@link #TYPE_INCREMENTAL}.
62+
* Content-based libvirt pull-mode backup, used for raw block-device storage such as
63+
* LINSTOR/DRBD which cannot carry persistent dirty bitmaps. A full is written as a sparse
64+
* qcow2 in a single pass; an incremental is a qcow2 overlay on the disk's NBD export,
65+
* safe-rebased onto the parent so it holds only the clusters that differ.
6266
*/
63-
public static final String TYPE_CONTENT_INCREMENTAL = "content-incremental";
67+
public static final String METHOD_CONTENT = "content";
6468

6569
/**
6670
* VM-scoped detail (stored in {@code vm_instance_details}) holding the QEMU dirty-bitmap

‎plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java‎

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,12 @@ protected Host getVMHypervisorHost(VirtualMachine vm) {
224224

225225
/**
226226
* Returned by {@link #decideChain(VirtualMachine)} to describe the next backup's place in
227-
* the chain: full vs incremental, the bitmap name to create, and (for incrementals) the
228-
* parent bitmap and parent file path.
227+
* the chain: full vs incremental, how it is taken, the bitmap name to create, and (for
228+
* incrementals) the parent bitmap and parent file path.
229229
*/
230230
static final class ChainDecision {
231231
final String mode; // "full" or "incremental"
232+
final String method; // NASBackupChainKeys.METHOD_QCOW2 or METHOD_CONTENT
232233
final String bitmapNew;
233234
final String bitmapParent; // null for full
234235
// Per-volume parent backup file paths, one per current VM volume in deviceId order.
@@ -243,12 +244,14 @@ static final class ChainDecision {
243244

244245
private ChainDecision(String mode, String bitmapNew, String bitmapParent, List<String> parentPaths,
245246
String chainId, int chainPosition) {
246-
this(mode, bitmapNew, bitmapParent, parentPaths, chainId, chainPosition, null);
247+
this(mode, NASBackupChainKeys.METHOD_QCOW2, bitmapNew, bitmapParent, parentPaths, chainId,
248+
chainPosition, null);
247249
}
248250

249-
private ChainDecision(String mode, String bitmapNew, String bitmapParent, List<String> parentPaths,
250-
String chainId, int chainPosition, String parentBackupUuid) {
251+
private ChainDecision(String mode, String method, String bitmapNew, String bitmapParent,
252+
List<String> parentPaths, String chainId, int chainPosition, String parentBackupUuid) {
251253
this.mode = mode;
254+
this.method = method;
252255
this.bitmapNew = bitmapNew;
253256
this.bitmapParent = bitmapParent;
254257
this.parentPaths = parentPaths;
@@ -282,25 +285,23 @@ static ChainDecision incremental(String bitmapNew, String bitmapParent, List<Str
282285
* does anchor a chain so later content-incrementals can hang off it.
283286
*/
284287
static ChainDecision contentFull() {
285-
return new ChainDecision(NASBackupChainKeys.TYPE_CONTENT_FULL, null, null, null,
286-
UUID.randomUUID().toString(), 0, null);
288+
return new ChainDecision(NASBackupChainKeys.TYPE_FULL, NASBackupChainKeys.METHOD_CONTENT, null, null,
289+
null, UUID.randomUUID().toString(), 0, null);
287290
}
288291

289292
static ChainDecision contentIncremental(List<String> parentPaths, String chainId,
290293
int chainPosition, String parentBackupUuid) {
291-
return new ChainDecision(NASBackupChainKeys.TYPE_CONTENT_INCREMENTAL, null, null,
292-
parentPaths, chainId, chainPosition, parentBackupUuid);
294+
return new ChainDecision(NASBackupChainKeys.TYPE_INCREMENTAL, NASBackupChainKeys.METHOD_CONTENT, null,
295+
null, parentPaths, chainId, chainPosition, parentBackupUuid);
293296
}
294297

295298
boolean isIncremental() {
296-
return NASBackupChainKeys.TYPE_INCREMENTAL.equals(mode)
297-
|| NASBackupChainKeys.TYPE_CONTENT_INCREMENTAL.equals(mode);
299+
return NASBackupChainKeys.TYPE_INCREMENTAL.equals(mode);
298300
}
299301

300302
/** True for the pull-mode content-diff path (no dirty bitmaps involved). */
301303
boolean isContentBased() {
302-
return NASBackupChainKeys.TYPE_CONTENT_FULL.equals(mode)
303-
|| NASBackupChainKeys.TYPE_CONTENT_INCREMENTAL.equals(mode);
304+
return NASBackupChainKeys.METHOD_CONTENT.equals(method);
304305
}
305306

306307
boolean isLegacyFull() {
@@ -710,6 +711,7 @@ public Pair<Boolean, Backup> takeBackup(final VirtualMachine vm, Boolean quiesce
710711
command.setQuiesce(quiesceVM);
711712
command.setQuiesceTimeout(NASBackupQuiesceAgentTimeout.valueIn(vm.getDataCenterId()));
712713
command.setMode(decision.mode);
714+
command.setMethod(decision.method);
713715
command.setBitmapNew(decision.bitmapNew);
714716
command.setBitmapParent(decision.bitmapParent);
715717
command.setParentPaths(decision.parentPaths);

‎plugins/backup/nas/src/test/java/org/apache/cloudstack/backup/NASBackupProviderTest.java‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ public void decideChainReturnsFullWhenVmHasNoActiveCheckpoint() {
505505
NASBackupProvider.ChainDecision decision = nasBackupProvider.decideChain(vm);
506506
Assert.assertNotNull(decision);
507507
Assert.assertEquals(NASBackupChainKeys.TYPE_FULL, decision.mode);
508+
Assert.assertEquals(NASBackupChainKeys.METHOD_QCOW2, decision.method);
508509
Assert.assertNull(decision.bitmapParent);
509510
Assert.assertEquals(0, decision.chainPosition);
510511
}
@@ -1123,16 +1124,17 @@ public void decideChainReturnsContentFullForLinstorWhenIncrementalDisabled() {
11231124
org.apache.cloudstack.framework.config.ConfigKey.Scope.Zone));
11241125

11251126
NASBackupProvider.ChainDecision decision = nasBackupProvider.decideChain(vm);
1126-
Assert.assertEquals(NASBackupChainKeys.TYPE_CONTENT_FULL, decision.mode);
1127+
Assert.assertEquals(NASBackupChainKeys.TYPE_FULL, decision.mode);
1128+
Assert.assertEquals(NASBackupChainKeys.METHOD_CONTENT, decision.method);
11271129
Assert.assertTrue(decision.isContentBased());
11281130
Assert.assertFalse(decision.isIncremental());
11291131
Assert.assertNull("content path uses no bitmaps", decision.bitmapNew);
1130-
Assert.assertNotNull("content-full still anchors a chain", decision.chainId);
1132+
Assert.assertNotNull("a content full still anchors a chain", decision.chainId);
11311133
}
11321134

11331135
/**
11341136
* Stopped VMs are imaged straight from the disk by qemu-img, with no point-in-time export to
1135-
* diff against a parent, so a LINSTOR VM that is stopped must take a content-full.
1137+
* diff against a parent, so a LINSTOR VM that is stopped must take a content full.
11361138
*/
11371139
@Test
11381140
public void decideChainReturnsContentFullForStoppedLinstorVm() {
@@ -1145,11 +1147,12 @@ public void decideChainReturnsContentFullForStoppedLinstorVm() {
11451147
enableIncrementals();
11461148

11471149
NASBackupProvider.ChainDecision decision = nasBackupProvider.decideChain(vm);
1148-
Assert.assertEquals(NASBackupChainKeys.TYPE_CONTENT_FULL, decision.mode);
1150+
Assert.assertEquals(NASBackupChainKeys.TYPE_FULL, decision.mode);
1151+
Assert.assertEquals(NASBackupChainKeys.METHOD_CONTENT, decision.method);
11491152
}
11501153

11511154
/**
1152-
* Running LINSTOR VM with a healthy parent inside the cadence => content-incremental, carrying
1155+
* Running LINSTOR VM with a healthy parent inside the cadence => content incremental, carrying
11531156
* the parent's chain id, the next position, the parent uuid (resolved directly since there is
11541157
* no bitmap to look it up by) and the per-volume parent paths the script rebases onto.
11551158
*/
@@ -1186,10 +1189,11 @@ public void decideChainReturnsContentIncrementalForLinstorWithValidParent() {
11861189
Mockito.when(backupDetailsDao.findDetail(900L, NASBackupChainKeys.CHAIN_POSITION)).thenReturn(chainPos);
11871190

11881191
NASBackupProvider.ChainDecision decision = nasBackupProvider.decideChain(vm);
1189-
Assert.assertEquals(NASBackupChainKeys.TYPE_CONTENT_INCREMENTAL, decision.mode);
1192+
Assert.assertEquals(NASBackupChainKeys.TYPE_INCREMENTAL, decision.mode);
1193+
Assert.assertEquals(NASBackupChainKeys.METHOD_CONTENT, decision.method);
11901194
Assert.assertTrue(decision.isIncremental());
11911195
Assert.assertTrue(decision.isContentBased());
1192-
Assert.assertNull("content-incremental carries no bitmap", decision.bitmapNew);
1196+
Assert.assertNull("a content incremental carries no bitmap", decision.bitmapNew);
11931197
Assert.assertNull(decision.bitmapParent);
11941198
Assert.assertEquals("chain-1", decision.chainId);
11951199
Assert.assertEquals(1, decision.chainPosition);
@@ -1200,7 +1204,7 @@ public void decideChainReturnsContentIncrementalForLinstorWithValidParent() {
12001204

12011205
/**
12021206
* Once the chain reaches nas.backup.full.every, the next LINSTOR backup must anchor a new
1203-
* chain with a content-full rather than extending the existing one.
1207+
* chain with a content full rather than extending the existing one.
12041208
*/
12051209
@Test
12061210
public void decideChainReturnsContentFullForLinstorAtChainEnd() {
@@ -1229,7 +1233,8 @@ public void decideChainReturnsContentFullForLinstorAtChainEnd() {
12291233
Mockito.when(backupDetailsDao.findDetail(901L, NASBackupChainKeys.CHAIN_POSITION)).thenReturn(chainPos);
12301234

12311235
NASBackupProvider.ChainDecision decision = nasBackupProvider.decideChain(vm);
1232-
Assert.assertEquals(NASBackupChainKeys.TYPE_CONTENT_FULL, decision.mode);
1236+
Assert.assertEquals(NASBackupChainKeys.TYPE_FULL, decision.mode);
1237+
Assert.assertEquals(NASBackupChainKeys.METHOD_CONTENT, decision.method);
12331238
}
12341239

12351240
/**

‎plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtTakeBackupCommandWrapper.java‎

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ public class LibvirtTakeBackupCommandWrapper extends CommandWrapper<TakeBackupCo
5454
// Incremental feature disabled: plain full backup with no QEMU bitmap/checkpoint and no
5555
// chain metadata. Matches nasbackup.sh's "legacy-full" mode (make_checkpoint=0).
5656
private static final String MODE_LEGACY_FULL = "legacy-full";
57-
/**
58-
* Content-based (libvirt pull mode) modes, used for raw block-device storage such as
59-
* LINSTOR/DRBD which cannot carry QEMU persistent dirty bitmaps. Neither carries a bitmap
60-
* name; the incremental one needs only its per-disk parent paths.
61-
*/
62-
private static final String MODE_CONTENT_FULL = "content-full";
63-
private static final String MODE_CONTENT_INCREMENTAL = "content-incremental";
57+
58+
// Backup methods, orthogonal to the mode. qcow2 is the push-mode path with QEMU dirty bitmaps,
59+
// also assumed when the management server sends none. content is libvirt pull mode, used for
60+
// raw block-device storage such as LINSTOR/DRBD which cannot carry persistent dirty bitmaps:
61+
// it needs no bitmap names, an incremental only its per-disk parent paths.
62+
private static final String METHOD_QCOW2 = "qcow2";
63+
private static final String METHOD_CONTENT = "content";
6464

6565
@Override
6666
public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvirtComputingResource) {
@@ -102,7 +102,7 @@ public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvir
102102

103103
if (result.first() != 0) {
104104
logger.debug("Failed to take VM backup: " + result.second());
105-
if (Script.ERR_TIMEOUT.equals(result.second()) && isPullMode(command.getMode())) {
105+
if (Script.ERR_TIMEOUT.equals(result.second()) && METHOD_CONTENT.equals(command.getMethod())) {
106106
abortPullBackupJob(vmName);
107107
}
108108
BackupAnswer answer = new BackupAnswer(command, false, StringUtils.trimToEmpty(result.second()));
@@ -130,10 +130,6 @@ public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvir
130130
return answer;
131131
}
132132

133-
private boolean isPullMode(String mode) {
134-
return MODE_CONTENT_FULL.equals(mode) || MODE_CONTENT_INCREMENTAL.equals(mode);
135-
}
136-
137133
/**
138134
* A pull-mode backup job never ends on its own: nasbackup.sh ends it once the data is read,
139135
* and its EXIT trap does so on failure. A timed-out script is killed with SIGKILL, which
@@ -195,6 +191,10 @@ private Pair<Integer, String> runBackupScript(LibvirtComputingResource libvirtCo
195191
argv.add("-M");
196192
argv.add(mode);
197193
}
194+
if (StringUtils.isNotBlank(command.getMethod())) {
195+
argv.add("--method");
196+
argv.add(command.getMethod());
197+
}
198198
if (StringUtils.isNotBlank(bitmapNew)) {
199199
argv.add("--bitmap-new");
200200
argv.add(bitmapNew);
@@ -226,6 +226,13 @@ private Pair<Integer, String> runBackupScript(LibvirtComputingResource libvirtCo
226226
*/
227227
private String validateBackupArgs(TakeBackupCommand command) {
228228
String mode = command.getMode();
229+
String method = StringUtils.defaultIfBlank(command.getMethod(), METHOD_QCOW2);
230+
if (METHOD_CONTENT.equals(method)) {
231+
return validateContentBackupArgs(command);
232+
}
233+
if (!METHOD_QCOW2.equals(method)) {
234+
return "Unknown backup method: " + method;
235+
}
229236
if (StringUtils.isBlank(mode)) {
230237
return null; // legacy full-only, no extra args expected
231238
}
@@ -250,17 +257,22 @@ private String validateBackupArgs(TakeBackupCommand command) {
250257
if (MODE_LEGACY_FULL.equals(mode)) {
251258
return null; // feature-off full backup, no bitmap or chain args expected
252259
}
253-
if (MODE_CONTENT_FULL.equals(mode)) {
260+
return "Unknown backup mode: " + mode;
261+
}
262+
263+
private String validateContentBackupArgs(TakeBackupCommand command) {
264+
String mode = command.getMode();
265+
if (MODE_FULL.equals(mode)) {
254266
return null; // pull-mode full — no bitmap, no parent
255267
}
256-
if (MODE_CONTENT_INCREMENTAL.equals(mode)) {
268+
if (MODE_INCREMENTAL.equals(mode)) {
257269
// No bitmap is involved: the delta comes from comparing the disk against the parent.
258270
if (CollectionUtils.isEmpty(command.getParentPaths())) {
259-
return "content-incremental mode requires parentPaths";
271+
return "content incremental mode requires parentPaths";
260272
}
261273
return null;
262274
}
263-
return "Unknown backup mode: " + mode;
275+
return "Unsupported mode for the content backup method: " + mode;
264276
}
265277

266278
/**

‎plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtTakeBackupCommandWrapperTest.java‎

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,16 @@ private void runFailing(Pair<Integer, String> result, boolean expectJobAbort) {
122122

123123
@Test
124124
public void executeAbortsPullBackupJobOnTimeout() {
125-
command.setMode("content-full");
125+
command.setMode("full");
126+
command.setMethod("content");
126127

127128
runFailing(new Pair<>(-1, Script.ERR_TIMEOUT), true);
128129
}
129130

130131
@Test
131132
public void executeLeavesPullBackupJobToScriptOnFailure() {
132-
command.setMode("content-full");
133+
command.setMode("full");
134+
command.setMethod("content");
133135

134136
runFailing(new Pair<>(1, "qemu-img convert failed"), false);
135137
}
@@ -140,4 +142,38 @@ public void executeDoesNotAbortPushBackupJobOnTimeout() {
140142

141143
runFailing(new Pair<>(-1, Script.ERR_TIMEOUT), false);
142144
}
145+
146+
@Test
147+
public void executePassesContentMethodToScript() {
148+
command.setMode("incremental");
149+
command.setMethod("content");
150+
command.setParentPaths(Arrays.asList("i-2-3-VM/2026.10.03.00.00.00/root.vol-1.qcow2"));
151+
152+
List<String> argv = runAndCaptureArgv();
153+
154+
Assert.assertEquals("incremental", argv.get(argv.indexOf("-M") + 1));
155+
Assert.assertEquals("content", argv.get(argv.indexOf("--method") + 1));
156+
Assert.assertFalse(argv.contains("--bitmap-new"));
157+
}
158+
159+
@Test
160+
public void executeRejectsContentIncrementalWithoutParentPaths() {
161+
command.setMode("incremental");
162+
command.setMethod("content");
163+
164+
BackupAnswer answer = (BackupAnswer) wrapper.execute(command, libvirtComputingResource);
165+
166+
Assert.assertFalse(answer.getResult());
167+
Assert.assertEquals("content incremental mode requires parentPaths", answer.getDetails());
168+
}
169+
170+
@Test
171+
public void executeRejectsLegacyFullWithContentMethod() {
172+
command.setMode("legacy-full");
173+
command.setMethod("content");
174+
175+
BackupAnswer answer = (BackupAnswer) wrapper.execute(command, libvirtComputingResource);
176+
177+
Assert.assertFalse(answer.getResult());
178+
}
143179
}

0 commit comments

Comments
 (0)