LCOV - code coverage report
Current view: top level - lib/util - gpfswrap.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 5 119 4.2 %
Date: 2024-06-13 04:01:37 Functions: 1 20 5.0 %

          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_fgetacl_fn)(int fd, 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_fn)(int fd, struct gpfs_winattr *attrs);
      37             : static int (*gpfs_ftruncate_fn)(int fd, gpfs_off64_t length);
      38             : static int (*gpfs_lib_init_fn)(int flags);
      39             : static int (*gpfs_set_times_fn)(int fd, int flags, gpfs_timestruc_t times[4]);
      40             : static int (*gpfs_set_times_path_fn)(char *path,
      41             :                                      int flags,
      42             :                                      gpfs_timestruc_t times[4]);
      43             : static int (*gpfs_quotactl_fn)(const char *pathname,
      44             :                                int cmd,
      45             :                                int id,
      46             :                                void *bufp);
      47             : static int (*gpfs_init_trace_fn)(void);
      48             : static int (*gpfs_query_trace_fn)(void);
      49             : static void (*gpfs_add_trace_fn)(int level, const char *msg);
      50             : static void (*gpfs_fini_trace_fn)(void);
      51             : static int (*gpfs_fstat_x_fn)(int fd, unsigned int *litemask,
      52             :                               struct gpfs_iattr64 *iattr, size_t len);
      53             : static int (*gpfs_stat_x_fn)(const char *pathname, unsigned int *litemask,
      54             :                              struct gpfs_iattr64 *iattr, size_t len);
      55             : 
      56       46036 : int gpfswrap_init(void)
      57             : {
      58             :         static void *l;
      59             : 
      60       46036 :         if (l != NULL) {
      61           0 :                 return 0;
      62             :         }
      63             : 
      64       46036 :         l = dlopen("libgpfs.so", RTLD_LAZY);
      65       46036 :         if (l == NULL) {
      66       46036 :                 return -1;
      67             :         }
      68             : 
      69           0 :         gpfs_set_share_fn             = dlsym(l, "gpfs_set_share");
      70           0 :         gpfs_set_lease_fn             = dlsym(l, "gpfs_set_lease");
      71           0 :         gpfs_fgetacl_fn               = dlsym(l, "gpfs_getacl_fd");
      72           0 :         gpfs_putacl_fn                = dlsym(l, "gpfs_putacl");
      73           0 :         gpfs_get_realfilename_path_fn = dlsym(l, "gpfs_get_realfilename_path");
      74           0 :         gpfs_set_winattrs_path_fn     = dlsym(l, "gpfs_set_winattrs_path");
      75           0 :         gpfs_set_winattrs_fn          = dlsym(l, "gpfs_set_winattrs");
      76           0 :         gpfs_get_winattrs_fn          = dlsym(l, "gpfs_get_winattrs");
      77           0 :         gpfs_ftruncate_fn             = dlsym(l, "gpfs_ftruncate");
      78           0 :         gpfs_lib_init_fn              = dlsym(l, "gpfs_lib_init");
      79           0 :         gpfs_set_times_fn             = dlsym(l, "gpfs_set_times");
      80           0 :         gpfs_set_times_path_fn        = dlsym(l, "gpfs_set_times_path");
      81           0 :         gpfs_quotactl_fn              = dlsym(l, "gpfs_quotactl");
      82           0 :         gpfs_init_trace_fn            = dlsym(l, "gpfs_init_trace");
      83           0 :         gpfs_query_trace_fn           = dlsym(l, "gpfs_query_trace");
      84           0 :         gpfs_add_trace_fn             = dlsym(l, "gpfs_add_trace");
      85           0 :         gpfs_fini_trace_fn            = dlsym(l, "gpfs_fini_trace");
      86           0 :         gpfs_fstat_x_fn       = dlsym(l, "gpfs_fstat_x");
      87           0 :         gpfs_stat_x_fn                = dlsym(l, "gpfs_stat_x");
      88             : 
      89           0 :         return 0;
      90             : }
      91             : 
      92           0 : int gpfswrap_set_share(int fd, unsigned int allow, unsigned int deny)
      93             : {
      94           0 :         if (gpfs_set_share_fn == NULL) {
      95           0 :                 errno = ENOSYS;
      96           0 :                 return -1;
      97             :         }
      98             : 
      99           0 :         return gpfs_set_share_fn(fd, allow, deny);
     100             : }
     101             : 
     102           0 : int gpfswrap_set_lease(int fd, unsigned int type)
     103             : {
     104           0 :         if (gpfs_set_lease_fn == NULL) {
     105           0 :                 errno = ENOSYS;
     106           0 :                 return -1;
     107             :         }
     108             : 
     109           0 :         return gpfs_set_lease_fn(fd, type);
     110             : }
     111             : 
     112           0 : int gpfswrap_fgetacl(int fd, int flags, void *acl)
     113             : {
     114           0 :         if (gpfs_fgetacl_fn == NULL) {
     115           0 :                 errno = ENOSYS;
     116           0 :                 return -1;
     117             :         }
     118             : 
     119           0 :         return gpfs_fgetacl_fn(fd, flags, acl);
     120             : }
     121             : 
     122           0 : int gpfswrap_putacl(const char *pathname, int flags, void *acl)
     123             : {
     124           0 :         if (gpfs_putacl_fn == NULL) {
     125           0 :                 errno = ENOSYS;
     126           0 :                 return -1;
     127             :         }
     128             : 
     129           0 :         return gpfs_putacl_fn(pathname, flags, acl);
     130             : }
     131             : 
     132           0 : int gpfswrap_get_realfilename_path(const char *pathname,
     133             :                                    char *filenamep,
     134             :                                    int *len)
     135             : {
     136           0 :         if (gpfs_get_realfilename_path_fn == NULL) {
     137           0 :                 errno = ENOSYS;
     138           0 :                 return -1;
     139             :         }
     140             : 
     141           0 :         return gpfs_get_realfilename_path_fn(pathname, filenamep, len);
     142             : }
     143             : 
     144           0 : int gpfswrap_set_winattrs_path(const char *pathname,
     145             :                                int flags,
     146             :                                struct gpfs_winattr *attrs)
     147             : {
     148           0 :         if (gpfs_set_winattrs_path_fn == NULL) {
     149           0 :                 errno = ENOSYS;
     150           0 :                 return -1;
     151             :         }
     152             : 
     153           0 :         return gpfs_set_winattrs_path_fn(pathname, flags, attrs);
     154             : }
     155             : 
     156           0 : int gpfswrap_set_winattrs(int fd, int flags, struct gpfs_winattr *attrs)
     157             : {
     158           0 :         if (gpfs_set_winattrs_fn == NULL) {
     159           0 :                 errno = ENOSYS;
     160           0 :                 return -1;
     161             :         }
     162             : 
     163           0 :         return gpfs_set_winattrs_fn(fd, flags, attrs);
     164             : }
     165             : 
     166           0 : int gpfswrap_get_winattrs(int fd, struct gpfs_winattr *attrs)
     167             : {
     168           0 :         if (gpfs_get_winattrs_fn == NULL) {
     169           0 :                 errno = ENOSYS;
     170           0 :                 return -1;
     171             :         }
     172             : 
     173           0 :         return gpfs_get_winattrs_fn(fd, attrs);
     174             : }
     175             : 
     176           0 : int gpfswrap_ftruncate(int fd, gpfs_off64_t length)
     177             : {
     178           0 :         if (gpfs_ftruncate_fn == NULL) {
     179           0 :                 errno = ENOSYS;
     180           0 :                 return -1;
     181             :         }
     182             : 
     183           0 :         return gpfs_ftruncate_fn(fd, length);
     184             : }
     185             : 
     186           0 : int gpfswrap_lib_init(int flags)
     187             : {
     188           0 :         if (gpfs_lib_init_fn == NULL) {
     189           0 :                 errno = ENOSYS;
     190           0 :                 return -1;
     191             :         }
     192             : 
     193           0 :         return gpfs_lib_init_fn(flags);
     194             : }
     195             : 
     196           0 : int gpfswrap_set_times(int fd, int flags, gpfs_timestruc_t times[4])
     197             : {
     198           0 :         if (gpfs_set_times_fn == NULL) {
     199           0 :                 errno = ENOSYS;
     200           0 :                 return -1;
     201             :         }
     202             : 
     203           0 :         return gpfs_set_times_fn(fd, flags, times);
     204             : }
     205             : 
     206           0 : int gpfswrap_set_times_path(char *path, int flags, gpfs_timestruc_t times[4])
     207             : {
     208           0 :         if (gpfs_set_times_path_fn == NULL) {
     209           0 :                 errno = ENOSYS;
     210           0 :                 return -1;
     211             :         }
     212             : 
     213           0 :         return gpfs_set_times_path_fn(path, flags, times);
     214             : }
     215             : 
     216           0 : int gpfswrap_quotactl(const char *pathname, int cmd, int id, void *bufp)
     217             : {
     218           0 :         if (gpfs_quotactl_fn == NULL) {
     219           0 :                 errno = ENOSYS;
     220           0 :                 return -1;
     221             :         }
     222             : 
     223           0 :         return gpfs_quotactl_fn(pathname, cmd, id, bufp);
     224             : }
     225             : 
     226           0 : int gpfswrap_init_trace(void)
     227             : {
     228           0 :         if (gpfs_init_trace_fn == NULL) {
     229           0 :                 errno = ENOSYS;
     230           0 :                 return -1;
     231             :         }
     232             : 
     233           0 :         return gpfs_init_trace_fn();
     234             : }
     235             : 
     236           0 : int gpfswrap_query_trace(void)
     237             : {
     238           0 :         if (gpfs_query_trace_fn == NULL) {
     239           0 :                 errno = ENOSYS;
     240           0 :                 return -1;
     241             :         }
     242             : 
     243           0 :         return gpfs_query_trace_fn();
     244             : }
     245             : 
     246           0 : void gpfswrap_add_trace(int level, const char *msg)
     247             : {
     248           0 :         if (gpfs_add_trace_fn == NULL) {
     249           0 :                 return;
     250             :         }
     251             : 
     252           0 :         gpfs_add_trace_fn(level, msg);
     253             : }
     254             : 
     255           0 : void gpfswrap_fini_trace(void)
     256             : {
     257           0 :         if (gpfs_fini_trace_fn == NULL) {
     258           0 :                 return;
     259             :         }
     260             : 
     261           0 :         gpfs_fini_trace_fn();
     262             : }
     263             : 
     264           0 : int gpfswrap_fstat_x(int fd, unsigned int *litemask,
     265             :                      struct gpfs_iattr64 *iattr, size_t len)
     266             : {
     267           0 :         if (gpfs_fstat_x_fn == NULL) {
     268           0 :                 errno = ENOSYS;
     269           0 :                 return -1;
     270             :         }
     271             : 
     272           0 :         return gpfs_fstat_x_fn(fd, litemask, iattr, len);
     273             : }
     274             : 
     275           0 : int gpfswrap_stat_x(const char *pathname, unsigned int *litemask,
     276             :                     struct gpfs_iattr64 *iattr, size_t len)
     277             : {
     278           0 :         if (gpfs_stat_x_fn == NULL) {
     279           0 :                 errno = ENOSYS;
     280           0 :                 return -1;
     281             :         }
     282             : 
     283           0 :         return gpfs_stat_x_fn(pathname, litemask, iattr, len);
     284             : }

Generated by: LCOV version 1.13