public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] fs: fsstress: make test more POSIX compliant
@ 2011-03-14 12:03 Caspar Zhang
  2011-03-16 12:07 ` Cyril Hrubis
  0 siblings, 1 reply; 4+ messages in thread
From: Caspar Zhang @ 2011-03-14 12:03 UTC (permalink / raw)
  To: LTP list

[-- Attachment #1: Type: text/plain, Size: 3364 bytes --]

[PATCH] fs: fsstress: make test more POSIX compliant

in commit bacc849720ec4efda5a0a8a9ea6a0e93a1415541, malloc.h was removed
and stdlib.h got used instead. However, it's not enough. The function
memalign() is also obsolete (via man memalign) and we should use
posix_memalign instead. Also if we keep memalign() function here, the
program would probably hit segfault once it enters dwrite_t and dread_t.

Besides the POSIX compliant fix, I also did a small fix to remove
compling warnings.

I tried to update this program output to tst_resm/tst_brkm style but
failed, I got confused by some printf output.

Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
 testcases/kernel/fs/fsstress/fsstress.c |   38
++++++++++++++++++------------
 1 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/testcases/kernel/fs/fsstress/fsstress.c
b/testcases/kernel/fs/fsstress/fsstress.c
index e3b48ea..0e5fba2 100644
--- a/testcases/kernel/fs/fsstress/fsstress.c
+++ b/testcases/kernel/fs/fsstress/fsstress.c
@@ -1746,7 +1746,7 @@ void
 dread_f(int opno, long r)
 {
 	__int64_t	align;
-	char		*buf;
+	char		*buf=NULL;
 	struct dioattr	diob;
 	int		e;
 	pathname_t	f;
@@ -1799,11 +1799,9 @@ dread_f(int opno, long r)
 		return;
 	}

-	if (no_xfs) {
-		diob.d_miniosz = stb.st_blksize;
-		diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
-		diob.d_mem = stb.st_blksize;
-	}
+	diob.d_miniosz = stb.st_blksize;
+	diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
+	diob.d_mem = stb.st_blksize;
 #ifndef NO_XFS
 	else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
 		if (v)
@@ -1826,7 +1824,13 @@ dread_f(int opno, long r)
 		len = align;
 	else if (len > diob.d_maxiosz)
 		len = diob.d_maxiosz;
-	buf = memalign(diob.d_mem, len);
+	if (posix_memalign((void **)buf, diob.d_mem, len) != 0) {
+		perror("posix_memalign");
+		exit (1);
+	} else if (buf == NULL) {
+		fprintf(stderr, "buf remains NULL unexpectly\n");
+		exit (1);
+	}
 	e = read(fd, buf, len) < 0 ? errno : 0;
 	free(buf);
 	if (v)
@@ -1840,7 +1844,7 @@ void
 dwrite_f(int opno, long r)
 {
 	__int64_t	align;
-	char		*buf;
+	char		*buf=NULL;
 	struct dioattr	diob;
 	int		e;
 	pathname_t	f;
@@ -1882,11 +1886,9 @@ dwrite_f(int opno, long r)
 		close(fd);
 		return;
 	}
-	if (no_xfs) {
-		diob.d_miniosz = stb.st_blksize;
-		diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
-		diob.d_mem = stb.st_blksize;
-	}
+	diob.d_miniosz = stb.st_blksize;
+	diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
+	diob.d_mem = stb.st_blksize;
 #ifndef NO_XFS
 	else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
 		if (v)
@@ -1909,7 +1911,13 @@ dwrite_f(int opno, long r)
 		len = align;
 	else if (len > diob.d_maxiosz)
 		len = diob.d_maxiosz;
-	buf = memalign(diob.d_mem, len);
+	if (posix_memalign((void **)buf, diob.d_mem, len) != 0) {
+		perror("posix_memalign");
+		exit (1);
+	} else if (buf == NULL)	{
+		fprintf(stderr, "buf remains NULL unexpectly\n");
+		exit (1);
+	}
 	off %= maxfsize;
 	lseek64(fd, off, SEEK_SET);
 	memset(buf, nameseq & 0xff, len);
@@ -2650,4 +2658,4 @@ write_f(int opno, long r)
 			procid, opno, f.path, (long long)off, (long int)len, e);
 	free_pathname(&f);
 	close(fd);
-}
\ No newline at end of file
+}
-- 
1.7.4.1


-- 
Quality Engineer (Kernel) in
Red Hat Software (Beijing) Co., R&D Branch
http://www.cn.redhat.com/
TEL: +86-10-62608150

[-- Attachment #2: 0001-fs-fsstress-make-test-more-POSIX-compliant.patch --]
[-- Type: text/plain, Size: 3241 bytes --]

[PATCH] fs: fsstress: make test more POSIX compliant

in commit bacc849720ec4efda5a0a8a9ea6a0e93a1415541, malloc.h was removed
and stdlib.h got used instead. However, it's not enough. The function
memalign() is also obsolete (via man memalign) and we should use
posix_memalign instead. Also if we keep memalign() function here, the
program would probably hit segfault once it enters dwrite_t and dread_t.

Besides the POSIX compliant fix, I also did a small fix to remove
compling warnings.

I tried to update this program output to tst_resm/tst_brkm style but
failed, I got confused by some printf output.

Signed-off-by: Caspar Zhang <czhang@redhat.com>
---
 testcases/kernel/fs/fsstress/fsstress.c |   38 ++++++++++++++++++------------
 1 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/testcases/kernel/fs/fsstress/fsstress.c b/testcases/kernel/fs/fsstress/fsstress.c
index e3b48ea..0e5fba2 100644
--- a/testcases/kernel/fs/fsstress/fsstress.c
+++ b/testcases/kernel/fs/fsstress/fsstress.c
@@ -1746,7 +1746,7 @@ void
 dread_f(int opno, long r)
 {
 	__int64_t	align;
-	char		*buf;
+	char		*buf=NULL;
 	struct dioattr	diob;
 	int		e;
 	pathname_t	f;
@@ -1799,11 +1799,9 @@ dread_f(int opno, long r)
 		return;
 	}
 
-	if (no_xfs) {
-		diob.d_miniosz = stb.st_blksize;
-		diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
-		diob.d_mem = stb.st_blksize;
-	}
+	diob.d_miniosz = stb.st_blksize;
+	diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
+	diob.d_mem = stb.st_blksize;
 #ifndef NO_XFS
 	else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
 		if (v)
@@ -1826,7 +1824,13 @@ dread_f(int opno, long r)
 		len = align;
 	else if (len > diob.d_maxiosz)
 		len = diob.d_maxiosz;
-	buf = memalign(diob.d_mem, len);
+	if (posix_memalign((void **)buf, diob.d_mem, len) != 0) {
+		perror("posix_memalign");
+		exit (1);
+	} else if (buf == NULL) {
+		fprintf(stderr, "buf remains NULL unexpectly\n");
+		exit (1);
+	}
 	e = read(fd, buf, len) < 0 ? errno : 0;
 	free(buf);
 	if (v)
@@ -1840,7 +1844,7 @@ void
 dwrite_f(int opno, long r)
 {
 	__int64_t	align;
-	char		*buf;
+	char		*buf=NULL;
 	struct dioattr	diob;
 	int		e;
 	pathname_t	f;
@@ -1882,11 +1886,9 @@ dwrite_f(int opno, long r)
 		close(fd);
 		return;
 	}
-	if (no_xfs) {
-		diob.d_miniosz = stb.st_blksize;
-		diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
-		diob.d_mem = stb.st_blksize;
-	}
+	diob.d_miniosz = stb.st_blksize;
+	diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
+	diob.d_mem = stb.st_blksize;
 #ifndef NO_XFS
 	else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
 		if (v)
@@ -1909,7 +1911,13 @@ dwrite_f(int opno, long r)
 		len = align;
 	else if (len > diob.d_maxiosz)
 		len = diob.d_maxiosz;
-	buf = memalign(diob.d_mem, len);
+	if (posix_memalign((void **)buf, diob.d_mem, len) != 0) {
+		perror("posix_memalign");
+		exit (1);
+	} else if (buf == NULL)	{
+		fprintf(stderr, "buf remains NULL unexpectly\n");
+		exit (1);
+	}
 	off %= maxfsize;
 	lseek64(fd, off, SEEK_SET);
 	memset(buf, nameseq & 0xff, len);
@@ -2650,4 +2658,4 @@ write_f(int opno, long r)
 			procid, opno, f.path, (long long)off, (long int)len, e);
 	free_pathname(&f);
 	close(fd);
-}
\ No newline at end of file
+}
-- 
1.7.4.1


[-- Attachment #3: Type: text/plain, Size: 249 bytes --]

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] fs: fsstress: make test more POSIX compliant
  2011-03-14 12:03 [LTP] [PATCH] fs: fsstress: make test more POSIX compliant Caspar Zhang
@ 2011-03-16 12:07 ` Cyril Hrubis
       [not found]   ` <4D80A5E1.2020002@redhat.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Cyril Hrubis @ 2011-03-16 12:07 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP list

Hi!
> -	if (no_xfs) {
> -		diob.d_miniosz = stb.st_blksize;
> -		diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
> -		diob.d_mem = stb.st_blksize;
> -	}
> +	diob.d_miniosz = stb.st_blksize;
> +	diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
> +	diob.d_mem = stb.st_blksize;

Hmm, why you are removing the if (no_xfs) here (I don't say it's wrong,
I only want to know why)?

>  #ifndef NO_XFS
>  	else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
>  		if (v)
> @@ -1826,7 +1824,13 @@ dread_f(int opno, long r)
>  		len = align;
>  	else if (len > diob.d_maxiosz)
>  		len = diob.d_maxiosz;
> -	buf = memalign(diob.d_mem, len);
> +	if (posix_memalign((void **)buf, diob.d_mem, len) != 0) {

The posix_memalign() actually returns pointer to the memory via buf, so
instead of (void **)buf, you should write &buf (and that would silence
the warning about uninitalized buf too).

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] fs: fsstress: make test more POSIX compliant
       [not found]   ` <4D80A5E1.2020002@redhat.com>
