Skip to content

Commit 91e2abe

Browse files
authored
Merge pull request #633 from jingxu97/oct/dismount
Modify NodeUnstageVolume call for Windows
2 parents 27b29d6 + c3ca5bc commit 91e2abe

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

pkg/gce-pd-csi-driver/utils_windows.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func cleanupStagePath(path string, m *mount.SafeFormatAndMount) error {
6868
if !ok {
6969
return fmt.Errorf("could not cast to csi proxy class")
7070
}
71-
return proxy.RemovePluginDir(path)
71+
return proxy.UnmountDevice(path)
7272
}
7373

7474
// search Windows disk number by volumeID

pkg/mount-manager/safe-mounter_windows.go

+30-4
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,38 @@ func (mounter *CSIProxyMounter) RemovePodDir(target string) error {
124124
return nil
125125
}
126126

127-
// Delete the given directory with plugin context. CSI proxy does a check for path prefix
127+
// UnmountDevice uses target path to find the volume id first, and then
128+
// call DismountVolume through csi-proxy. If succeeded, it will delete the given path
129+
// at last step. CSI proxy does a check for path prefix
128130
// based on context
129-
func (mounter *CSIProxyMounter) RemovePluginDir(target string) error {
131+
func (mounter *CSIProxyMounter) UnmountDevice(target string) error {
132+
target = mount.NormalizeWindowsPath(target)
133+
if exists, err := mounter.ExistsPath(target); !exists {
134+
return err
135+
}
136+
idRequest := &volumeapi.VolumeIDFromMountRequest{
137+
Mount: target,
138+
}
139+
idResponse, err := mounter.VolumeClient.GetVolumeIDFromMount(context.Background(), idRequest)
140+
if err != nil {
141+
return err
142+
}
143+
volumeId := idResponse.GetVolumeId()
144+
145+
dismountRequest := &volumeapi.DismountVolumeRequest{
146+
Path: target,
147+
VolumeId: volumeId,
148+
}
149+
_, err = mounter.VolumeClient.DismountVolume(context.Background(), dismountRequest)
150+
if err != nil {
151+
return err
152+
}
130153
rmdirRequest := &fsapi.RmdirRequest{
131-
Path: mount.NormalizeWindowsPath(target),
154+
Path: target,
132155
Context: fsapi.PathContext_PLUGIN,
133156
Force: true,
134157
}
135-
_, err := mounter.FsClient.Rmdir(context.Background(), rmdirRequest)
158+
_, err = mounter.FsClient.Rmdir(context.Background(), rmdirRequest)
136159
if err != nil {
137160
return err
138161
}
@@ -249,5 +272,8 @@ func (mounter *CSIProxyMounter) ExistsPath(path string) (bool, error) {
249272
&fsapi.PathExistsRequest{
250273
Path: mount.NormalizeWindowsPath(path),
251274
})
275+
if err != nil {
276+
return false, err
277+
}
252278
return isExistsResponse.Exists, err
253279
}

0 commit comments

Comments
 (0)