Skip to contentSkip to conversation

t_stripealign: Fix fibmap error handling

PATCH In review Carlos Maiolino 3 participants 4 messages Aug 23, 2019 – Aug 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 t_stripealign: Fix fibmap error handling

FIBMAP only returns a negative value when the underlying filesystem does not support FIBMAP or on permission error. For the remaining errors, i.e. those usually returned from the filesystem itself, zero will be returned.

We can not trust a zero return from the FIBMAP, and such behavior made generic/223 succeed when it should not.

Also, we can't use perror() only to print errors when FIBMAP failed, or it will simply print 'success' when a zero is returned.

---
 src/t_stripealign.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
src/t_stripealign.c +5 -2
index 5cdadaae..164831f8 100644
@@ -76,8 +76,11 @@ int main(int argc, char ** argv)
 		unsigned int	bmap = 0;
 
 		ret = ioctl(fd, FIBMAP, &bmap);
-		if (ret < 0) {
-			perror("fibmap");
+		if (ret <= 0) {
+			if (ret < 0)
+				perror("fibmap");
+			else
+				fprintf(stderr, "fibmap error\n");
 			free(fie);
 			close(fd);
 			return 1;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 21 lines · Carlos Maiolino

FIBMAP only returns a negative value when the underlying filesystem does not support FIBMAP or on permission error. For the remaining errors, i.e. those usually returned from the filesystem itself, zero will be returned.

We can not trust a zero return from the FIBMAP, and such behavior made generic/223 succeed when it should not.

Also, we can't use perror() only to print errors when FIBMAP failed, or it will simply print 'success' when a zero is returned.

---
 src/t_stripealign.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
src/t_stripealign.c +0 -0
index 5cdadaae..164831f8 100644

src/t_stripealign.c int main(int argc, char ** argv) · line 83

Quoted 10 lines
src/t_stripealign.c +5 -2
@@ -76,8 +76,11 @@ int main(int argc, char ** argv)
 		unsigned int	bmap = 0;
 
 		ret = ioctl(fd, FIBMAP, &bmap);
-		if (ret < 0) {
-			perror("fibmap");
+		if (ret <= 0) {
+			if (ret < 0)
+				perror("fibmap");
+			else
+				fprintf(stderr, "fibmap error\n");

"fibmap returned no result"?

--D

Quoted 6 lines
src/t_stripealign.c +0 -0
 			free(fie);
 			close(fd);
 			return 1;
Signature · 1 line
2.20.1
#2 lore raw
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Carlos Maiolino

FIBMAP only returns a negative value when the underlying filesystem does not support FIBMAP or on permission error. For the remaining errors, i.e. those usually returned from the filesystem itself, zero will be returned.

We can not trust a zero return from the FIBMAP, and such behavior made generic/223 succeed when it should not.

Also, we can't use perror() only to print errors when FIBMAP failed, or it will simply print 'success' when a zero is returned.

---
 src/t_stripealign.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
src/t_stripealign.c +0 -0
index 5cdadaae..164831f8 100644
@@ -76,8 +76,11 @@ int main(int argc, char ** argv)
 		unsigned int	bmap = 0;
 
Quoted 10 lines

src/t_stripealign.c int main(int argc, char ** argv) · line 83

Quoted 8 lines
src/t_stripealign.c +5 -2
 		ret = ioctl(fd, FIBMAP, &bmap);
-		if (ret < 0) {
-			perror("fibmap");
+		if (ret <= 0) {
+			if (ret < 0)
+				perror("fibmap");
+			else
+				fprintf(stderr, "fibmap error\n");

"fibmap returned no result"?

Fixed on commit. Thanks!

Eryu

#3 lore raw
Quoted 36 lines · Eryu Guan
Quoted 24 lines · Darrick J. Wong
Quoted 23 lines · Carlos Maiolino

FIBMAP only returns a negative value when the underlying filesystem does not support FIBMAP or on permission error. For the remaining errors, i.e. those usually returned from the filesystem itself, zero will be returned.

We can not trust a zero return from the FIBMAP, and such behavior made generic/223 succeed when it should not.

Also, we can't use perror() only to print errors when FIBMAP failed, or it will simply print 'success' when a zero is returned.

---
 src/t_stripealign.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
src/t_stripealign.c +0 -0
index 5cdadaae..164831f8 100644
@@ -76,8 +76,11 @@ int main(int argc, char ** argv)
 		unsigned int	bmap = 0;
 
Quoted 10 lines

src/t_stripealign.c int main(int argc, char ** argv) · line 83

Quoted 8 lines
src/t_stripealign.c +5 -2
 		ret = ioctl(fd, FIBMAP, &bmap);
-		if (ret < 0) {
-			perror("fibmap");
+		if (ret <= 0) {
+			if (ret < 0)
+				perror("fibmap");
+			else
+				fprintf(stderr, "fibmap error\n");

"fibmap returned no result"?

Quoted 1 line

Fixed on commit. Thanks!

TZ discrepancy. Thanks for fixing it on commit Eryu :)

Quoted 2 lines

Eryu

Signature · 1 line
Carlos