mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-22 14:20:19 +00:00
node server: don't persist vol
Signed-off-by: Huamin Chen <hchen@redhat.com>
This commit is contained in:
parent
c7ba5a6f8b
commit
9d4b49b54b
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user