From patchwork Fri May 19 07:11:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Enric Balletbo i Serra X-Patchwork-Id: 9736065 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 559A16034C for ; Fri, 19 May 2017 07:12:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 334C3288A7 for ; Fri, 19 May 2017 07:12:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 269D6288B2; Fri, 19 May 2017 07:12:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9125D288EE for ; Fri, 19 May 2017 07:12:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 184E497829; Fri, 19 May 2017 07:12:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 184E497829 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dm-devel-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 184E497829 Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC6A85C54A; Fri, 19 May 2017 07:12:10 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 74EC94A48C; Fri, 19 May 2017 07:12:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4J7C8pt032558 for ; Fri, 19 May 2017 03:12:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id BB0FE1853C; Fri, 19 May 2017 07:12:08 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BD5C11866E; Fri, 19 May 2017 07:12:03 +0000 (UTC) Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83FFA80C14; Fri, 19 May 2017 07:12:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 83FFA80C14 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=enric.balletbo@collabora.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 83FFA80C14 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: eballetbo) with ESMTPSA id 166C726B3ED From: Enric Balletbo i Serra To: dm-devel@redhat.com, Alasdair Kergon Date: Fri, 19 May 2017 09:11:46 +0200 Message-Id: <20170519071146.25760-3-enric.balletbo@collabora.com> In-Reply-To: <20170519071146.25760-1-enric.balletbo@collabora.com> References: <20170519071146.25760-1-enric.balletbo@collabora.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 203 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 19 May 2017 07:12:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 19 May 2017 07:12:02 +0000 (UTC) for IP:'46.235.227.227' DOMAIN:'bhuna.collabora.co.uk' HELO:'bhuna.collabora.co.uk' FROM:'enric.balletbo@collabora.com' RCPT:'' X-RedHat-Spam-Score: 0.789 (BAYES_50, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, UNPARSEABLE_RELAY) 46.235.227.227 bhuna.collabora.co.uk 46.235.227.227 bhuna.collabora.co.uk X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: dm-devel@redhat.com Cc: Mike Snitzer , linux-lvm@redhat.com, linux-kernel@vger.kernel.org, Kees Cook , linux-doc@vger.kernel.org Subject: [dm-devel] [PATCH v8 2/2] dm ioctl: add a device mapper ioctl function. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 19 May 2017 07:12:12 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Add a dm_ioctl_cmd to issue the equivalent of a DM ioctl call in kernel. Signed-off-by: Enric Balletbo i Serra --- drivers/md/dm-ioctl.c | 50 +++++++++++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 6 ++++++ 2 files changed, 56 insertions(+) diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index d45c681..033e31d 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -2011,3 +2011,53 @@ int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid) return r; } + +/** + * dm_ioctl_cmd - Device mapper ioctl's + * @command: ioctl command + * @param: Pointer to device mapped ioctl struct + */ +int dm_ioctl_cmd(uint command, struct dm_ioctl *param) +{ + int r = 0; + int ioctl_flags; + unsigned int cmd; + ioctl_fn fn = NULL; + size_t input_param_size; + struct file *filp = NULL; + + if (_IOC_TYPE(command) != DM_IOCTL) + return -ENOTTY; + + /* DM_DEV_ARM_POLL is not supported */ + if (command == DM_DEV_ARM_POLL) + return -EINVAL; + + cmd = _IOC_NR(command); + + /* + * Nothing more to do for the version command. + */ + if (cmd == DM_VERSION_CMD) + return 0; + + fn = lookup_ioctl(cmd, &ioctl_flags); + if (!fn) { + DMWARN("dm_ioctl: unknown command 0x%x", command); + return -ENOTTY; + } + + input_param_size = param->data_size; + r = validate_params(cmd, param); + if (r) + return r; + + param->data_size = sizeof(*param); + r = fn(filp, param, input_param_size); + + if (unlikely(param->flags & DM_BUFFER_FULL_FLAG) && + unlikely(ioctl_flags & IOCTL_FLAGS_NO_PARAMS)) + DMERR("ioctl %d tried to output some data but has IOCTL_FLAGS_NO_PARAMS set", cmd); + + return r; +} diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index f4c639c..f81ba42 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -12,6 +12,7 @@ #include #include #include +#include struct dm_dev; struct dm_target; @@ -446,6 +447,11 @@ int dm_noflush_suspending(struct dm_target *ti); void dm_accept_partial_bio(struct bio *bio, unsigned n_sectors); union map_info *dm_get_rq_mapinfo(struct request *rq); +/* + * Device mapper ioctl function. + */ +int dm_ioctl_cmd(unsigned int command, struct dm_ioctl *param); + struct queue_limits *dm_get_queue_limits(struct mapped_device *md); /*