Skip to content

Commit 6eb61d5

Browse files
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 <[email protected]>
1 parent 54169dd commit 6eb61d5

31 files changed

+550
-521
lines changed

fs/ubifs/budget.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,16 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
439439
{
440440
int err, idx_growth, data_growth, dd_growth, retried = 0;
441441

442-
ubifs_assert(req->new_page <= 1);
443-
ubifs_assert(req->dirtied_page <= 1);
444-
ubifs_assert(req->new_dent <= 1);
445-
ubifs_assert(req->mod_dent <= 1);
446-
ubifs_assert(req->new_ino <= 1);
447-
ubifs_assert(req->new_ino_d <= UBIFS_MAX_INO_DATA);
448-
ubifs_assert(req->dirtied_ino <= 4);
449-
ubifs_assert(req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
450-
ubifs_assert(!(req->new_ino_d & 7));
451-
ubifs_assert(!(req->dirtied_ino_d & 7));
442+
ubifs_assert(c, req->new_page <= 1);
443+
ubifs_assert(c, req->dirtied_page <= 1);
444+
ubifs_assert(c, req->new_dent <= 1);
445+
ubifs_assert(c, req->mod_dent <= 1);
446+
ubifs_assert(c, req->new_ino <= 1);
447+
ubifs_assert(c, req->new_ino_d <= UBIFS_MAX_INO_DATA);
448+
ubifs_assert(c, req->dirtied_ino <= 4);
449+
ubifs_assert(c, req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
450+
ubifs_assert(c, !(req->new_ino_d & 7));
451+
ubifs_assert(c, !(req->dirtied_ino_d & 7));
452452

453453
data_growth = calc_data_growth(c, req);
454454
dd_growth = calc_dd_growth(c, req);
@@ -458,9 +458,9 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
458458

459459
again:
460460
spin_lock(&c->space_lock);
461-
ubifs_assert(c->bi.idx_growth >= 0);
462-
ubifs_assert(c->bi.data_growth >= 0);
463-
ubifs_assert(c->bi.dd_growth >= 0);
461+
ubifs_assert(c, c->bi.idx_growth >= 0);
462+
ubifs_assert(c, c->bi.data_growth >= 0);
463+
ubifs_assert(c, c->bi.dd_growth >= 0);
464464

465465
if (unlikely(c->bi.nospace) && (c->bi.nospace_rp || !can_use_rp(c))) {
466466
dbg_budg("no space");
@@ -526,20 +526,20 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
526526
*/
527527
void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req)
528528
{
529-
ubifs_assert(req->new_page <= 1);
530-
ubifs_assert(req->dirtied_page <= 1);
531-
ubifs_assert(req->new_dent <= 1);
532-
ubifs_assert(req->mod_dent <= 1);
533-
ubifs_assert(req->new_ino <= 1);
534-
ubifs_assert(req->new_ino_d <= UBIFS_MAX_INO_DATA);
535-
ubifs_assert(req->dirtied_ino <= 4);
536-
ubifs_assert(req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
537-
ubifs_assert(!(req->new_ino_d & 7));
538-
ubifs_assert(!(req->dirtied_ino_d & 7));
529+
ubifs_assert(c, req->new_page <= 1);
530+
ubifs_assert(c, req->dirtied_page <= 1);
531+
ubifs_assert(c, req->new_dent <= 1);
532+
ubifs_assert(c, req->mod_dent <= 1);
533+
ubifs_assert(c, req->new_ino <= 1);
534+
ubifs_assert(c, req->new_ino_d <= UBIFS_MAX_INO_DATA);
535+
ubifs_assert(c, req->dirtied_ino <= 4);
536+
ubifs_assert(c, req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
537+
ubifs_assert(c, !(req->new_ino_d & 7));
538+
ubifs_assert(c, !(req->dirtied_ino_d & 7));
539539
if (!req->recalculate) {
540-
ubifs_assert(req->idx_growth >= 0);
541-
ubifs_assert(req->data_growth >= 0);
542-
ubifs_assert(req->dd_growth >= 0);
540+
ubifs_assert(c, req->idx_growth >= 0);
541+
ubifs_assert(c, req->data_growth >= 0);
542+
ubifs_assert(c, req->dd_growth >= 0);
543543
}
544544

545545
if (req->recalculate) {
@@ -561,13 +561,13 @@ void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req)
561561
c->bi.dd_growth -= req->dd_growth;
562562
c->bi.min_idx_lebs = ubifs_calc_min_idx_lebs(c);
563563

564-
ubifs_assert(c->bi.idx_growth >= 0);
565-
ubifs_assert(c->bi.data_growth >= 0);
566-
ubifs_assert(c->bi.dd_growth >= 0);
567-
ubifs_assert(c->bi.min_idx_lebs < c->main_lebs);
568-
ubifs_assert(!(c->bi.idx_growth & 7));
569-
ubifs_assert(!(c->bi.data_growth & 7));
570-
ubifs_assert(!(c->bi.dd_growth & 7));
564+
ubifs_assert(c, c->bi.idx_growth >= 0);
565+
ubifs_assert(c, c->bi.data_growth >= 0);
566+
ubifs_assert(c, c->bi.dd_growth >= 0);
567+
ubifs_assert(c, c->bi.min_idx_lebs < c->main_lebs);
568+
ubifs_assert(c, !(c->bi.idx_growth & 7));
569+
ubifs_assert(c, !(c->bi.data_growth & 7));
570+
ubifs_assert(c, !(c->bi.dd_growth & 7));
571571
spin_unlock(&c->space_lock);
572572
}
573573

@@ -680,7 +680,7 @@ long long ubifs_get_free_space_nolock(struct ubifs_info *c)
680680
int rsvd_idx_lebs, lebs;
681681
long long available, outstanding, free;
682682

683-
ubifs_assert(c->bi.min_idx_lebs == ubifs_calc_min_idx_lebs(c));
683+
ubifs_assert(c, c->bi.min_idx_lebs == ubifs_calc_min_idx_lebs(c));
684684
outstanding = c->bi.data_growth + c->bi.dd_growth;
685685
available = ubifs_calc_available(c, c->bi.min_idx_lebs);
686686

fs/ubifs/commit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ static int nothing_to_commit(struct ubifs_info *c)
9191
if (c->nroot && test_bit(DIRTY_CNODE, &c->nroot->flags))
9292
return 0;
9393

94-
ubifs_assert(atomic_long_read(&c->dirty_zn_cnt) == 0);
95-
ubifs_assert(c->dirty_pn_cnt == 0);
96-
ubifs_assert(c->dirty_nn_cnt == 0);
94+
ubifs_assert(c, atomic_long_read(&c->dirty_zn_cnt) == 0);
95+
ubifs_assert(c, c->dirty_pn_cnt == 0);
96+
ubifs_assert(c, c->dirty_nn_cnt == 0);
9797

9898
return 1;
9999
}
@@ -113,7 +113,7 @@ static int do_commit(struct ubifs_info *c)
113113
struct ubifs_lp_stats lst;
114114

115115
dbg_cmt("start");
116-
ubifs_assert(!c->ro_media && !c->ro_mount);
116+
ubifs_assert(c, !c->ro_media && !c->ro_mount);
117117

118118
if (c->ro_error) {
119119
err = -EROFS;

fs/ubifs/crypto.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ int ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn,
3232
struct page *ret;
3333
unsigned int pad_len = round_up(in_len, UBIFS_CIPHER_BLOCK_SIZE);
3434

35-
ubifs_assert(pad_len <= *out_len);
35+
ubifs_assert(c, pad_len <= *out_len);
3636
dn->compr_size = cpu_to_le16(in_len);
3737

3838
/* pad to full block cipher length */
@@ -63,7 +63,7 @@ int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
6363
return -EINVAL;
6464
}
6565

66-
ubifs_assert(dlen <= UBIFS_BLOCK_SIZE);
66+
ubifs_assert(c, dlen <= UBIFS_BLOCK_SIZE);
6767
err = fscrypt_decrypt_page(inode, virt_to_page(&dn->data), dlen,
6868
offset_in_page(&dn->data), block);
6969
if (err) {

fs/ubifs/debug.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ const char *dbg_snprintf_key(const struct ubifs_info *c,
134134
}
135135
} else
136136
len -= snprintf(p, len, "bad key format %d", c->key_fmt);
137-
ubifs_assert(len > 0);
137+
ubifs_assert(c, len > 0);
138138
return p;
139139
}
140140

@@ -276,7 +276,7 @@ void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode)
276276
return;
277277

278278
pr_err("List of directory entries:\n");
279-
ubifs_assert(!mutex_is_locked(&c->tnc_mutex));
279+
ubifs_assert(c, !mutex_is_locked(&c->tnc_mutex));
280280

281281
lowest_dent_key(c, &key, inode->i_ino);
282282
while (1) {
@@ -931,7 +931,7 @@ void ubifs_dump_tnc(struct ubifs_info *c)
931931

932932
pr_err("\n");
933933
pr_err("(pid %d) start dumping TNC tree\n", current->pid);
934-
znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL);
934+
znode = ubifs_tnc_levelorder_next(c, c->zroot.znode, NULL);
935935
level = znode->level;
936936
pr_err("== Level %d ==\n", level);
937937
while (znode) {
@@ -940,7 +940,7 @@ void ubifs_dump_tnc(struct ubifs_info *c)
940940
pr_err("== Level %d ==\n", level);
941941
}
942942
ubifs_dump_znode(c, znode);
943-
znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode);
943+
znode = ubifs_tnc_levelorder_next(c, c->zroot.znode, znode);
944944
}
945945
pr_err("(pid %d) finish dumping TNC tree\n", current->pid);
946946
}
@@ -1183,7 +1183,7 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
11831183
union ubifs_key key;
11841184
char key_buf[DBG_KEY_BUF_LEN];
11851185

