Skip to content

Snapshot update#116

Merged
kwonkwonn merged 4 commits intomainfrom
snapshot_update
Mar 27, 2026
Merged

Snapshot update#116
kwonkwonn merged 4 commits intomainfrom
snapshot_update

Conversation

@Jbchan01
Copy link
Copy Markdown
Contributor

@Jbchan01 Jbchan01 commented Mar 17, 2026

Type of Change

  • Bug fix
  • New feature
  • Refactor / tech debt
  • Docs / test

Summary

merge 기능이 추가되었습니다. 종속성 문제가 있긴 한데, revert 기능과 종속성 문제가 다소 있어 보여서 해결해야 하긴 합니다.

Related Issue

Closes #

Test Plan

  • make test passes
  • Manually verified on libvirt environment

@Jbchan01 Jbchan01 marked this pull request as ready for review March 27, 2026 06:38
@Jbchan01
Copy link
Copy Markdown
Contributor Author

우선적으로 각 코드 분리를 해두었습니다.

Copy link
Copy Markdown
Contributor

@kwonkwonn kwonkwonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전반적으로 구조는 아주 좋은 거 같아요.
이 방식으로 PoC 진행하고, 공통 로직을 분리하는 식으로 진행해도 좋을 것 같습니다.


// waitBlockJobReady waits until a block commit job has copied all data and is
// ready for pivot.
func waitBlockJobReady(domain *libvirt.Domain, disk string, timeout time.Duration) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

서비스에서 libvirt.Domain 필연적인 경우가 아니라면 interface 로 감춰주세요

job, err := domain.GetBlockJobInfo(disk, 0)
if err != nil {
if time.Now().After(deadline) {
return fmt.Errorf("timeout waiting for block job on disk %s: %w", disk, err)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

에러 반환 컨밴션 확인해주세요
VirError 로 합성해야 될거 같아요

// - source: The source file path to use for the disk
//
// Returns the XML string for the disk device.
func buildDiskDeviceXML(info diskInfo, source string) string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devicedefiner 에서 쓰는걸 추천하지만, 아직 완성된 패키지가 아니라서 염두만 해주세요

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

바이너리가 붙어있네요


func ListSnapshots(domain *domCon.Domain) ([]string, error) {
if domain == nil || domain.Domain == nil {
return nil, virerr.ErrorGen(virerr.InvalidParameter, fmt.Errorf("nil domain"))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지금 이 방식대로 다른 에러에서도 적용해주세용
virtError 로 특정하기 어려운 깊이<- return error
virtError 로 특정할 수 있는 시작점 <-- ErrorGen
상위레이어로 갈때 ErrorJoin <-- 으로 생각해주시면 됩니다

}

var listFlags libvirt.DomainSnapshotListFlags
snaps, err := domain.Domain.ListAllSnapshots(listFlags)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

libvirt 패키지에서 호출하는 함수를 기반으로 interface 정의하고 받아주는게 좋을 거 같아요
e.g,

type Domain interface{
	ListAllstanpshots(listFlags) (snaps, error)
}

이렇게 두고 함수 호출시점에 domcon,Domain을 넣는식으로 하면 테스트 넣기 유용해질 거 같아요.
listFlags가 libvirt 종속적이라면 alias 나 타입 변환 고려해서 서비스에서는 libvirt를 호출하지 않으려고 합니다


snapXML := fmt.Sprintf(`<domainsnapshot><name>%s</name><description>%s</description></domainsnapshot>`, name, description)

flags := libvirt.DomainSnapshotCreateFlags(0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 libvirt 노출 최소화와 같은 맥락입니당
인터페이스로 감추는게 좋아보여요

description = opts.Description
}

snapXML := fmt.Sprintf(`<domainsnapshot><name>%s</name><description>%s</description></domainsnapshot>`, name, description)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string 하드코딩 대신 다른 방식으로 넣는게 좋아보입니다.
pkg/virtXML에 넣어놓고 받아오는 것도 좋아보여요

targetSource, ok := targetSources[d.TargetDev]
if !ok || targetSource == "" {
continue
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전반적으로 함수가 비대해졌는데, 역할별로 분리시키는게 좋아보여요
예를 들어 xml 수정 로직은 virtxml로 이동시켜서 수행하는 식으로
snapshot 도 만약 공통 로직이 있다면 internal/snapshot 같은 파일로 옮기는 것도 좋아보입니다

return nil, fmt.Errorf("failed to parse domain xml: %w", err)
}

out := make([]diskInfo, 0, len(doc.Devices.Disks))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XML 수정 로직은 MAP + libvirt_xml 로 이전시켜서 진행하는게 좋아보입니다.
추후에 xml 관련 수정이 있을때 골치 아파질것 같아요

@kwonkwonn
Copy link
Copy Markdown
Contributor

리뷰 인지만 해주세요.
동작 검증만 되면 코드 단에서의 수정은 머지하고 천천히 분리해도 될 거 같아요.
나중에
internal/snapshot + pkg/xml로 로직 이동하고 서비스에서 가져다쓰는 방식으로 진행하는것도 좋아보입니다.
인터페이스 붙이고 테스트도 추가해보죠

@Jbchan01
Copy link
Copy Markdown
Contributor Author

확인했습니다.

@Jbchan01 Jbchan01 mentioned this pull request Mar 27, 2026
4 tasks
Copy link
Copy Markdown
Contributor

@kwonkwonn kwonkwonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니당

@kwonkwonn kwonkwonn merged commit 48b2784 into main Mar 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants