jffs2: -ENOSPC when truncating file?!
Hi!
I'm trying to free space by truncating big file, and I get:
root@fic-gta01:~# ls -al gps.nmea -rw-r--r-- 1 root root 2332070 Feb 19 22:13 gps.nmea root@fic-gta01:~# > gps.nmea -sh: cannot create gps.nmea: No space left on device root@fic-gta01:~# rm gps.nmea root@fic-gta01:~# > gps.nmea root@fic-gta01:~#
:-(
Kernel is not-so-ancient, on openmoko:
root@fic-gta01:~# uname -a Linux fic-gta01 2.6.24 #1 PREEMPT Mon Feb 18 21:30:53 GMT 2008 armv4tl unknown root@fic-gta01:~#
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
David Woodhouse
maintainerQuoted 11 lines · Pavel Machek
Hi!
I'm trying to free space by truncating big file, and I get:
root@fic-gta01:~# ls -al gps.nmea -rw-r--r-- 1 root root 2332070 Feb 19 22:13 gps.nmea root@fic-gta01:~# > gps.nmea -sh: cannot create gps.nmea: No space left on device root@fic-gta01:~# rm gps.nmea root@fic-gta01:~# > gps.nmea root@fic-gta01:~#
You need to write a log entry indicating the new length of the file. There is no space for new log entries.
There is a special case for removal -- 'rm gps.nmea' would work. Perhaps we should add a special case for truncation too, so that it can also use the extra pool of free space.
Signature · 1 line
dwmw2
Quoted 15 lines · David Woodhouse
Quoted 10 lines · Pavel Machek
I'm trying to free space by truncating big file, and I get:
root@fic-gta01:~# ls -al gps.nmea -rw-r--r-- 1 root root 2332070 Feb 19 22:13 gps.nmea root@fic-gta01:~# > gps.nmea -sh: cannot create gps.nmea: No space left on device root@fic-gta01:~# rm gps.nmea root@fic-gta01:~# > gps.nmea root@fic-gta01:~#You need to write a log entry indicating the new length of the file. There is no space for new log entries.
Quoted 3 lines
There is a special case for removal -- 'rm gps.nmea' would work. Perhaps we should add a special case for truncation too, so that it can also use the extra pool of free space.
Could a naïve implementation of this get exploited by doing a large number of truncates that just shave single bytes off various files?
Looks like the safe way to do it would be to write out a replacement node for the truncated node, if the special case ever triggers.
Jörn
Signature · 3 lines
"[One] doesn't need to know [...] how to cause a headache in order to take an aspirin." -- Scott Culp, Manager of the Microsoft Security Response Center, 2001
David Woodhouse
maintainerQuoted 2 lines · Jörn Engel
Could a naïve implementation of this get exploited by doing a large number of truncates that just shave single bytes off various files?
Yeah, which is why _my_ naïve implementation would do it for truncate-to-zero instead of just _any_ truncate (which could even be truncate-to-larger).
A more complex version might allow _any_ transaction to eat into the ALLOC_DELETION pool if it is ultimately going to reduce the amount of space taken on the file system -- even overwriting 'real' data with zeroes which compress better. That's going to be hard to calculate in the general case though.
If allowing only truncate-to-zero isn't good enough, perhaps we could allow truncation to use the ALLOC_DELETION pool when it's going to obsolete at least one full data node. That's not so hard to check.
Signature · 1 line
dwmw2
Quoted 7 lines · David Woodhouse
Quoted 2 lines · Jörn Engel
Could a naïve implementation of this get exploited by doing a large number of truncates that just shave single bytes off various files?
Yeah, which is why _my_ naïve implementation would do it for truncate-to-zero instead of just _any_ truncate (which could even be truncate-to-larger).
Truncate-to-larger is trivial to check. Almost every filesystem does it somewhere, including JFFS2. ;)
But yeah, truncate-to-zero should catch the common case.
Quoted 3 lines
If allowing only truncate-to-zero isn't good enough, perhaps we could allow truncation to use the
ALLOC_DELETIONpool when it's going to obsolete at least one full data node. That's not so hard to check.
I would simply always write out a "full" replacement node, i.e. the complete tail page for the file. No need to check if an old node gets obsoleted, we just made sure it does. Anyway, it is your baby, so you get to change the dirty diapers and pick your favorite pair of clean ones.
Jörn
Signature · 2 lines
Joern's library part 3: http://inst.eecs.berkeley.edu/~cs152/fa05/handouts/clark-test.pdf
Quoted 15 lines · David Woodhouse
Quoted 2 lines · Jörn Engel
Could a na??ve implementation of this get exploited by doing a large number of truncates that just shave single bytes off various files?
Yeah, which is why _my_ na??ve implementation would do it for truncate-to-zero instead of just _any_ truncate (which could even be truncate-to-larger).
A more complex version might allow _any_ transaction to eat into the
ALLOC_DELETIONpool if it is ultimately going to reduce the amount of space taken on the file system -- even overwriting 'real' data with zeroes which compress better. That's going to be hard to calculate in the general case though.
Quoted 3 lines
If allowing only truncate-to-zero isn't good enough, perhaps we could allow truncation to use the
ALLOC_DELETIONpool when it's going to obsolete at least one full data node. That's not so hard to check.
I believe truncate-to-zero is good enough.
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 17 lines · David Woodhouse
Quoted 11 lines · Pavel Machek
Hi!
I'm trying to free space by truncating big file, and I get:
root@fic-gta01:~# ls -al gps.nmea -rw-r--r-- 1 root root 2332070 Feb 19 22:13 gps.nmea root@fic-gta01:~# > gps.nmea -sh: cannot create gps.nmea: No space left on device root@fic-gta01:~# rm gps.nmea root@fic-gta01:~# > gps.nmea root@fic-gta01:~#You need to write a log entry indicating the new length of the file. There is no space for new log entries.
Quoted 3 lines
There is a special case for removal -- 'rm gps.nmea' would work. Perhaps we should add a special case for truncation too, so that it can also use the extra pool of free space.
Yes, that would be nice. I somehow assumed that truncate can't fail for -ENOSPC ... I was trying to actually free some space on the filesystem...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 10 lines · Pavel Machek
Quoted 6 lines
You need to write a log entry indicating the new length of the file. There is no space for new log entries.
There is a special case for removal -- 'rm gps.nmea' would work. Perhaps we should add a special case for truncation too, so that it can also use the extra pool of free space.
Yes, that would be nice. I somehow assumed that truncate can't fail for
-ENOSPC... I was trying to actually free some space on the filesystem...
Same here! When I got ENOSPC from truncate, trying to free some space, I was so surprised (and a bit disappointed) that I assumed removal could fail too. So now I'm pleasantly surprised to learn I can at least remove a file.
It does seem odd that truncate to zero length can fail. It is guaranteed to free up one or more data nodes, so there should be enough space for the size change node, provided GC is invoked when necessary and the node sizes are compatible for this in corner cases.
-- Jamie
Quoted 12 lines · Pavel Machek
Hi!
I'm trying to free space by truncating big file, and I get:
root@fic-gta01:~# ls -al gps.nmea -rw-r--r-- 1 root root 2332070 Feb 19 22:13 gps.nmea root@fic-gta01:~# > gps.nmea -sh: cannot create gps.nmea: No space left on device root@fic-gta01:~# rm gps.nmea root@fic-gta01:~# > gps.nmea root@fic-gta01:~#
Quoted 3 lines
:-(
Kernel is not-so-ancient, on openmoko:
Hi!
JFFS2 has known bug in GC leading to -ENOSPC upon file removal. Time ago I've sent a patch with detailed explanations of what is going on. Probably your case is the same.
Here is the patch
http://lists.infradead.org/pipermail/linux-mtd/2007-December/020091.html
(though infradead mailing list archive is missing most of messages from this thread)
And here are some details
http://lists.infradead.org/pipermail/linux-mtd/2007-June/018756.html
Alexander
Hi!
Quoted 20 lines
Quoted 10 lines
I'm trying to free space by truncating big file, and I get:
root@fic-gta01:~# ls -al gps.nmea -rw-r--r-- 1 root root 2332070 Feb 19 22:13 gps.nmea root@fic-gta01:~# > gps.nmea -sh: cannot create gps.nmea: No space left on device root@fic-gta01:~# rm gps.nmea root@fic-gta01:~# > gps.nmea root@fic-gta01:~#Quoted 3 lines
:-(
Kernel is not-so-ancient, on openmoko:
Hi!
JFFS2 has known bug in GC leading to
-ENOSPCupon file removal. Time ago I've sent a patch with detailed explanations of what is going on. Probably your case is the same.
Quoted 7 lines
Here is the patch
http://lists.infradead.org/pipermail/linux-mtd/2007-December/020091.html
(though infradead mailing list archive is missing most of messages from this thread)And here are some details
http://lists.infradead.org/pipermail/linux-mtd/2007-June/018756.html
Patch is here (I whitespace-damaged it, sorry], and I've seen no discussion.. should it just be applied?
Pavel
fs/jffs2/wbuf.c +0 -0
@@ -117,7 +117,7 @@ D1(printk(KERN_DEBUG "Removing eraseblock at 0x%08x
from erasable_pending_wbuf_list...\n", jeb->offset));
list_del(this);
- if ((jiffies + (n++)) & 127) {
+ if (((jiffies + (n++)) & 127) &&
!list_empty(&c->erasable_list)) {
/* Most of the time, we just erase it immediately. Otherwise we
spend ages scanning it on mount, etc. */
D1(printk(KERN_DEBUG "...and adding to
erase_pending_list\n"));
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Quoted 3 lines · Pavel Machek
Patch is here (I whitespace-damaged it, sorry], and I've seen no discussion.. should it just be applied?
There was discussion. The patch is a pure band-aid. It should not make a difference at all, so clearly something is very wrong and we should dig deeper to find the real problem. So far noone has done it.
Jörn
Signature · 2 lines
All models are wrong. Some models are useful. -- George Box
Quoted 4 lines · Pavel Machek
Patch is here (I whitespace-damaged it, sorry], and I've seen no discussion.. should it just be applied?
Pavel
Being very simple workaround, this patch helps to avoid -ENOSPC bug until better (proper) solution is found. IMO it is worth to try this patch (at least to make sure that you are indeed dealing with the same bug).
-a