summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt
diff options
context:
space:
mode:
authorJeff Darcy <jdarcy@redhat.com>2011-10-03 13:56:23 -0400
committerAnand Avati <avati@gluster.com>2011-11-24 00:11:44 -0800
commit86ed5d68596e577b4d923750a619a6921f2cfe18 (patch)
tree77f79cb4202b329622b9e17e60fb52d4f6c1ac08 /xlators/mgmt
parent3f1092c1a79adefd4400bfb6fd20029a22b0f827 (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')
-rw-r--r--xlators/mgmt/glusterd/src/Makefile.am1
-rw-r--r--xlators/mgmt/glusterd/src/glusterd-volgen.c59
2 files changed, 59 insertions, 1 deletions
diff --git a/xlators/mgmt/glusterd/src/Makefile.am b/xlators/mgmt/glusterd/src/Makefile.am
index e1495c273b6..817f0273561 100644
--- a/xlators/mgmt/glusterd/src/Makefile.am
+++ b/xlators/mgmt/glusterd/src/Makefile.am
@@ -1,5 +1,6 @@
xlator_LTLIBRARIES = glusterd.la
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/mgmt
+glusterd_la_CPPFLAGS = "-DFILTERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/filter\""
glusterd_la_LDFLAGS = -module -avoidversion $(LIBXML2_LIBS)
glusterd_la_SOURCES = glusterd.c glusterd-handler.c glusterd-sm.c glusterd-op-sm.c \
glusterd-utils.c glusterd-rpc-ops.c glusterd-store.c glusterd-handshake.c \
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: