Skip to contentSkip to conversation

src/fssum: skip subvolumes when building a sum

PATCH In review Josef Bacik 2 participants 2 messages Dec 17, 2019 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 src/fssum: skip subvolumes when building a sum

With the snapshot/subvolume support added to fsstress I've been seeing random failures with our send/receive related tests. This is because fssum is summing the path with the subvolumes for our test fs'es that are generated by fsstress. But with send/receive it skips subvolumes, which makes the sums mismatch. Fix this by skipping directories that do not match our st_dev, which is how we differentiate subvolumes in btrfs.

---
 src/fssum.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
src/fssum.c +11 -0
index 6ba0a95c..a243839a 100644
@@ -517,6 +517,12 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
 	int excl;
 	sum_file_data_t sum_file_data = flags[FLAG_STRUCTURE] ?
 			sum_file_data_strict : sum_file_data_permissive;
+	struct stat64 dir_st;
+
+	if (fstat64(dirfd, &dir_st)) {
+		perror("fstat");
+		exit(-1);
+	}
 
 	d = fdopendir(dirfd);
 	if (!d) {
@@ -570,6 +576,11 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
 				path_prefix, path, strerror(errno));
 			exit(-1);
 		}
+
+		/* We are crossing into a different subvol, skip this subtree. */
+		if (st.st_dev != dir_st.st_dev)
+			goto next;
+
 		sum_add_u64(&meta, level);
 		sum_add(&meta, namelist[i], strlen(namelist[i]));
 		if (!S_ISDIR(st.st_mode))
Signature · 1 line
2.23.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Josef Bacik

With the snapshot/subvolume support added to fsstress I've been seeing random failures with our send/receive related tests. This is because fssum is summing the path with the subvolumes for our test fs'es that are generated by fsstress. But with send/receive it skips subvolumes, which makes the sums mismatch. Fix this by skipping directories that do not match our st_dev, which is how we differentiate subvolumes in btrfs.

Looks good, thanks.

Quoted 36 lines
---
 src/fssum.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
src/fssum.c +11 -1
index 6ba0a95c..a243839a 100644
@@ -517,6 +517,12 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
        int excl;
        sum_file_data_t sum_file_data = flags[FLAG_STRUCTURE] ?
                        sum_file_data_strict : sum_file_data_permissive;
+       struct stat64 dir_st;
+
+       if (fstat64(dirfd, &dir_st)) {
+               perror("fstat");
+               exit(-1);
+       }
 
        d = fdopendir(dirfd);
        if (!d) {
@@ -570,6 +576,11 @@ sum(int dirfd, int level, sum_t *dircs, char *path_prefix, char *path_in)
                                path_prefix, path, strerror(errno));
                        exit(-1);
                }
+
+               /* We are crossing into a different subvol, skip this subtree. */
+               if (st.st_dev != dir_st.st_dev)
+                       goto next;
+
                sum_add_u64(&meta, level);
                sum_add(&meta, namelist[i], strlen(namelist[i]));
                if (!S_ISDIR(st.st_mode))
--

2.23.0

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”