e7a346
From 668b55b7dd86b23e635cfb2264bc5e50f4cd888d Mon Sep 17 00:00:00 2001
e7a346
From: Krutika Dhananjay <kdhananj@redhat.com>
e7a346
Date: Tue, 9 Jan 2018 15:11:00 +0530
e7a346
Subject: [PATCH 461/493] mount/fuse: Add support for multi-threaded fuse
e7a346
 readers
e7a346
e7a346
     > Upstream: https://review.gluster.org/19226
e7a346
     > Github issue #412
e7a346
     > Change-Id: I94aa1505e5ae6a133683d473e0e4e0edd139b76b
e7a346
e7a346
Usage: Use 'reader-thread-count=<NUM>' as command line option to
e7a346
set the thread count at the time of mounting the volume.
e7a346
e7a346
Next task is to make these threads auto-scale based on the load,
e7a346
instead of having the user remount the volume everytime to change
e7a346
the thread count.
e7a346
e7a346
Change-Id: I94aa1505e5ae6a133683d473e0e4e0edd139b76b
e7a346
BUG: 1651040
e7a346
Signed-off-by: Krutika Dhananjay <kdhananj@redhat.com>
e7a346
Reviewed-on: https://code.engineering.redhat.com/gerrit/158514
e7a346
Tested-by: RHGS Build Bot <nigelb@redhat.com>
e7a346
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
e7a346
---
e7a346
 glusterfsd/src/glusterfsd.c                 |  26 ++++
e7a346
 glusterfsd/src/glusterfsd.h                 |   1 +
e7a346
 libglusterfs/src/glusterfs.h                |   1 +
e7a346
 xlators/mount/fuse/src/fuse-bridge.c        | 231 ++++++++++++++++++----------
e7a346
 xlators/mount/fuse/src/fuse-bridge.h        |   9 +-
e7a346
 xlators/mount/fuse/src/fuse-helpers.c       |   3 +
e7a346
 xlators/mount/fuse/src/fuse-mem-types.h     |   1 +
e7a346
 xlators/mount/fuse/utils/mount.glusterfs.in |   7 +
e7a346
 8 files changed, 196 insertions(+), 83 deletions(-)
e7a346
e7a346
diff --git a/glusterfsd/src/glusterfsd.c b/glusterfsd/src/glusterfsd.c
e7a346
index 78f3719..03bca24 100644
e7a346
--- a/glusterfsd/src/glusterfsd.c
e7a346
+++ b/glusterfsd/src/glusterfsd.c
e7a346
@@ -238,6 +238,8 @@ static struct argp_option gf_options[] = {
e7a346
          "Enable localtime logging"},
e7a346
         {"event-history", ARGP_FUSE_EVENT_HISTORY_KEY, "BOOL",
e7a346
          OPTION_ARG_OPTIONAL, "disable/enable fuse event-history"},
e7a346
+        {"reader-thread-count", ARGP_READER_THREAD_COUNT_KEY, "INTEGER",
e7a346
+         OPTION_ARG_OPTIONAL, "set fuse reader thread count"},
e7a346
         {0, 0, 0, 0, "Miscellaneous Options:"},
e7a346
         {0, }
e7a346
 };
e7a346
@@ -557,6 +559,17 @@ set_fuse_mount_options (glusterfs_ctx_t *ctx, dict_t *options)
e7a346
                         goto err;
e7a346
                 }
e7a346
         }
e7a346
+        if (cmd_args->reader_thread_count) {
e7a346
+                ret = dict_set_uint32 (options, "reader-thread-count",
e7a346
+                                       cmd_args->reader_thread_count);
e7a346
+                if (ret < 0) {
e7a346
+                        gf_msg ("glusterfsd", GF_LOG_ERROR, 0, glusterfsd_msg_4,
e7a346
+                                "failed to set dict value for key "
e7a346
+                                "reader-thread-count");
e7a346
+                        goto err;
e7a346
+                }
e7a346
+        }
e7a346
+
e7a346
         ret = 0;
e7a346
 err:
e7a346
         return ret;
e7a346
@@ -1307,6 +1320,19 @@ no_oom_api:
e7a346
                 argp_failure (state, -1, 0,
e7a346
                               "unknown event-history setting \"%s\"", arg);
e7a346
                 break;
