Skip to content

Commit

Permalink
Add WriteVolumeCache API to v1beta2 Volume API group
Browse files Browse the repository at this point in the history
add writevolumecache api to csi-proxy v1beta2 volume API group
  • Loading branch information
jingxu97 committed Oct 9, 2020
1 parent 897abed commit 934cf70
Show file tree
Hide file tree
Showing 15 changed files with 2,186 additions and 60 deletions.
2 changes: 1 addition & 1 deletion client/api/volume/v1beta1/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ message VolumeIDFromMountRequest {
message VolumeIDFromMountResponse {
// Mount
string volume_id = 1;
}
}
1 change: 1 addition & 0 deletions integrationtests/volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ func simpleE2e(t *testing.T) {
if err != nil {
t.Fatalf("Volume id %s mount to path %s failed. Error: %v", volumeID, mountPath, err)
}

// Dismount the volume
dismountVolumeRequest := &v1alpha1.DismountVolumeRequest{
VolumeId: volumeID,
Expand Down
10 changes: 10 additions & 0 deletions internal/os/volume/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,16 @@ func (VolAPIImplementor) FormatVolume(volumeID string) (err error) {
return nil
}

// WriteVolumeCache - Writes the file system cache to disk where given file path is located
func (VolAPIImplementor) WriteVolumeCache(filePath string) (err error) {
cmd := fmt.Sprintf("Get-Volume -FilePath \"%s\" | Write-Volumecache", filePath)
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
}

// IsVolumeFormatted - Check if the volume is formatted with the pre specified filesystem(typically ntfs).
func (VolAPIImplementor) IsVolumeFormatted(volumeID string) (bool, error) {
cmd := fmt.Sprintf("(Get-Volume -UniqueId \"%s\" -ErrorAction Stop).FileSystemType", volumeID)
Expand Down
7 changes: 7 additions & 0 deletions internal/server/volume/api_group_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions internal/server/volume/internal/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ type FormatVolumeRequest struct {
type FormatVolumeResponse struct {
}

type WriteVolumeCacheRequest struct {
FilePath string
}

type WriteVolumeCacheResponse struct {
}

type DismountVolumeRequest struct {
VolumeId string
Path string
Expand Down
1 change: 1 addition & 0 deletions internal/server/volume/internal/types_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/server/volume/internal/v1beta2/conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package v1beta2

// Add manual conversion functions here to override automatic conversion functions
408 changes: 408 additions & 0 deletions internal/server/volume/internal/v1beta2/conversion_generated.go

Large diffs are not rendered by default.

218 changes: 218 additions & 0 deletions internal/server/volume/internal/v1beta2/server_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions internal/server/volume/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type API interface {
GetVolumeDiskNumber(volumeID string) (int64, error)
// GetVolumeIDFromMount returns the volume id of a given mount
GetVolumeIDFromMount(mount string) (string, error)
// WriteVolumeCache writes volume cache to disk
WriteVolumeCache(filePath string) error
}

func NewServer(hostAPI API) (*Server, error) {
Expand Down Expand Up @@ -137,7 +139,24 @@ func (s *Server) FormatVolume(context context.Context, request *internal.FormatV
klog.Errorf("failed FormatVolume %v", err)
return response, err
}
return response, nil
}

func (s *Server) WriteVolumeCache(context context.Context, request *internal.WriteVolumeCacheRequest, version apiversion.Version) (*internal.WriteVolumeCacheResponse, error) {
klog.V(4).Infof("calling WriteVolumeCache with request: %+v", request)
response := &internal.WriteVolumeCacheResponse{}

filePath := request.FilePath
if filePath == "" {
klog.Errorf("file path empty")
return response, fmt.Errorf("file path empty")
}

err := s.hostAPI.WriteVolumeCache(filePath)
if err != nil {
klog.Errorf("failed WriteVolumeCache %v", err)
return response, err
}
return response, nil
}

Expand Down
4 changes: 4 additions & 0 deletions internal/server/volume/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (volumeAPI *fakeVolumeAPI) VolumeStats(volumeID string) (int64, int64, erro
return -1, -1, nil
}

func (volumeAPI *fakeVolumeAPI) WriteVolumeCache(filePath string) error {
return nil
}

func TestListVolumesOnDisk(t *testing.T) {
v1alpha1, err := apiversion.NewVersion("v1alpha1")
if err != nil {
Expand Down
Loading

0 comments on commit 934cf70

Please sign in to comment.