LCOV - code coverage report
Current view: top level - misc/kabi/lvm2.git/lib/striped - striped.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 13 91 14.3 %
Date: 2010-04-13 Functions: 2 11 18.2 %
Branches: 1 62 1.6 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved.
       3                 :            :  * Copyright (C) 2004-2007 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 "toolcontext.h"
      18                 :            : #include "segtype.h"
      19                 :            : #include "display.h"
      20                 :            : #include "text_export.h"
      21                 :            : #include "text_import.h"
      22                 :            : #include "config.h"
      23                 :            : #include "str_list.h"
      24                 :            : #include "targets.h"
      25                 :            : #include "lvm-string.h"
      26                 :            : #include "activate.h"
      27                 :            : #include "pv_alloc.h"
      28                 :            : #include "metadata.h"
      29                 :            : 
      30                 :          0 : static const char *_striped_name(const struct lv_segment *seg)
      31                 :            : {
      32         [ #  # ]:          0 :         return (seg->area_count == 1) ? "linear" : seg->segtype->name;
      33                 :            : }
      34                 :            : 
      35                 :          0 : static void _striped_display(const struct lv_segment *seg)
      36                 :            : {
      37                 :            :         uint32_t s;
      38                 :            : 
      39         [ #  # ]:          0 :         if (seg->area_count == 1)
      40                 :          0 :                 display_stripe(seg, 0, "  ");
      41                 :            :         else {
      42                 :          0 :                 log_print("  Stripes\t\t%u", seg->area_count);
      43                 :            : 
      44         [ #  # ]:          0 :                 if (seg->lv->vg->cmd->si_unit_consistency)
      45                 :          0 :                         log_print("  Stripe size\t\t%s",
      46                 :            :                                   display_size(seg->lv->vg->cmd,
      47                 :            :                                                (uint64_t) seg->stripe_size));
      48                 :            :                 else
      49                 :          0 :                         log_print("  Stripe size\t\t%u KB",
      50                 :            :                                   seg->stripe_size / 2);
      51                 :            : 
      52         [ #  # ]:          0 :                 for (s = 0; s < seg->area_count; s++) {
      53                 :          0 :                         log_print("  Stripe %d:", s);
      54                 :          0 :                         display_stripe(seg, s, "    ");
      55                 :            :                 }
      56                 :            :         }
      57                 :          0 :         log_print(" ");
      58                 :          0 : }
      59                 :            : 
      60                 :          0 : static int _striped_text_import_area_count(struct config_node *sn, uint32_t *area_count)
      61                 :            : {
      62         [ #  # ]:          0 :         if (!get_config_uint32(sn, "stripe_count", area_count)) {
      63                 :          0 :                 log_error("Couldn't read 'stripe_count' for "
      64                 :            :                           "segment '%s'.", config_parent_name(sn));
      65                 :          0 :                 return 0;
      66                 :            :         }
      67                 :            : 
      68                 :          0 :         return 1;
      69                 :            : }
      70                 :            : 
      71                 :          0 : static int _striped_text_import(struct lv_segment *seg, const struct config_node *sn,
      72                 :            :                         struct dm_hash_table *pv_hash)
      73                 :            : {
      74                 :            :         struct config_node *cn;
      75                 :            : 
      76   [ #  #  #  # ]:          0 :         if ((seg->area_count != 1) &&
      77                 :          0 :             !get_config_uint32(sn, "stripe_size", &seg->stripe_size)) {
      78                 :          0 :                 log_error("Couldn't read stripe_size for segment %s "
      79                 :            :                           "of logical volume %s.", config_parent_name(sn), seg->lv->name);
      80                 :          0 :                 return 0;
      81                 :            :         }
      82                 :            : 
      83         [ #  # ]:          0 :         if (!(cn = find_config_node(sn, "stripes"))) {
      84                 :          0 :                 log_error("Couldn't find stripes array for segment %s "
      85                 :            :                           "of logical volume %s.", config_parent_name(sn), seg->lv->name);
      86                 :          0 :                 return 0;
      87                 :            :         }
      88                 :            : 
      89                 :          0 :         seg->area_len /= seg->area_count;
      90                 :            : 
      91                 :          0 :         return text_import_areas(seg, sn, cn, pv_hash, 0);
      92                 :            : }
      93                 :            : 
      94                 :          0 : static int _striped_text_export(const struct lv_segment *seg, struct formatter *f)
      95                 :            : {
      96                 :            : 
      97 [ #  # ][ #  # ]:          0 :         outf(f, "stripe_count = %u%s", seg->area_count,
      98                 :            :              (seg->area_count == 1) ? "\t# linear" : "");
      99                 :            : 
     100         [ #  # ]:          0 :         if (seg->area_count > 1)
     101         [ #  # ]:          0 :                 outsize(f, (uint64_t) seg->stripe_size,
     102                 :            :                         "stripe_size = %u", seg->stripe_size);
     103                 :            : 
     104                 :          0 :         return out_areas(f, seg, "stripe");
     105                 :            : }
     106                 :            : 
     107                 :            : /*
     108                 :            :  * Test whether two segments could be merged by the current merging code
     109                 :            :  */
     110                 :          0 : static int _striped_segments_compatible(struct lv_segment *first,
     111                 :            :                                 struct lv_segment *second)
     112                 :            : {
     113                 :            :         uint32_t width;
     114                 :            :         unsigned s;
     115                 :            : 
     116 [ #  # ][ #  # ]:          0 :         if ((first->area_count != second->area_count) ||
     117                 :          0 :             (first->stripe_size != second->stripe_size))
     118                 :          0 :                 return 0;
     119                 :            : 
     120         [ #  # ]:          0 :         for (s = 0; s < first->area_count; s++) {
     121                 :            : 
     122                 :            :                 /* FIXME Relax this to first area type != second area type */
     123                 :            :                 /*       plus the additional AREA_LV checks needed */
     124 [ #  # ][ #  # ]:          0 :                 if ((seg_type(first, s) != AREA_PV) ||
     125                 :          0 :                     (seg_type(second, s) != AREA_PV))
     126                 :          0 :                         return 0;
     127                 :            : 
     128                 :          0 :                 width = first->area_len;
     129                 :            : 
     130 [ #  # ][ #  # ]:          0 :                 if ((seg_pv(first, s) !=
     131                 :          0 :                      seg_pv(second, s)) ||
     132                 :          0 :                     (seg_pe(first, s) + width !=
     133                 :          0 :                      seg_pe(second, s)))
     134                 :          0 :                         return 0;
     135                 :            :         }
     136                 :            : 
     137         [ #  # ]:          0 :         if (!str_list_lists_equal(&first->tags, &second->tags))
     138                 :          0 :                 return 0;
     139                 :            : 
     140                 :          0 :         return 1;
     141                 :            : }
     142                 :            : 
     143                 :          0 : static int _striped_merge_segments(struct lv_segment *seg1, struct lv_segment *seg2)
     144                 :            : {
     145                 :            :         uint32_t s;
     146                 :            : 
     147         [ #  # ]:          0 :         if (!_striped_segments_compatible(seg1, seg2))
     148                 :          0 :                 return 0;
     149                 :            : 
     150                 :          0 :         seg1->len += seg2->len;
     151                 :          0 :         seg1->area_len += seg2->area_len;
     152                 :            : 
     153         [ #  # ]:          0 :         for (s = 0; s < seg1->area_count; s++)
     154         [ #  # ]:          0 :                 if (seg_type(seg1, s) == AREA_PV)
     155                 :          0 :                         merge_pv_segments(seg_pvseg(seg1, s),
     156                 :          0 :                                           seg_pvseg(seg2, s));
     157                 :            : 
     158                 :          0 :         return 1;
     159                 :            : }
     160                 :            : 
     161                 :            : #ifdef DEVMAPPER_SUPPORT
     162                 :          0 : static int _striped_add_target_line(struct dev_manager *dm,
     163                 :            :                                 struct dm_pool *mem __attribute((unused)),
     164                 :            :                                 struct cmd_context *cmd __attribute((unused)),
     165                 :            :                                 void **target_state __attribute((unused)),
     166                 :            :                                 struct lv_segment *seg,
     167                 :            :                                 struct dm_tree_node *node, uint64_t len,
     168                 :            :                                 uint32_t *pvmove_mirror_count __attribute((unused)))
     169                 :            : {
     170         [ #  # ]:          0 :         if (!seg->area_count) {
     171                 :          0 :                 log_error(INTERNAL_ERROR "striped add_target_line called "
     172                 :            :                           "with no areas for %s.", seg->lv->name);
     173                 :          0 :                 return 0;
     174                 :            :         }
     175         [ #  # ]:          0 :         if (seg->area_count == 1) {
     176         [ #  # ]:          0 :                 if (!dm_tree_node_add_linear_target(node, len))
     177                 :          0 :                         return_0;
     178         [ #  # ]:          0 :         } else if (!dm_tree_node_add_striped_target(node, len,
     179                 :            :                                                   seg->stripe_size))
     180                 :          0 :                 return_0;
     181                 :            : 
     182                 :          0 :         return add_areas_line(dm, seg, node, 0u, seg->area_count);
     183                 :            : }
     184                 :            : 
     185                 :          0 : static int _striped_target_present(struct cmd_context *cmd,
     186                 :            :                                    const struct lv_segment *seg __attribute((unused)),
     187                 :            :                                    unsigned *attributes __attribute((unused)))
     188                 :            : {
     189                 :            :         static int _striped_checked = 0;
     190                 :            :         static int _striped_present = 0;
     191                 :            : 
     192         [ #  # ]:          0 :         if (!_striped_checked)
     193   [ #  #  #  # ]:          0 :                 _striped_present = target_present(cmd, "linear", 0) &&
     194                 :          0 :                           target_present(cmd, "striped", 0);
     195                 :            : 
     196                 :          0 :         _striped_checked = 1;
     197                 :            : 
     198                 :          0 :         return _striped_present;
     199                 :            : }
     200                 :            : #endif
     201                 :            : 
     202                 :          3 : static void _striped_destroy(const struct segment_type *segtype)
     203                 :            : {
     204                 :          3 :         dm_free((void *)segtype);
     205                 :          3 : }
     206                 :            : 
     207                 :            : static struct segtype_handler _striped_ops = {
     208                 :            :         .name = _striped_name,
     209                 :            :         .display = _striped_display,
     210                 :            :         .text_import_area_count = _striped_text_import_area_count,
     211                 :            :         .text_import = _striped_text_import,
     212                 :            :         .text_export = _striped_text_export,
     213                 :            :         .merge_segments = _striped_merge_segments,
     214                 :            : #ifdef DEVMAPPER_SUPPORT
     215                 :            :         .add_target_line = _striped_add_target_line,
     216                 :            :         .target_present = _striped_target_present,
     217                 :            : #endif
     218                 :            :         .destroy = _striped_destroy,
     219                 :            : };
     220                 :            : 
     221                 :          3 : struct segment_type *init_striped_segtype(struct cmd_context *cmd)
     222                 :            : {
     223                 :          3 :         struct segment_type *segtype = dm_malloc(sizeof(*segtype));
     224                 :            : 
     225         [ -  + ]:          3 :         if (!segtype)
     226                 :          0 :                 return_NULL;
     227                 :            : 
     228                 :          3 :         segtype->cmd = cmd;
     229                 :          3 :         segtype->ops = &_striped_ops;
     230                 :          3 :         segtype->name = "striped";
     231                 :          3 :         segtype->private = NULL;
     232                 :          3 :         segtype->flags =
     233                 :            :             SEG_CAN_SPLIT | SEG_AREAS_STRIPED | SEG_FORMAT1_SUPPORT;
     234                 :            : 
     235                 :          3 :         log_very_verbose("Initialised segtype: %s", segtype->name);
     236                 :            : 
     237                 :          3 :         return segtype;
     238                 :            : }

Generated by: LCOV version 1.8