Ejemplo n.º 1
0
static struct sbuf *setup_sbuf(const char *path, const char *datapth,
	const char *endfile, int compression)
{
	struct sbuf *sb;
	fail_unless((sb=sbuf_alloc(PROTO_1))!=NULL);
	if(path)
	{
		fail_unless((path=strdup_w(path, __func__))!=NULL);
		iobuf_from_str(&sb->path, CMD_FILE, (char *)path);
	}
	if(datapth)
	{
		fail_unless((datapth=strdup_w("/datapth", __func__))!=NULL);
		iobuf_from_str(&sb->protocol1->datapth,
			CMD_FILE, (char *)datapth);
	}
	if(endfile)
	{
		fail_unless((endfile=strdup_w(endfile, __func__))!=NULL);
		iobuf_from_str(&sb->endfile, CMD_END_FILE, (char *)endfile);
	}

	sb->compression=compression;

	return sb;
}
Ejemplo n.º 2
0
static int get_wbuf_from_sigs(struct iobuf *wbuf, struct slist *slist,
	uint8_t *end_flags)
{
	static char req[32]="";
	struct sbuf *sb=slist->blks_to_request;

	while(sb && !(sb->flags & SBUF_NEED_DATA)) sb=sb->next;

	if(!sb)
	{
		slist->blks_to_request=NULL;
		if((*end_flags)&END_SIGS && !((*end_flags)&END_BLK_REQUESTS))
		{
			iobuf_from_str(wbuf,
				CMD_GEN, (char *)"blk_requests_end");
			(*end_flags)|=END_BLK_REQUESTS;
		}
		return 0;
	}
	if(!sb->protocol2->bsighead)
	{
		// Trying to move onto the next file.
		// ??? Does this really work?
		if(sb->protocol2->bend)
		{
			slist->blks_to_request=sb->next;
			printf("move to next\n");
		}
		if((*end_flags)&END_SIGS && !((*end_flags)&END_BLK_REQUESTS))
		{
			iobuf_from_str(wbuf,
				CMD_GEN, (char *)"blk_requests_end");
			(*end_flags)|=END_BLK_REQUESTS;
		}
		return 0;
	}

	if(sb->protocol2->bsighead->got==BLK_INCOMING)
		return 0;

	if(sb->protocol2->bsighead->got==BLK_NOT_GOT)
	{
		base64_from_uint64(sb->protocol2->bsighead->index, req);
		iobuf_from_str(wbuf, CMD_DATA_REQ, req);
		sb->protocol2->bsighead->requested=1;
	}

	// Move on.
	if(sb->protocol2->bsighead==sb->protocol2->bend)
	{
		slist->blks_to_request=sb->next;
		sb->protocol2->bsighead=sb->protocol2->bstart;
	}
	else
	{
		sb->protocol2->bsighead=sb->protocol2->bsighead->next;
	}
	return 0;
}
Ejemplo n.º 3
0
END_TEST

START_TEST(test_check_browsedir_alloc_error)
{
	char *path;
	size_t bdlen;
	struct sbuf *mb;
	const char *browsedir;
	char *last_bd_match=NULL;

	fail_unless((mb=sbuf_alloc(PROTO_1))!=NULL);

	browsedir="";
	bdlen=0;
	fail_unless((path=strdup_w("aaa", __func__))!=NULL);
	iobuf_from_str(&mb->path, CMD_FILE, path);
	alloc_errors=1;
	fail_unless(check_browsedir(
		browsedir,
		mb,
		bdlen,
		&last_bd_match)
			==-1);

	sbuf_free(&mb);
	free_w(&last_bd_match);
	alloc_check();
}
Ejemplo n.º 4
0
static void setup_reads_from_slist_blks(struct asfd *asfd,
	int *ar, struct slist *slist, int number_of_blks, uint64_t interrupt)
{
	struct sbuf *s;
	struct blk blk;
	struct iobuf iobuf;
	uint64_t file_no=1;
	if(!slist) return;
	for(s=slist->head; s; s=s->next)
	{
		if(sbuf_is_filedata(s)
		  && !sbuf_is_encrypted(s)) // Not working for proto2 yet.
		{
			int b;
			if(interrupt==file_no++)
				continue;
			blk_to_iobuf_sig(&blk, &iobuf);
			for(b=0; b<number_of_blks; b++)
			{
				iobuf_from_str(&iobuf, CMD_DATA,
					(char *)"some data");
				asfd_mock_read_iobuf(asfd, ar, 0, &iobuf);
			}
		}
	}
}
Ejemplo n.º 5
0
static char *set_new_datapth(struct asfd *asfd,
	struct sdirs *sdirs, struct conf **cconfs,
	struct sbuf *sb, struct dpth *dpth, int *istreedata)
{
	char *tmp=NULL;
	char *rpath=NULL;
	if(get_int(cconfs[OPT_DIRECTORY_TREE]))
		*istreedata=treedata(sb, cconfs);

	if(*istreedata)
	{
		// We want to place this file in a directory structure like
		// the directory structure on the original client.
		if(!(tmp=prepend_s(TREE_DIR, sb->path.buf)))
		{
			log_and_send_oom(asfd, __func__);
			return NULL;
		}
	}
	else
	{
		if(!(tmp=strdup_w(dpth_protocol1_mk(dpth,
			get_int(cconfs[OPT_COMPRESSION]),
			sb->path.cmd), __func__))) return NULL;
	}
	iobuf_from_str(&sb->protocol1->datapth, CMD_DATAPTH, tmp);
	if(build_path(sdirs->datadirtmp,
		sb->protocol1->datapth.buf, &rpath, sdirs->datadirtmp))
	{
		log_and_send(asfd, "build path failed");
		return NULL;
	}
	return rpath;
}
Ejemplo n.º 6
0
static struct slist *do_build_manifest(struct manio *manio,
	enum protocol protocol, int entries, int with_data_files)
{
	struct sbuf *sb;
	struct slist *slist=NULL;

	slist=build_slist(protocol, entries, with_data_files);

	for(sb=slist->head; sb; sb=sb->next)
	{
		fail_unless(!manio_write_sbuf(manio, sb));
		if(protocol==PROTO_2)
		{
			struct blk *blk=NULL;
			for(blk=sb->protocol2->bstart;
				blk && blk!=sb->protocol2->bend; blk=blk->next)
			{
				fail_unless(!manio_write_sig_and_path(manio,
					blk));
			}
			if(sbuf_is_filedata(sb) || sbuf_is_vssdata(sb))
			{
				struct iobuf endfile;
				iobuf_from_str(&endfile,
					CMD_END_FILE, (char *)"0:0");
				fail_unless(!iobuf_send_msg_fzp(&endfile,
					manio->fzp));
			}
			hack_protocol2_attr(&sb->attr);
		}
	}

	return slist;
}
Ejemplo n.º 7
0
static void get_wbuf_from_scan(struct iobuf *wbuf, struct slist *flist)
{
	struct sbuf *sb=flist->head;
	if(!sb) return;
	if(!(sb->flags & SBUF_SENT_STAT))
	{
		iobuf_copy(wbuf, &sb->attr);
		sb->flags |= SBUF_SENT_STAT;
	}
	else if(!(sb->flags & SBUF_SENT_PATH))
	{
		iobuf_copy(wbuf, &sb->path);
		sb->flags |= SBUF_SENT_PATH;
	}
	else if(sb->link.buf && !(sb->flags & SBUF_SENT_LINK))
	{
		iobuf_copy(wbuf, &sb->link);
		sb->flags |= SBUF_SENT_LINK;
	}
	else
	{
		flist->head=flist->head->next;
		sbuf_free(&sb);
		if(flist->head)
		{
			// Go ahead and get the next one from the list.
			get_wbuf_from_scan(wbuf, flist);
		}
		else
		{
			flist->tail=NULL;
			iobuf_from_str(wbuf, CMD_GEN, (char *)"scan_end");
		}
	}
}
Ejemplo n.º 8
0
END_TEST

static void run_check_browsedir(const char *browsedir,
	struct sbuf *mb,
	enum cmd cmd,
	const char *path,
	char **last_bd_match,
	const char *expected_last_bd_match,
	int expected_ret,
	int expected_isdir)
{
	char *mbpath;
	size_t bdlen=0;
	if(browsedir) bdlen=strlen(browsedir);
	fail_unless((mbpath=strdup_w(path, __func__))!=NULL);
	iobuf_from_str(&mb->path, cmd, mbpath);
	fail_unless(check_browsedir(
		browsedir,
		mb,
		bdlen,
		last_bd_match)
			==expected_ret);
	if(expected_last_bd_match)
	{
		fail_unless(*last_bd_match!=NULL);
		ck_assert_str_eq(expected_last_bd_match, *last_bd_match);
	}
	else
		fail_unless(*last_bd_match==NULL);
	fail_unless(expected_isdir==S_ISDIR(mb->statp.st_mode));
	sbuf_free_content(mb);
}
Ejemplo n.º 9
0
static void get_wbuf_from_files(struct iobuf *wbuf, struct slist *slist, struct manio *p1manio, int *requests_end)
{
	static uint64_t file_no=1;
	struct sbuf *sb=slist->last_requested;
	if(!sb)
	{
		if(manio_closed(p1manio) && !*requests_end)
		{
			iobuf_from_str(wbuf, CMD_GEN, (char *)"requests_end");
			*requests_end=1;
		}
		return;
	}

	if(sb->flags & SBUF_SENT_PATH || !(sb->flags & SBUF_NEED_DATA))
	{
		slist->last_requested=sb->next;
		return;
	}

	// Only need to request the path at this stage.
	iobuf_copy(wbuf, &sb->path);
	sb->flags |= SBUF_SENT_PATH;
	sb->burp2->index=file_no++;
}
Ejemplo n.º 10
0
static void setup_writes_from_slist_blk_requests(struct asfd *asfd,
	int *aw, struct slist *slist, int number_of_blks, uint64_t interrupt)
{
	struct sbuf *s;
	struct iobuf iobuf;
	char req[32]="";
	int blk_index=1;
	uint64_t file_no=1;
	if(!slist) return;
	for(s=slist->head; s; s=s->next)
	{
		if(sbuf_is_filedata(s)
		  && !sbuf_is_encrypted(s)) // Not working for proto2 yet.
		{
			int b;
			if(interrupt==file_no++)
				continue;
			for(b=0; b<number_of_blks; b++)
			{
				base64_from_uint64(blk_index++, req);
				iobuf_from_str(&iobuf, CMD_DATA_REQ, req);
				asfd_assert_write_iobuf(asfd, aw, 0, &iobuf);
			}
		}
	}
}
Ejemplo n.º 11
0
static void get_wbuf_from_files(struct iobuf *wbuf, struct slist *slist,
	struct manios *manios, uint8_t *end_flags, uint64_t *file_no)
{
	struct sbuf *sb=slist->last_requested;
	if(!sb)
	{
		if(!manios->phase1 && !((*end_flags)&END_REQUESTS))
		{
			iobuf_from_str(wbuf, CMD_GEN, (char *)"requests_end");
			(*end_flags)|=END_REQUESTS;
		}
		return;
	}

	if(sb->flags & SBUF_SENT_PATH || !(sb->flags & SBUF_NEED_DATA))
	{
		slist->last_requested=sb->next;
		return;
	}

