Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

vSphere "The operation is not allowed in the current state": find which state is blocking the task

Technical article
VMware

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

The text The operation is not allowed in the current state. is what vSphere returns when it refuses a task because the object is in a state that does not allow it. On the ESXi command line the same refusal shows as vim.fault.InvalidState. Broadcom's knowledge base ties the message to several different states, so the fix depends on finding the state first: host maintenance mode, a host stuck in partial maintenance mode, a hung vCenter task, a passthrough device on a VM, or a leftover VM process.

What the error means

vCenter and the ESXi host each keep a state for every object: whether the host is in maintenance mode, whether a VM is on, off or in the middle of a snapshot, whether the host connection has a task running against it. A request that does not fit the current state is refused with this message. The message names no object and no reason, so the log and the object's state carry the answer.

Broadcom's pages show it in these situations:

  • A VM will not power on, and the host is in maintenance mode. The ESXCLI page for maintenance mode says: "You cannot deploy or power on a virtual machine on hosts in maintenance mode."
  • Power-on, power-off and snapshot tasks fail on ESXi 8.0 Update 3 although the host does not look like it is in maintenance mode. The cause in KB 393092 is a host stuck in partial maintenance mode, which the KB says is a feature of that release.
  • A host shows as disconnected in vCenter, and the Reconnect task fails with Reconnect Failed. The operation is not allowed in the current state. KB 373245 gives a hung task inside the vCenter service daemon (vpxd) as the frequent cause, on vCenter 7.x and 8.x.
  • A snapshot of a powered-on VM fails, and the VM has a PCI or PCIe passthrough (DirectPath IO) device. KB 428701 says snapshots are not supported on such VMs, on ESXi 8.0 and vCenter 8.0.
  • A migration back to the original host fails after a failover. KB 448321 describes a leftover VM process on that host, on ESXi 8.x and 9.x.

A different message, Another task is already in progress, is covered in vCenter "Another task is already in progress": find the task holding the VM.

Likely causes

Cause What you see How to confirm
Host is in maintenance mode VM power-on fails; the Power On and Off actions can be greyed out esxcli system maintenanceMode get on the host, or the host summary in the vSphere Client
Host is stuck in partial maintenance mode (ESXi 8.0 Update 3) Power and snapshot tasks fail, yet the host does not look like it is in maintenance mode hostd.log lines saying a state transition is blocked by the host's partial maintenance mode state; a vob.user.maintenancemode.entering line in vobd.log
Hung task for the host inside vCenter Reconnect Failed on a disconnected host while the network between vCenter and the host is fine A stuck task for that host in Recent Tasks in the vSphere Client
PCI or PCIe passthrough device on a powered-on VM Only snapshot tasks fail, and backups that use snapshots fail for that one VM pciPassthru entries in the VM's .vmx file, or the passthrough device in the VM's hardware list
Leftover VM process after a failover Migration back to the original host fails; the VM runs fine on another host esxcli vm process list on the original host shows a VM that is not in that host's inventory

Prove the cause before changing anything

These checks only read. Start with the operation that failed, because each cause above affects a different one.

1. Is the host in maintenance mode? KB 376378 lists these ways to check from the ESXi shell:

esxcli system maintenanceMode get
vim-cmd /hostsvc/hostsummary | grep inMaintenanceMode

A host that reports maintenance mode on, or inMaintenanceMode true, explains a failed power-on. The vSphere Client shows the same on the host's Summary tab.

2. Is it partial maintenance mode? On ESXi 8.0 Update 3, KB 393092 shows three log sources. Search for them:

grep "not allowed for this Vm" /var/run/log/hostd.log
grep maintenancemode /var/run/log/vobd.log
grep maintenanceMode /var/run/log/shell.log

A good result for this cause is a State Transition line in hostd.log ending in Blocked due to host (partial) maintenance mode state, a vob.user.maintenancemode.entering line in vobd.log and an esxcli system maintenanceMode set --enable true line in shell.log that someone ran on the host. No such lines means this is not the cause.

3. Is a task hung for the host? In the vSphere Client, open Recent Tasks for the host that will not reconnect. A task for that host that has run far longer than its normal duration is the cause KB 373245 describes. The KB gives no time limit.

4. Does the VM have a passthrough device? Search its configuration file, using the datastore, folder and VM name of the failing VM:

