From patchwork Thu Sep 9 22:24:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508552 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.7 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 BE04BC43219 for ; Thu, 9 Sep 2021 22:25:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8916C611C7 for ; Thu, 9 Sep 2021 22:25:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345760AbhIIW0j (ORCPT ); Thu, 9 Sep 2021 18:26:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344830AbhIIW0f (ORCPT ); Thu, 9 Sep 2021 18:26:35 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A1A8C061575; Thu, 9 Sep 2021 15:25:25 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id n27so150225oij.0; Thu, 09 Sep 2021 15:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bS03gH8cDYgvnSLfr8sw2gf9sO3fp5rYXzNR2wunLpo=; b=gP0F9TDVP2eJ/K4hqxcGEN4xE574UeLdZinlUrJRAlWtcnaFxcLCR0hJVFDg8yMv1h sT3bs6UFXNx4pWRqNdRlcyuCVSbuN4RNosITz0FTuN6i+nAe7CDTuD61lsr7dOgF3jQj FDfzPHlSbmQDWp8OKgXyN/zHViZ1KyDP5pVIvdcRalrBmuphr/LckAdKjlxwQsgWFQSG 4YDH1gbEohg+D8aUSgOHPV2UpYZWVFUbBgxdiB9AkjbZfetQ3qsS0VcUuRSIQFbEWbow godwykb0LpHkAhlafEFsoqLXmDn0OpIeeG1RNXGiLHPHdtNddHuGE2TJtn2Blta5Hp0B /DBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bS03gH8cDYgvnSLfr8sw2gf9sO3fp5rYXzNR2wunLpo=; b=vAwOFBboa8+aZLInXJDFmJySm6kAaYt9i/iJB0T86t8YPh6IzlClaqqyQ5xQQTXY8e OKiQdvOPkj8ApHYw6DiwVDAVCiZWYqn91t9uDxqXv7mIJCWO0rMqO14gtfXO7lmrPBev OJMPD5QlaIa7YwIKEP1BdExqQfldqmnAMz0DtN73sUqr1KNZ6ZGH6vT/2VssL6vE3R1L /n4Q3FRBvKgmwaz+qwPoAzUk/oP1uW30QaRn5uHWBRXPRa1MPKqliW9KGWpXnhpYT6IY HBISi3hhMl05TtloeewAmBfP0oZjN2iuyapdJl3ZM+/6Jz0avWZQdrwtOpsEvu6VwXac hwxA== X-Gm-Message-State: AOAM530Vj7mMtkZZjSP5oRx8GeWeFQoYrgiQb1mEju9SHIkja57qC9Sh QLBAC5NPbnYuQk4Z00rKkKPzgAdoq5U= X-Google-Smtp-Source: ABdhPJyhIEf0GTHss77cGnhq4UIPnI7nX1fu8GYJP+BY66rosfT6fysHT/C1Az0gUczeZV3WSlerFg== X-Received: by 2002:aca:b2c4:: with SMTP id b187mr1829292oif.90.1631226323548; Thu, 09 Sep 2021 15:25:23 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:23 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 01/15] docs: Add block device (blkdev) LED trigger documentation Date: Thu, 9 Sep 2021 17:24:59 -0500 Message-Id: <20210909222513.2184795-2-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add Documentation/ABI/testing/sysfs-class-led-trigger-blkdev to document: * /sys/class/leds//blink_time * /sys/class/leds//interval * /sys/class/leds//mode * /sys/class/leds//link_device * /sys/class/leds//unlink_device * /sys/class/leds//linked_devices Add /sys/block//linked_leds to Documentation/ABI/testing/sysfs-block Add overview in Documentation/leds/ledtrig-blkdev.rst Signed-off-by: Ian Pilcher --- Documentation/ABI/testing/sysfs-block | 9 ++ .../testing/sysfs-class-led-trigger-blkdev | 46 ++++++ Documentation/leds/index.rst | 1 + Documentation/leds/ledtrig-blkdev.rst | 138 ++++++++++++++++++ 4 files changed, 194 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-blkdev create mode 100644 Documentation/leds/ledtrig-blkdev.rst diff --git a/Documentation/ABI/testing/sysfs-block b/Documentation/ABI/testing/sysfs-block index a0ed87386639..80d4becc4e6d 100644 --- a/Documentation/ABI/testing/sysfs-block +++ b/Documentation/ABI/testing/sysfs-block @@ -328,3 +328,12 @@ Description: does not complete in this time then the block driver timeout handler is invoked. That timeout handler can decide to retry the request, to fail it or to start a device recovery strategy. + +What: /sys/block//linked_leds +Date: September 2021 +Contact: Ian Pilcher +Description: + Directory containing links to all LEDs that are associated + with this block device through the blkdev LED trigger. Only + present when at least one LED is associated. (See + Documentation/leds/ledtrig-blkdev.rst.) diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-blkdev b/Documentation/ABI/testing/sysfs-class-led-trigger-blkdev new file mode 100644 index 000000000000..9f75d0bccceb --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-led-trigger-blkdev @@ -0,0 +1,46 @@ +What: /sys/class/leds//blink_time +Date: September 2021 +Contact: Ian Pilcher +Description: + Time (in milliseconds) that the LED will be on during a single + "blink". + +What: /sys/class/leds//interval +Date: September 2021 +Contact: Ian Pilcher +Description: + Frequency (in milliseconds) with which block devices associated + with the blkdev LED trigger will be checked for activity. + + NOTE that this attribute is a global setting. All changes + apply to all LEDs associated with the blkdev LED trigger. + +What: /sys/class/leds//mode +Date: September 2021 +Contact: Ian Pilcher +Description: + Type of events for which LED will blink - read, write, + or rw (both). Note that any activity that changes the state of + the device's non-volatile storage (including discards and cache + flushes) is considered to be a write. + +What: /sys/class/leds//link_device +Date: September 2021 +Contact: Ian Pilcher +Description: + Associate a block device with this LED by writing its kernel + name (as shown in /sys/block) to this attribute. + +What: /sys/class/leds//unlink_device +Date: September 2021 +Contact: Ian Pilcher +Description: + Remove the association between this LED and a block device by + writing the device's kernel name to this attribute. + +What: /sys/class/leds//linked_devices +Date: September 2021 +Contact: Ian Pilcher +Description: + Directory containing links to all block devices that are + associated with this LED. diff --git a/Documentation/leds/index.rst b/Documentation/leds/index.rst index e5d63b940045..e3c24e468cbc 100644 --- a/Documentation/leds/index.rst +++ b/Documentation/leds/index.rst @@ -10,6 +10,7 @@ LEDs leds-class leds-class-flash leds-class-multicolor + ledtrig-blkdev ledtrig-oneshot ledtrig-transient ledtrig-usbport diff --git a/Documentation/leds/ledtrig-blkdev.rst b/Documentation/leds/ledtrig-blkdev.rst new file mode 100644 index 000000000000..a4acc532f31b --- /dev/null +++ b/Documentation/leds/ledtrig-blkdev.rst @@ -0,0 +1,138 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================= +Block Device (blkdev) LED Trigger +================================= + +Available when ``CONFIG_LEDS_TRIGGER_BLKDEV=y`` or +``CONFIG_LEDS_TRIGGER_BLKDEV=m``. + +See also: + +* ``Documentation/ABI/testing/sysfs-class-led-trigger-blkdev`` +* ``Documentation/ABI/testing/sysfs-block`` (``/sys/block//linked_leds``) + +Overview +======== + +.. note:: + The examples below use ```` to refer to the name of a + system-specific LED. If no suitable LED is available on a test + system (in a virtual machine, for example), it is possible to + use a userspace LED. (See ``Documentation/leds/uleds.rst``.) + +Verify that the ``blkdev`` LED trigger is available:: + + # grep blkdev /sys/class/leds//trigger + ... rfkill-none blkdev + +(If the previous command produces no output, you may need to load the trigger +module - ``modprobe ledtrig_blkdev``. If the module is not available, check +the value of ``CONFIG_LEDS_TRIGGER_BLKDEV`` in your kernel configuration.) + +Associate the LED with the ``blkdev`` LED trigger:: + + # echo blkdev > /sys/class/leds//trigger + + # cat /sys/class/leds//trigger + ... rfkill-none [blkdev] + +Note that several new device attributes are available in the +``/sys/class/leds/`` directory. + +* ``link_device`` and ``unlink_device`` are used to manage the set of block + devices associated with this LED. The LED will blink in response to read or + write activity on its linked devices. + +* ``mode`` is used to control the type of device activity that will cause this + LED to blink - read activity, write activity, or both. (Note that any + activity that changes the state of a device's non-volatile storage is + considered to be a write. This includes discard and cache flush requests.) + +* ``blink_time`` is the duration (in milliseconds) of each blink of this LED. + +* ``interval`` is the frequency (in milliseconds) with which devices are checked + for activity. (Note that this is a global setting. Any change affects + **all** LEDs associated with the ``blkdev`` trigger.) + +* The ``linked_devices`` directory will contain a symbolic link to every device + that is associated with this LED. + +Link a block device to the LED:: + + # echo sda > /sys/class/leds//link_device + + # ls /sys/class/leds//linked_devices + sda + +Read and write activity on the device should cause the LED to blink. The +duration of each blink (in milliseconds) can be adjusted by setting +``/sys/class/leds//blink_time``. (But see **interval and blink_time** +below.) + +Associate a second device with the LED:: + + # echo sdb > /sys/class/leds//link_device + + # ls /sys/class/leds//linked_devices + sda sdb + +When a block device is linked to one or more LEDs, the LEDs are linked from +the device's ``linked_leds`` directory:: + + # ls /sys/block/sd{a,b}/linked_leds + /sys/block/sda/linked_leds: + + + /sys/block/sdb/linked_leds: + + +(The ``linked_leds`` directory only exists when the block device is linked to +at least one LED.) + +``interval`` and ``blink_time`` +=============================== + +* The ``interval`` attribute is a global setting. Changing the value via + ``/sys/class/leds//interval`` will change it for all LEDs associated with + the ``blkdev`` trigger. + +* All associated devices are checked for activity every ``interval`` + milliseconds, and a blink is triggered on appropriate LEDs. The duration + of an LED's blink is determined by its ``blink_time`` attribute (also in + milliseconds). Thus (assuming that activity of the relevant type has occurred + on one of an LED's linked devices), the LED will be on for ``blink_time`` + milliseconds and off for ``interval - blink_time`` milliseconds. + +* The LED subsystem ignores new blink requests for an LED that is already in + in the process of blinking, so setting a ``blink_time`` greater than or equal + to ``interval`` will cause some blinks to be dropped. + +* Because of processing times, scheduling latencies, etc., avoiding missed + blinks actually requires a difference of at least a few milliseconds between + the ``blink_time`` and ``interval``. The required difference is likely to + vary from system to system. As a reference, a Thecus N5550 NAS requires a + difference of 7 milliseconds (``interval == 100``, ``blink_time == 93``). + +* The default values (``interval == 100``, ``blink_time == 75``) cause the LED + associated with a continuously active device to blink rapidly. For a more + "constantly on" effect, increase the ``blink_time`` (but not too much; see + the previous bullet). + +Other Notes +=========== + +* Many (possibly all) types of block devices work with this trigger, including: + + * SCSI (including SATA and USB) hard disk drives and SSDs + * SCSI (including SATA and USB) optical drives + * NVMe SSDs + * SD cards + * loopback block devices (``/dev/loop*``) + * device mapper devices, such as LVM logical volumes + * MD RAID devices + * zRAM compressed RAM-disks + +* The ``blkdev`` LED trigger supports many-to-many device/LED associations. + A device can be associated with multiple LEDs, and an LED can be associated + with multiple devices. From patchwork Thu Sep 9 22:25:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508933 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.7 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 16DADC433EF for ; Thu, 9 Sep 2021 22:25:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE592611C4 for ; Thu, 9 Sep 2021 22:25:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344624AbhIIW0f (ORCPT ); Thu, 9 Sep 2021 18:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236975AbhIIW0e (ORCPT ); Thu, 9 Sep 2021 18:26:34 -0400 Received: from mail-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9504AC061574; Thu, 9 Sep 2021 15:25:24 -0700 (PDT) Received: by mail-oi1-x235.google.com with SMTP id r26so105399oij.2; Thu, 09 Sep 2021 15:25:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oE2dmDo4LT1pVf6VTHd6IbjQP+KgGw77nfi53BDXduM=; b=S16JJiZrgD3R6keXvN/r8v3uH+XTwhEjNThmCeNDgkocLm93wivja+wmCtrhzAhP5Z EmLLw6gYvZydbppgp3jWN+zbAiYO9kcapSIXFrcmq0bZB1NBL9JhpKDzMq0QYCiroHCX gN0eVMeLwbBHhBlla84IMtWV4z1fg/e8rGDrdQRr24qxc6yjo6typaIWwbvdc8XJUeHc prOIeWvli8r15sv/pdGIxP656QD97rHU93pl7uy0leKtRakC6QWcOU0+5lrzYmDsGNLW stkdKBJALNe6vry/lw1Y+g03T0kfEGPvfYZZQzoktt0M+iTYOQaEMi3+OyCQ9cXAo0Mh pctw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oE2dmDo4LT1pVf6VTHd6IbjQP+KgGw77nfi53BDXduM=; b=RifOCGNzUSvKGmiRwI2QTxF1YuwWnfRDhp3paN3xjHiAZ+tH8AKV+ZcQac/mZ02fr6 oOCUDTMo6qZF8wNcyBm1nYMXn9L+YYu2Lm67fFAAucSx333tIF0jrMP0ep5qM4DK0YzX cMn7p1vOM31iRkx60Q1sIqfA0CiddRnqz9bD/2yWeLwnXUITvptNdW9H4PCVENYuQl9u lGlo/upnrItE7mf+YqgS5La4c/bNFG+yGB7S61x3cXuCVg12hxTSdsZBg5PimWjEHNSg B4aQfKua2tguGLeg/3TwNiG4Yz+mjjDTA+zLUsL/wUokPzyIXWrrM6RAyMuThIKYQ043 VjQA== X-Gm-Message-State: AOAM531EOPytYw/jmCRLwiJkU/+MmvutcqLldjGcn0kdsyJkSHKQcX5G XCSl65YI6Jy5IqnwEleURI0= X-Google-Smtp-Source: ABdhPJx81UtcafQ/b9mUND8pAEly10N1ZOs6UvDF/ZPCkhNEveY1Ev60KsbUP5LjL6RcP5qsWwyagw== X-Received: by 2002:aca:4344:: with SMTP id q65mr1757970oia.70.1631226323966; Thu, 09 Sep 2021 15:25:23 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:23 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 02/15] leds: trigger: blkdev: Add build infrastructure Date: Thu, 9 Sep 2021 17:25:00 -0500 Message-Id: <20210909222513.2184795-3-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add files: * ledtrig-blkdev-core.c - trigger components that are always built-in * ledtrig-blkdev.c - trigger components that can be built as a module * ledtrig-blkdev.h - common declarations Add Kconfig options - CONFIG_LEDS_TRIGGER_BLKDEV (visible, tristate) and CONFIG_LEDS_TRIGGER_BLKDEV_CORE (hidden, boolean) Make CONFIG_LEDS_TRIGGER_BLKDEV select CONFIG_LEDS_TRIGGER_BLKDEV_CORE, so built-in portion of the trigger is enabled when trigger is either built-in or modular Signed-off-by: Ian Pilcher --- drivers/leds/trigger/Kconfig | 18 ++++++++++++++++++ drivers/leds/trigger/Makefile | 2 ++ drivers/leds/trigger/ledtrig-blkdev-core.c | 9 +++++++++ drivers/leds/trigger/ledtrig-blkdev.c | 16 ++++++++++++++++ drivers/leds/trigger/ledtrig-blkdev.h | 12 ++++++++++++ 5 files changed, 57 insertions(+) create mode 100644 drivers/leds/trigger/ledtrig-blkdev-core.c create mode 100644 drivers/leds/trigger/ledtrig-blkdev.c create mode 100644 drivers/leds/trigger/ledtrig-blkdev.h diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig index 1f1d57288085..ad49d92713fb 100644 --- a/drivers/leds/trigger/Kconfig +++ b/drivers/leds/trigger/Kconfig @@ -153,4 +153,22 @@ config LEDS_TRIGGER_TTY When build as a module this driver will be called ledtrig-tty. +config LEDS_TRIGGER_BLKDEV + tristate "LED Trigger for block devices" + depends on BLOCK + select LEDS_TRIGGER_BLKDEV_CORE + help + The blkdev LED trigger allows LEDs to be controlled by block device + activity (reads and writes). + + See Documentation/leds/ledtrig-blkdev.rst. + +config LEDS_TRIGGER_BLKDEV_CORE + bool + depends on LEDS_TRIGGER_BLKDEV + help + This enables the portion of the block device LED trigger that must + be built-in to the kernel, even when the trigger is built as a + module. + endif # LEDS_TRIGGERS diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile index 25c4db97cdd4..3732eeb86775 100644 --- a/drivers/leds/trigger/Makefile +++ b/drivers/leds/trigger/Makefile @@ -16,3 +16,5 @@ obj-$(CONFIG_LEDS_TRIGGER_NETDEV) += ledtrig-netdev.o obj-$(CONFIG_LEDS_TRIGGER_PATTERN) += ledtrig-pattern.o obj-$(CONFIG_LEDS_TRIGGER_AUDIO) += ledtrig-audio.o obj-$(CONFIG_LEDS_TRIGGER_TTY) += ledtrig-tty.o +obj-$(CONFIG_LEDS_TRIGGER_BLKDEV) += ledtrig-blkdev.o +obj-$(CONFIG_LEDS_TRIGGER_BLKDEV_CORE) += ledtrig-blkdev-core.o diff --git a/drivers/leds/trigger/ledtrig-blkdev-core.c b/drivers/leds/trigger/ledtrig-blkdev-core.c new file mode 100644 index 000000000000..bd9e5f09b7e3 --- /dev/null +++ b/drivers/leds/trigger/ledtrig-blkdev-core.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Block device LED trigger - built-in components + * + * Copyright 2021 Ian Pilcher + */ + +#include "ledtrig-blkdev.h" diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c new file mode 100644 index 000000000000..b615a8bf38e2 --- /dev/null +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Block device LED trigger - modular components + * + * Copyright 2021 Ian Pilcher + */ + +#include + +#include "ledtrig-blkdev.h" + +MODULE_DESCRIPTION("Block device LED trigger"); +MODULE_AUTHOR("Ian Pilcher "); +MODULE_LICENSE("GPL v2"); +MODULE_IMPORT_NS(LEDTRIG_BLKDEV); diff --git a/drivers/leds/trigger/ledtrig-blkdev.h b/drivers/leds/trigger/ledtrig-blkdev.h new file mode 100644 index 000000000000..6264d8a9201b --- /dev/null +++ b/drivers/leds/trigger/ledtrig-blkdev.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* + * Block device LED trigger + * + * Copyright 2021 Ian Pilcher + */ + +#ifndef __LEDTRIG_BLKDEV_H +#define __LEDTRIG_BLKDEV_H + +#endif /* __LEDTRIG_BLKDEV_H */ From patchwork Thu Sep 9 22:25:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508932 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=-12.9 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,UNWANTED_LANGUAGE_BODY, 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 BFD23C433FE for ; Thu, 9 Sep 2021 22:25:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A7339611C7 for ; Thu, 9 Sep 2021 22:25:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345526AbhIIW0i (ORCPT ); Thu, 9 Sep 2021 18:26:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344616AbhIIW0f (ORCPT ); Thu, 9 Sep 2021 18:26:35 -0400 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 127B1C061574; Thu, 9 Sep 2021 15:25:25 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id q11-20020a9d4b0b000000b0051acbdb2869so4591493otf.2; Thu, 09 Sep 2021 15:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=L4BSq92N5y+/fvChpos2+SAQ+rQstA94HqdG0a5jEzo=; b=Rk7b1HTG+dEF5nNseowxsTHvQqYhsIv9a7AarkSJMF1SCjTHZOF3C1Rzaa4g2Vj8Lr ahswkxsdBtjMhQDnNOGZuQCNDn3Bm2NNcNBSe96iC5Ro49kVRLRyBnea4foj6thCPxFS HfDK7E2BnEnylmUncFF4mC0kleyrtqdj/b9Zusv39OV2co/IPVg7UDWU5BQwS7OEds5x QmYPTv1QhcImXwNIFa/1qocERXzpGBkbaJM39HNBt0zL4kc7ZEeVp7N4614yMtrLNfXs PeyxBbUT+DF0agWkPYDAvClzheXvNcMHZ5YEL0D7t72XrugyZVWs3hf9c9Bjv+mGu0O0 GprQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=L4BSq92N5y+/fvChpos2+SAQ+rQstA94HqdG0a5jEzo=; b=FzogFgkf4IVwJLbqiHoqlNQixGqBCt5zMnQSOyAxRdhDLTLQNJy4IVDAmbq6P6KOd4 Udql8JW66u0WOmUv6U2Ln4mH9gtiB9DjTYCy2tXOr1QJUjTXJIkzE6vtTXg05VB6LhkP 2hx++5tYdZH/1HbSKKDb7lsfjEmMCg/YI4jTIT0uVaZHnEgVxJNZehZCZRV3omgx61e0 EhZq7qVLjb1iiCkBwpXO6qIOHDicY0+eJkQ44BHy6FkETcsnL8wPh8BQpajpk64uEVBY voTkHwW061Jzo4926LhIPDgNbRha2ljyRScoxnXiGXphQCLsHl0NdMaSu4NFA53aucq/ erlg== X-Gm-Message-State: AOAM531DurgsMMVKTW+GH4xLQkLgd3lRdebGdik0iQ9GzzTfXNUAwB8C x01HSnJzz8t/t9Jg6S3wQiY/nXGwdKg= X-Google-Smtp-Source: ABdhPJxvwnQrmgnDleol7tW5LVcQZ1GSLYMaxBeU/NiJJqjEYt6JJDa2tfsYa7V6C5bjnU8WlZhwbA== X-Received: by 2002:a9d:72c5:: with SMTP id d5mr2004885otk.212.1631226324422; Thu, 09 Sep 2021 15:25:24 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:24 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 03/15] leds: trigger: blkdev: Add functions needed by block changes Date: Thu, 9 Sep 2021 17:25:01 -0500 Message-Id: <20210909222513.2184795-4-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add ledtrig_blkdev_disk_init() and ledtrig_blkdev_disk_cleanup() placeholders. (Function bodies depend on block subsystem changes in next commit.) Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev-core.c | 11 +++++++++++ include/linux/leds.h | 19 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev-core.c b/drivers/leds/trigger/ledtrig-blkdev-core.c index bd9e5f09b7e3..b0a455180b05 100644 --- a/drivers/leds/trigger/ledtrig-blkdev-core.c +++ b/drivers/leds/trigger/ledtrig-blkdev-core.c @@ -6,4 +6,15 @@ * Copyright 2021 Ian Pilcher */ +#include + #include "ledtrig-blkdev.h" + +/** + * ledtrig_blkdev_disk_cleanup - remove a block device from the blkdev LED + * trigger + * @gd: the disk to be removed + */ +void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd) +{ +} diff --git a/include/linux/leds.h b/include/linux/leds.h index a0b730be40ad..38fb8b6e68fe 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -605,4 +606,22 @@ static inline void ledtrig_audio_set(enum led_audio type, } #endif +#if IS_ENABLED(CONFIG_LEDS_TRIGGER_BLKDEV) +/** + * ledtrig_blkdev_disk_init - initialize the ledtrig field of a new gendisk + * @gd: the gendisk to be initialized + */ +static inline void ledtrig_blkdev_disk_init(struct gendisk *const gd) +{ +} +void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd); +#else /* IS_ENABLED(CONFIG_LEDS_TRIGGER_BLKDEV) */ +static inline void ledtrig_blkdev_disk_init(const struct gendisk *gd) +{ +} +static inline void ledtrig_blkdev_disk_cleanup(const struct gendisk *gd) +{ +} +#endif /* IS_ENABLED(CONFIG_LEDS_TRIGGER_BLKDEV) */ + #endif /* __LINUX_LEDS_H_INCLUDED */ From patchwork Thu Sep 9 22:25:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508551 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.7 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=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 54983C433EF for ; Thu, 9 Sep 2021 22:25:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3F8CF61186 for ; Thu, 9 Sep 2021 22:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346098AbhIIW0l (ORCPT ); Thu, 9 Sep 2021 18:26:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345073AbhIIW0f (ORCPT ); Thu, 9 Sep 2021 18:26:35 -0400 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EB8CC061756; Thu, 9 Sep 2021 15:25:25 -0700 (PDT) Received: by mail-oo1-xc35.google.com with SMTP id y3-20020a4ab403000000b00290e2a52c71so1071222oon.2; Thu, 09 Sep 2021 15:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5IvB2ie/eR/p0ZXjKpNOoLs51YY8X2DxXyaLyjEGU5s=; b=O7Lrxvdjp9rmXnWXN6cN3wCovZwHVrpRw+J8dHaOE1IHnLxOyOprFhm6t6nkjJ0XLn c3PxliT2pHGWQqNcuht6a3BVZKYFVd3FkYRTXpa4k4UqCCG+ZkPyyTHdbmMsQSc+1Oyl 3vRABWfn2lUyrAfshml7FY0iuvmcgzlZ2NJNZqPVnUNwhU8kqPxIatF9AJOGIkt7vP// S08grsbyjPbrBTkcv37taFMoV53FpoinEskk3u7DjiHeKbQZ3KIPzANwudBLwyua7cIe 2iKFiSAacrC1RSJ7lujclmKJvzKylL7lRvs7XJdBClyMCYmLIo28iNYEXS9C5QxXxOBN FcBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5IvB2ie/eR/p0ZXjKpNOoLs51YY8X2DxXyaLyjEGU5s=; b=aL0eRcdY2n8/bySCvhJdp8ldr621fSmX+gwMJR4O/npa4PkSoQxx1UDswaIhZlWXuj J2aTbU0+Nl/W7628cnn36qD4702cMm8+IiNiV5IpgttgkCcgJlkReJsFtvdjmIn6ynYb 4Mza/Ra8Bms6PtutChzFr/X77hiaP0RMZU5k9W2MYu7FO09IEOcyxt6rOmHysu5zCRsZ hmSemHH5ycMX6qLTcAha5Xa5VlrM5WZq81x1ISG+uwOg8Ba7alogg0/FHnG6kBdQtYZO WA/zrslq7MF28X60SkgUJATXZdTJ92HtPHFCHlrX0NkC2YKt9vt4vmnqdTEifPgCQmgr 0iow== X-Gm-Message-State: AOAM530AduKtcgUWKuLRgF1x2btp8VKEP66x4vojI9iQwHNphwAf1uJq lzSzBL8J3t/K06qiGrFaO70= X-Google-Smtp-Source: ABdhPJz1DcaFu/ilKPUNbaGKdUBmyHS98IMiktlfW3megURnCIqFZQwdWUaccOOWGIvFcF2QYa5ZSg== X-Received: by 2002:a4a:e942:: with SMTP id v2mr1798582ood.96.1631226324934; Thu, 09 Sep 2021 15:25:24 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:24 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 04/15] block: Add block device LED trigger integrations Date: Thu, 9 Sep 2021 17:25:02 -0500 Message-Id: <20210909222513.2184795-5-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add LED trigger disk info pointer to gendisk structure Call ledtrig_blkdev_disk_init() from device_add_disk() to ensure that ledtrig is initialized to NULL, in case a driver allocates the structure itself and doesn't use kzalloc() Call ledtrig_blkdev_disk_cleanup() from del_gendisk() to ensure that the LED trigger stops trying to check the disk for activity Signed-off-by: Ian Pilcher --- block/genhd.c | 4 ++++ include/linux/genhd.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 567549a011d1..6f340a717099 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "blk.h" @@ -390,6 +391,8 @@ int device_add_disk(struct device *parent, struct gendisk *disk, struct device *ddev = disk_to_dev(disk); int ret; + ledtrig_blkdev_disk_init(disk); + /* * The disk queue should now be all set with enough information about * the device for the elevator code to pick an adequate default @@ -559,6 +562,7 @@ void del_gendisk(struct gendisk *disk) if (WARN_ON_ONCE(!disk_live(disk) && !(disk->flags & GENHD_FL_HIDDEN))) return; + ledtrig_blkdev_disk_cleanup(disk); blk_integrity_del(disk); disk_del_events(disk); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index c68d83c87f83..29039367ccad 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -166,6 +166,9 @@ struct gendisk { #endif /* CONFIG_BLK_DEV_INTEGRITY */ #if IS_ENABLED(CONFIG_CDROM) struct cdrom_device_info *cdi; +#endif +#if IS_ENABLED(CONFIG_LEDS_TRIGGER_BLKDEV) + struct ledtrig_blkdev_disk *ledtrig; #endif int node_id; struct badblocks *bb; From patchwork Thu Sep 9 22:25:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508930 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.7 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=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 99D6BC43219 for ; Thu, 9 Sep 2021 22:25:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 846216103D for ; Thu, 9 Sep 2021 22:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346078AbhIIW0k (ORCPT ); Thu, 9 Sep 2021 18:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345132AbhIIW0f (ORCPT ); Thu, 9 Sep 2021 18:26:35 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3850C061757; Thu, 9 Sep 2021 15:25:25 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id p2so110469oif.1; Thu, 09 Sep 2021 15:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B9eeaudGo2vbFyWuC9u2+X8O9/8e4JqvbQd9kXidz48=; b=VJiBClSMfBlHzr8KKo1MdKbKQu8spCbPJM20BXrrcl2TsNjuyAa5R6kgVNwImtYJKz kDpDTgvQUfpaeV5CyeYTFUCa2ij43x0y8kwMMw/8DHCLG/dFnk9n1P7aUFmZWV4S3kiz NJBkObuvo3r02k822cu0tLcNMAuInst03Kgt3ieQw91SbeSNHJVGxXOxy2U7ynPcnmbq clJ3PrUKVHk6/Qt/b7aKs0A+37XYh3eacH/fMRaHsROl7pMpD5lmwc9vKsqrBQlLDriZ 2mZmuN2JuuQ6JWIcRMgvmM8KxN8xZJoyRGE+TPQqYAv5tbbg+YDNpsD5sZRLFmcwAD/B URQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B9eeaudGo2vbFyWuC9u2+X8O9/8e4JqvbQd9kXidz48=; b=iJF6n+wBrV8oPuRU5Bx8nrUCILP2xisvtaF93AHFOICER8ZhWfSbVcBPMQKzYr8m7d MiDa6glXxpbJWo3MIwhOFl5ZVGNGkfOq///SaV1/a2KeITb5k4Uu76HNPSuI1+8BTGbp ReoTZDn+3KFFhG64NXqRu/d+dsf7r+r/3ghMFcRzmt5aDxWqJUM7kom92ZPzsdkW/PrM WfebToxllCMH8XP7Pqg74pEZOVS4BIIaAw5Bo2QdWdAnHW1FI83ArK40Ux65xTEfp74L JRxfCJ7066kYFNGcCuY+XZxGv+0TUq/RY+R3SPggqQpLsnDIqM6bX37NleaFUXsD06Tw kj7w== X-Gm-Message-State: AOAM531LL51b6yPqRqc59cOo1KIV7TZjVuVxv9jsubVg8RC3d0eCyPSB ccBw1ULCzFhWbsi6laSaz+A= X-Google-Smtp-Source: ABdhPJzEf7GjMQ0hi0um2SRAf+sNVmkJPJL1ZvuVeDvcDUr5bf3pTq20DcH9zTd0/ZShLPpxyctwAw== X-Received: by 2002:a05:6808:483:: with SMTP id z3mr1750372oid.5.1631226325435; Thu, 09 Sep 2021 15:25:25 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:25 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 05/15] leds: trigger: blkdev: Complete functions called by block subsys Date: Thu, 9 Sep 2021 17:25:03 -0500 Message-Id: <20210909222513.2184795-6-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Now that the ledtrig member has been added to struct gendisk, add the function bodies to ledtrig_blkdev_disk_init() and ledtrig_blkdev_disk_cleanup() Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev-core.c | 15 +++++++++++++++ drivers/leds/trigger/ledtrig-blkdev.c | 1 + drivers/leds/trigger/ledtrig-blkdev.h | 3 +++ include/linux/leds.h | 1 + 4 files changed, 20 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev-core.c b/drivers/leds/trigger/ledtrig-blkdev-core.c index b0a455180b05..d7b02e760b06 100644 --- a/drivers/leds/trigger/ledtrig-blkdev-core.c +++ b/drivers/leds/trigger/ledtrig-blkdev-core.c @@ -10,6 +10,13 @@ #include "ledtrig-blkdev.h" +DEFINE_MUTEX(ledtrig_blkdev_mutex); +EXPORT_SYMBOL_NS_GPL(ledtrig_blkdev_mutex, LEDTRIG_BLKDEV); + +/* Set when module is loaded (or trigger is initialized) */ +void (*__ledtrig_blkdev_disk_cleanup)(struct gendisk *gd) = NULL; +EXPORT_SYMBOL_NS_GPL(__ledtrig_blkdev_disk_cleanup, LEDTRIG_BLKDEV); + /** * ledtrig_blkdev_disk_cleanup - remove a block device from the blkdev LED * trigger @@ -17,4 +24,12 @@ */ void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd) { + mutex_lock(&ledtrig_blkdev_mutex); + + if (gd->ledtrig != NULL) { + if (!WARN_ON(__ledtrig_blkdev_disk_cleanup == NULL)) + __ledtrig_blkdev_disk_cleanup(gd); + } + + mutex_unlock(&ledtrig_blkdev_mutex); } diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index b615a8bf38e2..7f85e6080ea1 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -6,6 +6,7 @@ * Copyright 2021 Ian Pilcher */ +#include #include #include "ledtrig-blkdev.h" diff --git a/drivers/leds/trigger/ledtrig-blkdev.h b/drivers/leds/trigger/ledtrig-blkdev.h index 6264d8a9201b..b1294da17ba3 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.h +++ b/drivers/leds/trigger/ledtrig-blkdev.h @@ -9,4 +9,7 @@ #ifndef __LEDTRIG_BLKDEV_H #define __LEDTRIG_BLKDEV_H +extern struct mutex ledtrig_blkdev_mutex; +extern void (*__ledtrig_blkdev_disk_cleanup)(struct gendisk *gd); + #endif /* __LEDTRIG_BLKDEV_H */ diff --git a/include/linux/leds.h b/include/linux/leds.h index 38fb8b6e68fe..3925499c0b3d 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -613,6 +613,7 @@ static inline void ledtrig_audio_set(enum led_audio type, */ static inline void ledtrig_blkdev_disk_init(struct gendisk *const gd) { + gd->ledtrig = NULL; } void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd); #else /* IS_ENABLED(CONFIG_LEDS_TRIGGER_BLKDEV) */ From patchwork Thu Sep 9 22:25:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508553 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.7 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 E2CC3C4332F for ; Thu, 9 Sep 2021 22:25:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0596611C7 for ; Thu, 9 Sep 2021 22:25:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345311AbhIIW0h (ORCPT ); Thu, 9 Sep 2021 18:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345235AbhIIW0g (ORCPT ); Thu, 9 Sep 2021 18:26:36 -0400 Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74F1FC06175F; Thu, 9 Sep 2021 15:25:26 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id l16-20020a9d6a90000000b0053b71f7dc83so4559121otq.7; Thu, 09 Sep 2021 15:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6ytqfu1+r4YEz0nqSMNay+oDma8axhIPc/igiM7FRwE=; b=XSmErYRWdzMOC+MCLstVHqd9cwXygzDnbVImyZGh5WrECSfUbKkIhY+Z9kjAAHYPfh pnxoo3h/x4D58u7mVL2KmcA6qlx1e8VFOFWkCwk2Xk1lL0lVXSoC0fzmAfhupd6cljjx sXZX3bs+326Qe+S5704phqCBt2QIEp0yY+kNLByZAiOoYZQ6oBHtTEFQwL/jdof0HgI4 slC8AZGH2q5+w0NZOWq3lR/DNlGllCIuPNrSeGOpkGEqFgNSfLJexam+UxhO2LqVMHRb E+ZGIdH2usWMZ/cxdHVGZ2V2faIPZz3WvXEJJx41BbQTK1vqeBdR7Gjjph3jULyg2xmR mu+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6ytqfu1+r4YEz0nqSMNay+oDma8axhIPc/igiM7FRwE=; b=T6mriN9TnJxkELtgoHrv24isR534qm9zN/DI8B+CJaM/5Ku0H+s6GmYevNEVHpZoaV obQNgaOXQGpYBx7zG238eMrJdeAEwRW6ckhTQCl/DEEb8V4TKiACqt+2iqT4N9LKGuuM ixOdZNAxEzBaHgCUbCtOsNifYCb6uuk2JMPf0mPp6HvVwUUjLitH5IQJBAzet6s/rbVT WVJGr/yJhlUj1g2++iu7kJ46AjVMUr4nlCfkiBPJzygjg5JPkLubGYiFsZRhyEH9HBMw +hoxVkWTAQREbzv6UEZwmNqbrORMOD0sXyF/grlob3ijePxQML2Fo1B1i+Bt6R5g1Uh/ 7lLw== X-Gm-Message-State: AOAM533ST2ymXcuRmmTbSBTTxjPWExcF3oYgpbJU8ZfOhJ6isM+gHmNW jFNFZhNuRNi33I1T486af5dwLwjjmJk= X-Google-Smtp-Source: ABdhPJwZSoxLn1QDZiP9fMUjHH/Q9JkWuwdkzt0CTHbRERk43Od+wJroZzPmarH5V1BYxiMtJEztxg== X-Received: by 2002:a9d:4914:: with SMTP id e20mr2012120otf.324.1631226325850; Thu, 09 Sep 2021 15:25:25 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:25 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 06/15] leds: trigger: blkdev: Add function to get gendisk by name Date: Thu, 9 Sep 2021 17:25:04 -0500 Message-Id: <20210909222513.2184795-7-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add ledtrig_blkdev_get_disk() to find block device by name and increment its reference count. (Caller must call put_disk().) Must be built-in to access block_class and disk_type symbols. Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev-core.c | 20 ++++++++++++++++++++ drivers/leds/trigger/ledtrig-blkdev.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev-core.c b/drivers/leds/trigger/ledtrig-blkdev-core.c index d7b02e760b06..5fd741aa14a6 100644 --- a/drivers/leds/trigger/ledtrig-blkdev-core.c +++ b/drivers/leds/trigger/ledtrig-blkdev-core.c @@ -33,3 +33,23 @@ void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd) mutex_unlock(&ledtrig_blkdev_mutex); } + +/* class_find_device() callback. Must be built-in to access disk_type. */ +static int blkdev_match_name(struct device *const dev, const void *const name) +{ + return dev->type == &disk_type + && sysfs_streq(dev_to_disk(dev)->disk_name, name); +} + +/* Must be built-in to access block_class */ +struct gendisk *ledtrig_blkdev_get_disk(const char *const name) +{ + struct device *dev; + + dev = class_find_device(&block_class, NULL, name, blkdev_match_name); + if (dev == NULL) + return NULL; + + return dev_to_disk(dev); +} +EXPORT_SYMBOL_NS_GPL(ledtrig_blkdev_get_disk, LEDTRIG_BLKDEV); diff --git a/drivers/leds/trigger/ledtrig-blkdev.h b/drivers/leds/trigger/ledtrig-blkdev.h index b1294da17ba3..a6ff24fad0c2 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.h +++ b/drivers/leds/trigger/ledtrig-blkdev.h @@ -12,4 +12,7 @@ extern struct mutex ledtrig_blkdev_mutex; extern void (*__ledtrig_blkdev_disk_cleanup)(struct gendisk *gd); +/* Caller must call put_disk() */ +struct gendisk *ledtrig_blkdev_get_disk(const char *const name); + #endif /* __LEDTRIG_BLKDEV_H */ From patchwork Thu Sep 9 22:25:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508550 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.7 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 B71EFC4321E for ; Thu, 9 Sep 2021 22:25:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A03216103D for ; Thu, 9 Sep 2021 22:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346669AbhIIW0n (ORCPT ); Thu, 9 Sep 2021 18:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345284AbhIIW0h (ORCPT ); Thu, 9 Sep 2021 18:26:37 -0400 Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC190C061760; Thu, 9 Sep 2021 15:25:26 -0700 (PDT) Received: by mail-oo1-xc2b.google.com with SMTP id m11-20020a056820034b00b0028bb60b551fso1070035ooe.5; Thu, 09 Sep 2021 15:25:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t5T+AFlgbNoGcPrVLT53gG0D4KLaxBBE1fEOtdfcLqE=; b=Cg1rpKDFgQ3EhEFN0AzLXlkGd/m9G1+XdFsD8fySprsOVbAmlByxUGxW0OTh7Xtjzl sSKwvR1QXvYlO00x7RouJ/jvIVkJgvxru8cfVd9DtXubdVr2xqTjcTjlMuIN6uQ1wKV7 I4Lu1HgWw4dqZ8QXXelY7ylGffElTqTX+zPPvzvljTT8hhZeQ1OXaQYLKwmpMs/BHM9+ VDJxHGXOlgKgbnHk5J7wzXSF8EJHfeZJMN3ISBPgnlSxXkjPJdMGEL6SXficb3k3DsyY RayuJUuqgzQpF7zhMaVbJ97IjsQjMH3H1c7fNKeJ+uXwlQcoWdI1vZ6BX+NDS17YcmpJ hCSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t5T+AFlgbNoGcPrVLT53gG0D4KLaxBBE1fEOtdfcLqE=; b=2zpccEbidYfrrdvOHawFbOkkO0E3MGjtk+RBl1sZ7KZ07Zi4HbJ9fEgfdKLvlwRNz3 bBx1A0E/EJ2QlsTqL8R6f9lxxb3d5HFqT2onuKfce8HSIT/P1Qpko0xikvun7usuGyx7 OHJ5+kd8PWS/mRnv8mD6t/Fjk006dcnixZA6X22S80NVVWGtYUEFMK10QnAayuOaFKJT yU16y1Vzlq8jOwQoIJFG7fkgeHrIaDrc8uBI9Qi4KLsklN0HdSoBpXlYwaghRd20GPPx 4UDtgf6A+caUAKN5tw3c+2be0xwKtTXbi7+kOQNhciYt2S+3pkyxh8Pjpsz6rUXqXZ9s DFww== X-Gm-Message-State: AOAM533xUlzxqNbg/jWEZUxbpOccnsOBGg/3MKvkA74GijoVeT1MTnQx 5jdMGIdOtg2ionYMdWA53Ww= X-Google-Smtp-Source: ABdhPJyYrYBPaw6ekxeII0CMS8TKIPFMx/YqnPYNX0Lp7CUmQiAxXUJnw79CVApfd8k5tzKMiqx7TA== X-Received: by 2002:a05:6820:613:: with SMTP id e19mr1798819oow.67.1631226326272; Thu, 09 Sep 2021 15:25:26 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:26 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 07/15] leds: trigger: blkdev: Add constants and types Date: Thu, 9 Sep 2021 17:25:05 -0500 Message-Id: <20210909222513.2184795-8-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Avoid bloating gendisk structure by storing per-device trigger data in ledtrig_blkdev_disk Support many-to-many device/LED associations with ledtrig_blkdev_link struct. Per-device (ledtrig_blkdev_disk) and per-LED (ledtrig_blkdev_led) structures both include a list of links, so a device can be linked to multiple LEDs, and an LED can be linked to multiple devices. Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 7f85e6080ea1..38a2cd2df85c 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -15,3 +15,47 @@ MODULE_DESCRIPTION("Block device LED trigger"); MODULE_AUTHOR("Ian Pilcher "); MODULE_LICENSE("GPL v2"); MODULE_IMPORT_NS(LEDTRIG_BLKDEV); + +/* Default blink time & check interval (milliseconds) */ +#define LEDTRIG_BLKDEV_BLINK_MSEC 75 +#define LEDTRIG_BLKDEV_INTERVAL 100 + +/* Minimum blink time & check interval (milliseconds) */ +#define LEDTRIG_BLKDEV_MIN_BLINK 10 +#define LEDTRIG_BLKDEV_MIN_INT 25 + +enum ledtrig_blkdev_mode { + LEDTRIG_BLKDEV_MODE_RO = 0, /* blink for reads */ + LEDTRIG_BLKDEV_MODE_WO = 1, /* blink for writes */ + LEDTRIG_BLKDEV_MODE_RW = 2 /* blink for reads and writes */ +}; + +/* Per-block device information */ +struct ledtrig_blkdev_disk { + struct gendisk *gd; + struct kobject *dir; /* linked_leds dir */ + struct hlist_head leds; + unsigned long read_ios; + unsigned long write_ios; + unsigned int generation; + bool read_act; + bool write_act; +}; + +/* For many-to-many relationships between "disks" (block devices) and LEDs */ +struct ledtrig_blkdev_link { + struct hlist_node disk_leds_node; + struct hlist_node led_disks_node; + struct ledtrig_blkdev_disk *disk; + struct ledtrig_blkdev_led *led; +}; + +/* Every LED associated with the blkdev trigger gets one of these */ +struct ledtrig_blkdev_led { + struct kobject *dir; /* linked_devices dir */ + struct led_classdev *led_dev; + unsigned int blink_msec; + struct hlist_head disks; /* linked block devs */ + struct hlist_node leds_node; + enum ledtrig_blkdev_mode mode; +}; From patchwork Thu Sep 9 22:25:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508931 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.7 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 91C5CC4332F for ; Thu, 9 Sep 2021 22:25:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D2F7611C2 for ; Thu, 9 Sep 2021 22:25:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346563AbhIIW0n (ORCPT ); Thu, 9 Sep 2021 18:26:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345294AbhIIW0h (ORCPT ); Thu, 9 Sep 2021 18:26:37 -0400 Received: from mail-oo1-xc2d.google.com (mail-oo1-xc2d.google.com [IPv6:2607:f8b0:4864:20::c2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 610D8C061574; Thu, 9 Sep 2021 15:25:27 -0700 (PDT) Received: by mail-oo1-xc2d.google.com with SMTP id m14-20020a4ad50e000000b002912a944a47so1058145oos.12; Thu, 09 Sep 2021 15:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GdOcaIt+lEs3P/5jE6RLnbfIIvqFBGA/JhoMskjrSdU=; b=hCMclT5Mqq4sU+Yr0lvxe+xbbwa0bmJ8/8QFGcmhfAsJs7mGj3WMBkP4REPpn1Y49Q XTS1RBL190LzsPM5VgmKOWOqoTyBGCNLHoCjkyiLQtM3Mlnw4yaR9oCBAenIDve9qm5B s9pS4SqZFXGhiaddxJ7f8TQ7quoPYDHtUnQwESp1ipRLCMRKeu+lTJWDtwPCFBM4vXjd YbL2ESZydO0TxFC6KpqkxBjgqg9hSgILIAIRGrv2WWlBpPAzUQ8dM/RQOZ3CF1GocIyP V3qtiRp7JCKzQrbu6kgjdswc1Aa6+zMZs8rgXgVJnsohNoUOp8hfeG61ixsmBMHhBhaf Vvmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GdOcaIt+lEs3P/5jE6RLnbfIIvqFBGA/JhoMskjrSdU=; b=nNqlwJKK7PGHdUIioZ3I/a+Fx4ON9GoJN9B/hwlBZfULeLR5mDB7OaUQmiUR3hPFrW Of9Z3jQGgOC485KnuI8SV2fzDSNgzYhOr8aSgP+KPP3oxlgPWtZzJN0LyKt4HSoAHCm6 +6nmGwnA0/8aEH60gUX5loPbUfu3WqhtITSkFUl5VIt98Pv/UIldo/oG/2wASn7h+Twj eEw6/3ho9W6qL1K6df2NA9+Vx43tC68+O25duMzOq7m7SOCo/e8uHalsyLQbw7xMblIa 2jUqnwP7LD4yuR9ue2t258G78WaLKU2I0KLlGGIYXLb9s9gJCJjT3Ob/RLeWErbNIt9T THNw== X-Gm-Message-State: AOAM533IY7b8WozlQE4fYdB2O+JNQI0XBPvO4KTjEAu/rCYS2ztwZDJJ zc7tAiygbL140DI0c83bG8Y= X-Google-Smtp-Source: ABdhPJwkjpFiiNvLdHXbnfuH2r8Lk2hJNSCAkfhUOmt3idGydzd3vpNQEFdl+gjVbpxhFOXiMjH3OQ== X-Received: by 2002:a4a:a78a:: with SMTP id l10mr1809670oom.30.1631226326744; Thu, 09 Sep 2021 15:25:26 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:26 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 08/15] leds: trigger: blkdev: Add stub LED trigger structure Date: Thu, 9 Sep 2021 17:25:06 -0500 Message-Id: <20210909222513.2184795-9-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Needed to avoid unused function warnings/errors from subsequent patches Make ledtrig_blkdev_trigger non-static for now to avoid unused variable warning/error Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 38a2cd2df85c..53b62e320491 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -59,3 +59,28 @@ struct ledtrig_blkdev_led { struct hlist_node leds_node; enum ledtrig_blkdev_mode mode; }; + + +/* + * + * Initialization - register the trigger + * + */ + +static struct attribute *ledtrig_blkdev_attrs[] = { + NULL +}; + +static const struct attribute_group ledtrig_blkdev_attr_group = { + .attrs = ledtrig_blkdev_attrs, +}; + +static const struct attribute_group *ledtrig_blkdev_attr_groups[] = { + &ledtrig_blkdev_attr_group, + NULL +}; + +struct led_trigger ledtrig_blkdev_trigger = { + .name = "blkdev", + .groups = ledtrig_blkdev_attr_groups, +}; From patchwork Thu Sep 9 22:25:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508929 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.7 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 8BFFCC433F5 for ; Thu, 9 Sep 2021 22:25:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 76068611AF for ; Thu, 9 Sep 2021 22:25:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346831AbhIIW0p (ORCPT ); Thu, 9 Sep 2021 18:26:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345349AbhIIW0h (ORCPT ); Thu, 9 Sep 2021 18:26:37 -0400 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D69AFC061575; Thu, 9 Sep 2021 15:25:27 -0700 (PDT) Received: by mail-ot1-x333.google.com with SMTP id m7-20020a9d4c87000000b0051875f56b95so4565999otf.6; Thu, 09 Sep 2021 15:25:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZLOPme3bTnjA2h6AchbcXlnzuUCG5BQ91CmIdjqTch4=; b=LtponteebQeI+Jw8nG5IkAAZtIy0uuRsADT1LEelc7mhkRfU6dT4xN/bTUpevL3O3R BUQHn2ij7mY2Y/IWgVEwZVuWG4NKHF75At+3ly4UbWR74ZfI4BpVcSUWYxL+zJiZq+f0 uWBRlSLoTsMHO9eRvv398Qpzh285jIA2kmc0isMnuMyjeyAZJWbdQuRwPRLgSy35RRYA HK3aa/7rXYBAHod21AFUAWMfqgEQvCC4eGCLsWN4upLOWVKlubmOWDtgvDvYTvJJepQm CvuWltVSJczZMdzd4dU6Rrmh3FdKHUpkn3zBN4OL3nxLZyx2pzIYPO17XGDkf+kGTXDE HWSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZLOPme3bTnjA2h6AchbcXlnzuUCG5BQ91CmIdjqTch4=; b=AvP6w2UVwCUG1YTnxF/WJQYHNComzhgkUbzbvGPKBBUTil2sa8AvPDcD2Em532JNvM qRsM7HBolhR9TnuQtKiXZgUL+jJjTqhADx1ieUy9kEiFUVmixjKZvebZxJmxIINSjZht wJOamRWsLc6FW0N23VKEHTNkQVUq9Tb0ul6q5r139gpGtclpq5t25dn/CZVLDHZMfyA1 YGwUqUF/b2VHVDWNaL+UqyMiLROHOznEqP5xcnhEc8mWdIPtQ1QnX88P+PmXUCD26/X5 kBxfZRQKlF6VbzQOc6WUEGqIM4TAlb6dldY0i1px7nIrxwGh4RJyNe5AkGn4w4D9HKLv 7yow== X-Gm-Message-State: AOAM531ZB5Z3YNBdDiivdb+rPf2xf92iH44AJDSytlz1Hrz8pqlDQ1AQ hg0506cwqSjZQTi5JBUEg1Y= X-Google-Smtp-Source: ABdhPJymhcAar4MC37SQkwoGEHEL+ZOu0WpDW4mlRmyEcb8UmY18fPxgWhceTeD9mVthrLwBuYE/4Q== X-Received: by 2002:a9d:4910:: with SMTP id e16mr1893390otf.170.1631226327264; Thu, 09 Sep 2021 15:25:27 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:26 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 09/15] leds: trigger: blkdev: Check devices for activity and blink LEDs Date: Thu, 9 Sep 2021 17:25:07 -0500 Message-Id: <20210909222513.2184795-10-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Use a delayed workqueue to periodically check configured block devices for activity since the last check. Blink LEDs associated with devices on which the configured type of activity (read/write) has occurred. Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 103 ++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 53b62e320491..40dc55e5d4f3 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -8,6 +8,7 @@ #include #include +#include #include "ledtrig-blkdev.h" @@ -60,6 +61,108 @@ struct ledtrig_blkdev_led { enum ledtrig_blkdev_mode mode; }; +/* All LEDs associated with the trigger */ +static HLIST_HEAD(ledtrig_blkdev_leds); + +/* How often to check for drive activity - in jiffies */ +static unsigned int ledtrig_blkdev_interval; + +/* Delayed work used to periodically check for activity & blink LEDs */ +static void blkdev_process(struct work_struct *const work); +static DECLARE_DELAYED_WORK(ledtrig_blkdev_work, blkdev_process); + + +/* + * + * Periodically check for device acitivity and blink LEDs + * + */ + +static void blkdev_blink(const struct ledtrig_blkdev_led *const led) +{ + unsigned long delay_on = READ_ONCE(led->blink_msec); + unsigned long delay_off = 1; /* 0 leaves LED turned on */ + + led_blink_set_oneshot(led->led_dev, &delay_on, &delay_off, 0); +} + +static void blkdev_update_disk(struct ledtrig_blkdev_disk *const disk, + const unsigned int generation) +{ + const struct block_device *const part0 = disk->gd->part0; + const unsigned long read_ios = part_stat_read(part0, ios[STAT_READ]); + const unsigned long write_ios = part_stat_read(part0, ios[STAT_WRITE]) + + part_stat_read(part0, ios[STAT_DISCARD]) + + part_stat_read(part0, ios[STAT_FLUSH]); + + if (disk->read_ios != read_ios) { + disk->read_act = true; + disk->read_ios = read_ios; + } else { + disk->read_act = false; + } + + if (disk->write_ios != write_ios) { + disk->write_act = true; + disk->write_ios = write_ios; + } else { + disk->write_act = false; + } + + disk->generation = generation; +} + +static bool blkdev_read_mode(const enum ledtrig_blkdev_mode mode) +{ + return mode != LEDTRIG_BLKDEV_MODE_WO; +} + +static bool blkdev_write_mode(const enum ledtrig_blkdev_mode mode) +{ + return mode != LEDTRIG_BLKDEV_MODE_RO; +} + +static void blkdev_process(struct work_struct *const work) +{ + static unsigned int generation; + + struct ledtrig_blkdev_led *led; + struct ledtrig_blkdev_link *link; + unsigned long delay; + + if (!mutex_trylock(&ledtrig_blkdev_mutex)) + goto exit_reschedule; + + hlist_for_each_entry(led, &ledtrig_blkdev_leds, leds_node) { + + hlist_for_each_entry(link, &led->disks, led_disks_node) { + + struct ledtrig_blkdev_disk *const disk = link->disk; + + if (disk->generation != generation) + blkdev_update_disk(disk, generation); + + if (disk->read_act && blkdev_read_mode(led->mode)) { + blkdev_blink(led); + break; + } + + if (disk->write_act && blkdev_write_mode(led->mode)) { + blkdev_blink(led); + break; + } + } + } + + ++generation; + + mutex_unlock(&ledtrig_blkdev_mutex); + +exit_reschedule: + delay = READ_ONCE(ledtrig_blkdev_interval); + WARN_ON_ONCE(!schedule_delayed_work(&ledtrig_blkdev_work, delay)); +} + /* * From patchwork Thu Sep 9 22:25:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508549 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.7 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 38554C28B21 for ; Thu, 9 Sep 2021 22:25:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2060D611C0 for ; Thu, 9 Sep 2021 22:25:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345971AbhIIW0p (ORCPT ); Thu, 9 Sep 2021 18:26:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345433AbhIIW0i (ORCPT ); Thu, 9 Sep 2021 18:26:38 -0400 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CB22C061574; Thu, 9 Sep 2021 15:25:28 -0700 (PDT) Received: by mail-oi1-x232.google.com with SMTP id bi4so64815oib.9; Thu, 09 Sep 2021 15:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JA7MvqNCRAXbYo05TfGKX4daKtGDuTCNxMXvkKsnrrw=; b=Wpa5qcsKD3h1dxUxPkvXqucRseJMxsqBR1HCxJhdsXbr4dJJ0RmZr+H6Rk9dRHmby+ 5dEfveugg5KqVNdn2AEVV/Tr5cXPObo38HqLPCcDs9NsMziOZdwCx96rGTu7jeS1n+Ef sUn2lQ4QJOwEvC1Q3qRCuLpveehx1XDZIRoxlD2MjfCujitWZBsRgVXFctJRshz4ib8F CzZnEfFY4bVJ9Snth4SK6uDnai6xxyqp6iDUMTC/sETqY6KChUWQATMB4gs61r2nQ/kQ LuimEGNIOEvXB7L2mexoypPnLmO6aQbJge7esB1ku5C0p5BXaTBXzkpjyCILbKLha47u yDcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JA7MvqNCRAXbYo05TfGKX4daKtGDuTCNxMXvkKsnrrw=; b=D3NKO7gR+T+gX1zh6cURBfE1gF8yhKUjwvDfSR+2VQVZH8wyh9AssEr2STf3DGvqPf QqFk80QgPquXk4F+WfkuS2LYzW4uWVsgeMm2OGokYr6ckaPFikDlnhZk2S/vvSmr01iB VQgVAHj+sYInkDDJNosghS/eIAcIEDZ69aaL8F7RNMPVIdPJWdLA6YuGnJnBeg0/zxdk L0JqF22yiXIHnCJ8QsOAgX3AoJNq7LoTn755jJsjb3/de1AbtfhsKzYndcUzcfyuJQLE bI6PJ0T2qfqBX77AJ+rnaSRhNrVu+drStHhYly6JT2S3S0XQjPnpVnfpuYgd6uZhjBrX F6WQ== X-Gm-Message-State: AOAM5330XTfSjvi10RLfBRjT1mqXfQVbKa2qYRy+N35juQfB9Qou7H1e 1EGbnJ9UdWtMc63+nGve2Tk= X-Google-Smtp-Source: ABdhPJyTLkciEZWXP55CqUV0Z5GfYTsPtI4BadqhkY4+1ljfmHHr8iZaZDAuq2jBvcbmLNEdfyLf7Q== X-Received: by 2002:a05:6808:1294:: with SMTP id a20mr1775934oiw.4.1631226327717; Thu, 09 Sep 2021 15:25:27 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:27 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 10/15] leds: trigger: blkdev: Add LED trigger activate function Date: Thu, 9 Sep 2021 17:25:08 -0500 Message-Id: <20210909222513.2184795-11-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Allocate per-LED data structure and initialize with default values Create /sys/class/leds//block_devices directory Increment module reference count. Module can only be removed when no LEDs are associated with the trigger. Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 40dc55e5d4f3..6f78a9515976 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -164,6 +164,62 @@ static void blkdev_process(struct work_struct *const work) } +/* + * + * Associate an LED with the blkdev trigger + * + */ + +static int blkdev_activate(struct led_classdev *const led_dev) +{ + struct ledtrig_blkdev_led *led; + int ret; + + /* Don't allow module to be removed while any LEDs are linked */ + if (WARN_ON(!try_module_get(THIS_MODULE))) { + ret = -ENODEV; /* Shouldn't ever happen */ + goto exit_return; + } + + led = kmalloc(sizeof(*led), GFP_KERNEL); + if (led == NULL) { + ret = -ENOMEM; + goto exit_put_module; + } + + led->led_dev = led_dev; + led->blink_msec = LEDTRIG_BLKDEV_BLINK_MSEC; + led->mode = LEDTRIG_BLKDEV_MODE_RW; + INIT_HLIST_HEAD(&led->disks); + + ret = mutex_lock_interruptible(&ledtrig_blkdev_mutex); + if (ret != 0) + goto exit_free; + + led->dir = kobject_create_and_add("linked_devices", + &led_dev->dev->kobj); + if (led->dir == NULL) { + ret = -ENOMEM; + goto exit_unlock; + } + + hlist_add_head(&led->leds_node, &ledtrig_blkdev_leds); + led_set_trigger_data(led_dev, led); + ret = 0; + +exit_unlock: + mutex_unlock(&ledtrig_blkdev_mutex); +exit_free: + if (ret != 0) + kfree(led); +exit_put_module: + if (ret != 0) + module_put(THIS_MODULE); +exit_return: + return ret; +} + + /* * * Initialization - register the trigger @@ -185,5 +241,6 @@ static const struct attribute_group *ledtrig_blkdev_attr_groups[] = { struct led_trigger ledtrig_blkdev_trigger = { .name = "blkdev", + .activate = blkdev_activate, .groups = ledtrig_blkdev_attr_groups, }; From patchwork Thu Sep 9 22:25:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508928 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.7 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 B7B79C4332F for ; Thu, 9 Sep 2021 22:25:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9612E61132 for ; Thu, 9 Sep 2021 22:25:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346083AbhIIW0q (ORCPT ); Thu, 9 Sep 2021 18:26:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345643AbhIIW0i (ORCPT ); Thu, 9 Sep 2021 18:26:38 -0400 Received: from mail-ot1-x32d.google.com (mail-ot1-x32d.google.com [IPv6:2607:f8b0:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0B8AC061574; Thu, 9 Sep 2021 15:25:28 -0700 (PDT) Received: by mail-ot1-x32d.google.com with SMTP id g66-20020a9d12c8000000b0051aeba607f1so4549633otg.11; Thu, 09 Sep 2021 15:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=COFijmkBIWZf2LFD9bYNkKbzuh96VAJr7qSkbGV27Zc=; b=dCwz/OsGRMMfsXzab8kkv8acI7tYG3eF3XFL0zEO7W+Rf+wiIMdnQlVgzN/1ZRilps JTcHsYdC0reLhCgpGXVB5Y8YUvXWKGIBwm1ciNWMX+2ay2sLbvD37DfjI+Z8ytpbdlkS AnsTEs4lzf5kpOVlvnFMYUEmGPmKJAlIQw4MPQHQqw7dgk5VXZlFdnPw/HiLWguliJvS BrjmS2vTQKs6RERHjgfwnVPFm5tmKTJwqnEy0ymA/rPnDK52YZfjxWfPSu9d9avONgjy sGBBruIkXiivuDqPafPnCJ3mBJ/HBPGhFl88vUu7MJjCBW4YzjF0qW5krVnWD6YLYOj1 beQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=COFijmkBIWZf2LFD9bYNkKbzuh96VAJr7qSkbGV27Zc=; b=SVyRpLwXz6R7U3C0/dffG2pWIrmF7pWiFr/dC8KV5V6jqnj5stSk1a+a9Vdvo8MmH1 fYyszFV8lodlPKiFOzPYl2ezNnKf1dnyPoA7soEIK01n3gEYXnqHkugQFlvdzf9OC+cU LmmvIQ0K62FWijYWDqlJKAwMbRtAbfF03k6mnU1XHBo8jK0exvv8Uv2W+2oqxLcavcsu ivbHBTwITyr3kbjR1p66c6uVmBQkUo87rnQnMiuo8Fm9gX87Y2PKb/dcJA/hUfJX9dFX AaKMJ5HWYvaGySm2jU2Vh6oe+62FUaqRXcCr+Xkv+hXyH7f0CAKe8yWPkd0xTcNeZTrd Imhg== X-Gm-Message-State: AOAM532v2MiDwCjAwUU41SHGe3Y18UnM6W6X0A6oZfENwTS3NJqFX/rf jzdiSWzOJH29SBVFi2j833s= X-Google-Smtp-Source: ABdhPJz2vBOzC/+pORZicjpgHAegun4f/ToWb78SnRYCh3qpiJTSmYNdcAxABsNexxNqVcXY5Q9ahA== X-Received: by 2002:a05:6830:2108:: with SMTP id i8mr1957526otc.336.1631226328166; Thu, 09 Sep 2021 15:25:28 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:27 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 11/15] leds: trigger: blkdev: Enable linking block devices to LEDs Date: Thu, 9 Sep 2021 17:25:09 -0500 Message-Id: <20210909222513.2184795-12-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add /sys/class/leds//link_device sysfs attribute If this is the first LED associated with the device, create the /sys/block//blkdev_leds directory. Otherwise, increment its reference count. Create symlinks in /sys/class/leds//block_devices and /sys/block//blkdev_leds If this the first device associated with *any* LED, schedule delayed work to periodically check associated devices and blink LEDs Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 160 ++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 6f78a9515976..26509837f037 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -71,6 +71,9 @@ static unsigned int ledtrig_blkdev_interval; static void blkdev_process(struct work_struct *const work); static DECLARE_DELAYED_WORK(ledtrig_blkdev_work, blkdev_process); +/* Total number of device-to-LED associations */ +static unsigned int ledtrig_blkdev_count; + /* * @@ -220,6 +223,162 @@ static int blkdev_activate(struct led_classdev *const led_dev) } +/* + * + * link_device sysfs attribute - assocate a block device with this LED + * + */ + +/* Gets or allocs & initializes the blkdev disk for a gendisk */ +static int blkdev_get_disk(struct gendisk *const gd) +{ + struct ledtrig_blkdev_disk *disk; + struct kobject *dir; + + if (gd->ledtrig != NULL) { + kobject_get(gd->ledtrig->dir); + return 0; + } + + disk = kmalloc(sizeof(*disk), GFP_KERNEL); + if (disk == NULL) + return -ENOMEM; + + dir = kobject_create_and_add("linked_leds", &disk_to_dev(gd)->kobj); + if (dir == NULL) { + kfree(disk); + return -ENOMEM; + } + + INIT_HLIST_HEAD(&disk->leds); + disk->gd = gd; + disk->dir = dir; + disk->read_ios = 0; + disk->write_ios = 0; + + gd->ledtrig = disk; + + return 0; +} + +static void blkdev_put_disk(struct ledtrig_blkdev_disk *const disk) +{ + kobject_put(disk->dir); + + if (hlist_empty(&disk->leds)) { + disk->gd->ledtrig = NULL; + kfree(disk); + } +} + +static int blkdev_disk_link_locked(struct ledtrig_blkdev_led *const led, + struct gendisk *const gd) +{ + struct ledtrig_blkdev_link *link; + struct ledtrig_blkdev_disk *disk; + unsigned long delay; + int ret; + + link = kmalloc(sizeof(*link), GFP_KERNEL); + if (link == NULL) { + ret = -ENOMEM; + goto error_return; + } + + ret = blkdev_get_disk(gd); + if (ret != 0) + goto error_free_link; + + disk = gd->ledtrig; + + ret = sysfs_create_link(disk->dir, &led->led_dev->dev->kobj, + led->led_dev->name); + if (ret != 0) + goto error_put_disk; + + ret = sysfs_create_link(led->dir, &disk_to_dev(gd)->kobj, + gd->disk_name); + if (ret != 0) + goto error_remove_link; + + link->disk = disk; + link->led = led; + hlist_add_head(&link->led_disks_node, &led->disks); + hlist_add_head(&link->disk_leds_node, &disk->leds); + + if (ledtrig_blkdev_count == 0) { + delay = READ_ONCE(ledtrig_blkdev_interval); + WARN_ON(!schedule_delayed_work(&ledtrig_blkdev_work, delay)); + } + + ++ledtrig_blkdev_count; + + return 0; + +error_remove_link: + sysfs_remove_link(disk->dir, led->led_dev->name); +error_put_disk: + blkdev_put_disk(disk); +error_free_link: + kfree(link); +error_return: + return ret; +} + +static bool blkdev_already_linked(const struct ledtrig_blkdev_led *const led, + const struct gendisk *const gd) +{ + const struct ledtrig_blkdev_link *link; + + if (gd->ledtrig == NULL) + return false; + + hlist_for_each_entry(link, &gd->ledtrig->leds, disk_leds_node) { + + if (link->led == led) + return true; + } + + return false; +} + +static ssize_t link_device_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count) +{ + struct ledtrig_blkdev_led *const led = led_trigger_get_drvdata(dev); + struct gendisk *gd; + int ret; + + ret = mutex_lock_interruptible(&ledtrig_blkdev_mutex); + if (ret != 0) + goto exit_return; + + gd = ledtrig_blkdev_get_disk(buf); + if (gd == NULL) { + ret = -ENODEV; + goto exit_unlock; + } + + if (blkdev_already_linked(led, gd)) { + ret = -EEXIST; + goto exit_put_disk; + } + + ret = blkdev_disk_link_locked(led, gd); + +exit_put_disk: + if (ret != 0) + put_disk(gd); +exit_unlock: + mutex_unlock(&ledtrig_blkdev_mutex); +exit_return: + return (ret == 0) ? count : ret; +} + +static DEVICE_ATTR_WO(link_device); + + /* * * Initialization - register the trigger @@ -227,6 +386,7 @@ static int blkdev_activate(struct led_classdev *const led_dev) */ static struct attribute *ledtrig_blkdev_attrs[] = { + &dev_attr_link_device.attr, NULL }; From patchwork Thu Sep 9 22:25:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508548 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.7 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 39E7FC433EF for ; Thu, 9 Sep 2021 22:25:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A8EE61186 for ; Thu, 9 Sep 2021 22:25:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346944AbhIIW0r (ORCPT ); Thu, 9 Sep 2021 18:26:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345809AbhIIW0j (ORCPT ); Thu, 9 Sep 2021 18:26:39 -0400 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2773CC061757; Thu, 9 Sep 2021 15:25:29 -0700 (PDT) Received: by mail-oi1-x234.google.com with SMTP id v2so83599oie.6; Thu, 09 Sep 2021 15:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+OWBpnRYKTA9XJIeXV+fWpllaXIMTnG6vSbQ+mGIkUI=; b=HGByUuo1qHqOQrb1NgszLt4+QVNaVphP6cdYk/h801IRiTHoN9orv/Otax7ZVQgk8W lO4s35uKHKuJxcZArPR3GClB2NCp04O7ePunK611kL/5/xnTHNp/jb3pLmcvYyqy77OG fYOUmQGBInHqzQPGslSiMSNaT6GAgQxpVwMHr/rsr4a4aadhZQgiITAx+Vno8T5zCN3W SYsm9HKjsx8PiRjNB0p1VNmrFPxY3TiJTI0TWQE69U/DWZ+2+JoR8jzvVcneyDAnSbLp litFAffz37hBy0fVsdEI9rDyeZNuQXa/KJ8veibD0AuWIdhB9zPCvh+Tn84gk3g3a2Ns CKaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+OWBpnRYKTA9XJIeXV+fWpllaXIMTnG6vSbQ+mGIkUI=; b=7e4dKwM9GZ4qOfIXwsJe15Z/x1j/LHIX6l/z1CRX3rIXvaXT15H2HyM8opHDV3SuCK +nxiyYTKd0r1sYu2Ncd3Sdj9QPZqrqxWb6qGxZ7f15Qozz2EwIcWgAplNAZOem7XgPis xGzZP4lQZLoKxzsIjwrWkiV9w6vjQrySuU6vB7fe24FXc3W0MR9EAy6SLqgCvHTeTnRK XX/awHuj+dih8zkXl0KH4ZSoPtnakaJej87pfueBiaNb/PoNEvCVOwBWriZtzgmytPjP G+fHjmsZN6gA/GrnLxH1ijFcOUIITPcGmIfijmVyEyqJgNmiwT9RuC3y+YValZY+9Z1K R5Kg== X-Gm-Message-State: AOAM533VaDvUP/1F4n8wwQ/DvLlrB1ERHNprRm1yndo2GMdvgN4+US6p pVIsfD2rMGQcPHs0wq2c6Bw= X-Google-Smtp-Source: ABdhPJwmRXBiE1FNJvFgfv37fGM8QXPVVz1aiEBc0oYxsuY0sU1D6TITrzUV4htMIvtiQo9hZGtX+w== X-Received: by 2002:a05:6808:657:: with SMTP id z23mr1835231oih.113.1631226328602; Thu, 09 Sep 2021 15:25:28 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:28 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 12/15] leds: trigger: blkdev: Enable unlinking block devices from LEDs Date: Thu, 9 Sep 2021 17:25:10 -0500 Message-Id: <20210909222513.2184795-13-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add /sys/class/leds//unlink_device sysfs attribute Remove symlinks in /sys/class/leds//block_devices and /sys/block//blkdev_leds Decrement reference count on /sys/block//blkdev_leds directory (removes directory when empty) Cancel delayed work if no devices are associated with *any* LEDs Signed-off-by: Ian Pilcher Reported-by: kernel test robot Reported-by: Dan Carpenter --- drivers/leds/trigger/ledtrig-blkdev.c | 57 +++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 26509837f037..fff67ebd28f2 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -379,6 +379,62 @@ static ssize_t link_device_store(struct device *const dev, static DEVICE_ATTR_WO(link_device); +/* + * + * unlink_device sysfs attribute - disassociate a device from this LED + * + */ + +static void blkdev_disk_unlink_locked(struct ledtrig_blkdev_led *const led, + struct ledtrig_blkdev_link *const link, + struct ledtrig_blkdev_disk *const disk) +{ + --ledtrig_blkdev_count; + + if (ledtrig_blkdev_count == 0) + WARN_ON(!cancel_delayed_work_sync(&ledtrig_blkdev_work)); + + sysfs_remove_link(led->dir, disk->gd->disk_name); + sysfs_remove_link(disk->dir, led->led_dev->name); + kobject_put(disk->dir); + + hlist_del(&link->led_disks_node); + hlist_del(&link->disk_leds_node); + kfree(link); + + if (hlist_empty(&disk->leds)) { + disk->gd->ledtrig = NULL; + kfree(disk); + } + + put_disk(disk->gd); +} + +static ssize_t unlink_device_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count) +{ + struct ledtrig_blkdev_led *const led = led_trigger_get_drvdata(dev); + struct ledtrig_blkdev_link *link; + + mutex_lock(&ledtrig_blkdev_mutex); + + hlist_for_each_entry(link, &led->disks, led_disks_node) { + + if (sysfs_streq(link->disk->gd->disk_name, buf)) { + blkdev_disk_unlink_locked(led, link, link->disk); + break; + } + } + + mutex_unlock(&ledtrig_blkdev_mutex); + + return count; +} + +static DEVICE_ATTR_WO(unlink_device); + + /* * * Initialization - register the trigger @@ -387,6 +443,7 @@ static DEVICE_ATTR_WO(link_device); static struct attribute *ledtrig_blkdev_attrs[] = { &dev_attr_link_device.attr, + &dev_attr_unlink_device.attr, NULL }; From patchwork Thu Sep 9 22:25:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508927 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.7 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 3C755C433FE for ; Thu, 9 Sep 2021 22:25:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 228CE6103D for ; Thu, 9 Sep 2021 22:25:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344616AbhIIW0r (ORCPT ); Thu, 9 Sep 2021 18:26:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345835AbhIIW0j (ORCPT ); Thu, 9 Sep 2021 18:26:39 -0400 Received: from mail-ot1-x331.google.com (mail-ot1-x331.google.com [IPv6:2607:f8b0:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92A5DC061575; Thu, 9 Sep 2021 15:25:29 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id x10-20020a056830408a00b004f26cead745so4552061ott.10; Thu, 09 Sep 2021 15:25:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Hi3pqytord6VA6AZ/0fy4UVgNbJFo01Go8vz0Qkno0=; b=TSplS6Yn6eAoeV4ddIRj6XrP5QxQ8Xa9Y21MMWF2ELp6X5d9C677r47b+QL3CO3hmB BzegxKvURdRvBJbR7tJt9TgLBH5cs/Y0c7wGJsI1vtrPXDmKhe8SuYScGtMed9VAg+Mb 169ZKk0ro/Q2sNc0pYSJHkAAT1sxCbmanu8Y1rOL0EPWIFlRxgMM5Hhmwewi2P8vex/1 m7945xyUWTC5TG/7A3ip7l1MrEF/8BxiF7y6o+Kedy+CSxn70dKJIvcU29cm5L4rLXEr 5JMyu0420EQqBrJ45LEeJAtdstCTFrOXBcLh3byS7aCrg78Hifj9xIuPDlQV74oQFl20 +ZhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Hi3pqytord6VA6AZ/0fy4UVgNbJFo01Go8vz0Qkno0=; b=LnxFTsnmaWKjlkIsyfSSpQHULTC8TANL7kqkkai4VCQuS/TQXty2PMrY02AQ+qmmyJ OLCVURwoJqOpOi16hSaQL75/atcWTEBONvyapgRiOrsFZqjGum/mhxiUYgXhADWOjkLp EixTx+LSfyA4Dzt7fJA6+3jIIzYQ0Fq7lWtYzdYrSK3FJU3qGP8udmauRsccB6QCcYOR gOBG3A69VSTcXfRbHbB3tiKeJIVNfGaa+hy3r3J5ZoqDf0fASpmSUTwJMPG0XBGMNRuJ Q+CzyoFJBzIMZknebGaVMR9fgX010S0Nu6tD+hblEk+YYpdSHLbkircUVLnbB+cYxSP8 9ukQ== X-Gm-Message-State: AOAM532/ABAFiavp1o1Q7Nfyn6aQOJXh/bJmb61qH9JRJruKHaPCFH3M 7KD+U6TSOh/GUDUj7zhxYGI= X-Google-Smtp-Source: ABdhPJyxD4gYU6utv6Hj8J6aFumDEknFcUs+8upzTbGMx/d63HjKBngDqRqB9mqRuDxQnbK5zgakag== X-Received: by 2002:a9d:7ccc:: with SMTP id r12mr1946300otn.350.1631226328999; Thu, 09 Sep 2021 15:25:28 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:28 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 13/15] leds: trigger: blkdev: Add LED trigger deactivate function Date: Thu, 9 Sep 2021 17:25:11 -0500 Message-Id: <20210909222513.2184795-14-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Remove all device links from this LED Remove /sys/class/leds//block_devices directory Free per-LED data structure Decrement module reference count Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 28 +++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index fff67ebd28f2..c7e101935bf6 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -435,6 +435,33 @@ static ssize_t unlink_device_store(struct device *const dev, static DEVICE_ATTR_WO(unlink_device); +/* + * + * Disassociate an LED from the trigger + * + */ + +static void blkdev_deactivate(struct led_classdev *const led_dev) +{ + struct ledtrig_blkdev_led *const led = led_get_trigger_data(led_dev); + struct ledtrig_blkdev_link *link; + struct hlist_node *next; + + mutex_lock(&ledtrig_blkdev_mutex); + + hlist_for_each_entry_safe(link, next, &led->disks, led_disks_node) + blkdev_disk_unlink_locked(led, link, link->disk); + + hlist_del(&led->leds_node); + kobject_put(led->dir); + kfree(led); + + mutex_unlock(&ledtrig_blkdev_mutex); + + module_put(THIS_MODULE); +} + + /* * * Initialization - register the trigger @@ -459,5 +486,6 @@ static const struct attribute_group *ledtrig_blkdev_attr_groups[] = { struct led_trigger ledtrig_blkdev_trigger = { .name = "blkdev", .activate = blkdev_activate, + .deactivate = blkdev_deactivate, .groups = ledtrig_blkdev_attr_groups, }; From patchwork Thu Sep 9 22:25:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508547 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.7 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=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 5614DC4332F for ; Thu, 9 Sep 2021 22:25:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3ECB361132 for ; Thu, 9 Sep 2021 22:25:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346567AbhIIW1A (ORCPT ); Thu, 9 Sep 2021 18:27:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346813AbhIIW0p (ORCPT ); Thu, 9 Sep 2021 18:26:45 -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 0418AC061762; Thu, 9 Sep 2021 15:25:33 -0700 (PDT) Received: by mail-ot1-x334.google.com with SMTP id i8-20020a056830402800b0051afc3e373aso4585941ots.5; Thu, 09 Sep 2021 15:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wROv0gkSVLlQgiV3dTqte44uo2NP+QxD284SroRgYCM=; b=lJ0YGiCrc0oMVBjDFQYj5HE7PJl758CvCYWTbTtN+6SmQmjWvwv+9rtyB3YbBwv3qx QahoM9PE4zAJUv3G3yZKq1t1zVbPJOb7HCUZT1opoyp/FbxPrgVHa6ds5uNXRg5ry9gM ZYvTSDvnuXaeOz9XL/5XWA+XzsG48jFBCiI3R96Gh9m2mUu0ZickGROEjmHb9dF6tUc/ IoBa4Sw2k8dHKo/kopA7vmPVAefeHXNriKABkgs6/Q0923MDzK5aG3PY+QfRerB9K8xR sVfs5PToSyYaEW14FUGwfUjHLK+Bg6HcF/9nj1JsuwTOhxDCOKSJT8XKg/iWV88FQNc0 RDzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wROv0gkSVLlQgiV3dTqte44uo2NP+QxD284SroRgYCM=; b=M8vvzsOWSX5qsmIOUqWM2lKZcG2RgDAZkJQ77IRdDzXJ0V7SjQ7TsTOLu/ErP6R0KX zhMBVoQBiuJXCKGCYjI6TB3CILW7H37OOCdoTDwK++1kqqT8HiQaivVprn8PCxxkL235 hy4RtNrKomjlO5e5WeliPUdSbEMnhnY8Xa9bvT5ecdP0+fkFbslxD1q1RNlMpQnOpky3 WY1w8p72yxEoX9FnTNbjWZZvQq6hudO75pJA2nB+8Z+86Mk8VEgY/WAD85y+pUiSp2th QzlD0sp70i2V+hl21XEc1UyyqUWqwckoUXbncJfFFneEQY/eAOXsNEPAmyYaJ7/hOb6t hiUA== X-Gm-Message-State: AOAM5325cIU3hb9ZjpVSWrJ8hftsm2gRlBaldoFghZ6GTy+yyQephu/i 2efy57M6IdzGHCGsHY9/CdQ= X-Google-Smtp-Source: ABdhPJykiJQ83ETtg4IQyPTdQ7ozvxzPSy+bNmovIJd5VatyuNQ52rtT2cNMwUKzGuFUUDTMKtbq0A== X-Received: by 2002:a9d:ecc:: with SMTP id 70mr1997929otj.96.1631226329405; Thu, 09 Sep 2021 15:25:29 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:29 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 14/15] leds: trigger: blkdev: Add remaining sysfs attributes Date: Thu, 9 Sep 2021 17:25:12 -0500 Message-Id: <20210909222513.2184795-15-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org /sys/class/leds//blink_time controls - per-LED blink duration /sys/class/leds//interval - global frequency with which devices are checked for activity and LEDs are blinked /sys/class/leds//mode - blink LED for reads, writes, or both When showing mode, show all modes with current value in square brackets Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 132 ++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index c7e101935bf6..4b88f877ee81 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -462,6 +462,135 @@ static void blkdev_deactivate(struct led_classdev *const led_dev) } +/* + * + * blink_time sysfs attribute + * + */ + +static ssize_t blink_time_show(struct device *const dev, + struct device_attribute *const attr, + char *const buf) +{ + const struct ledtrig_blkdev_led *const led = + led_trigger_get_drvdata(dev); + + return sprintf(buf, "%u\n", READ_ONCE(led->blink_msec)); +} + +static ssize_t blink_time_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count) +{ + struct ledtrig_blkdev_led *const led = led_trigger_get_drvdata(dev); + unsigned int value; + int ret; + + ret = kstrtouint(buf, 0, &value); + if (ret != 0) + return ret; + + if (value < LEDTRIG_BLKDEV_MIN_BLINK) + return -ERANGE; + + WRITE_ONCE(led->blink_msec, value); + return count; +} + +static DEVICE_ATTR_RW(blink_time); + + +/* + * + * interval sysfs attribute - affects all LEDS + * + */ + +static ssize_t interval_show(struct device *const dev, + struct device_attribute *const attr, + char *const buf) +{ + return sprintf(buf, "%u\n", + jiffies_to_msecs(READ_ONCE(ledtrig_blkdev_interval))); +} + +static ssize_t interval_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count) +{ + unsigned int value; + int ret; + + ret = kstrtouint(buf, 0, &value); + if (ret != 0) + return ret; + + if (value < LEDTRIG_BLKDEV_MIN_INT) + return -ERANGE; + + WRITE_ONCE(ledtrig_blkdev_interval, msecs_to_jiffies(value)); + + return count; +} + +static DEVICE_ATTR_RW(interval); + + +/* + * + * mode sysfs attribute - blink for reads, writes, or both + * + */ + +static const struct { + const char *name; + const char *show; +} blkdev_modes[] = { + [LEDTRIG_BLKDEV_MODE_RO] = { + .name = "read", + .show = "[read] write rw\n", + }, + [LEDTRIG_BLKDEV_MODE_WO] = { + .name = "write", + .show = "read [write] rw\n", + }, + [LEDTRIG_BLKDEV_MODE_RW] = { + .name = "rw", + .show = "read write [rw]\n", + }, +}; + +static ssize_t mode_show(struct device *const dev, + struct device_attribute *const attr, char *const buf) +{ + const struct ledtrig_blkdev_led *const led = + led_trigger_get_drvdata(dev); + + return sprintf(buf, blkdev_modes[READ_ONCE(led->mode)].show); +} + +static ssize_t mode_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count) +{ + struct ledtrig_blkdev_led *const led = led_trigger_get_drvdata(dev); + enum ledtrig_blkdev_mode mode; + + for (mode = LEDTRIG_BLKDEV_MODE_RO; + mode <= LEDTRIG_BLKDEV_MODE_RW; ++mode) { + + if (sysfs_streq(blkdev_modes[mode].name, buf)) { + WRITE_ONCE(led->mode, mode); + return count; + } + } + + return -EINVAL; +} + +static DEVICE_ATTR_RW(mode); + + /* * * Initialization - register the trigger @@ -471,6 +600,9 @@ static void blkdev_deactivate(struct led_classdev *const led_dev) static struct attribute *ledtrig_blkdev_attrs[] = { &dev_attr_link_device.attr, &dev_attr_unlink_device.attr, + &dev_attr_blink_time.attr, + &dev_attr_interval.attr, + &dev_attr_mode.attr, NULL }; From patchwork Thu Sep 9 22:25:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 508926 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.7 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=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 3AC6AC433EF for ; Thu, 9 Sep 2021 22:25:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 244256103D for ; Thu, 9 Sep 2021 22:25:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348828AbhIIW07 (ORCPT ); Thu, 9 Sep 2021 18:26:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346823AbhIIW0p (ORCPT ); Thu, 9 Sep 2021 18:26:45 -0400 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C0CC061764; Thu, 9 Sep 2021 15:25:33 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id s20so101082oiw.3; Thu, 09 Sep 2021 15:25:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=57sH7rbHDCtndpXrjoz5ALAT6TMzRAfWHgGMDK00Q1w=; b=aTD33AfBhDhGMQGAKEWJQxoV7Q0RxdGwq0rs8Wb4nnoNuzoRNFJvHo9LaAVotzMr+s CfRVHTtFj0KhONHMLOc2+hTQXBvYqENmxJjNpMD5sEL6n8tc1C7DLmBwmXqAH5axuGa8 UftJlAleHCa2DldkBhLNGN+o1L35bZXV/MG4i6BGoVhmZ2aTecnqxeI9tvxAWhSJcYVA WY4E/nnti/KsRAL0WnWlXxVYEbp6IzPx+f3YRWOB52BEqy8pY9UJ1f98wI0ONyb29f2y 6r+rp28BtmUKIbsdQleaUh6FDn4bgFkVFxlk7F3Bmfc532VyeGQzd1/HilEkr4rgGgMU j6Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=57sH7rbHDCtndpXrjoz5ALAT6TMzRAfWHgGMDK00Q1w=; b=SPiQaz+K0Evfdn6Ymxf84W38eSq1ixk67r6KfkPOU5OaKvAegZgnSmW5sMniPiFLiJ FXK+XBFsGavJYQ4mnX+PwY0swL+g4BwryS/WXwM7KDJs0R6/LU9HIz1KEQaJRjkSoAhj d4HCJA3znfboJBodu+i5k5OmOjnVPu6Sq01ueWeCoLux/FEjn/rDphk5lNwL81h+3Mmg N5qLndG5qiForc5AO5HpiJpBNLF5Ku5X5ogtfoBzCP9zojgeFaBURsCRi2KYajWlFut8 4bQGwmhM4KsiRC5Z/n1eQ0LKYgUcjuzeYYs4A+v3tnwYJDPJhfZ0nujKHSbQZCNgzmub WMww== X-Gm-Message-State: AOAM532DojwqRRI7YIKQIhDAIYi8hm5rMYR/eCft+jHTZ8gpMD4qJeE1 lLH2rBagV/hniBua9kUJ+1IOAR+O2V0= X-Google-Smtp-Source: ABdhPJzwsGy9wITJK6/Ou5BOUSLzjFkl9yxn495BEF84qNPHzcNg5IKrMTtgWf5WIIFu7EOFJ1EyUA== X-Received: by 2002:a05:6808:10ce:: with SMTP id s14mr1824088ois.157.1631226332821; Thu, 09 Sep 2021 15:25:32 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id 4sm747293oil.38.2021.09.09.15.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Sep 2021 15:25:32 -0700 (PDT) From: Ian Pilcher To: axboe@kernel.dk, pavel@ucw.cz Cc: linux-leds@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, kabel@kernel.org Subject: [PATCH v2 15/15] leds: trigger: blkdev: Add disk cleanup and init/exit functions Date: Thu, 9 Sep 2021 17:25:13 -0500 Message-Id: <20210909222513.2184795-16-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210909222513.2184795-1-arequipeno@gmail.com> References: <20210909222513.2184795-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Disk cleanup function - blkdev_disk_cleanup(): * Called when block device is being removed * Called via __ledtrig_blkdev_disk_cleanup function pointer from ledtrig_blkdev_disk_cleanup() in ledtrig-blkdev-core.c Init function - blkdev_init(): * Initialize interval (convert default value to jiffies) * Initialize __ledtrig_blkdev_disk_cleanup function pointer * Register the block device LED trigger Exit function - blkdev_exit(): * Unregister the LED trigger * Set __ledtrig_blkdev_disk_cleanup back to NULL Make LED trigger struct (ledtrig_blkdev_trigger) static (as it's now referenced in blkdev_init()). Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 65 ++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 4b88f877ee81..96ea694ce29f 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -435,6 +435,23 @@ static ssize_t unlink_device_store(struct device *const dev, static DEVICE_ATTR_WO(unlink_device); +/* + * + * Disassociate all LEDs from a block device (because it's going away) + * + */ + +static void blkdev_disk_cleanup(struct gendisk *const gd) +{ + struct ledtrig_blkdev_link *link; + struct hlist_node *next; + + hlist_for_each_entry_safe(link, next, + &gd->ledtrig->leds, disk_leds_node) + blkdev_disk_unlink_locked(link->led, link, gd->ledtrig); +} + + /* * * Disassociate an LED from the trigger @@ -615,9 +632,55 @@ static const struct attribute_group *ledtrig_blkdev_attr_groups[] = { NULL }; -struct led_trigger ledtrig_blkdev_trigger = { +static struct led_trigger ledtrig_blkdev_trigger = { .name = "blkdev", .activate = blkdev_activate, .deactivate = blkdev_deactivate, .groups = ledtrig_blkdev_attr_groups, }; + +static int __init blkdev_init(void) +{ + int ret; + + ret = mutex_lock_interruptible(&ledtrig_blkdev_mutex); + if (ret != 0) + return ret; + + ledtrig_blkdev_interval = msecs_to_jiffies(LEDTRIG_BLKDEV_INTERVAL); + __ledtrig_blkdev_disk_cleanup = blkdev_disk_cleanup; + + /* + * Can't call led_trigger_register() with ledtrig_blkdev_mutex locked. + * If an LED has blkdev as its default_trigger, blkdev_activate() will + * be called for that LED, and it will try to lock the mutex, which will + * hang. + */ + mutex_unlock(&ledtrig_blkdev_mutex); + + ret = led_trigger_register(&ledtrig_blkdev_trigger); + if (ret != 0) { + mutex_lock(&ledtrig_blkdev_mutex); + __ledtrig_blkdev_disk_cleanup = NULL; + mutex_unlock(&ledtrig_blkdev_mutex); + } + + return ret; +} +module_init(blkdev_init); + +static void __exit blkdev_exit(void) +{ + mutex_lock(&ledtrig_blkdev_mutex); + + /* + * It's OK to call led_trigger_unregister() with the mutex locked, + * because the module can only be unloaded when no LEDs are using + * the blkdev trigger, so blkdev_deactivate() won't be called. + */ + led_trigger_unregister(&ledtrig_blkdev_trigger); + __ledtrig_blkdev_disk_cleanup = NULL; + + mutex_unlock(&ledtrig_blkdev_mutex); +} +module_exit(blkdev_exit);