forked from zincsoda/libheca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaster.c
63 lines (50 loc) · 1.56 KB
/
master.c
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
57
58
59
60
61
62
63
/*
* Steve Walsh <[email protected]>
*/
#include "libheca.h"
#define PAGE_SIZE 4096
#define NUM_PAGES 5
static struct svm_data svm_array[2] = {
{ .dsm_id = 1, .svm_id = 1, .ip = "192.168.4.1", .port = 4444 },
{ .dsm_id = 1, .svm_id = 2, .ip = "192.168.4.2", .port = 4444 }
};
static struct unmap_data mr_array[1] = {
{ .dsm_id = 1, .id = 1, .svm_ids = {2, 0} }
};
void notify(char *msg)
{
char x;
fprintf(stdout, "%s ... <press any key>", msg);
fscanf(stdin, "%c", &x);
}
int main()
{
int fd, i;
unsigned long dsm_mem_sz = PAGE_SIZE * 1000;
int svm_count = sizeof(svm_array) / sizeof(struct svm_data);
int mr_count = sizeof(mr_array) / sizeof(struct unmap_data);
void *mem = valloc(dsm_mem_sz);
if (!mem) {
printf("Could not allocate enough memory\n");
exit(1);
}
/* allocate just one memory region */
mr_array[0].addr = mem;
mr_array[0].sz = dsm_mem_sz;
fd = dsm_master_init(svm_count, svm_array, mr_count, mr_array, AUTO_UNMAP);
if (fd < 0) {
printf("Error initializing master node\n");
exit(1);
}
/* DSM is now setup and ready to use */
notify("get pages from client");
for (i = 0; i < NUM_PAGES; i++)
printf("%04d: %10.10s\n", i, (char *) mem+(PAGE_SIZE*i));
notify("dirty pages locally on master and push back to client");
memset(mem, 'c', PAGE_SIZE * NUM_PAGES);
for (i = 0; i < NUM_PAGES; i++)
printf("%04d: %10.10s\n", i, (char *) mem+(PAGE_SIZE*i));
notify("disconnect");
dsm_cleanup(fd);
return 0;
}