So, I was playing around with snapshots and trying to come up with a cron
job which would do automatic snapshots of a system, kind of similar to
what you can get with a NetApp.  I wrote the attatched (somewhat ugly)
proof of concept script to manage a /.snapshot directory for all the
mounted filesystems on a box.  Running this in a tight loop caused some
pretty severe problems where the box would tend to panic if i tried to
remove some of the snapshot files.  A whole lot of "rm, panic,
reboot, fsck, wash, rinse, repeat" later I seem to have cleared all
the snapshot files off my system and stabilized it.

My -current snapshot is:

> uname -a
FreeBSD coredump.scriptkiddie.org 5.0-CURRENT FreeBSD 5.0-CURRENT #10: Sun
Jul 28 18:30:39 PDT 2002 
[EMAIL PROTECTED]:/usr/obj/usr/src/sys/COREDUMP  i386

My mounts are:

> mount
/dev/ad0s1a on / (ufs, local, soft-updates)
devfs on /dev (devfs, local)
procfs on /proc (procfs, local)

And my dmesg is attatched.

Incidentally, it might be good to have mount report that a filesystem is
a mounted snapshot.  It would make it very easy to grep to select or
remove all the mounted snapshots from the output of mount.

I'm hoping that the rotatesnapshots script is enough to replicate and
identify the bugs.  If not, feel free to contact me and I can try to
replicate them on my system to get more information on the specifics of
the panics...
#!/bin/sh

for fs in `mount -t ufs | egrep -v read-only | awk '{ print $3 }'`; do
        echo "rotating snapshots on $fs"

        # create .snapshot directory if it doesn't exist
        if [ ! -e "$fs/.snapshot" ]; then
                echo "creating .snapshot directory on $fs"
                mkdir "$fs/.snapshot"
        fi

        # get number of snapshot files in .snapshot
        num=`ls $fs/.snapshot | egrep "\.snap" | wc -l`

        # unlink them if there are more than 20
        if [ $num -ge 20 ]; then
                nunlink=$(( $num - 19 ))
                echo "unlinking $nunlink snapshot files"
                for sf in `ls -t $fs/.snapshot | egrep ".snap" | tail -$nunlink`; do
                        snapfile="$fs/.snapshot/$sf"
                        sd=`echo $sf | sed -e s/\.snap/snap/`
                        snapdir="$fs/.snapshot/$sd"
                        md=`mount | egrep $sd | awk '{ print $1 }' | sed -e 
s/.dev.md//'`
                        
                        echo "unmounting $snapdir"
                        umount $snapdir
                        echo "removing $snapdir"
                        rmdir $snapdir
                        echo "removing /dev/md$md"
                        mdconfig -d -u $md
                        echo "deleting $snapfile"
                        rm -f $snapfile
                done
        fi

        # do a snapshot
        date=`date +%Y-%m-%d-%H:%M:%S`
        
        snapfile="$fs/.snapshot/.snap-$date"
        snapdir="$fs/.snapshot/snap-$date"

        echo "mounting snapshot file"
        mount -u -o snapshot $snapfile $fs

        md=0
        while [ -e "/dev/md$md" ]; do
                md=$(($md + 1))
        done

        echo "creating /dev/md$md"

        mdconfig -a -t vnode -f $snapfile -u $md

        echo "creating $snapdir"

        mkdir $snapdir

        echo "mounting $snapdir" 

        mount -r /dev/md$md $snapdir

done


#/.snapshot/.snap-2002-05-04-20:02
#/.snapshot/snap-2002-05-04-20:02

Copyright (c) 1992-2002 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
        The Regents of the University of California. All rights reserved.
FreeBSD 5.0-CURRENT #10: Sun Jul 28 18:30:39 PDT 2002
    [EMAIL PROTECTED]:/usr/obj/usr/src/sys/COREDUMP
Preloaded elf kernel "/boot/kernel/kernel" at 0xc047b000.
Preloaded elf module "/boot/kernel/acpi.ko" at 0xc047b0a8.
Timecounter "i8254"  frequency 1193182 Hz
CPU: AMD Athlon(TM) XP 1600+ (1400.06-MHz 686-class CPU)
  Origin = "AuthenticAMD"  Id = 0x662  Stepping = 2
  
Features=0x383fbff<FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,MMX,FXSR,SSE>

  AMD Features=0xffffffffc0480000<MP,AMIE,DSP,3DNow!>
real memory  = 536788992 (524208K bytes)
avail memory = 515944448 (503852K bytes)
Programming 24 pins in IOAPIC #0
IOAPIC #0 intpin 2 -> irq 0
FreeBSD/SMP: Multiprocessor System Detected: 2 CPUs
 cpu0 (BSP): apic id:  0, version: 0x00040010, at 0xfee00000
 cpu1 (AP):  apic id:  1, version: 0x00040010, at 0xfee00000
 io0 (APIC): apic id:  2, version: 0x00170011, at 0xfec00000
