@@ -44,13 +44,23 @@ var (
4444 }
4545)
4646
47+ var (
48+ ADD_SPDK_PLAYBOOK_STEPS = []int {
49+ //playbook.CREATE_VOLUME,
50+ playbook .ADD_SPDK_TARGET ,
51+ }
52+ )
53+
4754type 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
5464}
5565
5666func checkAddOptions (curveadm * cli.CurveAdm , options addOptions ) error {
@@ -60,6 +70,17 @@ func checkAddOptions(curveadm *cli.CurveAdm, options addOptions) error {
6070 return err
6171 } else if _ , err = client .ParseBlockSize (options .blocksize ); err != nil {
6272 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+ }
6384 } else if ! utils .PathExist (options .filename ) {
6485 return errno .ERR_CLIENT_CONFIGURE_FILE_NOT_EXIST .
6586 F ("file path: %s" , utils .AbsPath (options .filename ))
@@ -91,9 +112,41 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
91112 flags .StringVar (& options .size , "size" , "10GiB" , "Specify volume size" )
92113 flags .StringVarP (& options .filename , "conf" , "c" , "client.yaml" , "Specify client configuration file" )
93114 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)" )
94118 return cmd
95119}
96120
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+
97150func genAddPlaybook (curveadm * cli.CurveAdm ,
98151 ccs []* configure.ClientConfig ,
99152 options addOptions ) (* playbook.Playbook , error ) {
@@ -130,11 +183,19 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
130183 return errno .ERR_REQUIRE_CURVEBS_KIND_CLIENT_CONFIGURE_FILE .
131184 F ("kind: %s" , cc .GetKind ())
132185 }
133-
186+ var pb * playbook. Playbook
134187 // 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+ }
138199 }
139200
140201 // 3) run playground
0 commit comments