mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-22 17:35:59 +03:00
6ab2a22fcf
commit a125a3bb50
"lv_remove: reduce commits for removed LVs"
changed "lvremove <vgname>" from removing one LV at a time,
to removing all LVs in one vg write/commit. It also changed
the behavior if some of the LVs could not be removed, from
removing those LVs that could be removed, to removing nothing
if any LV could not be removed. This caused a regression in
shared VGs using sanlock, in which the on-disk lease was
removed for any LV that could be removed, even if the command
decided to remove nothing. This would leave LVs without a
valid ondisk lease, and "lock failed: error -221" would be
returned for any command attempting to lock the LV.
Fix this by not freeing the on-disk leases until after the
command has decided to go ahead and remove everything, and
has written the VG metadata.
Before the fix:
node1: lvchange -ay vg/lv1
node2: lvchange -ay vg/lv2
node1: lvs
lv1 test -wi-a----- 4.00m
lv2 test -wi------- 4.00m
node2: lvs
lv1 test -wi------- 4.00m
lv2 test -wi-a----- 4.00m
node1: lvremove -y vg/lv1 vg/lv2
LV locked by other host: vg/lv2
(lvremove removed neither of the LVs, but it freed
the lock for lv1, which could have been removed
except for the proper locking failure on lv2.)
node1: lvs
lv1 test -wi------- 4.00m
lv2 test -wi------- 4.00m
node1: lvremove -y vg/lv1
LV vg/lv1 lock failed: error -221
(The lock for lv1 is gone, so nothing can be done with it.)
195 lines
6.3 KiB
C
195 lines
6.3 KiB
C
/*
|
|
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
|
|
* Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved.
|
|
*
|
|
* This file is part of LVM2.
|
|
*
|
|
* This copyrighted material is made available to anyone wishing to use,
|
|
* modify, copy, or redistribute it subject to the terms and conditions
|
|
* of the GNU Lesser General Public License v.2.1.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
#ifndef _LVM_VG_H
|
|
#define _LVM_VG_H
|
|
|
|
#include "lib/uuid/uuid.h"
|
|
#include "device_mapper/all.h"
|
|
|
|
struct cmd_context;
|
|
struct format_instance;
|
|
struct logical_volume;
|
|
|
|
typedef enum {
|
|
ALLOC_INVALID,
|
|
ALLOC_CONTIGUOUS,
|
|
ALLOC_CLING,
|
|
ALLOC_CLING_BY_TAGS, /* Internal - never written or displayed. */
|
|
ALLOC_NORMAL,
|
|
ALLOC_ANYWHERE,
|
|
ALLOC_INHERIT
|
|
} alloc_policy_t;
|
|
|
|
#define MAX_EXTENT_COUNT (UINT32_MAX)
|
|
|
|
struct volume_group {
|
|
struct cmd_context *cmd;
|
|
struct dm_pool *vgmem;
|
|
struct format_instance *fid;
|
|
const struct format_type *original_fmt; /* Set when processing backup files */
|
|
struct lvmcache_vginfo *vginfo;
|
|
uint32_t seqno; /* Metadata sequence number */
|
|
unsigned skip_validate_lock_args : 1;
|
|
unsigned lockd_not_started : 1;
|
|
unsigned needs_backup : 1;
|
|
unsigned needs_write_and_commit : 1;
|
|
unsigned needs_lockd_free_lvs : 1;
|
|
uint32_t write_count; /* count the number of vg_write calls */
|
|
uint32_t buffer_size_hint; /* hint with buffer size of parsed VG */
|
|
|
|
/*
|
|
* The parsed committed (on-disk) copy of this VG; is NULL if this VG is committed
|
|
* version (i.e. vg_committed == NULL *implies* this is the committed copy,
|
|
* there is no guarantee that if this VG is the same as the committed one
|
|
* this will be NULL). The pointer is maintained by calls to vg_write & vg_commit
|
|
*/
|
|
struct dm_config_tree *committed_cft;
|
|
struct volume_group *vg_committed;
|
|
struct volume_group *vg_precommitted;
|
|
|
|
alloc_policy_t alloc;
|
|
struct profile *profile;
|
|
uint64_t status;
|
|
|
|
struct id id;
|
|
const char *name;
|
|
const char *old_name; /* Set during vgrename and vgcfgrestore */
|
|
const char *system_id;
|
|
const char *lock_type;
|
|
const char *lock_args;
|
|
|
|
uint32_t extent_size;
|
|
uint32_t extent_count;
|
|
uint32_t free_count;
|
|
|
|
uint32_t max_lv;
|
|
uint32_t max_pv;
|
|
|
|
/* physical volumes */
|
|
uint32_t pv_count;
|
|
struct dm_list pvs;
|
|
|
|
/*
|
|
* List of physical volumes that were used in vgextend but do not carry
|
|
* a PV label yet. They need to be pvcreate'd at vg_write time.
|
|
*/
|
|
|
|
struct dm_list pv_write_list; /* struct pv_list */
|
|
|
|
/*
|
|
* logical volumes
|
|
* The following relationship should always hold:
|
|
* dm_list_size(lvs) = user visible lv_count + snapshot_count + other invisible LVs
|
|
*
|
|
* Snapshots consist of 2 instances of "struct logical_volume":
|
|
* - cow (lv_name is visible to the user)
|
|
* - snapshot (lv_name is 'snapshotN')
|
|
*
|
|
* Mirrors consist of multiple instances of "struct logical_volume":
|
|
* - one for the mirror log
|
|
* - one for each mirror leg
|
|
* - one for the user-visible mirror LV
|
|
*/
|
|
struct dm_list lvs;
|
|
struct dm_list historical_lvs;
|
|
|
|
struct dm_list tags;
|
|
|
|
/*
|
|
* FIXME: Move the next fields into a different struct?
|
|
*/
|
|
|
|
/*
|
|
* List of removed logical volumes by _lv_reduce.
|
|
*/
|
|
struct dm_list removed_lvs;
|
|
|
|
/*
|
|
* List of removed historical logical volumes by historical_glv_remove.
|
|
*/
|
|
struct dm_list removed_historical_lvs;
|
|
|
|
/*
|
|
* List of removed physical volumes by pvreduce.
|
|
* They have to get cleared on vg_commit.
|
|
*/
|
|
struct dm_list removed_pvs;
|
|
uint32_t open_mode; /* FIXME: read or write - check lock type? */
|
|
|
|
uint32_t mda_copies; /* target number of mdas for this VG */
|
|
|
|
struct logical_volume *pool_metadata_spare_lv; /* one per VG */
|
|
struct logical_volume *sanlock_lv; /* one per VG */
|
|
struct dm_list msg_list;
|
|
struct dm_list lockd_free_lvs;
|
|
};
|
|
|
|
struct volume_group *alloc_vg(const char *pool_name, struct cmd_context *cmd,
|
|
const char *vg_name);
|
|
|
|
/*
|
|
* release_vg() must be called on every struct volume_group allocated
|
|
* by vg_create() or vg_read_internal() to free it when no longer required.
|
|
*/
|
|
void release_vg(struct volume_group *vg);
|
|
void free_orphan_vg(struct volume_group *vg);
|
|
|
|
char *vg_fmt_dup(const struct volume_group *vg);
|
|
char *vg_name_dup(const struct volume_group *vg);
|
|
char *vg_system_id_dup(const struct volume_group *vg);
|
|
char *vg_lock_type_dup(const struct volume_group *vg);
|
|
char *vg_lock_args_dup(const struct volume_group *vg);
|
|
uint32_t vg_seqno(const struct volume_group *vg);
|
|
uint64_t vg_status(const struct volume_group *vg);
|
|
int vg_set_alloc_policy(struct volume_group *vg, alloc_policy_t alloc);
|
|
int vg_set_system_id(struct volume_group *vg, const char *system_id);
|
|
int vg_set_lock_type(struct volume_group *vg, const char *lock_type);
|
|
uint64_t vg_size(const struct volume_group *vg);
|
|
uint64_t vg_free(const struct volume_group *vg);
|
|
uint64_t vg_extent_size(const struct volume_group *vg);
|
|
int vg_check_new_extent_size(const struct format_type *fmt, uint32_t new_extent_size);
|
|
int vg_set_extent_size(struct volume_group *vg, uint32_t new_extent_size);
|
|
uint64_t vg_extent_count(const struct volume_group *vg);
|
|
uint64_t vg_free_count(const struct volume_group *vg);
|
|
uint64_t vg_pv_count(const struct volume_group *vg);
|
|
uint64_t vg_max_pv(const struct volume_group *vg);
|
|
int vg_set_max_pv(struct volume_group *vg, uint32_t max_pv);
|
|
uint64_t vg_max_lv(const struct volume_group *vg);
|
|
int vg_set_max_lv(struct volume_group *vg, uint32_t max_lv);
|
|
uint32_t vg_mda_count(const struct volume_group *vg);
|
|
uint32_t vg_mda_used_count(const struct volume_group *vg);
|
|
uint32_t vg_mda_copies(const struct volume_group *vg);
|
|
int vg_set_mda_copies(struct volume_group *vg, uint32_t mda_copies);
|
|
char *vg_profile_dup(const struct volume_group *vg);
|
|
void vg_backup_if_needed(struct volume_group *vg);
|
|
|
|
/*
|
|
* Returns visible LV count - number of LVs from user perspective
|
|
*/
|
|
unsigned vg_visible_lvs(const struct volume_group *vg);
|
|
|
|
/*
|
|
* Count snapshot LVs.
|
|
*/
|
|
unsigned snapshot_count(const struct volume_group *vg);
|
|
|
|
uint64_t vg_mda_size(const struct volume_group *vg);
|
|
uint64_t vg_mda_free(const struct volume_group *vg);
|
|
char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg);
|
|
char *vg_uuid_dup(const struct volume_group *vg);
|
|
char *vg_tags_dup(const struct volume_group *vg);
|
|
|
|
#endif /* _LVM_VG_H */
|