LCOV - code coverage report
Current view: top level - lib/util - gpfswrap.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 5 125 4.0 %
Date: 2021-09-23 10:06:22 Functions: 1 21 4.8 %

          Line data    Source code
       1             : /*
       2             :  *  Unix SMB/CIFS implementation.
       3             :  *  Wrapper for GPFS library
       4             :  *  Copyright (C) Volker Lendecke 2005
       5             :  *  Copyright (C) Christof Schmitt 2015
       6             :  *
       7             :  *  This program is free software; you can redistribute it and/or modify
       8             :  *  it under the terms of the GNU General Public License as published by
       9             :  *  the Free Software Foundation; either version 3 of the License, or
      10             :  *  (at your option) any later version.
      11             :  *
      12             :  *  This program is distributed in the hope that it will be useful,
      13             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :  *  GNU General Public License for more details.
      16             :  *
      17             :  *  You should have received a copy of the GNU General Public License
      18             :  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
      19             :  */
      20             : 
      21             : #include "replace.h"
      22             : #include "gpfswrap.h"
      23             : 
      24             : static int (*gpfs_set_share_fn)(int fd, unsigned int allow, unsigned int deny);
      25             : static int (*gpfs_set_lease_fn)(int fd, unsigned int type);
      26             : static int (*gpfs_getacl_fn)(const char *pathname, int flags, void *acl);
      27             : static int (*gpfs_putacl_fn)(const char *pathname, int flags, void *acl);
      28             : static int (*gpfs_get_realfilename_path_fn)(const char *pathname,
      29             :                                             char *filenamep,
      30             :                                             int *len);
      31             : static int (*gpfs_set_winattrs_path_fn)(const char *pathname,
      32             :                                         int flags,
      33             :                                         struct gpfs_winattr *attrs);
      34             : static int (*gpfs_set_winattrs_fn)(int fd, int flags,
      35             :                                    struct gpfs_winattr *attrs);
      36             : static int (*gpfs_get_winattrs_path_fn)(const char *pathname,
      37             :                                         struct gpfs_winattr *attrs);
      38             : static int (*gpfs_get_winattrs_fn)(int fd, struct gpfs_winattr *attrs);
      39             : static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
      40             : static int (*gpfs_lib_init_fn)(int flags);
      41             : static int (*gpfs_set_times_fn)(int fd, int flags, gpfs_timestruc_t times[4]);
      42             : static int (*gpfs_set_times_path_fn)(char *path,
      43             :                                      int flags,
      44             :                                      gpfs_timestruc_t times[4]);
      45             : static int (*gpfs_quotactl_fn)(const char *pathname,
      46             :                                int cmd,
      47             :                                int id,
      48             :                                void *bufp);
      49             : static int (*gpfs_init_trace_fn)(void);
      50             : static int (*gpfs_query_trace_fn)(void);
      51             : static void (*gpfs_add_trace_fn)(int level, const char *msg);
      52             : static void (*gpfs_fini_trace_fn)(void);
      53             : static int (*gpfs_fstat_x_fn)(int fd, unsigned int *litemask,
      54             :                               struct gpfs_iattr64 *iattr, size_t len);
      55             : static int (*gpfs_stat_x_fn)(const char *pathname, unsigned int *litemask,
      56             :                              struct gpfs_iattr64 *iattr, size_t len);
      57             : 
      58      160598 : int gpfswrap_init(void)
      59             : {
      60             :         static void *l;
      61             : 
      62      160598 :         if (l != NULL) {
      63           0 :                 return 0;
      64             :         }
      65             : 
      66      160598 :         l = dlopen("libgpfs.so", RTLD_LAZY);
      67      160598 :         if (l == NULL) {
      68      157081 :                 return -1;
      69             :         }
      70             : 
      71           0 :         gpfs_set_share_fn             = dlsym(l, "gpfs_set_share");
      72           0 :         gpfs_set_lease_fn             = dlsym(l, "gpfs_set_lease");
      73           0 :         gpfs_getacl_fn                = dlsym(l, "gpfs_getacl");
      74           0 :         gpfs_putacl_fn                = dlsym(l, "gpfs_putacl");
      75           0 :         gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
      76           0 :         gpfs_set_winattrs_path_fn     = dlsym(l, "gpfs_set_winattrs_path");
      77           0 :         gpfs_set_winattrs_fn          = dlsym(l, "gpfs_set_winattrs");
      78           0 :         gpfs_get_winattrs_path_fn     = dlsym(l, "gpfs_get_winattrs_path");
      79           0 :         gpfs_get_winattrs_fn          = dlsym(l, "gpfs_get_winattrs");
      80           0 :         gpfs_ftruncate_fn             = dlsym(l, "gpfs_ftruncate");
      81           0 :         gpfs_lib_init_fn              = dlsym(l, "gpfs_lib_init");
      82           0 :         gpfs_set_times_fn             = dlsym(l, "gpfs_set_times");
      83           0 :         gpfs_set_times_path_fn        = dlsym(l, "gpfs_set_times_path");
      84           0 :         gpfs_quotactl_fn              = dlsym(l, "gpfs_quotactl");
      85           0 :         gpfs_init_trace_fn            = dlsym(l, "gpfs_init_trace");
      86           0 :         gpfs_query_trace_fn           = dlsym(l, "gpfs_query_trace");
      87           0 :         gpfs_add_trace_fn             = dlsym(l, "gpfs_add_trace");
      88           0 :         gpfs_fini_trace_fn            = dlsym(l, "gpfs_fini_trace");
      89           0 :         gpfs_fstat_x_fn       = dlsym(l, "gpfs_fstat_x");
      90           0 :         gpfs_stat_x_fn                = dlsym(l, "gpfs_stat_x");
      91             : 
      92           0 :         return 0;
      93             : }
      94             : 
      95           0 : int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
      96             : {
      97           0 :         if (gpfs_set_share_fn == NULL) {
      98           0 :                 errno = ENOSYS;
      99           0 :                 return -1;
     100             :         }
     101             : 
     102           0 :         return gpfs_set_share_fn(fd, allow, deny);
     103             : }
     104             : 
     105           0 : int gpfswrap_set_lease(int fd, unsigned int type)
     106             : {
     107           0 :         if (gpfs_set_lease_fn == NULL) {
     108           0 :                 errno = ENOSYS;
     109           0 :                 return -1;
     110             :         }
     111             : 
     112           0 :         return gpfs_set_lease_fn(fd, type);
     113             : }
     114             : 
     115           0 : int gpfswrap_getacl(const char *pathname, int flags, void *acl)
     116             : {
     117           0 :         if (gpfs_getacl_fn == NULL) {
     118           0 :                 errno = ENOSYS;
     119           0 :                 return -1;
     120             :         }
     121             : 
     122           0 :         return gpfs_getacl_fn(pathname, flags, acl);
     123             : }
     124             : 
     125           0 : int gpfswrap_putacl(const char *pathname, int flags, void *acl)
     126             : {
     127           0 :         if (gpfs_putacl_fn == NULL) {
     128           0 :                 errno = ENOSYS;
     129           0 :                 return -1;
     130             :         }
     131             : 
     132           0 :         return gpfs_putacl_fn(pathname, flags, acl);
     133             : }
     134             : 
     135           0 : int gpfswrap_get_realfilename_path(const char *pathname,
     136             :                                    char *filenamep,
     137             :                                    int *len)
     138             : {
     139           0 :         if (gpfs_get_realfilename_path_fn == NULL) {
     140           0 :                 errno = ENOSYS;
     141           0 :                 return -1;
     142             :         }
     143             : 
     144           0 :         return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
     145             : }
     146             : 
     147           0 : int gpfswrap_set_winattrs_path(const char *pathname,
     148             :                                int flags,
     149             :                                struct gpfs_winattr *attrs)
     150             : {
     151           0 :         if (gpfs_set_winattrs_path_fn == NULL) {
     152           0 :                 errno = ENOSYS;
     153           0 :                 return -1;
     154             :         }
     155             : 
     156           0 :         return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
     157             : }
     158             : 
     159           0 : int gpfswrap_set_winattrs(int fd, int flags, struct gpfs_winattr *attrs)
     160             : {
     161           0 :         if (gpfs_set_winattrs_fn == NULL) {
     162           0 :                 errno = ENOSYS;
     163           0 :                 return -1;
     164             :         }
     165             : 
     166           0 :         return gpfs_set_winattrs_fn(fd, flags, attrs);
     167             : }
     168             : 
     169           0 : int gpfswrap_get_winattrs_path(const char *pathname,
     170             :                                struct gpfs_winattr *attrs)
     171             : {
     172           0 :         if (gpfs_get_winattrs_path_fn == NULL) {
     173           0 :                 errno = ENOSYS;
     174           0 :                 return -1;
     175             :         }
     176             : 
     177           0 :         return gpfs_get_winattrs_path_fn(pathname, attrs);
     178             : }
     179             : 
     180           0 : int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
     181             : {
     182           0 :         if (gpfs_get_winattrs_fn == NULL) {
     183           0 :                 errno = ENOSYS;
     184           0 :                 return -1;
     185             :         }
     186             : 
     187           0 :         return gpfs_get_winattrs_fn(fd, attrs);
     188             : }
     189             : 
     190           0 : int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
     191             : {
     192           0 :         if (gpfs_ftruncate_fn == NULL) {
     193           0 :                 errno = ENOSYS;
     194           0 :                 return -1;
     195             :         }
     196             : 
     197           0 :         return gpfs_ftruncate_fn(fd, length);
     198             : }
     199             : 
     200           0 : int gpfswrap_lib_init(int flags)
     201             : {
     202           0 :         if (gpfs_lib_init_fn == NULL) {
     203           0 :                 errno = ENOSYS;
     204           0 :                 return -1;
     205             :         }
     206             : 
     207           0 :         return gpfs_lib_init_fn(flags);
     208             : }
     209             : 
     210           0 : int gpfswrap_set_times(int fd, int flags, gpfs_timestruc_t times[4])
     211             : {
     212           0 :         if (gpfs_set_times_fn == NULL) {
     213           0 :                 errno = ENOSYS;
     214           0 :                 return -1;
     215             :         }
     216             : 
     217           0 :         return gpfs_set_times_fn(fd, flags, times);
     218             : }
     219             : 
     220           0 : int gpfswrap_set_times_path(char *path, int flags, gpfs_timestruc_t times[4])
     221             : {
     222           0 :         if (gpfs_set_times_path_fn == NULL) {
     223           0 :                 errno = ENOSYS;
     224           0 :                 return -1;
     225             :         }
     226             : 
     227           0 :         return gpfs_set_times_path_fn(path, flags, times);
     228             : }
     229             : 
     230           0 : int gpfswrap_quotactl(const char *pathname, int cmd, int id, void *bufp)
     231             : {
     232           0 :         if (gpfs_quotactl_fn == NULL) {
     233           0 :                 errno = ENOSYS;
     234           0 :                 return -1;
     235             :         }
     236             : 
     237           0 :         return gpfs_quotactl_fn(pathname, cmd, id, bufp);
     238             : }
     239             : 
     240           0 : int gpfswrap_init_trace(void)
     241             : {
     242           0 :         if (gpfs_init_trace_fn == NULL) {
     243           0 :                 errno = ENOSYS;
     244           0 :                 return -1;
     245             :         }
     246             : 
     247           0 :         return gpfs_init_trace_fn();
     248             : }
     249             : 
     250           0 : int gpfswrap_query_trace(void)
     251             : {
     252           0 :         if (gpfs_query_trace_fn == NULL) {
     253           0 :                 errno = ENOSYS;
     254           0 :                 return -1;
     255             :         }
     256             : 
     257           0 :         return gpfs_query_trace_fn();
     258             : }
     259             : 
     260           0 : void gpfswrap_add_trace(int level, const char *msg)
     261             : {
     262           0 :         if (gpfs_add_trace_fn == NULL) {
     263           0 :                 return;
     264             :         }
     265             : 
     266           0 :         gpfs_add_trace_fn(level, msg);
     267             : }
     268             : 
     269           0 : void gpfswrap_fini_trace(void)
     270             : {
     271           0 :         if (gpfs_fini_trace_fn == NULL) {
     272           0 :                 return;
     273             :         }
     274             : 
     275           0 :         gpfs_fini_trace_fn();
     276             : }
     277             : 
     278           0 : int gpfswrap_fstat_x(int fd, unsigned int *litemask,
     279             :                      struct gpfs_iattr64 *iattr, size_t len)
     280             : {
     281           0 :         if (gpfs_fstat_x_fn == NULL) {
     282           0 :                 errno = ENOSYS;
     283           0 :                 return -1;
     284             :         }
     285             : 
     286           0 :         return gpfs_fstat_x_fn(fd, litemask, iattr, len);
     287             : }
     288             : 
     289           0 : int gpfswrap_stat_x(const char *pathname, unsigned int *litemask,
     290             :                     struct gpfs_iattr64 *iattr, size_t len)
     291             : {
     292           0 :         if (gpfs_stat_x_fn == NULL) {
     293           0 :                 errno = ENOSYS;
     294           0 :                 return -1;
     295             :         }
     296             : 
     297           0 :         return gpfs_stat_x_fn(pathname, litemask, iattr, len);
     298             : }

Generated by: LCOV version 1.13