Commit b8a86845 authored by Lukas Czerner's avatar Lukas Czerner Committed by Theodore Ts'o

ext4: Introduce FALLOC_FL_ZERO_RANGE flag for fallocate

Introduce new FALLOC_FL_ZERO_RANGE flag for fallocate. This has the same
functionality as xfs ioctl XFS_IOC_ZERO_RANGE.

It can be used to convert a range of file to zeros preferably without
issuing data IO. Blocks should be preallocated for the regions that span
holes in the file, and the entire range is preferable converted to
unwritten extents

This can be also used to preallocate blocks past EOF in the same way as
with fallocate. Flag FALLOC_FL_KEEP_SIZE which should cause the inode
size to remain the same.

Also add appropriate tracepoints.
Signed-off-by: default avatarLukas Czerner <lczerner@redhat.com>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent 0e8b6879
...@@ -568,6 +568,8 @@ enum { ...@@ -568,6 +568,8 @@ enum {
#define EXT4_GET_BLOCKS_NO_LOCK 0x0100 #define EXT4_GET_BLOCKS_NO_LOCK 0x0100
/* Do not put hole in extent cache */ /* Do not put hole in extent cache */
#define EXT4_GET_BLOCKS_NO_PUT_HOLE 0x0200 #define EXT4_GET_BLOCKS_NO_PUT_HOLE 0x0200
/* Convert written extents to unwritten */
#define EXT4_GET_BLOCKS_CONVERT_UNWRITTEN 0x0400
/* /*
* The bit position of these flags must not overlap with any of the * The bit position of these flags must not overlap with any of the
......
This diff is collapsed.
...@@ -503,6 +503,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, ...@@ -503,6 +503,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
{ {
struct extent_status es; struct extent_status es;
int retval; int retval;
int ret = 0;
#ifdef ES_AGGRESSIVE_TEST #ifdef ES_AGGRESSIVE_TEST
struct ext4_map_blocks orig_map; struct ext4_map_blocks orig_map;
...@@ -558,7 +559,6 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, ...@@ -558,7 +559,6 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
EXT4_GET_BLOCKS_KEEP_SIZE); EXT4_GET_BLOCKS_KEEP_SIZE);
} }
if (retval > 0) { if (retval > 0) {
int ret;
unsigned int status; unsigned int status;
if (unlikely(retval != map->m_len)) { if (unlikely(retval != map->m_len)) {
...@@ -585,7 +585,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, ...@@ -585,7 +585,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
found: found:
if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
int ret = check_block_validity(inode, map); ret = check_block_validity(inode, map);
if (ret != 0) if (ret != 0)
return ret; return ret;
} }
...@@ -602,7 +602,13 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, ...@@ -602,7 +602,13 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
* with buffer head unmapped. * with buffer head unmapped.
*/ */
if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED)
return retval; /*
* If we need to convert extent to unwritten
* we continue and do the actual work in
* ext4_ext_map_blocks()
*/
if (!(flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN))
return retval;
/* /*
* Here we clear m_flags because after allocating an new extent, * Here we clear m_flags because after allocating an new extent,
...@@ -658,7 +664,6 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, ...@@ -658,7 +664,6 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
ext4_clear_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED); ext4_clear_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED);
if (retval > 0) { if (retval > 0) {
int ret;
unsigned int status; unsigned int status;
if (unlikely(retval != map->m_len)) { if (unlikely(retval != map->m_len)) {
...@@ -693,7 +698,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode, ...@@ -693,7 +698,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
has_zeroout: has_zeroout:
up_write((&EXT4_I(inode)->i_data_sem)); up_write((&EXT4_I(inode)->i_data_sem));
if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
int ret = check_block_validity(inode, map); ret = check_block_validity(inode, map);
if (ret != 0) if (ret != 0)
return ret; return ret;
} }
...@@ -3507,7 +3512,7 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length) ...@@ -3507,7 +3512,7 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
return -EOPNOTSUPP; return -EOPNOTSUPP;
trace_ext4_punch_hole(inode, offset, length); trace_ext4_punch_hole(inode, offset, length, 0);
/* /*
* Write out all dirty pages to avoid race conditions * Write out all dirty pages to avoid race conditions
......
...@@ -21,6 +21,10 @@ struct extent_status; ...@@ -21,6 +21,10 @@ struct extent_status;
#define FALLOC_FL_COLLAPSE_RANGE 0x08 #define FALLOC_FL_COLLAPSE_RANGE 0x08
#endif #endif
#ifndef FALLOC_FL_ZERO_RANGE
#define FALLOC_FL_ZERO_RANGE 0x10
#endif
#define EXT4_I(inode) (container_of(inode, struct ext4_inode_info, vfs_inode)) #define EXT4_I(inode) (container_of(inode, struct ext4_inode_info, vfs_inode))
#define show_mballoc_flags(flags) __print_flags(flags, "|", \ #define show_mballoc_flags(flags) __print_flags(flags, "|", \
...@@ -77,7 +81,8 @@ struct extent_status; ...@@ -77,7 +81,8 @@ struct extent_status;
{ FALLOC_FL_KEEP_SIZE, "KEEP_SIZE"}, \ { FALLOC_FL_KEEP_SIZE, "KEEP_SIZE"}, \
{ FALLOC_FL_PUNCH_HOLE, "PUNCH_HOLE"}, \ { FALLOC_FL_PUNCH_HOLE, "PUNCH_HOLE"}, \
{ FALLOC_FL_NO_HIDE_STALE, "NO_HIDE_STALE"}, \ { FALLOC_FL_NO_HIDE_STALE, "NO_HIDE_STALE"}, \
{ FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"}) { FALLOC_FL_COLLAPSE_RANGE, "COLLAPSE_RANGE"}, \
{ FALLOC_FL_ZERO_RANGE, "ZERO_RANGE"})
TRACE_EVENT(ext4_free_inode, TRACE_EVENT(ext4_free_inode,
...@@ -1339,7 +1344,7 @@ TRACE_EVENT(ext4_direct_IO_exit, ...@@ -1339,7 +1344,7 @@ TRACE_EVENT(ext4_direct_IO_exit,
__entry->rw, __entry->ret) __entry->rw, __entry->ret)
); );
TRACE_EVENT(ext4_fallocate_enter, DECLARE_EVENT_CLASS(ext4__fallocate_mode,
TP_PROTO(struct inode *inode, loff_t offset, loff_t len, int mode), TP_PROTO(struct inode *inode, loff_t offset, loff_t len, int mode),
TP_ARGS(inode, offset, len, mode), TP_ARGS(inode, offset, len, mode),
...@@ -1347,23 +1352,45 @@ TRACE_EVENT(ext4_fallocate_enter, ...@@ -1347,23 +1352,45 @@ TRACE_EVENT(ext4_fallocate_enter,
TP_STRUCT__entry( TP_STRUCT__entry(
__field( dev_t, dev ) __field( dev_t, dev )
__field( ino_t, ino ) __field( ino_t, ino )
__field( loff_t, pos ) __field( loff_t, offset )
__field( loff_t, len ) __field( loff_t, len )
__field( int, mode ) __field( int, mode )
), ),
TP_fast_assign( TP_fast_assign(
__entry->dev = inode->i_sb->s_dev; __entry->dev = inode->i_sb->s_dev;
__entry->ino = inode->i_ino; __entry->ino = inode->i_ino;
__entry->pos = offset; __entry->offset = offset;
__entry->len = len; __entry->len = len;
__entry->mode = mode; __entry->mode = mode;
), ),
TP_printk("dev %d,%d ino %lu pos %lld len %lld mode %s", TP_printk("dev %d,%d ino %lu offset %lld len %lld mode %s",
MAJOR(__entry->dev), MINOR(__entry->dev), MAJOR(__entry->dev), MINOR(__entry->dev),
(unsigned long) __entry->ino, __entry->pos, (unsigned long) __entry->ino,
__entry->len, show_falloc_mode(__entry->mode)) __entry->offset, __entry->len,
show_falloc_mode(__entry->mode))
);
DEFINE_EVENT(ext4__fallocate_mode, ext4_fallocate_enter,
TP_PROTO(struct inode *inode, loff_t offset, loff_t len, int mode),
TP_ARGS(inode, offset, len, mode)
);
DEFINE_EVENT(ext4__fallocate_mode, ext4_punch_hole,
TP_PROTO(struct inode *inode, loff_t offset, loff_t len, int mode),
TP_ARGS(inode, offset, len, mode)
);
DEFINE_EVENT(ext4__fallocate_mode, ext4_zero_range,
TP_PROTO(struct inode *inode, loff_t offset, loff_t len, int mode),
TP_ARGS(inode, offset, len, mode)
); );
TRACE_EVENT(ext4_fallocate_exit, TRACE_EVENT(ext4_fallocate_exit,
...@@ -1395,31 +1422,6 @@ TRACE_EVENT(ext4_fallocate_exit, ...@@ -1395,31 +1422,6 @@ TRACE_EVENT(ext4_fallocate_exit,
__entry->ret) __entry->ret)
); );
TRACE_EVENT(ext4_punch_hole,
TP_PROTO(struct inode *inode, loff_t offset, loff_t len),
TP_ARGS(inode, offset, len),
TP_STRUCT__entry(
__field( dev_t, dev )
__field( ino_t, ino )
__field( loff_t, offset )
__field( loff_t, len )
),
TP_fast_assign(
__entry->dev = inode->i_sb->s_dev;
__entry->ino = inode->i_ino;
__entry->offset = offset;
__entry->len = len;
),
TP_printk("dev %d,%d ino %lu offset %lld len %lld",
MAJOR(__entry->dev), MINOR(__entry->dev),
(unsigned long) __entry->ino,
__entry->offset, __entry->len)
);
TRACE_EVENT(ext4_unlink_enter, TRACE_EVENT(ext4_unlink_enter,
TP_PROTO(struct inode *parent, struct dentry *dentry), TP_PROTO(struct inode *parent, struct dentry *dentry),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment