Whamcloud - gitweb
Fixes to shell scripts to check for errors and other improvements
authorbraam <braam>
Thu, 23 Dec 1999 02:31:35 +0000 (02:31 +0000)
committerbraam <braam>
Thu, 23 Dec 1999 02:31:35 +0000 (02:31 +0000)
Added  a fully featured snaprestore to obdcontrol
Fix refcount for class driver.

16 files changed:
lustre/demos/baseclean.sh
lustre/demos/basesetup.sh
lustre/demos/config.sh
lustre/demos/obdfsclean.sh [moved from lustre/demos/obdclean.sh with 88% similarity]
lustre/demos/obdfssetup.sh [new file with mode: 0755]
lustre/demos/obdsetup.sh [deleted file]
lustre/demos/obdtest.sh
lustre/demos/snap3set.sh
lustre/demos/snapclean.sh
lustre/demos/snapdel.sh
lustre/demos/snaprest.sh
lustre/demos/snaprestclean.sh [new file with mode: 0755]
lustre/demos/snapsetup.sh
lustre/obdclass/class_obd.c
lustre/obdclass/obdcontrol
lustre/obdfs/namei.c

index 846dfd8..5ac231b 100755 (executable)
@@ -1,9 +1,33 @@
 #!/bin/sh
 # Script to remove the loopback device and temp file created in newtest.sh
 OBDDIR="`dirname $0`/.."
 #!/bin/sh
 # Script to remove the loopback device and temp file created in newtest.sh
 OBDDIR="`dirname $0`/.."
-[ "$OBDDIR" = "" ] && OBDDIR=".."
+
+[ "$OBDDIR" = "./.." ] && OBDDIR=".."
+
 . $OBDDIR/demos/config.sh
 
 . $OBDDIR/demos/config.sh
 
+
+mount | grep $MNTOBD > /dev/null 2>&1
+if [ x$? = x0 ]; then 
+    echo "Stuff still mounted on $MNTOBD"
+    exit 
+fi
+
+mount | grep $MNTSNAP > /dev/null 2>&1
+if [ x$? = x0 ]; then 
+    echo "Stuff still mounted on $MNTSNAP"
+    exit 
+fi
+
+mount | grep $MNTSNAP > /dev/null 2>&1
+if [ x$? = x0 ]; then 
+    echo "Stuff still mounted on $MNTSNAP2"
+    exit 
+fi
+
+
 [ "$LOOPDEV" ] && losetup -d $LOOPDEV
 [ "$LOOPDEV" ] && losetup -d $LOOPDEV
-#[ "$TMPFILE" ] && rm $TMPFILE
+rmmod loop > /dev/null 2>&1
+
+# [ "$TMPFILE" -a -f "$TMPFILE" ] && rm $TMPFILE
 
 
index 8874372..7cecc93 100755 (executable)
@@ -1,36 +1,47 @@
 #! /bin/sh
 # Get the locations for the files from a single place to avoid confusion
 OBDDIR="`dirname $0`/.."
 #! /bin/sh
 # Get the locations for the files from a single place to avoid confusion
 OBDDIR="`dirname $0`/.."
-[ "$OBDDIR" = "" ] && OBDDIR=".."
+[ "$OBDDIR" = "./.." ] && OBDDIR=".."
+
+# source config info
 . $OBDDIR/demos/config.sh
 
 . $OBDDIR/demos/config.sh
 
-#if [ "$TMPFILE" -a -f $TMPFILE ]; then 
-#    echo "$TMPFILE exists; I'm unwilling to overwrite it." 1>&2
-#    exit 1
-#fi
+[ ! -d $MNTOBD ] &&  mkdir $MNTOBD
+[ ! -d $MNTSNAP ] &&  mkdir $MNTSNAP
+[ ! -d $MNTSNAP2 ] &&  mkdir $MNTSNAP2
+
+
+# temp file
+if [ "$TMPFILE" -a -f $TMPFILE ]; then 
+    echo "$TMPFILE exists; I'm unwilling to overwrite it." 1>&2
+    exit 1
+fi
+[ "$TMPFILE" ] && dd if=/dev/zero of=$TMPFILE bs=1k count=10k
 
 
-# We assume the loop module will be installed by kerneld if required.
-# If not, the following line should be uncommented.
-#insmod loop
 
 
+# loop device
+insmod loop > /dev/null 2>&1
 if [ "$LOOPDEV" -a "`losetup $LOOPDEV 2> /dev/null`" ]; then
     echo "It appears that $LOOPDEV is in use.  Unable to continue" 1>&2
     echo "You need to clean up $LOOPDEV (via cleanup.sh),"
     echo "or you can change which device is used in demos/config.sh" 1>&2
 if [ "$LOOPDEV" -a "`losetup $LOOPDEV 2> /dev/null`" ]; then
     echo "It appears that $LOOPDEV is in use.  Unable to continue" 1>&2
     echo "You need to clean up $LOOPDEV (via cleanup.sh),"
     echo "or you can change which device is used in demos/config.sh" 1>&2
