Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp2342847pxt; Sun, 8 Aug 2021 20:35:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDtIHh+P0uMmpp1F+uq7AohUYy6nMi6yl8Z3SAQ5gF+7AlibVtdBjttgIhDY+kF3Lzsloo X-Received: by 2002:a05:6e02:15c8:: with SMTP id q8mr192301ilu.285.1628480146180; Sun, 08 Aug 2021 20:35:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628480146; cv=none; d=google.com; s=arc-20160816; b=jcwWWInvczLT12kXn5xZHYdUih/62stsIqm2h2iYSdVjStpfhcUrxih+DPkiTYu/nU 130skP3bZ4GbxTuoel5OCeou7WiAsOhdL0Z3QQlAJZPO9iLnjXZl33hR3oaIvl5Qp5sI UjTjFo1nAeTDsyj/V1g0pSsxE6hsY0U2QLvWx3hkVlvWeInE639hjeHZAIPAKH10oEI2 6uJ+AAs6ueLv2ka4Fs3eJ4LKXU0uUwH3RLycQVEE1TeUot21OduNqJV+dDVCEXEBt/xk yrEzwQIVCjlQ0P/Lrg95qRVtw3uwEmWX/x1BXy5kBiD6WManmZ/VMPI3yxF2gbIjqpcW nIRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qODwXXqin3j/qsovJZX1OPoeqYbdkrnP0jJoGjELmHg=; b=AakfWOsyhsgD4PbJW+Ml6O+r8yDWmUj9szprrrnLhU9OaFPa/RSK9GI8HRN1zEVRR2 mM+l18+hKzmDCcrpOKlptAhTg829vH3giMwNhtzJ+cX4rY7BrHK2mv2GTpfIkJ3+Ioop NQHY5GTprsH4Fpn9k09FITCJB5Hq4a6Ap/gfCDkWUuM1oRuy77GCiKlVj75HkQsc2J/8 Xupkd3khnjMIOuPAzgTu0MBJZEH99n+KqimF9m7yX6CBkO06qIQXju47oMfVQVrEQDvq NmtdvozKBtr5gx6y/SyJduhc1RSuHNV3qll+JIRZXXkhxqxM/K2Y2iAMaDR8Jidjmuyk GE4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Eyk5GgBH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g2si16801290ilj.118.2021.08.08.20.35.34; Sun, 08 Aug 2021 20:35:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Eyk5GgBH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232916AbhHIDdh (ORCPT + 99 others); Sun, 8 Aug 2021 23:33:37 -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-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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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: -- 2.31.1