* [PATCH] mmc_test: move files from sysfs to debugfs
@ 2010-09-10 7:10 Andy Shevchenko
2010-09-10 7:19 ` Adrian Hunter
0 siblings, 1 reply; 7+ messages in thread
From: Andy Shevchenko @ 2010-09-10 7:10 UTC (permalink / raw)
To: linux-mmc, linux-kernel
Cc: Andrew Morton, Greg KH, Hunter Adrian, Andy Shevchenko
As proposed by Greg the more logically is to keep files for mmc_test driver
under debugfs.
Additionally this patch brings seq_file API for show() method. It allows to
write unlimited data to the file.
Example of usage:
# mount -t debugfs none /sys/kernel/debug
# modprobe mmc_test
[ 581.395843] mmc_test mmc0:0001: Card claimed for testing.
# echo 25 > /sys/kernel/debug/mmc0/mmc0\:0001/test
[ 604.568542] mmc0: Starting tests of card mmc0:0001...
[ 604.582733] mmc0: Test case 25. Best-case read performance into scattered pages...
[ 604.923553] mmc0: Transfer of 8192 sectors (4096 KiB) took 0.124664314 seconds (33644 kB/s, 32856 KiB/s)
[ 604.933227] mmc0: Result: OK
[ 604.936248] mmc0: Tests completed.
# cat /sys/kernel/debug/mmc0/mmc0\:0001/test
Test 25: 0
1 8192 0.124664314 33644784
Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
drivers/mmc/card/mmc_test.c | 138 ++++++++++++++++++++++++++++++++-----------
1 files changed, 103 insertions(+), 35 deletions(-)
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 58d746b..e59bb02 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -19,6 +19,10 @@
#include <linux/swap.h> /* For nr_free_buffer_pages() */
#include <linux/list.h>
+#include <linux/debugfs.h>
+#include <asm/uaccess.h>
+#include <linux/seq_file.h>
+
#define RESULT_OK 0
#define RESULT_FAIL 1
#define RESULT_UNSUP_HOST 2
@@ -106,6 +110,18 @@ struct mmc_test_general_result {
};
/**
+ * struct mmc_test_dbgfs_file - debugfs related file.
+ * @link: double-linked list
+ * @card: card under test
+ * @file: file created under debugfs
+ */
+struct mmc_test_dbgfs_file {
+ struct list_head link;
+ struct mmc_card *card;
+ struct dentry *file;
+};
+
+/**
* struct mmc_test_card - test information.
* @card: card under test
* @scratch: transfer buffer
@@ -2037,14 +2053,12 @@ static void mmc_test_free_result(struct mmc_card *card)
mutex_unlock(&mmc_test_lock);
}
-static ssize_t mmc_test_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+static LIST_HEAD(mmc_test_file_test);
+
+static int mtf_test_show(struct seq_file *sf, void *data)
{
- struct mmc_card *card = mmc_dev_to_card(dev);
+ struct mmc_card *card = (struct mmc_card *)sf->private;
struct mmc_test_general_result *gr;
- char *p = buf;
- size_t len = PAGE_SIZE;
- int ret;
mutex_lock(&mmc_test_lock);
@@ -2054,49 +2068,44 @@ static ssize_t mmc_test_show(struct device *dev,
if (gr->card != card)
continue;
- ret = snprintf(p, len, "Test %d: %d\n", gr->testcase + 1,
- gr->result);
- if (ret < 0)
- goto err;
- if (ret >= len) {
- ret = -ENOBUFS;
- goto err;
- }
- p += ret;
- len -= ret;
+ seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
list_for_each_entry(tr, &gr->tr_lst, link) {
- ret = snprintf(p, len, "%u %d %lu.%09lu %u\n",
+ seq_printf(sf, "%u %d %lu.%09lu %u\n",
tr->count, tr->sectors,
(unsigned long)tr->ts.tv_sec,
(unsigned long)tr->ts.tv_nsec,
tr->rate);
- if (ret < 0)
- goto err;
- if (ret >= len) {
- ret = -ENOBUFS;
- goto err;
- }
- p += ret;
- len -= ret;
}
}
- ret = PAGE_SIZE - len;
-err:
mutex_unlock(&mmc_test_lock);
- return ret;
+ return 0;
}
-static ssize_t mmc_test_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
+static int mtf_test_open(struct inode *inode, struct file *file)
{
- struct mmc_card *card = mmc_dev_to_card(dev);
+ return single_open(file, mtf_test_show, inode->i_private);
+}
+
+static ssize_t mtf_test_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *pos)
+{
+ struct seq_file *sf = (struct seq_file *)file->private_data;
+ struct mmc_card *card = (struct mmc_card *)sf->private;
struct mmc_test_card *test;
+ char lbuf[12];
long testcase;
- if (strict_strtol(buf, 10, &testcase))
+ if (count >= sizeof(lbuf))
+ return -EINVAL;
+
+ if (copy_from_user(lbuf, buf, count))
+ return -EFAULT;
+ lbuf[count] = '\0';
+
+ if (strict_strtol(lbuf, 10, &testcase))
return -EINVAL;
test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL);
@@ -2135,7 +2144,65 @@ static ssize_t mmc_test_store(struct device *dev,
return count;
}
-static DEVICE_ATTR(test, S_IWUSR | S_IRUGO, mmc_test_show, mmc_test_store);
+static const struct file_operations mmc_test_fops_test = {
+ .open = mtf_test_open,
+ .read = seq_read,
+ .write = mtf_test_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static void mmc_test_free_file_test(struct mmc_card *card)
+{
+ struct mmc_test_dbgfs_file *df, *dfs;
+
+ mutex_lock(&mmc_test_lock);
+
+ list_for_each_entry_safe(df, dfs, &mmc_test_file_test, link) {
+ if (card && df->card != card)
+ continue;
+ debugfs_remove(df->file);
+ list_del(&df->link);
+ kfree(df);
+ }
+
+ mutex_unlock(&mmc_test_lock);
+}
+
+static int mmc_test_register_file_test(struct mmc_card *card)
+{
+ struct dentry *file = NULL;
+ struct mmc_test_dbgfs_file *df;
+ int ret = 0;
+
+ mutex_lock(&mmc_test_lock);
+
+ if (card->debugfs_root)
+ file = debugfs_create_file("test", S_IWUSR, card->debugfs_root,
+ card, &mmc_test_fops_test);
+
+ if (IS_ERR_OR_NULL(file)) {
+ ret = -ENODEV;
+ goto err;
+ }
+
+ df = kmalloc(sizeof(struct mmc_test_dbgfs_file), GFP_KERNEL);
+ if (!df) {
+ debugfs_remove(file);
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ df->card = card;
+ df->file = file;
+
+ list_add(&df->link, &mmc_test_file_test);
+
+err:
+ mutex_unlock(&mmc_test_lock);
+
+ return ret;
+}
static int mmc_test_probe(struct mmc_card *card)
{
@@ -2144,7 +2211,7 @@ static int mmc_test_probe(struct mmc_card *card)
if (!mmc_card_mmc(card) && !mmc_card_sd(card))
return -ENODEV;
- ret = device_create_file(&card->dev, &dev_attr_test);
+ ret = mmc_test_register_file_test(card);
if (ret)
return ret;
@@ -2156,7 +2223,7 @@ static int mmc_test_probe(struct mmc_card *card)
static void mmc_test_remove(struct mmc_card *card)
{
mmc_test_free_result(card);
- device_remove_file(&card->dev, &dev_attr_test);
+ mmc_test_free_file_test(card);
}
static struct mmc_driver mmc_driver = {
@@ -2176,6 +2243,7 @@ static void __exit mmc_test_exit(void)
{
/* Clear stalled data if card is still plugged */
mmc_test_free_result(NULL);
+ mmc_test_free_file_test(NULL);
mmc_unregister_driver(&mmc_driver);
}
--
1.6.3.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc_test: move files from sysfs to debugfs
2010-09-10 7:10 [PATCH] mmc_test: move files from sysfs to debugfs Andy Shevchenko
@ 2010-09-10 7:19 ` Adrian Hunter
0 siblings, 0 replies; 7+ messages in thread
From: Adrian Hunter @ 2010-09-10 7:19 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-mmc, linux-kernel, Andrew Morton, Greg KH,
Shevchenko Andriy (EXT-Teleca/Helsinki)
Andy Shevchenko wrote:
> As proposed by Greg the more logically is to keep files for mmc_test driver
> under debugfs.
What happens if debugfs is not enabled in config? Should there be
some kind of dependency there? At least an error message would be
good - see below.
>
> Additionally this patch brings seq_file API for show() method. It allows to
> write unlimited data to the file.
>
> Example of usage:
> # mount -t debugfs none /sys/kernel/debug
> # modprobe mmc_test
> [ 581.395843] mmc_test mmc0:0001: Card claimed for testing.
> # echo 25 > /sys/kernel/debug/mmc0/mmc0\:0001/test
> [ 604.568542] mmc0: Starting tests of card mmc0:0001...
> [ 604.582733] mmc0: Test case 25. Best-case read performance into scattered pages...
> [ 604.923553] mmc0: Transfer of 8192 sectors (4096 KiB) took 0.124664314 seconds (33644 kB/s, 32856 KiB/s)
> [ 604.933227] mmc0: Result: OK
> [ 604.936248] mmc0: Tests completed.
> # cat /sys/kernel/debug/mmc0/mmc0\:0001/test
> Test 25: 0
> 1 8192 0.124664314 33644784
>
> Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
> ---
> drivers/mmc/card/mmc_test.c | 138 ++++++++++++++++++++++++++++++++-----------
> 1 files changed, 103 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
> index 58d746b..e59bb02 100644
> --- a/drivers/mmc/card/mmc_test.c
> +++ b/drivers/mmc/card/mmc_test.c
> @@ -19,6 +19,10 @@
> #include <linux/swap.h> /* For nr_free_buffer_pages() */
> #include <linux/list.h>
>
> +#include <linux/debugfs.h>
> +#include <asm/uaccess.h>
> +#include <linux/seq_file.h>
> +
> #define RESULT_OK 0
> #define RESULT_FAIL 1
> #define RESULT_UNSUP_HOST 2
> @@ -106,6 +110,18 @@ struct mmc_test_general_result {
> };
>
> /**
> + * struct mmc_test_dbgfs_file - debugfs related file.
> + * @link: double-linked list
> + * @card: card under test
> + * @file: file created under debugfs
> + */
> +struct mmc_test_dbgfs_file {
> + struct list_head link;
> + struct mmc_card *card;
> + struct dentry *file;
> +};
> +
> +/**
> * struct mmc_test_card - test information.
> * @card: card under test
> * @scratch: transfer buffer
> @@ -2037,14 +2053,12 @@ static void mmc_test_free_result(struct mmc_card *card)
> mutex_unlock(&mmc_test_lock);
> }
>
> -static ssize_t mmc_test_show(struct device *dev,
> - struct device_attribute *attr, char *buf)
> +static LIST_HEAD(mmc_test_file_test);
> +
> +static int mtf_test_show(struct seq_file *sf, void *data)
> {
> - struct mmc_card *card = mmc_dev_to_card(dev);
> + struct mmc_card *card = (struct mmc_card *)sf->private;
> struct mmc_test_general_result *gr;
> - char *p = buf;
> - size_t len = PAGE_SIZE;
> - int ret;
>
> mutex_lock(&mmc_test_lock);
>
> @@ -2054,49 +2068,44 @@ static ssize_t mmc_test_show(struct device *dev,
> if (gr->card != card)
> continue;
>
> - ret = snprintf(p, len, "Test %d: %d\n", gr->testcase + 1,
> - gr->result);
> - if (ret < 0)
> - goto err;
> - if (ret >= len) {
> - ret = -ENOBUFS;
> - goto err;
> - }
> - p += ret;
> - len -= ret;
> + seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
>
> list_for_each_entry(tr, &gr->tr_lst, link) {
> - ret = snprintf(p, len, "%u %d %lu.%09lu %u\n",
> + seq_printf(sf, "%u %d %lu.%09lu %u\n",
> tr->count, tr->sectors,
> (unsigned long)tr->ts.tv_sec,
> (unsigned long)tr->ts.tv_nsec,
> tr->rate);
> - if (ret < 0)
> - goto err;
> - if (ret >= len) {
> - ret = -ENOBUFS;
> - goto err;
> - }
> - p += ret;
> - len -= ret;
> }
> }
>
> - ret = PAGE_SIZE - len;
> -err:
> mutex_unlock(&mmc_test_lock);
>
> - return ret;
> + return 0;
> }
>
> -static ssize_t mmc_test_store(struct device *dev,
> - struct device_attribute *attr, const char *buf, size_t count)
> +static int mtf_test_open(struct inode *inode, struct file *file)
> {
> - struct mmc_card *card = mmc_dev_to_card(dev);
> + return single_open(file, mtf_test_show, inode->i_private);
> +}
> +
> +static ssize_t mtf_test_write(struct file *file, const char __user *buf,
> + size_t count, loff_t *pos)
> +{
> + struct seq_file *sf = (struct seq_file *)file->private_data;
> + struct mmc_card *card = (struct mmc_card *)sf->private;
> struct mmc_test_card *test;
> + char lbuf[12];
> long testcase;
>
> - if (strict_strtol(buf, 10, &testcase))
> + if (count >= sizeof(lbuf))
> + return -EINVAL;
> +
> + if (copy_from_user(lbuf, buf, count))
> + return -EFAULT;
> + lbuf[count] = '\0';
> +
> + if (strict_strtol(lbuf, 10, &testcase))
> return -EINVAL;
>
> test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL);
> @@ -2135,7 +2144,65 @@ static ssize_t mmc_test_store(struct device *dev,
> return count;
> }
>
> -static DEVICE_ATTR(test, S_IWUSR | S_IRUGO, mmc_test_show, mmc_test_store);
> +static const struct file_operations mmc_test_fops_test = {
> + .open = mtf_test_open,
> + .read = seq_read,
> + .write = mtf_test_write,
> + .llseek = seq_lseek,
> + .release = single_release,
> +};
> +
> +static void mmc_test_free_file_test(struct mmc_card *card)
> +{
> + struct mmc_test_dbgfs_file *df, *dfs;
> +
> + mutex_lock(&mmc_test_lock);
> +
> + list_for_each_entry_safe(df, dfs, &mmc_test_file_test, link) {
> + if (card && df->card != card)
> + continue;
> + debugfs_remove(df->file);
> + list_del(&df->link);
> + kfree(df);
> + }
> +
> + mutex_unlock(&mmc_test_lock);
> +}
> +
> +static int mmc_test_register_file_test(struct mmc_card *card)
> +{
> + struct dentry *file = NULL;
> + struct mmc_test_dbgfs_file *df;
> + int ret = 0;
> +
> + mutex_lock(&mmc_test_lock);
> +
> + if (card->debugfs_root)
> + file = debugfs_create_file("test", S_IWUSR, card->debugfs_root,
> + card, &mmc_test_fops_test);
> +
> + if (IS_ERR_OR_NULL(file)) {
Perhaps a error message should be printed here.
> + ret = -ENODEV;
> + goto err;
> + }
> +
> + df = kmalloc(sizeof(struct mmc_test_dbgfs_file), GFP_KERNEL);
> + if (!df) {
> + debugfs_remove(file);
> + ret = -ENOMEM;
> + goto err;
> + }
> +
> + df->card = card;
> + df->file = file;
> +
> + list_add(&df->link, &mmc_test_file_test);
> +
> +err:
> + mutex_unlock(&mmc_test_lock);
> +
> + return ret;
> +}
>
> static int mmc_test_probe(struct mmc_card *card)
> {
> @@ -2144,7 +2211,7 @@ static int mmc_test_probe(struct mmc_card *card)
> if (!mmc_card_mmc(card) && !mmc_card_sd(card))
> return -ENODEV;
>
> - ret = device_create_file(&card->dev, &dev_attr_test);
> + ret = mmc_test_register_file_test(card);
> if (ret)
> return ret;
>
> @@ -2156,7 +2223,7 @@ static int mmc_test_probe(struct mmc_card *card)
> static void mmc_test_remove(struct mmc_card *card)
> {
> mmc_test_free_result(card);
> - device_remove_file(&card->dev, &dev_attr_test);
> + mmc_test_free_file_test(card);
> }
>
> static struct mmc_driver mmc_driver = {
> @@ -2176,6 +2243,7 @@ static void __exit mmc_test_exit(void)
> {
> /* Clear stalled data if card is still plugged */
> mmc_test_free_result(NULL);
> + mmc_test_free_file_test(NULL);
>
> mmc_unregister_driver(&mmc_driver);
> }
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc_test: move files from sysfs to debugfs
@ 2010-09-10 7:19 ` Adrian Hunter
0 siblings, 0 replies; 7+ messages in thread
From: Adrian Hunter @ 2010-09-10 7:19 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-mmc, linux-kernel, Andrew Morton, Greg KH,
Shevchenko Andriy (EXT-Teleca/Helsinki)
Andy Shevchenko wrote:
> As proposed by Greg the more logically is to keep files for mmc_test driver
> under debugfs.
What happens if debugfs is not enabled in config? Should there be
some kind of dependency there? At least an error message would be
good - see below.
>
> Additionally this patch brings seq_file API for show() method. It allows to
> write unlimited data to the file.
>
> Example of usage:
> # mount -t debugfs none /sys/kernel/debug
> # modprobe mmc_test
> [ 581.395843] mmc_test mmc0:0001: Card claimed for testing.
> # echo 25 > /sys/kernel/debug/mmc0/mmc0\:0001/test
> [ 604.568542] mmc0: Starting tests of card mmc0:0001...
> [ 604.582733] mmc0: Test case 25. Best-case read performance into scattered pages...
> [ 604.923553] mmc0: Transfer of 8192 sectors (4096 KiB) took 0.124664314 seconds (33644 kB/s, 32856 KiB/s)
> [ 604.933227] mmc0: Result: OK
> [ 604.936248] mmc0: Tests completed.
> # cat /sys/kernel/debug/mmc0/mmc0\:0001/test
> Test 25: 0
> 1 8192 0.124664314 33644784
>
> Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
> ---
> drivers/mmc/card/mmc_test.c | 138 ++++++++++++++++++++++++++++++++-----------
> 1 files changed, 103 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
> index 58d746b..e59bb02 100644
> --- a/drivers/mmc/card/mmc_test.c
> +++ b/drivers/mmc/card/mmc_test.c
> @@ -19,6 +19,10 @@
> #include <linux/swap.h> /* For nr_free_buffer_pages() */
> #include <linux/list.h>
>
> +#include <linux/debugfs.h>
> +#include <asm/uaccess.h>
> +#include <linux/seq_file.h>
> +
> #define RESULT_OK 0
> #define RESULT_FAIL 1
> #define RESULT_UNSUP_HOST 2
> @@ -106,6 +110,18 @@ struct mmc_test_general_result {
> };
>
> /**
> + * struct mmc_test_dbgfs_file - debugfs related file.
> + * @link: double-linked list
> + * @card: card under test
> + * @file: file created under debugfs
> + */
> +struct mmc_test_dbgfs_file {
> + struct list_head link;
> + struct mmc_card *card;
> + struct dentry *file;
> +};
> +
> +/**
> * struct mmc_test_card - test information.
> * @card: card under test
> * @scratch: transfer buffer
> @@ -2037,14 +2053,12 @@ static void mmc_test_free_result(struct mmc_card *card)
> mutex_unlock(&mmc_test_lock);
> }
>
> -static ssize_t mmc_test_show(struct device *dev,
> - struct device_attribute *attr, char *buf)
> +static LIST_HEAD(mmc_test_file_test);
> +
> +static int mtf_test_show(struct seq_file *sf, void *data)
> {
> - struct mmc_card *card = mmc_dev_to_card(dev);
> + struct mmc_card *card = (struct mmc_card *)sf->private;
> struct mmc_test_general_result *gr;
> - char *p = buf;
> - size_t len = PAGE_SIZE;
> - int ret;
>
> mutex_lock(&mmc_test_lock);
>
> @@ -2054,49 +2068,44 @@ static ssize_t mmc_test_show(struct device *dev,
> if (gr->card != card)
> continue;
>
> - ret = snprintf(p, len, "Test %d: %d\n", gr->testcase + 1,
> - gr->result);
> - if (ret < 0)
> - goto err;
> - if (ret >= len) {
> - ret = -ENOBUFS;
> - goto err;
> - }
> - p += ret;
> - len -= ret;
> + seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
>
> list_for_each_entry(tr, &gr->tr_lst, link) {
> - ret = snprintf(p, len, "%u %d %lu.%09lu %u\n",
> + seq_printf(sf, "%u %d %lu.%09lu %u\n",
> tr->count, tr->sectors,
> (unsigned long)tr->ts.tv_sec,
> (unsigned long)tr->ts.tv_nsec,
> tr->rate);
> - if (ret < 0)
> - goto err;
> - if (ret >= len) {
> - ret = -ENOBUFS;
> - goto err;
> - }
> - p += ret;
> - len -= ret;
> }
> }
>
> - ret = PAGE_SIZE - len;
> -err:
> mutex_unlock(&mmc_test_lock);
>
> - return ret;
> + return 0;
> }
>
> -static ssize_t mmc_test_store(struct device *dev,
> - struct device_attribute *attr, const char *buf, size_t count)
> +static int mtf_test_open(struct inode *inode, struct file *file)
> {
> - struct mmc_card *card = mmc_dev_to_card(dev);
> + return single_open(file, mtf_test_show, inode->i_private);
> +}
> +
> +static ssize_t mtf_test_write(struct file *file, const char __user *buf,
> + size_t count, loff_t *pos)
> +{
> + struct seq_file *sf = (struct seq_file *)file->private_data;
> + struct mmc_card *card = (struct mmc_card *)sf->private;
> struct mmc_test_card *test;
> + char lbuf[12];
> long testcase;
>
> - if (strict_strtol(buf, 10, &testcase))
> + if (count >= sizeof(lbuf))
> + return -EINVAL;
> +
> + if (copy_from_user(lbuf, buf, count))
> + return -EFAULT;
> + lbuf[count] = '\0';
> +
> + if (strict_strtol(lbuf, 10, &testcase))
> return -EINVAL;
>
> test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL);
> @@ -2135,7 +2144,65 @@ static ssize_t mmc_test_store(struct device *dev,
> return count;
> }
>
> -static DEVICE_ATTR(test, S_IWUSR | S_IRUGO, mmc_test_show, mmc_test_store);
> +static const struct file_operations mmc_test_fops_test = {
> + .open = mtf_test_open,
> + .read = seq_read,
> + .write = mtf_test_write,
> + .llseek = seq_lseek,
> + .release = single_release,
> +};
> +
> +static void mmc_test_free_file_test(struct mmc_card *card)
> +{
> + struct mmc_test_dbgfs_file *df, *dfs;
> +
> + mutex_lock(&mmc_test_lock);
> +
> + list_for_each_entry_safe(df, dfs, &mmc_test_file_test, link) {
> + if (card && df->card != card)
> + continue;
> + debugfs_remove(df->file);
> + list_del(&df->link);
> + kfree(df);
> + }
> +
> + mutex_unlock(&mmc_test_lock);
> +}
> +
> +static int mmc_test_register_file_test(struct mmc_card *card)
> +{
> + struct dentry *file = NULL;
> + struct mmc_test_dbgfs_file *df;
> + int ret = 0;
> +
> + mutex_lock(&mmc_test_lock);
> +
> + if (card->debugfs_root)
> + file = debugfs_create_file("test", S_IWUSR, card->debugfs_root,
> + card, &mmc_test_fops_test);
> +
> + if (IS_ERR_OR_NULL(file)) {
Perhaps a error message should be printed here.
> + ret = -ENODEV;
> + goto err;
> + }
> +
> + df = kmalloc(sizeof(struct mmc_test_dbgfs_file), GFP_KERNEL);
> + if (!df) {
> + debugfs_remove(file);
> + ret = -ENOMEM;
> + goto err;
> + }
> +
> + df->card = card;
> + df->file = file;
> +
> + list_add(&df->link, &mmc_test_file_test);
> +
> +err:
> + mutex_unlock(&mmc_test_lock);
> +
> + return ret;
> +}
>
> static int mmc_test_probe(struct mmc_card *card)
> {
> @@ -2144,7 +2211,7 @@ static int mmc_test_probe(struct mmc_card *card)
> if (!mmc_card_mmc(card) && !mmc_card_sd(card))
> return -ENODEV;
>
> - ret = device_create_file(&card->dev, &dev_attr_test);
> + ret = mmc_test_register_file_test(card);
> if (ret)
> return ret;
>
> @@ -2156,7 +2223,7 @@ static int mmc_test_probe(struct mmc_card *card)
> static void mmc_test_remove(struct mmc_card *card)
> {
> mmc_test_free_result(card);
> - device_remove_file(&card->dev, &dev_attr_test);
> + mmc_test_free_file_test(card);
> }
>
> static struct mmc_driver mmc_driver = {
> @@ -2176,6 +2243,7 @@ static void __exit mmc_test_exit(void)
> {
> /* Clear stalled data if card is still plugged */
> mmc_test_free_result(NULL);
> + mmc_test_free_file_test(NULL);
>
> mmc_unregister_driver(&mmc_driver);
> }
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCHv2] mmc_test: move files from sysfs to debugfs
2010-09-10 7:19 ` Adrian Hunter
(?)
@ 2010-09-10 12:47 ` Andy Shevchenko
-1 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2010-09-10 12:47 UTC (permalink / raw)
To: linux-mmc, linux-kernel
Cc: Andrew Morton, Greg KH, Hunter Adrian, Andy Shevchenko
As proposed by Greg the more logically is to keep files for mmc_test driver
under debugfs.
Additionally this patch brings seq_file API for show() method. It allows to
write unlimited data to the file.
Example of usage:
# mount -t debugfs none /sys/kernel/debug
# modprobe mmc_test
[ 581.395843] mmc_test mmc0:0001: Card claimed for testing.
# echo 25 > /sys/kernel/debug/mmc0/mmc0\:0001/test
[ 604.568542] mmc0: Starting tests of card mmc0:0001...
[ 604.582733] mmc0: Test case 25. Best-case read performance into scattered pages...
[ 604.923553] mmc0: Transfer of 8192 sectors (4096 KiB) took 0.124664314 seconds (33644 kB/s, 32856 KiB/s)
[ 604.933227] mmc0: Result: OK
[ 604.936248] mmc0: Tests completed.
# cat /sys/kernel/debug/mmc0/mmc0\:0001/test
Test 25: 0
1 8192 0.124664314 33644784
Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
drivers/mmc/card/mmc_test.c | 142 ++++++++++++++++++++++++++++++++-----------
1 files changed, 107 insertions(+), 35 deletions(-)
diff --git a/drivers/mmc/card/mmc_test.c b/drivers/mmc/card/mmc_test.c
index 58d746b..4ea6aab 100644
--- a/drivers/mmc/card/mmc_test.c
+++ b/drivers/mmc/card/mmc_test.c
@@ -19,6 +19,10 @@
#include <linux/swap.h> /* For nr_free_buffer_pages() */
#include <linux/list.h>
+#include <linux/debugfs.h>
+#include <asm/uaccess.h>
+#include <linux/seq_file.h>
+
#define RESULT_OK 0
#define RESULT_FAIL 1
#define RESULT_UNSUP_HOST 2
@@ -106,6 +110,18 @@ struct mmc_test_general_result {
};
/**
+ * struct mmc_test_dbgfs_file - debugfs related file.
+ * @link: double-linked list
+ * @card: card under test
+ * @file: file created under debugfs
+ */
+struct mmc_test_dbgfs_file {
+ struct list_head link;
+ struct mmc_card *card;
+ struct dentry *file;
+};
+
+/**
* struct mmc_test_card - test information.
* @card: card under test
* @scratch: transfer buffer
@@ -2037,14 +2053,12 @@ static void mmc_test_free_result(struct mmc_card *card)
mutex_unlock(&mmc_test_lock);
}
-static ssize_t mmc_test_show(struct device *dev,
- struct device_attribute *attr, char *buf)
+static LIST_HEAD(mmc_test_file_test);
+
+static int mtf_test_show(struct seq_file *sf, void *data)
{
- struct mmc_card *card = mmc_dev_to_card(dev);
+ struct mmc_card *card = (struct mmc_card *)sf->private;
struct mmc_test_general_result *gr;
- char *p = buf;
- size_t len = PAGE_SIZE;
- int ret;
mutex_lock(&mmc_test_lock);
@@ -2054,49 +2068,44 @@ static ssize_t mmc_test_show(struct device *dev,
if (gr->card != card)
continue;
- ret = snprintf(p, len, "Test %d: %d\n", gr->testcase + 1,
- gr->result);
- if (ret < 0)
- goto err;
- if (ret >= len) {
- ret = -ENOBUFS;
- goto err;
- }
- p += ret;
- len -= ret;
+ seq_printf(sf, "Test %d: %d\n", gr->testcase + 1, gr->result);
list_for_each_entry(tr, &gr->tr_lst, link) {
- ret = snprintf(p, len, "%u %d %lu.%09lu %u\n",
+ seq_printf(sf, "%u %d %lu.%09lu %u\n",
tr->count, tr->sectors,
(unsigned long)tr->ts.tv_sec,
(unsigned long)tr->ts.tv_nsec,
tr->rate);
- if (ret < 0)
- goto err;
- if (ret >= len) {
- ret = -ENOBUFS;
- goto err;
- }
- p += ret;
- len -= ret;
}
}
- ret = PAGE_SIZE - len;
-err:
mutex_unlock(&mmc_test_lock);
- return ret;
+ return 0;
}
-static ssize_t mmc_test_store(struct device *dev,
- struct device_attribute *attr, const char *buf, size_t count)
+static int mtf_test_open(struct inode *inode, struct file *file)
{
- struct mmc_card *card = mmc_dev_to_card(dev);
+ return single_open(file, mtf_test_show, inode->i_private);
+}
+
+static ssize_t mtf_test_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *pos)
+{
+ struct seq_file *sf = (struct seq_file *)file->private_data;
+ struct mmc_card *card = (struct mmc_card *)sf->private;
struct mmc_test_card *test;
+ char lbuf[12];
long testcase;
- if (strict_strtol(buf, 10, &testcase))
+ if (count >= sizeof(lbuf))
+ return -EINVAL;
+
+ if (copy_from_user(lbuf, buf, count))
+ return -EFAULT;
+ lbuf[count] = '\0';
+
+ if (strict_strtol(lbuf, 10, &testcase))
return -EINVAL;
test = kzalloc(sizeof(struct mmc_test_card), GFP_KERNEL);
@@ -2135,7 +2144,69 @@ static ssize_t mmc_test_store(struct device *dev,
return count;
}
-static DEVICE_ATTR(test, S_IWUSR | S_IRUGO, mmc_test_show, mmc_test_store);
+static const struct file_operations mmc_test_fops_test = {
+ .open = mtf_test_open,
+ .read = seq_read,
+ .write = mtf_test_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static void mmc_test_free_file_test(struct mmc_card *card)
+{
+ struct mmc_test_dbgfs_file *df, *dfs;
+
+ mutex_lock(&mmc_test_lock);
+
+ list_for_each_entry_safe(df, dfs, &mmc_test_file_test, link) {
+ if (card && df->card != card)
+ continue;
+ debugfs_remove(df->file);
+ list_del(&df->link);
+ kfree(df);
+ }
+
+ mutex_unlock(&mmc_test_lock);
+}
+
+static int mmc_test_register_file_test(struct mmc_card *card)
+{
+ struct dentry *file = NULL;
+ struct mmc_test_dbgfs_file *df;
+ int ret = 0;
+
+ mutex_lock(&mmc_test_lock);
+
+ if (card->debugfs_root)
+ file = debugfs_create_file("test", S_IWUSR | S_IRUGO,
+ card->debugfs_root, card, &mmc_test_fops_test);
+
+ if (IS_ERR_OR_NULL(file)) {
+ dev_err(&card->dev,
+ "Can't create file. Perhaps debugfs is disabled.\n");
+ ret = -ENODEV;
+ goto err;
+ }
+
+ df = kmalloc(sizeof(struct mmc_test_dbgfs_file), GFP_KERNEL);
+ if (!df) {
+ debugfs_remove(file);
+ dev_err(&card->dev,
+ "Can't allocate memory for internal usage.\n");
+ ret = -ENOMEM;
+ goto err;
+ }
+
+ df->card = card;
+ df->file = file;
+
+ list_add(&df->link, &mmc_test_file_test);
+
+err:
+ mutex_unlock(&mmc_test_lock);
+
+ return ret;
+}
static int mmc_test_probe(struct mmc_card *card)
{
@@ -2144,7 +2215,7 @@ static int mmc_test_probe(struct mmc_card *card)
if (!mmc_card_mmc(card) && !mmc_card_sd(card))
return -ENODEV;
- ret = device_create_file(&card->dev, &dev_attr_test);
+ ret = mmc_test_register_file_test(card);
if (ret)
return ret;
@@ -2156,7 +2227,7 @@ static int mmc_test_probe(struct mmc_card *card)
static void mmc_test_remove(struct mmc_card *card)
{
mmc_test_free_result(card);
- device_remove_file(&card->dev, &dev_attr_test);
+ mmc_test_free_file_test(card);
}
static struct mmc_driver mmc_driver = {
@@ -2176,6 +2247,7 @@ static void __exit mmc_test_exit(void)
{
/* Clear stalled data if card is still plugged */
mmc_test_free_result(NULL);
+ mmc_test_free_file_test(NULL);
mmc_unregister_driver(&mmc_driver);
}
--
1.6.3.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc_test: move files from sysfs to debugfs
2010-09-10 7:19 ` Adrian Hunter
@ 2010-09-10 20:29 ` Greg KH
-1 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2010-09-10 20:29 UTC (permalink / raw)
To: Adrian Hunter
Cc: Andy Shevchenko, linux-mmc, linux-kernel, Andrew Morton,
Shevchenko Andriy (EXT-Teleca/Helsinki)
On Fri, Sep 10, 2010 at 10:19:29AM +0300, Adrian Hunter wrote:
> Andy Shevchenko wrote:
> >As proposed by Greg the more logically is to keep files for mmc_test driver
> >under debugfs.
>
> What happens if debugfs is not enabled in config? Should there be
> some kind of dependency there? At least an error message would be
> good - see below.
That would be good, but note that all major distros now enable it, so
it's less and less of an issue these days.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc_test: move files from sysfs to debugfs
@ 2010-09-10 20:29 ` Greg KH
0 siblings, 0 replies; 7+ messages in thread
From: Greg KH @ 2010-09-10 20:29 UTC (permalink / raw)
To: Adrian Hunter
Cc: Andy Shevchenko, linux-mmc, linux-kernel, Andrew Morton,
Shevchenko Andriy (EXT-Teleca/Helsinki)
On Fri, Sep 10, 2010 at 10:19:29AM +0300, Adrian Hunter wrote:
> Andy Shevchenko wrote:
> >As proposed by Greg the more logically is to keep files for mmc_test driver
> >under debugfs.
>
> What happens if debugfs is not enabled in config? Should there be
> some kind of dependency there? At least an error message would be
> good - see below.
That would be good, but note that all major distros now enable it, so
it's less and less of an issue these days.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mmc_test: move files from sysfs to debugfs
2010-09-10 20:29 ` Greg KH
(?)
@ 2013-11-20 1:56 ` spalav
-1 siblings, 0 replies; 7+ messages in thread
From: spalav @ 2013-11-20 1:56 UTC (permalink / raw)
To: linux-mmc
Greg KH <greg <at> kroah.com> writes:
>
> On Fri, Sep 10, 2010 at 10:19:29AM +0300, Adrian Hunter wrote:
> > Andy Shevchenko wrote:
> > >As proposed by Greg the more logically is to keep files for mmc_test driver
> > >under debugfs.
> >
> > What happens if debugfs is not enabled in config? Should there be
> > some kind of dependency there? At least an error message would be
> > good - see below.
>
> That would be good, but note that all major distros now enable it, so
> it's less and less of an issue these days.
>
> thanks,
>
> greg k-h
> --
> To unsubscribe from this list: send the line "unsubscribe linux-mmc" in
> the body of a message to majordomo <at> vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
Hi,
I am using 3.4 kernel and trying to use CONFIG_MMC_TEST option.
I am booting from an SD card, want to test eMMC on board.
I have CONFIG_DEBUF_FS option turned on and I am building mmc_test as a
module. But when I follow the steps written here, I do not see driver
probing. So "test" file never gets created under
/sys/kernel/debug/mmc2/mmc2\:001/.
Can you please help me out here by pointing out what I am doing wrong? I
know this is a very old thread but it's worth a shot!
Thanks,
SP
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-11-20 2:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-10 7:10 [PATCH] mmc_test: move files from sysfs to debugfs Andy Shevchenko
2010-09-10 7:19 ` Adrian Hunter
2010-09-10 7:19 ` Adrian Hunter
2010-09-10 12:47 ` [PATCHv2] " Andy Shevchenko
2010-09-10 20:29 ` [PATCH] " Greg KH
2010-09-10 20:29 ` Greg KH
2013-11-20 1:56 ` spalav
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.