Skip to content

Commit 36b7e2f

Browse files
committed
support spdk tgt
Signed-off-by: YLShiJustFly <youseeicanfly@126.com>
1 parent 3b6b0a1 commit 36b7e2f

File tree

20 files changed

+594
-170
lines changed

20 files changed

+594
-170
lines changed

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,3 @@ upload:
7373
lint:
7474
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCILINT_VERSION)
7575
$(GOBIN_GOLANGCILINT) run -v
76-

cli/command/client/map.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ func ParseSize(size string) (int, error) {
110110
return n, nil
111111
}
112112

113+
func ParseOriginDevname(origindevname string) error {
114+
if !strings.HasSuffix(origindevname, "/dev/") {
115+
return errno.ERR_SPDK_TARGET_DEVNAME_IS_ABNORMAL.
116+
F("origindevname: %s", origindevname)
117+
}
118+
return nil
119+
}
120+
121+
func ParseDevno(size string) (int, error) {
122+
n, err := strconv.Atoi(size)
123+
if err != nil || n < 0 {
124+
return 0, errno.ERR_SPDK_TARGET_DEVNO_IS_ABNORMAL
125+
}
126+
return n, nil
127+
}
128+
113129
func ParseBlockSize(blocksize string) (uint64, error) {
114130
if !strings.HasSuffix(blocksize, "B") {
115131
return 0, errno.ERR_VOLUME_BLOCKSIZE_MUST_END_WITH_BYTE_SUFFIX.

cli/command/target/add.go

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,15 @@ var (
4545
)
4646

4747
type addOptions struct {
48-
image string
49-
host string
50-
size string
51-
create bool
52-
filename string
53-
blocksize string
48+
image string
49+
host string
50+
size string
51+
create bool
52+
filename string
53+
blocksize string
54+
devno string
55+
originbdevname string
56+
spdk bool
5457
}
5558

5659
func checkAddOptions(curveadm *cli.CurveAdm, options addOptions) error {
@@ -60,6 +63,17 @@ func checkAddOptions(curveadm *cli.CurveAdm, options addOptions) error {
6063
return err
6164
} else if _, err = client.ParseBlockSize(options.blocksize); err != nil {
6265
return err
66+
} else if options.spdk {
67+
if len(options.devno) != 0 {
68+
if _, err = client.ParseDevno(options.size); err != nil {
69+
return err
70+
}
71+
}
72+
if len(options.originbdevname) != 0 {
73+
if err = client.ParseOriginDevname(options.size); err != nil {
74+
return err
75+
}
76+
}
6377
} else if !utils.PathExist(options.filename) {
6478
return errno.ERR_CLIENT_CONFIGURE_FILE_NOT_EXIST.
6579
F("file path: %s", utils.AbsPath(options.filename))
@@ -91,6 +105,9 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
91105
flags.StringVar(&options.size, "size", "10GiB", "Specify volume size")
92106
flags.StringVarP(&options.filename, "conf", "c", "client.yaml", "Specify client configuration file")
93107
flags.StringVar(&options.blocksize, "blocksize", "4096B", "Specify volume blocksize")
108+
flags.BoolVar(&options.spdk, "spdk", false, "create iscsi spdk target")
109+
flags.StringVar(&options.devno, "devno", "0", "Specify bdev num(when set --spdk flag)")
110+
flags.StringVar(&options.originbdevname, "originbdevname", "/dev/cbd0", "Specify cbd dev(when set --spdk flag)")
94111
return cmd
95112
}
96113

@@ -108,12 +125,15 @@ func genAddPlaybook(curveadm *cli.CurveAdm,
108125
Configs: ccs,
109126
Options: map[string]interface{}{
110127
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
111-
Host: options.host,
112-
User: user,
113-
Volume: name,
114-
Size: size,
115-
Blocksize: blocksize,
116-
Create: options.create,
128+
Host: options.host,
129+
User: user,
130+
Volume: name,
131+
Size: size,
132+
Blocksize: blocksize,
133+
Create: options.create,
134+
Devno: options.devno,
135+
OriginBdevname: options.originbdevname,
136+
Spdk: options.spdk,
117137
},
118138
},
119139
})
@@ -130,7 +150,6 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
130150
return errno.ERR_REQUIRE_CURVEBS_KIND_CLIENT_CONFIGURE_FILE.
131151
F("kind: %s", cc.GetKind())
132152
}
133-
134153
// 2) generate map playbook
135154
pb, err := genAddPlaybook(curveadm, []*configure.ClientConfig{cc}, options)
136155
if err != nil {

cli/command/target/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func NewTargetCommand(curveadm *cli.CurveAdm) *cobra.Command {
3232
cmd := &cobra.Command{
3333
Use: "target",
3434
Short: "Manage SCSI target of CurveBS",
35-
Args: cliutil.NoArgs,
35+
Args: cliutil.ExactArgs(1),
3636
RunE: cliutil.ShowHelp(curveadm.Err()),
3737
}
3838

cli/command/target/delete.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ var (
3939
)
4040

4141
type deleteOptions struct {
42-
host string
43-
tid string
42+
host string
43+
tid string
44+
devno string
45+
spdk bool
4446
}
4547

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

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

6467
return cmd
6568
}
@@ -73,8 +76,10 @@ func genDeletePlaybook(curveadm *cli.CurveAdm, options deleteOptions) (*playbook
7376
Configs: nil,
7477
Options: map[string]interface{}{
7578
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
76-
Host: options.host,
77-
Tid: options.tid,
79+
Host: options.host,
80+
Tid: options.tid,
81+
Spdk: options.spdk,
82+
Devno: options.devno,
7883
},
7984
},
8085
})
@@ -84,11 +89,16 @@ func genDeletePlaybook(curveadm *cli.CurveAdm, options deleteOptions) (*playbook
8489

8590
func runDelete(curveadm *cli.CurveAdm, options deleteOptions) error {
8691
// 1) generate list playbook
92+
8793
pb, err := genDeletePlaybook(curveadm, options)
8894
if err != nil {
8995
return err
9096
}
9197

98+
if err != nil {
99+
return err
100+
}
101+
92102
// 2) run playground
93103
err = pb.Run()
94104
if err != nil {

cli/command/target/list.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141

4242
type listOptions struct {
4343
host string
44+
spdk bool
4445
}
4546

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

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

6365
return cmd
6466
}
@@ -73,6 +75,7 @@ func genListPlaybook(curveadm *cli.CurveAdm, options listOptions) (*playbook.Pla
7375
Options: map[string]interface{}{
7476
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
7577
Host: options.host,
78+
Spdk: options.spdk,
7679
},
7780
},
7881
})

