]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: support allocating uninit blocks in bmap2()
authorDarrick J. Wong <darrick.wong@oracle.com>
Sun, 17 May 2015 00:54:29 +0000 (20:54 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sun, 17 May 2015 00:54:29 +0000 (20:54 -0400)
As part of supporting fallocate-like functionality, extend
ext2fs_bmap() with two flags -- BMAP_UNINIT and BMAP_ZERO.  The first
will cause it to mark/set a block uninitialized, if it's part of an
extent based file.  For a block mapped file, the mapping is put in,
but there is no way to remember the uninitialized status.  The second
flag causes the block to be zeroed to support the use case of
emulating uninitialized blocks on a block-map file by zeroing them.

Eventually fallocate or fuse2fs or somebody will use these.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
lib/ext2fs/bmap.c
lib/ext2fs/ext2fs.h

index cb3f5a1d5f38a9c34e763cc4bcacd268918eef05..c18f742054b82657d8b4e77a1c6660a41df5ab84 100644 (file)
@@ -214,10 +214,13 @@ static errcode_t extent_bmap(ext2_filsys fs, ext2_ino_t ino,
        errcode_t               retval = 0;
        blk64_t                 blk64 = 0;
        int                     alloc = 0;
+       int                     set_flags;
+
+       set_flags = bmap_flags & BMAP_UNINIT ? EXT2_EXTENT_SET_BMAP_UNINIT : 0;
 
        if (bmap_flags & BMAP_SET) {
                retval = ext2fs_extent_set_bmap(handle, block,
-                                               *phys_blk, 0);
+                                               *phys_blk, set_flags);
                return retval;
        }
        retval = ext2fs_extent_goto(handle, block);
@@ -254,7 +257,7 @@ got_block:
                alloc++;
        set_extent:
                retval = ext2fs_extent_set_bmap(handle, block,
-                                               blk64, 0);
+                                               blk64, set_flags);
                if (retval) {
                        ext2fs_block_alloc_stats2(fs, blk64, -1);
                        return retval;
@@ -441,6 +444,8 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode,
        if (retval == 0)
                *phys_blk = blk32;
 done:
+       if (*phys_blk && retval == 0 && (bmap_flags & BMAP_ZERO))
+               retval = ext2fs_zero_blocks2(fs, *phys_blk, 1, NULL, NULL);
        if (buf)
                ext2fs_free_mem(&buf);
        if (handle)
index 231a951db4ef91562625a07eb4556da36494205d..2039ca0bc974942a75074b9103b979c95d12338b 100644 (file)
@@ -527,6 +527,8 @@ typedef struct ext2_icount *ext2_icount_t;
  */
 #define BMAP_ALLOC     0x0001
 #define BMAP_SET       0x0002
+#define BMAP_UNINIT    0x0004
+#define BMAP_ZERO      0x0008
 
 /*
  * Returned flags from ext2fs_bmap