@@ -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