Skip to contentSkip to conversation

Fix for syscalls/utimensat01 test on Ubuntu 4.4 kernel

PATCH New Po-Hsu Lin 2 participants 8 messages Aug 18, 2020 – Aug 19, 2020 Library code

lore
Share & tools
lore

Po-Hsu Lin

author
#0 lore raw

v2 cover Fix for syscalls/utimensat01 test on Ubuntu 4.4 kernel

Ubuntu 4.4 kernel got the backported kernel patch (b3b4283) for syscalls/utimensat01 since 4.4.0-48.69, therefore it will return EPERM instead of EACCES.

Without this fix, the test will fail on Ubuntu 4.4 kernel with:
FAIL: 18: utimensat() failed with incorrect error, expected EACCES: EPERM (1)
FAIL: 19: utimensat() failed with incorrect error, expected EACCES: EPERM (1)

Add Ubuntu kernel version comparison to fix this.

Also add support to get the distname for different OS by parsing ID= from /etc/os-release in tst_kvcmp_distname()

Po-Hsu Lin (2):
lib/tst_kvercmp: Add support to get distname for different OS in
tst_kvcmp_distname
syscalls/utimensat01: add exception for Ubuntu 4.4 kernel

 lib/tst_kvercmp.c                                | 16 ++++++++++++++++
 .../kernel/syscalls/utimensat/utimensat01.c      |  7 ++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH v2 1/2 lib/tst_kvercmp: Add support to get distname for different OS in tst_kvcmp_distname

The kver on Ubuntu will be something like these:
* 4.4.0-187-generic
* 5.4.0-1021-kvm
* 4.15.0-1093-azure

So it's better to parse OS name from ID= in /etc/os-release, instead of doing this from checking kver substring like what we did for RHEL and Oracle Linux here.

From the document [1] this string will alway be in lowercase. Example:
"ID=fedora" or "ID=debian". Thus it needs to be converted to uppercase to make it consistent with other return values in tst_kvcmp_distname().

Note that if ID was not set, it will default to "ID=linux". Thus we can expect to get LINUX on some distros.

[1] https://www.freedesktop.org/software/systemd/man/os-release.html

---
 lib/tst_kvercmp.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
lib/tst_kvercmp.c +16 -0
index dc3bb669b..af6c6de69 100644
@@ -18,6 +18,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <ctype.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -25,6 +26,8 @@
 #include <sys/utsname.h>
 #include "test.h"
 
