Skip to contentSkip to conversation

filefrag: improvements to filefrag FIEMAP handling

PATCH In review Andreas Dilger 2 participants 2 messages Nov 23, 2012 – Dec 30, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 filefrag: improvements to filefrag FIEMAP handling

Update the filefrag program to allow displaying the extents in some different formats. Try and stay within 80 columns.
* add -k option to print extents in kB-sized units (like df -k)
* add -b {blocksize} to print extents in blocksize units
* add -e option to print extent format, even when FIBMAP is used
* add -X option to print extents in hexadecimal format

Internally, the FIBMAP handling code has been moved into its own function like FIEMAP, so that the code is more modular. Extent offsets are now handled in bytes instead of in blocks, to allow printing extents with arbitrary block sizes. The extent header printing also moved into its own function so that it can be shared between the FIEMAP and FIBMAP handling routines, since it got more complex with the different output options.

Only print error about FIBMAP being root-only a single time. Print the filesystem type if it changes between specified files. Add fsync() for FIBMAP if "-s" is given.

Add support for filesystems that have multiple backing devices so that extents stored on different devices can be disinguished from each other. This is enabled by default for Lustre, but can be selected for other filesystems if desired/supported with the "-l" option.

---
 lib/ext2fs/fiemap.h |    6 +-
 misc/filefrag.8.in  |   28 +++-
 misc/filefrag.c     |  413 +++++++++++++++++++++++++++++++++++----------------
 3 files changed, 315 insertions(+), 132 deletions(-)
lib/ext2fs/fiemap.h +5 -1
index 30bf555..a0c87b5 100644
@@ -19,7 +19,8 @@ struct fiemap_extent {
 	__u64 fe_length;   /* length in bytes for this extent */
 	__u64 fe_reserved64[2];
 	__u32 fe_flags;    /* FIEMAP_EXTENT_* flags for this extent */
-	__u32 fe_reserved[3];
+	__u32 fe_device;   /* device number (fs-specific if FIEMAP_EXTENT_NET)*/
+	__u32 fe_reserved[2];
 };
 
 struct fiemap {
@@ -42,6 +43,7 @@ struct fiemap {
 
 #define FIEMAP_FLAG_SYNC	0x00000001 /* sync file data before map */
 #define FIEMAP_FLAG_XATTR	0x00000002 /* map extended attribute tree */
+#define FIEMAP_FLAG_DEVICE_ORDER 0x40000000 /* return device ordered mapping */
 
 #define FIEMAP_FLAGS_COMPAT	(FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
 
@@ -65,4 +67,6 @@ struct fiemap {
 						    * support extents. Result
 						    * merged for efficiency. */
 
+#define FIEMAP_EXTENT_NET		0x80000000 /* Data stored remotely. */
+
 #endif /* _LINUX_FIEMAP_H */
misc/filefrag.8.in +25 -3
index 463f731..b0639a3 100644
@@ -5,7 +5,10 @@ filefrag \- report on file fragmentation
 .SH SYNOPSIS
 .B filefrag
 [
-.B \-Bbsvx
+.BI \-b blocksize
+]
+[
+.B \-BeklsvxX
 ]
 [
 .I files...
@@ -27,8 +30,24 @@ If FIEMAP is not supported then filefrag will fall back to using FIBMAP.
 Force the use of the older FIBMAP ioctl instead of the FIEMAP ioctl for
 testing purposes.
 .TP
-.B \-b
-Use 1024 byte blocksize for the output.
+.BI \-b blocksize
+Use
+.I blocksize
+in bytes for output instead of the filesystem blocksize.
+For compatibility with earlier versions of
+.BR filefrag ,
+if
+.I blocksize
+is unspecified it defaults to 1024 bytes.
+.TP
+.B \-e
+Print output in extent format, even for block-mapped files.
+.TP
+.BI \-k
+Use 1024\-byte blocksize for output (identical to '\-b 1024').
+.TP
+.B \-l
+Extents are displayed in device-logical offset order.
 .TP
 .B \-s
 Sync the file before requesting the mapping.
@@ -38,6 +57,9 @@ Be verbose when checking for file fragmentation.
 .TP
 .B \-x
 Display mapping of extended attributes.
+.TP
+.B \-X
+Display extent block numbers in hexadecimal format.
 .SH AUTHOR
 .B filefrag
 was written by Theodore Ts'o <[email protected]>.
misc/filefrag.c +285 -128

585 lines not on this page · raw message

Signature · 1 line
1.7.3.4
#1 lore raw
Quoted 19 lines · Andreas Dilger

Update the filefrag program to allow displaying the extents in some different formats. Try and stay within 80 columns.
* add -k option to print extents in kB-sized units (like df -k)
* add -b {blocksize} to print extents in blocksize units
* add -e option to print extent format, even when FIBMAP is used
* add -X option to print extents in hexadecimal format

Internally, the FIBMAP handling code has been moved into its own function like FIEMAP, so that the code is more modular. Extent offsets are now handled in bytes instead of in blocks, to allow printing extents with arbitrary block sizes. The extent header printing also moved into its own function so that it can be shared between the FIEMAP and FIBMAP handling routines, since it got more complex with the different output options.

Only print error about FIBMAP being root-only a single time. Print the filesystem type if it changes between specified files. Add fsync() for FIBMAP if "-s" is given.

Quoted 7 lines

Add support for filesystems that have multiple backing devices so that extents stored on different devices can be disinguished from each other. This is enabled by default for Lustre, but can be selected for other filesystems if desired/supported with the "-l" option.

In the future, it's really a lot easier to review these sorts of patches if you break up the patch. Note how I sent my resize2fs flex_bg patches as an example. Reviewing a huge megapatch is much more difficult, and it makes patch conflicts more common and more difficult to resolve.

I removed the DEVICE_ORDER support since I'm not entirely sure how much we want support these Lustre-specific extensions, especially since they require out-of-tree ABI extensions. The bit fields in question haven't been reserved in the kernel, and I've been having trouble finding the formal definition of these ABI extensions.

In any case, it looks like Lustre's e2fsprogs patches have hugely modified filefrag, and so by accepting the bulk of this patch, it should make things easier for you to maintain the Lustre-speciific patches until we can figure out how we want ot deal with this bit of your changes.

- Ted