Whamcloud - gitweb
filefrag: Display the number of contiguous, not physical, extents
authorTheodore Ts'o <tytso@mit.edu>
Fri, 30 Sep 2011 22:43:39 +0000 (18:43 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Sat, 1 Oct 2011 01:28:39 +0000 (21:28 -0400)
From a bug report filed by Ibragimov Rinat:

   When filefrag uses FIEMAP ioctl its logic differs for ordinary and
   verbose (-v) modes. ext4 returns extent on every 32768 block so on
   large files it is possible that `filefrag large-file' tells about 4
   extents while `filefrag -v large-file' finds only one.

   Also when I tried to use generic_block_fiemap function to add
   FIEMAP for reiserfs, every block was reported as a new extent
   resulting in thousands "extents" for continuous files.

   I think filefrag should merge adjacent extents even when -v is not
   specified.

Addresses-Debian-Bug: #631498

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
misc/filefrag.c

index 8441757..0131bf2 100644 (file)
@@ -223,11 +223,6 @@ static int filefrag_fiemap(int fd, int blk_shift, int *num_extents)
                        fiemap_header_printed = 1;
                }
 
-               if (!verbose) {
-                       *num_extents = fiemap->fm_mapped_extents;
-                       goto out;
-               }
-
                /* If 0 extents are returned, then more ioctls are not needed */
                if (fiemap->fm_mapped_extents == 0)
                        break;
@@ -244,7 +239,9 @@ static int filefrag_fiemap(int fd, int blk_shift, int *num_extents)
                                tot_extents++;
                        else
                                last_blk = 0;
-                       print_extent_info(&fm_ext[i], n, last_blk, blk_shift);
+                       if (verbose)
+                               print_extent_info(&fm_ext[i], n, last_blk,
+                                                 blk_shift);
 
                        last_blk = phy_blk + ext_len - 1;
                        if (fm_ext[i].fe_flags & FIEMAP_EXTENT_LAST)