linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] proc: smoke test lseek()
       [not found] <20210328221524.ukfuztGsl%akpm@linux-foundation.org>
@ 2021-04-07 19:55 ` Alexey Dobriyan
  2021-04-07 19:58   ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2021-04-07 19:55 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, linux-fsdevel

Now that ->proc_lseek has been made mandatory it would be nice to test
that nothing has been forgotten.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

		May want to fold into
	proc-mandate-proc_lseek-in-struct-proc_ops.patch

 tools/testing/selftests/proc/read.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/tools/testing/selftests/proc/read.c
+++ b/tools/testing/selftests/proc/read.c
@@ -14,7 +14,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 // Test
-// 1) read of every file in /proc
+// 1) read and lseek on every file in /proc
 // 2) readlink of every symlink in /proc
 // 3) recursively (1) + (2) for every directory in /proc
 // 4) write to /proc/*/clear_refs and /proc/*/task/*/clear_refs
@@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename)
 	fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
 	if (fd == -1)
 		return;
+	/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
+	(void)lseek(fd, 0, SEEK_SET);
 	rv = read(fd, buf, sizeof(buf));
 	assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
 	close(fd);

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

* Re: [PATCH] proc: smoke test lseek()
  2021-04-07 19:55 ` [PATCH] proc: smoke test lseek() Alexey Dobriyan
@ 2021-04-07 19:58   ` Matthew Wilcox
  2021-04-07 20:06     ` Alexey Dobriyan
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2021-04-07 19:58 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: akpm, linux-kernel, linux-fsdevel

On Wed, Apr 07, 2021 at 10:55:14PM +0300, Alexey Dobriyan wrote:
> Now that ->proc_lseek has been made mandatory it would be nice to test
> that nothing has been forgotten.

> @@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename)
>  	fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
>  	if (fd == -1)
>  		return;
> +	/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
> +	(void)lseek(fd, 0, SEEK_SET);
>  	rv = read(fd, buf, sizeof(buf));
>  	assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
>  	close(fd);

why throw away the return value?  if it returns an error seeking to
offset 0, something is terribly wrong.

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

* Re: [PATCH] proc: smoke test lseek()
  2021-04-07 19:58   ` Matthew Wilcox
@ 2021-04-07 20:06     ` Alexey Dobriyan
  0 siblings, 0 replies; 3+ messages in thread
From: Alexey Dobriyan @ 2021-04-07 20:06 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: akpm, linux-kernel, linux-fsdevel

On Wed, Apr 07, 2021 at 08:58:09PM +0100, Matthew Wilcox wrote:
> On Wed, Apr 07, 2021 at 10:55:14PM +0300, Alexey Dobriyan wrote:
> > Now that ->proc_lseek has been made mandatory it would be nice to test
> > that nothing has been forgotten.
> 
> > @@ -45,6 +45,8 @@ static void f_reg(DIR *d, const char *filename)
> >  	fd = openat(dirfd(d), filename, O_RDONLY|O_NONBLOCK);
> >  	if (fd == -1)
> >  		return;
> > +	/* struct proc_ops::proc_lseek is mandatory if file is seekable. */
> > +	(void)lseek(fd, 0, SEEK_SET);
> >  	rv = read(fd, buf, sizeof(buf));
> >  	assert((0 <= rv && rv <= sizeof(buf)) || rv == -1);
> >  	close(fd);
> 
> why throw away the return value?  if it returns an error seeking to
> offset 0, something is terribly wrong.

Some files may use nonseekable_open().
This smoke test doesn't verify that seeking is done correctly anyway.

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

end of thread, other threads:[~2021-04-07 20:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20210328221524.ukfuztGsl%akpm@linux-foundation.org>
2021-04-07 19:55 ` [PATCH] proc: smoke test lseek() Alexey Dobriyan
2021-04-07 19:58   ` Matthew Wilcox
2021-04-07 20:06     ` Alexey Dobriyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).