cmogstored.git  about / heads / tags
alternative mogstored implementation for MogileFS
blob 849903f26831ef2c836b132b0db62b4030b4a896 1262 bytes (raw)
$ git show HEAD:test/ioutil-1.c	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
 
/*
 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 */
#include "check.h"

int main(void)
{
	char tmp[MOG_IOUTIL_LEN];
	dev_t i;

	/* just ensure we don't segfault */
	mog_iou_active(1);
	mog_iou_active(2);

	/* we should get back what we wrote */
	memcpy(tmp, "6.66", 5);
	mog_iou_write(3, tmp);
	mog_iou_active(3);
	memset(tmp, 0, sizeof(tmp));
	mog_iou_read(3, tmp);
	assert(strcmp(tmp, "6.66") == 0);

	/* cleanup should've clobbered us */
	mog_iou_cleanup_begin();
	mog_iou_cleanup_finish();
	memset(tmp, 0, sizeof(tmp));
	mog_iou_read(3, tmp);
	assert(strcmp(tmp, "-") == 0);

	/* cleanup should not clobber active entries */
	memcpy(tmp, "6.66", 5);
	mog_iou_write(3, tmp);
	mog_iou_cleanup_begin();
	mog_iou_active(3);
	mog_iou_cleanup_finish();
	mog_iou_read(3, tmp);
	assert(strcmp(tmp, "6.66") == 0);

	/* create many devices and cleanup all of them */
	for (i = 0; i < 100; i++)
		mog_iou_active(i);
	mog_iou_cleanup_begin();
	mog_iou_active(3);
	mog_iou_cleanup_finish();
	mog_iou_read(3, tmp);
	assert(strcmp(tmp, "6.66") == 0);
	for (i = 0; i < 100; i++) {
		if (i == 3)
			continue;
		mog_iou_read(i, tmp);
		assert(strcmp(tmp, "-") == 0);
	}

	return 0;
}

git clone https://yhbt.net/cmogstored.git