#!/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
+
+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
-#[ "$TMPFILE" ] && rm $TMPFILE
+rmmod loop > /dev/null 2>&1
+
+# [ "$TMPFILE" -a -f "$TMPFILE" ] && rm $TMPFILE
#! /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
-#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
+ # undo previous
+ rm $TMPFILE
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
-[ "$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!"
- exit 1
+ [ "$LOOPDEV" ] && losetup -d $LOOPDEV
+ rm $TMPFILE
+ exit 3
fi
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
}
#!/bin/sh
# Utility script for cleaning up a simple OBDFS mounted filesystem
OBDDIR="`dirname $0`/.."
-[ "$OBDDIR" = "" ] && OBDDIR=".."
+
. $OBDDIR/demos/config.sh
umount $MNTOBD
--- /dev/null
+#! /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
+++ /dev/null
-#! /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
[ "$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
-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
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
rmmod obdsnap
-$OBDDIR/demos/obdclean.sh
+$OBDDIR/demos/obdfsclean.sh
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
# 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
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
-sleep 1
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
-XXX need to reverse current/restored entries here!!!
-snapset 0 $SNAPTABLE
-device /dev/obd2
-connect
-snaprestore 1
device /dev/obd1
cleanup
detach
-snaptable
-$SNAPTABLE
-d
-1
-q
-y
-snapset 0 $SNAPTABLE
+device /dev/obd2
+connect
+snaprestore 2 $SNAPTABLE 0
EOF
+
plog log "COMPLETE snaprestore"
-plog mount -t obdfs -odevice=/dev/obd2 /dev/obd2 $MNTOBD
+plog mount -t obdfs -odevice=/dev/obd2 none $MNTOBD
--- /dev/null
+#! /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
# 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
-[ ! -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
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
-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.
-[ ! -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
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;
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;
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" },
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;
}
$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;
}
-# 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 {
+ 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 ( ! $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 $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);
- 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);
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";
}
}
+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 Setup {
my $err = 0;
- my $type = shift;
+ my $arg = shift;
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;
/* 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),
- page_address(page) + PAGE_SIZE, offset);
+ page_address(page) + PAGE_SIZE, offset); */
if ((char *) de + namelen <= dlimit &&
ext2_match (namelen, name, de)) {
/* 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);
- CDEBUG(D_INODE, "Next while %lx\n", offset);
+ /* CDEBUG(D_INODE, "Next while %lx\n", offset); */
}
if ( lock )
UnlockPage(page);