	// Only need to request the path at this stage.
	iobuf_copy(wbuf, &sb->path);
	sb->flags |= SBUF_SENT_PATH;
	sb->protocol2->index=(*file_no)++;
}
Ejemplo n.º 12
0
// Return 1 if there is still stuff needing to be sent.
static int do_stuff_to_send(struct asfd *asfd,
	struct sbuf *p1b, char **last_requested)
{
	static struct iobuf wbuf;
	if(p1b->flags & SBUFL_SEND_DATAPTH)
	{
		iobuf_copy(&wbuf, &p1b->burp1->datapth);
		if(asfd->append_all_to_write_buffer(asfd, &wbuf))
			return 1;
		p1b->flags &= ~SBUFL_SEND_DATAPTH;
	}
	if(p1b->flags & SBUFL_SEND_STAT)
	{
		iobuf_copy(&wbuf, &p1b->attr);
		if(asfd->append_all_to_write_buffer(asfd, &wbuf))
			return 1;
		p1b->flags &= ~SBUFL_SEND_STAT;
	}
	if(p1b->flags & SBUFL_SEND_PATH)
	{
		iobuf_copy(&wbuf, &p1b->path);
		if(asfd->append_all_to_write_buffer(asfd, &wbuf))
			return 1;
		p1b->flags &= ~SBUFL_SEND_PATH;
		if(*last_requested) free(*last_requested);
		if(!(*last_requested=strdup_w(p1b->path.buf, __func__)))
			return -1;
	}
	if(p1b->burp1->sigjob && !(p1b->flags & SBUFL_SEND_ENDOFSIG))
	{
		rs_result sigresult;

		sigresult=rs_async(p1b->burp1->sigjob, &(p1b->burp1->rsbuf),
			p1b->burp1->infb, p1b->burp1->outfb);

		if(sigresult==RS_DONE)
		{
			p1b->flags |= SBUFL_SEND_ENDOFSIG;
		}
		else if(sigresult==RS_BLOCKED || sigresult==RS_RUNNING)
		{
			// keep going round the loop.
			return 1;
		}
		else
		{
			logp("error in rs_async: %d\n", sigresult);
			return -1;
		}
	}
	if(p1b->flags & SBUFL_SEND_ENDOFSIG)
	{
		iobuf_from_str(&wbuf, CMD_END_FILE, (char *)"endfile");
		if(asfd->append_all_to_write_buffer(asfd, &wbuf)) return 1;
		p1b->flags &= ~SBUFL_SEND_ENDOFSIG;
	}
	return 0;
}
Ejemplo n.º 13
0
static void get_wbuf_from_index(struct iobuf *wbuf, uint64_t index)
{
	static char *p;
	static char tmp[32];
	p=tmp;
	p+=to_base64(index, tmp);
	*p='\0';
	iobuf_from_str(wbuf, CMD_WRAP_UP, tmp);
}
Ejemplo n.º 14
0
static void get_wbuf_from_index(struct iobuf *wbuf, uint64_t index)
{
	static char *p;
	static char tmp[32];
//printf("%s: %d\n", __func__, index);
	p=tmp;
	p+=to_base64(index, tmp);
	*p='\0';
	iobuf_from_str(wbuf, CMD_WRAP_UP, tmp);
}
Ejemplo n.º 15
0
// FIX THIS: this function is now named strangely.
static void get_wbuf_from_wrap_up(struct iobuf *wbuf, uint64_t wrap_up)
{
	static char *p;
	static char tmp[32];
//printf("get_wbuf_from_wrap_up: %d\n", wrap_up);
	p=tmp;
	p+=to_base64(wrap_up, tmp);
	*p='\0';
	iobuf_from_str(wbuf, CMD_WRAP_UP, tmp);
}
Ejemplo n.º 16
0
static int write_endfile(struct sbuf *sb, struct manios *manios)
{
	struct iobuf endfile;

	if(sb->flags & SBUF_END_WRITTEN_TO_MANIFEST)
		return 0;
	if(!iobuf_is_filedata(&sb->path))
		return 0;

	sb->flags |= SBUF_END_WRITTEN_TO_MANIFEST;
	// FIX THIS: Should give a proper length and md5sum.
	iobuf_from_str(&endfile, CMD_END_FILE, (char *)"0:0");
	return iobuf_send_msg_fzp(&endfile, manios->changed->fzp);
}
Ejemplo n.º 17
0
void build_manifest_phase2_from_slist(const char *path,
	struct slist *slist, enum protocol protocol, int short_write)
{
	struct sbuf *sb;
	struct manio *manio=NULL;

	for(sb=slist->head; sb; sb=sb->next)
		set_sbuf(slist, sb, 0 /* with_data_files */);

	fail_unless((manio=manio_open_phase2(path, "wb", protocol))!=NULL);

	for(sb=slist->head; sb; sb=sb->next)
	{
		fail_unless(!manio_write_sbuf(manio, sb));
		if(protocol==PROTO_2)
		{
			struct blk *blk=NULL;
			for(blk=sb->protocol2->bstart;
				blk && blk!=sb->protocol2->bend; blk=blk->next)
			{
				fail_unless(!manio_write_sig_and_path(manio,
					blk));
			}
			if(sbuf_is_filedata(sb) || sbuf_is_vssdata(sb))
			{
				struct iobuf endfile;
				iobuf_from_str(&endfile,
					CMD_END_FILE, (char *)"0:0");
				fail_unless(!iobuf_send_msg_fzp(&endfile,
					manio->fzp));
			}
			hack_protocol2_attr(&sb->attr);
		}
	}

