[Cluster-devel] conga/ricci/modules/storage PartitionTable.cpp ...
kupcevic at sourceware.org
kupcevic at sourceware.org
Thu Aug 24 14:51:45 UTC 2006
CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2006-08-24 14:51:44
Modified files:
ricci/modules/storage: PartitionTable.cpp parted_wrapper.cpp
Log message:
storage module: fix parted versioning differences
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/PartitionTable.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/parted_wrapper.cpp.diff?cvsroot=cluster&r1=1.6&r2=1.7
--- conga/ricci/modules/storage/PartitionTable.cpp 2006/08/10 22:53:09 1.3
+++ conga/ricci/modules/storage/PartitionTable.cpp 2006/08/24 14:51:44 1.4
@@ -41,9 +41,9 @@
// check if a partition table is on the path
list<String> ids;
- for (list<String>::iterator iter = hds.begin();
+ for (list<String>::const_iterator iter = hds.begin();
iter != hds.end();
- iter ++) {
+ iter++) {
try {
Parted::partitions(*iter);
ids.push_back(PT_PREFIX + *iter);
--- conga/ricci/modules/storage/parted_wrapper.cpp 2006/08/10 22:53:09 1.6
+++ conga/ricci/modules/storage/parted_wrapper.cpp 2006/08/24 14:51:44 1.7
@@ -39,6 +39,8 @@
list<PartedPartition>& parts,
long long begin,
long long end);
+static String
+__probe_pt_execute(const String& pt_path);
static list<PartedPartition>
plain_partitions(const String& path,
String& label,
@@ -235,18 +237,11 @@
-
-list<PartedPartition>
-plain_partitions(const String& path,
- String& label,
- long long& disk_size)
+String
+__probe_pt_execute(const String& pt_path)
{
- list<PartedPartition> parts;
- label = "";
- disk_size = 0;
-
vector<String> args;
- args.push_back(path);
+ args.push_back(pt_path);
args.push_back("print");
args.push_back("-s");
String out, err;
@@ -254,28 +249,57 @@
if (utils::execute(PARTED_BIN_PATH, args, out, err, status))
throw String("execute failed");
if (status)
- throw String("parted failed") + " " + path;
+ throw String("parted failed") + " " + pt_path;
+ return out;
+}
+
+list<PartedPartition>
+plain_partitions(const String& path,
+ String& label,
+ long long& disk_size)
+{
+ list<PartedPartition> parts;
+ label = "";
+ disk_size = 0;
- vector<String> lines = utils::split(utils::strip(out), "\n");
- for (vector<String>::iterator iter = lines.begin();
+ String parted_output = utils::strip(__probe_pt_execute(path));
+ vector<String> lines = utils::split(parted_output, "\n");
+ for (vector<String>::const_iterator iter = lines.begin();
iter != lines.end();
iter++) {
vector<String> words = utils::split(utils::strip(*iter));
if (words.size() < 3)
continue;
- if (words[0] == "Disk" && words[1] == "label" && words[2] == "type:") {
- label = words[3];
+
+ // label
+ if ((words[0] == "Disk" && words[1] == "label" && words[2] == "type:") ||
+ (words[0] == "Partition" && words[1] == "Table:")) {
+ label = words.back();
continue;
}
- if (words[0] == "Disk" && words[1] == "geometry" && words[5] == "megabytes") {
- String size = words[4];
- String::size_type idx = size.find("-");
- if (idx != size.npos) {
- size = size.substr(idx + 1);
- disk_size = utils::to_long(size) * 1024 * 1024;
- }
+
+ // disk size
+ if (words[0] == "Disk" && words[1] == (path + ":")) {
+ disk_size = parted_size_to_bytes(words[2]);
continue;
}
+ if (words.size() > 4) {
+ if (words[0] == "Disk" &&
+ words[1] == "geometry" &&
+ words[2] == "for" &&
+ words[3] == (path + ":")) {
+ String s = words[4];
+ String::size_type idx = s.find("-");
+ if (idx != s.npos)
+ s = s.substr(idx + 1);
+ else
+ s = words.back();
+ disk_size = parted_size_to_bytes(s);
+ continue;
+ }
+ }
+
+ // partition
if (!isdigit(words[0][0]))
continue;
int partnum = utils::to_long(words[0]);
@@ -283,7 +307,7 @@
long long end = parted_size_to_bytes(words[2]);
bool bootable = false;
PPType type = PPTprimary;
- for (vector<String>::iterator word_iter = words.begin();
+ for (vector<String>::const_iterator word_iter = words.begin();
word_iter != words.end();
word_iter++) {
if (*word_iter == "boot")
@@ -305,6 +329,8 @@
if (label.empty() || label == "loop")
throw String("not a partition table");
+ if (disk_size == 0)
+ throw String("disk_size == 0???");
return parts;
}
@@ -457,7 +483,7 @@
if (status)
throw String("blockdev failed");
vector<String> lines = utils::split(out, "\n");
- for (vector<String>::iterator iter = lines.begin();
+ for (vector<String>::const_iterator iter = lines.begin();
iter != lines.end();
iter++) {
vector<String> words = utils::split(utils::strip(*iter));
@@ -519,7 +545,7 @@
// don't overwrite existing label
bool in_use = false;
try {
- partitions(path);
+ __probe_pt_execute(path); // throws if empty (no PT or known FS)
in_use = true;
} catch ( ... ) {}
if (in_use)
@@ -638,7 +664,7 @@
String s = utils::to_lower(utils::strip(size_str));
long long multiplier;
if (s.find("b") == s.npos)
- multiplier = 1024 * 1024; // by old parted behavior. size is in MB
+ multiplier = 1024 * 1024; // by old parted behavior, size is in MB
else {
if (s.size() < 3)
throw String("parted size has an invalid value: ") + s;
More information about the Cluster-devel
mailing list