Skip to content

Commit a86786c

Browse files
committed
fix(linstorvolumemanager): don't allow InUse volumes to be deleted
Check for usage status before deleting a linstor volume and raise an appropriate error if this happens Signed-off-by: Antoine Bartuccio <[email protected]>
1 parent de309bc commit a86786c

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

drivers/linstorvolumemanager.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
#
1717

18-
from sm_typing import override
18+
from sm_typing import Dict, override
1919

2020
import errno
2121
import json
@@ -682,9 +682,28 @@ def destroy_volume(self, volume_uuid):
682682
Destroy a volume.
683683
:param str volume_uuid: The volume uuid to destroy.
684684
"""
685+
def get_volume_info(volume_uuid: str) -> Dict:
686+
for volume in self.get_resources_info().values():
687+
if volume["uuid"] == volume_uuid:
688+
return volume
689+
raise LinstorVolumeManagerError(
690+
f"Could not find info about volume `{volume_uuid}`",
691+
LinstorVolumeManagerError.ERR_VOLUME_DESTROY
692+
)
693+
694+
def is_volume_in_use(volume_info: Dict) -> bool:
695+
for node in volume_info["nodes"].values():
696+
if node["in-use"]:
697+
return True
698+
return False
685699

686700
self._ensure_volume_exists(volume_uuid)
687701
self.ensure_volume_is_not_locked(volume_uuid)
702+
if is_volume_in_use(get_volume_info(volume_uuid)):
703+
raise LinstorVolumeManagerError(
704+
f"Could not destroy volume `{volume_uuid}` as it is currently in use",
705+
LinstorVolumeManagerError.ERR_VOLUME_DESTROY
706+
)
688707

689708
# Mark volume as destroyed.
690709
volume_properties = self._get_volume_properties(volume_uuid)

0 commit comments

Comments
 (0)