Пример #1
0
/*
  send the next offline file fetch request
*/
static void test_offline(struct offline_state *state)
{
	struct composite_context *ctx;
	double lat;

	lat = timeval_elapsed(&state->tv_start);
	if (latencies[state->op] < lat) {
		latencies[state->op] = lat;
	}

	state->op = (enum offline_op) (random() % OP_ENDOFLIST);
	
	state->fnumber = random() % torture_numops;
	talloc_free(state->fname);
	state->fname = filename(state->mem_ctx, state->fnumber);

	state->tv_start = timeval_current();

	switch (state->op) {
	case OP_LOADFILE:
		state->loadfile = talloc_zero(state->mem_ctx, struct smb_composite_loadfile);
		state->loadfile->in.fname = state->fname;
	
		ctx = smb_composite_loadfile_send(state->tree, state->loadfile);
		if (ctx == NULL) {
			printf("Failed to setup loadfile for %s\n", state->fname);
			test_failed = true;
		}

		talloc_steal(state->loadfile, ctx);

		ctx->async.fn = loadfile_callback;
		ctx->async.private_data = state;
		break;

	case OP_SAVEFILE:
		state->savefile = talloc_zero(state->mem_ctx, struct smb_composite_savefile);

		state->savefile->in.fname = state->fname;
		state->savefile->in.data  = talloc_size(state->savefile, FILE_SIZE);
		state->savefile->in.size  = FILE_SIZE;
		memset(state->savefile->in.data, 1+(state->fnumber%255), FILE_SIZE);
	
		ctx = smb_composite_savefile_send(state->tree, state->savefile);
		if (ctx == NULL) {
			printf("Failed to setup savefile for %s\n", state->fname);
			test_failed = true;
		}

		talloc_steal(state->savefile, ctx);

		ctx->async.fn = savefile_callback;
		ctx->async.private_data = state;
		break;

	case OP_SETOFFLINE: {
		union smb_setfileinfo io;
		ZERO_STRUCT(io);
		io.setattr.level = RAW_SFILEINFO_SETATTR;
		io.setattr.in.attrib = FILE_ATTRIBUTE_OFFLINE;
		io.setattr.in.file.path = state->fname;
		/* make the file 1 hour old, to get past mininum age restrictions 
		   for HSM systems */
		io.setattr.in.write_time = time(NULL) - 60*60;

		state->req = smb_raw_setpathinfo_send(state->tree, &io);
		if (state->req == NULL) {
			printf("Failed to setup setoffline for %s\n", state->fname);
			test_failed = true;
		}
		
		state->req->async.fn = setoffline_callback;
		state->req->async.private_data = state;
		break;
	}

	case OP_GETOFFLINE: {
		union smb_fileinfo io;
		ZERO_STRUCT(io);
		io.getattr.level = RAW_FILEINFO_GETATTR;
		io.getattr.in.file.path = state->fname;

		state->req = smb_raw_pathinfo_send(state->tree, &io);
		if (state->req == NULL) {
			printf("Failed to setup getoffline for %s\n", state->fname);
			test_failed = true;
		}
		
		state->req->async.fn = getoffline_callback;
		state->req->async.private_data = state;
		break;
	}

	default:
		printf("bad operation??\n");
		break;
	}
}
Пример #2
0
/*
  test a simple savefile/loadfile combination
*/
static bool test_loadfile(struct smbcli_state *cli, struct torture_context *tctx)
{
	const char *fname = BASEDIR "\\test.txt";
	NTSTATUS status;
	struct smb_composite_savefile io1;
	struct smb_composite_loadfile io2;
	struct composite_context **c;
	uint8_t *data;
	size_t len = random() % 100000;
	const int num_ops = 50;
	int i;
	int *count = talloc_zero(tctx, int);

	data = talloc_array(tctx, uint8_t, len);

	generate_random_buffer(data, len);

	io1.in.fname = fname;
	io1.in.data  = data;
	io1.in.size  = len;

	printf("testing savefile\n");

	status = smb_composite_savefile(cli->tree, &io1);
	if (!NT_STATUS_IS_OK(status)) {
		printf("(%s) savefile failed: %s\n", __location__,nt_errstr(status));
		return false;
	}

	io2.in.fname = fname;

	printf("testing parallel loadfile with %d ops\n", num_ops);

	c = talloc_array(tctx, struct composite_context *, num_ops);

	for (i=0;i<num_ops;i++) {
		c[i] = smb_composite_loadfile_send(cli->tree, &io2);
		c[i]->async.fn = loadfile_complete;
		c[i]->async.private_data = count;
	}

	printf("waiting for completion\n");
	while (*count != num_ops) {
		event_loop_once(cli->transport->socket->event.ctx);
		if (torture_setting_bool(tctx, "progress", true)) {
			printf("(%s) count=%d\r", __location__, *count);
			fflush(stdout);
		}
	}
	printf("count=%d\n", *count);
	
	for (i=0;i<num_ops;i++) {
		status = smb_composite_loadfile_recv(c[i], tctx);
		if (!NT_STATUS_IS_OK(status)) {
			printf("(%s) loadfile[%d] failed - %s\n", __location__, i, nt_errstr(status));
			return false;
		}

		if (io2.out.size != len) {
			printf("(%s) wrong length in returned data - %d should be %d\n",__location__,
			       io2.out.size, (int)len);
			return false;
		}
		
		if (memcmp(io2.out.data, data, len) != 0) {
			printf("(%s) wrong data in loadfile!\n",__location__);
			return false;
		}
	}

	talloc_free(data);

	return true;
}