Pentium Pro MTRR support enabled
Using $PIR table, 9 entries at 0xc00f1370
npx0: <math processor> on motherboard
npx0: INT 16 interface
acpi0: <ASUS   A7M266-D> on motherboard
acpi0: power button is handled as a fixed feature programming model.
acpi0: sleep button is handled as a fixed feature programming model.
Timecounter "ACPI-fast"  frequency 3579545 Hz
acpi_timer0: <24-bit timer at 3.579545MHz> port 0xe408-0xe40b on acpi0
acpi_cpu0: <CPU> on acpi0
acpi_cpu1: <CPU> on acpi0
acpi_button0: <Power Button> on acpi0
acpi_pcib0: <Host-PCI bridge> port 0xcf8-0xcff on acpi0
pci0: <PCI bus> on acpi_pcib0
pcib1: <PCI-PCI bridge> at device 1.0 on pci0
pci1: <PCI bus> on pcib1
pci1: <display, VGA> at device 5.0 (no driver attached)
isab0: <PCI-ISA bridge> at device 7.0 on pci0
isa0: <ISA bus> on isab0
atapci0: <AMD 768 ATA100 controller> port 0xd800-0xd80f at device 7.1 on pci0
ata0: at 0x1f0 irq 14 on atapci0
ata1: at 0x170 irq 15 on atapci0
pci0: <bridge, PCI-unknown> at device 7.3 (no driver attached)
ahc0: <Adaptec 3960D Ultra160 SCSI adapter> port 0xd400-0xd4ff mem 
0xed800000-0xed800fff irq 10 at device 9.0 on pci0
aic7899: Ultra160 Wide Channel A, SCSI Id=7, 32/253 SCBs
ahc1: <Adaptec 3960D Ultra160 SCSI adapter> port 0xd000-0xd0ff mem 
0xed000000-0xed000fff irq 5 at device 9.1 on pci0
aic7899: Ultra160 Wide Channel B, SCSI Id=7, 32/253 SCBs
pcib2: <PCI-PCI bridge> at device 16.0 on pci0
pci2: <PCI bus> on pcib2
fxp0: <Intel Pro 10/100B/100+ Ethernet> port 0xb800-0xb83f mem 
0xeb800000-0xeb8fffff,0xec000000-0xec000fff irq 10 at device 6.0 on pci2
fxp0: Ethernet address 00:90:27:bc:09:95
inphy0: <i82555 10/100 media interface> on miibus0
inphy0:  10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, auto
pci2: <multimedia, audio> at device 8.0 (no driver attached)
pci2: <input device> at device 8.1 (no driver attached)
ppc0 port 0x778-0x77f,0x378-0x37f irq 7 drq 3 on acpi0
ppc0: SMC-like chipset (ECP/EPP/PS2/NIBBLE) in COMPATIBLE mode
ppc0: FIFO with 16/16/9 bytes threshold
plip0: <PLIP network interface> on ppbus0
lpt0: <Printer> on ppbus0
lpt0: Interrupt-driven port
ppi0: <Parallel I/O> on ppbus0
sio0 port 0x3f8-0x3ff irq 4 on acpi0
sio0: type 16550A
sio1 port 0x2f8-0x2ff irq 3 on acpi0
sio1: type 16550A
atkbdc0: <Keyboard controller (i8042)> port 0x64,0x60 irq 1 on acpi0
atkbd0: <AT Keyboard> flags 0x1 irq 1 on atkbdc0
kbd0 at atkbd0
psm0: <PS/2 Mouse> irq 12 on atkbdc0
psm0: model IntelliMouse Explorer, device ID 4
orm0: <Option ROMs> at iomem 0xd8000-0xd8fff,0xc0000-0xcc7ff on isa0
fdc0: cannot reserve I/O port range (6 ports)
pmtimer0 on isa0
sc0: <System console> at flags 0x100 on isa0
sc0: VGA <16 virtual consoles, flags=0x300>
vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0
Timecounters tick every 10.000 msec
APIC_IO: Testing 8254 interrupt delivery
APIC_IO: routing 8254 via IOAPIC #0 intpin 2
acpi_cpu: CPU throttling enabled, 2 steps from 100% to 50.0%
ad0: 12949MB <IBM-DJNA-371350> [26310/16/63] at ata0-master UDMA66
acd0: DVD-ROM <CREATIVEDVD8400E> at ata1-master PIO4
Mounting root from ufs:/dev/ad0s1a
SMP: AP CPU #1 Launched!
cd0 at ahc0 bus 0 target 4 lun 0
cd0: <PLEXTOR CD-R   PX-W1210S 1.01> Removable CD-ROM SCSI-2 device 
cd0: 20.000MB/s transfers (20.000MHz, offset 16)
cd0: Attempt to query device size failed: NOT READY, Medium not present - tray closed
da0 at ahc0 bus 0 target 0 lun 0
da0: <SEAGATE ST336704LW 0004> Fixed Direct Access SCSI-3 device 
da0: 40.000MB/s transfers (20.000MHz, offset 63, 16bit), Tagged Queueing Enabled
da0: 35003MB (71687369 512 byte sectors: 255H 63S/T 4462C)
/usr/src/sys/vm/uma_core.c:1332: could sleep with "process lock" locked from 
/usr/src/sys/kern/kern_exec.c:336
lock order reversal
 1st 0xc448c160 process lock (process lock) @ /usr/src/sys/kern/kern_exec.c:336
 2nd 0xc03486a0 filelist lock (filelist lock) @ /usr/src/sys/kern/kern_descrip.c:1111
/usr/src/sys/vm/uma_core.c:1332: could sleep with "process lock" locked from 
/usr/src/sys/kern/kern_exec.c:336

Reply via email to