You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by ma...@apache.org on 2016/04/28 02:14:28 UTC

[29/50] [abbrv] incubator-mynewt-core git commit: nffs - Fix for broken iteration through all objs.

nffs - Fix for broken iteration through all objs.

The NFFS_HASH_FOREACH macro was broken because it did not account for
the fact that read operations can still modify the ordering in the hash.
In particular, lookups cause an object to be moved to the front of the
list to facilitate LRU.

Now, the macro stores a "next" pointer before executing the body of the
loop.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/ff204970
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/ff204970
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/ff204970

Branch: refs/heads/master
Commit: ff2049703b1b9720ad1d047df3cfbe119e1e70fb
Parents: 832637d
Author: Christopher Collins <cc...@apache.org>
Authored: Wed Apr 20 17:52:03 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Wed Apr 20 17:52:03 2016 -0700

----------------------------------------------------------------------
 fs/nffs/src/nffs_priv.h    | 6 ++++--
 fs/nffs/src/nffs_restore.c | 6 ++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ff204970/fs/nffs/src/nffs_priv.h
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_priv.h b/fs/nffs/src/nffs_priv.h
index 3670251..49b72ea 100644
--- a/fs/nffs/src/nffs_priv.h
+++ b/fs/nffs/src/nffs_priv.h
@@ -431,9 +431,11 @@ int nffs_restore_full(const struct nffs_area_desc *area_descs);
 int nffs_write_to_file(struct nffs_file *file, const void *data, int len);
 
 
-#define NFFS_HASH_FOREACH(entry, i)                                     \
+#define NFFS_HASH_FOREACH(entry, i, next)                               \
     for ((i) = 0; (i) < NFFS_HASH_SIZE; (i)++)                          \
-        SLIST_FOREACH((entry), &nffs_hash[i], nhe_next)
+        for ((entry) = SLIST_FIRST(nffs_hash + (i));                    \
+             (entry) && (((next)) = SLIST_NEXT((entry), nhe_next), 1);  \
+             (entry) = ((next)))
 
 #define NFFS_FLASH_LOC_NONE  nffs_flash_loc(NFFS_AREA_ID_NONE, 0)
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/ff204970/fs/nffs/src/nffs_restore.c
----------------------------------------------------------------------
diff --git a/fs/nffs/src/nffs_restore.c b/fs/nffs/src/nffs_restore.c
index 28ea39a..9289203 100644
--- a/fs/nffs/src/nffs_restore.c
+++ b/fs/nffs/src/nffs_restore.c
@@ -275,10 +275,11 @@ static int
 nffs_restore_find_file_ends(void)
 {
     struct nffs_hash_entry *block_entry;
+    struct nffs_hash_entry *next;
     int rc;
     int i;
 
-    NFFS_HASH_FOREACH(block_entry, i) {
+    NFFS_HASH_FOREACH(block_entry, i, next) {
         if (!nffs_hash_id_is_inode(block_entry->nhe_id)) {
             rc = nffs_restore_find_file_end_block(block_entry);
             assert(rc == 0);
@@ -984,12 +985,13 @@ nffs_log_contents(void)
 
     struct nffs_inode_entry *inode_entry;
     struct nffs_hash_entry *entry;
+    struct nffs_hash_entry *next;
     struct nffs_block block;
     struct nffs_inode inode;
     int rc;
     int i;
 
-    NFFS_HASH_FOREACH(entry, i) {
+    NFFS_HASH_FOREACH(entry, i, next) {
         if (nffs_hash_id_is_block(entry->nhe_id)) {
             rc = nffs_block_from_hash_entry(&block, entry);
             assert(rc == 0);