[Devel] [PATCH RHEL9 COMMIT] dm-ploop: add device name to log messages

Konstantin Khorenko khorenko at virtuozzo.com
Thu Nov 3 16:54:09 MSK 2022


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.8
------>
commit ae859bc38d82584334eb46769f0862b67f4b31c6
Author: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
Date:   Tue Nov 1 13:33:03 2022 +0200

    dm-ploop: add device name to log messages
    
    ploop 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:
    
      ploop: dm-47274: log message here
    
    Where 47274 is the device minor number which corresponds
    to /dev/mapper/ploop47274 which is a symlink to /dev/dm-47274 - the
    printed device name.
    
    No functional changes, only log messages are reformatted with standard
    prefix including the device name.
    
    https://jira.sw.ru/browse/PSBM-142993
    Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
    
    Feature: dm-ploop: ploop target driver
---
 drivers/md/dm-ploop-bat.c    |  4 ++--
 drivers/md/dm-ploop-cmd.c    | 14 +++++++-------
 drivers/md/dm-ploop-map.c    | 16 +++++++++-------
 drivers/md/dm-ploop-target.c |  1 +
 drivers/md/dm-ploop.h        | 10 ++++++++++
 5 files changed, 29 insertions(+), 16 deletions(-)

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index 48bf525aa981..cbe48e376097 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -215,12 +215,12 @@ int ploop_setup_metadata(struct ploop *ploop, struct page *page)
 	/* Clusters from start of file to first data block */
 	offset_clusters = SEC_TO_CLU(ploop, le32_to_cpu(m_hdr->m_FirstBlockOffset));
 	if (bat_clusters != offset_clusters) {
-		pr_err("ploop: custom FirstBlockOffset\n");
+		PL_ERR("custom FirstBlockOffset");
 		goto out;
 	}
 	ret = -EBADSLT;
 	if (le64_to_cpu(m_hdr->m_SizeInSectors_v2) < ti->len) {
-		pr_err("ploop: Too short BAT\n");
+		PL_ERR("Too short BAT");
 		goto out;
 	}
 	kunmap(page);
diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index aa4374d8b94b..88519f590148 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -311,13 +311,13 @@ static int ploop_grow_relocate_cluster(struct ploop *ploop,
 	/* Read full clu sync */
 	ret = ploop_read_cluster_sync(ploop, pio, dst_clu);
 	if (ret < 0) {
-		pr_err("ploop: reloc: failed read: %d\n", ret);
+		PL_ERR("reloc: failed read: %d", ret);
 		goto out;
 	}
 
 	ret = ploop_prepare_reloc_index_wb(ploop, &md, clu, &new_dst);
 	if (ret < 0) {
-		pr_err("ploop: reloc: can't prepare it: %d\n", ret);
+		PL_ERR("reloc: can't prepare it: %d", ret);
 		goto out;
 	}
 	piwb = md->piwb;
@@ -325,7 +325,7 @@ static int ploop_grow_relocate_cluster(struct ploop *ploop,
 	/* Write clu to new destination */
 	ret = ploop_write_cluster_sync(ploop, pio, new_dst);
 	if (ret) {
-		pr_err("ploop: reloc: failed write: %d\n", ret);
+		PL_ERR("reloc: failed write: %d", ret);
 		ploop_break_bat_update(ploop, md);
 		goto out;
 	}
@@ -340,7 +340,7 @@ static int ploop_grow_relocate_cluster(struct ploop *ploop,
 
 	ret = blk_status_to_errno(bi_status);
 	if (ret) {
-		pr_err("ploop: reloc: failed md page write: %d\n", ret);
+		PL_ERR("reloc: failed md page write: %d", ret);
 		goto out;
 	}
 
@@ -360,7 +360,7 @@ static int ploop_grow_relocate_cluster(struct ploop *ploop,
 	/* Zero new BAT entries on disk. */
 	ret = ploop_write_zero_cluster_sync(ploop, pio, dst_clu);
 	if (ret)
-		pr_err("ploop: reloc: failed zero: %d\n", ret);
+		PL_ERR("reloc: failed zero: %d", ret);
 out:
 	return ret;
 }
@@ -413,7 +413,7 @@ static int ploop_grow_update_header(struct ploop *ploop,
 		hdr->m_FirstBlockOffset = offset;
 		kunmap_atomic(hdr);
 	} else {
-		pr_err("ploop: Failed to update hdr: %d\n", ret);
+		PL_ERR("Failed to update hdr: %d", ret);
 	}
 
 	return ret;
@@ -1047,7 +1047,7 @@ static int ploop_check_delta_before_flip(struct ploop *ploop, struct file *file)
 
 	ret = ploop_read_delta_metadata(ploop, file, &md_root, &nr_be);
 	if (ret) {
-		pr_err("Error reading metadata\n");
+		PL_ERR("Error reading metadata");
 		goto out;
 	}
 
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index e8288e522e28..bcbe3c644779 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -172,7 +172,8 @@ static bool ploop_try_delay_enospc(struct ploop_rq *prq, struct pio *pio)
 
 	ploop_init_prq_and_embedded_pio(ploop, prq->rq, prq, pio);
 
-	pr_err_once("ploop: underlying disk is almost full\n");
+	pr_err_once(PL_FMT("underlying disk is almost full"),
+		ploop_device_name(ploop));
 	ploop->event_enospc = true;
 	list_add_tail(&pio->list, &ploop->enospc_pios);
 unlock:
@@ -639,7 +640,8 @@ static void ploop_handle_discard_pio(struct ploop *ploop, struct pio *pio,
 
 	if (inflight_h) {
 		/* @pio will be requeued on inflight_h's pio end */
-		pr_err_once("ploop: delayed discard: device is used as raw?\n");
+		pr_err_once(PL_FMT("delayed discard: device is used as raw?"),
+			ploop_device_name(ploop));
 		return;
 	}
 
@@ -1012,13 +1014,13 @@ static int ploop_truncate_prealloc_safe(struct ploop *ploop,
 	else
 		ret = vfs_fallocate(file, 0, old_len, new_len - old_len);
 	if (ret) {
-		pr_err("ploop: %s->prealloc: %d\n", func, ret);
+		PL_ERR("%s->prealloc: %d", func, ret);
 		return ret;
 	}
 
 	ret = vfs_fsync(file, 0);
 	if (ret) {
-		pr_err("ploop: %s->fsync(): %d\n", func, ret);
+		PL_ERR("%s->fsync(): %d", func, ret);
 		return ret;
 	}
 
@@ -1051,7 +1053,7 @@ static int ploop_allocate_cluster(struct ploop *ploop, u32 *dst_clu)
 		else
 			ret = ploop_zero_range(file, pos, off - pos);
 		if (ret) {
-			pr_err("ploop: punch/zero area: %d\n", ret);
+			PL_ERR("punch/zero area: %d", ret);
 			return ret;
 		}
 	}
@@ -1068,7 +1070,7 @@ static int ploop_allocate_cluster(struct ploop *ploop, u32 *dst_clu)
 		 */
 		ret = vfs_fsync(file, 0);
 		if (ret) {
-			pr_err("ploop: fsync: %d\n", ret);
+			PL_ERR("fsync: %d", ret);
 			return ret;
 		}
 	}
@@ -1918,7 +1920,7 @@ int ploop_prepare_reloc_index_wb(struct ploop *ploop,
 
 	err = -EIO;
 	if ((md->status & (MD_DIRTY|MD_WRITEBACK))) {
-		pr_err("ploop: Unexpected md status: %x\n", md->status);
+		PL_ERR("Unexpected md status: %x", md->status);
 		goto out_error;
 	}
 	err = ploop_prepare_bat_update(ploop, md, type);
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 4f7dc36eee0c..673d8b955246 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -21,6 +21,7 @@
 #include <linux/uio.h>
 #include <linux/error-injection.h>
 #include "dm-ploop.h"
+#include "dm-core.h"
 
 #define DM_MSG_PREFIX "ploop"
 
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 5d953278a976..4a25d869dd26 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -10,6 +10,7 @@
 
 #include <linux/device-mapper.h>
 #include <linux/bio.h>
+#include "dm-core.h"
 
 #define PLOOP_MAP_OFFSET 16
 typedef u32 map_index_t;
@@ -541,6 +542,15 @@ static inline void ploop_free_pio(struct ploop *ploop, struct pio *pio)
 	mempool_free(pio, ploop->pio_pool);
 }
 
+static inline const char *ploop_device_name(struct ploop *ploop)
+{
+	return ploop->ti->table->md->disk->disk_name;
+}
+
+#define PL_FMT(fmt) "ploop: %s: " fmt "\n"
+#define PL_ERR(fmt, ...) pr_err(PL_FMT(fmt), ploop_device_name(ploop), ##__VA_ARGS__)
+#define PL_INFO(fmt, ...) pr_info(PL_FMT(fmt), ploop_device_name(ploop), ##__VA_ARGS__)
+
 extern void ploop_md_page_insert(struct ploop *ploop, struct md_page *md);
 extern void ploop_free_md_page(struct md_page *md);
 extern void ploop_free_md_pages_tree(struct rb_root *root);


More information about the Devel mailing list