+#define OSRELEASE_PATH "/etc/os-release"
+
 static char *parse_digit(const char *str, int *d)
 {
 	unsigned long v;
@@ -127,6 +130,8 @@ int tst_kvexcmp(const char *tst_exv, const char *cur_ver)
 
 const char *tst_kvcmp_distname(const char *kver)
 {
+	static char distname[64];
+	char *tok;
 	if (strstr(kver, ".el5uek"))
 		return "OL5UEK";
 
@@ -139,6 +144,17 @@ const char *tst_kvcmp_distname(const char *kver)
 	if (strstr(kver, ".el6"))
 		return "RHEL6";
 
+	// Special case for other releases with the presencse of /etc/os-release
+	if (access(OSRELEASE_PATH, F_OK) != -1) {
+		SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
+		tok = strtok(distname,"\0");
+		while (*tok) {
+			*tok = toupper((unsigned char) *tok);
+			tok++;
+		}
+		return distname;
+	}
+
 	return NULL;
 }
 
Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 1/2 lib/tst_kvercmp: Add support to get distname for different OS in tst_kvcmp_distname

Hi!

Quoted 13 lines

static char *parse_digit(const char *str, int *d) {

lib/tst_kvercmp.c +2 -0
 	unsigned long v;
@@ -127,6 +130,8 @@ int tst_kvexcmp(const char *tst_exv, const char *cur_ver)
 
 const char *tst_kvcmp_distname(const char *kver)
 {
+	static char distname[64];
+	char *tok;
 	if (strstr(kver, ".el5uek"))
 		return "OL5UEK";
 

lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 150

Quoted 7 lines
lib/tst_kvercmp.c +4 -0
@@ -139,6 +144,17 @@ const char *tst_kvcmp_distname(const char *kver)
 	if (strstr(kver, ".el6"))
 		return "RHEL6";
 
+	// Special case for other releases with the presencse of /etc/os-release
+	if (access(OSRELEASE_PATH, F_OK) != -1) {
+		SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
+		tok = strtok(distname,"\0");

Isn't this strtok() useless?

Other than that the patchset looks fine.

Quoted 13 lines
lib/tst_kvercmp.c +7 -0
+		while (*tok) {
+			*tok = toupper((unsigned char) *tok);
+			tok++;
+		}
+		return distname;
+	}
+
 	return NULL;
 }
 
Signature · 1 line
2.25.1
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#3 lore raw

PATCH v2 1/2 lib/tst_kvercmp: Add support to get distname for different OS in tst_kvcmp_distname

Quoted 18 lines · Cyril Hrubis

Hi!

Quoted 16 lines

static char *parse_digit(const char *str, int *d)

 {
      unsigned long v;
lib/tst_kvercmp.c +2 -0
@@ -127,6 +130,8 @@ int tst_kvexcmp(const char *tst_exv, const char *cur_ver)
 
 const char *tst_kvcmp_distname(const char *kver)
 {
+     static char distname[64];
+     char *tok;
      if (strstr(kver, ".el5uek"))
              return "OL5UEK";
 
@@ -139,6 +144,17 @@ const char *tst_kvcmp_distname(const char *kver)
      if (strstr(kver, ".el6"))
              return "RHEL6";
 
Quoted 6 lines

lib/tst_kvercmp.c const char *tst_kvcmp_distname(const char *kver) · line 150

Quoted 4 lines
lib/tst_kvercmp.c +4 -0
+     // Special case for other releases with the presencse of /etc/os-release
+     if (access(OSRELEASE_PATH, F_OK) != -1) {
+             SAFE_FILE_LINES_SCANF(NULL, OSRELEASE_PATH, "ID=%s", distname);
+             tok = strtok(distname,"\0");

Isn't this strtok() useless?

Hello,
oh indeed, the delimiter in strtok will become null character anyway. I think just tok = distname can do the trick here.
I will send v3 tomorrow.

Thank you

Quoted 21 lines

Other than that the patchset looks fine.

Quoted 11 lines
lib/tst_kvercmp.c +7 -1
+             while (*tok) {
+                     *tok = toupper((unsigned char) *tok);
+                     tok++;
+             }
+             return distname;
+     }
+
      return NULL;
 }
 
--
Quoted 2 lines

2.25.1

--
Cyril Hrubis
[email protected]

#4 lore raw

PATCH v2 1/2 lib/tst_kvercmp: Add support to get distname for different OS in tst_kvcmp_distname

Hi!

Quoted 3 lines

oh indeed, the delimiter in strtok will become null character anyway. I think just tok = distname can do the trick here.
I will send v3 tomorrow.

I can easily fix that before I push the patch, no need for v3.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#5 lore raw

PATCH v2 1/2 lib/tst_kvercmp: Add support to get distname for different OS in tst_kvcmp_distname

Quoted 7 lines · Cyril Hrubis

Hi!

Quoted 3 lines

oh indeed, the delimiter in strtok will become null character anyway. I think just tok = distname can do the trick here.
I will send v3 tomorrow.

I can easily fix that before I push the patch, no need for v3.

Hello Cyril,
that would be great, thanks for the review!

Quoted 4 lines

--
Cyril Hrubis
[email protected]

#6 lore raw

PATCH v2 1/2 lib/tst_kvercmp: Add support to get distname for different OS in tst_kvcmp_distname

Hi!
Both patches pushed with a minor changes, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#7 lore raw

PATCH v2 2/2 syscalls/utimensat01: add exception for Ubuntu 4.4 kernel

In reply to Po-Hsu Lin

Ubuntu 4.4 kernel got this patch (b3b4283) since 4.4.0-48.69, therefore it will return EPERM instead of EACCES.

Without this fix, the test will fail on Ubuntu 4.4 kernel with:
FAIL: 18: utimensat() failed with incorrect error, expected EACCES: EPERM (1)
FAIL: 19: utimensat() failed with incorrect error, expected EACCES: EPERM (1)

---
 testcases/kernel/syscalls/utimensat/utimensat01.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/utimensat/utimensat01.c +6 -1
index 7dabfed6d..de4f0601b 100644
@@ -158,6 +158,11 @@ static void tst_multi_set_time(enum tst_ts_type type, struct mytime *mytime)
 
 static void update_error(struct test_case *tc)
 {
+	// Special case for Ubuntu kernel, which has patch b3b4283 since 4.4.0-48.69
+	static struct tst_kern_exv kvers[] = {
+		{ "UBUNTU", "4.4.0-48.69" },
+	};
+
 	if (tc->exp_err != -1)
 		return;
 
@@ -167,7 +172,7 @@ static void update_error(struct test_case *tc)
 	 * This patch has also been merged to stable 4.4 with
 	 * b3b4283 ("vfs: move permission checking into notify_change() for utimes(NULL)")
 	 */
-	if (tst_kvercmp(4, 4, 27) < 0)
+	if (tst_kvercmp2(4, 4, 27, kvers) < 0)
 		tc->exp_err = EACCES;
 	else
 		tc->exp_err = EPERM;
Signature · 1 line
2.25.1