From patchwork Wed Aug 25 08:51:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuya Mio X-Patchwork-Id: 62657 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C97ABB70DA for ; Wed, 25 Aug 2010 19:01:07 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752830Ab0HYJBF (ORCPT ); Wed, 25 Aug 2010 05:01:05 -0400 Received: from TYO201.gate.nec.co.jp ([202.32.8.193]:39166 "EHLO tyo201.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752822Ab0HYJBF (ORCPT ); Wed, 25 Aug 2010 05:01:05 -0400 Received: from mailgate3.nec.co.jp ([10.7.69.195]) by tyo201.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id o7P912I6013781; Wed, 25 Aug 2010 18:01:02 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id o7P912r20350; Wed, 25 Aug 2010 18:01:02 +0900 (JST) Received: from mail02.kamome.nec.co.jp (mail02.kamome.nec.co.jp [10.25.43.5]) by mailsv4.nec.co.jp (8.13.8/8.13.4) with ESMTP id o7P912Cu003173; Wed, 25 Aug 2010 18:01:02 +0900 (JST) Received: from shoin.jp.nec.com ([10.26.220.3] [10.26.220.3]) by mail02.kamome.nec.co.jp with ESMTP id BT-MMP-150219; Wed, 25 Aug 2010 17:51:56 +0900 Received: from [10.64.168.30] ([10.64.168.30] [10.64.168.30]) by mail.jp.nec.com with ESMTP; Wed, 25 Aug 2010 17:51:56 +0900 Message-ID: <4C74D9AC.70104@sx.jp.nec.com> Date: Wed, 25 Aug 2010 17:51:56 +0900 From: Kazuya Mio User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.2.8) Gecko/20100802 Thunderbird/3.1.2 MIME-Version: 1.0 To: ext4 , Theodore Tso CC: linux-fsdevel@vger.kernel.org Subject: [RFC][PATCH V2 3/5] ext4: add EXT4_IOC_GET_PA to get inode PA information Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This ioctl gets the information of all inode PAs in the target inode. The interface of this ioctl is like FS_IOC_FIEMAP. If we call this ioctl, we get the array of struct ext4_prealloc_info that stores the information of inode PA. INTERFACE ----------- #define EXT4_IOC_GET_PA _IOWR('f', 17, struct ext4_prealloc_list) struct ext4_prealloc_list { __u32 pl_count; /* size of pl_space array (in) */ __u32 pl_mapped; /* number of PAs that were mapped (out) */ __u32 pl_entries; /* number of PAs the inode has (out) */ struct ext4_prealloc_info pl_space[0]; /* array of mapped PAs (out) */ }; pl_count specifies the number of elements in the pl_space[] array that can be used to return inode PAs. If pl_count is zero, no inode PAs will be returned. Moreover, if pl_count is set the value that is better than the number of elements in the pl_space array, this ioctl returns EFAULT. pl_mapped shows the number of getting inode PAs, and pl_entries shows the number of inode PAs in the target inode. You can confirm that we could get all inode PAs in the target inode by comparison with pl_mapped and pl_entries. Signed-off-by: Kazuya Mio Signed-off-by: Akira Fujita --- fs/ext4/ext4.h | 11 +++++++++++ fs/ext4/ioctl.c | 33 +++++++++++++++++++++++++++++++++ fs/ext4/mballoc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 550c61b..a7cb560 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -147,6 +147,14 @@ struct ext4_prealloc_info { __u16 pi_flags; /* flags for the inode PA setting ioctl (in) */ }; +/* inode PA list */ +struct ext4_prealloc_list { + __u32 pl_count; /* size of pl_space array (in) */ + __u32 pl_mapped; /* number of PAs that were mapped (out) */ + __u32 pl_entries; /* number of PAs the inode has (out) */ + struct ext4_prealloc_info pl_space[0]; /* array of mapped PAs (out) */ +}; + /* * Logical to physical block mapping, used by ext4_map_blocks() * @@ -534,6 +542,7 @@ struct ext4_new_group_data { #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12) #define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent) #define EXT4_IOC_CONTROL_PA _IOWR('f', 16, struct ext4_prealloc_info) +#define EXT4_IOC_GET_PA _IOWR('f', 17, struct ext4_prealloc_list) #if defined(__KERNEL__) && defined(CONFIG_COMPAT) /* @@ -1654,6 +1663,8 @@ extern void ext4_mb_put_buddy_cache_lock(struct super_block *, ext4_group_t, int); extern int ext4_mb_control_pa(struct inode *inode, struct ext4_prealloc_info *pi); +extern int ext4_mb_get_pa(struct inode *inode, struct ext4_prealloc_list *pl, + struct ext4_prealloc_info *dest); /* inode.c */ struct buffer_head *ext4_getblk(handle_t *, struct inode *, diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c index 631ae01..352cb35 100644 --- a/fs/ext4/ioctl.c +++ b/fs/ext4/ioctl.c @@ -424,6 +424,38 @@ mext_out: return err; } + case EXT4_IOC_GET_PA: + { + struct ext4_prealloc_list pl; + struct ext4_prealloc_info *dest; + int err; + + if (!S_ISREG(inode->i_mode)) + return -EINVAL; + if (!(filp->f_mode & FMODE_READ)) + return -EBADF; + + if (copy_from_user(&pl, + (struct ext4_prealloc_list __user *)arg, sizeof(pl))) + return -EFAULT; + + dest = (struct ext4_prealloc_info *)(arg + sizeof(pl)); + if (!access_ok(VERIFY_WRITE, + (struct ext4_prealloc_info __force __user *)dest, + pl.pl_count * sizeof(struct ext4_prealloc_info))) + return -EFAULT; + + err = ext4_mb_get_pa(inode, &pl, dest); + + if (err) + return err; + + if (copy_to_user((struct ext4_prealloc_list __user *)arg, + &pl, sizeof(pl))) + return -EFAULT; + return err; + } + default: return -ENOTTY; } @@ -492,6 +524,7 @@ long ext4_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case EXT4_IOC_MOVE_EXT: case EXT4_IOC_DEBUG_DELALLOC: case EXT4_IOC_CONTROL_PA: + case EXT4_IOC_GET_PA: break; default: return -ENOIOCTLCMD; diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 9a33c33..a412e72 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -5089,3 +5089,47 @@ out: return err1; } +/** + * ext4_mb_get_pa - Pass inode PA information to user space + * + * @inode: target inode + * @pl: information of the inode PA list (in/out) + * @dest: user space address where PAs' information is written to + * + * Return 0 if success or error code on failure. + */ +int ext4_mb_get_pa(struct inode *inode, struct ext4_prealloc_list *pl, + struct ext4_prealloc_info *dest) +{ + struct ext4_inode_info *ei = EXT4_I(inode); + struct ext4_prealloc_space *pa; + struct ext4_prealloc_info pi; + + pl->pl_entries = 0; + pl->pl_mapped = 0; + + rcu_read_lock(); + list_for_each_entry_rcu(pa, &ei->i_prealloc_list, pa_inode_list) { + pl->pl_entries++; + if (pl->pl_mapped < pl->pl_count) { + memset(&pi, 0, sizeof(pi)); + pi.pi_pstart = pa->pa_pstart; + pi.pi_lstart = pa->pa_lstart; + pi.pi_len = pa->pa_len; + pi.pi_free = pa->pa_free; + + rcu_read_unlock(); + if (copy_to_user( + (struct ext4_prealloc_info __force __user *)dest, + &pi, sizeof(pi))) { + return -EFAULT; + } + dest++; + pl->pl_mapped++; + rcu_read_lock(); + } + } + rcu_read_unlock(); + + return 0; +}