Skip to content

Commit

Permalink
ubifs: Pass struct ubifs_info to ubifs_assert()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
richardweinberger committed Aug 14, 2018
1 parent 54169dd commit 6eb61d5
Show file tree
Hide file tree
Showing 31 changed files with 550 additions and 521 deletions.
68 changes: 34 additions & 34 deletions fs/ubifs/budget.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,16 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
{
int err, idx_growth, data_growth, dd_growth, retried = 0;

ubifs_assert(req->new_page <= 1);
ubifs_assert(req->dirtied_page <= 1);
ubifs_assert(req->new_dent <= 1);
ubifs_assert(req->mod_dent <= 1);
ubifs_assert(req->new_ino <= 1);
ubifs_assert(req->new_ino_d <= UBIFS_MAX_INO_DATA);
ubifs_assert(req->dirtied_ino <= 4);
ubifs_assert(req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
ubifs_assert(!(req->new_ino_d & 7));
ubifs_assert(!(req->dirtied_ino_d & 7));
ubifs_assert(c, req->new_page <= 1);
ubifs_assert(c, req->dirtied_page <= 1);
ubifs_assert(c, req->new_dent <= 1);
ubifs_assert(c, req->mod_dent <= 1);
ubifs_assert(c, req->new_ino <= 1);
ubifs_assert(c, req->new_ino_d <= UBIFS_MAX_INO_DATA);
ubifs_assert(c, req->dirtied_ino <= 4);
ubifs_assert(c, req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
ubifs_assert(c, !(req->new_ino_d & 7));
ubifs_assert(c, !(req->dirtied_ino_d & 7));

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

again:
spin_lock(&c->space_lock);
ubifs_assert(c->bi.idx_growth >= 0);
ubifs_assert(c->bi.data_growth >= 0);
ubifs_assert(c->bi.dd_growth >= 0);
ubifs_assert(c, c->bi.idx_growth >= 0);
ubifs_assert(c, c->bi.data_growth >= 0);
ubifs_assert(c, c->bi.dd_growth >= 0);

if (unlikely(c->bi.nospace) && (c->bi.nospace_rp || !can_use_rp(c))) {
dbg_budg("no space");
Expand Down Expand Up @@ -526,20 +526,20 @@ int ubifs_budget_space(struct ubifs_info *c, struct ubifs_budget_req *req)
*/
void ubifs_release_budget(struct ubifs_info *c, struct ubifs_budget_req *req)
{
ubifs_assert(req->new_page <= 1);
ubifs_assert(req->dirtied_page <= 1);
ubifs_assert(req->new_dent <= 1);
ubifs_assert(req->mod_dent <= 1);
ubifs_assert(req->new_ino <= 1);
ubifs_assert(req->new_ino_d <= UBIFS_MAX_INO_DATA);
ubifs_assert(req->dirtied_ino <= 4);
ubifs_assert(req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
ubifs_assert(!(req->new_ino_d & 7));
ubifs_assert(!(req->dirtied_ino_d & 7));
ubifs_assert(c, req->new_page <= 1);
ubifs_assert(c, req->dirtied_page <= 1);
ubifs_assert(c, req->new_dent <= 1);
ubifs_assert(c, req->mod_dent <= 1);
ubifs_assert(c, req->new_ino <= 1);
ubifs_assert(c, req->new_ino_d <= UBIFS_MAX_INO_DATA);
ubifs_assert(c, req->dirtied_ino <= 4);
ubifs_assert(c, req->dirtied_ino_d <= UBIFS_MAX_INO_DATA * 4);
ubifs_assert(c, !(req->new_ino_d & 7));
ubifs_assert(c, !(req->dirtied_ino_d & 7));
if (!req->recalculate) {
ubifs_assert(req->idx_growth >= 0);
ubifs_assert(req->data_growth >= 0);
ubifs_assert(req->dd_growth >= 0);
ubifs_assert(c, req->idx_growth >= 0);
ubifs_assert(c, req->data_growth >= 0);
ubifs_assert(c, req->dd_growth >= 0);
}

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

ubifs_assert(c->bi.idx_growth >= 0);
ubifs_assert(c->bi.data_growth >= 0);
ubifs_assert(c->bi.dd_growth >= 0);
ubifs_assert(c->bi.min_idx_lebs < c->main_lebs);
ubifs_assert(!(c->bi.idx_growth & 7));
ubifs_assert(!(c->bi.data_growth & 7));
ubifs_assert(!(c->bi.dd_growth & 7));
ubifs_assert(c, c->bi.idx_growth >= 0);
ubifs_assert(c, c->bi.data_growth >= 0);
ubifs_assert(c, c->bi.dd_growth >= 0);
ubifs_assert(c, c->bi.min_idx_lebs < c->main_lebs);
ubifs_assert(c, !(c->bi.idx_growth & 7));
ubifs_assert(c, !(c->bi.data_growth & 7));
ubifs_assert(c, !(c->bi.dd_growth & 7));
spin_unlock(&c->space_lock);
}

Expand Down Expand Up @@ -680,7 +680,7 @@ long long ubifs_get_free_space_nolock(struct ubifs_info *c)
int rsvd_idx_lebs, lebs;
long long available, outstanding, free;

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

Expand Down
8 changes: 4 additions & 4 deletions fs/ubifs/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ static int nothing_to_commit(struct ubifs_info *c)
if (c->nroot && test_bit(DIRTY_CNODE, &c->nroot->flags))
return 0;

ubifs_assert(atomic_long_read(&c->dirty_zn_cnt) == 0);
ubifs_assert(c->dirty_pn_cnt == 0);
ubifs_assert(c->dirty_nn_cnt == 0);
ubifs_assert(c, atomic_long_read(&c->dirty_zn_cnt) == 0);
ubifs_assert(c, c->dirty_pn_cnt == 0);
ubifs_assert(c, c->dirty_nn_cnt == 0);

return 1;
}
Expand All @@ -113,7 +113,7 @@ static int do_commit(struct ubifs_info *c)
struct ubifs_lp_stats lst;

dbg_cmt("start");
ubifs_assert(!c->ro_media && !c->ro_mount);
ubifs_assert(c, !c->ro_media && !c->ro_mount);

if (c->ro_error) {
err = -EROFS;
Expand Down
4 changes: 2 additions & 2 deletions fs/ubifs/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int ubifs_encrypt(const struct inode *inode, struct ubifs_data_node *dn,
struct page *ret;
unsigned int pad_len = round_up(in_len, UBIFS_CIPHER_BLOCK_SIZE);

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

/* pad to full block cipher length */
Expand Down Expand Up @@ -63,7 +63,7 @@ int ubifs_decrypt(const struct inode *inode, struct ubifs_data_node *dn,
return -EINVAL;
}

ubifs_assert(dlen <= UBIFS_BLOCK_SIZE);
ubifs_assert(c, dlen <= UBIFS_BLOCK_SIZE);
err = fscrypt_decrypt_page(inode, virt_to_page(&dn->data), dlen,
offset_in_page(&dn->data), block);
if (err) {
Expand Down
20 changes: 10 additions & 10 deletions fs/ubifs/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const char *dbg_snprintf_key(const struct ubifs_info *c,
}
} else
len -= snprintf(p, len, "bad key format %d", c->key_fmt);
ubifs_assert(len > 0);
ubifs_assert(c, len > 0);
return p;
}

Expand Down Expand Up @@ -276,7 +276,7 @@ void ubifs_dump_inode(struct ubifs_info *c, const struct inode *inode)
return;

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

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

pr_err("\n");
pr_err("(pid %d) start dumping TNC tree\n", current->pid);
znode = ubifs_tnc_levelorder_next(c->zroot.znode, NULL);
znode = ubifs_tnc_levelorder_next(c, c->zroot.znode, NULL);
level = znode->level;
pr_err("== Level %d ==\n", level);
while (znode) {
Expand All @@ -940,7 +940,7 @@ void ubifs_dump_tnc(struct ubifs_info *c)
pr_err("== Level %d ==\n", level);
}
ubifs_dump_znode(c, znode);
znode = ubifs_tnc_levelorder_next(c->zroot.znode, znode);
znode = ubifs_tnc_levelorder_next(c, c->zroot.znode, znode);
}
pr_err("(pid %d) finish dumping TNC tree\n", current->pid);
}
Expand Down Expand Up @@ -1183,7 +1183,7 @@ static int dbg_check_key_order(struct ubifs_info *c, struct ubifs_zbranch *zbr1,
union ubifs_key key;
char key_buf[DBG_KEY_BUF_LEN];

ubifs_assert(!keys_cmp(c, &zbr1->key, &zbr2->key));
ubifs_assert(c, !keys_cmp(c, &zbr1->key, &zbr2->key));
dent1 = kmalloc(UBIFS_MAX_DENT_NODE_SZ, GFP_NOFS);
if (!dent1)
return -ENOMEM;
Expand Down Expand Up @@ -1479,7 +1479,7 @@ int dbg_check_tnc(struct ubifs_info *c, int extra)
if (!dbg_is_chk_index(c))
return 0;

ubifs_assert(mutex_is_locked(&c->tnc_mutex));
ubifs_assert(c, mutex_is_locked(&c->tnc_mutex));
if (!c->zroot.znode)
return 0;

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

prev = znode;
znode = ubifs_tnc_postorder_next(znode);
znode = ubifs_tnc_postorder_next(c, znode);
if (!znode)
break;

Expand Down Expand Up @@ -2036,7 +2036,7 @@ static int check_leaf(struct ubifs_info *c, struct ubifs_zbranch *zbr,
long long blk_offs;
struct ubifs_data_node *dn = node;

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

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

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

err = ubifs_validate_entry(c, dent);
if (err)
Expand Down Expand Up @@ -2461,7 +2461,7 @@ static int power_cut_emulated(struct ubifs_info *c, int lnum, int write)
{
struct ubifs_debug_info *d = c->dbg;

ubifs_assert(dbg_is_tst_rcvry(c));
ubifs_assert(c, dbg_is_tst_rcvry(c));

if (!d->pc_cnt) {
/* First call - decide delay to the power cut */
Expand Down
4 changes: 2 additions & 2 deletions fs/ubifs/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ struct ubifs_global_debug_info {
unsigned int tst_rcvry:1;
};

#define ubifs_assert(expr) do { \
#define ubifs_assert(c, expr) do { \
if (unlikely(!(expr))) { \
pr_crit("UBIFS assert failed in %s at %u (pid %d)\n", \
__func__, __LINE__, current->pid); \
Expand All @@ -160,7 +160,7 @@ struct ubifs_global_debug_info {
if (unlikely(down_write_trylock(&(c)->commit_sem))) { \
up_write(&(c)->commit_sem); \
pr_crit("commit lock is not locked!\n"); \
ubifs_assert(0); \
ubifs_assert(c, 0); \
} \
} while (0)

Expand Down
35 changes: 18 additions & 17 deletions fs/ubifs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
}

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

if (whiteout) {
init_special_inode(inode, inode->i_mode, WHITEOUT_DEV);
ubifs_assert(inode->i_op == &ubifs_file_inode_operations);
ubifs_assert(c, inode->i_op == &ubifs_file_inode_operations);
}

err = ubifs_init_security(dir, inode, &dentry->d_name);
Expand All @@ -421,7 +421,7 @@ static int do_tmpfile(struct inode *dir, struct dentry *dentry,
} else {
d_tmpfile(dentry, inode);
}
ubifs_assert(ui->dirty);
ubifs_assert(c, ui->dirty);

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

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

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

err = fscrypt_prepare_link(old_dentry, dir, dentry);
if (err)
Expand Down Expand Up @@ -804,8 +804,8 @@ static int ubifs_unlink(struct inode *dir, struct dentry *dentry)

sz_change = CALC_DENT_SIZE(fname_len(&nm));

ubifs_assert(inode_is_locked(dir));
ubifs_assert(inode_is_locked(inode));
ubifs_assert(c, inode_is_locked(dir));
ubifs_assert(c, inode_is_locked(inode));
err = dbg_check_synced_i_size(c, inode);
if (err)
goto out_fname;
Expand Down Expand Up @@ -896,8 +896,8 @@ static int ubifs_rmdir(struct inode *dir, struct dentry *dentry)

dbg_gen("directory '%pd', ino %lu in dir ino %lu", dentry,
inode->i_ino, dir->i_ino);
ubifs_assert(inode_is_locked(dir));
ubifs_assert(inode_is_locked(inode));
ubifs_assert(c, inode_is_locked(dir));
ubifs_assert(c, inode_is_locked(inode));
err = ubifs_check_dir_empty(d_inode(dentry));
if (err)
return err;
Expand Down Expand Up @@ -1295,7 +1295,7 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
new_dentry, new_dir->i_ino, flags);

if (unlink)
ubifs_assert(inode_is_locked(new_inode));
ubifs_assert(c, inode_is_locked(new_inode));

if (unlink && is_dir) {
err = ubifs_check_dir_empty(new_inode);
Expand Down Expand Up @@ -1349,7 +1349,7 @@ static int do_rename(struct inode *old_dir, struct dentry *old_dentry,
whiteout_ui = ubifs_inode(whiteout);
whiteout_ui->data = dev;
whiteout_ui->data_len = ubifs_encode_dev(dev, MKDEV(0, 0));
ubifs_assert(!whiteout_ui->dirty);
ubifs_assert(c, !whiteout_ui->dirty);
}

lock_4_inodes(old_dir, new_dir, new_inode, whiteout);
Expand Down Expand Up @@ -1509,7 +1509,7 @@ static int ubifs_xrename(struct inode *old_dir, struct dentry *old_dentry,
int err;
struct fscrypt_name fst_nm, snd_nm;

ubifs_assert(fst_inode && snd_inode);
ubifs_assert(c, fst_inode && snd_inode);

err = fscrypt_setup_filename(old_dir, &old_dentry->d_name, 0, &fst_nm);
if (err)
Expand Down Expand Up @@ -1556,12 +1556,13 @@ static int ubifs_rename(struct inode *old_dir, struct dentry *old_dentry,
unsigned int flags)
{
int err;
struct ubifs_info *c = old_dir->i_sb->s_fs_info;

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

ubifs_assert(inode_is_locked(old_dir));
ubifs_assert(inode_is_locked(new_dir));
ubifs_assert(c, inode_is_locked(old_dir));
ubifs_assert(c, inode_is_locked(new_dir));

err = fscrypt_prepare_rename(old_dir, old_dentry, new_dir, new_dentry,
flags);
Expand Down
Loading

0 comments on commit 6eb61d5

Please sign in to comment.