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 8D9388015C for ; Mon, 7 Sep 2026 19:16:39 +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 687JFKIF030666; Mon, 7 Sep 2026 22:15:21 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 687JFKIF030666 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="PZiwPuxq" Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 687JFJGW030650 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 7 Sep 2026 22:15:19 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 687JFJGW030650 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-48439ef42d8so3157771f8f.2 for ; Mon, 07 Sep 2026 12:15:19 -0700 (PDT) X-Forwarded-Encrypted: i=2; AKwUvBw4l0JYIwYdq+coUE4oF3R9xubuHqHNoBX/i5cVRzkR9OVU4PZ2yZ7L6+g5q76d7AXmMsO4nQ==@openvz.org X-Gm-Message-State: AFuF++ksrBlInEbSxcDIQ3YmnM8xCVs7MlhZcqqTBf7ZRhLRDL7nEEJV +0Xzdrg0YyvTKBFxGALU9721KidhhEMj3UBzoIpf93DoJqStGe5aOPflPImHCHCMkUh3MeyKgMn b7nYJEJvvqS1g+Yezn0zFvvGiW5pQICBrWdtub809GF3nYf/5xpVGyw== X-Gm-Gg: AYBFou1AFbUGP6wJUp9jFMJ06Cue5/8cXcvAnnttGed7NY7Ednc70vbcOZaJxZl6y1m G+T3Cman+1OgyF43uHrip5yt8ClkiUHOmRllKoqL56r6TYySSxS4fXysmCN5oltdjAtxGG4zc0n 5BWakpbniyfV77zPh7e91Ik8G7voXpc502JAf7rlxTV5QszhyiAEu7TIPX8/Sgp6hLcf2+EuioK Q27PhYUq5iJnu+XbkidtBr0m8fN2dI+DNYcNbj8X/2L0hSR8iawUfgqIUmGbM9YfmNaTaAteamd YqdeRAukqU0R9C63F9N5j4OTGuYxgmRnVPIB0ZstZF1AJsyJ46RqhwEXedsR/5/fjXbi52Jnblg WHZeEyDrhNAnV5SeTvFlLLvXFbvFbvw== X-Received: by 2002:a05:600c:3550:b0:49c:d019:70c5 with SMTP id 5b1f17b1804b1-49cf7f4a6cfmr220419275e9.0.1788808518913; Mon, 07 Sep 2026 12:15:18 -0700 (PDT) X-Received: by 2002:a05:600c:3550:b0:49c:d019:70c5 with SMTP id 5b1f17b1804b1-49cf7f4a6cfmr220418905e9.0.1788808518412; Mon, 07 Sep 2026 12:15:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788808518; cv=none; d=google.com; s=arc-20260327; b=R0Nhgywhd1DfVkJIBoHNo0JBAMO+63JQVTtcZFxjq0goIMIzYUT40g4OcLcBa45ZRb Kf0d4GiSyrNdbb6vW8NLa3yz3bcwVoKUwmafzC0wwj1Y1nu9ZWAEPtHcYgpQdLgJ+WQv o9ErNH4MqgS1bNyb+FBScyixTLJnA78GIDCzPf3RJn4mr1R2VZ35SgcIrPRzDsNmobWt H8XnUxHZ/E7iaAfRN0lwt1yC5uYiy30CdLOLbhmLEuBYNBwyT4XjIiCHiuc8aMDEU0sM eaQ0i1Mj5AQvNQfDGsSQqDSJwJb94T83KHHoGDQM+ixYSvvOSunyNM2p0rZTshzUCYJI GTIw== 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=uZrhQPA9Scv3Fil5s2AMAk+t2oxU9YwbTtjJp5h82Qk=; fh=4dppuILCfGifWHfxjIIA1BWoKQtGs1EMopxlFiqV6no=; b=CbKSPb+QWut6VTlg+zmmiR1oJX+HxHAjm9uvlZZknfn0C1+5Cfe5HNe5WtacSLpi4i TCjpuU52MxcVDtsNr7oEOWqhchPJ7pIZwWpJ+pmENqqO50XC4OwVixLYgzixSUvHe13N 8TLwJUUwanwBqzBbJEAqFGOzgufDtNUZhcWTLLIqYxcjtlJS4xl/Ic61u7WzeZBH2Z5Z OYH6DX0odUe+L6x7kkS7uu+77HKxSUmCI+9Dx1T24PAA33VNYvEu1PPg+r1WtF3UEyY2 w6svj+qWjJXW12IpTurmQhYTxpo3qs5jGz0JTE8FonZcnJsSR4Pi8ajLtenENW4eFACS Z4xg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=PZiwPuxq; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@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-485883b8f9dsi27820303f8f.138.2026.09.07.12.15.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Sep 2026 12:15:18 -0700 (PDT) Received-SPF: pass (google.com: domain of vladimir.riabchun@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=PZiwPuxq; spf=pass (google.com: domain of vladimir.riabchun@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=vladimir.riabchun@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=uZrhQPA9Scv3Fil5s2AMAk+t2oxU9YwbTtjJp5h82Qk=; b=PZiwPuxqI4J1BjNtqxX T/WQcOdY3RH27BQ9uE65OyCJlQndImV5cavHilEEbssV4HwZlgu9SfnFTJs07tLHYycaTTOoB3/wQ XFZzwjm9upwrU3mWToDpmU2UXfq/UsoipBQtOCRMhKtsnjfZRN6xirp2+84bfGhuvlCT9Y9T5l5a3 PKXZz9XevrBUbixl9QFQB4h05hbQIko31yno6M6ZHJEhSSTF8W+CDjOq7dbyEMf1Uws4dK1qyfpos gHfUw1adPhBzFGyq4D+sjA1n1aXggumqq1IFoXfPM8WmM3yRKoQ7p8ayyY7IkD1rRwJ+3c7gfb7Kr fuV9Yryc7/HxD7Q==; Received: from [130.117.225.5] (helo=dev012.aci.vzint.dev) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x3elk-006g0W-2p; Mon, 07 Sep 2026 21:15:09 +0200 From: Vladimir Riabchun Date: Mon, 07 Sep 2026 19:14:45 +0000 MIME-Version: 1.0 Message-Id: <20260907-ve-selftest-improv-v1-2-a17847abbd48@virtuozzo.com> References: <20260907-ve-selftest-improv-v1-0-a17847abbd48@virtuozzo.com> In-Reply-To: <20260907-ve-selftest-improv-v1-0-a17847abbd48@virtuozzo.com> To: Konstantin Khorenko X-Mailer: b4 0.16.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH VZ10 2/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 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 --- tools/testing/selftests/ve/ve_selftest.h | 78 +++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/ve/ve_selftest.h b/tools/testing/selftests/ve/ve_selftest.h index b3c5bf63f34d..d35fec30c7b4 100644 --- a/tools/testing/selftests/ve/ve_selftest.h +++ b/tools/testing/selftests/ve/ve_selftest.h @@ -163,6 +163,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[20]; + + 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) { @@ -193,19 +201,31 @@ static inline int read_u64_at(int dirfd, const char *path, unsigned long long *out) { char buf[32] = {0}, *end; - int fd, ret; + int ret; - fd = openat(dirfd, path, O_RDONLY); - if (fd < 0) + ret = read_file_at(dirfd, path, buf, sizeof(buf)); + if (ret <= 0) return -1; - ret = read(fd, buf, sizeof(buf) - 1); - close(fd); + errno = 0; + *out = strtoull(buf, &end, 10); + if (errno || end == buf) + return -1; + return 0; +} + +static inline int read_s32_at(int dirfd, const char *path, + int *out) +{ + char buf[32] = {0}, *end; + int ret; + + ret = read_file_at(dirfd, path, buf, sizeof(buf)); if (ret <= 0) return -1; errno = 0; - *out = strtoull(buf, &end, 10); + *out = strtol(buf, &end, 10); if (errno || end == buf) return -1; return 0; @@ -254,6 +274,52 @@ 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. + * CLONE_NEWVE flag is set by this function. + * Return values: + * - 0 if function returns zero + * - -1 if function returns negative value + * - 1 if setup fails or function returns positive value + */ +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 1; + } + if (pid == 0) { + int ret; + + if (enter_cgroup(cgv2_fd, ctid) < 0) { + fprintf(stderr, "%s: enter_cgroup failed\n", __func__); + _exit(255); + } + if (enter_namespaces(ctx, flags) < 0) + _exit(255); + + 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) == 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.47.1 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel