[JFFS2] Introduce jffs2_link_node_ref() function to reduce code duplication

The same sequence of code was repeated in many places, to add a new
struct jffs2_raw_node_ref to an eraseblock and adjust the space accounting
accordingly. Move it out-of-line.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
This commit is contained in:
David Woodhouse 2006-05-20 19:45:26 +01:00
Родитель 0cfc7da3ff
Коммит f1f9671bd8
6 изменённых файлов: 68 добавлений и 122 удалений

Просмотреть файл

@ -373,12 +373,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
goto filebad; goto filebad;
} }
jeb->first_node = jeb->last_node = NULL; /* Everything else got zeroed before the erase */
jeb->free_size = c->sector_size; jeb->free_size = c->sector_size;
jeb->used_size = 0;
jeb->dirty_size = 0;
jeb->wasted_size = 0;
} else { } else {
struct kvec vecs[1]; struct kvec vecs[1];
@ -412,17 +408,13 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
goto filebad; goto filebad;
} }
/* Everything else got zeroed before the erase */
jeb->free_size = c->sector_size;
marker_ref->next_in_ino = NULL; marker_ref->next_in_ino = NULL;
marker_ref->next_phys = NULL;
marker_ref->flash_offset = jeb->offset | REF_NORMAL; marker_ref->flash_offset = jeb->offset | REF_NORMAL;
marker_ref->__totlen = c->cleanmarker_size;
jeb->first_node = jeb->last_node = marker_ref; jffs2_link_node_ref(c, jeb, marker_ref, c->cleanmarker_size);
jeb->free_size = c->sector_size - c->cleanmarker_size;
jeb->used_size = c->cleanmarker_size;
jeb->dirty_size = 0;
jeb->wasted_size = 0;
} }
spin_lock(&c->erase_completion_lock); spin_lock(&c->erase_completion_lock);

Просмотреть файл

@ -1046,3 +1046,37 @@ void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
cond_resched(); cond_resched();
} }
} }
void jffs2_link_node_ref(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
struct jffs2_raw_node_ref *ref, uint32_t len)
{
if (!jeb->first_node)
jeb->first_node = ref;
if (jeb->last_node)
jeb->last_node->next_phys = ref;
jeb->last_node = ref;
switch(ref_flags(ref)) {
case REF_UNCHECKED:
c->unchecked_size += len;
jeb->unchecked_size += len;
break;
case REF_NORMAL:
case REF_PRISTINE:
c->used_size += len;
jeb->used_size += len;
break;
case REF_OBSOLETE:
c->dirty_size += len;
jeb->used_size += len;
break;
}
c->free_size -= len;
jeb->free_size -= len;
/* Set __totlen field... for now */
ref->__totlen = len;
ref->next_phys = NULL;
}

Просмотреть файл

@ -348,6 +348,8 @@ void jffs2_obsolete_node_frag(struct jffs2_sb_info *c, struct jffs2_node_frag *t
int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn); int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn);
void jffs2_truncate_fragtree (struct jffs2_sb_info *c, struct rb_root *list, uint32_t size); void jffs2_truncate_fragtree (struct jffs2_sb_info *c, struct rb_root *list, uint32_t size);
int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_tmp_dnode_info *tn); int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_tmp_dnode_info *tn);
void jffs2_link_node_ref(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
struct jffs2_raw_node_ref *ref, uint32_t len);
/* nodemgmt.c */ /* nodemgmt.c */
int jffs2_thread_should_wake(struct jffs2_sb_info *c); int jffs2_thread_should_wake(struct jffs2_sb_info *c);

Просмотреть файл

