LCOV - code coverage report
Current view: top level - misc/kabi/lvm2.git/lib/locking - external_locking.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 41 0.0 %
Date: 2010-04-13 Functions: 0 4 0.0 %
Branches: 0 20 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved.
       3                 :            :  * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
       4                 :            :  *
       5                 :            :  * This file is part of LVM2.
       6                 :            :  *
       7                 :            :  * This copyrighted material is made available to anyone wishing to use,
       8                 :            :  * modify, copy, or redistribute it subject to the terms and conditions
       9                 :            :  * of the GNU Lesser General Public License v.2.1.
      10                 :            :  *
      11                 :            :  * You should have received a copy of the GNU Lesser General Public License
      12                 :            :  * along with this program; if not, write to the Free Software Foundation,
      13                 :            :  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "lib.h"
      17                 :            : #include "locking_types.h"
      18                 :            : #include "defaults.h"
      19                 :            : #include "sharedlib.h"
      20                 :            : #include "toolcontext.h"
      21                 :            : 
      22                 :            : static void *_locking_lib = NULL;
      23                 :            : static void (*_reset_fn) (void) = NULL;
      24                 :            : static void (*_end_fn) (void) = NULL;
      25                 :            : static int (*_lock_fn) (struct cmd_context * cmd, const char *resource,
      26                 :            :                         uint32_t flags) = NULL;
      27                 :            : static int (*_init_fn) (int type, struct config_tree * cft,
      28                 :            :                         uint32_t *flags) = NULL;
      29                 :            : static int (*_lock_query_fn) (const char *resource, int *mode) = NULL;
      30                 :            : 
      31                 :          0 : static int _lock_resource(struct cmd_context *cmd, const char *resource,
      32                 :            :                           uint32_t flags)
      33                 :            : {
      34         [ #  # ]:          0 :         if (_lock_fn)
      35                 :          0 :                 return _lock_fn(cmd, resource, flags);
      36                 :            :         else
      37                 :          0 :                 return 0;
      38                 :            : }
      39                 :            : 
      40                 :          0 : static void _fin_external_locking(void)
      41                 :            : {
      42         [ #  # ]:          0 :         if (_end_fn)
      43                 :          0 :                 _end_fn();
      44                 :            : 
      45                 :          0 :         dlclose(_locking_lib);
      46                 :            : 
      47                 :          0 :         _locking_lib = NULL;
      48                 :          0 :         _init_fn = NULL;
      49                 :          0 :         _end_fn = NULL;
      50                 :          0 :         _lock_fn = NULL;
      51                 :          0 :         _reset_fn = NULL;
      52                 :          0 : }
      53                 :            : 
      54                 :          0 : static void _reset_external_locking(void)
      55                 :            : {
      56         [ #  # ]:          0 :         if (_reset_fn)
      57                 :          0 :                 _reset_fn();
      58                 :          0 : }
      59                 :            : 
      60                 :          0 : int init_external_locking(struct locking_type *locking, struct cmd_context *cmd)
      61                 :            : {
      62                 :            :         const char *libname;
      63                 :            : 
      64         [ #  # ]:          0 :         if (_locking_lib) {
      65                 :          0 :                 log_error("External locking already initialised");
      66                 :          0 :                 return 1;
      67                 :            :         }
      68                 :            : 
      69                 :          0 :         locking->lock_resource = _lock_resource;
      70                 :          0 :         locking->fin_locking = _fin_external_locking;
      71                 :          0 :         locking->reset_locking = _reset_external_locking;
      72                 :          0 :         locking->flags = 0;
      73                 :            : 
      74                 :          0 :         libname = find_config_tree_str(cmd, "global/locking_library",
      75                 :            :                                        DEFAULT_LOCKING_LIB);
      76                 :            : 
      77         [ #  # ]:          0 :         if (!(_locking_lib = load_shared_library(cmd, libname, "locking", 1)))
      78                 :          0 :                 return_0;
      79                 :            : 
      80                 :            :         /* Get the functions we need */
      81 [ #  #  #  #  # :          0 :         if (!(_init_fn = dlsym(_locking_lib, "locking_init")) ||
                #  #  # ]
      82                 :          0 :             !(_lock_fn = dlsym(_locking_lib, "lock_resource")) ||
      83                 :          0 :             !(_reset_fn = dlsym(_locking_lib, "reset_locking")) ||
      84                 :          0 :             !(_end_fn = dlsym(_locking_lib, "locking_end"))) {
      85                 :          0 :                 log_error("Shared library %s does not contain locking "
      86                 :            :                           "functions", libname);
      87                 :          0 :                 dlclose(_locking_lib);
      88                 :          0 :                 _locking_lib = NULL;
      89                 :          0 :                 return 0;
      90                 :            :         }
      91                 :            : 
      92         [ #  # ]:          0 :         if (!(_lock_query_fn = dlsym(_locking_lib, "query_resource")))
      93                 :          0 :                 log_warn("WARNING: %s: _query_resource() missing: "
      94                 :            :                          "Using inferior activation method.", libname);
      95                 :            : 
      96                 :          0 :         log_verbose("Loaded external locking library %s", libname);
      97                 :          0 :         return _init_fn(2, cmd->cft, &locking->flags);
      98                 :            : }

Generated by: LCOV version 1.8