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 7E31DC4338F for ; Mon, 9 Aug 2021 03:36:09 +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 234E260560 for ; Mon, 9 Aug 2021 03:36:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 234E260560 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 1mCw59-00024n-QD; Sun, 08 Aug 2021 23:36:07 -0400 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1mCw20-0003bx-UW for kernelnewbies@kernelnewbies.org; Sun, 08 Aug 2021 23:32:52 -0400 Received: by mail-oi1-x22d.google.com with SMTP id x15so21690726oic.9 for ; 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=nOXqGjwB5NbK7X3brbqUHcGxPOggq9ocWmiQx3+FHt1xGMUQT82oT/22vZy/p3QC+X MIUbiQGiBfkonmal1yq/9kDCNt2A1agsbIs7LivKvFaaEt5/hikLGkzkcLqhRkyDo5N3 eWBu0C7zVr5t/vBQYVoXBLBv4lt5w8m7fMjgW/kANz1DjF//jYLLuPEyrS4VtEtH3QOv db6aPp+KLDdewIcWCRyClgylZG8geE3tvj6ZoN0g6kWVxIDGQTk/yyjZQyw+2EnvXrYH cFfM1DO0lV8YZx6O1ndgGchpNBIcmcaCrD9LvKp97K1HzYG3BGhzqi3Wb3e0lKG5SSCR cKVg== X-Gm-Message-State: AOAM532gykwdgkh5PF2MYKIcUUGE9yoKzuDicRhwXAmXz6+LsrMUTjXX 6IF21rXcgRz0S5NETX8nGok= 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 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 Cc: axboe@kernel.dk, 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 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); +} -- 2.31.1 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies