From patchwork Wed Nov 27 03:55:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygo Blaxell X-Patchwork-Id: 11263407 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AAC31875 for ; Wed, 27 Nov 2019 04:44:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 027E72075C for ; Wed, 27 Nov 2019 04:44:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbfK0EoL (ORCPT ); Tue, 26 Nov 2019 23:44:11 -0500 Received: from james.kirk.hungrycats.org ([174.142.39.145]:48386 "EHLO james.kirk.hungrycats.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727016AbfK0EoK (ORCPT ); Tue, 26 Nov 2019 23:44:10 -0500 X-Envelope-Mail-From: zblaxell@waya.furryterror.org X-Envelope-Mail-From: zblaxell@waya.furryterror.org Received: from waya.furryterror.org (waya.vpn7.hungrycats.org [10.132.226.63]) by james.kirk.hungrycats.org (Postfix) with ESMTP id BA27E4F8A76; Tue, 26 Nov 2019 23:37:44 -0500 (EST) Received: from zblaxell by waya.furryterror.org with local (Exim 4.92) (envelope-from ) id 1iZp5E-0003PD-Bl; Tue, 26 Nov 2019 23:37:44 -0500 From: Zygo Blaxell To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/6] btrfs-progs: ioctl-test: add LOGICAL_INO_V2 Date: Tue, 26 Nov 2019 22:55:04 -0500 Message-Id: <20191127035509.15011-2-ce3g8jdj@umail.furryterror.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> References: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Same as LOGICAL_INO, except a different magic number. Signed-off-by: Zygo Blaxell --- ioctl-test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ioctl-test.c b/ioctl-test.c index 65d584be..a79a13b0 100644 --- a/ioctl-test.c +++ b/ioctl-test.c @@ -82,7 +82,8 @@ ONE(BTRFS_IOC_GET_FEATURES) \ ONE(BTRFS_IOC_SET_FEATURES) \ ONE(BTRFS_IOC_GET_SUPPORTED_FEATURES) \ - ONE(BTRFS_IOC_RM_DEV_V2) + ONE(BTRFS_IOC_RM_DEV_V2) \ + ONE(BTRFS_IOC_LOGICAL_INO_V2) #define LIST \ LIST_BASE \ @@ -160,6 +161,7 @@ static struct ioctl_number expected_list[] = { { BTRFS_IOC_SET_FEATURES, 0x0040309439 }, { BTRFS_IOC_GET_SUPPORTED_FEATURES, 0x0080489439 }, { BTRFS_IOC_RM_DEV_V2, 0x005000943a }, + { BTRFS_IOC_LOGICAL_INO_V2, 0x00c038943b }, }; static struct btrfs_ioctl_vol_args used_vol_args __attribute__((used)); From patchwork Wed Nov 27 03:55:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygo Blaxell X-Patchwork-Id: 11263409 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 381D51872 for ; Wed, 27 Nov 2019 04:44:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 211B32075C for ; Wed, 27 Nov 2019 04:44:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727254AbfK0EoL (ORCPT ); Tue, 26 Nov 2019 23:44:11 -0500 Received: from james.kirk.hungrycats.org ([174.142.39.145]:48384 "EHLO james.kirk.hungrycats.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727017AbfK0EoK (ORCPT ); Tue, 26 Nov 2019 23:44:10 -0500 X-Envelope-Mail-From: zblaxell@waya.furryterror.org X-Envelope-Mail-From: zblaxell@waya.furryterror.org Received: from waya.furryterror.org (waya.vpn7.hungrycats.org [10.132.226.63]) by james.kirk.hungrycats.org (Postfix) with ESMTP id ED2D54F8A77; Tue, 26 Nov 2019 23:37:44 -0500 (EST) Received: from zblaxell by waya.furryterror.org with local (Exim 4.92) (envelope-from ) id 1iZp5E-0003PF-E0; Tue, 26 Nov 2019 23:37:44 -0500 From: Zygo Blaxell To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/6] btrfs-progs: libbtrfsutil: add LOGICAL_INO_V2 Date: Tue, 26 Nov 2019 22:55:05 -0500 Message-Id: <20191127035509.15011-3-ce3g8jdj@umail.furryterror.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> References: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Update the args structure, add the flags constant and the ioctl magic number. Signed-off-by: Zygo Blaxell --- libbtrfsutil/btrfs.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libbtrfsutil/btrfs.h b/libbtrfsutil/btrfs.h index 944d5013..daa769fd 100644 --- a/libbtrfsutil/btrfs.h +++ b/libbtrfsutil/btrfs.h @@ -624,10 +624,14 @@ struct btrfs_ioctl_ino_path_args { struct btrfs_ioctl_logical_ino_args { __u64 logical; /* in */ __u64 size; /* in */ - __u64 reserved[4]; + __u64 reserved[3]; + __u64 flags; /* in */ /* struct btrfs_data_container *inodes; out */ __u64 inodes; }; +/* Return every ref to the extent, not just those containing logical block. + * Requires logical == extent bytenr. */ +#define BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET (1ULL << 0) enum btrfs_dev_stat_values { /* disk I/O failure stats */ @@ -927,6 +931,8 @@ enum btrfs_err_code { struct btrfs_ioctl_feature_flags[3]) #define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \ struct btrfs_ioctl_vol_args_v2) +#define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, \ + struct btrfs_ioctl_logical_ino_args) #define BTRFS_IOC_GET_SUBVOL_INFO _IOR(BTRFS_IOCTL_MAGIC, 60, \ struct btrfs_ioctl_get_subvol_info_args) #define BTRFS_IOC_GET_SUBVOL_ROOTREF _IOWR(BTRFS_IOCTL_MAGIC, 61, \ From patchwork Wed Nov 27 03:55:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygo Blaxell X-Patchwork-Id: 11263401 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A98DB6C1 for ; Wed, 27 Nov 2019 04:44:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 919EB207DD for ; Wed, 27 Nov 2019 04:44:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727010AbfK0EoK (ORCPT ); Tue, 26 Nov 2019 23:44:10 -0500 Received: from james.kirk.hungrycats.org ([174.142.39.145]:48372 "EHLO james.kirk.hungrycats.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726822AbfK0EoK (ORCPT ); Tue, 26 Nov 2019 23:44:10 -0500 X-Envelope-Mail-From: zblaxell@waya.furryterror.org X-Envelope-Mail-From: zblaxell@waya.furryterror.org Received: from waya.furryterror.org (waya.vpn7.hungrycats.org [10.132.226.63]) by james.kirk.hungrycats.org (Postfix) with ESMTP id 6F1EE4F8A79; Tue, 26 Nov 2019 23:37:45 -0500 (EST) Received: from zblaxell by waya.furryterror.org with local (Exim 4.92) (envelope-from ) id 1iZp5E-0003PQ-QX; Tue, 26 Nov 2019 23:37:44 -0500 From: Zygo Blaxell To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/6] btrfs-progs: inspect: add support for LOGICAL_INO_V2 ioctl Date: Tue, 26 Nov 2019 22:55:07 -0500 Message-Id: <20191127035509.15011-5-ce3g8jdj@umail.furryterror.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> References: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Increase the maximum buffer size to SZ_16M. Add an option (-o) to set the ..._IGNORE_OFFSET flag. If the buffer size is greater than 64K or the IGNORE_OFFSET option is used, call ioctl V2; otherwise, use ioctl V1 to be compatible with older kernels. Signed-off-by: Zygo Blaxell --- cmds/inspect.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/cmds/inspect.c b/cmds/inspect.c index 758b6e60..81eb8125 100644 --- a/cmds/inspect.c +++ b/cmds/inspect.c @@ -126,14 +126,17 @@ static int cmd_inspect_inode_resolve(const struct cmd_struct *cmd, static DEFINE_SIMPLE_COMMAND(inspect_inode_resolve, "inode-resolve"); static const char * const cmd_inspect_logical_resolve_usage[] = { - "btrfs inspect-internal logical-resolve [-Pv] [-s bufsize] ", + "btrfs inspect-internal logical-resolve [-Pvo] [-s bufsize] ", "Get file system paths for the given logical address", "", "-P skip the path resolving and print the inodes instead", "-v verbose mode", + "-o ignore offsets when matching references (requires v2 ioctl", + " support in the kernel)", "-s bufsize set inode container's size. This is used to increase inode", " container's size in case it is not enough to read all the ", - " resolved results. The max value one can set is 64k", + " resolved results. The max value one can set is 64k with the", + " v1 ioctl. Sizes over 64k will use the v2 ioctl.", NULL }; @@ -152,10 +155,12 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd, char full_path[PATH_MAX]; char *path_ptr; DIR *dirstream = NULL; + u64 flags = 0; + unsigned long request = BTRFS_IOC_LOGICAL_INO; optind = 0; while (1) { - int c = getopt(argc, argv, "Pvs:"); + int c = getopt(argc, argv, "Pvos:"); if (c < 0) break; @@ -166,6 +171,9 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd, case 'v': verbose = 1; break; + case 'o': + flags |= BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET; + break; case 's': size = arg_strtou64(optarg); break; @@ -177,14 +185,18 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd, if (check_argc_exact(argc - optind, 2)) return 1; - size = min(size, (u64)SZ_64K); + size = min(size, (u64)SZ_16M); inodes = malloc(size); if (!inodes) return 1; + if (size > SZ_64K || flags != 0) + request = BTRFS_IOC_LOGICAL_INO_V2; + memset(inodes, 0, sizeof(*inodes)); loi.logical = arg_strtou64(argv[optind]); loi.size = size; + loi.flags = flags; loi.inodes = ptr_to_u64(inodes); fd = btrfs_open_dir(argv[optind + 1], &dirstream, 1); @@ -193,7 +205,7 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd, goto out; } - ret = ioctl(fd, BTRFS_IOC_LOGICAL_INO, &loi); + ret = ioctl(fd, request, &loi); if (ret < 0) { error("logical ino ioctl: %m"); goto out; From patchwork Wed Nov 27 03:55:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygo Blaxell X-Patchwork-Id: 11263405 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0ED515AB for ; Wed, 27 Nov 2019 04:44:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D86E02075C for ; Wed, 27 Nov 2019 04:44:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726983AbfK0EoK (ORCPT ); Tue, 26 Nov 2019 23:44:10 -0500 Received: from james.kirk.hungrycats.org ([174.142.39.145]:48368 "EHLO james.kirk.hungrycats.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726546AbfK0EoK (ORCPT ); Tue, 26 Nov 2019 23:44:10 -0500 X-Greylist: delayed 379 seconds by postgrey-1.27 at vger.kernel.org; Tue, 26 Nov 2019 23:44:09 EST X-Envelope-Mail-From: zblaxell@waya.furryterror.org X-Envelope-Mail-From: zblaxell@waya.furryterror.org Received: from waya.furryterror.org (waya.vpn7.hungrycats.org [10.132.226.63]) by james.kirk.hungrycats.org (Postfix) with ESMTP id 4CF294F8A7A; Tue, 26 Nov 2019 23:37:45 -0500 (EST) Received: from zblaxell by waya.furryterror.org with local (Exim 4.92) (envelope-from ) id 1iZp5E-0003PU-UZ; Tue, 26 Nov 2019 23:37:44 -0500 From: Zygo Blaxell To: linux-btrfs@vger.kernel.org Subject: [PATCH 5/6] btrfs-progs: inspect: increase logical-resolve default buffer size to 64K Date: Tue, 26 Nov 2019 22:55:08 -0500 Message-Id: <20191127035509.15011-6-ce3g8jdj@umail.furryterror.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> References: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Filesystems with nontrivial snapshots or dedupe will easily overflow a 4K buffer. Bump the size up to the largest size supported by the V1 ioctl. Signed-off-by: Zygo Blaxell --- cmds/inspect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds/inspect.c b/cmds/inspect.c index 81eb8125..c3c41905 100644 --- a/cmds/inspect.c +++ b/cmds/inspect.c @@ -151,7 +151,7 @@ static int cmd_inspect_logical_resolve(const struct cmd_struct *cmd, int bytes_left; struct btrfs_ioctl_logical_ino_args loi; struct btrfs_data_container *inodes; - u64 size = 4096; + u64 size = SZ_64K; char full_path[PATH_MAX]; char *path_ptr; DIR *dirstream = NULL; From patchwork Wed Nov 27 03:55:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zygo Blaxell X-Patchwork-Id: 11263403 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D21C41863 for ; Wed, 27 Nov 2019 04:44:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B070D2075C for ; Wed, 27 Nov 2019 04:44:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726990AbfK0EoK (ORCPT ); Tue, 26 Nov 2019 23:44:10 -0500 Received: from james.kirk.hungrycats.org ([174.142.39.145]:48374 "EHLO james.kirk.hungrycats.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726634AbfK0EoK (ORCPT ); Tue, 26 Nov 2019 23:44:10 -0500 X-Envelope-Mail-From: zblaxell@waya.furryterror.org X-Envelope-Mail-From: zblaxell@waya.furryterror.org Received: from waya.furryterror.org (waya.vpn7.hungrycats.org [10.132.226.63]) by james.kirk.hungrycats.org (Postfix) with ESMTP id 7D8B74F8A7B; Tue, 26 Nov 2019 23:37:45 -0500 (EST) Received: from zblaxell by waya.furryterror.org with local (Exim 4.92) (envelope-from ) id 1iZp5F-0003PZ-2q; Tue, 26 Nov 2019 23:37:45 -0500 From: Zygo Blaxell To: linux-btrfs@vger.kernel.org Subject: [PATCH 6/6] btrfs-progs: inspect-internal: document new logical-resolve options and kernel requirements Date: Tue, 26 Nov 2019 22:55:09 -0500 Message-Id: <20191127035509.15011-7-ce3g8jdj@umail.furryterror.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> References: <20191127035509.15011-1-ce3g8jdj@umail.furryterror.org> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Document the new options requiring the V2 ioctl and the increased default buffer size. Signed-off-by: Zygo Blaxell --- Documentation/btrfs-inspect-internal.asciidoc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/btrfs-inspect-internal.asciidoc b/Documentation/btrfs-inspect-internal.asciidoc index 2abf044a..39e41e74 100644 --- a/Documentation/btrfs-inspect-internal.asciidoc +++ b/Documentation/btrfs-inspect-internal.asciidoc @@ -125,7 +125,7 @@ at 'path', ie. all hardlinks -v:::: verbose mode, print count of returned paths and ioctl() return value -*logical-resolve* [-Pv] [-s ] :: +*logical-resolve* [-Pvo] [-s ] :: (needs root privileges) + resolve paths to all files at given 'logical' address in the linear filesystem space @@ -136,8 +136,10 @@ resolve paths to all files at given 'logical' address in the linear filesystem s skip the path resolving and print the inodes instead -v:::: verbose mode, print count of returned paths and all ioctl() return values +-o:::: +ignore offsets, find all references to an extent instead of a single block. Requires kernel support for the V2 ioctl. -s :::: -set internal buffer for storing the file names to 'bufsize', default is 4096, maximum 64k +set internal buffer for storing the file names to 'bufsize', default is 64k, maximum 16m. Buffer sizes over 64K require kernel support for the V2 ioctl. *min-dev-size* [options] :: (needs root privileges)