e7a346
+        case ARGP_READER_THREAD_COUNT_KEY:
e7a346
+                if (gf_string2uint32 (arg, &cmd_args->reader_thread_count)) {
e7a346
+                        argp_failure (state, -1, 0,
e7a346
+                                      "unknown reader thread count option %s",
e7a346
+                                      arg);
e7a346
+                } else if ((cmd_args->reader_thread_count < 1) ||
e7a346
+                           (cmd_args->reader_thread_count > 64)) {
e7a346
+                        argp_failure (state, -1, 0,
e7a346
+                                      "Invalid reader thread count %s. "
e7a346
+                                      "Valid range: [\"1, 64\"]", arg);
e7a346
+                }
e7a346
+
e7a346
+                break;
e7a346
 	}
e7a346
 
e7a346
         return 0;
e7a346
diff --git a/glusterfsd/src/glusterfsd.h b/glusterfsd/src/glusterfsd.h
e7a346
index f66947b..75cb1d8 100644
e7a346
--- a/glusterfsd/src/glusterfsd.h
e7a346
+++ b/glusterfsd/src/glusterfsd.h
e7a346
@@ -99,6 +99,7 @@ enum argp_option_keys {
e7a346
         ARGP_LOCALTIME_LOGGING_KEY        = 177,
e7a346
         ARGP_SUBDIR_MOUNT_KEY             = 178,
e7a346
         ARGP_FUSE_EVENT_HISTORY_KEY       = 179,
e7a346
+        ARGP_READER_THREAD_COUNT_KEY      = 180,
e7a346
 };
e7a346
 
