-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathget_rid_status.c
More file actions
106 lines (89 loc) · 2.78 KB
/
get_rid_status.c
File metadata and controls
106 lines (89 loc) · 2.78 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
#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 "fmttypes.h"
#include "allocation.h"
#include "ibp_ClientLib.h"
#include "ibp_server.h"
#include "log.h"
#include "fmttypes.h"
#include "subnet.h"
#include "ibp_time.h"
#include "print_alloc.h"
#include "osd_abstract.h"
#include "resource.h"
#define HEADER_SIZE 4096
#define MAX_SIZE 100
//*************************************************************************
//*************************************************************************
int main(int argc, char **argv)
{
int start_option, i;
char buffer[10240];
char *afile, *state;
osd_fd_t *afd;
osd_t *dev;
struct stat sbuf;
resource_usage_file_t usage;
//printf("sizeof(Allocation_t)=" LU " ALLOC_HEADER=%d\n", sizeof(Allocation_t), ALLOC_HEADER);
if (argc < 2) {
printf("get_rid_status [-d debug_level] RID|RID_usage_file\n");
printf(" -d debug_level Sets the debug level. Default is 0.\n");
printf("\n");
return(0);
}
//** Initialize APR for use
assert(apr_initialize() == APR_SUCCESS);
set_log_level(0);
i = 1;
do {
start_option = i;
if (strcmp("-d", argv[i]) == 0) {
i++;
set_log_level(atoi(argv[i])); i++;
}
} while (start_option < i);
//** Determine if this is just a RID or an actual full file path
afile = argv[i]; i++;
//** Assume it's a complete file path
if (stat(afile, &sbuf) != 0) { //** Not an absolute path. Flip to a RID check
snprintf(buffer, sizeof(buffer), "/depot/rid-%s/data/1/1", afile);
if (stat(buffer, &sbuf) != 0) {
printf("ERROR: Unable to open usage file: %s or %s\n", afile, buffer);
return(1);
}
afile = buffer;
}
//** Read the Allocation ***
dev = osd_mount_fs("loopback", 10, 1000); //** Mount the file via loopback
fs_associate_id(dev, 0, afile); //** Associate the loopback id with the actual file
afd = osd_open(dev, 0, OSD_READ_MODE);
assert(afd != NULL);
//** Read the Usage
if (osd_read(dev, afd, 0, sizeof(usage), &usage) != sizeof(usage)) {
printf("ERROR reading usage file! (%s)\n", afile);
return(1);
}
printf("Status file: %s\n", afile);
state = (usage.state == 0) ? "GOOD" : "BAD";
printf("State: %s\n", state);
printf("Used space[SOFT]: " I64T "\n", usage.used_space[ALLOC_SOFT]);
printf("Used space[HARD]: " I64T "\n", usage.used_space[ALLOC_HARD]);
printf("Total allocations: " I64T "\n", usage.n_allocs);
printf("Total alias allocations: " I64T "\n", usage.n_alias);
printf("\n");
osd_close(dev, afd);
osd_umount(dev);
apr_terminate();
return(usage.state);
}