This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
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: #1058 (cherry picked from commit 4f1a2d8)
- Loading branch information
Showing
4 changed files
with
98 additions
and
13 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,56 @@ | ||
/* | ||
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" | ||
) | ||
|
||
// ConfigureFS must be called after mkfs.xfs for the mounted | ||
// XFS filesystem to prepare the volume for usage as fsdax. | ||
// It is idempotent. | ||
func ConfigureFS(path string) error { | ||
// Operate on root directory. | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return fmt.Errorf("open %q: %v", path, err) | ||
} | ||
defer file.Close() | ||
fd := C.int(file.Fd()) | ||
|
||
// Get extended attributes. | ||
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)) | ||
} | ||
|
||
// Set extsize to 2m to enable hugepages in combination with | ||
// fsdax. This is equivalent to the "xfs_io -c 'extsize 2m'" invocation | ||
// mentioned in https://nvdimm.wiki.kernel.org/2mib_fs_dax | ||
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_ConfigureFS(t *testing.T) { | ||
// This is assumed to be backed by tmpfs and thus doesn't support xattr. | ||
tmp := t.TempDir() | ||
err := ConfigureFS(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