Skip to content

Commit

Permalink
close the shared pipe so the virt-v2v commad will finish.
Browse files Browse the repository at this point in the history
Signed-off-by: Bella Khizgiyaev <bkhizgiy@redhat.com>
  • Loading branch information
bkhizgiy committed May 20, 2024
1 parent e090985 commit b95bd5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
2 changes: 2 additions & 0 deletions cmd/virt-v2v-monitor/virt-v2v-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func main() {
err := scanner.Err()
if err != nil {
fmt.Println("virt-v2v monitoring: Output monitoring failed! ", err)
os.Exit(1)
}

if match := COPY_DISK_RE.FindSubmatch(line); match != nil {
Expand Down Expand Up @@ -120,5 +121,6 @@ func main() {
err := scanner.Err()
if err != nil {
fmt.Println("virt-v2v monitoring: Output monitoring failed! ", err)
os.Exit(1)
}
}
43 changes: 27 additions & 16 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,36 +207,47 @@ func executeVirtV2v(source string, args []string) (err error) {
virtV2vMonitorCmd := exec.Command("/usr/local/bin/virt-v2v-monitor")
virtV2vMonitorCmd.Stdin = r
virtV2vMonitorCmd.Stdout = os.Stdout
virtV2vMonitorCmd.Stderr = os.Stderr

if err = virtV2vMonitorCmd.Start(); err != nil {
fmt.Printf("Error executing monitor command: %v\n", err)
return
}

if source == OVA {
scanner := bufio.NewScanner(r)
const maxCapacity = 1024 * 1024
buf := make([]byte, 0, 64*1024)
scanner.Buffer(buf, maxCapacity)

for scanner.Scan() {
line := scanner.Bytes()
if match := UEFI_RE.FindSubmatch(line); match != nil {
fmt.Println("UEFI firmware detected")
firmware = "efi"
done := make(chan error, 1)
go func() {
if source == OVA {
scanner := bufio.NewScanner(r)
const maxCapacity = 1024 * 1024
buf := make([]byte, 0, 64*1024)
scanner.Buffer(buf, maxCapacity)

for scanner.Scan() {
line := scanner.Bytes()
if match := UEFI_RE.FindSubmatch(line); match != nil {
fmt.Println("UEFI firmware detected")
firmware = "efi"
}
}
}

if err = scanner.Err(); err != nil {
fmt.Println("Output query failed:", err)
return err
if err := scanner.Err(); err != nil {
fmt.Println("Output query failed:", err)
done <- err
return
}
}
}
done <- nil
}()

if err = virtV2vCmd.Wait(); err != nil {
fmt.Printf("Error waiting for virt-v2v to finish: %v\n", err)
return
}
w.Close()

if err = <-done; err != nil {
return err
}
return
}

Expand Down

0 comments on commit b95bd5f

Please sign in to comment.