static struct addrinfo *lookup_host(char *func, const char *node, const char *service) { struct addrinfo *aitop; int gaierrno; struct addrinfo hints; memset (&hints, 0, sizeof(struct addrinfo)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; #ifdef AI_ADDRCONFIG hints.ai_flags |= AI_ADDRCONFIG; #endif gaierrno = Cgetaddrinfo (node, service, &hints, &aitop); if (gaierrno !=0 && serrno == 0) serrno = SENOSHOST; if (gaierrno == EAI_NONAME) { dpm_errmsg (func, DP009, "Host unknown:", node); return (NULL); } else if (gaierrno != 0) { dpm_errmsg (func, "Error during lookup of %s: %s\n", node, Cgai_strerror (gaierrno)); return (NULL); } return (aitop); }
int DLL_DECL dpm_ping(char *host, char *info) { int c; char func[16]; gid_t gid; int msglen; char *q; char *rbp; char repbuf[256]; char *sbp; char sendbuf[REQBUFSZ]; struct dpm_api_thread_info *thip; uid_t uid; strcpy (func, "dpm_ping"); if (dpm_apiinit (&thip)) return (-1); uid = geteuid(); gid = getegid(); #if defined(_WIN32) if (uid < 0 || gid < 0) { dpm_errmsg (func, DP053); serrno = SENOMAPFND; return (-1); } #endif if (! info) { serrno = EFAULT; return (-1); } /* Build request header */ sbp = sendbuf; marshall_LONG (sbp, DPM_MAGIC); marshall_LONG (sbp, DPM_PING); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); /* Build request body */ marshall_LONG (sbp, uid); marshall_LONG (sbp, gid); msglen = sbp - sendbuf; marshall_LONG (q, msglen); /* update length field */ c = send2dpm (host, sendbuf, msglen, repbuf, sizeof(repbuf), NULL, NULL); if (c == 0) { rbp = repbuf; unmarshall_STRING (rbp, info); } return (c); }
int DLL_DECL dpm_put (int nbreqfiles, struct dpm_putfilereq *reqfiles, int nbprotocols, char **protocols, char *u_token, int overwrite, time_t retrytime, char *r_token, int *nbreplies, struct dpm_putfilestatus **filestatuses) { int c; char errstring[256]; char func[16]; gid_t gid; int i; int msglen; char *rbp; char repbuf[4+256+CA_MAXDPMTOKENLEN+1]; char *sbp; char *sendbuf; char surl[CA_MAXSFNLEN+1]; struct dpm_api_thread_info *thip; uid_t uid; strcpy (func, "dpm_put"); if (dpm_apiinit (&thip)) return (-1); uid = geteuid(); gid = getegid(); #if defined(_WIN32) if (uid < 0 || gid < 0) { dpm_errmsg (func, DP053); serrno = SENOMAPFND; return (-1); } #endif if (nbreqfiles <= 0 || nbprotocols <= 0) { serrno = EINVAL; return (-1); } if (! reqfiles || ! protocols || ! r_token || ! nbreplies || ! filestatuses) { serrno = EFAULT; return (-1); } /* Compute size of send buffer */ msglen = 6 * LONGSIZE; for (i = 0; i < nbprotocols; i++) msglen += strlen (protocols[i]) + 1; if (u_token) msglen += strlen (u_token) + 1; else msglen++; msglen += LONGSIZE; msglen += TIME_TSIZE; msglen += LONGSIZE; for (i = 0; i < nbreqfiles; i++) { msglen += strlen ((reqfiles+i)->to_surl) + 1; msglen += TIME_TSIZE; msglen++; msglen += strlen ((reqfiles+i)->s_token) + 1; msglen += HYPERSIZE; msglen += TIME_TSIZE; msglen++; msglen++; } /* Allocate send buffer */ if ((sendbuf = malloc (msglen)) == NULL) { serrno = ENOMEM; return (-1); } /* Build request header */ sbp = sendbuf; marshall_LONG (sbp, DPM_MAGIC2); marshall_LONG (sbp, DPM_PUT); marshall_LONG (sbp, msglen); /* Build request body */ marshall_LONG (sbp, uid); marshall_LONG (sbp, gid); marshall_LONG (sbp, nbprotocols); for (i = 0; i < nbprotocols; i++) marshall_STRING (sbp, protocols[i]); if (u_token) { marshall_STRING (sbp, u_token); } else { marshall_STRING (sbp, ""); } marshall_LONG (sbp, overwrite); marshall_TIME_T (sbp, retrytime); marshall_LONG (sbp, nbreqfiles); for (i = 0; i < nbreqfiles; i++) { marshall_STRING (sbp, (reqfiles+i)->to_surl); marshall_TIME_T (sbp, (reqfiles+i)->lifetime); marshall_BYTE (sbp, (reqfiles+i)->f_type); marshall_STRING (sbp, (reqfiles+i)->s_token); marshall_HYPER (sbp, (reqfiles+i)->requested_size); marshall_TIME_T (sbp, (reqfiles+i)->f_lifetime); marshall_BYTE (sbp, (reqfiles+i)->ret_policy); marshall_BYTE (sbp, (reqfiles+i)->ac_latency); } c = send2dpm (NULL, sendbuf, msglen, repbuf, sizeof(repbuf), (void **)filestatuses, nbreplies); free (sendbuf); if (c == 0) { rbp = repbuf; unmarshall_LONG (rbp, c); if ((c & 0xF000) == DPM_FAILED) { serrno = c - DPM_FAILED; c = -1; } unmarshall_STRING (rbp, errstring); if (*errstring) dpm_errmsg (func, "%s\n", errstring); unmarshall_STRING (rbp, r_token); } return (c); }
int DLL_DECL dpm_replicatex(const char *path, char f_type, const char *s_token, time_t ltime, char *pfn) { struct dpm_filestatus *filestatuses = NULL; char *from_turl; struct dpm_getfilereq getfilereq; struct dpm_getfilestatus *getfilestatus; int i; int nbreplies; char *p; static char *protocols[] = {"rfio"}; struct dpm_putfilereq putfilereq; struct dpm_putfilestatus *putfilestatus; int r = 0; char r_tokeng[CA_MAXDPMTOKENLEN+1]; char r_tokenp[CA_MAXDPMTOKENLEN+1]; int save_serrno; char sfn[CA_MAXSFNLEN+1]; struct Cns_filestatg statbuf; int status; char *surl; char *to_turl; char turl[CA_MAXSFNLEN+1]; if (s_token && strlen (s_token) > CA_MAXDPMTOKENLEN) { serrno = ENAMETOOLONG; return (-1); } if (strncmp (path, "srm://", 6) == 0 || (strncmp (path, CNS_ROOT, sizeof(CNS_ROOT)-1) == 0 && (*(path+sizeof(CNS_ROOT)-1) == '\0' || *(path+sizeof(CNS_ROOT)-1) == '/'))) { surl = (char *) path; memset (&getfilereq, 0, sizeof(getfilereq)); getfilereq.from_surl = surl; if ((status = dpm_get (1, &getfilereq, 1, protocols, NULL, 0, r_tokeng, &nbreplies, &getfilestatus)) < 0) return (-1); /* wait for request status "Done" or "Failed" */ while (status == DPM_QUEUED || status == DPM_ACTIVE) { if (getfilestatus->from_surl) free (getfilestatus->from_surl); if (getfilestatus->turl) free (getfilestatus->turl); if (getfilestatus->errstring) free (getfilestatus->errstring); free (getfilestatus); sleep ((r++ == 0) ? 1 : DEFPOLLINT); if ((status = dpm_getstatus_getreq (r_tokeng, 0, NULL, &nbreplies, &getfilestatus)) < 0) return (-1); } if (getfilestatus->turl) from_turl = getfilestatus->turl; if (getfilestatus->from_surl) free (getfilestatus->from_surl); if (getfilestatus->errstring) free (getfilestatus->errstring); free (getfilestatus); } else { if (Cns_statr (path, &statbuf) < 0) return (-1); strcpy (turl, "rfio://"); strcpy (turl + 7, path); p = strchr (turl + 7, ':'); *p = '/'; from_turl = turl; if (Cns_getpath (NULL, statbuf.fileid, sfn) < 0) return (-1); surl = sfn; } /* get turl for replica */ memset (&putfilereq, 0, sizeof(putfilereq)); putfilereq.to_surl = surl; putfilereq.f_type = f_type; if (s_token) strcpy(putfilereq.s_token, s_token); putfilereq.f_lifetime = ltime; if ((status = dpm_put (1, &putfilereq, 1, protocols, NULL, 4, 0, r_tokenp, &nbreplies, &putfilestatus)) < 0) return (-1); /* wait for request status "Done" or "Failed" */ r = 0; while (status == DPM_QUEUED || status == DPM_ACTIVE) { if (putfilestatus->to_surl) free (putfilestatus->to_surl); if (putfilestatus->turl) free (putfilestatus->turl); if (putfilestatus->errstring) free (putfilestatus->errstring); free (putfilestatus); sleep ((r++ == 0) ? 1 : DEFPOLLINT); if ((status = dpm_getstatus_putreq (r_tokenp, 0, NULL, &nbreplies, &putfilestatus)) < 0) return (-1); } if (putfilestatus->turl) to_turl = putfilestatus->turl; if (putfilestatus->to_surl) free (putfilestatus->to_surl); if (putfilestatus->errstring) free (putfilestatus->errstring); free (putfilestatus); status = rfio_rcp (from_turl, to_turl, 0); save_serrno = serrno; if (from_turl != turl) { free (from_turl); (void) dpm_relfiles (r_tokeng, 1, &surl, 0, &nbreplies, &filestatuses); dpm_free_filest (nbreplies, filestatuses); } filestatuses = NULL; if (status < 0) { (void) dpm_abortfiles (r_tokenp, 1, &surl, &nbreplies, &filestatuses); } else { status = dpm_putdone (r_tokenp, 1, &surl, &nbreplies, &filestatuses); save_serrno = serrno; if (status < 0 && nbreplies == 1 && filestatuses && *filestatuses->errstring) dpm_errmsg (NULL, "%s", filestatuses->errstring); } dpm_free_filest (nbreplies, filestatuses); serrno = save_serrno; if (pfn != NULL) { *pfn = '\0'; if ((p = strstr (to_turl, "rfio://"))) { p += 7; strcpy (pfn, p); if ((p = strchr (pfn, '/'))) *p = ':'; } if (!*pfn) { status = -1; serrno = ENOENT; } } free (to_turl); return (status); }
int DLL_DECL dpm_getreqsummary (int nbtokens, char **r_tokens, int *nbreplies, struct dpm_reqsummary **summaries) { int c; char errstring[256]; char func[18]; gid_t gid; int i; int msglen; char *rbp; char repbuf[4+256]; char *sbp; char *sendbuf; struct dpm_api_thread_info *thip; uid_t uid; strcpy (func, "dpm_getreqsummary"); if (dpm_apiinit (&thip)) return (-1); uid = geteuid(); gid = getegid(); #if defined(_WIN32) if (uid < 0 || gid < 0) { dpm_errmsg (func, DP053); serrno = SENOMAPFND; return (-1); } #endif if (nbtokens <= 0) { serrno = EINVAL; return (-1); } if (! r_tokens || ! nbreplies || ! summaries) { serrno = EFAULT; return (-1); } /* Compute size of send buffer */ msglen = 6 * LONGSIZE; for (i = 0; i < nbtokens; i++) { msglen += strlen (r_tokens[i]) + 1; } /* Allocate send buffer */ if ((sendbuf = malloc (msglen)) == NULL) { serrno = ENOMEM; return (-1); } /* Build request header */ sbp = sendbuf; marshall_LONG (sbp, DPM_MAGIC); marshall_LONG (sbp, DPM_GETREQSUM); marshall_LONG (sbp, msglen); /* Build request body */ marshall_LONG (sbp, uid); marshall_LONG (sbp, gid); marshall_LONG (sbp, nbtokens); for (i = 0; i < nbtokens; i++) { marshall_STRING (sbp, r_tokens[i]); } c = send2dpm (NULL, sendbuf, msglen, repbuf, sizeof(repbuf), (void **)summaries, nbreplies); free (sendbuf); if (c == 0) { rbp = repbuf; unmarshall_LONG (rbp, c); if (c) { serrno = c - DPM_FAILED; c = -1; } unmarshall_STRING (rbp, errstring); if (*errstring) dpm_errmsg (func, "%s\n", errstring); } return (c); }
int DLL_DECL dpm_modifypool(struct dpm_pool *dpm_pool) { int c; char func[16]; gid_t gid; int i; int msglen; char *p; char *q; char *sbp; char sendbuf[REQBUFSZ]; struct dpm_api_thread_info *thip; uid_t uid; strcpy (func, "dpm_modifypool"); if (dpm_apiinit (&thip)) return (-1); uid = geteuid(); gid = getegid(); #if defined(_WIN32) if (uid < 0 || gid < 0) { dpm_errmsg (func, DP053); serrno = SENOMAPFND; return (-1); } #endif if (! dpm_pool) { serrno = EFAULT; return (-1); } /* Build request header */ sbp = sendbuf; marshall_LONG (sbp, DPM_MAGIC3); marshall_LONG (sbp, DPM_MODPOOL); q = sbp; /* save pointer. The next field will be updated */ msglen = 3 * LONGSIZE; marshall_LONG (sbp, msglen); /* Build request body */ marshall_LONG (sbp, uid); marshall_LONG (sbp, gid); marshall_STRING (sbp, dpm_pool->poolname); marshall_HYPER (sbp, dpm_pool->defsize); marshall_LONG (sbp, dpm_pool->gc_start_thresh); marshall_LONG (sbp, dpm_pool->gc_stop_thresh); marshall_LONG (sbp, dpm_pool->defpintime); marshall_STRING (sbp, dpm_pool->fss_policy); marshall_STRING (sbp, dpm_pool->gc_policy); marshall_STRING (sbp, dpm_pool->rs_policy); marshall_LONG (sbp, dpm_pool->nbgids > 0 ? dpm_pool->gids[0] : -1); marshall_BYTE (sbp, dpm_pool->s_type); marshall_STRING (sbp, dpm_pool->mig_policy); marshall_BYTE (sbp, dpm_pool->ret_policy); marshall_LONG (sbp, dpm_pool->def_lifetime); marshall_LONG (sbp, dpm_pool->max_lifetime); marshall_LONG (sbp, dpm_pool->maxpintime); marshall_LONG (sbp, dpm_pool->nbgids); for (i = 0; i < dpm_pool->nbgids; i++) marshall_LONG (sbp, dpm_pool->gids[i]); msglen = sbp - sendbuf; marshall_LONG (q, msglen); /* update length field */ c = send2dpm (NULL, sendbuf, msglen, NULL, 0, NULL, NULL); return (c); }