partial progress with sandbox plugin
authorMiloš Mulač <mulac@civ.zcu.cz>
Mon, 11 Dec 2006 12:56:29 +0000 (12:56 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Mon, 11 Dec 2006 12:56:29 +0000 (12:56 +0000)
org.glite.jp.primary/Makefile
org.glite.jp.primary/config/startup
org.glite.jp.primary/src/sandbox_plugin.c [new file with mode: 0644]

index a071071..48e93dd 100644 (file)
@@ -32,7 +32,7 @@ GLOBUS_CFLAGS:=-I${globus_prefix}/include/${nothrflavour}
 
 DEBUG:=-g -O0  -DDEBUG
 
-CFLAGS:=${DEBUG} -I. -I${top_srcdir}/interface -I${top_srcdir}/src -I${gsoap_prefix}/include -I${gsoap_prefix} -I${stagedir}/include ${GLOBUS_CFLAGS} -I${mysql_prefix}/include -I${mysql_prefix}/include/mysql -I${classads_prefix}/include
+CFLAGS:=${DEBUG} -I. -I${top_srcdir}/interface -I${top_srcdir}/src -I${gsoap_prefix}/include -I${gsoap_prefix} -I${stagedir}/include ${GLOBUS_CFLAGS} -I${mysql_prefix}/include -I${mysql_prefix}/include/mysql -I${classads_prefix}/include -I${libtar_prefix}/include
 LDFLAGS:=-L${stagedir}/lib
 
 LINK:=libtool --mode=link ${CC} ${LDFLAGS} 
@@ -51,7 +51,7 @@ ps_prefix:=jpps_
 is_prefix:=jpis_
 sample_jobs:=sample_job_aborted  sample_job_cleared  sample_job_tagged_done  sample_job_waiting
 
-plugins:=glite-jp-tags.la glite-jp-ftpdauth.la
+plugins:=glite-jp-tags.la glite-jp-ftpdauth.la glite-jp-sandbox.la
 
 HDRS_I=file_plugin.h
 HDRS_S=builtin_plugins.h backend.h feed.h
@@ -79,6 +79,7 @@ COMMONLIB:=-lglite_jp_common_${nothrflavour}
 BONESLIB:=-lglite_lb_server_bones
 GSOAPLIB:=-L${stagedir}/lib -lglite_security_gsoap_plugin_${dotless_soap_ver}_${nothrflavour} 
 TRIOLIB:=-lglite_jp_trio
+LIBTARLIB:=-L${libtar_prefix}/lib -llibtar
 
 ifneq (${mysql_prefix},/usr)
        ifeq ($(shell test -f ${mysql_prefix}/lib/libmysqlclient.a -o -f ${mysql_prefix}/lib/libmysqlclient.so && echo ok),ok)
@@ -196,6 +197,9 @@ simple_server.o soap_ops.o jpps-test.o: ${ps_prefix}H.h
 #      ${CC} -o $@ -c -DWITH_NONAMESPACES -DHAVE_CONFIG_H ${CFLAGS} ${gsoap_prefix}/devel/stdsoap2.c
 # 
 
+glite-jp-sandbox.la: sandbox_plugin.lo
+       ${SOLINK} -o $@ sandbox_plugin.lo ${LIBLIBTAR}
+
 glite-jp-tags.la: tags_plugin.lo
        ${SOLINK} -o $@ tags_plugin.lo
 
index e7120ed..c08da87 100644 (file)
@@ -69,7 +69,7 @@ start()
        echo -n Starting glite-jp-primarystoraged ...
        su - $GLITE_USER -c " $GLITE_LOCATION/bin/glite-jp-primarystoraged \
                $GLITE_JP_DEBUG \
-               -P $GLITE_LOCATION/lib/glite-jp-tags.so -P $GLITE_LOCATION/lib/glite_lb_plugin.so \
+               -P $GLITE_LOCATION/lib/glite-jp-tags.so -P $GLITE_LOCATION/lib/glite_lb_plugin.so -P $GLITE_LOCATION/lib/glite-jp-sandbox.so \
                $creds -a '$GLITE_JP_PRIMARY_PEERS' \
                -i '$pidfile' -p $GLITE_JP_PRIMARY_PORT $GLITE_JP_PRIMARY_SPECIAL \
                -BI,'$GLITE_JP_PRIMARY_INTERNAL' -BE,'$GLITE_JP_PRIMARY_EXTERNAL' \
diff --git a/org.glite.jp.primary/src/sandbox_plugin.c b/org.glite.jp.primary/src/sandbox_plugin.c
new file mode 100644 (file)
index 0000000..2bd63ef
--- /dev/null
@@ -0,0 +1,142 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
+#include <stdint.h>
+
+#include <libtar.h>
+#include <fcntl.h>
+
+#include <glite/jp/types.h>
+
+#include "file_plugin.h"
+#include "builtin_plugins.h"
+#include "backend.h"
+
+typedef struct _sb_handle {
+       void            *bhandle;
+       TAR             *t;
+       tartype_t       *tt;
+       char            **file_names;
+} sb_handle;
+
+
+
+//static int sandbox_append(void *,void *,int,...);
+static int sandbox_open(void *,void *,const char *uri,void **);
+static int sandbox_close(void *,void *);
+static int sandbox_attr(void *,void *,const char *,glite_jp_attrval_t **);
+
+static int my_open(const char *pathname, int flags, ...) {
+       // Do not open file, it is opened in ftp_backend
+       // returned fd does not matter, read/write/close does ftp_backend
+       return 12345;
+}
+
+static int my_close(int fd) {
+       // Closed in ftp_backend
+        return 0;
+}
+
+static ssize_t my_read(int fd, void *buf, size_t count) {
+       // XXX: wrapper around glite_jppsbe_pread
+}
+
+
+static ssize_t my_write(int fd, const void *buf, size_t count) {
+       // XXX: wrapper around glite_jppsbe_pwrite
+}
+
+
+int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data)
+{
+       data->fpctx = ctx;
+
+       data->uris = calloc(2,sizeof *data->uris);
+       data->uris[0] = strdup(GLITE_JP_FILETYPE_ISB);
+
+       data->classes = calloc(2,sizeof *data->classes);
+       data->classes[0] = strdup("sandbox");
+
+       data->ops.open = sandbox_open;
+       data->ops.close = sandbox_close;
+       data->ops.attr = sandbox_attr;
+       
+       printf("sandbox_plugin: URI: \"%s\"",GLITE_JP_FILETYPE_ISB);
+       return 0;
+}
+
+static int sandbox_open(void *fpctx,void *bhandle,const char *uri,void **handle)
+{
+       sb_handle       *h = calloc(1,sizeof *h);
+
+
+       printf("sandbox_open() called\n");
+
+       h->bhandle = bhandle;
+
+       h->tt = malloc(sizeof(*h->tt));
+       h->tt->openfunc = my_open;
+       h->tt->closefunc = my_close;
+       h->tt->readfunc = my_read;
+       h->tt->writefunc = my_write;
+
+       if (tar_open(&h->t, NULL /* not needed, opened in ftp_backend */, h->tt, O_RDONLY, 0, TAR_GNU) == -1)
+               printf("tar_open()\n"); //XXX: use glite_jp_stack_error
+
+//     tar_fdopen(&t, ((fhandle)handle)->fd, char *pathname, tartype_t *type, int oflags, int mode, int options);
+
+
+       *handle = h;
+
+       return 0;
+}
+
+static int sandbox_close(void *fpctx,void *handle)
+{
+       int     i;
+       sb_handle *h = handle;
+
+       tar_close(h->t);
+       free(h->tt);
+
+       for (i=0; h->file_names; i++) free(h->file_names[i]);
+       free(h->file_names);
+       
+       free(h);
+
+       printf("sandbox_close() called\n");
+
+       return 0;
+}
+
+
+static int sandbox_attr(void *fpctx,void *handle,const char *attr,glite_jp_attrval_t **attrval)
+{
+       glite_jp_error_t        err;
+       glite_jp_context_t      ctx = fpctx;
+       glite_jp_attrval_t      *out = NULL;
+       int                     i,nout = 0;
+       sb_handle       *h = handle;
+
+       memset(&err,0,sizeof err);
+       err.source = __FUNCTION__;
+       glite_jp_clear_error(ctx);
+
+
+       while ((i = th_read(h->t)) == 0)
+       {
+               printf("-- %s\n", th_get_pathname(h->t));
+
+               if (TH_ISREG(h->t) && tar_extract_regfile(h->t, th_get_pathname(h->t)) != 0)
+               {
+                       err.code = EIO;
+                       err.desc = "tar_skip_regfile";
+                       return glite_jp_stack_error(ctx,&err);
+               }
+       }
+
+       printf("sandbox_attr() called\n");
+}
+