Source:
<code>protected void executeVmCommand() { Guid newActiveSnapshotId = Guid.NewGuid(); Guid createdSnapshotId = getSnapshotDao().getId(getVmId(), SnapshotType.ACTIVE); getParameters().setSnapshotType(determineSnapshotType()); getSnapshotDao().updateId(createdSnapshotId, newActiveSnapshotId); new SnapshotsManager().addSnapshot(createdSnapshotId, getParameters().getDescription(), getParameters().getSnapshotType(), getVm(), getCompensationContext()); <START> <END> setActionReturnValue(createdSnapshotId); if (getDisksList().isEmpty()) { getParameters().setTaskGroupSuccess(true); endSuccessfully(); } else { for (DiskImage image : getDisksList()) { ImagesActionsParametersBase tempVar = new ImagesActionsParametersBase(image.getImageId()); tempVar.setDescription(getParameters().getDescription()); tempVar.setSessionId(getParameters().getSessionId()); tempVar.setQuotaId(image.getQuotaId()); tempVar.setVmSnapshotId(newActiveSnapshotId); tempVar.setEntityId(getParameters().getEntityId()); tempVar.setParentCommand(getParameters().getParentCommand() != VdcActionType.Unknown ? getParameters() .getParentCommand() : VdcActionType.CreateAllSnapshotsFromVm); ImagesActionsParametersBase p = tempVar; getParameters().getImagesParameters().add(p); p.setParentParameters(getParameters()); VdcReturnValueBase vdcReturnValue = Backend.getInstance().runInternalAction( VdcActionType.CreateSnapshot, p, ExecutionHandler.createDefaultContexForTasks(getExecutionContext())); if (vdcReturnValue.getSucceeded()) { getTaskIdList().addAll(vdcReturnValue.getInternalTaskIdList()); } else { freeLock(); throw new VdcBLLException(vdcReturnValue.getFault().getError(), "CreateAllSnapshotsFromVmCommand::executeVmCommand: Failed to create snapshot!"); } } freeLock(); setSucceeded(true); } }</code><technical_language>is wrong, if want prevent hot plug add check hot plug command - SnapshotsValidator.vmNotDuringSnapshot(), lock is for other purposes</technical_language>

Target:
protected void executeVmCommand() { Guid newActiveSnapshotId = Guid.NewGuid(); Guid createdSnapshotId = getSnapshotDao().getId(getVmId(), SnapshotType.ACTIVE); getParameters().setSnapshotType(determineSnapshotType()); getSnapshotDao().updateId(createdSnapshotId, newActiveSnapshotId); new SnapshotsManager().addSnapshot(createdSnapshotId, getParameters().getDescription(), getParameters().getSnapshotType(), getVm(), getCompensationContext()); freeLock(); setActionReturnValue(createdSnapshotId); if (getDisksList().isEmpty()) { getParameters().setTaskGroupSuccess(true); endSuccessfully(); } else { for (DiskImage image : getDisksList()) { ImagesActionsParametersBase tempVar = new ImagesActionsParametersBase(image.getImageId()); tempVar.setDescription(getParameters().getDescription()); tempVar.setSessionId(getParameters().getSessionId()); tempVar.setQuotaId(image.getQuotaId()); tempVar.setVmSnapshotId(newActiveSnapshotId); tempVar.setEntityId(getParameters().getEntityId()); tempVar.setParentCommand(getParameters().getParentCommand() != VdcActionType.Unknown ? getParameters() .getParentCommand() : VdcActionType.CreateAllSnapshotsFromVm); ImagesActionsParametersBase p = tempVar; getParameters().getImagesParameters().add(p); p.setParentParameters(getParameters()); VdcReturnValueBase vdcReturnValue = Backend.getInstance().runInternalAction( VdcActionType.CreateSnapshot, p, ExecutionHandler.createDefaultContexForTasks(getExecutionContext())); if (vdcReturnValue.getSucceeded()) { getTaskIdList().addAll(vdcReturnValue.getInternalTaskIdList()); } else { throw new VdcBLLException(vdcReturnValue.getFault().getError(), "CreateAllSnapshotsFromVmCommand::executeVmCommand: Failed to create snapshot!"); } } setSucceeded(true); } }