@ 2011-03-16 12:51     ` Cyril Hrubis
  2011-03-16 13:12     ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2011-03-16 12:51 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP list

Hi!
> >> -	if (no_xfs) {
> >> -		diob.d_miniosz = stb.st_blksize;
> >> -		diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
> >> -		diob.d_mem = stb.st_blksize;
> >> -	}
> >> +	diob.d_miniosz = stb.st_blksize;
> >> +	diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
> >> +	diob.d_mem = stb.st_blksize;
> > 
> > Hmm, why you are removing the if (no_xfs) here (I don't say it's wrong,
> > I only want to know why)?
> 
> The compiler gave warning that diob.d_* may not initialized. I don't
> know what the values diob.d_* should be if XFS exists (no_xfs == 0), but
> I guess they should be the same as when XFS not available.
> 
> > 
> >>  #ifndef NO_XFS
> >>  	else if (ioctl(fd, XFS_IOC_DIOINFO, &diob) < 0) {
> >>  		if (v)
> >> @@ -1826,7 +1824,13 @@ dread_f(int opno, long r)
> >>  		len = align;
> >>  	else if (len > diob.d_maxiosz)
> >>  		len = diob.d_maxiosz;
> >> -	buf = memalign(diob.d_mem, len);
> >> +	if (posix_memalign((void **)buf, diob.d_mem, len) != 0) {
> > 
> > The posix_memalign() actually returns pointer to the memory via buf, so
> > instead of (void **)buf, you should write &buf (and that would silence
> > the warning about uninitalized buf too).
> > 
> 
> sorry, my mistake. I'll correct it. Btw, compiler kept silent when I
> missed & sign..

That's because of the (void **) cast. The char * and void ** are
not compatible pointers and copiler should print a warning about
incompatible type. On the other hand void ** and char ** are
incompatible pointers too.

As one wise man said: "C is a Spartan language" ...

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [LTP] [PATCH] fs: fsstress: make test more POSIX compliant
       [not found]   ` <4D80A5E1.2020002@redhat.com>
  2011-03-16 12:51     ` Cyril Hrubis
@ 2011-03-16 13:12     ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2011-03-16 13:12 UTC (permalink / raw)
  To: Caspar Zhang; +Cc: LTP list

Hi!
> >> -	if (no_xfs) {
> >> -		diob.d_miniosz = stb.st_blksize;
> >> -		diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
> >> -		diob.d_mem = stb.st_blksize;
> >> -	}
> >> +	diob.d_miniosz = stb.st_blksize;
> >> +	diob.d_maxiosz = stb.st_blksize * 256;  /* good number ? */
> >> +	diob.d_mem = stb.st_blksize;
> > 
> > Hmm, why you are removing the if (no_xfs) here (I don't say it's wrong,
> > I only want to know why)?
> 
> The compiler gave warning that diob.d_* may not initialized. I don't
> know what the values diob.d_* should be if XFS exists (no_xfs == 0), but
> I guess they should be the same as when XFS not available.

Actually it's a little more complicated. This change breaks compilation
without -DNO_XFS (that is defined as default in Makefile).

The whole point of NO_XFS and no_xfs is that the test may be compiled
with and without xfs specialities as well as executed with and without
xfs specialities.

-- 
Cyril Hrubis
chrubis@suse.cz

------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-16 12:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-14 12:03 [LTP] [PATCH] fs: fsstress: make test more POSIX compliant Caspar Zhang
2011-03-16 12:07 ` Cyril Hrubis
     [not found]   ` <4D80A5E1.2020002@redhat.com>
2011-03-16 12:51     ` Cyril Hrubis
2011-03-16 13:12     ` Cyril Hrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox