Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support spdk tgt #304

Open
wants to merge 1 commit into
base: tombstone
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,3 @@ upload:
lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION)
$(GOBIN_GOLANGCILINT) run -v

16 changes: 16 additions & 0 deletions cli/command/client/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ func ParseSize(size string) (int, error) {
return n, nil
}

func ParseOriginDevname(origindevname string) error {
if !strings.HasSuffix(origindevname, "/dev/") {
return errno.ERR_SPDK_TARGET_DEVNAME_IS_ABNORMAL.
F("origindevname: %s", origindevname)
}
return nil
}

func ParseDevno(size string) (int, error) {
n, err := strconv.Atoi(size)
if err != nil || n < 0 {
return 0, errno.ERR_SPDK_TARGET_DEVNO_IS_ABNORMAL
}
return n, nil
}

func ParseBlockSize(blocksize string) (uint64, error) {
if !strings.HasSuffix(blocksize, "B") {
return 0, errno.ERR_VOLUME_BLOCKSIZE_MUST_END_WITH_BYTE_SUFFIX.
Expand Down
45 changes: 32 additions & 13 deletions cli/command/target/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ var (
)

type addOptions struct {
image string
host string
size string
create bool
filename string
blocksize string
image string
host string
size string
create bool
filename string
blocksize string
devno string
originbdevname string
spdk bool
}

func checkAddOptions(curveadm *cli.CurveAdm, options addOptions) error {
Expand All @@ -60,6 +63,17 @@ func checkAddOptions(curveadm *cli.CurveAdm, options addOptions) error {
return err
} else if _, err = client.ParseBlockSize(options.blocksize); err != nil {
return err
} else if options.spdk {
if len(options.devno) != 0 {
if _, err = client.ParseDevno(options.size); err != nil {
return err
}
}
if len(options.originbdevname) != 0 {
if err = client.ParseOriginDevname(options.size); err != nil {
return err
}
}
} else if !utils.PathExist(options.filename) {
return errno.ERR_CLIENT_CONFIGURE_FILE_NOT_EXIST.
F("file path: %s", utils.AbsPath(options.filename))
Expand Down Expand Up @@ -91,6 +105,9 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags.StringVar(&options.size, "size", "10GiB", "Specify volume size")
flags.StringVarP(&options.filename, "conf", "c", "client.yaml", "Specify client configuration file")
flags.StringVar(&options.blocksize, "blocksize", "4096B", "Specify volume blocksize")
flags.BoolVar(&options.spdk, "spdk", false, "create iscsi spdk target")
flags.StringVar(&options.devno, "devno", "0", "Specify bdev num(when set --spdk flag)")
flags.StringVar(&options.originbdevname, "originbdevname", "/dev/cbd0", "Specify cbd dev(when set --spdk flag)")
return cmd
}

Expand All @@ -108,12 +125,15 @@ func genAddPlaybook(curveadm *cli.CurveAdm,
Configs: ccs,
Options: map[string]interface{}{
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
Host: options.host,
User: user,
Volume: name,
Size: size,
Blocksize: blocksize,
Create: options.create,
Host: options.host,
User: user,
Volume: name,
Size: size,
Blocksize: blocksize,
Create: options.create,
Devno: options.devno,
OriginBdevname: options.originbdevname,
Spdk: options.spdk,
},
},
})
Expand All @@ -130,7 +150,6 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
return errno.ERR_REQUIRE_CURVEBS_KIND_CLIENT_CONFIGURE_FILE.
F("kind: %s", cc.GetKind())
}

