Whamcloud - gitweb
Updated snapshot indexes in superblock to not depend on index "0" as being
[fs/lustre-release.git] / lustre / obdclass / obdcontrol
index a399b7e..e866cc6 100755 (executable)
@@ -307,6 +307,11 @@ sub SnapAttach {
 
     $snapcount = keys %{$table};
     print "Snapcount $snapcount\n";
+
+    if ( ! defined $table->{0} ) {
+       print "No current snapshot in table! First make one\n";
+       return ;
+    }
     $data = pack("iii", $snapdev, $snapno, $snapcount);
     $datalen = 3 * 4;
     foreach my $time (sort keys %{$table}) {
@@ -318,7 +323,6 @@ sub SnapAttach {
     my $cl = length($data);
     my $add = pack("p", $data);
     print "type $type (len $len), datalen $datalen ($cl)\n";
-    printf "Addr of data %x\n", $add; 
     my $packed = pack("ipip", length($type), $type, $datalen, $data);
 
     my $rc = ioctl(DEV_OBD, &OBD_IOC_ATTACH, $packed);
@@ -350,11 +354,19 @@ sub SnapShotTable  {
     goto again;
 
   add:
-    my $idx = &readl("enter new index: ");
-    my $time = &readl("enter time (hit RET for \"now\"): ");
+    my $idx = &readl("enter index where you want this snapshot: ");
+    my $time = &readl("enter time or 'now' or 'current': ");
     my $oldtime = SnapFindTimeFromIdx($idx, $table);
-    delete $table->{$oldtime} if defined $oldtime;
-    $time = time unless $time;
+    if (defined $oldtime) {
+       print "This already exists, first clean up\n";
+       goto again;
+    }
+
+    if ( $time  eq 'now' ) {
+       $time = time;
+    } elsif ( $time eq 'current' ) { 
+       $time = 0;
+    }
     $table->{$time} = $idx;
     goto again;
 
@@ -389,6 +401,9 @@ sub PrintSnapShotTable {
     
     foreach  $time ( sort keys %{$table} ) {
        my $stime = localtime($time);
+       if ( ! $time ) { 
+           $stime = "current";
+       }
        printf "Time: %s -- Index %d\n", $stime, $table->{$time};
     }
 }
@@ -404,6 +419,9 @@ sub ReadSnapShotTable {
        $table->{$time} = $index;
     }
     close FH;
+
+    PrintSnapShotTable($table);
+
     return $table;
 }