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 (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"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 {
|
||||
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
|
||||
}
|
||||
|
||||
func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
|
||||
targetPath := req.GetTargetPath()
|
||||
volumeID := req.GetVolumeId()
|
||||
volOptions := &rbdVolumeOptions{}
|
||||
if err := loadVolInfo(volumeID, path.Join(PluginFolder, "node"), volOptions); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
volName := volOptions.VolName
|
||||
mounter := mount.New("")
|
||||
|
||||
notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath)
|
||||
notMnt, err := mounter.IsLikelyNotMountPoint(targetPath)
|
||||
if err != nil {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
if notMnt {
|
||||
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 {
|
||||
return nil, status.Error(codes.Internal, err.Error())
|
||||
}
|
||||
// Unmapping rbd device
|
||||
glog.V(4).Infof("deleting volume %s", volName)
|
||||
if err := detachRBDImage(volOptions); err != nil {
|
||||
glog.V(3).Infof("failed to unmap rbd device: %s with error: %v", volOptions.VolName, err)
|
||||
return nil, err
|
||||
|
||||
// Unmounting the image
|
||||
err = mounter.Unmount(targetPath)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -256,19 +256,14 @@ func attachRBDImage(volOptions *rbdVolumeOptions) (string, error) {
|
||||
return devicePath, nil
|
||||
}
|
||||
|
||||
func detachRBDImage(volOptions *rbdVolumeOptions) error {
|
||||
func detachRBDDevice(devicePath string) error {
|
||||
var err error
|
||||
var output []byte
|
||||
|
||||
image := volOptions.VolName
|
||||
glog.V(1).Infof("rbd: unmap device %s", image)
|
||||
id := volOptions.UserID
|
||||
secret := volOptions.UserSecret
|
||||
glog.V(3).Infof("rbd: unmap device %s", devicePath)
|
||||
|
||||
output, err = execCommand("rbd", []string{
|
||||
"unmap", image, "--id", id, "--key=" + secret})
|
||||
output, err = execCommand("rbd", []string{"unmap", devicePath})
|
||||
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))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user