proof-of-concept sandbox plugin
authorMiloš Mulač <mulac@civ.zcu.cz>
Fri, 12 Jan 2007 12:06:36 +0000 (12:06 +0000)
committerMiloš Mulač <mulac@civ.zcu.cz>
Fri, 12 Jan 2007 12:06:36 +0000 (12:06 +0000)
- no extact-from-tar functionality yet

org.glite.jp.common/interface/known_attr.h
org.glite.jp.primary/project/configure.properties.xml
org.glite.jp.primary/src/sandbox_plugin.c

index fafeb82..60c7fea 100644 (file)
 /** Namespace for LB user tags, schemaless, all values are strings */
 #define GLITE_JP_LBTAG_NS      "http://egee.cesnet.cz/en/WSDL/jp-lbtag"
 
+
+/** Namespace for Sandboxes */
+#define GLITE_JP_ISB_NS       "http://egee.cesnet.cz/en/Schema/JP/ISB"
+#define GLITE_JP_OSB_NS       "http://egee.cesnet.cz/en/Schema/JP/OSB"
+
+/** File names in SB tar */
+#define GLITE_JP_ATTR_ISB_FILENAME     GLITE_JP_ISB_NS ":fileName"
+#define GLITE_JP_ATTR_OSB_FILENAME     GLITE_JP_OSB_NS ":fileName"
+
+
 #endif
index 53515a6..cfa060a 100644 (file)
@@ -12,6 +12,9 @@
 
        Revision history:
        $Log$
+       Revision 1.7  2006/10/10 17:36:32  akrenek
+       merge from 3.1
+
        Revision 1.6.4.1  2006/08/28 18:49:23  akrenek
        pch06 tool to generate subjob relationships from DAG JDL
 
@@ -76,6 +79,7 @@ cppunit=${with.cppunit.prefix}
 jpproject=${subsystem.project.dir}
 project=${component.project.dir}
 classads_prefix=${with.classads.prefix}
+libtar_prefix=${with.libtar.prefix}
                        </echo>
            </target>
        </project>
index 314806b..7e57bcd 100644 (file)
@@ -9,11 +9,15 @@
 #include <fcntl.h>
 
 #include <glite/jp/types.h>
+#include <glite/jp/known_attr.h>
 
 #include "file_plugin.h"
 #include "builtin_plugins.h"
 #include "backend.h"
 
+#define ALLOC_CHUNK    3
+
+
 typedef struct _sb_handle {
        void            *bhandle;
        TAR             *t;
@@ -34,6 +38,31 @@ 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 **);
 
+
+int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data)
+{
+       data->fpctx = ctx;
+       global_data.ctx = 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\"\n",GLITE_JP_FILETYPE_ISB);
+
+       return 0;
+}
+
+
+/**
+* Wrappers for tar_open
+*/
 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
@@ -45,12 +74,10 @@ static int my_close(int fd) {
         return 0;
 }
 
-// wrapper around glite_jppsbe_pread
-static ssize_t my_read(int fd, void *buf, size_t count) 
-{
+static ssize_t my_read(int fd, void *buf, size_t count) {
+       // wrapper around glite_jppsbe_pread
        size_t                  r;
 
-       
        if (glite_jppsbe_pread(global_data.ctx,global_data.bhandle,buf,count,global_data.offset,&r)) {
                errno = global_data.ctx->error->code;
                return -1;
@@ -61,30 +88,12 @@ static ssize_t my_read(int fd, void *buf, size_t count)
        return r;
 }
 
-
 static ssize_t my_write(int fd, const void *buf, size_t count) {
-       // XXX: wrapper around glite_jppsbe_pwrite
+       // wrapper around glite_jppsbe_pwrite
+       // just stub, not needed here&now
 }
 
 
-int init(glite_jp_context_t ctx, glite_jpps_fplug_data_t *data)
-{
-       data->fpctx = ctx;
-       global_data.ctx = 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\"\n",GLITE_JP_FILETYPE_ISB);
-       return 0;
-}
 
 static int sandbox_open(void *fpctx,void *bhandle,const char *uri,void **handle)
 {
@@ -106,14 +115,12 @@ static int sandbox_open(void *fpctx,void *bhandle,const char *uri,void **handle)
        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;
@@ -138,18 +145,33 @@ static int sandbox_attr(void *fpctx,void *handle,const char *attr,glite_jp_attrv
        glite_jp_error_t        err;
        glite_jp_context_t      ctx = fpctx;
        glite_jp_attrval_t      *out = NULL;
-       int                     i,nout = 0;
+       int                     i,nout = 0, count = 0;
        sb_handle       *h = handle;
 
+
+       printf("sandbox_attr() called\n");
+
        memset(&err,0,sizeof err);
        err.source = __FUNCTION__;
        glite_jp_clear_error(ctx);
 
+       *attrval = NULL;
 
        while ((i = th_read(h->t)) == 0)
        {
                printf("-- %s\n", th_get_pathname(h->t));
 
+               if ( !(count % ALLOC_CHUNK) ) {
+                       *attrval = realloc(*attrval, (count + ALLOC_CHUNK + 1) * sizeof(**attrval) );
+                       memset( (*attrval) + count, 0, (ALLOC_CHUNK + 1) * sizeof(**attrval));
+               }
+               (*attrval)[count].name = strdup(GLITE_JP_ATTR_ISB_FILENAME);
+               (*attrval)[count].value = strdup(th_get_pathname(h->t));
+               (*attrval)[count].origin = GLITE_JP_ATTR_ORIG_FILE;
+               (*attrval)[count].timestamp = th_get_mtime(h->t);
+
+               count++;
+
                if (TH_ISREG(h->t) && tar_skip_regfile(h->t) != 0)
                {
                        err.code = EIO;
@@ -158,6 +180,6 @@ static int sandbox_attr(void *fpctx,void *handle,const char *attr,glite_jp_attrv
                }
        }
 
-       printf("sandbox_attr() called\n");
+       return glite_jp_stack_error(ctx,&err);
 }