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=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 2A5C4C4338F for ; Mon, 9 Aug 2021 03:34:37 +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 B958A61002 for ; Mon, 9 Aug 2021 03:34:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B958A61002 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 1mCw3f-0005hz-Eu for kernelnewbies@archiver.kernel.org; Sun, 08 Aug 2021 23:34:35 -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 1mCw1y-0003bN-Sq for kernelnewbies@kernelnewbies.org; Sun, 08 Aug 2021 23:32:50 -0400 Received: by mail-oi1-x22d.google.com with SMTP id u25so21732168oiv.5 for ; 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=ijmM88sQnikh8S0qWcQ4uXj5Wfv+UO2hkhDi4Iph8r+LRL5Isz61kbWwZ1m+iQ5jEf OiM8bvZ9Y9WHsna6BWWeyZKz/lrnLULR8dgBQ66+yNNHEpA/juxQGp6E6qvLQKmLd/kL jfZnRGf0Thk292fP5hZaujNAOQbS0amGmKYlM0AUxjfEaPwyPDv8wqJGzhPPK31Y99r4 d89NVNclbAuyegJF5vAmBGVVOFMs+d2CZ4uRup+g8XuxK3jGodGxMMl8tR5JkC8BJJGd u8YlQSGBHqrUN3rCuqdMy2tiRwF119J3F4bDiZ4IkyFQXMz87/Wwg2B1knmM8v9PUinP 1Ebg== X-Gm-Message-State: AOAM5323LaKi1ElxFsGHNuQeyG1NQEw1kr9qKwzBtKcQjthppvK729vw NPsklymkaQyHb8NJH9ud3jU= 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 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 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=archiver.kernel.org@kernelnewbies.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; +} -- 2.31.1 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies