-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexpire_list.c
More file actions
164 lines (134 loc) · 3.84 KB
/
expire_list.c
File metadata and controls
164 lines (134 loc) · 3.84 KB
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <assert.h>
#include "allocation.h"
#include "ibp_ClientLib.h"
#include "ibp_server.h"
#include "network.h"
#include "net_sock.h"
#include "log.h"
#include "dns_cache.h"
#include "fmttypes.h"
#include "cmd_send.h"
apr_time_t parse_time(char *buffer)
{
int time_unit[4] = { 1, 60, 3600, 86400 };
int err, count, i, j;
int num[4];
apr_time_t t;
char *tmp, *bstate;
//printf("parse_time: buffer = %s\n", buffer);
count = 0;
tmp = string_token(buffer, ":", &bstate, &err);
while (( err == 0) && (count < 4)) {
num[count] = atoi(tmp);
//printf("parse_time: num[%d] = %d\n", count, num[count]);
count++;
tmp = string_token(NULL, ":", &bstate, &err);
}
count--;
t = 0; j = 0;
for (i=count; i >= 0; i--) {
t = t + time_unit[j] * num[i];
j++;
}
//printf("parse_time: time = " TT "\n", t);
return(apr_time_make(t, 0));
}
//*************************************************************************
void parse_line(char *buffer, apr_time_t *t, osd_id_t *id, uint64_t *bytes)
{
char *bstate;
int fin;
*t = 0;
*id = 0;
*bytes = 0;
sscanf(string_token(buffer, " ", &bstate, &fin), TT, t);
sscanf(string_token(NULL, " ", &bstate, &fin), LU, id);
sscanf(string_token(NULL, " ", &bstate, &fin), LU, bytes);
// printf("t=" TT " * id=" LU " * b=" LU "\n", *t, *id, *bytes);
}
//*************************************************************************
//*************************************************************************
int main(int argc, char **argv)
{
int bufsize = 1024*1024;
char buffer[bufsize], *bstate;
int err, i, mode;
Net_timeout_t dt;
apr_time_t it;
osd_id_t id;
char print_time[128];
uint64_t bytes, total_bytes;
double fb1, fb2;
uint64_t base_unit;
double units;
NetStream_t *ns;
int timeout = 10;
if (argc < 7) {
printf("expire_list host port RID mode time count\n");
printf("\n");
printf(" mode - abs or rel\n");
printf(" time - Future time with format of days:hours:min:sec\n");
printf(" count - Number of allocations to retreive\n");
printf("\n");
return(0);
}
assert(apr_initialize() == APR_SUCCESS);
base_unit = 1024 * 1024;
units = base_unit;
units = 1.0 / units;
i = 1;
char *host = argv[i]; i++;
int port = atoi(argv[i]); i++;
char *rid = argv[i]; i++;
mode = 0;
if (strcmp(argv[i], "abs") == 0) mode = 1;
i++;
it = apr2ibp_time(parse_time(argv[i])); i++;
int count = atoi(argv[i]);
dns_cache_init(10);
set_net_timeout(&dt, 5, 0);
sprintf(buffer, "1 %d %s %d " TT " %d %d\n", INTERNAL_EXPIRE_LIST, rid, mode, it, count, timeout);
ns = cmd_send(host, port, buffer, &bstate, timeout);
if (ns == NULL) return(-1);
if (bstate != NULL) free(bstate);
//** Cycle through the data **
total_bytes = 0;
printf("n Time date ID mb_max total_max_mb\n");
printf("------------------------------------------------------------------------------------------------------\n");
err = 0;
i = 0;
while (err != -1) {
buffer[0] = '\0';
err = readline_netstream(ns, buffer, bufsize, dt);
//printf("err=%d buf=%s\n", err, buffer);
if (err == NS_OK) {
if (strcmp("END", buffer) == 0) { //** Finished
err = -1;
} else {
parse_line(buffer, &it, &id, &bytes);
apr_ctime(print_time, ibp2apr_time(it));
total_bytes = total_bytes + bytes;
fb1 = bytes * units;
fb2 = total_bytes * units;
printf("%4d " TT " * %s * " LU " * %lf * %lf\n", i, it, print_time, id, fb1, fb2);
}
}
i++;
}
close_netstream(ns);
printf("\n");
apr_terminate();
return(0);
}