Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list_bitmaps command #393

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/vdsm/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,9 @@ def remove_bitmap(self, job_id, vol_info, bitmap):
def clear_bitmaps(self, job_id, vol_info):
return self._irs.sdm_clear_bitmaps(job_id, vol_info)

def list_bitmaps(self, job_id, vol_info):
return self._irs.sdm_list_bitmaps(job_id, vol_info)


class Lease(APIBase):
ctorArgs = []
Expand Down
20 changes: 20 additions & 0 deletions lib/vdsm/api/vdsm-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7478,6 +7478,13 @@ types:
type: boolean
added: '4.5'

- defaultvalue: false
description: Indicates whether listing volume bitmaps
is implemented in VDSM
name: list_bitmaps
type: boolean
added: '4.5.5'

type: object

VdsmNetworkCapabilities: &VdsmNetworkCapabilities
Expand Down Expand Up @@ -12606,6 +12613,19 @@ SDM.clear_bitmaps:
name: vol_info
type: *CopyDataDIVEndpoint

SDM.list_bitmaps:
added: '4.5.5'
description: List all the bitmaps from the volume.
Allowed only for a volume with qcow2 format.
params:
- description: A UUID to be used for tracking the job progress
name: job_id
type: *UUID

- description: The volume to list the bitmap from.
name: vol_info
type: *CopyDataDIVEndpoint

NBD.start_server:
added: '4.3'
description: Start serving a volume using NBD protocol. Fail if the service
Expand Down
1 change: 1 addition & 0 deletions lib/vdsm/host/caps.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def get():
caps['measure_active'] = True
caps['mailbox_events'] = config.getboolean("mailbox", "events_enable")
caps['zerocopy_migrations'] = hasattr(libvirt, 'VIR_MIGRATE_ZEROCOPY')
caps['list_bitmaps'] = True

return caps

Expand Down
11 changes: 11 additions & 0 deletions lib/vdsm/storage/bitmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@ def clear_bitmaps(vol_path):
vol_path=vol_path)


def list_bitmaps(vol_path):
"""
List bitmaps to the given volume path

Arguments:
vol_path (str): Path to the volume
"""
bitmaps = _query_bitmaps(vol_path)
return bitmaps


def _add_bitmap(vol_path, bitmap, granularity=None, enable=True):
log.info("Add bitmap %s to %r", bitmap, vol_path)

Expand Down
15 changes: 15 additions & 0 deletions lib/vdsm/storage/hsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
add_bitmap,
copy_data,
clear_bitmaps,
list_bitmaps,
merge as api_merge,
move_device,
reduce_domain,
Expand Down Expand Up @@ -3492,6 +3493,20 @@ def sdm_clear_bitmaps(self, job_id, vol_info):
job = clear_bitmaps.Job(job_id, self._pool.id, vol_info)
self.sdm_schedule(job)

@public
def sdm_list_bitmaps(self, job_id, vol_info):
"""
List all the bitmaps from the given volume.

Arguments:
job_id (str): The UUID of the job.
vol_info (dict): Dictionary that contains all the needed info
on the volume.
"""
job = list_bitmaps.Job(job_id, self._pool.id, vol_info)
self.sdm_schedule(job)
return dict(uuidlist=bitmaps)

# Lease operations

@public
Expand Down
1 change: 1 addition & 0 deletions lib/vdsm/storage/sdm/api/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dist_vdsmsdmapi_PYTHON = \
base.py \
copy_data.py \
clear_bitmaps.py \
list_bitmaps.py \
merge.py \
move_device.py \
reduce_domain.py \
Expand Down
35 changes: 35 additions & 0 deletions lib/vdsm/storage/sdm/api/list_bitmaps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# SPDX-FileCopyrightText: Red Hat, Inc.
# SPDX-License-Identifier: GPL-2.0-or-later

from vdsm.storage import bitmaps
from vdsm.storage import constants as sc
from vdsm.storage import exception as se
from vdsm.storage import guarded
from vdsm.storage.sdm.volume_info import VolumeInfo

from . import base


class Job(base.Job):

def __init__(self, job_id, host_id, vol_info):
super(Job, self).__init__(job_id, 'list_bitmaps', host_id)
self._vol_info = VolumeInfo(vol_info, host_id)
self._bitmaps = None

def _validate(self):
if self._vol_info.volume.getFormat() != sc.COW_FORMAT:
raise se.UnsupportedOperation(
"Volume is not in COW format",
vol_uuid=self._vol_info.vol_id)

def _run(self):
with guarded.context(self._vol_info.locks):
self._validate()
with self._vol_info.prepare():
with self._vol_info.volume_operation():
self._bitmaps = bitmaps.list_bitmaps(self._vol_info.path)

@property
def bitmaps(self):
return self._bitmaps
23 changes: 23 additions & 0 deletions tests/storage/bitmaps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,26 @@ def test_clear_bitmaps_failed(monkeypatch, tmp_mount, vol_chain):
monkeypatch.setattr(qemuimg, "bitmap_remove", qemuimg_failure)
with pytest.raises(exception.RemoveBitmapError):
bitmaps.clear_bitmaps(vol_chain.top_vol)


def test_list_bitmaps(tmp_mount, vol_chain):
# Add new bitmaps to top volume
for bitmap in ['bitmap_1', 'bitmap_2']:
op = qemuimg.bitmap_add(vol_chain.top_vol, bitmap)
op.run()

uuids = bitmaps.list_bitmaps(vol_chain.top_vol)
assert uuids == ['bitmap_1', 'bitmap_2']


def test_list_bitmaps_empty(tmp_mount, vol_chain):
# Add new bitmaps to top volume
for bitmap in ['bitmap_1', 'bitmap_2']:
op = qemuimg.bitmap_add(vol_chain.top_vol, bitmap)
op.run()

# Clear top volume bitmaps
bitmaps.clear_bitmaps(vol_chain.top_vol)

uuids = bitmaps.list_bitmaps(vol_chain.top_vol)
assert uuids == []
2 changes: 1 addition & 1 deletion tests/storage/sdm_clear_bitmaps_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from vdsm.storage import guarded
from vdsm.storage import qemuimg
from vdsm.storage.sdm import volume_info
from vdsm.storage.sdm.api import clear_bitmaps
from vdsm.storage.sdm.api import clear_bitmaps, list_bitmaps


def failure(*args, **kwargs):
Expand Down