From patchwork Sat Jan 18 00:15:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Heift X-Patchwork-Id: 3507681 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 83B3C9F390 for ; Sat, 18 Jan 2014 00:16:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AC2232017D for ; Sat, 18 Jan 2014 00:16:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D34462017B for ; Sat, 18 Jan 2014 00:16:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752836AbaARAQ0 (ORCPT ); Fri, 17 Jan 2014 19:16:26 -0500 Received: from mail-ee0-f50.google.com ([74.125.83.50]:48473 "EHLO mail-ee0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752766AbaARAQW (ORCPT ); Fri, 17 Jan 2014 19:16:22 -0500 Received: by mail-ee0-f50.google.com with SMTP id d17so2442654eek.9 for ; Fri, 17 Jan 2014 16:16:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Z0CNk0P7vbhC88U4c6ElrnArjOXgDGmcYXI6DE/wkWQ=; b=KTDZsdcaxF3ZtcHguCUb0//y11oBMxekLzMBQu+xX3zDuHgnHl3BGbMUvq+DPUedkl GFtxJ/UGWTxAryWHO5IMQMQgbyRyA8gMPlo5NB5TekZ7UYIe3g992D+0BUJhWtRzJAvp OjEzITqkzjnZz7n5yM+Uyfj/rJvVrSM81VWjU3LsloCyV4uX9FihQA4xfpKw2cBu2pfu j9a1lEP/NN30uyAMNN/WvDqP8wAxHwnc7/MRaNFy9UkoacsvStBlDcmK38xkPsCPPmso 6d631iIv4d0n8MTq7a7yzgtan+hWgBGNIDGgiAe/tVzOsAw+mbGXl6sEd/iJTqnHX4yF C5tA== X-Gm-Message-State: ALoCoQl6s4OtcYZqm7ew7g1hIspbpyWzf38rZVuTTIQK004/CJ7JZseHGEumNK9coDXaqNxEbecw X-Received: by 10.15.48.201 with SMTP id h49mr5275538eew.43.1390004181068; Fri, 17 Jan 2014 16:16:21 -0800 (PST) Received: from localhost (host-115-115.kawo1.rwth-aachen.de. [134.130.115.115]) by mx.google.com with ESMTPSA id o13sm30864540eex.19.2014.01.17.16.16.20 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Fri, 17 Jan 2014 16:16:20 -0800 (PST) From: Gerhard Heift To: linux-btrfs@vger.kernel.org Subject: [PATCH RFC 4/5] btrfs: new ioctl TREE_SEARCH_V2 Date: Sat, 18 Jan 2014 01:15:52 +0100 Message-Id: <1390004153-4228-5-git-send-email-Gerhard@Heift.Name> X-Mailer: git-send-email 1.8.5.3 In-Reply-To: <1390004153-4228-1-git-send-email-Gerhard@Heift.Name> References: <20140116150710.GL6498@suse.cz> <1390004153-4228-1-git-send-email-Gerhard@Heift.Name> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This new ioctl call allows the user to supply a buffer of varying size in which a tree search can store its results. This is much more flexible if you want to receive items which are larger than the current fixed buffer of 3992 bytes or if you want to fetch mor item at once. Currently the buffer is limited to 32 pages. Signed-off-by: Gerhard Heift --- fs/btrfs/ioctl.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/btrfs.h | 8 ++++++++ 2 files changed, 56 insertions(+) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 9fa222d..cc82bd9 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2032,6 +2032,52 @@ static noinline int btrfs_ioctl_tree_search(struct file *file, return ret; } +static noinline int btrfs_ioctl_tree_search_v2(struct file *file, + void __user *argp) +{ + struct btrfs_ioctl_search_args_v2 *args; + struct inode *inode; + int ret; + char *buf; + size_t buf_size; + + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + + /* copy search header and buffer size */ + args = memdup_user(argp, sizeof(*args)); + if (IS_ERR(args)) + return PTR_ERR(args); + + buf_size = args->buf_size; + + if (buf_size < sizeof(struct btrfs_ioctl_search_header)) { + kfree(args); + return -ENOMEM; + } + + /* limit memory */ + if (buf_size > PAGE_SIZE * 32) + buf_size = PAGE_SIZE * 32; + + buf = memdup_user(argp->buf, buf_size); + if (IS_ERR(buf)) { + kfree(args); + return PTR_ERR(buf); + } + + inode = file_inode(file); + ret = search_ioctl(inode, &args->key, buf_size, buf); + if (ret == 0 && ( + copy_to_user(argp, args, sizeof(*args)) || + copy_to_user(argp->buf, buf, buf_size) + )) + ret = -EFAULT; + kfree(buf); + kfree(args); + return ret; +} + /* * Search INODE_REFs to identify path name of 'dirid' directory * in a 'tree_id' tree. and sets path name to 'name'. @@ -4777,6 +4823,8 @@ long btrfs_ioctl(struct file *file, unsigned int return btrfs_ioctl_trans_end(file); case BTRFS_IOC_TREE_SEARCH: return btrfs_ioctl_tree_search(file, argp); + case BTRFS_IOC_TREE_SEARCH_V2: + return btrfs_ioctl_tree_search_v2(file, argp); case BTRFS_IOC_INO_LOOKUP: return btrfs_ioctl_ino_lookup(file, argp); case BTRFS_IOC_INO_PATHS: diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index 1b8a0f4..6ba0d0f 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -301,6 +301,12 @@ struct btrfs_ioctl_search_args { char buf[BTRFS_SEARCH_ARGS_BUFSIZE]; }; +struct btrfs_ioctl_search_args_v2 { + struct btrfs_ioctl_search_key key; + size_t buf_size; + char buf[0]; +}; + struct btrfs_ioctl_clone_range_args { __s64 src_fd; __u64 src_offset, src_length; @@ -553,6 +559,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) struct btrfs_ioctl_defrag_range_args) #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \ struct btrfs_ioctl_search_args) +#define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \ + struct btrfs_ioctl_search_args_v2) #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \ struct btrfs_ioctl_ino_lookup_args) #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)