[systemd-devel] [PATCH 5/6] readahead-collect: handle btrfs FIEMAP

harald at redhat.com harald at redhat.com
Fri Sep 24 03:06:03 PDT 2010


From: Harald Hoyer <harald at redhat.com>

Some files on btrfs do not have a physical extent. Just return an increasing number.
---
 src/readahead-collect.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/readahead-collect.c b/src/readahead-collect.c
index 7983b31..f7f0f14 100644
--- a/src/readahead-collect.c
+++ b/src/readahead-collect.c
@@ -146,6 +146,7 @@ static unsigned long fd_first_block(int fd) {
                 struct fiemap fiemap;
                 struct fiemap_extent extent;
         } data;
+	static unsigned long ul = 0;
 
         zero(data);
         data.fiemap.fm_length = ~0ULL;
@@ -160,6 +161,12 @@ static unsigned long fd_first_block(int fd) {
         if (data.fiemap.fm_extents[0].fe_flags & FIEMAP_EXTENT_UNKNOWN)
                 return 0;
 
+	// Some filesystems/files do not have a physical extent.
+	// Just return an increasing number.
+	if (data.fiemap.fm_extents[0].fe_flags & FIEMAP_EXTENT_MERGED
+	    && data.fiemap.fm_extents[0].fe_physical == 0)
+		return ul++;
+
         return (unsigned long) data.fiemap.fm_extents[0].fe_physical;
 }
 
@@ -298,7 +305,7 @@ static int collect(const char *root) {
 
                                                 ul = fd_first_block(m->fd);
 
-                                                if ((k = hashmap_put(files, p, ULONG_TO_PTR(ul))) < 0) {
+                                                if (ul && (k = hashmap_put(files, p, ULONG_TO_PTR(ul))) < 0) {
 
                                                         if (k != -EEXIST)
                                                                 log_warning("set_put() failed: %s", strerror(-k));
-- 
1.7.3



More information about the systemd-devel mailing list