Commit d304820a authored by Artem Bityutskiy's avatar Artem Bityutskiy Committed by Artem Bityutskiy

UBIFS: switch to ubifs_leb_read

Instead of using 'ubi_read()' function directly, used the 'ubifs_leb_read()'
helper function instead. This allows to get rid of several redundant error
messages and make sure that we always have a stack dump on read errors.
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent 83cef708
...@@ -941,14 +941,10 @@ int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len, ...@@ -941,14 +941,10 @@ int ubifs_read_node_wbuf(struct ubifs_wbuf *wbuf, void *buf, int type, int len,
if (rlen > 0) { if (rlen > 0) {
/* Read everything that goes before write-buffer */ /* Read everything that goes before write-buffer */
err = ubi_read(c->ubi, lnum, buf, offs, rlen); err = ubifs_leb_read(c, lnum, buf, offs, rlen, 0);
if (err && err != -EBADMSG) { if (err && err != -EBADMSG)
ubifs_err("failed to read node %d from LEB %d:%d, "
"error %d", type, lnum, offs, err);
dbg_dump_stack();
return err; return err;
} }
}
if (type != ch->node_type) { if (type != ch->node_type) {
ubifs_err("bad node type (%d but expected %d)", ubifs_err("bad node type (%d but expected %d)",
...@@ -1002,12 +998,9 @@ int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len, ...@@ -1002,12 +998,9 @@ int ubifs_read_node(const struct ubifs_info *c, void *buf, int type, int len,
ubifs_assert(!(offs & 7) && offs < c->leb_size); ubifs_assert(!(offs & 7) && offs < c->leb_size);
ubifs_assert(type >= 0 && type < UBIFS_NODE_TYPES_CNT); ubifs_assert(type >= 0 && type < UBIFS_NODE_TYPES_CNT);
err = ubi_read(c->ubi, lnum, buf, offs, len); err = ubifs_leb_read(c, lnum, buf, offs, len, 0);
if (err && err != -EBADMSG) { if (err && err != -EBADMSG)
ubifs_err("cannot read node %d from LEB %d:%d, error %d",
type, lnum, offs, err);
return err; return err;
}
if (type != ch->node_type) { if (type != ch->node_type) {
ubifs_err("bad node type (%d but expected %d)", ubifs_err("bad node type (%d but expected %d)",
......
...@@ -1222,7 +1222,7 @@ int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip) ...@@ -1222,7 +1222,7 @@ int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
if (c->big_lpt) if (c->big_lpt)
nnode->num = calc_nnode_num_from_parent(c, parent, iip); nnode->num = calc_nnode_num_from_parent(c, parent, iip);
} else { } else {
err = ubi_read(c->ubi, lnum, buf, offs, c->nnode_sz); err = ubifs_leb_read(c, lnum, buf, offs, c->nnode_sz, 1);
if (err) if (err)
goto out; goto out;
err = ubifs_unpack_nnode(c, buf, nnode); err = ubifs_unpack_nnode(c, buf, nnode);
...@@ -1291,7 +1291,7 @@ static int read_pnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip) ...@@ -1291,7 +1291,7 @@ static int read_pnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
lprops->flags = ubifs_categorize_lprops(c, lprops); lprops->flags = ubifs_categorize_lprops(c, lprops);
} }
} else { } else {
err = ubi_read(c->ubi, lnum, buf, offs, c->pnode_sz); err = ubifs_leb_read(c, lnum, buf, offs, c->pnode_sz, 1);
if (err) if (err)
goto out; goto out;
err = unpack_pnode(c, buf, pnode); err = unpack_pnode(c, buf, pnode);
...@@ -1333,7 +1333,7 @@ static int read_ltab(struct ubifs_info *c) ...@@ -1333,7 +1333,7 @@ static int read_ltab(struct ubifs_info *c)
buf = vmalloc(c->ltab_sz); buf = vmalloc(c->ltab_sz);
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
err = ubi_read(c->ubi, c->ltab_lnum, buf, c->ltab_offs, c->ltab_sz); err = ubifs_leb_read(c, c->ltab_lnum, buf, c->ltab_offs, c->ltab_sz, 1);
if (err) if (err)
goto out; goto out;
err = unpack_ltab(c, buf); err = unpack_ltab(c, buf);
...@@ -1356,7 +1356,8 @@ static int read_lsave(struct ubifs_info *c) ...@@ -1356,7 +1356,8 @@ static int read_lsave(struct ubifs_info *c)
buf = vmalloc(c->lsave_sz); buf = vmalloc(c->lsave_sz);
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
err = ubi_read(c->ubi, c->lsave_lnum, buf, c->lsave_offs, c->lsave_sz); err = ubifs_leb_read(c, c->lsave_lnum, buf, c->lsave_offs,
c->lsave_sz, 1);
if (err) if (err)
goto out; goto out;
err = unpack_lsave(c, buf); err = unpack_lsave(c, buf);
...@@ -1816,8 +1817,8 @@ static struct ubifs_nnode *scan_get_nnode(struct ubifs_info *c, ...@@ -1816,8 +1817,8 @@ static struct ubifs_nnode *scan_get_nnode(struct ubifs_info *c,
if (c->big_lpt) if (c->big_lpt)
nnode->num = calc_nnode_num_from_parent(c, parent, iip); nnode->num = calc_nnode_num_from_parent(c, parent, iip);
} else { } else {
err = ubi_read(c->ubi, branch->lnum, buf, branch->offs, err = ubifs_leb_read(c, branch->lnum, buf, branch->offs,
c->nnode_sz); c->nnode_sz, 1);
if (err) if (err)
return ERR_PTR(err); return ERR_PTR(err);
err = ubifs_unpack_nnode(c, buf, nnode); err = ubifs_unpack_nnode(c, buf, nnode);
...@@ -1885,8 +1886,8 @@ static struct ubifs_pnode *scan_get_pnode(struct ubifs_info *c, ...@@ -1885,8 +1886,8 @@ static struct ubifs_pnode *scan_get_pnode(struct ubifs_info *c,
ubifs_assert(branch->lnum >= c->lpt_first && ubifs_assert(branch->lnum >= c->lpt_first &&
branch->lnum <= c->lpt_last); branch->lnum <= c->lpt_last);
ubifs_assert(branch->offs >= 0 && branch->offs < c->leb_size); ubifs_assert(branch->offs >= 0 && branch->offs < c->leb_size);
err = ubi_read(c->ubi, branch->lnum, buf, branch->offs, err = ubifs_leb_read(c, branch->lnum, buf, branch->offs,
c->pnode_sz); c->pnode_sz, 1);
if (err) if (err)
return ERR_PTR(err); return ERR_PTR(err);
err = unpack_pnode(c, buf, pnode); err = unpack_pnode(c, buf, pnode);
......
...@@ -1161,11 +1161,11 @@ static int lpt_gc_lnum(struct ubifs_info *c, int lnum) ...@@ -1161,11 +1161,11 @@ static int lpt_gc_lnum(struct ubifs_info *c, int lnum)
void *buf = c->lpt_buf; void *buf = c->lpt_buf;
dbg_lp("LEB %d", lnum); dbg_lp("LEB %d", lnum);
err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size);
if (err) { err = ubifs_leb_read(c, lnum, buf, 0, c->leb_size, 1);
ubifs_err("cannot read LEB %d, error %d", lnum, err); if (err)
return err; return err;
}
while (1) { while (1) {
if (!is_a_node(c, buf, len)) { if (!is_a_node(c, buf, len)) {
int pad_len; int pad_len;
...@@ -1651,11 +1651,11 @@ static int dbg_check_ltab_lnum(struct ubifs_info *c, int lnum) ...@@ -1651,11 +1651,11 @@ static int dbg_check_ltab_lnum(struct ubifs_info *c, int lnum)
} }
dbg_lp("LEB %d", lnum); dbg_lp("LEB %d", lnum);
err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size);
if (err) { err = ubifs_leb_read(c, lnum, buf, 0, c->leb_size, 1);
dbg_msg("ubi_read failed, LEB %d, error %d", lnum, err); if (err)
goto out; goto out;
}
while (1) { while (1) {
if (!is_a_node(c, p, len)) { if (!is_a_node(c, p, len)) {
int i, pad_len; int i, pad_len;
...@@ -1902,11 +1902,10 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum) ...@@ -1902,11 +1902,10 @@ static void dump_lpt_leb(const struct ubifs_info *c, int lnum)
return; return;
} }
err = ubi_read(c->ubi, lnum, buf, 0, c->leb_size); err = ubifs_leb_read(c, lnum, buf, 0, c->leb_size, 1);
if (err) { if (err)
ubifs_err("cannot read LEB %d, error %d", lnum, err);
goto out; goto out;
}
while (1) { while (1) {
offs = c->leb_size - len; offs = c->leb_size - len;
if (!is_a_node(c, p, len)) { if (!is_a_node(c, p, len)) {
......
...@@ -117,7 +117,7 @@ static int get_master_node(const struct ubifs_info *c, int lnum, void **pbuf, ...@@ -117,7 +117,7 @@ static int get_master_node(const struct ubifs_info *c, int lnum, void **pbuf,
if (!sbuf) if (!sbuf)
return -ENOMEM; return -ENOMEM;
err = ubi_read(c->ubi, lnum, sbuf, 0, c->leb_size); err = ubifs_leb_read(c, lnum, sbuf, 0, c->leb_size, 0);
if (err && err != -EBADMSG) if (err && err != -EBADMSG)
goto out_free; goto out_free;
...@@ -539,8 +539,8 @@ static int fix_unclean_leb(struct ubifs_info *c, struct ubifs_scan_leb *sleb, ...@@ -539,8 +539,8 @@ static int fix_unclean_leb(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
int len = ALIGN(endpt, c->min_io_size); int len = ALIGN(endpt, c->min_io_size);
if (start) { if (start) {
err = ubi_read(c->ubi, lnum, sleb->buf, 0, err = ubifs_leb_read(c, lnum, sleb->buf, 0,
start); start, 1);
if (err) if (err)
return err; return err;
} }
...@@ -819,7 +819,8 @@ static int get_cs_sqnum(struct ubifs_info *c, int lnum, int offs, ...@@ -819,7 +819,8 @@ static int get_cs_sqnum(struct ubifs_info *c, int lnum, int offs,
return -ENOMEM; return -ENOMEM;
if (c->leb_size - offs < UBIFS_CS_NODE_SZ) if (c->leb_size - offs < UBIFS_CS_NODE_SZ)
goto out_err; goto out_err;
err = ubi_read(c->ubi, lnum, (void *)cs_node, offs, UBIFS_CS_NODE_SZ); err = ubifs_leb_read(c, lnum, (void *)cs_node, offs,
UBIFS_CS_NODE_SZ, 0);
if (err && err != -EBADMSG) if (err && err != -EBADMSG)
goto out_free; goto out_free;
ret = ubifs_scan_a_node(c, cs_node, UBIFS_CS_NODE_SZ, lnum, offs, 0); ret = ubifs_scan_a_node(c, cs_node, UBIFS_CS_NODE_SZ, lnum, offs, 0);
...@@ -930,12 +931,12 @@ static int recover_head(struct ubifs_info *c, int lnum, int offs, void *sbuf) ...@@ -930,12 +931,12 @@ static int recover_head(struct ubifs_info *c, int lnum, int offs, void *sbuf)
return 0; return 0;
/* Read at the head location and check it is empty flash */ /* Read at the head location and check it is empty flash */
err = ubi_read(c->ubi, lnum, sbuf, offs, len); err = ubifs_leb_read(c, lnum, sbuf, offs, len, 1);
if (err || !is_empty(sbuf, len)) { if (err || !is_empty(sbuf, len)) {
dbg_rcvry("cleaning head at %d:%d", lnum, offs); dbg_rcvry("cleaning head at %d:%d", lnum, offs);
if (offs == 0) if (offs == 0)
return ubifs_leb_unmap(c, lnum); return ubifs_leb_unmap(c, lnum);
err = ubi_read(c->ubi, lnum, sbuf, 0, offs); err = ubifs_leb_read(c, lnum, sbuf, 0, offs, 1);
if (err) if (err)
return err; return err;
return ubi_leb_change(c->ubi, lnum, sbuf, offs, UBI_UNKNOWN); return ubi_leb_change(c->ubi, lnum, sbuf, offs, UBI_UNKNOWN);
...@@ -1008,7 +1009,7 @@ static int clean_an_unclean_leb(struct ubifs_info *c, ...@@ -1008,7 +1009,7 @@ static int clean_an_unclean_leb(struct ubifs_info *c,
return 0; return 0;
} }
err = ubi_read(c->ubi, lnum, buf, offs, len); err = ubifs_leb_read(c, lnum, buf, offs, len, 0);
if (err && err != -EBADMSG) if (err && err != -EBADMSG)
return err; return err;
...@@ -1453,7 +1454,7 @@ static int fix_size_in_place(struct ubifs_info *c, struct size_entry *e) ...@@ -1453,7 +1454,7 @@ static int fix_size_in_place(struct ubifs_info *c, struct size_entry *e)
if (i_size >= e->d_size) if (i_size >= e->d_size)
return 0; return 0;
/* Read the LEB */ /* Read the LEB */
err = ubi_read(c->ubi, lnum, c->sbuf, 0, c->leb_size); err = ubifs_leb_read(c, lnum, c->sbuf, 0, c->leb_size, 1);
if (err) if (err)
goto out; goto out;
/* Change the size field and recalculate the CRC */ /* Change the size field and recalculate the CRC */
......
...@@ -523,8 +523,7 @@ static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud) ...@@ -523,8 +523,7 @@ static int is_last_bud(struct ubifs_info *c, struct ubifs_bud *bud)
if (!list_is_last(&next->list, &jh->buds_list)) if (!list_is_last(&next->list, &jh->buds_list))
return 0; return 0;
err = ubi_read(c->ubi, next->lnum, (char *)&data, err = ubifs_leb_read(c, next->lnum, (char *)&data, next->start, 4, 1);
next->start, 4);
if (err) if (err)
return 0; return 0;
......
...@@ -678,7 +678,7 @@ static int fixup_leb(struct ubifs_info *c, int lnum, int len) ...@@ -678,7 +678,7 @@ static int fixup_leb(struct ubifs_info *c, int lnum, int len)
} }
dbg_mnt("fixup LEB %d, data len %d", lnum, len); dbg_mnt("fixup LEB %d, data len %d", lnum, len);
err = ubi_read(c->ubi, lnum, c->sbuf, 0, len); err = ubifs_leb_read(c, lnum, c->sbuf, 0, len, 1);
if (err) if (err)
return err; return err;
......
...@@ -148,7 +148,7 @@ struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum, ...@@ -148,7 +148,7 @@ struct ubifs_scan_leb *ubifs_start_scan(const struct ubifs_info *c, int lnum,
INIT_LIST_HEAD(&sleb->nodes); INIT_LIST_HEAD(&sleb->nodes);
sleb->buf = sbuf; sleb->buf = sbuf;
err = ubi_read(c->ubi, lnum, sbuf + offs, offs, c->leb_size - offs); err = ubifs_leb_read(c, lnum, sbuf + offs, offs, c->leb_size - offs, 0);
if (err && err != -EBADMSG) { if (err && err != -EBADMSG) {
ubifs_err("cannot read %d bytes from LEB %d:%d," ubifs_err("cannot read %d bytes from LEB %d:%d,"
" error %d", c->leb_size - offs, lnum, offs, err); " error %d", c->leb_size - offs, lnum, offs, err);
......
...@@ -462,7 +462,7 @@ static int try_read_node(const struct ubifs_info *c, void *buf, int type, ...@@ -462,7 +462,7 @@ static int try_read_node(const struct ubifs_info *c, void *buf, int type,
dbg_io("LEB %d:%d, %s, length %d", lnum, offs, dbg_ntype(type), len); dbg_io("LEB %d:%d, %s, length %d", lnum, offs, dbg_ntype(type), len);
err = ubi_read(c->ubi, lnum, buf, offs, len); err = ubifs_leb_read(c, lnum, buf, offs, len, 1);
if (err) { if (err) {
ubifs_err("cannot read node type %d from LEB %d:%d, error %d", ubifs_err("cannot read node type %d from LEB %d:%d, error %d",
type, lnum, offs, err); type, lnum, offs, err);
...@@ -1666,7 +1666,7 @@ static int read_wbuf(struct ubifs_wbuf *wbuf, void *buf, int len, int lnum, ...@@ -1666,7 +1666,7 @@ static int read_wbuf(struct ubifs_wbuf *wbuf, void *buf, int len, int lnum,
if (!overlap) { if (!overlap) {
/* We may safely unlock the write-buffer and read the data */ /* We may safely unlock the write-buffer and read the data */
spin_unlock(&wbuf->lock); spin_unlock(&wbuf->lock);
return ubi_read(c->ubi, lnum, buf, offs, len); return ubifs_leb_read(c, lnum, buf, offs, len, 0);
} }
/* Don't read under wbuf */ /* Don't read under wbuf */
...@@ -1680,7 +1680,7 @@ static int read_wbuf(struct ubifs_wbuf *wbuf, void *buf, int len, int lnum, ...@@ -1680,7 +1680,7 @@ static int read_wbuf(struct ubifs_wbuf *wbuf, void *buf, int len, int lnum,
if (rlen > 0) if (rlen > 0)
/* Read everything that goes before write-buffer */ /* Read everything that goes before write-buffer */
return ubi_read(c->ubi, lnum, buf, offs, rlen); return ubifs_leb_read(c, lnum, buf, offs, rlen, 0);
return 0; return 0;
} }
...@@ -1767,7 +1767,7 @@ int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu) ...@@ -1767,7 +1767,7 @@ int ubifs_tnc_bulk_read(struct ubifs_info *c, struct bu_info *bu)
if (wbuf) if (wbuf)
err = read_wbuf(wbuf, bu->buf, len, lnum, offs); err = read_wbuf(wbuf, bu->buf, len, lnum, offs);
else else
err = ubi_read(c->ubi, lnum, bu->buf, offs, len); err = ubifs_leb_read(c, lnum, bu->buf, offs, len, 0);
/* Check for a race with GC */ /* Check for a race with GC */
if (maybe_leb_gced(c, lnum, bu->gc_seq)) if (maybe_leb_gced(c, lnum, bu->gc_seq))
......
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