Improve sync to flush metadata
authorcharles <charles>
Wed, 23 Sep 2009 23:24:55 +0000 (23:24 +0000)
committercharles <charles>
Wed, 23 Sep 2009 23:24:55 +0000 (23:24 +0000)
direct/yaffsfs.c
direct/yaffsfs.h
yaffs_fs.c
yaffs_guts.c
yaffs_guts.h

index 3be1ea7d13a83a521b2ec4f78c551519730f5d9d..1da4d059049e4e3dc1acd238f2b04a9a7b4bfc67 100644 (file)
@@ -24,7 +24,7 @@
 #endif
 
 
-const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.25 2009-03-05 01:47:17 charles Exp $";
+const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.26 2009-09-23 23:24:55 charles Exp $";
 
 // configurationList is the list of devices that are supported
 static yaffsfs_DeviceConfiguration *yaffsfs_configurationList;
@@ -587,7 +587,7 @@ int yaffs_open(const YCHAR *path, int oflag, int mode)
        return handle;
 }
 
-int yaffs_flush(int fd)
+int yaffs_Dofsync(int fd,int datasync)
 {
        yaffsfs_Handle *h = NULL;
        int retVal = 0;
@@ -599,7 +599,7 @@ int yaffs_flush(int fd)
        if(h && h->inUse)
        {
                // flush the file
-               yaffs_FlushFile(h->obj,1);
+               yaffs_FlushFile(h->obj,1,datasync);
        }
        else
        {
@@ -613,6 +613,15 @@ int yaffs_flush(int fd)
        return retVal;
 }
 
+int yaffs_fsync(int fd)
+{
+       return yaffs_Dofsync(fd,0);
+}
+
+int yaffs_fdatasync(int fd)
+{
+       return yaffs_Dofsync(fd,1);
+}
 
 int yaffs_close(int fd)
 {
@@ -626,7 +635,7 @@ int yaffs_close(int fd)
        if(h && h->inUse)
        {
                // clean up
-               yaffs_FlushFile(h->obj,1);
+               yaffs_FlushFile(h->obj,1,0);
                h->obj->inUse--;
                if(h->obj->inUse <= 0 && h->obj->unlinked)
                {
@@ -1265,7 +1274,7 @@ int yaffs_set_wince_times(int fd,
                 }
 
                 obj->dirty = 1;
-                result = yaffs_FlushFile(obj,0);
+                result = yaffs_FlushFile(obj,0,0);
                 retVal = 0;
         }
         else
@@ -1295,7 +1304,7 @@ static int yaffsfs_DoChMod(yaffs_Object *obj,mode_t mode)
        {
                obj->yst_mode = mode;
                obj->dirty = 1;
-               result = yaffs_FlushFile(obj,0);
+               result = yaffs_FlushFile(obj,0,0);
        }
 
        return result == YAFFS_OK ? 0 : -1;
index c05e02a6c2cf6603a7902c6e0f0e81dcb4d308bb..7cb845371f18b257ddeaaff3d29844a3eaca2c70 100644 (file)
@@ -216,7 +216,9 @@ struct yaffs_stat{
 
 int yaffs_open(const YCHAR *path, int oflag, int mode) ;
 int yaffs_close(int fd) ;
-int yaffs_flush(int fd) ;
+int yaffs_fsync(int fd) ;
+int yaffs_fdatasync(int fd) ;
+int yaffs_flush(int fd) ; /* same as yaffs_fsync() */
 
 int yaffs_access(const YCHAR *path, int amode);
 
index 855a639c03e58d1c100395fdd5fe849a1cd8a737..3fd94df12bab57878658836f06b4a0056ce0a7e8 100644 (file)
@@ -32,7 +32,7 @@
  */
 
 const char *yaffs_fs_c_version =
-    "$Id: yaffs_fs.c,v 1.82 2009-09-18 00:39:21 charles Exp $";
+    "$Id: yaffs_fs.c,v 1.83 2009-09-23 23:24:55 charles Exp $";
 extern const char *yaffs_guts_c_version;
 
 #include <linux/version.h>
@@ -589,7 +589,7 @@ static int yaffs_file_flush(struct file *file)
 
        yaffs_GrossLock(dev);
 
-       yaffs_FlushFile(obj, 1);
+       yaffs_FlushFile(obj, 1,0);
 
        yaffs_GrossUnlock(dev);
 
@@ -1438,7 +1438,7 @@ static int yaffs_sync_object(struct file *file, struct dentry *dentry,
 
        T(YAFFS_TRACE_OS, ("yaffs_sync_object\n"));
        yaffs_GrossLock(dev);
-       yaffs_FlushFile(obj, 1);
+       yaffs_FlushFile(obj, 1, datasync);
        yaffs_GrossUnlock(dev);
        return 0;
 }
@@ -1596,6 +1596,21 @@ static int yaffs_statfs(struct super_block *sb, struct statfs *buf)
 }
 
 
+
+static void yaffs_flush_sb_inodes(struct super_block *sb)
+{
+       struct inode *iptr;
+       yaffs_Object *obj;
+       
+       list_for_each_entry(iptr,&sb->s_inodes, i_sb_list){
+               obj = yaffs_InodeToObject(iptr);
+               if(obj){
+                       T(YAFFS_TRACE_OS, ("flushing obj %d\n",obj->objectId));
+                       yaffs_FlushFile(obj,1,0);
+               }
+       }
+}
+
 static int yaffs_do_sync_fs(struct super_block *sb)
 {
 
@@ -1607,6 +1622,7 @@ static int yaffs_do_sync_fs(struct super_block *sb)
 
                if (dev) {
                        yaffs_FlushEntireDeviceCache(dev);
+                       yaffs_flush_sb_inodes(sb);
                        yaffs_CheckpointSave(dev);
                }
 
index 2acfb8e031b4e83f18b1bb03d1a28d25f8ba14a1..2b9bf7bd66228b3b173d276ffbcc416c1cd59f39 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 const char *yaffs_guts_c_version =
-    "$Id: yaffs_guts.c,v 1.89 2009-09-09 00:56:53 charles Exp $";
+    "$Id: yaffs_guts.c,v 1.90 2009-09-23 23:24:55 charles Exp $";
 
 #include "yportenv.h"
 
@@ -5060,23 +5060,27 @@ loff_t yaffs_GetFileSize(yaffs_Object *obj)
 
 
 
-int yaffs_FlushFile(yaffs_Object *in, int updateTime)
+int yaffs_FlushFile(yaffs_Object *in, int updateTime, int dataSync)
 {
        int retVal;
        if (in->dirty) {
                yaffs_FlushFilesChunkCache(in);
-               if (updateTime) {
+               if(dataSync) /* Only sync data */
+                       retVal=YAFFS_OK;
+               else {
+                       if (updateTime) {
 #ifdef CONFIG_YAFFS_WINCE
-                       yfsd_WinFileTimeNow(in->win_mtime);
+                               yfsd_WinFileTimeNow(in->win_mtime);
 #else
 
-                       in->yst_mtime = Y_CURRENT_TIME;
+                               in->yst_mtime = Y_CURRENT_TIME;
 
 #endif
-               }
+                       }
 
-               retVal = (yaffs_UpdateObjectHeader(in, NULL, 0, 0, 0) >=
-                       0) ? YAFFS_OK : YAFFS_FAIL;
+                       retVal = (yaffs_UpdateObjectHeader(in, NULL, 0, 0, 0) >=
+                               0) ? YAFFS_OK : YAFFS_FAIL;
+               }
        } else {
                retVal = YAFFS_OK;
        }
index a3b110291d3832c4b73a83069e9e7d3d1fc7b92f..cb8d8ec788683b26b29b646faaf2d9bf1d4dae15 100644 (file)
@@ -840,7 +840,8 @@ int yaffs_ResizeFile(yaffs_Object *obj, loff_t newSize);
 
 yaffs_Object *yaffs_MknodFile(yaffs_Object *parent, const YCHAR *name,
                                __u32 mode, __u32 uid, __u32 gid);
-int yaffs_FlushFile(yaffs_Object *obj, int updateTime);
+
+int yaffs_FlushFile(yaffs_Object *obj, int updateTime, int dataSync);
 
 /* Flushing and checkpointing */
 void yaffs_FlushEntireDeviceCache(yaffs_Device *dev);