2 * Unix SMB/CIFS implementation.
3 * Provide a connection to GPFS specific features
4 * Copyright (C) Volker Lendecke 2005
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.
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.
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/>.
21 #include "system/filesys.h"
22 #include "smbd/smbd.h"
25 #include <gpfs_fcntl.h>
26 #include "libcli/security/security.h"
29 static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
30 static int (*gpfs_set_lease_fn)(int fd, unsigned int type);
31 static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
32 static int (*gpfs_putacl_fn)(char *pathname, int flags, void *acl);
33 static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
35 static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags,
36 struct gpfs_winattr *attrs);
37 static int (*gpfs_get_winattrs_path_fn)(char *pathname,
38 struct gpfs_winattr *attrs);
39 static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
40 static int (*gpfs_prealloc_fn)(int fd, gpfs_off64_t start, gpfs_off64_t bytes);
41 static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
42 static int (*gpfs_lib_init_fn)(int flags);
43 static int (*gpfs_set_times_path_fn)(char *pathname, int flags,
44 gpfs_timestruc_t times[4]);
45 static int (*gpfs_quotactl_fn)(char *pathname, int cmd, int id, void *bufferP);
46 static int (*gpfs_fcntl_fn)(gpfs_file_t fileDesc, void *fcntlArgP);
47 static int (*gpfs_getfilesetid_fn)(char *pathname, char *name, int *idP);
49 int gpfswrap_init(void)
57 l = dlopen("libgpfs.so", RTLD_LAZY);
62 gpfs_set_share_fn = dlsym(l, "gpfs_set_share");
63 gpfs_set_lease_fn = dlsym(l, "gpfs_set_lease");
64 gpfs_getacl_fn = dlsym(l, "gpfs_getacl");
65 gpfs_putacl_fn = dlsym(l, "gpfs_putacl");
66 gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
67 gpfs_set_winattrs_path_fn = dlsym(l, "gpfs_set_winattrs_path");
68 gpfs_get_winattrs_path_fn = dlsym(l, "gpfs_get_winattrs_path");
69 gpfs_get_winattrs_fn = dlsym(l, "gpfs_get_winattrs");
70 gpfs_prealloc_fn = dlsym(l, "gpfs_prealloc");
71 gpfs_ftruncate_fn = dlsym(l, "gpfs_ftruncate");
72 gpfs_lib_init_fn = dlsym(l, "gpfs_lib_init");
73 gpfs_set_times_path_fn = dlsym(l, "gpfs_set_times_path");
74 gpfs_quotactl_fn = dlsym(l, "gpfs_quotactl");
75 gpfs_fcntl_fn = dlsym(l, "gpfs_fcntl");
76 gpfs_getfilesetid_fn = dlsym(l, "gpfs_getfilesetid");
81 int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
83 if (gpfs_set_share_fn == NULL) {
88 return gpfs_set_share_fn(fd, allow, deny);
91 int gpfswrap_set_lease(int fd, unsigned int type)
93 if (gpfs_set_lease_fn == NULL) {
98 return gpfs_set_lease_fn(fd, type);
101 int gpfswrap_getacl(char *pathname, int flags, void *acl)
103 if (gpfs_getacl_fn == NULL) {
108 return gpfs_getacl_fn(pathname, flags, acl);
111 int gpfswrap_putacl(char *pathname, int flags, void *acl)
113 if (gpfs_putacl_fn == NULL) {
118 return gpfs_putacl_fn(pathname, flags, acl);
121 int gpfswrap_get_realfilename_path(char *pathname, char *filenamep, int *len)
123 if (gpfs_get_realfilename_path_fn == NULL) {
128 return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
131 int gpfswrap_set_winattrs_path(char *pathname, int flags,
132 struct gpfs_winattr *attrs)
134 if (gpfs_set_winattrs_path_fn == NULL) {
139 return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
142 int gpfswrap_get_winattrs_path(char *pathname, struct gpfs_winattr *attrs)
144 if (gpfs_get_winattrs_path_fn == NULL) {
149 return gpfs_get_winattrs_path_fn(pathname, attrs);
152 int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
154 if (gpfs_get_winattrs_fn == NULL) {
159 return gpfs_get_winattrs_fn(fd, attrs);
162 int gpfswrap_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes)
164 if (gpfs_prealloc_fn == NULL) {
169 return gpfs_prealloc_fn(fd, start, bytes);
172 int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
174 if (gpfs_ftruncate_fn == NULL) {
179 return gpfs_ftruncate_fn(fd, length);
182 int gpfswrap_lib_init(int flags)
184 if (gpfs_lib_init_fn == NULL) {
189 return gpfs_lib_init_fn(flags);
192 int gpfswrap_set_times_path(char *pathname, int flags,
193 gpfs_timestruc_t times[4])
195 if (gpfs_set_times_path_fn == NULL) {
200 return gpfs_set_times_path_fn(pathname, flags, times);
203 bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
206 unsigned int allow = GPFS_SHARE_NONE;
207 unsigned int deny = GPFS_DENY_NONE;
210 if ((fsp == NULL) || (fsp->fh == NULL) || (fsp->fh->fd < 0)) {
211 /* No real file, don't disturb */
215 allow |= (access_mask & (FILE_WRITE_DATA|FILE_APPEND_DATA|
216 DELETE_ACCESS)) ? GPFS_SHARE_WRITE : 0;
217 allow |= (access_mask & (FILE_READ_DATA|FILE_EXECUTE)) ?
220 if (allow == GPFS_SHARE_NONE) {
221 DEBUG(10, ("special case am=no_access:%x\n",access_mask));
224 deny |= (share_access & FILE_SHARE_WRITE) ?
226 deny |= (share_access & (FILE_SHARE_READ)) ?
229 DEBUG(10, ("am=%x, allow=%d, sa=%x, deny=%d\n",
230 access_mask, allow, share_access, deny));
232 result = gpfswrap_set_share(fsp->fh->fd, allow, deny);
234 if (errno == ENOSYS) {
235 DEBUG(5, ("VFS module vfs_gpfs loaded, but gpfs "
236 "set_share function support not available. "
237 "Allowing access\n"));
240 DEBUG(10, ("gpfs_set_share failed: %s\n",
245 return (result == 0);
248 int set_gpfs_lease(int fd, int leasetype)
250 int gpfs_type = GPFS_LEASE_NONE;
252 if (leasetype == F_RDLCK) {
253 gpfs_type = GPFS_LEASE_READ;
255 if (leasetype == F_WRLCK) {
256 gpfs_type = GPFS_LEASE_WRITE;
259 /* we unconditionally set CAP_LEASE, rather than looking for
260 -1/EACCES as there is a bug in some versions of
261 libgpfs_gpl.so which results in a leaked fd on /dev/ss0
262 each time we try this with the wrong capabilities set
264 linux_set_lease_capability();
265 return gpfswrap_set_lease(fd, gpfs_type);
268 int get_gpfs_quota(const char *pathname, int type, int id,
269 struct gpfs_quotaInfo *qi)
273 if (!gpfs_quotactl_fn) {
279 ret = gpfs_quotactl_fn(discard_const_p(char, pathname),
280 GPFS_QCMD(Q_GETQUOTA, type), id, qi);
283 if (errno == GPFS_E_NO_QUOTA_INST) {
284 DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
286 DEBUG(0, ("Get quota failed, type %d, id, %d, "
287 "errno %d.\n", type, id, errno));
293 DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
294 type, id, qi->blockUsage, qi->blockHardLimit,
295 qi->blockSoftLimit, qi->blockGraceTime));
300 int get_gpfs_fset_id(const char *pathname, int *fset_id)
302 int err, fd, errno_fcntl;
305 gpfsFcntlHeader_t hdr;
306 gpfsGetFilesetName_t fsn;
309 if (!gpfs_fcntl_fn || !gpfs_getfilesetid_fn) {
314 arg.hdr.totalLength = sizeof(arg);
315 arg.hdr.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
316 arg.hdr.fcntlReserved = 0;
317 arg.fsn.structLen = sizeof(arg.fsn);
318 arg.fsn.structType = GPFS_FCNTL_GET_FILESETNAME;
320 fd = open(pathname, O_RDONLY);
322 DEBUG(1, ("Could not open %s: %s\n",
323 pathname, strerror(errno)));
327 err = gpfs_fcntl_fn(fd, &arg);
333 DEBUG(1, ("GPFS_FCNTL_GET_FILESETNAME for %s failed: %s\n",
334 pathname, strerror(errno)));
338 err = gpfs_getfilesetid_fn(discard_const_p(char, pathname),
339 arg.fsn.buffer, fset_id);
341 DEBUG(1, ("gpfs_getfilesetid for %s failed: %s\n",
342 pathname, strerror(errno)));
347 static void timespec_to_gpfs_time(struct timespec ts, gpfs_timestruc_t *gt,
350 if (!null_timespec(ts)) {
352 gt[idx].tv_sec = ts.tv_sec;
353 gt[idx].tv_nsec = ts.tv_nsec;
354 DEBUG(10, ("Setting GPFS time %d, flags 0x%x\n", idx, *flags));
358 int smbd_gpfs_set_times_path(char *path, struct smb_file_time *ft)
360 gpfs_timestruc_t gpfs_times[4];
364 ZERO_ARRAY(gpfs_times);
365 timespec_to_gpfs_time(ft->atime, gpfs_times, 0, &flags);
366 timespec_to_gpfs_time(ft->mtime, gpfs_times, 1, &flags);
367 /* No good mapping from LastChangeTime to ctime, not storing */
368 timespec_to_gpfs_time(ft->create_time, gpfs_times, 3, &flags);
371 DEBUG(10, ("nothing to do, return to avoid EINVAL\n"));
375 rc = gpfswrap_set_times_path(path, flags, gpfs_times);
377 if (rc != 0 && errno != ENOSYS) {
378 DEBUG(1,("gpfs_set_times() returned with error %s\n",