mirror of https://github.com/jetkvm/kvm.git
refactor(nbd): move platform-specific code to different files
This commit is contained in:
parent
cf9e90c4a6
commit
daa7185883
|
@ -7,7 +7,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pojntfx/go-nbd/pkg/client"
|
|
||||||
"github.com/pojntfx/go-nbd/pkg/server"
|
"github.com/pojntfx/go-nbd/pkg/server"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
)
|
)
|
||||||
|
@ -148,30 +147,3 @@ func (d *NBDDevice) runServerConn() {
|
||||||
|
|
||||||
d.l.Info().Err(err).Msg("nbd server exited")
|
d.l.Info().Err(err).Msg("nbd server exited")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *NBDDevice) runClientConn() {
|
|
||||||
err := client.Connect(d.clientConn, d.dev, &client.Options{
|
|
||||||
ExportName: "jetkvm",
|
|
||||||
BlockSize: uint32(4 * 1024),
|
|
||||||
})
|
|
||||||
d.l.Info().Err(err).Msg("nbd client exited")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *NBDDevice) Close() {
|
|
||||||
if d.dev != nil {
|
|
||||||
err := client.Disconnect(d.dev)
|
|
||||||
if err != nil {
|
|
||||||
d.l.Warn().Err(err).Msg("error disconnecting nbd client")
|
|
||||||
}
|
|
||||||
_ = d.dev.Close()
|
|
||||||
}
|
|
||||||
if d.listener != nil {
|
|
||||||
_ = d.listener.Close()
|
|
||||||
}
|
|
||||||
if d.clientConn != nil {
|
|
||||||
_ = d.clientConn.Close()
|
|
||||||
}
|
|
||||||
if d.serverConn != nil {
|
|
||||||
_ = d.serverConn.Close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
//go:build linux
|
||||||
|
|
||||||
|
package kvm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pojntfx/go-nbd/pkg/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (d *NBDDevice) runClientConn() {
|
||||||
|
err := client.Connect(d.clientConn, d.dev, &client.Options{
|
||||||
|
ExportName: "jetkvm",
|
||||||
|
BlockSize: uint32(4 * 1024),
|
||||||
|
})
|
||||||
|
d.l.Info().Err(err).Msg("nbd client exited")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *NBDDevice) Close() {
|
||||||
|
if d.dev != nil {
|
||||||
|
err := client.Disconnect(d.dev)
|
||||||
|
if err != nil {
|
||||||
|
d.l.Warn().Err(err).Msg("error disconnecting nbd client")
|
||||||
|
}
|
||||||
|
_ = d.dev.Close()
|
||||||
|
}
|
||||||
|
if d.listener != nil {
|
||||||
|
_ = d.listener.Close()
|
||||||
|
}
|
||||||
|
if d.clientConn != nil {
|
||||||
|
_ = d.clientConn.Close()
|
||||||
|
}
|
||||||
|
if d.serverConn != nil {
|
||||||
|
_ = d.serverConn.Close()
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
//go:build !linux
|
||||||
|
|
||||||
|
package kvm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (d *NBDDevice) runClientConn() {
|
||||||
|
d.l.Error().Msg("platform not supported")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *NBDDevice) Close() {
|
||||||
|
d.l.Error().Msg("platform not supported")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
Loading…
Reference in New Issue