Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 347182
b: refs/heads/master
c: 22a8578
h: refs/heads/master
v: v3
  • Loading branch information
Ezequiel Garcia authored and Artem Bityutskiy committed Nov 21, 2012
1 parent 74324b2 commit 20346ab
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9329c5eb5b087d6e6af905bd7e4f7eee13f9f7e5
refs/heads/master: 22a8578fca5a47e643bb4f70c232d0ec84db9e4e
47 changes: 15 additions & 32 deletions trunk/drivers/mtd/mtd_blkdevs.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <linux/hdreg.h>
#include <linux/init.h>
#include <linux/mutex.h>
#include <linux/kthread.h>
#include <asm/uaccess.h>

#include "mtdcore.h"
Expand Down Expand Up @@ -121,24 +120,22 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,

int mtd_blktrans_cease_background(struct mtd_blktrans_dev *dev)
{
if (kthread_should_stop())
return 1;

return dev->bg_stop;
}
EXPORT_SYMBOL_GPL(mtd_blktrans_cease_background);

static int mtd_blktrans_thread(void *arg)
static void mtd_blktrans_work(struct work_struct *work)
{
struct mtd_blktrans_dev *dev = arg;
struct mtd_blktrans_dev *dev =
container_of(work, struct mtd_blktrans_dev, work);
struct mtd_blktrans_ops *tr = dev->tr;
struct request_queue *rq = dev->rq;
struct request *req = NULL;
int background_done = 0;

spin_lock_irq(rq->queue_lock);

while (!kthread_should_stop()) {
while (1) {
int res;

dev->bg_stop = false;
Expand All @@ -156,15 +153,7 @@ static int mtd_blktrans_thread(void *arg)
background_done = !dev->bg_stop;
continue;
}
set_current_state(TASK_INTERRUPTIBLE);

if (kthread_should_stop())
set_current_state(TASK_RUNNING);

spin_unlock_irq(rq->queue_lock);
schedule();
spin_lock_irq(rq->queue_lock);
continue;
break;
}

spin_unlock_irq(rq->queue_lock);
Expand All @@ -185,8 +174,6 @@ static int mtd_blktrans_thread(void *arg)
__blk_end_request_all(req, -EIO);

spin_unlock_irq(rq->queue_lock);

return 0;
}

static void mtd_blktrans_request(struct request_queue *rq)
Expand All @@ -199,10 +186,8 @@ static void mtd_blktrans_request(struct request_queue *rq)
if (!dev)
while ((req = blk_fetch_request(rq)) != NULL)
__blk_end_request_all(req, -ENODEV);
else {
dev->bg_stop = true;
wake_up_process(dev->thread);
}
else
queue_work(dev->wq, &dev->work);
}

static int blktrans_open(struct block_device *bdev, fmode_t mode)
Expand Down Expand Up @@ -437,14 +422,13 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)

gd->queue = new->rq;

/* Create processing thread */
/* TODO: workqueue ? */
new->thread = kthread_run(mtd_blktrans_thread, new,
"%s%d", tr->name, new->mtd->index);
if (IS_ERR(new->thread)) {
ret = PTR_ERR(new->thread);
/* Create processing workqueue */
new->wq = alloc_workqueue("%s%d", 0, 0,
tr->name, new->mtd->index);
if (!new->wq)
goto error4;
}
INIT_WORK(&new->work, mtd_blktrans_work);

gd->driverfs_dev = &new->mtd->dev;

if (new->readonly)
Expand Down Expand Up @@ -484,9 +468,8 @@ int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
/* Stop new requests to arrive */
del_gendisk(old->disk);


/* Stop the thread */
kthread_stop(old->thread);
/* Stop workqueue. This will perform any pending request. */
destroy_workqueue(old->wq);

/* Kill current requests */
spin_lock_irqsave(&old->queue_lock, flags);
Expand Down
4 changes: 3 additions & 1 deletion trunk/include/linux/mtd/blktrans.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <linux/mutex.h>
#include <linux/kref.h>
#include <linux/sysfs.h>
#include <linux/workqueue.h>

struct hd_geometry;
struct mtd_info;
Expand All @@ -43,7 +44,8 @@ struct mtd_blktrans_dev {
struct kref ref;
struct gendisk *disk;
struct attribute_group *disk_attributes;
struct task_struct *thread;
struct workqueue_struct *wq;
struct work_struct work;
struct request_queue *rq;
spinlock_t queue_lock;
void *priv;
Expand Down

0 comments on commit 20346ab

Please sign in to comment.