示例#1
0
文件: database.c 项目: Hyask/drqueue
int
database_job_load_frames (int sfd, struct job *job) {
  uint32_t nframes = job_nframes (job);
  struct frame_info *fi;
  uint32_t d;

  if (nframes) {
    if ((job->fishmid = get_frame_shared_memory (nframes)) == (int64_t)-1) {
      drerrno = DRE_GETSHMEM;
      return 0;
    }
    if ((fi = attach_frame_shared_memory (job->fishmid)) == (void *) -1) {
      drerrno = DRE_ATTACHSHMEM;
      return 0;
    }
    for (d = 0; d < nframes; d++) {
      if (!recv_frame_info (sfd, &fi[d])) {
	drerrno = DRE_ERRORREADING;
	close (sfd);
	detach_frame_shared_memory(fi);
	job_delete(job);
	return 0;
      }
    }
    detach_frame_shared_memory (fi);
  } else {
    job->fishmid = -1;
    job->frame_info.ptr = NULL;
  }
  

  return 1;
}
示例#2
0
void masterconn_delete(masterconn *eptr,const uint8_t *data,uint32_t length) {
	uint64_t chunkid;
	uint32_t version;
	uint8_t *ptr;
	void *packet;

	if (length!=8+4) {
		syslog(LOG_NOTICE,"MATOCS_DELETE - wrong size (%"PRIu32"/12)",length);
		eptr->mode = KILL;
		return;
	}
	chunkid = get64bit(&data);
	version = get32bit(&data);
	packet = masterconn_create_detached_packet(eptr,CSTOMA_DELETE,8+1);
	ptr = masterconn_get_packet_data(packet);
	put64bit(&ptr,chunkid);
	job_delete(masterconn_jobfinished,packet,chunkid,version);
}
示例#3
0
文件: database.c 项目: Hyask/drqueue
int
database_job_load (int sfd, struct job *job) {
  uint32_t datasize;
  
  //if (!dr_file_read(sfd,(char*)&datasize,sizeof(datasize))) {
  if (!dr_read(sfd,(char*)&datasize,sizeof(datasize))) {
    log_auto (L_ERROR,"database_job_load(): error reading job data size (%u). (%s)",ntohl(datasize),strerror(drerrno_system));
    return 0;
  }
  datasize = ntohl (datasize);

  if (datasize != sizeof (struct job)) {
    log_auto (L_ERROR,"database_job_load(): job data sizes do not match. Read: %u Current: %u",datasize,sizeof(struct job));
    return 0;
  }
  
  job_delete(job);
  //if (!dr_file_read(sfd,(char*)job,datasize)) {
  if (!dr_read(sfd, (char*)job, datasize)) {
    log_auto (L_ERROR,"database_job_load(): error reading job main information. (%s)",strerror(drerrno_system));
    return 0;
  }
  job_bswap_from_network (job,job);
  job_fix_received_invalid (job);

  if (job->used) {
    if (!database_job_load_envvars (sfd,job)) {
      log_auto (L_ERROR,"database_job_load(): error reading job environment variables. (%s)",strerror(drerrno_system));
      return 0;
    }
    if (!database_job_load_frames(sfd,job)) {
      log_auto (L_ERROR,"database_job_load(): error reading job frame information. (%s)",strerror(drerrno_system));
      return 0;
    }
    if (!database_job_load_blocked_hosts(sfd,job)) {
      log_auto (L_ERROR,"database_job_load(): error reading job blocked hosts list. (%s)",strerror(drerrno_system));
      return 0;
    }
  }

  drerrno = DRE_NOERROR;
  return 1;
}
示例#4
0
//读取Master的packet,删除chunk
//调用:masterconn_gotpacket()
void masterconn_delete(masterconn *eptr,const uint8_t *data,uint32_t length) {
	uint64_t chunkid;
	uint32_t version;
	uint8_t *ptr;
#ifdef BGJOBS
	void *packet;
#else /* BGJOBS */
	uint8_t status;
#endif /* BGJOBS */

	if (length!=8+4) {
		syslog(LOG_NOTICE,"MATOCS_DELETE - wrong size (%"PRIu32"/12)",length);
		eptr->mode = KILL;
		return;
	}
	chunkid = get64bit(&data);
	version = get32bit(&data);
#ifdef BGJOBS
	packet = masterconn_create_detached_packet(CSTOMA_DELETE,8+1);
	if (packet==NULL) {
		eptr->mode=KILL;
		return;
	}
	ptr = masterconn_get_packet_data(packet);
	put64bit(&ptr,chunkid);
	job_delete(eptr->jpool,masterconn_jobfinished,packet,chunkid,version);
#else /* BGJOBS */
	status = hdd_delete(chunkid,version);
	ptr = masterconn_create_attached_packet(eptr,CSTOMA_DELETE,8+1);
	if (ptr==NULL) {
		eptr->mode=KILL;
		return;
	}
	put64bit(&ptr,chunkid);
	put8bit(&ptr,status);
#endif /* BGJOBS */
}
示例#5
0
int conflict_handle(const char *path, job_op op, int *keep_which)
{
    int res;
    int keep;
    char *p;
    size_t p_len = strlen(path);

    /* select which to keep by comparing mtime */
    if (discofs_options.conflict == CONFLICT_NEWER)
    {
        struct stat st_c;
        struct stat st_r;
        int cmp;

        /* stat cache file */
        p = cache_path2(path, p_len);
        res = lstat(p, &st_c);
        free(p);
        if (res == -1)
            return -1;

        /* stat remote file */
        p = remote_path2(path, p_len);
        res = lstat(p, &st_r);
        free(p);
        if (res == -1)
            return -1;

        /* compare mtime */
        cmp = sync_timecmp(ST_MTIME(st_c), ST_MTIME(st_r));

        /* keep newer file */
        keep = (cmp < 0) ? CONFLICT_KEEP_REMOTE : CONFLICT_KEEP_CACHE;
    }
    /* always keep remote */
    else if (discofs_options.conflict == CONFLICT_THEIRS)
        keep = CONFLICT_KEEP_REMOTE;
    /* always keep cache */
    else /* CONFLICT_MINE */
        keep = CONFLICT_KEEP_CACHE;

    VERBOSE("CONFLICT during %s on %s, keeping %s",
        job_opstr(op), path, (keep == CONFLICT_KEEP_REMOTE) ? "remote" : "local");

    /* save which file to keep in caller-provided pointer */
    if (keep_which)
        *keep_which = keep;

    /* delete/backup the file NOT to keep
       this will also schedule a push/pull job if
       the file was backed up */
    delete_or_backup(path, keep);

    if (keep == CONFLICT_KEEP_REMOTE)
    {
        p = cache_path2(path, p_len);

        if (op == JOB_RENAME)
        {
            char *newpath = conflict_path(path);

            /* no prefix/suffix -> delete sync/jobs */
            if (!newpath)
            {
                job_delete(path, JOB_ANY);

                if (is_dir(p))
                    sync_delete_dir(path);
                else
                    sync_delete_file(path);
            }
            /* else rename sync/jobs */
            else
            {
                if (is_dir(p))
                {
                    sync_rename_dir(path, newpath);
                    job_rename_dir(path, newpath);
                }
                else
                {
                    sync_rename_file(path, newpath);
                    job_rename_file(path, newpath);
                }
            }
            free(newpath);
        }
        else if (op == JOB_PUSH || op == JOB_PULL)
            job_schedule_pull(path);

        free(p);
    }
    /* keep cache file */
    else
    {
        if (op == JOB_PUSH || op == JOB_PULL)
           job_schedule_push(path);
    }

    return 0;
}
示例#6
0
int transfer_instant_pull(const char *path)
{
    int res;
    char *pc, *pr;
    size_t p_len = strlen(path);
    bool path_equal = false;

    VERBOSE("instant_pulling %s", path);

    pthread_mutex_lock(&m_instant_pull);

    worker_block();

    pr = remote_path2(path, p_len);
    pc = cache_path2(path, p_len);

    pthread_mutex_lock(&m_transfer);
    if (t_state.active)
        path_equal = !strcmp(path, t_state.job->path);
    pthread_mutex_unlock(&m_transfer);

    /* requested file is already being transfered (normally).
       just continue the transfer until it is finished */
    if (path_equal)
    {
        /* continuing a running transfer() only works if !worker_blocked() */
        worker_unblock();
        do
        {
            res = transfer(NULL, NULL);
        }
        while (ONLINE && res == TRANSFER_OK);

        res = (res == TRANSFER_FINISH) ? 0 : 1;
        worker_block();
    }
    else
    {
        res = copy_file(pr, pc);

        /* if copy_file failed, possibly because the file's directory didn't
           exist in the cache yet. create it and retry */
        if (res && errno == ENOENT)
        {
            char *dir = dirname_r(path);

            if (dir)
            {
                transfer_pull_dir(dir);
                free(dir);
                res = copy_file(pr, pc);
            }
        }
    }

    worker_unblock();

    copy_attrs(pr, pc);
    free(pr);
    free(pc);

    /* if copying failed, return error and dont set sync */
    if (res)
    {
        ERROR("instant_pull on %s FAILED", path);
        pthread_mutex_unlock(&m_instant_pull);
        return -1;
    }

    /* file is in sync now */
    job_delete(path, JOB_PULL);
    sync_set(path, 0);

    pthread_mutex_unlock(&m_instant_pull);
    return 0;
}