From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (unknown [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 2E6988015B for ; Fri, 25 Sep 2026 12:48:41 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68PClQ6Y025261; Fri, 25 Sep 2026 15:47:26 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68PClQ6Y025261 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="gppNYsiW" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 68PClApk025230 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Fri, 25 Sep 2026 15:47:10 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 68PClApk025230 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-486e8fb7d75so386040f8f.0 for ; Fri, 25 Sep 2026 05:47:10 -0700 (PDT) X-Gm-Message-State: AFuF++nHH1v3Ap+738F7OqbpI1DPnIgHme40/PEYxyWfOItEFk6U8gRR 5i2Kzkwvsu2ZGhJGxkFT4vew9hTfew4SkLodj4UI4CUsx0LuKUwvXGYet1kdpeu6gSlPOWyUyr+ 3rtPTcCK3F37FYg2TJydhxpNOzZqeNV9JmtOULfpO01s5Ckhu5/xuVg== X-Gm-Gg: AYBFou2btC6pLbcZkgG5q1WYJPP+c5+kiwm9HpbCwoKRa8JKu33LGuB5F/UcxP5qyYl T3pEEkMLfr6ZSXlclvN79h3IiFIcBC6ssmxx93OmbzbZP2EYcg7SDkHJFtP8PEugfWs9b8huN8A VF0sHpXq/gtS8gQcKB40ISNVPoT4tRDQQ4E91SkTG2Twhjo7p3FjtCQsSAQs3dCWRb6hJ2EYFkE ouE/zMvuyB2MM45bOKMYGvhmg0ZGx/1eiHYRv80TksasPPj3YXgWQAzWtzJhSibLFiJS4QNPlvW OkzBdcBsoqOAtoseDEPpBB3jUIHFOoTqMsgykUqBMXM8bw9pKGnrFfg+ot7VICjG5rgYoDQliqL 0xOjAtMLp7I3IQChu X-Received: by 2002:a05:6000:2893:b0:487:10a9:57cb with SMTP id ffacd0b85a97d-488719756c5mr9144447f8f.49.1790340430073; Fri, 25 Sep 2026 05:47:10 -0700 (PDT) X-Received: by 2002:a05:6000:2893:b0:487:10a9:57cb with SMTP id ffacd0b85a97d-488719756c5mr9144409f8f.49.1790340429514; Fri, 25 Sep 2026 05:47:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1790340429; cv=none; d=google.com; s=arc-20260327; b=BYZ4amIjjuw0ucPNGTft6+f22F2PANMq2hi7xnAqXx2yFtdWjUG+Ny0DXJupa5TSec o0bcy89y7dhfOL6/NGteOc+LAMHTkTBNheFQa1CqjHM4ZYivV8ncZDh+UGOJieneA2ry Bfnnt1aOmXE2k03Ri7XpmR+jtlGllalJ4alTIA8o6rY6zUVth5TomB1x8gY1Gfxds39l NC/GTyNukQASk9QrtF2Aa4tNn/sntwTGVs5t+f6yjbgzV3phZDV4e5+0W0ejWVPPgM3T 4Uin1NhsrCY2MRL2IAw78e3JpgM7k4yI3FwM35+KXOhgPNflLO7AQHgeGbSKgRQqv61s KPfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=w40caWBl0e4neB7SxAuBe4SRs19+sFcPZdpZBBentNA=; fh=RKXkvghX4iWYZXS5wDgL7Ui0VKwsIa3ttyVns5QVLNU=; b=IrMqM4L/ME+CZQyE2laH9mBq5Yg6nlYlxq1lBrAqKyagXsrJmcevFIhqfiVgiaH6p6 qHz7U5LbRPsp2QrJYBvxL5h2BSemdfX0MT79yMV6IuF8B8/U9vwEwasCrIeioNmR6zR/ fJsiwKDnGHdJycl9PK2zT5/bfc7HU/JmimRlCHonlVwEtRnkEjUyJtRxitE5fYn3e5zp Nkj7kgih6Dgmt24/A22Y0lDowl/3b+RFgNu/tNUUDdGEwj0P7VsrF8r+bv8G2D80MVvO 4njXoRhH5Se+dWlpG/IvmXwHy7pplkttxj7XkjK8Cgm8MdaxR1YNCwvARR0qh84Bez7+ 0pPA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=gppNYsiW; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-4887a35f3c1si5155515f8f.134.2026.09.25.05.47.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Sep 2026 05:47:09 -0700 (PDT) Received-SPF: pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=gppNYsiW; spf=pass (google.com: domain of khorenko@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=khorenko@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Message-Id:Content-Type:MIME-Version:Subject:Date :From; bh=w40caWBl0e4neB7SxAuBe4SRs19+sFcPZdpZBBentNA=; b=gppNYsiWmldbZvGABpJ T10CwROQZFTa0qHa4NkBVL6kF4JimVZtvB8mBdI4Evc5awV4Hxv4aHYEk863PDMaJji5+FV5hWIEs 6EhP9514W1pqw8HWdZduXW9tfBAYJxeY3MuVMH/Qfi+7ddp9G+DvsnoWzHxzl2/Jn436uFIzAh2X5 CxSPoD+2vyvcTY8ohsxOr+XGmBPqKSPbsW6F5WqxLQ8P5duhfGCE+peiJdqe8LKWkky+kvxFgK7y1 Mabx96BNy3M+AYqJueZJnUakUUL0UgORdf+xfw4RCkFyZYdgZTyMKRsCMsRiKz52oaGSQ6r1oqgqg rna/K6/xvPMMVGA==; Received: from ch-demo-asa.virtuozzo.com ([130.117.225.8] helo=f0.sw.ru) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1xA5HZ-007Y8o-0e; Fri, 25 Sep 2026 14:47:05 +0200 From: Konstantin Khorenko Date: Fri, 25 Sep 2026 14:47:04 +0200 MIME-Version: 1.0 Message-Id: <20260925-ve-selftest-improv-v4-3-1f505bd0eca6@virtuozzo.com> References: <20260925-ve-selftest-improv-v4-0-1f505bd0eca6@virtuozzo.com> In-Reply-To: <20260925-ve-selftest-improv-v4-0-1f505bd0eca6@virtuozzo.com> To: Vladimir Riabchun , Vasileios Almpanis X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3649; i=khorenko@virtuozzo.com; h=from:subject:message-id; bh=iKlWYxEb/VEL4+B95Eyf0JjVsPA5S6qp7R+rbY8TpYs=; b=owEBbQKS/ZANAwAKAVGWCkf5YVwqAcsmYgBqtm1MYGaOGnUao2JXqs3Cdiox0+mCng9gXWP07 iOaj75HhhOJAjMEAAEKAB0WIQRWD23IPcXT0GO9CCxRlgpH+WFcKgUCarZtTAAKCRBRlgpH+WFc KgKoEACUBTZNr304VwVcQHqJsmrkMGrnW5/YdrEjQo0T+PRexhm279tCC3kxkatAkxSRhUNErRZ vKdp69uN+EosFaiONLJXSvDGVscAeSjLhhKNLAVpSD/lrPiEcXR6Tj4TxJTrwGMg5NeRx1Hi/jn iC6izvCcFX3RYdWRfiN6hH5RB+JxEOZyATLDLDHmSJv3iNjT3VsGlyo7jJFmOz+8RqZP9hx89T0 77uT1n2/RogGqUS9b6naqozwjztx80qaZfPOsYRyrAE6QgJvX5BZADJnKPPZuvY/7lHpfUGZHJv krFIm/8vrf5LQ/+2IYICQy+rTeaLCJPvGqQ9mZ3b2SX13GAt8zHYiv7+a8jVEpCEq3FCZ3FLiKb DYpetc4yWJGzo2omSIB2FwZJ0FUm67VvmO/cDTC1BA9/FQd7ANHUq/oJfw+VxGn/9kPK1IVaJTt 1LloSFlySOjt671VwaJt2rb+iZ1DNjDy90n8ad3d4/x7lh0SggDxCP/m0C2K9ioVUCwS7AjjVWt AsZWaN9zQPEMiy5ajDjZ/uMk9hTMn/Md2VZV8EcKy8lG9opzxUrlVA0yEx13PHKmb5S6XYWObWL FNrnNr54UbpNGsgX9lHTzlTuAjJ+9Hu/2+pS4fvGTKA1nCh5q/9ZdoJ6OaZU87eYY7Mi+JQC8G1 FlslVYi21lnyNwg== X-Developer-Key: i=khorenko@virtuozzo.com; a=openpgp; fpr=560F6DC83DC5D3D063BD082C51960A47F9615C2A X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH VZ10 v4 3/3] selftests/ve: Add more helpers X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org From: Vladimir Riabchun 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 Reviewed-by: Vasileios Almpanis Reviewed-by: Konstantin Khorenko --- tools/testing/selftests/ve/ve_selftest.h | 84 +++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/ve/ve_selftest.h b/tools/testing/selftests/ve/ve_selftest.h index bc9dc28a8d074..7b45f91c1d561 100644 --- a/tools/testing/selftests/ve/ve_selftest.h +++ b/tools/testing/selftests/ve/ve_selftest.h @@ -175,6 +175,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) { @@ -205,14 +213,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; @@ -223,6 +226,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) { @@ -266,6 +288,54 @@ static inline int enter_cgroup(int cgv2_fd, int ctid) return ret; } +/* + * Run function in VE cgroup and given namespaces. + * + * Namespaces are provided via namespace_ctx and entered based on flags mask. + * + * Return values: + * - 0 if function returns zero + * - -1 if function returns negative value + * - 1 if function returns positive value + * - 2 if setup fails + */ +static inline int run_in_ve(int cgv2_fd, int ctid, struct namespace_ctx *ctx, + int flags, int (*fn)(void *), void *arg) +{ + int status; + pid_t pid; + + pid = fork(); + if (pid < 0) { + fprintf(stderr, "%s: fork failed\n", __func__); + return 2; + } + if (pid == 0) { + int ret; + + if (enter_cgroup(cgv2_fd, ctid) < 0) { + fprintf(stderr, "%s: enter_cgroup failed\n", __func__); + _exit(254); + } + if (enter_namespaces(ctx, flags) < 0) + _exit(254); + + ret = fn(arg); + if (ret < 0) + ret = 1; + else if (ret > 0) + ret = 255; + _exit(ret); + } + if (waitpid(pid, &status, 0) < 0 || !WIFEXITED(status) || WEXITSTATUS(status) == 254) + return 2; + if (WEXITSTATUS(status) == 255) + return 1; + if (WEXITSTATUS(status)) + return -1; + return 0; +} + /* * Create a fresh VE cgroup at the first free id at or after @from and unhide * its ve.* control files. Return the new id, or -1. -- 2.43.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel