Skip to content

Commit ce9793c

Browse files
Pearl1594Pearl Dsilvasureshanaparti
authored
CLVM enhancements and fixes (#12617)
This PR enhances the existing CLVM implementation which was based on the deprecated CLVM technology which was based on corosync/pacemaker. With RHEL 7 having reached EOL, CLVM seems to be broken. CLVM supports RAW volumes on LVM , where as CLVM_NG support QCOW2 on LVM. Further details: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Modernized+CLVM%3A+Enhancements+and+CLVM_NG+support NOTE: On testing - it was identified that incremental snapshots for clvm-ng do not work as expected. As of now it's been removed from scope. So, CLVM and CLVM_NG would only support full snapshots. * add support for proper cleanup of snapshots and prevent vol snapshot of running vm * remove snap vol restriction for sunning vms * refactor clvm code * add support for live migration * add support for migrating lvm lock * clvm deletion called explicitly * made necessary changes to allow migration of lock and deletion of detached volumes * fix create vol from snap and attach * add support to revert snapshot for clvm * add support to revert snapshot for clvm * make zero fill configurable * make setting non-dynamic & fix test * fix locking at vol/vm creation * fix revert snapshot format type and handle revert snapshot functionality for clvm * 1. Create clvmlockmanager and move common code \n 2. handle attaching volumes to stopped VMs \n 3. Handle lock transfer when VM is started on another host * add license * remove command/answer classes from sonar coverage check * add support for new gen clvm with template (qcow2) backing * Add support for clvm_ng - which allows qcow2 on block storage , linked clones, etc * fix test and use physical size + 50% of virtual size for backing file, while virtual size + pe for disk * migrate clvm volumes as full clone and allow migration from clvm to nfs * fix clvm_ng to nfs migration, and handle overhead calc * support live migration from clvm_ng to nfs and vice-versa * add support to migrate to and from clvm to nfs * fix creation of volume on destination host during migration to clvm/clvm-ng * support live vm migration between clvm -> clvm-ng (vice-versa), nfs -> clvm (vice-versa) and nfs->clvm-ng (vice-versa) * add unit tests for clvm/clvm_ng operations * Add support for incremental volume snapshots for clvm_ng * prevent snapshot backup for incremental clvm_ng snaps, fix build failure, add unit tests * fix lockhost on creation of volumes from snap and fix bitmap issue when migrating a vol with incremental snap * restrict pre and post migration commands to only kvm hosts where vm has CLVM/CLVM-NG volumes * evist lock tracking - use lvs command to get lock host than DB * add test for pre/post migration * Create a CLVM storage adaptor * update existing clvm get stats method * fix precommit check failure * Apply suggestions from code review Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com> * Apply suggestions from code review Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com> * improve lock host retrieval logic and quicker retrival using db host as first check point and then fanning out * add proper support for resizing of clvm_ng which calculated PE correctly for qcow2 metadata * fallback to full snapshots for clvm-ng - incremental not supported in 4.23 * expunge volume detail of lock host on vm expunge * if vmmigration with volume is done to the same clvm volume group, then dont do data transfer, just lock transfer and vm * add clvm pools with deterministic uuid , so as to prevent adding the same pool twic * added a small improvement to factor in a senario when lv is inactive on all hosts, could happen in storage outage issue * address comment - extract common code for endpoint identification if clvm pool type * Address comments - add early return guard to reduce indentation * minor improvement - when migrating vm with volumes, if there's a failures, change the clvm vols to exclusive on source from shared, and on success, change dest vol to exclusive only for cross-pool migration * cleanup unused code and tests for incremental snaps for clvmng and other cleanups * allow storage browser to list lv in clvm, fix clvm shrink, overprovisioning factor isnt used for clvm pools - so set it to 1 and prevented display of provisioning type for clvm * no need to have locktransfercommand to execute in sequence * increase lv cmd timeouts to consider cluster load --------- Co-authored-by: Pearl Dsilva <pearl1954@gmail.com> Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
1 parent ac6c1c8 commit ce9793c

76 files changed

Lines changed: 11956 additions & 226 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/src/main/java/com/cloud/storage/Storage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public static enum StoragePoolType {
170170
ISO(false, false, EncryptionSupport.Unsupported), // for iso image
171171
LVM(false, false, EncryptionSupport.Unsupported), // XenServer local LVM SR
172172
CLVM(true, false, EncryptionSupport.Unsupported),
173+
CLVM_NG(true, false, EncryptionSupport.Hypervisor),
173174
RBD(true, true, EncryptionSupport.Unsupported), // http://libvirt.org/storage.html#StorageBackendRBD
174175
SharedMountPoint(true, true, EncryptionSupport.Hypervisor),
175176
VMFS(true, true, EncryptionSupport.Unsupported), // VMware VMFS storage

core/src/main/java/com/cloud/agent/api/MigrateCommand.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.cloud.agent.api.to.DpdkTO;
2828
import com.cloud.agent.api.to.VirtualMachineTO;
29+
import com.cloud.storage.Storage;
2930

3031
public class MigrateCommand extends Command {
3132
private String vmName;
@@ -42,6 +43,7 @@ public class MigrateCommand extends Command {
4243
private Map<String, DpdkTO> dpdkInterfaceMapping = new HashMap<>();
4344

4445
private int newVmCpuShares;
46+
private boolean clvmCrossPoolMigration;
4547

4648
Map<String, Boolean> vlanToPersistenceMap = new HashMap<>();
4749

@@ -149,6 +151,14 @@ public void setNewVmCpuShares(int newVmCpuShares) {
149151
this.newVmCpuShares = newVmCpuShares;
150152
}
151153

154+
public boolean isClvmCrossPoolMigration() {
155+
return clvmCrossPoolMigration;
156+
}
157+
158+
public void setClvmCrossPoolMigration(boolean clvmCrossPoolMigration) {
159+
this.clvmCrossPoolMigration = clvmCrossPoolMigration;
160+
}
161+
152162
public static class MigrateDiskInfo {
153163
public enum DiskType {
154164
FILE, BLOCK;
@@ -184,6 +194,8 @@ public String toString() {
184194
private final String sourceText;
185195
private final String backingStoreText;
186196
private boolean isSourceDiskOnStorageFileSystem;
197+
private Storage.StoragePoolType sourcePoolType;
198+
private Storage.StoragePoolType destPoolType;
187199

188200
public MigrateDiskInfo(final String serialNumber, final DiskType diskType, final DriverType driverType, final Source source, final String sourceText) {
189201
this.serialNumber = serialNumber;
@@ -232,6 +244,22 @@ public boolean isSourceDiskOnStorageFileSystem() {
232244
public void setSourceDiskOnStorageFileSystem(boolean isDiskOnFileSystemStorage) {
233245
this.isSourceDiskOnStorageFileSystem = isDiskOnFileSystemStorage;
234246
}
247+
248+
public Storage.StoragePoolType getSourcePoolType() {
249+
return sourcePoolType;
250+
}
251+
252+
public void setSourcePoolType(Storage.StoragePoolType sourcePoolType) {
253+
this.sourcePoolType = sourcePoolType;
254+
}
255+
256+
public Storage.StoragePoolType getDestPoolType() {
257+
return destPoolType;
258+
}
259+
260+
public void setDestPoolType(Storage.StoragePoolType destPoolType) {
261+
this.destPoolType = destPoolType;
262+
}
235263
}
236264

237265
@Override
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
/**
23+
* Answer for PostMigrationCommand.
24+
* Indicates success or failure of post-migration operations on the destination host.
25+
*/
26+
public class PostMigrationAnswer extends Answer {
27+
28+
protected PostMigrationAnswer() {
29+
}
30+
31+
public PostMigrationAnswer(PostMigrationCommand cmd, String detail) {
32+
super(cmd, false, detail);
33+
}
34+
35+
public PostMigrationAnswer(PostMigrationCommand cmd, Exception ex) {
36+
super(cmd, ex);
37+
}
38+
39+
public PostMigrationAnswer(PostMigrationCommand cmd) {
40+
super(cmd, true, null);
41+
}
42+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
import com.cloud.agent.api.to.VirtualMachineTO;
23+
24+
/**
25+
* PostMigrationCommand is sent to the destination host after a successful VM migration.
26+
* It performs post-migration tasks such as:
27+
* - Claiming exclusive locks on CLVM volumes (converting from shared to exclusive mode)
28+
* - Other post-migration cleanup operations
29+
*/
30+
public class PostMigrationCommand extends Command {
31+
private VirtualMachineTO vm;
32+
private String vmName;
33+
34+
protected PostMigrationCommand() {
35+
}
36+
37+
public PostMigrationCommand(VirtualMachineTO vm, String vmName) {
38+
this.vm = vm;
39+
this.vmName = vmName;
40+
}
41+
42+
public VirtualMachineTO getVirtualMachine() {
43+
return vm;
44+
}
45+
46+
public String getVmName() {
47+
return vmName;
48+
}
49+
50+
@Override
51+
public boolean executeInSequence() {
52+
return true;
53+
}
54+
55+
@Override
56+
public boolean isBypassHostMaintenance() {
57+
return true;
58+
}
59+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package com.cloud.agent.api;
21+
22+
import com.cloud.agent.api.to.VirtualMachineTO;
23+
24+
/**
25+
* PreMigrationCommand is sent to the source host before VM migration starts.
26+
* It performs pre-migration tasks such as:
27+
* - Converting CLVM volume exclusive locks to shared mode so destination host can access them
28+
* - Other pre-migration preparation operations on the source host
29+
*
30+
* This command runs on the SOURCE host before PrepareForMigrationCommand runs on the DESTINATION host.
31+
*/
32+
public class PreMigrationCommand extends Command {
33+
private VirtualMachineTO vm;
34+
private String vmName;
35+
36+
protected PreMigrationCommand() {
37+
}
38+
39+
public PreMigrationCommand(VirtualMachineTO vm, String vmName) {
40+
this.vm = vm;
41+
this.vmName = vmName;
42+
}
43+
44+
public VirtualMachineTO getVirtualMachine() {
45+
return vm;
46+
}
47+
48+
public String getVmName() {
49+
return vmName;
50+
}
51+
52+
@Override
53+
public boolean executeInSequence() {
54+
return true;
55+
}
56+
57+
@Override
58+
public boolean isBypassHostMaintenance() {
59+
return true;
60+
}
61+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.cloudstack.storage.clvm.command;
19+
20+
import com.cloud.agent.api.Answer;
21+
22+
/**
23+
* Answer for ClvmLockTransferCommand, containing lock state information.
24+
* This answer includes the current lock holder information when querying lock state.
25+
*/
26+
public class ClvmLockTransferAnswer extends Answer {
27+
28+
private String currentLockHostname;
29+
private boolean isActive;
30+
private boolean isOpen;
31+
private String lvAttributes;
32+
33+
public ClvmLockTransferAnswer(ClvmLockTransferCommand cmd, boolean result, String details) {
34+
super(cmd, result, details);
35+
}
36+
37+
public ClvmLockTransferAnswer(ClvmLockTransferCommand cmd, boolean result, String details,
38+
String currentLockHostname, boolean isActive, boolean isOpen,
39+
String lvAttributes) {
40+
super(cmd, result, details);
41+
this.currentLockHostname = currentLockHostname;
42+
this.isActive = isActive;
43+
this.isOpen = isOpen;
44+
this.lvAttributes = lvAttributes;
45+
}
46+
47+
/**
48+
* Get the hostname from lv_host. Retained for diagnostics only —
49+
* do NOT use this to determine lock holder identity.
50+
*/
51+
public String getCurrentLockHostname() {
52+
return currentLockHostname;
53+
}
54+
55+
public void setCurrentLockHostname(String currentLockHostname) {
56+
this.currentLockHostname = currentLockHostname;
57+
}
58+
59+
/**
60+
* Whether the LV is locally active on the queried host (lv_attr[4]=='a').
61+
* This is the authoritative signal for lock holder discovery via fan-out.
62+
*/
63+
public boolean isActive() {
64+
return isActive;
65+
}
66+
67+
public void setActive(boolean active) {
68+
isActive = active;
69+
}
70+
71+
/**
72+
* Whether a process has the device file open on the queried host (lv_attr[5]=='o').
73+
* true means a VM is actively doing I/O on this host right now — do NOT deactivate.
74+
*/
75+
public boolean isOpen() {
76+
return isOpen;
77+
}
78+
79+
public void setOpen(boolean open) {
80+
isOpen = open;
81+
}
82+
83+
public String getLvAttributes() {
84+
return lvAttributes;
85+
}
86+
87+
public void setLvAttributes(String lvAttributes) {
88+
this.lvAttributes = lvAttributes;
89+
}
90+
}

0 commit comments

Comments
 (0)