Skip to content

Commit

Permalink
Lock devices during OVF export as this could cause a race otherwise
Browse files Browse the repository at this point in the history
Closes: oVirt#797

During the creation of the ovf config export, oVirt does modifications
to the VmDevices.
Now another thread cleans those entries again, and if you are unlucky it
happens during the ovf generation itself.

DEBUG [org.ovirt.engine.core.vdsbroker.monitoring.VmDevicesMonitoring]
(EE-ManagedScheduledExecutorService-engineScheduledThreadPool-Thread-60)
[] VM 'xxxx' unmanaged device was marked for remove : {1}

And this causes the export to be skipped.

So we add a device lock during the ovf export to resolve this.

Signed-off-by: Jean-Louis Dupond <jean-louis@dupond.be>
  • Loading branch information
dupondje committed Jan 12, 2023
1 parent 68e5a98 commit 0f7b86b
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.ovirt.engine.core.common.queries.GetVmOvfByVmIdParameters;
import org.ovirt.engine.core.dao.SnapshotDao;
import org.ovirt.engine.core.dao.VmDao;
import org.ovirt.engine.core.vdsbroker.ResourceManager;

public class GetVmOvfByVmIdQuery<P extends GetVmOvfByVmIdParameters> extends QueriesCommandBase<P> {
@Inject
Expand All @@ -23,6 +24,9 @@ public class GetVmOvfByVmIdQuery<P extends GetVmOvfByVmIdParameters> extends Que
@Inject
private VmDeviceUtils vmDeviceUtils;

@Inject
private ResourceManager resourceManager;

public GetVmOvfByVmIdQuery(P parameters, EngineContext engineContext) {
super(parameters, engineContext);
}
Expand All @@ -35,10 +39,16 @@ protected void executeQueryCommand() {
return;
}

// We want to lock the devices to make sure no other thread modifies them during the ovf export.
// Otherwise we end up without ovf in the export
resourceManager.getVmManager(getParameters().getId()).getVmDevicesLock().lock();

vm.setSnapshots(snapshotDao.getAllWithConfiguration(vm.getId()));
vmDeviceUtils.setVmDevices(vm.getStaticData());
String ovfData = generateOvfConfig(vm, getParameters().isAsOva());

resourceManager.getVmManager(getParameters().getId()).getVmDevicesLock().unlock();

if (ovfData == null) {
return;
}
Expand Down

0 comments on commit 0f7b86b

Please sign in to comment.