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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <limits.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <glusterfs/api/glfs.h>
#include <glusterfs/api/glfs-handles.h>
int gfapi = 1;
#define LOG_ERR(func, ret) do { \
if (ret != 0) { \
fprintf (stderr, "%s : returned error ret(%d), errno(%d)\n", \
func, ret, errno); \
exit(1); \
} else { \
fprintf (stderr, "%s : returned %d\n", func, ret); \
} \
} while (0)
#define LOG_IF_NO_ERR(func, ret) do { \
if (ret == 0) { \
fprintf (stderr, "%s : hasn't returned error %d\n", \
func, ret); \
exit(1); \
} else { \
fprintf (stderr, "%s : returned %d\n", func, ret); \
} \
} while (0)
#define GLAPI_UUID_LENGTH 16
int
main (int argc, char *argv[])
{
glfs_t *fs = NULL;
glfs_t *fs2 = NULL;
int ret = 0, i;
glfs_fd_t *fd = NULL;
char *filename = "/a1";
char *filename2 = "/a2";
struct stat sb = {0, };
char *logfile = NULL;
char *volname = NULL;
char *hostname = NULL;
int cnt = 1;
int upcall_received = 0;
struct glfs_upcall *cbk = NULL;
struct glfs_object *root = NULL, *leaf = NULL;
unsigned char globjhdl[GFAPI_HANDLE_LENGTH];
unsigned char globjhdl2[GFAPI_HANDLE_LENGTH];
fprintf (stderr, "Starting libgfapi_fini\n");
if (argc != 4) {
fprintf (stderr, "Invalid argument\n");
exit(1);
}
hostname = argv[1];
volname = argv[2];
logfile = argv[3];
fs = glfs_new (volname);
if (!fs) {
fprintf (stderr, "glfs_new: returned NULL\n");
return 1;
}
ret = glfs_set_volfile_server (fs, "tcp", hostname, 24007);
LOG_ERR("glfs_set_volfile_server", ret);
ret = glfs_set_logging (fs, logfile, 7);
LOG_ERR("glfs_set_logging", ret);
ret = glfs_init (fs);
LOG_ERR("glfs_init", ret);
/* This does not block, but enables caching of events. Real
* applications like NFS-Ganesha run this in a thread before activity
* on the fs (through this instance) happens. */
ret = glfs_h_poll_upcall(fs, &cbk);
LOG_ERR ("glfs_h_poll_upcall", ret);
fs2 = glfs_new (volname);
if (!fs) {
fprintf (stderr, "glfs_new: returned NULL\n");
return 1;
}
ret = glfs_set_volfile_server (fs2, "tcp", hostname, 24007);
LOG_ERR("glfs_set_volfile_server", ret);
ret = glfs_set_logging (fs2, logfile, 7);
LOG_ERR("glfs_set_logging", ret);
ret = glfs_init (fs2);
LOG_ERR("glfs_init", ret);
sleep (2);
root = glfs_h_lookupat (fs, NULL, "/", &sb, 0);
if (!root) {
ret = -1;
LOG_ERR ("glfs_h_lookupat root", ret);
}
leaf = glfs_h_lookupat (fs, root, filename, &sb, 0);
if (!leaf) {
ret = -1;
LOG_IF_NO_ERR ("glfs_h_lookupat leaf", ret);
}
root = glfs_h_lookupat (fs2, NULL, "/", &sb, 0);
if (!root) {
ret = -1;
LOG_ERR ("glfs_h_lookupat root", ret);
}
leaf = glfs_h_creat (fs2, root, filename, O_RDWR, 0644, &sb);
if (!leaf) {
ret = -1;
LOG_ERR ("glfs_h_lookupat leaf", ret);
}
fprintf (stderr, "glfs_h_create leaf - %p\n", leaf);
while (cnt++ < 5 && !upcall_received) {
enum glfs_upcall_reason reason = 0;
struct glfs_upcall_inode *in_arg = NULL;
ret = glfs_h_poll_upcall(fs, &cbk);
LOG_ERR ("glfs_h_poll_upcall", ret);
if (ret)
goto retry;
reason = glfs_upcall_get_reason (cbk);
fprintf (stderr, "Upcall received(%d)\n", reason);
if (reason == GLFS_UPCALL_INODE_INVALIDATE) {
struct glfs_object *object = NULL;
in_arg = glfs_upcall_get_event (cbk);
object = glfs_upcall_inode_get_object (in_arg);
ret = glfs_h_extract_handle (root,
globjhdl+GLAPI_UUID_LENGTH,
GFAPI_HANDLE_LENGTH);
LOG_ERR("glfs_h_extract_handle", (ret != 16));
ret = glfs_h_extract_handle (object,
globjhdl2+GLAPI_UUID_LENGTH,
GFAPI_HANDLE_LENGTH);
LOG_ERR("glfs_h_extract_handle", (ret != 16));
if (memcmp (globjhdl+GLAPI_UUID_LENGTH,
globjhdl2+GLAPI_UUID_LENGTH, 16)) {
fprintf (stderr, "Error: gfid mismatch\n");
exit (1);
}
upcall_received = 1;
}
retry:
if (!upcall_received)
sleep (1); /* glfs_h_poll_upcall() does not block */
glfs_free (cbk);
cbk = NULL;
}
if (!upcall_received) {
fprintf (stderr, "Error: Upcall not received\n");
exit (1);
}
ret = glfs_fini(fs);
LOG_ERR("glfs_fini", ret);
fprintf (stderr, "End of libgfapi_fini\n");
exit(0);
}
|