Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1422377pxb; Thu, 4 Mar 2021 10:51:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwSkkJ9EPCwBheaUEfKnsuBIVTJZqoobz0SZSMe2c2JeefLndDoOGQFYPIRYAcCTn+YFoaw X-Received: by 2002:aa7:c345:: with SMTP id j5mr5868278edr.338.1614883864916; Thu, 04 Mar 2021 10:51:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614883864; cv=none; d=google.com; s=arc-20160816; b=SRg/4XH27wpJ0igsMNylNQuIl1lEd8xuDqFFA+YlgHmGf5kqO0g7yyELlLCrAJ8do+ g+xdjRq5pafcBfrex773aCbD6V9i3f2QCmiWZx5uiNzSlneEd9uPvo9YUOTsB1JYRWGh Tw8nVpuAD4hAHM61oSJ5211hHIogVUO5aaKbxoMN0lCLbd8jPjC5A6OgR3kmA3NpJfby kC7YAtelpTSnH/aZ02aFp/PIIMnGuTpbj69bkn/s5A4Wb+06fm0aJNSY4EMp1XAQJ4aq 4S940ZU9fdsfQ9+FO85ioOqGBUXOEsLMadVVl+KzVlyk18zx1YoVzwsoLykqSqivK+3V NcFA== 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=TYaXRqDRCEs2PMBaoiW/qVmPuFZVeQxVq43GzQdhb/o=; b=RoC0Al62ieERpa70fRzLMGd4NQVZaSRd3s1zs+glcnMZDUBmvmiWWfBxz0gBSdAGmR iPaDU3lkxdiHF8MnyOMce3mWVpAbKVZ1mwbKHPwuE+H9Mhwe039zkltH5jJ50KgHARM9 b83i9ebLW+VQkTOXyYqhceYfuscgN4gCE/n74eFR3AY6FWxoJPrijlBNsx863xNRUy54 xqQP+TQ5HGAfg0D8b6E1/zPHZV5OwxHrR14ZIs4BlJLpxj7DMXycLgAzkcbw24C10cCI 7HY7U4cmFGAfGXBFJ7L1VR+RZgwXwAvyTGPOdukpKpPmarlsBPSUxcAmOqIomzTm69Le sPgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@veeam.com header.s=mx4 header.b=NNS50kou; 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=REJECT sp=REJECT dis=NONE) header.from=veeam.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m7si177700edj.442.2021.03.04.10.50.42; Thu, 04 Mar 2021 10:51:04 -0800 (PST) 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=@veeam.com header.s=mx4 header.b=NNS50kou; 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=REJECT sp=REJECT dis=NONE) header.from=veeam.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239088AbhCDRPD (ORCPT + 99 others); Thu, 4 Mar 2021 12:15:03 -0500 Received: from mx4.veeam.com ([104.41.138.86]:54496 "EHLO mx4.veeam.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231374AbhCDROf (ORCPT ); Thu, 4 Mar 2021 12:14:35 -0500 Received: from mail.veeam.com (prgmbx01.amust.local [172.24.0.171]) (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 354FE114A94; Thu, 4 Mar 2021 20:13:52 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=veeam.com; s=mx4; t=1614878032; bh=TYaXRqDRCEs2PMBaoiW/qVmPuFZVeQxVq43GzQdhb/o=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=NNS50koujeOmLv8ytRwRnkDk+8Dj3tIXlG34BNdzZs6izVoTx63w65e9eR7+pazYP xkRXe5e/cxbvHVtu82NyhWSvSm4tD82EM9mvGH/qUf8Zd/w8qB6yf/JQDCpLpVGte3 ZUC8oaZTlDkOLDwd6NJrCdIzAWvchLWLLe4fvj9k= Received: from prgdevlinuxpatch01.amust.local (172.24.14.5) by prgmbx01.amust.local (172.24.0.171) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.721.2; Thu, 4 Mar 2021 18:13:50 +0100 From: Sergei Shtepa To: , , , , , CC: , Subject: [PATCH 1/1] dm: adds an IOCTL to work with device-filters Date: Thu, 4 Mar 2021 20:13:38 +0300 Message-ID: <1614878018-23278-2-git-send-email-sergei.shtepa@veeam.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1614878018-23278-1-git-send-email-sergei.shtepa@veeam.com> References: <1614878018-23278-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: prgmbx02.amust.local (172.24.0.172) To prgmbx01.amust.local (172.24.0.171) X-EsetResult: clean, is OK X-EsetId: 37303A29D2A50B58637265 X-Veeam-MMEX: True Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The four simplest IOCTL's allow to create new filters, remove them and pass control commands specific to each target. Signed-off-by: Sergei Shtepa --- drivers/md/Makefile | 2 +- drivers/md/dm-ioctl.c | 22 ++++++++++++++++++++++ drivers/md/flt-ctl.c | 25 +++++++++++++++++++++++++ drivers/md/flt-ctl.h | 10 ++++++++++ include/uapi/linux/dm-ioctl.h | 18 ++++++++++++++++-- 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 drivers/md/flt-ctl.c create mode 100644 drivers/md/flt-ctl.h diff --git a/drivers/md/Makefile b/drivers/md/Makefile index bd5b38bee82e..1b650950adc1 100644 --- a/drivers/md/Makefile +++ b/drivers/md/Makefile @@ -5,7 +5,7 @@ dm-mod-y += dm.o dm-table.o dm-target.o dm-linear.o dm-stripe.o \ dm-ioctl.o dm-io.o dm-kcopyd.o dm-sysfs.o dm-stats.o \ - dm-rq.o dm-interposer.o + dm-rq.o dm-interposer.o flt-ctl.o dm-multipath-y += dm-path-selector.o dm-mpath.o dm-historical-service-time-y += dm-ps-historical-service-time.o dm-io-affinity-y += dm-ps-io-affinity.o diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 2bcb316144a1..f5f0c9377752 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -6,6 +6,7 @@ */ #include "dm-core.h" +#include "flt-control.h" #include #include @@ -1700,6 +1701,27 @@ static ioctl_fn lookup_ioctl(unsigned int cmd, int *ioctl_flags) {DM_GET_TARGET_VERSION, 0, get_target_version}, }; + static const struct { + int cmd; + int flags; + ioctl_fn fn; + } _flt_ioctls[] = { + {FLT_REMOVE_ALL_CMD, IOCTL_FLAGS_NO_PARAMS | IOCTL_FLAGS_ISSUE_GLOBAL_EVENT, filter_remove_all}, + {FLT_CREATE_CMD, IOCTL_FLAGS_NO_PARAMS | IOCTL_FLAGS_ISSUE_GLOBAL_EVENT, filter_create}, + {FLT_REMOVE_CMD, IOCTL_FLAGS_NO_PARAMS | IOCTL_FLAGS_ISSUE_GLOBAL_EVENT, filter_remove}, + {FLT_CONTROL_CMD, 0, filter_control}, + }; + + if (cmd >= DM_FILTER_CMD) { + cmd -= DM_FILTER_CMD; + + if (unlikely(cmd >= ARRAY_SIZE(_flt_ioctls))) + return NULL; + + *ioctl_flags = _flt_ioctls[cmd].flags; + return _flt_ioctls[cmd].fn; + } + if (unlikely(cmd >= ARRAY_SIZE(_ioctls))) return NULL; diff --git a/drivers/md/flt-ctl.c b/drivers/md/flt-ctl.c new file mode 100644 index 000000000000..aadf04be1438 --- /dev/null +++ b/drivers/md/flt-ctl.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include + +#include "flt-ctl.h" + +int filter_remove_all(struct file *filp, struct dm_ioctl *param, size_t param_size) +{ + return 0; +}; +int filter_create(struct file *filp, struct dm_ioctl *param, size_t param_size) +{ + return 0; +}; +int filter_remove(struct file *filp, struct dm_ioctl *param, size_t param_size) +{ + return 0; +}; +int filter_control(struct file *filp, struct dm_ioctl *param, size_t param_size) +{ + return 0; +}; + diff --git a/drivers/md/flt-ctl.h b/drivers/md/flt-ctl.h new file mode 100644 index 000000000000..61a80184abae --- /dev/null +++ b/drivers/md/flt-ctl.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: LGPL-2.0+ WITH Linux-syscall-note */ +#ifndef FLT_CTL_H +#define FLT_CTL_H + +int filter_remove_all(struct file *filp, struct dm_ioctl *param, size_t param_size); +int filter_create(struct file *filp, struct dm_ioctl *param, size_t param_size); +int filter_remove(struct file *filp, struct dm_ioctl *param, size_t param_size); +int filter_control(struct file *filp, struct dm_ioctl *param, size_t param_size); + +#endif diff --git a/include/uapi/linux/dm-ioctl.h b/include/uapi/linux/dm-ioctl.h index e942e7d7c594..012e16761ba9 100644 --- a/include/uapi/linux/dm-ioctl.h +++ b/include/uapi/linux/dm-ioctl.h @@ -16,6 +16,7 @@ #define DM_MAX_TYPE_NAME 16 #define DM_NAME_LEN 128 #define DM_UUID_LEN 129 +#define DM_FILTER_CMD 128 /* First filters command */ /* * A traditional ioctl interface for the device mapper. @@ -244,6 +245,14 @@ enum { DM_DEV_SET_GEOMETRY_CMD, DM_DEV_ARM_POLL_CMD, DM_GET_TARGET_VERSION_CMD, + + /* Reserved space for additional DM ioctl */ + + /* Filters commands */ + FLT_REMOVE_ALL_CMD = DM_FILTER_CMD, /* Cleanup all filters */ + FLT_CREATE_CMD, /* Create new filter */ + FLT_REMOVE_CMD, /* Remove filter */ + FLT_CONTROL_CMD, /* Send a filter-specific command */ }; #define DM_IOCTL 0xfd @@ -271,10 +280,15 @@ enum { #define DM_TARGET_MSG _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, struct dm_ioctl) #define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl) +#define FLT_REMOVE_ALL _IOWR(DM_IOCTL, FLT_REMOVE_ALL_CMD, struct dm_ioctl) +#define FLT_CREATE _IOWR(DM_IOCTL, FLT_CREATE_CMD, struct dm_ioctl) +#define FLT_REMOVE _IOWR(DM_IOCTL, FLT_REMOVE_CMD, struct dm_ioctl) +#define FLT_CONTROL _IOWR(DM_IOCTL, FLT_CONTROL_CMD, struct dm_ioctl) + #define DM_VERSION_MAJOR 4 -#define DM_VERSION_MINOR 43 +#define DM_VERSION_MINOR 44 #define DM_VERSION_PATCHLEVEL 0 -#define DM_VERSION_EXTRA "-ioctl (2020-10-01)" +#define DM_VERSION_EXTRA "-ioctl (2021-03-03)" /* Status bits */ #define DM_READONLY_FLAG (1 << 0) /* In/Out */ -- 2.20.1