[sheepdog] [PATCH] Convert config file - the free disk space is now stored in the config file

Jens Weber jweber at tek2b.org
Sun Aug 5 21:46:53 CEST 2012


To use this new feature (commit 5e39f98abf32faa340afc9b535a56391359b5234) do as follow

  - first shutdown cluster
  - convert all config files with 'vnodes2autoconfig /path/to/store/config'
  - update to new version and start cluster again

Signed-off-by: Jens Weber <jweber at tek2b.org>
---
 script/vnodes2autoconfig |   90 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)
 create mode 100755 script/vnodes2autoconfig

diff --git a/script/vnodes2autoconfig b/script/vnodes2autoconfig
new file mode 100755
index 0000000..55aa5d2
--- /dev/null
+++ b/script/vnodes2autoconfig
@@ -0,0 +1,90 @@
+#!/usr/bin/perl -w
+#
+# Copyright:
+#
+#    Copyright (C) 2012 Jens Weber <jweber at tek2b.org>
+#
+# License:
+#
+#    This program is free software; you can redistribute it and/or modify it
+#    under the terms of the GNU General Public License version 2 as published by
+#    the Free Software Foundation.
+
+use strict;
+
+my $config;
+my $buf;
+
+my $ctime;	# unit64
+my $space;	# unit64
+my $flags;	# uint16
+my $copies;	# unit8
+my $store;	# unit8[STORE_LEN]
+
+my $configfile;
+my $storedir;
+my $convert=0;
+
+if(!$ARGV[0]) {
+  print("Usage: vnodes2autoconfig /path/to/store/config\n");
+  exit 1;
+}
+
+while(my $ARGV = shift @ARGV) {
+  $configfile=$ARGV."/config";
+  $storedir=$ARGV;
+}
+
+open($config,"<",$configfile) or die "can't open config: $!";
+binmode($config);
+
+read($config,$buf,8);
+$ctime=unpack("Q",$buf);
+read($config,$buf,2);
+$flags=unpack("S",$buf);
+read($config,$buf,1);
+$copies=unpack("C",$buf);
+while(read($config,$buf,1)) {
+  $store=$store.$buf;
+}
+
+close($config);
+
+if (!($store =~ /^farm/)) {
+  print("already new style, nothing to do.\n");
+  exit 1;
+}
+
+print($configfile);
+print("\n\n");
+
+# calculate free space
+my @df=qx(df -BM $storedir);
+my $size_now=0;
+while(my $line = shift @df) {
+  $size_now=$1 if ($line =~ /[0-9]+M\s+[0-9]+M\s+([0-9]+)M/);
+}
+my @du=qx(du -BM -s $storedir);
+my $size_use=0;
+while(my $line = shift @du) {
+  $size_use=$1 if ($line =~ /^([0-9]+)M/);
+}
+$space=$size_now + $size_use;
+
+printf("CTime:  %016x\n",$ctime);
+printf("Space:  %i\n",$space);
+printf("Flags:  %016b\n",$flags);
+printf("Copies: %i\n",$copies);
+printf("Store:  %s\n\n",$store);
+
+open($config,">",$configfile);
+
+print($config pack("Q",$ctime));
+print($config pack("Q",$space));
+print($config pack("S",$flags));
+print($config pack("C",$copies));
+print($config $store);
+
+close($config);
+
+print("convert done.\n");
-- 
1.7.10.4



More information about the sheepdog mailing list