[rh7,2/2] ploop: Move duplicated code to a helper

Submitted by Kirill Tkhai on Feb. 14, 2020, 12:23 p.m.

Details

Message ID 158168298588.795662.3801617348109173102.stgit@localhost.localdomain
State New
Series "Series without cover letter"
Headers show

Commit Message

Kirill Tkhai Feb. 14, 2020, 12:23 p.m.
Fix one more pattern of duplicated code.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/map.c |   47 ++++++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/map.c b/drivers/block/ploop/map.c
index 91e3762c691d..99b1eb735469 100644
--- a/drivers/block/ploop/map.c
+++ b/drivers/block/ploop/map.c
@@ -884,6 +884,28 @@  static void ploop_index_wb_proceed_or_delay(struct ploop_request * preq,
 	ploop_index_wb_proceed(preq);
 }
 
+static unsigned long preq_extract_rq_index_update_rw(struct ploop_request *preq,
+						     unsigned long state,
+						     int *do_fsync_if_delayed)
+{
+	unsigned long rw = (preq->req_rw & (REQ_FUA | REQ_FLUSH));
+
+	/* We've just set REQ_FLUSH in rw, ->write_page() below
+	   will do the FLUSH */
+	preq->req_rw &= ~REQ_FLUSH;
+
+	/*
+	 * Relocate and merge require consistent index update.
+	 * FIXME: COW also wants it?
+	 */
+	if (state & (PLOOP_REQ_RELOC_A_FL|PLOOP_REQ_RELOC_S_FL|PLOOP_REQ_MERGE_FL)) {
+		rw |= (REQ_FLUSH | REQ_FUA);
+		*do_fsync_if_delayed = 1;
+	}
+
+	return rw;
+}
+
 /* Data write is commited. Now we need to update index. */
 
 void ploop_index_update(struct ploop_request * preq)
@@ -951,17 +973,8 @@  void ploop_index_update(struct ploop_request * preq)
 	__TRACE("wbi %p %u %p\n", preq, preq->req_cluster, m);
 	plo->st.map_single_writes++;
 
-	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 */
-	preq->req_rw &= ~REQ_FLUSH;
-
-	/* Relocate requires consistent index update */
-	if (state & (PLOOP_REQ_RELOC_A_FL|PLOOP_REQ_RELOC_S_FL|PLOOP_REQ_MERGE_FL)) {
-		preq->req_index_update_rw |= (REQ_FLUSH | REQ_FUA);
-		do_fsync_if_delayed = 1;
-	}
+	preq->req_index_update_rw =
+		preq_extract_rq_index_update_rw(preq, state, &do_fsync_if_delayed);
 
 	ploop_index_wb_proceed_or_delay(preq, do_fsync_if_delayed);
 	return;
@@ -1168,18 +1181,8 @@  static void map_wb_complete(struct map_node * m, int err)
 				break;
 			}
 
-			rw |= (preq->req_rw & (REQ_FLUSH | REQ_FUA));
-
-			/* We've just set REQ_FLUSH in rw, ->write_page() below
-			   will do the FLUSH */
-			preq->req_rw &= ~REQ_FLUSH;
-
 			state = READ_ONCE(preq->state);
-			/* Relocate requires consistent index update */
-			if (state & (PLOOP_REQ_RELOC_A_FL|PLOOP_REQ_RELOC_S_FL|PLOOP_REQ_MERGE_FL)) {
-				rw |= (REQ_FLUSH | REQ_FUA);
-				do_fsync_if_delayed = 1;
-			}
+			rw |= preq_extract_rq_index_update_rw(preq, state, &do_fsync_if_delayed);
 
 			preq->eng_state = PLOOP_E_INDEX_WB;
 			get_page(page);