1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

Add clustered attribute so vgchange can identify clustered VGs w/o locking.

This commit is contained in:
Alasdair Kergon 2005-03-21 22:55:12 +00:00
parent e5b836d2d6
commit 343a8c920d
12 changed files with 101 additions and 9 deletions

View File

@ -1,5 +1,6 @@
Version 2.01.08 - Version 2.01.08 -
================================ ================================
Add clustered attribute so vgchange can identify clustered VGs w/o locking.
Improve detection of external changes affecting internal cache. Improve detection of external changes affecting internal cache.
Add 'already in device cache' debug message. Add 'already in device cache' debug message.
Add -a to pvdisplay -C. Add -a to pvdisplay -C.

View File

@ -446,7 +446,7 @@ int init_cluster_locking(struct locking_type *locking, struct config_tree *cft)
locking->lock_resource = _lock_resource; locking->lock_resource = _lock_resource;
locking->fin_locking = _locking_end; locking->fin_locking = _locking_end;
locking->reset_locking = _reset_locking; locking->reset_locking = _reset_locking;
locking->flags = LCK_PRE_MEMLOCK; locking->flags = LCK_PRE_MEMLOCK | LCK_CLUSTERED;
_clvmd_sock = _open_local_sock(); _clvmd_sock = _open_local_sock();
if (_clvmd_sock == -1) if (_clvmd_sock == -1)
@ -463,6 +463,7 @@ int locking_init(int type, struct config_tree *cf, uint32_t *flags)
/* Ask LVM to lock memory before calling us */ /* Ask LVM to lock memory before calling us */
*flags |= LCK_PRE_MEMLOCK; *flags |= LCK_PRE_MEMLOCK;
*flags |= LCK_CLUSTERED;
return 1; return 1;
} }

View File