+    # undo previous
+    rm $TMPFILE
     exit 2
 fi
 
     exit 2
 fi
 
+[ "$LOOPDEV" ] && losetup $LOOPDEV $TMPFILE
 # Ensure that we have the correct devices for OBD to work
 [ ! -c /dev/obd0 ] && mknod /dev/obd0 c $OBDMAJ 0
 [ ! -c /dev/obd1 ] && mknod /dev/obd1 c $OBDMAJ 1
 [ ! -c /dev/obd2 ] && mknod /dev/obd2 c $OBDMAJ 2
 
 # Ensure that we have the correct devices for OBD to work
 [ ! -c /dev/obd0 ] && mknod /dev/obd0 c $OBDMAJ 0
 [ ! -c /dev/obd1 ] && mknod /dev/obd1 c $OBDMAJ 1
 [ ! -c /dev/obd2 ] && mknod /dev/obd2 c $OBDMAJ 2
 
-[ "$TMPFILE" ] && dd if=/dev/zero of=$TMPFILE bs=1k count=10k
 
 
-[ "$LOOPDEV" ] && losetup $LOOPDEV $TMPFILE
 if [ "$BASEDEV" ]; then
     mke2fs -b 4096 $BASEDEV
 else
     echo "\$BASEDEV not defined in demos/config.sh.  Please fix!"
 if [ "$BASEDEV" ]; then
     mke2fs -b 4096 $BASEDEV
 else
     echo "\$BASEDEV not defined in demos/config.sh.  Please fix!"
-    exit 1
+    [ "$LOOPDEV" ] && losetup -d $LOOPDEV 
+    rm $TMPFILE
+    exit 3
 fi
 fi
index 825c1d6..713a199 100644 (file)
@@ -36,7 +36,7 @@ plog () {
        echo "****start**** $* *****" >> /var/log/messages
        echo "$*"
        $*
        echo "****start**** $* *****" >> /var/log/messages
        echo "$*"
        $*
-       sleep 3 # to allow messages to be flushed
+       sleep 3 # to allow messages to be flushed
        echo "*****end***** $* *****" >> /var/log/messages
     fi
 }
        echo "*****end***** $* *****" >> /var/log/messages
     fi
 }
similarity index 88%
rename from lustre/demos/obdclean.sh
rename to lustre/demos/obdfsclean.sh
index 6f84731..aad02f5 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Utility script for cleaning up a simple OBDFS mounted filesystem
 OBDDIR="`dirname $0`/.."
 #!/bin/sh
 # Utility script for cleaning up a simple OBDFS mounted filesystem
 OBDDIR="`dirname $0`/.."
-[ "$OBDDIR" = "" ] && OBDDIR=".."
+
 . $OBDDIR/demos/config.sh
 
 umount $MNTOBD
 . $OBDDIR/demos/config.sh
 
 umount $MNTOBD
