Skip to content

Commit 8c8f619

Browse files
author
gitlab
committed
Merge branch 'check-ceph-snap-revert' into '5.1.0'
<fix>[cephprimarystorage]: check cap before revert snap See merge request zstackio/zstack-utility!4656
2 parents da52de7 + 7dd5cb1 commit 8c8f619

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

cephprimarystorage/cephprimarystorage/cephagent.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, success=True, error=None):
6767
self.error = error if error else ''
6868
self.totalCapacity = None
6969
self.availableCapacity = None
70-
self.poolCapacities = None
70+
self.poolCapacities = None # type: list[CephPoolCapacity]
7171
self.type = None
7272

7373
def set_err(self, err):
@@ -765,13 +765,27 @@ def delete_pool(self, req):
765765
def rollback_snapshot(self, req):
766766
cmd = jsonobject.loads(req[http.REQUEST_BODY])
767767
spath = self._normalize_install_path(cmd.snapshotPath)
768+
rsp = RollbackSnapshotRsp()
769+
self._set_capacity_to_response(rsp)
770+
771+
self.validate_snapshot_rollback(spath, rsp)
772+
768773
driver = self.get_driver(cmd)
769774
driver.rollback_snapshot(cmd)
770-
rsp = RollbackSnapshotRsp()
771775
rsp.size = self._get_file_size(spath)
772-
self._set_capacity_to_response(rsp)
773776
return jsonobject.dumps(rsp)
774777

778+
def validate_snapshot_rollback(self, spath, rsp):
779+
asize = self._get_file_actual_size(spath)
780+
if asize is None:
781+
return
782+
783+
pool_name = spath.split("/")[0]
784+
if pool_name in rsp.poolCapacities:
785+
cap = rsp.poolCapacities[pool_name]
786+
if cap.usedCapacity + asize > cap.totalCapacity * 0.9:
787+
raise Exception("In the worst case, The rollback operation will exceed the 90%% capacity of the pool[%s]" % pool_name)
788+
775789
@staticmethod
776790
def _wrap_shareable_cmd(cmd, cmd_string):
777791
if cmd.shareable:

0 commit comments

Comments
 (0)