	if(short_write)
	{
		man_off_t *pos;
		fail_unless((pos=manio_tell(manio))!=NULL);
		if(pos->offset>=short_write) pos->offset-=short_write;
		fail_unless(!manio_close_and_truncate(&manio,
			pos, 0 /* compression */));
		man_off_t_free(&pos);
	}
	fail_unless(!manio_close(&manio));
}
Ejemplo n.º 18
0
static int append_for_champ_chooser(struct asfd *chfd,
	struct blist *blist, int end_flags)
{
	static int finished_sending=0;
	static struct iobuf wbuf;
	static struct blk *blk=NULL;

	while(blist->blk_for_champ_chooser)
	{
		blk=blist->blk_for_champ_chooser;
		// If we send too many blocks to the champ chooser at once,
		// it can go faster than we can send paths to completed
		// manifests to it. This means that deduplication efficiency
		// is reduced (although speed may be faster).
		// So limit the sending.
		if(blk->index
		  - blist->head->index > MANIFEST_SIG_MAX)
			return 0;

		blk_to_iobuf_sig(blk, &wbuf);

		switch(chfd->append_all_to_write_buffer(chfd, &wbuf))
		{
			case APPEND_OK: break;
			case APPEND_BLOCKED:
				return 0; // Try again later.
			default: return -1;
		}
		blist->blk_for_champ_chooser=blk->next;
	}
	if(end_flags&END_SIGS
	  && !finished_sending && !blist->blk_for_champ_chooser)
	{
		iobuf_from_str(&wbuf, CMD_GEN, (char *)"sigs_end");
		switch(chfd->append_all_to_write_buffer(chfd, &wbuf))
		{
			case APPEND_OK: break;
			case APPEND_BLOCKED:
				return 0; // Try again later.
			default: return -1;
		}
		finished_sending++;
	}
	return 0;
}
Ejemplo n.º 19
0
static void set_sbuf_protocol1(struct sbuf *sb)
{
	if(sbuf_is_filedata(sb) || sbuf_is_vssdata(sb))
	{
		char *endfile=gen_endfile_str();
		iobuf_free_content(&sb->endfile);
		sb->endfile.cmd=CMD_END_FILE;
		sb->endfile.len=strlen(endfile);
		fail_unless((sb->endfile.buf
			=strdup_w(endfile, __func__))!=NULL);
	}

	if(sbuf_is_filedata(sb) || sbuf_is_vssdata(sb))
	{
		char *datapth;
		fail_unless((datapth=prepend_s(TREE_DIR, sb->path.buf))!=NULL);
		iobuf_free_content(&sb->protocol1->datapth);
		iobuf_from_str(&sb->protocol1->datapth, CMD_DATAPTH, datapth);
	}
}
Ejemplo n.º 20
0
static int get_wbuf_from_blks(struct iobuf *wbuf,
	struct slist *slist, uint8_t *end_flags)
{
	struct sbuf *sb=slist->blks_to_send;

	if(!sb)
	{
		if((*end_flags)&END_REQUESTS && !((*end_flags)&END_SIGS))
		{
			iobuf_from_str(wbuf, CMD_GEN, (char *)"sigs_end");
			(*end_flags)|=END_SIGS;
		}
		return 0;
	}
	if(!sb->protocol2->bsighead) return 0;

	if(!(sb->flags & SBUF_SENT_STAT))
	{
		iobuf_copy(wbuf, &sb->attr);
		wbuf->cmd=CMD_ATTRIBS_SIGS; // hack
		sb->flags |= SBUF_SENT_STAT;
		return 0;
	}

	if(iobuf_from_blk_data(wbuf, sb->protocol2->bsighead)) return -1;

	// Move on.
	if(sb->protocol2->bsighead==sb->protocol2->bend)
	{
		slist->blks_to_send=sb->next;
		sb->protocol2->bsighead=sb->protocol2->bstart;
	}
	else
	{
		sb->protocol2->bsighead=sb->protocol2->bsighead->next;
	}
	return 0;
}
Ejemplo n.º 21
0
static void get_wbuf_from_blks(struct iobuf *wbuf,
	struct slist *slist, int requests_end, int *sigs_end)
{
	struct sbuf *sb=slist->blks_to_send;

