diff --git a/doc/source/admin/share_back_ends_feature_support_mapping.rst b/doc/source/admin/share_back_ends_feature_support_mapping.rst index d8130f52fb..306e273620 100644 --- a/doc/source/admin/share_back_ends_feature_support_mapping.rst +++ b/doc/source/admin/share_back_ends_feature_support_mapping.rst @@ -30,69 +30,69 @@ Column value "-" means that this feature is not currently supported. Mapping of share drivers and share features support --------------------------------------------------- -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Driver name | create delete share | manage unmanage share | extend share | shrink share | create delete snapshot | create share from snapshot | manage unmanage snapshot | revert to snapshot | mountable snapshot | -+========================================+=======================+=======================+==============+==============+========================+============================+==========================+====================+====================+ -| ZFSonLinux | M | N | M | M | M | M | N | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Container | N | \- | N | \- | \- | \- | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Generic (Cinder as back-end) | J | K | L | L | J | J | M | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| NetApp Clustered Data ONTAP | J | L | L | L | J | J | N | O | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| EMC VMAX | O | \- | O | \- | O | O | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| EMC VNX | J | \- | \- | \- | J | J | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| EMC Unity | N | \- | N | S | N | N | \- | S | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| EMC Isilon | K | \- | M | \- | K | K | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| GlusterFS | J | \- | \- | \- | volume layout (L) | volume layout (L) | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| GlusterFS-Native | J | \- | \- | \- | K | L | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| HDFS | K | \- | M | \- | K | K | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Hitachi HNAS | L | L | L | M | L | L | O | O | O | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Hitachi HSP | N | N | N | N | \- | \- | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| HPE 3PAR | K | \- | \- | \- | K | K | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Huawei | K | L | L | L | K | M | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| IBM GPFS | K | O | L | \- | K | K | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| INFINIDAT | Q | \- | Q | \- | Q | Q | \- | Q | Q | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| INSPUR AS13000 | R | \- | R | \- | R | R | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| INSPUR InStorage | T | \- | T | \- | \- | \- | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Infortrend | T | T | T | T | \- | \- | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| LVM | M | \- | M | \- | M | M | \- | O | O | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Quobyte | K | \- | M | M | \- | \- | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Windows SMB | L | L | L | L | L | L | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Oracle ZFSSA | K | N | M | M | K | K | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| CephFS | M | \- | M | M | M | \- | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| Tegile | M | \- | M | M | M | M | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| NexentaStor4 | N | \- | N | \- | N | N | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| NexentaStor5 | N | \- | N | N | N | N | \- | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| MapRFS | O | O | O | O | O | O | O | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ -| QNAP | O | O | O | \- | O | O | O | \- | \- | -+----------------------------------------+-----------------------+-----------------------+--------------+--------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Driver name | create delete share | manage unmanage share | extend share | shrink share | create delete snapshot | create share from snapshot | manage unmanage snapshot | revert to snapshot | mountable snapshot | ++========================================+=======================+=======================+==========================+==========================+========================+============================+==========================+====================+====================+ +| ZFSonLinux | M | N | M | M | M | M | N | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Container | N | \- | N | \- | \- | \- | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Generic (Cinder as back-end) | J | K | L | L | J | J | M | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| NetApp Clustered Data ONTAP | J | L | L | L | J | J | N | O | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| EMC VMAX | O | \- | O | \- | O | O | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| EMC VNX | J | \- | \- | \- | J | J | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| EMC Unity | N | \- | N | S | N | N | \- | S | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| EMC Isilon | K | \- | M | \- | K | K | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| GlusterFS | J | \- | directory layout (T) | directory layout (T) | volume layout (L) | volume layout (L) | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| GlusterFS-Native | J | \- | \- | \- | K | L | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| HDFS | K | \- | M | \- | K | K | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Hitachi HNAS | L | L | L | M | L | L | O | O | O | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Hitachi HSP | N | N | N | N | \- | \- | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| HPE 3PAR | K | \- | \- | \- | K | K | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Huawei | K | L | L | L | K | M | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| IBM GPFS | K | O | L | \- | K | K | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| INFINIDAT | Q | \- | Q | \- | Q | Q | \- | Q | Q | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| INSPUR AS13000 | R | \- | R | \- | R | R | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| INSPUR InStorage | T | \- | T | \- | \- | \- | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Infortrend | T | T | T | T | \- | \- | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| LVM | M | \- | M | \- | M | M | \- | O | O | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Quobyte | K | \- | M | M | \- | \- | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Windows SMB | L | L | L | L | L | L | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Oracle ZFSSA | K | N | M | M | K | K | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| CephFS | M | \- | M | M | M | \- | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| Tegile | M | \- | M | M | M | M | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| NexentaStor4 | N | \- | N | \- | N | N | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| NexentaStor5 | N | \- | N | N | N | N | \- | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| MapRFS | O | O | O | O | O | O | O | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ +| QNAP | O | O | O | \- | O | O | O | \- | \- | ++----------------------------------------+-----------------------+-----------------------+--------------------------+--------------------------+------------------------+----------------------------+--------------------------+--------------------+--------------------+ Mapping of share drivers and share access rules support ------------------------------------------------------- diff --git a/manila/share/drivers/glusterfs/layout_directory.py b/manila/share/drivers/glusterfs/layout_directory.py index 75725fe2ab..19bfc5b1ff 100644 --- a/manila/share/drivers/glusterfs/layout_directory.py +++ b/manila/share/drivers/glusterfs/layout_directory.py @@ -15,16 +15,19 @@ """GlusterFS directory mapped share layout.""" +import math import os from oslo_config import cfg from oslo_log import log import six +import xml.etree.cElementTree as etree from manila import exception from manila.i18n import _ from manila.share.drivers.glusterfs import common from manila.share.drivers.glusterfs import layout +from manila import utils LOG = log.getLogger(__name__) @@ -137,16 +140,12 @@ class GlusterfsDirectoryMappedLayout(layout.GlusterfsShareLayoutBase): """Create a sub-directory/share in the GlusterFS volume.""" # probe into getting a NAS protocol helper for the share in order # to facilitate early detection of unsupported protocol type - sizestr = six.text_type(share['size']) + 'GB' - share_dir = '/' + share['name'] local_share_path = self._get_local_share_path(share) cmd = ['mkdir', local_share_path] - # set hard limit quota on the sub-directory/share - args = ('volume', 'quota', self.gluster_manager.volume, - 'limit-usage', share_dir, sizestr) + try: self.driver._execute(*cmd, run_as_root=True) - self.gluster_manager.gluster_call(*args) + self._set_directory_quota(share, share['size']) except Exception as exc: if isinstance(exc, exception.ProcessExecutionError): exc = exception.GlusterfsException(exc) @@ -205,7 +204,46 @@ class GlusterfsDirectoryMappedLayout(layout.GlusterfsShareLayoutBase): raise NotImplementedError def extend_share(self, share, new_size, share_server=None): - raise NotImplementedError + """Extend a sub-directory/share in the GlusterFS volume.""" + self._set_directory_quota(share, new_size) def shrink_share(self, share, new_size, share_server=None): - raise NotImplementedError + """Shrink a sub-directory/share in the GlusterFS volume.""" + usage = self._get_directory_usage(share) + consumed_limit = int(math.ceil(usage)) + if consumed_limit > new_size: + raise exception.ShareShrinkingPossibleDataLoss( + share_id=share['id']) + + self._set_directory_quota(share, new_size) + + def _set_directory_quota(self, share, new_size): + sizestr = six.text_type(new_size) + 'GB' + share_dir = '/' + share['name'] + + args = ('volume', 'quota', self.gluster_manager.volume, + 'limit-usage', share_dir, sizestr) + + try: + self.gluster_manager.gluster_call(*args) + except exception.GlusterfsException: + LOG.error('Unable to set quota share %s', share['name']) + raise + + def _get_directory_usage(self, share): + share_dir = '/' + share['name'] + + args = ('--xml', 'volume', 'quota', self.gluster_manager.volume, + 'list', share_dir) + + try: + out, err = self.gluster_manager.gluster_call(*args) + except exception.GlusterfsException: + LOG.error('Unable to get quota share %s', share['name']) + raise + + volxml = etree.fromstring(out) + usage_byte = volxml.find('./volQuota/limit/used_space').text + usage = utils.translate_string_size_to_float(usage_byte) + + return usage diff --git a/manila/tests/share/drivers/glusterfs/test_layout_directory.py b/manila/tests/share/drivers/glusterfs/test_layout_directory.py index 5fa6cb610b..f4a942b575 100644 --- a/manila/tests/share/drivers/glusterfs/test_layout_directory.py +++ b/manila/tests/share/drivers/glusterfs/test_layout_directory.py @@ -378,15 +378,91 @@ class GlusterfsDirectoryMappedLayoutTestCase(test.TestCase): def test_ensure_share(self): self.assertIsNone(self._layout.ensure_share(self._context, self.share)) + def test_extend_share(self): + self._layout.extend_share(self.share, 3) + + self._layout.gluster_manager.gluster_call.assert_called_once_with( + 'volume', 'quota', 'testvol', 'limit-usage', '/fakename', '3GB') + + def test_shrink_share(self): + self.mock_object(self._layout, '_get_directory_usage', + mock.Mock(return_value=10.0)) + + self._layout.shrink_share(self.share, 11) + self._layout.gluster_manager.gluster_call.assert_called_once_with( + 'volume', 'quota', 'testvol', 'limit-usage', '/fakename', '11GB') + + def test_shrink_share_data_loss(self): + self.mock_object(self._layout, '_get_directory_usage', + mock.Mock(return_value=10.0)) + shrink_on_gluster = self.mock_object(self._layout, + '_set_directory_quota') + + self.assertRaises(exception.ShareShrinkingPossibleDataLoss, + self._layout.shrink_share, self.share, 9) + shrink_on_gluster.assert_not_called() + + def test_set_directory_quota(self): + self._layout._set_directory_quota(self.share, 3) + + self._layout.gluster_manager.gluster_call.assert_called_once_with( + 'volume', 'quota', 'testvol', 'limit-usage', '/fakename', '3GB') + + def test_set_directory_quota_unable_to_set(self): + self.mock_object(self._layout.gluster_manager, 'gluster_call', + mock.Mock(side_effect=exception.GlusterfsException)) + + self.assertRaises(exception.GlusterfsException, + self._layout._set_directory_quota, self.share, 3) + + self._layout.gluster_manager.gluster_call.assert_called_once_with( + 'volume', 'quota', 'testvol', 'limit-usage', '/fakename', '3GB') + + def test_get_directory_usage(self): + + def xml_output(*ignore_args, **ignore_kwargs): + return """ + + 0 + 0 + + + + 10737418240 + + +""", '' + + self.mock_object(self._layout.gluster_manager, 'gluster_call', + mock.Mock(side_effect=xml_output)) + + ret = self._layout._get_directory_usage(self.share) + + self.assertEqual(10.0, ret) + share_dir = '/' + self.share['name'] + self._layout.gluster_manager.gluster_call.assert_called_once_with( + '--xml', 'volume', 'quota', self._layout.gluster_manager.volume, + 'list', share_dir) + + def test_get_directory_usage_unable_to_get(self): + self.mock_object(self._layout.gluster_manager, 'gluster_call', + mock.Mock(side_effect=exception.GlusterfsException)) + + self.assertRaises(exception.GlusterfsException, + self._layout._get_directory_usage, self.share) + + share_dir = '/' + self.share['name'] + self._layout.gluster_manager.gluster_call.assert_called_once_with( + '--xml', 'volume', 'quota', self._layout.gluster_manager.volume, + 'list', share_dir) + @ddt.data( ('create_share_from_snapshot', ('context', 'share', 'snapshot'), {'share_server': None}), ('create_snapshot', ('context', 'snapshot'), {'share_server': None}), ('delete_snapshot', ('context', 'snapshot'), {'share_server': None}), ('manage_existing', ('share', 'driver_options'), {}), - ('unmanage', ('share',), {}), - ('extend_share', ('share', 'new_size'), {'share_server': None}), - ('shrink_share', ('share', 'new_size'), {'share_server': None})) + ('unmanage', ('share',), {})) def test_nonimplemented_methods(self, method_invocation): method, args, kwargs = method_invocation self.assertRaises(NotImplementedError, getattr(self._layout, method), diff --git a/releasenotes/notes/glusterfs-add-directory-layout-extend-shrink-fd2a008f152edbf5.yaml b/releasenotes/notes/glusterfs-add-directory-layout-extend-shrink-fd2a008f152edbf5.yaml new file mode 100644 index 0000000000..283688e0bf --- /dev/null +++ b/releasenotes/notes/glusterfs-add-directory-layout-extend-shrink-fd2a008f152edbf5.yaml @@ -0,0 +1,3 @@ +--- +features: + - For glusterfs_nfs driver, added share extend/shrink support.