[RHEL7,COMMIT] fs/fuse kio: make req_classify callback

Submitted by Konstantin Khorenko on May 27, 2019, 4:07 p.m.

Details

Message ID 201905271607.x4RG7KFN010370@finist-ce7.sw.ru
State New
Series "Series without cover letter"
Headers show

Commit Message

Konstantin Khorenko May 27, 2019, 4:07 p.m.
The commit is pushed to "branch-rh7-3.10.0-957.12.2.vz7.96.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.12.2.vz7.96.5
------>
commit 508d1e5d41a2fe347712060ae56e7a8dc80649e2
Author: Pavel Butsykin <pbutsykin@virtuozzo.com>
Date:   Mon May 27 19:07:20 2019 +0300

    fs/fuse kio: make req_classify callback
    
    This is preparation patch that splits kio.op->req_send() into two callbacks -
    kio.op->req_classify() and kio.op->req_send(). This patch is cosmetic and it's
    necessary for implementation of the next patch.
    
    Signed-off-by: Pavel Butsykin <pbutsykin@virtuozzo.com>
    Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 fs/fuse/dev.c                      | 29 ++++++++++++++++++++++-------
 fs/fuse/fuse_i.h                   |  6 ++++--
 fs/fuse/kio/pcs/pcs_fuse_kdirect.c | 38 ++++++++++++++++++++++++--------------
 3 files changed, 50 insertions(+), 23 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index a3e9e7aacafa..3e0fecbe8db3 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -401,9 +401,14 @@  static void flush_bg_queue(struct fuse_conn *fc, struct fuse_iqueue *fiq)
 		list_del_init(&req->list);
 		fc->active_background++;
 
-		if (fc->kio.op && !fc->kio.op->req_send(fc, req, NULL, true, true))
-			continue;
-
+		if (fc->kio.op) {
+			int ret = fc->kio.op->req_classify(fc, req, true, true);
+			if (likely(!ret)) {
+				fc->kio.op->req_send(fc, req, NULL, true, true);
+				continue;
+			} else if (ret < 0)
+				continue;
+		}
 		spin_lock(&fiq->waitq.lock);
 		req->in.h.unique = fuse_get_unique(fiq);
 		queue_request(fiq, req);
