forked from vitalif/vitastor
Check for empty output of vitastor-nbd map (just in case)
parent
68553eabbb
commit
7f8f7ded52
|
@ -114,7 +114,7 @@ func GetConnectionParams(params map[string]string) (map[string]string, error)
|
||||||
return ctxVars, nil
|
return ctxVars, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func system(program string, args ...string) ([]byte, error)
|
func system(program string, args ...string) ([]byte, []byte, error)
|
||||||
{
|
{
|
||||||
klog.Infof("Running "+program+" "+strings.Join(args, " "))
|
klog.Infof("Running "+program+" "+strings.Join(args, " "))
|
||||||
c := exec.Command(program, args...)
|
c := exec.Command(program, args...)
|
||||||
|
@ -125,9 +125,9 @@ func system(program string, args ...string) ([]byte, error)
|
||||||
{
|
{
|
||||||
stdoutStr, stderrStr := string(stdout.Bytes()), string(stderr.Bytes())
|
stdoutStr, stderrStr := string(stdout.Bytes()), string(stderr.Bytes())
|
||||||
klog.Errorf(program+" "+strings.Join(args, " ")+" failed: %s, status %s\n", stdoutStr+stderrStr, err)
|
klog.Errorf(program+" "+strings.Join(args, " ")+" failed: %s, status %s\n", stdoutStr+stderrStr, err)
|
||||||
return nil, status.Error(codes.Internal, stdoutStr+stderrStr+" (status "+err.Error()+")")
|
return nil, nil, status.Error(codes.Internal, stdoutStr+stderrStr+" (status "+err.Error()+")")
|
||||||
}
|
}
|
||||||
return stdout.Bytes(), nil
|
return stdout.Bytes(), stderr.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func invokeCLI(ctxVars map[string]string, args []string) ([]byte, error)
|
func invokeCLI(ctxVars map[string]string, args []string) ([]byte, error)
|
||||||
|
@ -136,7 +136,8 @@ func invokeCLI(ctxVars map[string]string, args []string) ([]byte, error)
|
||||||
{
|
{
|
||||||
args = append(args, "--config_path", ctxVars["configPath"])
|
args = append(args, "--config_path", ctxVars["configPath"])
|
||||||
}
|
}
|
||||||
return system("/usr/bin/vitastor-cli", args...)
|
stdout, _, err := system("/usr/bin/vitastor-cli", args...)
|
||||||
|
return stdout, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the volume
|
// Create the volume
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -154,8 +155,13 @@ func (ns *NodeServer) mapNbd(volName string, ctxVars map[string]string, readonly
|
||||||
{
|
{
|
||||||
args = append(args, "--readonly", "1")
|
args = append(args, "--readonly", "1")
|
||||||
}
|
}
|
||||||
dev, err := system("/usr/bin/vitastor-nbd", args...)
|
stdout, stderr, err := system("/usr/bin/vitastor-nbd", args...)
|
||||||
return strings.TrimSpace(string(dev)), err
|
dev := strings.TrimSpace(string(stdout))
|
||||||
|
if (dev == "")
|
||||||
|
{
|
||||||
|
return "", fmt.Errorf("vitastor-nbd did not return the name of NBD device. output: %s", stderr)
|
||||||
|
}
|
||||||
|
return dev, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NodeServer) unmapNbd(devicePath string)
|
func (ns *NodeServer) unmapNbd(devicePath string)
|
||||||
|
@ -221,7 +227,7 @@ func startStorageDaemon(vdpaId, volName, pidFile, configPath string, readonly bo
|
||||||
{
|
{
|
||||||
writable = "false"
|
writable = "false"
|
||||||
}
|
}
|
||||||
_, err := system(
|
_, _, err := system(
|
||||||
"/usr/bin/qemu-storage-daemon", "--daemonize", "--pidfile", pidFile, "--blockdev", string(blockSpecJson),
|
"/usr/bin/qemu-storage-daemon", "--daemonize", "--pidfile", pidFile, "--blockdev", string(blockSpecJson),
|
||||||
"--export", "vduse-blk,id="+vdpaId+",node-name=disk1,name="+vdpaId+",num-queues=16,queue-size=128,writable="+writable,
|
"--export", "vduse-blk,id="+vdpaId+",node-name=disk1,name="+vdpaId+",num-queues=16,queue-size=128,writable="+writable,
|
||||||
)
|
)
|
||||||
|
@ -246,7 +252,7 @@ func (ns *NodeServer) mapVduse(volName string, ctxVars map[string]string, readon
|
||||||
if (err == nil)
|
if (err == nil)
|
||||||
{
|
{
|
||||||
// Add device to VDPA bus
|
// Add device to VDPA bus
|
||||||
_, err = system("/sbin/vdpa", "-j", "dev", "add", "name", vdpaId, "mgmtdev", "vduse")
|
_, _, err = system("/sbin/vdpa", "-j", "dev", "add", "name", vdpaId, "mgmtdev", "vduse")
|
||||||
if (err == nil)
|
if (err == nil)
|
||||||
{
|
{
|
||||||
// Find block device name
|
// Find block device name
|
||||||
|
@ -278,8 +284,6 @@ func (ns *NodeServer) mapVduse(volName string, ctxVars map[string]string, readon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (err != nil)
|
|
||||||
{
|
|
||||||
killErr := killByPidFile(pidFile)
|
killErr := killByPidFile(pidFile)
|
||||||
if (killErr != nil)
|
if (killErr != nil)
|
||||||
{
|
{
|
||||||
|
@ -288,7 +292,6 @@ func (ns *NodeServer) mapVduse(volName string, ctxVars map[string]string, readon
|
||||||
os.Remove(stateFile)
|
os.Remove(stateFile)
|
||||||
os.Remove(pidFile)
|
os.Remove(pidFile)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return "", "", err
|
return "", "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +336,7 @@ func (ns *NodeServer) unmapVduseById(vdpaId string)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_, _ = system("/sbin/vdpa", "-j", "dev", "del", vdpaId)
|
_, _, _ = system("/sbin/vdpa", "-j", "dev", "del", vdpaId)
|
||||||
}
|
}
|
||||||
stateFile := ns.stateDir + vdpaId + ".json"
|
stateFile := ns.stateDir + vdpaId + ".json"
|
||||||
os.Remove(stateFile)
|
os.Remove(stateFile)
|
||||||
|
@ -373,7 +376,7 @@ func (ns *NodeServer) restoreVduseDaemons()
|
||||||
}
|
}
|
||||||
devList := make(map[string]interface{})
|
devList := make(map[string]interface{})
|
||||||
// example output: {"dev":{"test1":{"type":"block","mgmtdev":"vduse","vendor_id":0,"max_vqs":16,"max_vq_size":128}}}
|
// example output: {"dev":{"test1":{"type":"block","mgmtdev":"vduse","vendor_id":0,"max_vqs":16,"max_vq_size":128}}}
|
||||||
devListJSON, err := system("/sbin/vdpa", "-j", "dev", "list")
|
devListJSON, _, err := system("/sbin/vdpa", "-j", "dev", "list")
|
||||||
if (err != nil)
|
if (err != nil)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue