s3:vfs_gpfs: add GPFS api calls for quota and free space reporting
authorChristof Schmitt <christof.schmitt@us.ibm.com>
Fri, 2 Mar 2012 21:26:19 +0000 (14:26 -0700)
committerChristian Ambach <ambi@samba.org>
Thu, 22 Mar 2012 17:41:22 +0000 (18:41 +0100)
Add the GPFS api calls for reporting the quotas and free space:
- get_gpfs_quota for querying a quota
- get_gpfs_fset_id for mapping a path to a fileset id

source3/modules/gpfs.c
source3/modules/vfs_gpfs.h

index 5ce23810c428a8c761abddcb1ddb8b17a3b54c43..f17c6bb252db9509dfe42f062ec74c4bf4e97bba 100644 (file)
@@ -22,6 +22,7 @@
 #include "smbd/smbd.h"
 
 #include "libcli/security/security.h"
+#include "gpfs_fcntl.h"
 #include "gpfs_gpl.h"
 #include "vfs_gpfs.h"
 
@@ -36,6 +37,9 @@ static int (*gpfs_get_winattrs_path_fn)(char *pathname, struct gpfs_winattr *att
 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_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)
@@ -184,6 +188,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) {
@@ -258,6 +331,9 @@ void init_gpfs(void)
         init_gpfs_function(&gpfs_get_winattrs_fn,"gpfs_get_winattrs");
        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");
 
        return;
 }
index 4a05841feba7c56c6946e8b831feda47e3ffbf9a..4a9528ae058c34bbc64d70df69abcd66d0a56e34 100644 (file)
@@ -34,5 +34,9 @@ int smbd_fget_gpfs_winattrs(int fd, struct gpfs_winattr *attrs);
 int get_gpfs_winattrs(char * pathname,struct gpfs_winattr *attrs);
 int set_gpfs_winattrs(char * pathname,int flags,struct gpfs_winattr *attrs);
 int smbd_gpfs_ftruncate(int fd, gpfs_off64_t length);
+int get_gpfs_quota(const char *pathname, int type, int id,
+                  struct gpfs_quotaInfo *qi);
+int get_gpfs_fset_id(const char *pathname, int *fset_id);
+
 void init_gpfs(void);
 void smbd_gpfs_lib_init();