提交 348709ba 编写于 作者: A Artem Bityutskiy

UBIFS: do not print scary error messages needlessly

At the moment UBIFS print large and scary error messages and
flash dumps in case of nearly any corruption, even if it is
a recoverable corruption. For example, if the master node is
corrupted, ubifs_scan() prints error dumps, then UBIFS recovers
just fine and goes on.

This patch makes UBIFS print scary error messages only in
real cases, which are not recoverable. It adds 'quiet' argument
to the 'ubifs_scan()' function, so the caller may ask 'ubi_scan()'
not to print error messages if the caller is able to do recovery.
Signed-off-by: NArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Reviewed-by: NAdrian Hunter <Adrian.Hunter@nokia.com>
上级 e3c3efc2
...@@ -724,7 +724,7 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum) ...@@ -724,7 +724,7 @@ void dbg_dump_leb(const struct ubifs_info *c, int lnum)
printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n", printk(KERN_DEBUG "(pid %d) start dumping LEB %d\n",
current->pid, lnum); current->pid, lnum);
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf); sleb = ubifs_scan(c, lnum, 0, c->dbg->buf, 0);
if (IS_ERR(sleb)) { if (IS_ERR(sleb)) {
ubifs_err("scan error %d", (int)PTR_ERR(sleb)); ubifs_err("scan error %d", (int)PTR_ERR(sleb));
return; return;
......
...@@ -529,7 +529,7 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp) ...@@ -529,7 +529,7 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp)
* We scan the entire LEB even though we only really need to scan up to * We scan the entire LEB even though we only really need to scan up to
* (c->leb_size - lp->free). * (c->leb_size - lp->free).
*/ */
sleb = ubifs_scan(c, lnum, 0, c->sbuf); sleb = ubifs_scan(c, lnum, 0, c->sbuf, 0);
if (IS_ERR(sleb)) if (IS_ERR(sleb))
return PTR_ERR(sleb); return PTR_ERR(sleb);
......
...@@ -695,7 +695,7 @@ int ubifs_consolidate_log(struct ubifs_info *c) ...@@ -695,7 +695,7 @@ int ubifs_consolidate_log(struct ubifs_info *c)
lnum = c->ltail_lnum; lnum = c->ltail_lnum;
write_lnum = lnum; write_lnum = lnum;
while (1) { while (1) {
sleb = ubifs_scan(c, lnum, 0, c->sbuf); sleb = ubifs_scan(c, lnum, 0, c->sbuf, 0);
if (IS_ERR(sleb)) { if (IS_ERR(sleb)) {
err = PTR_ERR(sleb); err = PTR_ERR(sleb);
goto out_free; goto out_free;
......
...@@ -1096,7 +1096,7 @@ static int scan_check_cb(struct ubifs_info *c, ...@@ -1096,7 +1096,7 @@ static int scan_check_cb(struct ubifs_info *c,
} }
} }
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf); sleb = ubifs_scan(c, lnum, 0, c->dbg->buf, 0);
if (IS_ERR(sleb)) { if (IS_ERR(sleb)) {
/* /*
* After an unclean unmount, empty and freeable LEBs * After an unclean unmount, empty and freeable LEBs
......
...@@ -40,7 +40,7 @@ static int scan_for_master(struct ubifs_info *c) ...@@ -40,7 +40,7 @@ static int scan_for_master(struct ubifs_info *c)
lnum = UBIFS_MST_LNUM; lnum = UBIFS_MST_LNUM;
sleb = ubifs_scan(c, lnum, 0, c->sbuf); sleb = ubifs_scan(c, lnum, 0, c->sbuf, 1);
if (IS_ERR(sleb)) if (IS_ERR(sleb))
return PTR_ERR(sleb); return PTR_ERR(sleb);
nodes_cnt = sleb->nodes_cnt; nodes_cnt = sleb->nodes_cnt;
...@@ -56,7 +56,7 @@ static int scan_for_master(struct ubifs_info *c) ...@@ -56,7 +56,7 @@ static int scan_for_master(struct ubifs_info *c)
lnum += 1; lnum += 1;
sleb = ubifs_scan(c, lnum, 0, c->sbuf); sleb = ubifs_scan(c, lnum, 0, c->sbuf, 1);
if (IS_ERR(sleb)) if (IS_ERR(sleb))
return PTR_ERR(sleb); return PTR_ERR(sleb);
if (sleb->nodes_cnt != nodes_cnt) if (sleb->nodes_cnt != nodes_cnt)
......
...@@ -670,7 +670,7 @@ static int kill_orphans(struct ubifs_info *c) ...@@ -670,7 +670,7 @@ static int kill_orphans(struct ubifs_info *c)
struct ubifs_scan_leb *sleb; struct ubifs_scan_leb *sleb;
dbg_rcvry("LEB %d", lnum); dbg_rcvry("LEB %d", lnum);
sleb = ubifs_scan(c, lnum, 0, c->sbuf); sleb = ubifs_scan(c, lnum, 0, c->sbuf, 1);
if (IS_ERR(sleb)) { if (IS_ERR(sleb)) {
sleb = ubifs_recover_leb(c, lnum, 0, c->sbuf, 0); sleb = ubifs_recover_leb(c, lnum, 0, c->sbuf, 0);
if (IS_ERR(sleb)) { if (IS_ERR(sleb)) {
...@@ -899,7 +899,7 @@ static int dbg_scan_orphans(struct ubifs_info *c, struct check_info *ci) ...@@ -899,7 +899,7 @@ static int dbg_scan_orphans(struct ubifs_info *c, struct check_info *ci)
for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) { for (lnum = c->orph_first; lnum <= c->orph_last; lnum++) {
struct ubifs_scan_leb *sleb; struct ubifs_scan_leb *sleb;
sleb = ubifs_scan(c, lnum, 0, c->dbg->buf); sleb = ubifs_scan(c, lnum, 0, c->dbg->buf, 0);
if (IS_ERR(sleb)) { if (IS_ERR(sleb)) {
err = PTR_ERR(sleb); err = PTR_ERR(sleb);
break; break;
......
...@@ -286,7 +286,7 @@ int ubifs_recover_master_node(struct ubifs_info *c) ...@@ -286,7 +286,7 @@ int ubifs_recover_master_node(struct ubifs_info *c)
mst = mst2; mst = mst2;
} }
dbg_rcvry("recovered master node from LEB %d", ubifs_msg("recovered master node from LEB %d",
(mst == mst1 ? UBIFS_MST_LNUM : UBIFS_MST_LNUM + 1)); (mst == mst1 ? UBIFS_MST_LNUM : UBIFS_MST_LNUM + 1));
memcpy(c->mst_node, mst, UBIFS_MST_NODE_SZ); memcpy(c->mst_node, mst, UBIFS_MST_NODE_SZ);
...@@ -790,7 +790,7 @@ struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum, ...@@ -790,7 +790,7 @@ struct ubifs_scan_leb *ubifs_recover_log_leb(struct ubifs_info *c, int lnum,
* We can only recover at the end of the log, so check that the * We can only recover at the end of the log, so check that the
* next log LEB is empty or out of date. * next log LEB is empty or out of date.
*/ */
sleb = ubifs_scan(c, next_lnum, 0, sbuf); sleb = ubifs_scan(c, next_lnum, 0, sbuf, 0);
if (IS_ERR(sleb)) if (IS_ERR(sleb))
return sleb; return sleb;
if (sleb->nodes_cnt) { if (sleb->nodes_cnt) {
......
...@@ -506,7 +506,7 @@ static int replay_bud(struct ubifs_info *c, int lnum, int offs, int jhead, ...@@ -506,7 +506,7 @@ static int replay_bud(struct ubifs_info *c, int lnum, int offs, int jhead,
if (c->need_recovery) if (c->need_recovery)
sleb = ubifs_recover_leb(c, lnum, offs, c->sbuf, jhead != GCHD); sleb = ubifs_recover_leb(c, lnum, offs, c->sbuf, jhead != GCHD);
else else
sleb = ubifs_scan(c, lnum, offs, c->sbuf); sleb = ubifs_scan(c, lnum, offs, c->sbuf, 0);
if (IS_ERR(sleb)) if (IS_ERR(sleb))
return PTR_ERR(sleb); return PTR_ERR(sleb);
...@@ -836,8 +836,8 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf) ...@@ -836,8 +836,8 @@ static int replay_log_leb(struct ubifs_info *c, int lnum, int offs, void *sbuf)
const struct ubifs_cs_node *node; const struct ubifs_cs_node *node;
dbg_mnt("replay log LEB %d:%d", lnum, offs); dbg_mnt("replay log LEB %d:%d", lnum, offs);
sleb = ubifs_scan(c, lnum, offs, sbuf); sleb = ubifs_scan(c, lnum, offs, sbuf, c->need_recovery);
if (IS_ERR(sleb) ) { if (IS_ERR(sleb)) {
if (PTR_ERR(sleb) != -EUCLEAN || !c->need_recovery) if (PTR_ERR(sleb) != -EUCLEAN || !c->need_recovery)
return PTR_ERR(sleb); return PTR_ERR(sleb);
sleb = ubifs_recover_log_leb(c, lnum, offs, sbuf); sleb = ubifs_recover_log_leb(c, lnum, offs, sbuf);
......
...@@ -108,10 +108,9 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum, ...@@ -108,10 +108,9 @@ int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
/* Make the node pads to 8-byte boundary */ /* Make the node pads to 8-byte boundary */
if ((node_len + pad_len) & 7) { if ((node_len + pad_len) & 7) {
if (!quiet) { if (!quiet)
dbg_err("bad padding length %d - %d", dbg_err("bad padding length %d - %d",
offs, offs + node_len + pad_len); offs, offs + node_len + pad_len);
}
return SCANNED_A_BAD_PAD_NODE; return SCANNED_A_BAD_PAD_NODE;
} }
...@@ -253,15 +252,19 @@ void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs, ...@@ -253,15 +252,19 @@ void ubifs_scanned_corruption(const struct ubifs_info *c, int lnum, int offs,
* @c: UBIFS file-system description object * @c: UBIFS file-system description object
* @lnum: logical eraseblock number * @lnum: logical eraseblock number
* @offs: offset to start at (usually zero) * @offs: offset to start at (usually zero)
* @sbuf: scan buffer (must be c->leb_size) * @sbuf: scan buffer (must be of @c->leb_size bytes in size)
* @quiet: print no messages
* *
* This function scans LEB number @lnum and returns complete information about * This function scans LEB number @lnum and returns complete information about
* its contents. Returns the scaned information in case of success and, * its contents. Returns the scaned information in case of success and,
* %-EUCLEAN if the LEB neads recovery, and other negative error codes in case * %-EUCLEAN if the LEB neads recovery, and other negative error codes in case
* of failure. * of failure.
*
* If @quiet is non-zero, this function does not print large and scary
* error messages and flash dumps in case of errors.
*/ */
struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum, struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
int offs, void *sbuf) int offs, void *sbuf, int quiet)
{ {
void *buf = sbuf + offs; void *buf = sbuf + offs;
int err, len = c->leb_size - offs; int err, len = c->leb_size - offs;
...@@ -280,7 +283,7 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum, ...@@ -280,7 +283,7 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
cond_resched(); cond_resched();
ret = ubifs_scan_a_node(c, buf, len, lnum, offs, 0); ret = ubifs_scan_a_node(c, buf, len, lnum, offs, quiet);
if (ret > 0) { if (ret > 0) {
/* Padding bytes or a valid padding node */ /* Padding bytes or a valid padding node */
offs += ret; offs += ret;
...@@ -320,7 +323,9 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum, ...@@ -320,7 +323,9 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
} }
if (offs % c->min_io_size) { if (offs % c->min_io_size) {
ubifs_err("empty space starts at non-aligned offset %d", offs); if (!quiet)
ubifs_err("empty space starts at non-aligned offset %d",
offs);
goto corrupted;; goto corrupted;;
} }
...@@ -331,18 +336,25 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum, ...@@ -331,18 +336,25 @@ struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
break; break;
for (; len; offs++, buf++, len--) for (; len; offs++, buf++, len--)
if (*(uint8_t *)buf != 0xff) { if (*(uint8_t *)buf != 0xff) {
ubifs_err("corrupt empty space at LEB %d:%d", if (!quiet)
lnum, offs); ubifs_err("corrupt empty space at LEB %d:%d",
lnum, offs);
goto corrupted; goto corrupted;
} }
return sleb; return sleb;
corrupted: corrupted:
ubifs_scanned_corruption(c, lnum, offs, buf); if (!quiet) {
ubifs_scanned_corruption(c, lnum, offs, buf);
ubifs_err("LEB %d scanning failed", lnum);
}
err = -EUCLEAN; err = -EUCLEAN;
ubifs_scan_destroy(sleb);
return ERR_PTR(err);
error: error:
ubifs_err("LEB %d scanning failed", lnum); ubifs_err("LEB %d scanning failed, error %d", lnum, err);
ubifs_scan_destroy(sleb); ubifs_scan_destroy(sleb);
return ERR_PTR(err); return ERR_PTR(err);
} }
......
...@@ -245,7 +245,7 @@ static int layout_leb_in_gaps(struct ubifs_info *c, int *p) ...@@ -245,7 +245,7 @@ static int layout_leb_in_gaps(struct ubifs_info *c, int *p)
* it is more comprehensive and less efficient than is needed for this * it is more comprehensive and less efficient than is needed for this
* purpose. * purpose.
*/ */
sleb = ubifs_scan(c, lnum, 0, c->ileb_buf); sleb = ubifs_scan(c, lnum, 0, c->ileb_buf, 0);
c->ileb_len = 0; c->ileb_len = 0;
if (IS_ERR(sleb)) if (IS_ERR(sleb))
return PTR_ERR(sleb); return PTR_ERR(sleb);
......
...@@ -1451,7 +1451,7 @@ int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode); ...@@ -1451,7 +1451,7 @@ int ubifs_sync_wbufs_by_inode(struct ubifs_info *c, struct inode *inode);
/* scan.c */ /* scan.c */
struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum, struct ubifs_scan_leb *ubifs_scan(const struct ubifs_info *c, int lnum,
int offs, void *sbuf); int offs, void *sbuf, int quiet);
void ubifs_scan_destroy(struct ubifs_scan_leb *sleb); void ubifs_scan_destroy(struct ubifs_scan_leb *sleb);
int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum, int ubifs_scan_a_node(const struct ubifs_info *c, void *buf, int len, int lnum,
int offs, int quiet); int offs, int quiet);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册