Skip to content

Commit

Permalink
nbd_client_manager.py: make NBD disconnect idempotent
Browse files Browse the repository at this point in the history
To ensure that it does not fail when we call it on an already
disconnected device.

Signed-off-by: Gabor Igloi <gabor.igloi@citrix.com>
  • Loading branch information
gaborigloi committed Mar 14, 2018
1 parent 96e0ba5 commit 636eed1
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scripts/nbd_client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,15 @@ def connect_nbd(path, exportname):

def disconnect_nbd_device(nbd_device):
"""
Disconnects the given device using nbd-client
Disconnects the given device using nbd-client.
This function is idempotent: calling it on an already disconnected device
does nothing.
"""
FILE_LOCK.lock()
cmd = ['nbd-client', '-disconnect', nbd_device]
_call(cmd)
_wait_for_nbd_device(nbd_device=nbd_device, connected=False)
if _is_nbd_device_connected(nbd_device=nbd_device):
cmd = ['nbd-client', '-disconnect', nbd_device]
_call(cmd)
_wait_for_nbd_device(nbd_device=nbd_device, connected=False)
FILE_LOCK.unlock()


Expand Down

0 comments on commit 636eed1

Please sign in to comment.