All of lore.kernel.org
 help / color / mirror / Atom feed
* sysfs: write returns ENOMEM?
@ 2005-08-19  5:55 ` Dmitry Torokhov
  2005-08-19  7:29   ` Greg KH
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Dmitry Torokhov @ 2005-08-19  5:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg KH

[Apologies if you see this message twice - I accidentially sent it in HTML
 format first time around and I am pretty sure LKML will eat it]

Hi,

According to the SuS write() can not return ENOMEM, only ENOBUFS is allowed
(surprisingly read() is allowed to use both ENOMEM and ENOBUFS):

http://www.opengroup.org/onlinepubs/000095399/functions/write.html

Should we adjust sysfs write to follow the standard?

-- 
Dmitry

===================================================================
sysfs: write should return ENOBUFS

According to SuS ENOMEM is not a valid return code for write(),
ENOBUFS should be returned.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 fs/sysfs/file.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

Index: work/fs/sysfs/file.c
===================================================================
--- work.orig/fs/sysfs/file.c
+++ work/fs/sysfs/file.c
@@ -180,7 +180,7 @@ fill_write_buffer(struct sysfs_buffer * 
 	if (!buffer->page)
 		buffer->page = (char *)get_zeroed_page(GFP_KERNEL);
 	if (!buffer->page)
-		return -ENOMEM;
+		return -ENOBUFS;
 
 	if (count >= PAGE_SIZE)
 		count = PAGE_SIZE;

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

* Re: sysfs: write returns ENOMEM?
  2005-08-19  5:55 ` sysfs: write returns ENOMEM? Dmitry Torokhov
@ 2005-08-19  7:29   ` Greg KH
  2005-08-19  7:39   ` Pekka Enberg
  2005-08-23  7:32   ` Nathan Scott
  2 siblings, 0 replies; 11+ messages in thread
From: Greg KH @ 2005-08-19  7:29 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-kernel

On Fri, Aug 19, 2005 at 12:55:25AM -0500, Dmitry Torokhov wrote:
> [Apologies if you see this message twice - I accidentially sent it in HTML
>  format first time around and I am pretty sure LKML will eat it]
> 
> Hi,
> 
> According to the SuS write() can not return ENOMEM, only ENOBUFS is allowed
> (surprisingly read() is allowed to use both ENOMEM and ENOBUFS):
> 
> http://www.opengroup.org/onlinepubs/000095399/functions/write.html
> 
> Should we adjust sysfs write to follow the standard?

Sure, I don't have a problem with this.  Anyone else object?

thanks,

greg k-h

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

* Re: sysfs: write returns ENOMEM?
  2005-08-19  5:55 ` sysfs: write returns ENOMEM? Dmitry Torokhov
  2005-08-19  7:29   ` Greg KH
@ 2005-08-19  7:39   ` Pekka Enberg
  2005-08-23  7:32   ` Nathan Scott
  2 siblings, 0 replies; 11+ messages in thread
From: Pekka Enberg @ 2005-08-19  7:39 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-kernel, Greg KH, Pekka Enberg

Hi Dmitry,

On 8/19/05, Dmitry Torokhov <dtor_core@ameritech.net> wrote:
> According to the SuS write() can not return ENOMEM, only ENOBUFS is allowed
> (surprisingly read() is allowed to use both ENOMEM and ENOBUFS):
> 
> http://www.opengroup.org/onlinepubs/000095399/functions/write.html
> 
> Should we adjust sysfs write to follow the standard?

Please note that sysfs is not the only one to do this. A quick peek
reveals XFS and CIFS returing ENOMEM for write() and there are
probably others as well. Perhaps we should replace ENOMEM with ENOBUFS
in vfs_write() instead?

linvfs_write
	xfs_write
		xfs_zero_eof
			xfs_zero_last_block
				xfs_iozero
					-> Returns -ENOMEM

cifs_user_write
	cifs_reopen_file
		-> Returns -ENOMEM

                            Pekka

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

* Re: sysfs: write returns ENOMEM?
  2005-08-19  5:55 ` sysfs: write returns ENOMEM? Dmitry Torokhov
  2005-08-19  7:29   ` Greg KH
  2005-08-19  7:39   ` Pekka Enberg
@ 2005-08-23  7:32   ` Nathan Scott
  2005-08-23  7:55     ` Pekka Enberg
  2 siblings, 1 reply; 11+ messages in thread
From: Nathan Scott @ 2005-08-23  7:32 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Dmitry Torokhov, linux-kernel, Greg KH

> On 8/19/05, Dmitry Torokhov <dtor_core@ameritech.net> wrote:
> > According to the SuS write() can not return ENOMEM, only ENOBUFS is allowed
> > (surprisingly read() is allowed to use both ENOMEM and ENOBUFS):
> > 
> > http://www.opengroup.org/onlinepubs/000095399/functions/write.html
> > 
> > Should we adjust sysfs write to follow the standard?
> 
> Please note that sysfs is not the only one to do this. A quick peek
> reveals XFS and CIFS returing ENOMEM for write() and there are
> probably others as well. Perhaps we should replace ENOMEM with ENOBUFS

FWIW, all filesystems using the generic page cache routines are able
to return this - see mm/filemap.c -> generic_file_buffered_write...

	page = __grab_cache_page(mapping,index,&cached_page,&lru_pvec);
	if (!page) {
		status = -ENOMEM;
		break;
	}

which is a similar condition to the one under which the XFS code is
returning this error.  Let me know what the verdict is and I'll get
the XFS side of this merged if its really necessary.

cheers.

-- 
Nathan

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

* Re: sysfs: write returns ENOMEM?
  2005-08-23  7:32   ` Nathan Scott
@ 2005-08-23  7:55     ` Pekka Enberg
  2005-08-23  8:28       ` Andrew Morton
  0 siblings, 1 reply; 11+ messages in thread
From: Pekka Enberg @ 2005-08-23  7:55 UTC (permalink / raw)
  To: Nathan Scott
  Cc: Dmitry Torokhov, linux-kernel, Greg KH, Andrew Morton,
	Christoph Hellwig, Pekka Enberg

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

On 8/23/05, Nathan Scott <nathans@sgi.com> wrote:
> FWIW, all filesystems using the generic page cache routines are able
> to return this - see mm/filemap.c -> generic_file_buffered_write...

I don't think it makes much sense to fix this in individual
filesystems as many functions returning -NOMEM can be used in other
paths as well where they're ok.

Andrew, please consider picking this up for -mm. (I've included it as
an attachment as well as gmail will surely mess up the patch. Sorry.)

                               Pekka

[PATCH] VFS: return ENOBUFS instead of ENOMEM for vfs_write()

As noticed by Dmitry Torokhov, write() can not return ENOMEM:

http://www.opengroup.org/onlinepubs/000095399/functions/write.html

Currently almost all filesystems can return -ENOMEM due to
generic_file_buffered_write() in mm/filemap.c so filter out the invalid
error code in vfs_write().

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---

 read_write.c |    2 ++
 1 files changed, 2 insertions(+)

Index: 2.6-mm/fs/read_write.c
===================================================================
--- 2.6-mm.orig/fs/read_write.c
+++ 2.6-mm/fs/read_write.c
@@ -310,6 +310,8 @@ ssize_t vfs_write(struct file *file, con
                }
        }

