-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend-sep.c
129 lines (120 loc) · 4.25 KB
/
send-sep.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* FS-test (send-sep.c)
* Send a separator string to log server
*
* (C) Copyright 2010-2012 TOSHIBA CORPORATION
*
* This source code is licensed under the GNU General Public License,
* Version 2. See the file COPYING for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <fcntl.h>
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/syscall.h>
#include <linux/reboot.h>
#include "config.h"
#include "common.h"
/*
* Shared objects
*/
int progress;
char s_char;
/*
* main thread ->
* (thread1 for file creation * N)
*/
int main(int argc, char *argv[])
{
int opt;
long fsize;
long wsize;
int gran;
char *serv_ipstr;
char *io_name;
int soc;
int len;
char str[256];
struct sockaddr_in *serv_addr;
// set default val
gran = GRAN_DEFAULT;
fsize = FSIZE_DEFAULT;
wsize = FSIZE_DEFAULT;
serv_ipstr = NULL;
io_name = NULL;
while ((opt = getopt(argc, argv, "s:i:g:z:")) != -1) {
switch (opt) {
case 'g': // granularity
gran = atoi(optarg);
if (gran < 0){
fprintf(stderr, "WARNING: GRANULARITY too small (g<0)\n");
gran = GRAN_DEFAULT;
}
break;
case 'i': // net log
serv_ipstr = optarg;
printf("fsk %s\n",serv_ipstr);
if (serv_ipstr == NULL){
fprintf(stderr, "Server IP ADDR??\n");
exit(EXIT_FAILURE);
}
break;
case 'z': // iosched
io_name = optarg;
//io_name = "noop";
printf("fsk %s\n",io_name);
if (io_name == NULL){
fprintf(stderr, "IOsched??\n");
exit(EXIT_FAILURE);
}
break;
case 's': // FILE size
fsize = atoi(optarg);
fsize = fsize * 1024; // change to KB
if (fsize < 8192){
fprintf(stderr,
"BUF size too small! < 8K: %ld\n",
fsize);
fsize = FSIZE_DEFAULT;
}
break;
default:
fprintf(stderr,
"Usage: %s [-n num_thr] [-f num_file]\n",
argv[0]);
fprintf(stderr,
" [-s file_size] [-t test_type]\n");
exit(EXIT_SUCCESS);
}
}
/* save parameters */
fprintf(stderr, "FILE SIZE : %ld\n", fsize);
fprintf(stderr, "GRANULARITY : %d\n", gran);
fprintf(stderr, "IO SHCED : %s\n", io_name);
/* prepare socket */
serv_addr = (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
memset(serv_addr, 0, sizeof(struct sockaddr_in));
fprintf(stderr, "IP ADDR:%s\n", serv_ipstr);
if (inet_aton(serv_ipstr, &serv_addr->sin_addr) == 0){
fprintf(stderr, "Server IP ADDR??\n");
exit(EXIT_FAILURE);
};
serv_addr->sin_port = htons(COMM_PORT);
serv_addr->sin_family = AF_INET;
soc = socket(AF_INET, SOCK_DGRAM, 0);
// prepare data
gran = 1 << gran;
len = fsize / gran;
fprintf(stderr, "WRITE SIZE : %d\n", len);
sprintf((char *)&str, "8888\t%d\t%lu\t%s\n", len, fsize, io_name);
len = strlen(str);
sendto(soc, &str, len, 0, serv_addr, sizeof(struct sockaddr_in));
return 0;
}