cli/command/target/start.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
type startOptions struct {
4545
host string
4646
filename string
47+
spdk bool
4748
}
4849

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

6668
return cmd
6769
}
@@ -78,6 +80,7 @@ func genStartPlaybook(curveadm *cli.CurveAdm,
7880
Options: map[string]interface{}{
7981
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
8082
Host: options.host,
83+
Spdk: options.spdk,
8184
},
8285
},
8386
})

cli/command/target/stop.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var (
4040

4141
type stopOptions struct {
4242
host string
43+
spdk bool
4344
}
4445

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

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

6163
return cmd
6264
}
@@ -71,6 +73,7 @@ func genStopPlaybook(curveadm *cli.CurveAdm, options stopOptions) (*playbook.Pla
7173
Options: map[string]interface{}{
7274
comm.KEY_TARGET_OPTIONS: bs.TargetOption{
7375
Host: options.host,
76+
Spdk: options.spdk,
7477
},
7578
},
7679
})
@@ -79,6 +82,7 @@ func genStopPlaybook(curveadm *cli.CurveAdm, options stopOptions) (*playbook.Pla
7982
}
8083

8184
func runStop(curveadm *cli.CurveAdm, options stopOptions) error {
85+
8286
// 1) generate stop playbook
8387
pb, err := genStopPlaybook(curveadm, options)
8488
if err != nil {

go.mod

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/opencurve/curveadm
22

3-
go 1.18
3+
go 1.21
44

55
require (
66
github.com/docker/cli v24.0.1+incompatible
@@ -11,7 +11,7 @@ require (
1111
github.com/google/uuid v1.3.0
1212
github.com/jpillora/longestcommon v0.0.0-20161227235612-adb9d91ee629
1313
github.com/kpango/glg v1.6.14
14-
github.com/mattn/go-sqlite3 v1.14.16
14+
github.com/mattn/go-sqlite3 v1.14.17
1515
github.com/mcuadros/go-defaults v1.2.0
1616
github.com/melbahja/goph v1.3.0
1717
github.com/mitchellh/hashstructure/v2 v2.0.2
@@ -24,7 +24,7 @@ require (
2424
github.com/stretchr/testify v1.8.2
2525
github.com/vbauerster/mpb/v7 v7.5.3
2626
go.uber.org/zap v1.24.0
27-
golang.org/x/crypto v0.8.0
27+
golang.org/x/crypto v0.13.0
2828
)
2929

3030
require (
@@ -33,11 +33,13 @@ require (
3333
github.com/VividCortex/ewma v1.2.0 // indirect
3434
github.com/Wine93/grace v0.0.0-20221021033009-7d0348013a3c // indirect
3535
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
36+
github.com/andybalholm/brotli v1.0.5 // indirect
3637
github.com/benbjohnson/clock v1.3.0 // indirect
3738
github.com/beorn7/perks v1.0.1 // indirect
3839
github.com/bytedance/sonic v1.8.7 // indirect
3940
github.com/cespare/xxhash/v2 v2.2.0 // indirect
4041
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
42+
github.com/cloudflare/circl v1.3.3 // indirect
4143
github.com/davecgh/go-spew v1.1.1 // indirect
4244
github.com/docker/distribution v2.8.1+incompatible // indirect
4345
github.com/docker/docker v24.0.1+incompatible // indirect
@@ -52,6 +54,7 @@ require (
5254
github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 // indirect
5355
github.com/fsnotify/fsnotify v1.6.0 // indirect
5456
github.com/fvbommel/sortorder v1.1.0 // indirect
57+
github.com/gaukas/godicttls v0.0.4 // indirect
5558
github.com/gin-contrib/sse v0.1.0 // indirect
5659
github.com/gin-gonic/gin v1.9.0 // indirect
5760
github.com/go-playground/locales v0.14.1 // indirect
@@ -62,15 +65,16 @@ require (
6265
github.com/gogo/protobuf v1.3.2 // indirect
6366
github.com/golang/mock v1.6.0 // indirect
6467
github.com/golang/protobuf v1.5.3 // indirect
65-
github.com/google/pprof v0.0.0-20230406165453-00490a63f317 // indirect
68+
github.com/google/pprof v0.0.0-20230912144702-c363fe2c2ed8 // indirect
6669
github.com/gorilla/mux v1.8.0 // indirect
6770
github.com/hashicorp/errwrap v1.1.0 // indirect
6871
github.com/hashicorp/go-multierror v1.1.1 // indirect
6972
github.com/hashicorp/hcl v1.0.0 // indirect
70-
github.com/imroc/req/v3 v3.33.2 // indirect
73+
github.com/imroc/req/v3 v3.42.0 // indirect
7174
github.com/inconshreveable/mousetrap v1.1.0 // indirect
7275
github.com/json-iterator/go v1.1.12 // indirect
7376
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect
77+
github.com/klauspost/compress v1.16.7 // indirect
7478
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
7579
github.com/kpango/fastime v1.1.6 // indirect
7680
github.com/kr/fs v0.1.0 // indirect
@@ -86,7 +90,7 @@ require (
8690
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
8791
github.com/modern-go/reflect2 v1.0.2 // indirect
8892
github.com/morikuni/aec v1.0.0 // indirect
89-
github.com/onsi/ginkgo/v2 v2.9.2 // indirect
93+
github.com/onsi/ginkgo/v2 v2.12.0 // indirect
9094
github.com/opencontainers/go-digest v1.0.0 // indirect
9195
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
9296
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
@@ -99,8 +103,9 @@ require (
99103
github.com/prometheus/procfs v0.9.0 // indirect
100104
github.com/quic-go/qpack v0.4.0 // indirect
101105
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
102-
github.com/quic-go/qtls-go1-20 v0.2.2 // indirect
103-
github.com/quic-go/quic-go v0.33.0 // indirect
106+
github.com/quic-go/qtls-go1-20 v0.3.4 // indirect
107+
github.com/quic-go/quic-go v0.38.1 // indirect
108+
github.com/refraction-networking/utls v1.5.3 // indirect
104109
github.com/rivo/uniseg v0.4.3 // indirect
105110
github.com/sevlyar/go-daemon v0.1.6 // indirect
106111
github.com/sirupsen/logrus v1.9.0 // indirect
@@ -115,14 +120,14 @@ require (
115120
go.uber.org/atomic v1.10.0 // indirect
116121
go.uber.org/multierr v1.11.0 // indirect
117122
golang.org/x/arch v0.3.0 // indirect
118-
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
119-
golang.org/x/mod v0.10.0 // indirect
120-
golang.org/x/net v0.9.0 // indirect
121-
golang.org/x/sync v0.1.0 // indirect
122-
golang.org/x/sys v0.7.0 // indirect
123-
golang.org/x/term v0.7.0 // indirect
124-
golang.org/x/text v0.9.0 // indirect
125-
golang.org/x/tools v0.8.0 // indirect
123+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
124+
golang.org/x/mod v0.12.0 // indirect
125+
golang.org/x/net v0.15.0 // indirect
126+
golang.org/x/sync v0.3.0 // indirect
127+
golang.org/x/sys v0.12.0 // indirect
128+
golang.org/x/term v0.12.0 // indirect
129+
golang.org/x/text v0.13.0 // indirect
130+
golang.org/x/tools v0.13.0 // indirect
126131
google.golang.org/protobuf v1.30.0 // indirect
127132
gopkg.in/ini.v1 v1.67.0 // indirect
128133
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect

0 commit comments

Comments
 (0)