[Devel,rh7,1/3] ploop: factor ->write_page() out

Submitted by Maxim Patlasov on July 21, 2016, 2:01 a.m.

Details

Message ID 20160721020045.13387.26079.stgit@maxim-thinkpad
State New
Series "Series without cover letter"
Headers show

Commit Message

Maxim Patlasov July 21, 2016, 2:01 a.m.
Simple re-work. No logic changed. Will be useful for the next patch.

Signed-off-by: Maxim Patlasov <mpatlasov@virtuozzo.com>
---
 drivers/block/ploop/map.c   |   39 +++++++++++++++++++++++++--------------
 include/linux/ploop/ploop.h |    2 ++
 2 files changed, 27 insertions(+), 14 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/map.c b/drivers/block/ploop/map.c
index 1883674..5f7fd66 100644
--- a/drivers/block/ploop/map.c
+++ b/drivers/block/ploop/map.c
@@ -896,6 +896,25 @@  static void copy_index_for_wb(struct page * page, struct map_node * m, int level
 	}
 }
 
+
+void ploop_index_wb_proceed(struct ploop_request * preq)
+{
+	struct map_node * m = preq->map;
+	struct ploop_delta * top_delta = map_top_delta(m->parent);
+	struct page * page = preq->sinfo.wi.tpage;
+	unsigned long rw = preq->req_index_update_rw;
+	sector_t sec;
+
+	preq->eng_state = PLOOP_E_INDEX_WB;
+
+	top_delta->ops->map_index(top_delta, m->mn_start, &sec);
+
+	__TRACE("wbi-proceed %p %u %p\n", preq, preq->req_cluster, m);
+	top_delta->io.ops->write_page(&top_delta->io, preq, page, sec, rw);
+
+	put_page(page);
+}
+
 /* Data write is commited. Now we need to update index. */
 
 void ploop_index_update(struct ploop_request * preq)
@@ -907,8 +926,6 @@  void ploop_index_update(struct ploop_request * preq)
 	map_index_t blk;
 	int old_level;
 	struct page * page;
-	sector_t sec;
-	unsigned long rw;
 	unsigned long state = READ_ONCE(preq->state);
 
 	/* No way back, we are going to initiate index write. */
@@ -955,15 +972,13 @@  void ploop_index_update(struct ploop_request * preq)
 
 	((map_index_t*)page_address(page))[idx] = preq->iblock << ploop_map_log(plo);
 
-	preq->eng_state = PLOOP_E_INDEX_WB;
 	get_page(page);
 	preq->sinfo.wi.tpage = page;
 
 	__TRACE("wbi %p %u %p\n", preq, preq->req_cluster, m);
 	plo->st.map_single_writes++;
-	top_delta->ops->map_index(top_delta, m->mn_start, &sec);
 
-	rw = (preq->req_rw & (REQ_FUA | REQ_FLUSH));
+	preq->req_index_update_rw = (preq->req_rw & (REQ_FUA | REQ_FLUSH));
 
 	/* We've just set REQ_FLUSH in rw, ->write_page() below
 	   will do the FLUSH */
@@ -971,11 +986,9 @@  void ploop_index_update(struct ploop_request * preq)
 
 	/* Relocate requires consistent index update */
 	if (state & (PLOOP_REQ_RELOC_A_FL|PLOOP_REQ_RELOC_S_FL))
-		rw |= (REQ_FLUSH | REQ_FUA);
+		preq->req_index_update_rw |= (REQ_FLUSH | REQ_FUA);
 
-	top_delta->io.ops->write_page(&top_delta->io, preq, page, sec, rw);
-
-	put_page(page);
+	ploop_index_wb_proceed(preq);
 	return;
 
 enomem:
@@ -991,6 +1004,7 @@  out:
 }
 EXPORT_SYMBOL(ploop_index_update);
 
+
 int map_index(struct ploop_delta * delta, struct ploop_request * preq, unsigned long *sec)
 {
 	return delta->ops->map_index(delta, preq->map->mn_start, sec);
@@ -1094,7 +1108,6 @@  static void map_wb_complete(struct map_node * m, int err)
 	struct page * page = NULL;
 	int delayed = 0;
 	unsigned int idx;
-	sector_t sec;
 	unsigned long rw;
 
 	/* First, complete processing of written back indices,
@@ -1219,11 +1232,9 @@  static void map_wb_complete(struct map_node * m, int err)
 
 	__TRACE("wbi2 %p %u %p\n", main_preq, main_preq->req_cluster, m);
 	plo->st.map_multi_writes++;
-	top_delta->ops->map_index(top_delta, m->mn_start, &sec);
 
-	top_delta->io.ops->write_page(&top_delta->io, main_preq, page, sec,
-				      rw);
-	put_page(page);
+	main_preq->req_index_update_rw = rw;
+	ploop_index_wb_proceed(main_preq);
 }
 
 void
diff --git a/include/linux/ploop/ploop.h b/include/linux/ploop/ploop.h
index 7864edf..3d52f28 100644
--- a/include/linux/ploop/ploop.h
+++ b/include/linux/ploop/ploop.h
@@ -534,6 +534,7 @@  struct ploop_request
 	sector_t		req_sector;
 	unsigned int		req_size;
 	unsigned int		req_rw;
+	unsigned int		req_index_update_rw;
 	unsigned long		tstamp;
 	struct io_context	*ioc;
 
@@ -803,6 +804,7 @@  void map_init(struct ploop_device *, struct ploop_map * map);
 void ploop_map_start(struct ploop_map * map, u64 bd_size);
 void ploop_map_destroy(struct ploop_map * map);
 void ploop_map_remove_delta(struct ploop_map * map, int level);
+void ploop_index_wb_proceed(struct ploop_request * preq);
 void ploop_index_update(struct ploop_request * preq);
 void ploop_index_wb_complete(struct ploop_request * preq);
 int __init ploop_map_init(void);