* [Cluster-devel] conga/ricci/modules/storage PartitionTable.cpp ...
@ 2006-08-24 14:51 kupcevic
0 siblings, 0 replies; 2+ messages in thread
From: kupcevic @ 2006-08-24 14:51 UTC (permalink / raw)
To: cluster-devel.redhat.com
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;
^ permalink raw reply [flat|nested] 2+ messages in thread* [Cluster-devel] conga/ricci/modules/storage PartitionTable.cpp ...
@ 2006-10-16 15:32 kupcevic
0 siblings, 0 replies; 2+ messages in thread
From: kupcevic @ 2006-10-16 15:32 UTC (permalink / raw)
To: cluster-devel.redhat.com
CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2006-10-16 15:32:25
Modified files:
ricci/modules/storage: PartitionTable.cpp VG.cpp
Log message:
storage module: add "size" property to Volume Groups and Partition Tables
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/PartitionTable.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/VG.cpp.diff?cvsroot=cluster&r1=1.7&r2=1.8
--- conga/ricci/modules/storage/PartitionTable.cpp 2006/08/24 14:51:44 1.4
+++ conga/ricci/modules/storage/PartitionTable.cpp 2006/10/16 15:32:25 1.5
@@ -106,7 +106,9 @@
_label) != supp_labels.end());
// sources
- sources.push_back(BDFactory::get_bd(_pt_path));
+ counting_auto_ptr<BD> source = BDFactory::get_bd(_pt_path);
+ _props.set(Variable("size", source->_props.get("size").get_int()));
+ sources.push_back(source);
// targets
generate_targets(_pt_path, parts, targets);
--- conga/ricci/modules/storage/VG.cpp 2006/10/06 03:10:13 1.7
+++ conga/ricci/modules/storage/VG.cpp 2006/10/16 15:32:25 1.8
@@ -99,6 +99,10 @@
}
}
} else {
+ long long size =
+ _props.get("extents_total").get_int() * _props.get("extent_size").get_int();
+ _props.set(Variable("size", size));
+
bool rem = true;
for (list<counting_auto_ptr<BD> >::const_iterator iter = targets.begin();
iter != targets.end();
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-10-16 15:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-24 14:51 [Cluster-devel] conga/ricci/modules/storage PartitionTable.cpp kupcevic
-- strict thread matches above, loose matches on Subject: below --
2006-10-16 15:32 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).