@ -403,21 +403,7 @@ int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_r
#endif #endif
spin_lock(&c->erase_completion_lock); spin_lock(&c->erase_completion_lock);
if (!jeb->first_node) jffs2_link_node_ref(c, jeb, new, len);
jeb->first_node = new;
if (jeb->last_node)
jeb->last_node->next_phys = new;
jeb->last_node = new;
jeb->free_size -= len;
c->free_size -= len;
if (ref_obsolete(new)) {
jeb->dirty_size += len;
c->dirty_size += len;
} else {
jeb->used_size += len;
c->used_size += len;
}
if (!jeb->free_size && !jeb->dirty_size && !ISDIRTY(jeb->wasted_size)) { if (!jeb->free_size && !jeb->dirty_size && !ISDIRTY(jeb->wasted_size)) {
/* If it lives on the dirty_list, jffs2_reserve_space will put it there */ /* If it lives on the dirty_list, jffs2_reserve_space will put it there */

Просмотреть файл

@ -351,17 +351,11 @@ static int jffs2_scan_xattr_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
xd->data_crc = je32_to_cpu(rx->data_crc); xd->data_crc = je32_to_cpu(rx->data_crc);
xd->node = raw; xd->node = raw;
raw->__totlen = totlen;
raw->flash_offset = ofs | REF_PRISTINE; raw->flash_offset = ofs | REF_PRISTINE;
raw->next_phys = NULL;
raw->next_in_ino = (void *)xd; raw->next_in_ino = (void *)xd;
if (!jeb->first_node)
jeb->first_node = raw;
if (jeb->last_node)
jeb->last_node->next_phys = raw;
jeb->last_node = raw;
USED_SPACE(PAD(je32_to_cpu(rx->totlen))); jffs2_link_node_ref(c, jeb, raw, totlen);
if (jffs2_sum_active()) if (jffs2_sum_active())
jffs2_sum_add_xattr_mem(s, rx, ofs - jeb->offset); jffs2_sum_add_xattr_mem(s, rx, ofs - jeb->offset);
dbg_xattr("scaning xdatum at %#08x (xid=%u, version=%u)\n", dbg_xattr("scaning xdatum at %#08x (xid=%u, version=%u)\n",
@ -418,17 +412,11 @@ static int jffs2_scan_xref_node(struct jffs2_sb_info *c, struct jffs2_eraseblock
ref->next = c->xref_temp; ref->next = c->xref_temp;
c->xref_temp = ref; c->xref_temp = ref;
raw->__totlen = PAD(je32_to_cpu(rr->totlen));
raw->flash_offset = ofs | REF_PRISTINE; raw->flash_offset = ofs | REF_PRISTINE;
raw->next_phys = NULL;
raw->next_in_ino = (void *)ref; raw->next_in_ino = (void *)ref;
if (!jeb->first_node)
jeb->first_node = raw;
if (jeb->last_node)
jeb->last_node->next_phys = raw;
jeb->last_node = raw;
USED_SPACE(PAD(je32_to_cpu(rr->totlen))); jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(rr->totlen)));
if (jffs2_sum_active()) if (jffs2_sum_active())
jffs2_sum_add_xref_mem(s, rr, ofs - jeb->offset); jffs2_sum_add_xref_mem(s, rr, ofs - jeb->offset);
dbg_xattr("scan xref at %#08x (xid=%u, ino=%u)\n", dbg_xattr("scan xref at %#08x (xid=%u, ino=%u)\n",
@ -827,12 +815,10 @@ scan_more:
return -ENOMEM; return -ENOMEM;
} }
marker_ref->next_in_ino = NULL; marker_ref->next_in_ino = NULL;
marker_ref->next_phys = NULL;
marker_ref->flash_offset = ofs | REF_NORMAL; marker_ref->flash_offset = ofs | REF_NORMAL;
marker_ref->__totlen = c->cleanmarker_size;
jeb->first_node = jeb->last_node = marker_ref;
USED_SPACE(PAD(c->cleanmarker_size)); jffs2_link_node_ref(c, jeb, marker_ref, c->cleanmarker_size);
ofs += PAD(c->cleanmarker_size); ofs += PAD(c->cleanmarker_size);
} }
break; break;
@ -971,16 +957,11 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
/* Wheee. It worked */ /* Wheee. It worked */
raw->flash_offset = ofs | REF_UNCHECKED; raw->flash_offset = ofs | REF_UNCHECKED;
raw->__totlen = PAD(je32_to_cpu(ri->totlen));
raw->next_phys = NULL;
raw->next_in_ino = ic->nodes;
raw->next_in_ino = ic->nodes;
ic->nodes = raw; ic->nodes = raw;
if (!jeb->first_node)
jeb->first_node = raw; jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(ri->totlen)));
if (jeb->last_node)
jeb->last_node->next_phys = raw;
jeb->last_node = raw;
D1(printk(KERN_DEBUG "Node is ino #%u, version %d. Range 0x%x-0x%x\n", D1(printk(KERN_DEBUG "Node is ino #%u, version %d. Range 0x%x-0x%x\n",
je32_to_cpu(ri->ino), je32_to_cpu(ri->version), je32_to_cpu(ri->ino), je32_to_cpu(ri->version),
@ -989,8 +970,6 @@ static int jffs2_scan_inode_node(struct jffs2_sb_info *c, struct jffs2_erasebloc
pseudo_random += je32_to_cpu(ri->version); pseudo_random += je32_to_cpu(ri->version);
UNCHECKED_SPACE(PAD(je32_to_cpu(ri->totlen)));
if (jffs2_sum_active()) { if (jffs2_sum_active()) {
jffs2_sum_add_inode_mem(s, ri, ofs - jeb->offset); jffs2_sum_add_inode_mem(s, ri, ofs - jeb->offset);
} }
@ -1053,16 +1032,11 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
return -ENOMEM; return -ENOMEM;
} }
raw->__totlen = PAD(je32_to_cpu(rd->totlen));
raw->flash_offset = ofs | REF_PRISTINE; raw->flash_offset = ofs | REF_PRISTINE;
raw->next_phys = NULL;
raw->next_in_ino = ic->nodes; raw->next_in_ino = ic->nodes;
ic->nodes = raw; ic->nodes = raw;
if (!jeb->first_node)
jeb->first_node = raw; jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(rd->totlen)));
if (jeb->last_node)
jeb->last_node->next_phys = raw;
jeb->last_node = raw;
fd->raw = raw; fd->raw = raw;
fd->next = NULL; fd->next = NULL;
@ -1070,7 +1044,6 @@ static int jffs2_scan_dirent_node(struct jffs2_sb_info *c, struct jffs2_eraseblo
fd->ino = je32_to_cpu(rd->ino); fd->ino = je32_to_cpu(rd->ino);
fd->nhash = full_name_hash(fd->name, rd->nsize); fd->nhash = full_name_hash(fd->name, rd->nsize);
fd->type = rd->type; fd->type = rd->type;
USED_SPACE(PAD(je32_to_cpu(rd->totlen)));
jffs2_add_fd_to_list(c, fd, &ic->scan_dents); jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
if (jffs2_sum_active()) { if (jffs2_sum_active()) {

Просмотреть файл

@ -410,19 +410,13 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
} }
raw->flash_offset = (jeb->offset + je32_to_cpu(spi->offset)) | REF_UNCHECKED; raw->flash_offset = (jeb->offset + je32_to_cpu(spi->offset)) | REF_UNCHECKED;
raw->__totlen = PAD(je32_to_cpu(spi->totlen));
raw->next_phys = NULL;
raw->next_in_ino = ic->nodes; raw->next_in_ino = ic->nodes;
ic->nodes = raw; ic->nodes = raw;
if (!jeb->first_node)
jeb->first_node = raw;
if (jeb->last_node)
jeb->last_node->next_phys = raw;
jeb->last_node = raw;
*pseudo_random += je32_to_cpu(spi->version);
UNCHECKED_SPACE(PAD(je32_to_cpu(spi->totlen))); jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spi->totlen)));
*pseudo_random += je32_to_cpu(spi->version);
sp += JFFS2_SUMMARY_INODE_SIZE; sp += JFFS2_SUMMARY_INODE_SIZE;
@ -457,16 +451,11 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
return -ENOMEM; return -ENOMEM;
} }
raw->__totlen = PAD(je32_to_cpu(spd->totlen));
raw->flash_offset = (jeb->offset + je32_to_cpu(spd->offset)) | REF_PRISTINE; raw->flash_offset = (jeb->offset + je32_to_cpu(spd->offset)) | REF_PRISTINE;
raw->next_phys = NULL;
raw->next_in_ino = ic->nodes; raw->next_in_ino = ic->nodes;
ic->nodes = raw; ic->nodes = raw;
if (!jeb->first_node)
jeb->first_node = raw; jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spd->totlen)));
if (jeb->last_node)
jeb->last_node->next_phys = raw;
jeb->last_node = raw;
fd->raw = raw; fd->raw = raw;
fd->next = NULL; fd->next = NULL;
@ -474,7 +463,7 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
fd->ino = je32_to_cpu(spd->ino); fd->ino = je32_to_cpu(spd->ino);
fd->nhash = full_name_hash(fd->name, spd->nsize); fd->nhash = full_name_hash(fd->name, spd->nsize);
fd->type = spd->type; fd->type = spd->type;
USED_SPACE(PAD(je32_to_cpu(spd->totlen)));
jffs2_add_fd_to_list(c, fd, &ic->scan_dents); jffs2_add_fd_to_list(c, fd, &ic->scan_dents);
*pseudo_random += je32_to_cpu(spd->version); *pseudo_random += je32_to_cpu(spd->version);
@ -516,17 +505,11 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
xd->node = raw; xd->node = raw;
raw->flash_offset = ofs | REF_UNCHECKED; raw->flash_offset = ofs | REF_UNCHECKED;
raw->__totlen = PAD(je32_to_cpu(spx->totlen));
raw->next_phys = NULL;
raw->next_in_ino = (void *)xd; raw->next_in_ino = (void *)xd;
if (!jeb->first_node)
jeb->first_node = raw; jffs2_link_node_ref(c, jeb, raw, PAD(je32_to_cpu(spx->totlen)));
if (jeb->last_node)
jeb->last_node->next_phys = raw;
jeb->last_node = raw;
*pseudo_random += je32_to_cpu(spx->xid); *pseudo_random += je32_to_cpu(spx->xid);
UNCHECKED_SPACE(je32_to_cpu(spx->totlen));
sp += JFFS2_SUMMARY_XATTR_SIZE; sp += JFFS2_SUMMARY_XATTR_SIZE;
break; break;
@ -559,17 +542,11 @@ static int jffs2_sum_process_sum_data(struct jffs2_sb_info *c, struct jffs2_eras
ref->next = c->xref_temp; ref->next = c->xref_temp;
c->xref_temp = ref; c->xref_temp = ref;
raw->__totlen = PAD(sizeof(struct jffs2_raw_xref));
raw->flash_offset = ofs | REF_UNCHECKED; raw->flash_offset = ofs | REF_UNCHECKED;
raw->next_phys = NULL;
raw->next_in_ino = (void *)ref; raw->next_in_ino = (void *)ref;
if (!jeb->first_node)
jeb->first_node = raw;
if (jeb->last_node)
jeb->last_node->next_phys = raw;
jeb->last_node = raw;
UNCHECKED_SPACE(PAD(sizeof(struct jffs2_raw_xref))); jffs2_link_node_ref(c, jeb, raw, PAD(sizeof(struct jffs2_raw_xref)));
*pseudo_random += ofs; *pseudo_random += ofs;
sp += JFFS2_SUMMARY_XREF_SIZE; sp += JFFS2_SUMMARY_XREF_SIZE;
@ -653,13 +630,10 @@ int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb
return -ENOMEM; return -ENOMEM;
} }
marker_ref->next_in_ino = NULL;
marker_ref->next_phys = NULL;
marker_ref->flash_offset = jeb->offset | REF_NORMAL; marker_ref->flash_offset = jeb->offset | REF_NORMAL;
marker_ref->__totlen = je32_to_cpu(summary->cln_mkr); marker_ref->next_in_ino = NULL;
jeb->first_node = jeb->last_node = marker_ref;
USED_SPACE( PAD(je32_to_cpu(summary->cln_mkr)) ); jffs2_link_node_ref(c, jeb, marker_ref, je32_to_cpu(summary->cln_mkr));
} }
} }
@ -682,15 +656,8 @@ int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb
cache_ref->next_in_ino = NULL; cache_ref->next_in_ino = NULL;
cache_ref->next_phys = NULL; cache_ref->next_phys = NULL;
cache_ref->flash_offset = ofs | REF_NORMAL; cache_ref->flash_offset = ofs | REF_NORMAL;
cache_ref->__totlen = sumsize;
if (!jeb->first_node) jffs2_link_node_ref(c, jeb, cache_ref, sumsize);
jeb->first_node = cache_ref;
if (jeb->last_node)
jeb->last_node->next_phys = cache_ref;
jeb->last_node = cache_ref;
USED_SPACE(sumsize);
jeb->wasted_size += jeb->free_size; jeb->wasted_size += jeb->free_size;
c->wasted_size += jeb->free_size; c->wasted_size += jeb->free_size;
@ -888,17 +855,9 @@ int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
} }
summary_ref->next_in_ino = NULL; summary_ref->next_in_ino = NULL;
summary_ref->next_phys = NULL;
summary_ref->flash_offset = (jeb->offset + c->sector_size - jeb->free_size) | REF_NORMAL; summary_ref->flash_offset = (jeb->offset + c->sector_size - jeb->free_size) | REF_NORMAL;
summary_ref->__totlen = infosize;
if (!jeb->first_node) jffs2_link_node_ref(c, jeb, summary_ref, infosize);
jeb->first_node = summary_ref;
if (jeb->last_node)
jeb->last_node->next_phys = summary_ref;
jeb->last_node = summary_ref;
USED_SPACE(infosize);
return 0; return 0;
} }