Skip to content

Commit

Permalink
Merge pull request #2171 from petrkotas/fix-vnc
Browse files Browse the repository at this point in the history
Fix disappearing vnc socket
  • Loading branch information
davidvossel committed Apr 5, 2019
2 parents 06d9119 + 4571bc7 commit 115b1f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
26 changes: 26 additions & 0 deletions cmd/virt-launcher/virt-launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,26 @@ func waitForFinalNotify(deleteNotificationSent chan watch.Event,
}
}

// writeProtectPrivateDir waits until the kubevirt private vnc socket exists and than mark its folder as read only
// this is a workaround preventing QEMU from deleting its sockets prematurely as described in a bug https://bugs.launchpad.net/qemu/+bug/1795100
// once the QEMU 4.0 is released the need for this workaround goes away
// Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1683964
func writeProtectPrivateDir(uid string) {
vncAppeared := false
// waits maximum of 20s for vnc file to appear
for i := 0; i < 20; i++ {
if _, err := os.Stat(filepath.Join("/var/run/kubevirt-private", uid, "virt-vnc")); os.IsNotExist(err) {
time.Sleep(1 * time.Second)
continue
}
vncAppeared = true
break
}
if vncAppeared {
os.Chmod(filepath.Join("/var/run/kubevirt-private", uid), 0444)
}
}

func main() {
qemuTimeout := pflag.Duration("qemu-timeout", defaultStartTimeout, "Amount of time to wait for qemu")
virtShareDir := pflag.String("kubevirt-share-dir", "/var/run/kubevirt", "Shared directory between virt-handler and virt-launcher")
Expand Down Expand Up @@ -432,6 +452,12 @@ func main() {
*gracePeriodSeconds,
shutdownCallback)

// waits until virt-vnc socket is ready and than mark its parent folder as read only
// workaround preventing QEMU from deleting socket prematurely
// the code need to be executed after the QEMU reports VM is running, so the wait
// for socket creation is the shortest possible
go writeProtectPrivateDir(*uid)

// This is a wait loop that monitors the qemu pid. When the pid
// exits, the wait loop breaks.
mon.RunForever(*qemuTimeout, signalStopChan)
Expand Down
13 changes: 12 additions & 1 deletion tests/vnc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var _ = Describe("[rfe_id:127][crit:medium][vendor:cnv-qe@redhat.com][level:comp

Context("with VNC connection", func() {

It("[test_id:1611]should allow accessing the VNC device", func() {
vncConnect := func() {
pipeInReader, _ := io.Pipe()
pipeOutReader, pipeOutWriter := io.Pipe()
defer pipeInReader.Close()
Expand Down Expand Up @@ -113,6 +113,17 @@ var _ = Describe("[rfe_id:127][crit:medium][vendor:cnv-qe@redhat.com][level:comp
By("Checking the response from VNC server")
Expect(response).To(Equal("RFB 003.008\n"))
Expect(err).To(BeNil())
}

It("[test_id:1611]should allow accessing the VNC device", func() {
vncConnect()
})

It("should allow accessing the VNC device multiple times", func() {

for i := 0; i < 10; i++ {
vncConnect()
}
})
})

Expand Down

0 comments on commit 115b1f0

Please sign in to comment.