LCOV - code coverage report
Current view: top level - misc/kabi/lvm2.git/lib/filters - filter-composite.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 25 32 78.1 %
Date: 2010-04-13 Functions: 3 3 100.0 %
Branches: 8 12 66.7 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2001-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 "filter-composite.h"
      18                 :            : 
      19                 :            : #include <stdarg.h>
      20                 :            : 
      21                 :         39 : static int _and_p(struct dev_filter *f, struct device *dev)
      22                 :            : {
      23                 :         39 :         struct dev_filter **filters = (struct dev_filter **) f->private;
      24                 :            : 
      25         [ +  - ]:         78 :         while (*filters) {
      26         [ +  + ]:         78 :                 if (!(*filters)->passes_filter(*filters, dev))
      27                 :         39 :                         return 0;
      28                 :         39 :                 filters++;
      29                 :            :         }
      30                 :            : 
      31                 :          0 :         log_debug("Using %s", dev_name(dev));
      32                 :            : 
      33                 :         39 :         return 1;
      34                 :            : }
      35                 :            : 
      36                 :          3 : static void _composite_destroy(struct dev_filter *f)
      37                 :            : {
      38                 :          3 :         struct dev_filter **filters = (struct dev_filter **) f->private;
      39                 :            : 
      40         [ +  + ]:         15 :         while (*filters) {
      41                 :         12 :                 (*filters)->destroy(*filters);
      42                 :         12 :                 filters++;
      43                 :            :         }
      44                 :            : 
      45                 :          3 :         dm_free(f->private);
      46                 :          3 :         dm_free(f);
      47                 :          3 : }
      48                 :            : 
      49                 :          3 : struct dev_filter *composite_filter_create(int n, struct dev_filter **filters)
      50                 :            : {
      51                 :            :         struct dev_filter **filters_copy, *cft;
      52                 :            : 
      53         [ -  + ]:          3 :         if (!filters)
      54                 :          0 :                 return_NULL;
      55                 :            : 
      56         [ -  + ]:          3 :         if (!(filters_copy = dm_malloc(sizeof(*filters) * (n + 1)))) {
      57                 :          0 :                 log_error("composite filters allocation failed");
      58                 :          0 :                 return NULL;
      59                 :            :         }
      60                 :            : 
      61                 :          3 :         memcpy(filters_copy, filters, sizeof(*filters) * n);
      62                 :          3 :         filters_copy[n] = NULL;
      63                 :            : 
      64         [ -  + ]:          3 :         if (!(cft = dm_malloc(sizeof(*cft)))) {
      65                 :          0 :                 log_error("compsoite filters allocation failed");
      66                 :          0 :                 dm_free(filters_copy);
      67                 :          0 :                 return NULL;
      68                 :            :         }
      69                 :            : 
      70                 :          3 :         cft->passes_filter = _and_p;
      71                 :          3 :         cft->destroy = _composite_destroy;
      72                 :          3 :         cft->private = filters_copy;
      73                 :            : 
      74                 :          3 :         return cft;
      75                 :            : }

Generated by: LCOV version 1.8