forked from intel/pmem-csi
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XFS: fix creating volumes on OpenShift
On OpenShift, the xfs_io command that was used while creating XFS volumes hangs while getting loaded (kernel or container runtime bug?). This problem can be avoided by making the same ioctl calls as in that binary directly from the PMEM-CSI driver. Fixes: intel#1058
- Loading branch information
Showing
4 changed files
with
92 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
Copyright 2022 Intel Corporation | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package xfs | ||
|
||
// #include <linux/fs.h> | ||
// #include <sys/ioctl.h> | ||
// #include <errno.h> | ||
// #include <string.h> | ||
// | ||
// char *getxattr(int fd, struct fsxattr *arg) { | ||
// return ioctl(fd, FS_IOC_FSGETXATTR, arg) == 0 ? 0 : strerror(errno); | ||
// } | ||
// | ||
// char *setxattr(int fd, struct fsxattr *arg) { | ||
// return ioctl(fd, FS_IOC_FSSETXATTR, arg) == 0 ? 0 : strerror(errno); | ||
// } | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// SetXFSExtsize sets the inherit flag for extsize and the 2M extsize that is | ||
// needed for fsdax huge pages on XFS. | ||
func SetXFSExtsize(path string) error { | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return fmt.Errorf("open %q: %v", path, err) | ||
} | ||
defer file.Close() | ||
fd := C.int(file.Fd()) | ||
|
||
var attr C.struct_fsxattr | ||
if errnostr := C.getxattr(fd, &attr); errnostr != nil { | ||
return fmt.Errorf("FS_IOC_FSGETXATTR for %q: %v", path, C.GoString(errnostr)) | ||
} | ||
|
||
attr.fsx_xflags |= C.FS_XFLAG_EXTSZINHERIT | ||
attr.fsx_extsize = 2 * 1024 * 1024 | ||
if errnostr := C.setxattr(fd, &attr); errnostr != nil { | ||
return fmt.Errorf("FS_IOC_FSSETXATTR for %q: %v", path, C.GoString(errnostr)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright 2022 Intel Corporation | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package xfs | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_SetXFSExtsize(t *testing.T) { | ||
// This is assumed to be backed by tmpfs and thus doesn't support xattr. | ||
tmp := t.TempDir() | ||
err := SetXFSExtsize(tmp) | ||
if err == nil { | ||
t.Fatal("did not get expected error") | ||
} | ||
t.Logf("got expected error: %v", err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters