From patchwork Thu Apr 7 22:42:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 12805879 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 855B5C433EF for ; Thu, 7 Apr 2022 22:44:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 501DC8D0002; Thu, 7 Apr 2022 18:43:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4886A6B0074; Thu, 7 Apr 2022 18:43:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2DD248D0002; Thu, 7 Apr 2022 18:43:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.25]) by kanga.kvack.org (Postfix) with ESMTP id 1BAB76B0073 for ; Thu, 7 Apr 2022 18:43:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 3EF4621266 for ; Thu, 7 Apr 2022 22:43:13 +0000 (UTC) X-FDA: 79331560266.13.3B7C4BF Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf11.hostedemail.com (Postfix) with ESMTP id CFA2E40005 for ; Thu, 7 Apr 2022 22:43:12 +0000 (UTC) Received: by mail-pg1-f201.google.com with SMTP id z132-20020a63338a000000b003844e317066so3739323pgz.19 for ; Thu, 07 Apr 2022 15:43:12 -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=pAk5rXzYOgjs6QN7PF4DKfEiueSRXqJopL6r+G+SYMg=; b=qv/ZfWS96JL8ToxxS9HkzUsNxcgjDjomFpfz2944+t+BaDBFk//TDRRG0EQou1qHv2 eqtDQoRcsXpquUS0GLLciQ+s6RJpZuc5N56AEikJDuC/RYBBajToGFWwv8SSCf70AJn5 nAvqvnMqE3DpzvAAnlizcVl8NObJlzGhEZrLv1CqOzM7NbEyFhaP9l17bP/X/kcgXvqH Z383gcxcH0YzFx6TkICE9yiq1GpgaghTRTqqOm1KrLlQVkWbnwK1LdgyPxl33cFL/TQS APv0PQrKflod2nwRa68HyFfut0wbUsxWxrxhZDN+gvGGIijQIlAlL739L4M7oVvMtwlR WQkQ== 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=pAk5rXzYOgjs6QN7PF4DKfEiueSRXqJopL6r+G+SYMg=; b=eJ5zbOqsjYEDPwE2qVQ1kyyEQTqS2G0RnRL1KxnvuVkEnlZvUhpOi4Y/z4JW/6bLY7 isu5I8POUx6ARFWhOKZQOapGuVJXnQhlL1QGjx+fEwTxkQ/Gb1w8/CgPKFYlyQyKHmIH PMtigkFU0PC2kgT1nwZ25tDuumUE+B+ZOtsYGzIuvhHR21j01x7EKsm2W04U8R4PXu4X C+xBNuENpP6QWU/cBYNpIj7TFPaOsfNQ39HuGjLfthf8dAu+UAleY37oo42M5j31ZzJ8 URiTvdXfPioPC6Nic157n4lN3tgCGC8UGkpw33DoqozacZuTMNMVLuoHXI5XVLDMNW83 4WdA== X-Gm-Message-State: AOAM533azOs4EL7f3tlfGl2yv9u7dIzXGy6NMmQEUj1BGb9xelIlAz7J aIGkHkIcJTFpjgFKI8/MHzl7czemhwHNU/0o X-Google-Smtp-Source: ABdhPJz/m6t1/bLDKPjThB/2Yt1mSc3IiH/+dngiTDVwURy7M/hstiNpOlv5+A8nC+3p1I4e1xSZSGYn6L82YpXb X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a17:902:b694:b0:153:1d9a:11a5 with SMTP id c20-20020a170902b69400b001531d9a11a5mr16223355pls.151.1649371391903; Thu, 07 Apr 2022 15:43:11 -0700 (PDT) Date: Thu, 7 Apr 2022 22:42:42 +0000 In-Reply-To: <20220407224244.1374102-1-yosryahmed@google.com> Message-Id: <20220407224244.1374102-3-yosryahmed@google.com> Mime-Version: 1.0 References: <20220407224244.1374102-1-yosryahmed@google.com> X-Mailer: git-send-email 2.35.1.1178.g4f1659d476-goog Subject: [PATCH v2 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 , Huang@google.com, Ying , " =?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 Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="qv/ZfWS9"; spf=pass (imf11.hostedemail.com: domain of 3_2hPYgoKCCgcSWVcELQIHKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--yosryahmed.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3_2hPYgoKCCgcSWVcELQIHKSSKPI.GSQPMRYb-QQOZEGO.SVK@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 7ngxy9sxsqxsfjat4x78qi1qgfbgzdc6 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CFA2E40005 X-HE-Tag: 1649371392-455867 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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 on failure. Signed-off-by: Yosry Ahmed --- tools/testing/selftests/cgroup/cgroup_util.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/cgroup/cgroup_util.c b/tools/testing/selftests/cgroup/cgroup_util.c index dbaa7aabbb4a..ef76db6026aa 100644 --- a/tools/testing/selftests/cgroup/cgroup_util.c +++ b/tools/testing/selftests/cgroup/cgroup_util.c @@ -48,6 +48,8 @@ static ssize_t write_text(const char *path, char *buf, ssize_t len) len = write(fd, buf, len); if (len < 0) { + /* preserve the errno of write() */ + len = errno; close(fd); return len; } @@ -177,17 +179,16 @@ long cg_read_lc(const char *cgroup, const char *control) return cnt; } +/* Returns 0 on success, or the errno of write() on failure. */ int cg_write(const char *cgroup, const char *control, char *buf) { char path[PATH_MAX]; - ssize_t len = strlen(buf); + ssize_t len = strlen(buf), ret; snprintf(path, sizeof(path), "%s/%s", cgroup, control); - if (write_text(path, buf, len) == len) - return 0; - - return -1; + ret = write_text(path, buf, len); + return ret == len ? 0 : ret; } int cg_find_unified_root(char *root, size_t len)