gpfs: Simplify initialization for gpfs library wrapper
authorChristof Schmitt <cs@samba.org>
Wed, 18 Feb 2015 17:14:22 +0000 (10:14 -0700)
committerChristof Schmitt <cs@samba.org>
Mon, 2 Mar 2015 21:31:07 +0000 (22:31 +0100)
Merge the code for initializing the function pointers in one function.

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
source3/modules/gpfs.c
source3/modules/vfs_gpfs.c
source3/modules/vfs_gpfs.h

index b2ca704e0489b89e4b5f3c7b11d815fea54fc329..933d491e0a1a81649518402e45168e1a91f3ed7e 100644 (file)
@@ -44,6 +44,38 @@ 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);
 
+int gpfswrap_init(void)
+{
+       static void *l;
+
+       if (l != NULL) {
+               return 0;
+       }
+
+       l = dlopen("libgpfs.so", RTLD_LAZY);
+       if (l == NULL) {
+               return -1;
+       }
+
+       gpfs_set_share_fn             = dlsym(l, "gpfs_set_share");
+       gpfs_set_lease_fn             = dlsym(l, "gpfs_set_lease");
+       gpfs_getacl_fn                = dlsym(l, "gpfs_getacl");
+       gpfs_putacl_fn                = dlsym(l, "gpfs_putacl");
+       gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
+       gpfs_set_winattrs_path_fn     = dlsym(l, "gpfs_set_winattrs_path");
+       gpfs_get_winattrs_path_fn     = dlsym(l, "gpfs_get_winattrs_path");
+       gpfs_get_winattrs_fn          = dlsym(l, "gpfs_get_winattrs");
+       gpfs_prealloc_fn              = dlsym(l, "gpfs_prealloc");
+       gpfs_ftruncate_fn             = dlsym(l, "gpfs_ftruncate");
+       gpfs_lib_init_fn              = dlsym(l, "gpfs_lib_init");
+       gpfs_set_times_path_fn        = dlsym(l, "gpfs_set_times_path");
+       gpfs_quotactl_fn              = dlsym(l, "gpfs_quotactl");
+       gpfs_fcntl_fn                 = dlsym(l, "gpfs_fcntl");
+       gpfs_getfilesetid_fn          = dlsym(l, "gpfs_getfilesetid");
+
+       return 0;
+}
+
 bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
                        uint32 share_access)
 {
@@ -331,67 +363,3 @@ int smbd_gpfs_set_times_path(char *path, struct smb_file_time *ft)
 
        return rc;
 }
-
-static bool init_gpfs_function_lib(void *plibhandle_pointer,
-                                  const char *libname,
-                                  void *pfn_pointer, const char *fn_name)
-{
-       bool did_open_here = false;
-       void **libhandle_pointer = (void **)plibhandle_pointer;
-       void **fn_pointer = (void **)pfn_pointer;
-
-       DEBUG(10, ("trying to load name %s from %s\n",
-                  fn_name, libname));
-
-       if (*libhandle_pointer == NULL) {
-               *libhandle_pointer = dlopen(libname, RTLD_LAZY);
-               did_open_here = true;
-       }
-       if (*libhandle_pointer == NULL) {
-               DEBUG(10, ("Could not open lib %s\n", libname));
-               return false;
-       }
-
-       *fn_pointer = dlsym(*libhandle_pointer, fn_name);
-       if (*fn_pointer == NULL) {
-               DEBUG(10, ("Did not find symbol %s in lib %s\n",
-                          fn_name, libname));
-               if (did_open_here) {
-                       dlclose(*libhandle_pointer);
-                       *libhandle_pointer = NULL;
-               }
-               return false;
-       }
-
-       return true;
-}
-
-static bool init_gpfs_function(void *fn_pointer, const char *fn_name)
-{
-       static void *libgpfs_handle = NULL;
-
-       return init_gpfs_function_lib(&libgpfs_handle, "libgpfs.so",
-                                     fn_pointer, fn_name);
-}
-
-void init_gpfs(void)
-{
-       init_gpfs_function(&gpfs_set_share_fn, "gpfs_set_share");
-       init_gpfs_function(&gpfs_set_lease_fn, "gpfs_set_lease");
-       init_gpfs_function(&gpfs_getacl_fn, "gpfs_getacl");
-       init_gpfs_function(&gpfs_putacl_fn, "gpfs_putacl");
-       init_gpfs_function(&gpfs_get_realfilename_path_fn,
-                          "gpfs_get_realfilename_path");
-       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_set_times_path_fn, "gpfs_set_times_path");
-       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 3d99830b15249ad7e7c0a1500b9ae5ca12c7d355..7d1ea88416a2303fc068a15fb5fc64b00b9d7fc8 100644 (file)
@@ -2347,7 +2347,12 @@ static struct vfs_fn_pointers vfs_gpfs_fns = {
 NTSTATUS vfs_gpfs_init(void);
 NTSTATUS vfs_gpfs_init(void)
 {
-       init_gpfs();
+       int ret;
+
+       ret = gpfswrap_init();
+       if (ret != 0) {
+               DEBUG(1, ("Could not initialize GPFS library wrapper\n"));
+       }
 
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "gpfs",
                                &vfs_gpfs_fns);
index 728231f146b64465af9eda81eb4d9e9d0e380867..37b58f712c743a4711be386182ffa16558c0114b 100644 (file)
@@ -27,6 +27,7 @@
 #define GPFS_GETACL_NATIVE 0x00000004
 #endif
 
+int gpfswrap_init(void);
 bool set_gpfs_sharemode(files_struct *fsp, uint32 access_mask,
                        uint32 share_access);
 int set_gpfs_lease(int fd, int leasetype);
@@ -44,5 +45,4 @@ int get_gpfs_quota(const char *pathname, int type, int id,
 int get_gpfs_fset_id(const char *pathname, int *fset_id);
 int smbd_gpfs_set_times_path(char *path, struct smb_file_time *ft);
 
-void init_gpfs(void);
 void smbd_gpfs_lib_init(void);