-
Notifications
You must be signed in to change notification settings - Fork 3
refactor external snapshot using qemu-img #150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jbchan01
wants to merge
1
commit into
main
Choose a base branch
from
revert_qemu
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,9 +15,6 @@ func CreateExternalSnapshot(domain *domCon.Domain, name string, opts *ExternalSn | |
| return "", virerr.ErrorGen(virerr.InvalidParameter, fmt.Errorf("nil domain")) | ||
| } | ||
|
|
||
| active, err := domain.Domain.IsActive() | ||
| domainActive := err == nil && active | ||
|
|
||
| xmlDesc, err := domain.Domain.GetXMLDesc(0) | ||
| if err != nil { | ||
| return "", virerr.ErrorGen(virerr.SnapshotError, fmt.Errorf("failed to get domain xml: %w", err)) | ||
|
|
@@ -28,10 +25,10 @@ func CreateExternalSnapshot(domain *domCon.Domain, name string, opts *ExternalSn | |
| return "", virerr.ErrorGen(virerr.SnapshotError, fmt.Errorf("failed to resolve domain uuid: %w", err)) | ||
| } | ||
|
|
||
| return createExternalSnapshot(newExternalSnapshotDomain(domain.Domain), domainActive, domainUUID, xmlDesc, name, opts) | ||
| return createExternalSnapshot(newExternalSnapshotDomain(domain.Domain), newQemuImg(), domainUUID, xmlDesc, name, opts) | ||
| } | ||
|
|
||
| func createExternalSnapshot(domain SnapshotDomain, domainActive bool, domainUUID, xmlDesc, name string, opts *ExternalSnapshotOptions) (string, error) { | ||
| func createExternalSnapshot(domain SnapshotDomain, qimg QemuImg, domainUUID, xmlDesc, name string, opts *ExternalSnapshotOptions) (string, error) { | ||
| if domain == nil { | ||
| return "", virerr.ErrorGen(virerr.InvalidParameter, fmt.Errorf("nil domain")) | ||
| } | ||
|
|
@@ -61,17 +58,25 @@ func createExternalSnapshot(domain SnapshotDomain, domainActive bool, domainUUID | |
|
|
||
| snapDisks := make([]snapshotDisk, 0, len(disks)) | ||
| for _, d := range disks { | ||
| overlayPath := filepath.Join(snapshotDir, fmt.Sprintf("%s.qcow2", d.TargetDev)) | ||
|
|
||
| backingFormat := d.Driver | ||
| if backingFormat == "" { | ||
| backingFormat = "qcow2" | ||
| } | ||
| if err := qimg.Create(d.Source, backingFormat, overlayPath); err != nil { | ||
| return "", virerr.ErrorGen(virerr.SnapshotError, fmt.Errorf("failed to create overlay for disk %s: %w", d.TargetDev, err)) | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 서비스 함수 내부에서 데이터 검증, 파싱, 디렉토리 생성, qemu 이미지 생성, xml 생성 및 도메인 업데이트의 모든 로직이 많은 경우 직접호출로 진행되고 있는 것 같습니다. 실패시 롤백이나, 함수 수정, 테스트 작성이 쉽지 않을 것 같아요. |
||
| var driver *snapshotDriver | ||
| if d.Driver != "" { | ||
| driver = &snapshotDriver{Type: d.Driver} | ||
| } | ||
|
|
||
| snapshotFile := filepath.Join(snapshotDir, fmt.Sprintf("%s.qcow2", d.TargetDev)) | ||
| snapDisks = append(snapDisks, snapshotDisk{ | ||
| Name: d.TargetDev, | ||
| Snapshot: "external", | ||
| Driver: driver, | ||
| Source: &snapshotSource{File: snapshotFile}, | ||
| Source: &snapshotSource{File: overlayPath}, | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -91,23 +96,15 @@ func createExternalSnapshot(domain SnapshotDomain, domainActive bool, domainUUID | |
| return "", virerr.ErrorGen(virerr.SnapshotError, fmt.Errorf("failed to build snapshot xml: %w", err)) | ||
| } | ||
|
|
||
| live := opts != nil && opts.Live && domainActive | ||
|
|
||
| createOpts := externalSnapshotCreateExecOptions{ | ||
| Live: live, | ||
| Quiesce: opts != nil && opts.Quiesce, | ||
| Atomic: len(disks) > 1, | ||
| } | ||
|
|
||
| snap, err := domain.CreateExternalSnapshot(string(snapBytes), createOpts) | ||
| snap, err := domain.RegisterExternalSnapshot(string(snapBytes)) | ||
| if err != nil { | ||
| return "", virerr.ErrorGen(virerr.SnapshotError, fmt.Errorf("failed to create external snapshot: %w", err)) | ||
| return "", virerr.ErrorGen(virerr.SnapshotError, fmt.Errorf("failed to register external snapshot: %w", err)) | ||
| } | ||
| defer snap.Free() | ||
|
|
||
| snapName, err := snap.Name() | ||
| if err != nil { | ||
| return "", virerr.ErrorGen(virerr.SnapshotError, fmt.Errorf("snapshot created but failed to read name: %w", err)) | ||
| return "", virerr.ErrorGen(virerr.SnapshotError, fmt.Errorf("snapshot registered but failed to read name: %w", err)) | ||
| } | ||
|
|
||
| return snapName, nil | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CreateExternalSnapshot 에서 데이터를 검증하는 부분에 중복이 있는 것 같습니다.
이름,도메인 검증등
또한 지금은 Create(외부) 와 create(내부)가 강하게 엮여있어서 함수를 분리하는 것이 괜찮을까 생각이듭니다 :)
검증(외부) -> 생성(내부) 처럼 역할을 분리시키면 유지하기 쉬워질거 같아요
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
검증용 함수를 따로 구현해 분리시키도록 하겠습니다.