s3-vfs: Use the system. namespace for fake ACLs
[kai/samba.git] / source3 / modules / gpfs.c
index 5b0d7d04abdefa4c3424907ab85ad5a41eedf348..db6025642b140d63026d8bcea176e30d958c22e9 100644 (file)
 #include "system/filesys.h"
 #include "smbd/smbd.h"
 
-#ifdef HAVE_GPFS
-
+#include <fcntl.h>
 #include "libcli/security/security.h"
+#include "gpfs_fcntl.h"
 #include "gpfs_gpl.h"
 #include "vfs_gpfs.h"
 
-static bool gpfs_getrealfilename;
-static bool gpfs_winattr;
-static bool gpfs_do_ftruncate;
-
 static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
 static int (*gpfs_set_lease_fn)(int fd, unsigned int leaseType);
 static int (*gpfs_getacl_fn)(char *pathname, int flags, void *acl);
@@ -40,8 +36,12 @@ static int (*gpfs_get_realfilename_path_fn)(char *pathname, char *filenamep,
 static int (*gpfs_set_winattrs_path_fn)(char *pathname, int flags, struct gpfs_winattr *attrs);
 static int (*gpfs_get_winattrs_path_fn)(char *pathname, struct gpfs_winattr *attrs);
 static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
+static int (*gpfs_prealloc_fn)(int fd, gpfs_off64_t startOffset, gpfs_off64_t bytesToPrealloc);
 static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
 static int (*gpfs_lib_init_fn)(int flags);
+static int (*gpfs_quotactl_fn)(char *pathname, int cmd, int id, void *bufferP);
+static int (*gpfs_fcntl_fn)(gpfs_file_t fileDesc, void *fcntlArgP);
+static int (*gpfs_getfilesetid_fn)(char *pathname, char *name, int *idP);
 
 bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
                        uint32 share_access)
