Skip to contentSkip to conversation

sysfs: write returns ENOMEM?

PATCH In review Dmitry Torokhov 8 participants 10 messages Aug 19, 2005 – Aug 23, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

[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?

Signature · 27 lines
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 <[email protected]>
---

 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;
#1 lore raw

Hi Dmitry,

Quoted 6 lines · Dmitry Torokhov

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
#2 lore raw
In reply to Dmitry Torokhov
Quoted 11 lines · Dmitry Torokhov

[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

#3 lore raw
In reply to Dmitry Torokhov
Quoted 11 lines · Dmitry Torokhov
Quoted 6 lines

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.

Signature · 1 line
Nathan
#4 lore raw
Quoted 2 lines · Nathan Scott

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().

---

 read_write.c |    2 ++
 1 files changed, 2 insertions(+)
fs/read_write.c +2 -0
Index: 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;
 }

[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().

---

 read_write.c |    2 ++
 1 files changed, 2 insertions(+)
fs/read_write.c +2 -0
Index: 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;
 }
 
#5 lore raw

fs/read_write.c ssize_t vfs_write(struct file *file, con · line 316

Quoted 10 lines · Pekka Enberg
fs/read_write.c +0 -0
@@ -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.

#6 lore raw
Quoted 1 line · Andrew Morton

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

#7 lore raw

PATCH 1/1 mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write

In reply to Andrew Morton

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).

---

 filemap.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)
mm/filemap.c +1 -1
Index: 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;
 		}
 
#8 lore raw

Re: [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write

Quoted 6 lines · Pekka J Enberg

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.

#9 lore raw

Re: [PATCH] mm: return ENOBUFS instead of ENOMEM in generic_file_buffered_write

Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Pekka J Enberg

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?

Signature · 1 line
Dmitry