From a9cfd80d8722f9af7fc18ea70115a6b1b1033168 Mon Sep 17 00:00:00 2001 From: Christof Schmitt Date: Fri, 2 Mar 2012 14:26:19 -0700 Subject: [PATCH] s3:vfs_gpfs: add GPFS api calls for quota and free space reporting 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 | 76 ++++++++++++++++++++++++++++++++++++++++++++++ source3/modules/vfs_gpfs.h | 4 +++ 2 files changed, 80 insertions(+) diff --git a/source3/modules/gpfs.c b/source3/modules/gpfs.c index 5ce23810c42..f17c6bb252d 100644 --- a/source3/modules/gpfs.c +++ b/source3/modules/gpfs.c @@ -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; } diff --git a/source3/modules/vfs_gpfs.h b/source3/modules/vfs_gpfs.h index 4a05841feba..4a9528ae058 100644 --- a/source3/modules/vfs_gpfs.h +++ b/source3/modules/vfs_gpfs.h @@ -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(); -- 2.11.4.GIT