Commit c8566350 authored by Artem Bityutskiy's avatar Artem Bityutskiy

UBI: fix and re-work debugging stuff

Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent 85c6e6e2
...@@ -403,7 +403,7 @@ static int uif_init(struct ubi_device *ubi) ...@@ -403,7 +403,7 @@ static int uif_init(struct ubi_device *ubi)
ubi_assert(MINOR(dev) == 0); ubi_assert(MINOR(dev) == 0);
cdev_init(&ubi->cdev, &ubi_cdev_operations); cdev_init(&ubi->cdev, &ubi_cdev_operations);
dbg_msg("%s major is %u", ubi->ubi_name, MAJOR(dev)); dbg_gen("%s major is %u", ubi->ubi_name, MAJOR(dev));
ubi->cdev.owner = THIS_MODULE; ubi->cdev.owner = THIS_MODULE;
err = cdev_add(&ubi->cdev, dev, 1); err = cdev_add(&ubi->cdev, dev, 1);
......
...@@ -116,7 +116,7 @@ static int vol_cdev_open(struct inode *inode, struct file *file) ...@@ -116,7 +116,7 @@ static int vol_cdev_open(struct inode *inode, struct file *file)
else else
mode = UBI_READONLY; mode = UBI_READONLY;
dbg_msg("open volume %d, mode %d", vol_id, mode); dbg_gen("open volume %d, mode %d", vol_id, mode);
desc = ubi_open_volume(ubi_num, vol_id, mode); desc = ubi_open_volume(ubi_num, vol_id, mode);
unlock_kernel(); unlock_kernel();
...@@ -132,7 +132,7 @@ static int vol_cdev_release(struct inode *inode, struct file *file) ...@@ -132,7 +132,7 @@ static int vol_cdev_release(struct inode *inode, struct file *file)
struct ubi_volume_desc *desc = file->private_data; struct ubi_volume_desc *desc = file->private_data;
struct ubi_volume *vol = desc->vol; struct ubi_volume *vol = desc->vol;
dbg_msg("release volume %d, mode %d", vol->vol_id, desc->mode); dbg_gen("release volume %d, mode %d", vol->vol_id, desc->mode);
if (vol->updating) { if (vol->updating) {
ubi_warn("update of volume %d not finished, volume is damaged", ubi_warn("update of volume %d not finished, volume is damaged",
...@@ -141,7 +141,7 @@ static int vol_cdev_release(struct inode *inode, struct file *file) ...@@ -141,7 +141,7 @@ static int vol_cdev_release(struct inode *inode, struct file *file)
vol->updating = 0; vol->updating = 0;
vfree(vol->upd_buf); vfree(vol->upd_buf);
} else if (vol->changing_leb) { } else if (vol->changing_leb) {
dbg_msg("only %lld of %lld bytes received for atomic LEB change" dbg_gen("only %lld of %lld bytes received for atomic LEB change"
" for volume %d:%d, cancel", vol->upd_received, " for volume %d:%d, cancel", vol->upd_received,
vol->upd_bytes, vol->ubi->ubi_num, vol->vol_id); vol->upd_bytes, vol->ubi->ubi_num, vol->vol_id);
vol->changing_leb = 0; vol->changing_leb = 0;
...@@ -183,7 +183,7 @@ static loff_t vol_cdev_llseek(struct file *file, loff_t offset, int origin) ...@@ -183,7 +183,7 @@ static loff_t vol_cdev_llseek(struct file *file, loff_t offset, int origin)
return -EINVAL; return -EINVAL;
} }
dbg_msg("seek volume %d, offset %lld, origin %d, new offset %lld", dbg_gen("seek volume %d, offset %lld, origin %d, new offset %lld",
vol->vol_id, offset, origin, new_offset); vol->vol_id, offset, origin, new_offset);
file->f_pos = new_offset; file->f_pos = new_offset;
...@@ -201,7 +201,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count, ...@@ -201,7 +201,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
void *tbuf; void *tbuf;
uint64_t tmp; uint64_t tmp;
dbg_msg("read %zd bytes from offset %lld of volume %d", dbg_gen("read %zd bytes from offset %lld of volume %d",
count, *offp, vol->vol_id); count, *offp, vol->vol_id);
if (vol->updating) { if (vol->updating) {
...@@ -216,7 +216,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count, ...@@ -216,7 +216,7 @@ static ssize_t vol_cdev_read(struct file *file, __user char *buf, size_t count,
return 0; return 0;
if (vol->corrupted) if (vol->corrupted)
dbg_msg("read from corrupted volume %d", vol->vol_id); dbg_gen("read from corrupted volume %d", vol->vol_id);
if (*offp + count > vol->used_bytes) if (*offp + count > vol->used_bytes)
count_save = count = vol->used_bytes - *offp; count_save = count = vol->used_bytes - *offp;
...@@ -285,7 +285,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf, ...@@ -285,7 +285,7 @@ static ssize_t vol_cdev_direct_write(struct file *file, const char __user *buf,
char *tbuf; char *tbuf;
uint64_t tmp; uint64_t tmp;
dbg_msg("requested: write %zd bytes to offset %lld of volume %u", dbg_gen("requested: write %zd bytes to offset %lld of volume %u",
count, *offp, vol->vol_id); count, *offp, vol->vol_id);
if (vol->vol_type == UBI_STATIC_VOLUME) if (vol->vol_type == UBI_STATIC_VOLUME)
...@@ -514,7 +514,7 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file, ...@@ -514,7 +514,7 @@ static int vol_cdev_ioctl(struct inode *inode, struct file *file,
break; break;
} }
dbg_msg("erase LEB %d:%d", vol->vol_id, lnum); dbg_gen("erase LEB %d:%d", vol->vol_id, lnum);
err = ubi_eba_unmap_leb(ubi, vol, lnum); err = ubi_eba_unmap_leb(ubi, vol, lnum);
if (err) if (err)
break; break;
...@@ -626,7 +626,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file, ...@@ -626,7 +626,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
{ {
struct ubi_mkvol_req req; struct ubi_mkvol_req req;
dbg_msg("create volume"); dbg_gen("create volume");
err = copy_from_user(&req, argp, sizeof(struct ubi_mkvol_req)); err = copy_from_user(&req, argp, sizeof(struct ubi_mkvol_req));
if (err) { if (err) {
err = -EFAULT; err = -EFAULT;
...@@ -656,7 +656,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file, ...@@ -656,7 +656,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
{ {
int vol_id; int vol_id;
dbg_msg("remove volume"); dbg_gen("remove volume");
err = get_user(vol_id, (__user int32_t *)argp); err = get_user(vol_id, (__user int32_t *)argp);
if (err) { if (err) {
err = -EFAULT; err = -EFAULT;
...@@ -689,7 +689,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file, ...@@ -689,7 +689,7 @@ static int ubi_cdev_ioctl(struct inode *inode, struct file *file,
uint64_t tmp; uint64_t tmp;
struct ubi_rsvol_req req; struct ubi_rsvol_req req;
dbg_msg("re-size volume"); dbg_gen("re-size volume");
err = copy_from_user(&req, argp, sizeof(struct ubi_rsvol_req)); err = copy_from_user(&req, argp, sizeof(struct ubi_rsvol_req));
if (err) { if (err) {
err = -EFAULT; err = -EFAULT;
...@@ -742,7 +742,7 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file, ...@@ -742,7 +742,7 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
struct ubi_attach_req req; struct ubi_attach_req req;
struct mtd_info *mtd; struct mtd_info *mtd;
dbg_msg("attach MTD device"); dbg_gen("attach MTD device");
err = copy_from_user(&req, argp, sizeof(struct ubi_attach_req)); err = copy_from_user(&req, argp, sizeof(struct ubi_attach_req));
if (err) { if (err) {
err = -EFAULT; err = -EFAULT;
...@@ -782,7 +782,7 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file, ...@@ -782,7 +782,7 @@ static int ctrl_cdev_ioctl(struct inode *inode, struct file *file,
{ {
int ubi_num; int ubi_num;
dbg_msg("dettach MTD device"); dbg_gen("dettach MTD device");
err = get_user(ubi_num, (__user int32_t *)argp); err = get_user(ubi_num, (__user int32_t *)argp);
if (err) { if (err) {
err = -EFAULT; err = -EFAULT;
......
This diff is collapsed.
...@@ -24,21 +24,16 @@ ...@@ -24,21 +24,16 @@
#ifdef CONFIG_MTD_UBI_DEBUG #ifdef CONFIG_MTD_UBI_DEBUG
#include <linux/random.h> #include <linux/random.h>
#define ubi_assert(expr) BUG_ON(!(expr))
#define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__) #define dbg_err(fmt, ...) ubi_err(fmt, ##__VA_ARGS__)
#else
#define ubi_assert(expr) ({})
#define dbg_err(fmt, ...) ({})
#endif
#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT #define ubi_assert(expr) do { \
#define DBG_DISABLE_BGT 1 if (unlikely(!(expr))) { \
#else printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \
#define DBG_DISABLE_BGT 0 __func__, __LINE__, current->pid); \
#endif ubi_dbg_dump_stack(); \
} \
} while (0)
#ifdef CONFIG_MTD_UBI_DEBUG_MSG
/* Generic debugging message */
#define dbg_msg(fmt, ...) \ #define dbg_msg(fmt, ...) \
printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \ printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \
current->pid, __func__, ##__VA_ARGS__) current->pid, __func__, ##__VA_ARGS__)
...@@ -61,19 +56,12 @@ void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv); ...@@ -61,19 +56,12 @@ void ubi_dbg_dump_sv(const struct ubi_scan_volume *sv);
void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type);
void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
#ifdef CONFIG_MTD_UBI_DEBUG_MSG
/* General debugging messages */
#define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
#else #else
#define dbg_gen(fmt, ...) ({})
#define dbg_msg(fmt, ...) ({}) #endif
#define ubi_dbg_dump_stack() ({})
#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
#define ubi_dbg_dump_vol_info(vol) ({})
#define ubi_dbg_dump_vtbl_record(r, idx) ({})
#define ubi_dbg_dump_sv(sv) ({})
#define ubi_dbg_dump_seb(seb, type) ({})
#define ubi_dbg_dump_mkvol_req(req) ({})
#endif /* CONFIG_MTD_UBI_DEBUG_MSG */
#ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA #ifdef CONFIG_MTD_UBI_DEBUG_MSG_EBA
/* Messages from the eraseblock association sub-system */ /* Messages from the eraseblock association sub-system */
...@@ -105,6 +93,12 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); ...@@ -105,6 +93,12 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
#define UBI_IO_DEBUG 0 #define UBI_IO_DEBUG 0
#endif #endif
#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
#define DBG_DISABLE_BGT 1
#else
#define DBG_DISABLE_BGT 0
#endif
#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS #ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
/** /**
* ubi_dbg_is_bitflip - if it is time to emulate a bit-flip. * ubi_dbg_is_bitflip - if it is time to emulate a bit-flip.
...@@ -149,4 +143,30 @@ static inline int ubi_dbg_is_erase_failure(void) ...@@ -149,4 +143,30 @@ static inline int ubi_dbg_is_erase_failure(void)
#define ubi_dbg_is_erase_failure() 0 #define ubi_dbg_is_erase_failure() 0
#endif #endif
#else
#define ubi_assert(expr) ({})
#define dbg_err(fmt, ...) ({})
#define dbg_msg(fmt, ...) ({})
#define dbg_gen(fmt, ...) ({})
#define dbg_eba(fmt, ...) ({})
#define dbg_wl(fmt, ...) ({})
#define dbg_io(fmt, ...) ({})
#define dbg_bld(fmt, ...) ({})
#define ubi_dbg_dump_stack() ({})
#define ubi_dbg_dump_ec_hdr(ec_hdr) ({})
#define ubi_dbg_dump_vid_hdr(vid_hdr) ({})
#define ubi_dbg_dump_vol_info(vol) ({})
#define ubi_dbg_dump_vtbl_record(r, idx) ({})
#define ubi_dbg_dump_sv(sv) ({})
#define ubi_dbg_dump_seb(seb, type) ({})
#define ubi_dbg_dump_mkvol_req(req) ({})
#define UBI_IO_DEBUG 0
#define DBG_DISABLE_BGT 0
#define ubi_dbg_is_bitflip() 0
#define ubi_dbg_is_write_failure() 0
#define ubi_dbg_is_erase_failure() 0
#endif /* !CONFIG_MTD_UBI_DEBUG */
#endif /* !__UBI_DEBUG_H__ */ #endif /* !__UBI_DEBUG_H__ */
...@@ -111,7 +111,7 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len, ...@@ -111,7 +111,7 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len,
struct ubi_device *ubi; struct ubi_device *ubi;
uint64_t tmp = from; uint64_t tmp = from;
dbg_msg("read %zd bytes from offset %lld", len, from); dbg_gen("read %zd bytes from offset %lld", len, from);
if (len < 0 || from < 0 || from + len > mtd->size) if (len < 0 || from < 0 || from + len > mtd->size)
return -EINVAL; return -EINVAL;
...@@ -162,7 +162,7 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -162,7 +162,7 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len,
struct ubi_device *ubi; struct ubi_device *ubi;
uint64_t tmp = to; uint64_t tmp = to;
dbg_msg("write %zd bytes to offset %lld", len, to); dbg_gen("write %zd bytes to offset %lld", len, to);
if (len < 0 || to < 0 || len + to > mtd->size) if (len < 0 || to < 0 || len + to > mtd->size)
return -EINVAL; return -EINVAL;
...@@ -215,7 +215,7 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr) ...@@ -215,7 +215,7 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr)
struct ubi_volume *vol; struct ubi_volume *vol;
struct ubi_device *ubi; struct ubi_device *ubi;
dbg_msg("erase %u bytes at offset %u", instr->len, instr->addr); dbg_gen("erase %u bytes at offset %u", instr->len, instr->addr);
if (instr->addr < 0 || instr->addr > mtd->size - mtd->erasesize) if (instr->addr < 0 || instr->addr > mtd->size - mtd->erasesize)
return -EINVAL; return -EINVAL;
...@@ -304,7 +304,7 @@ int ubi_create_gluebi(struct ubi_device *ubi, struct ubi_volume *vol) ...@@ -304,7 +304,7 @@ int ubi_create_gluebi(struct ubi_device *ubi, struct ubi_volume *vol)
return -ENFILE; return -ENFILE;
} }
dbg_msg("added mtd%d (\"%s\"), size %u, EB size %u", dbg_gen("added mtd%d (\"%s\"), size %u, EB size %u",
mtd->index, mtd->name, mtd->size, mtd->erasesize); mtd->index, mtd->name, mtd->size, mtd->erasesize);
return 0; return 0;
} }
...@@ -322,7 +322,7 @@ int ubi_destroy_gluebi(struct ubi_volume *vol) ...@@ -322,7 +322,7 @@ int ubi_destroy_gluebi(struct ubi_volume *vol)
int err; int err;
struct mtd_info *mtd = &vol->gluebi_mtd; struct mtd_info *mtd = &vol->gluebi_mtd;
dbg_msg("remove mtd%d", mtd->index); dbg_gen("remove mtd%d", mtd->index);
err = del_mtd_device(mtd); err = del_mtd_device(mtd);
if (err) if (err)
return err; return err;
......
...@@ -187,7 +187,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset, ...@@ -187,7 +187,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
ubi_assert(len == read); ubi_assert(len == read);
if (ubi_dbg_is_bitflip()) { if (ubi_dbg_is_bitflip()) {
dbg_msg("bit-flip (emulated)"); dbg_gen("bit-flip (emulated)");
err = UBI_IO_BITFLIPS; err = UBI_IO_BITFLIPS;
} }
} }
...@@ -1256,7 +1256,7 @@ static int paranoid_check_all_ff(struct ubi_device *ubi, int pnum, int offset, ...@@ -1256,7 +1256,7 @@ static int paranoid_check_all_ff(struct ubi_device *ubi, int pnum, int offset,
fail: fail:
ubi_err("paranoid check failed for PEB %d", pnum); ubi_err("paranoid check failed for PEB %d", pnum);
dbg_msg("hex dump of the %d-%d region", offset, offset + len); ubi_msg("hex dump of the %d-%d region", offset, offset + len);
print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
ubi->dbg_peb_buf, len, 1); ubi->dbg_peb_buf, len, 1);
err = 1; err = 1;
......
...@@ -106,7 +106,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode) ...@@ -106,7 +106,7 @@ struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode)
struct ubi_device *ubi; struct ubi_device *ubi;
struct ubi_volume *vol; struct ubi_volume *vol;
dbg_msg("open device %d volume %d, mode %d", ubi_num, vol_id, mode); dbg_gen("open device %d volume %d, mode %d", ubi_num, vol_id, mode);
if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES) if (ubi_num < 0 || ubi_num >= UBI_MAX_DEVICES)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -215,7 +215,7 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name, ...@@ -215,7 +215,7 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
struct ubi_device *ubi; struct ubi_device *ubi;
struct ubi_volume_desc *ret; struct ubi_volume_desc *ret;
dbg_msg("open volume %s, mode %d", name, mode); dbg_gen("open volume %s, mode %d", name, mode);
if (!name) if (!name)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -266,7 +266,7 @@ void ubi_close_volume(struct ubi_volume_desc *desc) ...@@ -266,7 +266,7 @@ void ubi_close_volume(struct ubi_volume_desc *desc)
struct ubi_volume *vol = desc->vol; struct ubi_volume *vol = desc->vol;
struct ubi_device *ubi = vol->ubi; struct ubi_device *ubi = vol->ubi;
dbg_msg("close volume %d, mode %d", vol->vol_id, desc->mode); dbg_gen("close volume %d, mode %d", vol->vol_id, desc->mode);
spin_lock(&ubi->volumes_lock); spin_lock(&ubi->volumes_lock);
switch (desc->mode) { switch (desc->mode) {
...@@ -323,7 +323,7 @@ int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset, ...@@ -323,7 +323,7 @@ int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
struct ubi_device *ubi = vol->ubi; struct ubi_device *ubi = vol->ubi;
int err, vol_id = vol->vol_id; int err, vol_id = vol->vol_id;
dbg_msg("read %d bytes from LEB %d:%d:%d", len, vol_id, lnum, offset); dbg_gen("read %d bytes from LEB %d:%d:%d", len, vol_id, lnum, offset);
if (vol_id < 0 || vol_id >= ubi->vtbl_slots || lnum < 0 || if (vol_id < 0 || vol_id >= ubi->vtbl_slots || lnum < 0 ||
lnum >= vol->used_ebs || offset < 0 || len < 0 || lnum >= vol->used_ebs || offset < 0 || len < 0 ||
...@@ -388,7 +388,7 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf, ...@@ -388,7 +388,7 @@ int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
struct ubi_device *ubi = vol->ubi; struct ubi_device *ubi = vol->ubi;
int vol_id = vol->vol_id; int vol_id = vol->vol_id;
dbg_msg("write %d bytes to LEB %d:%d:%d", len, vol_id, lnum, offset); dbg_gen("write %d bytes to LEB %d:%d:%d", len, vol_id, lnum, offset);
if (vol_id < 0 || vol_id >= ubi->vtbl_slots) if (vol_id < 0 || vol_id >= ubi->vtbl_slots)
return -EINVAL; return -EINVAL;
...@@ -438,7 +438,7 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, ...@@ -438,7 +438,7 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
struct ubi_device *ubi = vol->ubi; struct ubi_device *ubi = vol->ubi;
int vol_id = vol->vol_id; int vol_id = vol->vol_id;
dbg_msg("atomically write %d bytes to LEB %d:%d", len, vol_id, lnum); dbg_gen("atomically write %d bytes to LEB %d:%d", len, vol_id, lnum);
if (vol_id < 0 || vol_id >= ubi->vtbl_slots) if (vol_id < 0 || vol_id >= ubi->vtbl_slots)
return -EINVAL; return -EINVAL;
...@@ -482,7 +482,7 @@ int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum) ...@@ -482,7 +482,7 @@ int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum)
struct ubi_device *ubi = vol->ubi; struct ubi_device *ubi = vol->ubi;
int err; int err;
dbg_msg("erase LEB %d:%d", vol->vol_id, lnum); dbg_gen("erase LEB %d:%d", vol->vol_id, lnum);
if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
return -EROFS; return -EROFS;
...@@ -542,7 +542,7 @@ int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum) ...@@ -542,7 +542,7 @@ int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum)
struct ubi_volume *vol = desc->vol; struct ubi_volume *vol = desc->vol;
struct ubi_device *ubi = vol->ubi; struct ubi_device *ubi = vol->ubi;
dbg_msg("unmap LEB %d:%d", vol->vol_id, lnum); dbg_gen("unmap LEB %d:%d", vol->vol_id, lnum);
if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
return -EROFS; return -EROFS;
...@@ -579,7 +579,7 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype) ...@@ -579,7 +579,7 @@ int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype)
struct ubi_volume *vol = desc->vol; struct ubi_volume *vol = desc->vol;
struct ubi_device *ubi = vol->ubi; struct ubi_device *ubi = vol->ubi;
dbg_msg("unmap LEB %d:%d", vol->vol_id, lnum); dbg_gen("unmap LEB %d:%d", vol->vol_id, lnum);
if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME)
return -EROFS; return -EROFS;
...@@ -621,7 +621,7 @@ int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum) ...@@ -621,7 +621,7 @@ int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum)
{ {
struct ubi_volume *vol = desc->vol; struct ubi_volume *vol = desc->vol;
dbg_msg("test LEB %d:%d", vol->vol_id, lnum); dbg_gen("test LEB %d:%d", vol->vol_id, lnum);
if (lnum < 0 || lnum >= vol->reserved_pebs) if (lnum < 0 || lnum >= vol->reserved_pebs)
return -EINVAL; return -EINVAL;
......
...@@ -932,7 +932,7 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) ...@@ -932,7 +932,7 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
for (pnum = 0; pnum < ubi->peb_count; pnum++) { for (pnum = 0; pnum < ubi->peb_count; pnum++) {
cond_resched(); cond_resched();
dbg_msg("process PEB %d", pnum); dbg_gen("process PEB %d", pnum);
err = process_eb(ubi, si, pnum); err = process_eb(ubi, si, pnum);
if (err < 0) if (err < 0)
goto out_vidh; goto out_vidh;
......
...@@ -56,11 +56,11 @@ static int set_update_marker(struct ubi_device *ubi, struct ubi_volume *vol) ...@@ -56,11 +56,11 @@ static int set_update_marker(struct ubi_device *ubi, struct ubi_volume *vol)
int err; int err;
struct ubi_vtbl_record vtbl_rec; struct ubi_vtbl_record vtbl_rec;
dbg_msg("set update marker for volume %d", vol->vol_id); dbg_gen("set update marker for volume %d", vol->vol_id);
if (vol->upd_marker) { if (vol->upd_marker) {
ubi_assert(ubi->vtbl[vol->vol_id].upd_marker); ubi_assert(ubi->vtbl[vol->vol_id].upd_marker);
dbg_msg("already set"); dbg_gen("already set");
return 0; return 0;
} }
...@@ -92,7 +92,7 @@ static int clear_update_marker(struct ubi_device *ubi, struct ubi_volume *vol, ...@@ -92,7 +92,7 @@ static int clear_update_marker(struct ubi_device *ubi, struct ubi_volume *vol,
uint64_t tmp; uint64_t tmp;
struct ubi_vtbl_record vtbl_rec; struct ubi_vtbl_record vtbl_rec;
dbg_msg("clear update marker for volume %d", vol->vol_id); dbg_gen("clear update marker for volume %d", vol->vol_id);
memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id], memcpy(&vtbl_rec, &ubi->vtbl[vol->vol_id],
sizeof(struct ubi_vtbl_record)); sizeof(struct ubi_vtbl_record));
...@@ -133,7 +133,7 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol, ...@@ -133,7 +133,7 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
int i, err; int i, err;
uint64_t tmp; uint64_t tmp;
dbg_msg("start update of volume %d, %llu bytes", vol->vol_id, bytes); dbg_gen("start update of volume %d, %llu bytes", vol->vol_id, bytes);
ubi_assert(!vol->updating && !vol->changing_leb); ubi_assert(!vol->updating && !vol->changing_leb);
vol->updating = 1; vol->updating = 1;
...@@ -183,7 +183,7 @@ int ubi_start_leb_change(struct ubi_device *ubi, struct ubi_volume *vol, ...@@ -183,7 +183,7 @@ int ubi_start_leb_change(struct ubi_device *ubi, struct ubi_volume *vol,
{ {
ubi_assert(!vol->updating && !vol->changing_leb); ubi_assert(!vol->updating && !vol->changing_leb);
dbg_msg("start changing LEB %d:%d, %u bytes", dbg_gen("start changing LEB %d:%d, %u bytes",
vol->vol_id, req->lnum, req->bytes); vol->vol_id, req->lnum, req->bytes);
if (req->bytes == 0) if (req->bytes == 0)
return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0, return ubi_eba_atomic_leb_change(ubi, vol, req->lnum, NULL, 0,
...@@ -242,7 +242,7 @@ static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum, ...@@ -242,7 +242,7 @@ static int write_leb(struct ubi_device *ubi, struct ubi_volume *vol, int lnum,
memset(buf + len, 0xFF, l - len); memset(buf + len, 0xFF, l - len);
len = ubi_calc_data_len(ubi, buf, l); len = ubi_calc_data_len(ubi, buf, l);
if (len == 0) { if (len == 0) {
dbg_msg("all %d bytes contain 0xFF - skip", len); dbg_gen("all %d bytes contain 0xFF - skip", len);
return 0; return 0;
} }
...@@ -283,7 +283,7 @@ int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol, ...@@ -283,7 +283,7 @@ int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol,
uint64_t tmp; uint64_t tmp;
int lnum, offs, err = 0, len, to_write = count; int lnum, offs, err = 0, len, to_write = count;
dbg_msg("write %d of %lld bytes, %lld already passed", dbg_gen("write %d of %lld bytes, %lld already passed",
count, vol->upd_bytes, vol->upd_received); count, vol->upd_bytes, vol->upd_received);
if (ubi->ro_mode) if (ubi->ro_mode)
...@@ -400,7 +400,7 @@ int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol, ...@@ -400,7 +400,7 @@ int ubi_more_leb_change_data(struct ubi_device *ubi, struct ubi_volume *vol,
{ {
int err; int err;
dbg_msg("write %d of %lld bytes, %lld already passed", dbg_gen("write %d of %lld bytes, %lld already passed",
count, vol->upd_bytes, vol->upd_received); count, vol->upd_bytes, vol->upd_received);
if (ubi->ro_mode) if (ubi->ro_mode)
......
...@@ -28,9 +28,9 @@ ...@@ -28,9 +28,9 @@
#include "ubi.h" #include "ubi.h"
#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
static void paranoid_check_volumes(struct ubi_device *ubi); static int paranoid_check_volumes(struct ubi_device *ubi);
#else #else
#define paranoid_check_volumes(ubi) #define paranoid_check_volumes(ubi) 0
#endif #endif
static ssize_t vol_attribute_show(struct device *dev, static ssize_t vol_attribute_show(struct device *dev,
...@@ -218,7 +218,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) ...@@ -218,7 +218,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
spin_lock(&ubi->volumes_lock); spin_lock(&ubi->volumes_lock);
if (vol_id == UBI_VOL_NUM_AUTO) { if (vol_id == UBI_VOL_NUM_AUTO) {
/* Find unused volume ID */ /* Find unused volume ID */
dbg_msg("search for vacant volume ID"); dbg_gen("search for vacant volume ID");
for (i = 0; i < ubi->vtbl_slots; i++) for (i = 0; i < ubi->vtbl_slots; i++)
if (!ubi->volumes[i]) { if (!ubi->volumes[i]) {
vol_id = i; vol_id = i;
...@@ -233,7 +233,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) ...@@ -233,7 +233,7 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
req->vol_id = vol_id; req->vol_id = vol_id;
} }
dbg_msg("volume ID %d, %llu bytes, type %d, name %s", dbg_gen("volume ID %d, %llu bytes, type %d, name %s",
vol_id, (unsigned long long)req->bytes, vol_id, (unsigned long long)req->bytes,
(int)req->vol_type, req->name); (int)req->vol_type, req->name);
...@@ -361,8 +361,8 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) ...@@ -361,8 +361,8 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
ubi->vol_count += 1; ubi->vol_count += 1;
spin_unlock(&ubi->volumes_lock); spin_unlock(&ubi->volumes_lock);
paranoid_check_volumes(ubi); err = paranoid_check_volumes(ubi);
return 0; return err;
out_sysfs: out_sysfs:
/* /*
...@@ -414,7 +414,7 @@ int ubi_remove_volume(struct ubi_volume_desc *desc) ...@@ -414,7 +414,7 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
struct ubi_device *ubi = vol->ubi; struct ubi_device *ubi = vol->ubi;
int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs; int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs;
dbg_msg("remove UBI volume %d", vol_id); dbg_gen("remove UBI volume %d", vol_id);
ubi_assert(desc->mode == UBI_EXCLUSIVE); ubi_assert(desc->mode == UBI_EXCLUSIVE);
ubi_assert(vol == ubi->volumes[vol_id]); ubi_assert(vol == ubi->volumes[vol_id]);
...@@ -465,8 +465,8 @@ int ubi_remove_volume(struct ubi_volume_desc *desc) ...@@ -465,8 +465,8 @@ int ubi_remove_volume(struct ubi_volume_desc *desc)
ubi->vol_count -= 1; ubi->vol_count -= 1;
spin_unlock(&ubi->volumes_lock); spin_unlock(&ubi->volumes_lock);
paranoid_check_volumes(ubi); err = paranoid_check_volumes(ubi);
return 0; return err;
out_err: out_err:
ubi_err("cannot remove volume %d, error %d", vol_id, err); ubi_err("cannot remove volume %d, error %d", vol_id, err);
...@@ -497,7 +497,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) ...@@ -497,7 +497,7 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
if (ubi->ro_mode) if (ubi->ro_mode)
return -EROFS; return -EROFS;
dbg_msg("re-size volume %d to from %d to %d PEBs", dbg_gen("re-size volume %d to from %d to %d PEBs",
vol_id, vol->reserved_pebs, reserved_pebs); vol_id, vol->reserved_pebs, reserved_pebs);
if (vol->vol_type == UBI_STATIC_VOLUME && if (vol->vol_type == UBI_STATIC_VOLUME &&
...@@ -586,8 +586,8 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) ...@@ -586,8 +586,8 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
(long long)vol->used_ebs * vol->usable_leb_size; (long long)vol->used_ebs * vol->usable_leb_size;
} }
paranoid_check_volumes(ubi); err = paranoid_check_volumes(ubi);
return 0; return err;
out_acc: out_acc:
if (pebs > 0) { if (pebs > 0) {
...@@ -615,8 +615,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) ...@@ -615,8 +615,7 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
int err, vol_id = vol->vol_id; int err, vol_id = vol->vol_id;
dev_t dev; dev_t dev;
dbg_msg("add volume %d", vol_id); dbg_gen("add volume %d", vol_id);
ubi_dbg_dump_vol_info(vol);
/* Register character device for the volume */ /* Register character device for the volume */
cdev_init(&vol->cdev, &ubi_vol_cdev_operations); cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
...@@ -650,8 +649,8 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) ...@@ -650,8 +649,8 @@ int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
return err; return err;
} }
paranoid_check_volumes(ubi); err = paranoid_check_volumes(ubi);
return 0; return err;
out_gluebi: out_gluebi:
err = ubi_destroy_gluebi(vol); err = ubi_destroy_gluebi(vol);
...@@ -672,7 +671,7 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) ...@@ -672,7 +671,7 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
{ {
int err; int err;
dbg_msg("free volume %d", vol->vol_id); dbg_gen("free volume %d", vol->vol_id);
ubi->volumes[vol->vol_id] = NULL; ubi->volumes[vol->vol_id] = NULL;
err = ubi_destroy_gluebi(vol); err = ubi_destroy_gluebi(vol);
...@@ -686,8 +685,10 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) ...@@ -686,8 +685,10 @@ void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
* paranoid_check_volume - check volume information. * paranoid_check_volume - check volume information.
* @ubi: UBI device description object * @ubi: UBI device description object
* @vol_id: volume ID * @vol_id: volume ID
*
* Returns zero if volume is all right and a a negative error code if not.
*/ */
static void paranoid_check_volume(struct ubi_device *ubi, int vol_id) static int paranoid_check_volume(struct ubi_device *ubi, int vol_id)
{ {
int idx = vol_id2idx(ubi, vol_id); int idx = vol_id2idx(ubi, vol_id);
int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker; int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker;
...@@ -705,16 +706,7 @@ static void paranoid_check_volume(struct ubi_device *ubi, int vol_id) ...@@ -705,16 +706,7 @@ static void paranoid_check_volume(struct ubi_device *ubi, int vol_id)
goto fail; goto fail;
} }
spin_unlock(&ubi->volumes_lock); spin_unlock(&ubi->volumes_lock);
return; return 0;
}
if (vol->exclusive) {
/*
* The volume may be being created at the moment, do not check
* it (e.g., it may be in the middle of ubi_create_volume().
*/
spin_unlock(&ubi->volumes_lock);
return;
} }
if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 ||
...@@ -830,25 +822,34 @@ static void paranoid_check_volume(struct ubi_device *ubi, int vol_id) ...@@ -830,25 +822,34 @@ static void paranoid_check_volume(struct ubi_device *ubi, int vol_id)
} }
spin_unlock(&ubi->volumes_lock); spin_unlock(&ubi->volumes_lock);
return; return 0;
fail: fail:
ubi_err("paranoid check failed for volume %d", vol_id); ubi_err("paranoid check failed for volume %d", vol_id);
ubi_dbg_dump_vol_info(vol); if (vol) {
ubi_dbg_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id); ubi_dbg_dump_vol_info(vol);
ubi_dbg_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id);
}
spin_unlock(&ubi->volumes_lock); spin_unlock(&ubi->volumes_lock);
BUG(); return -EINVAL;
} }
/** /**
* paranoid_check_volumes - check information about all volumes. * paranoid_check_volumes - check information about all volumes.
* @ubi: UBI device description object * @ubi: UBI device description object
*
* Returns zero if volumes are all right and a a negative error code if not.
*/ */
static void paranoid_check_volumes(struct ubi_device *ubi) static int paranoid_check_volumes(struct ubi_device *ubi)
{ {
int i; int i, err = 0;
for (i = 0; i < ubi->vtbl_slots; i++) for (i = 0; i < ubi->vtbl_slots; i++) {
paranoid_check_volume(ubi, i); err = paranoid_check_volume(ubi, i);
if (err)
break;
}
return err;
} }
#endif #endif
...@@ -371,7 +371,7 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, ...@@ -371,7 +371,7 @@ static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
* to LEB 0. * to LEB 0.
*/ */
dbg_msg("check layout volume"); dbg_gen("check layout volume");
/* Read both LEB 0 and LEB 1 into memory */ /* Read both LEB 0 and LEB 1 into memory */
ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) { ubi_rb_for_each_entry(rb, seb, &sv->root, u.rb) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment