1 /*
2  *  Unix SMB/CIFS implementation.
3  *  Wrapper for GPFS library
4  *  Copyright (C) Volker Lendecke 2005
5  *  Copyright (C) Christof Schmitt 2015
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #include "replace.h"
22 #include "gpfswrap.h"
23 
24 static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
25 static int (*gpfs_set_lease_fn)(int fd, unsigned int type);
26 static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
27 static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
28 static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
29 					    int *len);
30 static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags,
31 					struct gpfs_winattr *attrs);
32 static int (*gpfs_set_winattrs_fn)(int fd, int flags,
33 				   struct gpfs_winattr *attrs);
34 static int (*gpfs_get_winattrs_path_fn)(char *pathname,
35 					struct gpfs_winattr *attrs);
36 static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
37 static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
38 static int (*gpfs_lib_init_fn)(int flags);
39 static int (*gpfs_set_times_path_fn)(char *pathname, int flags,
40 				     gpfs_timestruc_t times[4]);
41 static int (*gpfs_quotactl_fn)(char *pathname, int cmd, int id, void *bufp);
42 static int (*gpfs_getfilesetid_fn)(char *pathname, char *name, int *idp);
43 static int (*gpfs_init_trace_fn)(void);
44 static int (*gpfs_query_trace_fn)(void);
45 static void (*gpfs_add_trace_fn)(int level, const char *msg);
46 static void (*gpfs_fini_trace_fn)(void);
47 static int (*gpfs_fstat_x_fn)(int fd, unsigned int *litemask,
48 			      struct gpfs_iattr64 *iattr, size_t len);
49 static int (*gpfs_stat_x_fn)(const char *pathname, unsigned int *litemask,
50 			     struct gpfs_iattr64 *iattr, size_t len);
51 
gpfswrap_init(void)52 int gpfswrap_init(void)
53 {
54 	static void *l;
55 
56 	if (l != NULL) {
57 		return 0;
58 	}
59 
60 	l = dlopen("libgpfs.so", RTLD_LAZY);
61 	if (l == NULL) {
62 		return -1;
63 	}
64 
65 	gpfs_set_share_fn	      = dlsym(l, "gpfs_set_share");
66 	gpfs_set_lease_fn	      = dlsym(l, "gpfs_set_lease");
67 	gpfs_getacl_fn		      = dlsym(l, "gpfs_getacl");
68 	gpfs_putacl_fn		      = dlsym(l, "gpfs_putacl");
69 	gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
70 	gpfs_set_winattrs_path_fn     = dlsym(l, "gpfs_set_winattrs_path");
71 	gpfs_set_winattrs_fn	      = dlsym(l, "gpfs_set_winattrs");
72 	gpfs_get_winattrs_path_fn     = dlsym(l, "gpfs_get_winattrs_path");
73 	gpfs_get_winattrs_fn	      = dlsym(l, "gpfs_get_winattrs");
74 	gpfs_ftruncate_fn	      = dlsym(l, "gpfs_ftruncate");
75 	gpfs_lib_init_fn	      = dlsym(l, "gpfs_lib_init");
76 	gpfs_set_times_path_fn	      = dlsym(l, "gpfs_set_times_path");
77 	gpfs_quotactl_fn	      = dlsym(l, "gpfs_quotactl");
78 	gpfs_getfilesetid_fn	      = dlsym(l, "gpfs_getfilesetid");
79 	gpfs_init_trace_fn	      = dlsym(l, "gpfs_init_trace");
80 	gpfs_query_trace_fn	      = dlsym(l, "gpfs_query_trace");
81 	gpfs_add_trace_fn	      = dlsym(l, "gpfs_add_trace");
82 	gpfs_fini_trace_fn	      = dlsym(l, "gpfs_fini_trace");
83 	gpfs_fstat_x_fn	      = dlsym(l, "gpfs_fstat_x");
84 	gpfs_stat_x_fn		      = dlsym(l, "gpfs_stat_x");
85 
86 	return 0;
87 }
88 
gpfswrap_set_share(int fd,unsigned int allow,unsigned int deny)89 int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
90 {
91 	if (gpfs_set_share_fn == NULL) {
92 		errno = ENOSYS;
93 		return -1;
94 	}
95 
96 	return gpfs_set_share_fn(fd, allow, deny);
97 }
98 
gpfswrap_set_lease(int fd,unsigned int type)99 int gpfswrap_set_lease(int fd, unsigned int type)
100 {
101 	if (gpfs_set_lease_fn == NULL) {
102 		errno = ENOSYS;
103 		return -1;
104 	}
105 
106 	return gpfs_set_lease_fn(fd, type);
107 }
108 
gpfswrap_getacl(char * pathname,int flags,void * acl)109 int gpfswrap_getacl(char *pathname, int flags, void *acl)
110 {
111 	if (gpfs_getacl_fn == NULL) {
112 		errno = ENOSYS;
113 		return -1;
114 	}
115 
116 	return gpfs_getacl_fn(pathname, flags, acl);
117 }
118 
gpfswrap_putacl(char * pathname,int flags,void * acl)119 int gpfswrap_putacl(char *pathname, int flags, void *acl)
120 {
121 	if (gpfs_putacl_fn == NULL) {
122 		errno = ENOSYS;
123 		return -1;
124 	}
125 
126 	return gpfs_putacl_fn(pathname, flags, acl);
127 }
128 
gpfswrap_get_realfilename_path(char * pathname,char * filenamep,int * len)129 int gpfswrap_get_realfilename_path(char *pathname, char *filenamep, int *len)
130 {
131 	if (gpfs_get_realfilename_path_fn == NULL) {
132 		errno = ENOSYS;
133 		return -1;
134 	}
135 
136 	return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
137 }
138 
gpfswrap_set_winattrs_path(char * pathname,int flags,struct gpfs_winattr * attrs)139 int gpfswrap_set_winattrs_path(char *pathname, int flags,
140 			       struct gpfs_winattr *attrs)
141 {
142 	if (gpfs_set_winattrs_path_fn == NULL) {
143 		errno = ENOSYS;
144 		return -1;
145 	}
146 
147 	return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
148 }
149 
gpfswrap_set_winattrs(int fd,int flags,struct gpfs_winattr * attrs)150 int gpfswrap_set_winattrs(int fd, int flags, struct gpfs_winattr *attrs)
151 {
152 	if (gpfs_set_winattrs_fn == NULL) {
153 		errno = ENOSYS;
154 		return -1;
155 	}
156 
157 	return gpfs_set_winattrs_fn(fd, flags, attrs);
158 }
159 
gpfswrap_get_winattrs_path(char * pathname,struct gpfs_winattr * attrs)160 int gpfswrap_get_winattrs_path(char *pathname, struct gpfs_winattr *attrs)
161 {
162 	if (gpfs_get_winattrs_path_fn == NULL) {
163 		errno = ENOSYS;
164 		return -1;
165 	}
166 
167 	return gpfs_get_winattrs_path_fn(pathname, attrs);
168 }
169 
gpfswrap_get_winattrs(int fd,struct gpfs_winattr * attrs)170 int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
171 {
172 	if (gpfs_get_winattrs_fn == NULL) {
173 		errno = ENOSYS;
174 		return -1;
175 	}
176 
177 	return gpfs_get_winattrs_fn(fd, attrs);
178 }
179 
gpfswrap_ftruncate(int fd,gpfs_off64_t length)180 int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
181 {
182 	if (gpfs_ftruncate_fn == NULL) {
183 		errno = ENOSYS;
184 		return -1;
185 	}
186 
187 	return gpfs_ftruncate_fn(fd, length);
188 }
189 
gpfswrap_lib_init(int flags)190 int gpfswrap_lib_init(int flags)
191 {
192 	if (gpfs_lib_init_fn == NULL) {
193 		errno = ENOSYS;
194 		return -1;
195 	}
196 
197 	return gpfs_lib_init_fn(flags);
198 }
199 
gpfswrap_set_times_path(char * pathname,int flags,gpfs_timestruc_t times[4])200 int gpfswrap_set_times_path(char *pathname, int flags,
201 			    gpfs_timestruc_t times[4])
202 {
203 	if (gpfs_set_times_path_fn == NULL) {
204 		errno = ENOSYS;
205 		return -1;
206 	}
207 
208 	return gpfs_set_times_path_fn(pathname, flags, times);
209 }
210 
gpfswrap_quotactl(char * pathname,int cmd,int id,void * bufp)211 int gpfswrap_quotactl(char *pathname, int cmd, int id, void *bufp)
212 {
213 	if (gpfs_quotactl_fn == NULL) {
214 		errno = ENOSYS;
215 		return -1;
216 	}
217 
218 	return gpfs_quotactl_fn(pathname, cmd, id, bufp);
219 }
220 
gpfswrap_getfilesetid(char * pathname,char * name,int * idp)221 int gpfswrap_getfilesetid(char *pathname, char *name, int *idp)
222 {
223 	if (gpfs_getfilesetid_fn == NULL) {
224 		errno = ENOSYS;
225 		return -1;
226 	}
227 
228 	return gpfs_getfilesetid_fn(pathname, name, idp);
229 }
230 
gpfswrap_init_trace(void)231 int gpfswrap_init_trace(void)
232 {
233 	if (gpfs_init_trace_fn == NULL) {
234 		errno = ENOSYS;
235 		return -1;
236 	}
237 
238 	return gpfs_init_trace_fn();
239 }
240 
gpfswrap_query_trace(void)241 int gpfswrap_query_trace(void)
242 {
243 	if (gpfs_query_trace_fn == NULL) {
244 		errno = ENOSYS;
245 		return -1;
246 	}
247 
248 	return gpfs_query_trace_fn();
249 }
250 
gpfswrap_add_trace(int level,const char * msg)251 void gpfswrap_add_trace(int level, const char *msg)
252 {
253 	if (gpfs_add_trace_fn == NULL) {
254 		return;
255 	}
256 
257 	gpfs_add_trace_fn(level, msg);
258 }
259 
gpfswrap_fini_trace(void)260 void gpfswrap_fini_trace(void)
261 {
262 	if (gpfs_fini_trace_fn == NULL) {
263 		return;
264 	}
265 
266 	gpfs_fini_trace_fn();
267 }
268 
gpfswrap_fstat_x(int fd,unsigned int * litemask,struct gpfs_iattr64 * iattr,size_t len)269 int gpfswrap_fstat_x(int fd, unsigned int *litemask,
270 		     struct gpfs_iattr64 *iattr, size_t len)
271 {
272 	if (gpfs_fstat_x_fn == NULL) {
273 		errno = ENOSYS;
274 		return -1;
275 	}
276 
277 	return gpfs_fstat_x_fn(fd, litemask, iattr, len);
278 }
279 
gpfswrap_stat_x(const char * pathname,unsigned int * litemask,struct gpfs_iattr64 * iattr,size_t len)280 int gpfswrap_stat_x(const char *pathname, unsigned int *litemask,
281 		    struct gpfs_iattr64 *iattr, size_t len)
282 {
283 	if (gpfs_stat_x_fn == NULL) {
284 		errno = ENOSYS;
285 		return -1;
286 	}
287 
288 	return gpfs_stat_x_fn(pathname, litemask, iattr, len);
289 }
290