[Devel] [PATCH rh7 38/38] ploop: added printk of function, line, backtrace before ploop_set_error
Andrey Smetanin
asmetanin at virtuozzo.com
Fri May 15 09:48:39 PDT 2015
There are several bugs where we only see messages like:
"ploop_set_error=-7 on ploop28808". Sometimes such infomation
insufficient to find fastly why and where error in ploop happens.
This patch added extra printk of function, line and stack backtrace
in case of ploop request failure.
Signed-off-by: Andrey Smetanin <asmetanin at virtuozzo.com>
---
drivers/block/ploop/dev.c | 32 +++++++++++++++++++-------------
drivers/block/ploop/fmt_ploop1.c | 2 +-
drivers/block/ploop/io_direct.c | 20 ++++++++++----------
drivers/block/ploop/io_kaio.c | 16 ++++++++--------
drivers/block/ploop/map.c | 12 ++++++------
include/linux/ploop/ploop.h | 36 +++++++++++++++++++++++++++++++++++-
6 files changed, 79 insertions(+), 39 deletions(-)
diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index bd5fe37..f780618 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -1331,7 +1331,7 @@ void ploop_fail_request(struct ploop_request * preq, int err)
{
struct ploop_device * plo = preq->plo;
- ploop_set_error(preq, err);
+ ploop_req_set_error(preq, err);
spin_lock_irq(&plo->lock);
if (err == -ENOSPC) {
@@ -1351,13 +1351,19 @@ void ploop_fail_immediate(struct ploop_request * preq, int err)
{
struct ploop_device * plo = preq->plo;
- ploop_set_error(preq, err);
+ ploop_req_set_error(preq, err);
set_bit(PLOOP_S_ABORT, &plo->state);
preq->eng_state = PLOOP_E_COMPLETE;
ploop_complete_request(preq);
}
+#define PLOOP_REQ_FAIL_IMMEDIATE(preq, err) \
+ do { \
+ PLOOP_REQ_TRACE_ERROR(preq, err); \
+ ploop_fail_immediate(preq, err); \
+ } while (0);
+
void ploop_complete_io_state(struct ploop_request * preq)
{
struct ploop_device * plo = preq->plo;
@@ -1577,7 +1583,7 @@ ploop_reloc_sched_read(struct ploop_request *preq, iblock_t iblk)
if (!preq->aux_bio ||
fill_bio(plo, preq->aux_bio, preq->req_cluster)) {
- ploop_fail_immediate(preq, -ENOMEM);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, -ENOMEM);
return;
}
}
@@ -2064,7 +2070,7 @@ restart:
if (!preq->aux_bio ||
fill_bio(plo, preq->aux_bio, preq->req_cluster)) {
- ploop_fail_immediate(preq, -ENOMEM);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, -ENOMEM);
return;
}
@@ -2170,7 +2176,7 @@ delta_io:
if (!preq->aux_bio ||
fill_bio(plo, preq->aux_bio, preq->req_cluster)) {
- ploop_fail_immediate(preq, -ENOMEM);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, -ENOMEM);
return;
}
spin_lock_irq(&plo->lock);
@@ -2225,7 +2231,7 @@ delta_io:
return;
error:
- ploop_fail_immediate(preq, err);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, err);
}
static void ploop_req_state_process(struct ploop_request * preq)
@@ -2271,7 +2277,7 @@ restart:
if (preq->error ||
((preq->req_rw & REQ_WRITE) &&
test_bit(PLOOP_S_ABORT, &plo->state))) {
- ploop_fail_immediate(preq, preq->error ? : -EIO);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, preq->error ? : -EIO);
break;
}
@@ -2346,7 +2352,7 @@ restart:
*/
if (preq->error ||
test_bit(PLOOP_S_ABORT, &plo->state)) {
- ploop_fail_immediate(preq, preq->error ? : -EIO);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, preq->error ? : -EIO);
break;
}
@@ -2386,7 +2392,7 @@ restart:
if (!preq->aux_bio ||
fill_bio(plo, preq->aux_bio, preq->req_cluster)) {
- ploop_fail_immediate(preq, -ENOMEM);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, -ENOMEM);
break;
}
@@ -2425,7 +2431,7 @@ restart:
if (preq->error ||
test_bit(PLOOP_S_ABORT, &plo->state)) {
- ploop_fail_immediate(preq, preq->error ? : -EIO);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, preq->error ? : -EIO);
break;
}
@@ -2455,7 +2461,7 @@ restart:
{
if (preq->error ||
test_bit(PLOOP_S_ABORT, &plo->state)) {
- ploop_fail_immediate(preq, preq->error ? : -EIO);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, preq->error ? : -EIO);
break;
}
@@ -2484,7 +2490,7 @@ restart:
*/
if (preq->error ||
test_bit(PLOOP_S_ABORT, &plo->state)) {
- ploop_fail_immediate(preq, preq->error ? : -EIO);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, preq->error ? : -EIO);
break;
}
@@ -2522,7 +2528,7 @@ restart:
/* Data written. Index must be updated. */
if (preq->error ||
test_bit(PLOOP_S_ABORT, &plo->state)) {
- ploop_fail_immediate(preq, preq->error ? : -EIO);
+ PLOOP_REQ_FAIL_IMMEDIATE(preq, preq->error ? : -EIO);
break;
}
diff --git a/drivers/block/ploop/fmt_ploop1.c b/drivers/block/ploop/fmt_ploop1.c
index 585f6ce..e8d5a50 100644
--- a/drivers/block/ploop/fmt_ploop1.c
+++ b/drivers/block/ploop/fmt_ploop1.c
@@ -224,7 +224,7 @@ ploop1_allocate(struct ploop_delta * delta, struct ploop_request * preq,
{
if (delta->io.alloc_head >=
(delta->max_delta_size >> delta->cluster_log)) {
- ploop_fail_request(preq, -E2BIG);
+ PLOOP_FAIL_REQUEST(preq, -E2BIG);
return;
}
delta->io.ops->submit_alloc(&delta->io, preq, sbl, size);
diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
index 2c3581f..a3eb173 100644
--- a/drivers/block/ploop/io_direct.c
+++ b/drivers/block/ploop/io_direct.c
@@ -52,7 +52,7 @@ DEFINE_BIO_CB(dio_endio_async)
if (!err && !bio_flagged(bio, BIO_UPTODATE))
err = -EIO;
if (err)
- ploop_set_error(preq, err);
+ PLOOP_REQ_SET_ERROR(preq, err);
ploop_complete_io_request(preq);
@@ -288,7 +288,7 @@ out:
}
if (err)
- ploop_fail_request(preq, err);
+ PLOOP_FAIL_REQUEST(preq, err);
}
struct bio_iter {
@@ -638,7 +638,7 @@ out:
b->bi_next = NULL;
bio_put(b);
}
- ploop_fail_request(preq, err);
+ PLOOP_FAIL_REQUEST(preq, err);
}
static struct extent_map * dio_fallocate(struct ploop_io *io, u32 iblk, int nr)
@@ -666,7 +666,7 @@ dio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
trace_submit_alloc(preq);
if (!(io->files.file->f_mode & FMODE_WRITE)) {
- ploop_fail_request(preq, -EBADF);
+ PLOOP_FAIL_REQUEST(preq, -EBADF);
return;
}
@@ -690,7 +690,7 @@ dio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
em = dio_fallocate(io, iblk, 1);
if (unlikely(IS_ERR(em))) {
- ploop_fail_request(preq, PTR_ERR(em));
+ PLOOP_FAIL_REQUEST(preq, PTR_ERR(em));
return;
}
@@ -705,7 +705,7 @@ dio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
if (err) {
if (err == -ENOSPC)
io->alloc_head--;
- ploop_fail_request(preq, err);
+ PLOOP_FAIL_REQUEST(preq, err);
}
preq->eng_state = PLOOP_E_DATA_WBI;
}
@@ -778,7 +778,7 @@ static int dio_fsync_thread(void * data)
preq = list_entry(list.next, struct ploop_request, list);
list_del(&preq->list);
if (err)
- ploop_set_error(preq, err);
+ PLOOP_REQ_SET_ERROR(preq, err);
list_add_tail(&preq->list, &plo->ready_queue);
io->fsync_qlen--;
}
@@ -1457,7 +1457,7 @@ out:
b->bi_next = NULL;
bio_put(b);
}
- ploop_fail_request(preq, err);
+ PLOOP_FAIL_REQUEST(preq, err);
}
static void
@@ -1472,7 +1472,7 @@ dio_write_page(struct ploop_io * io, struct ploop_request * preq,
struct page * page, sector_t sec, int fua)
{
if (!(io->files.file->f_mode & FMODE_WRITE)) {
- ploop_fail_request(preq, -EBADF);
+ PLOOP_FAIL_REQUEST(preq, -EBADF);
return;
}
@@ -1768,7 +1768,7 @@ static void dio_issue_flush(struct ploop_io * io, struct ploop_request *preq)
bio = bio_alloc(GFP_NOFS, 0);
if (unlikely(!bio)) {
- ploop_fail_request(preq, -ENOMEM);
+ PLOOP_FAIL_REQUEST(preq, -ENOMEM);
return;
}
diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index 8f62f62..ccdf1f4 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -120,7 +120,7 @@ static void kaio_rw_aio_complete(u64 data, long res)
bio_list_for_each(b, &preq->bl)
printk(" bio=%p: bi_sector=%ld bi_size=%d\n",
b, b->bi_sector, b->bi_size);
- ploop_set_error(preq, res);
+ PLOOP_REQ_SET_ERROR(preq, res);
}
kaio_complete_io_request(preq);
@@ -280,7 +280,7 @@ static void kaio_sbl_submit(struct file *file, struct ploop_request *preq,
kreq = kaio_kreq_alloc(preq, &nr_segs);
if (!kreq) {
- ploop_set_error(preq, -ENOMEM);
+ PLOOP_REQ_SET_ERROR(preq, -ENOMEM);
break;
}
@@ -289,7 +289,7 @@ static void kaio_sbl_submit(struct file *file, struct ploop_request *preq,
atomic_inc(&preq->io_count);
err = kaio_kernel_submit(file, kreq, nr_segs, copy, off, rw);
if (err) {
- ploop_set_error(preq, err);
+ PLOOP_REQ_SET_ERROR(preq, err);
ploop_complete_io_request(preq);
kfree(kreq);
break;
@@ -405,7 +405,7 @@ static int kaio_fsync_thread(void * data)
err = kaio_truncate(io, io->files.file,
preq->prealloc_size >> (plo->cluster_log + 9));
if (err)
- ploop_set_error(preq, -EIO);
+ PLOOP_REQ_SET_ERROR(preq, -EIO);
} else {
struct file *file = io->files.file;
err = vfs_fsync(file, 1);
@@ -415,7 +415,7 @@ static int kaio_fsync_thread(void * data)
"on ploop%d)\n",
err, io->files.inode->i_ino,
io2level(io), plo->index);
- ploop_set_error(preq, -EIO);
+ PLOOP_REQ_SET_ERROR(preq, -EIO);
} else if (preq->req_rw & REQ_FLUSH) {
BUG_ON(!preq->req_size);
preq->req_rw &= ~REQ_FLUSH;
@@ -446,7 +446,7 @@ kaio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
loff_t clu_siz = 1 << log;
if (delta->flags & PLOOP_FMT_RDONLY) {
- ploop_fail_request(preq, -EBADF);
+ PLOOP_FAIL_REQUEST(preq, -EBADF);
return;
}
@@ -585,7 +585,7 @@ kaio_io_page(struct ploop_io * io, int op, struct ploop_request * preq,
iocb = aio_kernel_alloc(GFP_NOIO);
if (!iocb) {
- ploop_set_error(preq, -ENOMEM);
+ PLOOP_REQ_SET_ERROR(preq, -ENOMEM);
goto out;
}
@@ -601,7 +601,7 @@ kaio_io_page(struct ploop_io * io, int op, struct ploop_request * preq,
"err=%d (rw=%s; state=%ld/0x%lx; pos=%lld)\n",
err, (op == IOCB_CMD_WRITE_ITER) ? "WRITE" : "READ",
preq->eng_state, preq->state, pos);
- ploop_set_error(preq, err);
+ PLOOP_REQ_SET_ERROR(preq, err);
}
out:
diff --git a/drivers/block/ploop/map.c b/drivers/block/ploop/map.c
index 8ea67e9..3a6365d 100644
--- a/drivers/block/ploop/map.c
+++ b/drivers/block/ploop/map.c
@@ -528,7 +528,7 @@ int map_index_fault(struct ploop_request * preq)
err_out:
clear_bit(PLOOP_MAP_READ, &m->state);
- ploop_fail_request(preq, err);
+ PLOOP_FAIL_REQUEST(preq, err);
return 0;
}
@@ -922,7 +922,7 @@ void ploop_index_update(struct ploop_request * preq)
if (test_bit(PLOOP_REQ_ZERO, &preq->state) && !blk) {
printk("Either map_node is corrupted or bug in "
"ploop-balloon (%u)\n", preq->req_cluster);
- ploop_set_error(preq, -EIO);
+ PLOOP_REQ_SET_ERROR(preq, -EIO);
goto corrupted;
}
@@ -964,7 +964,7 @@ void ploop_index_update(struct ploop_request * preq)
return;
enomem:
- ploop_set_error(preq, -ENOMEM);
+ PLOOP_REQ_SET_ERROR(preq, -ENOMEM);
corrupted:
set_bit(PLOOP_S_ABORT, &plo->state);
out:
@@ -1117,7 +1117,7 @@ static void map_wb_complete(struct map_node * m, int err)
BUG_ON(MAP_LEVEL(m) != top_delta->level);
}
} else {
- ploop_set_error(preq, err);
+ PLOOP_REQ_SET_ERROR(preq, err);
}
put_page(preq->sinfo.wi.tpage);
preq->sinfo.wi.tpage = NULL;
@@ -1125,7 +1125,7 @@ static void map_wb_complete(struct map_node * m, int err)
break;
case PLOOP_E_INDEX_DELAY:
if (err) {
- ploop_set_error(preq, err);
+ PLOOP_REQ_SET_ERROR(preq, err);
preq->eng_state = PLOOP_E_COMPLETE;
spin_lock_irq(&plo->lock);
list_del(cursor);
@@ -1159,7 +1159,7 @@ static void map_wb_complete(struct map_node * m, int err)
switch (preq->eng_state) {
case PLOOP_E_INDEX_DELAY:
if (page == NULL) {
- ploop_set_error(preq, -ENOMEM);
+ PLOOP_REQ_SET_ERROR(preq, -ENOMEM);
preq->eng_state = PLOOP_E_COMPLETE;
spin_lock_irq(&plo->lock);
list_del(cursor);
diff --git a/include/linux/ploop/ploop.h b/include/linux/ploop/ploop.h
index 73280e0..b8c7130 100644
--- a/include/linux/ploop/ploop.h
+++ b/include/linux/ploop/ploop.h
@@ -597,7 +597,7 @@ static inline int ploop_req_delay_fua_possible(unsigned long rw,
return delay_fua;
}
-static inline void ploop_set_error(struct ploop_request * preq, int err)
+static inline void ploop_req_set_error(struct ploop_request * preq, int err)
{
if (!preq->error) {
preq->error = err;
@@ -614,6 +614,40 @@ static inline void ploop_set_error(struct ploop_request * preq, int err)
}
}
+#define PLOOP_TRACE_ERROR 1
+#define PLOOP_TRACE_ERROR_DUMP_STACK_ON 1
+
+#if PLOOP_TRACE_ERROR_DUMP_STACK_ON
+#define PLOOP_TRACE_ERROR_DUMP_STACK() dump_stack();
+#else
+#define PLOOP_TRACE_ERROR_DUMP_STACK()
+#endif
+
+#if PLOOP_TRACE_ERROR
+#define PLOOP_REQ_TRACE_ERROR(preq, err) \
+ do { \
+ if ((err)) { \
+ printk("%s() %d ploop%d set error %d\n", \
+ __FUNCTION__, __LINE__, (preq)->plo->index, (int)(err));\
+ PLOOP_TRACE_ERROR_DUMP_STACK(); \
+ } \
+ } while (0);
+#else
+#define PLOOP_REQ_TRACE_ERROR(preq, err)
+#endif
+
+#define PLOOP_REQ_SET_ERROR(preq, err) \
+ do { \
+ PLOOP_REQ_TRACE_ERROR(preq, err); \
+ ploop_req_set_error(preq, err); \
+ } while (0);
+
+#define PLOOP_FAIL_REQUEST(preq, err) \
+ do { \
+ PLOOP_REQ_TRACE_ERROR(preq, err); \
+ ploop_fail_request(preq, err); \
+ } while (0);
+
static inline void ploop_prepare_io_request(struct ploop_request * preq)
{
atomic_set(&preq->io_count, 1);
--
1.9.3
More information about the Devel
mailing list