From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B514933C515 for ; Wed, 25 Feb 2026 22:34:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772058865; cv=none; b=dzwPi+7u/SToIwRqW6rnyV2FpJ2Y8N1MUsrEPrHQrNMqMKe0tVMHR92lYABKyhbkZx27HsDivOgDf8motsR3sKgxIqEyunaXNj/ZuSdcj2ZxIivcj0dcFHzhv6Tdhkc+r+KP2Rfv7iILdYrdZsRcPsKhhFYOZXFsZeEhCWzDWgI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772058865; c=relaxed/simple; bh=ymKrZvnn1wXoX3MO7tLDPSCDvegTjqhP4f2VwqTSGPs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NtUmPWJfznllei6hK7yhD0qTgnr9GBLxnf2dzM3v/tPXqe1G0WXBOaXojkEeAFOugI9BvEUOwpta1B0KXOcgZxFD/TkECqHZHZg9hRR3/m44dkFzuZfnm0Zt/Ay19Zpbq8yBkQsRTyrA/Vwew9UV7AP454wIw3tbj4GFwQl3zA0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=fRyqgEis; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--tjmercier.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fRyqgEis" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2aad5fc5b2fso1209535ad.1 for ; Wed, 25 Feb 2026 14:34:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772058860; x=1772663660; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=VLezOUj++5KtU+iy76kNFYSHOIOxW3z9n/oglLgyr0s=; b=fRyqgEis2xyUjaczHDwUma1EDA4AN3QlAcp39p2ElDW4QdhH0DTLDPCl7rTl5rsZfh Y/ck5cCTlHbNLSolchZLjwn9VSuHY3NZZ1siS5e/dTqtYxfDTWYgaUqQ9RbV42/Dx2lp 5aJsid0eP1DXY4+W6icRzkGWD8wx1Qmv4uRhPoUzdIKx7wwtLVb1iW5xHv0trPMR3qDo 4oOanaN7QY1I2kSkutdShCw1hportGfjNSeQH6lxleyityFGAjNU91i7EA+eyop34/e0 R5REy3LkQFB3KGJRT274Er5i19oVizrit3USMZ0IZxf6EZgXh0+M7llGlnj5nVMB5zlM 118g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772058860; x=1772663660; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VLezOUj++5KtU+iy76kNFYSHOIOxW3z9n/oglLgyr0s=; b=vl+eAdq0J2NnSQOYx8lRqrJ09DrEqxScV0OrJwZJr0uMTnCRBzTVJpB75z7/bGvFKy ZQzTKadTl3r4wz6o+JYx0qq2ANOqiLYbZpH1q7tPCLZ0LK3ipXhJiHTQHG77y2uHPD+W 8JRiQV/CWH42sMNaEolzPqsUE8C81Bg24PEmHO5W9xwhjyUdBQ7NBo2O/GJG12gphzew SqHQiTxDiuepLYBqjZ8DIGWJU9KJP8COuU5o1eLty1w3h+Ca0rvbJqtMRawPsUSAt9tX GP9EPXxTAXWC5YpOl73mDHljboYxF1tdg/m25BkKiWd9xIbzxFOjG74e138+Jpw9mVH1 OzUA== X-Forwarded-Encrypted: i=1; AJvYcCVjJ7QttdEu5M1qNuQ8dPUYMIAu43w8565INlWYCvh4X9Vcb7xs7RSwMWiU/+1z6eSmfAoDR7TA@vger.kernel.org X-Gm-Message-State: AOJu0Yy6tZTc2idheSxmzsMQAPcFdeRu1H1aK7kY26gLosjpDU4Na/NY xdPtN+M5zOnPSuNPtHmb7iucIJr/z/LbH70BTfKlc06WUNSka/OMokUOeRzpsGlk2p0j04NIAkw Y8fSnVTiDksZ9mb0nPg== X-Received: from plbld14.prod.google.com ([2002:a17:902:face:b0:2a7:7822:9011]) (user=tjmercier job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:b48:b0:2a0:bb05:df55 with SMTP id d9443c01a7336-2ae034613a3mr358175ad.21.1772058859947; Wed, 25 Feb 2026 14:34:19 -0800 (PST) Date: Wed, 25 Feb 2026 14:34:04 -0800 In-Reply-To: <20260225223404.783173-1-tjmercier@google.com> Precedence: bulk X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260225223404.783173-1-tjmercier@google.com> X-Mailer: git-send-email 2.53.0.414.gf7e9f6c205-goog Message-ID: <20260225223404.783173-4-tjmercier@google.com> Subject: [PATCH v5 3/3] selftests: memcg: Add tests for IN_DELETE_SELF and IN_IGNORED From: "T.J. Mercier" To: gregkh@linuxfoundation.org, tj@kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-fsdevel@vger.kernel.org, jack@suse.cz, amir73il@gmail.com, shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: "T.J. Mercier" Content-Type: text/plain; charset="UTF-8" Add two new tests that verify inotify events are sent when memcg files or directories are removed with rmdir. Signed-off-by: T.J. Mercier Acked-by: Tejun Heo Acked-by: Amir Goldstein --- .../selftests/cgroup/test_memcontrol.c | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_memcontrol.c b/tools/testing/selftests/cgroup/test_memcontrol.c index 4e1647568c5b..57726bc82757 100644 --- a/tools/testing/selftests/cgroup/test_memcontrol.c +++ b/tools/testing/selftests/cgroup/test_memcontrol.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -1625,6 +1626,115 @@ static int test_memcg_oom_group_score_events(const char *root) return ret; } +static int read_event(int inotify_fd, int expected_event, int expected_wd) +{ + struct inotify_event event; + ssize_t len = 0; + + len = read(inotify_fd, &event, sizeof(event)); + if (len < (ssize_t)sizeof(event)) + return -1; + + if (event.mask != expected_event || event.wd != expected_wd) { + fprintf(stderr, + "event does not match expected values: mask %d (expected %d) wd %d (expected %d)\n", + event.mask, expected_event, event.wd, expected_wd); + return -1; + } + + return 0; +} + +static int test_memcg_inotify_delete_file(const char *root) +{ + int ret = KSFT_FAIL; + char *memcg = NULL; + int fd, wd; + + memcg = cg_name(root, "memcg_test_0"); + + if (!memcg) + goto cleanup; + + if (cg_create(memcg)) + goto cleanup; + + fd = inotify_init1(0); + if (fd == -1) + goto cleanup; + + wd = inotify_add_watch(fd, cg_control(memcg, "memory.events"), IN_DELETE_SELF); + if (wd == -1) + goto cleanup; + + if (cg_destroy(memcg)) + goto cleanup; + free(memcg); + memcg = NULL; + + if (read_event(fd, IN_DELETE_SELF, wd)) + goto cleanup; + + if (read_event(fd, IN_IGNORED, wd)) + goto cleanup; + + ret = KSFT_PASS; + +cleanup: + if (fd >= 0) + close(fd); + if (memcg) + cg_destroy(memcg); + free(memcg); + + return ret; +} + +static int test_memcg_inotify_delete_dir(const char *root) +{ + int ret = KSFT_FAIL; + char *memcg = NULL; + int fd, wd; + + memcg = cg_name(root, "memcg_test_0"); + + if (!memcg) + goto cleanup; + + if (cg_create(memcg)) + goto cleanup; + + fd = inotify_init1(0); + if (fd == -1) + goto cleanup; + + wd = inotify_add_watch(fd, memcg, IN_DELETE_SELF); + if (wd == -1) + goto cleanup; + + if (cg_destroy(memcg)) + goto cleanup; + free(memcg); + memcg = NULL; + + if (read_event(fd, IN_DELETE_SELF, wd)) + goto cleanup; + + if (read_event(fd, IN_IGNORED, wd)) + goto cleanup; + + ret = KSFT_PASS; + +cleanup: + if (fd >= 0) + close(fd); + if (memcg) + cg_destroy(memcg); + free(memcg); + + return ret; +} + #define T(x) { x, #x } struct memcg_test { int (*fn)(const char *root); @@ -1644,6 +1754,8 @@ struct memcg_test { T(test_memcg_oom_group_leaf_events), T(test_memcg_oom_group_parent_events), T(test_memcg_oom_group_score_events), + T(test_memcg_inotify_delete_file), + T(test_memcg_inotify_delete_dir), }; #undef T -- 2.53.0.414.gf7e9f6c205-goog