/
filesystem_trim.go
161 lines (126 loc) · 4.38 KB
/
filesystem_trim.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
Package sdk is the gRPC implementation of the SDK gRPC server
Copyright 2018 Portworx
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package sdk
import (
"context"
"github.com/libopenstorage/openstorage/api"
"github.com/libopenstorage/openstorage/volume"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// FilesystemTrimServer is an implementation of the gRPC OpenStorageFilesystemTrim interface
type FilesystemTrimServer struct {
server serverAccessor
}
func (s *FilesystemTrimServer) driver(ctx context.Context) volume.VolumeDriver {
return s.server.driver(ctx)
}
// Start a filesystem trim operation on a mounted volume
func (s *FilesystemTrimServer) Start(
ctx context.Context,
req *api.SdkFilesystemTrimStartRequest,
) (*api.SdkFilesystemTrimStartResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
var err error
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply a volume id")
}
if len(req.GetMountPath()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply a volume mount path")
}
r, err := s.driver(ctx).FilesystemTrimStart(req)
return r, err
}
// Status of a filesystem trim operation
func (s *FilesystemTrimServer) Status(
ctx context.Context,
req *api.SdkFilesystemTrimStatusRequest,
) (*api.SdkFilesystemTrimStatusResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
var err error
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply a volume id")
}
if len(req.GetMountPath()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply a volume mount path")
}
r, err := s.driver(ctx).FilesystemTrimStatus(req)
return r, err
}
// Status of auto fs trim operation
func (s *FilesystemTrimServer) AutoFSTrimStatus(
ctx context.Context,
req *api.SdkAutoFSTrimStatusRequest,
) (*api.SdkAutoFSTrimStatusResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
r, err := s.driver(ctx).AutoFilesystemTrimStatus(req)
return r, err
}
// Usage of auto fs trim
func (s *FilesystemTrimServer) AutoFSTrimUsage(
ctx context.Context,
req *api.SdkAutoFSTrimUsageRequest,
) (*api.SdkAutoFSTrimUsageResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
r, err := s.driver(ctx).AutoFilesystemTrimUsage(req)
return r, err
}
// Stop the background filesystem trim operation on a volume, if any
func (s *FilesystemTrimServer) Stop(
ctx context.Context,
req *api.SdkFilesystemTrimStopRequest,
) (*api.SdkFilesystemTrimStopResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
var err error
if len(req.GetVolumeId()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply a volume id")
}
if len(req.GetMountPath()) == 0 {
return nil, status.Error(codes.InvalidArgument, "Must supply a volume mount path")
}
r, err := s.driver(ctx).FilesystemTrimStop(req)
return r, err
}
// Push a job to of auto fstrim queue
func (s *FilesystemTrimServer) AutoFSTrimPush(
ctx context.Context,
req *api.SdkAutoFSTrimPushRequest,
) (*api.SdkAutoFSTrimPushResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
r, err := s.driver(ctx).AutoFilesystemTrimPush(req)
return r, err
}
// Pop a job to of auto fstrim queue
func (s *FilesystemTrimServer) AutoFSTrimPop(
ctx context.Context,
req *api.SdkAutoFSTrimPopRequest,
) (*api.SdkAutoFSTrimPopResponse, error) {
if s.driver(ctx) == nil {
return nil, status.Error(codes.Unavailable, "Resource has not been initialized")
}
r, err := s.driver(ctx).AutoFilesystemTrimPop(req)
return r, err
}