All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Brandenburg <martin@omnibond.com>
To: hubcap@omnibond.com
Cc: Martin Brandenburg <martin@omnibond.com>, linux-fsdevel@vger.kernel.org
Subject: [PATCH] orangefs: free readdir buffer index before the dir_emit loop
Date: Wed, 17 Feb 2016 12:55:42 -0500	[thread overview]
Message-ID: <1455731742-14789-1-git-send-email-martin@omnibond.com> (raw)

We only need it while the service operation is actually in progress
since it is only used to co-ordinate the client-core's memory use. The
kernel allocates its own space.

Also clean up some comments which mislead the reader into thinking
the readdir buffers are shared memory.

Signed-off-by: Martin Brandenburg <martin@omnibond.com>
---
 fs/orangefs/dir.c | 34 +++++++++-------------------------
 1 file changed, 9 insertions(+), 25 deletions(-)

diff --git a/fs/orangefs/dir.c b/fs/orangefs/dir.c
index c9b8d0c..43e3aeb 100644
--- a/fs/orangefs/dir.c
+++ b/fs/orangefs/dir.c
@@ -9,7 +9,6 @@
 #include "orangefs-bufmap.h"
 
 struct readdir_handle_s {
-	int buffer_index;
 	struct orangefs_readdir_response_s readdir_response;
 	void *dents_buf;
 };
@@ -143,7 +142,7 @@ out:
 }
 
 static long readdir_handle_ctor(struct readdir_handle_s *rhandle, void *buf,
-				size_t size, int buffer_index)
+				size_t size)
 {
 	long ret;
 
@@ -152,17 +151,10 @@ static long readdir_handle_ctor(struct readdir_handle_s *rhandle, void *buf,
 		    ("Invalid NULL buffer specified in readdir_handle_ctor\n");
 		return -ENOMEM;
 	}
-	if (buffer_index < 0) {
-		gossip_err
-		    ("Invalid buffer index specified in readdir_handle_ctor\n");
-		return -EINVAL;
-	}
-	rhandle->buffer_index = buffer_index;
 	rhandle->dents_buf = buf;
 	ret = decode_dirents(buf, size, &rhandle->readdir_response);
 	if (ret < 0) {
 		gossip_err("Could not decode readdir from buffer %ld\n", ret);
-		rhandle->buffer_index = -1;
 		gossip_debug(GOSSIP_DIR_DEBUG, "vfree %p\n", buf);
 		vfree(buf);
 		rhandle->dents_buf = NULL;
@@ -179,10 +171,6 @@ static void readdir_handle_dtor(struct readdir_handle_s *rhandle)
 	kfree(rhandle->readdir_response.dirent_array);
 	rhandle->readdir_response.dirent_array = NULL;
 
-	if (rhandle->buffer_index >= 0) {
-		orangefs_readdir_index_put(rhandle->buffer_index);
-		rhandle->buffer_index = -1;
-	}
 	if (rhandle->dents_buf) {
 		gossip_debug(GOSSIP_DIR_DEBUG, "vfree %p\n",
 			     rhandle->dents_buf);
@@ -236,7 +224,6 @@ static int orangefs_readdir(struct file *file, struct dir_context *ctx)
 		     "orangefs_readdir called on %s (pos=%llu)\n",
 		     dentry->d_name.name, llu(pos));
 
-	rhandle.buffer_index = -1;
 	rhandle.dents_buf = NULL;
 	memset(&rhandle.readdir_response, 0, sizeof(rhandle.readdir_response));
 
@@ -244,6 +231,10 @@ static int orangefs_readdir(struct file *file, struct dir_context *ctx)
 	if (!new_op)
 		return -ENOMEM;
 
+	/*
+	 * Only the indices are shared. No memory is actually shared, but the
+	 * mechanism is used.
+	 */
 	new_op->uses_shared_memory = 1;
 	new_op->upcall.req.readdir.refn = orangefs_inode->refn;
 	new_op->upcall.req.readdir.max_dirent_count =
@@ -274,23 +265,19 @@ get_new_buffer_index:
 		     new_op->downcall.status,
 		     ret);
 
+	orangefs_readdir_index_put(buffer_index);
+
 	if (ret == -EAGAIN && op_state_purged(new_op)) {
-		/*
-		 * readdir shared memory aread has been wiped due to
-		 * pvfs2-client-core restarting, so we must get a new
-		 * index into the shared memory.
-		 */
+		/* Client-core indices are invalid after it restarted. */
 		gossip_debug(GOSSIP_DIR_DEBUG,
 			"%s: Getting new buffer_index for retry of readdir..\n",
 			 __func__);
-		orangefs_readdir_index_put(buffer_index);
 		goto get_new_buffer_index;
 	}
 
 	if (ret == -EIO && op_state_purged(new_op)) {
 		gossip_err("%s: Client is down. Aborting readdir call.\n",
 			__func__);
-		orangefs_readdir_index_put(buffer_index);
 		goto out_free_op;
 	}
 
@@ -298,7 +285,6 @@ get_new_buffer_index:
 		gossip_debug(GOSSIP_DIR_DEBUG,
 			     "Readdir request failed.  Status:%d\n",
 			     new_op->downcall.status);
-		orangefs_readdir_index_put(buffer_index);
 		if (ret >= 0)
 			ret = new_op->downcall.status;
 		goto out_free_op;
@@ -307,13 +293,11 @@ get_new_buffer_index:
 	bytes_decoded =
 		readdir_handle_ctor(&rhandle,
 				    new_op->downcall.trailer_buf,
-				    new_op->downcall.trailer_size,
-				    buffer_index);
+				    new_op->downcall.trailer_size);
 	if (bytes_decoded < 0) {
 		gossip_err("orangefs_readdir: Could not decode trailer buffer into a readdir response %d\n",
 			ret);
 		ret = bytes_decoded;
-		orangefs_readdir_index_put(buffer_index);
 		goto out_free_op;
 	}
 
-- 
1.8.3.1


                 reply	other threads:[~2016-02-17 17:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455731742-14789-1-git-send-email-martin@omnibond.com \
    --to=martin@omnibond.com \
    --cc=hubcap@omnibond.com \
    --cc=linux-fsdevel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.