Clean up yaffs_FindNiceObject to be thread safe and simpler. Fix code that does a...
authorcharles <charles>
Tue, 2 Mar 2010 02:29:21 +0000 (02:29 +0000)
committercharles <charles>
Tue, 2 Mar 2010 02:29:21 +0000 (02:29 +0000)
direct/dtest.c
yaffs_guts.c
yaffs_guts.h

index af02ff3edda4382e82f40682d629d34243d0bc98..24f5ad28a2b5001162a480df1afafd7c5b148f69 100644 (file)
@@ -2479,7 +2479,7 @@ int main(int argc, char *argv[])
 
        //rename_over_test("//////////////////flash///////////////////yaffs1///////////");
        
-       //fill_empty_files_test("/yaffs2/");
+       fill_empty_files_test("/yaffs2/");
        //long_name_test("/yaffs2");
        //link_test0("/yaffs2");
        //link_test1("yaffs2");
index dc9742ba84be4baeb92b830fc6ea20d95a52680b..ff6e9932a769f94185b20b799125b2ebe03bf8f1 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 const char *yaffs_guts_c_version =
-    "$Id: yaffs_guts.c,v 1.110 2010-02-25 22:41:46 charles Exp $";
+    "$Id: yaffs_guts.c,v 1.111 2010-03-02 02:29:21 charles Exp $";
 
 #include "yportenv.h"
 #include "yaffs_trace.h"
@@ -2129,33 +2129,21 @@ static void yaffs_InitialiseObjects(yaffs_Device *dev)
 
 static int yaffs_FindNiceObjectBucket(yaffs_Device *dev)
 {
-       static int x;
        int i;
        int l = 999;
        int lowest = 999999;
 
-       /* First let's see if we can find one that's empty. */
 
-       for (i = 0; i < 10 && lowest > 0; i++) {
-               x++;
-               x %= YAFFS_NOBJECT_BUCKETS;
-               if (dev->objectBucket[x].count < lowest) {
-                       lowest = dev->objectBucket[x].count;
-                       l = x;
-               }
-
-       }
-
-       /* If we didn't find an empty list, then try
-        * looking a bit further for a short one
+       /* Search for the shortest list or one that
+        * isn't too long.
         */
 
-       for (i = 0; i < 10 && lowest > 3; i++) {
-               x++;
-               x %= YAFFS_NOBJECT_BUCKETS;
-               if (dev->objectBucket[x].count < lowest) {
-                       lowest = dev->objectBucket[x].count;
-                       l = x;
+       for (i = 0; i < 10 && lowest > 4; i++) {
+               dev->bucketFinder++;
+               dev->bucketFinder %= YAFFS_NOBJECT_BUCKETS;
+               if (dev->objectBucket[dev->bucketFinder].count < lowest) {
+                       lowest = dev->objectBucket[dev->bucketFinder].count;
+                       l = dev->bucketFinder;
                }
 
        }
@@ -3818,9 +3806,9 @@ static int yaffs_WriteChunkDataToObject(yaffs_Object *in, int chunkInInode,
         * the tnode now, rather than later when it is harder to clean up.
         */
        prevChunkId = yaffs_FindChunkInFile(in, chunkInInode, &prevTags);
-       if(prevChunkId <= 0 &&
-               !yaffs_PutChunkIntoFile(in, chunkInInode, 0, 0)){
-       }
+       if(prevChunkId < 1 &&
+               !yaffs_PutChunkIntoFile(in, chunkInInode, 0, 0))
+               return 0;
 
        /* Set up new tags */
        yaffs_InitialiseTags(&newTags);
@@ -3837,13 +3825,6 @@ static int yaffs_WriteChunkDataToObject(yaffs_Object *in, int chunkInInode,
                YBUG();
        }
        
-       /*
-        * If there isn't already a chunk there then do a dummy
-        * insert to make sue we have the desired tnode structure.
-        */
-       if(prevChunkId < 1 &&
-               yaffs_PutChunkIntoFile(in, chunkInInode, 0, 0) != YAFFS_OK)
-               return -1;
                
        newChunkId =
            yaffs_WriteNewChunkWithTagsToNAND(dev, buffer, &newTags,
index 7d2ab53011e909346de68de72bda99a8203400cf..c74b51c05c3567efef77d92285ba1d31922028c4 100644 (file)
@@ -700,6 +700,7 @@ struct yaffs_DeviceStruct {
        yaffs_ObjectList *allocatedObjectList;
 
        yaffs_ObjectBucket objectBucket[YAFFS_NOBJECT_BUCKETS];
+       __u32 bucketFinder;
 
        int nFreeChunks;