	if(!sb)
	{
		if(requests_end && !*sigs_end)
		{
			iobuf_from_str(wbuf, CMD_GEN, (char *)"sigs_end");
			*sigs_end=1;
		}
		return;
	}
	if(!sb->burp2->bsighead) return;

	if(!(sb->flags & SBUF_SENT_STAT))
	{
		iobuf_copy(wbuf, &sb->attr);
		wbuf->cmd=CMD_ATTRIBS_SIGS; // hack
		sb->flags |= SBUF_SENT_STAT;
		return;
	}

	iobuf_from_blk_data(wbuf, sb->burp2->bsighead);

	// Move on.
	if(sb->burp2->bsighead==sb->burp2->bend)
	{
		slist->blks_to_send=sb->next;
		sb->burp2->bsighead=sb->burp2->bstart;
	}
	else
	{
		sb->burp2->bsighead=sb->burp2->bsighead->next;
	}
}
Ejemplo n.º 22
0
static char *set_new_datapth(struct asfd *asfd,
	struct sdirs *sdirs, struct conf *cconf,
	struct sbuf *sb, struct dpthl *dpthl, int *istreedata)
{
	static char *tmp=NULL;
	char *rpath=NULL;
	if(cconf->directory_tree) *istreedata=treedata(sb);

	if(*istreedata)
	{
		// We want to place this file in a directory structure like
		// the directory structure on the original client.
		if(!(tmp=prepend_s("t", sb->path.buf)))
		{
			log_and_send_oom(asfd, __func__);
			return NULL;
		}
	}
	else
	{
		mk_dpthl(dpthl, cconf, sb->path.cmd);
		if(!(tmp=strdup(dpthl->path))) // file data path
		{
			log_and_send_oom(asfd, __func__);
			return NULL;
		}
	}
	iobuf_from_str(&sb->burp1->datapth, CMD_DATAPTH, tmp);
	if(build_path(sdirs->datadirtmp,
		sb->burp1->datapth.buf, &rpath, sdirs->datadirtmp))
	{
		log_and_send(asfd, "build path failed");
		return NULL;
	}
	return rpath;
}
Ejemplo n.º 23
0
// Return 1 if there is still stuff needing to be sent.
// FIX THIS: lots of repeated code.
static int do_stuff_to_send(struct asfd *asfd,
	struct sbuf *p1b, char **last_requested)
{
	static struct iobuf wbuf;
	if(p1b->flags & SBUF_SEND_DATAPTH)
	{
		iobuf_copy(&wbuf, &p1b->protocol1->datapth);
		switch(asfd->append_all_to_write_buffer(asfd, &wbuf))
		{
			case APPEND_OK: break;
			case APPEND_BLOCKED: return 1;
			default: return -1;
		}
		p1b->flags &= ~SBUF_SEND_DATAPTH;
	}
	if(p1b->flags & SBUF_SEND_STAT)
	{
		iobuf_copy(&wbuf, &p1b->attr);
		switch(asfd->append_all_to_write_buffer(asfd, &wbuf))
		{
			case APPEND_OK: break;
			case APPEND_BLOCKED: return 1;
			default: return -1;
		}
		p1b->flags &= ~SBUF_SEND_STAT;
	}
	if(p1b->flags & SBUF_SEND_PATH)
	{
		iobuf_copy(&wbuf, &p1b->path);
		switch(asfd->append_all_to_write_buffer(asfd, &wbuf))
		{
			case APPEND_OK: break;
			case APPEND_BLOCKED: return 1;
			default: return -1;
		}
		p1b->flags &= ~SBUF_SEND_PATH;
		free_w(last_requested);
		if(!(*last_requested=strdup_w(p1b->path.buf, __func__)))
			return -1;
	}
	if(p1b->protocol1->sigjob && !(p1b->flags & SBUF_SEND_ENDOFSIG))
	{
		rs_result sigresult;

		switch((sigresult=rs_async(p1b->protocol1->sigjob,
			&(p1b->protocol1->rsbuf),
			p1b->protocol1->infb, p1b->protocol1->outfb)))
		{
			case RS_DONE:
				p1b->flags |= SBUF_SEND_ENDOFSIG;
				break;
			case RS_BLOCKED:
			case RS_RUNNING:
				// keep going round the loop.
				return 1;
			default:
				logp("error in rs_async: %d\n", sigresult);
				return -1;
		}
	}
	if(p1b->flags & SBUF_SEND_ENDOFSIG)
	{
		iobuf_from_str(&wbuf, CMD_END_FILE, (char *)"endfile");
		switch(asfd->append_all_to_write_buffer(asfd, &wbuf))
		{
			case APPEND_OK: break;
			case APPEND_BLOCKED: return 1;
			default: return -1;
		}
		p1b->flags &= ~SBUF_SEND_ENDOFSIG;
	}
	return 0;
}
Ejemplo n.º 24
0
static int get_wbuf_from_sigs(struct iobuf *wbuf, struct slist *slist, struct blist *blist, int sigs_end, int *blk_requests_end, struct dpth *dpth, struct conf *conf)
{
	static char req[32]="";
	struct sbuf *sb=slist->blks_to_request;

	while(sb && !(sb->flags & SBUF_NEED_DATA)) sb=sb->next;

	if(!sb)
	{
		slist->blks_to_request=NULL;
		if(sigs_end && !*blk_requests_end)
		{
			iobuf_from_str(wbuf,
				CMD_GEN, (char *)"blk_requests_end");
			*blk_requests_end=1;
		}
		return 0;
	}
	if(!sb->burp2->bsighead)
	{
		// Trying to move onto the next file.
		// ??? Does this really work?
		if(sb->burp2->bend)
		{
			slist->blks_to_request=sb->next;
			printf("move to next\n");
		}
		if(sigs_end && !*blk_requests_end)
		{
			iobuf_from_str(wbuf,
				CMD_GEN, (char *)"blk_requests_end");
			*blk_requests_end=1;
		}
		return 0;
	}

	if(sb->burp2->bsighead->got==BLK_INCOMING)
	{
//		if(sigs_end
//		  && deduplicate(sb->burp2->bsighead, dpth, conf, wrap_up))
//			return -1;
		return 0;
	}

	if(sb->burp2->bsighead->got==BLK_NOT_GOT)
	{
		encode_req(sb->burp2->bsighead, req);
		iobuf_from_str(wbuf, CMD_DATA_REQ, req);
		sb->burp2->bsighead->requested=1;
	}

	// Move on.
	if(sb->burp2->bsighead==sb->burp2->bend)
	{
		slist->blks_to_request=sb->next;
		sb->burp2->bsighead=sb->burp2->bstart;
	}
	else
	{
		sb->burp2->bsighead=sb->burp2->bsighead->next;
	}
	return 0;
}
Ejemplo n.º 25
0
static int sbuf_needs_data(struct sbuf *sb, struct asfd *asfd,
        struct asfd *chfd, struct manios *manios,
        struct slist *slist, int end_flags)
{
	int ret=-1;
	struct blk *blk;
	static struct iobuf wbuf;
	struct blist *blist=slist->blist;

