From: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
To: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
Cc: devel@openvz.org
Subject: Re: [Devel] [PATCH VZ10 v2 2/3] selftests/ve: Add more helpers
Date: Wed, 09 Sep 2026 14:33:53 +0000 [thread overview]
Message-ID: <178896443372.479408.12192911474785454186.b4-review@b4> (raw)
In-Reply-To: <20260909-ve-selftest-improv-v2-2-aad0a25d6569@virtuozzo.com>
> Some more read/write helpers may be useful.
>
> Also, add a helper to execute functions in child process with
> switched namespaces and cgroup.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-144504
>
> Feature: ve selftests
> Signed-off-by: Vladimir Riabchun <vladimir.riabchun@virtuozzo.com>
>
> diff --git a/tools/testing/selftests/ve/ve_selftest.h b/tools/testing/selftests/ve/ve_selftest.h
> index ee960f7db0b4..e88293a39d34 100644
> --- a/tools/testing/selftests/ve/ve_selftest.h
> +++ b/tools/testing/selftests/ve/ve_selftest.h
> @@ -168,6 +168,14 @@ static inline int write_file_at(int dirfd, const char *path, const char *val)
> return (ret == (int)len) ? 0 : -1;
> }
>
> +static inline int write_u64_at(int dirfd, const char *path, unsigned long long val)
> +{
> + char s[32];
> +
> + snprintf(s, sizeof(s), "%llu", val);
> + return write_file_at(dirfd, path, s);
> +}
> +
> static inline int read_file_at(int dirfd, const char *path, char *buf,
> size_t buflen)
> {
> @@ -198,14 +206,9 @@ static inline int read_u64_at(int dirfd, const char *path,
> unsigned long long *out)
> {
> char buf[32] = {0}, *end;
> - int fd, ret;
> -
> - fd = openat(dirfd, path, O_RDONLY);
> - if (fd < 0)
> - return -1;
> + int ret;
>
> - ret = read(fd, buf, sizeof(buf) - 1);
> - close(fd);
> + ret = read_file_at(dirfd, path, buf, sizeof(buf));
> if (ret <= 0)
> return -1;
>
> @@ -216,6 +219,25 @@ static inline int read_u64_at(int dirfd, const char *path,
> return 0;
> }
>
> +static inline int read_s32_at(int dirfd, const char *path,
> + int *out)
> +{
> + char buf[32] = {0}, *end;
> + long tmp;
> + int ret;
> +
> + ret = read_file_at(dirfd, path, buf, sizeof(buf));
> + if (ret <= 0)
> + return -1;
> +
> + errno = 0;
> + tmp = strtol(buf, &end, 10);
> + if (errno || end == buf || tmp < INT_MIN || tmp > INT_MAX)
> + return -1;
> + *out = tmp;
> + return 0;
> +}
> +
> /* A fresh, private cgroup2 mount, returned as an fd to use with *at() calls. */
> static inline int mount_cg2_fd(void)
> {
> @@ -259,6 +281,55 @@ static inline int enter_cgroup(int cgv2_fd, int ctid)
> return ret;
> }
>
> +/*
> + * Run function in VE cgroup and new namespaces.
> + *
> + * Namespaces are provided via unshare_flags.
The documentation here is a bit weird. There is no unshare_flags
just flags and they are not passed to unshare but to enter_namespaces.
--
Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel
next prev parent reply other threads:[~2026-09-09 14:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 12:14 [Devel] [PATCH VZ10 v2 0/3] Improvements for ve selftests Vladimir Riabchun
2026-09-09 12:14 ` [Devel] [PATCH VZ10 v2 1/3] selftests/ve: Add namespace management helpers Vladimir Riabchun
2026-09-09 14:33 ` Vasileios Almpanis
2026-09-09 12:14 ` [Devel] [PATCH VZ10 v2 2/3] selftests/ve: Add more helpers Vladimir Riabchun
2026-09-09 14:33 ` Vasileios Almpanis [this message]
2026-09-09 12:14 ` [Devel] [PATCH VZ10 v2 3/3] ve_namespace: Allow entering non-running VE namespace Vladimir Riabchun
2026-09-09 14:33 ` Vasileios Almpanis
2026-09-09 18:56 ` Vladimir Riabchun
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=178896443372.479408.12192911474785454186.b4-review@b4 \
--to=vasileios.almpanis@virtuozzo.com \
--cc=devel@openvz.org \
--cc=vladimir.riabchun@virtuozzo.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.