QueryChangedDiskAreas API cannot return changed blocks list after reverting to a preexisting snapshot
search cancel

QueryChangedDiskAreas API cannot return changed blocks list after reverting to a preexisting snapshot

book

Article ID: 320058

calendar_today

Updated On:

Products

VMware Aria Suite

Issue/Introduction

Symptoms:
When users revert a snapshot for a virtual machine that has Changed Block Tracking (CBT) enabled, QueryChangedDiskAreas returns InvalidArgument if the VM is not powered on. The error message is not meaningful to indicate the real failure reason.

Cause

When users revert to a snapshot, it will automatically disable and enable CBT. If the snapshot is not a memory snapshot, enabling CBT will fail and CBT is disabled after reverting.

Resolution

To resolve this issue, re-enable CBT and perform a full backup.

  1. Power on the VM or reconfigure the VM (with "changeTrackingEnabled" true) from mob to re-enable CBT.
    Note: Reconfiguring the VM from mob to re-enable CBT is only supported in vSphere 7.0 or later.
You can set
*********************************
<spec>
<!-- optional -->
   <changeTrackingEnabled>true</changeTrackingEnabled>
</spec>

*********************************
in "VALUE" block of ReconfigVM_Task and click "Invoke Method" button to reconfigure the VM.
ReconfigVM_Task: https://<IP_Address>/mob/?moid=<VM_Moref>&method=reconfigure
---------------------------------------------------------
  1. Perform a full backup of the VM.



Additional Information

Note: Ensure that there are no snapshots on the virtual machine before enabling change tracking. If you create snapshots before enabling CBT, the QueryChangedDiskAreas API might not return any error or the data returned by QueryChangedDiskAreas might be incorrect.

Product version Impact
The issue can occurs in all vSphere versions.

How to detect a snapshot revert operation
See the sample code below for an example of how to query tasks from VM task history is provided in the attachment. It shows how to find tasks of type “RevertToSnapshot_Task” ever happened on a VM “RHELXfsTargetClone_src” in the last 7 days. The VixDiskLib_QueryAllocatedBlocks is available since VDDK 6.7 and later.

--------------------------------------------------------------------
/**
* This class is to demonstrate querying tasks from VM task history.
*/
public class TaskQuery {
 
    /**
     * find task of specific type in VM task history
     */
    public List<TaskInfo> query(ManagedObjectReference vmRef, Date sinceDate, String taskType) throws Exception {
   
        ServiceContent mSC = …;
        VimPortType vimPort = …;
        ManagedObjectReference taskManagerRef = mSC.getTaskManager();
       
        //prepare task filter. specify the vmRef as target
        TaskFilterSpecByEntity entityFilter = new TaskFilterSpecByEntity();
        entityFilter.setEntity(vmRef);
        entityFilter.setRecursion(TaskFilterSpecRecursionOption.SELF);
       
        //specify startTime
        TaskFilterSpecByTime startTimeFilter = new TaskFilterSpecByTime();
        Calendar startTime = Calendar.getInstance();
        startTime.setTime(sinceDate);
        startTimeFilter.setBeginTime(startTime);
        startTimeFilter.setTimeType(TaskFilterSpecTimeOption.STARTED_TIME);
       
        TaskFilterSpec taskFilter = new TaskFilterSpec();
        taskFilter.setEntity(entityFilter);
        taskFilter.setTime(startTimeFilter);
       
        //do query
        ManagedObjectReference taskCollectorRef = vimPort.createCollectorForTasks(taskManagerRef, taskFilter);
       
        List<TaskInfo> taskList = new LinkedList<TaskInfo>();       
        List<TaskInfo> pageInfo = vimPort.readNextTasks(taskCollectorRef, 100);
        while (pageInfo != null && pageInfo.size() != 0) {
           taskList.addAll(pageInfo);
           pageInfo = vimPort.readNextTasks(taskCollectorRef, 100);
        }
       
        List<TaskInfo> retList = new ArrayList<>();
        for (TaskInfo task : taskList) {
           if (task.getName().equals(taskType)) {
                retList.add(task);
           }
        }
       
        return retList;
   }
 
   
   public static void main(String[] args) throws Exception {
      TaskQuery taskQuery = new TaskQuery(context);
      Date oneWeekAgo = new Date(System.currentTimeMillis() - 7 * 24 * 3600 * 1000);
 
      ManagedObjectReference vmRef = …;
 
      List<TaskInfo> taskList = taskQuery.query(vmRef, oneWeekAgo, "RevertToSnapshot_Task");
      if (taskList.size() > 0) {
         System.out.println("RevertSnapshot tasks have been triggered on the vm.");
      }
   }
}
--------------------------------------------------------------------