mtd: mtd_blkdevs: handle REQ_FLUSH request and do explicit flush of writeback buffer
PATCH 1/1 mtd: mtd_blkdevs: handle REQ_FLUSH request and do explicit flush of writeback buffer
From: Roman Peniaev <[email protected]>
mtd_blkdevs is device with volatile cache (writeback buffer), so it should support REQ_FLUSH to do explicit flush.
Without this patch 'sync' does not guarantee that writeback buffer will be flushed on disk in case of power off, e.g.:
$ cp some_file /mnt $ sync
### POWER OFF
In case of this sequence writeback buffer will not be flushed on disk.
This patch fixes this behaviour and explicitly reports to block layer that flush requests are being supported.
--- drivers/mtd/mtd_blkdevs.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/mtd/mtd_blkdevs.c +8 -0
@@ -89,6 +89,12 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,if (req->cmd_type !=REQ_TYPE_FS )return -EIO ; +if (req->cmd_flags &REQ_FLUSH ) { +if (tr->flush) +return tr->flush (dev); +return 0 ; + } +if (blk_rq_pos (req) +blk_rq_cur_sectors (req) >get_capacity (req->rq_disk))return -EIO ;
@@ -409,6 +415,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)if (!new->rq) goto error3; +blk_queue_flush (new->rq,REQ_FLUSH ); + new->rq->queuedata = new;blk_queue_logical_block_size (new->rq, tr->blksize);
Signature · 1 line
1.8.5.2
Quoted 44 lines · Roman Pen
From: Roman Peniaev <[email protected]>
mtd_blkdevsis device with volatile cache (writeback buffer), so it should supportREQ_FLUSHto do explicit flush.Without this patch 'sync' does not guarantee that writeback buffer will be flushed on disk in case of power off, e.g.:
$ cp some_file /mnt $ sync### POWER OFF
In case of this sequence writeback buffer will not be flushed on disk.
This patch fixes this behaviour and explicitly reports to block layer that flush requests are being supported.
Signed-off-by Roman Peniaev <[email protected]>CC David Woodhouse <[email protected]>--- drivers/mtd/mtd_blkdevs.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/mtd/mtd_blkdevs.c +6
-0@@ -89,6 +89,12 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,if (req->cmd_type !=REQ_TYPE_FS )return -EIO ; +if (req->cmd_flags &REQ_FLUSH ) { +if (tr->flush) +return tr->flush (dev); +return 0 ; + } +if (blk_rq_pos (req) +blk_rq_cur_sectors (req) >get_capacity (req->rq_disk))return -EIO ;
drivers/mtd/mtd_blkdevs.c int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) · line 418
Quoted 4 lines
drivers/mtd/mtd_blkdevs.c +1
-0@@ -409,6 +415,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)if (!new->rq) goto error3; +blk_queue_flush (new->rq,REQ_FLUSH );
How about only registering the flush command if we support it? So:
if (tr->flush) blk_queue_flush(new->rq, REQ_FLUSH);
Then you can probably also change the earlier hunk to the following, no?
if (req->cmd_flags & REQ_FLUSH) return tr->flush(dev);
drivers/mtd/mtd_blkdevs.c int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) · line 422
Quoted 4 lines
drivers/mtd/mtd_blkdevs.c +1
-0+ new->rq->queuedata = new;blk_queue_logical_block_size (new->rq, tr->blksize);
Brian
Quoted 48 lines · Brian Norris
Quoted 47 lines · Roman Pen
From: Roman Peniaev <[email protected]>
mtd_blkdevsis device with volatile cache (writeback buffer), so it should supportREQ_FLUSHto do explicit flush.Without this patch 'sync' does not guarantee that writeback buffer will be flushed on disk in case of power off, e.g.:
$ cp some_file /mnt $ sync### POWER OFF
In case of this sequence writeback buffer will not be flushed on disk.
This patch fixes this behaviour and explicitly reports to block layer that flush requests are being supported.
Signed-off-by Roman Peniaev <[email protected]>CC David Woodhouse <[email protected]>--- drivers/mtd/mtd_blkdevs.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/mtd/mtd_blkdevs.c +6
-0@@ -89,6 +89,12 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr,if (req->cmd_type !=REQ_TYPE_FS )return -EIO ; +if (req->cmd_flags &REQ_FLUSH ) { +if (tr->flush) +return tr->flush (dev); +return 0 ; + } +if (blk_rq_pos (req) +blk_rq_cur_sectors (req) >get_capacity (req->rq_disk))return -EIO ;@@ -409,6 +415,8 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)if (!new->rq) goto error3;
Quoted 6 lines
drivers/mtd/mtd_blkdevs.c int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) · line 418
Quoted 1 line
drivers/mtd/mtd_blkdevs.c +1
-0+blk_queue_flush (new->rq,REQ_FLUSH );How about only registering the flush command if we support it? So:
if (tr->flush) blk_queue_flush(new->rq, REQ_FLUSH);
Yep, that's better.
Will send v2.
--
Roman
Quoted 12 lines
Then you can probably also change the earlier hunk to the following, no?
if (req->cmd_flags & REQ_FLUSH) return tr->flush(dev);drivers/mtd/mtd_blkdevs.c int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) · line 422
Quoted 4 lines
drivers/mtd/mtd_blkdevs.c +1
-0+ new->rq->queuedata = new;blk_queue_logical_block_size (new->rq, tr->blksize);Brian