Commit a6590b9f authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'upstream-3.9-rc1' of git://git.infradead.org/linux-ubifs

Pull ubifs updates from Artem Bityutskiy:
 "It's been quite silent and we have only a couple of bug-fixes for the
  orphans handling code plus one cosmetic change."

* tag 'upstream-3.9-rc1' of git://git.infradead.org/linux-ubifs:
  UBIFS: fix double free of ubifs_orphan objects
  UBIFS: fix use of freed ubifs_orphan objects
  UBIFS: rename random32() to prandom_u32()
parents 1085db4a 8afd500c
...@@ -2459,7 +2459,7 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head) ...@@ -2459,7 +2459,7 @@ int dbg_check_nondata_nodes_order(struct ubifs_info *c, struct list_head *head)
static inline int chance(unsigned int n, unsigned int out_of) static inline int chance(unsigned int n, unsigned int out_of)
{ {
return !!((random32() % out_of) + 1 <= n); return !!((prandom_u32() % out_of) + 1 <= n);
} }
...@@ -2477,13 +2477,13 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write) ...@@ -2477,13 +2477,13 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
if (chance(1, 2)) { if (chance(1, 2)) {
d->pc_delay = 1; d->pc_delay = 1;
/* Fail withing 1 minute */ /* Fail withing 1 minute */
delay = random32() % 60000; delay = prandom_u32() % 60000;
d->pc_timeout = jiffies; d->pc_timeout = jiffies;
d->pc_timeout += msecs_to_jiffies(delay); d->pc_timeout += msecs_to_jiffies(delay);
ubifs_warn("failing after %lums", delay); ubifs_warn("failing after %lums", delay);
} else { } else {
d->pc_delay = 2; d->pc_delay = 2;
delay = random32() % 10000; delay = prandom_u32() % 10000;
/* Fail within 10000 operations */ /* Fail within 10000 operations */
d->pc_cnt_max = delay; d->pc_cnt_max = delay;
ubifs_warn("failing after %lu calls", delay); ubifs_warn("failing after %lu calls", delay);
...@@ -2563,7 +2563,7 @@ static int corrupt_data(const struct ubifs_info *c, const void *buf, ...@@ -2563,7 +2563,7 @@ static int corrupt_data(const struct ubifs_info *c, const void *buf,
unsigned int from, to, ffs = chance(1, 2); unsigned int from, to, ffs = chance(1, 2);
unsigned char *p = (void *)buf; unsigned char *p = (void *)buf;
from = random32() % (len + 1); from = prandom_u32() % (len + 1);
/* Corruption may only span one max. write unit */ /* Corruption may only span one max. write unit */
to = min(len, ALIGN(from, c->max_write_size)); to = min(len, ALIGN(from, c->max_write_size));
......
...@@ -2007,28 +2007,28 @@ static int dbg_populate_lsave(struct ubifs_info *c) ...@@ -2007,28 +2007,28 @@ static int dbg_populate_lsave(struct ubifs_info *c)
if (!dbg_is_chk_gen(c)) if (!dbg_is_chk_gen(c))
return 0; return 0;
if (random32() & 3) if (prandom_u32() & 3)
return 0; return 0;
for (i = 0; i < c->lsave_cnt; i++) for (i = 0; i < c->lsave_cnt; i++)
c->lsave[i] = c->main_first; c->lsave[i] = c->main_first;
list_for_each_entry(lprops, &c->empty_list, list) list_for_each_entry(lprops, &c->empty_list, list)
c->lsave[random32() % c->lsave_cnt] = lprops->lnum; c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum;
list_for_each_entry(lprops, &c->freeable_list, list) list_for_each_entry(lprops, &c->freeable_list, list)
c->lsave[random32() % c->lsave_cnt] = lprops->lnum; c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum;
list_for_each_entry(lprops, &c->frdi_idx_list, list) list_for_each_entry(lprops, &c->frdi_idx_list, list)
c->lsave[random32() % c->lsave_cnt] = lprops->lnum; c->lsave[prandom_u32() % c->lsave_cnt] = lprops->lnum;
heap = &c->lpt_heap[LPROPS_DIRTY_IDX - 1]; heap = &c->lpt_heap[LPROPS_DIRTY_IDX - 1];
for (i = 0; i < heap->cnt; i++) for (i = 0; i < heap->cnt; i++)
c->lsave[random32() % c->lsave_cnt] = heap->arr[i]->lnum; c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum;
heap = &c->lpt_heap[LPROPS_DIRTY - 1]; heap = &c->lpt_heap[LPROPS_DIRTY - 1];
for (i = 0; i < heap->cnt; i++) for (i = 0; i < heap->cnt; i++)
c->lsave[random32() % c->lsave_cnt] = heap->arr[i]->lnum; c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum;
heap = &c->lpt_heap[LPROPS_FREE - 1]; heap = &c->lpt_heap[LPROPS_FREE - 1];
for (i = 0; i < heap->cnt; i++) for (i = 0; i < heap->cnt; i++)
c->lsave[random32() % c->lsave_cnt] = heap->arr[i]->lnum; c->lsave[prandom_u32() % c->lsave_cnt] = heap->arr[i]->lnum;
return 1; return 1;
} }
...@@ -126,13 +126,14 @@ void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum) ...@@ -126,13 +126,14 @@ void ubifs_delete_orphan(struct ubifs_info *c, ino_t inum)
else if (inum > o->inum) else if (inum > o->inum)
p = p->rb_right; p = p->rb_right;
else { else {
if (o->dnext) { if (o->del) {
spin_unlock(&c->orphan_lock); spin_unlock(&c->orphan_lock);
dbg_gen("deleted twice ino %lu", dbg_gen("deleted twice ino %lu",
(unsigned long)inum); (unsigned long)inum);
return; return;
} }
if (o->cnext) { if (o->cmt) {
o->del = 1;
o->dnext = c->orph_dnext; o->dnext = c->orph_dnext;
c->orph_dnext = o; c->orph_dnext = o;
spin_unlock(&c->orphan_lock); spin_unlock(&c->orphan_lock);
...@@ -172,7 +173,9 @@ int ubifs_orphan_start_commit(struct ubifs_info *c) ...@@ -172,7 +173,9 @@ int ubifs_orphan_start_commit(struct ubifs_info *c)
last = &c->orph_cnext; last = &c->orph_cnext;
list_for_each_entry(orphan, &c->orph_new, new_list) { list_for_each_entry(orphan, &c->orph_new, new_list) {
ubifs_assert(orphan->new); ubifs_assert(orphan->new);
ubifs_assert(!orphan->cmt);
orphan->new = 0; orphan->new = 0;
orphan->cmt = 1;
*last = orphan; *last = orphan;
last = &orphan->cnext; last = &orphan->cnext;
} }
...@@ -299,7 +302,9 @@ static int write_orph_node(struct ubifs_info *c, int atomic) ...@@ -299,7 +302,9 @@ static int write_orph_node(struct ubifs_info *c, int atomic)
cnext = c->orph_cnext; cnext = c->orph_cnext;
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
orphan = cnext; orphan = cnext;
ubifs_assert(orphan->cmt);
orph->inos[i] = cpu_to_le64(orphan->inum); orph->inos[i] = cpu_to_le64(orphan->inum);
orphan->cmt = 0;
cnext = orphan->cnext; cnext = orphan->cnext;
orphan->cnext = NULL; orphan->cnext = NULL;
} }
...@@ -378,6 +383,7 @@ static int consolidate(struct ubifs_info *c) ...@@ -378,6 +383,7 @@ static int consolidate(struct ubifs_info *c)
list_for_each_entry(orphan, &c->orph_list, list) { list_for_each_entry(orphan, &c->orph_list, list) {
if (orphan->new) if (orphan->new)
continue; continue;
orphan->cmt = 1;
*last = orphan; *last = orphan;
last = &orphan->cnext; last = &orphan->cnext;
cnt += 1; cnt += 1;
...@@ -442,6 +448,7 @@ static void erase_deleted(struct ubifs_info *c) ...@@ -442,6 +448,7 @@ static void erase_deleted(struct ubifs_info *c)
orphan = dnext; orphan = dnext;
dnext = orphan->dnext; dnext = orphan->dnext;
ubifs_assert(!orphan->new); ubifs_assert(!orphan->new);
ubifs_assert(orphan->del);
rb_erase(&orphan->rb, &c->orph_tree); rb_erase(&orphan->rb, &c->orph_tree);
list_del(&orphan->list); list_del(&orphan->list);
c->tot_orphans -= 1; c->tot_orphans -= 1;
...@@ -531,6 +538,7 @@ static int insert_dead_orphan(struct ubifs_info *c, ino_t inum) ...@@ -531,6 +538,7 @@ static int insert_dead_orphan(struct ubifs_info *c, ino_t inum)
rb_link_node(&orphan->rb, parent, p); rb_link_node(&orphan->rb, parent, p);
rb_insert_color(&orphan->rb, &c->orph_tree); rb_insert_color(&orphan->rb, &c->orph_tree);
list_add_tail(&orphan->list, &c->orph_list); list_add_tail(&orphan->list, &c->orph_list);
orphan->del = 1;
orphan->dnext = c->orph_dnext; orphan->dnext = c->orph_dnext;
c->orph_dnext = orphan; c->orph_dnext = orphan;
dbg_mnt("ino %lu, new %d, tot %d", (unsigned long)inum, dbg_mnt("ino %lu, new %d, tot %d", (unsigned long)inum,
......
...@@ -683,7 +683,7 @@ static int alloc_idx_lebs(struct ubifs_info *c, int cnt) ...@@ -683,7 +683,7 @@ static int alloc_idx_lebs(struct ubifs_info *c, int cnt)
c->ilebs[c->ileb_cnt++] = lnum; c->ilebs[c->ileb_cnt++] = lnum;
dbg_cmt("LEB %d", lnum); dbg_cmt("LEB %d", lnum);
} }
if (dbg_is_chk_index(c) && !(random32() & 7)) if (dbg_is_chk_index(c) && !(prandom_u32() & 7))
return -ENOSPC; return -ENOSPC;
return 0; return 0;
} }
......
...@@ -904,6 +904,8 @@ struct ubifs_budget_req { ...@@ -904,6 +904,8 @@ struct ubifs_budget_req {
* @dnext: next orphan to delete * @dnext: next orphan to delete
* @inum: inode number * @inum: inode number
* @new: %1 => added since the last commit, otherwise %0 * @new: %1 => added since the last commit, otherwise %0
* @cmt: %1 => commit pending, otherwise %0
* @del: %1 => delete pending, otherwise %0
*/ */
struct ubifs_orphan { struct ubifs_orphan {
struct rb_node rb; struct rb_node rb;
...@@ -912,7 +914,9 @@ struct ubifs_orphan { ...@@ -912,7 +914,9 @@ struct ubifs_orphan {
struct ubifs_orphan *cnext; struct ubifs_orphan *cnext;
struct ubifs_orphan *dnext; struct ubifs_orphan *dnext;
ino_t inum; ino_t inum;
int new; unsigned new:1;
unsigned cmt:1;
unsigned del:1;
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment