Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:09:02

0001 *
0002 * $Id$
0003 *
0004 * $Log$
0005 * Revision 1.1  1996/03/01 11:38:49  mclareni
0006 * Initial revision
0007 *
0008 *
0009 *
0010 *CMZ :          13/11/95  18.36.34  by  Timo Hakulinen
0011 *-- Author :    Timo Hakulinen   25/08/94
0012 /*************************************************************************
0013  *
0014  * stagerd.h
0015  *
0016  * author:  Timo Hakulinen, CERN / CN
0017  * date:    12/8/94
0018  *
0019  *************************************************************************/
0020 
0021 #ifndef STAGERD_H
0022 #define STAGERD_H
0023 
0024 /* all system include files are here so each file sees them */
0025 
0026 #include <stdio.h>
0027 #include <stdlib.h>
0028 #include <stdarg.h>
0029 #include <string.h>
0030 #include <setjmp.h>
0031 #include <signal.h>
0032 #include <time.h>
0033 #include <errno.h>
0034 #include <ctype.h>
0035 
0036 #include <pwd.h>
0037 #include <fcntl.h>
0038 #include <syslog.h>
0039 #include <unistd.h>
0040 #include <sys/types.h>
0041 #include <sys/wait.h>
0042 #include <sys/param.h>
0043 #include <sys/stat.h>
0044 #ifdef _AIX
0045 #define NBBY 8
0046 #include <sys/select.h>
0047 #endif
0048 
0049 #include <netdb.h>
0050 #include <sys/socket.h>
0051 #include <netinet/in.h>
0052 #include <netinet/tcp.h>
0053 #include <arpa/inet.h>
0054 
0055 /* messages to pass */
0056 
0057 #define SGD_MSG_NONE        0
0058 #define SGD_MSG_ERROR       1     /* error occurred */
0059 #define SGD_MSG_OK          2     /* an operation (whichever) was
0060                                      successfully completed */
0061 #define SGD_MSG_STAGE       3     /* perform staging */
0062 #define SGD_MSG_STATUS      4     /* status query */
0063 #define SGD_MSG_INIT        5     /* slaves initiate connection */
0064 #define SGD_MSG_PING        6     /* hello, are you there */
0065 #define SGD_MSG_FORGET      7     /* forget about this stage */
0066 #define SGD_MSG_TRANS       8     /* do a slave-slave data transfer */
0067 
0068 /* file types */
0069 
0070 #define SGD_FTYP_NONE       0
0071 #define SGD_FTYP_LOCAL      1     /* file on user's local disk */
0072 #define SGD_FTYP_TAPE       2     /* file on CERN tape server */
0073 #define SGD_FTYP_FATMEN     3     /* FATMEN path */
0074 
0075 /* stage statuses */
0076 
0077 #define SGD_STATUS_NONE     0
0078 #define SGD_STATUS_ERROR    1     /* an error occurred in staging */
0079 #define SGD_STATUS_DONE     2     /* staging successfully completed */
0080 #define SGD_STATUS_RUNNING  3     /* staging process running on a slave */
0081 #define SGD_STATUS_PENDING  4     /* staging request not yet sent to slave */
0082 #define SGD_STATUS_CONNECT  5     /* trouble (hopefully temporary) while
0083                                      talking to a slave */
0084 
0085 /* stager return codes */
0086 
0087 #define SGD_RET_OK          0
0088 #define SGD_RET_STAGERBIN   1
0089 #define SGD_RET_FTPBIN      2
0090 #define SGD_RET_PATHLEN     3
0091 #define SGD_RET_SFNAME      4
0092 /* 5 is special (comes from CLIO) */
0093 #define SGD_RET_FOPEN       6
0094 #define SGD_RET_POPEN       7
0095 #define SGD_RET_STAT        8
0096 #define SGD_RET_PW          9
0097 #define SGD_RET_PWDIR       10
0098 #define SGD_RET_CHDIR       11
0099 #define SGD_RET_CHMOD       12
0100 #define SGD_RET_CHOWN       13
0101 #define SGD_RET_FTPCONN     14
0102 #define SGD_RET_FTPREAD     15
0103 #define SGD_RET_FTPCD       16
0104 #define SGD_RET_FTPLOGIN    17
0105 #define SGD_RET_HBOOKFORM   18
0106 #define SGD_RET_WRITE       19
0107 #define SGD_RET_CLIOTIMEOUT 20
0108 #define SGD_RET_SIGNAL      21
0109 #define SGD_RET_FATMENFILE  22
0110 #define SGD_RET_TOOLONG     23
0111 #define SGD_RET_TAPEID      24
0112 #define SGD_RET_FATMENBIN   25
0113 #define SGD_RET_LOCKERR     26
0114 #define SGD_RET_RMBIN       27
0115 #define SGD_RET_FORKERR     28
0116 #define SGD_RET_CONCHECK    29
0117 #define SGD_RET_TFNAME      30
0118 #define SGD_RET_PIAFHOME    31
0119 #define SGD_RET_UNKNOWN     32
0120 
0121 #define SGD_RET_LASTCODE    SGD_RET_UNKNOWN
0122 
0123 /* some characteristic constants about Hbook files */
0124 
0125 #define HBOOK_WORD_BYTES  4
0126 #define HBOOK_WORD_BITS   (HBOOK_WORD_BYTES * 8)
0127 #define HBOOK_EXT         ".hbook"
0128 
0129 #define FSTRIPE_SIG     "###FSTRIPE-V001###"
0130 
0131 #define do_striping     (bftp.bf_stripenum > 0)
0132 
0133 /* data structure for the peers of the daemon process
0134    (of slaves kept by masters and of masters kept by slaves) */
0135 
0136 struct peer {
0137   char          *pr_machname;   /* machine */
0138   char          *pr_ipaddr;     /* IP address */
0139   time_t        pr_last;        /* time of the last connection */
0140   int           pr_conport;     /* remote port to connect to */
0141   int           pr_lisport;     /* local port to listen to */
0142   int           pr_sock;        /* effective socket number when connected */
0143   int           pr_up;          /* peer state: up=1, down=0 */
0144   int           pr_keep;        /* keep listening to this peer until done
0145                                    (only meaningful when shutting
0146                                     down masters) */
0147   struct peer   *pr_next;
0148 };
0149 
0150 /* data structure for file stripes across disks */
0151 
0152 struct pfinfo {
0153   char          *pf_name;
0154   unsigned long pf_size;
0155   long          pf_nrec;
0156   FILE          *pf_out;
0157   struct peer   *pf_peer;
0158 };
0159 
0160 /* struct for holding info about revectored stage acks */
0161 
0162 struct revector {
0163   unsigned long rt_stageid;
0164   time_t        rt_time;
0165   struct revector *rt_next;
0166 };
0167 
0168 /* struct for handling slave-slave transfer requests */
0169 
0170 struct transfer {
0171   pid_t         tf_pid;
0172   struct transfer *tf_next;
0173 };
0174 
0175 /* data structure for the ongoing staging processes of the client */
0176 
0177 struct stage {
0178 
0179   /* fields that come from the client */
0180   char          *sg_sfname;     /* source file name */
0181   char          *sg_tfname;     /* target file name (optional) */
0182   char          *sg_prserver;   /* preferred server (optional) */
0183   int           sg_ftyp;        /* file type (local, tape, fatmen) */
0184   unsigned long sg_fsiz;        /* file size in bytes (slave may update) */
0185   int           sg_nowait;      /* nowait-mode (PAW session doesn't wait) */
0186 
0187   /* master fills in these */
0188   int           sg_fnum;        /* number of stripes */
0189   struct pfinfo *sg_ptfname;    /* physical target file name(s) */
0190   char          *sg_masterip;   /* which master (its ip address) */
0191   char          *sg_serverip;   /* which server (its ip address) */
0192   unsigned long sg_stageid;     /* internal id number for the stage */
0193   time_t        sg_queuetime;   /* time when stage operation queued */
0194   time_t        sg_starttime;   /* time when stage operation started */
0195   time_t        sg_endtime;     /* time when - " - ended */
0196 
0197   /* slave does the rest */
0198   char          *sg_otfname;    /* old target file name (if modified
0199                                    by the slave for some reason) */
0200   char          *sg_psfname;    /* physical source file name */
0201   unsigned long sg_fdone;       /* how many bytes of the file has
0202                                    been transferred */
0203   int           sg_status;      /* how are things proceeding */
0204   int           sg_retcode;     /* return code from the stager */
0205 
0206   /* these are only used internally */
0207   char          *sg_slavelist;  /* list of other available slaves */
0208   pid_t         sg_childpid;    /* pid of the slave child doing the staging */
0209   char          *sg_lfname;     /* lock file name */
0210   struct stage  *sg_next;
0211 };
0212 
0213 /* data structure for the clients kept by masters */
0214 
0215 struct client {
0216   char          *ct_username;   /* client user */
0217   char          *ct_machname;   /* client machine (needed for sending mail) */
0218   char          *ct_ipaddr;     /* client IP address for FTP */
0219   char          *ct_fusername;  /* client user for FTP (may be different) */
0220   char          *ct_passwd;     /* user's password on client for FTP
0221                                    (optional) */
0222   unsigned long ct_clientid;    /* internal id number for the client */
0223   struct stage  *ct_stagelist;  /* list of ongoing stages */
0224   struct client *ct_next;
0225 };
0226 
0227 /* for the builtin ftp client to connect to clio */
0228 
0229 struct cliopar {
0230 
0231   /* default parameters */
0232   char *bc_blocksize;
0233   char *bc_fileid;
0234   char *bc_format;
0235   char *bc_reclen;
0236   int  bc_datsiz;
0237 
0238   /* set in config file */
0239   int  bc_version;
0240   char *bc_server;
0241   int  bc_port;
0242   char *bc_login;
0243   int  bc_retries;
0244   int  bc_wait;
0245 };
0246 
0247 struct ftppar {
0248   long bf_bufsize;          /* size of the receive buffer */
0249   int  bf_stripenum;        /* max number of file stripes to use */
0250   long bf_minsize;          /* minimum stripe size */
0251   long bf_dotransfer;       /* buffer size for slave-slave transfers */
0252 };
0253 
0254 struct tcppar {
0255   long tc_rcvbuf;           /* TCP receive buffer size */
0256   long tc_sndbuf;           /* TCP send buffer size */
0257   int  tc_nodelay;          /* use TCP nodelay option or not */
0258 };
0259 
0260 /* number of elements in a table */
0261 #define SIZE(s) (int)(sizeof(s) / sizeof((s)[0]))
0262 
0263 /* to make string comparisons a bit more readable */
0264 #define streql(a,b)     !strcmp(a,b)
0265 #define strneql(a,b,n)  !strncmp(a,b,n)
0266 
0267 /* IDBITS tells how many bits the client and stage id's can have.
0268    The only sensible value for this nowadays is 32, since most
0269    workstations are 32 bit machines.
0270 
0271    MASTERBITS is a magic constant setting bits allocated to master id
0272    in the client id and stage id fields.  Thereby the maximum number of
0273    masters that can coexist is 2^MASTERBITS.  If 3 bits are reserved
0274    for master id, one can have 8 masters with different id's with
0275    numbering going from 0 to 7.
0276 
0277    TIMESTAMPBITS allocates bits for the cycle of the entire id after
0278    which same id's start to be reused.  This cycle is expressed in
0279    seconds and it has to be "long" to prevent any spurious matches in id's.
0280 
0281    REQUESTBITS allocates bits for the max. number of staging requests that
0282    can be processed per second.  If more than the max. number arrives
0283    during the duration of the same timestamp value, the process waits
0284    for the timestamp to advance one step to keep id's unique.  No
0285    requests are ever discarded, however. */
0286 
0287 #define IDBITS          32
0288 
0289 #define MASTERBITS      3   /* max 2^3 = 8 masters */
0290 #define TIMESTAMPBITS   25  /* max 2^25 = 33,554,432 seconds = 388 days */
0291 #define REQUESTBITS     4   /* max 2^4 = 16 requests / second */
0292 
0293 #define MAX_MASTERS     (1 << MASTERBITS)
0294 #define MAX_TIMESTAMPS  (1 << TIMESTAMPBITS)
0295 #define MAX_REQUESTS    (1 << REQUESTBITS)
0296 
0297 #define NEW_CLIENTID    new_id(1)
0298 #define NEW_STAGEID     new_id(0)
0299 
0300 #define MAST_NUM(x)     ((x) >> (IDBITS - MASTERBITS))
0301 
0302 /* how many times to try a system call (like close()) before giving up */
0303 #define MAX_SYSATTEMPTS   100
0304 
0305 /* for how many seconds to allow a recv() on a socket before giving up */
0306 #define RECV_ALARMTIMEOUT 300
0307 
0308 /* defaults for timeouts */
0309 #define DEF_PENDINGTIME   (5 * 60)
0310 #define DEF_SELECTTIMEOUT (5 * 60)
0311 #define DEF_STAGETIMEOUT  -1
0312 #define DEF_PINGINTERVAL  -1
0313 #define DEF_STAGECANCEL   -1
0314 
0315 /* default umask for the user - group readable, world nil */
0316 #define DEF_USERUMASK     026
0317 
0318 #define useruperm       (userumask ^ 0666)
0319 
0320 /* default tmp and nfs paths (have to end in a slash) */
0321 #define DEF_TMPPATH     "/tmp/"
0322 #define DEF_NFSPATH     "/nfs/"
0323 
0324 /* default receive buffer size for slave-slave data transfers */
0325 #define DEF_TRRECVBUF   (16 * 1024)
0326 
0327 /* default piafhome (has to end in a slash) */
0328 #define DEF_PIAFHOME    "piaf/"
0329 
0330 /* template for mktmp() */
0331 #define TMP_TEMPLATE    "stagerdXXXXXX"
0332 
0333 /* lock file extension */
0334 #define LOCKFILE_EXT    ".#fslock#"
0335 
0336 /* maximum length of client user password */
0337 #define MAX_PASSWD      40
0338 
0339 /* patches for stuff that should be defined in the system headers,
0340    but aren't always */
0341 #ifndef PATH_MAX
0342 # ifdef MAXPATHLEN
0343 #  define PATH_MAX MAXPATHLEN
0344 # else
0345 #  define PATH_MAX 255
0346 # endif
0347 #endif
0348 #if defined(ultrix) || defined(__hpux) || defined(_AIX)
0349 extern void syslog(int,char *,...);
0350 #endif
0351 #ifndef S_ISLNK
0352 # define S_ISLNK(mode)  (((mode) & S_IFMT) == S_IFLNK)
0353 #endif
0354 #ifndef LOG_AUTH
0355 # define LOG_LOCAL0  0
0356 # define LOG_LOCAL1  0
0357 # define LOG_LOCAL2  0
0358 # define LOG_LOCAL3  0
0359 # define LOG_LOCAL4  0
0360 # define LOG_LOCAL5  0
0361 # define LOG_LOCAL6  0
0362 # define LOG_LOCAL7  0
0363 #endif
0364 #ifndef LOG_PID
0365 # define LOG_PID     0
0366 #endif
0367 #ifndef LOG_CONS
0368 # define LOG_CONS    0
0369 #endif
0370 
0371 /* IBM tape identifier components */
0372 #define MAX_VOLID   6
0373 #define MAX_FSEQID  2
0374 #define MAX_LBLTYP  3
0375 #define MAX_VOLSER  6
0376 #define MAX_TAPEID  (MAX_VOLID + MAX_FSEQID + MAX_LBLTYP + MAX_VOLSER + 3)
0377 
0378 /* IBM tape identifier defaults */
0379 #define FSEQID_DEFAULT  1
0380 #define LBLTYP_DEFAULT  "sl"
0381 
0382 /* max lengths for string conversion for unsigned numbers -
0383    should be enough for up to 64 bit longs */
0384 #define MAX_ULSTR    20
0385 
0386 /* max length of a message string */
0387 #define MAX_MSGSTR   20
0388 
0389 #define send_msg(s,m)     sendstr(s,sgd_msg[m])
0390 #define send_ftyp(s,m)    sendstr(s,sgd_ftyp[m])
0391 #define send_status(s,m)  sendstr(s,sgd_status[m])
0392 #define recv_msg(s)       recvmstr(s,sgd_msg)
0393 #define recv_ftyp(s)      recvmstr(s,sgd_ftyp)
0394 #define recv_status(s)    recvmstr(s,sgd_status)
0395 
0396 #define find_slavebyip(ip)  find_peerbyip(slavelist,ip)
0397 #define find_masterbyip(ip) find_peerbyip(selectlist,ip)
0398 #define tcplisaddr(p)       tcpaddr(0,p)
0399 #define tcpconaddr(p)       tcpaddr(1,p)
0400 
0401 #ifndef PSTAGE
0402 
0403 /* external function prototypes */
0404 
0405 /* sockio.c */
0406 
0407 extern int recvul(int,unsigned long *);
0408 extern int sendul(int,unsigned long);
0409 extern int recvstr(int,char **,size_t *);
0410 extern int recvmstr(int,char **);
0411 extern int sendstr(int,char *);
0412 
0413 /* debuglog.c */
0414 
0415 #ifdef DEBUG_LOG
0416 # define DLOG_OPEN(s)         dlog_open(s)
0417 # define DLOG_REOPEN(s)       (dlog_close(), dlog_open(s))
0418 # define DLOG_CLOSE()         dlog_close()
0419 # define DLOG_MSG(s)          dlog_msg s
0420 # define DLOG_ERROR(s)        dlog_error s
0421 # define DLOG_CLIENT(s)       dlog_client(s)
0422 # define DLOG_STAGE(s)        dlog_stage(s)
0423 # define DLOG_SOCKADDR_IN(a)  dlog_sockaddr_in(a)
0424 extern void dlog_open(char *);
0425 extern void dlog_close(void);
0426 extern void dlog_msg(char *,...);
0427 extern void dvlog_error(char *,va_list);
0428 extern void dlog_error(char *,...);
0429 extern void dlog_client(struct client *);
0430 extern void dlog_stage(struct stage *);
0431 extern void dlog_sockaddr_in(struct sockaddr_in *);
0432 #else
0433 # define DLOG_OPEN(s)
0434 # define DLOG_REOPEN(s)
0435 # define DLOG_CLOSE()
0436 # define DLOG_MSG(s)
0437 # define DLOG_ERROR(s)
0438 # define DLOG_CLIENT(s)
0439 # define DLOG_STAGE(s)
0440 # define DLOG_SOCKADDR_IN(a)
0441 #endif /* DEBUG_LOG */
0442 
0443 /* master.c */
0444 
0445 extern int m_master_ops(int,struct revector **);
0446 extern int m_flush_pending(long *);
0447 
0448 /* slave.c */
0449 
0450 extern int s_slave_ops(int,struct revector **);
0451 extern int s_check_children(void);
0452 extern int s_init_masters(void);
0453 extern int s_ping_masters(long *);
0454 
0455 /* child.c */
0456 
0457 extern void c_child_ops(struct client *,struct stage *);
0458 
0459 /* syscalls.c */
0460 
0461 #ifdef DEBUG_ALLOC
0462 extern void dump_xallocinfo(FILE *);
0463 #endif
0464 extern void * x_malloc(size_t);
0465 extern void x_free(void *);
0466 extern int x_select(int,fd_set *,fd_set *,fd_set *,struct timeval *);
0467 extern int x_socket(int,int,int);
0468 extern int x_setsockopt(int,int,int,char *,int);
0469 extern int x_connect(int,struct sockaddr *,int);
0470 extern int x_accept(int,struct sockaddr *,int *);
0471 extern int x_bind(int,struct sockaddr *,int);
0472 extern int x_listen(int,int);
0473 extern int x_close(int);
0474 extern int x_shutdown(int,int);
0475 
0476 /* dump.c */
0477 
0478 extern void dumpstatus(void);
0479 
0480 /* codestr.c */
0481 
0482 extern char * st_retcodestr(int);
0483 
0484 /* stagerd.c */
0485 
0486 extern void errlog(int,char *,...);
0487 extern void joblog(struct client *,struct stage *);
0488 extern void fatal(int,char *,...);
0489 extern void get_child_stat(pid_t,int,struct stage *);
0490 
0491 /* util.c */
0492 
0493 /*extern char * true_tfname(char *);*/
0494 extern int is_striped(char *);
0495 extern unsigned long new_id(int);
0496 extern char * dcpass(char *);
0497 extern char * dupstr(char *);
0498 extern struct revector * add_revect(unsigned long);
0499 extern void remove_revect(struct revector *);
0500 extern struct revector * find_revect(unsigned long);
0501 
0502 /* tcputil.c */
0503 
0504 extern int tcpsockopt(int);
0505 extern char * get_peerip(int,struct sockaddr_in **);
0506 extern int tcpconnect(struct sockaddr_in *);
0507 extern int tcplisten(struct sockaddr_in *);
0508 extern struct sockaddr_in * tcpaddr(int,struct peer *);
0509 extern int ping_peer(struct peer *);
0510 extern void tell_to_forget(struct peer *,struct revector *);
0511 
0512 /* lists.c */
0513 
0514 extern struct client * find_client(struct client *);
0515 extern struct peer * find_peerbyip(struct peer *,char *);
0516 extern char * find_peeripbyname(char *);
0517 extern char * find_peeripbypath(char *);
0518 extern struct stage * find_stagebyid(unsigned long,struct client **);
0519 extern struct client * find_clientbyid(unsigned long);
0520 extern struct client * find_clientbystageid(unsigned long);
0521 extern struct stage * find_stagebypid(pid_t);
0522 extern void remove_transferbypid(pid_t);
0523 extern void release_peer(struct peer *);
0524 extern void release_client(struct client *);
0525 extern void release_stage(struct stage *);
0526 extern void remove_client(struct client *);
0527 extern void remove_stage(struct client *,struct stage *);
0528 extern size_t prlen_ulong(unsigned long);
0529 extern size_t prlen_long(long);
0530 extern size_t prlen_stage(struct stage *);
0531 
0532 /* transfer.c */
0533 
0534 extern int put_client(int,struct client *);
0535 extern int get_client(int,struct client *);
0536 extern int put_stage(int,struct stage *);
0537 extern int get_stage(int,struct stage *);
0538 
0539 /* bftp.c */
0540 
0541 extern int ftp_clio(FILE *,struct client *,struct stage *,
0542                     char *,char *,char *,char *);
0543 extern int ftp_ftp(FILE *,struct client *,struct stage *,char *,char *);
0544 
0545 /* global variables */
0546 
0547 extern int master;
0548 extern char *myname;
0549 extern char *myipaddr;
0550 extern char *mymachname;
0551 extern char *mailbin;
0552 extern char *ftpbin;
0553 extern char *stagerbin;
0554 extern char *fatmenbin;
0555 extern char *dpmbin;
0556 extern char *rmbin;
0557 extern char *nfspath;
0558 extern char *tmppath;
0559 extern struct cliopar bclio;
0560 extern struct ftppar bftp;
0561 extern struct tcppar tcpparam;
0562 extern char *syslogchn;
0563 extern char *errlogname;
0564 extern char *joblogname;
0565 extern char *dumpname;
0566 extern char *admin;
0567 extern char *piafhome;
0568 extern int pendingtime;
0569 extern int selecttimeout;
0570 extern int stagetimeout;
0571 extern int pinginterval;
0572 extern int stagecancel;
0573 extern int userumask;
0574 extern char *configfile;
0575 extern int updateconfig;
0576 extern int doshutdown;
0577 extern unsigned long master_id;
0578 extern struct client *clientlist;
0579 extern struct peer *selectlist;
0580 extern struct peer *slavelist;
0581 extern struct revector *revectorlist;
0582 extern struct transfer *transferlist;
0583 extern struct client cl_init;
0584 extern struct stage st_init;
0585 extern struct peer pe_init;
0586 extern char *ftyptb[];
0587 extern char *statustb[];
0588 extern char *sgd_msg[];
0589 extern char *sgd_ftyp[];
0590 extern char *sgd_status[];
0591 
0592 #endif /* PSTAGE */
0593 
0594 #endif /* STAGERD_H */