Skip to content

Commit 3b08300

Browse files
author
gitlab
committed
Merge branch '5.1.0@@2' into '5.1.0'
<fix>[cephbackupstorage]: detect image format after upload completed See merge request zstackio/zstack-utility!4664
2 parents 7f0efc2 + 1fa24d2 commit 3b08300

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

cephbackupstorage/cephbackupstorage/cephagent.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,13 @@ def get_boundary(entity):
315315
return ib
316316

317317

318+
def get_image_format_from_header(ioctx, image_name):
319+
qcow2_length = 0x9007
320+
ifo = ImageFileObject(rbd.Image(ioctx, image_name))
321+
buf = ifo.read(qcow2_length)
322+
return get_image_format_from_buf(buf)
323+
324+
318325
def get_image_format_from_buf(qhdr):
319326
if qhdr[:4] == 'QFI\xfb':
320327
if qhdr[16:20] == '\x00\x00\x00\00':
@@ -396,7 +403,7 @@ def stream_body(entity, boundary, param, task, ioctx):
396403
(param.image_uuid, param.slice_index, param.slice_offset, param.slice_size))
397404

398405

399-
def complete_upload(task):
406+
def complete_upload(task, ioctx):
400407
# type: (UploadTask) -> None
401408
try:
402409
file_format = linux.get_img_fmt('rbd:' + task.tmpPath)
@@ -433,6 +440,9 @@ def complete_upload(task):
433440

434441
if task.lastError:
435442
raise Exception(task.lastError)
443+
444+
_, img_name = task.dstPath.split('/')
445+
task.image_format = get_image_format_from_header(ioctx, img_name)
436446
task.success()
437447

438448

@@ -806,7 +816,10 @@ def upload(self, req):
806816
self.upload_slice(req.body, upload_param, task)
807817

808818
if task.allow_image_completing():
809-
complete_upload(task)
819+
pool, img_name = task.dstPath.split('/')
820+
ioctx = self.get_ioctx(pool)
821+
complete_upload(task, ioctx)
822+
810823

811824
@staticmethod
812825
def get_upload_param(req_header):

0 commit comments

Comments
 (0)