mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] fs: flush device on close
@ 2012-03-06 18:36 Enrico Scholz
  2012-03-07  8:46 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Enrico Scholz @ 2012-03-06 18:36 UTC (permalink / raw)
  To: barebox; +Cc: Enrico Scholz

When working with DMA backed devices (e.g. framebuffers), writes are
delayed so that 'mw -d /dev/fb0' might not have an immediate effect.

Behavior after this patch resembles POSIX close(2) functionality which
flushes (blocking) streams on close.

Drivers which provide 'memmap()' can/should implement a 'flush()' method
which works similarly msync(2) so that buffers can be synchronized on
demand (without low level dma_*_range() operations). Closing such
devices (e.g. when 'mw' or 'bmp' exits) will flush modified memory
content automatically without the need to touch the 'mw', 'bmp' or ...
code.

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
---
 fs/fs.c         |    5 +++++
 include/fcntl.h |    1 +
 2 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 13df71c..6ba1da6 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -714,6 +714,11 @@ int close(int fd)
 	dev = f->dev;
 
 	fsdrv = (struct fs_driver_d *)dev->driver->type_data;
+
+	if (!(f->flags & O_NONBLOCK) && fsdrv->flush)
+		/* no way to deal with errors here... */
+		fsdrv->flush(dev, f);
+
 	errno = fsdrv->close(dev, f);
 
 	put_file(f);
diff --git a/include/fcntl.h b/include/fcntl.h
index aed741e..ffe2f5f 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -13,6 +13,7 @@
 #define O_EXCL		00000200	/* not fcntl */
 #define O_TRUNC		00001000	/* not fcntl */
 #define O_APPEND	00002000
+#define O_NONBLOCK	00004000
 #define O_DIRECTORY	00200000	/* must be a directory */
 #define O_NOFOLLOW	00400000	/* don't follow links */
 
-- 
1.7.7.6


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] fs: flush device on close
  2012-03-06 18:36 [PATCH] fs: flush device on close Enrico Scholz
@ 2012-03-07  8:46 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2012-03-07  8:46 UTC (permalink / raw)
  To: Enrico Scholz; +Cc: barebox

On Tue, Mar 06, 2012 at 07:36:26PM +0100, Enrico Scholz wrote:
> When working with DMA backed devices (e.g. framebuffers), writes are
> delayed so that 'mw -d /dev/fb0' might not have an immediate effect.
> 
> Behavior after this patch resembles POSIX close(2) functionality which
> flushes (blocking) streams on close.
> 
> Drivers which provide 'memmap()' can/should implement a 'flush()' method
> which works similarly msync(2) so that buffers can be synchronized on
> demand (without low level dma_*_range() operations). Closing such
> devices (e.g. when 'mw' or 'bmp' exits) will flush modified memory
> content automatically without the need to touch the 'mw', 'bmp' or ...
> code.

I don't think that's the right way to do it. Framebuffer drivers
should use dma_alloc_coherent instead (I know some don't do it atm)

Sascha

> 
> Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> ---
>  fs/fs.c         |    5 +++++
>  include/fcntl.h |    1 +
>  2 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/fs.c b/fs/fs.c
> index 13df71c..6ba1da6 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -714,6 +714,11 @@ int close(int fd)
>  	dev = f->dev;
>  
>  	fsdrv = (struct fs_driver_d *)dev->driver->type_data;
> +
> +	if (!(f->flags & O_NONBLOCK) && fsdrv->flush)
> +		/* no way to deal with errors here... */
> +		fsdrv->flush(dev, f);
> +
>  	errno = fsdrv->close(dev, f);
>  
>  	put_file(f);
> diff --git a/include/fcntl.h b/include/fcntl.h
> index aed741e..ffe2f5f 100644
> --- a/include/fcntl.h
> +++ b/include/fcntl.h
> @@ -13,6 +13,7 @@
>  #define O_EXCL		00000200	/* not fcntl */
>  #define O_TRUNC		00001000	/* not fcntl */
>  #define O_APPEND	00002000
> +#define O_NONBLOCK	00004000
>  #define O_DIRECTORY	00200000	/* must be a directory */
>  #define O_NOFOLLOW	00400000	/* don't follow links */
>  
> -- 
> 1.7.7.6
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2012-03-07  8:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-06 18:36 [PATCH] fs: flush device on close Enrico Scholz
2012-03-07  8:46 ` Sascha Hauer

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