* [Cluster-devel] conga/ricci/modules/storage LVM.cpp
@ 2006-08-21 15:44 kupcevic
0 siblings, 0 replies; 5+ messages in thread
From: kupcevic @ 2006-08-21 15:44 UTC (permalink / raw)
To: cluster-devel.redhat.com
CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2006-08-21 15:44:42
Modified files:
ricci/modules/storage: LVM.cpp
Log message:
storage module: use `pvdisplay -c` if `pvs` fails (`pvs` will fail if one of hard drives is not readable, while `pvdisplay -c` will give incomplete but usefull info)
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/LVM.cpp.diff?cvsroot=cluster&r1=1.5&r2=1.6
--- conga/ricci/modules/storage/LVM.cpp 2006/08/10 22:53:09 1.5
+++ conga/ricci/modules/storage/LVM.cpp 2006/08/21 15:44:42 1.6
@@ -32,16 +32,42 @@
#include <vector>
-
-
-
-
-
#include <iostream>
using namespace std;
+class PV_data
+{
+public:
+ PV_data() {}
+ PV_data(const String& path,
+ const String& vgname,
+ long long extent_size,
+ long long size,
+ long long size_free,
+ const String& uuid,
+ const String& attrs,
+ const String& format) :
+ path(path),
+ vgname(vgname),
+ extent_size(extent_size),
+ size(size),
+ size_free(size_free),
+ uuid(uuid),
+ attrs(attrs),
+ format(format) {}
+
+ String path;
+ String vgname;
+ long long extent_size;
+ long long size;
+ long long size_free;
+ String uuid;
+ String attrs;
+ String format;
+};
+
static String
get_locking_type();
@@ -49,9 +75,12 @@
static vector<String>
vg_props(const String& vgname);
+static const map<String, PV_data>
+probe_pvs();
+// pvs
static String PVS_OPTIONS = "pv_name,vg_name,pv_size,pv_free,pv_attr,pv_fmt,pv_uuid,vg_extent_size";
static unsigned int PVS_NAME_IDX = 0;
static unsigned int PVS_VG_NAME_IDX = 1;
@@ -64,6 +93,19 @@
static unsigned int PVS_OPTIONS_LENGTH = 8; // last
+// pvdisplay -c
+static unsigned int PVDISPLAY_c_NAME_IDX = 0;
+static unsigned int PVDISPLAY_c_VG_NAME_IDX = 1;
+static unsigned int PVDISPLAY_c_SIZE_IDX = 2;
+static unsigned int PVDISPLAY_c_EXTENT_SIZE_IDX = 7;
+static unsigned int PVDISPLAY_c_TOT_EXT_IDX = 8;
+static unsigned int PVDISPLAY_c_FREE_EXT_IDX = 9;
+static unsigned int PVDISPLAY_c_USED_EXT_IDX = 10;
+static unsigned int PVDISPLAY_c_UUID_IDX = 11;
+static unsigned int PVDISPLAY_c_OPTIONS_LENGTH = 12; // last
+
+
+// lvs
static String LVS_OPTIONS_STRING = "lv_name,vg_name,stripes,stripesize,lv_attr,lv_uuid,devices,origin,snap_percent,seg_start,seg_size,vg_extent_size,lv_size,vg_free_count,vg_attr";
static unsigned int LVS_NAME_IDX = 0;
static unsigned int LVS_VG_NAME_IDX = 1;
@@ -86,7 +128,7 @@
static unsigned int LVS_OPTIONS_LENGTH = 15; // last
-
+// vgs
static String VGS_OPTIONS_STRING = "vg_name,vg_attr,vg_size,vg_extent_size,vg_free_count,max_lv,max_pv,vg_uuid";
static unsigned int VGS_NAME_IDX = 0;
static unsigned int VGS_ATTR_IDX = 1;
@@ -134,40 +176,11 @@
{
check_locking();
- vector<String> args;
- args.push_back("pvs");
- args.push_back("--nosuffix");
- args.push_back("--noheadings");
- args.push_back("--units");
- args.push_back("b");
- args.push_back("--separator");
- args.push_back(";");
- args.push_back("-o");
- args.push_back(PVS_OPTIONS);
- String out, err;
- int status;
- if (utils::execute(LVM_BIN_PATH, args, out, err, status))
- throw String("execute failed");
- if (status != 0)
- throw String("pvs failed");
- vector<String> lines = utils::split(out, "\n");
- vector<String> words;
- for (vector<String>::iterator iter = lines.begin();
- iter != lines.end();
- iter++) {
- String line = utils::strip(*iter);
- vector<String> t_words = utils::split(line, ";");
- if (t_words.size() < PVS_OPTIONS_LENGTH)
- continue;
- if (t_words[PVS_NAME_IDX] == path) {
- words = t_words;
- break;
- }
- }
- if (words.size() < PVS_OPTIONS_LENGTH)
- throw String("no such pv");
-
- return words[PVS_VG_NAME_IDX];
+ map<String, PV_data> pvs(probe_pvs());
+ map<String, PV_data>::const_iterator iter = pvs.find(path);
+ if (iter == pvs.end())
+ throw String("no such pv: ") + path;
+ return iter->second.vgname;
}
@@ -274,56 +287,19 @@
{
check_locking();
- vector<String> args;
- args.push_back("pvs");
- args.push_back("--nosuffix");
- args.push_back("--noheadings");
- args.push_back("--units");
- args.push_back("b");
- args.push_back("--separator");
- args.push_back(";");
- args.push_back("-o");
- args.push_back(PVS_OPTIONS);
- String out, err;
- int status;
- if (utils::execute(LVM_BIN_PATH, args, out, err, status))
- throw String("execute failed");
- if (status != 0)
- throw String("pvs failed");
- vector<String> lines = utils::split(out, "\n");
- vector<String> words;
- for (vector<String>::iterator iter = lines.begin();
- iter != lines.end();
- iter++) {
- String line = utils::strip(*iter);
- vector<String> t_words = utils::split(line, ";");
- if (t_words.size() < PVS_OPTIONS_LENGTH)
- continue;
- if (t_words[PVS_NAME_IDX] == path) {
- words = t_words;
- break;
- }
- }
- if (words.size() < PVS_OPTIONS_LENGTH)
- throw String("no such pv");
-
- String vgname(utils::strip(words[PVS_VG_NAME_IDX]));
- props.set(Variable("vgname", vgname));
-
- long long extent_size = utils::to_long(words[PVS_EXTENT_SIZE_IDX]);
- props.set(Variable("extent_size", extent_size));
-
- long long size = utils::to_long(words[PVS_SIZE_IDX]);
- props.set(Variable("size", size));
-
- long long free = utils::to_long(words[PVS_FREE_IDX]);
- props.set(Variable("size_free", free));
-
- props.set(Variable("attrs", words[PVS_ATTR_IDX]));
-
- props.set(Variable("format", words[PVS_FMT_IDX]));
-
- props.set(Variable("uuid", words[PVS_UUID_IDX]));
+ map<String, PV_data> pvs(probe_pvs());
+ map<String, PV_data>::const_iterator iter = pvs.find(path);
+ if (iter == pvs.end())
+ throw String("no such pv: ") + path;
+ const PV_data& data = iter->second;
+
+ props.set(Variable("vgname", data.vgname));
+ props.set(Variable("extent_size", data.extent_size));
+ props.set(Variable("size", data.size));
+ props.set(Variable("size_free", data.size_free));
+ props.set(Variable("uuid", data.uuid));
+ props.set(Variable("attrs", data.attrs));
+ props.set(Variable("format", data.format));
}
@@ -339,31 +315,11 @@
// pv to vg mappings
map<String, String> pv_to_vg;
- vector<String> args;
- args.push_back("pvs");
- args.push_back("--nosuffix");
- args.push_back("--noheadings");
- args.push_back("--units");
- args.push_back("b");
- args.push_back("--separator");
- args.push_back(";");
- args.push_back("-o");
- args.push_back(PVS_OPTIONS);
- String out, err;
- int status;
- if (utils::execute(LVM_BIN_PATH, args, out, err, status))
- throw String("execute failed");
- if (status != 0)
- throw String("pvs failed");
- vector<String> lines = utils::split(out, "\n");
- for (vector<String>::iterator iter = lines.begin();
- iter != lines.end();
- iter++) {
- String& line = *iter;
- vector<String> words = utils::split(utils::strip(line), ";");
- if (words.size() >= PVS_OPTIONS_LENGTH)
- pv_to_vg[words[PVS_NAME_IDX]] = words[PVS_VG_NAME_IDX];
- }
+ map<String, PV_data> pvs_data(probe_pvs());
+ for (map<String, PV_data>::const_iterator iter = pvs_data.begin();
+ iter != pvs_data.end();
+ iter++)
+ pv_to_vg[iter->first] = iter->second.vgname;
// probe vg
if (!vgname.empty()) {
@@ -412,15 +368,16 @@
// LVS
- args.clear();
+ String out, err;
+ int status;
+ vector<String> args;
args.push_back("lvdisplay");
args.push_back("-c");
- out = err = "";
if (utils::execute(LVM_BIN_PATH, args, out, err, status))
throw String("execute failed");
if (status != 0)
throw String("lvdisplay failed");
- lines = utils::split(out, "\n");
+ vector<String> lines = utils::split(out, "\n");
for (vector<String>::iterator iter = lines.begin();
iter != lines.end();
iter++) {
@@ -782,3 +739,112 @@
return false;
return vg_props(vgname)[VGS_ATTR_IDX][5] == 'c';
}
+
+
+
+const map<String, PV_data>
+probe_pvs()
+{
+ map<String, PV_data> pvs;
+
+ String out, err;
+ int status;
+ vector<String> args;
+ args.push_back("pvs");
+ args.push_back("--nosuffix");
+ args.push_back("--noheadings");
+ args.push_back("--units");
+ args.push_back("b");
+ args.push_back("--separator");
+ args.push_back(";");
+ args.push_back("-o");
+ args.push_back(PVS_OPTIONS);
+ if (utils::execute(LVM_BIN_PATH, args, out, err, status))
+ throw String("execute failed");
+
+ bool use_pvdisplay = false;
+ if (status)
+ // wouldn't `pvdisplay -c` fail if `pvs` has already failed?
+ // `pvs` fails if it cannot read one hard drive (common in SANs),
+ // while pvdisplay reports without failure
+ use_pvdisplay = true;
+
+ if (use_pvdisplay) {
+ args.clear();
+ args.push_back("pvdisplay");
+ args.push_back("-c");
+ if (utils::execute(LVM_BIN_PATH, args, out, err, status))
+ throw String("execute failed");
+ if (status)
+ throw String("pvs and pvdisplay failed");
+
+ vector<String> lines = utils::split(utils::strip(out), "\n");
+ for (vector<String>::iterator iter = lines.begin();
+ iter != lines.end();
+ iter++) {
+ vector<String> words = utils::split(utils::strip(*iter), ":");
+ if (words.size() >= PVDISPLAY_c_OPTIONS_LENGTH) {
+ String path(utils::strip(words[PVDISPLAY_c_NAME_IDX]));
+ String vgname(utils::strip(words[PVDISPLAY_c_VG_NAME_IDX]));
+ long long extent_size = utils::to_long(words[PVDISPLAY_c_EXTENT_SIZE_IDX]);
+ extent_size *= 1024;
+ long long size = utils::to_long(words[PVDISPLAY_c_SIZE_IDX]);
+ size = size / 2 * 1024;
+ long long size_free = utils::to_long(words[PVDISPLAY_c_FREE_EXT_IDX]);
+ size_free *= extent_size;
+ if (vgname.empty())
+ size_free = size;
+ String uuid(words[PVDISPLAY_c_UUID_IDX]);
+
+ // pvdisplay doesn't report attr and format
+ // guess
+ // FIXME: probe somewhere else
+ String attrs;
+ if (vgname.empty())
+ attrs = "--";
+ else
+ attrs = "a-";
+ String format = "lvm2";
+
+ pvs[path] = PV_data(path,
+ vgname,
+ extent_size,
+ size,
+ size_free,
+ uuid,
+ attrs,
+ format);
+ }
+ }
+
+ } else {
+ vector<String> lines = utils::split(utils::strip(out), "\n");
+ for (vector<String>::iterator iter = lines.begin();
+ iter != lines.end();
+ iter++) {
+ vector<String> words = utils::split(utils::strip(*iter), ";");
+ if (words.size() >= PVS_OPTIONS_LENGTH) {
+ String path(utils::strip(words[PVS_NAME_IDX]));
+ String vgname(utils::strip(words[PVS_VG_NAME_IDX]));
+ long long extent_size = utils::to_long(words[PVS_EXTENT_SIZE_IDX]);
+ long long size = utils::to_long(words[PVS_SIZE_IDX]);
+ long long size_free = utils::to_long(words[PVS_FREE_IDX]);
+ String uuid(words[PVS_UUID_IDX]);
+ String attrs(words[PVS_ATTR_IDX]);
+ String format(words[PVS_FMT_IDX]);
+
+ pvs[path] = PV_data(path,
+ vgname,
+ extent_size,
+ size,
+ size_free,
+ uuid,
+ attrs,
+ format);
+ }
+ }
+ }
+
+ return pvs;
+}
+
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Cluster-devel] conga/ricci/modules/storage LVM.cpp
@ 2006-11-01 21:27 kupcevic
0 siblings, 0 replies; 5+ messages in thread
From: kupcevic @ 2006-11-01 21:27 UTC (permalink / raw)
To: cluster-devel.redhat.com
CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2006-11-01 21:27:05
Modified files:
ricci/modules/storage: LVM.cpp
Log message:
storage module: properly probe cluster quorum if LVM locking is marked as clustered
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/LVM.cpp.diff?cvsroot=cluster&r1=1.7&r2=1.8
--- conga/ricci/modules/storage/LVM.cpp 2006/10/06 03:10:13 1.7
+++ conga/ricci/modules/storage/LVM.cpp 2006/11/01 21:27:04 1.8
@@ -78,6 +78,9 @@
static const map<String, PV_data>
probe_pvs();
+static bool
+cluster_quorate();
+
// pvs
@@ -644,11 +647,15 @@
return get_locking_type() == "2";
}
-void
-LVM::check_locking()
+bool
+cluster_quorate()
{
- if (get_locking_type() == "2") {
- // check if quorate
+ bool use_magma = true;
+ if (access("/sbin/magma_tool", X_OK))
+ use_magma = false;
+
+ if (use_magma) {
+ // use magma_tool
String out, err;
int status;
vector<String> args;
@@ -657,11 +664,63 @@
throw command_not_found_error_msg("magma_tool");
if (status)
throw String("cluster tools: magma_tool errored");
- if (out.find("Quorate") == out.npos)
+ if (out.find("Quorate") != out.npos)
+ return true;
+ else
+ return false;
+ } else {
+ // use cman_tool
+ String cman_tool_path = "/sbin/cman_tool";
+ if (access(cman_tool_path.c_str(), X_OK))
+ cman_tool_path = "/usr/sbin/cman_tool";
+
+ String out, err;
+ int status;
+ vector<String> args;
+ args.push_back("status");
+ if (utils::execute(cman_tool_path, args, out, err, status))
+ throw command_not_found_error_msg("cman_tool");
+ if (status)
+ throw String("cluster tools: cman_tool errored");
+
+ long long quorum = -1;
+ long long votes = -1;
+ vector<String> lines = utils::split(utils::strip(out), "\n");
+ for (vector<String>::const_iterator iter = lines.begin();
+ iter != lines.end();
+ iter++) {
+ vector<String> words = utils::split(*iter);
+ if (words.size() < 2)
+ continue;
+ if (words[0] == "Quorum:")
+ quorum = utils::to_long(words[1]);
+ if (words[0] == "Total_votes:")
+ votes = utils::to_long(words[1]);
+ if (words.size() < 3)
+ continue;
+ if (words[0] == "Total" &&
+ words[1] == "votes:")
+ votes = utils::to_long(words[2]);
+ }
+
+ if (quorum <= 0 ||
+ votes < 0)
+ throw String("Unable to retrieve cluster quorum info");
+ return votes >= quorum;
+ }
+}
+
+void
+LVM::check_locking()
+{
+ if (get_locking_type() == "2") {
+ if (!cluster_quorate())
throw ClusterNotQuorateError();
// try to start clvmd, if not running
- args.clear();
+ String out, err;
+ int status;
+ vector<String> args;
args.push_back("clvmd");
args.push_back("start");
if (utils::execute("/sbin/service", args, out, err, status))
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Cluster-devel] conga/ricci/modules/storage LVM.cpp
@ 2006-11-29 16:39 rmccabe
0 siblings, 0 replies; 5+ messages in thread
From: rmccabe @ 2006-11-29 16:39 UTC (permalink / raw)
To: cluster-devel.redhat.com
CVSROOT: /cvs/cluster
Module name: conga
Changes by: rmccabe at sourceware.org 2006-11-29 16:39:35
Modified files:
ricci/modules/storage: LVM.cpp
Log message:
fix for creating a clustered logical volume
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/LVM.cpp.diff?cvsroot=cluster&r1=1.8&r2=1.9
--- conga/ricci/modules/storage/LVM.cpp 2006/11/01 21:27:04 1.8
+++ conga/ricci/modules/storage/LVM.cpp 2006/11/29 16:39:34 1.9
@@ -644,7 +644,8 @@
bool
LVM::clustered_available()
{
- return get_locking_type() == "2";
+ String locking_type = get_locking_type();
+ return (locking_type == "2" || locking_type == "3");
}
bool
@@ -713,7 +714,7 @@
void
LVM::check_locking()
{
- if (get_locking_type() == "2") {
+ if (clustered_available()) {
if (!cluster_quorate())
throw ClusterNotQuorateError();
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Cluster-devel] conga/ricci/modules/storage LVM.cpp
@ 2007-01-16 17:05 kupcevic
0 siblings, 0 replies; 5+ messages in thread
From: kupcevic @ 2007-01-16 17:05 UTC (permalink / raw)
To: cluster-devel.redhat.com
CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2007-01-16 17:05:27
Modified files:
ricci/modules/storage: LVM.cpp
Log message:
Fix for 222223 (deactivate LV before removal)
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/LVM.cpp.diff?cvsroot=cluster&r1=1.10&r2=1.11
--- conga/ricci/modules/storage/LVM.cpp 2006/12/12 13:11:51 1.10
+++ conga/ricci/modules/storage/LVM.cpp 2007/01/16 17:05:27 1.11
@@ -589,8 +589,8 @@
LVM::lvremove(const String& path)
{
vector<String> args;
- args.push_back("lvremove");
- args.push_back("--force");
+ args.push_back("lvchange");
+ args.push_back("-an");
args.push_back(path);
String out, err;
@@ -598,8 +598,28 @@
if (utils::execute(LVM_BIN_PATH, args, out, err, status, false))
throw command_not_found_error_msg(LVM_BIN_PATH);
if (status != 0)
- throw String("lvremove failed");
- utils::clear_cache();
+ throw String("Unable to deactivate LV (might be in use by other cluster nodes)");
+
+ try {
+ args.clear();
+ args.push_back("lvremove");
+ args.push_back("--force");
+ args.push_back(path);
+
+ if (utils::execute(LVM_BIN_PATH, args, out, err, status, false))
+ throw command_not_found_error_msg(LVM_BIN_PATH);
+ if (status != 0)
+ throw String("lvremove failed");
+ utils::clear_cache();
+ } catch ( ... ) {
+ args.clear();
+ args.push_back("lvchange");
+ args.push_back("-ay");
+ args.push_back(path);
+ utils::execute(LVM_BIN_PATH, args, out, err, status, false);
+ utils::clear_cache();
+ throw;
+ }
}
void
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Cluster-devel] conga/ricci/modules/storage LVM.cpp
@ 2007-01-17 14:41 kupcevic
0 siblings, 0 replies; 5+ messages in thread
From: kupcevic @ 2007-01-17 14:41 UTC (permalink / raw)
To: cluster-devel.redhat.com
CVSROOT: /cvs/cluster
Module name: conga
Branch: RHEL5
Changes by: kupcevic at sourceware.org 2007-01-17 14:41:15
Modified files:
ricci/modules/storage: LVM.cpp
Log message:
Fix for 222223 (deactivate LV before removal)
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/LVM.cpp.diff?cvsroot=cluster&only_with_tag=RHEL5&r1=1.7.2.3&r2=1.7.2.4
--- conga/ricci/modules/storage/LVM.cpp 2006/12/12 13:26:24 1.7.2.3
+++ conga/ricci/modules/storage/LVM.cpp 2007/01/17 14:41:13 1.7.2.4
@@ -589,8 +589,8 @@
LVM::lvremove(const String& path)
{
vector<String> args;
- args.push_back("lvremove");
- args.push_back("--force");
+ args.push_back("lvchange");
+ args.push_back("-an");
args.push_back(path);
String out, err;
@@ -598,8 +598,28 @@
if (utils::execute(LVM_BIN_PATH, args, out, err, status, false))
throw command_not_found_error_msg(LVM_BIN_PATH);
if (status != 0)
- throw String("lvremove failed");
- utils::clear_cache();
+ throw String("Unable to deactivate LV (might be in use by other cluster nodes)");
+
+ try {
+ args.clear();
+ args.push_back("lvremove");
+ args.push_back("--force");
+ args.push_back(path);
+
+ if (utils::execute(LVM_BIN_PATH, args, out, err, status, false))
+ throw command_not_found_error_msg(LVM_BIN_PATH);
+ if (status != 0)
+ throw String("lvremove failed");
+ utils::clear_cache();
+ } catch ( ... ) {
+ args.clear();
+ args.push_back("lvchange");
+ args.push_back("-ay");
+ args.push_back(path);
+ utils::execute(LVM_BIN_PATH, args, out, err, status, false);
+ utils::clear_cache();
+ throw;
+ }
}
void
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-01-17 14:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-17 14:41 [Cluster-devel] conga/ricci/modules/storage LVM.cpp kupcevic
-- strict thread matches above, loose matches on Subject: below --
2007-01-16 17:05 kupcevic
2006-11-29 16:39 rmccabe
2006-11-01 21:27 kupcevic
2006-08-21 15:44 kupcevic
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).