From nobody Tue Apr 7 15:26:14 2026 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 B505B33C1A7 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=1772058866; cv=none; b=ijShZ2eWDzBwu52LTwDoR3q22NTjA7LGbW0tPHZX5d+AKQ5ZypZdtEzdKL55ya7dKDGXDzPB44bP1Z6VEqJ/DItrdNtMTPIw4sJfoc5N357Ton3kmJjKzFts5k/ORNHCG+1yLyQIV4xs8iitBjMWTW6dVMdo3VmPKBWHuPcG/3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772058866; c=relaxed/simple; bh=ymKrZvnn1wXoX3MO7tLDPSCDvegTjqhP4f2VwqTSGPs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=gOM0ypT8Zx7slKOMrG4Cph4JR2EEkCd7xoaY7YGo2hxROjy6UMO2j1jbhv0g8Ntm1mfCq3gFR5QxV9Wkb4PTSatoPH54pwikk4/cn7balweRLoXoQ07YmP0jgxdEGCYBJmUOU8qFTrjlb6QeG8c+QRfmgpK7cggzYKvmzmhQ0N8= 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-2add59d1a5aso997405ad.3 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=C8Q5pBnCpTtYd24y1Sbn2VFZT7kkRoZuSSl6GO9cuukP4FmjeEz7sLkwWkzTdGFPfS RNcVrHh+xZtk5xi55GJWZuL4EmJpzkWbVJgPRTCx+2a4hArjyDG6v9ST7dp2CqyjMv9L TvASzsUzzDDNQkJgWTaJcvMfMdYg+SqzdRNfz2mHOA78pOyGB5T3JDjxU4pH4CL+fV+y lkG3X0ScrKzGFezA3zNsGQgcQ42ekGsJT/xv4v8YxHjH4gArRvegioKAn1b2CO3HXEOU bdC4u4ztvOPI7Yc3ibFSRsu0NsNo4rUpAgZ6WJlleP2XG3YbjZq93SorivBQ2m3jt8l6 4dSw== X-Forwarded-Encrypted: i=1; AJvYcCWMQQoiWwvic0D2S022MLRkIJV8fi2LwoWLhjaJFdaa2gmXJMwfktdN/JGYw0wCpOdTDNADsx7W8zrG4aI=@vger.kernel.org X-Gm-Message-State: AOJu0YxAEFqONPnn6bZqTbyVNWRxt1akHqgr63TqDrjvxHRpD71+IWmj gfzV4hN8WAawBeo1dngL9fVV968Ih2ZNq6+o8imVh8/QvW1jbD1GJ1sJDzm6ZuuvwT7YOr/68IM RcnYW7W5F74NJLXSWIA== 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: linux-kernel@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-Transfer-Encoding: quoted-printable 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/testi= ng/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; } =20 +static int read_event(int inotify_fd, int expected_event, int expected_wd) +{ + struct inotify_event event; + ssize_t len =3D 0; + + len =3D read(inotify_fd, &event, sizeof(event)); + if (len < (ssize_t)sizeof(event)) + return -1; + + if (event.mask !=3D expected_event || event.wd !=3D expected_wd) { + fprintf(stderr, + "event does not match expected values: mask %d (expected %d) wd %d (exp= ected %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 =3D KSFT_FAIL; + char *memcg =3D NULL; + int fd, wd; + + memcg =3D cg_name(root, "memcg_test_0"); + + if (!memcg) + goto cleanup; + + if (cg_create(memcg)) + goto cleanup; + + fd =3D inotify_init1(0); + if (fd =3D=3D -1) + goto cleanup; + + wd =3D inotify_add_watch(fd, cg_control(memcg, "memory.events"), IN_DELET= E_SELF); + if (wd =3D=3D -1) + goto cleanup; + + if (cg_destroy(memcg)) + goto cleanup; + free(memcg); + memcg =3D NULL; + + if (read_event(fd, IN_DELETE_SELF, wd)) + goto cleanup; + + if (read_event(fd, IN_IGNORED, wd)) + goto cleanup; + + ret =3D KSFT_PASS; + +cleanup: + if (fd >=3D 0) + close(fd); + if (memcg) + cg_destroy(memcg); + free(memcg); + + return ret; +} + +static int test_memcg_inotify_delete_dir(const char *root) +{ + int ret =3D KSFT_FAIL; + char *memcg =3D NULL; + int fd, wd; + + memcg =3D cg_name(root, "memcg_test_0"); + + if (!memcg) + goto cleanup; + + if (cg_create(memcg)) + goto cleanup; + + fd =3D inotify_init1(0); + if (fd =3D=3D -1) + goto cleanup; + + wd =3D inotify_add_watch(fd, memcg, IN_DELETE_SELF); + if (wd =3D=3D -1) + goto cleanup; + + if (cg_destroy(memcg)) + goto cleanup; + free(memcg); + memcg =3D NULL; + + if (read_event(fd, IN_DELETE_SELF, wd)) + goto cleanup; + + if (read_event(fd, IN_IGNORED, wd)) + goto cleanup; + + ret =3D KSFT_PASS; + +cleanup: + if (fd >=3D 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 =20 --=20 2.53.0.414.gf7e9f6c205-goog