Skip to content

Commit 32cc947

Browse files
Praveenrajmaniwlan0
authored andcommitted
Fix checkXFS check to handle "operation not supported" mount errors as well
check mounting with reflink enable during formatting. If the mounting fails, try with reflink disabled and conclude based on the results
1 parent edb53e6 commit 32cc947

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

centos.repo

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[base-8]
22
name=CentOS 8 - $basearch - Base
3-
baseurl=http://mirror.centos.org/centos/8-stream/BaseOS/$basearch/os/
3+
baseurl=http://mirrors.kernel.org/centos/8-stream/BaseOS/$basearch/os/
44
gpgcheck=1
55
enabled=1
66
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official
77
[appstream-8]
88
name=CentOS 8 - $basearch - AppStream
9-
baseurl=http://mirror.centos.org/centos/8-stream/AppStream/$basearch/os/
9+
baseurl=http://mirrors.kernel.org/centos/8-stream/AppStream/$basearch/os/
1010
gpgcheck=1
1111
enabled=1
1212
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-Official

cmd/directpv/run.go

+28-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"fmt"
2525
"net/http"
2626
"os"
27-
"syscall"
2827
"time"
2928

3029
"github.com/google/uuid"
@@ -52,6 +51,7 @@ const (
5251

5352
var (
5453
errInvalidConversionHealthzURL = errors.New("the `--conversion-webhook-healthz-url` flag is unset/empty")
54+
errMountFailure = errors.New("could not mount the drive")
5555
)
5656

5757
func waitForConversionWebhook() error {
@@ -101,31 +101,32 @@ func waitForConversionWebhook() error {
101101
return nil
102102
}
103103

104-
func checkXFS(ctx context.Context) (bool, error) {
104+
func checkXFS(ctx context.Context, reflinkSupport bool) error {
105105
mountPoint, err := os.MkdirTemp("", "xfs.check.mnt.")
106106
if err != nil {
107-
return false, err
107+
return err
108108
}
109109
defer os.Remove(mountPoint)
110110

111111
file, err := os.CreateTemp("", "xfs.check.file.")
112112
if err != nil {
113-
return false, err
113+
return err
114114
}
115115
defer os.Remove(file.Name())
116116
file.Close()
117117

118118
if err = os.Truncate(file.Name(), sys.MinSupportedDeviceSize); err != nil {
119-
return false, err
119+
return err
120120
}
121121

122-
if err = xfs.MakeFS(ctx, file.Name(), uuid.New().String(), false, true); err != nil {
123-
return false, err
122+
if err = xfs.MakeFS(ctx, file.Name(), uuid.New().String(), false, reflinkSupport); err != nil {
123+
klog.V(3).ErrorS(err, "failed to format", "reflink", reflinkSupport)
124+
return err
124125
}
125126

126127
loopDevice, err := losetup.Attach(file.Name(), 0, false)
127128
if err != nil {
128-
return false, err
129+
return err
129130
}
130131

131132
defer func() {
@@ -135,13 +136,11 @@ func checkXFS(ctx context.Context) (bool, error) {
135136
}()
136137

137138
if err = mount.Mount(loopDevice.Path(), mountPoint, "xfs", nil, ""); err != nil {
138-
if errors.Is(err, syscall.EINVAL) {
139-
err = nil
140-
}
141-
return false, err
139+
klog.V(3).ErrorS(err, "failed to mount", "reflink", reflinkSupport)
140+
return errMountFailure
142141
}
143142

144-
return true, mount.Unmount(mountPoint, true, true, false)
143+
return mount.Unmount(mountPoint, true, true, false)
145144
}
146145

147146
func run(ctx context.Context, args []string) error {
@@ -169,9 +168,22 @@ func run(ctx context.Context, args []string) error {
169168

170169
var nodeSrv csi.NodeServer
171170
if driver {
172-
reflinkSupport, err := checkXFS(ctx)
173-
if err != nil {
174-
return err
171+
172+
var reflinkSupport bool
173+
// try with reflink enabled
174+
if err := checkXFS(ctx, true); err == nil {
175+
reflinkSupport = true
176+
klog.V(3).Infof("enabled reflink while formatting")
177+
} else {
178+
if !errors.Is(err, errMountFailure) {
179+
return err
180+
}
181+
// try with reflink disabled
182+
if err := checkXFS(ctx, false); err != nil {
183+
return err
184+
}
185+
reflinkSupport = false
186+
klog.V(3).Infof("disabled reflink while formatting")
175187
}
176188

177189
if !dynamicDriveDiscovery {

0 commit comments

Comments
 (0)