Skip to content

Commit

Permalink
Merge pull request #114 from gostor/daemon_port
Browse files Browse the repository at this point in the history
add target port as command flag
  • Loading branch information
carmark authored Dec 13, 2022
2 parents cec0938 + d94641a commit f5fec6b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
18 changes: 11 additions & 7 deletions cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ import (
)

func newDaemonCommand() *cobra.Command {
var host string
var driver string
var logLevel string
var blockMultipleHosts bool
var (
host string
driver string
logLevel string
blockMultipleHosts bool
port int
)
var cmd = &cobra.Command{
Use: "daemon",
Short: "Setup a daemon",
Expand All @@ -48,17 +51,18 @@ func newDaemonCommand() *cobra.Command {
},
RunE: func(cmd *cobra.Command, args []string) error {
host = viper.GetString("host")
return createDaemon(host, driver, logLevel, blockMultipleHosts)
return createDaemon(host, driver, logLevel, blockMultipleHosts, port)
},
}
flags := cmd.Flags()
flags.StringVar(&logLevel, "log", "info", "Log level of SCSI target daemon")
flags.StringVar(&driver, "driver", "iscsi", "SCSI low level driver")
flags.IntVar(&port, "port", 3260, "iSCSI default target port")
flags.BoolVar(&blockMultipleHosts, "block-multiple-hosts", false, "Disable login from multiple hosts")
return cmd
}

func createDaemon(host, driver, level string, blockMultipleHosts bool) error {
func createDaemon(host, driver, level string, blockMultipleHosts bool, port int) error {
switch level {
case "info":
log.SetLevel(log.InfoLevel)
Expand Down Expand Up @@ -101,7 +105,7 @@ func createDaemon(host, driver, level string, blockMultipleHosts bool) error {
// comment this to avoid concurrent issue
// runtime.GOMAXPROCS(runtime.NumCPU())
// run a service
go targetDriver.Run()
go targetDriver.Run(port)

serverConfig := &apiserver.Config{
Addrs: []apiserver.Addr{},
Expand Down
2 changes: 1 addition & 1 deletion mock/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (r *remoteBs) startScsiTarget(cfg *config.Config) error {
}
r.targetDriver.NewTarget(r.tgtName, cfg)
//r.targetDriver.SetClusterIP(r.clusterIP)
go r.targetDriver.Run()
go r.targetDriver.Run(3260)
// Wait here so that listener get started
time.Sleep(1 * time.Second)

Expand Down
4 changes: 2 additions & 2 deletions pkg/port/iscsit/iscsid.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ func (s *ISCSITargetDriver) HasPortal(tgtName string, tpgt uint16, portal string
}
}

func (s *ISCSITargetDriver) Run() error {
l, err := net.Listen("tcp", ":3260")
func (s *ISCSITargetDriver) Run(port int) error {
l, err := net.Listen("tcp", ":"+strconv.Itoa(port))
if err != nil {
log.Error(err)
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/scsi/drivers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

type SCSITargetDriver interface {
Run() error
Run(port int) error
NewTarget(string, *config.Config) error
RereadTargetLUNMap()
Close() error
Expand Down

0 comments on commit f5fec6b

Please sign in to comment.