Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp189108lqo; Thu, 16 May 2024 03:29:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXNCSAn3oH/CFo3laoh1S3/L4TjNfJj0jqvXZKTcRsA+G6cqUwJYdKX1E+IT/FQtLwWpd/haEADDOU7+Sz3OoiyL6t8KdJjwBfh6Xdq/g== X-Google-Smtp-Source: AGHT+IHN9Puhy6abD3jkDZEvVofSS35S/x0GW1f4760gmFDNv4ELd8AeqPyGGeZX1gNK/nOfKoBb X-Received: by 2002:a50:9fc9:0:b0:572:7c97:6c58 with SMTP id 4fb4d7f45d1cf-5734d5be310mr12643026a12.5.1715855352394; Thu, 16 May 2024 03:29:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715855352; cv=pass; d=google.com; s=arc-20160816; b=TnrnYsNbl9hywVpirzfREA6MjlsLXuILmJgu5e5STlW2zJtRojqYWb9QVMx7rcCBSc Wehcxc36ye6E08lPdvd5bsxM0FDDoOaxbcUEcIijJ4XjhD5goB9vD3aqxAO9lMabPpF3 +XWMus5y3Esozd+ZurRcgijZxrVsIvkppLNKwJDBQoa4Yad727VALHMS/Oa2o47e3Qln RXMh6/rqb68vEkZEWNTedkB7Q0tzemG+Y8XfZ5JNUdPdgzJRVni9HkBYNEzuwlvTrLDG xmEaVb8HbC+c+xIgkCZhr4EiWxwRuDJNt9JY/JVRPce8BN2TAp0qUDi15sU2wozX795I BtSQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:message-id:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:subject:date :from:dkim-signature; bh=BtVMBjfm2Rr6sHr+9ieDEUQVIdDe87XltcnTckXPsQo=; fh=JGIFBcgTyi8iJa1VSa20iouK0gS5HA4HQWDR2yt+GlQ=; b=tmYRw10gWhYtIHhQGrkHp8g1tuDHibIAWpg38a/X0s8cXUx02IZ4qNSz6IKVDw8ij1 7GlV1lUXHjbGBySc+lHxjgi3r+oWltS55hnO6PUzrD850LoarUXEVRFeKUQ/u2peJdgy C53zn9zL6BZKPF4KEQUHAqubMjMspCzKSHpzoW9TowNH8UNZCGbKOs/g6uj47S9dxim3 9HnMUgU4K0lmF2PHjwFykUuQb4+GCmVwC5ZKzQyjfTzoS7vIBZht6iqG7xPAxoD51WbI 7sIAP9fdNDgmiRhlLe9g2nEZL1HS3zkKS89E5X6QGL6Jca0ZM9xuKY+Zrqgm/PDborMQ PzxA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=p7GQIrVf; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-180907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180907-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733c36d6d7si8089331a12.544.2024.05.16.03.29.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 03:29:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@weissschuh.net header.s=mail header.b=p7GQIrVf; arc=pass (i=1 spf=pass spfdomain=weissschuh.net dkim=pass dkdomain=weissschuh.net); spf=pass (google.com: domain of linux-kernel+bounces-180907-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180907-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 26D6E1F228E6 for ; Thu, 16 May 2024 10:29:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05811143C47; Thu, 16 May 2024 10:29:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b="p7GQIrVf" Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A59A143866; Thu, 16 May 2024 10:28:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=159.69.126.157 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715855344; cv=none; b=qJZpvFPNRYh3TLvwyCdnZCyooyN4SjGFP3CadvlhDp78l3MQTdiBH3d2Gtv+tpCKpjImcMkw5ZxsmSMwsEQEaaYg/La24UzF7qsGjtfkBfPQcXV1JvdOdhdOT1bswP2baw4+js2Kz9fZIkmWjlGG6GBa5LCZp3qvxkwhkdHp00Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715855344; c=relaxed/simple; bh=rhWKU/w9EhYtdGU3yXEB9F2o1FFwvXQv9QHzvfSeWm8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:To:Cc; b=T95Mkz0psLIJ+91lv/Y9zPy6DkewsfdpXHid1QOmEpl1x9pzBrslQ5eXtyvXvk1FGsPj0lVWbbHUBJ2QmfJU1J7tBBHEA+VPmd9C4YwRmJE218Tzp4BYa4UFX0kXyLGfPaXApzSaa4WtyGmSEZrReo9J+/vo6qPsyIyylU3TIus= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net; spf=pass smtp.mailfrom=weissschuh.net; dkim=pass (1024-bit key) header.d=weissschuh.net header.i=@weissschuh.net header.b=p7GQIrVf; arc=none smtp.client-ip=159.69.126.157 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=weissschuh.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=weissschuh.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1715855331; bh=rhWKU/w9EhYtdGU3yXEB9F2o1FFwvXQv9QHzvfSeWm8=; h=From:Date:Subject:To:Cc:From; b=p7GQIrVfXT/4YTBAILCAbJv/R+06z/uETHEniJwvS7mLHUItHoFambXxhAba5qizg xk+TWh4InQukHD6QBu5u7NrFL4jIqsSrgPdjIE6gJxXXzUTcFX1FN1y/4BdWu29Z3z mYIhUHIolrhGgUxd8crwlUslX0zO1c/xRRRsUDbQ= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Thu, 16 May 2024 12:27:58 +0200 Subject: [PATCH RFC] kobject_uevent: notify uevent sysfs file on changes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20240516-uevent-sysfs-notify-v1-1-2ebb39930c09@weissschuh.net> X-B4-Tracking: v=1; b=H4sIAK3fRWYC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDIxMDU0NT3dLUstS8Et3iyuK0Yt28/JLMtEpdk9Qky1RLU2NL87QUJaDOgqL UtMwKsKnRSkFuzkqxtbUANjsAumoAAAA= To: Andrew Morton , Greg Kroah-Hartman , "Rafael J. Wysocki" Cc: linux-kernel@vger.kernel.org, Sebastian Reichel , linux-pm@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715855331; l=1997; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=rhWKU/w9EhYtdGU3yXEB9F2o1FFwvXQv9QHzvfSeWm8=; b=LTz1bpDcGQFHz/mOSRq2nXcpsX6XtUet8VwgBaPFE6QIY63XT4/pGmiPw57GoK7UVOIgNNEjN qGdjFBZrdOIBOQnLeg6GhMtSOIBtuPmVC2ubITEfRPV1HGf6XVM0hbp X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= The sysfs file "uevent" that exists for each device contains the same information that is attached to uevents emitted via netlink (or the usermode helper). This is useful for userspace which interacts with sysfs directly, without using (lib)udev. However it is not possible to actually get notified when the data in the "uevent" file changes. Enable these notifications, so that the "uevent" file can be used together with inotify and friends. Signed-off-by: Thomas Weißschuh --- My original usecase is to get updates for power supplies. Current charge status and similar. All this data is exposed via "uevent", and on updates an KOBJ_CHANGED event is emitted. To me, a general solution covering all devices looked the best. Open questions for the RFC: * Is this a good idea? * How to handle other actions? _ADD and _REMOVE should not call sysfs_notify() in any case, these cases can be detected otherwise. --- lib/kobject_uevent.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index 03b427e2707e..74047a79cb13 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -593,6 +594,9 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, retval = kobject_uevent_net_broadcast(kobj, env, action_string, devpath); + if (action == KOBJ_CHANGE) + sysfs_notify(kobj, NULL, "uevent"); + #ifdef CONFIG_UEVENT_HELPER /* call uevent_helper, usually only enabled during early boot */ if (uevent_helper[0] && !kobj_usermode_filter(kobj)) { --- base-commit: 3c999d1ae3c75991902a1a7dad0cb62c2a3008b4 change-id: 20240515-uevent-sysfs-notify-4eb9e95397fd Best regards, -- Thomas Weißschuh