diff --git a/lustre/demos/obdfssetup.sh b/lustre/demos/obdfssetup.sh
new file mode 100755 (executable)
index 0000000..543ae5a
--- /dev/null
@@ -0,0 +1,27 @@
+#! /bin/bash
+# Utility script for configuring a simple OBDFS mount
+
+OBDDIR="`dirname $0`/.."
+[ "$OBDDIR" = "./.." ] && OBDDIR=".."
+
+.  $OBDDIR/demos/config.sh
+
+$OBDDIR/demos/basesetup.sh
+
+if [ x$? != x0 ]; then 
+    echo "Errors in basesetup"
+    exit 4;
+fi
+
+insmod $OBDDIR/class/obdclass.o
+insmod $OBDDIR/ext2obd/obdext2.o
+insmod $OBDDIR/obdfs/obdfs.o
+
+plog log "ATTACHING /dev/obd0"
+$OBDDIR/class/obdcontrol -f << EOF
+attach ext2_obd 
+setup $BASEDEV
+quit
+EOF
+
+plog mount -t obdfs -odevice=/dev/obd0 none $MNTOBD
diff --git a/lustre/demos/obdsetup.sh b/lustre/demos/obdsetup.sh
deleted file mode 100755 (executable)
index cc69f1a..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#! /bin/bash
-# Utility script for configuring a simple OBDFS mount
-
-OBDDIR="`dirname $0`/.."
-[ "$OBDDIR" = "" ] && OBDDIR=".."
-. $OBDDIR/demos/basesetup.sh
-
-insmod $OBDDIR/class/obdclass.o
-insmod $OBDDIR/ext2obd/obdext2.o
-insmod $OBDDIR/obdfs/obdfs.o
-
-plog log "CREATING /dev/obd0"
-$OBDDIR/class/obdcontrol -f << EOF
-attach ext2_obd $BASEDEV
-setup
-quit
-EOF
-[ ! -d $MNTOBD ] && mkdir $MNTOBD
-plog mount -t obdfs -odevice=/dev/obd0 /dev/obd0 $MNTOBD
index f4ea42e..34f86d1 100755 (executable)
@@ -6,9 +6,9 @@ OBDDIR="`dirname $0`/.."
 [ "$OBDDIR" = "" ] && OBDDIR=".."
 . $OBDDIR/demos/config.sh
 
 [ "$OBDDIR" = "" ] && OBDDIR=".."
 . $OBDDIR/demos/config.sh
 
-[ ! -d $MNTOBD/lost+found ] && $OBDDIR/demos/obdsetup.sh
+[ ! -d $MNTOBD/lost+found ] && $OBDDIR/demos/obdfssetup.sh
 
 echo "yesterday" > $MNTOBD/hello       # create a file
 echo "testing" > $MNTOBD/goodbye       # create a file
 
 echo "yesterday" > $MNTOBD/hello       # create a file
 echo "testing" > $MNTOBD/goodbye       # create a file
-ln -s hello $MNTOBD/link               # create a link
+ln -s hello $MNTOBD/link               # create a symbolic link
 cd $MNTOBD ; touch a b c ; cd -                # create a file
 cd $MNTOBD ; touch a b c ; cd -                # create a file
index d739ff7..517101e 100755 (executable)
@@ -28,4 +28,4 @@ quit
 EOF
 
 [ ! -d "$MNTSNAP2" ] && mkdir $MNTSNAP2
 EOF
 
 [ ! -d "$MNTSNAP2" ] && mkdir $MNTSNAP2
-plog mount -t obdfs -oro,device=/dev/obd3 /dev/obd3 $MNTSNAP2
+plog mount -t obdfs -oro,device=/dev/obd3 none $MNTSNAP2
index ce483f0..10d08f8 100755 (executable)
@@ -20,4 +20,4 @@ EOF
 
 rmmod obdsnap
 
 
 rmmod obdsnap
 
-$OBDDIR/demos/obdclean.sh
+$OBDDIR/demos/obdfsclean.sh
index 6c141b0..d6fece3 100755 (executable)
@@ -30,4 +30,4 @@ y
 snapset 0 $SNAPTABLE
 EOF
 plog log "COMPLETE snapdelete"
 snapset 0 $SNAPTABLE
 EOF
 plog log "COMPLETE snapdelete"
-plog mount -t obdfs -odevice=/dev/obd1 /dev/obd1 $MNTOBD
+plog mount -t obdfs -odevice=/dev/obd1 none $MNTOBD
index 7175389..23d0080 100755 (executable)
@@ -2,7 +2,7 @@
 # Utility script to test restoring a previous snapshot.  This will destroy
 # the "current" snapshot and restore the old one in its place.
 OBDDIR="`dirname $0`/.."
 # Utility script to test restoring a previous snapshot.  This will destroy
 # the "current" snapshot and restore the old one in its place.
 OBDDIR="`dirname $0`/.."
-[ "$OBDDIR" = "" ] && OBDDIR=".."
+[ "$OBDDIR" = "./.." ] && OBDDIR=".."
 . $OBDDIR/demos/config.sh
 
 [ ! -d $MNTSNAP/lost+found ] && echo "need to run snapsetup.sh first" && exit 1
 . $OBDDIR/demos/config.sh
 
 [ ! -d $MNTSNAP/lost+found ] && echo "need to run snapsetup.sh first" && exit 1
@@ -10,32 +10,31 @@ OBDDIR="`dirname $0`/.."
 plog umount $MNTSNAP
 plog umount $MNTOBD
 
 plog umount $MNTSNAP
 plog umount $MNTOBD
 
+mount | grep $MNTOBD > /dev/null 2>&1
+if [ x$? = x0 ]; then 
+    echo "Stuff still mounted on $MNTOBD; clean up first."
+    exit 
+fi
+
+mount | grep $MNTSNAP > /dev/null 2>&1
+if [ x$? = x0 ]; then 
+    echo "Stuff still mounted on $MNTSNAP; clean up first."
+    exit 
+fi
+
 sync
 sync
-sleep 1
 plog log "STARTING snaprestore"
 plog log "STARTING snaprestore"
-# To do a snapshot restore at this time, we need to do several steps.  In
-# the future, this should all be wrapped into the snaprestore function.
-# - we reverse the current and restored entries in the snapshot table
-# - we proceed to delete the previous current snapshot
-# - we unconfigure the previous current snapshot
-# - we delete the previous current snapshot from the table and load it
+
+
 $OBDDIR/class/obdcontrol -f << EOF
 $OBDDIR/class/obdcontrol -f << EOF
-XXX need to reverse current/restored entries here!!!
-snapset 0 $SNAPTABLE
-device /dev/obd2
-connect
-snaprestore 1
 device /dev/obd1
 cleanup
 detach
 device /dev/obd1
 cleanup
 detach
-snaptable
-$SNAPTABLE
-d
-1
-q
-y
-snapset 0 $SNAPTABLE
+device /dev/obd2
+connect
+snaprestore 2 $SNAPTABLE 0
 EOF
 EOF
+
 plog log "COMPLETE snaprestore"
 
 plog log "COMPLETE snaprestore"
 
-plog mount -t obdfs -odevice=/dev/obd2 /dev/obd2 $MNTOBD
+plog mount -t obdfs -odevice=/dev/obd2 none $MNTOBD
diff --git a/lustre/demos/snaprestclean.sh b/lustre/demos/snaprestclean.sh
new file mode 100755 (executable)
index 0000000..70a343e
--- /dev/null
@@ -0,0 +1,30 @@
+#! /bin/bash
+# Utility script for cleaning up a simple OBDFS mounted filesystem
+OBDDIR="`dirname $0`/.."
+
+. $OBDDIR/demos/config.sh
+
+umount $MNTOBD
+mount | grep $MNTOBD > /dev/null 2>&1
+if [ x$? = x0 ]; then 
+    echo "Stuff still mounted on $MNTOBD; clean up first."
+    exit 
+fi
+
+rmmod obdfs
+
+$OBDDIR/class/obdcontrol -f << EOF
+device /dev/obd2
+cleanup
+detach
+device /dev/obd0
+cleanup
+detach
+quit
+EOF
+
+rmmod obdsnap
+rmmod obdext2
+rmmod obdclass
+
+$OBDDIR/demos/baseclean.sh
index 862b271..f7ef4df 100755 (executable)
@@ -3,12 +3,33 @@
 # not already mounted on /mnt/obd, we call the basic OBD setup script to
 # create and mount a filesystem for us.
 OBDDIR="`dirname $0`/.."
 # not already mounted on /mnt/obd, we call the basic OBD setup script to
 # create and mount a filesystem for us.
 OBDDIR="`dirname $0`/.."
-[ "$OBDDIR" = "" ] && OBDDIR=".."
+
 . $OBDDIR/demos/config.sh
 
 . $OBDDIR/demos/config.sh
 
-[ ! -d $MNTOBD/lost+found ] && $OBDDIR/demos/obdsetup.sh
 
 
-[ ! -f $MNTDIR/hello ] && $OBDDIR/demos/obdtest.sh
+# prepare the snapshot drive with a file to be COW'd
+
+mount | grep $MNTOBD > /dev/null 2>&1
+if [ x$? = x0 ]; then 
+    echo "Stuff still mounted on $MNTOBD; clean up first."
+    exit 
+fi
+
+if [ ! -d /mnt/obd/lost+found ]; then 
+    $OBDDIR/demos/obdfssetup.sh
+    if [ x$? != x0 ]; then 
+       echo "Error in obdfssetup.sh"
+       exit 4
+   fi
+fi
+
+if [ ! -f $MNTOBD/hello ]; then
+       $OBDDIR/demos/obdtest.sh
+       if [ x$? != x0 ]; then 
+           echo "Error in obdfssetup.sh"
+       exit 4
+    fi
+fi
 
 umount $MNTOBD
 
 
 umount $MNTOBD
 
@@ -37,17 +58,16 @@ y
 snapset 0 $SNAPTABLE
 device /dev/obd1
 attach snap_obd 0 1 0
 snapset 0 $SNAPTABLE
 device /dev/obd1
 attach snap_obd 0 1 0
-setup snap_obd
+setup
 device /dev/obd2
 attach snap_obd 0 2 0
 device /dev/obd2
 attach snap_obd 0 2 0
-setup snap_obd
+setup
 quit
 EOF
 
 # Mount the two filesystems.  The filesystem under $MNTOBD will be the
 # one where changes are made, while $MNTSNAP will contain the original
 # files at the point when the snapshot was taken.
 quit
 EOF
 
 # Mount the two filesystems.  The filesystem under $MNTOBD will be the
 # one where changes are made, while $MNTSNAP will contain the original
 # files at the point when the snapshot was taken.
-[ ! -d $MNTOBD ] && mkdir $MNTOBD
-plog mount -t obdfs -odevice=/dev/obd1 /dev/obd1 $MNTOBD
-[ ! -d $MNTSNAP ] && mkdir $MNTSNAP
-plog mount -t obdfs -oro,device=/dev/obd2 /dev/obd2 $MNTSNAP
+
+plog mount -t obdfs -odevice=/dev/obd1 none $MNTOBD
+plog mount -t obdfs -oro,device=/dev/obd2 none $MNTSNAP
index f597be7..bb97aa5 100644 (file)
@@ -74,7 +74,7 @@ static int obd_class_open(struct inode * inode, struct file * file)
        if (dev >= MAX_OBD_DEVICES)
                return -ENODEV;
        obd_dev[dev].obd_refcnt++;
        if (dev >= MAX_OBD_DEVICES)
                return -ENODEV;
        obd_dev[dev].obd_refcnt++;
-       CDEBUG(D_PSDEV, "Refcount now %d\n", obd_dev[dev].obd_refcnt++);
+       CDEBUG(D_PSDEV, "Refcount now %d\n", obd_dev[dev].obd_refcnt);
 
         MOD_INC_USE_COUNT;
         EXIT;
 
         MOD_INC_USE_COUNT;
         EXIT;
@@ -98,8 +98,7 @@ static int obd_class_release(struct inode * inode, struct file * file)
                       obd_dev[dev].obd_refcnt);
        obd_dev[dev].obd_refcnt--;
 
                       obd_dev[dev].obd_refcnt);
        obd_dev[dev].obd_refcnt--;
 
-       CDEBUG(D_PSDEV, "Refcount now %d\n", obd_dev[dev].obd_refcnt++);
-
+       CDEBUG(D_PSDEV, "Refcount now %d\n", obd_dev[dev].obd_refcnt);
         MOD_DEC_USE_COUNT;
 
         EXIT;
         MOD_DEC_USE_COUNT;
 
         EXIT;