// 2) generate map playbook
pb, err := genAddPlaybook(curveadm, []*configure.ClientConfig{cc}, options)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/target/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewTargetCommand(curveadm *cli.CurveAdm) *cobra.Command {
cmd := &cobra.Command{
Use: "target",
Short: "Manage SCSI target of CurveBS",
Args: cliutil.NoArgs,
Args: cliutil.ExactArgs(1),
RunE: cliutil.ShowHelp(curveadm.Err()),
}

Expand Down
18 changes: 14 additions & 4 deletions cli/command/target/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ var (
)

type deleteOptions struct {
host string
tid string
host string
tid string
devno string
spdk bool
}

func NewDeleteCommand(curveadm *cli.CurveAdm) *cobra.Command {
Expand All @@ -60,6 +62,7 @@ func NewDeleteCommand(curveadm *cli.CurveAdm) *cobra.Command {

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.BoolVar(&options.spdk, "spdk", false, "delete iscsi spdk target")

return cmd
}
Expand All @@ -73,8 +76,10 @@ func genDeletePlaybook(curveadm *cli.CurveAdm, options deleteOptions) (*playbook
Configs: nil,
Options: map[string]interface{}{
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
Host: options.host,
Tid: options.tid,
Host: options.host,
Tid: options.tid,
Spdk: options.spdk,
Devno: options.devno,
},
},
})
Expand All @@ -84,11 +89,16 @@ func genDeletePlaybook(curveadm *cli.CurveAdm, options deleteOptions) (*playbook

func runDelete(curveadm *cli.CurveAdm, options deleteOptions) error {
// 1) generate list playbook

pb, err := genDeletePlaybook(curveadm, options)
if err != nil {
return err
}

if err != nil {
return err
}

// 2) run playground
err = pb.Run()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions cli/command/target/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (

type listOptions struct {
host string
spdk bool
}

func NewListCommand(curveadm *cli.CurveAdm) *cobra.Command {
Expand All @@ -59,6 +60,7 @@ func NewListCommand(curveadm *cli.CurveAdm) *cobra.Command {

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.BoolVar(&options.spdk, "spdk", false, "list iscsi spdk target")

return cmd
}
Expand All @@ -73,6 +75,7 @@ func genListPlaybook(curveadm *cli.CurveAdm, options listOptions) (*playbook.Pla
Options: map[string]interface{}{
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
Host: options.host,
Spdk: options.spdk,
},
},
})
Expand Down
3 changes: 3 additions & 0 deletions cli/command/target/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var (
type startOptions struct {
host string
filename string
spdk bool
}

func NewStartCommand(curveadm *cli.CurveAdm) *cobra.Command {
Expand All @@ -62,6 +63,7 @@ func NewStartCommand(curveadm *cli.CurveAdm) *cobra.Command {
flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.StringVarP(&options.filename, "conf", "c", "client.yaml", "Specify client configuration file")
flags.BoolVar(&options.spdk, "spdk", false, "start iscsi spdk target")

return cmd
}
Expand All @@ -78,6 +80,7 @@ func genStartPlaybook(curveadm *cli.CurveAdm,
Options: map[string]interface{}{
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
Host: options.host,
Spdk: options.spdk,
},
},
})
Expand Down
4 changes: 4 additions & 0 deletions cli/command/target/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var (

type stopOptions struct {
host string
spdk bool
}

func NewStopCommand(curveadm *cli.CurveAdm) *cobra.Command {
Expand All @@ -57,6 +58,7 @@ func NewStopCommand(curveadm *cli.CurveAdm) *cobra.Command {

flags := cmd.Flags()
flags.StringVar(&options.host, "host", "localhost", "Specify target host")
flags.BoolVar(&options.spdk, "spdk", false, "stop iscsi spdk target")

return cmd
}
Expand All @@ -71,6 +73,7 @@ func genStopPlaybook(curveadm *cli.CurveAdm, options stopOptions) (*playbook.Pla
Options: map[string]interface{}{
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
Host: options.host,
Spdk: options.spdk,
},
},
})
Expand All @@ -79,6 +82,7 @@ func genStopPlaybook(curveadm *cli.CurveAdm, options stopOptions) (*playbook.Pla
}

func runStop(curveadm *cli.CurveAdm, options stopOptions) error {

// 1) generate stop playbook
pb, err := genStopPlaybook(curveadm, options)
if err != nil {
Expand Down
37 changes: 21 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/opencurve/curveadm

go 1.18
go 1.21

require (
github.com/docker/cli v24.0.1+incompatible
Expand All @@ -11,7 +11,7 @@ require (
github.com/google/uuid v1.3.0
github.com/jpillora/longestcommon v0.0.0-20161227235612-adb9d91ee629
github.com/kpango/glg v1.6.14
github.com/mattn/go-sqlite3 v1.14.16
github.com/mattn/go-sqlite3 v1.14.17
github.com/mcuadros/go-defaults v1.2.0
github.com/melbahja/goph v1.3.0
github.com/mitchellh/hashstructure/v2 v2.0.2
Expand All @@ -24,7 +24,7 @@ require (
github.com/stretchr/testify v1.8.2
github.com/vbauerster/mpb/v7 v7.5.3
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.8.0
golang.org/x/crypto v0.13.0
)

require (
Expand All @@ -33,11 +33,13 @@ require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/Wine93/grace v0.0.0-20221021033009-7d0348013a3c // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.8.7 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v24.0.1+incompatible // indirect
Expand All @@ -52,6 +54,7 @@ require (
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fvbommel/sortorder v1.1.0 // indirect
github.com/gaukas/godicttls v0.0.4 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
Expand All @@ -62,15 +65,16 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/pprof v0.0.0-20230406165453-00490a63f317 // indirect
github.com/google/pprof v0.0.0-20230912144702-c363fe2c2ed8 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/imroc/req/v3 v3.33.2 // indirect
github.com/imroc/req/v3 v3.42.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/kpango/fastime v1.1.6 // indirect
github.com/kr/fs v0.1.0 // indirect
Expand All @@ -86,7 +90,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/onsi/ginkgo/v2 v2.9.2 // indirect
github.com/onsi/ginkgo/v2 v2.12.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
Expand All @@ -99,8 +103,9 @@ require (
github.com/prometheus/procfs v0.9.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.4 // indirect
github.com/quic-go/quic-go v0.38.1 // indirect
github.com/refraction-networking/utls v1.5.3 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/sevlyar/go-daemon v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
Expand All @@ -115,14 +120,14 @@ require (
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/tools v0.8.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/term v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
Expand Down
Loading