Tony Asleson
2014-08-26 21:38:01 UTC
Ensure we get an IS_MASKED error if we try to delete a volume
that is masked against an access group.
Tested against sim & simc
Signed-off-by: Tony Asleson <***@redhat.com>
---
plugin/simc/simc_lsmplugin.c | 27 +++++++++++++++++++++++++--
test/plugin_test.py | 18 +++++++++++++++++-
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 618613b..b263adb 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -332,6 +332,11 @@ static int vol_accessible_by_ag(lsm_plugin_ptr c,
lsm_volume **volumes[],
uint32_t *count, lsm_flag flags);
+static int ag_granted_to_volume( lsm_plugin_ptr c,
+ lsm_volume *volume,
+ lsm_access_group **groups[],
+ uint32_t *count, lsm_flag flags);
+
static int cap(lsm_plugin_ptr c, lsm_system *system,
lsm_storage_capabilities **cap, lsm_flag flags)
{
@@ -923,11 +928,29 @@ static int _volume_delete(lsm_plugin_ptr c, const char *volume_id)
static int volume_delete(lsm_plugin_ptr c, lsm_volume *volume,
char **job, lsm_flag flags)
{
+ lsm_access_group **groups = NULL;
+ uint32_t count = 0;
+
struct plugin_data *pd = (struct plugin_data*)lsm_private_data_get(c);
- int rc = _volume_delete(c, lsm_volume_id_get(volume));
+
+ // Check to see if this volume is masked to any access groups, if it is we
+ // will return an IS_MASKED error code.
+ int rc = ag_granted_to_volume(c, volume, &groups, &count, LSM_FLAG_RSVD);
if( LSM_ERR_OK == rc ) {
- rc = create_job(pd, job, LSM_DATA_TYPE_NONE, NULL, NULL);
+ lsm_access_group_record_array_free(groups, count);
+ groups = NULL;
+
+ if( !count ) {
+
+ rc = _volume_delete(c, lsm_volume_id_get(volume));
+
+ if( LSM_ERR_OK == rc ) {
+ rc = create_job(pd, job, LSM_DATA_TYPE_NONE, NULL, NULL);
+ }
+ } else {
+ rc = lsm_log_error_basic(c, LSM_ERR_IS_MASKED, "Volume is masked!");
+ }
}
return rc;
}
diff --git a/test/plugin_test.py b/test/plugin_test.py
index 10d0c26..042835a 100755
--- a/test/plugin_test.py
+++ b/test/plugin_test.py
@@ -914,7 +914,7 @@ class TestPlugin(unittest.TestCase):
self._delete_access_group(ag_created)
- def test_ag_delete_with_vol_masked(self):
+ def test_ag_vol_delete_with_vol_masked(self):
for s in self.systems:
cap = self.c.capabilities(s)
if supported(cap, [lsm.Capabilities.ACCESS_GROUPS,
@@ -945,6 +945,8 @@ class TestPlugin(unittest.TestCase):
got_exception = False
self.c.volume_mask(ag, vol)
+ # Try to delete the access group
+
try:
self.c.access_group_delete(ag)
except LsmError as le:
@@ -954,6 +956,20 @@ class TestPlugin(unittest.TestCase):
lsm.ErrorNumber.IS_MASKED)
self.assertTrue(got_exception)
+
+ # Try to delete the volume
+ got_exception = False
+ try:
+ self.c.volume_delete(vol)
+ except LsmError as le:
+ if le.code == lsm.ErrorNumber.IS_MASKED:
+ got_exception = True
+ self.assertTrue(le.code ==
+ lsm.ErrorNumber.IS_MASKED)
+
+ self.assertTrue(got_exception)
+
+ # Clean up
self.c.volume_unmask(ag, vol)
self.c.volume_delete(vol)
that is masked against an access group.
Tested against sim & simc
Signed-off-by: Tony Asleson <***@redhat.com>
---
plugin/simc/simc_lsmplugin.c | 27 +++++++++++++++++++++++++--
test/plugin_test.py | 18 +++++++++++++++++-
2 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/plugin/simc/simc_lsmplugin.c b/plugin/simc/simc_lsmplugin.c
index 618613b..b263adb 100644
--- a/plugin/simc/simc_lsmplugin.c
+++ b/plugin/simc/simc_lsmplugin.c
@@ -332,6 +332,11 @@ static int vol_accessible_by_ag(lsm_plugin_ptr c,
lsm_volume **volumes[],
uint32_t *count, lsm_flag flags);
+static int ag_granted_to_volume( lsm_plugin_ptr c,
+ lsm_volume *volume,
+ lsm_access_group **groups[],
+ uint32_t *count, lsm_flag flags);
+
static int cap(lsm_plugin_ptr c, lsm_system *system,
lsm_storage_capabilities **cap, lsm_flag flags)
{
@@ -923,11 +928,29 @@ static int _volume_delete(lsm_plugin_ptr c, const char *volume_id)
static int volume_delete(lsm_plugin_ptr c, lsm_volume *volume,
char **job, lsm_flag flags)
{
+ lsm_access_group **groups = NULL;
+ uint32_t count = 0;
+
struct plugin_data *pd = (struct plugin_data*)lsm_private_data_get(c);
- int rc = _volume_delete(c, lsm_volume_id_get(volume));
+
+ // Check to see if this volume is masked to any access groups, if it is we
+ // will return an IS_MASKED error code.
+ int rc = ag_granted_to_volume(c, volume, &groups, &count, LSM_FLAG_RSVD);
if( LSM_ERR_OK == rc ) {
- rc = create_job(pd, job, LSM_DATA_TYPE_NONE, NULL, NULL);
+ lsm_access_group_record_array_free(groups, count);
+ groups = NULL;
+
+ if( !count ) {
+
+ rc = _volume_delete(c, lsm_volume_id_get(volume));
+
+ if( LSM_ERR_OK == rc ) {
+ rc = create_job(pd, job, LSM_DATA_TYPE_NONE, NULL, NULL);
+ }
+ } else {
+ rc = lsm_log_error_basic(c, LSM_ERR_IS_MASKED, "Volume is masked!");
+ }
}
return rc;
}
diff --git a/test/plugin_test.py b/test/plugin_test.py
index 10d0c26..042835a 100755
--- a/test/plugin_test.py
+++ b/test/plugin_test.py
@@ -914,7 +914,7 @@ class TestPlugin(unittest.TestCase):
self._delete_access_group(ag_created)
- def test_ag_delete_with_vol_masked(self):
+ def test_ag_vol_delete_with_vol_masked(self):
for s in self.systems:
cap = self.c.capabilities(s)
if supported(cap, [lsm.Capabilities.ACCESS_GROUPS,
@@ -945,6 +945,8 @@ class TestPlugin(unittest.TestCase):
got_exception = False
self.c.volume_mask(ag, vol)
+ # Try to delete the access group
+
try:
self.c.access_group_delete(ag)
except LsmError as le:
@@ -954,6 +956,20 @@ class TestPlugin(unittest.TestCase):
lsm.ErrorNumber.IS_MASKED)
self.assertTrue(got_exception)
+
+ # Try to delete the volume
+ got_exception = False
+ try:
+ self.c.volume_delete(vol)
+ except LsmError as le:
+ if le.code == lsm.ErrorNumber.IS_MASKED:
+ got_exception = True
+ self.assertTrue(le.code ==
+ lsm.ErrorNumber.IS_MASKED)
+
+ self.assertTrue(got_exception)
+
+ # Clean up
self.c.volume_unmask(ag, vol)
self.c.volume_delete(vol)
--
1.8.2.1
1.8.2.1