e7a346
 struct _gfd_vol_top_priv {
e7a346
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
e7a346
index 5e641fd..3e2f426 100644
e7a346
--- a/libglusterfs/src/glusterfs.h
e7a346
+++ b/libglusterfs/src/glusterfs.h
e7a346
@@ -446,6 +446,7 @@ struct _cmd_args {
e7a346
         char           *subdir_mount;
e7a346
 
e7a346
         char              *event_history;
e7a346
+        uint32_t           reader_thread_count;
e7a346
 };
e7a346
 typedef struct _cmd_args cmd_args_t;
e7a346
 
e7a346
diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c
e7a346
index fbb4c53..8d1e3a0 100644
e7a346
--- a/xlators/mount/fuse/src/fuse-bridge.c
e7a346
+++ b/xlators/mount/fuse/src/fuse-bridge.c
e7a346
@@ -665,7 +665,8 @@ fuse_lookup_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_lookup (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_lookup (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+             struct iobuf *iobuf)
e7a346
 {
e7a346
         char           *name     = msg;
e7a346
         fuse_state_t   *state    = NULL;
e7a346
@@ -693,7 +694,8 @@ do_forget(xlator_t *this, uint64_t unique, uint64_t nodeid, uint64_t nlookup)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_forget (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_forget (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+             struct iobuf *iobuf)
e7a346
 
e7a346
 {
e7a346
         struct fuse_forget_in *ffi        = msg;
e7a346
@@ -714,7 +716,8 @@ fuse_forget (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
 
e7a346
 #if FUSE_KERNEL_MINOR_VERSION >= 16
e7a346
 static void
e7a346
-fuse_batch_forget(xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_batch_forget(xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+                  struct iobuf *iobuf)
e7a346
 {
e7a346
 	struct fuse_batch_forget_in *fbfi = msg;
e7a346
 	struct fuse_forget_one *ffo = (struct fuse_forget_one *) (fbfi + 1);
e7a346
@@ -932,7 +935,8 @@ fuse_getattr_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_getattr (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_getattr (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+              struct iobuf *iobuf)
e7a346
 {
e7a346
 #if FUSE_KERNEL_MINOR_VERSION >= 9
e7a346
         struct fuse_getattr_in *fgi  = msg;
e7a346
@@ -1265,7 +1269,8 @@ fuse_setattr_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_setattr (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_setattr (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+              struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_setattr_in *fsi = msg;
e7a346
 
e7a346
@@ -1492,7 +1497,8 @@ fuse_access_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_access (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_access (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+             struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_access_in *fai = msg;
e7a346
         fuse_state_t *state = NULL;
e7a346
@@ -1566,7 +1572,8 @@ fuse_readlink_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_readlink (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_readlink (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+               struct iobuf *iobuf)
e7a346
 {
e7a346
         fuse_state_t *state = NULL;
e7a346
 
e7a346
@@ -1616,7 +1623,8 @@ fuse_mknod_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_mknod (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_mknod (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_mknod_in *fmi = msg;
e7a346
         char         *name = (char *)(fmi + 1);
e7a346
@@ -1686,7 +1694,8 @@ fuse_mkdir_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_mkdir (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_mkdir (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_mkdir_in *fmi = msg;
e7a346
         char *name = (char *)(fmi + 1);
e7a346
@@ -1738,7 +1747,8 @@ fuse_unlink_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_unlink (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_unlink (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+             struct iobuf *iobuf)
e7a346
 {
e7a346
         char         *name = msg;
e7a346
         fuse_state_t *state = NULL;
e7a346
@@ -1775,7 +1785,8 @@ fuse_rmdir_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_rmdir (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_rmdir (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         char         *name = msg;
e7a346
         fuse_state_t *state = NULL;
e7a346
@@ -1825,7 +1836,8 @@ fuse_symlink_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_symlink (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_symlink (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+              struct iobuf *iobuf)
e7a346
 {
e7a346
         char         *name = msg;
e7a346
         char         *linkname = name + strlen (name) + 1;
e7a346
@@ -1947,7 +1959,8 @@ fuse_rename_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_rename (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_rename (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+             struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_rename_in  *fri = msg;
e7a346
         char *oldname = (char *)(fri + 1);
e7a346
@@ -1997,7 +2010,8 @@ fuse_link_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_link (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_link (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+           struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_link_in *fli = msg;
e7a346
         char         *name = (char *)(fli + 1);
e7a346
@@ -2186,7 +2200,8 @@ fuse_create_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_create (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_create (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+             struct iobuf *iobuf)
e7a346
 {
e7a346
 #if FUSE_KERNEL_MINOR_VERSION >= 12
e7a346
         struct fuse_create_in *fci = msg;
e7a346
@@ -2280,7 +2295,8 @@ fuse_open_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_open (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_open (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+           struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_open_in *foi = msg;
e7a346
         fuse_state_t *state = NULL;
e7a346
@@ -2357,7 +2373,8 @@ fuse_readv_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_readv (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_readv (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_read_in *fri = msg;
e7a346
 
e7a346
@@ -2433,8 +2450,6 @@ void
e7a346
 fuse_write_resume (fuse_state_t *state)
e7a346
 {
e7a346
         struct iobref *iobref = NULL;
e7a346
-        struct iobuf  *iobuf = NULL;
e7a346
-
e7a346
 
e7a346
         iobref = iobref_new ();
e7a346
         if (!iobref) {
e7a346
@@ -2447,8 +2462,7 @@ fuse_write_resume (fuse_state_t *state)
e7a346
                 return;
e7a346
         }
e7a346
 
e7a346
-        iobuf = ((fuse_private_t *) (state->this->private))->iobuf;
e7a346
-        iobref_add (iobref, iobuf);
e7a346
+        iobref_add (iobref, state->iobuf);
e7a346
 
e7a346
         gf_log ("glusterfs-fuse", GF_LOG_TRACE,
e7a346
                 "%"PRIu64": WRITE (%p, size=%"GF_PRI_SIZET", offset=%"PRId64")",
e7a346
@@ -2462,7 +2476,8 @@ fuse_write_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_write (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_write (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         /* WRITE is special, metadata is attached to in_header,
e7a346
          * and msg is the payload as-is.
e7a346
@@ -2505,6 +2520,7 @@ fuse_write (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
 
e7a346
         state->vector.iov_base = msg;
e7a346
         state->vector.iov_len  = fwi->size;
e7a346
+        state->iobuf = iobuf;
e7a346
 
e7a346
         fuse_resolve_and_resume (state, fuse_write_resume);
e7a346
 
e7a346
@@ -2543,7 +2559,8 @@ fuse_lseek_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_lseek (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_lseek (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_lseek_in *ffi   = msg;
e7a346
         fuse_state_t         *state = NULL;
e7a346
@@ -2579,7 +2596,8 @@ fuse_flush_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_flush (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_flush (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_flush_in *ffi = msg;
e7a346
 
e7a346
@@ -2615,7 +2633,8 @@ fuse_internal_release (xlator_t *this, fd_t *fd)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_release (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_release (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+              struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_release_in *fri       = msg;
e7a346
         fd_t                   *fd        = NULL;
e7a346
@@ -2660,7 +2679,8 @@ fuse_fsync_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_fsync (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_fsync (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_fsync_in *fsi = msg;
e7a346
 
e7a346
@@ -2735,7 +2755,8 @@ fuse_opendir_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_opendir (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_opendir (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+              struct iobuf *iobuf)
e7a346
 {
e7a346
         /*
e7a346
         struct fuse_open_in *foi = msg;
e7a346
@@ -2877,7 +2898,8 @@ fuse_readdir_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_readdir (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_readdir (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+              struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_read_in *fri = msg;
e7a346
 
e7a346
@@ -3028,7 +3050,8 @@ fuse_readdirp_resume (fuse_state_t *state)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_readdirp (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_readdirp (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+               struct iobuf *iobuf)
e7a346
 {
e7a346
 	struct fuse_read_in *fri = msg;
e7a346
 
e7a346
@@ -3075,7 +3098,8 @@ fuse_fallocate_resume(fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_fallocate(xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_fallocate(xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+               struct iobuf *iobuf)
e7a346
 {
e7a346
 	struct fuse_fallocate_in *ffi = msg;
e7a346
 	fuse_state_t *state = NULL;
e7a346
@@ -3093,7 +3117,8 @@ fuse_fallocate(xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
 #endif /* FUSE minor version >= 19 */
e7a346
 
e7a346
 static void
e7a346
-fuse_releasedir (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_releasedir (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+                 struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_release_in *fri       = msg;
e7a346
         fuse_state_t           *state     = NULL;
e7a346
@@ -3134,7 +3159,8 @@ fuse_fsyncdir_resume (fuse_state_t *state)
e7a346
 }
e7a346
 
e7a346
 static void
e7a346
-fuse_fsyncdir (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_fsyncdir (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+               struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_fsync_in *fsi = msg;
e7a346
 
e7a346
@@ -3221,7 +3247,8 @@ fuse_statfs_resume (fuse_state_t *state)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_statfs (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_statfs (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+             struct iobuf *iobuf)
e7a346
 {
e7a346
         fuse_state_t *state = NULL;
e7a346
 
e7a346
@@ -3273,7 +3300,8 @@ fuse_setxattr_resume (fuse_state_t *state)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_setxattr (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_setxattr (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+               struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_setxattr_in *fsi = msg;
e7a346
         char         *name = (char *)(fsi + 1);
e7a346
@@ -3604,7 +3632,8 @@ fuse_getxattr_resume (fuse_state_t *state)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_getxattr (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_getxattr (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+               struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_getxattr_in *fgxi     = msg;
e7a346
         char                    *name     = (char *)(fgxi + 1);
e7a346
@@ -3710,7 +3739,8 @@ fuse_listxattr_resume (fuse_state_t *state)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_listxattr (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_listxattr (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+                struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_getxattr_in *fgxi = msg;
e7a346
         fuse_state_t *state = NULL;
e7a346
@@ -3766,7 +3796,8 @@ fuse_removexattr_resume (fuse_state_t *state)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_removexattr (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_removexattr (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+                  struct iobuf *iobuf)
e7a346
 {
e7a346
         char *name = msg;
e7a346
 
e7a346
@@ -3865,7 +3896,8 @@ fuse_getlk_resume (fuse_state_t *state)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_getlk (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_getlk (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_lk_in *fli = msg;
e7a346
 
e7a346
@@ -3957,7 +3989,8 @@ fuse_setlk_resume (fuse_state_t *state)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_setlk (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_setlk (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+            struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_lk_in *fli = msg;
e7a346
 
e7a346
@@ -4056,7 +4089,8 @@ notify_kernel_loop (void *data)
e7a346
 #endif
e7a346
 
e7a346
 static void
e7a346
-fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+           struct iobuf *iobuf)
e7a346
 {
e7a346
         struct fuse_init_in  *fini      = msg;
e7a346
         struct fuse_init_out  fino      = {0,};
e7a346
@@ -4227,7 +4261,8 @@ fuse_init (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_enosys (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_enosys (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+             struct iobuf *iobuf)
e7a346
 {
e7a346
         send_fuse_err (this, finh, ENOSYS);
e7a346
 
e7a346
@@ -4236,7 +4271,8 @@ fuse_enosys (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_destroy (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_destroy (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+              struct iobuf *iobuf)
e7a346
 {
e7a346
         send_fuse_err (this, finh, 0);
e7a346
 
e7a346
@@ -4826,6 +4862,7 @@ fuse_graph_sync (xlator_t *this)
e7a346
                 new_graph_id = priv->next_graph->id;
e7a346
                 priv->next_graph = NULL;
e7a346
                 need_first_lookup = 1;
e7a346
+                priv->handle_graph_switch = _gf_true;
e7a346
 
e7a346
                 while (!priv->event_recvd) {
e7a346
                         ret = pthread_cond_wait (&priv->sync_cond,
e7a346
@@ -4854,6 +4891,8 @@ unlock:
e7a346
                 {
e7a346
                         old_subvol->switched = 1;
e7a346
                         winds_on_old_subvol = old_subvol->winds;
e7a346
+                        priv->handle_graph_switch = _gf_false;
e7a346
+                        pthread_cond_broadcast (&priv->migrate_cond);
e7a346
                 }
e7a346
                 pthread_mutex_unlock (&priv->sync_mutex);
e7a346
 
e7a346
@@ -4861,6 +4900,13 @@ unlock:
e7a346
                         xlator_notify (old_subvol, GF_EVENT_PARENT_DOWN,
e7a346
                                        old_subvol, NULL);
e7a346
                 }
e7a346
+        } else {
e7a346
+                pthread_mutex_lock (&priv->sync_mutex);
e7a346
+                {
e7a346
+                        priv->handle_graph_switch = _gf_false;
e7a346
+                        pthread_cond_broadcast (&priv->migrate_cond);
e7a346
+                }
e7a346
+                pthread_mutex_unlock (&priv->sync_mutex);
e7a346
         }
e7a346
 
e7a346
         return 0;
e7a346
@@ -4897,7 +4943,6 @@ fuse_thread_proc (void *data)
e7a346
         const size_t              msg0_size = sizeof (*finh) + 128;
e7a346
         fuse_handler_t          **fuse_ops = NULL;
e7a346
         struct pollfd             pfd[2] = {{0,}};
e7a346
-        gf_boolean_t              mount_finished = _gf_false;
e7a346
 
e7a346
         this = data;
e7a346
         priv = this->private;
e7a346
@@ -4914,32 +4959,40 @@ fuse_thread_proc (void *data)
e7a346
                 /* THIS has to be reset here */
e7a346
                 THIS = this;
e7a346
 
e7a346
-                if (!mount_finished) {
e7a346
-                        memset(pfd,0,sizeof(pfd));
e7a346
-                        pfd[0].fd = priv->status_pipe[0];
e7a346
-                        pfd[0].events = POLLIN | POLLHUP | POLLERR;
e7a346
-                        pfd[1].fd = priv->fd;
e7a346
-                        pfd[1].events = POLLIN | POLLHUP | POLLERR;
e7a346
-                        if (poll(pfd,2,-1) < 0) {
e7a346
-                                gf_log (this->name, GF_LOG_ERROR,
e7a346
-                                        "poll error %s", strerror(errno));
e7a346
-                                break;
e7a346
-                        }
e7a346
-                        if (pfd[0].revents & POLLIN) {
e7a346
-                                if (fuse_get_mount_status(this) != 0) {
e7a346
+                pthread_mutex_lock (&priv->sync_mutex);
e7a346
+                {
e7a346
+                        if (!priv->mount_finished) {
e7a346
+                                memset(pfd, 0, sizeof(pfd));
e7a346
+                                pfd[0].fd = priv->status_pipe[0];
e7a346
+                                pfd[0].events = POLLIN | POLLHUP | POLLERR;
e7a346
+                                pfd[1].fd = priv->fd;
e7a346
+                                pfd[1].events = POLLIN | POLLHUP | POLLERR;
e7a346
+                                if (poll(pfd, 2, -1) < 0) {
e7a346
+                                        gf_log (this->name, GF_LOG_ERROR,
e7a346
+                                                "poll error %s",
e7a346
+                                                strerror(errno));
e7a346
+                                        pthread_mutex_unlock (&priv->sync_mutex);
e7a346
                                         break;
e7a346
                                 }
e7a346
-                                mount_finished = _gf_true;
e7a346
-                        }
e7a346
-                        else if (pfd[0].revents) {
e7a346
-                                gf_log (this->name, GF_LOG_ERROR,
e7a346
-                                        "mount pipe closed without status");
e7a346
-                                break;
e7a346
-                        }
e7a346
-                        if (!pfd[1].revents) {
e7a346
-                                continue;
e7a346
+                                if (pfd[0].revents & POLLIN) {
e7a346
+                                        if (fuse_get_mount_status(this) != 0) {
e7a346
+                                                pthread_mutex_unlock (&priv->sync_mutex);
e7a346
+                                                break;
e7a346
+                                        }
e7a346
+                                        priv->mount_finished = _gf_true;
e7a346
+                                } else if (pfd[0].revents) {
e7a346
+                                        gf_log (this->name, GF_LOG_ERROR,
e7a346
+                                                "mount pipe closed without status");
e7a346
+                                        pthread_mutex_unlock (&priv->sync_mutex);
e7a346
+                                        break;
e7a346
+                                }
e7a346
+                                if (!pfd[1].revents) {
e7a346
+                                        pthread_mutex_unlock (&priv->sync_mutex);
e7a346
+                                        continue;
e7a346
+                                }
e7a346
                         }
e7a346
                 }
e7a346
+                pthread_mutex_unlock (&priv->sync_mutex);
e7a346
 
e7a346
                 /*
e7a346
                  * We don't want to block on readv while we're still waiting
e7a346
@@ -5034,8 +5087,6 @@ fuse_thread_proc (void *data)
e7a346
                         break;
e7a346
                 }
e7a346
 
e7a346
-                priv->iobuf = iobuf;
e7a346
-
e7a346
                 /*
e7a346
                  * This can be moved around a bit, but it's important to do it
e7a346
                  * *after* the readv.  Otherwise, a graph switch could occur
e7a346
@@ -5078,9 +5129,9 @@ fuse_thread_proc (void *data)
e7a346
 
e7a346
                 if (finh->opcode >= FUSE_OP_HIGH)
e7a346
                         /* turn down MacFUSE specific messages */
e7a346
-                        fuse_enosys (this, finh, msg);
e7a346
+                        fuse_enosys (this, finh, msg, NULL);
e7a346
                 else
e7a346
-                        fuse_ops[finh->opcode] (this, finh, msg);
e7a346
+                        fuse_ops[finh->opcode] (this, finh, msg, iobuf);
e7a346
 
e7a346
                 iobuf_unref (iobuf);
e7a346
                 continue;
e7a346
@@ -5152,8 +5203,6 @@ fuse_priv_dump (xlator_t  *this)
e7a346
                             private->volfile_size);
e7a346
         gf_proc_dump_write("mount_point", "%s",
e7a346
                             private->mount_point);
e7a346
-        gf_proc_dump_write("iobuf", "%p",
e7a346
-                            private->iobuf);
e7a346
         gf_proc_dump_write("fuse_thread_started", "%d",
e7a346
                             (int)private->fuse_thread_started);
e7a346
         gf_proc_dump_write("direct_io_mode", "%d",
e7a346
@@ -5279,6 +5328,7 @@ unlock:
e7a346
 int
e7a346
 notify (xlator_t *this, int32_t event, void *data, ...)
e7a346
 {
e7a346
+        int                 i       = 0;
e7a346
         int32_t             ret     = 0;
e7a346
         fuse_private_t     *private = NULL;
e7a346
         gf_boolean_t        start_thread = _gf_false;
e7a346
@@ -5327,14 +5377,21 @@ notify (xlator_t *this, int32_t event, void *data, ...)
e7a346
                 pthread_mutex_unlock (&private->sync_mutex);
e7a346
 
e7a346
                 if (start_thread) {
e7a346
-                        ret = gf_thread_create (&private->fuse_thread, NULL,
e7a346
-                                                fuse_thread_proc, this,
e7a346
-                                                "fuseproc");
e7a346
-                        if (ret != 0) {
e7a346
-                                gf_log (this->name, GF_LOG_DEBUG,
e7a346
-                                        "pthread_create() failed (%s)",
e7a346
-                                        strerror (errno));
e7a346
-                                break;
e7a346
+                        private->fuse_thread = GF_CALLOC (private->reader_thread_count,
e7a346
+                                                          sizeof (pthread_t),
e7a346
+                                                          gf_fuse_mt_pthread_t);
e7a346
+                        for (i = 0; i < private->reader_thread_count; i++) {
e7a346
+
e7a346
+                                ret = gf_thread_create (&private->fuse_thread[i],
e7a346
+                                                        NULL,
e7a346
+                                                        fuse_thread_proc, this,
e7a346
+                                                        "fuseproc");
e7a346
+                                if (ret != 0) {
e7a346
+                                        gf_log (this->name, GF_LOG_DEBUG,
e7a346
+                                                "pthread_create() failed (%s)",
e7a346
+                                                strerror (errno));
e7a346
+                                        break;
e7a346
+                                }
e7a346
                         }
e7a346
                 }
e7a346
 
e7a346
@@ -5441,7 +5498,8 @@ static fuse_handler_t *fuse_dump_ops[FUSE_OP_HIGH];
e7a346
 
e7a346
 
e7a346
 static void
e7a346
-fuse_dumper (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
+fuse_dumper (xlator_t *this, fuse_in_header_t *finh, void *msg,
e7a346
+             struct iobuf *iobuf)
e7a346
 {
e7a346
         fuse_private_t *priv = NULL;
e7a346
         struct iovec diov[6]           = {{0,},};
e7a346
@@ -5473,7 +5531,7 @@ fuse_dumper (xlator_t *this, fuse_in_header_t *finh, void *msg)
e7a346
                         "failed to dump fuse message (R): %s",
e7a346
                         strerror (errno));
e7a346
 
e7a346
-        priv->fuse_ops0[finh->opcode] (this, finh, msg);
e7a346
+        priv->fuse_ops0[finh->opcode] (this, finh, msg, NULL);
e7a346
 }
e7a346
 
e7a346
 
e7a346
@@ -5578,6 +5636,9 @@ init (xlator_t *this_xl)
e7a346
         GF_OPTION_INIT (ZR_ATTR_TIMEOUT_OPT, priv->attribute_timeout, double,
e7a346
                         cleanup_exit);
e7a346
 
e7a346
+        GF_OPTION_INIT ("reader-thread-count", priv->reader_thread_count, uint32,
e7a346
+                        cleanup_exit);
e7a346
+
e7a346
         GF_OPTION_INIT (ZR_ENTRY_TIMEOUT_OPT, priv->entry_timeout, double,
e7a346
                         cleanup_exit);
e7a346
 
e7a346
@@ -5793,6 +5854,7 @@ init (xlator_t *this_xl)
e7a346
 
e7a346
         pthread_mutex_init (&priv->fuse_dump_mutex, NULL);
e7a346
         pthread_cond_init (&priv->sync_cond, NULL);
e7a346
+        pthread_cond_init (&priv->migrate_cond, NULL);
e7a346
         pthread_mutex_init (&priv->sync_mutex, NULL);
e7a346
         priv->event_recvd = 0;
e7a346
 
e7a346
@@ -5992,5 +6054,12 @@ struct volume_options options[] = {
e7a346
           .description = "This option can be used to enable or disable fuse "
e7a346
           "event history.",
e7a346
         },
e7a346
+        { .key = {"reader-thread-count"},
e7a346
+          .type = GF_OPTION_TYPE_INT,
e7a346
+          .default_value = "1",
e7a346
+          .min = 1,
e7a346
+          .max = 64,
e7a346
+          .description = "Sets fuse reader thread count.",
e7a346
+        },
e7a346
         { .key = {NULL} },
e7a346
 };
e7a346
diff --git a/xlators/mount/fuse/src/fuse-bridge.h b/xlators/mount/fuse/src/fuse-bridge.h
e7a346
index 2dfef64..4ca76e9 100644
e7a346
--- a/xlators/mount/fuse/src/fuse-bridge.h
e7a346
+++ b/xlators/mount/fuse/src/fuse-bridge.h
e7a346
@@ -52,7 +52,7 @@
e7a346
 
e7a346
 typedef struct fuse_in_header fuse_in_header_t;
e7a346
 typedef void (fuse_handler_t) (xlator_t *this, fuse_in_header_t *finh,
e7a346
-                               void *msg);
e7a346
+                               void *msg, struct iobuf *iobuf);
e7a346
 
e7a346
 struct fuse_private {
e7a346
         int                  fd;
e7a346
@@ -62,7 +62,8 @@ struct fuse_private {
e7a346
         char                *mount_point;
e7a346
         struct iobuf        *iobuf;
e7a346
 
e7a346
-        pthread_t            fuse_thread;
e7a346
+        pthread_t            *fuse_thread;
e7a346
+        uint32_t              reader_thread_count;
e7a346
         char                 fuse_thread_started;
e7a346
 
e7a346
         uint32_t             direct_io_mode;
e7a346
@@ -140,6 +141,9 @@ struct fuse_private {
e7a346
 
e7a346
         /* whether to run the unmount daemon */
e7a346
         gf_boolean_t auto_unmount;
e7a346
+        gf_boolean_t         mount_finished;
e7a346
+        gf_boolean_t         handle_graph_switch;
e7a346
+        pthread_cond_t       migrate_cond;
e7a346
 };
e7a346
 typedef struct fuse_private fuse_private_t;
e7a346
 
e7a346
@@ -391,6 +395,7 @@ typedef struct {
e7a346
         int32_t        fd_no;
e7a346
 
e7a346
         gf_seek_what_t whence;
e7a346
+        struct iobuf *iobuf;
e7a346
 } fuse_state_t;
e7a346
 
e7a346
 typedef struct {
e7a346
diff --git a/xlators/mount/fuse/src/fuse-helpers.c b/xlators/mount/fuse/src/fuse-helpers.c
e7a346
index c59ff77..c2d4d0c 100644
e7a346
--- a/xlators/mount/fuse/src/fuse-helpers.c
e7a346
+++ b/xlators/mount/fuse/src/fuse-helpers.c
e7a346
@@ -123,6 +123,9 @@ get_fuse_state (xlator_t *this, fuse_in_header_t *finh)
e7a346
 
e7a346
         pthread_mutex_lock (&priv->sync_mutex);
e7a346
         {
e7a346
+                while (priv->handle_graph_switch)
e7a346
+                        pthread_cond_wait (&priv->migrate_cond,
e7a346
+                                           &priv->sync_mutex);
e7a346
                 active_subvol = fuse_active_subvol (state->this);
e7a346
                 active_subvol->winds++;
e7a346
         }
e7a346
diff --git a/xlators/mount/fuse/src/fuse-mem-types.h b/xlators/mount/fuse/src/fuse-mem-types.h
e7a346
index 2b4b473..721b9a3 100644
e7a346
--- a/xlators/mount/fuse/src/fuse-mem-types.h
e7a346
+++ b/xlators/mount/fuse/src/fuse-mem-types.h
e7a346
@@ -23,6 +23,7 @@ enum gf_fuse_mem_types_ {
e7a346
         gf_fuse_mt_graph_switch_args_t,
e7a346
 	gf_fuse_mt_gids_t,
e7a346
         gf_fuse_mt_invalidate_node_t,
e7a346
+        gf_fuse_mt_pthread_t,
e7a346
         gf_fuse_mt_end
e7a346
 };
e7a346
 #endif
e7a346
diff --git a/xlators/mount/fuse/utils/mount.glusterfs.in b/xlators/mount/fuse/utils/mount.glusterfs.in
e7a346
index b39bb98..817619e 100755
e7a346
--- a/xlators/mount/fuse/utils/mount.glusterfs.in
e7a346
+++ b/xlators/mount/fuse/utils/mount.glusterfs.in
e7a346
@@ -221,6 +221,10 @@ start_glusterfs ()
e7a346
         cmd_line=$(echo "$cmd_line --event-history=$event_history");
e7a346
     fi
e7a346
 
e7a346
+    if [ -n "$reader_thread_count" ]; then
e7a346
+        cmd_line=$(echo "$cmd_line --reader-thread-count=$reader_thread_count");
e7a346
+    fi
e7a346
+
e7a346
     if [ -n "$volume_name" ]; then
e7a346
         cmd_line=$(echo "$cmd_line --volume-name=$volume_name");
e7a346
     fi
e7a346
@@ -496,6 +500,9 @@ with_options()
e7a346
         "event-history")
e7a346
             event_history=$value
e7a346
             ;;
e7a346
+        "reader-thread-count")
e7a346
+            reader_thread_count=$value
e7a346
+            ;;
e7a346
         "no-root-squash")
e7a346
             if [ $value = "yes" ] ||
e7a346
                 [ $value = "on" ] ||
e7a346
-- 
e7a346
1.8.3.1
e7a346