Pearl1594 commented on code in PR #12617:
URL: https://github.com/apache/cloudstack/pull/12617#discussion_r3390406146
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java:
##########
@@ -6820,4 +6827,242 @@ public String getHypervisorPath() {
public String getGuestCpuArch() {
return guestCpuArch;
}
+
+ /**
+ * CLVM volume state for migration operations on source host
+ */
+ public enum ClvmVolumeState {
+ /** Shared mode (-asy) - used before migration to allow both hosts to
access volume */
+ SHARED("-asy", "shared", "Before migration: activating in shared
mode"),
+
+ /** Deactivate (-an) - used after successful migration to release
volume on source */
+ DEACTIVATE("-an", "deactivated", "After successful migration:
deactivating volume"),
+
+ /** Exclusive mode (-aey) - used after failed migration to revert to
original exclusive state */
+ EXCLUSIVE("-aey", "exclusive", "After failed migration: reverting to
exclusive mode");
+
+ private final String lvchangeFlag;
+ private final String description;
+ private final String logMessage;
+
+ ClvmVolumeState(String lvchangeFlag, String description, String
logMessage) {
+ this.lvchangeFlag = lvchangeFlag;
+ this.description = description;
+ this.logMessage = logMessage;
+ }
+
+ public String getLvchangeFlag() {
+ return lvchangeFlag;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getLogMessage() {
+ return logMessage;
+ }
+ }
+
+ public static void modifyClvmVolumesStateForMigration(List<DiskDef> disks,
LibvirtComputingResource resource,
+ VirtualMachineTO
vmSpec, ClvmVolumeState state) {
+ for (DiskDef disk : disks) {
+ if (isClvmVolume(disk, resource, vmSpec)) {
+ String volumePath = disk.getDiskPath();
+ try {
+ modifyClvmVolumeState(volumePath, state.getLvchangeFlag(),
state.getDescription(), state.getLogMessage());
+ } catch (Exception e) {
+ LOGGER.error("[CLVM Migration] Exception while setting
volume [{}] to {} state: {}",
+ volumePath, state.getDescription(),
e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ private static void modifyClvmVolumeState(String volumePath, String
lvchangeFlag,
+ String stateDescription, String
logMessage) {
+ try {
+ LOGGER.info("{} for volume [{}]", logMessage, volumePath);
+
+ Script cmd = new Script("lvchange", Duration.standardSeconds(300),
LOGGER);
+ cmd.add(lvchangeFlag);
+ cmd.add(volumePath);
+
+ String result = cmd.execute();
+ if (result != null) {
+ String errorMsg = String.format(
+ "Failed to set volume [%s] to %s state. Command
result: %s",
+ volumePath, stateDescription, result);
+ LOGGER.error(errorMsg);
+ throw new CloudRuntimeException(errorMsg);
+ } else {
+ LOGGER.info("Successfully set volume [{}] to {} state.",
+ volumePath, stateDescription);
+ }
+ } catch (CloudRuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ String errorMsg = String.format(
+ "Exception while setting volume [%s] to %s state: %s",
+ volumePath, stateDescription, e.getMessage());
+ LOGGER.error(errorMsg, e);
+ throw new CloudRuntimeException(errorMsg, e);
+ }
+ }
+
+ public static void activateClvmVolumeExclusive(String volumePath) {
Review Comment:
as explained above
##########
plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java:
##########
@@ -6820,4 +6827,242 @@ public String getHypervisorPath() {
public String getGuestCpuArch() {
return guestCpuArch;
}
+
+ /**
+ * CLVM volume state for migration operations on source host
+ */
+ public enum ClvmVolumeState {
+ /** Shared mode (-asy) - used before migration to allow both hosts to
access volume */
+ SHARED("-asy", "shared", "Before migration: activating in shared
mode"),
+
+ /** Deactivate (-an) - used after successful migration to release
volume on source */
+ DEACTIVATE("-an", "deactivated", "After successful migration:
deactivating volume"),
+
+ /** Exclusive mode (-aey) - used after failed migration to revert to
original exclusive state */
+ EXCLUSIVE("-aey", "exclusive", "After failed migration: reverting to
exclusive mode");
+
+ private final String lvchangeFlag;
+ private final String description;
+ private final String logMessage;
+
+ ClvmVolumeState(String lvchangeFlag, String description, String
logMessage) {
+ this.lvchangeFlag = lvchangeFlag;
+ this.description = description;
+ this.logMessage = logMessage;
+ }
+
+ public String getLvchangeFlag() {
+ return lvchangeFlag;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getLogMessage() {
+ return logMessage;
+ }
+ }
+
+ public static void modifyClvmVolumesStateForMigration(List<DiskDef> disks,
LibvirtComputingResource resource,
+ VirtualMachineTO
vmSpec, ClvmVolumeState state) {
+ for (DiskDef disk : disks) {
+ if (isClvmVolume(disk, resource, vmSpec)) {
+ String volumePath = disk.getDiskPath();
+ try {
+ modifyClvmVolumeState(volumePath, state.getLvchangeFlag(),
state.getDescription(), state.getLogMessage());
+ } catch (Exception e) {
+ LOGGER.error("[CLVM Migration] Exception while setting
volume [{}] to {} state: {}",
+ volumePath, state.getDescription(),
e.getMessage(), e);
+ }
+ }
+ }
+ }
+
+ private static void modifyClvmVolumeState(String volumePath, String
lvchangeFlag,
+ String stateDescription, String
logMessage) {
+ try {
+ LOGGER.info("{} for volume [{}]", logMessage, volumePath);
+
+ Script cmd = new Script("lvchange", Duration.standardSeconds(300),
LOGGER);
+ cmd.add(lvchangeFlag);
+ cmd.add(volumePath);
+
+ String result = cmd.execute();
+ if (result != null) {
+ String errorMsg = String.format(
+ "Failed to set volume [%s] to %s state. Command
result: %s",
+ volumePath, stateDescription, result);
+ LOGGER.error(errorMsg);
+ throw new CloudRuntimeException(errorMsg);
+ } else {
+ LOGGER.info("Successfully set volume [{}] to {} state.",
+ volumePath, stateDescription);
+ }
+ } catch (CloudRuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ String errorMsg = String.format(
+ "Exception while setting volume [%s] to %s state: %s",
+ volumePath, stateDescription, e.getMessage());
+ LOGGER.error(errorMsg, e);
+ throw new CloudRuntimeException(errorMsg, e);
+ }
+ }
+
+ public static void activateClvmVolumeExclusive(String volumePath) {
+ modifyClvmVolumeState(volumePath,
ClvmVolumeState.EXCLUSIVE.getLvchangeFlag(),
+ ClvmVolumeState.EXCLUSIVE.getDescription(),
+ "Activating CLVM volume in exclusive mode");
+ }
+
+ public static void deactivateClvmVolume(String volumePath) {
+ try {
+ modifyClvmVolumeState(volumePath,
ClvmVolumeState.DEACTIVATE.getLvchangeFlag(),
+ ClvmVolumeState.DEACTIVATE.getDescription(),
+ "Deactivating CLVM volume");
+ } catch (Exception e) {
+ LOGGER.warn("Failed to deactivate CLVM volume {}: {}", volumePath,
e.getMessage());
+ }
+ }
+
+ public static void setClvmVolumeToSharedMode(String volumePath) {
Review Comment:
explained above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]