All of lore.kernel.org
 help / color / mirror / Atom feed
From: kupcevic@sourceware.org <kupcevic@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/ricci/modules/storage PartitionTable.cpp ...
Date: 24 Aug 2006 14:51:45 -0000	[thread overview]
Message-ID: <20060824145145.15087.qmail@sourceware.org> (raw)

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;



             reply	other threads:[~2006-08-24 14:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-24 14:51 kupcevic [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-10-16 15:32 [Cluster-devel] conga/ricci/modules/storage PartitionTable.cpp kupcevic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060824145145.15087.qmail@sourceware.org \
    --to=kupcevic@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.