diff options
| author | Jeff Darcy <jdarcy@redhat.com> | 2011-10-03 13:56:23 -0400 | 
|---|---|---|
| committer | Anand Avati <avati@gluster.com> | 2011-11-24 00:11:44 -0800 | 
| commit | 86ed5d68596e577b4d923750a619a6921f2cfe18 (patch) | |
| tree | 77f79cb4202b329622b9e17e60fb52d4f6c1ac08 /xlators/mgmt/glusterd/src/glusterd-volgen.c | |
| parent | 3f1092c1a79adefd4400bfb6fd20029a22b0f827 (diff) | |
Add volfile-generation hook facility.
Change-Id: I958c393ce5cfffcde8d120499a43dbe6105a082c
BUG: 3688
Reviewed-on: http://review.gluster.com/558
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@gluster.com>
Diffstat (limited to 'xlators/mgmt/glusterd/src/glusterd-volgen.c')
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-volgen.c | 59 | 
1 files changed, 58 insertions, 1 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-volgen.c b/xlators/mgmt/glusterd/src/glusterd-volgen.c index a7856f7820b..0fa7601f145 100644 --- a/xlators/mgmt/glusterd/src/glusterd-volgen.c +++ b/xlators/mgmt/glusterd/src/glusterd-volgen.c @@ -24,6 +24,7 @@  #endif  #include <fnmatch.h> +#include <sys/wait.h>  #if (HAVE_LIB_XML)  #include <libxml/encoding.h> @@ -42,6 +43,7 @@  #include "glusterd-volgen.h"  #include "glusterd-op-sm.h"  #include "glusterd-utils.h" +#include "run.h"  /* dispatch table for VOLUME SET @@ -1055,6 +1057,59 @@ out:          return ret;  } +static void +volgen_apply_filters (char *orig_volfile) +{ +	DIR           *filterdir = NULL; +	struct dirent  entry = {0,}; +	struct dirent *next = NULL; +	char          *filterpath = NULL; +	struct stat    statbuf = {0,}; + +	filterdir = opendir(FILTERDIR); +	if (!filterdir) { +		return; +	} + +	while ((readdir_r(filterdir,&entry,&next) == 0) && next) { +		if (!strncmp(entry.d_name,".",sizeof(entry.d_name))) { +			continue; +		} +		if (!strncmp(entry.d_name,"..",sizeof(entry.d_name))) { +			continue; +		} +		/* +		 * d_type isn't guaranteed to be present/valid on all systems, +		 * so do an explicit stat instead. +		 */ +		if (gf_asprintf(&filterpath,"%s/%.*s",FILTERDIR, +				sizeof(entry.d_name), entry.d_name) == (-1)) { +			continue; +		} +		/* Deliberately use stat instead of lstat to allow symlinks. */ +		if (stat(filterpath,&statbuf) == (-1)) { +			goto free_fp; +		} +		if (!S_ISREG(statbuf.st_mode)) { +			goto free_fp; +		} +		/* +		 * We could check the mode in statbuf directly, or just skip +		 * this entirely and check for EPERM after exec fails, but this +		 * is cleaner. +		 */ +		if (access(filterpath,X_OK) != 0) { +			goto free_fp; +		} +		if (runcmd(filterpath,orig_volfile,NULL)) { +			gf_log("",GF_LOG_ERROR,"failed to run filter %.*s", +			       (int)sizeof(entry.d_name), entry.d_name); +		} +free_fp: +		GF_FREE(filterpath); +	} +} +  static int  volgen_write_volfile (volgen_graph_t *graph, char *filename)  { @@ -1072,7 +1127,7 @@ volgen_write_volfile (volgen_graph_t *graph, char *filename)                  goto error;          if (glusterfs_graph_print_file (f, &graph->graph) == -1) -                goto error; +	goto error;          if (fclose (f) == -1)                  goto error; @@ -1083,6 +1138,8 @@ volgen_write_volfile (volgen_graph_t *graph, char *filename)          GF_FREE (ftmp); +	volgen_apply_filters(filename); +          return 0;   error:  | 
