Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp745565iog; Mon, 13 Jun 2022 12:00:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7ir9pXIwzxzSQ3keeqs4nVk43tdY/htec9y96p9UsbBlYIXAax7MiaVgPiFPr9Tq8J2Jq X-Received: by 2002:a17:907:1b19:b0:6f0:1022:1430 with SMTP id mp25-20020a1709071b1900b006f010221430mr1074346ejc.13.1655146830128; Mon, 13 Jun 2022 12:00:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655146830; cv=none; d=google.com; s=arc-20160816; b=Lpp6aY3upB1NfWA01iqg80HL4wBuszWULlszu5/rfsmHZW+/BzPLcCsB9VYi7G+Cbj cOMu3K/GEhN+xKsxgziqgrU2HKhzYxxNjVGbaoy4jiZbcfNjLWoDW5S9/yZeDOAaKTTv yBrVCBeqdlbIERb6+RD548pqpOTxXVjXAI1Gr33lO5tJ/zScKehVy74kvortfiEHFTMZ 9AwKEjZV2hHuwBUUvY3Me+MrSfXpQVM4tTfOEdMTFGEqD/jwDgdb2iTjwqUdfli0N10h Mu4Cb3YBGFiceGKOAyCqtq+Segtm0Lv9TDhOSt+GTpr1EBs7oQoz10eHK9wHMSHgW9Iu q8Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JeE4IDLZnrkgWQvxzU/0/BAJVvEljvMQrQHfVZ+A+xM=; b=NZ6t79MuTLeF7eegR2zdOWE685i5lKu5ehSe036YnIt027EsvqVjiy5kFrqGob6KOk 0ao8lcg8aDbMdTMawe2lldZn7VM775TsgCZSnIbQG0xQ2zRpK8rU/RETte3Li9DDlJV6 k/KDeQ/5XHMdOHxwo5bGJ2yABFvmJDhmjJzhrfm78yi/V68AP4UaiVPBXaLi4LDaK/VN Zsw7+gbxHFx7JvUp2Ztincb/NMD3nwaF/nvFaJ1W50Gx5o0IADW4/iBRguq9xtNggAEA d90qAeIjw7rrzR5632N4CZ32ewqTmM57bsBXMSpBACtZdOzUrmyPMTRTGZ14uCZka5QM vRDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@veeam.com header.s=mx4-2022 header.b=MSw3FLAC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=veeam.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs2-20020a1709073e8200b00712e4774584si9777550ejc.690.2022.06.13.12.00.02; Mon, 13 Jun 2022 12:00:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@veeam.com header.s=mx4-2022 header.b=MSw3FLAC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=veeam.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244048AbiFMSzu (ORCPT + 99 others); Mon, 13 Jun 2022 14:55:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345077AbiFMSz1 (ORCPT ); Mon, 13 Jun 2022 14:55:27 -0400 Received: from mx4.veeam.com (mx4.veeam.com [104.41.138.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 570C4FC833; Mon, 13 Jun 2022 08:59:53 -0700 (PDT) Received: from mail.veeam.com (prgmbx01.amust.local [172.24.128.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx4.veeam.com (Postfix) with ESMTPS id 6F344CCE27; Mon, 13 Jun 2022 18:54:16 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=veeam.com; s=mx4-2022; t=1655135656; bh=JeE4IDLZnrkgWQvxzU/0/BAJVvEljvMQrQHfVZ+A+xM=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=MSw3FLACURP7Fe6FANRB+tcHjJCINeI7ZI37CTeiDgUlFR2XJRltn5tsnfM+yuHoY FNZzluNQuZfT5fgGj7Dcv08r5DiisCtJFpSprCrkfXsnBWz1/fcTVJa5crAORO937f /TIeBLgrdXB6E3zjchji9n92+F5Vc05RW2Ok72gfeBH7C6pSHj08jsvA7geN3fxp9s 7MFxLla0NsIDOSijG+vNB96pTrm4mA0Riizc0DHk5XOnhOk7szGX/es7cWzCDLBMO2 Oigk8zuPXYS00O1nzCWmIzxttXAAJht/mND7KsB69RtWjyLMdzDP+Dy7WsPt4KCkvO W+R01to3DUp4A== Received: from prgdevlinuxpatch01.amust.local (172.24.14.5) by prgmbx01.amust.local (172.24.128.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.9; Mon, 13 Jun 2022 17:54:14 +0200 From: Sergei Shtepa To: , , CC: Sergei Shtepa Subject: [PATCH 05/20] block, blksnap: interaction with sysfs Date: Mon, 13 Jun 2022 18:52:58 +0300 Message-ID: <1655135593-1900-6-git-send-email-sergei.shtepa@veeam.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1655135593-1900-1-git-send-email-sergei.shtepa@veeam.com> References: <1655135593-1900-1-git-send-email-sergei.shtepa@veeam.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.24.14.5] X-ClientProxiedBy: prgmbx01.amust.local (172.24.128.102) To prgmbx01.amust.local (172.24.128.102) X-EsetResult: clean, is OK X-EsetId: 37303A29D2A50A536D7766 X-Veeam-MMEX: True X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provides creation of a class file /sys/class/blksnap and a device file /dev/blksnap for module management. Signed-off-by: Sergei Shtepa --- drivers/block/blksnap/sysfs.c | 81 +++++++++++++++++++++++++++++++++++ drivers/block/blksnap/sysfs.h | 5 +++ 2 files changed, 86 insertions(+) create mode 100644 drivers/block/blksnap/sysfs.c create mode 100644 drivers/block/blksnap/sysfs.h diff --git a/drivers/block/blksnap/sysfs.c b/drivers/block/blksnap/sysfs.c new file mode 100644 index 000000000000..32a34609d106 --- /dev/null +++ b/drivers/block/blksnap/sysfs.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0 +#define pr_fmt(fmt) KBUILD_MODNAME "-sysfs: " fmt +#include +#include +#include +#include +#ifdef CONFIG_BLK_SNAP_DEBUG_MEMORY_LEAK +#include "memory_checker.h" +#endif +#include "sysfs.h" +#include "ctrl.h" + +static ssize_t major_show(struct class *class, struct class_attribute *attr, + char *buf) +{ + sprintf(buf, "%d", get_blk_snap_major()); + return strlen(buf); +} + +/* Declare class_attr_major */ +CLASS_ATTR_RO(major); + +static struct class *blk_snap_class; + +static struct device *blk_snap_device; + +int sysfs_init(void) +{ + struct device *dev; + int res; + + blk_snap_class = class_create(THIS_MODULE, BLK_SNAP_MODULE_NAME); + if (IS_ERR(blk_snap_class)) { + res = PTR_ERR(blk_snap_class); + + pr_err("Bad class create. errno=%d\n", abs(res)); + return res; + } + + pr_info("Create 'major' sysfs attribute\n"); + res = class_create_file(blk_snap_class, &class_attr_major); + if (res) { + pr_err("Failed to create 'major' sysfs file\n"); + + class_destroy(blk_snap_class); + blk_snap_class = NULL; + return res; + } + + dev = device_create(blk_snap_class, NULL, + MKDEV(get_blk_snap_major(), 0), NULL, + BLK_SNAP_MODULE_NAME); + if (IS_ERR(dev)) { + res = PTR_ERR(dev); + pr_err("Failed to create device, errno=%d\n", abs(res)); + + class_remove_file(blk_snap_class, &class_attr_major); + class_destroy(blk_snap_class); + blk_snap_class = NULL; + return res; + } + + blk_snap_device = dev; + return res; +} + +void sysfs_done(void) +{ + pr_info("Cleanup sysfs\n"); + + if (blk_snap_device) { + device_unregister(blk_snap_device); + blk_snap_device = NULL; + } + + if (blk_snap_class != NULL) { + class_remove_file(blk_snap_class, &class_attr_major); + class_destroy(blk_snap_class); + blk_snap_class = NULL; + } +} diff --git a/drivers/block/blksnap/sysfs.h b/drivers/block/blksnap/sysfs.h new file mode 100644 index 000000000000..b41c301fe33b --- /dev/null +++ b/drivers/block/blksnap/sysfs.h @@ -0,0 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#pragma once + +int sysfs_init(void); +void sysfs_done(void); -- 2.20.1