Ignore:
Timestamp:
Aug 16, 2018, 8:00:56 AM (6 years ago)
Author:
djay
Message:

Fixes for supporting properly the memory=protect which force the ZOO-Kernel to not store any downloaded files in memory. Add footer to the HPC support. Fix the autotools to build service_json and sshapi only when required so, when HPC support is activated, this also avoid adding too much dependencies at compilation time. Store md5 of the downloaded files to avoid uploading on HPC server the same file more than once, in case the md5 correspond.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/prototype-v0/zoo-project/zoo-kernel/service_internal.c

    r862 r877  
    22 * Author : Gérald FENOY
    33 *
    4  * Copyright (c) 2009-2015 GeoLabs SARL
     4 * Copyright (c) 2009-2018 GeoLabs SARL
    55 *
    66 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    3838#endif
    3939
     40#ifdef WIN32
     41// cf. https://stackoverflow.com/questions/3168504/lockfileex-read-write-upgrade-downgrade
     42// only works for (SEEK_SET, start=0, len=0) file locking.
     43__inline int fcntl(int fd, int cmd, ...)
     44{
     45    va_list a;
     46    va_start(a, cmd);
     47    switch(cmd)
     48    {
     49    case F_SETLK:
     50        {
     51            struct flock *l = va_arg(a, struct flock*);
     52            switch(l->l_type)
     53            {
     54            case F_RDLCK:
     55                {
     56                    LPOVERLAPPED o = { 0 };
     57                    HANDLE h = (HANDLE)_get_osfhandle(fd);
     58                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
     59                    {
     60                        _set_errno(ENOTSUP);
     61                        return -1;
     62                    }
     63                    if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY, 0, 0, 1, o)) // read lock
     64                    {
     65                        unsigned long x = GetLastError();
     66                        _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF);
     67                        return -1;
     68                    }
     69                    UnlockFile(h, 0, 0, 1, 1); // write lock
     70                }
     71                break;
     72            case F_WRLCK:
     73                {
     74                    LPOVERLAPPED o = { 0 };
     75                    HANDLE h = (HANDLE)_get_osfhandle(fd);
     76                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
     77                    {
     78                        _set_errno(ENOTSUP);
     79                        return -1;
     80                    }
     81                    if (!LockFileEx(h, LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 1, o)) // write lock
     82                    {
     83                        unsigned long x = GetLastError();
     84                        _set_errno(GetLastError() == ERROR_LOCK_VIOLATION ? EAGAIN : EBADF);
     85                        return -1;
     86                    }
     87                    UnlockFile(h, 0, 0, 0, 1); // read lock
     88                }
     89                break;
     90            case F_UNLCK:
     91                {
     92                    HANDLE h = (HANDLE)_get_osfhandle(fd);
     93                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
     94                    {
     95                        _set_errno(ENOTSUP);
     96                        return -1;
     97                    }
     98                    UnlockFile(h, 0, 0, 0, 1); // read lock
     99                    UnlockFile(h, 0, 0, 1, 1); // write lock
     100                }
     101                break;
     102            default:
     103                _set_errno(ENOTSUP);
     104                return -1;
     105            }
     106        }
     107        break;
     108    case F_SETLKW:
     109        {
     110            struct flock *l = va_arg(a, struct flock*);
     111            switch(l->l_type)
     112            {
     113            case F_RDLCK:
     114                {
     115                    LPOVERLAPPED o = { 0 };
     116                    HANDLE h = (HANDLE)_get_osfhandle(fd);
     117                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
     118                    {
     119                        _set_errno(ENOTSUP);
     120                        return -1;
     121                    }
     122                    if(!LockFileEx(h, 0, 0, 0, 1, o)) // read lock
     123                    {
     124                        unsigned long x = GetLastError();
     125                        return -1;
     126                    }
     127                    UnlockFile(h, 0, 0, 1, 1); // write lock
     128                }
     129                break;
     130            case F_WRLCK:
     131                {
     132                    LPOVERLAPPED o = { 0 };
     133                    HANDLE h = (HANDLE)_get_osfhandle(fd);
     134                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
     135                    {
     136                        _set_errno(ENOTSUP);
     137                        return -1;
     138                    }
     139                    if (!LockFileEx(h, LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 1, o)) // write lock
     140                    {
     141                        unsigned long x = GetLastError();
     142                        return -1;
     143                    }
     144                    UnlockFile(h, 0, 0, 0, 1); // read lock
     145                }
     146                break;
     147            case F_UNLCK:
     148                {
     149                    flock *l = va_arg(a, flock*);
     150                    HANDLE h = (HANDLE)_get_osfhandle(fd);
     151                    if (l->l_whence != SEEK_SET || l->l_start != 0 || l->l_len != 0)
     152                    {
     153                        _set_errno(ENOTSUP);
     154                        return -1;
     155                    }
     156                    UnlockFile(h, 0, 0, 0, 1); // read lock
     157                    UnlockFile(h, 0, 0, 1, 1); // write lock
     158                }
     159                break;
     160            default:
     161                _set_errno(ENOTSUP);
     162                return -1;
     163            }
     164        }
     165        break;
     166    default:
     167        _set_errno(ENOTSUP);
     168        return -1;
     169    }
     170
     171    return 0;
     172}
     173#endif
     174
    40175#define ERROR_MSG_MAX_LENGTH 1024
    41176
     
    53188  struct zooLock* myLock=(struct zooLock*)malloc(sizeof(struct flock)+sizeof(FILE*)+sizeof(char*));
    54189  int len=6;
    55   char *template="%s.lock";
     190  char *myTemplate="%s.lock";
    56191  int res=-1;
    57192 retryLockFile:
    58193  myLock->filename=(char*)malloc((strlen(filename)+len)*sizeof(char));
    59   sprintf(myLock->filename,"%s.lock",filename);
     194  sprintf(myLock->filename,myTemplate,filename);
    60195  s=stat(myLock->filename, &f_status);
    61196  if(s==0 && mode!='r'){
     
    64199      fprintf(stderr,"(%d) Wait for write lock on %s, tried %d times (sleep) ... \n",getpid(),myLock->filename,itn);
    65200      fflush(stderr);
    66       sleep(5);
     201      zSleep(5);
    67202      free(myLock->filename);
    68203      goto retryLockFile;
     
    105240      if((res=fcntl(fileno(myLock->lockfile), F_SETLK, &(myLock->lock)))==-1 &&
    106241         (errno==EAGAIN || errno==EACCES)){
    107         if(cnt >= ZOO_LOCK_MAX_RETRY){
    108           char message[51];       
    109           sprintf(message,"Unable to get the lock after %d attempts.\n",cnt);
    110           setMapInMaps(conf,"lenv","message",message);
    111           fclose(myLock->lockfile);
    112           free(myLock->filename);
    113           free(myLock);
    114           return NULL;
    115         }
    116         fprintf(stderr,"(%d) Wait for lock on  %s, tried %d times ... \n",getpid(),myLock->filename,cnt);
    117         fflush(stderr);
    118         sleep(1);
    119         cnt++;
    120       }else
    121         break;
     242          if(cnt >= ZOO_LOCK_MAX_RETRY){
     243            char message[51];     
     244            sprintf(message,"Unable to get the lock after %d attempts.\n",cnt);
     245            setMapInMaps(conf,"lenv","message",message);
     246            fclose(myLock->lockfile);
     247            free(myLock->filename);
     248            free(myLock);
     249            return NULL;
     250          }
     251          fprintf(stderr,"(%d) Wait for lock on  %s, tried %d times ... \n",getpid(),myLock->filename,cnt);
     252          fflush(stderr);
     253          zSleep(1);
     254          cnt++;
     255        }else
     256           break;
    122257    }
    123258    if(res<0){
     
    163298
    164299#ifndef RELY_ON_DB
    165 #include <dirent.h>
     300#include "dirent.h"
    166301
    167302/**
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png