From: braam Date: Thu, 23 Dec 1999 02:31:35 +0000 (+0000) Subject: Fixes to shell scripts to check for errors and other improvements X-Git-Tag: v1_7_100~6154 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=bbb126f8d22cff6180bf362487cc373facdb9274;ds=sidebyside Fixes to shell scripts to check for errors and other improvements Added a fully featured snaprestore to obdcontrol Fix refcount for class driver. --- diff --git a/lustre/demos/baseclean.sh b/lustre/demos/baseclean.sh index 846dfd8..5ac231b 100755 --- a/lustre/demos/baseclean.sh +++ b/lustre/demos/baseclean.sh @@ -1,9 +1,33 @@ #!/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 diff --git a/lustre/demos/basesetup.sh b/lustre/demos/basesetup.sh index 8874372..7cecc93 100755 --- a/lustre/demos/basesetup.sh +++ b/lustre/demos/basesetup.sh @@ -1,36 +1,47 @@ #! /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 diff --git a/lustre/demos/config.sh b/lustre/demos/config.sh index 825c1d6..713a199 100644 --- a/lustre/demos/config.sh +++ b/lustre/demos/config.sh @@ -36,7 +36,7 @@ plog () { 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 } diff --git a/lustre/demos/obdclean.sh b/lustre/demos/obdfsclean.sh similarity index 88% rename from lustre/demos/obdclean.sh rename to lustre/demos/obdfsclean.sh index 6f84731..aad02f5 100755 --- a/lustre/demos/obdclean.sh +++ b/lustre/demos/obdfsclean.sh @@ -1,7 +1,7 @@ #!/bin/sh # Utility script for cleaning up a simple OBDFS mounted filesystem OBDDIR="`dirname $0`/.." -[ "$OBDDIR" = "" ] && OBDDIR=".." + . $OBDDIR/demos/config.sh umount $MNTOBD diff --git a/lustre/demos/obdfssetup.sh b/lustre/demos/obdfssetup.sh new file mode 100755 index 0000000..543ae5a --- /dev/null +++ b/lustre/demos/obdfssetup.sh @@ -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 index cc69f1a..0000000 --- a/lustre/demos/obdsetup.sh +++ /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 diff --git a/lustre/demos/obdtest.sh b/lustre/demos/obdtest.sh index f4ea42e..34f86d1 100755 --- a/lustre/demos/obdtest.sh +++ b/lustre/demos/obdtest.sh @@ -6,9 +6,9 @@ OBDDIR="`dirname $0`/.." [ "$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 diff --git a/lustre/demos/snap3set.sh b/lustre/demos/snap3set.sh index d739ff7..517101e 100755 --- a/lustre/demos/snap3set.sh +++ b/lustre/demos/snap3set.sh @@ -28,4 +28,4 @@ quit 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 diff --git a/lustre/demos/snapclean.sh b/lustre/demos/snapclean.sh index ce483f0..10d08f8 100755 --- a/lustre/demos/snapclean.sh +++ b/lustre/demos/snapclean.sh @@ -20,4 +20,4 @@ EOF rmmod obdsnap -$OBDDIR/demos/obdclean.sh +$OBDDIR/demos/obdfsclean.sh diff --git a/lustre/demos/snapdel.sh b/lustre/demos/snapdel.sh index 6c141b0..d6fece3 100755 --- a/lustre/demos/snapdel.sh +++ b/lustre/demos/snapdel.sh @@ -30,4 +30,4 @@ y 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 diff --git a/lustre/demos/snaprest.sh b/lustre/demos/snaprest.sh index 7175389..23d0080 100755 --- a/lustre/demos/snaprest.sh +++ b/lustre/demos/snaprest.sh @@ -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`/.." -[ "$OBDDIR" = "" ] && OBDDIR=".." +[ "$OBDDIR" = "./.." ] && OBDDIR=".." . $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 +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 diff --git a/lustre/demos/snaprestclean.sh b/lustre/demos/snaprestclean.sh new file mode 100755 index 0000000..70a343e --- /dev/null +++ b/lustre/demos/snaprestclean.sh @@ -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 diff --git a/lustre/demos/snapsetup.sh b/lustre/demos/snapsetup.sh index 862b271..f7ef4df 100755 --- a/lustre/demos/snapsetup.sh +++ b/lustre/demos/snapsetup.sh @@ -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`/.." -[ "$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 @@ -37,17 +58,16 @@ y 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 diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index f597be7..bb97aa5 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -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++; - 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; @@ -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--; - 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; diff --git a/lustre/obdclass/obdcontrol b/lustre/obdclass/obdcontrol index 8b1ddaa..68648d2 100755 --- a/lustre/obdclass/obdcontrol +++ b/lustre/obdclass/obdcontrol @@ -103,7 +103,7 @@ my $arg; my %commands = ('device' => {func => "Device", doc => "device : 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 : set the table (created with snaptable) as table #tableno" }, @@ -261,7 +261,7 @@ sub Attach { 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; } @@ -281,12 +281,7 @@ usage: $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; @@ -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 { + 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); @@ -414,13 +445,33 @@ sub SnapRestore { 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; @@ -672,14 +723,19 @@ sub Partition { 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; diff --git a/lustre/obdfs/namei.c b/lustre/obdfs/namei.c index 6630079..031910b 100644 --- a/lustre/obdfs/namei.c +++ b/lustre/obdfs/namei.c @@ -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; - 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)) { @@ -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) { - 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);