Compare commits

..

No commits in common. "7f8f7ded52b2dad42dfb168e115f6c872176ccff" and "a1c7cc3d8d762e9a1eeec1d4d014bd9ba0f46ddf" have entirely different histories.

2 changed files with 30 additions and 40 deletions

View File

@ -97,15 +97,6 @@ func GetConnectionParams(params map[string]string) (map[string]string, error)
}
case []string:
etcdUrl = config["etcd_address"].([]string)
case []interface{}:
for _, url := range config["etcd_address"].([]interface{})
{
s, ok := url.(string)
if (ok)
{
etcdUrl = append(etcdUrl, s)
}
}
}
if (len(etcdUrl) == 0)
{
@ -114,9 +105,8 @@ func GetConnectionParams(params map[string]string) (map[string]string, error)
return ctxVars, nil
}
func system(program string, args ...string) ([]byte, []byte, error)
func system(program string, args ...string) ([]byte, error)
{
klog.Infof("Running "+program+" "+strings.Join(args, " "))
c := exec.Command(program, args...)
var stdout, stderr bytes.Buffer
c.Stdout, c.Stderr = &stdout, &stderr
@ -125,9 +115,9 @@ func system(program string, args ...string) ([]byte, []byte, error)
{
stdoutStr, stderrStr := string(stdout.Bytes()), string(stderr.Bytes())
klog.Errorf(program+" "+strings.Join(args, " ")+" failed: %s, status %s\n", stdoutStr+stderrStr, err)
return nil, nil, status.Error(codes.Internal, stdoutStr+stderrStr+" (status "+err.Error()+")")
return nil, status.Error(codes.Internal, stdoutStr+stderrStr+" (status "+err.Error()+")")
}
return stdout.Bytes(), stderr.Bytes(), nil
return stdout.Bytes(), nil
}
func invokeCLI(ctxVars map[string]string, args []string) ([]byte, error)
@ -136,8 +126,7 @@ func invokeCLI(ctxVars map[string]string, args []string) ([]byte, error)
{
args = append(args, "--config_path", ctxVars["configPath"])
}
stdout, _, err := system("/usr/bin/vitastor-cli", args...)
return stdout, err
return system("/usr/bin/vitastor-cli", args...)
}
// Create the volume

View File

@ -7,7 +7,6 @@ import (
"context"
"errors"
"encoding/json"
"fmt"
"os"
"os/exec"
"path/filepath"
@ -155,13 +154,8 @@ func (ns *NodeServer) mapNbd(volName string, ctxVars map[string]string, readonly
{
args = append(args, "--readonly", "1")
}
stdout, stderr, err := system("/usr/bin/vitastor-nbd", args...)
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
dev, err := system("/usr/bin/vitastor-nbd", args...)
return strings.TrimSpace(string(dev)), err
}
func (ns *NodeServer) unmapNbd(devicePath string)
@ -227,7 +221,7 @@ func startStorageDaemon(vdpaId, volName, pidFile, configPath string, readonly bo
{
writable = "false"
}
_, _, err := system(
_, err := system(
"/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,
)
@ -240,7 +234,7 @@ func (ns *NodeServer) mapVduse(volName string, ctxVars map[string]string, readon
stateFd, err := os.CreateTemp(ns.stateDir, "vitastor-vduse-*.json")
if (err != nil)
{
return "", "", err
return "", "", status.Error(codes.Internal, err.Error())
}
stateFile := stateFd.Name()
stateFd.Close()
@ -252,7 +246,7 @@ func (ns *NodeServer) mapVduse(volName string, ctxVars map[string]string, readon
if (err == nil)
{
// 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)
{
// Find block device name
@ -283,14 +277,21 @@ func (ns *NodeServer) mapVduse(volName string, ctxVars map[string]string, readon
}
}
}
if (err != nil)
{
err = status.Error(codes.Internal, err.Error())
}
}
killErr := killByPidFile(pidFile)
if (killErr != nil)
if (err != nil)
{
klog.Errorf("Failed to kill started qemu-storage-daemon: %v", killErr)
killErr := killByPidFile(pidFile)
if (killErr != nil)
{
klog.Errorf("Failed to kill started qemu-storage-daemon: %v", killErr)
}
os.Remove(stateFile)
os.Remove(pidFile)
}
os.Remove(stateFile)
os.Remove(pidFile)
}
return "", "", err
}
@ -336,7 +337,7 @@ func (ns *NodeServer) unmapVduseById(vdpaId string)
}
else
{
_, _, _ = system("/sbin/vdpa", "-j", "dev", "del", vdpaId)
_, _ = system("/sbin/vdpa", "-j", "dev", "del", vdpaId)
}
stateFile := ns.stateDir + vdpaId + ".json"
os.Remove(stateFile)
@ -376,7 +377,7 @@ func (ns *NodeServer) restoreVduseDaemons()
}
devList := make(map[string]interface{})
// 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)
{
return
@ -455,13 +456,13 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if (err != nil)
{
klog.Errorf("failed to create block device mount target %s with error: %v", targetPath, err)
return nil, err
return nil, status.Error(codes.Internal, err.Error())
}
err = pathFile.Close()
if (err != nil)
{
klog.Errorf("failed to close %s with error: %v", targetPath, err)
return nil, err
return nil, status.Error(codes.Internal, err.Error())
}
}
else
@ -470,13 +471,13 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if (err != nil)
{
klog.Errorf("failed to create fs mount target %s with error: %v", targetPath, err)
return nil, err
return nil, status.Error(codes.Internal, err.Error())
}
}
}
else
{
return nil, err
return nil, status.Error(codes.Internal, err.Error())
}
}
@ -596,7 +597,7 @@ unmap:
{
ns.unmapVduseById(vdpaId)
}
return nil, err
return nil, status.Error(codes.Internal, err.Error())
}
// NodeUnpublishVolume unmounts the volume from the target path
@ -611,7 +612,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
{
return nil, status.Error(codes.NotFound, "Target path not found")
}
return nil, err
return nil, status.Error(codes.Internal, err.Error())
}
if (devicePath == "")
{
@ -624,7 +625,7 @@ func (ns *NodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
err = mount.CleanupMountPoint(targetPath, ns.mounter, false)
if (err != nil)
{
return nil, err
return nil, status.Error(codes.Internal, err.Error())
}
// unmap NBD device
if (refCount == 1)