From patchwork Thu Aug 19 02:50:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500728 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1EC8C432BE for ; Thu, 19 Aug 2021 02:51:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C599C61103 for ; Thu, 19 Aug 2021 02:51:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235761AbhHSCvl (ORCPT ); Wed, 18 Aug 2021 22:51:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235729AbhHSCvk (ORCPT ); Wed, 18 Aug 2021 22:51:40 -0400 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5248AC061764; Wed, 18 Aug 2021 19:51:05 -0700 (PDT) Received: by mail-ot1-x32a.google.com with SMTP id 61-20020a9d0d430000b02903eabfc221a9so6931099oti.0; Wed, 18 Aug 2021 19:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+KJ+LtUcknzEkHfsTVvqfXOdgjk417QG3hNVVCZe1bo=; b=DSAn74ZT+ETInT+hMQJI9ycd6AOUHJqZPUfUv4Tr4IzidsSPGhsXkS3KRgEdg8pJBZ nYtkweFwJ5q8sFl7BC2Ov1bcEz6a/nJXcfaOCc8/4BjnqLuJyr++czk93CZ+jDyFZwY3 sOkMlFTfP0WjE9LtBoB4fg4nifsJO2cnLwwoh6vk4pjAufGrL/CDn5WfyCRnA122cAYR mBBQsQ6wwBbQdWoA/faldjlkUM8l3UNqgyuloIGOLtYAPsyTzR/FKeghvuEwYu8rAt8J se7wdlbA56RmxbusJvUxOt3BDHWR+O6vqjKWmGBnWu5Qra4IEu+TywprfLv/oZWIqlGF UadQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+KJ+LtUcknzEkHfsTVvqfXOdgjk417QG3hNVVCZe1bo=; b=O+Z2JbIUl6nVPm9c72Aj7wVh7/E2WwJz10iDh71PJ0+Jayy3y772gSWrmzIcQS9/FI tYEP7rmL8Aq0DVnLFRMGMJFzAcOcl+ZGixw/AjEk3ovbRCtjbzJte7QzYDaGzMIDQoC4 AAqCIfQFEzoNS9HEFtP0vwvf1orReSb6P1CPswbhTkfomREbS4WYdb6OhtohMo2SnYuW im5UIfX5HJK2OxsfJ5vsdMdOhKDCWAZ6xt5kR5xR1BkLkIrH5I9+Y6tunKhLWCJtVJD9 W6flR//hjIHtDwDbz8eySrqm+ByrBD8Xftu/XFm/ZSxXEva0BLuzyGvx3CWlZxjZfEmH bi9w== X-Gm-Message-State: AOAM533yWG5GkR+vl1snWWikbwmqxWakkJa+VdtmBPbUt71yF78QyXJn zYBI1kMlUrn7U0j/JQ1/Q3RsTxelDXPCl60d X-Google-Smtp-Source: ABdhPJyf5nFinNpn1fZT34q1cYXqVBZ/pFNAwXBAOk+Kr7cm4xyehmm+fYwmI7uKx0PQ0w6zXXYKWQ== X-Received: by 2002:a9d:1408:: with SMTP id h8mr9476386oth.151.1629341464141; Wed, 18 Aug 2021 19:51:04 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:03 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 01/18] docs: Add block device (blkdev) LED trigger documentation Date: Wed, 18 Aug 2021 21:50:36 -0500 Message-Id: <20210819025053.222710-2-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-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//add_blkdev * /sys/class/leds//delete_blkdev * /sys/class/leds//block_devices Add /sys/block//blkdev_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 | 48 +++++++ Documentation/leds/index.rst | 1 + Documentation/leds/ledtrig-blkdev.rst | 132 ++++++++++++++++++ 4 files changed, 190 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 e34cdeeeb9d4..702601d6a276 100644 --- a/Documentation/ABI/testing/sysfs-block +++ b/Documentation/ABI/testing/sysfs-block @@ -316,3 +316,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//blkdev_leds +Date: August 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..1fd164983f13 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-led-trigger-blkdev @@ -0,0 +1,48 @@ +What: /sys/class/leds//blink_time +Date: August 2021 +Contact: Ian Pilcher +Description: + Time (in milliseconds) that the LED will be on during a single + "blink". + +What: /sys/class/leds//interval +Date: August 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: August 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//add_blkdev +Date: August 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. Multiple + device names may be written at once, separated by whitespace. + +What: /sys/class/leds//delete_blkdev +Date: August 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. Multiple + device names may be written at once, separated by whitespace. + +What: /sys/class/leds//block_devices +Date: August 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..0b1a9359ec39 --- /dev/null +++ b/Documentation/leds/ledtrig-blkdev.rst @@ -0,0 +1,132 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================= +Block Device (blkdev) LED Trigger +================================= + +Available when ``CONFIG_LEDS_TRIGGER_BLKDEV=y``. + +See also: + +* ``Documentation/ABI/testing/sysfs-class-led-trigger-blkdev`` +* ``Documentation/ABI/testing/sysfs-block`` (``/sys/block//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 (``Documentation/leds/uleds.rst``). + +Associate the LED with the ``blkdev`` LED trigger:: + + # echo blkdev > /sys/class/leds//trigger + + # cat /sys/class/leds//trigger + ... kbd-ctrlrlock [blkdev] disk-activity ... + +Note that several new device attributes are available. + +* ``add_blkdev`` and ``delete_blkdev`` are used to associate block devices with + this LED, and to remove associations. + +* ``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. + +* The ``block_devices`` directory will contain a symbolic link to every device + that is associated with this LED. + +Associate the LED with the block device:: + + # echo sda > /sys/class/leds//add_blkdev + + # ls /sys/class/leds//block_devices + sda + +Reads 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_on``, and the minimum delay between blinks can +be set via ``/sys/class/leds//blink_off``. + +Associate a second device with the LED:: + + # echo sdb > /sys/class/leds//add_blkdev + + # ls /sys/class/leds//block_devices + sda sdb + +When a block device is associated with one or more LEDs, the LEDs are linked +from the device's ``blkdev_leds`` directory:: + + # ls /sys/block/sd{a,b}/blkdev_leds + /sys/block/sda/blkdev_leds: + + + /sys/block/sdb/blkdev_leds: + + +(The ``blkdev_leds`` directory only exists when the block device is associated +with at least one LED.) + +The ``add_blkdev`` and ``delete_blkdev`` attributes both accept multiple, +whitespace separated, devices. For example:: + + # echo sda sdb > /sys/class/leds//delete_blkdev + + # ls /sys/class/leds//block_devices + +``interval`` and ``blink_time`` +=============================== + +* The ``interval`` attribute is a global setting. Changing the value via + ``/sys/class/leds//interval`` will affect all LEDs associated with + the ``blkdev`` LED 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 associated 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 currently 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 Aug 19 02:50:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500018 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A4DDC4338F for ; Thu, 19 Aug 2021 02:51:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5687661130 for ; Thu, 19 Aug 2021 02:51:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235787AbhHSCvm (ORCPT ); Wed, 18 Aug 2021 22:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235746AbhHSCvl (ORCPT ); Wed, 18 Aug 2021 22:51:41 -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 AEC5EC0613CF; Wed, 18 Aug 2021 19:51:05 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id w22-20020a056830411600b0048bcf4c6bd9so6844263ott.8; Wed, 18 Aug 2021 19:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VB+baDa9o7QBYGGk/mOq5L0ZVoeaDiRYIRcxi/hAPFM=; b=WCUXl+XhEcacaKGATrA0KhVNljLVCbZOhtVf4LLxwbgmArictmIyRRaV3cK3TnyIKM Qwo+vhcXG9tDKAhK+UHDSTI6KaRjNFEsDSG6SxnrfM3Cdy5/BHSrB/Ys67uMO6a7mPaE LBNPtjEPEIs8k0xr+vynoknFYsdSCNSEFEB872mk72bjjOAuwCuEH1VbMS5Qzv0U43Lv HkOAo4UeJ/lpKS+vu3oS7ZU0Ek351ZtjkspNE32IXc7s6Yi0JbZmRa/yaYd+tv/ZFUqF qlh4qZ9Rc+7HOja0yjtE4gJpKQl22gkLQ7C036FjyuDMvGYv2/3f/2w02xWUxBJC/OkK 2sdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VB+baDa9o7QBYGGk/mOq5L0ZVoeaDiRYIRcxi/hAPFM=; b=q7W6KV5fpXfu0h7fuMPdADDKjCPPdBZcSzh7jMHJNLFfYH61hY8q/cCSLwnv8KCPIx L5s3OBDm4yIIwOItqB3vyOv/YbnTEh6zftBDmyueDfqWO4Q7MdJj5hdWysmbZVBt0/58 39mNnAczLkU2MlRcM1T/FtYoz/j7XIMcg2f6+4dMvQtQvjGA+fek5uaDi709XiRbElcD 2V0LHzxxiNWFPqyTmUYhlwBIiDgpN3wE7KbGXBsA62MzPECaSZWXPJsqPdeYkrCbM7vR lcZGe/IiE0nKY5X6RsMDdECiJ8o3tUk8cbHZ79PKPfx4nQd+Bg2VW6p2JflmN8NVKGwb XvPw== X-Gm-Message-State: AOAM53009fpPz/r76is4SuU3Ir1pae+NoJIrLipEZCjMna78ZWZSbpel Mt8ei1J2O/3gJxM65eUGD3AHYd/8GxainqRJ X-Google-Smtp-Source: ABdhPJwoaFZji6/oDadqjC5RCzefm/AYQBsuP/lp5448Yd0r5LflzybTLSICxFXmrqu4zpxMmxjxQw== X-Received: by 2002:a05:6830:156:: with SMTP id j22mr1371657otp.75.1629341464884; Wed, 18 Aug 2021 19:51:04 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:04 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 02/18] block: Add get_disk_by_name() for use by blkdev LED trigger Date: Wed, 18 Aug 2021 21:50:37 -0500 Message-Id: <20210819025053.222710-3-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add API that gets a "handle" (pointer & incremented reference count) to a block device (struct gendisk) by name. Used by the block device LED trigger when configuring which device(s) an LED should monitor. Signed-off-by: Ian Pilcher --- block/genhd.c | 25 +++++++++++++++++++++++++ include/linux/genhd.h | 10 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 298ee78c1bda..e6d7bb709d62 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1362,3 +1362,28 @@ int bdev_read_only(struct block_device *bdev) return bdev->bd_read_only || get_disk_ro(bdev->bd_disk); } EXPORT_SYMBOL(bdev_read_only); + +static int match_disk_name(struct device *const dev, const void *const name) +{ + return dev->type == &disk_type + && strcmp(name, dev_to_disk(dev)->disk_name) == 0; +} + +/** + * get_disk_by_name - get a gendisk by name + * @name: the name of the disk + * + * Returns a pointer to the gendisk named @name (if it exists), @NULL if not. + * Increments the disk's reference count, so caller must call put_device(). + */ +struct gendisk *get_disk_by_name(const char *const name) +{ + struct device *dev; + + dev = class_find_device(&block_class, NULL, name, match_disk_name); + if (dev == NULL) + return NULL; + + return dev_to_disk(dev); +} +EXPORT_SYMBOL_GPL(get_disk_by_name); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 13b34177cc85..b26bbf2d9048 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -342,4 +342,14 @@ static inline void printk_all_partitions(void) } #endif /* CONFIG_BLOCK */ +/* for blkdev LED trigger (drivers/leds/trigger/ledtrig-blkdev.c) */ +#ifdef CONFIG_BLOCK +struct gendisk *get_disk_by_name(const char *name); +#else +static inline struct gendisk *get_disk_by_name(const char *name) +{ + return NULL; +} +#endif + #endif /* _LINUX_GENHD_H */ From patchwork Thu Aug 19 02:50:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=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 8F654C4338F for ; Thu, 19 Aug 2021 02:51:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79B80610A5 for ; Thu, 19 Aug 2021 02:51:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235804AbhHSCvm (ORCPT ); Wed, 18 Aug 2021 22:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235558AbhHSCvm (ORCPT ); Wed, 18 Aug 2021 22:51:42 -0400 Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E87FC061764; Wed, 18 Aug 2021 19:51:06 -0700 (PDT) Received: by mail-oi1-x233.google.com with SMTP id t35so6465436oiw.9; Wed, 18 Aug 2021 19:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i3RRDN8bijQwsoqPWVruCdSUNXKFKGVON2X6+jAlmv4=; b=Tjeeecq3I7NTk2XXKM1NItrtNGA67sP5QkkQUdNCDSnFgmgqxJ7Xx0ICeV0+mPCHT8 2CSBX5jkn+g/eH4u0M7TDj0k59qSa3p/1Ks1JZKuctF33WyHC3JYo5BulUg/D9F5+ZpZ R8FdZPO24iYt4tfIPLg2e3RY+vOUNQU5oSrCD+xu2NydukYLf+zqGbbo+Xw46GMWQXG9 u/l6tICTfZwiJYmEdruNvHMoJtsvEYaZmPBkX3+yAnEWI2BP9CfFeHAjxUBcuAlBnPpN 5JcGGrVBPUlyLQQUbgMvF1i8ikMcZerq6s4bby93r/4s+1y54uspc/ZULjTSHLrOD5Yw btJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i3RRDN8bijQwsoqPWVruCdSUNXKFKGVON2X6+jAlmv4=; b=e0ycrNfnYhQ7fimYz2uSBVTwIUAfzOmIHfU6tQJpZNW/3TTm5u/JqFE5Xu6iadOBpv JFCMx60JfJ3Jzkazs8q/MQsmEpuYGC03qbAy1rvTqeGG7vcAQvibFvktUzY58ZgdeHrN kX4Tr+94NWNvsvnU13QhSW9IPXdRTtmU4S3BcKfIMjSgu0Ao8O//9WxfjC/1iHw692RC xcivmaIz4ovp5qXT7oagZ3osxTZgs3srLARqIK6Ef3lGu//iKiUen3NDVt0Di0IWEoTY ViSwL/JNhopD1YnqzcMdUZ1yDXoepvHm4Il2aLaPZBm44MFmsIi2y+RfWmQ+lF8CGwCj yMVw== X-Gm-Message-State: AOAM5333UVC5jlKW4FI9oTzZyI89vWDdN2+fnf2TEVC/MkL+aoIxNnEj 7PyCksS/jmuT794myoeoGc/5p7VIwGDLjuYf X-Google-Smtp-Source: ABdhPJwrEUeY8+ucrN8skEp2O7F2N3gAPfSbef8yyOI5DdbmJnCQv5hk7cpZAddbN3hgLeZMvyhI6g== X-Received: by 2002:a05:6808:1442:: with SMTP id x2mr1011606oiv.162.1629341465681; Wed, 18 Aug 2021 19:51:05 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:05 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 03/18] ledtrig-blkdev: Add file (ledtrig-blkdev.c) for block device LED trigger Date: Wed, 18 Aug 2021 21:50:38 -0500 Message-Id: <20210819025053.222710-4-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add data types and global variables Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 66 +++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 drivers/leds/trigger/ledtrig-blkdev.c diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c new file mode 100644 index 000000000000..28ccbd7946ba --- /dev/null +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Block device LED triggers + * + * Copyright 2021 Ian Pilcher + */ + +#include +#include +#include + +/* Default blink time & polling interval (milliseconds) */ +#define LEDTRIG_BLKDEV_BLINK_MSEC 75 +#define LEDTRIG_BLKDEV_INTERVAL 100 + +/* Minimum VALUE for interval or blink_time */ +#define LEDTRIG_BLKDEV_MIN_TIME 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 */ +}; + +/* Trigger-specific info about a block device */ +struct ledtrig_blkdev_disk { + struct gendisk *gd; + struct kobject *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; /* block_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; +}; + +/* All LEDs associated with the trigger */ +static HLIST_HEAD(ledtrig_blkdev_leds); + +/* Must hold when changing trigger/LED/device associations */ +static DEFINE_MUTEX(ledtrig_blkdev_mutex); + +/* Total number of device-to-LED associations */ +static unsigned int ledtrig_blkdev_count; + +/* How often to check for drive activity - in jiffies */ +static unsigned int ledtrig_blkdev_interval; From patchwork Thu Aug 19 02:50:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D9D9C19F33 for ; Thu, 19 Aug 2021 02:51:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8278B60F35 for ; Thu, 19 Aug 2021 02:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235729AbhHSCvo (ORCPT ); Wed, 18 Aug 2021 22:51:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235809AbhHSCvm (ORCPT ); Wed, 18 Aug 2021 22:51:42 -0400 Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AAFEC061764; Wed, 18 Aug 2021 19:51:07 -0700 (PDT) Received: by mail-ot1-x332.google.com with SMTP id h63-20020a9d14450000b02904ce97efee36so6837170oth.7; Wed, 18 Aug 2021 19:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qbI1pPRxf25pr2Ei2jsbhNXjyN2At2UDUcIa0sXZlcc=; b=jXCqHfVzezbg84KWtIvjU7ss5ey/Rscavur5r8e3DywfgBSXVBtUkY0NzxSGKM2Pzd TnKa5l+QAyOXOczLXa9CIxleWka6VNkPvFj5L345VIsLGeZu1b5gxa7BVTMnuR7LyrkN w0KVQeBbisl1VJD8oQqaB/lQLbQKSF1kENggJbztncIFrIwp1a38AIHtU8Q18KV8rIcV XMSrxER3QcZE/N2X/D3/An7Z5JaIvlU3rkR2wP5stZFxjYNqoLfhHjt0CG7vYHwFsqtn g0Zy81YI8T647dIpQSK2lZQMJqqjcO7D4MCpApxvKIUvdkKC9hGhpq4VUns8zAdoArIM qweA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qbI1pPRxf25pr2Ei2jsbhNXjyN2At2UDUcIa0sXZlcc=; b=WrzaMcfNS5QRGXXlCd/A0CSjPVdEPGk6oNuqsCpEdwO+/8XlpTKe6vJBbYFg/fmCMg XiJobii35ZMGgqUAqxw7aTj54KrF1qy32GA6AtmUlw4TUShcWcFHsqLyms64YtvHQFg3 4F8XLrlpLGLMmYaon1oW5H+WawK4nCujrhLzzwF+mpzKIEOrB0naLEkXq857Fl/iKpWs 9Ii8wsH2ILWwaCoFt+yPXEJ63iBmYVZuIN2dakGb6+xhaZH2p5SvWwa4tvJbtMhpsmFq jCwbzjhEGXqxWKS0K9KaJbBPoPq8JDgOW7mtSE924CmtGBznUFydwZpqCnA47DQ9TxNM PUww== X-Gm-Message-State: AOAM533Vw+tsUthGZT6GNNXCNrukkeHuFtbBpZHWf/Yl4tP/BdZz31Of SOpu3e9Wrim/VNX5dXMCvLABac4ZDBvuHO7R X-Google-Smtp-Source: ABdhPJxhwdZVhIqT/etxLmyLnab1ijJigyk+plkkQknuZwxkylxcmMbHRDdpygEecfT5B5vYKjBhPQ== X-Received: by 2002:a9d:560a:: with SMTP id e10mr9928797oti.219.1629341466512; Wed, 18 Aug 2021 19:51:06 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:06 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 04/18] ledtrig-blkdev: Add misc. helper functions to blkdev LED trigger Date: Wed, 18 Aug 2021 21:50:39 -0500 Message-Id: <20210819025053.222710-5-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add various helper functions to the block device LED trigger: * blkdev_mkdir() - create a sysfs directory (and don't swallow error codes) * blkdev_streq(), blkdev_skip_space() & blkdev_find_space() - for parsing writes to sysfs attributes * blkdev_read_mode() & blkdev_write_mode() - LED mode activity type helpers Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 74 +++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 28ccbd7946ba..fcae7ce63b92 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 #include @@ -64,3 +65,76 @@ static unsigned int ledtrig_blkdev_count; /* How often to check for drive activity - in jiffies */ static unsigned int ledtrig_blkdev_interval; + + +/* + * + * Miscellaneous helper functions + * + */ + +/* Like kobject_create_and_add(), but doesn't swallow error codes */ +static struct kobject *blkdev_mkdir(const char *const name, + struct kobject *const parent) +{ + struct kobject *dir; + int ret; + + dir = kobject_create(); + if (dir == NULL) + return ERR_PTR(-ENOMEM); + + ret = kobject_add(dir, parent, "%s", name); + if (ret != 0) { + kobject_put(dir); + return ERR_PTR(ret); + } + + return dir; +} + +/* + * Compare a null-terminated C string with a non-null-terminated character + * sequence of a known length. Returns true if equal, false if not. + */ +static bool blkdev_streq(const char *const cstr, + const char *const cbuf, const size_t buf_len) +{ + return (strlen(cstr) == buf_len) && (memcmp(cstr, cbuf, buf_len) == 0); +} + +/* + * Returns a pointer to the first non-whitespace character in s + * (or a pointer to the terminating null). + */ +static const char *blkdev_skip_space(const char *s) +{ + while (*s != 0 && isspace(*s)) + ++s; + + return s; +} + +/* + * Returns a pointer to the first whitespace character in s (or a pointer to the + * terminating null), which is effectively a pointer to the position *after* the + * last character in the non-whitespace token at the beginning of s. (s is + * expected to be the result of a previous call to blkdev_skip_space()). + */ +static const char *blkdev_find_space(const char *s) +{ + while (*s != 0 && !isspace(*s)) + ++s; + + return s; +} + +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; +} From patchwork Thu Aug 19 02:50:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 368C3C41537 for ; Thu, 19 Aug 2021 02:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1A3626102A for ; Thu, 19 Aug 2021 02:51:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235876AbhHSCvo (ORCPT ); Wed, 18 Aug 2021 22:51:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235825AbhHSCvn (ORCPT ); Wed, 18 Aug 2021 22:51:43 -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 269DDC061764; Wed, 18 Aug 2021 19:51:08 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id l36-20020a0568302b24b0290517526ce5e3so6808846otv.11; Wed, 18 Aug 2021 19:51:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KN3RdtaPCPi2Hj7PNHCIU6zyZs4TyPkyQvFttMGrQr8=; b=SF+WcaoPyMlBNsME6TVNfMNiAF4SMkeIw2pw3VxZTre7ZxXbQxZ/ID9blfTbtnLceG X2yfgyXnYdGUypUpvHi941CK/WaRDh19ThrN3kZgQVYRXvLAnv0Z7a0gKSQoG0gLSQ6H P6cEwU909lAEhtwyVScYVFAX/X8UpFUR1RtgnAWt3JqxM0TfuXIr0AUoQgM+CHu3Da7z DXTlHt0B9i/4bCps0H7D5/YTm/u0GpY8fco1SKMPJA2tPab9VhSbDnMa6e8SXJo0I84N gr8rvrFfgiXnH/03EkPfTUwtAloNAIj4BUppdAsRot5kkF6EM/wCvOA2ifpZgg8eCdYI EZAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KN3RdtaPCPi2Hj7PNHCIU6zyZs4TyPkyQvFttMGrQr8=; b=uGhe+y6uSmyaeEZ+FpZ9vZ2zQ5WA7QX0lpXVG72chc71b51f644SmG3rbs35505Mxv KltJGvqbI4UbIdul/IEgxC2T91s7DR9t2beT/XT+uVKiuzbfjD3IQhhyyKsdZfB1OdJr MLn6HDAz48gdt6/HWOaOBHYgxyoGHzAetOHzmLktlDN9Z+ZLrTvCXy6/aCTwXQSPwb0v 3v+z86yAFQmZHXVwZXnGvwPCbe4+NYk+TrZaxYlxN+KWwWvBapPpvgIs2uUvwp3dDp/9 CK4K6u5UqKdHkXm4FEat6BsEIuNgE/iVgkRa9Fpv19ockjKGXC2Kd2MvA6hSSAC9QkRG BwyA== X-Gm-Message-State: AOAM531jijKtBq3mKLk4A0ke5Xb8JJ/k9ClaV2ZJUrAPqJJu0BQJMY5I ztZsGjGTY0fvFWSrhM3nw71kUr5ikRFCUOBP X-Google-Smtp-Source: ABdhPJym1+41WRSy25qtKnor96Xjxwr+V2eqznOK887iLdvIcDbRvWVehE9Gjvrx+fARt1Bmhlhsrg== X-Received: by 2002:a9d:4c89:: with SMTP id m9mr10214504otf.255.1629341467287; Wed, 18 Aug 2021 19:51:07 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:06 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 05/18] ledtrig-blkdev: Periodically check devices for activity & blink LEDs Date: Wed, 18 Aug 2021 21:50:40 -0500 Message-Id: <20210819025053.222710-6-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-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 | 87 +++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index fcae7ce63b92..e9c23824c33c 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -7,9 +7,11 @@ */ #include +#include #include #include #include +#include /* Default blink time & polling interval (milliseconds) */ #define LEDTRIG_BLKDEV_BLINK_MSEC 75 @@ -66,6 +68,9 @@ static unsigned int ledtrig_blkdev_count; /* How often to check for drive activity - in jiffies */ static unsigned int ledtrig_blkdev_interval; +static void blkdev_process(struct work_struct *const work); +static DECLARE_DELAYED_WORK(ledtrig_blkdev_work, blkdev_process); + /* * @@ -138,3 +143,85 @@ static bool blkdev_write_mode(const enum ledtrig_blkdev_mode mode) { return mode != LEDTRIG_BLKDEV_MODE_RO; } + + +/* + * + * 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 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 Aug 19 02:50:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500726 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F46BC4338F for ; Thu, 19 Aug 2021 02:51:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71A966115B for ; Thu, 19 Aug 2021 02:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235911AbhHSCvp (ORCPT ); Wed, 18 Aug 2021 22:51:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235853AbhHSCvo (ORCPT ); Wed, 18 Aug 2021 22:51:44 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F6BAC0613CF; Wed, 18 Aug 2021 19:51:09 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id l36-20020a0568302b24b0290517526ce5e3so6808882otv.11; Wed, 18 Aug 2021 19:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sHJ6xIxDt3XA246U2lV+K6FnAovAAMr3EploK9JC5Ks=; b=a7KK94iCAmI+6eXFYg75GNAI0bmgDA59ZXccCeX+9omBlPmR2885dUYbm5qktM9uMU wjKBRRBv/sPXB1EQVOQAxTFj1949ZxnF1OI0d3xHzYW+4liJVf2Y7LVdYPBPSdh9f4zy SGe+JhLOjC/JrkHOgW7ibBlf56WxpCmi8BtX+eiG8pKDzshXPXFfPU1woigl34w9G/bK 7sh0st3vvQdWpkqX7NfVvRz6dQEtx6KUp8m5rz1tOLxuEBpW6HZHKdvKM7jiLfu4mlBs NkV4i5iuYuOaLponvku/SuqrQ1cStxcFpkqV8Vyod9nNykVXz/T4Q2PanWAU0jUqJq1w jt8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sHJ6xIxDt3XA246U2lV+K6FnAovAAMr3EploK9JC5Ks=; b=BEgNMwBlJ8c4QVpKWJ+nY5bflJSbLyynVv5SGaBz8opNY4M9tK3BnVYMoiUN0hcTtP uoyWKdafXJn/RTqgv0tgMkjylGuadQEI6un2zuV4UGqPwJTiS10bFWS+QNjh29rNxKBZ /oI7D99hlqcXucA7lqOIn+PQY2xZ1MYBODSEsU/QhF5yg/x1CdDuxFXg4G8BUAlTaZaU kxqA7OBlbzOqNOfYE7CN+5/hFTPi/QGQX8as13/ibfOv2j8adm1hllsuaoBOdXLcYlVW 4FKLxzkt4rgXpjUtRAfFbRz0Cj9kWj7pj+BOEQTTluRm/ksnkMUKUmbgAcbK7pqoBcOc Trng== X-Gm-Message-State: AOAM532RX8D9zsU9Gt6ZWbsvpyNWikXTrl2u6JR4SAE+cUuFg2cZwcLu X5dT4Z+sf3nNxOaw2cav0cG+HfC6Gm1UPlA/ X-Google-Smtp-Source: ABdhPJyI82d41Fqs8kmor5RQK8H67itumoTrNSJPEf/KsY05snzSy/2jpn8MtLGyho0JZPUGQA/4sw== X-Received: by 2002:a9d:2de1:: with SMTP id g88mr9980024otb.84.1629341468225; Wed, 18 Aug 2021 19:51:08 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:07 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 06/18] block: Add LED trigger pointer to struct gendisk Date: Wed, 18 Aug 2021 21:50:41 -0500 Message-Id: <20210819025053.222710-7-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Needed by ledtrig_blkdev_disk_cleanup(), which removes all monitoring of a block device by the blkdev LED trigger when the device is removed Signed-off-by: Ian Pilcher --- include/linux/genhd.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/genhd.h b/include/linux/genhd.h index b26bbf2d9048..66e2760702cb 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -168,6 +168,9 @@ struct gendisk { #endif /* CONFIG_BLK_DEV_INTEGRITY */ #if IS_ENABLED(CONFIG_CDROM) struct cdrom_device_info *cdi; +#endif +#ifdef CONFIG_LEDS_TRIGGER_BLKDEV + struct ledtrig_blkdev_disk *ledtrig; #endif int node_id; struct badblocks *bb; From patchwork Thu Aug 19 02:50:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500016 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80275C43216 for ; Thu, 19 Aug 2021 02:51:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6829F6113A for ; Thu, 19 Aug 2021 02:51:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235974AbhHSCvr (ORCPT ); Wed, 18 Aug 2021 22:51:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235838AbhHSCvp (ORCPT ); Wed, 18 Aug 2021 22:51:45 -0400 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAB78C061764; Wed, 18 Aug 2021 19:51:09 -0700 (PDT) Received: by mail-ot1-x32c.google.com with SMTP id w22-20020a056830411600b0048bcf4c6bd9so6844440ott.8; Wed, 18 Aug 2021 19:51:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BkKk5IdQRzWklzG7HN3qRXs0xk7AxusQvu7aSpQWfNY=; b=d35XzzvrkYne8EgQl4IWEEGQcIsB5mM2CgVGd4U2m0dJP0+ttUMD1knAkSdg4UBuig c91p2X25gK6cmvA6wExYn298f2n/lpFmWU4XLxy2G7vMthM/vePscjReNCcQHc+5BEs/ r7lUWYwxjqPcBSDInCVSICp4MJk0nWD8JDP0y1WIUa7i8dR88zJss7VurRa2tTn2e/hy ry+tYU56dhhpaEYwgLI1txRcM0dFCdFcdvoQPpAB6Hb+yb1seBIbnWKtVI5hfGzriOBl HTTr49BFbX5sPEn6fkiGKUA+LZwRLoz34moSGyQXI77wtm0QhvtoTzV9uX+w+ePhTDLT cUig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BkKk5IdQRzWklzG7HN3qRXs0xk7AxusQvu7aSpQWfNY=; b=N0Y0GH+a4/9wE8bRqmsK5Vse2plZACcXsOdKdCBoOJQJaOr7yX9kd04moBC5lwzsyU uwc5Wj7RmNmWyEicVsb9PQRG/+hZdwJN+zF3gmk1zYncKLD5ZIygOiJKDhHSQKiZz1Bk LmSHvRZef+rtjnmVTx3+vhtxdGvbMP2tqjxujR1yBk71Wn5gYH1qWeAqi4bQDx+/UHPg R4afdwAG5hOTFAWlSqgHAhYUZ7/oRj2/w8X4TVbfGTCPPMvHC4ZuSELxefsVplFNmzdH 09F7hF0rlXEx45oMlopHyhzvAkeaseP8CEHZB3nR6mvpS2vqOHZBvpzh8Ww9ZJkBMl7u xzVA== X-Gm-Message-State: AOAM5323MovSDNzv2I08wAjbNr23l3wb5Wj18BmjnF4yEW8KjOsCU3m/ uk/7U3tCbGvYoHVsvMsErkEvxZz/zF+UKVia X-Google-Smtp-Source: ABdhPJwz+g7O6kNiz8COeZqlifuu0qwV+1TFbFCZnSdwZedt6whhHGs0tQ8q2RTrW8aCsiM67DlT3A== X-Received: by 2002:a9d:6e0a:: with SMTP id e10mr6439459otr.259.1629341469018; Wed, 18 Aug 2021 19:51:09 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:08 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 07/18] ledtrig-blkdev: Add function to initialize gendisk ledtrig member Date: Wed, 18 Aug 2021 21:50:42 -0500 Message-Id: <20210819025053.222710-8-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Ensures that gendisk ledtrig member is initialized to NULL, in case the structure was not allocated with kzalloc() or equivalent Signed-off-by: Ian Pilcher --- include/linux/leds.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/linux/leds.h b/include/linux/leds.h index 329fd914cf24..6b67650d8797 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -599,4 +600,19 @@ static inline void ledtrig_audio_set(enum led_audio type, } #endif +#ifdef 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) +{ + gd->ledtrig = NULL; +} +#else /* CONFIG_LEDS_TRIGGER_BLKDEV */ +static inline void ledtrig_blkdev_disk_init(const struct gendisk *gd) +{ +} +#endif /* CONFIG_LEDS_TRIGGER_BLKDEV */ + #endif /* __LINUX_LEDS_H_INCLUDED */ From patchwork Thu Aug 19 02:50:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=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 7133DC432BE for ; Thu, 19 Aug 2021 02:51:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 581B061103 for ; Thu, 19 Aug 2021 02:51:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235959AbhHSCvy (ORCPT ); Wed, 18 Aug 2021 22:51:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235922AbhHSCvq (ORCPT ); Wed, 18 Aug 2021 22:51:46 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFA1AC061764; Wed, 18 Aug 2021 19:51:10 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id w22-20020a056830411600b0048bcf4c6bd9so6844474ott.8; Wed, 18 Aug 2021 19:51:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M/NUaTEslE7hYgIeaV8Kn3/oBWy9c6O39iYX3Cnl+Lo=; b=FqT2S8VM3TK55vvDvRvBBb+HuJWK6vQOYFPfdnhPDrr0IykKsGbNrPAvPhTXgfIIcP FuzaZjlxskiilziBJgyAjUWa1YZkiBBela1eK/vlmyJH164vkghksiPpQ1e63JA0yXQ7 y5MRszITcbmp1Ig4BUr8lNXMlXtmzPNiAfepGDOlzvQW0ZDIGBSszXYn/wivjhGg1BlM DHjZo6FRR2PllWqFxd4F8nwLQTR7PvUMiaMHzcEJUYX/yyHfN9Ru5mbm+hKE07OF1wZ4 ii+bQThK1RQYAJ9TqHjBx/ooAll1VSk9sPhOqXY2alkf/3zX26LI4IOJcLxwaNulpbEw M9wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M/NUaTEslE7hYgIeaV8Kn3/oBWy9c6O39iYX3Cnl+Lo=; b=gl6tQxt5AUQL2YgqKurMv1v33slsvX2LHAvlU3gD+mySLItxQhRbbsJaVu68YnS0Xc /z9kZG9uwgAlAyB441Ar4O1KAweVUKLfn4lmeGmEGhIqHLTtN17G9WvaIWcImvIZhXhW Gseqsg9OYnYRZR3jFaPkhjc35SanYMhDZaC0c7t0ZGnD2k3MYLOpST4veuH4eihL/p89 OxmjYGsAMG3SD6CjsBvX7h5TQwwNoZm9pedWBPI3gpOKMyfwy8FyvXuAX2AXZMcVDzpt ca8LH6nvsLTQ3IEKxOL0z1+16gKDUwVcud6+czjLn/SmiJuFZznuBekYBDA6ZI6EPHVs 6hDw== X-Gm-Message-State: AOAM5318CenAQGURMgpv9fh9y6r6csSddlA2wuiKpq5wgXJ6cSDh01v3 QdtvWbwrVUHlFlGsA268xNqiAbrTsytwnM4n X-Google-Smtp-Source: ABdhPJy6HDMBN4qeDBPKHvTHqMK0xe6cVxyZEXGaXvEpfIv1mQoQcMcUv/7BZC+N+gf63ph0Id2SAw== X-Received: by 2002:a9d:6505:: with SMTP id i5mr4501523otl.284.1629341470011; Wed, 18 Aug 2021 19:51:10 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:09 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 08/18] ledtrig-blkdev: Add function to remove LED/device association Date: Wed, 18 Aug 2021 21:50:43 -0500 Message-Id: <20210819025053.222710-9-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org 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 when disassociating last device Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index e9c23824c33c..447fc81ae0c5 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -225,3 +225,59 @@ static void blkdev_process(struct work_struct *const work) delay = READ_ONCE(ledtrig_blkdev_interval); WARN_ON_ONCE(!schedule_delayed_work(&ledtrig_blkdev_work, delay)); } + + +/* + * + * Disassociate a block device from an LED + * + */ + +static void blkdev_disk_del_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_device(disk_to_dev(disk->gd)); +} + +static void blkdev_disk_delete(struct ledtrig_blkdev_led *const led, + const char *const disk_name, + const size_t name_len) +{ + struct ledtrig_blkdev_link *link; + + mutex_lock(&ledtrig_blkdev_mutex); + + hlist_for_each_entry(link, &led->disks, led_disks_node) { + + if (blkdev_streq(link->disk->gd->disk_name, + disk_name, name_len)) { + blkdev_disk_del_locked(led, link, link->disk); + goto exit_unlock; + } + } + + pr_info("blkdev LED: %.*s not associated with LED %s\n", + (int)name_len, disk_name, led->led_dev->name); + +exit_unlock: + mutex_unlock(&ledtrig_blkdev_mutex); +} From patchwork Thu Aug 19 02:50:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500724 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0432C4338F for ; Thu, 19 Aug 2021 02:51:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9DB576102A for ; Thu, 19 Aug 2021 02:51:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235977AbhHSCv4 (ORCPT ); Wed, 18 Aug 2021 22:51:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235957AbhHSCvr (ORCPT ); Wed, 18 Aug 2021 22:51:47 -0400 Received: from mail-ot1-x32e.google.com (mail-ot1-x32e.google.com [IPv6:2607:f8b0:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C457C061796; Wed, 18 Aug 2021 19:51:11 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id l36-20020a0568302b24b0290517526ce5e3so6808943otv.11; Wed, 18 Aug 2021 19:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gLq26oGhJkSVR5HWnDcMPok9R/cYfBLnVyDwU8dlv5w=; b=suB3ljiNGnGxG6Bp3moMcQsr25VLohaoWgkBBn6zRRbfsz7DTrraZ9YDFmz8dLR7Eq 7APEqWaAg2p4NgF0jwLhL4Ix/ZxcQoKYky7OacWw5PLP6bqRczjFV2tdrZ/JRF/XM6DB 66XwukMKDx5tRBJ4nQw2jvkm6yMjamsgdna14nwWTfomG3Zyy/S2BbKy/yWGzQYQJzOV OTqsj/UZQwhOgr8YrhyEzJcqCLHYhLCUZuTzhzoCB+9wRPvB+mIeRR61D+TI1OWSSKcr c1oYu/bGS78EHatKwKrsshufA34PvQan4ri1e4v2d437zE6dLrXdMjMpqEyreasBwcOJ CGfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gLq26oGhJkSVR5HWnDcMPok9R/cYfBLnVyDwU8dlv5w=; b=KO2wKZUhB2eEQky6jE2DQfFL3rO7Q2JDD1RIBSAFww2Z/FpKLcaf8hdZMYHzqsjHva Ux2KOMhJ7z4LpyflgFG00x3CJTBHLNyYQ+f9nMWXtg0uKs1W3Ebzfl6vJOGAyvNCxjvv qRBMq5oIsfkEGtqQAAYJK6SM179jlqET8+/xZSr/dQjHMV7o5Yj8+uTIsIrNalYOyNpW MCnJvLIKgQvOlYmrUjqJy61Nh24sl9BxuCkvBhmusGZdGCbH45UU41AQjwU9+bE4vfPq 8428+C7IUEJJQ2j3G1elMbr+zmf20hExH1sMtN9LU0FVonfeN75AXSNKfVk/+C7hdCn5 viFw== X-Gm-Message-State: AOAM531TKxKneu97zGIJ4Q/z2lFdXua54+P8dtNuGUPK83JAalQ0tb1n GDr3zzZxU/wxTrtcoGZogwVC2UmbGr8Ta3Gu X-Google-Smtp-Source: ABdhPJzlam1Dquw74l0eyIrxHOMvo3DoH1h7lrZKoDXGbh79W+Ks0D1jZowdb36CXuthHv0/38p/zA== X-Received: by 2002:a9d:6f0a:: with SMTP id n10mr9825670otq.190.1629341470771; Wed, 18 Aug 2021 19:51:10 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:10 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 09/18] ledtrig-blkdev: Add function to disassociate a device from all LEDs Date: Wed, 18 Aug 2021 21:50:44 -0500 Message-Id: <20210819025053.222710-10-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Called when block device is being removed Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 31 +++++++++++++++++++++++++++ include/linux/leds.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 447fc81ae0c5..2072cc904616 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -281,3 +281,34 @@ static void blkdev_disk_delete(struct ledtrig_blkdev_led *const led, exit_unlock: mutex_unlock(&ledtrig_blkdev_mutex); } + + +/* + * + * Disassociate all LEDs from a block device (because it's going away) + * + */ + +/** + * ledtrig_blkdev_disk_cleanup - remove a block device from the blkdev LED + * trigger + * @disk: the disk to be removed + */ +void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd) +{ + struct ledtrig_blkdev_link *link; + struct hlist_node *next; + + mutex_lock(&ledtrig_blkdev_mutex); + + if (gd->ledtrig != NULL) { + + hlist_for_each_entry_safe(link, next, + &gd->ledtrig->leds, disk_leds_node) { + blkdev_disk_del_locked(link->led, link, gd->ledtrig); + } + } + + mutex_unlock(&ledtrig_blkdev_mutex); +} +EXPORT_SYMBOL_GPL(ledtrig_blkdev_disk_cleanup); diff --git a/include/linux/leds.h b/include/linux/leds.h index 6b67650d8797..98c479814988 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -609,10 +609,14 @@ static inline void ledtrig_blkdev_disk_init(struct gendisk *const gd) { gd->ledtrig = NULL; } +void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd); #else /* 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 /* CONFIG_LEDS_TRIGGER_BLKDEV */ #endif /* __LINUX_LEDS_H_INCLUDED */ From patchwork Thu Aug 19 02:50:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500014 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F1B9C4320E for ; Thu, 19 Aug 2021 02:51:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6898B61156 for ; Thu, 19 Aug 2021 02:51:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236271AbhHSCwB (ORCPT ); Wed, 18 Aug 2021 22:52:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236007AbhHSCvs (ORCPT ); Wed, 18 Aug 2021 22:51:48 -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 502AEC0617A8; Wed, 18 Aug 2021 19:51:12 -0700 (PDT) Received: by mail-ot1-x32d.google.com with SMTP id y14-20020a0568302a0e00b0051acbdb2869so72454otu.2; Wed, 18 Aug 2021 19:51:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v5mjMakUsAY/Uh/ybHnL/303309Iy2FWIDQogSSAPJE=; b=CKzXUP9e9H7OnWKRpvxpj9DZggpzSBm9fUyxcGKPKhuDDkyVLNst7w8zLS49jQfets u4tb6EORuqkPnRVK5gu50hISvyG/WzA8m+XDzGM71NHZyZApr07bCxToJ4B2v7H61CaW JVbse/inPDtaC7KHv2QX7IXFMKiLgrSokBBTyOh7Kf2MSuKOs70SpJbnKVjS8dpceYG7 gRct/vplsSHmwvF4Wb5ie0JrxoFxonxNt7GenSssHntTS9HFQycxXNnk8whkyninX4Y7 9u9BffctCML+de4ezoF37vX1MD6txzMwX7yFIukgxw/UKksw0AW/xkXRp7nizsWyuHTk w8Sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v5mjMakUsAY/Uh/ybHnL/303309Iy2FWIDQogSSAPJE=; b=MoB79Up6ehYIZytUJ5mEon/K7e1ZsowNT3LdrZrU3+yDTH9h3rv4VnrqnmlAop//UB ucVYq43Qo/Mxud1OgmUJUQ/KuvQVPj3+zJ93vhSW7bdcClh9nSsFdH9wIe1mpKis18ha l9GGRtxdaAOvfm3ePmS7HR23NktpRXI0pvHv/B1xueI1Yq3Tmf9PCw584fE2fEMOS4cD 4ki43em/xEQZMcSWtWJhKLORjIcaq9vabo60hnQsY/8PbSel5JewUdrCLr/zKTO7rnTQ cLnLt63U+juCgiAaBPK2XuI5mDoYNjiqofoPMtM3UHIQnVPNuCtLEgCJvFrp2JXw2AEn UOtw== X-Gm-Message-State: AOAM5331+5d+5dIYM2B2VIkfSBX0lUvNksC/ZWwkC8y6BOwEScxjkIkx YSbfXBPAGPaabx+23LmnBxOXP9Os/DZs14aa X-Google-Smtp-Source: ABdhPJxA7g3i9lB/V607DC+8KFBgYk7tDMorATPY2xOn/FsLNCoYfwiuo6WPuwjqOx1oEdnbYIYVTA== X-Received: by 2002:a05:6830:2b0d:: with SMTP id l13mr9768430otv.39.1629341471526; Wed, 18 Aug 2021 19:51:11 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:11 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 10/18] block: Call LED trigger init/cleanup functions Date: Wed, 18 Aug 2021 21:50:45 -0500 Message-Id: <20210819025053.222710-11-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Call ledtrig_blkdev_disk_init() from __device_add_disk() to ensure that gendisk's ledtrig field is initialized Call ledtrig_blkdev_disk_cleanup() from del_gendisk() to clean up any references to the device from the block device LED trigger Signed-off-by: Ian Pilcher --- block/genhd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index e6d7bb709d62..091b954ddab3 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "blk.h" @@ -539,6 +540,7 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, disk_add_events(disk); blk_integrity_add(disk); + ledtrig_blkdev_disk_init(disk); } void device_add_disk(struct device *parent, struct gendisk *disk, @@ -581,6 +583,7 @@ void del_gendisk(struct gendisk *disk) if (WARN_ON_ONCE(!disk->queue)) return; + ledtrig_blkdev_disk_cleanup(disk); blk_integrity_del(disk); disk_del_events(disk); From patchwork Thu Aug 19 02:50:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C49EEC432BE for ; Thu, 19 Aug 2021 02:51:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADBD1610FB for ; Thu, 19 Aug 2021 02:51:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236124AbhHSCwG (ORCPT ); Wed, 18 Aug 2021 22:52:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236143AbhHSCvz (ORCPT ); Wed, 18 Aug 2021 22:51:55 -0400 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 24B69C06129E; Wed, 18 Aug 2021 19:51:13 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id r17-20020a0568302371b0290504f3f418fbso6795537oth.12; Wed, 18 Aug 2021 19:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CHR8GEyHKCZ6Ukss9VRJCG5gxZXrolsRZXMVOL6995E=; b=a+E/hwq57irPKDH3Yx0253HMNP6ebrgBa3XT5+xMpZqo2G6bKFVh8HsaPRs3OqSaPE A5CY6TXhP/4ChaZuTbVk18v9B3XvC/kNBGp1/CWfQMpw4yGIQoX/QO/UifLarYqeRKTp FW8um0kWWK7/Jd2+fCIWvYNIY/5NbTzBwsvyYHHd2g66ey8phNLuC0D7QDKaSwkYa/ZU bDVaoic0k6lkTIqEomRQglTir16F9fzNpfBuCG7j3YpC0VSnPI4BEhd/qPRU+2FdpYnI qTvtDaTIlzWAKaYayzNsah7H716cWM8spf/8L3iSMEC4EtDvpCqvVnIcXIWi5keK3ZhN JL5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CHR8GEyHKCZ6Ukss9VRJCG5gxZXrolsRZXMVOL6995E=; b=XK7Y0av1dZAeB3xjcj+R/rqFmASuoTsSzStMqANAjmICBfOOEY9rXlxiUXOw2mb7Yz a3HfH2bMDuvFdb3n88D+q0Eosh1LUXs8ucC6KBWytb/QDyJY05AjBJVIKOMDGKxDgmyQ ZXmVntsf0h23xHp8AgHK6zMAsWZ4qFNlLc06DZc1Y+J4bpyrLMqeRmYdZ7pgO3p4Uu1+ 5vWnLFdYclFZfekNyRnPdZHitB9tMhzspEPJ3LCqSlLk7wtrizyHKUfRZ3WPwHxm9Q/2 n2cFJ32dkB+6l+fdNYIqPuhxfqsogwRtDqvySARZ3c4ABzDDY4wmPuDPyzvLNL42x5Bw +cBg== X-Gm-Message-State: AOAM531Cu6UN2TnGc4kefY+J21ArO4bXsflg9d2hR177YU52cQqm/BAa nni3CMhRePVJDHvnoNHB/ahfj2IF7XItjFsR X-Google-Smtp-Source: ABdhPJwYn0zhky0T0oFkOw81AF80BaiHQyx4j85uT/pQJYNmeMUXQeqiBjX8nbS0H3WwNh8cwZOD6w== X-Received: by 2002:a9d:3a6:: with SMTP id f35mr7709660otf.144.1629341472243; Wed, 18 Aug 2021 19:51:12 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:11 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 11/18] ledtrig-blkdev: Add function to associate a device with an LED Date: Wed, 18 Aug 2021 21:50:46 -0500 Message-Id: <20210819025053.222710-12-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org 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 | 168 ++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 2072cc904616..a1646752b9a0 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -312,3 +312,171 @@ void ledtrig_blkdev_disk_cleanup(struct gendisk *const gd) mutex_unlock(&ledtrig_blkdev_mutex); } EXPORT_SYMBOL_GPL(ledtrig_blkdev_disk_cleanup); + + +/* + * + * Associate a block device with an 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 = blkdev_mkdir("blkdev_leds", &disk_to_dev(gd)->kobj); + if (IS_ERR(dir)) { + kfree(disk); + return PTR_ERR(dir); + } + + 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_add_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) { + pr_info("blkdev LED: %s already associated with %s\n", + gd->disk_name, led->led_dev->name); + return true; + } + } + + return false; +} + +static int blkdev_disk_add(struct ledtrig_blkdev_led *const led, + const char *const disk_name, const size_t name_len) +{ + static char name[DISK_NAME_LEN]; /* only used w/ mutex locked */ + struct gendisk *gd; + int ret; + + if (name_len >= DISK_NAME_LEN) { + pr_info("blkdev LED: invalid device name %.*s\n", + (int)name_len, disk_name); + ret = -EINVAL; + goto exit_return; + } + + ret = mutex_lock_interruptible(&ledtrig_blkdev_mutex); + if (ret != 0) + goto exit_return; + + memcpy(name, disk_name, name_len); + name[name_len] = 0; + gd = get_disk_by_name(name); /* increments disk's refcount */ + + if (gd == NULL) { + pr_info("blkdev LED: no such block device %.*s\n", + (int)name_len, disk_name); + ret = -ENODEV; + goto exit_unlock; + } + + if (blkdev_already_linked(led, gd)) { + ret = -EEXIST; + goto exit_put_dev; + } + + ret = blkdev_disk_add_locked(led, gd); + +exit_put_dev: + if (ret != 0) + put_device(disk_to_dev(gd)); +exit_unlock: + mutex_unlock(&ledtrig_blkdev_mutex); +exit_return: + return ret; +} From patchwork Thu Aug 19 02:50:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500013 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71FADC432BE for ; Thu, 19 Aug 2021 02:51:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CA2461100 for ; Thu, 19 Aug 2021 02:51:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236488AbhHSCwS (ORCPT ); Wed, 18 Aug 2021 22:52:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235985AbhHSCwB (ORCPT ); Wed, 18 Aug 2021 22:52:01 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D99CBC061764; Wed, 18 Aug 2021 19:51:13 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id x10-20020a056830408a00b004f26cead745so6843461ott.10; Wed, 18 Aug 2021 19:51:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IJR4ds+4+CeZ2VdvpA3rZh2hvpwHhN5sNDRM77ik75U=; b=SCTmfsSZXysNoVTmaqAaFscvgDU8pv6pdPdLRa1C1TcmqL5ah4cnY5ATsXtLecNeUo V/bM2E2jPLwBAtezc22JOg9o0sMDAVLqw1kkUw6WZxKnPHl5WXp1KXSdR8fWDwLUtV61 ClElyUvIWS3uyHNX8nK9j2bQSw0rxM0XuPS7lf8vWl9aPTzN6v5RXL5G7ulgoQeLWEte NthgHKrdFNdVKV9aAsOrfInsDhYRZWmGALekD695eJ0CCa34T4jFhzP86cmVMWrHyaHP nqqWEqmV2K4G8qIBW/LHti+sAPp+4LZzeDydwVFpz3t10EN6QAdcT83waSDLUrc0UaSS RYwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IJR4ds+4+CeZ2VdvpA3rZh2hvpwHhN5sNDRM77ik75U=; b=FNxGPbUjkY4oUsPm5Kx/Mbkc/Yo40/GAAvtYcGhrd9rgxZ9ErHQ6iZF4Bvn2zQRc6v AyoGWzobcy8gt93SNZvLBANM+Gv4XWn5QHCUuHOIoEQTv+VG7dcLy60i3rQ1KRm4+aPH UqEXxgeVnov3H7K2S7W7zH3YL8XAqyCvaR1j6/I1doo2VWlxZgznAP5o/gytU4CzAZh0 yQ+XN2krxG4fx9936AlDm+vBLqvCqxV4UJwJufr08szgJoyyUA4NzTKRAPSTDkI4yozI 5H7RzrOV7rlHH5n5/pt/3vjzHH/bNWbPs8kDn351yZd1z3GKx9EAqxO2555bgC9dXRO7 QF3w== X-Gm-Message-State: AOAM5303/uPxXpLn6onsbB9gdl5VZnODYgQLidNS/ZDe7EKluo1G22SQ 2cAiaFIluJ0hs/lITtDfhLXKAbTz7BzYe909 X-Google-Smtp-Source: ABdhPJzJzDp/zt8Lm9O57CeptXC+XBKQvnaQoxwF6kT5SljYeFYLRDQSPcZwZNJg9whgu9k3FuN++Q== X-Received: by 2002:a05:6830:411a:: with SMTP id w26mr9765377ott.127.1629341473048; Wed, 18 Aug 2021 19:51:13 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:12 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 12/18] ledtrig-blkdev: Add sysfs attributes to [dis]associate LEDs & devices Date: Wed, 18 Aug 2021 21:50:47 -0500 Message-Id: <20210819025053.222710-13-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org /sys/class/leds//add_blkdev - to create device/LED associations /sys/class/leds//delete_blkdev to remove device/LED associations For both attributes, accept multiple device names separated by whitespace Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index a1646752b9a0..15b15aefdfd8 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -480,3 +480,51 @@ static int blkdev_disk_add(struct ledtrig_blkdev_led *const led, exit_return: return ret; } + + +/* + * + * sysfs attributes to add & delete devices from LEDs + * + */ + +static ssize_t blkdev_add_or_del(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count); + +static struct device_attribute ledtrig_blkdev_attr_add = + __ATTR(add_blkdev, 0200, NULL, blkdev_add_or_del); + +static struct device_attribute ledtrig_blkdev_attr_del = + __ATTR(delete_blkdev, 0200, NULL, blkdev_add_or_del); + +static ssize_t blkdev_add_or_del(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); + const char *const disk_name = blkdev_skip_space(buf); + const char *const endp = blkdev_find_space(disk_name); + const ptrdiff_t name_len = endp - disk_name; /* always >= 0 */ + int ret; + + if (name_len == 0) { + pr_info("blkdev LED: empty block device name\n"); + return -EINVAL; + } + + if (attr == &ledtrig_blkdev_attr_del) { + blkdev_disk_delete(led, disk_name, name_len); + } else { /* attr == &ledtrig_blkdev_attr_add */ + ret = blkdev_disk_add(led, disk_name, name_len); + if (ret != 0) + return ret; + } + + /* + * Consume everything up to the next non-whitespace token (or the end + * of the input). Avoids "empty block device name" error if there is + * whitespace after the last token (e.g. a newline). + */ + return blkdev_skip_space(endp) - buf; +} From patchwork Thu Aug 19 02:50:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500722 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4A3EC4320A for ; Thu, 19 Aug 2021 02:51:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D06CB61139 for ; Thu, 19 Aug 2021 02:51:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236514AbhHSCwS (ORCPT ); Wed, 18 Aug 2021 22:52:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236250AbhHSCwB (ORCPT ); Wed, 18 Aug 2021 22:52:01 -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 B4A40C0613D9; Wed, 18 Aug 2021 19:51:14 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id w22-20020a056830411600b0048bcf4c6bd9so6844628ott.8; Wed, 18 Aug 2021 19:51:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1HN2fz/hl6o2IBWHxShTKoPIjV7uYpHR0/UMxqc+5q4=; b=fL4NgS5Shmo0+2ZqQYXfjcMKUtmFnqgekgokuEHiBLQRNPdP0WPjVgVa8Agy3Mwq3b lq9OI39oggQIH1oIfp+k4gr72zrVtr1b2fBjTst4NoAMJuewdj6dDC7tnNsJHLSqfsvV hU9J0cEeDCU8cV/8Oz+MmCq/T+I4EO5/yG7CIBI7Drgdms819BCbyuX+8MhvgxFmBvCs H6+HhNGv1U1Mvb7wJ3NWL20MxhrlLpX64iU3wMN64lH81bLdy+Kgu95pjPEvZUDTCbJH Q8eAxyhE7pLti0gkLMUiOwJ7VspGZRcK3i6u9YeRRw9PnhX368CN3J82ODMDKirdMWFA vfLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1HN2fz/hl6o2IBWHxShTKoPIjV7uYpHR0/UMxqc+5q4=; b=uYDsgi04D8/6fCKeMH3Hhnzh9X7JobTLWjc0jvJHzGg6c5tB94uGKBQj+snRq6gHZ6 7AomcCzpALEIw2odPU5L7Uihkdl2E1lkFTWl605DCnsMXleMiim7/H6rTkL1UWuzM296 Ur4PKcQ1OEwTnkqMlUeHC/p0YLsBI8uDxFAf2gP5f5QLK3ZsoZghWBjZK9hWQnQdfL6K w/meFhyhZWsbXaM0uHQhKx8JvEyoEDX3WOph233ZfIPsvAGEoKcf3J5OQ5I1AWndu7/N jCnJ6wmhIf4tPPvsKp331QptUdweUFXDKiTV60R78uQDoDwELI4Q+6yZY8rMduKAuXPk 4Ilg== X-Gm-Message-State: AOAM532s5v2bPMvulMt9/ogVIpHlt4viy/x7zJRf0WVoIDehWrz+Ttoq rd0XEIdMK5tJRZi3dbxon4uU802/4XmwfJMn X-Google-Smtp-Source: ABdhPJxlr17Uf/8YuP9vAZoS2kOLGIeaDcFO5/DaXhnwSLeMr9ioHwmpBQsJP3O2Y+0A887WKZG81Q== X-Received: by 2002:a9d:7653:: with SMTP id o19mr9992677otl.236.1629341473842; Wed, 18 Aug 2021 19:51:13 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:13 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 13/18] ledtrig-blkdev: Add blink_time & interval sysfs attributes Date: Wed, 18 Aug 2021 21:50:48 -0500 Message-Id: <20210819025053.222710-14-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-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 Enforce 25 millisecond minimum for both attributes Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 63 +++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 15b15aefdfd8..481b2d142db2 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -528,3 +528,66 @@ static ssize_t blkdev_add_or_del(struct device *const dev, */ return blkdev_skip_space(endp) - buf; } + + +/* + * + * blink_time & interval device attributes + * + */ + +static ssize_t blkdev_time_show(struct device *const dev, + struct device_attribute *const attr, + char *const buf); + +static ssize_t blkdev_time_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count); + +static struct device_attribute ledtrig_blkdev_attr_blink_time = + __ATTR(blink_time, 0644, blkdev_time_show, blkdev_time_store); + +static struct device_attribute ledtrig_blkdev_attr_interval = + __ATTR(interval, 0644, blkdev_time_show, blkdev_time_store); + +static ssize_t blkdev_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); + unsigned int value; + + if (attr == &ledtrig_blkdev_attr_blink_time) + value = READ_ONCE(led->blink_msec); + else // attr == &ledtrig_blkdev_attr_interval + value = jiffies_to_msecs(READ_ONCE(ledtrig_blkdev_interval)); + + return sprintf(buf, "%u\n", value); +} + +static ssize_t blkdev_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_TIME) { + pr_info("blkdev LED: attempt to set time < %s milliseconds\n", + __stringify(LEDTRIG_BLKDEV_MIN_TIME)); + return -ERANGE; + } + + if (attr == &ledtrig_blkdev_attr_blink_time) + WRITE_ONCE(led->blink_msec, value); + else // attr == &ledtrig_blkdev_attr_interval + WRITE_ONCE(ledtrig_blkdev_interval, msecs_to_jiffies(value)); + + return count; +} From patchwork Thu Aug 19 02:50:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500720 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AEFBC4320A for ; Thu, 19 Aug 2021 02:51:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 58A326113A for ; Thu, 19 Aug 2021 02:51:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236077AbhHSCw0 (ORCPT ); Wed, 18 Aug 2021 22:52:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236279AbhHSCwB (ORCPT ); Wed, 18 Aug 2021 22:52:01 -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 89380C0612A3; Wed, 18 Aug 2021 19:51:15 -0700 (PDT) Received: by mail-ot1-x331.google.com with SMTP id r17-20020a0568302371b0290504f3f418fbso6795660oth.12; Wed, 18 Aug 2021 19:51:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sXEks3JI+ONhTh8Qk52K9Fzoc117gt7kl+QmqDHFZ5c=; b=Xt4zZ+NS/ome28aS6rZPPnoQIgvLjCXE1je8BOkKS+mzqJeVv5MJlcZ3ppWG4G3dZJ I75AU1qbeRx1zb0TaOOyeCAas3nY7xnvszopf1FXTqfOgxk9G/JRhYS2xjHUVy1YfW9J uVYwzyIs2ourcYJyOk5LrMTMqd+nKkxm4zfPAYPUL2Ct+BwSSYT10mJbFumr3St8xQ2l c8DwKpIZBNY+Jhm4Ij9iJjD/Zh2r33hTfHsAe0KQkXEqX5fPcVi6UA4m6QZj8fpgGq41 R2vCnSN3m90BXH+SLHdcayd/CbG5Yf1q+OBJ7ZXtvLeSuBeWgGSLICG7TFA85BMECJ+T esFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sXEks3JI+ONhTh8Qk52K9Fzoc117gt7kl+QmqDHFZ5c=; b=SraNRyFjCGROOBeJtgyaOeesrz6gQRzYvPPXX45gnv2NNYUzCsebDILluJAx861Fxu pjHOdOiCoOgdk2sn85caW05N1yRXpoM5wntpK4YoOCy+eZ7YSE8bpeQvwsP0toIMQfou 6+dCrc6VnEra1bzIRIXee2EEG4tet+1MXknSobJhDRb4C2GFlTWvqQOG0fvW3Uj1gHMJ HYwpytG8NWTiqKnicMQ1HbH4saTNhPCExGvwgubb6+5J8MSTgg+ZfVFuvkqyF+0w+VIh vim45oYiwP+kN1upJGIIS3P7o65FDOL2yGAOgEEBKIi6/hgN6KvkrnxUtbEYDW0HtWpC hyqA== X-Gm-Message-State: AOAM530I2cntuiBkD3TIJot/xeAJllmC2HaPCtZC3JBZyhqd8Xp2bLe6 n+JMI2JPYi+vWdMQGiyj8mQYo4ghOmpMyMLz X-Google-Smtp-Source: ABdhPJz0J6AMMiJdieUg0LdlebyEWi5moitw0Ifbz/1N1W5wSKMYt8S+kjeiV2iLpIhAj/lcOfhbCA== X-Received: by 2002:a9d:6003:: with SMTP id h3mr9887837otj.42.1629341474721; Wed, 18 Aug 2021 19:51:14 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:14 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 14/18] ledtrig-blkdev: Add mode (read/write/rw) sysfs attributue Date: Wed, 18 Aug 2021 21:50:49 -0500 Message-Id: <20210819025053.222710-15-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Show all modes, with current mode in square brackets, in show function Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 67 +++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 481b2d142db2..88e2a11af1a9 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -591,3 +591,70 @@ static ssize_t blkdev_time_store(struct device *const dev, return count; } + + +/* + * + * LED mode device attribute + * + */ + +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 blkdev_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 blkdev_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); + const char *const mode_name = blkdev_skip_space(buf); + const char *const endp = blkdev_find_space(mode_name); + const ptrdiff_t name_len = endp - mode_name; /* always >= 0 */ + enum ledtrig_blkdev_mode mode; + + if (name_len == 0) { + pr_info("blkdev LED: empty mode\n"); + return -EINVAL; + } + + for (mode = LEDTRIG_BLKDEV_MODE_RO; + mode <= LEDTRIG_BLKDEV_MODE_RW; ++mode) { + + if (blkdev_streq(blkdev_modes[mode].name, + mode_name, name_len)) { + WRITE_ONCE(led->mode, mode); + return count; + } + } + + pr_info("blkdev LED: invalid mode (%.*s)\n", (int)name_len, mode_name); + return -EINVAL; +} + +static struct device_attribute ledtrig_blkdev_attr_mode = + __ATTR(mode, 0644, blkdev_mode_show, blkdev_mode_store); From patchwork Thu Aug 19 02:50:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=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 B4923C432BE for ; Thu, 19 Aug 2021 02:51:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F0E360F35 for ; Thu, 19 Aug 2021 02:51:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236657AbhHSCwZ (ORCPT ); Wed, 18 Aug 2021 22:52:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236283AbhHSCwB (ORCPT ); Wed, 18 Aug 2021 22:52:01 -0400 Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A850C0612A5; Wed, 18 Aug 2021 19:51:16 -0700 (PDT) Received: by mail-oo1-xc2a.google.com with SMTP id n1-20020a4ac7010000b0290262f3c22a63so1371218ooq.9; Wed, 18 Aug 2021 19:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Q2wKLNEH0ZbYjrDUELnu5nn9p/lz6FhQakpvCaCv3rE=; b=YWxti5zs+mKQ5MU1obAIyR/98ONUoXFb+Wu0HCWdHerS8lTXAHy83b6/AdOPe/qKKW 253R2Orr/ORDqIMkVoNGSo023X2JICmGWHjD+meUuacBXGyoYjbya5EMrv31m3p4KL2j jGXMXABSLs9jMMgCD7R4mTwFEUuEyzK31lCmiHTH40x1/l7itPAqNSrXI80604fT2uHt 70QU2riCrN2O01Y6JJ944OJWBk5wzYF30KOCtNeTXcfawn78EfgT9Ek68FowpLt6VDQz FJAZR4uX8KaeUMg0pYrBX1b1haTpwGH4jFfRm++dEaGAU+HAGbBoQjeHGtL+MzxQb5yx bs2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Q2wKLNEH0ZbYjrDUELnu5nn9p/lz6FhQakpvCaCv3rE=; b=IIDE38or8I5oMh3lcyZF2plc6Jn54bRbiVJKVgfcuVetB0FZKATaG3u9LZA02egHjj tjZ6s4owjJGEVfjzvQ6hfk4HOw4dLEkgilcyJeZHbft+KX+IVzmuoOXUnq7gQuerJPh7 CUyvZlq+vZ6qBJudgQI0zk/a+8Evh2W8lOKzSytOESzCgTMBNtr5tZyUB87CEp5+X8DJ AnrXfMxdTVzwyTdfQCZ/hhU0pX2KtZOOh7UHOstkFYFTQYpwvvywv8CGATKOdNpcrRIS tJEfAiFNTgq5+lORz6//+Tw2jX4wtSKNUpirh1ctgTX7r55bNE5tcyqm0qH4r6xAkVF+ 1UqA== X-Gm-Message-State: AOAM530xPp4+yVN2HuTdG/yjvqKToZYy51ecSqGc40ghQd0hcm+ZVu8N mw0+FE2dUAa1aF/BFKycwMQ/VvMgJfTNhj5O X-Google-Smtp-Source: ABdhPJwemmZ3CuBWp9AqP4vNAAw1NnZ2hQjX2k4dKeVfqVDO91v9PVNXgDBvFWRrKAYgV5LkShw8gw== X-Received: by 2002:a4a:1e46:: with SMTP id 67mr9370484ooq.38.1629341475424; Wed, 18 Aug 2021 19:51:15 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:15 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 15/18] ledtrig-blkdev: Add function to associate blkdev trigger with LED Date: Wed, 18 Aug 2021 21:50:50 -0500 Message-Id: <20210819025053.222710-16-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-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 Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 88e2a11af1a9..b331e3f24b04 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -658,3 +658,49 @@ static ssize_t blkdev_mode_store(struct device *const dev, static struct device_attribute ledtrig_blkdev_attr_mode = __ATTR(mode, 0644, blkdev_mode_show, blkdev_mode_store); + + +/* + * + * Associate an LED with the blkdev trigger + * + */ + +static int blkdev_activate(struct led_classdev *const led_dev) +{ + struct ledtrig_blkdev_led *led; + int ret; + + led = kmalloc(sizeof(*led), GFP_KERNEL); + if (led == NULL) { + ret = -ENOMEM; + goto exit_return; + } + + 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 = blkdev_mkdir("block_devices", &led_dev->dev->kobj); + if (IS_ERR(led->dir)) { + ret = PTR_ERR(led->dir); + 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_return: + return ret; +} From patchwork Thu Aug 19 02:50:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500011 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 1BDFBC4338F for ; Thu, 19 Aug 2021 02:51:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0AB47610FB for ; Thu, 19 Aug 2021 02:51:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236651AbhHSCwY (ORCPT ); Wed, 18 Aug 2021 22:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51470 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236290AbhHSCwC (ORCPT ); Wed, 18 Aug 2021 22:52:02 -0400 Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C0F5C0612A6; Wed, 18 Aug 2021 19:51:17 -0700 (PDT) Received: by mail-oo1-xc29.google.com with SMTP id h7-20020a4ab4470000b0290263c143bcb2so1381839ooo.7; Wed, 18 Aug 2021 19:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NFCrLsUf9iuGl/q7hZ+9DQ2aeBND1LI3Kn0Axyc++as=; b=OYfl89r0BeFvZj9WgsBh4ULLcCMgIlMtVpPcn7MgL8jU9BnXFYrl9ewYrBaoCHYYcK jH4ZzAZ+JiBJ+j1YlY/SrDh379Vb+tK8lNJOEyIihErgf015nK5Ek9uYy7Bkd1YLv3wd eFov81p24ptv31Eaa0wnHqdaJcDkebr8FpntNtJhHCzeywdtAlaxwwYBk/ZGmKeRRss4 H+ai5iRW8wXt6wGuX1B+hZi2hLyUvkLAVM2Tj8EfZXzgazZuGz2tCfGOq/YHjAFsotJN F1rltQ4NaDL+6gCjkDwTq5ztKzRVp52j9oNS0GO06Qsqw+LjET5cvfYxPyY8wqOB3+Wj XeXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NFCrLsUf9iuGl/q7hZ+9DQ2aeBND1LI3Kn0Axyc++as=; b=tnvPKmDXPGbEJ8KqIEgH7aeLIjxfqKniRRzOuoIKmuMrKeQKR/Cekk225/HBQV3XCc widGBxYbR3FHlFJkFBmADE1AwoRs1KBxeZDSZiqOWkgNjis9HuStUHQEA4vxV2mPyfGD ViSUtw4Ryn/aEaXXVAl6YiYocXyBTxQ79YfNX8fbLTZazNmhxxQGgkZNiqIMR+iOELd8 uoK0FcOWUfgLAF2z621XYrs1VXegRKT/O1WBtILJizr4EGWX/80P6m2FhNJXiH35scSK KsRndg4S91+rSIQ1BzsbhMIvaivRk6jkKpcW7AjJF3lFkWpv+yVqGZmN3vT8oy5fcSZB E/2Q== X-Gm-Message-State: AOAM5315GrAlhuwHWa8/U7ZMHMYLLcCG5nJgL/0Q1ChrUK3EtLudbS5P b25Yvcrgld/4JTZMDL4ArwJ7dE70aW87O7rP X-Google-Smtp-Source: ABdhPJyEYp+hyhDJ9HYn/93RsENi587CsY41MMGvUBgUSjy/qm7Llwt7TEvTVXNRKTNH1OLwvjBhBg== X-Received: by 2002:a4a:3f01:: with SMTP id e1mr9521891ooa.86.1629341476315; Wed, 18 Aug 2021 19:51:16 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:15 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 16/18] ledtrig-blkdev: Add function to disassociate an LED from the trigger Date: Wed, 18 Aug 2021 21:50:51 -0500 Message-Id: <20210819025053.222710-17-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Remove all device associations with this LED Remove /sys/class/leds//block_devices directory Free per-LED data structure 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 b331e3f24b04..01573c1ad855 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -704,3 +704,28 @@ static int blkdev_activate(struct led_classdev *const led_dev) exit_return: return ret; } + + +/* + * + * 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_del_locked(led, link, link->disk); + + hlist_del(&led->leds_node); + kobject_put(led->dir); + kfree(led); + + mutex_unlock(&ledtrig_blkdev_mutex); +} From patchwork Thu Aug 19 02:50:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ED5DC43214 for ; Thu, 19 Aug 2021 02:51:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8A45F60F35 for ; Thu, 19 Aug 2021 02:51:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236597AbhHSCwV (ORCPT ); Wed, 18 Aug 2021 22:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236292AbhHSCwC (ORCPT ); Wed, 18 Aug 2021 22:52:02 -0400 Received: from mail-ot1-x32f.google.com (mail-ot1-x32f.google.com [IPv6:2607:f8b0:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0666C0612A8; Wed, 18 Aug 2021 19:51:17 -0700 (PDT) Received: by mail-ot1-x32f.google.com with SMTP id l36-20020a0568302b24b0290517526ce5e3so6809182otv.11; Wed, 18 Aug 2021 19:51:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aRx3WSbHN2621ogL+fq9TI54goN5jX542hotfGdhgzw=; b=mkWoo3nCDSds4T6Pec/mDgTgogMejNa+jb5y5TNgUo5dQSgA9J2IozvxbsAcq8wKfV 7AeHMMvkxEQEa2TJf921T6s+7vqzAhBMwgK3eOlmXrNhDtZnG4Y2+U0wA6cC6FQhj3x2 PV8Qu0E4GcYvx60HEwcQNOeXGQb9jHrXAIQHGvSMoKYhh/oYgFmGIqjRpg7hegxzBxzI MejAfRc16AAyIVouwqzmlrngD2LwB03N/9C/nZ3Z/qatAexqxgGuA9a4T00BPDcetiSM MvUMaEGFrJtNLCI++/LgBdhQucNPoFfPAAHta0970g4FjJ/YVsKHed1lbuH28YHB1El+ zqrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aRx3WSbHN2621ogL+fq9TI54goN5jX542hotfGdhgzw=; b=htRFrgEpPzaz9h3mi5BOMSswMBOyHk6tPNXuw7b+bwTDvGukv2Xcg4uSSuymqGHtHg FslNgGR4oH8KeeCzWGwDeKOEU9rBzJLifAcoj9oukeVFu6DoSJFBcymWRwebKIyvIR6U 9d8iAeccp7AkZKSx0cySmbxmS0mYmb4HhIDQtUctIyLDVk2tAtQbivz2DjQ7p6NgblvH xVIEgW6jCIZVpjmx2X46m+RNb3rn6Vsbg34z3MTImQDJEjLvQcTjlXN2WNes6XmF1wLu xZZOucFJxxVkuwXIkuZGOO2LzvrLLkl+kUJlBbZwOcrRkxf1bUq7RXzdgbkxZuBeBHGp KhLg== X-Gm-Message-State: AOAM531eR9yzJ9nbXY/DXvuJq4IczIlcD4Mf1Fn1y3Ev6QGFGHlOqBal /vytvivbw8v1IxXVMtORQUbfNRiheDvonnbW X-Google-Smtp-Source: ABdhPJxrsxdNPMLvfHIHS78EckYX3kJNIRuhzveQuJ3F8cMkhyV6Op38Jh6v+q04PvHdzuRyP4uDbQ== X-Received: by 2002:a05:6830:31ac:: with SMTP id q12mr9836670ots.152.1629341477061; Wed, 18 Aug 2021 19:51:17 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:16 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 17/18] ledtrig-blkdev: Add initialization function Date: Wed, 18 Aug 2021 21:50:52 -0500 Message-Id: <20210819025053.222710-18-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Register the block device LED trigger Initialize interval (convert default value to jiffies) Signed-off-by: Ian Pilcher --- drivers/leds/trigger/ledtrig-blkdev.c | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/leds/trigger/ledtrig-blkdev.c b/drivers/leds/trigger/ledtrig-blkdev.c index 01573c1ad855..f152b00a4f1a 100644 --- a/drivers/leds/trigger/ledtrig-blkdev.c +++ b/drivers/leds/trigger/ledtrig-blkdev.c @@ -729,3 +729,42 @@ static void blkdev_deactivate(struct led_classdev *const led_dev) mutex_unlock(&ledtrig_blkdev_mutex); } + + +/* + * + * Initialization - register the trigger + * + */ + +static struct attribute *ledtrig_blkdev_attrs[] = { + &ledtrig_blkdev_attr_add.attr, + &ledtrig_blkdev_attr_del.attr, + &ledtrig_blkdev_attr_blink_time.attr, + &ledtrig_blkdev_attr_interval.attr, + &ledtrig_blkdev_attr_mode.attr, + 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 +}; + +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) +{ + ledtrig_blkdev_interval = msecs_to_jiffies(LEDTRIG_BLKDEV_INTERVAL); + return led_trigger_register(&ledtrig_blkdev_trigger); +} +device_initcall(blkdev_init); From patchwork Thu Aug 19 02:50:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 500012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECDBDC432BE for ; Thu, 19 Aug 2021 02:51:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB3B0610FB for ; Thu, 19 Aug 2021 02:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236555AbhHSCwU (ORCPT ); Wed, 18 Aug 2021 22:52:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236304AbhHSCwC (ORCPT ); Wed, 18 Aug 2021 22:52:02 -0400 Received: from mail-oo1-xc2c.google.com (mail-oo1-xc2c.google.com [IPv6:2607:f8b0:4864:20::c2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC177C0612A9; Wed, 18 Aug 2021 19:51:18 -0700 (PDT) Received: by mail-oo1-xc2c.google.com with SMTP id e3-20020a4ab9830000b029026ada3b6b90so1390733oop.0; Wed, 18 Aug 2021 19:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+ctrum5PuRodGtsvX5XCOy4ikb9APYy6K15rvAPhxuw=; b=ILzIQBfS2ieAWmqJdJ9cbsAvbtpfNrmW6+mzp+yOQe8ZXBA5RJgvyDuK32xdtAMmcD +cXbntu9cxNLEYwpTguKKlrTm+nONpoSFsNszNJJ6roNR40dSLUsmV3NkHjb2GTM/UxH CDxBg5zX3JV/2nwuTH9YTOWYRUnKLPqeHB8tjtIwxMIZO4ud7QNxR8uyXQM4Hf0WwLlt TQjxq24MvGA7J6SfkA5aWi0OUbHodsgCBDjOBcDbD4OvFJBiJhmowgOWOLDgL5aSyOaT r7WyTe0jvkwny1Vk/tp+vDhCI0qLsYSScTx8DvANWVALO5TOPvUCVw1ffBA9yIFnADL6 az7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+ctrum5PuRodGtsvX5XCOy4ikb9APYy6K15rvAPhxuw=; b=JN/TC0fGPc4HR9crQ/l3HGQDNBp7IskquIF6W2n8aOzUxoJoLyJXLmh2cLFFSNtIzC URkkEipMCq7VuGPF5XMYSWOm4PAjJwgNVkpZnJK6HP9lrH+uDUWotf4HxhgM87mbo/K2 BrkedLhTs3XkiHiFnWI1SmDPRlvxytlup1W4LEWQlKHFLyYIx7jrTstNbPMVf+32u5/h 0w7xfFsTUitpzD3IdvwS9iBw52ED8ZtZhF3G9if0Xoh20G95baMcPVdFvMCQjRGxrvS9 7YKeiXsmXo9/BCLGyGb8J/TEwhKgpcqpYYk0U9/uhoiYkuZOARI4wjIxgxDXlNsqsv/q xI8g== X-Gm-Message-State: AOAM532Nt6DPEo4OkEOlIngkidene3jzT2iOe67FCRCi61+09z9ExJ91 YU08/of8JV8ILBxu8JsWy7thU/4YJuqcTLgK X-Google-Smtp-Source: ABdhPJx8S06js5H4EW3aYT8LArDwry3Rs/BieIVbBdinWG2VSo7OvaTf1BEnioLv+62oWxdySEW9gw== X-Received: by 2002:a4a:9464:: with SMTP id j33mr9415660ooi.5.1629341477751; Wed, 18 Aug 2021 19:51:17 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id w15sm156792oiw.19.2021.08.18.19.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 19:51:17 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, kabel@kernel.org, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v3 18/18] ledtrig-blkdev: Add config option to enable the trigger Date: Wed, 18 Aug 2021 21:50:53 -0500 Message-Id: <20210819025053.222710-19-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210819025053.222710-1-arequipeno@gmail.com> References: <20210819025053.222710-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Signed-off-by: Ian Pilcher --- drivers/leds/trigger/Kconfig | 9 +++++++++ drivers/leds/trigger/Makefile | 1 + 2 files changed, 10 insertions(+) diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig index b77a01bd27f4..f15d38b3a632 100644 --- a/drivers/leds/trigger/Kconfig +++ b/drivers/leds/trigger/Kconfig @@ -153,4 +153,13 @@ config LEDS_TRIGGER_TTY When build as a module this driver will be called ledtrig-tty. +config LEDS_TRIGGER_BLKDEV + bool "LED Trigger for block devices" + depends on BLOCK + help + The blkdev LED trigger allows LEDs to be controlled by block device + activity (reads and writes). + + See Documentation/leds/ledtrig-blkdev.rst. + endif # LEDS_TRIGGERS diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile index 25c4db97cdd4..d53bab5d93f1 100644 --- a/drivers/leds/trigger/Makefile +++ b/drivers/leds/trigger/Makefile @@ -16,3 +16,4 @@ 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