提交 99988f7b 编写于 作者: D David Woodhouse

[JFFS2] Introduce ref_next() macro for finding next physical node

Another part of the preparation for switching to an array...
Signed-off-by: NDavid Woodhouse <dwmw2@infradead.org>
上级 2f785402
...@@ -192,13 +192,13 @@ __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c, ...@@ -192,13 +192,13 @@ __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
else else
my_dirty_size += totlen; my_dirty_size += totlen;
if ((!ref2->next_phys) != (ref2 == jeb->last_node)) { if ((!ref_next(ref2)) != (ref2 == jeb->last_node)) {
JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next_phys at %#08x (mem %p), last_node is at %#08x (mem %p).\n", JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next at %#08x (mem %p), last_node is at %#08x (mem %p).\n",
ref_offset(ref2), ref2, ref_offset(ref2->next_phys), ref2->next_phys, ref_offset(ref2), ref2, ref_offset(ref_next(ref2)), ref_next(ref2),
ref_offset(jeb->last_node), jeb->last_node); ref_offset(jeb->last_node), jeb->last_node);
goto error; goto error;
} }
ref2 = ref2->next_phys; ref2 = ref_next(ref2);
} }
if (my_used_size != jeb->used_size) { if (my_used_size != jeb->used_size) {
...@@ -268,9 +268,9 @@ __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c, ...@@ -268,9 +268,9 @@ __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
} }
printk(JFFS2_DBG); printk(JFFS2_DBG);
for (ref = jeb->first_node; ; ref = ref->next_phys) { for (ref = jeb->first_node; ; ref = ref_next(ref)) {
printk("%#08x(%#x)", ref_offset(ref), ref->__totlen); printk("%#08x(%#x)", ref_offset(ref), ref->__totlen);
if (ref->next_phys) if (ref_next(ref))
printk("->"); printk("->");
else else
break; break;
......
...@@ -239,7 +239,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c) ...@@ -239,7 +239,7 @@ int jffs2_garbage_collect_pass(struct jffs2_sb_info *c)
while(ref_obsolete(raw)) { while(ref_obsolete(raw)) {
D1(printk(KERN_DEBUG "Node at 0x%08x is obsolete... skipping\n", ref_offset(raw))); D1(printk(KERN_DEBUG "Node at 0x%08x is obsolete... skipping\n", ref_offset(raw)));
raw = raw->next_phys; raw = ref_next(raw);
if (unlikely(!raw)) { if (unlikely(!raw)) {
printk(KERN_WARNING "eep. End of raw list while still supposedly nodes to GC\n"); printk(KERN_WARNING "eep. End of raw list while still supposedly nodes to GC\n");
printk(KERN_WARNING "erase block at 0x%08x. free_size 0x%08x, dirty_size 0x%08x, used_size 0x%08x\n", printk(KERN_WARNING "erase block at 0x%08x. free_size 0x%08x, dirty_size 0x%08x, used_size 0x%08x\n",
......
...@@ -1159,9 +1159,10 @@ static inline uint32_t __ref_totlen(struct jffs2_sb_info *c, ...@@ -1159,9 +1159,10 @@ static inline uint32_t __ref_totlen(struct jffs2_sb_info *c,
struct jffs2_raw_node_ref *ref) struct jffs2_raw_node_ref *ref)
{ {
uint32_t ref_end; uint32_t ref_end;
struct jffs2_raw_node_ref *next_ref = ref_next(ref);
if (ref->next_phys) if (next_ref)
ref_end = ref_offset(ref->next_phys); ref_end = ref_offset(next_ref);
else { else {
if (!jeb) if (!jeb)
jeb = &c->blocks[ref->flash_offset / c->sector_size]; jeb = &c->blocks[ref->flash_offset / c->sector_size];
...@@ -1196,11 +1197,11 @@ uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c, struct jffs2_eraseblock *je ...@@ -1196,11 +1197,11 @@ uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c, struct jffs2_eraseblock *je
printk(KERN_CRIT "Totlen for ref at %p (0x%08x-0x%08x) miscalculated as 0x%x instead of %x\n", printk(KERN_CRIT "Totlen for ref at %p (0x%08x-0x%08x) miscalculated as 0x%x instead of %x\n",
ref, ref_offset(ref), ref_offset(ref)+ref->__totlen, ref, ref_offset(ref), ref_offset(ref)+ref->__totlen,
ret, ref->__totlen); ret, ref->__totlen);
if (ref->next_phys) { if (ref_next(ref)) {
printk(KERN_CRIT "next_phys %p (0x%08x-0x%08x)\n", ref->next_phys, ref_offset(ref->next_phys), printk(KERN_CRIT "next %p (0x%08x-0x%08x)\n", ref_next(ref), ref_offset(ref_next(ref)),
ref_offset(ref->next_phys)+ref->__totlen); ref_offset(ref_next(ref))+ref->__totlen);
} else } else
printk(KERN_CRIT "No next_phys. jeb->last_node is %p\n", jeb->last_node); printk(KERN_CRIT "No next ref. jeb->last_node is %p\n", jeb->last_node);
printk(KERN_CRIT "jeb->wasted_size %x, dirty_size %x, used_size %x, free_size %x\n", jeb->wasted_size, jeb->dirty_size, jeb->used_size, jeb->free_size); printk(KERN_CRIT "jeb->wasted_size %x, dirty_size %x, used_size %x, free_size %x\n", jeb->wasted_size, jeb->dirty_size, jeb->used_size, jeb->free_size);
ret = ref->__totlen; ret = ref->__totlen;
......
...@@ -88,18 +88,18 @@ struct jffs2_raw_node_ref ...@@ -88,18 +88,18 @@ struct jffs2_raw_node_ref
#endif #endif
}; };
#define ref_next(r) ((r)->next_phys)
static inline struct jffs2_inode_cache *jffs2_raw_ref_to_ic(struct jffs2_raw_node_ref *raw) static inline struct jffs2_inode_cache *jffs2_raw_ref_to_ic(struct jffs2_raw_node_ref *raw)
{ {
while(raw->next_in_ino) { while(raw->next_in_ino)
raw = raw->next_in_ino; raw = raw->next_in_ino;
}
/* NB. This can be a jffs2_xattr_datum or jffs2_xattr_ref and /* NB. This can be a jffs2_xattr_datum or jffs2_xattr_ref and
not actually a jffs2_inode_cache. Check ->class */ not actually a jffs2_inode_cache. Check ->class */
return ((struct jffs2_inode_cache *)raw); return ((struct jffs2_inode_cache *)raw);
} }
/* flash_offset & 3 always has to be zero, because nodes are /* flash_offset & 3 always has to be zero, because nodes are
always aligned at 4 bytes. So we have a couple of extra bits always aligned at 4 bytes. So we have a couple of extra bits
to play with, which indicate the node's status; see below: */ to play with, which indicate the node's status; see below: */
......
...@@ -458,6 +458,7 @@ static inline int on_list(struct list_head *obj, struct list_head *head) ...@@ -458,6 +458,7 @@ static inline int on_list(struct list_head *obj, struct list_head *head)
void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref) void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref)
{ {
struct jffs2_eraseblock *jeb; struct jffs2_eraseblock *jeb;
struct jffs2_raw_node_ref *next_ref;
int blocknr; int blocknr;
struct jffs2_unknown_node n; struct jffs2_unknown_node n;
int ret, addedsize; int ret, addedsize;
...@@ -685,24 +686,23 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref ...@@ -685,24 +686,23 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
/* Merge with the next node in the physical list, if there is one /* Merge with the next node in the physical list, if there is one
and if it's also obsolete and if it doesn't belong to any inode */ and if it's also obsolete and if it doesn't belong to any inode */
if (ref->next_phys && ref_obsolete(ref->next_phys) && next_ref = ref_next(ref);
!ref->next_phys->next_in_ino) {
struct jffs2_raw_node_ref *n = ref->next_phys;
if (next_ref && ref_obsolete(next_ref) && !next_ref->next_in_ino) {
spin_lock(&c->erase_completion_lock); spin_lock(&c->erase_completion_lock);
#ifdef TEST_TOTLEN #ifdef TEST_TOTLEN
ref->__totlen += n->__totlen; ref->__totlen += next_ref->__totlen;
#endif #endif
ref->next_phys = n->next_phys; ref->next_phys = ref_next(next_ref);
if (jeb->last_node == n) jeb->last_node = ref; if (jeb->last_node == next_ref) jeb->last_node = ref;
if (jeb->gc_node == n) { if (jeb->gc_node == next_ref) {
/* gc will be happy continuing gc on this node */ /* gc will be happy continuing gc on this node */
jeb->gc_node=ref; jeb->gc_node=ref;
} }
spin_unlock(&c->erase_completion_lock); spin_unlock(&c->erase_completion_lock);
__jffs2_free_raw_node_ref(n); __jffs2_free_raw_node_ref(next_ref);
} }
/* Also merge with the previous node in the list, if there is one /* Also merge with the previous node in the list, if there is one
...@@ -712,8 +712,8 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref ...@@ -712,8 +712,8 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
spin_lock(&c->erase_completion_lock); spin_lock(&c->erase_completion_lock);
while (p->next_phys != ref) while ((next_ref = ref_next(ref)) != ref)
p = p->next_phys; p = next_ref;
if (ref_obsolete(p) && !ref->next_in_ino) { if (ref_obsolete(p) && !ref->next_in_ino) {
#ifdef TEST_TOTLEN #ifdef TEST_TOTLEN
...@@ -726,7 +726,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref ...@@ -726,7 +726,7 @@ void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref
/* gc will be happy continuing gc on this node */ /* gc will be happy continuing gc on this node */
jeb->gc_node=p; jeb->gc_node=p;
} }
p->next_phys = ref->next_phys; p->next_phys = ref_next(ref);
__jffs2_free_raw_node_ref(ref); __jffs2_free_raw_node_ref(ref);
} }
spin_unlock(&c->erase_completion_lock); spin_unlock(&c->erase_completion_lock);
......
...@@ -295,7 +295,7 @@ int jffs2_fill_scan_buf (struct jffs2_sb_info *c, void *buf, ...@@ -295,7 +295,7 @@ int jffs2_fill_scan_buf (struct jffs2_sb_info *c, void *buf,
int jffs2_scan_classify_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) int jffs2_scan_classify_jeb(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
{ {
if ((jeb->used_size + jeb->unchecked_size) == PAD(c->cleanmarker_size) && !jeb->dirty_size if ((jeb->used_size + jeb->unchecked_size) == PAD(c->cleanmarker_size) && !jeb->dirty_size
&& (!jeb->first_node || !jeb->first_node->next_phys) ) && (!jeb->first_node || !ref_next(jeb->first_node)) )
return BLK_STATE_CLEANMARKER; return BLK_STATE_CLEANMARKER;
/* move blocks with max 4 byte dirty space to cleanlist */ /* move blocks with max 4 byte dirty space to cleanlist */
...@@ -647,7 +647,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo ...@@ -647,7 +647,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo
/* If we're only checking the beginning of a block with a cleanmarker, /* If we're only checking the beginning of a block with a cleanmarker,
bail now */ bail now */
if (buf_ofs == jeb->offset && jeb->used_size == PAD(c->cleanmarker_size) && if (buf_ofs == jeb->offset && jeb->used_size == PAD(c->cleanmarker_size) &&
c->cleanmarker_size && !jeb->dirty_size && !jeb->first_node->next_phys) { c->cleanmarker_size && !jeb->dirty_size && !ref_next(jeb->first_node)) {
D1(printk(KERN_DEBUG "%d bytes at start of block seems clean... assuming all clean\n", EMPTY_SCAN_SIZE(c->sector_size))); D1(printk(KERN_DEBUG "%d bytes at start of block seems clean... assuming all clean\n", EMPTY_SCAN_SIZE(c->sector_size)));
return BLK_STATE_CLEANMARKER; return BLK_STATE_CLEANMARKER;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册