summaryrefslogtreecommitdiffstats
path: root/lib/util/gpfswrap.c
blob: 2f15bf452cf6ab6a6a4043729d392fa457d0fd07 (plain)
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
 *  Unix SMB/CIFS implementation.
 *  Wrapper for GPFS library
 *  Copyright (C) Volker Lendecke 2005
 *  Copyright (C) Christof Schmitt 2015
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "replace.h"
#include "gpfswrap.h"

static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
static int (*gpfs_set_lease_fn)(int fd, unsigned int type);
static int (*gpfs_fgetacl_fn)(int fd, int flags, void *acl);
static int (*gpfs_putacl_fn)(const char *pathname, int flags, void *acl);
static int (*gpfs_get_realfilename_path_fn)(const char *pathname,
					    char *filenamep,
					    int *len);
static int (*gpfs_register_cifs_export_fn)(void);
static int (*gpfs_set_winattrs_path_fn)(const char *pathname,
					int flags,
					struct gpfs_winattr *attrs);
static int (*gpfs_set_winattrs_fn)(int fd, int flags,
				   struct gpfs_winattr *attrs);
static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
static int (*gpfs_lib_init_fn)(int flags);
static int (*gpfs_set_times_fn)(int fd, int flags, gpfs_timestruc_t times[4]);
static int (*gpfs_set_times_path_fn)(char *path,
				     int flags,
				     gpfs_timestruc_t times[4]);
static int (*gpfs_quotactl_fn)(const char *pathname,
			       int cmd,
			       int id,
			       void *bufp);
static int (*gpfs_init_trace_fn)(void);
static int (*gpfs_query_trace_fn)(void);
static void (*gpfs_add_trace_fn)(int level, const char *msg);
static void (*gpfs_fini_trace_fn)(void);
static int (*gpfs_fstat_x_fn)(int fd, unsigned int *litemask,
			      struct gpfs_iattr64 *iattr, size_t len);
static int (*gpfs_stat_x_fn)(const char *pathname, unsigned int *litemask,
			     struct gpfs_iattr64 *iattr, size_t len);

int gpfswrap_init(void)
{
	static void *l;

	if (l != NULL) {
		return 0;
	}

	l = dlopen("libgpfs.so", RTLD_LAZY);
	if (l == NULL) {
		return -1;
	}

	gpfs_set_share_fn	      = dlsym(l, "gpfs_set_share");
	gpfs_set_lease_fn	      = dlsym(l, "gpfs_set_lease");
	gpfs_fgetacl_fn		      = dlsym(l, "gpfs_getacl_fd");
	gpfs_putacl_fn		      = dlsym(l, "gpfs_putacl");
	gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
	gpfs_register_cifs_export_fn  = dlsym(l, "gpfs_register_cifs_export");
	gpfs_set_winattrs_path_fn     = dlsym(l, "gpfs_set_winattrs_path");
	gpfs_set_winattrs_fn	      = dlsym(l, "gpfs_set_winattrs");
	gpfs_get_winattrs_fn	      = dlsym(l, "gpfs_get_winattrs");
	gpfs_ftruncate_fn	      = dlsym(l, "gpfs_ftruncate");
	gpfs_lib_init_fn	      = dlsym(l, "gpfs_lib_init");
	gpfs_set_times_fn	      = dlsym(l, "gpfs_set_times");
	gpfs_set_times_path_fn	      = dlsym(l, "gpfs_set_times_path");
	gpfs_quotactl_fn	      = dlsym(l, "gpfs_quotactl");
	gpfs_init_trace_fn	      = dlsym(l, "gpfs_init_trace");
	gpfs_query_trace_fn	      = dlsym(l, "gpfs_query_trace");
	gpfs_add_trace_fn	      = dlsym(l, "gpfs_add_trace");
	gpfs_fini_trace_fn	      = dlsym(l, "gpfs_fini_trace");
	gpfs_fstat_x_fn	      = dlsym(l, "gpfs_fstat_x");
	gpfs_stat_x_fn		      = dlsym(l, "gpfs_stat_x");

	return 0;
}

int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
{
	if (gpfs_set_share_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_set_share_fn(fd, allow, deny);
}

int gpfswrap_set_lease(int fd, unsigned int type)
{
	if (gpfs_set_lease_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_set_lease_fn(fd, type);
}

int gpfswrap_fgetacl(int fd, int flags, void *acl)
{
	if (gpfs_fgetacl_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_fgetacl_fn(fd, flags, acl);
}

int gpfswrap_putacl(const char *pathname, int flags, void *acl)
{
	if (gpfs_putacl_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_putacl_fn(pathname, flags, acl);
}

int gpfswrap_get_realfilename_path(const char *pathname,
				   char *filenamep,
				   int *len)
{
	if (gpfs_get_realfilename_path_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
}

int gpfswrap_register_cifs_export(void)
{
	if (gpfs_register_cifs_export_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_register_cifs_export_fn();
}

int gpfswrap_set_winattrs_path(const char *pathname,
			       int flags,
			       struct gpfs_winattr *attrs)
{
	if (gpfs_set_winattrs_path_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
}

int gpfswrap_set_winattrs(int fd, int flags, struct gpfs_winattr *attrs)
{
	if (gpfs_set_winattrs_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_set_winattrs_fn(fd, flags, attrs);
}

int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
{
	if (gpfs_get_winattrs_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_get_winattrs_fn(fd, attrs);
}

int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
{
	if (gpfs_ftruncate_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_ftruncate_fn(fd, length);
}

int gpfswrap_lib_init(int flags)
{
	if (gpfs_lib_init_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_lib_init_fn(flags);
}

int gpfswrap_set_times(int fd, int flags, gpfs_timestruc_t times[4])
{
	if (gpfs_set_times_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_set_times_fn(fd, flags, times);
}

int gpfswrap_set_times_path(char *path, int flags, gpfs_timestruc_t times[4])
{
	if (gpfs_set_times_path_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_set_times_path_fn(path, flags, times);
}

int gpfswrap_quotactl(const char *pathname, int cmd, int id, void *bufp)
{
	if (gpfs_quotactl_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_quotactl_fn(pathname, cmd, id, bufp);
}

int gpfswrap_init_trace(void)
{
	if (gpfs_init_trace_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_init_trace_fn();
}

int gpfswrap_query_trace(void)
{
	if (gpfs_query_trace_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_query_trace_fn();
}

void gpfswrap_add_trace(int level, const char *msg)
{
	if (gpfs_add_trace_fn == NULL) {
		return;
	}

	gpfs_add_trace_fn(level, msg);
}

void gpfswrap_fini_trace(void)
{
	if (gpfs_fini_trace_fn == NULL) {
		return;
	}

	gpfs_fini_trace_fn();
}

int gpfswrap_fstat_x(int fd, unsigned int *litemask,
		     struct gpfs_iattr64 *iattr, size_t len)
{
	if (gpfs_fstat_x_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_fstat_x_fn(fd, litemask, iattr, len);
}

int gpfswrap_stat_x(const char *pathname, unsigned int *litemask,
		    struct gpfs_iattr64 *iattr, size_t len)
{
	if (gpfs_stat_x_fn == NULL) {
		errno = ENOSYS;
		return -1;
	}

	return gpfs_stat_x_fn(pathname, litemask, iattr, len);
}