LCOV - code coverage report
Current view: top level - misc/kabi/lvm2.git/tools - lvrename.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 61 0.0 %
Date: 2010-04-13 Functions: 0 1 0.0 %
Branches: 0 38 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                 :            : #include "lvm-types.h"
      18                 :            : 
      19                 :            : 
      20                 :            : /*
      21                 :            :  * lvrename command implementation.
      22                 :            :  * Check arguments and call lv_rename() to execute the request.
      23                 :            :  */
      24                 :          0 : int lvrename(struct cmd_context *cmd, int argc, char **argv)
      25                 :            : {
      26                 :            :         size_t maxlen;
      27                 :            :         char *lv_name_old, *lv_name_new;
      28                 :            :         const char *vg_name, *vg_name_new, *vg_name_old;
      29                 :            :         char *st;
      30                 :          0 :         int r = ECMD_FAILED;
      31                 :            : 
      32                 :          0 :         struct volume_group *vg = NULL;
      33                 :            :         struct lv_list *lvl;
      34                 :            : 
      35         [ #  # ]:          0 :         if (argc == 3) {
      36                 :          0 :                 vg_name = skip_dev_dir(cmd, argv[0], NULL);
      37                 :          0 :                 lv_name_old = argv[1];
      38                 :          0 :                 lv_name_new = argv[2];
      39 [ #  #  #  #  # :          0 :                 if (strchr(lv_name_old, '/') &&
                      # ]
      40                 :          0 :                     (vg_name_old = extract_vgname(cmd, lv_name_old)) &&
      41                 :          0 :                     strcmp(vg_name_old, vg_name)) {
      42                 :          0 :                         log_error("Please use a single volume group name "
      43                 :            :                                   "(\"%s\" or \"%s\")", vg_name, vg_name_old);
      44                 :          0 :                         return EINVALID_CMD_LINE;
      45                 :            :                 }
      46         [ #  # ]:          0 :         } else if (argc == 2) {
      47                 :          0 :                 lv_name_old = argv[0];
      48                 :          0 :                 lv_name_new = argv[1];
      49                 :          0 :                 vg_name = extract_vgname(cmd, lv_name_old);
      50                 :            :         } else {
      51                 :          0 :                 log_error("Old and new logical volume names required");
      52                 :          0 :                 return EINVALID_CMD_LINE;
      53                 :            :         }
      54                 :            : 
      55         [ #  # ]:          0 :         if (!validate_name(vg_name)) {
      56                 :          0 :                 log_error("Please provide a valid volume group name");
      57                 :          0 :                 return EINVALID_CMD_LINE;
      58                 :            :         }
      59                 :            : 
      60   [ #  #  #  # ]:          0 :         if (strchr(lv_name_new, '/') &&
                 [ #  # ]
      61                 :          0 :             (vg_name_new = extract_vgname(cmd, lv_name_new)) &&
      62                 :          0 :             strcmp(vg_name, vg_name_new)) {
      63                 :          0 :                 log_error("Logical volume names must "
      64                 :            :                           "have the same volume group (\"%s\" or \"%s\")",
      65                 :            :                           vg_name, vg_name_new);
      66                 :          0 :                 return EINVALID_CMD_LINE;
      67                 :            :         }
      68                 :            : 
      69         [ #  # ]:          0 :         if ((st = strrchr(lv_name_old, '/')))
      70                 :          0 :                 lv_name_old = st + 1;
      71                 :            : 
      72         [ #  # ]:          0 :         if ((st = strrchr(lv_name_new, '/')))
      73                 :          0 :                 lv_name_new = st + 1;
      74                 :            : 
      75                 :            :         /* Check sanity of new name */
      76                 :          0 :         maxlen = NAME_LEN - strlen(vg_name) - strlen(cmd->dev_dir) - 3;
      77         [ #  # ]:          0 :         if (strlen(lv_name_new) > maxlen) {
      78                 :          0 :                 log_error("New logical volume path exceeds maximum length "
      79                 :            :                           "of %" PRIsize_t "!", maxlen);
      80                 :          0 :                 return ECMD_FAILED;
      81                 :            :         }
      82                 :            : 
      83         [ #  # ]:          0 :         if (!*lv_name_new) {
      84                 :          0 :                 log_error("New logical volume name may not be blank");
      85                 :          0 :                 return ECMD_FAILED;
      86                 :            :         }
      87                 :            : 
      88         [ #  # ]:          0 :         if (!apply_lvname_restrictions(lv_name_new)) {
      89                 :          0 :                 stack;
      90                 :          0 :                 return ECMD_FAILED;
      91                 :            :         }
      92                 :            : 
      93         [ #  # ]:          0 :         if (!validate_name(lv_name_new)) {
      94                 :          0 :                 log_error("New logical volume name \"%s\" is invalid",
      95                 :            :                      lv_name_new);
      96                 :          0 :                 return EINVALID_CMD_LINE;
      97                 :            :         }
      98                 :            : 
      99         [ #  # ]:          0 :         if (!strcmp(lv_name_old, lv_name_new)) {
     100                 :          0 :                 log_error("Old and new logical volume names must differ");
     101                 :          0 :                 return EINVALID_CMD_LINE;
     102                 :            :         }
     103                 :            : 
     104                 :          0 :         log_verbose("Checking for existing volume group \"%s\"", vg_name);
     105                 :          0 :         vg = vg_read_for_update(cmd, vg_name, NULL, 0);
     106         [ #  # ]:          0 :         if (vg_read_error(vg)) {
     107                 :          0 :                 vg_release(vg);
     108                 :          0 :                 stack;
     109                 :          0 :                 return ECMD_FAILED;
     110                 :            :         }
     111                 :            : 
     112         [ #  # ]:          0 :         if (!(lvl = find_lv_in_vg(vg, lv_name_old))) {
     113                 :          0 :                 log_error("Existing logical volume \"%s\" not found in "
     114                 :            :                           "volume group \"%s\"", lv_name_old, vg_name);
     115                 :          0 :                 goto error;
     116                 :            :         }
     117                 :            : 
     118         [ #  # ]:          0 :         if (!lv_rename(cmd, lvl->lv, lv_name_new))
     119                 :          0 :                 goto error;
     120                 :            : 
     121                 :          0 :         log_print("Renamed \"%s\" to \"%s\" in volume group \"%s\"",
     122                 :            :                   lv_name_old, lv_name_new, vg_name);
     123                 :            : 
     124                 :          0 :         r = ECMD_PROCESSED;
     125                 :            : error:
     126                 :          0 :         unlock_and_release_vg(cmd, vg, vg_name);
     127                 :          0 :         return r;
     128                 :            : }

Generated by: LCOV version 1.8