Patchwork [v4,BUG:1750,1/3] xlator: make it possible to do type setting and dynamic loading separately

login
register
Submitter Csaba Henk
Date 2010-10-02 13:00:37
Message ID <1286024439-32587-1-git-send-email-csaba@gluster.com>
Download mbox | patch
Permalink /patch/5189/
State Accepted
Headers show

Comments

Csaba Henk - 2010-10-02 13:00:37
Signed-off-by: Csaba Henk <csaba@gluster.com>
---
 libglusterfs/src/xlator.c |   38 ++++++++++++++++++++++++++++++--------
 libglusterfs/src/xlator.h |    4 ++++
 2 files changed, 34 insertions(+), 8 deletions(-)

Patch

diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index 105ee49..6650896 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -674,14 +674,8 @@  validate_xlator_volume_options (xlator_t *xl, volume_option_t *opt)
 }
 
 int32_t
-xlator_set_type (xlator_t *xl,
-		 const char *type)
+xlator_set_type_virtual (xlator_t *xl, const char *type)
 {
-        int   ret = 0;
-	char *name = NULL;
-	void *handle = NULL;
-	volume_opt_list_t *vol_opt = NULL;
-
 	if (xl == NULL || type == NULL)	{
 		gf_log ("xlator", GF_LOG_DEBUG, "invalid argument");
 		return -1;
@@ -689,7 +683,22 @@  xlator_set_type (xlator_t *xl,
 
         xl->type = gf_strdup (type);
 
-	ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, type);
+        if (xl->type)
+                return 0;
+        else
+                return -1;
+}
+
+
+int32_t
+xlator_dynload (xlator_t *xl)
+{
+        int   ret = 0;
+	char *name = NULL;
+	void *handle = NULL;
+	volume_opt_list_t *vol_opt = NULL;
+
+	ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xl->type);
         if (-1 == ret) {
                 gf_log ("xlator", GF_LOG_ERROR, "asprintf failed");
                 return -1;
@@ -779,6 +788,19 @@  xlator_set_type (xlator_t *xl,
 }
 
 
+int32_t
+xlator_set_type (xlator_t *xl, const char *type)
+{
+        int ret = 0;
+
+        ret = xlator_set_type_virtual (xl, type);
+        if (!ret)
+                ret = xlator_dynload (xl);
+
+        return ret;
+}
+
+
 void
 xlator_foreach (xlator_t *this,
 		void (*fn)(xlator_t *each,
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index 618cf20..217ad97 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -828,8 +828,12 @@  struct _xlator {
 
 int validate_xlator_volume_options (xlator_t *xl, volume_option_t *opt);
 
+int32_t xlator_set_type_virtual (xlator_t *xl, const char *type);
+
 int32_t xlator_set_type (xlator_t *xl, const char *type);
 
+int32_t xlator_dynload (xlator_t *xl);
+
 xlator_t *file_to_xlator_tree (glusterfs_ctx_t *ctx,
 			       FILE *fp);