@@ -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,18 @@ 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 .originbdevname ) == 0 {
75+ return errno .ERR_SPDK_TARGET_WITHOUT_BLK_DEV
76+ }
77+ if len (options .devno ) != 0 {
78+ if _ , err = client .ParseDevno (options .size ); err != nil {
79+ return err
80+ }
81+ } else {
82+ options .devno = "0"
83+ }
84+
6385 } else if ! utils .PathExist (options .filename ) {
6486 return errno .ERR_CLIENT_CONFIGURE_FILE_NOT_EXIST .
6587 F ("file path: %s" , utils .AbsPath (options .filename ))
@@ -91,9 +113,41 @@ func NewAddCommand(curveadm *cli.CurveAdm) *cobra.Command {
91113 flags .StringVar (& options .size , "size" , "10GiB" , "Specify volume size" )
92114 flags .StringVarP (& options .filename , "conf" , "c" , "client.yaml" , "Specify client configuration file" )
93115 flags .StringVar (& options .blocksize , "blocksize" , "4096B" , "Specify volume blocksize" )
116+ flags .BoolVar (& options .spdk , "spdk" , false , "create iscsi spdk target" )
117+ flags .StringVar (& options .devno , "devno" , "0" , "Specify bdev num(when set --spdk flag)" )
118+ flags .StringVar (& options .originbdevname , "originbdevname" , "/dev/cbd0" , "Specify cbd dev(when set --spdk flag)" )
94119 return cmd
95120}
96121
122+ func genAddSpdkPlaybook (curveadm * cli.CurveAdm ,
123+ ccs []* configure.ClientConfig ,
124+ options addOptions ) (* playbook.Playbook , error ) {
125+ user , name , _ := client .ParseImage (options .image )
126+ size , _ := client .ParseSize (options .size )
127+ blocksize , _ := client .ParseBlockSize (options .blocksize )
128+ steps := ADD_SPDK_PLAYBOOK_STEPS
129+ pb := playbook .NewPlaybook (curveadm )
130+ for _ , step := range steps {
131+ pb .AddStep (& playbook.PlaybookStep {
132+ Type : step ,
133+ Configs : ccs ,
134+ Options : map [string ]interface {}{
135+ comm .KEY_SPDK_TARGET_OPTIONS : bs.SpdkTargetOption {
136+ Host : options .host ,
137+ User : user ,
138+ Volume : name ,
139+ Size : size ,
140+ Blocksize : blocksize ,
141+ Create : options .create ,
142+ Devno : options .devno ,
143+ OriginBdevname : options .originbdevname ,
144+ },
145+ },
146+ })
147+ }
148+ return pb , nil
149+ }
150+
97151func genAddPlaybook (curveadm * cli.CurveAdm ,
98152 ccs []* configure.ClientConfig ,
99153 options addOptions ) (* playbook.Playbook , error ) {
@@ -130,11 +184,19 @@ func runAdd(curveadm *cli.CurveAdm, options addOptions) error {
130184 return errno .ERR_REQUIRE_CURVEBS_KIND_CLIENT_CONFIGURE_FILE .
131185 F ("kind: %s" , cc .GetKind ())
132186 }
133-
187+ var pb * playbook. Playbook
134188 // 2) generate map playbook
135- pb , err := genAddPlaybook (curveadm , []* configure.ClientConfig {cc }, options )
136- if err != nil {
137- return err
189+ if options .spdk {
190+ pb , err = genAddSpdkPlaybook (curveadm , []* configure.ClientConfig {cc }, options )
191+ if err != nil {
192+ return err
193+ }
194+
195+ } else {
196+ pb , err = genAddPlaybook (curveadm , []* configure.ClientConfig {cc }, options )
197+ if err != nil {
198+ return err
199+ }
138200 }
139201
140202 // 3) run playground
0 commit comments