From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F95DC4338F for ; Thu, 29 Jul 2021 01:58:29 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4732F6056C for ; Thu, 29 Jul 2021 01:58:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4732F6056C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94.2) (envelope-from ) id 1m8vJX-0001mZ-76; Wed, 28 Jul 2021 21:58:23 -0400 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1m8vFq-0002j2-9U for kernelnewbies@kernelnewbies.org; Wed, 28 Jul 2021 21:54:34 -0400 Received: by mail-oo1-xc36.google.com with SMTP id s21-20020a4ae5550000b02902667598672bso1151151oot.12 for ; Wed, 28 Jul 2021 18:54:34 -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=UKOzPifcOxboRw82QSFcbD/HkRKqBfmFXN/TjZK3tNM=; b=Xxo4L1WAjsxK0AkStEI1tWU1wSyxl/+SCmyVmtSCGxJz7LsE5EadaoAUSOZsjpln3y o2a1d6Cf0uEJoWdVvIYj7BV6fwVMPfqhO82Ux+pgE5ckRNEJwFoy5ldpwTTBb21kDxd6 G1z0/OHY+dNjQ3KhIfNzIdzuKlRhe92RUcWHccVZYp6hNMiTaLOMVMow9eWFVU98wvPT DNibWu3exdtdPsoJE9Eh28hi2pAzqIv7pLBzSEYtV+MmtTym98pWI3xvbxTWDbaDhEpB vmgrsnkIPob/F1Epz0H+DIw4foMHsee32b2UaZDgN4VaSW4qVXK9L3CE6qi5BJ9rIBCZ 4Mug== 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=UKOzPifcOxboRw82QSFcbD/HkRKqBfmFXN/TjZK3tNM=; b=raiulaNIxajg4dstqv7jrg5rLeRKnnFyd9/aYRDw/c4AKyoUIGp39tHBbcR/c7Ry7x Wpn64Qj6dGVGNEdNarNp7TH7IQBM+DLK0bkW9yJwIgRMuTxcXFnrWc1ElkdgUOsyG38y TBBsh/GKar5mHCUaRnhPanMZJtRDZfLDPP+sKzOXqk/JFz25NcPu2/aNomW7kAavetFp 7bPrNX1fbQ5QXswHbWxeH5Qaq2dpaL3tK5YkAirBuEh42dEI1UejfnUyLd5XK6Uafc5O vlnqiohOOvVjoAZJRSF60fnwspll1cn0JKh4lfWv7Avs4WvV/qrYbL67qZ1060dgR1Az BK7A== X-Gm-Message-State: AOAM5325oxqgMEwbsZa+SAo0qUN6SNO09ZfrCu9oZ+BoxXhE7HuKdBx7 6KotuYSm3X+XYhR/C9vOGSw= X-Google-Smtp-Source: ABdhPJx62adXAx+HuWv/EHgbkjiBZk3d7ZmqLFbNj2fEXyRMYzp6AU1fgiKFXguabEtlV0l1xhiu5g== X-Received: by 2002:a4a:e089:: with SMTP id w9mr1456131oos.50.1627523673391; Wed, 28 Jul 2021 18:54:33 -0700 (PDT) Received: from ian.penurio.us ([47.184.51.90]) by smtp.gmail.com with ESMTPSA id c11sm311424otm.37.2021.07.28.18.54.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 18:54:33 -0700 (PDT) From: Ian Pilcher To: linux-block@vger.kernel.org, linux-leds@vger.kernel.org Subject: [RFC PATCH 7/8] block: Add block device attributes to set & clear LED triggers Date: Wed, 28 Jul 2021 20:53:43 -0500 Message-Id: <20210729015344.3366750-8-arequipeno@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210729015344.3366750-1-arequipeno@gmail.com> References: <20210729015344.3366750-1-arequipeno@gmail.com> MIME-Version: 1.0 Cc: axboe@kernel.dk, Ian Pilcher , linux-kernel@vger.kernel.org, pavel@ucw.cz, kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org * Set/store functions in block/blk-ledtrig.c * Add device attributes to disk_attrs in block/genhd.c Signed-off-by: Ian Pilcher --- block/blk-ledtrig.c | 65 +++++++++++++++++++++++++++++++++++++++++++++ block/blk-ledtrig.h | 8 ++++++ block/genhd.c | 9 +++++++ 3 files changed, 82 insertions(+) diff --git a/block/blk-ledtrig.c b/block/blk-ledtrig.c index 7c8fdff88683..2d324df45149 100644 --- a/block/blk-ledtrig.c +++ b/block/blk-ledtrig.c @@ -479,3 +479,68 @@ bool blk_ledtrig_clear(struct gendisk *const gd) return changed; } EXPORT_SYMBOL_GPL(blk_ledtrig_clear); + + +/* + * + * Set, clear & show LED triggers via sysfs device attributes + * + * (See dev_attr_led_trigger and disk_attrs in genhd.c) + * + */ + +ssize_t blk_ledtrig_devattr_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count) +{ + struct gendisk *const gd = dev_to_disk(dev); + const char *const name = blk_ledtrig_skip_whitespace(buf); + const char *const endp = blk_ledtrig_find_whitespace(name); + const ptrdiff_t name_len = endp - name; // always >= 0 + int ret; + + if (name_len == 0) + ret = blk_ledtrig_clear(gd); + else + ret = __blk_ledtrig_set(gd, name, name_len); + + if (ret < 0) + return ret; + + return blk_ledtrig_skip_whitespace(endp) - buf; +} + +ssize_t blk_ledtrig_devattr_show(struct device *const dev, + struct device_attribute *const attr, + char *const buf) +{ + struct gendisk *const gd = dev_to_disk(dev); + const struct blk_ledtrig *t; + size_t name_len; + int ret; + + ret = mutex_lock_interruptible(&gd->ledtrig_mutex); + if (unlikely(ret != 0)) + return ret; + + t = gd->ledtrig; + + if (t != NULL) { + name_len = strlen(t->name); + if (likely(name_len < PAGE_SIZE - 1)) + memcpy(buf, t->name, name_len); + } + + mutex_unlock(&gd->ledtrig_mutex); + + if (t == NULL) + return sprintf(buf, "(none)\n"); + + if (unlikely(name_len >= PAGE_SIZE - 1)) + return -EOVERFLOW; + + buf[name_len] = '\n'; + buf[name_len + 1] = 0; + + return (ssize_t)(name_len + 1); +} diff --git a/block/blk-ledtrig.h b/block/blk-ledtrig.h index 9b718d45783f..5d228905edbf 100644 --- a/block/blk-ledtrig.h +++ b/block/blk-ledtrig.h @@ -19,6 +19,14 @@ static inline void blk_ledtrig_disk_init(struct gendisk *const gd) mutex_init(&gd->ledtrig_mutex); } +ssize_t blk_ledtrig_devattr_store(struct device *const dev, + struct device_attribute *const attr, + const char *const buf, const size_t count); + +ssize_t blk_ledtrig_devattr_show(struct device *const dev, + struct device_attribute *const attr, + char *const buf); + #else // CONFIG_BLK_LED_TRIGGERS static inline void blk_ledtrig_init(void) {} diff --git a/block/genhd.c b/block/genhd.c index fb1617f21d79..fd37efe74d48 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1014,6 +1014,12 @@ 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_trigger = + __ATTR(led_trigger, 0644, + blk_ledtrig_devattr_show, blk_ledtrig_devattr_store); +#endif + static struct attribute *disk_attrs[] = { &dev_attr_range.attr, &dev_attr_ext_range.attr, @@ -1035,6 +1041,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_trigger.attr, #endif NULL }; -- 2.31.1 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies