Merge pull request #25 from rootfs/node

WIP node server: don't persist vol
This commit is contained in:
Serguei Bezverkhi 2018-03-07 11:40:48 -05:00 committed by GitHub
commit 4b3ebc171b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 29 deletions

View File

@ -19,7 +19,6 @@ package rbd
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"strings" "strings"
"github.com/golang/glog" "github.com/golang/glog"
@ -91,43 +90,41 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if err := diskMounter.FormatAndMount(devicePath, targetPath, fsType, options); err != nil { if err := diskMounter.FormatAndMount(devicePath, targetPath, fsType, options); err != nil {
return nil, err return nil, err
} }
// Storing volInfo into a persistent file
if err := persistVolInfo(req.GetVolumeId(), path.Join(PluginFolder, "node"), volOptions); err != nil {
glog.Warningf("rbd: failed to store volInfo with error: %v", err)
}
return &csi.NodePublishVolumeResponse{}, nil return &csi.NodePublishVolumeResponse{}, nil
} }
func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) { func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
targetPath := req.GetTargetPath() targetPath := req.GetTargetPath()
volumeID := req.GetVolumeId() mounter := mount.New("")
volOptions := &rbdVolumeOptions{}
if err := loadVolInfo(volumeID, path.Join(PluginFolder, "node"), volOptions); err != nil {
return nil, err
}
volName := volOptions.VolName
notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath) notMnt, err := mounter.IsLikelyNotMountPoint(targetPath)
if err != nil { if err != nil {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
if notMnt { if notMnt {
return nil, status.Error(codes.NotFound, "Volume not mounted") return nil, status.Error(codes.NotFound, "Volume not mounted")
} }
// Unmounting the image
err = mount.New("").Unmount(req.GetTargetPath()) devicePath, cnt, err := mount.GetDeviceNameFromMount(mounter, targetPath)
if err != nil { if err != nil {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
// Unmapping rbd device
glog.V(4).Infof("deleting volume %s", volName) // Unmounting the image
if err := detachRBDImage(volOptions); err != nil { err = mounter.Unmount(targetPath)
glog.V(3).Infof("failed to unmap rbd device: %s with error: %v", volOptions.VolName, err) if err != nil {
return nil, err return nil, status.Error(codes.Internal, err.Error())
} }
// Removing persistent storage file for the unmapped volume
if err := deleteVolInfo(volumeID, path.Join(PluginFolder, "node")); err != nil { cnt--
if cnt != 0 {
return &csi.NodeUnpublishVolumeResponse{}, nil
}
// Unmapping rbd device
if err := detachRBDDevice(devicePath); err != nil {
glog.V(3).Infof("failed to unmap rbd device: %s with error: %v", devicePath, err)
return nil, err return nil, err
} }

View File

@ -256,19 +256,14 @@ func attachRBDImage(volOptions *rbdVolumeOptions) (string, error) {
return devicePath, nil return devicePath, nil
} }
func detachRBDImage(volOptions *rbdVolumeOptions) error { func detachRBDDevice(devicePath string) error {
var err error var err error
var output []byte var output []byte
image := volOptions.VolName glog.V(3).Infof("rbd: unmap device %s", devicePath)
glog.V(1).Infof("rbd: unmap device %s", image)
id := volOptions.UserID
secret := volOptions.UserSecret
output, err = execCommand("rbd", []string{ output, err = execCommand("rbd", []string{"unmap", devicePath})
"unmap", image, "--id", id, "--key=" + secret})
if err != nil { if err != nil {
glog.V(1).Infof("rbd: unmap error %v, rbd output: %s", err, string(output))
return fmt.Errorf("rbd: unmap failed %v, rbd output: %s", err, string(output)) return fmt.Errorf("rbd: unmap failed %v, rbd output: %s", err, string(output))
} }