ext4: add EXT4_IOC_GET_PA to get inode PA information
Subsystems (2)
RFC PATCH v3 3/4 ext4: add EXT4_IOC_GET_PA to get inode PA information
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.
--- fs/ext4/ext4.h | 11 +++++++++++ fs/ext4/ioctl.c | 33 +++++++++++++++++++++++++++++++++ fs/ext4/mballoc.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+)
fs/ext4/ext4.h +11 -0
@@ -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() *
@@ -558,6 +566,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 )/*
@@ -1710,6 +1719,8 @@ extern int ext4_mb_add_groupinfo(struct super_block *sb,extern int ext4_trim_fs (struct super_block *,struct fstrim_range *);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 *,
fs/ext4/ioctl.c +33 -0
@@ -448,6 +448,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 ; }
@@ -516,6 +548,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 ;
fs/ext4/mballoc.c +44 -0
47 lines not on this page · raw message