From patchwork Thu Jul 7 09:43:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 9218767 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 9CB7D60574 for ; Thu, 7 Jul 2016 10:42:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FE5928848 for ; Thu, 7 Jul 2016 10:42:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 845502884B; Thu, 7 Jul 2016 10:42:33 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2043728848 for ; Thu, 7 Jul 2016 10:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752649AbcGGKm3 (ORCPT ); Thu, 7 Jul 2016 06:42:29 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35049 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752621AbcGGKm1 (ORCPT ); Thu, 7 Jul 2016 06:42:27 -0400 Received: by mail-pf0-f196.google.com with SMTP id t190so1500896pfb.2 for ; Thu, 07 Jul 2016 03:42:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=pUjy+1d3ayQOb0q0HKFX+O4i89854U83l9PQ2e5ZBJs=; b=xvyY9f+1Vu1npIx4mTSu/J/Hi2W94gmGV8i+H9xUBJ7W7lg+tJEFXrm4vuPPW50Oqr kDWwRPy5sjy5M3YJCmOHa5MP/YW39fI4nIIoHSXyy5is6zhYAICK/7xZZiZQRZWPdjFG 6EfKcgJZ8+kgKj5NS+mjuQtPL+y5okcImiseCBaH/QFyFC6Q+ZjedZ01K2wXWjA8rvey X4JrIgasIH6z9YA1rt77TcavXIMYZKYpRu7uTX3EZ2GLzRRooVJpxs6sG7A3J9BLt7D5 IQGwPZIE6GzyhLH5BcaDdS8lXokJk+K2YzUebNV3FJXD4pvx4GcjgkG/lkKT6JX+NsTS 9pag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=pUjy+1d3ayQOb0q0HKFX+O4i89854U83l9PQ2e5ZBJs=; b=EzL1wnUblkGQJvJQhUGZujMyX9SnTlmUlpSt7WbRfvcXierHDyArvAy/TSirn17QCw rzjdqoU6Ld7bunX/3nM/hHrGBOFeY91EoSfnLWpWFbieBTNGu5SPThY6124opJr1Ojtu BeueBLWkrOgZR6nWnptvEp9NqBUxiEO8NolLMdW1GUZW+5Qfqw4t3s7URY1d7S2jzJin 1o77bKaBLGKclr4p9fgCbHd6VnGO7gJ4GO7PtI0D+YQ3bqoFmez0wG0gjUmfEG/7e6RU kfZHHHjkHRpSF8w7KQdp6lMEtIQ1itwpF4ohu/0ca+u5xc/MnC6Y8/aToJV17EgPXwIV T8Qg== X-Gm-Message-State: ALyK8tKFX1lku/kaiKDnBR/IALXkLefoOQ8HMM/JU2T109QQELxLeqbAf9w9/DkwU8F4Jw== X-Received: by 10.98.19.77 with SMTP id b74mr4049629pfj.145.1467888147072; Thu, 07 Jul 2016 03:42:27 -0700 (PDT) Received: from localhost.localdomain ([45.32.20.47]) by smtp.gmail.com with ESMTPSA id bw1sm3780138pab.17.2016.07.07.03.42.23 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Jul 2016 03:42:26 -0700 (PDT) From: Wang Shilong To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, wangshilong1991@gmail.com Subject: [PATCH v2] btrfs-progs: du: fix to skip not btrfs dir/file Date: Thu, 7 Jul 2016 18:43:38 +0900 Message-Id: <1467884618-29630-1-git-send-email-wangshilong1991@gmail.com> X-Mailer: git-send-email 2.7.4 (Apple Git-66) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 'btrfs file du' is a very useful tool to watch my system file usage information with snapshot aware. when trying to run following commands: [root@localhost btrfs-progs]# btrfs file du / Total Exclusive Set shared Filename ERROR: Failed to lookup root id - Inappropriate ioctl for device ERROR: cannot check space of '/': Unknown error -1 and My Filesystem looks like this: [root@localhost btrfs-progs]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 16G 0 16G 0% /dev tmpfs tmpfs 16G 368K 16G 1% /dev/shm tmpfs tmpfs 16G 1.4M 16G 1% /run tmpfs tmpfs 16G 0 16G 0% /sys/fs/cgroup /dev/sda3 btrfs 60G 19G 40G 33% / tmpfs tmpfs 16G 332K 16G 1% /tmp /dev/sdc btrfs 2.8T 166G 1.7T 9% /data /dev/sda2 xfs 2.0G 452M 1.6G 23% /boot /dev/sda1 vfat 1.9G 11M 1.9G 1% /boot/efi tmpfs tmpfs 3.2G 24K 3.2G 1% /run/user/1000 So I installed Btrfs as my root partition, but boot partition can be other fs. We can Let btrfs tool aware of this is not a btrfs file or directory and skip those files, so that someone like me could just run 'btrfs file du /' to scan all btrfs filesystems. After patch, it will look like: Total Exclusive Set shared Filename 0.00B 0.00B - //root/.bash_logout 0.00B 0.00B - //root/.bash_profile 0.00B 0.00B - //root/.bashrc 0.00B 0.00B - //root/.cshrc 0.00B 0.00B - //root/.tcshrc This works for me to analysis system usage and analysis performaces. Signed-off-by: Wang Shilong --- v1->v2: remove extra unnecessary messages output --- cmds-fi-du.c | 8 +++++++- cmds-inspect.c | 2 +- utils.c | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmds-fi-du.c b/cmds-fi-du.c index 12855a5..6d5bf35 100644 --- a/cmds-fi-du.c +++ b/cmds-fi-du.c @@ -389,8 +389,14 @@ static int du_walk_dir(struct du_dir_ctxt *ctxt, struct rb_root *shared_extents) dirfd(dirstream), shared_extents, &tot, &shr, 0); - if (ret) + if (ret == -ENOTTY) { + continue; + } else if (ret) { + fprintf(stderr, + "failed to walk dir/file: %s :%s\n", + entry->d_name, strerror(-ret)); break; + } ctxt->bytes_total += tot; ctxt->bytes_shared += shr; diff --git a/cmds-inspect.c b/cmds-inspect.c index dd7b9dd..2ae44be 100644 --- a/cmds-inspect.c +++ b/cmds-inspect.c @@ -323,7 +323,7 @@ static int cmd_inspect_rootid(int argc, char **argv) ret = lookup_ino_rootid(fd, &rootid); if (ret) { - error("rootid failed with ret=%d", ret); + error("failed to lookup root id: %s", strerror(-ret)); goto out; } diff --git a/utils.c b/utils.c index 578fdb0..f73b048 100644 --- a/utils.c +++ b/utils.c @@ -2815,6 +2815,8 @@ path: if (fd < 0) goto err; ret = lookup_ino_rootid(fd, &id); + if (ret) + error("failed to lookup root id: %s", strerror(-ret)); close(fd); if (ret < 0) goto err; @@ -3497,10 +3499,8 @@ int lookup_ino_rootid(int fd, u64 *rootid) args.objectid = BTRFS_FIRST_FREE_OBJECTID; ret = ioctl(fd, BTRFS_IOC_INO_LOOKUP, &args); - if (ret < 0) { - error("failed to lookup root id: %s", strerror(errno)); - return ret; - } + if (ret < 0) + return -errno; *rootid = args.treeid;