LCOV - code coverage report
Current view: top level - misc/kabi/lvm2.git/tools - vgchange.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 311 0.0 %
Date: 2010-04-13 Functions: 0 17 0.0 %
Branches: 0 266 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 _monitor_lvs_in_vg(struct cmd_context *cmd,
      19                 :            :                                struct volume_group *vg, int reg)
      20                 :            : {
      21                 :            :         struct lv_list *lvl;
      22                 :            :         struct logical_volume *lv;
      23                 :            :         struct lvinfo info;
      24                 :            :         int lv_active;
      25                 :          0 :         int count = 0;
      26                 :            : 
      27         [ #  # ]:          0 :         dm_list_iterate_items(lvl, &vg->lvs) {
      28                 :          0 :                 lv = lvl->lv;
      29                 :            : 
      30         [ #  # ]:          0 :                 if (!lv_info(cmd, lv, &info, 0, 0))
      31                 :          0 :                         lv_active = 0;
      32                 :            :                 else
      33                 :          0 :                         lv_active = info.exists;
      34                 :            : 
      35                 :            :                 /*
      36                 :            :                  * FIXME: Need to consider all cases... PVMOVE, etc
      37                 :            :                  */
      38 [ #  # ][ #  # ]:          0 :                 if ((lv->status & PVMOVE) || !lv_active)
      39                 :          0 :                         continue;
      40                 :            : 
      41         [ #  # ]:          0 :                 if (!monitor_dev_for_events(cmd, lv, reg)) {
      42                 :          0 :                         continue;
      43                 :            :                 } else
      44                 :          0 :                         count++;
      45                 :            :         }
      46                 :            : 
      47                 :            :         /*
      48                 :            :          * returns the number of _new_ monitored devices
      49                 :            :          */
      50                 :            : 
      51                 :          0 :         return count;
      52                 :            : }
      53                 :            : 
      54                 :          0 : static int _poll_lvs_in_vg(struct cmd_context *cmd,
      55                 :            :                            struct volume_group *vg)
      56                 :            : {
      57                 :            :         struct lv_list *lvl;
      58                 :            :         struct logical_volume *lv;
      59                 :            :         struct lvinfo info;
      60                 :            :         int lv_active;
      61                 :          0 :         int count = 0;
      62                 :            : 
      63         [ #  # ]:          0 :         dm_list_iterate_items(lvl, &vg->lvs) {
      64                 :          0 :                 lv = lvl->lv;
      65                 :            : 
      66         [ #  # ]:          0 :                 if (!lv_info(cmd, lv, &info, 0, 0))
      67                 :          0 :                         lv_active = 0;
      68                 :            :                 else
      69                 :          0 :                         lv_active = info.exists;
      70                 :            : 
      71 [ #  # ][ #  # ]:          0 :                 if (lv_active &&
      72                 :          0 :                     (lv->status & (PVMOVE|CONVERTING|MERGING))) {
      73                 :          0 :                         lv_spawn_background_polling(cmd, lv);
      74                 :          0 :                         count++;
      75                 :            :                 }
      76                 :            :         }
      77                 :            : 
      78                 :            :         /*
      79                 :            :          * returns the number of polled devices
      80                 :            :          * - there is no way to know if lv is already being polled
      81                 :            :          */
      82                 :            : 
      83                 :          0 :         return count;
      84                 :            : }
      85                 :            : 
      86                 :          0 : static int _activate_lvs_in_vg(struct cmd_context *cmd,
      87                 :            :                                struct volume_group *vg, int activate)
      88                 :            : {
      89                 :            :         struct lv_list *lvl;
      90                 :            :         struct logical_volume *lv;
      91                 :          0 :         int count = 0, expected_count = 0;
      92                 :            : 
      93         [ #  # ]:          0 :         dm_list_iterate_items(lvl, &vg->lvs) {
      94                 :          0 :                 lv = lvl->lv;
      95                 :          0 :                 log_verbose("ACTIVATE1 %s", lv->name);
      96                 :            : 
      97         [ #  # ]:          0 :                 if (!lv_is_visible(lv))
      98                 :          0 :                         continue;
      99                 :            : 
     100                 :            :                 /* Only request activation of snapshot origin devices */
     101 [ #  # ][ #  # ]:          0 :                 if ((lv->status & SNAPSHOT) || lv_is_cow(lv))
     102                 :          0 :                         continue;
     103                 :            : 
     104                 :            :                 /* Only request activation of mirror LV */
     105 [ #  # ][ #  # ]:          0 :                 if ((lv->status & MIRROR_IMAGE) || (lv->status & MIRROR_LOG))
     106                 :          0 :                         continue;
     107                 :            : 
     108                 :            :                 /* Only request activation of the first replicator-dev LV */
     109 [ #  # ][ #  # ]:          0 :                 if (lv_is_replicator_dev(lv) && (lv != first_replicator_dev(lv)))
     110                 :          0 :                         continue;
     111                 :            : 
     112                 :            :                 /* Can't deactivate a pvmove LV */
     113                 :            :                 /* FIXME There needs to be a controlled way of doing this */
     114 [ #  # ][ #  # ]:          0 :                 if (((activate == CHANGE_AN) || (activate == CHANGE_ALN)) &&
                 [ #  # ]
     115                 :          0 :                     ((lv->status & PVMOVE) ))
     116                 :          0 :                         continue;
     117                 :            : 
     118                 :          0 :                 expected_count++;
     119                 :            : 
     120         [ #  # ]:          0 :                 if (activate == CHANGE_AN) {
     121 [ #  # ][ #  # ]:          0 :                         if (!deactivate_lv(cmd, lv)) {
                 [ #  # ]
     122                 :          0 :                                 stack;
     123                 :          0 :                                 continue;
     124                 :            :                         }
     125         [ #  # ]:          0 :                 } else if (activate == CHANGE_ALN) {
     126 [ #  # ][ #  # ]:          0 :                         if (!deactivate_lv_local(cmd, lv)) {
                 [ #  # ]
     127                 :          0 :                                 stack;
     128                 :          0 :                                 continue;
     129                 :            :                         }
     130 [ #  # ][ #  # ]:          0 :                 } else if (lv_is_origin(lv) || (activate == CHANGE_AE)) {
     131 [ #  # ][ #  # ]:          0 :                         if (!activate_lv_excl(cmd, lv)) {
                 [ #  # ]
     132                 :          0 :                                 stack;
     133                 :          0 :                                 continue;
     134                 :            :                         }
     135         [ #  # ]:          0 :                 } else if (activate == CHANGE_ALY) {
     136 [ #  # ][ #  # ]:          0 :                         if (!activate_lv_local(cmd, lv)) {
                 [ #  # ]
     137                 :          0 :                                 stack;
     138                 :          0 :                                 continue;
     139                 :            :                         }
     140 [ #  # ][ #  # ]:          0 :                 } else if (!activate_lv(cmd, lv)) {
                 [ #  # ]
     141                 :          0 :                         stack;
     142                 :          0 :                         continue;
     143                 :            :                 }
     144                 :            : 
     145 [ #  # ][ #  # ]:          0 :                 if (background_polling() &&
         [ #  # ][ #  # ]
     146                 :            :                     activate != CHANGE_AN && activate != CHANGE_ALN &&
     147                 :          0 :                     (lv->status & (PVMOVE|CONVERTING|MERGING)))
     148                 :          0 :                         lv_spawn_background_polling(cmd, lv);
     149                 :            : 
     150                 :          0 :                 count++;
     151                 :            :         }
     152                 :            : 
     153         [ #  # ]:          0 :         if (expected_count)
     154 [ #  # ][ #  # ]:          0 :                 log_verbose("%s %d logical volumes in volume group %s",
     155                 :            :                             (activate == CHANGE_AN || activate == CHANGE_ALN)?
     156                 :            :                             "Deactivated" : "Activated", count, vg->name);
     157                 :            : 
     158         [ #  # ]:          0 :         return (expected_count != count) ? ECMD_FAILED : ECMD_PROCESSED;
     159                 :            : }
     160                 :            : 
     161                 :          0 : static int _vgchange_monitoring(struct cmd_context *cmd, struct volume_group *vg)
     162                 :            : {
     163                 :            :         int active, monitored;
     164                 :            : 
     165   [ #  #  #  # ]:          0 :         if ((active = lvs_in_vg_activated(vg)) &&
     166                 :          0 :             dmeventd_monitor_mode() != DMEVENTD_MONITOR_IGNORE) {
     167                 :          0 :                 monitored = _monitor_lvs_in_vg(cmd, vg, dmeventd_monitor_mode());
     168         [ #  # ]:          0 :                 log_print("%d logical volume(s) in volume group "
     169                 :            :                             "\"%s\" %smonitored",
     170                 :            :                             monitored, vg->name, (dmeventd_monitor_mode()) ? "" : "un");
     171                 :            :         }
     172                 :            : 
     173                 :          0 :         return ECMD_PROCESSED;
     174                 :            : }
     175                 :            : 
     176                 :          0 : static int _vgchange_background_polling(struct cmd_context *cmd, struct volume_group *vg)
     177                 :            : {
     178                 :            :         int polled;
     179                 :            : 
     180 [ #  # ][ #  # ]:          0 :         if (lvs_in_vg_activated(vg) && background_polling()) {
     181                 :          0 :                 polled = _poll_lvs_in_vg(cmd, vg);
     182                 :          0 :                 log_print("Background polling started for %d logical volume(s) "
     183                 :            :                           "in volume group \"%s\"",
     184                 :            :                           polled, vg->name);
     185                 :            :         }
     186                 :            : 
     187                 :          0 :         return ECMD_PROCESSED;
     188                 :            : }
     189                 :            : 
     190                 :          0 : static int _vgchange_available(struct cmd_context *cmd, struct volume_group *vg)
     191                 :            : {
     192                 :            :         int lv_open, active, monitored;
     193                 :            :         int available, ret;
     194                 :          0 :         int activate = 1;
     195                 :            : 
     196                 :            :         /*
     197                 :            :          * Safe, since we never write out new metadata here. Required for
     198                 :            :          * partial activation to work.
     199                 :            :          */
     200                 :          0 :         cmd->handles_missing_pvs = 1;
     201                 :            : 
     202                 :          0 :         available = arg_uint_value(cmd, available_ARG, 0);
     203                 :            : 
     204   [ #  #  #  # ]:          0 :         if ((available == CHANGE_AN) || (available == CHANGE_ALN))
     205                 :          0 :                 activate = 0;
     206                 :            : 
     207                 :            :         /* FIXME: Force argument to deactivate them? */
     208 [ #  # ][ #  # ]:          0 :         if (!activate && (lv_open = lvs_in_vg_opened(vg))) {
     209                 :          0 :                 log_error("Can't deactivate volume group \"%s\" with %d open "
     210                 :            :                           "logical volume(s)", vg->name, lv_open);
     211                 :          0 :                 return ECMD_FAILED;
     212                 :            :         }
     213                 :            : 
     214                 :            :         /* FIXME Move into library where clvmd can use it */
     215         [ #  # ]:          0 :         if (activate)
     216                 :          0 :                 check_current_backup(vg);
     217                 :            : 
     218 [ #  # ][ #  # ]:          0 :         if (activate && (active = lvs_in_vg_activated(vg))) {
     219                 :          0 :                 log_verbose("%d logical volume(s) in volume group \"%s\" "
     220                 :            :                             "already active", active, vg->name);
     221         [ #  # ]:          0 :                 if (dmeventd_monitor_mode() != DMEVENTD_MONITOR_IGNORE) {
     222                 :          0 :                         monitored = _monitor_lvs_in_vg(cmd, vg, dmeventd_monitor_mode());
     223         [ #  # ]:          0 :                         log_verbose("%d existing logical volume(s) in volume "
     224                 :            :                                     "group \"%s\" %smonitored",
     225                 :            :                                     monitored, vg->name,
     226                 :            :                                     dmeventd_monitor_mode() ? "" : "un");
     227                 :            :                 }
     228                 :            :         }
     229                 :            : 
     230                 :          0 :         ret = _activate_lvs_in_vg(cmd, vg, available);
     231                 :            : 
     232         [ #  # ]:          0 :         if (!vg->missing_vgs)
     233                 :          0 :                 log_print("%d logical volume(s) in volume group \"%s\" now active",
     234                 :            :                           lvs_in_vg_activated(vg), vg->name);
     235                 :          0 :         return ret;
     236                 :            : }
     237                 :            : 
     238                 :          0 : static int _vgchange_alloc(struct cmd_context *cmd, struct volume_group *vg)
     239                 :            : {
     240                 :            :         alloc_policy_t alloc;
     241                 :            : 
     242                 :          0 :         alloc = arg_uint_value(cmd, alloc_ARG, ALLOC_NORMAL);
     243                 :            : 
     244         [ #  # ]:          0 :         if (!archive(vg)) {
     245                 :          0 :                 stack;
     246                 :          0 :                 return ECMD_FAILED;
     247                 :            :         }
     248                 :            : 
     249                 :            :         /* FIXME: make consistent with vg_set_alloc_policy() */
     250         [ #  # ]:          0 :         if (alloc == vg->alloc) {
     251                 :          0 :                 log_error("Volume group allocation policy is already %s",
     252                 :            :                           get_alloc_string(vg->alloc));
     253                 :          0 :                 return ECMD_FAILED;
     254                 :            :         }
     255         [ #  # ]:          0 :         if (!vg_set_alloc_policy(vg, alloc)) {
     256                 :          0 :                 stack;
     257                 :          0 :                 return ECMD_FAILED;
     258                 :            :         }
     259                 :            : 
     260 [ #  # ][ #  # ]:          0 :         if (!vg_write(vg) || !vg_commit(vg)) {
     261                 :          0 :                 stack;
     262                 :          0 :                 return ECMD_FAILED;
     263                 :            :         }
     264                 :            : 
     265                 :          0 :         backup(vg);
     266                 :            : 
     267                 :          0 :         log_print("Volume group \"%s\" successfully changed", vg->name);
     268                 :            : 
     269                 :          0 :         return ECMD_PROCESSED;
     270                 :            : }
     271                 :            : 
     272                 :          0 : static int _vgchange_resizeable(struct cmd_context *cmd,
     273                 :            :                                 struct volume_group *vg)
     274                 :            : {
     275                 :          0 :         int resizeable = !strcmp(arg_str_value(cmd, resizeable_ARG, "n"), "y");
     276                 :            : 
     277   [ #  #  #  # ]:          0 :         if (resizeable && vg_is_resizeable(vg)) {
     278                 :          0 :                 log_error("Volume group \"%s\" is already resizeable",
     279                 :            :                           vg->name);
     280                 :          0 :                 return ECMD_FAILED;
     281                 :            :         }
     282                 :            : 
     283 [ #  # ][ #  # ]:          0 :         if (!resizeable && !vg_is_resizeable(vg)) {
     284                 :          0 :                 log_error("Volume group \"%s\" is already not resizeable",
     285                 :            :                           vg->name);
     286                 :          0 :                 return ECMD_FAILED;
     287                 :            :         }
     288                 :            : 
     289         [ #  # ]:          0 :         if (!archive(vg)) {
     290                 :          0 :                 stack;
     291                 :          0 :                 return ECMD_FAILED;
     292                 :            :         }
     293                 :            : 
     294         [ #  # ]:          0 :         if (resizeable)
     295                 :          0 :                 vg->status |= RESIZEABLE_VG;
     296                 :            :         else
     297                 :          0 :                 vg->status &= ~RESIZEABLE_VG;
     298                 :            : 
     299 [ #  # ][ #  # ]:          0 :         if (!vg_write(vg) || !vg_commit(vg)) {
     300                 :          0 :                 stack;
     301                 :          0 :                 return ECMD_FAILED;
     302                 :            :         }
     303                 :            : 
     304                 :          0 :         backup(vg);
     305                 :            : 
     306                 :          0 :         log_print("Volume group \"%s\" successfully changed", vg->name);
     307                 :            : 
     308                 :          0 :         return ECMD_PROCESSED;
     309                 :            : }
     310                 :            : 
     311                 :          0 : static int _vgchange_clustered(struct cmd_context *cmd,
     312                 :            :                                struct volume_group *vg)
     313                 :            : {
     314                 :          0 :         int clustered = !strcmp(arg_str_value(cmd, clustered_ARG, "n"), "y");
     315                 :            : 
     316   [ #  #  #  # ]:          0 :         if (clustered && (vg_is_clustered(vg))) {
     317                 :          0 :                 log_error("Volume group \"%s\" is already clustered",
     318                 :            :                           vg->name);
     319                 :          0 :                 return ECMD_FAILED;
     320                 :            :         }
     321                 :            : 
     322 [ #  # ][ #  # ]:          0 :         if (!clustered && !(vg_is_clustered(vg))) {
     323                 :          0 :                 log_error("Volume group \"%s\" is already not clustered",
     324                 :            :                           vg->name);
     325                 :          0 :                 return ECMD_FAILED;
     326                 :            :         }
     327                 :            : 
     328         [ #  # ]:          0 :         if (!archive(vg)) {
     329                 :          0 :                 stack;
     330                 :          0 :                 return ECMD_FAILED;
     331                 :            :         }
     332                 :            : 
     333         [ #  # ]:          0 :         if (!vg_set_clustered(vg, clustered))
     334                 :          0 :                 return ECMD_FAILED;
     335                 :            : 
     336 [ #  # ][ #  # ]:          0 :         if (!vg_write(vg) || !vg_commit(vg)) {
     337                 :          0 :                 stack;
     338                 :          0 :                 return ECMD_FAILED;
     339                 :            :         }
     340                 :            : 
     341                 :          0 :         backup(vg);
     342                 :            : 
     343                 :          0 :         log_print("Volume group \"%s\" successfully changed", vg->name);
     344                 :            : 
     345                 :          0 :         return ECMD_PROCESSED;
     346                 :            : }
     347                 :            : 
     348                 :          0 : static int _vgchange_logicalvolume(struct cmd_context *cmd,
     349                 :            :                                    struct volume_group *vg)
     350                 :            : {
     351                 :          0 :         uint32_t max_lv = arg_uint_value(cmd, logicalvolume_ARG, 0);
     352                 :            : 
     353         [ #  # ]:          0 :         if (!archive(vg)) {
     354                 :          0 :                 stack;
     355                 :          0 :                 return ECMD_FAILED;
     356                 :            :         }
     357                 :            : 
     358         [ #  # ]:          0 :         if (!vg_set_max_lv(vg, max_lv)) {
     359                 :          0 :                 stack;
     360                 :          0 :                 return ECMD_FAILED;
     361                 :            :         }
     362                 :            : 
     363 [ #  # ][ #  # ]:          0 :         if (!vg_write(vg) || !vg_commit(vg)) {
     364                 :          0 :                 stack;
     365                 :          0 :                 return ECMD_FAILED;
     366                 :            :         }
     367                 :            : 
     368                 :          0 :         backup(vg);
     369                 :            : 
     370                 :          0 :         log_print("Volume group \"%s\" successfully changed", vg->name);
     371                 :            : 
     372                 :          0 :         return ECMD_PROCESSED;
     373                 :            : }
     374                 :            : 
     375                 :          0 : static int _vgchange_physicalvolumes(struct cmd_context *cmd,
     376                 :            :                                      struct volume_group *vg)
     377                 :            : {
     378                 :          0 :         uint32_t max_pv = arg_uint_value(cmd, maxphysicalvolumes_ARG, 0);
     379                 :            : 
     380         [ #  # ]:          0 :         if (arg_sign_value(cmd, maxphysicalvolumes_ARG, 0) == SIGN_MINUS) {
     381                 :          0 :                 log_error("MaxPhysicalVolumes may not be negative");
     382                 :          0 :                 return EINVALID_CMD_LINE;
     383                 :            :         }
     384                 :            : 
     385         [ #  # ]:          0 :         if (!archive(vg)) {
     386                 :          0 :                 stack;
     387                 :          0 :                 return ECMD_FAILED;
     388                 :            :         }
     389                 :            : 
     390         [ #  # ]:          0 :         if (!vg_set_max_pv(vg, max_pv)) {
     391                 :          0 :                 stack;
     392                 :          0 :                 return ECMD_FAILED;
     393                 :            :         }
     394                 :            : 
     395 [ #  # ][ #  # ]:          0 :         if (!vg_write(vg) || !vg_commit(vg)) {
     396                 :          0 :                 stack;
     397                 :          0 :                 return ECMD_FAILED;
     398                 :            :         }
     399                 :            : 
     400                 :          0 :         backup(vg);
     401                 :            : 
     402                 :          0 :         log_print("Volume group \"%s\" successfully changed", vg->name);
     403                 :            : 
     404                 :          0 :         return ECMD_PROCESSED;
     405                 :            : }
     406                 :            : 
     407                 :          0 : static int _vgchange_pesize(struct cmd_context *cmd, struct volume_group *vg)
     408                 :            : {
     409                 :            :         uint32_t extent_size;
     410                 :            : 
     411         [ #  # ]:          0 :         if (arg_sign_value(cmd, physicalextentsize_ARG, 0) == SIGN_MINUS) {
     412                 :          0 :                 log_error("Physical extent size may not be negative");
     413                 :          0 :                 return EINVALID_CMD_LINE;
     414                 :            :         }
     415                 :            : 
     416                 :          0 :         extent_size = arg_uint_value(cmd, physicalextentsize_ARG, 0);
     417                 :            :         /* FIXME: remove check - redundant with vg_change_pesize */
     418         [ #  # ]:          0 :         if (extent_size == vg->extent_size) {
     419                 :          0 :                 log_error("Physical extent size of VG %s is already %s",
     420                 :            :                           vg->name, display_size(cmd, (uint64_t) extent_size));
     421                 :          0 :                 return ECMD_PROCESSED;
     422                 :            :         }
     423                 :            : 
     424         [ #  # ]:          0 :         if (!archive(vg)) {
     425                 :          0 :                 stack;
     426                 :          0 :                 return ECMD_FAILED;
     427                 :            :         }
     428                 :            : 
     429         [ #  # ]:          0 :         if (!vg_set_extent_size(vg, extent_size)) {
     430                 :          0 :                 stack;
     431                 :          0 :                 return EINVALID_CMD_LINE;
     432                 :            :         }
     433                 :            : 
     434 [ #  # ][ #  # ]:          0 :         if (!vg_write(vg) || !vg_commit(vg)) {
     435                 :          0 :                 stack;
     436                 :          0 :                 return ECMD_FAILED;
     437                 :            :         }
     438                 :            : 
     439                 :          0 :         backup(vg);
     440                 :            : 
     441                 :          0 :         log_print("Volume group \"%s\" successfully changed", vg->name);
     442                 :            : 
     443                 :          0 :         return ECMD_PROCESSED;
     444                 :            : }
     445                 :            : 
     446                 :          0 : static int _vgchange_tag(struct cmd_context *cmd, struct volume_group *vg,
     447                 :            :                          int arg)
     448                 :            : {
     449                 :            :         const char *tag;
     450                 :            : 
     451         [ #  # ]:          0 :         if (!(tag = arg_str_value(cmd, arg, NULL))) {
     452                 :          0 :                 log_error("Failed to get tag");
     453                 :          0 :                 return ECMD_FAILED;
     454                 :            :         }
     455                 :            : 
     456         [ #  # ]:          0 :         if (!archive(vg)) {
     457                 :          0 :                 stack;
     458                 :          0 :                 return ECMD_FAILED;
     459                 :            :         }
     460                 :            : 
     461         [ #  # ]:          0 :         if (!vg_change_tag(vg, tag, arg == addtag_ARG)) {
     462                 :          0 :                 stack;
     463                 :          0 :                 return ECMD_FAILED;
     464                 :            :         }
     465                 :            : 
     466 [ #  # ][ #  # ]:          0 :         if (!vg_write(vg) || !vg_commit(vg)) {
     467                 :          0 :                 stack;
     468                 :          0 :                 return ECMD_FAILED;
     469                 :            :         }
     470                 :            : 
     471                 :          0 :         backup(vg);
     472                 :            : 
     473                 :          0 :         log_print("Volume group \"%s\" successfully changed", vg->name);
     474                 :            : 
     475                 :          0 :         return ECMD_PROCESSED;
     476                 :            : }
     477                 :            : 
     478                 :          0 : static int _vgchange_uuid(struct cmd_context *cmd __attribute((unused)),
     479                 :            :                           struct volume_group *vg)
     480                 :            : {
     481                 :            :         struct lv_list *lvl;
     482                 :            : 
     483         [ #  # ]:          0 :         if (lvs_in_vg_activated(vg)) {
     484                 :          0 :                 log_error("Volume group has active logical volumes");
     485                 :          0 :                 return ECMD_FAILED;
     486                 :            :         }
     487                 :            : 
     488         [ #  # ]:          0 :         if (!archive(vg)) {
     489                 :          0 :                 stack;
     490                 :          0 :                 return ECMD_FAILED;
     491                 :            :         }
     492                 :            : 
     493         [ #  # ]:          0 :         if (!id_create(&vg->id)) {
     494                 :          0 :                 log_error("Failed to generate new random UUID for VG %s.",
     495                 :            :                           vg->name);
     496                 :          0 :                 return ECMD_FAILED;
     497                 :            :         }
     498                 :            : 
     499         [ #  # ]:          0 :         dm_list_iterate_items(lvl, &vg->lvs) {
     500                 :          0 :                 memcpy(&lvl->lv->lvid, &vg->id, sizeof(vg->id));
     501                 :            :         }
     502                 :            : 
     503 [ #  # ][ #  # ]:          0 :         if (!vg_write(vg) || !vg_commit(vg)) {
     504                 :          0 :                 stack;
     505                 :          0 :                 return ECMD_FAILED;
     506                 :            :         }
     507                 :            : 
     508                 :          0 :         backup(vg);
     509                 :            : 
     510                 :          0 :         log_print("Volume group \"%s\" successfully changed", vg->name);
     511                 :            : 
     512                 :          0 :         return ECMD_PROCESSED;
     513                 :            : }
     514                 :            : 
     515                 :          0 : static int _vgchange_refresh(struct cmd_context *cmd, struct volume_group *vg)
     516                 :            : {
     517                 :          0 :         log_verbose("Refreshing volume group \"%s\"", vg->name);
     518                 :            : 
     519         [ #  # ]:          0 :         if (!vg_refresh_visible(cmd, vg)) {
     520                 :          0 :                 stack;
     521                 :          0 :                 return ECMD_FAILED;
     522                 :            :         }
     523                 :            : 
     524                 :          0 :         return ECMD_PROCESSED;
     525                 :            : }
     526                 :            : 
     527                 :          0 : static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
     528                 :            :                            struct volume_group *vg,
     529                 :            :                            void *handle __attribute((unused)))
     530                 :            : {
     531                 :          0 :         int dmeventd_mode, r = ECMD_FAILED;
     532                 :            : 
     533         [ #  # ]:          0 :         if (vg_is_exported(vg)) {
     534                 :          0 :                 log_error("Volume group \"%s\" is exported", vg_name);
     535                 :          0 :                 return ECMD_FAILED;
     536                 :            :         }
     537                 :            : 
     538         [ #  # ]:          0 :         if (!get_activation_monitoring_mode(cmd, vg, &dmeventd_mode))
     539                 :          0 :                 return ECMD_FAILED;
     540                 :            : 
     541                 :          0 :         init_dmeventd_monitor(dmeventd_mode);
     542                 :            : 
     543                 :            :         /*
     544                 :            :          * FIXME: DEFAULT_BACKGROUND_POLLING should be "unspecified".
     545                 :            :          * If --poll is explicitly provided use it; otherwise polling
     546                 :            :          * should only be started if the LV is not already active. So:
     547                 :            :          * 1) change the activation code to say if the LV was actually activated
     548                 :            :          * 2) make polling of an LV tightly coupled with LV activation
     549                 :            :          */
     550                 :          0 :         init_background_polling(arg_int_value(cmd, poll_ARG,
     551                 :            :                                               DEFAULT_BACKGROUND_POLLING));
     552                 :            : 
     553         [ #  # ]:          0 :         if (arg_count(cmd, available_ARG))
     554                 :          0 :                 r = _vgchange_available(cmd, vg);
     555                 :            : 
     556         [ #  # ]:          0 :         else if (arg_count(cmd, monitor_ARG))
     557                 :          0 :                 r = _vgchange_monitoring(cmd, vg);
     558                 :            : 
     559         [ #  # ]:          0 :         else if (arg_count(cmd, poll_ARG))
     560                 :          0 :                 r = _vgchange_background_polling(cmd, vg);
     561                 :            : 
     562         [ #  # ]:          0 :         else if (arg_count(cmd, resizeable_ARG))
     563                 :          0 :                 r = _vgchange_resizeable(cmd, vg);
     564                 :            : 
     565         [ #  # ]:          0 :         else if (arg_count(cmd, logicalvolume_ARG))
     566                 :          0 :                 r = _vgchange_logicalvolume(cmd, vg);
     567                 :            : 
     568         [ #  # ]:          0 :         else if (arg_count(cmd, maxphysicalvolumes_ARG))
     569                 :          0 :                 r = _vgchange_physicalvolumes(cmd, vg);
     570                 :            : 
     571         [ #  # ]:          0 :         else if (arg_count(cmd, addtag_ARG))
     572                 :          0 :                 r = _vgchange_tag(cmd, vg, addtag_ARG);
     573                 :            : 
     574         [ #  # ]:          0 :         else if (arg_count(cmd, deltag_ARG))
     575                 :          0 :                 r = _vgchange_tag(cmd, vg, deltag_ARG);
     576                 :            : 
     577         [ #  # ]:          0 :         else if (arg_count(cmd, physicalextentsize_ARG))
     578                 :          0 :                 r = _vgchange_pesize(cmd, vg);
     579                 :            : 
     580         [ #  # ]:          0 :         else if (arg_count(cmd, uuid_ARG))
     581                 :          0 :                 r = _vgchange_uuid(cmd, vg);
     582                 :            : 
     583         [ #  # ]:          0 :         else if (arg_count(cmd, alloc_ARG))
     584                 :          0 :                 r = _vgchange_alloc(cmd, vg);
     585                 :            : 
     586         [ #  # ]:          0 :         else if (arg_count(cmd, clustered_ARG))
     587                 :          0 :                 r = _vgchange_clustered(cmd, vg);
     588                 :            : 
     589         [ #  # ]:          0 :         else if (arg_count(cmd, refresh_ARG))
     590                 :          0 :                 r = _vgchange_refresh(cmd, vg);
     591                 :            : 
     592                 :          0 :         return r;
     593                 :            : }
     594                 :            : 
     595                 :          0 : int vgchange(struct cmd_context *cmd, int argc, char **argv)
     596                 :            : {
     597         [ #  # ]:          0 :         if (!
     598                 :          0 :             (arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) +
     599                 :          0 :              arg_count(cmd, maxphysicalvolumes_ARG) +
     600                 :          0 :              arg_count(cmd, resizeable_ARG) + arg_count(cmd, deltag_ARG) +
     601                 :          0 :              arg_count(cmd, addtag_ARG) + arg_count(cmd, uuid_ARG) +
     602                 :          0 :              arg_count(cmd, physicalextentsize_ARG) +
     603                 :          0 :              arg_count(cmd, clustered_ARG) + arg_count(cmd, alloc_ARG) +
     604                 :          0 :              arg_count(cmd, monitor_ARG) + arg_count(cmd, poll_ARG) +
     605                 :            :              arg_count(cmd, refresh_ARG))) {
     606                 :          0 :                 log_error("Need 1 or more of -a, -c, -l, -p, -s, -x, "
     607                 :            :                           "--refresh, --uuid, --alloc, --addtag, --deltag, "
     608                 :            :                           "--monitor or --poll");
     609                 :          0 :                 return EINVALID_CMD_LINE;
     610                 :            :         }
     611                 :            : 
     612                 :            :         /* FIXME Cope with several changes at once! */
     613         [ #  # ]:          0 :         if (arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) +
     614                 :          0 :             arg_count(cmd, maxphysicalvolumes_ARG) +
     615                 :          0 :             arg_count(cmd, resizeable_ARG) + arg_count(cmd, deltag_ARG) +
     616                 :          0 :             arg_count(cmd, addtag_ARG) + arg_count(cmd, alloc_ARG) +
     617                 :          0 :             arg_count(cmd, uuid_ARG) + arg_count(cmd, clustered_ARG) +
     618                 :          0 :             arg_count(cmd, physicalextentsize_ARG) > 1) {
     619                 :          0 :                 log_error("Only one of -a, -c, -l, -p, -s, -x, --uuid, "
     620                 :            :                           "--alloc, --addtag or --deltag allowed");
     621                 :          0 :                 return EINVALID_CMD_LINE;
     622                 :            :         }
     623                 :            : 
     624   [ #  #  #  # ]:          0 :         if (arg_count(cmd, ignorelockingfailure_ARG) &&
     625                 :          0 :             !arg_count(cmd, available_ARG)) {
     626                 :          0 :                 log_error("--ignorelockingfailure only available with -a");
     627                 :          0 :                 return EINVALID_CMD_LINE;
     628                 :            :         }
     629                 :            : 
     630   [ #  #  #  # ]:          0 :         if (arg_count(cmd, available_ARG) == 1
     631                 :          0 :             && arg_count(cmd, autobackup_ARG)) {
     632                 :          0 :                 log_error("-A option not necessary with -a option");
     633                 :          0 :                 return EINVALID_CMD_LINE;
     634                 :            :         }
     635                 :            : 
     636         [ #  # ]:          0 :         return process_each_vg(cmd, argc, argv,
     637                 :          0 :                                (arg_count(cmd, available_ARG)) ?
     638                 :            :                                0 : READ_FOR_UPDATE,
     639                 :            :                                NULL,
     640                 :            :                                &vgchange_single);
     641                 :            : }

Generated by: LCOV version 1.8