Thanks to visit codestin.com
Credit goes to github.com

Skip to content

File-based disk-only VM snapshot with KVM as hypervisor #10632

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

Open
wants to merge 3 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 @@ -155,6 +155,14 @@ public class AgentProperties{
*/
public static final Property<Integer> CMDS_TIMEOUT = new Property<>("cmds.timeout", 7200);

/**
* The timeout (in seconds) for the snapshot merge operation, mainly used for classic volume snapshots and disk-only VM snapshots on file-based storage.<br>
* This configuration is only considered if libvirt.events.enabled is also true. <br>
* Data type: Integer.<br>
* Default value: <code>259200</code>
*/
public static final Property<Integer> SNAPSHOT_MERGE_TIMEOUT = new Property<>("snapshot.merge.timeout", 60 * 60 * 72);

/**
* This parameter sets the VM migration speed (in mbps). The default value is -1,<br>
* which means that the agent will try to guess the speed of the guest network and consume all possible bandwidth.<br>
Expand Down
7 changes: 5 additions & 2 deletions api/src/main/java/com/cloud/vm/snapshot/VMSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public interface VMSnapshot extends ControlledEntity, Identity, InternalIdentity
enum State {
Allocated("The VM snapshot is allocated but has not been created yet."), Creating("The VM snapshot is being created."), Ready(
"The VM snapshot is ready to be used."), Reverting("The VM snapshot is being used to revert"), Expunging("The volume is being expunging"), Removed(
"The volume is destroyed, and can't be recovered."), Error("The volume is in error state, and can't be recovered");
"The volume is destroyed, and can't be recovered."), Error("The volume is in error state, and can't be recovered"),
Hidden("The VM snapshot is hidden from the user and cannot be recovered.");

String _description;

Expand Down Expand Up @@ -60,6 +61,8 @@ public String getDescription() {
s_fsm.addTransition(Expunging, Event.ExpungeRequested, Expunging);
s_fsm.addTransition(Expunging, Event.OperationSucceeded, Removed);
s_fsm.addTransition(Expunging, Event.OperationFailed, Error);
s_fsm.addTransition(Expunging, Event.Hide, Hidden);
s_fsm.addTransition(Hidden, Event.ExpungeRequested, Expunging);
}
}

Expand All @@ -68,7 +71,7 @@ enum Type {
}

enum Event {
CreateRequested, OperationFailed, OperationSucceeded, RevertRequested, ExpungeRequested,
CreateRequested, OperationFailed, OperationSucceeded, RevertRequested, ExpungeRequested, Hide,
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.storage;

import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import com.cloud.utils.Pair;

import java.util.Map;

public class CreateDiskOnlyVmSnapshotAnswer extends Answer {

protected Map<String, Pair<Long, String>> mapVolumeToSnapshotSizeAndNewVolumePath;

public CreateDiskOnlyVmSnapshotAnswer(Command command, boolean success, String details, Map<String, Pair<Long, String>> mapVolumeToSnapshotSizeAndNewVolumePath) {
super(command, success, details);
this.mapVolumeToSnapshotSizeAndNewVolumePath = mapVolumeToSnapshotSizeAndNewVolumePath;
}

Check warning on line 34 in core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotAnswer.java#L32-L34

Added lines #L32 - L34 were not covered by tests

public Map<String, Pair<Long, String>> getMapVolumeToSnapshotSizeAndNewVolumePath() {
return mapVolumeToSnapshotSizeAndNewVolumePath;
}

Check warning on line 38 in core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotAnswer.java#L36-L38

Added lines #L36 - L38 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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.storage;


import com.cloud.agent.api.VMSnapshotBaseCommand;
import com.cloud.agent.api.VMSnapshotTO;
import com.cloud.vm.VirtualMachine;
import org.apache.cloudstack.storage.to.VolumeObjectTO;

import java.util.List;

public class CreateDiskOnlyVmSnapshotCommand extends VMSnapshotBaseCommand {

protected VirtualMachine.State vmState;

public CreateDiskOnlyVmSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<VolumeObjectTO> volumeTOs, String guestOSType, VirtualMachine.State vmState) {
super(vmName, snapshot, volumeTOs, guestOSType);
this.vmState = vmState;
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L34 - L36 were not covered by tests

public VirtualMachine.State getVmState() {
return vmState;
}

Check warning on line 40 in core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotCommand.java#L38-L40

Added lines #L38 - L40 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.storage;

import com.cloud.agent.api.Command;

import com.cloud.agent.api.to.DataTO;


import java.util.List;

public class DeleteDiskOnlyVmSnapshotCommand extends Command {

List<DataTO> snapshots;

public DeleteDiskOnlyVmSnapshotCommand(List<DataTO> snapshots) {
this.snapshots = snapshots;
}

Check warning on line 34 in core/src/main/java/com/cloud/agent/api/storage/DeleteDiskOnlyVmSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/DeleteDiskOnlyVmSnapshotCommand.java#L32-L34

Added lines #L32 - L34 were not covered by tests

public List<DataTO> getSnapshots() {
return snapshots;
}

Check warning on line 38 in core/src/main/java/com/cloud/agent/api/storage/DeleteDiskOnlyVmSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/DeleteDiskOnlyVmSnapshotCommand.java#L36-L38

Added lines #L36 - L38 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L41 - L43 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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.storage;

import com.cloud.agent.api.Command;
import com.cloud.vm.VirtualMachine;

import java.util.List;

public class MergeDiskOnlyVmSnapshotCommand extends Command {

private List<SnapshotMergeTreeTO> snapshotMergeTreeToList;
private VirtualMachine.State vmState;
private String vmName;

public MergeDiskOnlyVmSnapshotCommand(List<SnapshotMergeTreeTO> snapshotMergeTreeToList, VirtualMachine.State vmState, String vmName) {
this.snapshotMergeTreeToList = snapshotMergeTreeToList;
this.vmState = vmState;
this.vmName = vmName;
}

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

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/MergeDiskOnlyVmSnapshotCommand.java#L32-L36

Added lines #L32 - L36 were not covered by tests

public List<SnapshotMergeTreeTO> getSnapshotMergeTreeToList() {
return snapshotMergeTreeToList;
}

Check warning on line 40 in core/src/main/java/com/cloud/agent/api/storage/MergeDiskOnlyVmSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/MergeDiskOnlyVmSnapshotCommand.java#L38-L40

Added lines #L38 - L40 were not covered by tests

public VirtualMachine.State getVmState() {
return vmState;
}

Check warning on line 44 in core/src/main/java/com/cloud/agent/api/storage/MergeDiskOnlyVmSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/MergeDiskOnlyVmSnapshotCommand.java#L42-L44

Added lines #L42 - L44 were not covered by tests

public String getVmName() {
return vmName;
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L46 - L48 were not covered by tests

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

Check warning on line 53 in core/src/main/java/com/cloud/agent/api/storage/MergeDiskOnlyVmSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/MergeDiskOnlyVmSnapshotCommand.java#L51-L53

Added lines #L51 - L53 were not covered by tests

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.storage;

import com.cloud.agent.api.Answer;
import com.cloud.agent.api.Command;
import org.apache.cloudstack.storage.to.VolumeObjectTO;

import java.util.List;

public class RevertDiskOnlyVmSnapshotAnswer extends Answer {
List<VolumeObjectTO> volumeObjectTos;

public RevertDiskOnlyVmSnapshotAnswer(Command cmd, List<VolumeObjectTO> volumeObjectTos) {
super(cmd, true, null);
this.volumeObjectTos = volumeObjectTos;
}

Check warning on line 33 in core/src/main/java/com/cloud/agent/api/storage/RevertDiskOnlyVmSnapshotAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/RevertDiskOnlyVmSnapshotAnswer.java#L31-L33

Added lines #L31 - L33 were not covered by tests

public List<VolumeObjectTO> getVolumeObjectTos() {
return volumeObjectTos;
}

Check warning on line 37 in core/src/main/java/com/cloud/agent/api/storage/RevertDiskOnlyVmSnapshotAnswer.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/RevertDiskOnlyVmSnapshotAnswer.java#L35-L37

Added lines #L35 - L37 were not covered by tests
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.storage;

import com.cloud.agent.api.Command;
import org.apache.cloudstack.storage.to.SnapshotObjectTO;

import java.util.List;

public class RevertDiskOnlyVmSnapshotCommand extends Command {

private List<SnapshotObjectTO> snapshotObjectTos;
private String vmName;

public RevertDiskOnlyVmSnapshotCommand(List<SnapshotObjectTO> snapshotObjectTos, String vmName) {
super();
this.snapshotObjectTos = snapshotObjectTos;
this.vmName = vmName;
}

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

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/RevertDiskOnlyVmSnapshotCommand.java#L32-L35

Added lines #L32 - L35 were not covered by tests

public List<SnapshotObjectTO> getSnapshotObjectTos() {
return snapshotObjectTos;
}

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

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/RevertDiskOnlyVmSnapshotCommand.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/storage/RevertDiskOnlyVmSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/RevertDiskOnlyVmSnapshotCommand.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/storage/RevertDiskOnlyVmSnapshotCommand.java

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L46 - L48 were not covered by tests

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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.storage;

import com.cloud.agent.api.to.DataTO;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

import java.util.List;

public class SnapshotMergeTreeTO {
DataTO parent;
DataTO child;
List<DataTO> grandChildren;

public SnapshotMergeTreeTO(DataTO parent, DataTO child, List<DataTO> grandChildren) {
this.parent = parent;
this.child = child;
this.grandChildren = grandChildren;
}

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

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/SnapshotMergeTreeTO.java#L31-L35

Added lines #L31 - L35 were not covered by tests

public DataTO getParent() {
return parent;
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L37 - L39 were not covered by tests

public DataTO getChild() {
return child;
}

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L41 - L43 were not covered by tests

public List<DataTO> getGrandChildren() {
return grandChildren;
}

Check warning on line 47 in core/src/main/java/com/cloud/agent/api/storage/SnapshotMergeTreeTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/SnapshotMergeTreeTO.java#L45-L47

Added lines #L45 - L47 were not covered by tests

public void addGrandChild(DataTO grandChild) {
grandChildren.add(grandChild);
}

Check warning on line 51 in core/src/main/java/com/cloud/agent/api/storage/SnapshotMergeTreeTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/SnapshotMergeTreeTO.java#L49-L51

Added lines #L49 - L51 were not covered by tests

@Override
public String toString() {
return ReflectionToStringBuilder.toString(this);
}

Check warning on line 56 in core/src/main/java/com/cloud/agent/api/storage/SnapshotMergeTreeTO.java

View check run for this annotation

Codecov / codecov/patch

core/src/main/java/com/cloud/agent/api/storage/SnapshotMergeTreeTO.java#L54-L56

Added lines #L54 - L56 were not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public interface VMSnapshotDao extends GenericDao<VMSnapshotVO, Long>, StateDao<

List<VMSnapshotVO> findByVm(Long vmId);

List<VMSnapshotVO> findByVmAndByType(Long vmId, VMSnapshot.Type type);

List<VMSnapshotVO> listExpungingSnapshot();

List<VMSnapshotVO> listByInstanceId(Long vmId, VMSnapshot.State... status);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@
return listBy(sc, null);
}

@Override
public List<VMSnapshotVO> findByVmAndByType(Long vmId, VMSnapshot.Type type) {
SearchCriteria<VMSnapshotVO> sc = AllFieldsSearch.create();
sc.setParameters("vm_id", vmId);
sc.setParameters("vm_snapshot_type", type);
return listBy(sc, null);
}

Check warning on line 89 in engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/schema/src/main/java/com/cloud/vm/snapshot/dao/VMSnapshotDaoImpl.java#L84-L89

Added lines #L84 - L89 were not covered by tests

@Override
public List<VMSnapshotVO> listExpungingSnapshot() {
SearchCriteria<VMSnapshotVO> sc = ExpungingSnapshotSearch.create();
Expand Down
Loading
Loading