grep -i pciPassthru /vmfs/volumes/<datastore>/<vm-folder>/<vm-name>.vmx

KB 428701 shows pciPassthru0.present = "TRUE" as an example of what the file contains. No pciPassthru lines means this is not the cause.

5. Is there a leftover VM process? On the host the migration is going back to:

esxcli vm process list

KB 448321 describes the leftover process as one belonging to a VM that is no longer in that host's inventory. Compare the list with the VMs registered on the host.

Fix

Host in maintenance mode or partial maintenance mode

First print and keep the current state:

esxcli system maintenanceMode get

Disruptive step: the next step takes the host out of maintenance mode. VMs can then be powered on and deployed on it again, and any plan that relied on the host staying empty no longer holds.

Exit maintenance mode. KB 393092 says to use the vSphere Client for the partial state: right-click the host and select Enter / Exit Maintenance Mode, or sign in to the ESXi Host Client as root and use Actions, then Exit Maintenance Mode. KB 376378 gives the host command for an ordinary maintenance mode:

esxcli system maintenanceMode set --enable false

To undo it: do this only if the output you saved shows the host was in maintenance mode on purpose. Enter maintenance mode again from the vSphere Client, with a right-click on the host and Enter Maintenance Mode, and not with the host command. KB 393092 says that when the command is issued on the host, DRS does not evacuate the VMs and the host is left in partial maintenance mode. Then run esxcli system maintenanceMode get and compare it with your saved output.

The other causes

The remaining fixes are not scripted here, because each is either disruptive or cannot be reversed. They are described so that you can recognise them in the KB.

  • Hung vCenter task. KB 373245 says the hung task must be cancelled in the vSphere Client. If cancelling fails, it says to restart the vpxd service on the vCenter appliance, and warns that this temporarily halts all vCenter operations, including scheduled backups, vMotion and vSphere Client access, until the service has initialised. Treat that as a vCenter outage and schedule it.
  • Passthrough device. KB 428701 gives two ways out: remove the passthrough device while the VM is powered off, or take the snapshot while the VM is powered off. The KB states that snapshots succeed on powered-off VMs even with passthrough devices attached.
  • Leftover VM process. KB 448321 ends the leftover process with a forced kill by world ID. A forced kill of the wrong world ID stops a running VM, so match the process to the inventory first and follow the KB and its link on powering off an unresponsive VM.

Confirm the fix

  1. Repeat the task that failed (power on, snapshot, reconnect or migrate) and watch it complete in Recent Tasks.
  2. esxcli system maintenanceMode get matches what you intended.
  3. No new not allowed for this Vm lines appear in hostd.log after the time of the change.

What to watch afterwards

  • Enter maintenance mode from the vSphere Client rather than the host shell on ESXi 8.0 Update 3, so that DRS can evacuate the VMs.
  • Keep passthrough VMs in the backup and snapshot plan as exceptions, because their snapshots are refused.
  • Look at Recent Tasks after any network disruption, since KB 373245 says the stuck-task problem typically follows an environmental or network disruption.

Risks and limits

  • These commands have not been run or lab-tested.
  • The message is generic. A cause that is not among those above is possible, and Broadcom gives no single list.
  • KB 393092 applies to ESXi 8.0 Update 3 only. The other KBs give their own version ranges, in the version scope above.
  • Exiting maintenance mode puts a host back into service. Confirm that no maintenance work is still under way.
  • The vCenter service restart, the forced kill and device removal are changes that need their own plan.
  • KB 393092 does not say what esxcli system maintenanceMode get prints in partial maintenance mode. Judge by the log lines and by the host's state after the exit.

Example (illustrative): On esx01, running ESXi 8.0 Update 3, an engineer runs esxcli system maintenanceMode set --enable true in the host shell before a firmware job, then cancels the job. The vSphere Client shows no maintenance state for the host. Later, powering on web01 fails with The operation is not allowed in the current state. On esx01, grep "not allowed for this Vm" /var/run/log/hostd.log shows Blocked due to host (partial) maintenance mode state, and grep maintenanceMode /var/run/log/shell.log shows the engineer's command. The engineer saves the output, exits maintenance mode from the vSphere Client, and web01 powers on. If the job must go ahead later, maintenance mode is entered from the vSphere Client instead.

Sources