	if(!(sb->flags & SBUF_HEADER_WRITTEN_TO_MANIFEST))
	{
		if(manio_write_sbuf(manios->changed, sb)) goto end;
		sb->flags |= SBUF_HEADER_WRITTEN_TO_MANIFEST;
	}

	while((blk=sb->protocol2->bstart)
		&& blk->got==BLK_GOT
		&& (blk->next || end_flags&END_BACKUP))
	{
		if(blk->got_save_path
		  && !blk_is_zero_length(blk))
		{
			if(breaking && breakcount--==0)
			{
				breakpoint(breaking, __func__);
				goto end;
			}
			if(manio_write_sig_and_path(manios->changed, blk))
				goto end;
			if(manios->changed->sig_count==0)
			{
				// Have finished a manifest file. Want to start
				// using it as a dedup candidate now.
				iobuf_from_str(&wbuf, CMD_MANIFEST,
					manios->changed->offset->fpath);
				if(chfd->write(chfd, &wbuf)) goto end;

				if(!blk->requested)
				{
					// Also let the client know, so that it
					// can free memory if there was a long
					// consecutive number of unrequested
					// blocks.
					get_wbuf_from_index(&wbuf, blk->index);
					if(asfd->write(asfd, &wbuf)) goto end;
				}
			}
		}

		if(blk==sb->protocol2->bend)
		{
			slist->head=sb->next;
			if(!(blist->head=sb->protocol2->bstart))
				blist->tail=NULL;
			sanity_before_sbuf_free(slist, sb);
			if(write_endfile(sb, manios)) return -1;
			sbuf_free(&sb);
			return 1;
		}

		if(sb->protocol2->bsighead==sb->protocol2->bstart)
			sb->protocol2->bsighead=blk->next;
		sb->protocol2->bstart=blk->next;
		if(blk==blist->blk_from_champ_chooser)
			blist->blk_from_champ_chooser=blk->next;

		blk_free(&blk);
	}
	if(!blk && sb && !sb->protocol2->bend && (end_flags&END_BACKUP))
	{
		// Write endfile for the very last file.
		if(write_endfile(sb, manios)) return -1;
	}
	ret=0;
end:
	if(!(blist->head=sb->protocol2->bstart)) blist->tail=NULL;
	return ret;
}
Ejemplo n.º 26
0
static int write_to_changed_file(struct asfd *asfd,
	struct asfd *chfd, struct manio *chmanio,
	struct slist *slist, struct blist *blist,
	struct dpth *dpth, int backup_end, struct conf *conf)
{
	struct sbuf *sb;
	static struct iobuf *wbuf=NULL;
	if(!slist) return 0;
        if(!wbuf && !(wbuf=iobuf_alloc())) return -1;

