aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs/lpt.c
diff options
context:
space:
mode:
authorSheng Yong <shengyong1@huawei.com>2015-03-20 06:39:42 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2015-03-25 05:08:41 -0400
commit235c362bd0f6afcf767bc72aa0c647e1434cc631 (patch)
tree1cbc858f95877e51ddf48ea00dec0f6f7a481469 /fs/ubifs/lpt.c
parent8a87dc55f75f19ffdbb52066afea1b633577c79f (diff)
UBIFS: extend debug/message capabilities
In the case where we have more than one volumes on different UBI devices, it may be not that easy to tell which volume prints the messages. Add ubi number and volume id in ubifs_msg/warn/error to help debug. These two values are passed by struct ubifs_info. For those where ubifs_info is not initialized yet, ubifs_* is replaced by pr_*. For those where ubifs_info is not avaliable, ubifs_info is passed to the calling function as a const parameter. The output looks like, [ 95.444879] UBIFS (ubi0:1): background thread "ubifs_bgt0_1" started, PID 696 [ 95.484688] UBIFS (ubi0:1): UBIFS: mounted UBI device 0, volume 1, name "test1" [ 95.484694] UBIFS (ubi0:1): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes [ 95.484699] UBIFS (ubi0:1): FS size: 30220288 bytes (28 MiB, 238 LEBs), journal size 1523712 bytes (1 MiB, 12 LEBs) [ 95.484703] UBIFS (ubi0:1): reserved for root: 1427378 bytes (1393 KiB) [ 95.484709] UBIFS (ubi0:1): media format: w4/r0 (latest is w4/r0), UUID 40DFFC0E-70BE-4193-8905-F7D6DFE60B17, small LPT model [ 95.489875] UBIFS (ubi1:0): background thread "ubifs_bgt1_0" started, PID 699 [ 95.529713] UBIFS (ubi1:0): UBIFS: mounted UBI device 1, volume 0, name "test2" [ 95.529718] UBIFS (ubi1:0): LEB size: 126976 bytes (124 KiB), min./max. I/O unit sizes: 2048 bytes/2048 bytes [ 95.529724] UBIFS (ubi1:0): FS size: 19808256 bytes (18 MiB, 156 LEBs), journal size 1015809 bytes (0 MiB, 8 LEBs) [ 95.529727] UBIFS (ubi1:0): reserved for root: 935592 bytes (913 KiB) [ 95.529733] UBIFS (ubi1:0): media format: w4/r0 (latest is w4/r0), UUID EEB7779D-F419-4CA9-811B-831CAC7233D4, small LPT model [ 954.264767] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node type (255 but expected 6) [ 954.367030] UBIFS error (ubi1:0 pid 756): ubifs_read_node: bad node at LEB 0:0, LEB mapping status 1 Signed-off-by: Sheng Yong <shengyong1@huawei.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'fs/ubifs/lpt.c')
-rw-r--r--fs/ubifs/lpt.c59
1 files changed, 30 insertions, 29 deletions
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
index 421bd0a80424..dc9f27e9d61b 100644
--- a/fs/ubifs/lpt.c
+++ b/fs/ubifs/lpt.c
@@ -145,13 +145,13 @@ int ubifs_calc_lpt_geom(struct ubifs_info *c)
145 sz = c->lpt_sz * 2; /* Must have at least 2 times the size */ 145 sz = c->lpt_sz * 2; /* Must have at least 2 times the size */
146 lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size); 146 lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size);
147 if (lebs_needed > c->lpt_lebs) { 147 if (lebs_needed > c->lpt_lebs) {
148 ubifs_err("too few LPT LEBs"); 148 ubifs_err(c, "too few LPT LEBs");
149 return -EINVAL; 149 return -EINVAL;
150 } 150 }
151 151
152 /* Verify that ltab fits in a single LEB (since ltab is a single node */ 152 /* Verify that ltab fits in a single LEB (since ltab is a single node */
153 if (c->ltab_sz > c->leb_size) { 153 if (c->ltab_sz > c->leb_size) {
154 ubifs_err("LPT ltab too big"); 154 ubifs_err(c, "LPT ltab too big");
155 return -EINVAL; 155 return -EINVAL;
156 } 156 }
157 157
@@ -213,7 +213,7 @@ static int calc_dflt_lpt_geom(struct ubifs_info *c, int *main_lebs,
213 continue; 213 continue;
214 } 214 }
215 if (c->ltab_sz > c->leb_size) { 215 if (c->ltab_sz > c->leb_size) {
216 ubifs_err("LPT ltab too big"); 216 ubifs_err(c, "LPT ltab too big");
217 return -EINVAL; 217 return -EINVAL;
218 } 218 }
219 *main_lebs = c->main_lebs; 219 *main_lebs = c->main_lebs;
@@ -911,7 +911,7 @@ static void replace_cats(struct ubifs_info *c, struct ubifs_pnode *old_pnode,
911 * 911 *
912 * This function returns %0 on success and a negative error code on failure. 912 * This function returns %0 on success and a negative error code on failure.
913 */ 913 */
914static int check_lpt_crc(void *buf, int len) 914static int check_lpt_crc(const struct ubifs_info *c, void *buf, int len)
915{ 915{
916 int pos = 0; 916 int pos = 0;
917 uint8_t *addr = buf; 917 uint8_t *addr = buf;
@@ -921,8 +921,8 @@ static int check_lpt_crc(void *buf, int len)
921 calc_crc = crc16(-1, buf + UBIFS_LPT_CRC_BYTES, 921 calc_crc = crc16(-1, buf + UBIFS_LPT_CRC_BYTES,
922 len - UBIFS_LPT_CRC_BYTES); 922 len - UBIFS_LPT_CRC_BYTES);
923 if (crc != calc_crc) { 923 if (crc != calc_crc) {
924 ubifs_err("invalid crc in LPT node: crc %hx calc %hx", crc, 924 ubifs_err(c, "invalid crc in LPT node: crc %hx calc %hx",
925 calc_crc); 925 crc, calc_crc);
926 dump_stack(); 926 dump_stack();
927 return -EINVAL; 927 return -EINVAL;
928 } 928 }
@@ -938,14 +938,15 @@ static int check_lpt_crc(void *buf, int len)
938 * 938 *
939 * This function returns %0 on success and a negative error code on failure. 939 * This function returns %0 on success and a negative error code on failure.
940 */ 940 */
941static int check_lpt_type(uint8_t **addr, int *pos, int type) 941static int check_lpt_type(const struct ubifs_info *c, uint8_t **addr,
942 int *pos, int type)
942{ 943{
943 int node_type; 944 int node_type;
944 945
945 node_type = ubifs_unpack_bits(addr, pos, UBIFS_LPT_TYPE_BITS); 946 node_type = ubifs_unpack_bits(addr, pos, UBIFS_LPT_TYPE_BITS);
946 if (node_type != type) { 947 if (node_type != type) {
947 ubifs_err("invalid type (%d) in LPT node type %d", node_type, 948 ubifs_err(c, "invalid type (%d) in LPT node type %d",
948 type); 949 node_type, type);
949 dump_stack(); 950 dump_stack();
950 return -EINVAL; 951 return -EINVAL;
951 } 952 }
@@ -966,7 +967,7 @@ static int unpack_pnode(const struct ubifs_info *c, void *buf,
966 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 967 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
967 int i, pos = 0, err; 968 int i, pos = 0, err;
968 969
969 err = check_lpt_type(&addr, &pos, UBIFS_LPT_PNODE); 970 err = check_lpt_type(c, &addr, &pos, UBIFS_LPT_PNODE);
970 if (err) 971 if (err)
971 return err; 972 return err;
972 if (c->big_lpt) 973 if (c->big_lpt)
@@ -985,7 +986,7 @@ static int unpack_pnode(const struct ubifs_info *c, void *buf,
985 lprops->flags = 0; 986 lprops->flags = 0;
986 lprops->flags |= ubifs_categorize_lprops(c, lprops); 987 lprops->flags |= ubifs_categorize_lprops(c, lprops);
987 } 988 }
988 err = check_lpt_crc(buf, c->pnode_sz); 989 err = check_lpt_crc(c, buf, c->pnode_sz);
989 return err; 990 return err;
990} 991}
991 992
@@ -1003,7 +1004,7 @@ int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1003 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1004 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1004 int i, pos = 0, err; 1005 int i, pos = 0, err;
1005 1006
1006 err = check_lpt_type(&addr, &pos, UBIFS_LPT_NNODE); 1007 err = check_lpt_type(c, &addr, &pos, UBIFS_LPT_NNODE);
1007 if (err) 1008 if (err)
1008 return err; 1009 return err;
1009 if (c->big_lpt) 1010 if (c->big_lpt)
@@ -1019,7 +1020,7 @@ int ubifs_unpack_nnode(const struct ubifs_info *c, void *buf,
1019 nnode->nbranch[i].offs = ubifs_unpack_bits(&addr, &pos, 1020 nnode->nbranch[i].offs = ubifs_unpack_bits(&addr, &pos,
1020 c->lpt_offs_bits); 1021 c->lpt_offs_bits);
1021 } 1022 }
1022 err = check_lpt_crc(buf, c->nnode_sz); 1023 err = check_lpt_crc(c, buf, c->nnode_sz);
1023 return err; 1024 return err;
1024} 1025}
1025 1026
@@ -1035,7 +1036,7 @@ static int unpack_ltab(const struct ubifs_info *c, void *buf)
1035 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1036 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1036 int i, pos = 0, err; 1037 int i, pos = 0, err;
1037 1038
1038 err = check_lpt_type(&addr, &pos, UBIFS_LPT_LTAB); 1039 err = check_lpt_type(c, &addr, &pos, UBIFS_LPT_LTAB);
1039 if (err) 1040 if (err)
1040 return err; 1041 return err;
1041 for (i = 0; i < c->lpt_lebs; i++) { 1042 for (i = 0; i < c->lpt_lebs; i++) {
@@ -1051,7 +1052,7 @@ static int unpack_ltab(const struct ubifs_info *c, void *buf)
1051 c->ltab[i].tgc = 0; 1052 c->ltab[i].tgc = 0;
1052 c->ltab[i].cmt = 0; 1053 c->ltab[i].cmt = 0;
1053 } 1054 }
1054 err = check_lpt_crc(buf, c->ltab_sz); 1055 err = check_lpt_crc(c, buf, c->ltab_sz);
1055 return err; 1056 return err;
1056} 1057}
1057 1058
@@ -1067,7 +1068,7 @@ static int unpack_lsave(const struct ubifs_info *c, void *buf)
1067 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1068 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1068 int i, pos = 0, err; 1069 int i, pos = 0, err;
1069 1070
1070 err = check_lpt_type(&addr, &pos, UBIFS_LPT_LSAVE); 1071 err = check_lpt_type(c, &addr, &pos, UBIFS_LPT_LSAVE);
1071 if (err) 1072 if (err)
1072 return err; 1073 return err;
1073 for (i = 0; i < c->lsave_cnt; i++) { 1074 for (i = 0; i < c->lsave_cnt; i++) {
@@ -1077,7 +1078,7 @@ static int unpack_lsave(const struct ubifs_info *c, void *buf)
1077 return -EINVAL; 1078 return -EINVAL;
1078 c->lsave[i] = lnum; 1079 c->lsave[i] = lnum;
1079 } 1080 }
1080 err = check_lpt_crc(buf, c->lsave_sz); 1081 err = check_lpt_crc(c, buf, c->lsave_sz);
1081 return err; 1082 return err;
1082} 1083}
1083 1084
@@ -1243,7 +1244,7 @@ int ubifs_read_nnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
1243 return 0; 1244 return 0;
1244 1245
1245out: 1246out:
1246 ubifs_err("error %d reading nnode at %d:%d", err, lnum, offs); 1247 ubifs_err(c, "error %d reading nnode at %d:%d", err, lnum, offs);
1247 dump_stack(); 1248 dump_stack();
1248 kfree(nnode); 1249 kfree(nnode);
1249 return err; 1250 return err;
@@ -1308,10 +1309,10 @@ static int read_pnode(struct ubifs_info *c, struct ubifs_nnode *parent, int iip)
1308 return 0; 1309 return 0;
1309 1310
1310out: 1311out:
1311 ubifs_err("error %d reading pnode at %d:%d", err, lnum, offs); 1312 ubifs_err(c, "error %d reading pnode at %d:%d", err, lnum, offs);
1312 ubifs_dump_pnode(c, pnode, parent, iip); 1313 ubifs_dump_pnode(c, pnode, parent, iip);
1313 dump_stack(); 1314 dump_stack();
1314 ubifs_err("calc num: %d", calc_pnode_num_from_parent(c, parent, iip)); 1315 ubifs_err(c, "calc num: %d", calc_pnode_num_from_parent(c, parent, iip));
1315 kfree(pnode); 1316 kfree(pnode);
1316 return err; 1317 return err;
1317} 1318}
@@ -2095,7 +2096,7 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2095 int i; 2096 int i;
2096 2097
2097 if (pnode->num != col) { 2098 if (pnode->num != col) {
2098 ubifs_err("pnode num %d expected %d parent num %d iip %d", 2099 ubifs_err(c, "pnode num %d expected %d parent num %d iip %d",
2099 pnode->num, col, pnode->parent->num, pnode->iip); 2100 pnode->num, col, pnode->parent->num, pnode->iip);
2100 return -EINVAL; 2101 return -EINVAL;
2101 } 2102 }
@@ -2110,13 +2111,13 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2110 if (lnum >= c->leb_cnt) 2111 if (lnum >= c->leb_cnt)
2111 continue; 2112 continue;
2112 if (lprops->lnum != lnum) { 2113 if (lprops->lnum != lnum) {
2113 ubifs_err("bad LEB number %d expected %d", 2114 ubifs_err(c, "bad LEB number %d expected %d",
2114 lprops->lnum, lnum); 2115 lprops->lnum, lnum);
2115 return -EINVAL; 2116 return -EINVAL;
2116 } 2117 }
2117 if (lprops->flags & LPROPS_TAKEN) { 2118 if (lprops->flags & LPROPS_TAKEN) {
2118 if (cat != LPROPS_UNCAT) { 2119 if (cat != LPROPS_UNCAT) {
2119 ubifs_err("LEB %d taken but not uncat %d", 2120 ubifs_err(c, "LEB %d taken but not uncat %d",
2120 lprops->lnum, cat); 2121 lprops->lnum, cat);
2121 return -EINVAL; 2122 return -EINVAL;
2122 } 2123 }
@@ -2129,7 +2130,7 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2129 case LPROPS_FRDI_IDX: 2130 case LPROPS_FRDI_IDX:
2130 break; 2131 break;
2131 default: 2132 default:
2132 ubifs_err("LEB %d index but cat %d", 2133 ubifs_err(c, "LEB %d index but cat %d",
2133 lprops->lnum, cat); 2134 lprops->lnum, cat);
2134 return -EINVAL; 2135 return -EINVAL;
2135 } 2136 }
@@ -2142,7 +2143,7 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2142 case LPROPS_FREEABLE: 2143 case LPROPS_FREEABLE:
2143 break; 2144 break;
2144 default: 2145 default:
2145 ubifs_err("LEB %d not index but cat %d", 2146 ubifs_err(c, "LEB %d not index but cat %d",
2146 lprops->lnum, cat); 2147 lprops->lnum, cat);
2147 return -EINVAL; 2148 return -EINVAL;
2148 } 2149 }
@@ -2183,14 +2184,14 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2183 break; 2184 break;
2184 } 2185 }
2185 if (!found) { 2186 if (!found) {
2186 ubifs_err("LEB %d cat %d not found in cat heap/list", 2187 ubifs_err(c, "LEB %d cat %d not found in cat heap/list",
2187 lprops->lnum, cat); 2188 lprops->lnum, cat);
2188 return -EINVAL; 2189 return -EINVAL;
2189 } 2190 }
2190 switch (cat) { 2191 switch (cat) {
2191 case LPROPS_EMPTY: 2192 case LPROPS_EMPTY:
2192 if (lprops->free != c->leb_size) { 2193 if (lprops->free != c->leb_size) {
2193 ubifs_err("LEB %d cat %d free %d dirty %d", 2194 ubifs_err(c, "LEB %d cat %d free %d dirty %d",
2194 lprops->lnum, cat, lprops->free, 2195 lprops->lnum, cat, lprops->free,
2195 lprops->dirty); 2196 lprops->dirty);
2196 return -EINVAL; 2197 return -EINVAL;
@@ -2199,7 +2200,7 @@ static int dbg_chk_pnode(struct ubifs_info *c, struct ubifs_pnode *pnode,
2199 case LPROPS_FREEABLE: 2200 case LPROPS_FREEABLE:
2200 case LPROPS_FRDI_IDX: 2201 case LPROPS_FRDI_IDX:
2201 if (lprops->free + lprops->dirty != c->leb_size) { 2202 if (lprops->free + lprops->dirty != c->leb_size) {
2202 ubifs_err("LEB %d cat %d free %d dirty %d", 2203 ubifs_err(c, "LEB %d cat %d free %d dirty %d",
2203 lprops->lnum, cat, lprops->free, 2204 lprops->lnum, cat, lprops->free,
2204 lprops->dirty); 2205 lprops->dirty);
2205 return -EINVAL; 2206 return -EINVAL;
@@ -2236,7 +2237,7 @@ int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode,
2236 /* cnode is a nnode */ 2237 /* cnode is a nnode */
2237 num = calc_nnode_num(row, col); 2238 num = calc_nnode_num(row, col);
2238 if (cnode->num != num) { 2239 if (cnode->num != num) {
2239 ubifs_err("nnode num %d expected %d parent num %d iip %d", 2240 ubifs_err(c, "nnode num %d expected %d parent num %d iip %d",
2240 cnode->num, num, 2241 cnode->num, num,
2241 (nnode ? nnode->num : 0), cnode->iip); 2242 (nnode ? nnode->num : 0), cnode->iip);
2242 return -EINVAL; 2243 return -EINVAL;