@@ -138,7 +138,7 @@ int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
 
 int smbd_gpfs_ftruncate(int fd, gpfs_off64_t length)
 {
-       if (!gpfs_do_ftruncate || (gpfs_ftruncate_fn == NULL)) {
+       if (gpfs_ftruncate_fn == NULL) {
                errno = ENOSYS;
                return -1;
        }
@@ -149,8 +149,7 @@ int smbd_gpfs_ftruncate(int fd, gpfs_off64_t length)
 int smbd_gpfs_get_realfilename_path(char *pathname, char *filenamep,
                                    int *buflen)
 {
-       if ((!gpfs_getrealfilename)
-           || (gpfs_get_realfilename_path_fn == NULL)) {
+       if (gpfs_get_realfilename_path_fn == NULL) {
                errno = ENOSYS;
                return -1;
        }
@@ -161,7 +160,7 @@ int smbd_gpfs_get_realfilename_path(char *pathname, char *filenamep,
 int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
 {
 
-        if ((!gpfs_winattr) || (gpfs_get_winattrs_path_fn == NULL)) {
+       if (gpfs_get_winattrs_path_fn == NULL) {
                 errno = ENOSYS;
                 return -1;
         }
@@ -172,7 +171,7 @@ int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
 int smbd_fget_gpfs_winattrs(int fd, struct gpfs_winattr *attrs)
 {
 
-        if ((!gpfs_winattr) || (gpfs_get_winattrs_fn == NULL)) {
+       if (gpfs_get_winattrs_fn == NULL) {
                 errno = ENOSYS;
                 return -1;
         }
@@ -180,9 +179,19 @@ int smbd_fget_gpfs_winattrs(int fd, struct gpfs_winattr *attrs)
         return gpfs_get_winattrs_fn(fd, attrs);
 }
 
+int smbd_gpfs_prealloc(int fd, gpfs_off64_t start, gpfs_off64_t bytes)
+{
+       if (gpfs_prealloc_fn == NULL) {
+               errno = ENOSYS;
+               return -1;
+       }
+
+       return gpfs_prealloc_fn(fd, start, bytes);
+}
+
 int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
 {
-        if ((!gpfs_winattr) || (gpfs_set_winattrs_path_fn == NULL)) {
+       if (gpfs_set_winattrs_path_fn == NULL) {
                 errno = ENOSYS;
                 return -1;
         }
@@ -191,6 +200,75 @@ int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
         return gpfs_set_winattrs_path_fn(pathname,flags, attrs);
 }
 
+int get_gpfs_quota(const char *pathname, int type, int id,
+                  struct gpfs_quotaInfo *qi)
+{
+       int ret;
+
+       if (!gpfs_quotactl_fn) {
+               errno = ENOSYS;
+               return -1;
+       }
+
+       ZERO_STRUCTP(qi);
+       ret = gpfs_quotactl_fn(discard_const_p(char, pathname),
+                              GPFS_QCMD(Q_GETQUOTA, type), id, qi);
+
+       if (ret) {
+               if (errno == GPFS_E_NO_QUOTA_INST) {
+                       DEBUG(10, ("Quotas disabled on GPFS filesystem.\n"));
+               } else {
+                       DEBUG(0, ("Get quota failed, type %d, id, %d, "
+                                 "errno %d.\n", type, id, errno));
+               }
+
+               return ret;
+       }
+
+       DEBUG(10, ("quota type %d, id %d, blk u:%lld h:%lld s:%lld gt:%u\n",
+                  type, id, qi->blockUsage, qi->blockHardLimit,
+                  qi->blockSoftLimit, qi->blockGraceTime));
+
+       return ret;
+}
+
+int get_gpfs_fset_id(const char *pathname, int *fset_id)
+{
+       int err, fd, errno_fcntl;
+
+       struct {
+               gpfsFcntlHeader_t hdr;
+               gpfsGetFilesetName_t fsn;
+       } arg;
+
+       if (!gpfs_fcntl_fn || !gpfs_getfilesetid_fn) {
+               errno = ENOSYS;
+               return -1;
+       }
+
+       arg.hdr.totalLength = sizeof(arg);
+       arg.hdr.fcntlVersion = GPFS_FCNTL_CURRENT_VERSION;
+       arg.hdr.fcntlReserved = 0;
+       arg.fsn.structLen = sizeof(arg.fsn);
+       arg.fsn.structType = GPFS_FCNTL_GET_FILESETNAME;
+
+       fd = open(pathname, O_RDONLY);
+       if (fd == -1)
+               return fd;
+
+       err = gpfs_fcntl_fn(fd, &arg);
+       errno_fcntl = errno;
+       close(fd);
+
+       if (err) {
+               errno = errno_fcntl;
+               return err;
+       }
+
+       return gpfs_getfilesetid_fn(discard_const_p(char, pathname),
+                                   arg.fsn.buffer, fset_id);
+}
+
 void smbd_gpfs_lib_init()
 {
        if (gpfs_lib_init_fn) {
@@ -263,76 +341,12 @@ void init_gpfs(void)
        init_gpfs_function(&gpfs_get_winattrs_path_fn,"gpfs_get_winattrs_path");
         init_gpfs_function(&gpfs_set_winattrs_path_fn,"gpfs_set_winattrs_path");
         init_gpfs_function(&gpfs_get_winattrs_fn,"gpfs_get_winattrs");
+       init_gpfs_function(&gpfs_prealloc_fn, "gpfs_prealloc");
        init_gpfs_function(&gpfs_ftruncate_fn, "gpfs_ftruncate");
         init_gpfs_function(&gpfs_lib_init_fn,"gpfs_lib_init");
+       init_gpfs_function(&gpfs_quotactl_fn, "gpfs_quotactl");
+       init_gpfs_function(&gpfs_fcntl_fn, "gpfs_fcntl");
+       init_gpfs_function(&gpfs_getfilesetid_fn, "gpfs_getfilesetid");
 
-       gpfs_getrealfilename = lp_parm_bool(-1, "gpfs", "getrealfilename",
-                                           True);
-       gpfs_winattr = lp_parm_bool(-1, "gpfs", "winattr", False);
-       gpfs_do_ftruncate = lp_parm_bool(-1, "gpfs", "ftruncate", True);
-
-       return;
-}
-
-#else
-
-int set_gpfs_lease(int snum, int leasetype)
-{
-       DEBUG(0, ("'VFS module smbgpfs loaded, without gpfs support compiled\n"));
-
-       /* We need to indicate that no GPFS is around by returning ENOSYS, so
-        * that the normal linux kernel oplock code is called. */
-       errno = ENOSYS;
-       return -1;
-}
-
-bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
-                       uint32 share_access)
-{
-       DEBUG(0, ("VFS module - smbgpfs.so loaded, without gpfs support compiled\n"));
-       /* Don't disturb but complain */
-       return True;
-}
-
-int smbd_gpfs_getacl(char *pathname, int flags, void *acl)
-{
-       errno = ENOSYS;
-       return -1;
-}
-
-int smbd_gpfs_putacl(char *pathname, int flags, void *acl)
-{
-       errno = ENOSYS;
-       return -1;
-}
-
-int smbd_gpfs_get_realfilename_path(char *pathname, char *fileamep,
-                                   int *buflen)
-{
-       errno = ENOSYS;
-       return -1;
-}
-
-int set_gpfs_winattrs(char *pathname,int flags,struct gpfs_winattr *attrs)
-{
-        errno = ENOSYS;
-        return -1;
-}
-
-int get_gpfs_winattrs(char *pathname,struct gpfs_winattr *attrs)
-{
-        errno = ENOSYS;
-        return -1;
-}
-
-void smbd_gpfs_lib_init()
-{
-       return;
-}
-
-void init_gpfs(void)
-{
        return;
 }
-
-#endif /* HAVE_GPFS */