Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KVM incremental snapshot feature #9270

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,16 @@ public Property<Integer> getWorkers() {
*/
public static final Property<String> HOST_TAGS = new Property<>("host.tags", null, String.class);

/**
* Timeout (in seconds) to wait for the incremental snapshot to complete.
* */
public static final Property<Integer> INCREMENTAL_SNAPSHOT_TIMEOUT = new Property<>("incremental.snapshot.timeout", 10800);

/**
* Timeout (in seconds) to wait for the snapshot reversion to complete.
* */
public static final Property<Integer> REVERT_SNAPSHOT_TIMEOUT = new Property<>("revert.snapshot.timeout", 10800);

public static class Property <T>{
private String name;
private T defaultValue;
Expand Down
36 changes: 36 additions & 0 deletions core/src/main/java/com/cloud/agent/api/ConvertSnapshotAnswer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.cloud.agent.api;

import org.apache.cloudstack.storage.to.SnapshotObjectTO;

public class ConvertSnapshotAnswer extends Answer {

private SnapshotObjectTO snapshotObjectTO;

public ConvertSnapshotAnswer(SnapshotObjectTO snapshotObjectTO) {
super(null);
this.snapshotObjectTO = snapshotObjectTO;
}

Check warning on line 31 in core/src/main/java/com/cloud/agent/api/ConvertSnapshotAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ConvertSnapshotAnswer.java#L29-L31

Added lines #L29 - L31 were not covered by tests

public SnapshotObjectTO getSnapshotObjectTO() {
return snapshotObjectTO;
}

Check warning on line 35 in core/src/main/java/com/cloud/agent/api/ConvertSnapshotAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ConvertSnapshotAnswer.java#L33-L35

Added lines #L33 - L35 were not covered by tests
}
42 changes: 42 additions & 0 deletions core/src/main/java/com/cloud/agent/api/ConvertSnapshotCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.cloud.agent.api;

import org.apache.cloudstack.storage.to.SnapshotObjectTO;

public class ConvertSnapshotCommand extends Command {

public static final String TEMP_SNAPSHOT_NAME = "_temp";

SnapshotObjectTO snapshotObjectTO;

public SnapshotObjectTO getSnapshotObjectTO() {
return snapshotObjectTO;
}

Check warning on line 32 in core/src/main/java/com/cloud/agent/api/ConvertSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ConvertSnapshotCommand.java#L30-L32

Added lines #L30 - L32 were not covered by tests

public ConvertSnapshotCommand(SnapshotObjectTO snapshotObjectTO) {
this.snapshotObjectTO = snapshotObjectTO;
}

Check warning on line 36 in core/src/main/java/com/cloud/agent/api/ConvertSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ConvertSnapshotCommand.java#L34-L36

Added lines #L34 - L36 were not covered by tests

@Override
public boolean executeInSequence() {
return true;
}

Check warning on line 41 in core/src/main/java/com/cloud/agent/api/ConvertSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/ConvertSnapshotCommand.java#L39-L41

Added lines #L39 - L41 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//

package com.cloud.agent.api;

import org.apache.cloudstack.storage.to.VolumeObjectTO;

import java.util.List;

public class RecreateCheckpointsCommand extends Command {

private List<VolumeObjectTO> volumes;

private String vmName;

public RecreateCheckpointsCommand(List<VolumeObjectTO> volumes, String vmName) {
this.volumes = volumes;
this.vmName = vmName;
}

public List<VolumeObjectTO> getDisks() {
return volumes;
}

Check warning on line 39 in core/src/main/java/com/cloud/agent/api/RecreateCheckpointsCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/RecreateCheckpointsCommand.java#L37-L39

Added lines #L37 - L39 were not covered by tests

public String getVmName() {
return vmName;
}

Check warning on line 43 in core/src/main/java/com/cloud/agent/api/RecreateCheckpointsCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/RecreateCheckpointsCommand.java#L41-L43

Added lines #L41 - L43 were not covered by tests

@Override
public boolean executeInSequence() {
return true;
}

Check warning on line 48 in core/src/main/java/com/cloud/agent/api/RecreateCheckpointsCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/RecreateCheckpointsCommand.java#L46-L48

Added lines #L46 - L48 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
}
return new CreateObjectAnswer("not supported type");
} catch (Exception e) {
logger.debug("Failed to create object: " + data.getObjectType() + ": " + e.toString());
logger.error("Failed to create object [%s] due to [%s].", data.getObjectType(), e.getMessage(), e);

Check warning on line 145 in core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java#L145

Added line #L145 was not covered by tests
return new CreateObjectAnswer(e.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class TemplateConstants {
public static final String DEFAULT_SNAPSHOT_ROOT_DIR = "snapshots";
public static final String DEFAULT_VOLUME_ROOT_DIR = "volumes";
public static final String DEFAULT_TMPLT_FIRST_LEVEL_DIR = "tmpl/";

public static final String DEFAULT_CHECKPOINT_ROOT_DIR = "checkpoints";
public static final String DEFAULT_SYSTEM_VM_TEMPLATE_PATH = "template/tmpl/1/";

public static final int DEFAULT_TMPLT_COPY_PORT = 80;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@
private VolumeObjectTO volume;
private String parentSnapshotPath;
private DataStoreTO dataStore;
private DataStoreTO imageStore;
private boolean kvmIncrementalSnapshot = false;
private String vmName;
private String name;
private HypervisorType hypervisorType;
private long id;
private boolean quiescevm;
private String[] parents;
private String checkpointPath;
private Long physicalSize = (long) 0;
private long accountId;

Expand All @@ -59,22 +62,28 @@
this.setVmName(vol.getAttachedVmName());
}

SnapshotInfo parentSnapshot = snapshot.getParent();
ArrayList<String> parentsArry = new ArrayList<String>();
if (parentSnapshot != null) {
this.parentSnapshotPath = parentSnapshot.getPath();
while(parentSnapshot != null) {
parentsArry.add(parentSnapshot.getPath());
parentSnapshot = parentSnapshot.getParent();
}
parents = parentsArry.toArray(new String[parentsArry.size()]);
ArrayUtils.reverse(parents);
}

this.dataStore = snapshot.getDataStore().getTO();
this.setName(snapshot.getName());
this.hypervisorType = snapshot.getHypervisorType();
this.quiescevm = false;

this.checkpointPath = snapshot.getCheckpointPath();
this.kvmIncrementalSnapshot = snapshot.isKvmIncrementalSnapshot();

SnapshotInfo parentSnapshot = snapshot.getParent();

if (parentSnapshot == null || (HypervisorType.KVM.equals(snapshot.getHypervisorType()) && !parentSnapshot.isKvmIncrementalSnapshot())) {
return;
}

ArrayList<String> parentsArray = new ArrayList<>();
this.parentSnapshotPath = parentSnapshot.getPath();

Check warning on line 80 in core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java#L79-L80

Added lines #L79 - L80 were not covered by tests
while (parentSnapshot != null) {
parentsArray.add(parentSnapshot.getPath());
parentSnapshot = parentSnapshot.getParent();

Check warning on line 83 in core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java#L82-L83

Added lines #L82 - L83 were not covered by tests
}
parents = parentsArray.toArray(new String[parentsArray.size()]);
ArrayUtils.reverse(parents);

Check warning on line 86 in core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java#L85-L86

Added lines #L85 - L86 were not covered by tests
}

@Override
Expand All @@ -91,6 +100,30 @@
this.dataStore = store;
}

public DataStoreTO getImageStore() {
return imageStore;
}

Check warning on line 105 in core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java#L103-L105

Added lines #L103 - L105 were not covered by tests

public void setImageStore(DataStoreTO imageStore) {
this.imageStore = imageStore;
}

Check warning on line 109 in core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java#L107-L109

Added lines #L107 - L109 were not covered by tests

public boolean isKvmIncrementalSnapshot() {
return kvmIncrementalSnapshot;
}

Check warning on line 113 in core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java#L111-L113

Added lines #L111 - L113 were not covered by tests

public void setKvmIncrementalSnapshot(boolean kvmIncrementalSnapshot) {
this.kvmIncrementalSnapshot = kvmIncrementalSnapshot;
}

Check warning on line 117 in core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java#L115-L117

Added lines #L115 - L117 were not covered by tests

public String getCheckpointPath() {
return checkpointPath;
}

Check warning on line 121 in core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java#L119-L121

Added lines #L119 - L121 were not covered by tests

public void setCheckpointPath(String checkpointPath) {
this.checkpointPath = checkpointPath;
}

Check warning on line 125 in core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/SnapshotObjectTO.java#L123-L125

Added lines #L123 - L125 were not covered by tests

@Override
public String getPath() {
return this.path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import com.cloud.storage.Volume;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class VolumeObjectTO extends DownloadableObjectTO implements DataTO {
private String uuid;
Expand Down Expand Up @@ -75,6 +77,8 @@
@LogLevel(LogLevel.Log4jLevel.Off)
private byte[] passphrase;
private String encryptFormat;
private List<String> checkpointPaths;
private Set<String> checkpointImageStoreUrls;

public VolumeObjectTO() {

Expand Down Expand Up @@ -394,4 +398,21 @@
public boolean requiresEncryption() {
return passphrase != null && passphrase.length > 0;
}


public List<String> getCheckpointPaths() {

Check warning on line 403 in core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java#L403

Added line #L403 was not covered by tests
return checkpointPaths;
}

Check warning on line 405 in core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java#L405

Added line #L405 was not covered by tests

public void setCheckpointPaths(List<String> checkpointPaths) {
this.checkpointPaths = checkpointPaths;
}

Check warning on line 409 in core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java#L407-L409

Added lines #L407 - L409 were not covered by tests

public Set<String> getCheckpointImageStoreUrls() {
return checkpointImageStoreUrls;
}

Check warning on line 413 in core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java#L411-L413

Added lines #L411 - L413 were not covered by tests

public void setCheckpointImageStoreUrls(Set<String> checkpointImageStoreUrls) {
this.checkpointImageStoreUrls = checkpointImageStoreUrls;
}

Check warning on line 417 in core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/org/apache/cloudstack/storage/to/VolumeObjectTO.java#L415-L417

Added lines #L415 - L417 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Set;

import com.cloud.exception.ResourceAllocationException;
import com.cloud.utils.Pair;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
Expand Down Expand Up @@ -179,4 +180,9 @@ DiskProfile updateImportedVolume(Type type, DiskOffering offering, VirtualMachin
* Unmanage VM volumes
*/
void unmanageVolumes(long vmId);

/**
* Retrieves the volume's checkpoints paths to be used in the KVM processor. If there are no checkpoints, it will return an empty list.
*/
Pair<List<String>, Set<String>> getVolumeCheckpointPathsAndImageStoreUrls(long volumeId, HypervisorType hypervisorType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public interface SnapshotInfo extends DataObject, Snapshot {

String getPath();

DataStore getImageStore();

void setImageStore(DataStore imageStore);

SnapshotInfo getChild();

List<SnapshotInfo> getChildren();
Expand All @@ -56,6 +60,14 @@ public interface SnapshotInfo extends DataObject, Snapshot {

void markBackedUp() throws CloudRuntimeException;

String getCheckpointPath();

void setCheckpointPath(String checkpointPath);

void setKvmIncrementalSnapshot(boolean isKvmIncrementalSnapshot);

boolean isKvmIncrementalSnapshot();

Snapshot getSnapshotVO();

long getAccountId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
public interface SnapshotService {
SnapshotResult takeSnapshot(SnapshotInfo snapshot);

DataStore findSnapshotImageStore(SnapshotInfo snapshot);

SnapshotInfo backupSnapshot(SnapshotInfo snapshot);

SnapshotInfo convertSnapshot(SnapshotInfo snapshotInfo);

boolean deleteSnapshot(SnapshotInfo snapshot);

boolean revertSnapshot(SnapshotInfo snapshot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TAKESNAPSHOT,
BACKUPSNAPSHOT,
DELETESNAPSHOT,
CONVERTSNAPSHOT,

Check warning on line 25 in engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/StorageAction.java

View check run for this annotation

Codecov / codecov/patch

engine/api/src/main/java/org/apache/cloudstack/engine/subsystem/api/storage/StorageAction.java#L25

Added line #L25 was not covered by tests
MIGRATEVOLUME,
DELETEVOLUME
}
Loading
Loading