Skip to content

Commit

Permalink
Merge pull request #92 from jingxu97/oct/dismount
Browse files Browse the repository at this point in the history
Add writevolumecache into Dismount API
  • Loading branch information
k8s-ci-robot authored Oct 15, 2020
2 parents b3cbf0c + 813c7bc commit 3b92646
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions internal/os/volume/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ func (VolAPIImplementor) FormatVolume(volumeID string) (err error) {

// WriteVolumeCache - Writes the file system cache to disk with the given volume id
func (VolAPIImplementor) WriteVolumeCache(volumeID string) (err error) {
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Write-Volumecache", volumeID)
out, err := runExec(cmd)
if err != nil {
return fmt.Errorf("error writing volume cache. cmd: %s, output: %s, error: %v", cmd, string(out), err)
}
return nil
return writeCache(volumeID)
}

// IsVolumeFormatted - Check if the volume is formatted with the pre specified filesystem(typically ntfs).
Expand Down Expand Up @@ -82,6 +77,9 @@ func (VolAPIImplementor) MountVolume(volumeID, path string) error {

// DismountVolume - unmounts the volume path by removing the partition access path
func (VolAPIImplementor) DismountVolume(volumeID, path string) error {
if err := writeCache(volumeID); err != nil {
return err
}
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Get-Partition | Remove-PartitionAccessPath -AccessPath %s", volumeID, path)
out, err := runExec(cmd)
if err != nil {
Expand Down Expand Up @@ -217,3 +215,12 @@ func getTarget(mount string) (string, error) {

return volumeString, nil
}

func writeCache(volumeID string) error {
cmd := fmt.Sprintf("Get-Volume -UniqueId \"%s\" | Write-Volumecache", volumeID)
out, err := runExec(cmd)
if err != nil {
return fmt.Errorf("error writing volume cache. cmd: %s, output: %s, error: %v", cmd, string(out), err)
}
return nil
}

0 comments on commit 3b92646

Please sign in to comment.