From patchwork Mon Aug 9 03:32:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494110 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 5A527C4338F for ; Mon, 9 Aug 2021 03:32:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BD2061004 for ; Mon, 9 Aug 2021 03:32:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232791AbhHIDdJ (ORCPT ); Sun, 8 Aug 2021 23:33:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232692AbhHIDdJ (ORCPT ); Sun, 8 Aug 2021 23:33:09 -0400 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C57C061760; Sun, 8 Aug 2021 20:32:49 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id o20so21693795oiw.12; Sun, 08 Aug 2021 20:32:49 -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=GWuq4x5Ma8/N/51ftwpP4AD0F7izQuOl1Oao0AbJWv0=; b=Xy+ucOGn3nozc0ifyyuOMg6MPM+itH8mqmavs1lMyi51OEDbmG0AghOoXnl5XzM29W 40RbBWmegX48ZF43bVyoFYwUtIJGpDqAgND8sumjaxEz98Wh4v03EyaiAc37h/WwvItX /nOrmZ0wppNuBrsMBCPDkisMiuHl1t2hXTwq6v1edBFm4GBLOralBQqDApGgZQ1U5LoZ iSPon0bEpKsM7rB3O9Vi0rTamsTI+vqDvoryLHS7dGraT6SZo+U75TH7H+H1XUiU9odZ A//qDX5T47go8g5YOCNQuppxZzku2fijjRUQls+X7Xe5XQt6jpJbjNSYLxfrb9Hvw161 tH4A== 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=GWuq4x5Ma8/N/51ftwpP4AD0F7izQuOl1Oao0AbJWv0=; b=Fs4UsoSQmvgKaQuto/n5AATUj1q8O0qwx8ztnMXqdXAO5nehXcz/kC9d/YZb/PnT8i 1/UzWpdZaYxiDqkpF4VuMJ+df2Uh+mhlNxjd/nJvhn4UEHsfPxM6NMEVS8G4FrmxJgh/ iKrGaNLii0EAlbHONH6lkNFrEghnHJp39raYqgbL+xjR0PdochPulK9RGqVNQ6/olSet Zm4Y4aVy0xiJTquWGOtmuNptAueRkR63d+mwmoWe5cy4iJVJ/lO37VMIWC/Xh56yE4SD 0rPRPcwiHXo8gSb06S8IuNWwiZTDgy04C5QEeU9YoLytnoxK9my81RCWzojR+A+va8uY zSRA== X-Gm-Message-State: AOAM532c8foCQtC98EDSOT1RxxF6CzaXuakO0p/VGtXWNHTTGytqG710 DjdDDAMC1sM+3fqP/xsRL6tWJLQnPQDzRf0S X-Google-Smtp-Source: ABdhPJyZQsNuoGiQWsOX7Js8N8w1bmGJg7pP+RdemzXG1FZZb9vBYq5SAKwfjdvBIj9qtz6EGr7cdg== X-Received: by 2002:aca:90c:: with SMTP id 12mr5402436oij.37.1628479968774; Sun, 08 Aug 2021 20:32:48 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:48 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 01/10] docs: Add block device LED trigger documentation Date: Sun, 8 Aug 2021 22:32:08 -0500 Message-Id: <20210809033217.1113444-2-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-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_on * /sys/class/leds//blink_off * /sys/class/leds//block_devices Add /sys/block//led to Documentation/ABI/testing/sysfs-block Add usage overview in Documentation/block/blk-ledtrig.rst Signed-off-by: Ian Pilcher --- Documentation/ABI/testing/sysfs-block | 16 ++++ .../testing/sysfs-class-led-trigger-blkdev | 28 +++++++ Documentation/block/blk-ledtrig.rst | 79 +++++++++++++++++++ Documentation/block/index.rst | 1 + 4 files changed, 124 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-blkdev create mode 100644 Documentation/block/blk-ledtrig.rst diff --git a/Documentation/ABI/testing/sysfs-block b/Documentation/ABI/testing/sysfs-block index e34cdeeeb9d4..36253fff25b2 100644 --- a/Documentation/ABI/testing/sysfs-block +++ b/Documentation/ABI/testing/sysfs-block @@ -316,3 +316,19 @@ 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//led +Date: August 2021 +Contact: Ian Pilcher +Description: + Set the LED associated with this block device (or show available + LEDs and the currently selected LED, if any). + + Reading the attribute will display the available LEDs (LEDs that + are associated with the blkdev LED trigger). The currently + selected LED is enclosed in square brackets. To clear the + device's LED association write 'none' (without the quotes) or + an empty string/line to the attribute. + + See Documentation/ABI/testing/sysfs-class-led-trigger-blkdev and + Documentation/block/blk-ledtrig.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..1139a099a3cc --- /dev/null +++ b/Documentation/ABI/testing/sysfs-class-led-trigger-blkdev @@ -0,0 +1,28 @@ +What: /sys/class/leds//blink_on +Date: August 2021 +Contact: Ian Pilcher +Description: + Time (in milliseconds) that the LED will be on during a single + "blink". + +What: /sys/class/leds//blink_off +Date: August 2021 +Contact: Ian Pilcher +Description: + Time (in milliseconds) that the LED will be off during a single + "blink". Effectively the amount of time that the LED will be + off before the next blink, when the associated block device(s) + are continuously active. + +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. + + Once an LED has been associated with the blkdev trigger, a block + device can be associated with that LED by writing the LED name + to the device's /sys/[class/]block//led attribute. (See + Documentation/ABI/testing/sysfs-block and + Documentation/block/blk-ledtrig.rst.) diff --git a/Documentation/block/blk-ledtrig.rst b/Documentation/block/blk-ledtrig.rst new file mode 100644 index 000000000000..194fc6a51019 --- /dev/null +++ b/Documentation/block/blk-ledtrig.rst @@ -0,0 +1,79 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================================= +Block Device (blkdev) LED Trigger +================================= + +Available when ``CONFIG_BLK_LED_TRIGGERS=y``. + +See also: + +* ``Documentation/ABI/testing/sysfs-class-led-trigger-blkdev`` +* ``Documentation/ABI/testing/sysfs-block`` (``/sys/block//led``) + +.. 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 the ``blink_on`` and ``blink_off`` attributes have been added to the +LED, along with the ``block_devices`` subdirectory. + +The LED is now available for association with block devices:: + + # cat /sys/block/sda/led + [none] + +Associate the LED with the block device:: + + # echo > /sys/block/sda/led + + # cat /sys/block/sda/led + none [] + +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 > /sys/block/sdb/led + + # cat /sys/block/sdb/led + none [] + +Note that both block devices are linked from the LED's ``block_devices`` +subdirectory:: + + # ls /sys/class/leds//block_devices + sda sdb + +Other notes: + +* Many 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 + * SD cards + * loopback block devices (``/dev/loop*``) + +* NVMe SSDs and most virtual block devices can be associated with LEDs, but + they will produce little or no LED activity. + +* Multiple LEDs can be associated with the ``blkdev`` trigger; different block + devices can be associated with different LEDs. + +* This trigger causes associated LED(s) to blink (per the LED's ``blink_on`` + and ``blink_off`` attributes) when a request is sent to an associated + block device's low-level driver. It does not track the duration (or + result) of requests further. Thus, it provides an approximate visual + indication of device activity, not an exact measurement. diff --git a/Documentation/block/index.rst b/Documentation/block/index.rst index 86dcf7159f99..cbb11a42f825 100644 --- a/Documentation/block/index.rst +++ b/Documentation/block/index.rst @@ -25,3 +25,4 @@ Block stat switching-sched writeback_cache_control + blk-ledtrig From patchwork Mon Aug 9 03:32:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494603 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 8729DC43216 for ; Mon, 9 Aug 2021 03:32:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 57FE06101E for ; Mon, 9 Aug 2021 03:32:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232692AbhHIDdL (ORCPT ); Sun, 8 Aug 2021 23:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232846AbhHIDdK (ORCPT ); Sun, 8 Aug 2021 23:33:10 -0400 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FBC6C061757; Sun, 8 Aug 2021 20:32:50 -0700 (PDT) Received: by mail-oi1-x22c.google.com with SMTP id bj40so2130284oib.6; Sun, 08 Aug 2021 20:32:50 -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=wknaelJleWmbQStzTD7XQOjUKLb9/tYz0iCEj9R3vek=; b=CnDQZSZGJnUZTRodt0mNNiPtMnyiz7zKnBnkyAZKnTbqnyMjZToT2XlH/JgVEZ9LLy N0PZGawTN0hZb8cJyOF0wf7Fth2dRyyeSXdiSihl1OQjAuH0Kn1wSvAh2hoRufsjhzKq b9FhX4t6uxCt2BLKaXtbj1xM5N2begvkEUjpDrm5on9yGtSXT6HoNjrmuAaGvWlwmQMA HLGfn/+AUR4CgkejBol9AUmrvW9kdDRzVbOOUHUa5+tqJgibWigTrbntUnTIsT5BA3Fs 6a5dXh6NpWYvxxWexLN2pP9oOwQZmAqwjNtvA5W8NoYjIoYXMssVT49mRzOvmIWRH9Ba MHrQ== 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=wknaelJleWmbQStzTD7XQOjUKLb9/tYz0iCEj9R3vek=; b=Dn9U6BJSTnVt6MdHesyKamlMA2SlAxQsdpGjKRXQlGGzxdNO8UH9uJkK8JSMHqTyiv 6C9OJkQUQl0qvi91rSLUFelTmK2DcD73U5zyFG5Z6GRnvG20qZ8g4iBTkvWtA6mY1Fqt b8UH7mFIir8HXKEpOIqy5N9049yNiZgB3niVtjpAQuzNxQa42WRs8h0gByobv0BJUg6b qLLY1zIISrNgPJws0exhpZGOk66gQNAJAzZlrsY+h1FsFg5myGnXB4BqF3tqqfaFT/js Kb70cp8L6UJFjLEp8ps9H/Z3uDHlshurZIS6zgs36MYNsjqUVdaWf7lvCanpcIsY+5bP F4Gg== X-Gm-Message-State: AOAM533Vb86vJMURfzSIZ5pPKav024VqzFQd+3Ul6M17ZE3w3bf7hs5A pKbzLThuyuweuUZQFgS90vMDVq7iBtqd1WQw X-Google-Smtp-Source: ABdhPJwybw7WflJ/i/e8jE/wSXFutGTw2x27POz0yzW2/k47dS7U5tD6xg8yUTmcQXBw0wsAAMPs1w== X-Received: by 2002:aca:2809:: with SMTP id 9mr21937984oix.3.1628479969470; Sun, 08 Aug 2021 20:32:49 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:49 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 02/10] block: Add file (blk-ledtrig.c) for block device LED trigger implementation Date: Sun, 8 Aug 2021 22:32:09 -0500 Message-Id: <20210809033217.1113444-3-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Define data structure for all associated LEDs Add list of associated LEDs and list search helper Add trigger mutex - must be held when accessing trigger/LED or device/LED associations Signed-off-by: Ian Pilcher --- block/blk-ledtrig.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 block/blk-ledtrig.c diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c new file mode 100644 index 000000000000..c5ad57ed9c3b --- /dev/null +++ b/block/blk-ledtrig.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Block device LED triggers + * + * Copyright 2021 Ian Pilcher + */ + +#include +#include + +/* + * + * Trigger mutex and LED list + * + */ + +// Must hold when doing anything with LED/trigger/block device +// associations +static DEFINE_MUTEX(blk_ledtrig_mutex); + +static LIST_HEAD(blk_ledtrig_leds); + +// Every LED associated with the blkdev trigger gets one of these +struct blk_ledtrig_led { + struct kobject *dir; // block_devices subdirectory + struct led_classdev *led; + unsigned int blink_on; + unsigned int blink_off; + struct list_head leds_list_node; + struct list_head dev_list; +}; + +// Caller must hold blk_ledtrig_mutex +static struct blk_ledtrig_led *blk_ledtrig_find(const char *const led_name, + const size_t name_len) +{ + struct blk_ledtrig_led *bd_led; + + list_for_each_entry(bd_led, &blk_ledtrig_leds, leds_list_node) { + if (strlen(bd_led->led->name) != name_len) + continue; + if (memcmp(bd_led->led->name, led_name, name_len) == 0) + return bd_led; + } + + return NULL; +} From patchwork Mon Aug 9 03:32:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494109 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 4F595C4320A for ; Mon, 9 Aug 2021 03:32:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3631F6101C for ; Mon, 9 Aug 2021 03:32:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232867AbhHIDdL (ORCPT ); Sun, 8 Aug 2021 23:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232850AbhHIDdK (ORCPT ); Sun, 8 Aug 2021 23:33:10 -0400 Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD508C061760; Sun, 8 Aug 2021 20:32:50 -0700 (PDT) Received: by mail-oi1-x22d.google.com with SMTP id bj40so2130335oib.6; Sun, 08 Aug 2021 20:32:50 -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=IcIaKivSr+2Yd3P4FVIhtXkcUXa5XZoFFn0fjLKQOWo=; b=mqYz/bI9Gx7XG281BcCFUWqFGyaKKaifMLfJnojAfArFfBGdZK/LWa0ej0sC+5XsCt QRd0bMUIdHh82fLgLyrJGvq1qammxusly2Hj3AuwRab5LHZD8BP5bLRMj2ER59Yk65bv YAhU3L9Gu2gkyAIIe1zGfNflWm5yYDdC6k3ugjap/rpnhOtGpOsGEMl4jO7Jf5+Ykr4T gUM1jzBI5FJGDv22aap5yHZgPRaTdh5Mp7phwaf7IpJUrwVGt6ocAWJGfEshYXqjmnhX stG5Yqni3t30HklKMzuoibv8FLdtYO+r8K8sgJF3Vw+2Qc3CYeKz55MwZBr1YdDR2mWW DBPQ== 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=IcIaKivSr+2Yd3P4FVIhtXkcUXa5XZoFFn0fjLKQOWo=; b=LqZ+BbIhm/UdYlYD66dsh4SNmDAvmJgQ1+aRahi3kC60nrzJFL+zGEGije2MWrt5E2 KAI+WvysQihpwGWQwScxykvusQlvAsJNRsMzfwqpN4M6xoVxg3/H4xkkCiIKyDwbQpJ3 +AQgIjbOdKaZ99Zq4CKeA2uKcywB4qRSZZcA8UXpjEYuK8Jd2wDVuOwb2xBrcb/PpKFd AFBa0Uv0wBUUFhO/Uc/XysXx1mUcgDKbVrg0e1izRtxttvt1wpN4t6txrvJABBWLm8rb 6Bkc2IwsXiXoSUndf/ry10xVhwMUnStlZgmw0rczRTuuzEnVxyxibPGfsq5jPqEuORmb k7ow== X-Gm-Message-State: AOAM530HYr/sXKmX/p7izKdu/tCHWW9cFCuAvSk1WzUlWQtIZfNgk0gk 3STnBYPuFksROumqab85l+bXZm/HS9OpG/FF X-Google-Smtp-Source: ABdhPJxaHA7mhECQguJGrUQ5hRrn555INgeZXFbjZGf6xE9vczxSGfhtcmcRacSOqsG7nNmVs6vQrQ== X-Received: by 2002:aca:f306:: with SMTP id r6mr13953554oih.165.1628479970169; Sun, 08 Aug 2021 20:32:50 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:49 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 03/10] block: Add block device LED trigger fields to gendisk structure Date: Sun, 8 Aug 2021 22:32:10 -0500 Message-Id: <20210809033217.1113444-4-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add header (blk-ledtrig.h) for LED trigger-related declarations Add (inline) function to ensure trigger pointer is initialized (to NULL) and call it from __device_add_disk() Signed-off-by: Ian Pilcher --- block/blk-ledtrig.h | 25 +++++++++++++++++++++++++ block/genhd.c | 2 ++ include/linux/genhd.h | 4 ++++ 3 files changed, 31 insertions(+) create mode 100644 block/blk-ledtrig.h diff --git a/block/blk-ledtrig.h b/block/blk-ledtrig.h new file mode 100644 index 000000000000..95a79d2fe447 --- /dev/null +++ b/block/blk-ledtrig.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +/* + * Block device LED triggers + * + * Copyright 2021 Ian Pilcher + */ + +#ifndef _BLOCK_BLK_LEDTRIG_H +#define _BLOCK_BLK_LEDTRIG_H + +#ifdef CONFIG_BLK_LED_TRIGGERS + +static inline void blk_ledtrig_disk_init(struct gendisk *const disk) +{ + RCU_INIT_POINTER(disk->led, NULL); +} + +#else // CONFIG_BLK_LED_TRIGGERS + +static inline void blk_ledtrig_disk_init(const struct gendisk *disk) {} + +#endif // CONFIG_BLK_LED_TRIGGERS + +#endif // _BLOCK_BLK_LEDTRIG_H diff --git a/block/genhd.c b/block/genhd.c index 298ee78c1bda..b168172e664b 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -26,6 +26,7 @@ #include #include "blk.h" +#include "blk-ledtrig.h" static struct kobject *block_depr; @@ -539,6 +540,7 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, disk_add_events(disk); blk_integrity_add(disk); + blk_ledtrig_disk_init(disk); } void device_add_disk(struct device *parent, struct gendisk *disk, diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 13b34177cc85..efcb1ca62f17 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -168,6 +168,10 @@ struct gendisk { #endif /* CONFIG_BLK_DEV_INTEGRITY */ #if IS_ENABLED(CONFIG_CDROM) struct cdrom_device_info *cdi; +#endif +#ifdef CONFIG_BLK_LED_TRIGGERS + struct blk_ledtrig_led __rcu *led; + struct list_head led_dev_list_node; #endif int node_id; struct badblocks *bb; From patchwork Mon Aug 9 03:32:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494108 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 D9DACC4320A for ; Mon, 9 Aug 2021 03:32:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBA0761019 for ; Mon, 9 Aug 2021 03:32:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232894AbhHIDdO (ORCPT ); Sun, 8 Aug 2021 23:33:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232861AbhHIDdL (ORCPT ); Sun, 8 Aug 2021 23:33:11 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6890FC061757; Sun, 8 Aug 2021 20:32:51 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id w6so21734420oiv.11; Sun, 08 Aug 2021 20:32:51 -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=OX+fGhBFKu5FC8W1LaNx83ZClAd+GqNacmx+NCQZpPI=; b=WCC40AOnAGPJCaly+0XFVIQEEX64WmZgZhhQF5zRUV4r4HOd8anG3DBtybTrc7soJe tGoCQUJTuST/3+LB8ERWMX41+GufyjY5NIgQAhP/BZqvyzELNQ098BPqituW4QSQq/FH ba+s+ygjJ/OfjWLGzE86crAdG56hD6CDqqFMRYOLLnVKmQWSTJbRJx9OWaZFv0QYNTQd qTssijziug4kor5ryPvtorh5aLHZnjZCON27lHp7zHcHhxsyDYsOPjsXoMD8eDQGoWmU GhmFz3/wN1XECvJTvjkp+D7xG0614KsXnhfui935r7yY3ksjGn2+I98ZG+Pf11Dg9qLu n1jQ== 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=OX+fGhBFKu5FC8W1LaNx83ZClAd+GqNacmx+NCQZpPI=; b=LrW+cH5Eeopi0Cx75GDz7JRyWltCGl2F263kA/CmmF0CdQg3Z/rYXXycXSiooiRcJl 2SgAJTH2C8mT6HZhr/jeQ/+kCQ6FerFFqq4/MhPCSVymf2OcY48TnidNzMTZaKF/uqob 5NfxlE12BMTIK3kE75ukqgs6f8EOE2FpOq+VSYfUWIQPfAqvu2zFjxboYkZGKILeKqSc G3Zg6NtMsXY38mqizOvEp4CbLEe7hCEvDMT5+prtsV5cglomcY7QdHswrXAKTCiqP89f QiRQek+Y61kYGJG2jvP5n4tcENJAhrNWwCCvtIzVS9DRYC1H39MgHhjTQyi5zM8HZbXo RyGQ== X-Gm-Message-State: AOAM530fW/AlCX3nKVy2S6NjL1gLulgRRN6PirlT1Wu6eacX+Xw79lIR NcbYrEc08yp9Qc+jLube5lCPyiosDjL6SPew X-Google-Smtp-Source: ABdhPJxsUg7gwG7M3FvrqmDHa42XuVGQE62q8ZQUKn9I3VhNuZ7da2cDoNa5fykXMIwI1js9pyQSsQ== X-Received: by 2002:aca:b757:: with SMTP id h84mr4870760oif.77.1628479970869; Sun, 08 Aug 2021 20:32:50 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:50 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 04/10] block: Add functions to set & clear block device LEDs Date: Sun, 8 Aug 2021 22:32:11 -0500 Message-Id: <20210809033217.1113444-5-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Create a symlink from /sys/class/leds//block_devices to each block device that is associated with that LED Ensure device LED is cleared when device is removed Signed-off-by: Ian Pilcher --- block/blk-ledtrig.c | 93 +++++++++++++++++++++++++++++++++++++++++++++ block/blk-ledtrig.h | 3 ++ block/genhd.c | 1 + 3 files changed, 97 insertions(+) diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c index c5ad57ed9c3b..280fa9edc2dd 100644 --- a/block/blk-ledtrig.c +++ b/block/blk-ledtrig.c @@ -6,9 +6,13 @@ * Copyright 2021 Ian Pilcher */ +#include #include #include +#include "blk-ledtrig.h" + + /* * * Trigger mutex and LED list @@ -46,3 +50,92 @@ static struct blk_ledtrig_led *blk_ledtrig_find(const char *const led_name, return NULL; } + + +/* + * + * Clear a block device's LED + * + */ + +// Also called from blk_ledtrig_dev_set() +static void blk_ledtrig_dev_cleanup(struct gendisk *const disk, + struct blk_ledtrig_led *const old_led) +{ + sysfs_remove_link(old_led->dir, disk->disk_name); + list_del(&disk->led_dev_list_node); +} + +// Also called from blk_ledtrig_deactivate() +static void blk_ledtrig_dev_clear_locked(struct gendisk *const disk, + struct blk_ledtrig_led *const old_led) +{ + RCU_INIT_POINTER(disk->led, NULL); + if (old_led != NULL) + blk_ledtrig_dev_cleanup(disk, old_led); +} + +// Also called from genhd.c:del_gendisk() +void blk_ledtrig_dev_clear(struct gendisk *const disk) +{ + struct blk_ledtrig_led *old_led; + + mutex_lock(&blk_ledtrig_mutex); + old_led = rcu_dereference_protected(disk->led, + lockdep_is_held(&blk_ledtrig_mutex)); + blk_ledtrig_dev_clear_locked(disk, old_led); + mutex_unlock(&blk_ledtrig_mutex); +} + + +/* + * + * Set a block device's LED + * + */ + +static int blk_ledtrig_dev_set(struct gendisk *const disk, + const char *const led_name, + const size_t name_len) +{ + struct blk_ledtrig_led *new_led, *old_led; + int ret; + + ret = mutex_lock_interruptible(&blk_ledtrig_mutex); + if (ret != 0) + goto led_set_exit_return; + + new_led = blk_ledtrig_find(led_name, name_len); + if (new_led == NULL) { + pr_info("no LED named %.*s associated with blkdev trigger\n", + (int)name_len, led_name); + ret = -ENODEV; + goto led_set_exit_unlock; + } + + old_led = rcu_dereference_protected(disk->led, + lockdep_is_held(&blk_ledtrig_mutex)); + + if (old_led == new_led) { + ret = 0; + goto led_set_exit_unlock; + } + + ret = sysfs_create_link(new_led->dir, &disk_to_dev(disk)->kobj, + disk->disk_name); + if (ret != 0) + goto led_set_exit_unlock; + + if (old_led != NULL) + blk_ledtrig_dev_cleanup(disk, old_led); + + rcu_assign_pointer(disk->led, new_led); + list_add(&disk->led_dev_list_node, &new_led->dev_list); + + ret = 0; + +led_set_exit_unlock: + mutex_unlock(&blk_ledtrig_mutex); +led_set_exit_return: + return ret; +} diff --git a/block/blk-ledtrig.h b/block/blk-ledtrig.h index 95a79d2fe447..66a1302a4174 100644 --- a/block/blk-ledtrig.h +++ b/block/blk-ledtrig.h @@ -16,9 +16,12 @@ static inline void blk_ledtrig_disk_init(struct gendisk *const disk) RCU_INIT_POINTER(disk->led, NULL); } +void blk_ledtrig_dev_clear(struct gendisk *const disk); + #else // CONFIG_BLK_LED_TRIGGERS static inline void blk_ledtrig_disk_init(const struct gendisk *disk) {} +static inline void blk_ledtrig_dev_clear(const struct gendisk *disk) {} #endif // CONFIG_BLK_LED_TRIGGERS diff --git a/block/genhd.c b/block/genhd.c index b168172e664b..9fa734aeab0f 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -583,6 +583,7 @@ void del_gendisk(struct gendisk *disk) if (WARN_ON_ONCE(!disk->queue)) return; + blk_ledtrig_dev_clear(disk); blk_integrity_del(disk); disk_del_events(disk); From patchwork Mon Aug 9 03:32:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494601 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 DC665C432BE for ; Mon, 9 Aug 2021 03:33:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C396361004 for ; Mon, 9 Aug 2021 03:33:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232963AbhHIDdV (ORCPT ); Sun, 8 Aug 2021 23:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232747AbhHIDdO (ORCPT ); Sun, 8 Aug 2021 23:33:14 -0400 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A98DC061760; Sun, 8 Aug 2021 20:32:53 -0700 (PDT) Received: by mail-oi1-x232.google.com with SMTP id x15so21690669oic.9; Sun, 08 Aug 2021 20:32:53 -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=zh5iqmi8rXG0JubuHldvmAB6oQlwzvKCz/SepLGCqCY=; b=MWP4T7dvrNbWzrDu4gDcDA+OElHp70VV+FLDPlBN0W02PhOVW5mmEpRlTuysz8buwR GwrUXd8+M+VNjs8sZW7xetR/Byrvxc5UCulyyE6NwJCVBvK+91RmqiWkGIBdgLjCEBow O/hk/HB6JfJDrwaWEDiK6wfOOF5T3kBD7ZMGt6oiq2BZMK/yhqgYOZiV3CO3J+LZX2S1 dAH03iYeYj/9K3pLn2u2Gw4p8EScWcbuueuy5XRZiXa5/Lv9dBWBIZghBnYoJSZ85Xyv /LNVdz9hqiIOHjThlrYrmPwl4ic/abelIkUjgJvVqNkOhQ6hqhphGEuq8TPj0IkpyTRZ wInw== 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=zh5iqmi8rXG0JubuHldvmAB6oQlwzvKCz/SepLGCqCY=; b=TUAYlVxf6I38Dd60EoWRfaW9Hrfmm2dzEEhmjbq/2n99nnyZq8LlNHMYVLPBbq5ACe B0yX1UGsK1uwYtJDeaQRGrT9+/ISi8Av+PMIhh6tXy/1ea1BXE5QzWvPw8SfDk4fnX3P qMlLP2/EqpT8cL9M96Qqh8e/CGlFbEF1pdoN0+XYt/0T9/T7Nn7tRl7uqSU8of1wh0Wu yRnyRBtY52+vHeKj9AMeMJ8xIpB8M1jbE68Tc2RWW1dEE+0j+wPkg0qDusO1Tm7Rwutg W7PdEN5TJ6f3sGdGjBmgLrcCPtgJd52pWIRpjojtEA40nvzE+9z3Ny3Bz7OPn0w+BcYD mgCA== X-Gm-Message-State: AOAM533yfegthzDO19v47CEod5ruyYE1YWA48cI1JZBJfNZ6wHfGTk+2 k+sqZb/FxphlpGDJL51S2wWQRDg26Tgi49Nu X-Google-Smtp-Source: ABdhPJzcy2hUnuR1AeGcvvqNHAkGkL2djYqnSo5AfgjJ1obRFD6jvrsxDLVAycTewHNHcuRTchzN2g== X-Received: by 2002:a05:6808:1d7:: with SMTP id x23mr8317031oic.126.1628479971524; Sun, 08 Aug 2021 20:32:51 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:51 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 05/10] block: Add block device sysfs attribute to set/clear/show LED Date: Sun, 8 Aug 2021 22:32:12 -0500 Message-Id: <20210809033217.1113444-6-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add show & store functions in blk-ledtrig.c (attributes defined in genhd.c) Show function shows all available LEDs (LEDs associated with blkdev trigger); currently associated LED is shown in square brackets ([]) Store function accepts either all whitespace or "none" to clear LED Signed-off-by: Ian Pilcher --- block/blk-ledtrig.c | 109 ++++++++++++++++++++++++++++++++++++++++++++ block/blk-ledtrig.h | 8 ++++ block/genhd.c | 8 ++++ 3 files changed, 125 insertions(+) diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c index 280fa9edc2dd..1af94dc7ea51 100644 --- a/block/blk-ledtrig.c +++ b/block/blk-ledtrig.c @@ -6,6 +6,7 @@ * Copyright 2021 Ian Pilcher */ +#include #include #include #include @@ -139,3 +140,111 @@ static int blk_ledtrig_dev_set(struct gendisk *const disk, led_set_exit_return: return ret; } + + +/* + * + * sysfs attribute store function to set or clear device LED + * + */ + +// Returns a pointer to the first non-whitespace character in s (or a pointer +// to the terminating null). +static const char *blk_ledtrig_skip_whitespace(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 blk_ledtrig_skip_whitespace.) +static const char *blk_ledtrig_find_whitespace(const char *s) +{ + while (*s != 0 && !isspace(*s)) + ++s; + + return s; +} + +static bool blk_ledtrig_name_is_none(const char *const name, const size_t len) +{ + static const char none[4] = "none"; // no terminating null + + return len == sizeof(none) && memcmp(name, none, sizeof(none)) == 0; +} + +ssize_t blk_ledtrig_dev_led_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count) +{ + struct gendisk *const disk = dev_to_disk(dev); + const char *const led_name = blk_ledtrig_skip_whitespace(buf); + const char *const endp = blk_ledtrig_find_whitespace(led_name); + const ptrdiff_t name_len = endp - led_name; // always >= 0 + int ret; + + if (name_len == 0 || blk_ledtrig_name_is_none(led_name, name_len)) { + blk_ledtrig_dev_clear(disk); + ret = 0; + } else { + ret = blk_ledtrig_dev_set(disk, led_name, name_len); + } + + if (ret < 0) + return ret; + + return count; +} + + +/* + * + * sysfs attribute show function for device LED + * + */ + +ssize_t blk_ledtrig_dev_led_show(struct device *const dev, + struct device_attribute *const attr, + char *const buf) +{ + struct gendisk *const disk = dev_to_disk(dev); + struct blk_ledtrig_led *bd_led, *disk_led; + int ret, c = 0; + + ret = mutex_lock_interruptible(&blk_ledtrig_mutex); + if (ret != 0) + goto led_show_exit_return; + + disk_led = rcu_dereference_protected(disk->led, + lockdep_is_held(&blk_ledtrig_mutex)); + + if (disk_led == NULL) + c += sprintf(buf, "[none]"); + else + c += sprintf(buf, "none"); + + list_for_each_entry(bd_led, &blk_ledtrig_leds, leds_list_node) { + + ret = snprintf(buf + c, PAGE_SIZE - c - 1, + bd_led == disk_led ? " [%s]" : " %s", + bd_led->led->name); + if (ret >= PAGE_SIZE - c - 1) { + ret = -EOVERFLOW; + goto led_show_exit_unlock; + } + + c += ret; + } + + buf[c] = '\n'; + ret = c + 1; + +led_show_exit_unlock: + mutex_unlock(&blk_ledtrig_mutex); +led_show_exit_return: + return ret; +} diff --git a/block/blk-ledtrig.h b/block/blk-ledtrig.h index 66a1302a4174..771000d43647 100644 --- a/block/blk-ledtrig.h +++ b/block/blk-ledtrig.h @@ -18,6 +18,14 @@ static inline void blk_ledtrig_disk_init(struct gendisk *const disk) void blk_ledtrig_dev_clear(struct gendisk *const disk); +ssize_t blk_ledtrig_dev_led_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count); + +ssize_t blk_ledtrig_dev_led_show(struct device *const dev, + struct device_attribute *const attr, + char *const buf); + #else // CONFIG_BLK_LED_TRIGGERS static inline void blk_ledtrig_disk_init(const struct gendisk *disk) {} diff --git a/block/genhd.c b/block/genhd.c index 9fa734aeab0f..d5413a633410 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1012,6 +1012,11 @@ static struct device_attribute dev_attr_fail_timeout = __ATTR(io-timeout-fail, 0644, part_timeout_show, part_timeout_store); #endif +#ifdef CONFIG_BLK_LED_TRIGGERS +static struct device_attribute dev_attr_led = + __ATTR(led, 0644, blk_ledtrig_dev_led_show, blk_ledtrig_dev_led_store); +#endif + static struct attribute *disk_attrs[] = { &dev_attr_range.attr, &dev_attr_ext_range.attr, @@ -1033,6 +1038,9 @@ static struct attribute *disk_attrs[] = { #endif #ifdef CONFIG_FAIL_IO_TIMEOUT &dev_attr_fail_timeout.attr, +#endif +#ifdef CONFIG_BLK_LED_TRIGGERS + &dev_attr_led.attr, #endif NULL }; From patchwork Mon Aug 9 03:32:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494602 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 CAF49C4320E for ; Mon, 9 Aug 2021 03:32:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC1866103B for ; Mon, 9 Aug 2021 03:32:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232887AbhHIDdN (ORCPT ); Sun, 8 Aug 2021 23:33:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232763AbhHIDdM (ORCPT ); Sun, 8 Aug 2021 23:33:12 -0400 Received: from mail-oi1-x231.google.com (mail-oi1-x231.google.com [IPv6:2607:f8b0:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF6DEC061757; Sun, 8 Aug 2021 20:32:52 -0700 (PDT) Received: by mail-oi1-x231.google.com with SMTP id be20so2853251oib.8; Sun, 08 Aug 2021 20:32:52 -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=kRrIoSKg1v4/TjhUcT0NK/1ehkQeeVfSwbumR9nUTwI=; b=rn0342fWakTOfnwZyR38Tk1r4457maQ+jFYOSAyl4x0tRYTdpBUqCMwdK9KqnUNHTY bnmYFStkH9MYPBH2rlut2KfG2yS8bN05EbM94cb0Y9oZdUoDQ0T5NqZC/MqagyLxKxDW mwXEcXWvCWkYEAPTfoJtFUwKauyIV2JiQMaH8ymqSgx2AYByFBE8JgTJNqeRwIflo2G0 sYgjHdY8ffdpCXbLYVSrnTYslQxiQ1mLrxHHtmmFIbIPanWYZxRQNF2GpAxVeBfTkn0G x0H5AQSDdhQ4ZO0QO7PZrElvYdKx1WyjZQqzAeoL2haikbCg4fZWvnFRRFnckA767QAS ZVwg== 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=kRrIoSKg1v4/TjhUcT0NK/1ehkQeeVfSwbumR9nUTwI=; b=lAk9k1Z051zbVu5nvLbSUduQDif9RWXyl0exsiOKdbBvTKA+fu6gUl5Sv4r2x6x0g6 T6fITdA11DduntmmIx2L176bBoRb9juRfH38knzGxxUkUpfvkNCmXSDNFAAIyM1M6CHb QtJGEp6zcG1pSV7p8sfTOLNgPGPiCNM2nrNvexTE6aEJ9B5vZVBlMdp+C8QKaYWe9ChW tQNqA+je9e5jtS5LjZRLJ691uXkP0myfnTe8nqm/8+vEtfZqTzoeoOT1IH3Z2akZSc8k LszbvPCWEyrw3dPtNMBE1Mefy+OSepX2Ijx7WNjNMM2u02aBXbAFxtus8JHjGBW3UZhV 7sqw== X-Gm-Message-State: AOAM531pUwPyOWVksmelUS88nIT43iMTZqQ7FZh2YAg1odXEbuV1kYwv TGBMJT4/9COoxO1cOxakorKz5sloqQnJqCze X-Google-Smtp-Source: ABdhPJwZ2nCdKz7ZHdKJ2lNlsJ+uCw9Aw35CFGNScZU6OYTKlyWRPBg+/wMC34wH3kMIblU9RFzmtQ== X-Received: by 2002:aca:de54:: with SMTP id v81mr2142698oig.40.1628479972174; Sun, 08 Aug 2021 20:32:52 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:51 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 06/10] block: Add activate and deactivate functions for block device LED trigger Date: Sun, 8 Aug 2021 22:32:13 -0500 Message-Id: <20210809033217.1113444-7-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Set up activated LED: * Allocate per-LED data structure * Add LED to list of LEDs associated with blkdev trigger * Create block_devices subdirectory for links to associated devices Clean up deactivated LED: * Clear LED of any associated devices * Remove from LED from blkdev trigger list * Remove block_devices subdirectory * Wait for any blinks using LED to complete (synchronize_rcu()) * Free per-LED structure Signed-off-by: Ian Pilcher --- block/blk-ledtrig.c | 95 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c index 1af94dc7ea51..f8cb6de203f8 100644 --- a/block/blk-ledtrig.c +++ b/block/blk-ledtrig.c @@ -13,6 +13,11 @@ #include "blk-ledtrig.h" +// Default blink_on & blink_off values +#define BLK_LEDTRIG_BLINK_ON 75 +#define BLK_LEDTRIG_BLINK_OFF 25 +#define BLK_LEDTRIG_BLINK_MAX 10000 // 10 seconds + /* * @@ -248,3 +253,93 @@ ssize_t blk_ledtrig_dev_led_show(struct device *const dev, led_show_exit_return: return ret; } + + +/* + * + * Associate an LED with the blkdev trigger + * + */ + +// Helper function to create /blkdevs subdirectory - doesn't +// swallow error code like kobject_create_and_add() +static int blk_ledtrig_subdir_create(struct blk_ledtrig_led *const bd_led, + struct led_classdev *const led) +{ + int ret; + + bd_led->dir = kobject_create(); + if (bd_led->dir == NULL) + return -ENOMEM; + + ret = kobject_add(bd_led->dir, &led->dev->kobj, "block_devices"); + if (ret != 0) + kobject_put(bd_led->dir); + + return ret; +} + +static int blk_ledtrig_activate(struct led_classdev *const led) +{ + struct blk_ledtrig_led *bd_led; + int ret; + + bd_led = kmalloc(sizeof(*bd_led), GFP_KERNEL); + if (bd_led == NULL) { + ret = -ENOMEM; + goto activate_exit_return; + } + + bd_led->led = led; + bd_led->blink_on = BLK_LEDTRIG_BLINK_ON; + bd_led->blink_off = BLK_LEDTRIG_BLINK_OFF; + INIT_LIST_HEAD(&bd_led->dev_list); + + ret = mutex_lock_interruptible(&blk_ledtrig_mutex); + if (ret != 0) + goto activate_exit_free; + + ret = blk_ledtrig_subdir_create(bd_led, led); + if (ret != 0) + goto activate_exit_unlock; + + list_add(&bd_led->leds_list_node, &blk_ledtrig_leds); + led_set_trigger_data(led, bd_led); + ret = 0; + +activate_exit_unlock: + mutex_unlock(&blk_ledtrig_mutex); +activate_exit_free: + if (ret != 0) + kfree(bd_led); +activate_exit_return: + return ret; +} + + +/* + * + * Disassociate an LED from the blkdev trigger + * + */ + +static void blk_ledtrig_deactivate(struct led_classdev *const led) +{ + struct blk_ledtrig_led *const bd_led = led_get_trigger_data(led); + struct gendisk *disk, *next; + + mutex_lock(&blk_ledtrig_mutex); + + list_for_each_entry_safe(disk, next, + &bd_led->dev_list, led_dev_list_node) { + + blk_ledtrig_dev_clear_locked(disk, bd_led); + } + + list_del(&bd_led->leds_list_node); + kobject_put(bd_led->dir); + + mutex_unlock(&blk_ledtrig_mutex); + synchronize_rcu(); + kfree(bd_led); +} From patchwork Mon Aug 9 03:32:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494107 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 0D021C4320A for ; Mon, 9 Aug 2021 03:33:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4BDE61052 for ; Mon, 9 Aug 2021 03:33:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232971AbhHIDdV (ORCPT ); Sun, 8 Aug 2021 23:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232895AbhHIDdO (ORCPT ); Sun, 8 Aug 2021 23:33:14 -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 81462C061757; Sun, 8 Aug 2021 20:32:53 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id z6-20020a0568302906b02904f268d34f86so16182632otu.2; Sun, 08 Aug 2021 20:32:53 -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=sIAnA5vosh2k60KabPnPPb10AS/W866dQZt7HVdCEmk=; b=tXZq1L2UVs+m3REWTqKVAZ3lqTY9tg6dPpuzB8R/WeFbcGsr9bPfyyIY8J2/4zYcyg Hyu11aflIYW2zmaxgqQD4KR5LNFV1114sUl/qQIg4xF367jGzQBWZbrG4FLl+C4xMAB5 S48NRK0IUHza1KxbWpbRyoen58MKtwco6odZ9/5TEzLP8v9iJ3tCLm1c8/Tz7dpMOlln syZGJr67PBLWAuJmcGwy0KBLBDSuUFWTogtSSopNtwzdfetnrHfo0yJnE9e/n2Mf+WRv nCS4u8yFqm1tAl6rBkO5rvSpEg/zguxXl1TsMNitI57eY5ve+enVNduOzXXdfxlULiN9 GzLQ== 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=sIAnA5vosh2k60KabPnPPb10AS/W866dQZt7HVdCEmk=; b=VT8lGtpAYriIG49/XmJcBACJp6/CmHCWLx1HopAuMqrf9KgoMTyJqKFYJZlY/U20M4 TP9wZNcwCJ2F/Z2ZoeMIGo6t5JAVHNEmn6eLP1ipzVhHRXcQ1JRViLtD0uvWM/3uBan5 fmxECaih9MRY1Z5VpIzG/q1QQdIi5A5dIiC2RRHZRWM2mUdKCqujnS7j00D6hov5X74d /ZvDV24+hXz24gE5f/ZnkfYnrKWcIwAifT5RglfnY5iwffb3AdErj6fKh+HbHPCPAVZA 3XqFiIpBFK2jfqid71wSemSS5CE8bvVqAdSGiHQKEyJwBbbSdT0u4fKUgCJg8YKVBKdX GT0Q== X-Gm-Message-State: AOAM533C6+N+GRAH4mdgOSr5ppwQ1ctT+7TSVvtiNKa4W0Ii1E6kSWJ4 29IcO2g0h0/V5SnRsKsCDrNj3UTbpXsTv0yw X-Google-Smtp-Source: ABdhPJzZ5kn7aTWi1x675wRiIsayhrUWdERSWqZCPUcYy5+LBYxj3/ENLc23Rie9UTG15kigouyauw== X-Received: by 2002:a05:6830:2377:: with SMTP id r23mr15886288oth.125.1628479972909; Sun, 08 Aug 2021 20:32:52 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:52 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 07/10] block: Add sysfs attributes to LEDs associated with blkdev trigger Date: Sun, 8 Aug 2021 22:32:14 -0500 Message-Id: <20210809033217.1113444-8-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Add blink_on & blink_off attributes to control the duration of each LED blink (blink_on) and the minimum time between blinks (blink_off) in milliseconds Signed-off-by: Ian Pilcher --- block/blk-ledtrig.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c index f8cb6de203f8..d02f32205985 100644 --- a/block/blk-ledtrig.c +++ b/block/blk-ledtrig.c @@ -343,3 +343,66 @@ static void blk_ledtrig_deactivate(struct led_classdev *const led) synchronize_rcu(); kfree(bd_led); } + + +/* + * + * Per-LED blink_on & blink_off device attributes + * + */ + +static ssize_t blk_ledtrig_blink_show(struct device *const dev, + struct device_attribute *const attr, + char *const buf); + +static ssize_t blk_ledtrig_blink_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, + const size_t count); + +static struct device_attribute blk_ledtrig_attr_blink_on = + __ATTR(blink_on, 0644, + blk_ledtrig_blink_show, blk_ledtrig_blink_store); + +static struct device_attribute blk_ledtrig_attr_blink_off = + __ATTR(blink_off, 0644, + blk_ledtrig_blink_show, blk_ledtrig_blink_store); + +static ssize_t blk_ledtrig_blink_show(struct device *const dev, + struct device_attribute *const attr, + char *const buf) +{ + struct blk_ledtrig_led *const bd_led = led_trigger_get_drvdata(dev); + unsigned int value; + + if (attr == &blk_ledtrig_attr_blink_on) + value = READ_ONCE(bd_led->blink_on); + else // attr == &blk_ledtrig_attr_blink_off + value = READ_ONCE(bd_led->blink_off); + + return sprintf(buf, "%u\n", value); +} + +static ssize_t blk_ledtrig_blink_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, + const size_t count) +{ + struct blk_ledtrig_led *const bd_led = led_trigger_get_drvdata(dev); + unsigned int value; + int ret; + + ret = kstrtouint(buf, 0, &value); + if (ret != 0) + return ret; + + if (value > BLK_LEDTRIG_BLINK_MAX) + return -ERANGE; + + if (attr == &blk_ledtrig_attr_blink_on) + WRITE_ONCE(bd_led->blink_on, value); + else // attr == &blk_ledtrig_attr_blink_off + WRITE_ONCE(bd_led->blink_off, value); + + return count; +} From patchwork Mon Aug 9 03:32:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494600 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 2A684C4338F for ; Mon, 9 Aug 2021 03:33:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1260860F38 for ; Mon, 9 Aug 2021 03:33:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233009AbhHIDd2 (ORCPT ); Sun, 8 Aug 2021 23:33:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232912AbhHIDdQ (ORCPT ); Sun, 8 Aug 2021 23:33:16 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2886CC061799; Sun, 8 Aug 2021 20:32:56 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id x15so21690881oic.9; Sun, 08 Aug 2021 20:32:56 -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=6Z9rErwEGMPwtnMf+3tIIodscSEF7PbZLxINPsDN2pY=; b=IXXn0yae9+6114TDZPAO0JeAF6zuOlZMoTq8VpXENUmAQNQ7J2EPFPNQ1MVrjnoFFz hNIsg3Mz9dhGm/RzwzxruxNoHxZzgWUlx19wJxgtnFjNerMYuLqhUK3XGXsxuBvwbadd RYgG4+gNYwTOzNbjrYL36s8kU+HEvPubnywgq+2mStie6v17xHJXnVEZjbH1JKYo2m+Q ILUxBRClj7WKlpWioSxVcF9ggIcvHDTzmdko9uNmv18JFtfTp5sm4jj3ZAfswiSDUIXV sNCpMddoKvR/GemueDFaL4624RRz9Bq3pJAVoUqXeqY9vK5Vn3SfMM6J8SmHgepj1JET eg5A== 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=6Z9rErwEGMPwtnMf+3tIIodscSEF7PbZLxINPsDN2pY=; b=iuwYWC4olbOwjJWXosBNLS98aopxFv1hmlOXTVksI9NQYnWZLcZLkD05YHwIdjajgv DF15x53OVyMtH3d+KjL+tk/sxwRvt8PB7ji/fHmEt0tnGsApDpNbil51CgZ6Dbq/Hvna mCvhdw/ZLOM5rCNDcQFq+f7kvmeNMfjvTv51iLu2X4dGhRv+tAWtllyivrOQrs7Y16n0 kmJXRPzDQyrN3E/G64/O5h238D5XAs4oBFktxBX0yD4O2yQtaRYjNYIysHyT4oEKhrlu AzIG7fMwngXyggLb4VWMQ/h74xcif9GHk63FjwWjCDhHJ2296mPf0FqujTxDDZ8eQhK1 vzOw== X-Gm-Message-State: AOAM530fWX7LrGVnos/5gcPXdzxrMxVY2hWSUVNFUX3Tyqe1bIS3Ai5f aBFnUXSqyLp1muo76hKDCn8OZgqsstRFCNHE X-Google-Smtp-Source: ABdhPJw6WuVvMNMovP224EhottNlKQH77w4NGsl9QyH4Cca4nRDS2xno/r4Q9LNL1jTtzb/qY2vupA== X-Received: by 2002:a05:6808:194:: with SMTP id w20mr13809607oic.142.1628479975581; Sun, 08 Aug 2021 20:32:55 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:55 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 08/10] block: Add init function for block device LED trigger Date: Sun, 8 Aug 2021 22:32:15 -0500 Message-Id: <20210809033217.1113444-9-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Register the blkdev LED trigger Signed-off-by: Ian Pilcher --- block/blk-ledtrig.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c index d02f32205985..14b1d33a2953 100644 --- a/block/blk-ledtrig.c +++ b/block/blk-ledtrig.c @@ -406,3 +406,38 @@ static ssize_t blk_ledtrig_blink_store(struct device *const dev, return count; } + + +/* + * + * Initialization - register the trigger + * + */ + +static struct attribute *blk_ledtrig_attrs[] = { + &blk_ledtrig_attr_blink_on.attr, + &blk_ledtrig_attr_blink_off.attr, + NULL +}; + +static const struct attribute_group blk_ledtrig_attr_group = { + .attrs = blk_ledtrig_attrs, +}; + +static const struct attribute_group *blk_ledtrig_attr_groups[] = { + &blk_ledtrig_attr_group, + NULL +}; + +static struct led_trigger blk_ledtrig_trigger = { + .name = "blkdev", + .activate = blk_ledtrig_activate, + .deactivate = blk_ledtrig_deactivate, + .groups = blk_ledtrig_attr_groups, +}; + +static int __init blk_ledtrig_init(void) +{ + return led_trigger_register(&blk_ledtrig_trigger); +} +device_initcall(blk_ledtrig_init); From patchwork Mon Aug 9 03:32:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494106 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 37616C4320A for ; Mon, 9 Aug 2021 03:33:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C8F861004 for ; Mon, 9 Aug 2021 03:33:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233035AbhHIDdc (ORCPT ); Sun, 8 Aug 2021 23:33:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232946AbhHIDdU (ORCPT ); Sun, 8 Aug 2021 23:33:20 -0400 Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D16DC06179C; Sun, 8 Aug 2021 20:32:57 -0700 (PDT) Received: by mail-oi1-x236.google.com with SMTP id s13so12448674oie.10; Sun, 08 Aug 2021 20:32:57 -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=qODwXXqin3j/qsovJZX1OPoeqYbdkrnP0jJoGjELmHg=; b=Eyk5GgBH6I3rb4Ai0P5hqtxOAtZoHai29umGdiMXpXSFkCoWLuuQXMHHxMnF31hWxy TwECvAwVMLCdlf3EY/me4rZjrK8xkJ4d+vGUeMSsz2chtXLaBqm3HzcUOH3C+nMiw9ov ddoIhKjjaFg8Ja1PgqSmcPqeS2MKOjGVdyeS3FQqQJkjbpF7RgZ74gO5Xzv0/Fwj8smV Zs+3HlfwdjOD4hCbKhA8VVT4fNr/Lv3YTtNPFw/ldWakbc7WVtDRiwIj+o8k8nA6tYt+ S1TR/vtuD14EjK0mbXCPrdPyTrAJNC0b1YRWE2bb7VB/Czq/G1dKcR4dQ7VLUz+mihzK Y2og== 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=qODwXXqin3j/qsovJZX1OPoeqYbdkrnP0jJoGjELmHg=; b=GPVs3eGmTlzoy3fEIqzQlAzLYj04rEHILjmRa0JkGD/4Z3H6lW51LktordleeFegJu dgkK347hXwLIziqfBFAXFnU51g/mqR0hxfelgsMCzAmrwW8Mm0vHHmbiOD6mhAXwcFep /92d084tisEGTVgLta0TINsIgXqrgtnI1R7McSZgkxg4fp+DiVsj27u1dJf6XvnefmD9 agtzfj6IoS14w/Qg9ASR4WeKFSOrTWT0UL9cxCLixuWSGfLiuKH40HCevqAOWnS7jNpl YJSZQd+64T8akRLIUQDMTG6hQ4ihUmj11FeE9fEzZcFGreeZGAYOWiKhacZYdLKxdZ8R sYWg== X-Gm-Message-State: AOAM533P0l+4jICX/c1rRZJjPUQhIL3chn4D9Krp/VLYmYNN5e7FuTDy SCKahVUVEtWDmlbZQ1htV5wPGjcBEZghiQWc X-Google-Smtp-Source: ABdhPJw7mnevUVdAxjv9lcCViU4OrDqE+qpTu4fIVB6YzvapPOcSvTc1UcLCL+4FqRr0v8fi4yqzAw== X-Received: by 2002:aca:130d:: with SMTP id e13mr26895oii.3.1628479976217; Sun, 08 Aug 2021 20:32:56 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:55 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 09/10] block: Blink device LED (if any) when request is sent to its driver Date: Sun, 8 Aug 2021 22:32:16 -0500 Message-Id: <20210809033217.1113444-10-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-1-arequipeno@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-leds@vger.kernel.org Call led_blink_set_oneshot() in RCU critical section to ensure that LED doesn't disappear. (See synchronize_rcu() call in blk_ledtrig_deactivate()). Signed-off-by: Ian Pilcher --- block/blk-ledtrig.c | 26 ++++++++++++++++++++++++++ block/blk-ledtrig.h | 9 +++++++++ block/blk-mq.c | 2 ++ 3 files changed, 37 insertions(+) diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c index 14b1d33a2953..10588f3dea15 100644 --- a/block/blk-ledtrig.c +++ b/block/blk-ledtrig.c @@ -6,6 +6,7 @@ * Copyright 2021 Ian Pilcher */ +#include #include #include #include @@ -441,3 +442,28 @@ static int __init blk_ledtrig_init(void) return led_trigger_register(&blk_ledtrig_trigger); } device_initcall(blk_ledtrig_init); + + +/* + * + * Blink the LED associated with a (non-NULL) disk (if set) + * + */ + +void __blk_ledtrig_try_blink(struct request *const rq) +{ + struct blk_ledtrig_led *bd_led; + unsigned long delay_on, delay_off; + + rcu_read_lock(); + + bd_led = rcu_dereference(rq->rq_disk->led); + + if (bd_led != NULL) { + delay_on = READ_ONCE(bd_led->blink_on); + delay_off = READ_ONCE(bd_led->blink_off); + led_blink_set_oneshot(bd_led->led, &delay_on, &delay_off, 0); + } + + rcu_read_unlock(); +} diff --git a/block/blk-ledtrig.h b/block/blk-ledtrig.h index 771000d43647..7eb1d88e2b3c 100644 --- a/block/blk-ledtrig.h +++ b/block/blk-ledtrig.h @@ -26,10 +26,19 @@ ssize_t blk_ledtrig_dev_led_show(struct device *const dev, struct device_attribute *const attr, char *const buf); +void __blk_ledtrig_try_blink(struct request *const rq); + +static inline void blk_ledtrig_try_blink(struct request *const rq) +{ + if (rq->rq_disk != NULL) + __blk_ledtrig_try_blink(rq); +} + #else // CONFIG_BLK_LED_TRIGGERS static inline void blk_ledtrig_disk_init(const struct gendisk *disk) {} static inline void blk_ledtrig_dev_clear(const struct gendisk *disk) {} +static inline void blk_ledtrig_try_blink(const struct request *rq) {} #endif // CONFIG_BLK_LED_TRIGGERS diff --git a/block/blk-mq.c b/block/blk-mq.c index 2c4ac51e54eb..7732e31f3ca8 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -40,6 +40,7 @@ #include "blk-stat.h" #include "blk-mq-sched.h" #include "blk-rq-qos.h" +#include "blk-ledtrig.h" static DEFINE_PER_CPU(struct llist_head, blk_cpu_done); @@ -1381,6 +1382,7 @@ bool blk_mq_dispatch_rq_list(struct blk_mq_hw_ctx *hctx, struct list_head *list, switch (ret) { case BLK_STS_OK: queued++; + blk_ledtrig_try_blink(rq); break; case BLK_STS_RESOURCE: case BLK_STS_DEV_RESOURCE: From patchwork Mon Aug 9 03:32:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Pilcher X-Patchwork-Id: 494599 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 BE82FC4320E for ; Mon, 9 Aug 2021 03:33:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A559F61004 for ; Mon, 9 Aug 2021 03:33:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232979AbhHIDde (ORCPT ); Sun, 8 Aug 2021 23:33:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232905AbhHIDdV (ORCPT ); Sun, 8 Aug 2021 23:33:21 -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 7AA35C06179E; Sun, 8 Aug 2021 20:32:57 -0700 (PDT) Received: by mail-ot1-x32e.google.com with SMTP id e13-20020a9d63cd0000b02904fa42f9d275so5605239otl.1; Sun, 08 Aug 2021 20:32:57 -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=jYD0I1JcL0BH0vCCzrjiH0y23RAOPCoB1MhwiKSdk1I=; b=ASwNRcZC+WslkMmnYkzKeAg3z3EdGFgbbNCh31jouaKVo60A66evSpkvvLRWbhw+5g nIxp6BJ+01A7BQZ+UxzSo2yFWVCtQn7mVg/tr93Q4V35bGHssqSPJf4XS8cVQ/jLxId+ C2xa9ZsEMKYB1hbS6WzLr2lJXzEe58ij8m148DOuQ9uqhuELQLOTxwSOtwwPv7h/9Yqd Uf/lGePC7NMPiDt3EShFA8vO9bPmxpemnTIZO4WfCQ5iV2tfygJwCiCr2l3C6wvTU7VZ NlFjMC2rbG6YyoXWz9LvgaRTZHAoQK3u+OqovsGJcXU8FZT2SBtRc6ZCHd5v5CPNhGTF NlMQ== 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=jYD0I1JcL0BH0vCCzrjiH0y23RAOPCoB1MhwiKSdk1I=; b=b+4+YwlOEm67fpWc0ezLeh02lKOvuKq1d2tqMq5OqPc3ZiRTJrdKwZmvdsKiKFLpAV RPvZa76djgP9tdElRWaZA2Ae8ah4MlsYjsRwC72oDUHGWWSjZ4MY7KgQ2mUCYGyjuWjq jQ2WNbV23huEP3GrpfKsN80XOf78MgS7pLJyn5lpKX4XjFpAQQYHUKdG0/NZzPx8xs+/ 27ust1ZnZXipbmIVSMPGRO82XcKnWwhSp0qoA5OI31/+lB4HJewz3nlvPSGF26VsMzeS pDiXA8Bbf5CzZYzmyWQcDu08IrNSf9d3LFtQVk6szve5sCXi/owdfqr3ejk30yh8gxNm 9Huw== X-Gm-Message-State: AOAM533nJVqJn7UnUc9F4NxaoVFuG83RDAEy4V3IeAZamoHQHCO57/2A YX6powhQogULnjEbknCVcl5F9wlwIm0dv8tF X-Google-Smtp-Source: ABdhPJznv0VzS5EFBDhxNOvRXEEZpBoNS4yw7oHByexjC6HrCWiHLgymSQWFvxuqHAhXUc10JmKamQ== X-Received: by 2002:a9d:5e0b:: with SMTP id d11mr15767902oti.371.1628479976891; Sun, 08 Aug 2021 20:32:56 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id r7sm1463646oij.14.2021.08.08.20.32.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Aug 2021 20:32:56 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Cc: axboe@kernel.dk, pavel@ucw.cz, linux-kernel@vger.kernel.org, kernelnewbies@kernelnewbies.org Subject: [RFC PATCH v2 10/10] block: Add config option to enable block device LED triggers Date: Sun, 8 Aug 2021 22:32:17 -0500 Message-Id: <20210809033217.1113444-11-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210809033217.1113444-1-arequipeno@gmail.com> References: <20210809033217.1113444-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 --- block/Kconfig | 8 ++++++++ block/Makefile | 1 + 2 files changed, 9 insertions(+) diff --git a/block/Kconfig b/block/Kconfig index fd732aede922..ef05b36b5251 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -220,6 +220,14 @@ config BLK_INLINE_ENCRYPTION_FALLBACK by falling back to the kernel crypto API when inline encryption hardware is not present. +config BLK_LED_TRIGGERS + bool "Enable the blkdev LED trigger" + depends on LEDS_TRIGGERS + help + The blkdev LED trigger allows LEDs to be controlled by + block device activity (reads and writes). See + Documentation/block/blk-ledtrig.rst. + menu "Partition Types" source "block/partitions/Kconfig" diff --git a/block/Makefile b/block/Makefile index bfbe4e13ca1e..bcd97ee26462 100644 --- a/block/Makefile +++ b/block/Makefile @@ -42,3 +42,4 @@ obj-$(CONFIG_BLK_SED_OPAL) += sed-opal.o obj-$(CONFIG_BLK_PM) += blk-pm.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION) += keyslot-manager.o blk-crypto.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK) += blk-crypto-fallback.o +obj-$(CONFIG_BLK_LED_TRIGGERS) += blk-ledtrig.o