-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NBD integration into controller and replica #1109
base: master
Are you sure you want to change the base?
Changes from all commits
c7338a5
8e44b12
4e39313
bf4a704
7708e07
7ad1a3d
21b354b
d882753
2be7692
7206bc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,6 +7,8 @@ mount --rbind /host/dev /dev | |||||||||||||||||||||||||||||||||||||||
volume=$1 | ||||||||||||||||||||||||||||||||||||||||
size=$2 | ||||||||||||||||||||||||||||||||||||||||
frontend=$3 | ||||||||||||||||||||||||||||||||||||||||
frontendStreams=$4 | ||||||||||||||||||||||||||||||||||||||||
nbdEnabled=$5 | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if [ -z $volume ] | ||||||||||||||||||||||||||||||||||||||||
then | ||||||||||||||||||||||||||||||||||||||||
|
@@ -28,6 +30,23 @@ then | |||||||||||||||||||||||||||||||||||||||
frontend="tgt-blockdev" | ||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if [ -z $frontendStreams ] | ||||||||||||||||||||||||||||||||||||||||
then | ||||||||||||||||||||||||||||||||||||||||
echo Use default frontend streams. No frontend nbd streams | ||||||||||||||||||||||||||||||||||||||||
frontendStreams="" | ||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||
frontendStreams="--frontend-streams "$frontendStreams | ||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+33
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validation for frontendStreams parameter The script should validate the format of frontendStreams parameter to ensure it meets the expected format. if [ -z $frontendStreams ]
then
echo Use default frontend streams. No frontend nbd streams
frontendStreams=""
else
+ # Validate format: should be a positive integer
+ if ! [[ $frontendStreams =~ ^[1-9][0-9]*$ ]]; then
+ echo "Error: frontendStreams must be a positive integer"
+ exit 1
+ fi
frontendStreams="--frontend-streams "$frontendStreams
fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
if [ -z $nbdEnabled ] | ||||||||||||||||||||||||||||||||||||||||
then | ||||||||||||||||||||||||||||||||||||||||
echo Use default dataserver. Dataconn dataserver | ||||||||||||||||||||||||||||||||||||||||
nbdEnabled="" | ||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||
nbdEnabled="--nbd-enabled "$nbdEnabled | ||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+41
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add validation for nbdEnabled parameter The script should validate the nbdEnabled parameter to ensure it's a valid boolean value. if [ -z $nbdEnabled ]
then
echo Use default dataserver. Dataconn dataserver
nbdEnabled=""
else
+ # Validate boolean value
+ if ! [[ "$nbdEnabled" =~ ^(true|false|0|1)$ ]]; then
+ echo "Error: nbdEnabled must be true/false or 0/1"
+ exit 1
+ fi
nbdEnabled="--nbd-enabled "$nbdEnabled
fi 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
function start() { | ||||||||||||||||||||||||||||||||||||||||
set +e | ||||||||||||||||||||||||||||||||||||||||
while true; | ||||||||||||||||||||||||||||||||||||||||
|
@@ -44,12 +63,12 @@ function start() { | |||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
tgtd -f 2>&1 | tee /var/log/tgtd.log & | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
longhorn-instance-manager process create --name "$volume-r" --binary /usr/local/bin/longhorn --port-count 15 --port-args "--listen,localhost:" -- replica /volume/ "--size" $size | ||||||||||||||||||||||||||||||||||||||||
longhorn-instance-manager process create --name "$volume-r" --binary /usr/local/bin/longhorn --port-count 15 --port-args "--listen,localhost:" -- replica /volume/ "--size" $size $nbdEnabled | ||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for instance manager process creation The script should check the return status of instance manager process creation commands and handle failures appropriately. - longhorn-instance-manager process create --name "$volume-r" --binary /usr/local/bin/longhorn --port-count 15 --port-args "--listen,localhost:" -- replica /volume/ "--size" $size $nbdEnabled
+ if ! longhorn-instance-manager process create --name "$volume-r" --binary /usr/local/bin/longhorn --port-count 15 --port-args "--listen,localhost:" -- replica /volume/ "--size" $size $nbdEnabled; then
+ echo "Error: Failed to create replica process"
+ exit 1
+ fi
# wait for the replica to be started
sleep 5
- longhorn-instance-manager process create --name "$volume-e" --binary /usr/local/bin/longhorn --port-count 1 --port-args "--listen,localhost:" -- controller $volume --frontend $frontend "--size" $size "--current-size" $size --replica tcp://localhost:10000 $nbdEnabled $frontendStreams
+ if ! longhorn-instance-manager process create --name "$volume-e" --binary /usr/local/bin/longhorn --port-count 1 --port-args "--listen,localhost:" -- controller $volume --frontend $frontend "--size" $size "--current-size" $size --replica tcp://localhost:10000 $nbdEnabled $frontendStreams; then
+ echo "Error: Failed to create controller process"
+ exit 1
+ fi Also applies to: 71-71 |
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
# wait for the replica to be started | ||||||||||||||||||||||||||||||||||||||||
sleep 5 | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
longhorn-instance-manager process create --name "$volume-e" --binary /usr/local/bin/longhorn --port-count 1 --port-args "--listen,localhost:" -- controller $volume --frontend $frontend "--size" $size "--current-size" $size --replica tcp://localhost:10000 | ||||||||||||||||||||||||||||||||||||||||
longhorn-instance-manager process create --name "$volume-e" --binary /usr/local/bin/longhorn --port-count 1 --port-args "--listen,localhost:" -- controller $volume --frontend $frontend "--size" $size "--current-size" $size --replica tcp://localhost:10000 $nbdEnabled $frontendStreams | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
start & | ||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,12 @@ func New(factories map[string]types.BackendFactory) types.BackendFactory { | |
} | ||
} | ||
|
||
func (d *Factory) Create(volumeName, address string, dataServerProtocol types.DataServerProtocol, engineToReplicaTimeout time.Duration) (types.Backend, error) { | ||
func (d *Factory) Create(volumeName, address string, dataServerProtocol types.DataServerProtocol, engineToReplicaTimeout time.Duration, nbdEnabled int) (types.Backend, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using a more semantic type for nbdEnabled Using Consider one of these alternatives: -func (d *Factory) Create(volumeName, address string, dataServerProtocol types.DataServerProtocol, engineToReplicaTimeout time.Duration, nbdEnabled int) (types.Backend, error) {
+// Option 1: Use boolean
+func (d *Factory) Create(volumeName, address string, dataServerProtocol types.DataServerProtocol, engineToReplicaTimeout time.Duration, nbdEnabled bool) (types.Backend, error) {
+// Option 2: Use custom type for clarity
+type NBDMode int
+const (
+ NBDDisabled NBDMode = iota
+ NBDEnabled
+)
+func (d *Factory) Create(volumeName, address string, dataServerProtocol types.DataServerProtocol, engineToReplicaTimeout time.Duration, nbdMode NBDMode) (types.Backend, error) {
|
||
parts := strings.SplitN(address, "://", 2) | ||
|
||
if len(parts) == 2 { | ||
if factory, ok := d.factories[parts[0]]; ok { | ||
return factory.Create(volumeName, parts[1], dataServerProtocol, engineToReplicaTimeout) | ||
return factory.Create(volumeName, parts[1], dataServerProtocol, engineToReplicaTimeout, nbdEnabled) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider version pinning and build verification for libnbd
The current implementation downloads libnbd without verifying the checksum. Additionally, consider pinning to a specific version in an environment variable for easier updates.
📝 Committable suggestion