1186-
ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key));
1186+
ubifs_assert(c, !keys_cmp(c, &zbr1->key, &zbr2->key));
11871187
dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS);
11881188
if (!dent1)
11891189
return -ENOMEM;
@@ -1479,7 +1479,7 @@ int dbg_check_tnc(struct ubifs_info *c, int extra)
14791479
if (!dbg_is_chk_index(c))
14801480
return 0;
14811481

1482-
ubifs_assert(mutex_is_locked(&c->tnc_mutex));
1482+
ubifs_assert(c, mutex_is_locked(&c->tnc_mutex));
14831483
if (!c->zroot.znode)
14841484
return 0;
14851485

@@ -1505,7 +1505,7 @@ int dbg_check_tnc(struct ubifs_info *c, int extra)
15051505
}
15061506

15071507
prev = znode;
1508-
znode = ubifs_tnc_postorder_next(znode);
1508+
znode = ubifs_tnc_postorder_next(c, znode);
15091509
if (!znode)
15101510
break;
15111511

@@ -2036,7 +2036,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
20362036
long long blk_offs;
20372037
struct ubifs_data_node *dn = node;
20382038

2039-
ubifs_assert(zbr->len >= UBIFS_DATA_NODE_SZ);
2039+
ubifs_assert(c, zbr->len >= UBIFS_DATA_NODE_SZ);
20402040