@ -124,6 +124,8 @@ static inline void _update_vg_lock_count(int flags)
*/ */
int init_locking(int type, struct config_tree *cft) int init_locking(int type, struct config_tree *cft)
{ {
init_lockingfailed(0);
switch (type) { switch (type) {
case 0: case 0:
init_no_locking(&_locking, cft); init_no_locking(&_locking, cft);
@ -165,6 +167,7 @@ int init_locking(int type, struct config_tree *cft)
log_verbose("Locking disabled - only read operations permitted."); log_verbose("Locking disabled - only read operations permitted.");
init_no_locking(&_locking, cft); init_no_locking(&_locking, cft);
init_lockingfailed(1);
return 1; return 1;
} }
@ -321,3 +324,9 @@ int vg_write_lock_held(void)
{ {
return _vg_write_lock_held; return _vg_write_lock_held;
} }
int locking_is_clustered(void)
{
return (_locking.flags & LCK_CLUSTERED) ? 1 : 0;
}

View File

@ -20,6 +20,7 @@ int init_locking(int type, struct config_tree *cf);
void fin_locking(void); void fin_locking(void);
void reset_locking(void); void reset_locking(void);
int vg_write_lock_held(void); int vg_write_lock_held(void);
int locking_is_clustered(void);
/* /*
* LCK_VG: * LCK_VG:

View File

@ -23,6 +23,7 @@ typedef void (*fin_lock_fn) (void);
typedef void (*reset_lock_fn) (void); typedef void (*reset_lock_fn) (void);
#define LCK_PRE_MEMLOCK 0x00000001 /* Is memlock() needed before calls? */ #define LCK_PRE_MEMLOCK 0x00000001 /* Is memlock() needed before calls? */
#define LCK_CLUSTERED 0x00000002
struct locking_type { struct locking_type {
uint32_t flags; uint32_t flags;

View File

@ -40,6 +40,7 @@ static int _indent = 1;
static int _log_cmd_name = 0; static int _log_cmd_name = 0;
static int _log_suppress = 0; static int _log_suppress = 0;
static int _ignorelockingfailure = 0; static int _ignorelockingfailure = 0;
static int _lockingfailed = 0;
static int _security_level = SECURITY_LEVEL; static int _security_level = SECURITY_LEVEL;
static char _cmd_name[30] = ""; static char _cmd_name[30] = "";
static char _msg_prefix[30] = " "; static char _msg_prefix[30] = " ";
@ -160,6 +161,11 @@ void init_ignorelockingfailure(int level)
_ignorelockingfailure = level; _ignorelockingfailure = level;
} }
void init_lockingfailed(int level)
{
_lockingfailed = level;
}
void init_security_level(int level) void init_security_level(int level)
{ {
_security_level = level; _security_level = level;
@ -214,6 +220,11 @@ int full_scan_done()
return _full_scan_done; return _full_scan_done;
} }
int lockingfailed()
{
return _lockingfailed;
}
int ignorelockingfailure() int ignorelockingfailure()
{ {
return _ignorelockingfailure; return _ignorelockingfailure;

View File

@ -71,6 +71,7 @@ void init_cmd_name(int status);
void init_msg_prefix(const char *prefix); void init_msg_prefix(const char *prefix);
void init_indent(int indent); void init_indent(int indent);
void init_ignorelockingfailure(int level); void init_ignorelockingfailure(int level);
void init_lockingfailed(int level);
void init_security_level(int level); void init_security_level(int level);
void set_cmd_name(const char *cmd_name); void set_cmd_name(const char *cmd_name);
@ -82,6 +83,7 @@ int pvmove_mode(void);
int full_scan_done(void); int full_scan_done(void);
int debug_level(void); int debug_level(void);
int ignorelockingfailure(void); int ignorelockingfailure(void);
int lockingfailed(void);
int security_level(void); int security_level(void);
/* Suppress messages to stdout/stderr */ /* Suppress messages to stdout/stderr */

View File

@ -59,6 +59,7 @@ arg(activevolumegroups_ARG, 'A', "activevolumegroups", NULL)
arg(background_ARG, 'b', "background", NULL) arg(background_ARG, 'b', "background", NULL)
arg(blockdevice_ARG, 'b', "blockdevice", NULL) arg(blockdevice_ARG, 'b', "blockdevice", NULL)
arg(chunksize_ARG, 'c', "chunksize", size_kb_arg) arg(chunksize_ARG, 'c', "chunksize", size_kb_arg)
arg(clustered_ARG, 'c', "clustered", yes_no_arg)
arg(colon_ARG, 'c', "colon", NULL) arg(colon_ARG, 'c', "colon", NULL)
arg(columns_ARG, 'C', "columns", NULL) arg(columns_ARG, 'C', "columns", NULL)
arg(contiguous_ARG, 'C', "contiguous", yes_no_arg) arg(contiguous_ARG, 'C', "contiguous", yes_no_arg)

View File

@ -566,6 +566,7 @@ xx(vgchange,
"\t[-v|--verbose] " "\n" "\t[-v|--verbose] " "\n"
"\t[--version]" "\n" "\t[--version]" "\n"
"\t{-a|--available [e|l]{y|n} |" "\n" "\t{-a|--available [e|l]{y|n} |" "\n"
"\t -c|--clustered {y|n} |" "\n"
"\t -x|--resizeable {y|n} |" "\n" "\t -x|--resizeable {y|n} |" "\n"
"\t -l|--logicalvolume MaxLogicalVolumes |" "\n" "\t -l|--logicalvolume MaxLogicalVolumes |" "\n"
"\t --addtag Tag |\n" "\t --addtag Tag |\n"
@ -573,8 +574,8 @@ xx(vgchange,
"\t[VolumeGroupName...]\n", "\t[VolumeGroupName...]\n",
addtag_ARG, alloc_ARG, allocation_ARG, autobackup_ARG, available_ARG, addtag_ARG, alloc_ARG, allocation_ARG, autobackup_ARG, available_ARG,
deltag_ARG, ignorelockingfailure_ARG, logicalvolume_ARG, partial_ARG, clustered_ARG, deltag_ARG, ignorelockingfailure_ARG, logicalvolume_ARG,
resizeable_ARG, resizable_ARG, test_ARG, uuid_ARG) partial_ARG, resizeable_ARG, resizable_ARG, test_ARG, uuid_ARG)
xx(vgck, xx(vgck,
"Check the consistency of volume group(s)", "Check the consistency of volume group(s)",
@ -608,6 +609,7 @@ xx(vgcreate,
"\t[-A|--autobackup {y|n}] " "\n" "\t[-A|--autobackup {y|n}] " "\n"
"\t[--addtag Tag] " "\n" "\t[--addtag Tag] " "\n"
"\t[--alloc AllocationPolicy] " "\n" "\t[--alloc AllocationPolicy] " "\n"
"\t[-c|--clustered] " "\n"
"\t[-d|--debug]" "\n" "\t[-d|--debug]" "\n"
"\t[-h|--help]" "\n" "\t[-h|--help]" "\n"
"\t[-l|--maxlogicalvolumes MaxLogicalVolumes]" "\n" "\t[-l|--maxlogicalvolumes MaxLogicalVolumes]" "\n"
@ -619,7 +621,7 @@ xx(vgcreate,
"\t[--version] " "\n" "\t[--version] " "\n"
"\tVolumeGroupName PhysicalVolume [PhysicalVolume...]\n", "\tVolumeGroupName PhysicalVolume [PhysicalVolume...]\n",
addtag_ARG, alloc_ARG, autobackup_ARG, maxlogicalvolumes_ARG, addtag_ARG, alloc_ARG, autobackup_ARG, clustered_ARG, maxlogicalvolumes_ARG,
maxphysicalvolumes_ARG, metadatatype_ARG, physicalextentsize_ARG, test_ARG) maxphysicalvolumes_ARG, metadatatype_ARG, physicalextentsize_ARG, test_ARG)
xx(vgdisplay, xx(vgdisplay,

View File

@ -94,6 +94,12 @@ static int lvchange_availability(struct cmd_context *cmd,
return 0; return 0;
} }
} else { } else {
if (lockingfailed() && (lv->vg->status & CLUSTERED)) {
log_verbose("Locking failed: ignoring clustered "
"logical volume %s", lv->name);
return 0;
}
if (lv_is_origin(lv) || (activate == CHANGE_AE)) { if (lv_is_origin(lv) || (activate == CHANGE_AE)) {
log_verbose("Activating logical volume \"%s\" " log_verbose("Activating logical volume \"%s\" "
"exclusively", lv->name); "exclusively", lv->name);
@ -361,6 +367,7 @@ static int lvchange_tag(struct cmd_context *cmd, struct logical_volume *lv,
return 1; return 1;
} }
static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv, static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
void *handle) void *handle)
{ {

View File

@ -83,6 +83,12 @@ static int _vgchange_available(struct cmd_context *cmd, struct volume_group *vg)
return ECMD_FAILED; return ECMD_FAILED;
} }
if (activate && lockingfailed() && (vg->status & CLUSTERED)) {
log_error("Locking inactive: ignoring clustered "
"volume group %s", vg->name);
return ECMD_FAILED;
}
if (activate && (active = lvs_in_vg_activated(vg))) if (activate && (active = lvs_in_vg_activated(vg)))
log_verbose("%d logical volume(s) in volume group \"%s\" " log_verbose("%d logical volume(s) in volume group \"%s\" "
"already active", active, vg->name); "already active", active, vg->name);
@ -168,6 +174,41 @@ static int _vgchange_resizeable(struct cmd_context *cmd,
return ECMD_PROCESSED; return ECMD_PROCESSED;
} }
static int _vgchange_clustered(struct cmd_context *cmd,
struct volume_group *vg)
{
int clustered = !strcmp(arg_str_value(cmd, clustered_ARG, "n"), "y");
if (clustered && (vg->status & CLUSTERED)) {
log_error("Volume group \"%s\" is already clustered",
vg->name);
return ECMD_FAILED;
}
if (!clustered && !(vg->status & CLUSTERED)) {
log_error("Volume group \"%s\" is already not clustered",
vg->name);
return ECMD_FAILED;
}
if (!archive(vg))
return ECMD_FAILED;
if (clustered)
vg->status |= CLUSTERED;
else
vg->status &= ~CLUSTERED;
if (!vg_write(vg) || !vg_commit(vg))
return ECMD_FAILED;
backup(vg);
log_print("Volume group \"%s\" successfully changed", vg->name);
return ECMD_PROCESSED;
}
static int _vgchange_logicalvolume(struct cmd_context *cmd, static int _vgchange_logicalvolume(struct cmd_context *cmd,
struct volume_group *vg) struct volume_group *vg)
{ {
@ -334,6 +375,9 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
else if (arg_count(cmd, alloc_ARG)) else if (arg_count(cmd, alloc_ARG))
r = _vgchange_alloc(cmd, vg); r = _vgchange_alloc(cmd, vg);
else if (arg_count(cmd, clustered_ARG))
r = _vgchange_clustered(cmd, vg);
return r; return r;
} }
@ -343,8 +387,8 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
(arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) + (arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) +
arg_count(cmd, resizeable_ARG) + arg_count(cmd, deltag_ARG) + arg_count(cmd, resizeable_ARG) + arg_count(cmd, deltag_ARG) +
arg_count(cmd, addtag_ARG) + arg_count(cmd, uuid_ARG) + arg_count(cmd, addtag_ARG) + arg_count(cmd, uuid_ARG) +
arg_count(cmd, alloc_ARG))) { arg_count(cmd, clustered_ARG) + arg_count(cmd, alloc_ARG))) {
log_error("One of -a, -l, -x, --alloc, --addtag, --deltag " log_error("One of -a, -c, -l, -x, --alloc, --addtag, --deltag "
"or --uuid required"); "or --uuid required");
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }
@ -353,9 +397,9 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
if (arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) + if (arg_count(cmd, available_ARG) + arg_count(cmd, logicalvolume_ARG) +
arg_count(cmd, resizeable_ARG) + arg_count(cmd, deltag_ARG) + arg_count(cmd, resizeable_ARG) + arg_count(cmd, deltag_ARG) +
arg_count(cmd, addtag_ARG) + arg_count(cmd, alloc_ARG) + arg_count(cmd, addtag_ARG) + arg_count(cmd, alloc_ARG) +
arg_count(cmd, uuid_ARG) > 1) { arg_count(cmd, uuid_ARG) + arg_count(cmd, clustered_ARG) > 1) {
log_error("Only one of -a, -l, -x, --alloc, --addtag, --deltag " log_error("Only one of -a, -c, -l, -x, --uuid, --alloc, "
"or --uuid allowed"); "--addtag or --deltag allowed");
return EINVALID_CMD_LINE; return EINVALID_CMD_LINE;
} }

View File

@ -26,6 +26,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
struct volume_group *vg; struct volume_group *vg;
const char *tag; const char *tag;
alloc_policy_t alloc; alloc_policy_t alloc;
int clustered;
if (!argc) { if (!argc) {
log_error("Please provide volume group name and " log_error("Please provide volume group name and "
@ -130,6 +131,17 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
} }
} }
if (arg_count(cmd, clustered_ARG))
clustered = !strcmp(arg_str_value(cmd, clustered_ARG, "n"), "y");
else
/* Default depends on current locking type */
clustered = locking_is_clustered();
if (clustered)
vg->status |= CLUSTERED;
else
vg->status &= ~CLUSTERED;
if (!lock_vol(cmd, "", LCK_VG_WRITE)) { if (!lock_vol(cmd, "", LCK_VG_WRITE)) {
log_error("Can't get lock for orphan PVs"); log_error("Can't get lock for orphan PVs");
return ECMD_FAILED; return ECMD_FAILED;