Skip to content

Commit

Permalink
Merge pull request #23373 from arixmkii/socket-url-util
Browse files Browse the repository at this point in the history
Add utility to convert VMFile to URL for UNIX sockets
  • Loading branch information
openshift-merge-bot[bot] authored Jul 23, 2024
2 parents afa5031 + 71d6e2f commit 525b9c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/machine/qemu/stubber.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -319,11 +318,15 @@ func (q *QEMUStubber) StartNetworking(mc *vmconfigs.MachineConfig, cmd *gvproxy.
if err != nil {
return err
}
socketURL, err := sockets.ToUnixURL(gvProxySock)
if err != nil {
return err
}
// make sure it does not exist before gvproxy is called
if err := gvProxySock.Delete(); err != nil {
logrus.Error(err)
}
cmd.AddQemuSocket(fmt.Sprintf("unix://%s", filepath.ToSlash(gvProxySock.GetPath())))
cmd.AddQemuSocket(socketURL.String())
return nil
}

Expand Down
15 changes: 15 additions & 0 deletions pkg/machine/sockets/sockets.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"fmt"
"net"
"net/url"
"path/filepath"
"time"

Expand Down Expand Up @@ -110,3 +111,17 @@ func WaitForSocketWithBackoffs(maxBackoffs int, backoff time.Duration, socketPat
}
return fmt.Errorf("unable to connect to %q socket at %q", name, socketPath)
}

// ToUnixURL converts `socketLoc` into URL representation
func ToUnixURL(socketLoc *define.VMFile) (*url.URL, error) {
p := socketLoc.GetPath()
if !filepath.IsAbs(p) {
return nil, fmt.Errorf("socket path must be absolute %q", p)
}
s, err := url.Parse("unix:///")
if err != nil {
return nil, err
}
s = s.JoinPath(filepath.ToSlash(p))
return s, nil
}

0 comments on commit 525b9c4

Please sign in to comment.