+       if (ret == -ENOMEM)
+               ret = -ENOBUFS;
        return ret;
 }

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: vfs-vfs_write-return-ENOBUFS-instead-ENOMEM.patch --]
[-- Type: text/x-patch; name="vfs-vfs_write-return-ENOBUFS-instead-ENOMEM.patch", Size: 759 bytes --]

[PATCH] VFS: return ENOBUFS instead of ENOMEM for vfs_write()

As noticed by Dmitry Torokhov, write() can not return ENOMEM:

http://www.opengroup.org/onlinepubs/000095399/functions/write.html

Currently almost all filesystems can return -ENOMEM due to
generic_file_buffered_write() in mm/filemap.c so filter out the invalid
error code in vfs_write().

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---

 read_write.c |    2 ++
 1 files changed, 2 insertions(+)

Index: 2.6-mm/fs/read_write.c
===================================================================
--- 2.6-mm.orig/fs/read_write.c
+++ 2.6-mm/fs/read_write.c
@@ -310,6 +310,8 @@ ssize_t vfs_write(struct file *file, con
 		}
 	}
 
+	if (ret == -ENOMEM)
+		ret = -ENOBUFS;
 	return ret;
 }
 

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

* Re: sysfs: write returns ENOMEM?
  2005-08-23  7:55     ` Pekka Enberg
@ 2005-08-23  8:28       ` Andrew Morton
  2005-08-23  8:36         ` Pekka J Enberg
  2005-08-23  8:46         ` [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write Pekka J Enberg
  0 siblings, 2 replies; 11+ messages in thread
From: Andrew Morton @ 2005-08-23  8:28 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: nathans, dtor_core, linux-kernel, greg, hch, penberg

Pekka Enberg <penberg@gmail.com> wrote:
>
> @@ -310,6 +310,8 @@ ssize_t vfs_write(struct file *file, con
>                  }
>          }
> 
>  +       if (ret == -ENOMEM)
>  +               ret = -ENOBUFS;
>          return ret;
>   }
> 