index 8b1ddaa..68648d2 100755 (executable)
@@ -103,7 +103,7 @@ my $arg;
 my %commands =
     ('device' => {func => "Device", doc => "device <dev>: open another OBD device"},
      'create' => {func => "Create", doc => "create: creates a new inode"},
 my %commands =
     ('device' => {func => "Device", doc => "device <dev>: open another OBD device"},
      'create' => {func => "Create", doc => "create: creates a new inode"},
-     'attach' => {func => "Attach", doc => "attach {ext2_obd | snap_obd snapdev snapidx tableno | scsi_obd adapter bus tid lun}"}, #
+     'attach' => {func => "Attach", doc => "attach { ext2_obd | snap_obd snapdev snapidx tableno | scsi_obd adapter bus tid lun" },
      'detach' => {func => "Detach", doc => "detach this device"},
      'testext2iterator' => {func => "TestExt2Iterator", doc => "test ext2 iterator function"},
      'snapset' => {func => "SnapSetTable", doc => "snapset <tableno> <file>: set the table (created with snaptable) as table #tableno" },
      'detach' => {func => "Detach", doc => "detach this device"},
      'testext2iterator' => {func => "TestExt2Iterator", doc => "test ext2 iterator function"},
      'snapset' => {func => "SnapSetTable", doc => "snapset <tableno> <file>: set the table (created with snaptable) as table #tableno" },
@@ -261,7 +261,7 @@ sub Attach {
     if ( ! $type ) {
        print "error: missing type\n";
 usage:
     if ( ! $type ) {
        print "error: missing type\n";
 usage:
-       print "usage: attach {ext2_obd | snap_obd}\n"; # XXX add scsi_obd later
+       print "usage: attach {ext2_obd | snap_obd | scsi_obd}\n";
        return;
     }
 
        return;
     }
 
@@ -281,12 +281,7 @@ usage:
        $data = pack("iii", $snapdev, $snapidx, $tableno);
        $datalen = 3 * 4;
     } elsif ($type eq "ext2_obd") {
        $data = pack("iii", $snapdev, $snapidx, $tableno);
        $datalen = 3 * 4;
     } elsif ($type eq "ext2_obd") {
-       my $basedev = shift;
-       # $basedev = "/dev/loop0" unless $basedev;
-
-       if (!defined($::st = stat($basedev))) {
-           die "Unable to stat $basedev.\n";
-       }
+       1;
     } else {
        print "error: unknown attach type $type\n";
        goto usage;
     } else {
        print "error: unknown attach type $type\n";
        goto usage;
@@ -386,27 +381,63 @@ sub SnapDelete {
 }
 
 
 }
 
 
-# XXX the parameter to snaprestore SHOULD be the snapshot number of the
-#     snapshot to be restored, and this routine should handle all of the
-#     removal of intervening snapshots and changing the snaptable to have
-#     the "restored" snapshot as current and move the previous current.
+#      this routine does the whole job
 sub SnapRestore { 
 sub SnapRestore { 
+    my $restoreto = shift;
+    my $snaptable = shift;
+    my $tableno = shift;
+    my $key;
+
+    # don't do anything until connected
     if (!defined($::client_id)) {
        print "You must first ``connect''.\n";
        return;
     }
 
     if (!defined($::client_id)) {
        print "You must first ``connect''.\n";
        return;
     }
 
+    if ( ! $snaptable || ! defined $restoreto ) {
+       print "Usage: snaprestore \"restore to slot\" \"snaptable\" \"tableno\"\n";
+       return;
+    }
+
+    if ( ! -f $snaptable ) {
+       print "Table $snaptable doesn't exist\n";
+       return;
+    }
+   
+    my $table = ReadSnapShotTable($snaptable);
+    $key = FindSnapInTable($table, $restoreto);
+    if ( ! defined $table->{0} || ! defined $key ) {
+       PrintSnapShotTable($table);
+       print "No current or $restoreto slot in this table\n";
+       return;
+    }
+
+    my $currentindex = $table->{0};
+    if (  $table->{$key} == $currentindex ) {
+       print "You should not restore to the current snapshot\n";
+       return;
+    }
+    
+    # swap the entries for 0 and $restoreto
+    my $tmp = $table->{$key};
+    $table->{$key} = $table->{0};
+    $table->{0} = $tmp;
+    PrintSnapShotTable($table);
+
+    # write it back
+    WriteSnapShotTable($snaptable, $table);
+
+    # set it in the kernel
+    SnapSetTable($tableno, $snaptable);
+
+    # ready for the ioctl
     my $err = 0;
     my $type = "snap_obd";
     my $err = 0;
     my $type = "snap_obd";
-    my $prevcurrent = shift;
-    $data = pack("i", $prevcurrent); # where previous current snapshot now lives
+    $data = pack("i", $currentindex); # slot of previous current snapshot 
     $datalen = 4;
 
     my $len = length($type);
     my $cl = length($data);
     $datalen = 4;
 
     my $len = length($type);
     my $cl = length($data);
-    my $add = pack("p", $data);
-    print "type $type (len $len), datalen $datalen ($cl)\n";
     my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
 
     my $rc = ioctl(DEV_OBD, &OBD_SNAP_RESTORE, $packed);
     my $packed = pack("Lipip", $::client_id, length($type), $type, $datalen, $data);
 
     my $rc = ioctl(DEV_OBD, &OBD_SNAP_RESTORE, $packed);
@@ -414,13 +445,33 @@ sub SnapRestore {
     if (!defined $rc) {
        print STDERR "ioctl failed: $!\n";
     } elsif ($rc eq "0 but true") {
     if (!defined $rc) {
        print STDERR "ioctl failed: $!\n";
     } elsif ($rc eq "0 but true") {
-       print "Finished (success)\n";
+       print "Snaprestore finished (success)\n";
+       delete $table->{$restoreto};
+       # write it back
+       WriteSnapShotTable($snaptable, $table);
+       
+       # set it in the kernel
+       SnapSetTable($tableno, $snaptable);
+       PrintSnapShotTable($table);
+
     } else {
        print "ioctl returned error code $rc.\n";
     }
 }
 
     } else {
        print "ioctl returned error code $rc.\n";
     }
 }
 
+sub FindSnapInTable { 
+    my $table = shift;
+    my $snapno =shift;
 
 
+    foreach my $key ( keys %{$table} ) {
+       if ( $table->{$key} == $snapno) { 
+           print "Found key $key for snapno $snapno\n";
+           return $key;
+       }
+    }
+    undef;
+}
+           
 
 sub SnapPrint { 
     my $err = 0;
 
 sub SnapPrint { 
     my $err = 0;
@@ -672,14 +723,19 @@ sub Partition {
 
 sub Setup {
     my $err = 0;
 
 sub Setup {
     my $err = 0;
-    my $type = shift;
+    my $arg = shift;
     my $data;
     my $datalen = 0;
     my $data;
     my $datalen = 0;
-    
-    $type = "ext2_obd" unless $type;
 
 
-    if ( $type eq "ext2_obd" ) {
-       my $dev = shift;
+    # XXX we need a getinfo ioctl to validate parameters 
+    # by type here
+
+    if ($arg  && !defined($::st = stat($arg))) {
+           print "$arg is not a valid device\n";
+           return;
+    }
+    
+    if ( $arg ) {
        $dev = $::st->rdev() unless $dev;
        $data = pack("i", $dev);
        $datalen = 4;
        $dev = $::st->rdev() unless $dev;
        $data = pack("i", $dev);
        $datalen = 4;
index 6630079..031910b 100644 (file)
@@ -107,9 +107,9 @@ static struct page * obdfs_find_entry (struct inode * dir,
                        /* this code is executed quadratically often */
                        /* do minimal checking `by hand' */
                        int de_len;
                        /* this code is executed quadratically often */
                        /* do minimal checking `by hand' */
                        int de_len;
-                       CDEBUG(D_INODE, "Entry %p len %d, page at %#lx - %#lx , offset %lx\n",
+                       /* CDEBUG(D_INODE, "Entry %p len %d, page at %#lx - %#lx , offset %lx\n",
                               de, le16_to_cpu(de->rec_len), page_address(page),
                               de, le16_to_cpu(de->rec_len), page_address(page),
-                              page_address(page) + PAGE_SIZE, offset);
+                              page_address(page) + PAGE_SIZE, offset); */
 
                        if ((char *) de + namelen <= dlimit &&
                            ext2_match (namelen, name, de)) {
 
                        if ((char *) de + namelen <= dlimit &&
                            ext2_match (namelen, name, de)) {
@@ -125,14 +125,13 @@ static struct page * obdfs_find_entry (struct inode * dir,
                        /* prevent looping on a bad block */
                        de_len = le16_to_cpu(de->rec_len);
                        if (de_len <= 0) {
                        /* prevent looping on a bad block */
                        de_len = le16_to_cpu(de->rec_len);
                        if (de_len <= 0) {
-                               CDEBUG(D_INODE, "Bad entry: at %p len %d\n",
-                                      de, de_len);
+                               printk("Bad entry at %p len %d\n", de, de_len);
                                goto failure;
                        }
                        offset += de_len;
                        de = (struct ext2_dir_entry_2 *)
                                ((char *) de + de_len);
                                goto failure;
                        }
                        offset += de_len;
                        de = (struct ext2_dir_entry_2 *)
                                ((char *) de + de_len);
-                       CDEBUG(D_INODE, "Next while %lx\n", offset);
+                       /* CDEBUG(D_INODE, "Next while %lx\n", offset); */
                }
                if ( lock ) 
                        UnlockPage(page);
                }
                if ( lock ) 
                        UnlockPage(page);