summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-05-31 19:09:16 +0300
committerPaul Buetow <paul@buetow.org>2026-05-31 19:09:16 +0300
commit8a1bf6236f6a525881c647fd881093b393436411 (patch)
tree0fb537b847b6e5c72d2d3d98d7ce8fbc15330102 /cmd
parentc3177bd82c16429c1bb246d19af76012479f0c01 (diff)
listxattrat: READ-classify return for xattr-list family consistency
listxattrat(2) (Linux 6.13+) returns the size in bytes of the list of extended attribute names, exactly like listxattr/llistxattr/flistxattr, but its exit was classified UNCLASSIFIED, so its read bytes were dropped from I/O totals. Classify it as ReadClassified and regenerate the BPF handler (ret_type now READ_CLASSIFIED). This mirrors the getxattrat fix (task ku, commit c3177bd) and completes xattr-family consistency: get-family and list-family are READ_CLASSIFIED while set-family and remove-family stay UNCLASSIFIED (they return 0/-1). Update the docs ReadClassified list and the retclassify expectation, and add an ioworkload scenario plus integration test: the workload sets a user xattr then lists names via the raw listxattrat(2) syscall with AT_FDCWD, and the test asserts enter_listxattrat captures the file path and accounts the returned name-list size as read bytes. Task: r20 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/ioworkload/scenario_xattr.go76
-rw-r--r--cmd/ioworkload/scenarios.go1
2 files changed, 77 insertions, 0 deletions
diff --git a/cmd/ioworkload/scenario_xattr.go b/cmd/ioworkload/scenario_xattr.go
index 42c679f..f974c01 100644
--- a/cmd/ioworkload/scenario_xattr.go
+++ b/cmd/ioworkload/scenario_xattr.go
@@ -21,6 +21,19 @@ import (
// or -1 on error.
const sysGetxattrat = 464
+// listxattrat is syscall number 465 on amd64 (added in Linux 6.13, right after
+// getxattrat). Go's syscall package does not export SYS_LISTXATTRAT, so we
+// invoke it by its raw number. Its signature is:
+//
+// listxattrat(int dfd, const char *pathname, unsigned int at_flags,
+// char *list, size_t size)
+//
+// The filesystem PATH is at args[1] (after the dirfd); args[3] is the userspace
+// buffer that receives the NUL-separated list of xattr names. The syscall
+// returns the size in bytes of the name list (a read byte-count), or -1 on
+// error — exactly like listxattr/llistxattr/flistxattr.
+const sysListxattrat = 465
+
// xattrArgs mirrors struct xattr_args from <linux/xattr.h> (Linux 6.13+):
// a userspace value buffer pointer plus its size and flags.
type xattrArgs struct {
@@ -105,3 +118,66 @@ func callGetxattrat(path, name string, wantSize int) error {
}
return nil
}
+
+// xattrListxattrat creates a file on tmpfs (/tmp), sets a user xattr on it, then
+// lists that file's xattr names via the raw listxattrat(2) syscall with
+// AT_FDCWD. This exercises ior's listxattrat tracing end-to-end and confirms:
+// - the real filesystem path (args[1]) is captured, NOT the dirfd;
+// - the syscall exit is READ-classified so the returned name-list size is
+// accounted as read bytes, consistent with listxattr/llistxattr/flistxattr.
+func xattrListxattrat() error {
+ dir, cleanup, err := makeTempDir("xattr-listxattrat")
+ if err != nil {
+ return err
+ }
+ defer cleanup()
+
+ path := filepath.Join(dir, "xattrfile.txt")
+ fd, err := syscall.Open(path, syscall.O_RDWR|syscall.O_CREAT, 0o644)
+ if err != nil {
+ return fmt.Errorf("open: %w", err)
+ }
+ syscall.Close(fd)
+
+ const xattrName = "user.ior"
+ if err := syscall.Setxattr(path, xattrName, []byte("listxattrat-value"), 0); err != nil {
+ return fmt.Errorf("setxattr: %w", err)
+ }
+
+ // The returned list is the NUL-terminated xattr name, e.g. "user.ior\0".
+ return callListxattrat(path, len(xattrName)+1)
+}
+
+// callListxattrat performs the raw listxattrat(AT_FDCWD, path, 0, list,
+// sizeof(list)) call and verifies it returns at least the expected list size.
+// The kernel may report additional system xattr names (e.g. "security.*"), so
+// we assert the returned size is at least wantMinSize rather than exact.
+func callListxattrat(path string, wantMinSize int) error {
+ pathBytes, err := syscall.BytePtrFromString(path)
+ if err != nil {
+ return fmt.Errorf("path bytes: %w", err)
+ }
+
+ list := make([]byte, 256)
+ // Use a runtime int variable so the negative AT_FDCWD survives the uintptr
+ // conversion: converting the negative constant directly overflows uintptr.
+ dirfd := _AT_FDCWD
+ ret, _, errno := syscall.Syscall6(
+ sysListxattrat,
+ uintptr(dirfd),
+ uintptr(unsafe.Pointer(pathBytes)),
+ 0, // at_flags
+ uintptr(unsafe.Pointer(&list[0])),
+ uintptr(len(list)),
+ 0,
+ )
+ runtime.KeepAlive(pathBytes)
+ runtime.KeepAlive(&list[0])
+ if errno != 0 {
+ return fmt.Errorf("listxattrat: %w", errno)
+ }
+ if int(ret) < wantMinSize {
+ return fmt.Errorf("listxattrat returned %d, want at least %d", int(ret), wantMinSize)
+ }
+ return nil
+}
diff --git a/cmd/ioworkload/scenarios.go b/cmd/ioworkload/scenarios.go
index b7ea44a..6503db7 100644
--- a/cmd/ioworkload/scenarios.go
+++ b/cmd/ioworkload/scenarios.go
@@ -99,6 +99,7 @@ var scenarios = map[string]func() error{
"stat-access-enoent": statAccessEnoent,
"stat-fstat-ebadf": statFstatEbadf,
"xattr-getxattrat": xattrGetxattrat,
+ "xattr-listxattrat": xattrListxattrat,
"utime-basic": utimeBasic,
"utime-utimes": utimeUtimes,
"utime-enoent": utimeEnoent,