That's lame.  It'd be better to hunt down all the -ENOMEMs and fix them up.

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

* Re: sysfs: write returns ENOMEM?
  2005-08-23  8:28       ` Andrew Morton
@ 2005-08-23  8:36         ` Pekka J Enberg
  2005-08-23  8:46         ` [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write Pekka J Enberg
  1 sibling, 0 replies; 11+ messages in thread
From: Pekka J Enberg @ 2005-08-23  8:36 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pekka Enberg, nathans, dtor_core, linux-kernel, greg, hch

Andrew Morton writes:
> That's lame.  It'd be better to hunt down all the -ENOMEMs and fix them up.

So there's our verdict. Thanks, Andrew :-) 

       Pekka 

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

* [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write
  2005-08-23  8:28       ` Andrew Morton
  2005-08-23  8:36         ` Pekka J Enberg
@ 2005-08-23  8:46         ` Pekka J Enberg
  2005-08-23 11:55           ` Christoph Hellwig
  1 sibling, 1 reply; 11+ messages in thread
From: Pekka J Enberg @ 2005-08-23  8:46 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Pekka Enberg, nathans, dtor_core, linux-kernel, greg, hch

As noticed by Dmitry Torokhov, write() can not return ENOMEM:

http://www.opengroup.org/onlinepubs/000095399/functions/write.html

Therefore fixup generic_file_buffered_write() in mm/filemap.c (pointed out by
Nathan Scott).

Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
---

 filemap.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)

Index: 2.6-mm/mm/filemap.c
===================================================================
--- 2.6-mm.orig/mm/filemap.c
+++ 2.6-mm/mm/filemap.c
@@ -1942,7 +1942,7 @@ generic_file_buffered_write(struct kiocb
 
 		page = __grab_cache_page(mapping,index,&cached_page,&lru_pvec);
 		if (!page) {
-			status = -ENOMEM;
+			status = -ENOBUFS;
 			break;
 		}
 

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

* Re: [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write
  2005-08-23  8:46         ` [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write Pekka J Enberg
@ 2005-08-23 11:55           ` Christoph Hellwig
  2005-08-23 13:50             ` Dmitry Torokhov
  0 siblings, 1 reply; 11+ messages in thread
From: Christoph Hellwig @ 2005-08-23 11:55 UTC (permalink / raw)
  To: Pekka J Enberg
  Cc: Andrew Morton, Pekka Enberg, nathans, dtor_core, linux-kernel,
	greg, hch

On Tue, Aug 23, 2005 at 11:46:33AM +0300, Pekka J Enberg wrote:
> As noticed by Dmitry Torokhov, write() can not return ENOMEM:
> 
> http://www.opengroup.org/onlinepubs/000095399/functions/write.html
> 
> Therefore fixup generic_file_buffered_write() in mm/filemap.c (pointed out by
> Nathan Scott).

We had this discussion before, for EACCESS then.  We've always been returning
more errnos than SuS mentioned and Linus declared it's fine.


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

* Re: [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write
  2005-08-23 11:55           ` Christoph Hellwig
@ 2005-08-23 13:50             ` Dmitry Torokhov
  0 siblings, 0 replies; 11+ messages in thread
From: Dmitry Torokhov @ 2005-08-23 13:50 UTC (permalink / raw)
  To: Christoph Hellwig, Pekka J Enberg, Andrew Morton, Pekka Enberg,
	nathans, dtor_core, linux-kernel, greg

On 8/23/05, Christoph Hellwig <hch@infradead.org> wrote:
> On Tue, Aug 23, 2005 at 11:46:33AM +0300, Pekka J Enberg wrote:
> > As noticed by Dmitry Torokhov, write() can not return ENOMEM:
> >
> > http://www.opengroup.org/onlinepubs/000095399/functions/write.html
> >
> > Therefore fixup generic_file_buffered_write() in mm/filemap.c (pointed out by
> > Nathan Scott).
> 
> We had this discussion before, for EACCESS then.  We've always been returning
> more errnos than SuS mentioned and Linus declared it's fine.
> 

So does that mean that any error code is allowed? I would love to be
able to return ENODEV from a sysfs attribute if its device happens to
be removed in process. Is there a list of valid errnos for Linux that
supercedes SuS?

-- 
Dmitry

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

* Re: [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write
@ 2005-08-31 19:03 Steve French
  0 siblings, 0 replies; 11+ messages in thread
From: Steve French @ 2005-08-31 19:03 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-fsdevel, penberg, hch

 > As noticed by Dmitry Torokhov, write() can not return ENOMEM
It turns out that Linux is ok here returning ENOMEM (even from a strict 
POSIX perspective) so the patch is not needed.

I consulted our longstanding POSIX workgroup representative to see what 
he could find out about this topic, and this particular one has some 
history (and it turns out ENOMEM is ok).   Also note that you can return 
more return codes as long as they do not conflict with meanings 
assignmed to others, and ENOBUFS was added not to exclude ENOMEM but to 
match some out of network buffer cases coming back from the 
corresponding socket case.   That the listed return codes for the read 
case and write cases were not symmetric (in listing return codes) was 
noticed as something needing fixing even by the guy who added ENOBUFS in 
the first place and is something that should be fixed up in future POSIX 
specs.

 > We've always been returning more errnos than SuS mentioned and Linus 
declared it's fine.
Christoph (see above line) is correct not just from a Linus perspective 
- it can be legal from a posix perspective to return other error codes 
(there are some exceptions e.g. when the case the new return code covers 
is the same as a listed return code creating obvious duplication)

See below:
          -------------------------------------------
<via Mark Brown, member of the POSIX 1003.1/1003.2 WG and its
Interpretions list>

First off, just because a specific errno is not listed in the ERRORS section
of a given API, doesn't mean that that errno can not be returned by an
implementation (1003.1-2001 Base Definitions Sec 2.3). The ERRORS section
describes errnos that must be used for a given condition, but other
conditions not explicitly listed may be reported. There are some APIs that
disallow reporting of additional error conditions, but they explicitly say
so in their entry.

Sec 2.3 does state that one cannot return a different errno than the one 
that
is listed for a given condition - You can't return EACCES when you mean 
ENOENT
and ENOENT is on the API's list. Does this mean that you can't return
ENOMEM (when getting space for a datastruct) if ENOBUFS is present?

My answer is that ENOMEM is conforming behavior. ENOBUFS has a different
meaning than ENOMEM. The complete descriptions of ENOBUFS and ENOMEM, taken
from the same Section 2.3:

ENOBUFS
No buffer space available. Insufficient buffer resources were available in
the system to perform the socket operation.

ENOMEM
Not enough space. The new process image requires more memory than is allowed
by the hardware or system-imposed memory management constraints.

Also, the history these errnos in both read() and write() shows that 
they were
not present in versions of 1003.1 before the 2001 version. These errnos were
added to the spec for the 2001 version in an attempt to rationalize their
behavior with recv() and send(), which can operate like read() or write()
under certain circumstances. recv() had both ENOBUFS and ENOMEM, so they
went into read(), send() only had ENOBUFS. However, it was conforming 
behavior
to return ENOMEM before the 2001 specification, and no specific intent
was offered to break existing conforming implementations by this change.


-------------------
Mark Brown/Austin/IBM
STSM, UNIX/Linux OS Standards

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

end of thread, other threads:[~2005-08-31 19:03 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <11394.1124781401@kao2.melbourne.sgi.com>
2005-08-19  5:55 ` sysfs: write returns ENOMEM? Dmitry Torokhov
2005-08-19  7:29   ` Greg KH
2005-08-19  7:39   ` Pekka Enberg
2005-08-23  7:32   ` Nathan Scott
2005-08-23  7:55     ` Pekka Enberg
2005-08-23  8:28       ` Andrew Morton
2005-08-23  8:36         ` Pekka J Enberg
2005-08-23  8:46         ` [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write Pekka J Enberg
2005-08-23 11:55           ` Christoph Hellwig
2005-08-23 13:50             ` Dmitry Torokhov
2005-08-31 19:03 Steve French

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.