Shahar Havivi has uploaded a new change for review. Change subject: virt-sparsify: add inplace virt-sparsify support ......................................................................
virt-sparsify: add inplace virt-sparsify support Change-Id: Ie0a1269d71816a8ab25c4a00bfb483620cfefde8 Signed-off-by: Shahar Havivi <shah...@redhat.com> --- M lib/api/vdsmapi-schema.json M lib/vdsm/Makefile.am M lib/vdsm/rpc/Bridge.py A lib/vdsm/virtsparsify.py M tests/Makefile.am A tests/sparsifyTests.py M vdsm.spec.in M vdsm/API.py 8 files changed, 154 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/27/54427/1 diff --git a/lib/api/vdsmapi-schema.json b/lib/api/vdsmapi-schema.json index a9f43ef..d09cf32 100644 --- a/lib/api/vdsmapi-schema.json +++ b/lib/api/vdsmapi-schema.json @@ -8276,7 +8276,6 @@ 'data': {'vmID': 'UUID', 'drive': 'DriveSpecVolume', 'baseVolUUID': 'UUID', 'topVolUUID': 'UUID', '*bandwidth': 'int', '*jobUUID': 'UUID'}} - ## Category: @Volume ########################################################## ## # @Volume: @@ -8713,6 +8712,25 @@ 'legality': 'VolumeLegality'}} ## +# @Volume.sparsifyInplace: +# +# Perform an in-place sparse (e.g. not creating a new image) on given volume +# +# @volumeID: The UUID of the Volume +# +# @storagepoolID: The UUID of the image that contains the volume +# +# @storagedomainID: The Storage Pool UUID associated with the Volume +# +# @imageID: The Storage Domain UUID associated with the Volume +# +# Since: 4.18.0 +## +{'command': {'class': 'Volume', 'name': 'sparsifyInplace'}, + 'data': {'volumeID': 'UUID', 'storagepoolID': 'UUID', + 'storagedomainID': 'UUID', 'imageID': 'UUID'}} + +## # @VmMemoryDeviceType: # # An enumeration of VM memory device types. @@ -8908,7 +8926,7 @@ # # This namespace is for SDM (storage domain manager) functions. # -# Since: 4.18 +# Since: 4.19 ## {'class': 'SDM'} diff --git a/lib/vdsm/Makefile.am b/lib/vdsm/Makefile.am index fb63dd3..69eb968 100644 --- a/lib/vdsm/Makefile.am +++ b/lib/vdsm/Makefile.am @@ -63,6 +63,7 @@ utils.py \ v2v.py \ vdscli.py \ + virtsparsify.py \ xmlrpc.py \ $(NULL) diff --git a/lib/vdsm/rpc/Bridge.py b/lib/vdsm/rpc/Bridge.py index ffd42f4..9f7b39b 100644 --- a/lib/vdsm/rpc/Bridge.py +++ b/lib/vdsm/rpc/Bridge.py @@ -502,6 +502,7 @@ 'Volume_getPath': {'ret': 'path'}, 'Volume_getSize': {'ret': Volume_getsize_Ret}, 'Volume_extendSize': {'ret': 'uuid'}, + 'Volume_sparsifyInplace': {}, 'Host_getAllTasks': {'ret': 'tasks'}, 'Host_getJobs': {'ret': 'jobs'}, } diff --git a/lib/vdsm/virtsparsify.py b/lib/vdsm/virtsparsify.py new file mode 100644 index 0000000..99452a5 --- /dev/null +++ b/lib/vdsm/virtsparsify.py @@ -0,0 +1,100 @@ +# +# Copyright 2016 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +from __future__ import absolute_import +from contextlib import contextmanager +import logging +import signal +from uuid import uuid4 + +from . import commands +from . import concurrent +from . import jobs +from . import utils +from . import response + +# Fedora, EL6 +_VIRTSPARSIFY = utils.CommandPath("virt-sparsify", + "/usr/bin/virt-sparsify",) + + +def inplace(sdUUID, spUUID, imgUUID, volUUID, irs): + """ + Sparsify the volume in place + (instead of copying from an input disk to an output disk) + """ + job = InplaceJob(volUUID, imgUUID, sdUUID, spUUID, irs) + job.start() + jobs.add(job) + + +def delete_inplace_job(job_id): + return jobs.delete(job_id) + + +def abort_inplace_job(job_id): + return jobs.abort(job_id) + + +@contextmanager +def volume(volUUID, imgUUID, sdUUID, spUUID, irs): + res = irs.prepareImage(sdUUID, spUUID, imgUUID, volUUID) + if response.is_error(res): + raise Exception('Cannot find volume path for %r' % volUUID) + try: + yield res['path'] + finally: + try: + irs.teardownImage(sdUUID, spUUID, imgUUID) + except Exception: + logging.exception('Error tearing down image: %r', imgUUID) + raise + + +class InplaceJob(jobs.Job): + def __init__(self, volUUID, imgUUID, sdUUID, spUUID, irs): + self._volUUID = volUUID + self._imgUUID = imgUUID + self._sdUUID = sdUUID + self._spUUID = spUUID + self._irs = irs + self._id = uuid4() + self._thread = None + + def start(self): + self._thread = concurrent.thread(self._run) + self._thread.start() + + def _run(self): + with volume(self._volUUID, self._imgUUID, self._sdUUID, + self._spUUID, self._irs) as path: + cmd = [_VIRTSPARSIFY.cmd, '--machine-readable', '--in-place', path] + logging.info('>>> cmd: %r', cmd) + rc, out, err = commands.execCmd(cmd, + deathSignal=signal.SIGTERM, + env={'LIBGUESTFS_BACKEND': + 'direct'}) + logging.info('>>> rc: %r', rc) + logging.info('>>> out: %r', out) + logging.info('>>> err: %r', err) + # self._proc = commands.execCmd(cmd, + # sync=False, + # deathSignal=signal.SIGTERM, + # env={'LIBGUESTFS_BACKEND': 'direct'}) diff --git a/tests/Makefile.am b/tests/Makefile.am index 903ed17..cc71074 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -108,6 +108,7 @@ sdm_indirection_tests.py \ securableTests.py \ sourceroutingTests.py \ + sparsifyTests.py \ sslTests.py \ stompAdapterTests.py \ stompAsyncClientTests.py \ diff --git a/tests/sparsifyTests.py b/tests/sparsifyTests.py new file mode 100644 index 0000000..81bf477 --- /dev/null +++ b/tests/sparsifyTests.py @@ -0,0 +1,25 @@ +# +# Copyright 2016 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# Refer to the README and COPYING files for full details of the license +# + +# from vdsm import cmdutils +# from vdsm import virtsparsify +# +# from monkeypatch import MonkeyPatch +# from testlib import VdsmTestCase as TestCaseBase diff --git a/vdsm.spec.in b/vdsm.spec.in index 5f9125f..b1873b8 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -1165,6 +1165,7 @@ %{python_sitelib}/%{vdsm_name}/utils.py* %{python_sitelib}/%{vdsm_name}/v2v.py* %{python_sitelib}/%{vdsm_name}/vdscli.py* +%{python_sitelib}/%{vdsm_name}/virtsparsify.py* %{python_sitelib}/%{vdsm_name}/xmlrpc.py* %{python_sitelib}/%{vdsm_name}/tool/__init__.py* %{python_sitelib}/%{vdsm_name}/tool/configfile.py* diff --git a/vdsm/API.py b/vdsm/API.py index 185a46c..359c24d 100644 --- a/vdsm/API.py +++ b/vdsm/API.py @@ -39,6 +39,7 @@ from vdsm import hooks from vdsm import hostdev from vdsm import response +from vdsm import virtsparsify from vdsm import supervdsm from vdsm import jobs from vdsm import v2v @@ -891,6 +892,10 @@ return self._irs.setVolumeLegality(self._sdUUID, self._spUUID, self._imgUUID, self._UUID, legality) + def sparsifyInplace(self): + return virtsparsify.inplace(self._sdUUID, self._spUUID, + self._imgUUID, self._UUID, self._irs) + class Image(APIBase): ctorArgs = ['imageID', 'storagepoolID', 'storagedomainID'] -- To view, visit https://gerrit.ovirt.org/54427 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie0a1269d71816a8ab25c4a00bfb483620cfefde8 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Shahar Havivi <shav...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches