The commit is pushed to "branch-rh9-5.14.0-70.22.1.vz9.17.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git after rh9-5.14.0-70.22.1.vz9.17.10 ------> commit c673a416f82f8e4fb8bd9e7defe9efe1ab2823ec Author: Alexander Atanasov <alexander.atana...@virtuozzo.com> Date: Mon Nov 14 21:04:28 2022 +0200
dm-qcow2: Add device name to log messages dm-qcow2 uses pr_info/pr_err for logging but it does not print which device the message is about. Add device name to log messages to make debugging easier. Messages are in the following format: dm-qcow2: dm-31337: log message here Where 31337 is the device minor number which corresponds to /dev/mapper/ploop31337 which is a symlink to /dev/dm-31337 - the printed device name. https://jira.sw.ru/browse/PSBM-142999 Signed-off-by: Alexander Atanasov <alexander.atana...@virtuozzo.com> Feature: dm-qcow2: block device over QCOW2 files driver --- drivers/md/dm-qcow2-cmd.c | 8 ++++---- drivers/md/dm-qcow2-map.c | 28 +++++++++++++++++----------- drivers/md/dm-qcow2-target.c | 15 ++++++++------- drivers/md/dm-qcow2.h | 14 ++++++++++++++ 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c index d510f8d06d24..6dc7e0722055 100644 --- a/drivers/md/dm-qcow2-cmd.c +++ b/drivers/md/dm-qcow2-cmd.c @@ -186,13 +186,13 @@ static int qcow2_merge_backward(struct qcow2_target *tgt) */ ret = qcow2_break_l1cow(tgt); if (ret) { - pr_err("dm-qcow2: Can't break L1 COW\n"); + QC_ERR(tgt->ti, "Can't break L1 COW"); goto out; } ret = qcow2_set_image_file_features(lower, true); if (ret) { - pr_err("dm-qcow2: Can't set dirty bit\n"); + QC_ERR(tgt->ti, "Can't set dirty bit"); goto out; } set_backward_merge_in_process(tgt, qcow2, true); @@ -203,7 +203,7 @@ static int qcow2_merge_backward(struct qcow2_target *tgt) set_backward_merge_in_process(tgt, qcow2, false); ret2 = qcow2_set_image_file_features(lower, false); if (ret2 < 0) - pr_err("dm-qcow2: Can't unuse lower (%d)\n", ret2); + QC_ERR(tgt->ti, "Can't unuse lower (%d)", ret2); goto out; } tgt->top = lower; @@ -214,7 +214,7 @@ static int qcow2_merge_backward(struct qcow2_target *tgt) ret2 = qcow2_set_image_file_features(qcow2, false); if (ret2 < 0) - pr_err("dm-qcow2: Can't unuse merged img (%d)\n", ret2); + QC_ERR(tgt->ti, "Can't unuse merged img (%d)", ret2); qcow2_destroy(qcow2); out: return ret; diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 28bd9a7c27d3..a779889c6970 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -1477,8 +1477,8 @@ static void submit_rw_md_page(unsigned int rw, struct qcow2 *qcow2, bi_op = (rw == READ ? REQ_OP_READ : REQ_OP_WRITE); if (pos > qcow2->file_size) { - pr_err_once("qcow2: rw=%x pos=%lld behind EOF %lld\n", - rw, pos, qcow2->file_size); + pr_err_once(QCOW2_FMT("rw=%x pos=%lld behind EOF %lld"), + qcow2_device_name(tgt->ti), rw, pos, qcow2->file_size); err = -EIO; } else { /* @@ -1926,6 +1926,7 @@ static int __handle_r1r2_maps(struct qcow2 *qcow2, loff_t pos, struct qio **qio, static int qcow2_handle_r1r2_maps(struct qcow2 *qcow2, loff_t pos, struct qio **qio, struct qcow2_map_item *r1, struct qcow2_map_item *r2, bool compressed) { + struct dm_target *ti = qcow2->tgt->ti; u64 entry; int ret; @@ -1937,7 +1938,7 @@ static int qcow2_handle_r1r2_maps(struct qcow2 *qcow2, loff_t pos, struct qio ** entry = get_r2_entry(qcow2, r2->md, r2->index_in_page); /* Sanity check */ if (unlikely(entry > 1)) { - pr_err("refblock=%llu, while no snapshots\n", entry); + QC_ERR(ti, "refblock=%llu, while no snapshots", entry); return -EIO; } } @@ -2021,6 +2022,7 @@ static int parse_metadata(struct qcow2 *qcow2, struct qio **qio, static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1, struct qcow2_map_item *r2, loff_t r2_pos, struct qio **qio) { + struct dm_target *ti = qcow2->tgt->ti; u64 page_id = r2_pos >> PAGE_SHIFT; int ret; @@ -2029,13 +2031,13 @@ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1, ret = qcow2_punch_hole(qcow2->file, r2_pos, qcow2->clu_size); if (ret) { - pr_err("qcow2: punch hole: %d\n", ret); + QC_ERR(ti, "punch hole: %d", ret); return ret; } ret = qcow2_alloc_and_insert_md_page(qcow2, page_id, &r2->md); if (ret < 0) { - pr_err("Can't alloc: ret=%d, page_id=%llu\n", ret, page_id); + QC_ERR(ti, "Can't alloc: ret=%d, page_id=%llu", ret, page_id); return ret; } @@ -2163,7 +2165,7 @@ static int truncate_prealloc_safe(struct qcow2 *qcow2, loff_t len, const char *f ret = qcow2_truncate_safe(file, new_len); if (ret) { - pr_err("qcow2: %s->truncate: %d\n", func, ret); + QC_ERR(qcow2->tgt->ti, "%s->truncate: %d", func, ret); return ret; } @@ -2229,7 +2231,8 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) old_clus = qcow2->hdr.refcount_table_clusters; clus = min_t(u32, old_clus + 1, REFCOUNT_TABLE_MAX_SIZE / clu_size); if (clus <= old_clus) { - pr_debug_ratelimited("qcow2: maximal refcount table size\n"); + pr_debug_ratelimited(QCOW2_FMT("maximal refcount table size"), + qcow2_device_name(qcow2->tgt->ti)); return -ENFILE; } @@ -2403,7 +2406,7 @@ static loff_t allocate_cluster(struct qcow2 *qcow2, struct qio *qio, off = min_t(loff_t, old_size, end); ret = qcow2_punch_hole(file, pos, off - pos); if (ret) { - pr_err("qcow2: punch hole: %d\n", ret); + QC_ERR(qcow2->tgt->ti, "punch hole: %d", ret); return ret; } } @@ -3565,7 +3568,8 @@ static int complete_metadata_writeback(struct qcow2 *qcow2) fsync_ret = vfs_fsync(qcow2->file, 0); /* FIXME: We should reread md page on error */ if (unlikely(fsync_ret)) - pr_err_ratelimited("qcow2: can't sync md: %d\n", fsync_ret); + pr_err_ratelimited(QCOW2_FMT("can't sync md: %d"), + qcow2_device_name(qcow2->tgt->ti), fsync_ret); while ((qio = qio_list_pop(&wb_list)) != NULL) { md = qio->ext->md; @@ -3909,6 +3913,7 @@ static void process_cow_indexes_write(struct qcow2 *qcow2, /* Finalize successful COW */ static void process_cow_end(struct qcow2 *qcow2, struct list_head *qio_list) { + struct dm_target *ti = qcow2->tgt->ti; u32 mask, clu_size = qcow2->clu_size; struct qcow2_map_item r1, r2; struct qio_ext *ext; @@ -3940,7 +3945,7 @@ next: qio = qio_list_pop(qio_list); if (ret == 0) /* We never shrink md pages, impossible */ goto next; if (WARN_ON_ONCE(ret < 0)) - pr_err("qcow2: clu at %lld leaked\n", pos); + QC_ERR(ti, "clu at %lld leaked", pos); else dec_cluster_usage(qcow2, r2.md, r2.index_in_page, pos); ext->cow_clu_pos += clu_size; @@ -4054,7 +4059,8 @@ static bool qcow2_try_delay_enospc(struct qcow2_target *tgt, struct qcow2_rq *qr init_qrq_and_embedded_qio(tgt, qrq->rq, qrq, qio); - pr_err_once("qcow2: underlying disk is almost full\n"); + pr_err_once(QCOW2_FMT("underlying disk is almost full"), + qcow2_device_name(tgt->ti)); tgt->event_enospc = true; list_add_tail(&qio->link, &tgt->enospc_qios); unlock: diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c index 11a21e8c788e..24ace08a03a0 100644 --- a/drivers/md/dm-qcow2-target.c +++ b/drivers/md/dm-qcow2-target.c @@ -189,7 +189,7 @@ void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2 md = rb_entry(node, struct md_page, node); /* FIXME: call md_make_dirty() and try once again? */ if (md->status & MD_WRITEBACK_ERROR) { - pr_err("qcow2: Failed to write dirty pages\n"); + QC_ERR(tgt->ti, "qcow2: Failed to write dirty pages"); tgt->md_writeback_error = true; break; } @@ -721,7 +721,7 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2, new_size = PAGE_ALIGN(qcow2->file_size); ret = qcow2_truncate_safe(file, new_size); if (ret) { - pr_err("qcow2: Can't truncate file\n"); + QC_ERR(ti, "qcow2: Can't truncate file"); return ret; } /* See md_page_read_complete() */ qcow2->file_size = new_size; @@ -794,7 +794,7 @@ static int qcow2_parse_metadata(struct dm_target *ti, struct qcow2_target *tgt) ret = 0; out: if (ret) - pr_err("dm-qcow2: Can't parse metadata\n"); + QC_ERR(ti, "dm-qcow2: Can't parse metadata"); return ret; } @@ -846,6 +846,7 @@ static int qcow2_ctr(struct dm_target *ti, unsigned int argc, char **argv) ti->num_flush_bios = 1; ti->discards_supported = true; ti->num_discard_bios = 1; + QC_INFO(ti, "created"); return 0; err: qcow2_tgt_destroy(tgt); @@ -874,7 +875,7 @@ static void qcow2_truncate_preallocations(struct dm_target *ti) ret = qcow2_truncate_safe(qcow2->file, end); if (ret) { - pr_err("dm-qcow2: Can't truncate preallocations\n"); + QC_ERR(ti, "dm-qcow2: Can't truncate preallocations"); tgt->truncate_error = true; return; } @@ -958,7 +959,7 @@ static void qcow2_postsuspend(struct dm_target *ti) if (dm_table_get_mode(ti->table) & FMODE_WRITE) { ret = qcow2_set_image_file_features(qcow2, false); if (ret) - pr_err("qcow2: Can't set features\n"); + QC_ERR(ti, "qcow2: Can't set features"); } } static int qcow2_preresume(struct dm_target *ti) @@ -967,7 +968,7 @@ static int qcow2_preresume(struct dm_target *ti) int ret = 0; if (qcow2_wants_check(tgt)) { - pr_err("qcow2: image check and target reload are required\n"); + QC_ERR(ti, "qcow2: image check and target reload are required"); return -EIO; } @@ -988,7 +989,7 @@ static int qcow2_preresume(struct dm_target *ti) if (dm_table_get_mode(ti->table) & FMODE_WRITE) { ret = qcow2_set_image_file_features(tgt->top, true); if (ret) - pr_err("qcow2: Can't set features\n"); + QC_ERR(ti, "qcow2: Can't set features"); } if (!ret) qcow2_set_wants_suspend(ti, false); diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h index ebe7048895ff..aec64c23dbae 100644 --- a/drivers/md/dm-qcow2.h +++ b/drivers/md/dm-qcow2.h @@ -5,6 +5,7 @@ #include <linux/percpu-refcount.h> #include <linux/device-mapper.h> #include <linux/fs.h> +#include "dm-core.h" #define DM_MSG_PREFIX "qcow2" @@ -201,6 +202,19 @@ struct qcow2 { struct work_struct fsync_worker; }; +static inline const char *qcow2_device_name(struct dm_target *ti) +{ + return ti ? ti->table->md->disk->disk_name : "-"; +} + +#define QCOW2_FMT(fmt) "dm-qcow2: %s: " fmt "\n" +#define QC_ERR(dmti, fmt, ...) pr_err (QCOW2_FMT(fmt), \ + qcow2_device_name(dmti), \ + ##__VA_ARGS__) +#define QC_INFO(dmti, fmt, ...) pr_info(QCOW2_FMT(fmt), \ + qcow2_device_name(dmti), \ + ##__VA_ARGS__) + /* * struct qio is embedded in every incoming bio, so we keep it * as small as possible. It is aimed to fit enough bytes only _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel