All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH v3] UBI: add debugfs file for tracking PEB state
@ 2017-05-16 17:58 Zach Brown
  2017-05-16 18:22 ` Richard Weinberger
  0 siblings, 1 reply; 4+ messages in thread
From: Zach Brown @ 2017-05-16 17:58 UTC (permalink / raw)
  To: dwmw2
  Cc: computersforpeace, boris.brezillon, marek.vasut, richard,
	cyrille.pitchen, dedekind1, linux-mtd, linux-kernel

From: Ben Shelton <ben.shelton@ni.com>

Add a file under debugfs to allow easy access to the erase count for
each physical erase block on an UBI device.  This is useful when
debugging data integrity issues with UBIFS on NAND flash devices.

Signed-off-by: Ben Shelton <ben.shelton@ni.com>
Signed-off-by: Zach Brown <zach.brown@ni.com>
---
v2:
* If ubi_io_is_bad eraseblk_count_seq_show just returns the err.
* if ubi->lookuptbl returns null, its no longer treated as an error
  instead info for that block is not printeded
* Removed check for UBI_MAX_ERASECOUNTER since it is impossible to hit
* Removed block state from print, if a block is printed then it is good and
  if it is not printed, then it is bad.

v3:
* Remove errant ! symbol from if statement checking if erase count is valid.

 drivers/mtd/ubi/debug.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 125 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index f101a49..7bc9629 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -22,6 +22,7 @@
 #include <linux/debugfs.h>
 #include <linux/uaccess.h>
 #include <linux/module.h>
+#include <linux/seq_file.h>
 
 
 /**
@@ -386,7 +387,9 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
 	return count;
 }
 
-/* File operations for all UBI debugfs files */
+/* File operations for all UBI debugfs files except
+ * detailed_erase_block_info
+ */
 static const struct file_operations dfs_fops = {
 	.read   = dfs_file_read,
 	.write  = dfs_file_write,
@@ -395,6 +398,121 @@ static const struct file_operations dfs_fops = {
 	.owner  = THIS_MODULE,
 };
 
+/* As long as the position is less then that total number of erase blocks,
+ * we still have more to print.
+ */
+static void *eraseblk_count_seq_start(struct seq_file *s, loff_t *pos)
+{
+	struct ubi_device *ubi = s->private;
+
+	if (*pos == 0)
+		return SEQ_START_TOKEN;
+
+	if (*pos < ubi->peb_count)
+		return pos;
+
+	return NULL;
+}
+
+/* Since we are using the position as the iterator, we just need to check if we
+ * are done and increment the position.
+ */
+static void *eraseblk_count_seq_next(struct seq_file *s, void *v, loff_t *pos)
+{
+	struct ubi_device *ubi = s->private;
+
+	if (v == SEQ_START_TOKEN)
+		return pos;
+	(*pos)++;
+
+	if (*pos < ubi->peb_count)
+		return pos;
+
+	return NULL;
+}
+
+static void eraseblk_count_seq_stop(struct seq_file *s, void *v)
+{
+}
+
+static int eraseblk_count_seq_show(struct seq_file *s, void *iter)
+{
+	struct ubi_device *ubi = s->private;
+	struct ubi_wl_entry *wl;
+	int *block_number = iter;
+	int erase_count = -1;
+	int err;
+
+	/* If this is the start, print a header */
+	if (iter == SEQ_START_TOKEN) {
+		seq_puts(s,
+			 "physical_block_number\terase_count\tblock_status\tread_status\n");
+		return 0;
+	}
+
+	err = ubi_io_is_bad(ubi, *block_number);
+	if (err)
+		return err;
+
+	spin_lock(&ubi->wl_lock);
+
+	wl = ubi->lookuptbl[*block_number];
+	if (wl)
+		erase_count = wl->ec;
+
+	spin_unlock(&ubi->wl_lock);
+
+	if (erase_count < 0)
+		return 0;
+
+	seq_printf(s, "%-22d\t%-11d\n", *block_number, erase_count);
+
+	return 0;
+}
+
+static const struct seq_operations eraseblk_count_seq_ops = {
+	.start = eraseblk_count_seq_start,
+	.next = eraseblk_count_seq_next,
+	.stop = eraseblk_count_seq_stop,
+	.show = eraseblk_count_seq_show
+};
+
+static int eraseblk_count_open(struct inode *inode, struct file *f)
+{
+	struct seq_file *s;
+	int err;
+
+	err = seq_open(f, &eraseblk_count_seq_ops);
+	if (err)
+		return err;
+
+	s = f->private_data;
+	s->private = ubi_get_device((unsigned long)inode->i_private);
+
+	if (!s->private)
+		return -ENODEV;
+	else
+		return 0;
+}
+
+static int eraseblk_count_release(struct inode *inode, struct file *f)
+{
+	struct seq_file *s = f->private_data;
+	struct ubi_device *ubi = s->private;
+
+	ubi_put_device(ubi);
+
+	return seq_release(inode, f);
+}
+
+static const struct file_operations eraseblk_count_fops = {
+	.owner = THIS_MODULE,
+	.open = eraseblk_count_open,
+	.read = seq_read,
+	.llseek = seq_lseek,
+	.release = eraseblk_count_release,
+};
+
 /**
  * ubi_debugfs_init_dev - initialize debugfs for an UBI device.
  * @ubi: UBI device description object
@@ -491,6 +609,12 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
 		goto out_remove;
 	d->dfs_power_cut_max = dent;
 
+	fname = "detailed_erase_block_info";
+	dent = debugfs_create_file(fname, S_IRUSR, d->dfs_dir, (void *)ubi_num,
+				   &eraseblk_count_fops);
+	if (IS_ERR_OR_NULL(dent))
+		goto out_remove;
+
 	return 0;
 
 out_remove:
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [RESEND PATCH v3] UBI: add debugfs file for tracking PEB state
  2017-05-16 17:58 [RESEND PATCH v3] UBI: add debugfs file for tracking PEB state Zach Brown
@ 2017-05-16 18:22 ` Richard Weinberger
  2017-05-17 10:36   ` Honza Petrouš
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Weinberger @ 2017-05-16 18:22 UTC (permalink / raw)
  To: Zach Brown, dwmw2
  Cc: computersforpeace, boris.brezillon, marek.vasut, cyrille.pitchen,
	dedekind1, linux-mtd, linux-kernel

Zach,

Am 16.05.2017 um 19:58 schrieb Zach Brown:
> From: Ben Shelton <ben.shelton@ni.com>
> 
> Add a file under debugfs to allow easy access to the erase count for
> each physical erase block on an UBI device.  This is useful when
> debugging data integrity issues with UBIFS on NAND flash devices.
> 
> Signed-off-by: Ben Shelton <ben.shelton@ni.com>
> Signed-off-by: Zach Brown <zach.brown@ni.com>

Hmmm, I thought I applied this to my v4.12 queue, but seems
like I didn't. So, it will be part of v4.13.
I'm very sorry, please accept my apologies.

Thanks,
//richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RESEND PATCH v3] UBI: add debugfs file for tracking PEB state
  2017-05-16 18:22 ` Richard Weinberger
@ 2017-05-17 10:36   ` Honza Petrouš
  2017-05-17 17:55     ` Zach Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Honza Petrouš @ 2017-05-17 10:36 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: Zach Brown, David Woodhouse, Boris Brezillon, dedekind1,
	linux-kernel, Marek Vasut, linux-mtd, cyrille.pitchen,
	Brian Norris

2017-05-16 20:22 GMT+02:00 Richard Weinberger <richard@nod.at>:
> Zach,
>
> Am 16.05.2017 um 19:58 schrieb Zach Brown:
>> From: Ben Shelton <ben.shelton@ni.com>
>>
>> Add a file under debugfs to allow easy access to the erase count for
>> each physical erase block on an UBI device.  This is useful when
>> debugging data integrity issues with UBIFS on NAND flash devices.
>>
>> Signed-off-by: Ben Shelton <ben.shelton@ni.com>
>> Signed-off-by: Zach Brown <zach.brown@ni.com>
>
> Hmmm, I thought I applied this to my v4.12 queue, but seems
> like I didn't. So, it will be part of v4.13.
> I'm very sorry, please accept my apologies.

Yes, you did it - at least my Linus' github repo clone has it already
= 7bccd12d27b7e358823feb5429731b8ee698b173

/Honza

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RESEND PATCH v3] UBI: add debugfs file for tracking PEB state
  2017-05-17 10:36   ` Honza Petrouš
@ 2017-05-17 17:55     ` Zach Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Zach Brown @ 2017-05-17 17:55 UTC (permalink / raw)
  To: Honza Petrouš
  Cc: Richard Weinberger, David Woodhouse, Boris Brezillon, dedekind1,
	linux-kernel, Marek Vasut, linux-mtd, cyrille.pitchen,
	Brian Norris

On Wed, May 17, 2017 at 12:36:35PM +0200, Honza Petrouš wrote:
> 2017-05-16 20:22 GMT+02:00 Richard Weinberger <richard@nod.at>:
> > Zach,
> >
> > Am 16.05.2017 um 19:58 schrieb Zach Brown:
> >> From: Ben Shelton <ben.shelton@ni.com>
> >>
> >> Add a file under debugfs to allow easy access to the erase count for
> >> each physical erase block on an UBI device.  This is useful when
> >> debugging data integrity issues with UBIFS on NAND flash devices.
> >>
> >> Signed-off-by: Ben Shelton <ben.shelton@ni.com>
> >> Signed-off-by: Zach Brown <zach.brown@ni.com>
> >
> > Hmmm, I thought I applied this to my v4.12 queue, but seems
> > like I didn't. So, it will be part of v4.13.
> > I'm very sorry, please accept my apologies.
> 
> Yes, you did it - at least my Linus' github repo clone has it already
> = 7bccd12d27b7e358823feb5429731b8ee698b173
> 
> /Honza

My mistake then. My apologies for the confusion. Thank you for noticing.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-05-17 18:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-16 17:58 [RESEND PATCH v3] UBI: add debugfs file for tracking PEB state Zach Brown
2017-05-16 18:22 ` Richard Weinberger
2017-05-17 10:36   ` Honza Petrouš
2017-05-17 17:55     ` Zach Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.