Skip to content

Commit

Permalink
Typos fix and error handling added
Browse files Browse the repository at this point in the history
  • Loading branch information
Kampadais committed Jan 25, 2024
1 parent 367fa66 commit e13c0b7
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions pkg/frontend/ublk/frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (u *Ublk) StartUblk() error {
return err
}

u.UblkId = int(jsonOutput["dev_id"].(float64))
u.UblkID = int(jsonOutput["dev_id"].(float64))
u.DaemonPId = int(jsonOutput["daemon_pid"].(float64))
u.Queues = int(jsonOutput["nr_hw_queues"].(float64))
u.QueueDepth = int(jsonOutput["queue_depth"].(float64))
Expand All @@ -100,7 +100,7 @@ func (u *Ublk) Startup(rwu types.ReaderWriterUnmapperAt) error {
}
func (u *Ublk) ShutdownUblk() {
comm := "ublk"
args := []string{"del", strconv.Itoa(u.UblkId)}
args := []string{"del", strconv.Itoa(u.UblkID)}

cmd := exec.Command(comm, args...)
logrus.Infof("Running command: %v", cmd.Args)
Expand Down Expand Up @@ -167,7 +167,12 @@ func (u *Ublk) startSocketServer(rwu types.ReaderWriterUnmapperAt) error {
}

u.socketPath = socketPath
go u.startSocketServerListen(rwu)
go func() {
err := u.startSocketServerListen(rwu)
if err != nil {
logrus.Errorf("Failed to start socket server: %v", err)
}
}()
return nil
}

Expand All @@ -176,7 +181,12 @@ func (u *Ublk) startSocketServerListen(rwu types.ReaderWriterUnmapperAt) error {
if err != nil {
return err
}
defer ln.Close()
defer func(ln net.Listener) {
err := ln.Close()
if err != nil {
logrus.WithError(err).Error("Failed to close socket listener")
}
}(ln)

for {
conn, err := ln.Accept()
Expand All @@ -189,7 +199,12 @@ func (u *Ublk) startSocketServerListen(rwu types.ReaderWriterUnmapperAt) error {
}

func (u *Ublk) handleServerConnection(c net.Conn, rwu types.ReaderWriterUnmapperAt) {
defer c.Close()
defer func(c net.Conn) {
err := c.Close()
if err != nil {
logrus.WithError(err).Error("Failed to close socket server connection")
}
}(c)

server := dataconn.NewServer(c, NewDataProcessorWrapper(rwu))
logrus.Info("New data socket connection established")
Expand Down

0 comments on commit e13c0b7

Please sign in to comment.