From patchwork Fri Apr 8 04:57:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12806063 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FA0FC433F5 for ; Fri, 8 Apr 2022 04:57:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C62096B0074; Fri, 8 Apr 2022 00:57:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C12538D0001; Fri, 8 Apr 2022 00:57:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A16406B0078; Fri, 8 Apr 2022 00:57:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 8EE176B0074 for ; Fri, 8 Apr 2022 00:57:50 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 53B601B4 for ; Fri, 8 Apr 2022 04:57:50 +0000 (UTC) X-FDA: 79332504300.16.BDE62AC Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) by imf10.hostedemail.com (Postfix) with ESMTP id CDE09C0002 for ; Fri, 8 Apr 2022 04:57:49 +0000 (UTC) Received: by mail-pf1-f202.google.com with SMTP id g5-20020a62f945000000b0050578328060so980541pfm.17 for ; Thu, 07 Apr 2022 21:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=RpFXlKvwb4pUJyIrx0BwPq/Sz7TwgzSMaU3KXpjsnFg=; b=PZfwTndHaHFeiId6kJJWIk58eh5ykRjdyumVYKw/V0Oluj34d7Lv6G9QfbAO6MG68X 5Cp8uWVnKwShcF0BFnxZHLWp6ZB5aWPOXG/Oix4YaoRQJT/TamzL0Z+Q0C1feePcwpoK FENgXFWEzQHHDlbUa6+OWFMfZy/Zs5THpeXzBDDUoSOpdHazwli+xVssStSpQX6dXP87 +gEZWfq2i6qSv+b+zRxuTxamA08CMwUpQtHbpqJp/ibE+JIapaGcj0/Y8FuPUv9ANtvB K64P3pZuES8BJSknRtTorjKzVC0kiVkym17TcMpzn9ih6gm1W5AFO0y+l2ijh3LMEALt vIDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=RpFXlKvwb4pUJyIrx0BwPq/Sz7TwgzSMaU3KXpjsnFg=; b=dcbfmsJvPwJzwq623seJifvtE5oWcrGmpgdqSWB6Yj+ZOHSUjaU5EjHTvqaxGL402h nG095Xnbl9Ke49OShyLlxtJNtiHBNXp4UgnCMGHOdPhZvh4FvPJH3/YfmF4L417ZWGOd wSCN0SsYZdY6TNttdoie6AO61crNEfTNWQ2YLpNkNZWO9oS+ec+YDoxyUU7VeAr4js21 BYeU2N+22oPOVfumaidfAbiHrIuEhVDOZjZCpT2Nt/xJXoMMCf5yP5ZLkrFMmUtDKPCm Zpn1/SWSHK82PoPIXeQj/aOUBBzGbyYyaBa9DsObOUz0y0+v1OXEwiZMfDNfhboczu9a 1FTg== X-Gm-Message-State: AOAM5322/3+lxX+uFgMoM2wpX4I90YwDPCtUdmi25d1qZNrytBwDeCrN DPAA+8yJ74avmPJGqUFcU0AoCA1M1ZtjqWRW X-Google-Smtp-Source: ABdhPJw5mVvKa75yNWq8X1toeYD179Hk+kkkpDn6jYwbzqwx+XJ9Se+9zdydnBR6hBfnjvMnIUQQ2/3DjI+R68dT X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:ecd1:b0:154:5393:aa7e with SMTP id a17-20020a170902ecd100b001545393aa7emr17225851plh.79.1649393868836; Thu, 07 Apr 2022 21:57:48 -0700 (PDT) Date: Fri, 8 Apr 2022 04:57:41 +0000 In-Reply-To: <20220408045743.1432968-1-yosryahmed@google.com> Message-Id: <20220408045743.1432968-3-yosryahmed@google.com> Mime-Version: 1.0 References: <20220408045743.1432968-1-yosryahmed@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH v3 2/4] selftests: cgroup: return the errno of write() in cg_write() on failure From: Yosry Ahmed To: Johannes Weiner , Michal Hocko , Shakeel Butt , Andrew Morton , Roman Gushchin Cc: David Rientjes , Tejun Heo , Zefan Li , Jonathan Corbet , Shuah Khan , Yu Zhao , Dave Hansen , Wei Xu , Greg Thelen , Chen Wandun , Vaibhav Jain , " =?utf-8?q?Michal_Koutn=C3=BD?= " , Tim Chen , cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, Yosry Ahmed X-Stat-Signature: zgkmnba39r5s5eoaxqg65y9tgeby3m57 Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=PZfwTndH; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf10.hostedemail.com: domain of 3zMBPYgoKCKUdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com designates 209.85.210.202 as permitted sender) smtp.mailfrom=3zMBPYgoKCKUdTXWdFMRJILTTLQJ.HTRQNSZc-RRPaFHP.TWL@flex--yosryahmed.bounces.google.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: CDE09C0002 X-HE-Tag: 1649393869-656562 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000071, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Currently, cg_write() returns 0 on success and -1 on failure. Modify it to return the errno of write() syscall when write() fails. Signed-off-by: Yosry Ahmed Acked-by: Roman Gushchin --- tools/testing/selftests/cgroup/cgroup_util.c | 32 +++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index dbaa7aabbb4a..3b6bb09985fa 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -38,23 +38,23 @@ static ssize_t read_text(const char *path, char *buf, size_t max_len) return len; } -static ssize_t write_text(const char *path, char *buf, ssize_t len) +/* + * Returns: + * success -> 0 + * open() failure -> -1 + * write() failure -> errno + */ +static int write_text(const char *path, char *buf, ssize_t len) { - int fd; + int fd, ret; fd = open(path, O_WRONLY | O_APPEND); if (fd < 0) return fd; - len = write(fd, buf, len); - if (len < 0) { - close(fd); - return len; - } - + ret = write(fd, buf, len) < 0 ? errno : 0; close(fd); - - return len; + return ret; } char *cg_name(const char *root, const char *name) @@ -177,17 +177,19 @@ long cg_read_lc(const char *cgroup, const char *control) return cnt; } +/* + * Returns: + * success -> 0 + * open() failure -> -1 + * write() failure -> errno + */ int cg_write(const char *cgroup, const char *control, char *buf) { char path[PATH_MAX]; ssize_t len = strlen(buf); snprintf(path, sizeof(path), "%s/%s", cgroup, control); - - if (write_text(path, buf, len) == len) - return 0; - - return -1; + return write_text(path, buf, len); } int cg_find_unified_root(char *root, size_t len)