source: branches/samba-3.5.x/source3/modules/gpfs.c@ 940

Last change on this file since 940 was 599, checked in by Herwig Bauernfeind, 14 years ago

Samba 3.5: Update trunk to 3.5.9

File size: 8.7 KB
Line 
1/*
2 * Unix SMB/CIFS implementation.
3 * Provide a connection to GPFS specific features
4 * Copyright (C) Volker Lendecke 2005
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "includes.h"
21
22#ifdef HAVE_GPFS
23
24#include "gpfs_gpl.h"
25#include "vfs_gpfs.h"
26
27static bool gpfs_getrealfilename;
28static bool gpfs_winattr;
29static bool gpfs_do_ftruncate;
30
31static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
32static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType);
33static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
34static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
35static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
36 int *buflen);
37static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags, struct gpfs_winattr *attrs);
38static int (*gpfs_get_winattrs_path_fn)(char *pathname, struct gpfs_winattr *attrs);
39static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
40static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
41
42bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
43 uint32 share_access)
44{
45 unsigned int allow = GPFS_SHARE_NONE;
46 unsigned int deny = GPFS_DENY_NONE;
47 int result;
48
49 if (gpfs_set_share_fn == NULL) {
50 return False;
51 }
52
53 if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
54 /* No real file, don't disturb */
55 return True;
56 }
57
58 allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
59 DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
60 allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
61 GPFS_SHARE_READ : 0;
62
63 if (allow == GPFS_SHARE_NONE) {
64 DEBUG(10, ("special case am=no_access:%x\n",access_mask));
65 }
66 else {
67 deny |= (share_access & FILE_SHARE_WRITE) ?
68 0 : GPFS_DENY_WRITE;
69 deny |= (share_access & (FILE_SHARE_READ)) ?
70 0 : GPFS_DENY_READ;
71 }
72 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
73 access_mask, allow, share_access, deny));
74
75 result = gpfs_set_share_fn(fsp->fh->fd, allow, deny);
76 if (result != 0) {
77 if (errno == ENOSYS) {
78 DEBUG(5, ("VFS module vfs_gpfs loaded, but no gpfs "
79 "support has been compiled into Samba. Allowing access\n"));
80 return True;
81 } else {
82 DEBUG(10, ("gpfs_set_share failed: %s\n",
83 strerror(errno)));
84 }
85 }
86
87 return (result == 0);
88}
89
90int set_gpfs_lease(int fd, int leasetype)
91{
92 int gpfs_type = GPFS_LEASE_NONE;
93
94 if (gpfs_set_lease_fn == NULL) {
95 errno = EINVAL;
96 return -1;
97 }
98
99 if (leasetype == F_RDLCK) {
100 gpfs_type = GPFS_LEASE_READ;
101 }
102 if (leasetype == F_WRLCK) {
103 gpfs_type = GPFS_LEASE_WRITE;
104 }
105
106 /* we unconditionally set CAP_LEASE, rather than looking for
107 -1/EACCES as there is a bug in some versions of
108 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
109 each time we try this with the wrong capabilities set
110 */
111 linux_set_lease_capability();
112 return gpfs_set_lease_fn(fd, gpfs_type);
113}
114
115int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
116{
117 if (gpfs_getacl_fn == NULL) {
118 errno = ENOSYS;
119 return -1;
120 }
121
122 return gpfs_getacl_fn(pathname, flags, acl);
123}
124
125int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
126{
127 if (gpfs_putacl_fn == NULL) {
128 errno = ENOSYS;
129 return -1;
130 }
131
132 return gpfs_putacl_fn(pathname, flags, acl);
133}
134
135int smbd_gpfs_ftrunctate(int fd, gpfs_off64_t length)
136{
137 if (!gpfs_do_ftruncate || (gpfs_ftruncate_fn == NULL)) {
138 errno = ENOSYS;
139 return -1;
140 }
141
142 return gpfs_ftruncate_fn(fd, length);
143}
144
145int smbd_gpfs_get_realfilename_path(char *pathname, char *filenamep,
146 int *buflen)
147{
148 if ((!gpfs_getrealfilename)
149 || (gpfs_get_realfilename_path_fn == NULL)) {
150 errno = ENOSYS;
151 return -1;
152 }
153
154 return gpfs_get_realfilename_path_fn(pathname, filenamep, buflen);
155}
156
157int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
158{
159
160 if ((!gpfs_winattr) || (gpfs_get_winattrs_path_fn == NULL)) {
161 errno = ENOSYS;
162 return -1;
163 }
164 DEBUG(10, ("gpfs_get_winattrs_path:open call %s\n",pathname));
165 return gpfs_get_winattrs_path_fn(pathname, attrs);
166}
167
168int smbd_fget_gpfs_winattrs(int fd, struct gpfs_winattr *attrs)
169{
170
171 if ((!gpfs_winattr) || (gpfs_get_winattrs_fn == NULL)) {
172 errno = ENOSYS;
173 return -1;
174 }
175 DEBUG(10, ("gpfs_get_winattrs_path:open call %d\n", fd));
176 return gpfs_get_winattrs_fn(fd, attrs);
177}
178
179int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
180{
181 if ((!gpfs_winattr) || (gpfs_set_winattrs_path_fn == NULL)) {
182 errno = ENOSYS;
183 return -1;
184 }
185
186 DEBUG(10, ("gpfs_set_winattrs_path:open call %s\n",pathname));
187 return gpfs_set_winattrs_path_fn(pathname,flags, attrs);
188}
189
190static bool init_gpfs_function_lib(void *plibhandle_pointer,
191 const char *libname,
192 void *pfn_pointer, const char *fn_name)
193{
194 bool did_open_here = false;
195 void **libhandle_pointer = (void **)plibhandle_pointer;
196 void **fn_pointer = (void **)pfn_pointer;
197
198 DEBUG(10, ("trying to load name %s from %s\n",
199 fn_name, libname));
200
201 if (*libhandle_pointer == NULL) {
202 *libhandle_pointer = dlopen(libname, RTLD_LAZY);
203 did_open_here = true;
204 }
205 if (*libhandle_pointer == NULL) {
206 DEBUG(10, ("Could not open lib %s\n", libname));
207 return false;
208 }
209
210 *fn_pointer = dlsym(*libhandle_pointer, fn_name);
211 if (*fn_pointer == NULL) {
212 DEBUG(10, ("Did not find symbol %s in lib %s\n",
213 fn_name, libname));
214 if (did_open_here) {
215 dlclose(*libhandle_pointer);
216 *libhandle_pointer = NULL;
217 }
218 return false;
219 }
220
221 return true;
222}
223
224static bool init_gpfs_function(void *fn_pointer, const char *fn_name)
225{
226 static void *libgpfs_handle = NULL;
227 static void *libgpfs_gpl_handle = NULL;
228
229 if (init_gpfs_function_lib(&libgpfs_handle, "libgpfs.so",
230 fn_pointer, fn_name)) {
231 return true;
232 }
233 if (init_gpfs_function_lib(&libgpfs_gpl_handle, "libgpfs_gpl.so",
234 fn_pointer, fn_name)) {
235 return true;
236 }
237 return false;
238}
239
240void init_gpfs(void)
241{
242 init_gpfs_function(&gpfs_set_share_fn, "gpfs_set_share");
243 init_gpfs_function(&gpfs_set_lease_fn, "gpfs_set_lease");
244 init_gpfs_function(&gpfs_getacl_fn, "gpfs_getacl");
245 init_gpfs_function(&gpfs_putacl_fn, "gpfs_putacl");
246 init_gpfs_function(&gpfs_get_realfilename_path_fn,
247 "gpfs_get_realfilename_path");
248 init_gpfs_function(&gpfs_get_winattrs_path_fn,"gpfs_get_winattrs_path");
249 init_gpfs_function(&gpfs_set_winattrs_path_fn,"gpfs_set_winattrs_path");
250 init_gpfs_function(&gpfs_get_winattrs_fn,"gpfs_get_winattrs");
251 init_gpfs_function(&gpfs_ftruncate_fn,"gpfs_ftruncate");
252
253 gpfs_getrealfilename = lp_parm_bool(-1, "gpfs", "getrealfilename",
254 True);
255 gpfs_winattr = lp_parm_bool(-1, "gpfs", "winattr", False);
256
257 gpfs_do_ftruncate = lp_parm_bool(-1, "gpfs", "ftruncate", True);
258
259 return;
260}
261
262#else
263
264int set_gpfs_lease(int snum, int leasetype)
265{
266 DEBUG(0, ("'VFS module smbgpfs loaded, without gpfs support compiled\n"));
267
268 /* We need to indicate that no GPFS is around by returning ENOSYS, so
269 * that the normal linux kernel oplock code is called. */
270 errno = ENOSYS;
271 return -1;
272}
273
274bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
275 uint32 share_access)
276{
277 DEBUG(0, ("VFS module - smbgpfs.so loaded, without gpfs support compiled\n"));
278 /* Don't disturb but complain */
279 return True;
280}
281
282int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
283{
284 errno = ENOSYS;
285 return -1;
286}
287
288int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
289{
290 errno = ENOSYS;
291 return -1;
292}
293
294int smbd_gpfs_get_realfilename_path(char *pathname, char *fileamep,
295 int *buflen)
296{
297 errno = ENOSYS;
298 return -1;
299}
300
301int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
302{
303 errno = ENOSYS;
304 return -1;
305}
306
307int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
308{
309 errno = ENOSYS;
310 return -1;
311}
312
313void init_gpfs(void)
314{
315 return;
316}
317
318#endif /* HAVE_GPFS */
Note: See TracBrowser for help on using the repository browser.