@@ -19,7 +19,8 @@ limitations under the License.
19
19
package resizefs
20
20
21
21
import (
22
- "fmt"
22
+ "google.golang.org/grpc/codes"
23
+ "google.golang.org/grpc/status"
23
24
24
25
"k8s.io/klog"
25
26
"k8s.io/mount-utils"
@@ -38,51 +39,22 @@ func NewResizeFs(mounter *mount.SafeFormatAndMount) *resizeFs {
38
39
}
39
40
40
41
// Resize perform resize of file system
41
- func (resizefs * resizeFs ) Resize (devicePath , deviceMountPath string ) (bool , error ) {
42
- format , err := resizefs .mounter .GetDiskFormat ( devicePath )
42
+ func (resizefs * resizeFs ) Resize (devicePath , deviceMountPath string ) (needResize bool , err error ) {
43
+ resizer := mount . NewResizeFs ( resizefs .mounter .Exec )
43
44
44
- if err != nil {
45
- formatErr := fmt .Errorf ("ResizeFS.Resize - error checking format for device %s: %v" , devicePath , err )
46
- return false , formatErr
45
+ klog .V (4 ).Infof ("Checking if filesystem needs to be resized. Device: %s Mountpoint: %s" , devicePath , deviceMountPath )
46
+ if needResize , err = resizer .NeedResize (devicePath , deviceMountPath ); err != nil {
47
+ err = status .Errorf (codes .Internal , "Could not determine if filesystem %q needs to be resized: %v" , deviceMountPath , err )
48
+ return
47
49
}
48
50
49
- // If disk has no format, there is no need to resize the disk because mkfs.*
50
- // by default will use whole disk anyways.
51
- if format == "" {
52
- return false , nil
51
+ if needResize {
52
+ klog .V (4 ).Infof ("Resizing filesystem. Device: %s Mountpoint: %s" , devicePath , deviceMountPath )
53
+ if _ , err = resizer .Resize (devicePath , deviceMountPath ); err != nil {
54
+ err = status .Errorf (codes .Internal , "Failed to resize filesystem %q: %v" , deviceMountPath , err )
55
+ return
56
+ }
53
57
}
54
58
55
- klog .V (3 ).Infof ("ResizeFS.Resize - Expanding mounted volume %s" , devicePath )
56
- switch format {
57
- case "ext3" , "ext4" :
58
- return resizefs .extResize (devicePath )
59
- case "xfs" :
60
- return resizefs .xfsResize (deviceMountPath )
61
- }
62
- return false , fmt .Errorf ("ResizeFS.Resize - resize of format %s is not supported for device %s mounted at %s" , format , devicePath , deviceMountPath )
63
- }
64
-
65
- func (resizefs * resizeFs ) extResize (devicePath string ) (bool , error ) {
66
- output , err := resizefs .mounter .Exec .Command ("resize2fs" , devicePath ).CombinedOutput ()
67
- if err == nil {
68
- klog .V (2 ).Infof ("Device %s resized successfully" , devicePath )
69
- return true , nil
70
- }
71
-
72
- resizeError := fmt .Errorf ("resize of device %s failed: %v. resize2fs output: %s" , devicePath , err , string (output ))
73
- return false , resizeError
74
-
75
- }
76
-
77
- func (resizefs * resizeFs ) xfsResize (deviceMountPath string ) (bool , error ) {
78
- args := []string {"-d" , deviceMountPath }
79
- output , err := resizefs .mounter .Exec .Command ("xfs_growfs" , args ... ).CombinedOutput ()
80
-
81
- if err == nil {
82
- klog .V (2 ).Infof ("Device %s resized successfully" , deviceMountPath )
83
- return true , nil
84
- }
85
-
86
- resizeError := fmt .Errorf ("resize of device %s failed: %v. xfs_growfs output: %s" , deviceMountPath , err , string (output ))
87
- return false , resizeError
59
+ return
88
60
}
0 commit comments