From: Richard Weinberger <richard@nod.at>
To: linux-mtd@lists.infradead.org
Cc: boris.brezillon@free-electrons.com, dedekind1@gmail.com,
goliath@sigma-star.at, alex@nextthing.co, beanhuo@micron.com,
Richard Weinberger <richard@nod.at>
Subject: [PATCH 13/13] ubi: Add debugfs knob to trigger LEB consolidation
Date: Mon, 30 May 2016 14:04:34 +0200 [thread overview]
Message-ID: <1464609874-15488-14-git-send-email-richard@nod.at> (raw)
In-Reply-To: <1464609874-15488-1-git-send-email-richard@nod.at>
...useful in combination with force_leb_consolidation
to test the worker.
Signed-off-by: Richard Weinberger <richard@nod.at>
---
drivers/mtd/ubi/consolidate.c | 14 ++++++++++++++
drivers/mtd/ubi/debug.c | 12 ++++++++++++
drivers/mtd/ubi/ubi.h | 5 +++++
drivers/mtd/ubi/work.c | 42 +++++++++++++++++++++++++++++-------------
4 files changed, 60 insertions(+), 13 deletions(-)
diff --git a/drivers/mtd/ubi/consolidate.c b/drivers/mtd/ubi/consolidate.c
index 7313be0..61b9903 100644
--- a/drivers/mtd/ubi/consolidate.c
+++ b/drivers/mtd/ubi/consolidate.c
@@ -359,6 +359,20 @@ void ubi_conso_schedule(struct ubi_device *ubi)
BUG();
}
+int ubi_conso_sync(struct ubi_device *ubi)
+{
+ int ret = -ENOMEM;
+
+ struct ubi_work *wrk = ubi_alloc_work(ubi);
+
+ if (wrk) {
+ wrk->func = &consolidation_worker;
+ ret = ubi_schedule_work_sync(ubi, wrk);
+ }
+
+ return ret;
+}
+
void ubi_eba_consolidate(struct ubi_device *ubi)
{
if (consolidation_possible(ubi) && ubi->consolidation_pnum >= 0)
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c
index 14b0ce5..98812bc 100644
--- a/drivers/mtd/ubi/debug.c
+++ b/drivers/mtd/ubi/debug.c
@@ -378,6 +378,11 @@ static ssize_t dfs_file_write(struct file *file, const char __user *user_buf,
d->emulate_io_failures = val;
else if (dent == d->dfs_force_leb_consolidation)
d->force_leb_consolidation = val;
+ else if (dent == d->dfs_trigger_leb_consolidation) {
+ val = ubi_conso_sync(ubi);
+ if (val < 0)
+ count = val;
+ }
else
count = -EINVAL;
@@ -490,6 +495,13 @@ int ubi_debugfs_init_dev(struct ubi_device *ubi)
if (IS_ERR_OR_NULL(dent))
goto out_remove;
d->dfs_force_leb_consolidation = dent;
+
+ fname = "trigger_leb_consolidation";
+ dent = debugfs_create_file(fname, S_IWUSR, d->dfs_dir, (void *)ubi_num,
+ &dfs_fops);
+ if (IS_ERR_OR_NULL(dent))
+ goto out_remove;
+ d->dfs_trigger_leb_consolidation = dent;
return 0;
out_remove:
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 15c8ff6..f022e9a 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -449,6 +449,7 @@ struct ubi_debug_info {
struct dentry *dfs_emulate_bitflips;
struct dentry *dfs_emulate_io_failures;
struct dentry *dfs_force_leb_consolidation;
+ struct dentry *dfs_trigger_leb_consolidation;
struct dentry *dfs_emulate_power_cut;
struct dentry *dfs_power_cut_min;
struct dentry *dfs_power_cut_max;
@@ -932,6 +933,7 @@ bool ubi_conso_invalidate_leb(struct ubi_device *ubi, int pnum,
int ubi_coso_add_full_leb(struct ubi_device *ubi, int vol_id, int lnum, int lpos);
int ubi_conso_init(struct ubi_device *ubi);
void ubi_conso_close(struct ubi_device *ubi);
+int ubi_conso_sync(struct ubi_device *ubi);
#else
static inline bool ubi_conso_consolidation_needed(struct ubi_device *ubi)
{
@@ -954,6 +956,7 @@ static inline int ubi_coso_add_full_leb(struct ubi_device *ubi, int vol_id, int
}
static inline int ubi_conso_init(struct ubi_device *ubi) { return 0; }
static inline void ubi_conso_close(struct ubi_device *ubi) {}
+static inline int ubi_conso_sync(struct ubi_device *ubi) { return 0; }
#endif
/* wl.c */
@@ -982,6 +985,8 @@ bool ubi_work_join_one(struct ubi_device *ubi);
struct ubi_work *ubi_alloc_erase_work(struct ubi_device *ubi,
struct ubi_wl_entry *e,
int torture);
+int ubi_schedule_work_sync(struct ubi_device *ubi, struct ubi_work *wrk);
+
/* io.c */
int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
int len);
diff --git a/drivers/mtd/ubi/work.c b/drivers/mtd/ubi/work.c
index d2f8ba8..cd1c38b 100644
--- a/drivers/mtd/ubi/work.c
+++ b/drivers/mtd/ubi/work.c
@@ -18,6 +18,18 @@ static bool work_suspended(struct ubi_device *ubi)
return ubi->thread_suspended || !ubi->thread_enabled;
}
+/**
+ * destroy_work - destroy an UBI work.
+ * @ref: kref object
+ *
+ * This function is called by kref upon the last reference is gone.
+ */
+static void destroy_work(struct kref *ref)
+{
+ struct ubi_work *wrk = container_of(ref, struct ubi_work, ref);
+
+ kfree(wrk);
+}
/**
* ubi_schedule_work - schedule a work.
@@ -42,6 +54,23 @@ void ubi_schedule_work(struct ubi_device *ubi, struct ubi_work *wrk)
mutex_unlock(&ubi->work_mutex);
}
+int ubi_schedule_work_sync(struct ubi_device *ubi, struct ubi_work *wrk)
+{
+ int ret;
+
+ kref_get(&wrk->ref);
+
+ ubi_schedule_work(ubi, wrk);
+ wait_for_completion(&wrk->comp);
+
+ spin_lock(&ubi->wl_lock);
+ ret = wrk->ret;
+ kref_put(&wrk->ref, destroy_work);
+ spin_unlock(&ubi->wl_lock);
+
+ return ret;
+}
+
struct ubi_work *ubi_alloc_work(struct ubi_device *ubi)
{
struct ubi_work *wrk;
@@ -57,19 +86,6 @@ struct ubi_work *ubi_alloc_work(struct ubi_device *ubi)
return wrk;
}
-/**
- * destroy_work - destroy an UBI work.
- * @ref: kref object
- *
- * This function is called by kref upon the last reference is gone.
- */
-static void destroy_work(struct kref *ref)
-{
- struct ubi_work *wrk = container_of(ref, struct ubi_work, ref);
-
- kfree(wrk);
-}
-
static void shutdown_work(struct ubi_device *ubi, int error)
{
struct ubi_work *wrk;
--
2.7.3
next prev parent reply other threads:[~2016-05-30 12:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-30 12:04 [RFC] UBI: MLC Support v0 Richard Weinberger
2016-05-30 12:04 ` [PATCH 01/13] ubi: Undo "UBI: modify ubi_wl_flush function to clear work queue for a lnum" Richard Weinberger
2016-05-30 12:04 ` [PATCH 02/13] ubi: Rework UBI worker Richard Weinberger
2016-05-30 12:04 ` [PATCH 03/13] ubi: auto re-size after UBI thread is ready Richard Weinberger
2016-05-30 12:04 ` [PATCH 04/13] ubi: Kill ubi->alc_mutex Richard Weinberger
2016-05-30 14:05 ` Richard Weinberger
2016-05-30 12:04 ` [PATCH 05/13] ubi: Get rid of __schedule_ubi_work() Richard Weinberger
2016-05-30 12:04 ` [PATCH 06/13] ubi: Remove tst_disable_bgt debugfs knob Richard Weinberger
2016-05-30 12:04 ` [PATCH 07/13] ubi: Move work related functions to work.c Richard Weinberger
2016-05-30 12:04 ` [PATCH 08/13] ubi: Remove lnum and vol_id from erase work Richard Weinberger
2016-05-30 12:04 ` [PATCH 09/13] ubi: Remove usless debug info from wear_leveling_worker() Richard Weinberger
2016-05-30 12:04 ` [PATCH 10/13] ubi: SLC mode Richard Weinberger
2016-05-30 12:04 ` [PATCH 11/13] ubi: LEB consolidation Richard Weinberger
2016-06-07 12:20 ` Boris Brezillon
2016-05-30 12:04 ` [PATCH 12/13] ubi: Add debugfs knob to force " Richard Weinberger
2016-05-30 12:04 ` Richard Weinberger [this message]
2016-06-03 12:40 ` [RFC] UBI: MLC Support v0 Boris Brezillon
2016-06-24 14:48 ` Bean Huo (beanhuo)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1464609874-15488-14-git-send-email-richard@nod.at \
--to=richard@nod.at \
--cc=alex@nextthing.co \
--cc=beanhuo@micron.com \
--cc=boris.brezillon@free-electrons.com \
--cc=dedekind1@gmail.com \
--cc=goliath@sigma-star.at \
--cc=linux-mtd@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).