Linux Test Project
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Darren Chang <chihsheng@google.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4] syscalls/xattr: Add runtime probe for socket xattr backports
Date: Wed, 3 Jun 2026 12:34:40 +0200	[thread overview]
Message-ID: <aiADQJONiWJVh0Qa@yuki.lan> (raw)
In-Reply-To: <20260602010754.190896-1-chihsheng@google.com>

Hi!
>  	socket_xattr_supported = tst_kvercmp(7, 1, 0) >= 0;
> +
> +	/*
> +	 * Commit dc0876b9846d "xattr: support extended attributes on sockets"
> +	 * merged in 7.1 mainline, but might be backported.
> +	 * Try to set xattr on socket to detect support.
> +	 */
> +	if (!socket_xattr_supported) {
> +		for (i = 0; i < ARRAY_SIZE(tc); i++) {
> +			if (tc[i].issocket) {
> +				socket_idx = i;
> +				break;
> +			}
> +		}
> +
> +		if (socket_idx != ARRAY_SIZE(tc)) {
> +			if (fsetxattr(tc[socket_idx].fd, tc[socket_idx].key,
> +				      tc[socket_idx].value, tc[socket_idx].size,
> +				      tc[socket_idx].flags) == 0) {
> +				tst_res(TINFO, "Socket xattr support detected (backport)");
> +				socket_xattr_supported = true;
> +
> +				SAFE_FREMOVEXATTR(tc[socket_idx].fd, tc[socket_idx].key);
> +			}

Instead of looking up the attribute in the array we can just create a
socket, try ato add an attribute and remove the socked instead. With
that we can up the code into a common header so that it's not duplicated
int two testcases. I guess that the best place would be the
lapi/socket.h header and we should add a static inline function
socket_xattrs_supported() there.

> +		}
> +	}
>  }
>  
>  static void cleanup(void)
> diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c
> index 994ab655d..167e068cf 100644
> --- a/testcases/kernel/syscalls/setxattr/setxattr02.c
> +++ b/testcases/kernel/syscalls/setxattr/setxattr02.c
> @@ -196,6 +196,20 @@ static void setup(void)
>  	SAFE_MKNOD(SOCK, S_IFSOCK | 0777, 0);
>  
>  	socket_xattr_supported = tst_kvercmp(7, 1, 0) >= 0;
> +
> +	/*
> +	 * Commit dc0876b9846d "xattr: support extended attributes on sockets"
> +	 * merged in 7.1 mainline, but might be backported.
> +	 * Try to set xattr on socket to detect support.
> +	 */
> +	if (!socket_xattr_supported) {
> +		if (setxattr(SOCK, XATTR_TEST_KEY, XATTR_TEST_VALUE,
> +			     XATTR_TEST_VALUE_SIZE, XATTR_CREATE) == 0) {
> +			tst_res(TINFO, "Socket xattr support detected (backport)");
> +			socket_xattr_supported = true;
> +			SAFE_REMOVEXATTR(SOCK, XATTR_TEST_KEY);
> +		}
> +	}
>  }
>  
>  static struct tst_test test = {
> -- 
> 2.54.0.929.g9b7fa37559-goog
> 

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

      parent reply	other threads:[~2026-06-03 10:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 10:13 [LTP] [PATCH] syscalls/xattr: Add runtime probe for socket xattr backports Darren Chang via ltp
2026-06-01 13:35 ` [LTP] " linuxtestproject.agent
2026-06-01 15:14 ` [LTP] [PATCH v2] " Darren Chang via ltp
2026-06-01 16:03   ` [LTP] " linuxtestproject.agent
2026-06-01 16:53 ` [LTP] [PATCH v3] " Darren Chang via ltp
2026-06-01 20:26   ` [LTP] " linuxtestproject.agent
2026-06-02  1:07   ` [LTP] [PATCH v4] " Darren Chang via ltp
2026-06-02  4:06     ` [LTP] " linuxtestproject.agent
2026-06-03 10:34     ` Cyril Hrubis [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aiADQJONiWJVh0Qa@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=chihsheng@google.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox