aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs/lpt_commit.c
diff options
context:
space:
mode:
authorRichard Weinberger <richard@nod.at>2018-07-12 07:01:57 -0400
committerRichard Weinberger <richard@nod.at>2018-08-14 18:25:21 -0400
commit6eb61d587f4515e4be5669eff383c0185009954f (patch)
treea5d3183e104338319152a888e0ff980c2546e6e1 /fs/ubifs/lpt_commit.c
parent54169ddd382d461f7c01cc5a5182a4b4bc539489 (diff)
ubifs: Pass struct ubifs_info to ubifs_assert()
This allows us to have more context in ubifs_assert() and take different actions depending on the configuration. Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'fs/ubifs/lpt_commit.c')
-rw-r--r--fs/ubifs/lpt_commit.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/fs/ubifs/lpt_commit.c b/fs/ubifs/lpt_commit.c
index 78da65b2fb85..7ce30994bbba 100644
--- a/fs/ubifs/lpt_commit.c
+++ b/fs/ubifs/lpt_commit.c
@@ -34,13 +34,14 @@ static int dbg_populate_lsave(struct ubifs_info *c);
34 34
35/** 35/**
36 * first_dirty_cnode - find first dirty cnode. 36 * first_dirty_cnode - find first dirty cnode.
37 * @c: UBIFS file-system description object
37 * @nnode: nnode at which to start 38 * @nnode: nnode at which to start
38 * 39 *
39 * This function returns the first dirty cnode or %NULL if there is not one. 40 * This function returns the first dirty cnode or %NULL if there is not one.
40 */ 41 */
41static struct ubifs_cnode *first_dirty_cnode(struct ubifs_nnode *nnode) 42static struct ubifs_cnode *first_dirty_cnode(const struct ubifs_info *c, struct ubifs_nnode *nnode)
42{ 43{
43 ubifs_assert(nnode); 44 ubifs_assert(c, nnode);
44 while (1) { 45 while (1) {
45 int i, cont = 0; 46 int i, cont = 0;
46 47
@@ -64,16 +65,17 @@ static struct ubifs_cnode *first_dirty_cnode(struct ubifs_nnode *nnode)
64 65
65/** 66/**
66 * next_dirty_cnode - find next dirty cnode. 67 * next_dirty_cnode - find next dirty cnode.
68 * @c: UBIFS file-system description object
67 * @cnode: cnode from which to begin searching 69 * @cnode: cnode from which to begin searching
68 * 70 *
69 * This function returns the next dirty cnode or %NULL if there is not one. 71 * This function returns the next dirty cnode or %NULL if there is not one.
70 */ 72 */
71static struct ubifs_cnode *next_dirty_cnode(struct ubifs_cnode *cnode) 73static struct ubifs_cnode *next_dirty_cnode(const struct ubifs_info *c, struct ubifs_cnode *cnode)
72{ 74{
73 struct ubifs_nnode *nnode; 75 struct ubifs_nnode *nnode;
74 int i; 76 int i;
75 77
76 ubifs_assert(cnode); 78 ubifs_assert(c, cnode);
77 nnode = cnode->parent; 79 nnode = cnode->parent;
78 if (!nnode) 80 if (!nnode)
79 return NULL; 81 return NULL;
@@ -83,7 +85,7 @@ static struct ubifs_cnode *next_dirty_cnode(struct ubifs_cnode *cnode)
83 if (cnode->level == 0) 85 if (cnode->level == 0)
84 return cnode; /* cnode is a pnode */ 86 return cnode; /* cnode is a pnode */
85 /* cnode is a nnode */ 87 /* cnode is a nnode */
86 return first_dirty_cnode((struct ubifs_nnode *)cnode); 88 return first_dirty_cnode(c, (struct ubifs_nnode *)cnode);
87 } 89 }
88 } 90 }
89 return (struct ubifs_cnode *)nnode; 91 return (struct ubifs_cnode *)nnode;
@@ -106,15 +108,15 @@ static int get_cnodes_to_commit(struct ubifs_info *c)
106 if (!test_bit(DIRTY_CNODE, &c->nroot->flags)) 108 if (!test_bit(DIRTY_CNODE, &c->nroot->flags))
107 return 0; 109 return 0;
108 110
109 c->lpt_cnext = first_dirty_cnode(c->nroot); 111 c->lpt_cnext = first_dirty_cnode(c, c->nroot);
110 cnode = c->lpt_cnext; 112 cnode = c->lpt_cnext;
111 if (!cnode) 113 if (!cnode)
112 return 0; 114 return 0;
113 cnt += 1; 115 cnt += 1;
114 while (1) { 116 while (1) {
115 ubifs_assert(!test_bit(COW_CNODE, &cnode->flags)); 117 ubifs_assert(c, !test_bit(COW_CNODE, &cnode->flags));
116 __set_bit(COW_CNODE, &cnode->flags); 118 __set_bit(COW_CNODE, &cnode->flags);
117 cnext = next_dirty_cnode(cnode); 119 cnext = next_dirty_cnode(c, cnode);
118 if (!cnext) { 120 if (!cnext) {
119 cnode->cnext = c->lpt_cnext; 121 cnode->cnext = c->lpt_cnext;
120 break; 122 break;
@@ -125,7 +127,7 @@ static int get_cnodes_to_commit(struct ubifs_info *c)
125 } 127 }
126 dbg_cmt("committing %d cnodes", cnt); 128 dbg_cmt("committing %d cnodes", cnt);
127 dbg_lp("committing %d cnodes", cnt); 129 dbg_lp("committing %d cnodes", cnt);
128 ubifs_assert(cnt == c->dirty_nn_cnt + c->dirty_pn_cnt); 130 ubifs_assert(c, cnt == c->dirty_nn_cnt + c->dirty_pn_cnt);
129 return cnt; 131 return cnt;
130} 132}
131 133
@@ -141,7 +143,7 @@ static void upd_ltab(struct ubifs_info *c, int lnum, int free, int dirty)
141 dbg_lp("LEB %d free %d dirty %d to %d +%d", 143 dbg_lp("LEB %d free %d dirty %d to %d +%d",
142 lnum, c->ltab[lnum - c->lpt_first].free, 144 lnum, c->ltab[lnum - c->lpt_first].free,
143 c->ltab[lnum - c->lpt_first].dirty, free, dirty); 145 c->ltab[lnum - c->lpt_first].dirty, free, dirty);
144 ubifs_assert(lnum >= c->lpt_first && lnum <= c->lpt_last); 146 ubifs_assert(c, lnum >= c->lpt_first && lnum <= c->lpt_last);
145 c->ltab[lnum - c->lpt_first].free = free; 147 c->ltab[lnum - c->lpt_first].free = free;
146 c->ltab[lnum - c->lpt_first].dirty += dirty; 148 c->ltab[lnum - c->lpt_first].dirty += dirty;
147} 149}
@@ -237,7 +239,7 @@ static int layout_cnodes(struct ubifs_info *c)
237 if (err) 239 if (err)
238 goto no_space; 240 goto no_space;
239 offs = 0; 241 offs = 0;
240 ubifs_assert(lnum >= c->lpt_first && 242 ubifs_assert(c, lnum >= c->lpt_first &&
241 lnum <= c->lpt_last); 243 lnum <= c->lpt_last);
242 /* Try to place lsave and ltab nicely */ 244 /* Try to place lsave and ltab nicely */
243 if (!done_lsave) { 245 if (!done_lsave) {
@@ -280,7 +282,7 @@ static int layout_cnodes(struct ubifs_info *c)
280 if (err) 282 if (err)
281 goto no_space; 283 goto no_space;
282 offs = 0; 284 offs = 0;
283 ubifs_assert(lnum >= c->lpt_first && 285 ubifs_assert(c, lnum >= c->lpt_first &&
284 lnum <= c->lpt_last); 286 lnum <= c->lpt_last);
285 } 287 }
286 done_lsave = 1; 288 done_lsave = 1;
@@ -300,7 +302,7 @@ static int layout_cnodes(struct ubifs_info *c)
300 if (err) 302 if (err)
301 goto no_space; 303 goto no_space;
302 offs = 0; 304 offs = 0;
303 ubifs_assert(lnum >= c->lpt_first && 305 ubifs_assert(c, lnum >= c->lpt_first &&
304 lnum <= c->lpt_last); 306 lnum <= c->lpt_last);
305 } 307 }
306 c->ltab_lnum = lnum; 308 c->ltab_lnum = lnum;
@@ -423,7 +425,7 @@ static int write_cnodes(struct ubifs_info *c)
423 if (err) 425 if (err)
424 goto no_space; 426 goto no_space;
425 offs = from = 0; 427 offs = from = 0;
426 ubifs_assert(lnum >= c->lpt_first && 428 ubifs_assert(c, lnum >= c->lpt_first &&
427 lnum <= c->lpt_last); 429 lnum <= c->lpt_last);
428 err = ubifs_leb_unmap(c, lnum); 430 err = ubifs_leb_unmap(c, lnum);
429 if (err) 431 if (err)
@@ -480,7 +482,7 @@ static int write_cnodes(struct ubifs_info *c)
480 if (err) 482 if (err)
481 goto no_space; 483 goto no_space;
482 offs = from = 0; 484 offs = from = 0;
483 ubifs_assert(lnum >= c->lpt_first && 485 ubifs_assert(c, lnum >= c->lpt_first &&
484 lnum <= c->lpt_last); 486 lnum <= c->lpt_last);
485 err = ubifs_leb_unmap(c, lnum); 487 err = ubifs_leb_unmap(c, lnum);
486 if (err) 488 if (err)
@@ -506,7 +508,7 @@ static int write_cnodes(struct ubifs_info *c)
506 if (err) 508 if (err)
507 goto no_space; 509 goto no_space;
508 offs = from = 0; 510 offs = from = 0;
509 ubifs_assert(lnum >= c->lpt_first && 511 ubifs_assert(c, lnum >= c->lpt_first &&
510 lnum <= c->lpt_last); 512 lnum <= c->lpt_last);
511 err = ubifs_leb_unmap(c, lnum); 513 err = ubifs_leb_unmap(c, lnum);
512 if (err) 514 if (err)
@@ -806,7 +808,7 @@ static void populate_lsave(struct ubifs_info *c)
806 struct ubifs_lpt_heap *heap; 808 struct ubifs_lpt_heap *heap;
807 int i, cnt = 0; 809 int i, cnt = 0;
808 810
809 ubifs_assert(c->big_lpt); 811 ubifs_assert(c, c->big_lpt);
810 if (!(c->lpt_drty_flgs & LSAVE_DIRTY)) { 812 if (!(c->lpt_drty_flgs & LSAVE_DIRTY)) {
811 c->lpt_drty_flgs |= LSAVE_DIRTY; 813 c->lpt_drty_flgs |= LSAVE_DIRTY;
812 ubifs_add_lpt_dirt(c, c->lsave_lnum, c->lsave_sz); 814 ubifs_add_lpt_dirt(c, c->lsave_lnum, c->lsave_sz);
@@ -1095,8 +1097,8 @@ static int get_lpt_node_type(const struct ubifs_info *c, uint8_t *buf,
1095 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES; 1097 uint8_t *addr = buf + UBIFS_LPT_CRC_BYTES;
1096 int pos = 0, node_type; 1098 int pos = 0, node_type;
1097 1099
1098 node_type = ubifs_unpack_bits(&addr, &pos, UBIFS_LPT_TYPE_BITS); 1100 node_type = ubifs_unpack_bits(c, &addr, &pos, UBIFS_LPT_TYPE_BITS);
1099 *node_num = ubifs_unpack_bits(&addr, &pos, c->pcnt_bits); 1101 *node_num = ubifs_unpack_bits(c, &addr, &pos, c->pcnt_bits);
1100 return node_type; 1102 return node_type;
1101} 1103}
1102 1104
@@ -1116,7 +1118,7 @@ static int is_a_node(const struct ubifs_info *c, uint8_t *buf, int len)
1116 1118
1117 if (len < UBIFS_LPT_CRC_BYTES + (UBIFS_LPT_TYPE_BITS + 7) / 8) 1119 if (len < UBIFS_LPT_CRC_BYTES + (UBIFS_LPT_TYPE_BITS + 7) / 8)
1118 return 0; 1120 return 0;
1119 node_type = ubifs_unpack_bits(&addr, &pos, UBIFS_LPT_TYPE_BITS); 1121 node_type = ubifs_unpack_bits(c, &addr, &pos, UBIFS_LPT_TYPE_BITS);
1120 if (node_type == UBIFS_LPT_NOT_A_NODE) 1122 if (node_type == UBIFS_LPT_NOT_A_NODE)
1121 return 0; 1123 return 0;
1122 node_len = get_lpt_node_len(c, node_type); 1124 node_len = get_lpt_node_len(c, node_type);
@@ -1124,7 +1126,7 @@ static int is_a_node(const struct ubifs_info *c, uint8_t *buf, int len)
1124 return 0; 1126 return 0;
1125 pos = 0; 1127 pos = 0;
1126 addr = buf; 1128 addr = buf;
1127 crc = ubifs_unpack_bits(&addr, &pos, UBIFS_LPT_CRC_BITS); 1129 crc = ubifs_unpack_bits(c, &addr, &pos, UBIFS_LPT_CRC_BITS);
1128 calc_crc = crc16(-1, buf + UBIFS_LPT_CRC_BYTES, 1130 calc_crc = crc16(-1, buf + UBIFS_LPT_CRC_BYTES,
1129 node_len - UBIFS_LPT_CRC_BYTES); 1131 node_len - UBIFS_LPT_CRC_BYTES);
1130 if (crc != calc_crc) 1132 if (crc != calc_crc)
@@ -1170,7 +1172,7 @@ static int lpt_gc_lnum(struct ubifs_info *c, int lnum)
1170 node_type = get_lpt_node_type(c, buf, &node_num); 1172 node_type = get_lpt_node_type(c, buf, &node_num);
1171 node_len = get_lpt_node_len(c, node_type); 1173 node_len = get_lpt_node_len(c, node_type);
1172 offs = c->leb_size - len; 1174 offs = c->leb_size - len;
1173 ubifs_assert(node_len != 0); 1175 ubifs_assert(c, node_len != 0);
1174 mutex_lock(&c->lp_mutex); 1176 mutex_lock(&c->lp_mutex);
1175 err = make_node_dirty(c, node_type, node_num, lnum, offs); 1177 err = make_node_dirty(c, node_type, node_num, lnum, offs);
1176 mutex_unlock(&c->lp_mutex); 1178 mutex_unlock(&c->lp_mutex);
@@ -1195,7 +1197,7 @@ static int lpt_gc(struct ubifs_info *c)
1195 1197
1196 mutex_lock(&c->lp_mutex); 1198 mutex_lock(&c->lp_mutex);
1197 for (i = 0; i < c->lpt_lebs; i++) { 1199 for (i = 0; i < c->lpt_lebs; i++) {
1198 ubifs_assert(!c->ltab[i].tgc); 1200 ubifs_assert(c, !c->ltab[i].tgc);
1199 if (i + c->lpt_first == c->nhead_lnum || 1201 if (i + c->lpt_first == c->nhead_lnum ||
1200 c->ltab[i].free + c->ltab[i].dirty == c->leb_size) 1202 c->ltab[i].free + c->ltab[i].dirty == c->leb_size)
1201 continue; 1203 continue;
@@ -1271,7 +1273,7 @@ int ubifs_lpt_start_commit(struct ubifs_info *c)
1271 populate_lsave(c); 1273 populate_lsave(c);
1272 1274
1273 cnt = get_cnodes_to_commit(c); 1275 cnt = get_cnodes_to_commit(c);
1274 ubifs_assert(cnt != 0); 1276 ubifs_assert(c, cnt != 0);
1275 1277
1276 err = layout_cnodes(c); 1278 err = layout_cnodes(c);
1277 if (err) 1279 if (err)