@@ -555,8 +560,13 @@  static void __fuse_request_send(struct fuse_conn *fc, struct fuse_req *req,
 
 	BUG_ON(test_bit(FR_BACKGROUND, &req->flags));
 
-	if (fc->kio.op && !fc->kio.op->req_send(fc, req, ff, false, false))
-		return;
+	if (fc->kio.op) {
+		int ret = fc->kio.op->req_classify(fc, req, false, false);
+		if (likely(!ret))
+			return fc->kio.op->req_send(fc, req, ff, false, false);
+		else if (ret < 0)
+			return;
+	}
 
 	spin_lock(&fiq->waitq.lock);
 	if (!fiq->connected) {
@@ -646,8 +656,13 @@  void fuse_request_send_background(struct fuse_conn *fc, struct fuse_req *req)
 {
 	WARN_ON(!req->end);
 
-	if (fc->kio.op && !fc->kio.op->req_send(fc, req, NULL, true, false))
-		return;
+	if (fc->kio.op) {
+		int ret = fc->kio.op->req_classify(fc, req, true, false);
+		if (likely(!ret))
+			return fc->kio.op->req_send(fc, req, NULL, true, false);
+		else if (ret < 0)
+			return;
+	}
 
 	if (!fuse_request_queue_background(fc, req)) {
 		if (!req->out.h.error)
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index ba6d5eeed3b4..7978a1d891d2 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -527,8 +527,10 @@  struct fuse_kio_ops {
 	/* Request handling hooks */
 	struct fuse_req *(*req_alloc)(struct fuse_conn *fc, unsigned nrpages,
 				      gfp_t flags);
-	int (*req_send)(struct fuse_conn *fc, struct fuse_req *req,
-			struct fuse_file *ff, bool bg, bool locked);
+	int (*req_classify)(struct fuse_conn *fc, struct fuse_req *req, bool bg,
+			    bool locked);
+	void (*req_send)(struct fuse_conn *fc, struct fuse_req *req,
+			 struct fuse_file *ff, bool bg, bool locked);
 
 	/* Inode scope hooks */
 	int  (*file_open)(struct fuse_conn *fc, struct file *file,
diff --git a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
index 8418d93ac5c4..a101d3950373 100644
--- a/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
+++ b/fs/fuse/kio/pcs/pcs_fuse_kdirect.c
@@ -1222,8 +1222,8 @@  static int pcs_kio_classify_req(struct fuse_conn *fc, struct fuse_req *req, bool
 	return -EINVAL;
 }
 
-static int kpcs_req_send(struct fuse_conn* fc, struct fuse_req *req,
-			 struct fuse_file *ff, bool bg, bool lk)
+static int kpcs_req_classify(struct fuse_conn* fc, struct fuse_req *req,
+			     bool bg, bool lk)
 {
 	struct pcs_fuse_cluster *pfc = (struct pcs_fuse_cluster*)fc->kio.ctx;
 	int ret;
@@ -1232,14 +1232,13 @@  static int kpcs_req_send(struct fuse_conn* fc, struct fuse_req *req,
 		return 1;
 
 	BUG_ON(!pfc);
-	/* HYPOTHESIS #1
-	 * IFAIU at this point request can not belongs to any list
-	 * so I cant avoid grab fc->lock here at all
+	/* At this point request can not belongs to any list
+	 * so we can avoid grab fc->lock here at all.
 	 */
 	BUG_ON(!list_empty(&req->list));
 
-	TRACE(" Enter req:%p op:%d end:%p bg:%d lk:%d\n", req, req->in.h.opcode, req->end, bg, lk);
-
+	DTRACE("Classify req:%p op:%d end:%p bg:%d lk:%d\n", req, req->in.h.opcode,
+							  req->end, bg, lk);
 	ret = pcs_kio_classify_req(fc, req, lk);
 	if (ret) {
 		if (ret < 0) {
@@ -1252,15 +1251,12 @@  static int kpcs_req_send(struct fuse_conn* fc, struct fuse_req *req,
 			request_end(fc, req);
 			if (lk)
 				spin_lock(&fc->bg_lock);
-			return 0;
+			return ret;
 		}
 		return 1;
 	}
 
-	/* request_end below will do fuse_put_request() */
-	if (!bg)
-		atomic_inc(&req->count);
-	else if (!lk) {
+	if (!lk) {
 		spin_lock(&fc->bg_lock);
 		if (fc->num_background + 1 >= fc->max_background ||
 		    !fc->connected) {
@@ -1277,14 +1273,27 @@  static int kpcs_req_send(struct fuse_conn* fc, struct fuse_req *req,
 		}
 		spin_unlock(&fc->bg_lock);
 	}
+       return 0;
+}
+
+static void kpcs_req_send(struct fuse_conn* fc, struct fuse_req *req,
+			  struct fuse_file *ff, bool bg, bool lk)
+{
+       struct pcs_fuse_cluster *pfc = (struct pcs_fuse_cluster*)fc->kio.ctx;
+
+       TRACE("Send req:%p op:%d end:%p bg:%d lk:%d\n",
+               req, req->in.h.opcode, req->end, bg, lk);
+
+       /* request_end below will do fuse_put_request() */
+       if (!bg)
+               atomic_inc(&req->count);
 	__clear_bit(FR_PENDING, &req->flags);
 
 	pcs_fuse_submit(pfc, req, ff ? : req->ff, lk, lk);
 	if (!bg)
 		wait_event(req->waitq,
 			   test_bit(FR_FINISHED, &req->flags) && !req->end);
-
-	return 0;
+	return;
 }
 
 static void fuse_trace_free(struct fuse_ktrace *tr)
@@ -1595,6 +1604,7 @@  static struct fuse_kio_ops kio_pcs_ops = {
 	.conn_fini	= kpcs_conn_fini,
 	.conn_abort	= kpcs_conn_abort,
 	.req_alloc	= kpcs_req_alloc,
+	.req_classify	= kpcs_req_classify,
 	.req_send	= kpcs_req_send,
 	.file_open	= kpcs_file_open,
 	.inode_release	= kpcs_inode_release,