@@ -44,13 +44,23 @@ var (
44
44
}
45
45
)
46
46
47
+ var (
48
+ ADD_SPDK_PLAYBOOK_STEPS = []int {
49
+ //playbook.CREATE_VOLUME,
50
+ playbook .ADD_SPDK_TARGET ,
51
+ }
52
+ )
53
+
47
54
type addOptions struct {
48
- image string
49
- host string
50
- size string
51
- create bool
52
- filename string
53
- blocksize string
55
+ image string
56
+ host string
57
+ size string
58
+ create bool
59
+ filename string
60
+ blocksize string
61
+ devno string
62
+ originbdevname string
63
+ spdk bool
54
64
}
55
65
56
66
func checkAddOptions (curveadm * cli.CurveAdm , options addOptions ) error {
@@ -60,6 +70,17 @@ func checkAddOptions(curveadm *cli.CurveAdm, options addOptions) error {
60
70
return err
61
71
} else if _ , err = client .ParseBlockSize (options .blocksize ); err != nil {
62
72
return err
73
+ } else if options .spdk {
74
+ if len (options .devno ) != 0 {
75
+ if _ , err = client .ParseDevno (options .size ); err != nil {
76
+ return err
77
+ }
78
+ }
79
+ if len (options .originbdevname ) != 0 {
80
+ if err = client .ParseOriginDevname (options .size ); err != nil {
81
+ return err
82
+ }
83
+ }
63
84
} else if ! utils .PathExist (options .filename ) {
64
85
return errno .ERR_CLIENT_CONFIGURE_FILE_NOT_EXIST .
65
86
F ("file path: %s" , utils .AbsPath (options .filename ))
@@ -91,9 +112,41 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
91
112
flags .StringVar (& options .size , "size" , "10GiB" , "Specify volume size" )
92
113
flags .StringVarP (& options .filename , "conf" , "c" , "client.yaml" , "Specify client configuration file" )
93
114
flags .StringVar (& options .blocksize , "blocksize" , "4096B" , "Specify volume blocksize" )
115
+ flags .BoolVar (& options .spdk , "spdk" , false , "create iscsi spdk target" )
116
+ flags .StringVar (& options .devno , "devno" , "0" , "Specify bdev num(when set --spdk flag)" )
117
+ flags .StringVar (& options .originbdevname , "originbdevname" , "/dev/cbd0" , "Specify cbd dev(when set --spdk flag)" )
94
118
return cmd
95
119
}
96
120
121
+ func genAddSpdkPlaybook (curveadm * cli.CurveAdm ,
122
+ ccs []* configure.ClientConfig ,
123
+ options addOptions ) (* playbook.Playbook , error ) {
124
+ user , name , _ := client .ParseImage (options .image )
125
+ size , _ := client .ParseSize (options .size )
126
+ blocksize , _ := client .ParseBlockSize (options .blocksize )
127
+ steps := ADD_SPDK_PLAYBOOK_STEPS
128
+ pb := playbook .NewPlaybook (curveadm )
129
+ for _ , step := range steps {
130
+ pb .AddStep (& playbook.PlaybookStep {
131
+ Type : step ,
132
+ Configs : ccs ,
133
+ Options : map [string ]interface {}{
134
+ comm .KEY_SPDK_TARGET_OPTIONS : bs.SpdkTargetOption {
135
+ Host : options .host ,
136
+ User : user ,
137
+ Volume : name ,
138
+ Size : size ,
139
+ Blocksize : blocksize ,
140
+ Create : options .create ,
141
+ Devno : options .devno ,
142
+ OriginBdevname : options .originbdevname ,
143
+ },
144
+ },
145
+ })
146
+ }
147
+ return pb , nil
148
+ }
149
+
97
150
func genAddPlaybook (curveadm * cli.CurveAdm ,
98
151
ccs []* configure.ClientConfig ,
99
152
options addOptions ) (* playbook.Playbook , error ) {
@@ -130,11 +183,19 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
130
183
return errno .ERR_REQUIRE_CURVEBS_KIND_CLIENT_CONFIGURE_FILE .
131
184
F ("kind: %s" , cc .GetKind ())
132
185
}
133
-
186
+ var pb * playbook. Playbook
134
187
// 2) generate map playbook
135
- pb , err := genAddPlaybook (curveadm , []* configure.ClientConfig {cc }, options )
136
- if err != nil {
137
- return err
188
+ if options .spdk {
189
+ pb , err = genAddSpdkPlaybook (curveadm , []* configure.ClientConfig {cc }, options )
190
+ if err != nil {
191
+ return err
192
+ }
193
+
194
+ } else {
195
+ pb , err = genAddPlaybook (curveadm , []* configure.ClientConfig {cc }, options )
196
+ if err != nil {
197
+ return err
198
+ }
138
199
}
139
200
140
201
// 3) run playground
0 commit comments