diff mbox series

[3/3] libltpswap: TCONF on EPERM

Message ID 20231011160822.578637-4-pvorel@suse.cz
State Accepted
Headers show
Series Cleanup tst_ioctl.c, libswap.c | expand

Commit Message

Petr Vorel Oct. 11, 2023, 4:08 p.m. UTC
Although tests, which use tst_fibmap() should use .needs_root = 1
to avoid EPERM, let's add a sanity check in case it's not used.

Signed-off-by: Petr Vorel <pvorel@suse.cz>
---
 libs/libltpswap/libswap.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Cyril Hrubis Dec. 8, 2023, 4:02 p.m. UTC | #1
Hi!
> +		if (fibmap == 1) {
> +			if (errno == EINVAL)
> +				tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
> +			if (errno == EPERM)
> +				tst_brk(TCONF, "No permission for swapon() on %s", fstype);

I'm not sure if we actually need to print the filesystem type in the
case that we do not have a permission to do swapon.

Also this kind of works because the fibmap ioctl() fails as well,
however I guess that this should really be:

	if (errno == EPERM)
		tst_brk(TCONF, "Permission denied for swapon()");
	else if (fibmap == 1 && errno == EINVAL)
		tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
	else
		tst_brk(TFAIL | TTERNO, ...);

> +		} else {
>  			tst_brk(TFAIL | TTERRNO, "swapon on %s failed", fstype);
> +		}
>  	}
>  
>  	TEST(tst_syscall(__NR_swapoff, filename, 0));
> -- 
> 2.42.0
>
Petr Vorel Dec. 10, 2023, 4:24 p.m. UTC | #2
Hi Cyril,

> Hi!
> > +		if (fibmap == 1) {
> > +			if (errno == EINVAL)
> > +				tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
> > +			if (errno == EPERM)
> > +				tst_brk(TCONF, "No permission for swapon() on %s", fstype);

> I'm not sure if we actually need to print the filesystem type in the
> case that we do not have a permission to do swapon.

> Also this kind of works because the fibmap ioctl() fails as well,
> however I guess that this should really be:

> 	if (errno == EPERM)
> 		tst_brk(TCONF, "Permission denied for swapon()");
> 	else if (fibmap == 1 && errno == EINVAL)
> 		tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
> 	else
> 		tst_brk(TFAIL | TTERNO, ...);

Ah, that's actually better, thanks!
Tomorrow, I'll modify it and merge with your RBT.

Kind regards,
Petr

> > +		} else {
> >  			tst_brk(TFAIL | TTERRNO, "swapon on %s failed", fstype);
> > +		}
> >  	}

> >  	TEST(tst_syscall(__NR_swapoff, filename, 0));
> > -- 
> > 2.42.0
Petr Vorel Dec. 11, 2023, 5:28 a.m. UTC | #3
Hi Cyril,

commit merged, thanks!

Kind regards,
Petr
diff mbox series

Patch

diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index a4427736f..4ef24ef5c 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -53,10 +53,14 @@  void is_swap_supported(const char *filename)
 
 	TEST(tst_syscall(__NR_swapon, filename, 0));
 	if (TST_RET == -1) {
-		if (fibmap == 1 && errno == EINVAL)
-			tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
-		else
+		if (fibmap == 1) {
+			if (errno == EINVAL)
+				tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
+			if (errno == EPERM)
+				tst_brk(TCONF, "No permission for swapon() on %s", fstype);
+		} else {
 			tst_brk(TFAIL | TTERRNO, "swapon on %s failed", fstype);
+		}
 	}
 
 	TEST(tst_syscall(__NR_swapoff, filename, 0));