Skip to contentSkip to conversation

dm dust: report some message results back to user directly

PATCH In review Bryan Gurney 3 participants 4 messages Jun 19, 2020 – Jun 28, 2020 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/4 dm dust: report some message results back to user directly

From: yangerkun <[email protected]>

From: yangerkun <[email protected]>

Some type of message(queryblock/countbadblocks/removebadblock) may better report results to user directly. Do it with DMEMIT.

[Bryan: maintain __func__ output in DMEMIT messages]

---
 drivers/md/dm-dust.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
drivers/md/dm-dust.c +18 -13
index ff03b90072c5..f1f2dd6a4e84 100644
@@ -138,20 +138,22 @@ static int dust_add_block(struct dust_device *dd, unsigned long long block,
 	return 0;
 }
 
-static int dust_query_block(struct dust_device *dd, unsigned long long block)
+static int dust_query_block(struct dust_device *dd, unsigned long long block, char *result,
+			    unsigned int maxlen, unsigned int *sz_ptr)
 {
 	struct badblock *bblock;
 	unsigned long flags;
+	unsigned int sz = *sz_ptr;
 
 	spin_lock_irqsave(&dd->dust_lock, flags);
 	bblock = dust_rb_search(&dd->badblocklist, block);
 	if (bblock != NULL)
-		DMINFO("%s: block %llu found in badblocklist", __func__, block);
+		DMEMIT("%s: block %llu found in badblocklist", __func__, block);
 	else
-		DMINFO("%s: block %llu not found in badblocklist", __func__, block);
+		DMEMIT("%s: block %llu not found in badblocklist", __func__, block);
 	spin_unlock_irqrestore(&dd->dust_lock, flags);
 
-	return 0;
+	return 1;
 }
 
 static int __dust_map_read(struct dust_device *dd, sector_t thisblock)
@@ -259,11 +261,13 @@ static bool __dust_clear_badblocks(struct rb_root *tree,
 	return true;
 }
 
-static int dust_clear_badblocks(struct dust_device *dd)
+static int dust_clear_badblocks(struct dust_device *dd, char *result, unsigned int maxlen,
+				unsigned int *sz_ptr)
 {
 	unsigned long flags;
 	struct rb_root badblocklist;
 	unsigned long long badblock_count;
+	unsigned int sz = *sz_ptr;
 
 	spin_lock_irqsave(&dd->dust_lock, flags);
 	badblocklist = dd->badblocklist;
@@ -273,11 +277,11 @@ static int dust_clear_badblocks(struct dust_device *dd)
 	spin_unlock_irqrestore(&dd->dust_lock, flags);
 
 	if (!__dust_clear_badblocks(&badblocklist, badblock_count))
-		DMINFO("%s: no badblocks found", __func__);
+		DMEMIT("%s: no badblocks found", __func__);
 	else
-		DMINFO("%s: badblocks cleared", __func__);
+		DMEMIT("%s: badblocks cleared", __func__);
 
-	return 0;
+	return 1;
 }
 
 /*
@@ -383,7 +387,7 @@ static void dust_dtr(struct dm_target *ti)
 }
 
 static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
-			char *result_buf, unsigned int maxlen)
+			char *result, unsigned int maxlen)
 {
 	struct dust_device *dd = ti->private;
 	sector_t size = i_size_read(dd->dev->bdev->bd_inode) >> SECTOR_SHIFT;
@@ -393,6 +397,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
 	unsigned char wr_fail_cnt;
 	unsigned int tmp_ui;
 	unsigned long flags;
+	unsigned int sz = 0;
 	char dummy;
 
 	if (argc == 1) {
@@ -410,12 +415,12 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
 			r = 0;
 		} else if (!strcasecmp(argv[0], "countbadblocks")) {
 			spin_lock_irqsave(&dd->dust_lock, flags);
-			DMINFO("countbadblocks: %llu badblock(s) found",
+			DMEMIT("countbadblocks: %llu badblock(s) found",
 			       dd->badblock_count);
 			spin_unlock_irqrestore(&dd->dust_lock, flags);
-			r = 0;
+			r = 1;
 		} else if (!strcasecmp(argv[0], "clearbadblocks")) {
-			r = dust_clear_badblocks(dd);
+			r = dust_clear_badblocks(dd, result, maxlen, &sz);
 		} else if (!strcasecmp(argv[0], "quiet")) {
 			if (!dd->quiet_mode)
 				dd->quiet_mode = true;
@@ -441,7 +446,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
 		else if (!strcasecmp(argv[0], "removebadblock"))
 			r = dust_remove_block(dd, block);
 		else if (!strcasecmp(argv[0], "queryblock"))
-			r = dust_query_block(dd, block);
+			r = dust_query_block(dd, block, result, maxlen, &sz);
 		else
 			invalid_msg = true;
 
Signature · 1 line
2.25.4
#1 lore raw

Hi,

Thanks a lot for your fix and this patchset! It looks better than before!

Thanks,
Kun.

Quoted 111 lines · Bryan Gurney

From: yangerkun <[email protected]>

From: yangerkun <[email protected]>

Some type of message(queryblock/countbadblocks/removebadblock) may better report results to user directly. Do it with DMEMIT.

[Bryan: maintain __func__ output in DMEMIT messages]

---
  drivers/md/dm-dust.c | 31 ++++++++++++++++++-------------
  1 file changed, 18 insertions(+), 13 deletions(-)
drivers/md/dm-dust.c +17 -12
index ff03b90072c5..f1f2dd6a4e84 100644
@@ -138,20 +138,22 @@ static int dust_add_block(struct dust_device *dd, unsigned long long block,
  	return 0;
  }
 
-static int dust_query_block(struct dust_device *dd, unsigned long long block)
+static int dust_query_block(struct dust_device *dd, unsigned long long block, char *result,
+			    unsigned int maxlen, unsigned int *sz_ptr)
  {
  	struct badblock *bblock;
  	unsigned long flags;
+	unsigned int sz = *sz_ptr;
 
  	spin_lock_irqsave(&dd->dust_lock, flags);
  	bblock = dust_rb_search(&dd->badblocklist, block);
  	if (bblock != NULL)
-		DMINFO("%s: block %llu found in badblocklist", __func__, block);
+		DMEMIT("%s: block %llu found in badblocklist", __func__, block);
  	else
-		DMINFO("%s: block %llu not found in badblocklist", __func__, block);
+		DMEMIT("%s: block %llu not found in badblocklist", __func__, block);
  	spin_unlock_irqrestore(&dd->dust_lock, flags);
 
-	return 0;
+	return 1;
  }
 
  static int __dust_map_read(struct dust_device *dd, sector_t thisblock)
@@ -259,11 +261,13 @@ static bool __dust_clear_badblocks(struct rb_root *tree,
  	return true;
  }
 
-static int dust_clear_badblocks(struct dust_device *dd)
+static int dust_clear_badblocks(struct dust_device *dd, char *result, unsigned int maxlen,
+				unsigned int *sz_ptr)
  {
  	unsigned long flags;
  	struct rb_root badblocklist;
  	unsigned long long badblock_count;
+	unsigned int sz = *sz_ptr;
 
  	spin_lock_irqsave(&dd->dust_lock, flags);
  	badblocklist = dd->badblocklist;
@@ -273,11 +277,11 @@ static int dust_clear_badblocks(struct dust_device *dd)
  	spin_unlock_irqrestore(&dd->dust_lock, flags);
 
  	if (!__dust_clear_badblocks(&badblocklist, badblock_count))
-		DMINFO("%s: no badblocks found", __func__);
+		DMEMIT("%s: no badblocks found", __func__);
  	else
-		DMINFO("%s: badblocks cleared", __func__);
+		DMEMIT("%s: badblocks cleared", __func__);
 
-	return 0;
+	return 1;
  }
 
  /*
@@ -383,7 +387,7 @@ static void dust_dtr(struct dm_target *ti)
  }
 
  static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
-			char *result_buf, unsigned int maxlen)
+			char *result, unsigned int maxlen)
  {
  	struct dust_device *dd = ti->private;
  	sector_t size = i_size_read(dd->dev->bdev->bd_inode) >> SECTOR_SHIFT;
@@ -393,6 +397,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
  	unsigned char wr_fail_cnt;
  	unsigned int tmp_ui;
  	unsigned long flags;
+	unsigned int sz = 0;
  	char dummy;
 
  	if (argc == 1) {
@@ -410,12 +415,12 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
  			r = 0;
  		} else if (!strcasecmp(argv[0], "countbadblocks")) {
  			spin_lock_irqsave(&dd->dust_lock, flags);
-			DMINFO("countbadblocks: %llu badblock(s) found",
+			DMEMIT("countbadblocks: %llu badblock(s) found",
  			       dd->badblock_count);
  			spin_unlock_irqrestore(&dd->dust_lock, flags);
-			r = 0;
+			r = 1;
  		} else if (!strcasecmp(argv[0], "clearbadblocks")) {
-			r = dust_clear_badblocks(dd);
+			r = dust_clear_badblocks(dd, result, maxlen, &sz);
  		} else if (!strcasecmp(argv[0], "quiet")) {
  			if (!dd->quiet_mode)
  				dd->quiet_mode = true;

drivers/md/dm-dust.c static int dust_message(struct dm_target *ti, unsigned int argc, char **argv, · line 452

Quoted 8 lines
drivers/md/dm-dust.c +1 -1
@@ -441,7 +446,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
  		else if (!strcasecmp(argv[0], "removebadblock"))
  			r = dust_remove_block(dd, block);
  		else if (!strcasecmp(argv[0], "queryblock"))
-			r = dust_query_block(dd, block);
+			r = dust_query_block(dd, block, result, maxlen, &sz);
  		else
  			invalid_msg = true;
 

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

#2 lore raw
In reply to Bryan Gurney

Hi Mike, does there any advice for this patchset?

Thanks,
Kun.

Quoted 111 lines · Bryan Gurney

From: yangerkun <[email protected]>

From: yangerkun <[email protected]>

Some type of message(queryblock/countbadblocks/removebadblock) may better report results to user directly. Do it with DMEMIT.

[Bryan: maintain __func__ output in DMEMIT messages]

---
  drivers/md/dm-dust.c | 31 ++++++++++++++++++-------------
  1 file changed, 18 insertions(+), 13 deletions(-)
drivers/md/dm-dust.c +17 -12
index ff03b90072c5..f1f2dd6a4e84 100644
@@ -138,20 +138,22 @@ static int dust_add_block(struct dust_device *dd, unsigned long long block,
  	return 0;
  }
 
-static int dust_query_block(struct dust_device *dd, unsigned long long block)
+static int dust_query_block(struct dust_device *dd, unsigned long long block, char *result,
+			    unsigned int maxlen, unsigned int *sz_ptr)
  {
  	struct badblock *bblock;
  	unsigned long flags;
+	unsigned int sz = *sz_ptr;
 
  	spin_lock_irqsave(&dd->dust_lock, flags);
  	bblock = dust_rb_search(&dd->badblocklist, block);
  	if (bblock != NULL)
-		DMINFO("%s: block %llu found in badblocklist", __func__, block);
+		DMEMIT("%s: block %llu found in badblocklist", __func__, block);
  	else
-		DMINFO("%s: block %llu not found in badblocklist", __func__, block);
+		DMEMIT("%s: block %llu not found in badblocklist", __func__, block);
  	spin_unlock_irqrestore(&dd->dust_lock, flags);
 
-	return 0;
+	return 1;
  }
 
  static int __dust_map_read(struct dust_device *dd, sector_t thisblock)
@@ -259,11 +261,13 @@ static bool __dust_clear_badblocks(struct rb_root *tree,
  	return true;
  }
 
-static int dust_clear_badblocks(struct dust_device *dd)
+static int dust_clear_badblocks(struct dust_device *dd, char *result, unsigned int maxlen,
+				unsigned int *sz_ptr)
  {
  	unsigned long flags;
  	struct rb_root badblocklist;
  	unsigned long long badblock_count;
+	unsigned int sz = *sz_ptr;
 
  	spin_lock_irqsave(&dd->dust_lock, flags);
  	badblocklist = dd->badblocklist;
@@ -273,11 +277,11 @@ static int dust_clear_badblocks(struct dust_device *dd)
  	spin_unlock_irqrestore(&dd->dust_lock, flags);
 
  	if (!__dust_clear_badblocks(&badblocklist, badblock_count))
-		DMINFO("%s: no badblocks found", __func__);
+		DMEMIT("%s: no badblocks found", __func__);
  	else
-		DMINFO("%s: badblocks cleared", __func__);
+		DMEMIT("%s: badblocks cleared", __func__);
 
-	return 0;
+	return 1;
  }
 
  /*
@@ -383,7 +387,7 @@ static void dust_dtr(struct dm_target *ti)
  }
 
  static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
-			char *result_buf, unsigned int maxlen)
+			char *result, unsigned int maxlen)
  {
  	struct dust_device *dd = ti->private;
  	sector_t size = i_size_read(dd->dev->bdev->bd_inode) >> SECTOR_SHIFT;
@@ -393,6 +397,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
  	unsigned char wr_fail_cnt;
  	unsigned int tmp_ui;
  	unsigned long flags;
+	unsigned int sz = 0;
  	char dummy;
 
  	if (argc == 1) {
@@ -410,12 +415,12 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
  			r = 0;
  		} else if (!strcasecmp(argv[0], "countbadblocks")) {
  			spin_lock_irqsave(&dd->dust_lock, flags);
-			DMINFO("countbadblocks: %llu badblock(s) found",
+			DMEMIT("countbadblocks: %llu badblock(s) found",
  			       dd->badblock_count);
  			spin_unlock_irqrestore(&dd->dust_lock, flags);
-			r = 0;
+			r = 1;
  		} else if (!strcasecmp(argv[0], "clearbadblocks")) {
-			r = dust_clear_badblocks(dd);
+			r = dust_clear_badblocks(dd, result, maxlen, &sz);
  		} else if (!strcasecmp(argv[0], "quiet")) {
  			if (!dd->quiet_mode)
  				dd->quiet_mode = true;

drivers/md/dm-dust.c static int dust_message(struct dm_target *ti, unsigned int argc, char **argv, · line 452

Quoted 8 lines
drivers/md/dm-dust.c +1 -1
@@ -441,7 +446,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
  		else if (!strcasecmp(argv[0], "removebadblock"))
  			r = dust_remove_block(dd, block);
  		else if (!strcasecmp(argv[0], "queryblock"))
-			r = dust_query_block(dd, block);
+			r = dust_query_block(dd, block, result, maxlen, &sz);
  		else
  			invalid_msg = true;
 

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

#3 lore raw

It is on the dm-devel patchwork list to pick up for the 5.9 merge window. I've just been busy with other work.

Thanks,
Mike

Quoted 105 lines · yangerkun

Hi Mike, does there any advice for this patchset?

Thanks,
Kun.

Quoted 99 lines · Bryan Gurney

From: yangerkun <[email protected]>

From: yangerkun <[email protected]>

Some type of message(queryblock/countbadblocks/removebadblock) may better report results to user directly. Do it with DMEMIT.

[Bryan: maintain __func__ output in DMEMIT messages]

---
 drivers/md/dm-dust.c | 31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)
drivers/md/dm-dust.c +17 -12
index ff03b90072c5..f1f2dd6a4e84 100644
@@ -138,20 +138,22 @@ static int dust_add_block(struct dust_device *dd, unsigned long long block,
 	return 0;
 }
-static int dust_query_block(struct dust_device *dd, unsigned long long block)
+static int dust_query_block(struct dust_device *dd, unsigned long long block, char *result,
+			    unsigned int maxlen, unsigned int *sz_ptr)
 {
 	struct badblock *bblock;
 	unsigned long flags;
+	unsigned int sz = *sz_ptr;
 	spin_lock_irqsave(&dd->dust_lock, flags);
 	bblock = dust_rb_search(&dd->badblocklist, block);
 	if (bblock != NULL)
-		DMINFO("%s: block %llu found in badblocklist", __func__, block);
+		DMEMIT("%s: block %llu found in badblocklist", __func__, block);
 	else
-		DMINFO("%s: block %llu not found in badblocklist", __func__, block);
+		DMEMIT("%s: block %llu not found in badblocklist", __func__, block);
 	spin_unlock_irqrestore(&dd->dust_lock, flags);
-	return 0;
+	return 1;
 }
 static int __dust_map_read(struct dust_device *dd, sector_t thisblock)
@@ -259,11 +261,13 @@ static bool __dust_clear_badblocks(struct rb_root *tree,
 	return true;
 }
-static int dust_clear_badblocks(struct dust_device *dd)
+static int dust_clear_badblocks(struct dust_device *dd, char *result, unsigned int maxlen,
+				unsigned int *sz_ptr)
 {
 	unsigned long flags;
 	struct rb_root badblocklist;
 	unsigned long long badblock_count;
+	unsigned int sz = *sz_ptr;
 	spin_lock_irqsave(&dd->dust_lock, flags);
 	badblocklist = dd->badblocklist;
@@ -273,11 +277,11 @@ static int dust_clear_badblocks(struct dust_device *dd)
 	spin_unlock_irqrestore(&dd->dust_lock, flags);
 	if (!__dust_clear_badblocks(&badblocklist, badblock_count))
-		DMINFO("%s: no badblocks found", __func__);
+		DMEMIT("%s: no badblocks found", __func__);
 	else
-		DMINFO("%s: badblocks cleared", __func__);
+		DMEMIT("%s: badblocks cleared", __func__);
-	return 0;
+	return 1;
 }
 /*
@@ -383,7 +387,7 @@ static void dust_dtr(struct dm_target *ti)
 }
 static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
-			char *result_buf, unsigned int maxlen)
+			char *result, unsigned int maxlen)
 {
 	struct dust_device *dd = ti->private;
 	sector_t size = i_size_read(dd->dev->bdev->bd_inode) >> SECTOR_SHIFT;
@@ -393,6 +397,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
 	unsigned char wr_fail_cnt;
 	unsigned int tmp_ui;
 	unsigned long flags;
+	unsigned int sz = 0;
 	char dummy;
 	if (argc == 1) {
@@ -410,12 +415,12 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
 			r = 0;
 		} else if (!strcasecmp(argv[0], "countbadblocks")) {
 			spin_lock_irqsave(&dd->dust_lock, flags);
-			DMINFO("countbadblocks: %llu badblock(s) found",
+			DMEMIT("countbadblocks: %llu badblock(s) found",
 			       dd->badblock_count);
 			spin_unlock_irqrestore(&dd->dust_lock, flags);
-			r = 0;
+			r = 1;
 		} else if (!strcasecmp(argv[0], "clearbadblocks")) {
-			r = dust_clear_badblocks(dd);
+			r = dust_clear_badblocks(dd, result, maxlen, &sz);
 		} else if (!strcasecmp(argv[0], "quiet")) {
 			if (!dd->quiet_mode)
 				dd->quiet_mode = true;
@@ -441,7 +446,7 @@ static int dust_message(struct dm_target *ti, unsigned int argc, char **argv,
Quoted 9 lines

drivers/md/dm-dust.c static int dust_message(struct dm_target *ti, unsigned int argc, char **argv, · line 452

Quoted 8 lines
drivers/md/dm-dust.c +1 -1
 		else if (!strcasecmp(argv[0], "removebadblock"))
 			r = dust_remove_block(dd, block);
 		else if (!strcasecmp(argv[0], "queryblock"))
-			r = dust_query_block(dd, block);
+			r = dust_query_block(dd, block, result, maxlen, &sz);
 		else
 			invalid_msg = true;
 

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel