From patchwork Thu Feb 25 08:57:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91bGlu?= X-Patchwork-Id: 8420771 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2937AC0553 for ; Thu, 25 Feb 2016 08:57:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5A98C20263 for ; Thu, 25 Feb 2016 08:57:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 74F0220259 for ; Thu, 25 Feb 2016 08:57:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760103AbcBYI5x (ORCPT ); Thu, 25 Feb 2016 03:57:53 -0500 Received: from mail-oi0-f65.google.com ([209.85.218.65]:36257 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759722AbcBYI5v (ORCPT ); Thu, 25 Feb 2016 03:57:51 -0500 Received: by mail-oi0-f65.google.com with SMTP id w71so2169890oia.3 for ; Thu, 25 Feb 2016 00:57:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=q7d8KyEH7tEAYmmDuSqXdpOWNDEYhoun9qhqDGyDt7k=; b=oRhu8Ch9Jxfec6b5Div1Wl3uYDoJ+JgYxe3Gwwm95lcey5h/fZ8Az5kmQMkA7HNXqX ZhBlFzr7fg52dskQT9+vgFNHOdd4w9hSefER0r/s2L3fHGYV1W/Mr/NoKRfcTWF+6bGM WCs+Hej55IzxmA32MNCH3NtrMwdIhIx5FXy+ccPfAc9iW8XZQW2L4Zz1js4O9CF73CQJ O5Mv1netUFv6o48pEhZg11u5UedE5QZeHlaTJUmDKDevpshb5CHJNd6BbTKcZg4Fy320 WuKjnDm4muHDA2sGriu2Mr0jDYCQMIjcqvpEOJElvfyQRRLPOsPTl190h4Po1ATk2+Qk I+MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=q7d8KyEH7tEAYmmDuSqXdpOWNDEYhoun9qhqDGyDt7k=; b=UKrXyYRx57PwdVPbStn6NkCQz1fLRj4j3Siz7D237bbYJ78Wk/T/+TvawBLfmGYgmu uT/0lYcSp2ffv9fwIx/pUlMbOs5OvCQh21I7+auzVWLn82lMijBzKQWcVjk5qAIx7nvQ UjRQldRR5hk6VqUJRXIndLb3w+o4PuXADiWBQ1VXSjDNCLr9NEv7wnSlov8kYUrur1i2 LjrEtSb46VzHkatzFgRzOxMQqU9rkg4Hhn5nwp41IiaE6ibkq0ErkJztJdmRQ4q1uxKr j+fY5kgqKalGfkUOZ687JgqEl0o1TTr+qUKrq+wfHNfXJoRJzlBfhvCoSBOEi9AYmqoa h/Xw== X-Gm-Message-State: AG10YOQo5v5e2Ertz0e2XxTAMqppveW0Z0nhLiT4/iDdb8q2IdFjmdwyLkU3ccu/YgLWHUSSXuiBGEuFcCxuyw== MIME-Version: 1.0 X-Received: by 10.202.170.10 with SMTP id t10mr19905278oie.60.1456390671091; Thu, 25 Feb 2016 00:57:51 -0800 (PST) Received: by 10.76.151.40 with HTTP; Thu, 25 Feb 2016 00:57:51 -0800 (PST) In-Reply-To: <1453326567-20454-3-git-send-email-mfasheh@suse.de> References: <1453326567-20454-1-git-send-email-mfasheh@suse.de> <1453326567-20454-3-git-send-email-mfasheh@suse.de> Date: Thu, 25 Feb 2016 03:57:51 -0500 Message-ID: Subject: Re: [PATCH 2/3] btrfs-progs: add 'du' command From: =?UTF-8?B?SsOpcsO0bWUgUG91bGlu?= To: Mark Fasheh Cc: linux-btrfs Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, UNPARSEABLE_RELAY autolearn=no 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 On Wed, Jan 20, 2016 at 4:49 PM, Mark Fasheh wrote: > 'btrfs du' differs from regular du in that it will work to resolve which > blocks are shared between files in its list. This gives the user a more > accurate bytecount from which they can make decisions regarding management > of their file space. Would it be a good idea for this new du to show the compressed file size too? It was not made by me but I know I had this patch lying around, it also does not compile right now but I could give it an update. The wiki says this patch was "not merged yet" but I have no idea why it was not since it was working correctly 2 years ago on my machine. --- fs/btrfs/ioctl.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/btrfs.h | 2 ++ 2 files changed, 79 insertions(+) #define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \ diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index da94138..1c6285b 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -4499,6 +4499,81 @@ static int build_ino_list(u64 inum, u64 offset, u64 root, void *ctx) return 0; } +/* + * Returns the compressed size of an inode in 512 byte blocks. + * Count the on-disk space used by extents starting in range [start, end), + * inline data are rounded up to sector, ie. 512. + * + * The range is start inclusive and end exclusive so it can be used to + * determine compressed size of a given extent by its start and start of the + * next extent easily, without counting length. + * Whole file is specified as start = 0, end = (u64)-1 + */ +static long btrfs_ioctl_compr_size(struct file *file, void __user *argp) +{ + struct inode *inode = fdentry(file)->d_inode; + struct btrfs_ioctl_compr_size_args compr_args; + u64 len; + u64 compressed_size = 0; + u64 offset = 0; + + if (S_ISDIR(inode->i_mode)) + return -EISDIR; + + if (copy_from_user(&compr_args, argp, + sizeof(struct btrfs_ioctl_compr_size_args))) + return -EFAULT; + + if (compr_args.start > compr_args.end) + return -EINVAL; + + mutex_lock(&inode->i_mutex); + + offset = compr_args.start; + if (inode->i_size > compr_args.end) + len = compr_args.end; + else + len = inode->i_size; + + /* + * do any pending delalloc/csum calc on inode, one way or + * another, and lock file content + */ + btrfs_wait_ordered_range(inode, compr_args.start, len); + + while (offset < len) { + struct extent_map *em; + + em = btrfs_get_extent(inode, NULL, 0, offset, 1, 0); + if (IS_ERR_OR_NULL(em)) + goto error; + if (em->block_len != (u64)-1) + compressed_size += em->block_len; + else if (em->block_start == EXTENT_MAP_INLINE) { + compressed_size += ALIGN(em->len, 512); + } + offset += em->len; + free_extent_map(em); + } + mutex_unlock(&inode->i_mutex); + + unlock_extent(&BTRFS_I(inode)->io_tree, compr_args.start, len); + + compr_args.size = compressed_size >> 9; + + if (copy_to_user(argp, &compr_args, sizeof(struct + btrfs_ioctl_compr_size_args))) + return -EFAULT; + + return 0; + +error: + mutex_unlock(&inode->i_mutex); + unlock_extent(&BTRFS_I(inode)->io_tree, compr_args.start, len); + + return -EIO; +} + static long btrfs_ioctl_logical_to_ino(struct btrfs_root *root, void __user *arg) { @@ -5532,6 +5607,8 @@ long btrfs_ioctl(struct file *file, unsigned int return btrfs_ioctl_scrub_progress(root, argp); case BTRFS_IOC_BALANCE_V2: return btrfs_ioctl_balance(file, argp); + case BTRFS_IOC_COMPR_SIZE: + return btrfs_ioctl_compr_size(file, argp); case BTRFS_IOC_BALANCE_CTL: return btrfs_ioctl_balance_ctl(root, arg); case BTRFS_IOC_BALANCE_PROGRESS: diff --git a/include/uapi/linux/btrfs.h b/include/uapi/linux/btrfs.h index dea8931..cd52cda 100644 --- a/include/uapi/linux/btrfs.h +++ b/include/uapi/linux/btrfs.h @@ -647,6 +647,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) char[BTRFS_LABEL_SIZE]) #define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \ char[BTRFS_LABEL_SIZE]) +#define BTRFS_IOC_COMPR_SIZE _IOR(BTRFS_IOCTL_MAGIC, 51, \ + struct btrfs_ioctl_compr_size_args) #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \ struct btrfs_ioctl_get_dev_stats)