From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD8C1C43216 for ; Thu, 29 Jul 2021 01:54:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B76961042 for ; Thu, 29 Jul 2021 01:54:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233286AbhG2Bye (ORCPT ); Wed, 28 Jul 2021 21:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233153AbhG2Byd (ORCPT ); Wed, 28 Jul 2021 21:54:33 -0400 Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19F17C061757; Wed, 28 Jul 2021 18:54:30 -0700 (PDT) Received: by mail-ot1-x334.google.com with SMTP id h63-20020a9d14450000b02904ce97efee36so4189578oth.7; Wed, 28 Jul 2021 18:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1f/SxtepgyjeAa5xFLbjbkeuNqISFy3PTrve9ir2rAc=; b=fCOe4rqRxw6SqV9uk9MpxuiUC9149oYHi6rbVfcg+KgaE/qHn5mwswIDYJ0SwFY+b1 eK8FEBwMJCp5rFT1S7dp42jG+v+nFBG/Us+bUu6uDCHYePeRlFv6MhsMm69K5wjSKaDC ZFolXFJka7u7RyUTzJgt34evLcRvH3aSOZ/PUVpT1k4QA9LSoH70nVLMg0m2N6lWAwYs +3E/4wnPo07PBFMvFtFc9lfx7Z6EmXltY2bNbOd8bupO+Lu1dmzX67pNhZpUgs4dn6XM tQWab73+IufvgU6kDVHJSx6kp62GyIKZf7re2lzyja5O1Z1Zny5etk2WtcAxU+7ohU3o EopA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1f/SxtepgyjeAa5xFLbjbkeuNqISFy3PTrve9ir2rAc=; b=tXmEaB+dAjjvuBcSZU4Fo0tTmXRRDsl/qcdNXpfIZL7sk4wZ2FIXo8tQyp71Nw2u8Z brZLLmnISDHlcv5UpIBypwWCWcGraS+7/ap4NWubzE3pUkHytRZG1CotkamGdRgUVnQx C3YKbwMIgxqhBuaAIzx1Y2LZC/e8Uz/AJVzTyiaPm97OsfZq0Bzhdwb9OIhl4HJKAZ55 c6nfEIF76EL4tFL8j1F4+zMM2lEPEblmdELcTqpDqD/2d9IEGWFWukWr/P27eSkQQCoo rW22M0r/FRiqjxNotiJPEbsR3TLP9rzpqjpRd7oIrrOKz3/nEtToBPsFyYwH63BZh38C Qeww== X-Gm-Message-State: AOAM531BhPebQPm9bqjicBg8GB7byzS70dZrYIVwdGGok+13WchDssa6 kqXSxNcsMW2mN1pSX+/ma6GUxA0ZhEy1B/uD X-Google-Smtp-Source: ABdhPJw8oRvrTnkHJKTijlAFiacDHgpqLu1mz1oZfo3fN8XvtZva5yr2NFp9LnaHTjz3UQrKimxbSw== X-Received: by 2002:a05:6830:23a7:: with SMTP id m7mr1910820ots.17.1627523669477; Wed, 28 Jul 2021 18:54:29 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id c11sm311424otm.37.2021.07.28.18.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 18:54:29 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org, Ian Pilcher Subject: [RFC PATCH 2/8] block: Add block device LED trigger list Date: Wed, 28 Jul 2021 20:53:38 -0500 Message-Id: <20210729015344.3366750-3-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210729015344.3366750-1-arequipeno@gmail.com> References: <20210729015344.3366750-1-arequipeno@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org * New config option (CONFIG_BLK_LED_TRIGGERS) to enable/disable block device LED triggers * New file - block/blk-ledtrig.c * Use a linked list of dynamically allocated triggers. There aren't likely to be that many of them, and the list is only searched when creating/deleting a trigger or setting/clearing a device/trigger association - none of which should occur very often. Signed-off-by: Ian Pilcher --- block/Kconfig | 10 +++++++++ block/Makefile | 1 + block/blk-ledtrig.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 block/blk-ledtrig.c diff --git a/block/Kconfig b/block/Kconfig index fd732aede922..051488413d6e 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -220,6 +220,16 @@ config BLK_INLINE_ENCRYPTION_FALLBACK by falling back to the kernel crypto API when inline encryption hardware is not present. +config BLK_LED_TRIGGERS + bool "Enable block device LED triggers" + depends on LEDS_TRIGGERS + help + Enabling this allows LED triggers to be created and + associated with block devices via sysfs/udev (or an + in-kernel API). These trigers can be used to drive + physical or user-space activity indicators. See + Documentation/block/led-triggers.rst. + menu "Partition Types" source "block/partitions/Kconfig" diff --git a/block/Makefile b/block/Makefile index bfbe4e13ca1e..bcd97ee26462 100644 --- a/block/Makefile +++ b/block/Makefile @@ -42,3 +42,4 @@ obj-$(CONFIG_BLK_SED_OPAL) += sed-opal.o obj-$(CONFIG_BLK_PM) += blk-pm.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION) += keyslot-manager.o blk-crypto.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK) += blk-crypto-fallback.o +obj-$(CONFIG_BLK_LED_TRIGGERS) += blk-ledtrig.o diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c new file mode 100644 index 000000000000..345a3b6bdbc6 --- /dev/null +++ b/block/blk-ledtrig.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Block device LED triggers + * + * Copyright 2021 Ian Pilcher + */ + +#include +#include +#include + + +/* + * + * The list of block device LED triggers + * + */ + +struct blk_ledtrig { + struct led_trigger trigger; + struct list_head list_node; + struct mutex refcount_mutex; + int refcount; + char name[]; +}; + +LIST_HEAD(blk_ledtrig_list); +DEFINE_MUTEX(blk_ledtrig_list_mutex); + +static inline +struct blk_ledtrig *blk_ledtrig_from_node(struct list_head *const node) +{ + return container_of(node, struct blk_ledtrig, list_node); +} + +// Caller must hold blk_ledtrig_list_mutex +static struct blk_ledtrig *blk_ledtrig_find(const char *const name, + const size_t len) +{ + struct blk_ledtrig *t; + struct list_head *n; + + list_for_each(n, &blk_ledtrig_list) { + t = blk_ledtrig_from_node(n); + if (strlen(t->name) == len && memcmp(name, t->name, len) == 0) + return t; + } + + return NULL; +} -- 2.31.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF938C4338F for ; Thu, 29 Jul 2021 01:57:06 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 79B1F6056C for ; Thu, 29 Jul 2021 01:57:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 79B1F6056C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1m8vI9-0006Ah-OU; Wed, 28 Jul 2021 21:56:57 -0400 Received: from mail-ot1-x333.google.com ([2607:f8b0:4864:20::333]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1m8vFn-0002iI-EH for kernelnewbies@kernelnewbies.org; Wed, 28 Jul 2021 21:54:31 -0400 Received: by mail-ot1-x333.google.com with SMTP id v8-20020a0568301bc8b02904d5b4e5ca3aso4158647ota.13 for ; Wed, 28 Jul 2021 18:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1f/SxtepgyjeAa5xFLbjbkeuNqISFy3PTrve9ir2rAc=; b=fCOe4rqRxw6SqV9uk9MpxuiUC9149oYHi6rbVfcg+KgaE/qHn5mwswIDYJ0SwFY+b1 eK8FEBwMJCp5rFT1S7dp42jG+v+nFBG/Us+bUu6uDCHYePeRlFv6MhsMm69K5wjSKaDC ZFolXFJka7u7RyUTzJgt34evLcRvH3aSOZ/PUVpT1k4QA9LSoH70nVLMg0m2N6lWAwYs +3E/4wnPo07PBFMvFtFc9lfx7Z6EmXltY2bNbOd8bupO+Lu1dmzX67pNhZpUgs4dn6XM tQWab73+IufvgU6kDVHJSx6kp62GyIKZf7re2lzyja5O1Z1Zny5etk2WtcAxU+7ohU3o EopA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1f/SxtepgyjeAa5xFLbjbkeuNqISFy3PTrve9ir2rAc=; b=Ab9xN1cIeMXD2O+g/VqHHJpqIhCCFCtNsbzyl2fkaCeVJ08cDifunNUIbtUlh1wrBD 05WP/T4HYDnjNr1IjR4afuTURTEo5bMN3qJHblmRxYOF64++g4/42pXBX1UrTNy3dTf+ 8n+B4nbT5gaR2JI+LNZBEt0mAn11uleatGzdPcZZWX7FoAm4ecTAWnDS21yS5xZUVv9J Jf/BtYiXmO0J3wNdjXhxAX767CgEECUsPTn4v4+nVyLSc+BccbypOQVIM30XJYMQLU4w d3JH0UubN03S/RTHkkr5YBMbgG5tUVqEl10OqPulWZWIT9xOXGFwmOCNlxB1K4jF+B+2 kOdw== X-Gm-Message-State: AOAM530fut0iXBqsoFbfvG8q1eBOPHDyhVYPb2QNJwwqLS7czk6B11VH o4KvpfaBz9tz/nPFZOyvHR4= X-Google-Smtp-Source: ABdhPJw8oRvrTnkHJKTijlAFiacDHgpqLu1mz1oZfo3fN8XvtZva5yr2NFp9LnaHTjz3UQrKimxbSw== X-Received: by 2002:a05:6830:23a7:: with SMTP id m7mr1910820ots.17.1627523669477; Wed, 28 Jul 2021 18:54:29 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id c11sm311424otm.37.2021.07.28.18.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 18:54:29 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Subject: [RFC PATCH 2/8] block: Add block device LED trigger list Date: Wed, 28 Jul 2021 20:53:38 -0500 Message-Id: <20210729015344.3366750-3-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210729015344.3366750-1-arequipeno@gmail.com> References: <20210729015344.3366750-1-arequipeno@gmail.com> MIME-Version: 1.0 Cc: axboe@kernel.dk, Ian Pilcher , linux-kernel@vger.kernel.org, pavel@ucw.cz, kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org * New config option (CONFIG_BLK_LED_TRIGGERS) to enable/disable block device LED triggers * New file - block/blk-ledtrig.c * Use a linked list of dynamically allocated triggers. There aren't likely to be that many of them, and the list is only searched when creating/deleting a trigger or setting/clearing a device/trigger association - none of which should occur very often. Signed-off-by: Ian Pilcher --- block/Kconfig | 10 +++++++++ block/Makefile | 1 + block/blk-ledtrig.c | 51 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 block/blk-ledtrig.c diff --git a/block/Kconfig b/block/Kconfig index fd732aede922..051488413d6e 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -220,6 +220,16 @@ config BLK_INLINE_ENCRYPTION_FALLBACK by falling back to the kernel crypto API when inline encryption hardware is not present. +config BLK_LED_TRIGGERS + bool "Enable block device LED triggers" + depends on LEDS_TRIGGERS + help + Enabling this allows LED triggers to be created and + associated with block devices via sysfs/udev (or an + in-kernel API). These trigers can be used to drive + physical or user-space activity indicators. See + Documentation/block/led-triggers.rst. + menu "Partition Types" source "block/partitions/Kconfig" diff --git a/block/Makefile b/block/Makefile index bfbe4e13ca1e..bcd97ee26462 100644 --- a/block/Makefile +++ b/block/Makefile @@ -42,3 +42,4 @@ obj-$(CONFIG_BLK_SED_OPAL) += sed-opal.o obj-$(CONFIG_BLK_PM) += blk-pm.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION) += keyslot-manager.o blk-crypto.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK) += blk-crypto-fallback.o +obj-$(CONFIG_BLK_LED_TRIGGERS) += blk-ledtrig.o diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c new file mode 100644 index 000000000000..345a3b6bdbc6 --- /dev/null +++ b/block/blk-ledtrig.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Block device LED triggers + * + * Copyright 2021 Ian Pilcher + */ + +#include +#include +#include + + +/* + * + * The list of block device LED triggers + * + */ + +struct blk_ledtrig { + struct led_trigger trigger; + struct list_head list_node; + struct mutex refcount_mutex; + int refcount; + char name[]; +}; + +LIST_HEAD(blk_ledtrig_list); +DEFINE_MUTEX(blk_ledtrig_list_mutex); + +static inline +struct blk_ledtrig *blk_ledtrig_from_node(struct list_head *const node) +{ + return container_of(node, struct blk_ledtrig, list_node); +} + +// Caller must hold blk_ledtrig_list_mutex +static struct blk_ledtrig *blk_ledtrig_find(const char *const name, + const size_t len) +{ + struct blk_ledtrig *t; + struct list_head *n; + + list_for_each(n, &blk_ledtrig_list) { + t = blk_ledtrig_from_node(n); + if (strlen(t->name) == len && memcmp(name, t->name, len) == 0) + return t; + } + + return NULL; +} -- 2.31.1 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies