Skip to contentSkip to conversation

growfiles:fix test failure due to missing directory

PATCH Superseded [email protected] 3 participants 4 messages Apr 9 – May 6

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 growfiles:fix test failure due to missing directory

From: lekshmi-cpillai <[email protected]>

---
 testcases/kernel/fs/doio/growfiles.c | 35 +++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
testcases/kernel/fs/doio/growfiles.c +34 -1
index 21960f82a..5a76ef4c5 100644
@@ -119,6 +119,38 @@ int lkfile(int fd, int operation, int lklevel);
 int pre_alloc(int fd, long size);
 #endif /* !linux */
 
+/* Helper function to create directories recursively */
+static int mkdir_recursive(const char *path, mode_t mode)
+{
+	char tmp[PATH_MAX];
+	char *p = NULL;
+	size_t len;
+	struct stat st;
+
+	snprintf(tmp, sizeof(tmp), "%s", path);
+	len = strlen(tmp);
+	if (tmp[len - 1] == '/')
+		tmp[len - 1] = 0;
+
+	for (p = tmp + 1; *p; p++) {
+		if (*p == '/') {
+			*p = 0;
+			if (stat(tmp, &st) == -1) {
+				if (mkdir(tmp, mode) == -1 && errno != EEXIST) {
+					return -1;
+				}
+			}
+			*p = '/';
+		}
+	}
+	if (stat(tmp, &st) == -1) {
+		if (mkdir(tmp, mode) == -1 && errno != EEXIST) {
+			return -1;
+		}
+	}
+	return 0;
+}
+
 extern int datapidgen(int, char *, int, int);
 extern int datapidchk(int, char *, int, int, char **);
 
@@ -482,7 +514,7 @@ int main(int argc, char **argv)
 			unsetenv("TMPDIR");	/* force the use of auto_dir */
 #endif
 			if (stat(auto_dir, &statbuf) == -1) {
-				if (mkdir(auto_dir, 0777) == -1) {
+				if (mkdir_recursive(auto_dir, 0777) == -1) {
 					if (errno != EEXIST) {
 						fprintf(stderr,
 							"%s%s: Unable to make dir %s\n",
@@ -3058,3 +3090,4 @@ int pre_alloc(int fd, long size)
 	return 0;
 }
 #endif
+
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!
Again you have send the patch twice, is there something wrong with your email setup?

Quoted 1 line

From: lekshmi-cpillai <[email protected]>

^
This stil isn't a clear description why these changes are needed.

Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

PATCH v3 1/1 growfiles:fix test failure due to missing directory /test/growfiles/reiser

In reply to [email protected]

From: lekshmi-cpillai <[email protected]>

-The test attempts to creates the required directory structure recursively(which was not in current code),Sets appropriate permissions (0755)and Verifies the directory is accessible -Added proper error handling

---
 testcases/kernel/fs/doio/growfiles.c | 35 +++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)
testcases/kernel/fs/doio/growfiles.c +34 -1
index 21960f82a..5a76ef4c5 100644
@@ -119,6 +119,38 @@ int lkfile(int fd, int operation, int lklevel);
 int pre_alloc(int fd, long size);
 #endif /* !linux */
 
+/* Helper function to create directories recursively */
+static int mkdir_recursive(const char *path, mode_t mode)
+{
+	char tmp[PATH_MAX];
+	char *p = NULL;
+	size_t len;
+	struct stat st;
+
+	snprintf(tmp, sizeof(tmp), "%s", path);
+	len = strlen(tmp);
+	if (tmp[len - 1] == '/')
+		tmp[len - 1] = 0;
+
+	for (p = tmp + 1; *p; p++) {
+		if (*p == '/') {
+			*p = 0;
+			if (stat(tmp, &st) == -1) {
+				if (mkdir(tmp, mode) == -1 && errno != EEXIST) {
+					return -1;
+				}
+			}
+			*p = '/';
+		}
+	}
+	if (stat(tmp, &st) == -1) {
+		if (mkdir(tmp, mode) == -1 && errno != EEXIST) {
+			return -1;
+		}
+	}
+	return 0;
+}
+
 extern int datapidgen(int, char *, int, int);
 extern int datapidchk(int, char *, int, int, char **);
 
@@ -482,7 +514,7 @@ int main(int argc, char **argv)
 			unsetenv("TMPDIR");	/* force the use of auto_dir */
 #endif
 			if (stat(auto_dir, &statbuf) == -1) {
-				if (mkdir(auto_dir, 0777) == -1) {
+				if (mkdir_recursive(auto_dir, 0777) == -1) {
 					if (errno != EEXIST) {
 						fprintf(stderr,
 							"%s%s: Unable to make dir %s\n",
@@ -3058,3 +3090,4 @@ int pre_alloc(int fd, long size)
 	return 0;
 }
 #endif
+
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v3] growfiles:fix test failure due to missing directory /test/growfiles/reiser

Hi,

our Agent review was missing in the ML.
Here it is the result, which seems ok, unless you want to add some notes to it.

Quoted 1 line · lekshmi-cpillai

growfiles:fix test failure due to missing directory /test/growfiles/reiser

Hi lekshmi,

Quoted 2 lines

-The test attempts to creates the required directory structure recursively(which was not in current code),Sets appropria te permissions (0755)and Verifies the directory is accessible

The body only describes what was changed, not why the directory is missing at runtime. Please explain the root cause: under what conditions does growfiles encounter a path whose intermediate directories do not exist, and why is /test/growfiles/reiser specifically affected?

The body also has typos ("appropria te" → "appropriate", "attempts to creates" → "attempts to create") and the subject is missing a space after the colon ("growfiles:fix" → "growfiles: fix").

testcases/kernel/fs/doio/growfiles.c int lkfile(int fd, int operation, int lklevel); · line 139

Quoted 4 lines
testcases/kernel/fs/doio/growfiles.c +3 -0
+	struct stat st;
...
+		if (stat(tmp, &st) == -1) {
+			if (mkdir(tmp, mode) == -1 && errno != EEXIST) {

The stat() result (st) is never read — only its return value is used. Drop the stat() call and call mkdir() directly; treat EEXIST as success. This simplifies the code and avoids a TOCTOU window between stat and mkdir.

Regards,
LTP AI Reviewer

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp