static void get_wbuf_from_data(struct conf **confs, struct iobuf *wbuf, struct slist *slist, uint8_t end_flags) { struct blk *blk; struct blist *blist=slist->blist; for(blk=blist->last_sent; blk; blk=blk->next) { if(blk->requested) { iobuf_set(wbuf, CMD_DATA, blk->data, blk->length); blk->requested=0; blist->last_sent=blk; cntr_add(get_cntr(confs), CMD_DATA, 1); break; } else { cntr_add_same(get_cntr(confs), CMD_DATA); if(end_flags&END_BLK_REQUESTS) { // Force onwards when the server has said that // there are no more blocks to request. blist->last_sent=blk; continue; } } if(blk==blist->last_requested) break; } // Need to free stuff that is no longer needed. free_stuff(slist); }
static int deal_with_read_from_chfd(struct asfd *chfd, struct blist *blist, uint64_t *wrap_up, struct dpth *dpth, struct cntr *cntr) { int ret=-1; // Deal with champ chooser read here. //printf("read from cc: %s\n", chfd->rbuf->buf); switch(chfd->rbuf->cmd) { case CMD_SIG: // Get these for blks that the champ chooser has found. if(deal_with_sig_from_chfd(chfd->rbuf, blist, dpth)) goto end; cntr_add_same(cntr, CMD_DATA); break; case CMD_WRAP_UP: if(deal_with_wrap_up_from_chfd(chfd->rbuf, blist, dpth)) goto end; break; default: iobuf_log_unexpected(chfd->rbuf, __func__); goto end; } ret=0; end: iobuf_free_content(chfd->rbuf); return ret; }
static void get_wbuf_from_data(struct conf *conf, struct iobuf *wbuf, struct slist *slist, struct blist *blist, int blk_requests_end) { struct blk *blk; for(blk=blist->last_sent; blk; blk=blk->next) { if(blk->requested) { wbuf->cmd=CMD_DATA; wbuf->buf=blk->data; wbuf->len=blk->length; blk->requested=0; blist->last_sent=blk; cntr_add(conf->cntr, CMD_DATA, 1); cntr_add_sentbytes(conf->cntr, blk->length); break; } else { cntr_add_same(conf->cntr, CMD_DATA); if(blk_requests_end) { // Force onwards when the server has said that // there are no more blocks to request. blist->last_sent=blk; continue; } } if(blk==blist->last_requested) break; } // Need to free stuff that is no longer needed. free_stuff(slist, blist); }
// Return -1 for error, 0 for entry not changed, 1 for entry changed (or new). static int found_in_current_manifest(struct sbuf *csb, struct sbuf *sb, struct manios *manios, struct asfd *chfd, struct cntr *cntr) { // Located the entry in the current manifest. // If the file type changed, I think it is time to back it up again // (for example, EFS changing to normal file, or back again). if(csb->path.cmd!=sb->path.cmd) { if(manio_forward_through_sigs(csb, manios->current)<0) return -1; return 1; } // mtime is the actual file data. // ctime is the attributes or meta data. if(csb->statp.st_mtime==sb->statp.st_mtime && csb->statp.st_ctime==sb->statp.st_ctime) { // Got an unchanged file. cntr_add_same(cntr, sb->path.cmd); return unchanged(csb, sb, manios, chfd); } if(csb->statp.st_mtime==sb->statp.st_mtime && csb->statp.st_ctime!=sb->statp.st_ctime) { // FIX THIS: // File data stayed the same, but attributes or meta data // changed. We already have the attributes, but may need to // get extra meta data. cntr_add_same(cntr, sb->path.cmd); return unchanged(csb, sb, manios, chfd); } // File data changed. cntr_add_changed(cntr, sb->path.cmd); if(manio_forward_through_sigs(csb, manios->current)<0) return -1; return 1; }
static int process_unchanged_file(struct sbuf *cb, FILE *ucfp, struct conf *cconf) { if(sbufl_to_manifest(cb, ucfp, NULL)) { sbuf_free_content(cb); return -1; } else { cntr_add_same(cconf->cntr, cb->path.cmd); } if(cb->burp1->endfile.buf) cntr_add_bytes(cconf->cntr, strtoull(cb->burp1->endfile.buf, NULL, 10)); sbuf_free_content(cb); return 1; }
static int process_unchanged_file(struct sbuf *p1b, struct sbuf *cb, struct fzp *ucfp, struct conf **cconfs) { // Need to re-encode the p1b attribs to include compression and // other bits and pieces that are recorded on cb. iobuf_move(&p1b->protocol1->datapth, &cb->protocol1->datapth); iobuf_move(&p1b->protocol1->endfile, &cb->protocol1->endfile); p1b->compression=cb->compression; if(attribs_encode(p1b)) return -1; if(sbufl_to_manifest(p1b, ucfp)) return -1; cntr_add_same(get_cntr(cconfs[OPT_CNTR]), p1b->path.cmd); if(p1b->protocol1->endfile.buf) cntr_add_bytes( get_cntr(cconfs[OPT_CNTR]), strtoull(p1b->protocol1->endfile.buf, NULL, 10)); sbuf_free_content(cb); return 1; }
static #endif int forward_before_entry(struct manio *manio, struct iobuf *target, struct cntr *cntr, struct dpth *dpth, enum protocol protocol, man_off_t **pos) { int ars=0; struct sbuf *sb=NULL; if(!(sb=sbuf_alloc(protocol))) goto error; man_off_t_free(pos); if(!(*pos=manio_tell(manio))) { logp("Could not manio_tell first pos in %s(): %s\n", __func__, strerror(errno)); goto error; } while(1) { if(sb->endfile.buf || (sb->path.buf && !sbuf_is_filedata(sb))) { man_off_t_free(pos); if(!(*pos=manio_tell(manio))) { logp("Could not manio_tell pos in %s(): " "%s\n", __func__, strerror(errno)); goto error; } } sbuf_free_content(sb); ars=manio_read(manio, sb); if(dpth && set_higher_datapth(sb, dpth)) goto error; switch(ars) { case 0: break; case 1: sbuf_free(&sb); return 0; default: logp("Error in %s(), but continuing\n", __func__); // Treat error in unchanged manio as // OK - could have been a short write. sbuf_free(&sb); return 0; } if(iobuf_pathcmp(target, &sb->path)<=0) { sbuf_free(&sb); return 0; } if(cntr) { cntr_add_same(cntr, sb->path.cmd); if(sb->endfile.buf) { uint64_t e=strtoull(sb->endfile.buf, NULL, 10); cntr_add_bytes(cntr, e); } } } error: sbuf_free(&sb); man_off_t_free(pos); return -1; }