	while((sb=slist->head))
	{
		if(sb->flags & SBUF_NEED_DATA)
		{
			int hack=0;
			// Need data...
			struct blk *blk;

			if(!(sb->flags & SBUF_HEADER_WRITTEN_TO_MANIFEST))
			{
				if(manio_write_sbuf(chmanio, sb)) return -1;
				sb->flags |= SBUF_HEADER_WRITTEN_TO_MANIFEST;
			}

			while((blk=sb->burp2->bstart)
				&& blk->got==BLK_GOT
				&& (blk->next || backup_end))
			{
				if(*(blk->save_path))
				{
					if(manio_write_sig_and_path(chmanio,
						blk)) return -1;
					if(chmanio->sig_count==0)
					{
						// Have finished a manifest
						// file. Want to start using
						// it as a dedup candidate
						// now.
						iobuf_from_str(wbuf,
							CMD_MANIFEST,
							chmanio->fpath);
						printf("send manifest path\n");
						if(chfd->write(chfd, wbuf))
                					return -1;

						if(!blk->requested)
						{
						  // Also let the client know,
						  // so that it can free memory
						  // if there was a long
						  // consecutive number of
						  // unrequested blocks.
						  get_wbuf_from_wrap_up(wbuf,
							blk->index);
						  if(asfd->write(asfd, wbuf))
                					return -1;
						}
					}
				}
/*
				else
				{
					// This gets hit if there is a zero
					// length file.
					printf("!!!!!!!!!!!!! no data; %s\n",
						sb->path);
					exit(1);
				}
*/

				if(blk==sb->burp2->bend)
				{
					slist->head=sb->next;
					if(!(blist->head=sb->burp2->bstart))
						blist->tail=NULL;
					sanity_before_sbuf_free(slist, sb);
					sbuf_free(&sb);
					hack=1;
					break;
				}

				if(sb->burp2->bsighead==sb->burp2->bstart)
					sb->burp2->bsighead=blk->next;
				sb->burp2->bstart=blk->next;
				if(blk==blist->blk_from_champ_chooser)
					blist->blk_from_champ_chooser=blk->next;

				//printf("freeing blk %d\n", blk->index);
				blk_free(&blk);
			}
			if(hack) continue;
			if(!(blist->head=sb->burp2->bstart))
				blist->tail=NULL;
			break;
		}
		else
		{
			// No change, can go straight in.
			if(manio_write_sbuf(chmanio, sb)) return -1;

			// Move along.
			slist->head=sb->next;

			sanity_before_sbuf_free(slist, sb);
			sbuf_free(&sb);
		}
	}
	return 0;
}
Ejemplo n.º 27
0
static int manio_component_to_chfd(struct asfd *chfd, char *path)
{
	struct iobuf wbuf;
	iobuf_from_str(&wbuf, CMD_MANIFEST, path);
	return chfd->write(chfd, &wbuf);
}