Skip to content

Commit 2ab0f51

Browse files
committed
support spdk tgt
1 parent 3b6b0a1 commit 2ab0f51

File tree

14 files changed

+720
-11
lines changed

14 files changed

+720
-11
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-

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh
331331
github.com/mattn/go-sqlite3 v1.6.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
332332
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
333333
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
334+
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
335+
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
334336
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
335337
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
336338
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=

internal/common/common.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ const (
120120
KEY_TARGET_OPTIONS = "TARGET_OPTIONS"
121121
KEY_ALL_TARGETS = "ALL_TARGETS"
122122

123+
// spdk_target
124+
KEY_SPDK_TARGET_OPTIONS = "SPDK_TARGET_OPTIONS"
125+
KEY_ALL_SPDK_TARGETS = "ALL_SPDK_TARGETS"
126+
123127
// playground
124128
KEY_ALL_PLAYGROUNDS_STATUS = "ALL_PLAYGROUNDS_STATUS"
125129
PLAYGROUDN_STATUS_LOSED = "Losed"

internal/errno/errno.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,17 @@ var (
419419
ERR_CLIENT_ID_NOT_FOUND = EC(410022, "client id not found")
420420

421421
// 420: common (curvebs client)
422-
ERR_VOLUME_ALREADY_MAPPED = EC(420000, "volume already mapped")
423-
ERR_VOLUME_CONTAINER_LOSED = EC(420001, "volume container is losed")
424-
ERR_VOLUME_CONTAINER_ABNORMAL = EC(420002, "volume container is abnormal")
425-
ERR_CREATE_VOLUME_FAILED = EC(420003, "create volume failed")
426-
ERR_MAP_VOLUME_FAILED = EC(420004, "map volume to NBD device failed")
427-
ERR_ENCODE_VOLUME_INFO_TO_JSON_FAILED = EC(420005, "encode volume info to json failed")
428-
ERR_UNMAP_VOLUME_FAILED = EC(420006, "unmap volume failed")
429-
ERR_OLD_TARGET_DAEMON_IS_ABNORMAL = EC(420007, "old target daemon is abnormal")
430-
ERR_TARGET_DAEMON_IS_ABNORMAL = EC(420008, "target daemon is abnormal")
422+
ERR_VOLUME_ALREADY_MAPPED = EC(420000, "volume already mapped")
423+
ERR_VOLUME_CONTAINER_LOSED = EC(420001, "volume container is losed")
424+
ERR_VOLUME_CONTAINER_ABNORMAL = EC(420002, "volume container is abnormal")
425+
ERR_CREATE_VOLUME_FAILED = EC(420003, "create volume failed")
426+
ERR_MAP_VOLUME_FAILED = EC(420004, "map volume to NBD device failed")
427+
ERR_ENCODE_VOLUME_INFO_TO_JSON_FAILED = EC(420005, "encode volume info to json failed")
428+
ERR_UNMAP_VOLUME_FAILED = EC(420006, "unmap volume failed")
429+
ERR_OLD_TARGET_DAEMON_IS_ABNORMAL = EC(420007, "old target daemon is abnormal")
430+
ERR_TARGET_DAEMON_IS_ABNORMAL = EC(420008, "target daemon is abnormal")
431+
ERR_OLD_SPDK_TARGET_DAEMON_IS_ABNORMAL = EC(420008, "old spdk target daemon is abnormal")
432+
ERR_SPDK_TARGET_DAEMON_IS_ABNORMAL = EC(420009, "spdk target daemon is abnormal")
431433

432434
// 430: common (curvefs client)
433435
ERR_FS_PATH_ALREADY_MOUNTED = EC(430000, "path already mounted")

internal/playbook/factory.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ const (
121121
DELETE_TARGET
122122
LIST_TARGETS
123123

124+
// bs/target
125+
START_SPDK_TARGET_DAEMON
126+
STOP_SPDK_TARGET_DAEMON
127+
ADD_SPDK_TARGET
128+
DELETE_SPDK_TARGET
129+
LIST_SPDK_TARGETS
130+
124131
// fs
125132
CHECK_CLIENT_S3
126133
MOUNT_FILESYSTEM
@@ -275,6 +282,7 @@ func (p *Playbook) createTasks(step *PlaybookStep) (*tasks.Tasks, error) {
275282
t, err = bs.NewMapTask(curveadm, config.GetCC(i))
276283
case UNMAP_IMAGE:
277284
t, err = bs.NewUnmapTask(curveadm, nil)
285+
278286
// bs/target
279287
case START_TARGET_DAEMON:
280288
t, err = bs.NewStartTargetDaemonTask(curveadm, config.GetCC(i))
@@ -286,6 +294,19 @@ func (p *Playbook) createTasks(step *PlaybookStep) (*tasks.Tasks, error) {
286294
t, err = bs.NewDeleteTargetTask(curveadm, nil)
287295
case LIST_TARGETS:
288296
t, err = bs.NewListTargetsTask(curveadm, nil)
297+
298+
// bs/target
299+
case START_SPDK_TARGET_DAEMON:
300+
t, err = bs.NewStartSpdkTargetDaemonTask(curveadm, config.GetCC(i))
301+
case STOP_SPDK_TARGET_DAEMON:
302+
t, err = bs.NewStopSpdkTargetDaemonTask(curveadm, nil)
303+
case ADD_SPDK_TARGET:
304+
t, err = bs.NewAddSpdkTargetTask(curveadm, config.GetCC(i))
305+
case DELETE_SPDK_TARGET:
306+
t, err = bs.NewDeleteSpdkTargetTask(curveadm, nil)
307+
case LIST_SPDK_TARGETS:
308+
t, err = bs.NewListSpdkTargetsTask(curveadm, nil)
309+
289310
// fs
290311
case CHECK_CLIENT_S3:
291312
t, err = checker.NewClientS3ConfigureTask(curveadm, config.GetCC(i))
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (c) 2021 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Project: CurveAdm
19+
* Created Date: 2022-02-08
20+
* Author: Jingli Chen (Wine93)
21+
*/
22+
23+
package scripts
24+
25+
/*
26+
* Usage: target USER VOLUME CREATE SIZE
27+
* Example: target curve test true 10
28+
* See Also: https://linux.die.net/man/8/tgtadm
29+
*/
30+
31+
var ADD__SPDK_TARGET = `
32+
#!/usr/bin/env bash
33+
34+
g_sockname=$1
35+
g_volume=$2
36+
g_originbdev=$3
37+
g_curvebdev=$4
38+
g_rpcpath=$5
39+
g_blocksize=$6
40+
g_cdbpath=$7
41+
g_isexclusive=$8
42+
g_targetip=$9
43+
g_targetport=$10
44+
g_initiatorip=$11
45+
g_initiatormask=$12
46+
g_user=$13
47+
g_create=$14
48+
g_size=%15
49+
g_volumename=%16
50+
51+
mkdir -p /curvebs/nebd/data/lock
52+
touch /etc/curve/curvetab
53+
54+
mkdir -p /curvebs/nebd/data/lock
55+
touch /etc/curve/curvetab
56+
if [ $g_create == "true" ]; then
57+
output=$(curve_ops_tool create -userName=$g_user -fileName=$g_volume -fileLength=$g_size)
58+
if [ $? -ne 0 ]; then
59+
if [ "$output" != "CreateFile fail with errCode: 101" ]; then
60+
exit 1
61+
fi
62+
fi
63+
fi
64+
if ${g_rpcpath} -s ${g_sockname} iscsi_get_target_nodes >/dev/null | grep "$g_curvebdev" | grep name >/dev/null; then
65+
echo "spdk target is already created, please try anther name"
66+
exit 1
67+
fi
68+
${g_rpcpath} -s ${g_sockname} bdev_aio_create ${g_volume} ${g_originbdev} 512 >/dev/null
69+
${g_rpcpath} -s ${g_sockname} bdev_cdb_create -b ${g_curvebdev} --cbd ${g_cbdpath} --exclusive=${g_isexclusive} --blocksize=${g_blocksize} >/dev/null
70+
${g_rpcpath} -s ${g_sockname} bdev_ocf_create bdev_ocf_create myocf wb ${g_originbdev} > /dev/null
71+
${g_rpcpath} -s ${g_sockname} iscsi_create_portal_group 1 ${g_targetip}:${g_targetport} > /dev/null
72+
${g_rpcpath} -s ${g_sockname} iscsi_create_initiator_group 2 ANY ${g_initiatorip}/${g_initiatormask} > /dev/null
73+
74+
${g_rpcpath} -s ${g_sockname} iscsi_create_target_node ${g_volumename} "Data Disk1" "myocf:0 ${g_originbdev}:1" 1:2 64 -d > /dev/null
75+
76+
77+
exit 0
78+
79+
`
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2021 NetEase Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*
18+
* Project: CurveAdm
19+
* Created Date: 2022-02-08
20+
* Author: Jingli Chen (Wine93)
21+
*/
22+
23+
package scripts
24+
25+
/*
26+
* Usage: target USER VOLUME CREATE SIZE
27+
* Example: target curve test true 10
28+
* See Also: https://linux.die.net/man/8/tgtadm
29+
*/
30+
31+
var SPDK_TARGET = `
32+
#!/usr/bin/env bash
33+
34+
g_binarypath=$1
35+
g_cpumask=$2
36+
g_sockname=$3
37+
g_iscsi_log=$4
38+
39+
mkdir -p /curvebs/nebd/data/lock
40+
touch /etc/curve/curvetab
41+
42+
process_name="iscsi_tgt"
43+
44+
if ps aux | grep -v grep | grep "$process_name" >/dev/null; then
45+
echo "spdk iscsi_tgt has already been started, now exit!"
46+
exit 1
47+
fi
48+
49+
nohup ${g_binarypath} -m ${g_cpumask} -r ${g_sockname} > ${g_iscsi_log} 2>&1 &
50+
51+
i=1
52+
while true
53+
do
54+
result=$(cat $VSDK_LOG_FILE | grep "please run rpc")
55+
if [[ "$result" != "" ]]; then
56+
i=0
57+
break
58+
else
59+
sleep 0.1
60+
i++
61+
fi
62+
if [ "$i" -ge 50 ]; then
63+
break
64+
fi
65+
done
66+
67+
if [ "$i" -eq 0]; then
68+
echo "spdk iscsi_tgt started success!"
69+
else
70+
echo "wait for 5s, spdk iscsi_tgt has not launched, please try again!"
71+
exit 1
72+
fi
73+
74+
exit 0
75+
76+
`

internal/task/step/daemon.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ type AddDaemonTask struct {
7777

7878
type DelDaemonTask struct {
7979
ContainerId *string
80+
Cmd string
81+
Args []string
82+
TaskName string
8083
Tid string
8184
MemStorage *utils.SafeMap
8285
module.ExecOptions

0 commit comments

Comments
 (0)