20412041
/*
20422042
* Search the inode node this data node belongs to and insert
@@ -2066,7 +2066,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
20662066
struct ubifs_dent_node *dent = node;
20672067
struct fsck_inode *fscki1;
20682068

2069-
ubifs_assert(zbr->len >= UBIFS_DENT_NODE_SZ);
2069+
ubifs_assert(c, zbr->len >= UBIFS_DENT_NODE_SZ);
20702070

20712071
err = ubifs_validate_entry(c, dent);
20722072
if (err)
@@ -2461,7 +2461,7 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
24612461
{
24622462
struct ubifs_debug_info *d = c->dbg;
24632463

2464-
ubifs_assert(dbg_is_tst_rcvry(c));
2464+
ubifs_assert(c, dbg_is_tst_rcvry(c));
24652465

24662466
if (!d->pc_cnt) {
24672467
/* First call - decide delay to the power cut */

fs/ubifs/debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ struct ubifs_global_debug_info {
148148
unsigned int tst_rcvry:1;
149149
};
150150

151-
#define ubifs_assert(expr) do { \
151+
#define ubifs_assert(c, expr) do { \
152152
if (unlikely(!(expr))) { \
153153
pr_crit("UBIFS assert failed in %s at %u (pid %d)\n", \
154154
__func__, __LINE__, current->pid); \
@@ -160,7 +160,7 @@ struct ubifs_global_debug_info {
160160
if (unlikely(down_write_trylock(&(c)->commit_sem))) { \
161161
up_write(&(c)->commit_sem); \
162162
pr_crit("commit lock is not locked!\n"); \
163-
ubifs_assert(0); \
163+
ubifs_assert(c, 0); \
164164
} \
165165
} while (0)
166166

fs/ubifs/dir.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
240240
}
241241

