[RHEL7,COMMIT] ploop: Move duplicated code to a helper

Submitted by Kirill Tkhai on Feb. 19, 2020, 3:06 p.m.

Details

Message ID 202002191506.01JF6sHN370452@localhost.localdomain
State New
Series "Series without cover letter"
Headers show

Commit Message

Kirill Tkhai Feb. 19, 2020, 3:06 p.m.
The commit is pushed to "branch-rh7-3.10.0-1062.12.1.vz7.131.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1062.12.1.vz7.131.3
------>
commit f0bca602e4ff65f28b60de3ed6ca2c6b77171e45
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Wed Feb 19 15:06:54 2020 +0000

    ploop: Move duplicated code to a helper
    
    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 91e3762..99b1eb7 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);