[Devel] [PATCH RFC 2/2] fs/fuse kio: synchronize pcs_cc_process_ireq_ioreq() with userspace

Pavel Butsykin pbutsykin at virtuozzo.com
Wed Jun 5 13:35:40 MSK 2019


This patch is aimed at eliminating discrepancies between fpath and current
vstorage userspace client. In the long run, this will help avoid confusion
and ease backporting patches.

Signed-off-by: Pavel Butsykin <pbutsykin at virtuozzo.com>
---
 fs/fuse/kio/pcs/pcs_cluster.c | 122 ++++++++++++++++++------------------------
 fs/fuse/kio/pcs/pcs_map.c     |  23 +++-----
 2 files changed, 61 insertions(+), 84 deletions(-)

diff --git a/fs/fuse/kio/pcs/pcs_cluster.c b/fs/fuse/kio/pcs/pcs_cluster.c
index 082acea9affa..a0bb9ecb4684 100644
--- a/fs/fuse/kio/pcs/pcs_cluster.c
+++ b/fs/fuse/kio/pcs/pcs_cluster.c
@@ -336,84 +336,45 @@ void pcs_cc_process_ireq_chunk(struct pcs_int_request *ireq)
 	map_submit(map, ireq);
 }
 
-/* TODO Remove noinline in production */
-static noinline void __pcs_cc_process_ireq_rw(struct pcs_int_request *ireq)
+static void process_varchunk_request(struct pcs_int_request *ireq,
+				     struct pcs_flow_node *fl, u64 pos, u64 sz)
 {
 	struct pcs_dentry_info *di = ireq->dentry;
-	u64 pos = ireq->apireq.req->pos;
-	unsigned int sz = ireq->apireq.req->size;
-	unsigned int dio_offset = 0;
-	struct pcs_flow_node *fl;
+	struct pcs_int_request *sreq;
 
-	if (di->fileinfo.sys.map_type != PCS_MAP_PLAIN) {
-		BUG_ON(1);
+	sreq = ireq_alloc(di);
+	if (!sreq) {
+		pcs_set_local_error(&ireq->error, PCS_ERR_NOMEM);
 		return;
 	}
 
-	TRACE(DENTRY_FMT " %p op=%d at %llu [%llu]\n", DENTRY_ARGS(di), ireq, ireq->apireq.req->type,
-	      (unsigned long long)ireq->apireq.req->pos, (unsigned long long)ireq->apireq.req->size);
-
-
-	atomic_set(&ireq->iocount, 1);
-	ireq->flags |= IREQ_F_CACHED;
-
-	fl =  pcs_flow_record(&di->mapping.ftab, ireq->apireq.req->type == PCS_REQ_T_WRITE,
-			      pos, sz, &di->cluster->maps.ftab);
-
-	while (sz) {
-		struct pcs_int_request *sreq;
-		unsigned int len;
-		u64 rpos, chunk, end_pos;
-
-		rpos = map_file_to_chunk(pos, di->fileinfo.sys.chunk_size_lo, di->fileinfo.sys.stripe_depth, di->fileinfo.sys.strip_width);
-
-		chunk = rpos & ~((u64)di->fileinfo.sys.chunk_size_lo - 1);
-		end_pos = ((rpos / di->fileinfo.sys.strip_width) + 1) * (u64)di->fileinfo.sys.strip_width;
-
-		sreq = ireq_alloc(di);
-		if (!sreq) {
-			pcs_set_local_error(&ireq->error, PCS_ERR_NOMEM);
-			break;
-		}
-
-		sreq->dentry = di;
-		sreq->type = PCS_IREQ_IOCHUNK;
-		INIT_LIST_HEAD(&sreq->tok_list);
-		sreq->tok_reserved = 0;
-		sreq->tok_serno = 0;
-		sreq->iochunk.map = NULL;
-		sreq->iochunk.flow = pcs_flow_get(fl);
-		sreq->iochunk.cmd = ireq->apireq.req->type;
-		sreq->iochunk.cs_index = 0;
-		sreq->iochunk.chunk = chunk;
-		sreq->iochunk.offset = rpos % di->fileinfo.sys.chunk_size_lo;
-		sreq->iochunk.dio_offset = dio_offset;
-		len = di->fileinfo.sys.chunk_size_lo - sreq->iochunk.offset;
-		if (len > sz)
-			len = sz;
-		if (rpos + len > end_pos)
-			len = end_pos - rpos;
-		sreq->iochunk.size = len;
-		sreq->iochunk.csl = NULL;
-		sreq->iochunk.banned_cs.val = 0;
-		sreq->iochunk.msg.destructor = NULL;
-		sreq->iochunk.msg.rpc = NULL;
-
-		pcs_sreq_attach(sreq, ireq);
-		sreq->complete_cb = pcs_sreq_complete;
-		pcs_cc_process_ireq_chunk(sreq);
-
-		pos += len;
-		sz -= len;
-		dio_offset += len;
-	}
-	pcs_flow_put(fl, &di->cluster->maps.ftab);
-	if (atomic_dec_and_test(&ireq->iocount))
-		ireq_complete(ireq);
+	sreq->dentry = di;
+	sreq->type = PCS_IREQ_IOCHUNK;
+	INIT_LIST_HEAD(&sreq->tok_list);
+	sreq->tok_reserved = 0;
+	sreq->tok_serno = 0;
+	sreq->iochunk.map = NULL;
+	sreq->iochunk.flow = pcs_flow_get(fl);
+	sreq->iochunk.cmd = ireq->apireq.req->type;
+	sreq->iochunk.cs_index = 0;
+	sreq->iochunk.chunk = pos;
+	sreq->iochunk.offset = 0;
+	sreq->iochunk.dio_offset = 0;
+	sreq->iochunk.size = sz;
+	sreq->iochunk.csl = NULL;
+	sreq->iochunk.banned_cs.val = 0;
+	sreq->iochunk.msg.destructor = NULL;
+	sreq->iochunk.msg.rpc = NULL;
+
+	pcs_sreq_attach(sreq, ireq);
+	sreq->complete_cb = pcs_sreq_complete;
+	pcs_cc_process_ireq_chunk(sreq);
 }
 
 static void pcs_cc_process_ireq_ioreq(struct pcs_int_request *ireq)
 {
+	struct pcs_dentry_info *di = ireq->dentry;
+
 	if (ireq->apireq.req->type == PCS_REQ_T_SYNC) {
 		map_inject_flush_req(ireq);
 		return;
@@ -432,7 +393,30 @@ static void pcs_cc_process_ireq_ioreq(struct pcs_int_request *ireq)
 		ireq_complete(ireq);
 		return;
 	}
-	return __pcs_cc_process_ireq_rw(ireq);
+
+	if (di->fileinfo.sys.map_type == PCS_MAP_PLAIN) {
+		u64 pos = ireq->apireq.req->pos;
+		u64 sz = ireq->apireq.req->size;
+		struct pcs_flow_node *fl;
+
+		TRACE(DENTRY_FMT " %p op=%d at %llu [%llu]\n", DENTRY_ARGS(di),
+		      ireq, ireq->apireq.req->type, (u64)ireq->apireq.req->pos,
+		      (u64)ireq->apireq.req->size);
+
+		atomic_set(&ireq->iocount, 1);
+		ireq->flags |= IREQ_F_CACHED;
+
+		fl =  pcs_flow_record(&di->mapping.ftab,
+				      pcs_req_direction(ireq->apireq.req->type),
+				      pos, sz, &di->cluster->maps.ftab);
+
+		BUG_ON(di->fileinfo.sys.stripe_depth != 1);
+		process_varchunk_request(ireq, fl, pos, sz);
+		pcs_flow_put(fl, &di->cluster->maps.ftab);
+		if (atomic_dec_and_test(&ireq->iocount))
+			ireq_complete(ireq);
+	} else
+		BUG_ON(1);
 }
 
 static void process_ireq_token(struct pcs_int_request * ireq)
diff --git a/fs/fuse/kio/pcs/pcs_map.c b/fs/fuse/kio/pcs/pcs_map.c
index 70be51b025d9..273697b840ff 100644
--- a/fs/fuse/kio/pcs/pcs_map.c
+++ b/fs/fuse/kio/pcs/pcs_map.c
@@ -2337,29 +2337,22 @@ void map_submit(struct pcs_map_entry * m, struct pcs_int_request *ireq)
 
 		if (ireq->type != PCS_IREQ_FLUSH && !(ireq->flags & IREQ_F_MAPPED)) {
 			u64 pos = ireq->iochunk.chunk + ireq->iochunk.offset;
-			u64 len = map_end - pos;
-
-			/*
-			 * For non variable chunks all alligment should be done
-			 * inside pcs_cc_process_ireq_ioreq();
-			 */
 			BUG_ON(pos < map_start);
-			BUG_ON(ireq->iochunk.chunk != map_start);
-			BUG_ON(ireq->iochunk.offset != pos - ireq->iochunk.chunk);
-			if (ireq->iochunk.size > len) {
+			ireq->iochunk.chunk = map_start;
+			ireq->iochunk.offset = pos - ireq->iochunk.chunk;
+			if (pos + ireq->iochunk.size > map_end) {
 				if (ireq->iochunk.cmd == PCS_REQ_T_FIEMAP) {
-					pcs_api_iorequest_t * ar = ireq->completion_data.parent->apireq.req;
-					ireq->iochunk.size = len;
+					pcs_api_iorequest_t *ar = ireq->completion_data.parent->apireq.req;
+					ireq->iochunk.size = map_end - pos;
 					ar->size = ireq->iochunk.size;
 				} else {
-					struct pcs_int_request * sreq;
-
-					sreq = pcs_ireq_split(ireq, len, 0);
+					struct pcs_int_request *sreq;
+					sreq = pcs_ireq_split(ireq, map_end - pos, 0);
 					if (ireq->iochunk.map) {
 						pcs_map_put(ireq->iochunk.map);
 						ireq->iochunk.map = NULL;
 					}
-					ireq->iochunk.chunk = map_end;
+					ireq->iochunk.chunk += ireq->iochunk.offset;
 					ireq->iochunk.offset = 0;
 					pcs_cc_submit(ireq->dentry->cluster, ireq);
 					ireq = sreq;
-- 
2.15.1



More information about the Devel mailing list