LCOV - code coverage report
Current view: top level - misc/kabi/lvm2.git/tools - vgconvert.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 114 0.0 %
Date: 2010-04-13 Functions: 0 2 0.0 %
Branches: 0 76 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (C) 2001-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 "tools.h"
      17                 :            : 
      18                 :          0 : static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
      19                 :            :                             struct volume_group *vg,
      20                 :            :                             void *handle __attribute((unused)))
      21                 :            : {
      22                 :            :         struct physical_volume *pv, *existing_pv;
      23                 :            :         struct logical_volume *lv;
      24                 :            :         struct lv_list *lvl;
      25                 :          0 :         uint64_t size = 0;
      26                 :            :         struct dm_list mdas;
      27                 :          0 :         int pvmetadatacopies = 0;
      28                 :          0 :         uint64_t pvmetadatasize = 0;
      29                 :          0 :         uint64_t pe_end = 0, pe_start = 0;
      30                 :            :         struct pv_list *pvl;
      31                 :          0 :         int change_made = 0;
      32                 :            :         struct lvinfo info;
      33                 :          0 :         int active = 0;
      34                 :            : 
      35         [ #  # ]:          0 :         if (!vg_check_status(vg, LVM_WRITE | EXPORTED_VG)) {
      36                 :          0 :                 stack;
      37                 :          0 :                 return ECMD_FAILED;
      38                 :            :         }
      39                 :            : 
      40         [ #  # ]:          0 :         if (vg->fid->fmt == cmd->fmt) {
      41                 :          0 :                 log_error("Volume group \"%s\" already uses format %s",
      42                 :            :                           vg_name, cmd->fmt->name);
      43                 :          0 :                 return ECMD_FAILED;
      44                 :            :         }
      45                 :            : 
      46         [ #  # ]:          0 :         if (cmd->fmt->features & FMT_MDAS) {
      47         [ #  # ]:          0 :                 if (arg_sign_value(cmd, metadatasize_ARG, 0) == SIGN_MINUS) {
      48                 :          0 :                         log_error("Metadata size may not be negative");
      49                 :          0 :                         return EINVALID_CMD_LINE;
      50                 :            :                 }
      51                 :            : 
      52                 :          0 :                 pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG,
      53                 :            :                                                   UINT64_C(0));
      54         [ #  # ]:          0 :                 if (!pvmetadatasize)
      55                 :          0 :                         pvmetadatasize =
      56                 :          0 :                             find_config_tree_int(cmd,
      57                 :            :                                             "metadata/pvmetadatasize",
      58                 :            :                                             DEFAULT_PVMETADATASIZE);
      59                 :            : 
      60                 :          0 :                 pvmetadatacopies = arg_int_value(cmd, pvmetadatacopies_ARG, -1);
      61         [ #  # ]:          0 :                 if (pvmetadatacopies < 0)
      62                 :          0 :                         pvmetadatacopies =
      63                 :          0 :                             find_config_tree_int(cmd,
      64                 :            :                                             "metadata/pvmetadatacopies",
      65                 :            :                                              DEFAULT_PVMETADATACOPIES);
      66                 :            :         }
      67                 :            : 
      68         [ #  # ]:          0 :         if (!archive(vg)) {
      69                 :          0 :                 log_error("Archive of \"%s\" metadata failed.", vg_name);
      70                 :          0 :                 return ECMD_FAILED;
      71                 :            :         }
      72                 :            : 
      73                 :            :         /* Set PV/LV limit if converting from unlimited metadata format */
      74 [ #  # ][ #  # ]:          0 :         if (vg->fid->fmt->features & FMT_UNLIMITED_VOLS &&
      75                 :          0 :             !(cmd->fmt->features & FMT_UNLIMITED_VOLS)) {
      76         [ #  # ]:          0 :                 if (!vg->max_lv)
      77                 :          0 :                         vg->max_lv = 255;
      78         [ #  # ]:          0 :                 if (!vg->max_pv)
      79                 :          0 :                         vg->max_pv = 255;
      80                 :            :         }
      81                 :            : 
      82                 :            :         /* If converting to restricted lvid, check if lvid is compatible */
      83 [ #  # ][ #  # ]:          0 :         if (!(vg->fid->fmt->features & FMT_RESTRICTED_LVIDS) &&
      84                 :          0 :             cmd->fmt->features & FMT_RESTRICTED_LVIDS)
      85         [ #  # ]:          0 :                 dm_list_iterate_items(lvl, &vg->lvs)
      86         [ #  # ]:          0 :                         if (!lvid_in_restricted_range(&lvl->lv->lvid)) {
      87                 :          0 :                                 log_error("Logical volume %s lvid format is"
      88                 :            :                                           " incompatible with requested"
      89                 :            :                                           " metadata format.", lvl->lv->name);
      90                 :          0 :                                 return ECMD_FAILED;
      91                 :            :                         }
      92                 :            : 
      93                 :            :         /* Attempt to change any LVIDs that are too big */
      94         [ #  # ]:          0 :         if (cmd->fmt->features & FMT_RESTRICTED_LVIDS) {
      95         [ #  # ]:          0 :                 dm_list_iterate_items(lvl, &vg->lvs) {
      96                 :          0 :                         lv = lvl->lv;
      97         [ #  # ]:          0 :                         if (lv->status & SNAPSHOT)
      98                 :          0 :                                 continue;
      99         [ #  # ]:          0 :                         if (lvnum_from_lvid(&lv->lvid) < MAX_RESTRICTED_LVS)
     100                 :          0 :                                 continue;
     101 [ #  # ][ #  # ]:          0 :                         if (lv_info(cmd, lv, &info, 0, 0) && info.exists) {
     102                 :          0 :                                 log_error("Logical volume %s must be "
     103                 :            :                                           "deactivated before conversion.",
     104                 :            :                                            lv->name);
     105                 :          0 :                                 active++;
     106                 :          0 :                                 continue;
     107                 :            :                         }
     108                 :          0 :                         lvid_from_lvnum(&lv->lvid, &lv->vg->id, find_free_lvnum(lv));
     109                 :            : 
     110                 :            :                 }
     111                 :            :         }
     112                 :            : 
     113         [ #  # ]:          0 :         if (active) {
     114                 :          0 :                 stack;
     115                 :          0 :                 return ECMD_FAILED;
     116                 :            :         }
     117                 :            : 
     118         [ #  # ]:          0 :         dm_list_iterate_items(pvl, &vg->pvs) {
     119                 :          0 :                 existing_pv = pvl->pv;
     120                 :            : 
     121                 :          0 :                 pe_start = pv_pe_start(existing_pv);
     122                 :          0 :                 pe_end = pv_pe_count(existing_pv) * pv_pe_size(existing_pv)
     123                 :          0 :                     + pe_start - 1;
     124                 :            : 
     125                 :          0 :                 dm_list_init(&mdas);
     126         [ #  # ]:          0 :                 if (!(pv = pv_create(cmd, pv_dev(existing_pv),
     127                 :            :                                      &existing_pv->id, size, 0, 0,
     128                 :            :                                      pe_start, pv_pe_count(existing_pv),
     129                 :            :                                      pv_pe_size(existing_pv), pvmetadatacopies,
     130                 :            :                                      pvmetadatasize, &mdas))) {
     131                 :          0 :                         log_error("Failed to setup physical volume \"%s\"",
     132                 :            :                                   pv_dev_name(existing_pv));
     133         [ #  # ]:          0 :                         if (change_made)
     134                 :          0 :                                 log_error("Use pvcreate and vgcfgrestore to "
     135                 :            :                                           "repair from archived metadata.");
     136                 :          0 :                         return ECMD_FAILED;
     137                 :            :                 }
     138                 :            : 
     139                 :            :                 /* Need to revert manually if it fails after this point */
     140                 :          0 :                 change_made = 1;
     141                 :            : 
     142                 :          0 :                 log_verbose("Set up physical volume for \"%s\" with %" PRIu64
     143                 :            :                             " available sectors", pv_dev_name(pv), pv_size(pv));
     144                 :            : 
     145                 :            :                 /* Wipe existing label first */
     146         [ #  # ]:          0 :                 if (!label_remove(pv_dev(pv))) {
     147                 :          0 :                         log_error("Failed to wipe existing label on %s",
     148                 :            :                                   pv_dev_name(pv));
     149                 :          0 :                         log_error("Use pvcreate and vgcfgrestore to repair "
     150                 :            :                                   "from archived metadata.");
     151                 :          0 :                         return ECMD_FAILED;
     152                 :            :                 }
     153                 :            : 
     154                 :          0 :                 log_very_verbose("Writing physical volume data to disk \"%s\"",
     155                 :            :                                  pv_dev_name(pv));
     156         [ #  # ]:          0 :                 if (!(pv_write(cmd, pv, &mdas,
     157                 :            :                                arg_int64_value(cmd, labelsector_ARG,
     158                 :            :                                                DEFAULT_LABELSECTOR)))) {
     159                 :          0 :                         log_error("Failed to write physical volume \"%s\"",
     160                 :            :                                   pv_dev_name(pv));
     161                 :          0 :                         log_error("Use pvcreate and vgcfgrestore to repair "
     162                 :            :                                   "from archived metadata.");
     163                 :          0 :                         return ECMD_FAILED;
     164                 :            :                 }
     165                 :          0 :                 log_verbose("Physical volume \"%s\" successfully created",
     166                 :            :                             pv_dev_name(pv));
     167                 :            : 
     168                 :            :         }
     169                 :            : 
     170                 :          0 :         log_verbose("Deleting existing metadata for VG %s", vg_name);
     171         [ #  # ]:          0 :         if (!vg_remove_mdas(vg)) {
     172                 :          0 :                 log_error("Removal of existing metadata for %s failed.",
     173                 :            :                           vg_name);
     174                 :          0 :                 log_error("Use pvcreate and vgcfgrestore to repair "
     175                 :            :                           "from archived metadata.");
     176                 :          0 :                 return ECMD_FAILED;
     177                 :            :         }
     178                 :            : 
     179                 :            :         /* FIXME Cache the label format change so we don't have to skip this */
     180         [ #  # ]:          0 :         if (test_mode()) {
     181                 :          0 :                 log_verbose("Test mode: Skipping metadata writing for VG %s in"
     182                 :            :                             " format %s", vg_name, cmd->fmt->name);
     183                 :          0 :                 return ECMD_PROCESSED;
     184                 :            :         }
     185                 :            : 
     186                 :          0 :         log_verbose("Writing metadata for VG %s using format %s", vg_name,
     187                 :            :                     cmd->fmt->name);
     188         [ #  # ]:          0 :         if (!backup_restore_vg(cmd, vg)) {
     189                 :          0 :                 log_error("Conversion failed for volume group %s.", vg_name);
     190                 :          0 :                 log_error("Use pvcreate and vgcfgrestore to repair from "
     191                 :            :                           "archived metadata.");
     192                 :          0 :                 return ECMD_FAILED;
     193                 :            :         }
     194                 :          0 :         log_print("Volume group %s successfully converted", vg_name);
     195                 :            : 
     196                 :          0 :         backup(vg);
     197                 :            : 
     198                 :          0 :         return ECMD_PROCESSED;
     199                 :            : }
     200                 :            : 
     201                 :          0 : int vgconvert(struct cmd_context *cmd, int argc, char **argv)
     202                 :            : {
     203         [ #  # ]:          0 :         if (!argc) {
     204                 :          0 :                 log_error("Please enter volume group(s)");
     205                 :          0 :                 return EINVALID_CMD_LINE;
     206                 :            :         }
     207                 :            : 
     208         [ #  # ]:          0 :         if (arg_int_value(cmd, labelsector_ARG, 0) >= LABEL_SCAN_SECTORS) {
     209                 :          0 :                 log_error("labelsector must be less than %lu",
     210                 :            :                           LABEL_SCAN_SECTORS);
     211                 :          0 :                 return EINVALID_CMD_LINE;
     212                 :            :         }
     213                 :            : 
     214         [ #  # ]:          0 :         if (arg_count(cmd, metadatacopies_ARG)) {
     215                 :          0 :                 log_error("Invalid option --metadatacopies, "
     216                 :            :                           "use --pvmetadatacopies instead.");
     217                 :          0 :                 return EINVALID_CMD_LINE;
     218                 :            :         }
     219 [ #  #  #  #  # :          0 :         if (!(cmd->fmt->features & FMT_MDAS) &&
                      # ]
     220                 :          0 :             (arg_count(cmd, pvmetadatacopies_ARG) ||
     221                 :          0 :              arg_count(cmd, metadatasize_ARG))) {
     222                 :          0 :                 log_error("Metadata parameters only apply to text format");
     223                 :          0 :                 return EINVALID_CMD_LINE;
     224                 :            :         }
     225                 :            : 
     226   [ #  #  #  # ]:          0 :         if (arg_count(cmd, pvmetadatacopies_ARG) &&
     227                 :          0 :             arg_int_value(cmd, pvmetadatacopies_ARG, -1) > 2) {
     228                 :          0 :                 log_error("Metadatacopies may only be 0, 1 or 2");
     229                 :          0 :                 return EINVALID_CMD_LINE;
     230                 :            :         }
     231                 :            : 
     232                 :          0 :         return process_each_vg(cmd, argc, argv, READ_FOR_UPDATE, NULL,
     233                 :            :                                &vgconvert_single);
     234                 :            : }

Generated by: LCOV version 1.8