242242
if (nm.hash) {
243-
ubifs_assert(fname_len(&nm) == 0);
244-
ubifs_assert(fname_name(&nm) == NULL);
243+
ubifs_assert(c, fname_len(&nm) == 0);
244+
ubifs_assert(c, fname_name(&nm) == NULL);
245245
dent_key_init_hash(c, &key, dir->i_ino, nm.hash);
246246
err = ubifs_tnc_lookup_dh(c, &key, dent, nm.minor_hash);
247247
} else {
@@ -404,7 +404,7 @@ static int do_tmpfile(struct inode *dir, struct dentry *dentry,
404404

405405
if (whiteout) {
406406
init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
407-
ubifs_assert(inode->i_op == &ubifs_file_inode_operations);
407+
ubifs_assert(c, inode->i_op == &ubifs_file_inode_operations);
408408
}
409409

410410
err = ubifs_init_security(dir, inode, &dentry->d_name);
@@ -421,7 +421,7 @@ static int do_tmpfile(struct inode *dir, struct dentry *dentry,
421421
} else {
422422
d_tmpfile(dentry, inode);
423423
}
424-
ubifs_assert(ui->dirty);
424+
ubifs_assert(c, ui->dirty);
425425

426426
instantiated = 1;
427427
mutex_unlock(&ui->ui_mutex);
@@ -556,7 +556,7 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx)
556556

557557
/* File positions 0 and 1 correspond to "." and ".." */
558558
if (ctx->pos < 2) {
559-
ubifs_assert(!file->private_data);
559+
ubifs_assert(c, !file->private_data);
560560
if (!dir_emit_dots(file, ctx)) {
561561
if (encrypted)
562562
fscrypt_fname_free_buffer(&fstr);
@@ -597,7 +597,7 @@ static int ubifs_readdir(struct file *file, struct dir_context *ctx)
597597
dbg_gen("ino %llu, new f_pos %#x",
598598
(unsigned long long)le64_to_cpu(dent->inum),
599599
key_hash_flash(c, &dent->key));
600-
ubifs_assert(le64_to_cpu(dent->ch.sqnum) >
600+
ubifs_assert(c, le64_to_cpu(dent->ch.sqnum) >
601601
ubifs_inode(dir)->creat_sqnum);
602602

603603
fname_len(&nm) = le16_to_cpu(dent->nlen);
@@ -716,8 +716,8 @@ static int ubifs_link(struct dentry *old_dentry, struct inode *dir,
716716
dbg_gen("dent '%pd' to ino %lu (nlink %d) in dir ino %lu",
717717
dentry, inode->i_ino,
718718
inode->i_nlink, dir->i_ino);
719-
ubifs_assert(inode_is_locked(dir));
720-
ubifs_assert(inode_is_locked(inode));
719+
ubifs_assert(c, inode_is_locked(dir));
720+
ubifs_assert(c, inode_is_locked(inode));
721721

722722
err = fscrypt_prepare_link(old_dentry, dir, dentry);
723723
if (err)
@@ -804,8 +804,8 @@ static int ubifs_unlink(struct inode *dir, struct dentry *dentry)
804804

805805
sz_change = CALC_DENT_SIZE(fname_len(&nm));
806806

807-
ubifs_assert(inode_is_locked(dir));
808-
ubifs_assert(inode_is_locked(inode));
807+
ubifs_assert(c, inode_is_locked(dir));
808+
ubifs_assert(c, inode_is_locked(inode));
809809
err = dbg_check_synced_i_size(c, inode);
810810
if (err)
811811
goto out_fname;
@@ -896,8 +896,8 @@ static int ubifs_rmdir(struct inode *dir, struct dentry *dentry)
896896

897897
dbg_gen("directory '%pd', ino %lu in dir ino %lu", dentry,
898898
inode->i_ino, dir->i_ino);
899-
ubifs_assert(inode_is_locked(dir));
900-
ubifs_assert(inode_is_locked(inode));
899+
ubifs_assert(c, inode_is_locked(dir));
900+
ubifs_assert(c, inode_is_locked(inode));
901901
err = ubifs_check_dir_empty(d_inode(dentry));
902902
if (err)
903903
return err;
@@ -1295,7 +1295,7 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
12951295
new_dentry, new_dir->i_ino, flags);
12961296

12971297
if (unlink)
1298-
ubifs_assert(inode_is_locked(new_inode));
1298+
ubifs_assert(c, inode_is_locked(new_inode));
12991299

13001300
if (unlink && is_dir) {
13011301
err = ubifs_check_dir_empty(new_inode);
@@ -1349,7 +1349,7 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
13491349
whiteout_ui = ubifs_inode(whiteout);
13501350
whiteout_ui->data = dev;
13511351
whiteout_ui->data_len = ubifs_encode_dev(dev, MKDEV(0, 0));
1352-
ubifs_assert(!whiteout_ui->dirty);
1352+
ubifs_assert(c, !whiteout_ui->dirty);
13531353
}
13541354

13551355
lock_4_inodes(old_dir, new_dir, new_inode, whiteout);
@@ -1509,7 +1509,7 @@ static int ubifs_xrename(struct inode *old_dir, struct dentry *old_dentry,
15091509
int err;
15101510
struct fscrypt_name fst_nm, snd_nm;
15111511

1512-
ubifs_assert(fst_inode && snd_inode);
1512+
ubifs_assert(c, fst_inode && snd_inode);
15131513

15141514
err = fscrypt_setup_filename(old_dir, &old_dentry->d_name, 0, &fst_nm);
15151515
if (err)
@@ -1556,12 +1556,13 @@ static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry,
15561556
unsigned int flags)
15571557
{
15581558
int err;
1559+
struct ubifs_info *c = old_dir->i_sb->s_fs_info;
15591560

15601561
if (flags & ~(RENAME_NOREPLACE | RENAME_WHITEOUT | RENAME_EXCHANGE))
15611562
return -EINVAL;
15621563

1563-
ubifs_assert(inode_is_locked(old_dir));
1564-
ubifs_assert(inode_is_locked(new_dir));
1564+
ubifs_assert(c, inode_is_locked(old_dir));
1565+
ubifs_assert(c, inode_is_locked(new_dir));
15651566

15661567
err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry,
15671568
flags);

0 commit comments

Comments
 (0)