From: Miao Xie <miaox@cn.fujitsu.com>
To: Ulrich Hecht <uli@suse.de>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: compressed file size ioctl
Date: Tue, 27 Jul 2010 09:44:48 +0800 [thread overview]
Message-ID: <4C4E3A10.8050204@cn.fujitsu.com> (raw)
In-Reply-To: <1280158253-10515-1-git-send-email-uli@suse.de>
On Mon, 26 Jul 2010 17:30:53 +0200, Ulrich Hecht wrote:
[snip]
> +static long btrfs_ioctl_compsize(struct file *file, void __user *argp)
> +{
[snip]
> +
> + /* search for the inode */
> + key.objectid = inode->i_ino;
> + key.type = BTRFS_EXTENT_DATA_KEY;
> + key.offset = 0;
> +
> + while (1) {
> + /* note the key will change type as we walk through the tree */
> + ret = btrfs_search_slot(NULL, root,&key, path, 0, 0);
> + if (ret< 0)
> + goto out;
Why don't you use btrfs_get_extent() to implement it?
Thanks
Miao
> +
> + nritems = btrfs_header_nritems(path->nodes[0]);
> + if (path->slots[0]>= nritems) {
> + ret = btrfs_next_leaf(root, path);
> + if (ret< 0)
> + goto out;
> + if (ret> 0)
> + break;
> + nritems = btrfs_header_nritems(path->nodes[0]);
> + }
> + leaf = path->nodes[0];
> + slot = path->slots[0];
> +
> + btrfs_item_key_to_cpu(leaf,&key, slot);
> + if (btrfs_key_type(&key)> BTRFS_EXTENT_DATA_KEY ||
> + key.objectid != inode->i_ino)
> + break;
> +
> + if (btrfs_key_type(&key) == BTRFS_EXTENT_DATA_KEY) {
> + struct btrfs_file_extent_item *extent;
> + int type;
> + u64 datal = 0;
> +
> + extent = btrfs_item_ptr(leaf, slot,
> + struct btrfs_file_extent_item);
> + type = btrfs_file_extent_type(leaf, extent);
> + if (type == BTRFS_FILE_EXTENT_REG) {
> + datal = btrfs_file_extent_num_bytes(leaf,
> + extent);
> + compressed_size +=
> + btrfs_file_extent_disk_num_bytes(leaf,
> + extent);
> + } else if (type == BTRFS_FILE_EXTENT_INLINE) {
> + datal = btrfs_file_extent_ram_bytes(leaf,
> + extent);
> + compressed_size +=
> + btrfs_file_extent_inline_item_len(leaf,
> + btrfs_item_nr(leaf, slot));
> + }
> + btrfs_release_path(root, path);
> + }
> +
> + btrfs_release_path(root, path);
> + key.offset++;
> + }
> +
> + /* We've succeeded in going through all extents; set the final size. */
> + if (copy_to_user(argp,&compressed_size, sizeof(compressed_size)))
> + ret = -EFAULT;
> + else
> + ret = 0;
> +
> +out:
> + btrfs_release_path(root, path);
> + unlock_extent(&BTRFS_I(inode)->io_tree, 0, len, GFP_NOFS);
> + mutex_unlock(&inode->i_mutex);
> + btrfs_free_path(path);
> + return ret;
> +}
> +
> static long btrfs_ioctl_clone_range(struct file *file, void __user *argp)
> {
> struct btrfs_ioctl_clone_range_args args;
> @@ -2034,6 +2135,8 @@ long btrfs_ioctl(struct file *file, unsigned int
> case BTRFS_IOC_SYNC:
> btrfs_sync_fs(file->f_dentry->d_sb, 1);
> return 0;
> + case BTRFS_IOC_COMPR_SIZE:
> + return btrfs_ioctl_compsize(file, argp);
> }
>
> return -ENOTTY;
> diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h
> index 424694a..a01ef1e 100644
> --- a/fs/btrfs/ioctl.h
> +++ b/fs/btrfs/ioctl.h
> @@ -178,4 +178,5 @@ struct btrfs_ioctl_space_args {
> #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64)
> #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
> struct btrfs_ioctl_space_args)
> +#define BTRFS_IOC_COMPR_SIZE _IOR(BTRFS_IOCTL_MAGIC, 21, u64)
> #endif
next prev parent reply other threads:[~2010-07-27 1:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-26 15:30 [PATCH] Btrfs: compressed file size ioctl Ulrich Hecht
2010-07-27 1:44 ` Miao Xie [this message]
2010-07-29 11:26 ` Ulrich Hecht
-- strict thread matches above, loose matches on Subject: below --
2010-07-29 11:27 Ulrich Hecht
2010-07-29 12:35 ` liubo
2010-08-02 1:15 ` Miao Xie
2010-08-06 12:22 ` Ulrich Hecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C4E3A10.8050204@cn.fujitsu.com \
--to=miaox@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=uli@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.