From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 04:13:35 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 820401065670; Tue, 4 Oct 2011 04:13:35 +0000 (UTC) (envelope-from grehan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6E2298FC1C; Tue, 4 Oct 2011 04:13:35 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p944DZ1h041633; Tue, 4 Oct 2011 04:13:35 GMT (envelope-from grehan@svn.freebsd.org) Received: (from grehan@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p944DZQB041619; Tue, 4 Oct 2011 04:13:35 GMT (envelope-from grehan@svn.freebsd.org) Message-Id: <201110040413.p944DZQB041619@svn.freebsd.org> From: Peter Grehan Date: Tue, 4 Oct 2011 04:13:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225959 - in projects/virtio: . bin/ls bin/mv bin/ps cddl/contrib/opensolaris/lib/libzfs/common contrib/llvm contrib/llvm/lib/Support contrib/llvm/tools/clang contrib/sendmail/src contr... X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 04:13:35 -0000 Author: grehan Date: Tue Oct 4 04:13:34 2011 New Revision: 225959 URL: http://svn.freebsd.org/changeset/base/225959 Log: IFC @ r225957 Added: projects/virtio/contrib/llvm/LICENSE.TXT - copied unchanged from r225957, head/contrib/llvm/LICENSE.TXT projects/virtio/contrib/llvm/lib/Support/COPYRIGHT.regex - copied unchanged from r225957, head/contrib/llvm/lib/Support/COPYRIGHT.regex projects/virtio/contrib/llvm/tools/clang/LICENSE.TXT - copied unchanged from r225957, head/contrib/llvm/tools/clang/LICENSE.TXT projects/virtio/share/doc/llvm/ - copied from r225957, head/share/doc/llvm/ Deleted: projects/virtio/lib/libftpio/ projects/virtio/release/Makefile.inc.docports projects/virtio/release/Makefile.sysinstall projects/virtio/release/amd64/boot_crunch.conf projects/virtio/release/fixit.profile projects/virtio/release/fixit.services projects/virtio/release/i386/boot_crunch.conf projects/virtio/release/i386/fixit_crunch.conf projects/virtio/release/ia64/boot_crunch.conf projects/virtio/release/pc98/boot_crunch.conf projects/virtio/release/pc98/fixit-small_crunch.conf projects/virtio/release/pc98/fixit_crunch.conf projects/virtio/release/powerpc/boot_crunch.conf projects/virtio/release/scripts/base-install.sh projects/virtio/release/scripts/catpages-install.sh projects/virtio/release/scripts/catpages-make.sh projects/virtio/release/scripts/checkindex.pl projects/virtio/release/scripts/chkINDEX projects/virtio/release/scripts/commerce-install.sh projects/virtio/release/scripts/dict-install.sh projects/virtio/release/scripts/dict-make.sh projects/virtio/release/scripts/doFS.sh projects/virtio/release/scripts/doc-install.sh projects/virtio/release/scripts/doc-make.sh projects/virtio/release/scripts/games-install.sh projects/virtio/release/scripts/info-install.sh projects/virtio/release/scripts/info-make.sh projects/virtio/release/scripts/info.sh projects/virtio/release/scripts/kernels-install.sh projects/virtio/release/scripts/lib32-install.sh projects/virtio/release/scripts/manpages-install.sh projects/virtio/release/scripts/manpages-make.sh projects/virtio/release/scripts/mkpkghier projects/virtio/release/scripts/mkpkgindex.sh projects/virtio/release/scripts/package-split.py projects/virtio/release/scripts/package-trees.sh projects/virtio/release/scripts/ports-install.sh projects/virtio/release/scripts/proflibs-install.sh projects/virtio/release/scripts/proflibs-make.sh projects/virtio/release/scripts/split-file.sh projects/virtio/release/scripts/src-install.sh projects/virtio/release/scripts/tar.sh projects/virtio/release/scripts/xperimnt-install.sh projects/virtio/release/sparc64/boot_crunch.conf projects/virtio/usr.sbin/sysinstall/ Modified: projects/virtio/MAINTAINERS projects/virtio/Makefile.inc1 projects/virtio/ObsoleteFiles.inc projects/virtio/UPDATING projects/virtio/bin/ls/ls.1 projects/virtio/bin/ls/ls.c projects/virtio/bin/ls/ls.h projects/virtio/bin/ls/print.c projects/virtio/bin/mv/mv.c projects/virtio/bin/ps/extern.h projects/virtio/bin/ps/keyword.c projects/virtio/bin/ps/print.c projects/virtio/bin/ps/ps.1 projects/virtio/bin/ps/ps.c projects/virtio/bin/ps/ps.h projects/virtio/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_changelist.c projects/virtio/contrib/sendmail/src/main.c projects/virtio/contrib/sendmail/src/sendmail.h projects/virtio/contrib/sendmail/src/usersmtp.c projects/virtio/crypto/openssh/ssh_namespace.h projects/virtio/etc/devd.conf projects/virtio/etc/mtree/BSD.include.dist projects/virtio/etc/mtree/BSD.usr.dist projects/virtio/etc/network.subr projects/virtio/gnu/usr.bin/groff/tmac/mdoc.local projects/virtio/include/Makefile projects/virtio/include/iso646.h projects/virtio/kerberos5/lib/libasn1/Makefile projects/virtio/kerberos5/lib/libgssapi_krb5/Makefile projects/virtio/kerberos5/lib/libgssapi_ntlm/Makefile projects/virtio/kerberos5/lib/libgssapi_spnego/Makefile projects/virtio/kerberos5/lib/libhdb/Makefile projects/virtio/kerberos5/lib/libheimntlm/Makefile projects/virtio/kerberos5/lib/libhx509/Makefile projects/virtio/kerberos5/lib/libkadm5clnt/Makefile projects/virtio/kerberos5/lib/libkadm5srv/Makefile projects/virtio/kerberos5/lib/libkafs5/Makefile projects/virtio/kerberos5/lib/libkrb5/Makefile projects/virtio/kerberos5/lib/libroken/Makefile projects/virtio/lib/Makefile projects/virtio/lib/libc/gen/ctermid.3 projects/virtio/lib/libc/gen/ctermid.c projects/virtio/lib/libc/gen/devname.c projects/virtio/lib/libc/locale/isspace.3 projects/virtio/lib/libfetch/common.c projects/virtio/lib/libfetch/common.h projects/virtio/lib/libfetch/fetch.3 projects/virtio/lib/libfetch/fetch.c projects/virtio/lib/libfetch/fetch.h projects/virtio/lib/libfetch/file.c projects/virtio/lib/libfetch/ftp.c projects/virtio/lib/libfetch/http.c projects/virtio/lib/libusbhid/data.c projects/virtio/lib/libusbhid/parse.c projects/virtio/lib/libusbhid/usbhid.3 projects/virtio/lib/libusbhid/usbhid.h projects/virtio/libexec/rtld-elf/map_object.c projects/virtio/sbin/camcontrol/camcontrol.c projects/virtio/sbin/fsdb/fsdbutil.c projects/virtio/sbin/hastctl/hastctl.c projects/virtio/sbin/hastd/activemap.c projects/virtio/sbin/hastd/control.c projects/virtio/sbin/hastd/ebuf.c projects/virtio/sbin/hastd/event.c projects/virtio/sbin/hastd/hast.conf.5 projects/virtio/sbin/hastd/hast.h projects/virtio/sbin/hastd/hast_proto.c projects/virtio/sbin/hastd/hastd.c projects/virtio/sbin/hastd/hooks.c projects/virtio/sbin/hastd/metadata.c projects/virtio/sbin/hastd/nv.c projects/virtio/sbin/hastd/parse.y projects/virtio/sbin/hastd/pjdlog.c projects/virtio/sbin/hastd/primary.c projects/virtio/sbin/hastd/proto_tcp.c projects/virtio/sbin/hastd/rangelock.c projects/virtio/sbin/hastd/secondary.c projects/virtio/sbin/hastd/subr.c projects/virtio/sbin/hastd/synch.h projects/virtio/sbin/hastd/token.l projects/virtio/share/doc/Makefile projects/virtio/share/examples/cvsup/stable-supfile projects/virtio/share/examples/scsi_target/scsi_cmds.c projects/virtio/share/examples/scsi_target/scsi_target.c projects/virtio/share/man/man4/smp.4 projects/virtio/share/man/man7/build.7 projects/virtio/share/man/man9/ifnet.9 projects/virtio/share/misc/committers-ports.dot projects/virtio/share/misc/committers-src.dot projects/virtio/share/misc/scsi_modes projects/virtio/sys/amd64/amd64/machdep.c projects/virtio/sys/amd64/amd64/trap.c projects/virtio/sys/arm/at91/at91_mci.c projects/virtio/sys/arm/at91/at91_pio.c projects/virtio/sys/arm/at91/at91_rtc.c projects/virtio/sys/arm/at91/at91_spi.c projects/virtio/sys/arm/at91/at91_ssc.c projects/virtio/sys/arm/at91/at91_twi.c projects/virtio/sys/arm/at91/uart_dev_at91usart.c projects/virtio/sys/arm/econa/if_ece.c projects/virtio/sys/boot/arm/ixp425/boot2/boot2.c projects/virtio/sys/cam/cam_ccb.h projects/virtio/sys/cam/cam_periph.c projects/virtio/sys/cam/scsi/scsi_all.c projects/virtio/sys/cam/scsi/scsi_all.h projects/virtio/sys/cam/scsi/scsi_cd.c projects/virtio/sys/cam/scsi/scsi_da.c projects/virtio/sys/cam/scsi/scsi_low.c projects/virtio/sys/cam/scsi/scsi_sa.c projects/virtio/sys/cam/scsi/scsi_targ_bh.c projects/virtio/sys/conf/newvers.sh projects/virtio/sys/dev/ahci/ahci.c projects/virtio/sys/dev/ath/ah_osdep.c projects/virtio/sys/dev/ath/ath_hal/ah_internal.h projects/virtio/sys/dev/ath/ath_hal/ah_regdomain.c projects/virtio/sys/dev/ath/ath_hal/ar5210/ar5210_attach.c projects/virtio/sys/dev/ath/ath_hal/ar5211/ar5211_attach.c projects/virtio/sys/dev/ath/ath_hal/ar5212/ar5112.c projects/virtio/sys/dev/ath/ath_hal/ar5212/ar5212_attach.c projects/virtio/sys/dev/ath/ath_hal/ar5212/ar5212_beacon.c projects/virtio/sys/dev/ath/ath_hal/ar5212/ar5212_xmit.c projects/virtio/sys/dev/ath/ath_hal/ar5312/ar5312_attach.c projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416.h projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416_attach.c projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416_beacon.c projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416_interrupts.c projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416_misc.c projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416_recv.c projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416_reset.c projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416_xmit.c projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416phy.h projects/virtio/sys/dev/ath/ath_hal/ar5416/ar5416reg.h projects/virtio/sys/dev/ath/ath_hal/ar9001/ar9130_attach.c projects/virtio/sys/dev/ath/ath_hal/ar9001/ar9160_attach.c projects/virtio/sys/dev/ath/ath_hal/ar9002/ar9280_attach.c projects/virtio/sys/dev/ath/ath_hal/ar9002/ar9285_attach.c projects/virtio/sys/dev/ath/ath_hal/ar9002/ar9287_attach.c projects/virtio/sys/dev/ath/if_ath.c projects/virtio/sys/dev/ath/if_athvar.h projects/virtio/sys/dev/bwi/if_bwi.c projects/virtio/sys/dev/ciss/ciss.c projects/virtio/sys/dev/fb/machfb.c projects/virtio/sys/dev/firewire/sbp.c projects/virtio/sys/dev/firewire/sbp_targ.c projects/virtio/sys/dev/iir/iir.c projects/virtio/sys/dev/iscsi/initiator/iscsi_subr.c projects/virtio/sys/dev/isp/isp_freebsd.h projects/virtio/sys/dev/le/lebuffer_sbus.c projects/virtio/sys/dev/mfi/mfi.c projects/virtio/sys/dev/mfi/mfivar.h projects/virtio/sys/dev/mly/mly.c projects/virtio/sys/dev/mps/mps_sas.c projects/virtio/sys/dev/mpt/mpt_cam.c projects/virtio/sys/dev/puc/pucdata.c projects/virtio/sys/dev/usb/input/uhid.c projects/virtio/sys/dev/usb/quirk/usb_quirk.c projects/virtio/sys/dev/usb/storage/umass.c projects/virtio/sys/dev/usb/usbdevs projects/virtio/sys/dev/xen/blkfront/blkfront.c projects/virtio/sys/dev/xen/blkfront/block.h projects/virtio/sys/dev/xen/control/control.c projects/virtio/sys/dev/xen/netfront/netfront.c projects/virtio/sys/i386/i386/machdep.c projects/virtio/sys/i386/i386/trap.c projects/virtio/sys/ia64/ia64/pmap.c projects/virtio/sys/kern/kern_clock.c projects/virtio/sys/kern/kern_exec.c projects/virtio/sys/kern/kern_fork.c projects/virtio/sys/kern/kern_racct.c projects/virtio/sys/kern/kern_rctl.c projects/virtio/sys/kern/kern_sig.c projects/virtio/sys/kern/subr_kdb.c projects/virtio/sys/kern/subr_syscall.c projects/virtio/sys/kern/subr_trap.c projects/virtio/sys/kern/uipc_usrreq.c projects/virtio/sys/mips/mips/machdep.c projects/virtio/sys/modules/ipfw/Makefile projects/virtio/sys/net/if_llatbl.h projects/virtio/sys/net/radix.h projects/virtio/sys/net/raw_cb.h projects/virtio/sys/net/raw_usrreq.c projects/virtio/sys/net/route.c projects/virtio/sys/net/route.h projects/virtio/sys/net/rtsock.c projects/virtio/sys/net80211/ieee80211_proto.c projects/virtio/sys/net80211/ieee80211_sta.c projects/virtio/sys/net80211/ieee80211_tdma.c projects/virtio/sys/netinet/in.c projects/virtio/sys/netinet/ipfw/ip_fw_pfil.c projects/virtio/sys/netinet6/in6.h projects/virtio/sys/netinet6/nd6.c projects/virtio/sys/powerpc/booke/pmap.c projects/virtio/sys/powerpc/ps3/ps3cdrom.c projects/virtio/sys/sparc64/central/central.c projects/virtio/sys/sparc64/conf/DEFAULTS projects/virtio/sys/sparc64/ebus/ebus.c projects/virtio/sys/sparc64/fhc/fhc.c projects/virtio/sys/sparc64/include/asmacros.h projects/virtio/sys/sparc64/include/atomic.h projects/virtio/sys/sparc64/include/bus.h projects/virtio/sys/sparc64/include/bus_private.h projects/virtio/sys/sparc64/pci/apb.c projects/virtio/sys/sparc64/pci/fire.c projects/virtio/sys/sparc64/pci/firevar.h projects/virtio/sys/sparc64/pci/ofw_pcib_subr.c projects/virtio/sys/sparc64/pci/psycho.c projects/virtio/sys/sparc64/pci/psychovar.h projects/virtio/sys/sparc64/pci/sbbc.c projects/virtio/sys/sparc64/pci/schizo.c projects/virtio/sys/sparc64/pci/schizovar.h projects/virtio/sys/sparc64/sbus/dma_sbus.c projects/virtio/sys/sparc64/sbus/sbus.c projects/virtio/sys/sparc64/sparc64/bus_machdep.c projects/virtio/sys/sparc64/sparc64/exception.S projects/virtio/sys/sparc64/sparc64/genassym.c projects/virtio/sys/sparc64/sparc64/machdep.c projects/virtio/sys/sparc64/sparc64/nexus.c projects/virtio/sys/sparc64/sparc64/pmap.c projects/virtio/sys/sparc64/sparc64/upa.c projects/virtio/sys/sys/param.h projects/virtio/sys/sys/racct.h projects/virtio/sys/ufs/ffs/ffs_snapshot.c projects/virtio/sys/ufs/ffs/ffs_softdep.c projects/virtio/sys/vm/vm_fault.c projects/virtio/sys/vm/vm_page.c projects/virtio/sys/vm/vm_page.h projects/virtio/sys/xen/xenbus/xenbusb.c projects/virtio/sys/xen/xenbus/xenbusb_back.c projects/virtio/sys/xen/xenbus/xenbusb_front.c projects/virtio/sys/xen/xenstore/xenstore.c projects/virtio/tools/make_libdeps.sh projects/virtio/usr.bin/calendar/calendars/calendar.freebsd projects/virtio/usr.bin/compress/zopen.c projects/virtio/usr.bin/csup/diff.c projects/virtio/usr.bin/fetch/fetch.1 projects/virtio/usr.bin/fetch/fetch.c projects/virtio/usr.bin/find/find.1 projects/virtio/usr.bin/find/ls.c projects/virtio/usr.bin/fstat/fstat.1 projects/virtio/usr.bin/fstat/fstat.c projects/virtio/usr.bin/gzip/zuncompress.c projects/virtio/usr.bin/script/script.1 projects/virtio/usr.bin/script/script.c projects/virtio/usr.bin/usbhidaction/usbhidaction.1 projects/virtio/usr.bin/usbhidaction/usbhidaction.c projects/virtio/usr.bin/usbhidctl/usbhid.c projects/virtio/usr.bin/usbhidctl/usbhidctl.1 projects/virtio/usr.sbin/Makefile projects/virtio/usr.sbin/mfiutil/mfi_show.c projects/virtio/usr.sbin/pkg_install/add/main.c projects/virtio/usr.sbin/pstat/pstat.c Directory Properties: projects/virtio/ (props changed) projects/virtio/cddl/contrib/opensolaris/ (props changed) projects/virtio/contrib/bind9/ (props changed) projects/virtio/contrib/binutils/ (props changed) projects/virtio/contrib/bzip2/ (props changed) projects/virtio/contrib/compiler-rt/ (props changed) projects/virtio/contrib/dialog/ (props changed) projects/virtio/contrib/ee/ (props changed) projects/virtio/contrib/expat/ (props changed) projects/virtio/contrib/file/ (props changed) projects/virtio/contrib/gcc/ (props changed) projects/virtio/contrib/gdb/ (props changed) projects/virtio/contrib/gdtoa/ (props changed) projects/virtio/contrib/gnu-sort/ (props changed) projects/virtio/contrib/groff/ (props changed) projects/virtio/contrib/less/ (props changed) projects/virtio/contrib/libpcap/ (props changed) projects/virtio/contrib/libstdc++/ (props changed) projects/virtio/contrib/llvm/ (props changed) projects/virtio/contrib/llvm/tools/clang/ (props changed) projects/virtio/contrib/ncurses/ (props changed) projects/virtio/contrib/netcat/ (props changed) projects/virtio/contrib/ntp/ (props changed) projects/virtio/contrib/one-true-awk/ (props changed) projects/virtio/contrib/openbsm/ (props changed) projects/virtio/contrib/openpam/ (props changed) projects/virtio/contrib/openresolv/ (props changed) projects/virtio/contrib/pf/ (props changed) projects/virtio/contrib/sendmail/ (props changed) projects/virtio/contrib/tcpdump/ (props changed) projects/virtio/contrib/tcsh/ (props changed) projects/virtio/contrib/tnftp/ (props changed) projects/virtio/contrib/top/ (props changed) projects/virtio/contrib/top/install-sh (props changed) projects/virtio/contrib/tzcode/stdtime/ (props changed) projects/virtio/contrib/tzcode/zic/ (props changed) projects/virtio/contrib/tzdata/ (props changed) projects/virtio/contrib/wpa/ (props changed) projects/virtio/contrib/xz/ (props changed) projects/virtio/crypto/heimdal/ (props changed) projects/virtio/crypto/openssh/ (props changed) projects/virtio/crypto/openssl/ (props changed) projects/virtio/gnu/lib/ (props changed) projects/virtio/gnu/usr.bin/binutils/ (props changed) projects/virtio/gnu/usr.bin/cc/cc_tools/ (props changed) projects/virtio/gnu/usr.bin/gdb/ (props changed) projects/virtio/lib/libc/ (props changed) projects/virtio/lib/libc/stdtime/ (props changed) projects/virtio/lib/libutil/ (props changed) projects/virtio/lib/libz/ (props changed) projects/virtio/sbin/ (props changed) projects/virtio/sbin/ipfw/ (props changed) projects/virtio/share/mk/bsd.arch.inc.mk (props changed) projects/virtio/share/zoneinfo/ (props changed) projects/virtio/sys/ (props changed) projects/virtio/sys/amd64/include/xen/ (props changed) projects/virtio/sys/boot/ (props changed) projects/virtio/sys/boot/i386/efi/ (props changed) projects/virtio/sys/boot/ia64/efi/ (props changed) projects/virtio/sys/boot/ia64/ski/ (props changed) projects/virtio/sys/boot/powerpc/boot1.chrp/ (props changed) projects/virtio/sys/boot/powerpc/ofw/ (props changed) projects/virtio/sys/cddl/contrib/opensolaris/ (props changed) projects/virtio/sys/conf/ (props changed) projects/virtio/sys/contrib/dev/acpica/ (props changed) projects/virtio/sys/contrib/octeon-sdk/ (props changed) projects/virtio/sys/contrib/pf/ (props changed) projects/virtio/sys/contrib/x86emu/ (props changed) projects/virtio/usr.bin/calendar/ (props changed) projects/virtio/usr.bin/csup/ (props changed) projects/virtio/usr.bin/procstat/ (props changed) projects/virtio/usr.sbin/ndiscvt/ (props changed) projects/virtio/usr.sbin/rtadvctl/ (props changed) projects/virtio/usr.sbin/rtadvd/ (props changed) projects/virtio/usr.sbin/rtsold/ (props changed) projects/virtio/usr.sbin/zic/ (props changed) Modified: projects/virtio/MAINTAINERS ============================================================================== --- projects/virtio/MAINTAINERS Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/MAINTAINERS Tue Oct 4 04:13:34 2011 (r225959) @@ -123,8 +123,6 @@ usr.sbin/zic edwin Heads-up appreciat maintained by a third party source. lib/libc/stdtime edwin Heads-up appreciated, since parts of this code is maintained by a third party source. -sysinstall randi Please contact about any major changes so that - they can be co-ordinated. sbin/routed bms Pre-commit review; notify vendor at rhyolite.com Following are the entries from the Makefiles, and a few other sources. Modified: projects/virtio/Makefile.inc1 ============================================================================== --- projects/virtio/Makefile.inc1 Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/Makefile.inc1 Tue Oct 4 04:13:34 2011 (r225959) @@ -1106,7 +1106,6 @@ build-tools: ${_aicasm} \ usr.bin/awk \ lib/libmagic \ - usr.sbin/sysinstall \ usr.bin/mkesdb_static \ usr.bin/mkcsmapper_static ${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \ @@ -1218,7 +1217,8 @@ _startup_libs+= lib/libc gnu/lib/libgcc__L: lib/libc__L -_prebuild_libs= ${_kerberos5_lib_libasn1} ${_kerberos5_lib_libheimntlm} \ +_prebuild_libs= ${_kerberos5_lib_libasn1} ${_kerberos5_lib_libhdb} \ + ${_kerberos5_lib_libheimntlm} \ ${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \ ${_kerberos5_lib_libroken} \ lib/libbz2 lib/libcom_err lib/libcrypt \ @@ -1268,6 +1268,19 @@ secure/lib/libssh__L: lib/libgssapi__L k _secure_lib= secure/lib .endif +.if ${MK_KERBEROS} != "no" +kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L +kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \ + kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L +kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L +kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \ + secure/lib/libcrypto__L kerberos5/lib/libroken__L +kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \ + lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \ + kerberos5/lib/libroken__L +kerberos5/lib/libroken__L: lib/libcrypt__L +.endif + .if ${MK_GSSAPI} != "no" _lib_libgssapi= lib/libgssapi .endif @@ -1279,6 +1292,7 @@ _lib_libipx= lib/libipx .if ${MK_KERBEROS} != "no" _kerberos5_lib= kerberos5/lib _kerberos5_lib_libasn1= kerberos5/lib/libasn1 +_kerberos5_lib_libhdb= kerberos5/lib/libhdb _kerberos5_lib_libkrb5= kerberos5/lib/libkrb5 _kerberos5_lib_libhx509= kerberos5/lib/libhx509 _kerberos5_lib_libroken= kerberos5/lib/libroken Modified: projects/virtio/ObsoleteFiles.inc ============================================================================== --- projects/virtio/ObsoleteFiles.inc Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/ObsoleteFiles.inc Tue Oct 4 04:13:34 2011 (r225959) @@ -38,6 +38,19 @@ # xargs -n1 | sort | uniq -d; # done +# 20110930: sysinstall removed +OLD_FILES+=usr/sbin/sysinstall +OLD_FILES+=usr/share/man/man8/sysinstall.8.gz +OLD_FILES+=usr/lib/libftpio.a +OLD_FILES+=usr/lib/libftpio.so +OLD_LIBS+=usr/lib/libftpio.so.8 +.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" +OLD_FILES+=usr/lib32/libftpio.a +OLD_FILES+=usr/lib32/libftpio.so +OLD_LIBS+=usr/lib32/libftpio.so.8 +.endif +OLD_FILES+=usr/include/ftpio.h +OLD_FILES+=usr/share/man/man3/ftpio.3.gz # 20110915: rename congestion control manpages OLD_FILES+=usr/share/man/man4/cc.4.gz OLD_FILES+=usr/share/man/man9/cc.9.gz @@ -54,7 +67,7 @@ OLD_LIBS+=usr/lib/libdwarf.so.2 OLD_LIBS+=usr/lib/libopie.so.6 OLD_LIBS+=usr/lib/librtld_db.so.1 OLD_LIBS+=usr/lib/libtacplus.so.4 -.if ${TARGET_ARCH} == "amd64" +.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" OLD_LIBS+=usr/lib32/libcam.so.5 OLD_LIBS+=usr/lib32/libpcap.so.7 OLD_LIBS+=usr/lib32/libufs.so.5 @@ -92,7 +105,7 @@ OLD_FILES+=usr/lib/libpkg.a OLD_FILES+=usr/lib/libpkg.so OLD_LIBS+=usr/lib/libpkg.so.0 OLD_FILES+=usr/lib/libpkg_p.a -.if ${TARGET_ARCH} == "amd64" +.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" OLD_FILES+=usr/lib32/libpkg.a OLD_FILES+=usr/lib32/libpkg.so OLD_LIBS+=usr/lib32/libpkg.so.0 @@ -100,7 +113,7 @@ OLD_FILES+=usr/lib32/libpkg_p.a .endif # 20110517: libsbuf version bump OLD_LIBS+=lib/libsbuf.so.5 -.if ${TARGET_ARCH} == "amd64" +.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" OLD_LIBS+=usr/lib32/libsbuf.so.5 .endif # 20110502: new clang import which bumps version from 2.9 to 3.0 @@ -131,7 +144,7 @@ OLD_FILES+=usr/lib/libobjc_p.a OLD_FILES+=usr/libexec/cc1obj OLD_LIBS+=usr/lib/libobjc.so.4 OLD_DIRS+=usr/include/objc -.if ${TARGET_ARCH} == "amd64" +.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" OLD_FILES+=usr/lib32/libobjc.a OLD_FILES+=usr/lib32/libobjc.so OLD_FILES+=usr/lib32/libobjc_p.a @@ -258,7 +271,7 @@ OLD_FILES+=usr/include/machine/intr.h .endif # 20100514: library version bump for versioned symbols for liblzma OLD_LIBS+=usr/lib/liblzma.so.0 -.if ${TARGET_ARCH} == "amd64" +.if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" OLD_LIBS+=usr/lib32/liblzma.so.0 .endif # 20100511: move GCC-specific headers to /usr/include/gcc @@ -2580,7 +2593,7 @@ OLD_FILES+=usr/lib/libpam_ssh.a OLD_FILES+=usr/lib/libpam_ssh_p.a OLD_FILES+=usr/bin/help OLD_FILES+=usr/bin/sccs -.if ${TARGET_ARCH} != "amd64" && ${TARGET_ARCH} != "arm" && ${TARGET_ARCH} != "i386" && ${TARGET_ARCH} != "powerpc" +.if ${TARGET_ARCH} != "amd64" && ${TARGET} != "arm" && ${TARGET_ARCH} != "i386" && ${TARGET} != "powerpc" OLD_FILES+=usr/bin/gdbserver .endif OLD_FILES+=usr/bin/ssh-keysign Modified: projects/virtio/UPDATING ============================================================================== --- projects/virtio/UPDATING Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/UPDATING Tue Oct 4 04:13:34 2011 (r225959) @@ -9,8 +9,8 @@ handbook. Items affecting the ports and packages system can be found in /usr/ports/UPDATING. Please read that file before running portupgrade. -NOTE TO PEOPLE WHO THINK THAT FreeBSD 9.x IS SLOW: - FreeBSD 9.x has many debugging features turned on, in both the kernel +NOTE TO PEOPLE WHO THINK THAT FreeBSD 10.x IS SLOW: + FreeBSD 10.x has many debugging features turned on, in both the kernel and userland. These features attempt to detect incorrect use of system primitives, and encourage loud failure through extra sanity checking and fail stop semantics. They also substantially impact @@ -22,6 +22,13 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 9. machines to maximize performance. (To disable malloc debugging, run ln -s aj /etc/malloc.conf.) +20110930: + sysinstall has been removed + +20110923: + The stable/9 branch created in subversion. This corresponds to the + RELENG_9 branch in CVS. + 20110913: This commit modifies vfs_register() so that it uses a hash calculation to set vfc_typenum, which is enabled by default. Modified: projects/virtio/bin/ls/ls.1 ============================================================================== --- projects/virtio/bin/ls/ls.1 Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/bin/ls/ls.1 Tue Oct 4 04:13:34 2011 (r225959) @@ -32,7 +32,7 @@ .\" @(#)ls.1 8.7 (Berkeley) 7/29/94 .\" $FreeBSD$ .\" -.Dd April 4, 2008 +.Dd September 28, 2011 .Dt LS 1 .Os .Sh NAME @@ -357,8 +357,7 @@ option is given, the numeric ID's are displayed. .Pp If the file is a character special or block special file, -the major and minor device numbers for the file are displayed -in the size field. +the device number for the file is displayed in the size field. If the file is a symbolic link the pathname of the linked-to file is preceded by .Dq Li -> . Modified: projects/virtio/bin/ls/ls.c ============================================================================== --- projects/virtio/bin/ls/ls.c Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/bin/ls/ls.c Tue Oct 4 04:13:34 2011 (r225959) @@ -563,7 +563,7 @@ display(const FTSENT *p, FTSENT *list, i long maxblock; u_long btotal, labelstrlen, maxinode, maxlen, maxnlink; u_long maxlabelstr; - u_int devstrlen; + u_int sizelen; int maxflags; gid_t maxgroup; uid_t maxuser; @@ -572,7 +572,6 @@ display(const FTSENT *p, FTSENT *list, i int entries, needstats; const char *user, *group; char *flags, *labelstr = NULL; - char buf[STRBUF_SIZEOF(u_quad_t) + 1]; char ngroup[STRBUF_SIZEOF(uid_t) + 1]; char nuser[STRBUF_SIZEOF(gid_t) + 1]; @@ -656,7 +655,8 @@ display(const FTSENT *p, FTSENT *list, i MAKENINES(maxsize); free(jinitmax); } - devstrlen = 0; + d.s_size = 0; + sizelen = 0; flags = NULL; for (cur = list, entries = 0; cur; cur = cur->fts_link) { if (cur->fts_info == FTS_ERR || cur->fts_info == FTS_NS) { @@ -796,14 +796,12 @@ label_out: np->group = &np->data[ulen + 1]; (void)strcpy(np->group, group); - if ((S_ISCHR(sp->st_mode) || - S_ISBLK(sp->st_mode)) && - devstrlen < DEVSTR_HEX_LEN) { - if (minor(sp->st_rdev) > 255 || - minor(sp->st_rdev) < 0) - devstrlen = DEVSTR_HEX_LEN; - else - devstrlen = DEVSTR_LEN; + if (S_ISCHR(sp->st_mode) || + S_ISBLK(sp->st_mode)) { + sizelen = snprintf(NULL, 0, + "%#jx", (uintmax_t)sp->st_rdev); + if (d.s_size < sizelen) + d.s_size = sizelen; } if (f_flags) { @@ -837,23 +835,16 @@ label_out: d.maxlen = maxlen; if (needstats) { d.btotal = btotal; - (void)snprintf(buf, sizeof(buf), "%lu", maxblock); - d.s_block = strlen(buf); + d.s_block = snprintf(NULL, 0, "%lu", maxblock); d.s_flags = maxflags; d.s_label = maxlabelstr; d.s_group = maxgroup; - (void)snprintf(buf, sizeof(buf), "%lu", maxinode); - d.s_inode = strlen(buf); - (void)snprintf(buf, sizeof(buf), "%lu", maxnlink); - d.s_nlink = strlen(buf); - if (f_humanval) - d.s_size = HUMANVALSTR_LEN; - else { - (void)snprintf(buf, sizeof(buf), "%ju", maxsize); - d.s_size = strlen(buf); - } - if (d.s_size < devstrlen) - d.s_size = devstrlen; + d.s_inode = snprintf(NULL, 0, "%lu", maxinode); + d.s_nlink = snprintf(NULL, 0, "%lu", maxnlink); + sizelen = f_humanval ? HUMANVALSTR_LEN : + snprintf(NULL, 0, "%ju", maxsize); + if (d.s_size < sizelen) + d.s_size = sizelen; d.s_user = maxuser; } printfcn(&d); Modified: projects/virtio/bin/ls/ls.h ============================================================================== --- projects/virtio/bin/ls/ls.h Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/bin/ls/ls.h Tue Oct 4 04:13:34 2011 (r225959) @@ -36,8 +36,6 @@ #define NO_PRINT 1 #define HUMANVALSTR_LEN 5 -#define DEVSTR_LEN 8 -#define DEVSTR_HEX_LEN 15 extern long blocksize; /* block size units */ Modified: projects/virtio/bin/ls/print.c ============================================================================== --- projects/virtio/bin/ls/print.c Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/bin/ls/print.c Tue Oct 4 04:13:34 2011 (r225959) @@ -48,6 +48,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -351,16 +352,8 @@ printaname(const FTSENT *p, u_long inode static void printdev(size_t width, dev_t dev) { - char buf[DEVSTR_HEX_LEN + 1]; - if (minor(dev) > 255 || minor(dev) < 0) - (void)snprintf(buf, sizeof(buf), "%3d, 0x%08x", - major(dev), (u_int)minor(dev)); - else - (void)snprintf(buf, sizeof(buf), "%3d, %3d", - major(dev), minor(dev)); - - (void)printf("%*s ", (u_int)width, buf); + (void)printf("%#*jx ", (u_int)width, (uintmax_t)dev); } static void Modified: projects/virtio/bin/mv/mv.c ============================================================================== --- projects/virtio/bin/mv/mv.c Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/bin/mv/mv.c Tue Oct 4 04:13:34 2011 (r225959) @@ -260,40 +260,34 @@ static int fastcopy(const char *from, const char *to, struct stat *sbp) { struct timeval tval[2]; - static u_int blen; - static char *bp; + static u_int blen = MAXPHYS; + static char *bp = NULL; mode_t oldmode; int nread, from_fd, to_fd; if ((from_fd = open(from, O_RDONLY, 0)) < 0) { - warn("%s", from); + warn("fastcopy: open() failed (from): %s", from); return (1); } - if (blen < sbp->st_blksize) { - if (bp != NULL) - free(bp); - if ((bp = malloc((size_t)sbp->st_blksize)) == NULL) { - blen = 0; - warnx("malloc failed"); - return (1); - } - blen = sbp->st_blksize; + if (bp == NULL && (bp = malloc((size_t)blen)) == NULL) { + warnx("malloc(%u) failed", blen); + return (1); } while ((to_fd = open(to, O_CREAT | O_EXCL | O_TRUNC | O_WRONLY, 0)) < 0) { if (errno == EEXIST && unlink(to) == 0) continue; - warn("%s", to); + warn("fastcopy: open() failed (to): %s", to); (void)close(from_fd); return (1); } while ((nread = read(from_fd, bp, (size_t)blen)) > 0) if (write(to_fd, bp, (size_t)nread) != nread) { - warn("%s", to); + warn("fastcopy: write() failed: %s", to); goto err; } if (nread < 0) { - warn("%s", from); + warn("fastcopy: read() failed: %s", from); err: if (unlink(to)) warn("%s: remove", to); (void)close(from_fd); Modified: projects/virtio/bin/ps/extern.h ============================================================================== --- projects/virtio/bin/ps/extern.h Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/bin/ps/extern.h Tue Oct 4 04:13:34 2011 (r225959) @@ -39,63 +39,52 @@ extern fixpt_t ccpu; extern int cflag, eval, fscale, nlistread, rawcpu; extern unsigned long mempages; extern time_t now; -extern int showthreads, sumrusage, termwidth, totwidth; +extern int showthreads, sumrusage, termwidth; extern STAILQ_HEAD(velisthead, varent) varlist; __BEGIN_DECLS -void arguments(KINFO *, VARENT *); -void command(KINFO *, VARENT *); -void cputime(KINFO *, VARENT *); +char *arguments(KINFO *, VARENT *); +char *command(KINFO *, VARENT *); +char *cputime(KINFO *, VARENT *); int donlist(void); -void elapsed(KINFO *, VARENT *); -void elapseds(KINFO *, VARENT *); -void emulname(KINFO *, VARENT *); +char *elapsed(KINFO *, VARENT *); +char *elapseds(KINFO *, VARENT *); +char *emulname(KINFO *, VARENT *); VARENT *find_varentry(VAR *); const char *fmt_argv(char **, char *, size_t); double getpcpu(const KINFO *); -void kvar(KINFO *, VARENT *); -void label(KINFO *, VARENT *); -void loginclass(KINFO *, VARENT *); -void logname(KINFO *, VARENT *); -void longtname(KINFO *, VARENT *); -void lstarted(KINFO *, VARENT *); -void maxrss(KINFO *, VARENT *); -void lockname(KINFO *, VARENT *); -void mwchan(KINFO *, VARENT *); -void nwchan(KINFO *, VARENT *); -void pagein(KINFO *, VARENT *); +char *kvar(KINFO *, VARENT *); +char *label(KINFO *, VARENT *); +char *loginclass(KINFO *, VARENT *); +char *logname(KINFO *, VARENT *); +char *longtname(KINFO *, VARENT *); +char *lstarted(KINFO *, VARENT *); +char *maxrss(KINFO *, VARENT *); +char *lockname(KINFO *, VARENT *); +char *mwchan(KINFO *, VARENT *); +char *nwchan(KINFO *, VARENT *); +char *pagein(KINFO *, VARENT *); void parsefmt(const char *, int); -void pcpu(KINFO *, VARENT *); -void pmem(KINFO *, VARENT *); -void pri(KINFO *, VARENT *); +char *pcpu(KINFO *, VARENT *); +char *pmem(KINFO *, VARENT *); +char *pri(KINFO *, VARENT *); void printheader(void); -void priorityr(KINFO *, VARENT *); -void egroupname(KINFO *, VARENT *); -void rgroupname(KINFO *, VARENT *); -void runame(KINFO *, VARENT *); -void rvar(KINFO *, VARENT *); -int s_comm(KINFO *); -int s_cputime(KINFO *); -int s_label(KINFO *); -int s_loginclass(KINFO *); -int s_logname(KINFO *); -int s_egroupname(KINFO *); -int s_rgroupname(KINFO *); -int s_runame(KINFO *); -int s_systime(KINFO *); -int s_uname(KINFO *); -int s_usertime(KINFO *); +char *priorityr(KINFO *, VARENT *); +char *egroupname(KINFO *, VARENT *); +char *rgroupname(KINFO *, VARENT *); +char *runame(KINFO *, VARENT *); +char *rvar(KINFO *, VARENT *); void showkey(void); -void started(KINFO *, VARENT *); -void state(KINFO *, VARENT *); -void systime(KINFO *, VARENT *); -void tdev(KINFO *, VARENT *); -void tdnam(KINFO *, VARENT *); -void tname(KINFO *, VARENT *); -void ucomm(KINFO *, VARENT *); -void uname(KINFO *, VARENT *); -void upr(KINFO *, VARENT *); -void usertime(KINFO *, VARENT *); -void vsize(KINFO *, VARENT *); -void wchan(KINFO *, VARENT *); +char *started(KINFO *, VARENT *); +char *state(KINFO *, VARENT *); +char *systime(KINFO *, VARENT *); +char *tdev(KINFO *, VARENT *); +char *tdnam(KINFO *, VARENT *); +char *tname(KINFO *, VARENT *); +char *ucomm(KINFO *, VARENT *); +char *uname(KINFO *, VARENT *); +char *upr(KINFO *, VARENT *); +char *usertime(KINFO *, VARENT *); +char *vsize(KINFO *, VARENT *); +char *wchan(KINFO *, VARENT *); __END_DECLS Modified: projects/virtio/bin/ps/keyword.c ============================================================================== --- projects/virtio/bin/ps/keyword.c Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/bin/ps/keyword.c Tue Oct 4 04:13:34 2011 (r225959) @@ -57,178 +57,116 @@ static int vcmp(const void *, const voi #define KOFF(x) offsetof(struct kinfo_proc, x) #define ROFF(x) offsetof(struct rusage, x) -#define EMULLEN 13 /* enough for "FreeBSD ELF32" */ #define LWPFMT "d" -#define LWPLEN 6 #define NLWPFMT "d" -#define NLWPLEN 4 #define UIDFMT "u" -#define UIDLEN 5 #define PIDFMT "d" -#define PIDLEN 5 -#define USERLEN (MAXLOGNAME - 1) /* PLEASE KEEP THE TABLE BELOW SORTED ALPHABETICALLY!!! */ static VAR var[] = { - {"%cpu", "%CPU", NULL, 0, pcpu, NULL, 5, 0, CHAR, NULL, 0}, - {"%mem", "%MEM", NULL, 0, pmem, NULL, 4, 0, CHAR, NULL, 0}, - {"acflag", "ACFLG", NULL, 0, kvar, NULL, 3, KOFF(ki_acflag), USHORT, - "x", 0}, - {"acflg", "", "acflag", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"args", "COMMAND", NULL, COMM|LJUST|USER, arguments, NULL, 16, 0, + {"%cpu", "%CPU", NULL, 0, pcpu, 0, CHAR, NULL, 0}, + {"%mem", "%MEM", NULL, 0, pmem, 0, CHAR, NULL, 0}, + {"acflag", "ACFLG", NULL, 0, kvar, KOFF(ki_acflag), USHORT, "x", 0}, + {"acflg", "", "acflag", 0, NULL, 0, CHAR, NULL, 0}, + {"args", "COMMAND", NULL, COMM|LJUST|USER, arguments, 0, CHAR, NULL, 0}, - {"blocked", "", "sigmask", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"caught", "", "sigcatch", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"class", "CLASS", NULL, LJUST, loginclass, s_loginclass, - MAXLOGNAME-1, 0, CHAR, NULL, 0}, - {"comm", "COMMAND", NULL, LJUST, ucomm, s_comm, - COMMLEN + TDNAMLEN + 1, 0, CHAR, NULL, 0}, - {"command", "COMMAND", NULL, COMM|LJUST|USER, command, NULL, 16, 0, + {"blocked", "", "sigmask", 0, NULL, 0, CHAR, NULL, 0}, + {"caught", "", "sigcatch", 0, NULL, 0, CHAR, NULL, 0}, + {"class", "CLASS", NULL, LJUST, loginclass, 0, CHAR, NULL, 0}, + {"comm", "COMMAND", NULL, LJUST, ucomm, 0, CHAR, NULL, 0}, + {"command", "COMMAND", NULL, COMM|LJUST|USER, command, 0, CHAR, NULL, 0}, - {"cpu", "CPU", NULL, 0, kvar, NULL, 3, KOFF(ki_estcpu), UINT, "d", - 0}, - {"cputime", "", "time", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"egid", "", "gid", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"egroup", "", "group", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"emul", "EMUL", NULL, LJUST, emulname, NULL, EMULLEN, 0, CHAR, - NULL, 0}, - {"etime", "ELAPSED", NULL, USER, elapsed, NULL, 12, 0, CHAR, NULL, 0}, - {"etimes", "ELAPSED", NULL, USER, elapseds, NULL, 12, 0, CHAR, NULL, 0}, - {"euid", "", "uid", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"f", "F", NULL, 0, kvar, NULL, 8, KOFF(ki_flag), INT, "x", 0}, - {"flags", "", "f", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"gid", "GID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_groups), - UINT, UIDFMT, 0}, - {"group", "GROUP", NULL, LJUST, egroupname, s_egroupname, - USERLEN, 0, CHAR, NULL, 0}, - {"ignored", "", "sigignore", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"inblk", "INBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_inblock), LONG, - "ld", 0}, - {"inblock", "", "inblk", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"jid", "JID", NULL, 0, kvar, NULL, 6, KOFF(ki_jid), INT, "d", 0}, - {"jobc", "JOBC", NULL, 0, kvar, NULL, 4, KOFF(ki_jobc), SHORT, "d", - 0}, - {"ktrace", "KTRACE", NULL, 0, kvar, NULL, 8, KOFF(ki_traceflag), INT, - "x", 0}, - {"label", "LABEL", NULL, LJUST, label, s_label, SHRT_MAX, 0, CHAR, - NULL, 0}, - {"lim", "LIM", NULL, 0, maxrss, NULL, 5, 0, CHAR, NULL, 0}, - {"lockname", "LOCK", NULL, LJUST, lockname, NULL, 6, 0, CHAR, NULL, - 0}, - {"login", "LOGIN", NULL, LJUST, logname, s_logname, MAXLOGNAME-1, - 0, CHAR, NULL, 0}, - {"logname", "", "login", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"lstart", "STARTED", NULL, LJUST|USER, lstarted, NULL, 28, 0, CHAR, - NULL, 0}, - {"lwp", "LWP", NULL, 0, kvar, NULL, LWPLEN, KOFF(ki_tid), UINT, - LWPFMT, 0}, - {"majflt", "MAJFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_majflt), - LONG, "ld", 0}, - {"minflt", "MINFLT", NULL, USER, rvar, NULL, 4, ROFF(ru_minflt), - LONG, "ld", 0}, - {"msgrcv", "MSGRCV", NULL, USER, rvar, NULL, 4, ROFF(ru_msgrcv), - LONG, "ld", 0}, - {"msgsnd", "MSGSND", NULL, USER, rvar, NULL, 4, ROFF(ru_msgsnd), - LONG, "ld", 0}, - {"mwchan", "MWCHAN", NULL, LJUST, mwchan, NULL, 6, 0, CHAR, NULL, 0}, - {"ni", "", "nice", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"nice", "NI", NULL, 0, kvar, NULL, 2, KOFF(ki_nice), CHAR, "d", - 0}, - {"nivcsw", "NIVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nivcsw), - LONG, "ld", 0}, - {"nlwp", "NLWP", NULL, 0, kvar, NULL, NLWPLEN, KOFF(ki_numthreads), - UINT, NLWPFMT, 0}, - {"nsignals", "", "nsigs", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"nsigs", "NSIGS", NULL, USER, rvar, NULL, 4, ROFF(ru_nsignals), - LONG, "ld", 0}, - {"nswap", "NSWAP", NULL, USER, rvar, NULL, 4, ROFF(ru_nswap), - LONG, "ld", 0}, - {"nvcsw", "NVCSW", NULL, USER, rvar, NULL, 5, ROFF(ru_nvcsw), - LONG, "ld", 0}, - {"nwchan", "NWCHAN", NULL, LJUST, nwchan, NULL, sizeof(void *) * 2, 0, - CHAR, NULL, 0}, - {"oublk", "OUBLK", NULL, USER, rvar, NULL, 4, ROFF(ru_oublock), - LONG, "ld", 0}, - {"oublock", "", "oublk", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"paddr", "PADDR", NULL, 0, kvar, NULL, sizeof(void *) * 2, - KOFF(ki_paddr), KPTR, "lx", 0}, - {"pagein", "PAGEIN", NULL, USER, pagein, NULL, 6, 0, CHAR, NULL, 0}, - {"pcpu", "", "%cpu", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"pending", "", "sig", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"pgid", "PGID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pgid), UINT, - PIDFMT, 0}, - {"pid", "PID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_pid), UINT, - PIDFMT, 0}, - {"pmem", "", "%mem", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"ppid", "PPID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_ppid), UINT, - PIDFMT, 0}, - {"pri", "PRI", NULL, 0, pri, NULL, 3, 0, CHAR, NULL, 0}, - {"re", "RE", NULL, INF127, kvar, NULL, 3, KOFF(ki_swtime), UINT, "d", - 0}, - {"rgid", "RGID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_rgid), - UINT, UIDFMT, 0}, - {"rgroup", "RGROUP", NULL, LJUST, rgroupname, s_rgroupname, - USERLEN, 0, CHAR, NULL, 0}, - {"rss", "RSS", NULL, 0, kvar, NULL, 6, KOFF(ki_rssize), PGTOK, "ld", 0}, - {"rtprio", "RTPRIO", NULL, 0, priorityr, NULL, 7, KOFF(ki_pri), CHAR, - NULL, 0}, - {"ruid", "RUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_ruid), - UINT, UIDFMT, 0}, - {"ruser", "RUSER", NULL, LJUST, runame, s_runame, USERLEN, - 0, CHAR, NULL, 0}, - {"sid", "SID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_sid), UINT, - PIDFMT, 0}, - {"sig", "PENDING", NULL, 0, kvar, NULL, 8, KOFF(ki_siglist), INT, - "x", 0}, - {"sigcatch", "CAUGHT", NULL, 0, kvar, NULL, 8, KOFF(ki_sigcatch), - UINT, "x", 0}, - {"sigignore", "IGNORED", NULL, 0, kvar, NULL, 8, KOFF(ki_sigignore), + {"cpu", "CPU", NULL, 0, kvar, KOFF(ki_estcpu), UINT, "d", 0}, + {"cputime", "", "time", 0, NULL, 0, CHAR, NULL, 0}, + {"egid", "", "gid", 0, NULL, 0, CHAR, NULL, 0}, + {"egroup", "", "group", 0, NULL, 0, CHAR, NULL, 0}, + {"emul", "EMUL", NULL, LJUST, emulname, 0, CHAR, NULL, 0}, + {"etime", "ELAPSED", NULL, USER, elapsed, 0, CHAR, NULL, 0}, + {"etimes", "ELAPSED", NULL, USER, elapseds, 0, CHAR, NULL, 0}, + {"euid", "", "uid", 0, NULL, 0, CHAR, NULL, 0}, + {"f", "F", NULL, 0, kvar, KOFF(ki_flag), INT, "x", 0}, + {"flags", "", "f", 0, NULL, 0, CHAR, NULL, 0}, + {"gid", "GID", NULL, 0, kvar, KOFF(ki_groups), UINT, UIDFMT, 0}, + {"group", "GROUP", NULL, LJUST, egroupname, 0, CHAR, NULL, 0}, + {"ignored", "", "sigignore", 0, NULL, 0, CHAR, NULL, 0}, + {"inblk", "INBLK", NULL, USER, rvar, ROFF(ru_inblock), LONG, "ld", 0}, + {"inblock", "", "inblk", 0, NULL, 0, CHAR, NULL, 0}, + {"jid", "JID", NULL, 0, kvar, KOFF(ki_jid), INT, "d", 0}, + {"jobc", "JOBC", NULL, 0, kvar, KOFF(ki_jobc), SHORT, "d", 0}, + {"ktrace", "KTRACE", NULL, 0, kvar, KOFF(ki_traceflag), INT, "x", 0}, + {"label", "LABEL", NULL, LJUST, label, 0, CHAR, NULL, 0}, + {"lim", "LIM", NULL, 0, maxrss, 0, CHAR, NULL, 0}, + {"lockname", "LOCK", NULL, LJUST, lockname, 0, CHAR, NULL, 0}, + {"login", "LOGIN", NULL, LJUST, logname, 0, CHAR, NULL, 0}, + {"logname", "", "login", 0, NULL, 0, CHAR, NULL, 0}, + {"lstart", "STARTED", NULL, LJUST|USER, lstarted, 0, CHAR, NULL, 0}, + {"lwp", "LWP", NULL, 0, kvar, KOFF(ki_tid), UINT, LWPFMT, 0}, + {"majflt", "MAJFLT", NULL, USER, rvar, ROFF(ru_majflt), LONG, "ld", 0}, + {"minflt", "MINFLT", NULL, USER, rvar, ROFF(ru_minflt), LONG, "ld", 0}, + {"msgrcv", "MSGRCV", NULL, USER, rvar, ROFF(ru_msgrcv), LONG, "ld", 0}, + {"msgsnd", "MSGSND", NULL, USER, rvar, ROFF(ru_msgsnd), LONG, "ld", 0}, + {"mwchan", "MWCHAN", NULL, LJUST, mwchan, 0, CHAR, NULL, 0}, + {"ni", "", "nice", 0, NULL, 0, CHAR, NULL, 0}, + {"nice", "NI", NULL, 0, kvar, KOFF(ki_nice), CHAR, "d", 0}, + {"nivcsw", "NIVCSW", NULL, USER, rvar, ROFF(ru_nivcsw), LONG, "ld", 0}, + {"nlwp", "NLWP", NULL, 0, kvar, KOFF(ki_numthreads), UINT, NLWPFMT, 0}, + {"nsignals", "", "nsigs", 0, NULL, 0, CHAR, NULL, 0}, + {"nsigs", "NSIGS", NULL, USER, rvar, ROFF(ru_nsignals), LONG, "ld", 0}, + {"nswap", "NSWAP", NULL, USER, rvar, ROFF(ru_nswap), LONG, "ld", 0}, + {"nvcsw", "NVCSW", NULL, USER, rvar, ROFF(ru_nvcsw), LONG, "ld", 0}, + {"nwchan", "NWCHAN", NULL, LJUST, nwchan, 0, CHAR, NULL, 0}, + {"oublk", "OUBLK", NULL, USER, rvar, ROFF(ru_oublock), LONG, "ld", 0}, + {"oublock", "", "oublk", 0, NULL, 0, CHAR, NULL, 0}, + {"paddr", "PADDR", NULL, 0, kvar, KOFF(ki_paddr), KPTR, "lx", 0}, + {"pagein", "PAGEIN", NULL, USER, pagein, 0, CHAR, NULL, 0}, + {"pcpu", "", "%cpu", 0, NULL, 0, CHAR, NULL, 0}, + {"pending", "", "sig", 0, NULL, 0, CHAR, NULL, 0}, + {"pgid", "PGID", NULL, 0, kvar, KOFF(ki_pgid), UINT, PIDFMT, 0}, + {"pid", "PID", NULL, 0, kvar, KOFF(ki_pid), UINT, PIDFMT, 0}, + {"pmem", "", "%mem", 0, NULL, 0, CHAR, NULL, 0}, + {"ppid", "PPID", NULL, 0, kvar, KOFF(ki_ppid), UINT, PIDFMT, 0}, + {"pri", "PRI", NULL, 0, pri, 0, CHAR, NULL, 0}, + {"re", "RE", NULL, INF127, kvar, KOFF(ki_swtime), UINT, "d", 0}, + {"rgid", "RGID", NULL, 0, kvar, KOFF(ki_rgid), UINT, UIDFMT, 0}, + {"rgroup", "RGROUP", NULL, LJUST, rgroupname, 0, CHAR, NULL, 0}, + {"rss", "RSS", NULL, 0, kvar, KOFF(ki_rssize), PGTOK, "ld", 0}, + {"rtprio", "RTPRIO", NULL, 0, priorityr, KOFF(ki_pri), CHAR, NULL, 0}, + {"ruid", "RUID", NULL, 0, kvar, KOFF(ki_ruid), UINT, UIDFMT, 0}, + {"ruser", "RUSER", NULL, LJUST, runame, 0, CHAR, NULL, 0}, + {"sid", "SID", NULL, 0, kvar, KOFF(ki_sid), UINT, PIDFMT, 0}, + {"sig", "PENDING", NULL, 0, kvar, KOFF(ki_siglist), INT, "x", 0}, + {"sigcatch", "CAUGHT", NULL, 0, kvar, KOFF(ki_sigcatch), UINT, "x", 0}, + {"sigignore", "IGNORED", NULL, 0, kvar, KOFF(ki_sigignore), UINT, "x", 0}, - {"sigmask", "BLOCKED", NULL, 0, kvar, NULL, 8, KOFF(ki_sigmask), - UINT, "x", 0}, - {"sl", "SL", NULL, INF127, kvar, NULL, 3, KOFF(ki_slptime), UINT, "d", - 0}, - {"start", "STARTED", NULL, LJUST|USER, started, NULL, 7, 0, CHAR, NULL, - 0}, - {"stat", "", "state", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"state", "STAT", NULL, 0, state, NULL, 4, 0, CHAR, NULL, 0}, - {"svgid", "SVGID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_svgid), - UINT, UIDFMT, 0}, - {"svuid", "SVUID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_svuid), - UINT, UIDFMT, 0}, - {"systime", "SYSTIME", NULL, USER, systime, s_systime, 15, 0, CHAR, - NULL, 0}, - {"tdaddr", "TDADDR", NULL, 0, kvar, NULL, sizeof(void *) * 2, - KOFF(ki_tdaddr), KPTR, "lx", 0}, - {"tdev", "TDEV", NULL, 0, tdev, NULL, 5, 0, CHAR, NULL, 0}, - {"tdnam", "TDNAM", NULL, LJUST, tdnam, NULL, COMMLEN, 0, CHAR, NULL, 0}, - {"time", "TIME", NULL, USER, cputime, s_cputime, 15, 0, CHAR, - NULL, 0}, - {"tpgid", "TPGID", NULL, 0, kvar, NULL, 4, KOFF(ki_tpgid), UINT, - PIDFMT, 0}, - {"tsid", "TSID", NULL, 0, kvar, NULL, PIDLEN, KOFF(ki_tsid), UINT, - PIDFMT, 0}, - {"tsiz", "TSIZ", NULL, 0, kvar, NULL, 4, KOFF(ki_tsize), PGTOK, "ld", 0}, - {"tt", "TT ", NULL, 0, tname, NULL, 4, 0, CHAR, NULL, 0}, - {"tty", "TTY", NULL, LJUST, longtname, NULL, 8, 0, CHAR, NULL, 0}, - {"ucomm", "UCOMM", NULL, LJUST, ucomm, s_comm, - COMMLEN + TDNAMLEN + 1, 0, CHAR, NULL, 0}, - {"uid", "UID", NULL, 0, kvar, NULL, UIDLEN, KOFF(ki_uid), UINT, - UIDFMT, 0}, - {"upr", "UPR", NULL, 0, upr, NULL, 3, 0, CHAR, NULL, 0}, - {"uprocp", "UPROCP", NULL, 0, kvar, NULL, sizeof(void *) * 2, - KOFF(ki_paddr), KPTR, "lx", 0}, - {"user", "USER", NULL, LJUST, uname, s_uname, USERLEN, 0, CHAR, - NULL, 0}, - {"usertime", "USERTIME", NULL, USER, usertime, s_usertime, 15, 0, - CHAR, NULL, 0}, - {"usrpri", "", "upr", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"vsize", "", "vsz", 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, - {"vsz", "VSZ", NULL, 0, vsize, NULL, 6, 0, CHAR, NULL, 0}, - {"wchan", "WCHAN", NULL, LJUST, wchan, NULL, 6, 0, CHAR, NULL, 0}, - {"xstat", "XSTAT", NULL, 0, kvar, NULL, 4, KOFF(ki_xstat), USHORT, - "x", 0}, - {"", NULL, NULL, 0, NULL, NULL, 0, 0, CHAR, NULL, 0}, + {"sigmask", "BLOCKED", NULL, 0, kvar, KOFF(ki_sigmask), UINT, "x", 0}, + {"sl", "SL", NULL, INF127, kvar, KOFF(ki_slptime), UINT, "d", 0}, + {"start", "STARTED", NULL, LJUST|USER, started, 0, CHAR, NULL, 0}, + {"stat", "", "state", 0, NULL, 0, CHAR, NULL, 0}, + {"state", "STAT", NULL, LJUST, state, 0, CHAR, NULL, 0}, + {"svgid", "SVGID", NULL, 0, kvar, KOFF(ki_svgid), UINT, UIDFMT, 0}, + {"svuid", "SVUID", NULL, 0, kvar, KOFF(ki_svuid), UINT, UIDFMT, 0}, + {"systime", "SYSTIME", NULL, USER, systime, 0, CHAR, NULL, 0}, + {"tdaddr", "TDADDR", NULL, 0, kvar, KOFF(ki_tdaddr), KPTR, "lx", 0}, + {"tdev", "TDEV", NULL, 0, tdev, 0, CHAR, NULL, 0}, + {"tdnam", "TDNAM", NULL, LJUST, tdnam, 0, CHAR, NULL, 0}, + {"time", "TIME", NULL, USER, cputime, 0, CHAR, NULL, 0}, + {"tpgid", "TPGID", NULL, 0, kvar, KOFF(ki_tpgid), UINT, PIDFMT, 0}, + {"tsid", "TSID", NULL, 0, kvar, KOFF(ki_tsid), UINT, PIDFMT, 0}, + {"tsiz", "TSIZ", NULL, 0, kvar, KOFF(ki_tsize), PGTOK, "ld", 0}, + {"tt", "TT ", NULL, 0, tname, 0, CHAR, NULL, 0}, + {"tty", "TTY", NULL, LJUST, longtname, 0, CHAR, NULL, 0}, + {"ucomm", "UCOMM", NULL, LJUST, ucomm, 0, CHAR, NULL, 0}, + {"uid", "UID", NULL, 0, kvar, KOFF(ki_uid), UINT, UIDFMT, 0}, + {"upr", "UPR", NULL, 0, upr, 0, CHAR, NULL, 0}, + {"uprocp", "UPROCP", NULL, 0, kvar, KOFF(ki_paddr), KPTR, "lx", 0}, + {"user", "USER", NULL, LJUST, uname, 0, CHAR, NULL, 0}, + {"usertime", "USERTIME", NULL, USER, usertime, 0, CHAR, NULL, 0}, + {"usrpri", "", "upr", 0, NULL, 0, CHAR, NULL, 0}, + {"vsize", "", "vsz", 0, NULL, 0, CHAR, NULL, 0}, + {"vsz", "VSZ", NULL, 0, vsize, 0, CHAR, NULL, 0}, + {"wchan", "WCHAN", NULL, LJUST, wchan, 0, CHAR, NULL, 0}, + {"xstat", "XSTAT", NULL, 0, kvar, KOFF(ki_xstat), USHORT, "x", 0}, + {"", NULL, NULL, 0, NULL, 0, CHAR, NULL, 0}, }; void Modified: projects/virtio/bin/ps/print.c ============================================================================== --- projects/virtio/bin/ps/print.c Tue Oct 4 04:00:29 2011 (r225958) +++ projects/virtio/bin/ps/print.c Tue Oct 4 04:13:34 2011 (r225959) @@ -64,6 +64,9 @@ __FBSDID("$FreeBSD$"); #include "ps.h" +#define COMMAND_WIDTH 16 +#define ARGUMENTS_WIDTH 16 + #define ps_pgtok(a) (((a) * getpagesize()) / 1024) void @@ -93,53 +96,42 @@ printheader(void) (void)putchar('\n'); } -void +char * arguments(KINFO *k, VARENT *ve) { VAR *v; - int left; - char *cp, *vis_args; + char *vis_args; v = ve->var; if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL) errx(1, "malloc failed"); strvis(vis_args, k->ki_args, VIS_TAB | VIS_NL | VIS_NOSLASH); - if (STAILQ_NEXT(ve, next_ve) == NULL) { - /* last field */ - if (termwidth == UNLIMITED) { - (void)printf("%s", vis_args); - } else { - left = termwidth - (totwidth - v->width); - if (left < 1) /* already wrapped, just use std width */ - left = v->width; - for (cp = vis_args; --left >= 0 && *cp != '\0';) - (void)putchar(*cp++); - } - } else { - (void)printf("%-*.*s", v->width, v->width, vis_args); - } - free(vis_args); + + if (STAILQ_NEXT(ve, next_ve) != NULL && strlen(vis_args) > ARGUMENTS_WIDTH) + vis_args[ARGUMENTS_WIDTH] = '\0'; + + return (vis_args); } -void +char * command(KINFO *k, VARENT *ve) { VAR *v; - int left; - char *cp, *vis_env, *vis_args; + char *vis_args, *vis_env, *str; v = ve->var; if (cflag) { /* If it is the last field, then don't pad */ if (STAILQ_NEXT(ve, next_ve) == NULL) { - if (k->ki_d.prefix) - (void)printf("%s", k->ki_d.prefix); - (void)printf("%s", k->ki_p->ki_comm); - if (showthreads && k->ki_p->ki_numthreads > 1) - (void)printf("/%s", k->ki_p->ki_tdname); + asprintf(&str, "%s%s%s%s", + k->ki_d.prefix ? k->ki_d.prefix : "", + k->ki_p->ki_comm, + (showthreads && k->ki_p->ki_numthreads > 1) ? "/" : "", + (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : ""); } else - (void)printf("%-*s", v->width, k->ki_p->ki_comm); - return; + str = strdup(k->ki_p->ki_comm); + + return (str); } if ((vis_args = malloc(strlen(k->ki_args) * 4 + 1)) == NULL) errx(1, "malloc failed"); @@ -157,89 +149,84 @@ command(KINFO *k, VARENT *ve) } else vis_env = NULL; - if (termwidth == UNLIMITED) { - if (k->ki_d.prefix) - (void)printf("%s", k->ki_d.prefix); - if (vis_env) - (void)printf("%s ", vis_env); - (void)printf("%s", vis_args); - } else { - left = termwidth - (totwidth - v->width); - if (left < 1) /* already wrapped, just use std width */ - left = v->width; - if ((cp = k->ki_d.prefix) != NULL) - while (--left >= 0 && *cp) - (void)putchar(*cp++); - if ((cp = vis_env) != NULL) { - while (--left >= 0 && *cp) - (void)putchar(*cp++); - if (--left >= 0) - putchar(' '); - } - for (cp = vis_args; --left >= 0 && *cp != '\0';) - (void)putchar(*cp++); - } + asprintf(&str, "%s%s%s%s", + k->ki_d.prefix ? k->ki_d.prefix : "", + vis_env ? vis_env : "", + vis_env ? " " : "", + vis_args); + if (vis_env != NULL) free(vis_env); - } else + free(vis_args); + } else { /* ki_d.prefix & ki_env aren't shown for interim fields */ - (void)printf("%-*.*s", v->width, v->width, vis_args); - free(vis_args); + str = vis_args; + + if (strlen(str) > COMMAND_WIDTH) + str[COMMAND_WIDTH] = '\0'; + } + + return (str); } -void +char * ucomm(KINFO *k, VARENT *ve) { - char tmpbuff[COMMLEN + TDNAMLEN + 2]; VAR *v; + char *str; v = ve->var; if (STAILQ_NEXT(ve, next_ve) == NULL) { /* last field, don't pad */ - if (k->ki_d.prefix) - (void)printf("%s", k->ki_d.prefix); - (void)printf("%s", k->ki_p->ki_comm); - if (showthreads && k->ki_p->ki_numthreads > 1) - printf("/%s", k->ki_p->ki_tdname); + asprintf(&str, "%s%s%s%s", + k->ki_d.prefix ? k->ki_d.prefix : "", + k->ki_p->ki_comm, + (showthreads && k->ki_p->ki_numthreads > 1) ? "/" : "", + (showthreads && k->ki_p->ki_numthreads > 1) ? k->ki_p->ki_tdname : ""); } else { - bzero(tmpbuff, sizeof(tmpbuff)); if (showthreads && k->ki_p->ki_numthreads > 1) - sprintf(tmpbuff, "%s/%s", k->ki_p->ki_comm, - k->ki_p->ki_tdname); + asprintf(&str, "%s/%s", k->ki_p->ki_comm, k->ki_p->ki_tdname); else - sprintf(tmpbuff, "%s", k->ki_p->ki_comm); - (void)printf("%-*s", v->width, tmpbuff); + str = strdup(k->ki_p->ki_comm); } + return (str); } -void +char * tdnam(KINFO *k, VARENT *ve) { VAR *v; + char *str; v = ve->var; if (showthreads && k->ki_p->ki_numthreads > 1) - (void)printf("%-*s", v->width, k->ki_p->ki_tdname); + str = strdup(k->ki_p->ki_tdname); else - (void)printf("%-*s", v->width, " "); + str = strdup(" "); + + return (str); } -void +char * logname(KINFO *k, VARENT *ve) { VAR *v; - char *s; v = ve->var; - (void)printf("%-*s", v->width, (s = k->ki_p->ki_login, *s) ? s : "-"); + if (*k->ki_p->ki_login == '\0') + return (NULL); + return (strdup(k->ki_p->ki_login)); } -void +char * state(KINFO *k, VARENT *ve) { int flag, tdflags; - char *cp; + char *cp, *buf; VAR *v; - char buf[16]; + + buf = malloc(16); + if (buf == NULL) + errx(1, "malloc failed"); v = ve->var; flag = k->ki_p->ki_flag; @@ -301,278 +288,270 @@ state(KINFO *k, VARENT *ve) if (flag & P_JAILED) *cp++ = 'J'; *cp = '\0'; - (void)printf("%-*s", v->width, buf); + return (buf); } #define scalepri(x) ((x) - PZERO) -void +char * pri(KINFO *k, VARENT *ve) { VAR *v; + char *str; v = ve->var; - (void)printf("%*d", v->width, scalepri(k->ki_p->ki_pri.pri_level)); + asprintf(&str, "%d", scalepri(k->ki_p->ki_pri.pri_level)); + return (str); } -void +char * upr(KINFO *k, VARENT *ve) { VAR *v; + char *str; v = ve->var; - (void)printf("%*d", v->width, scalepri(k->ki_p->ki_pri.pri_user)); + asprintf(&str, "%d", scalepri(k->ki_p->ki_pri.pri_user)); + return (str); } #undef scalepri -void +char * uname(KINFO *k, VARENT *ve) { VAR *v; v = ve->var; - (void)printf("%-*s", v->width, user_from_uid(k->ki_p->ki_uid, 0)); -} *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 13:05:07 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 978BF106564A; Tue, 4 Oct 2011 13:05:07 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6AF278FC18; Tue, 4 Oct 2011 13:05:07 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94D57Hu058681; Tue, 4 Oct 2011 13:05:07 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94D57Ea058680; Tue, 4 Oct 2011 13:05:07 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041305.p94D57Ea058680@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 13:05:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225972 - projects/geom-events X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 13:05:07 -0000 Author: lev (ports committer) Date: Tue Oct 4 13:05:07 2011 New Revision: 225972 URL: http://svn.freebsd.org/changeset/base/225972 Log: Start integrating geom-events project into SVN. Added: - copied from r225971, head/ Directory Properties: projects/geom-events/ (props changed) From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 16:47:18 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B792E106566B; Tue, 4 Oct 2011 16:47:18 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9C8BD8FC0A; Tue, 4 Oct 2011 16:47:18 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94GlIOx066150; Tue, 4 Oct 2011 16:47:18 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94GlIo3066146; Tue, 4 Oct 2011 16:47:18 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041647.p94GlIo3066146@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 16:47:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225984 - in projects/geom-events: sbin/geom/class/raid3 sys/geom/raid3 X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 16:47:18 -0000 Author: lev (ports committer) Date: Tue Oct 4 16:47:18 2011 New Revision: 225984 URL: http://svn.freebsd.org/changeset/base/225984 Log: Locally fix kern/160562: Allow to insert new component to geom_raid3 without specifying number. Now "geom_raid3" requires "-n " argument for "insert" command, which insert new component instead of removed (or failed) one. It is not convient in most cases (one lost component). This patch allows not to specify component number. In such case new component is added instead of first missed component. Modified: projects/geom-events/sbin/geom/class/raid3/geom_raid3.c projects/geom-events/sbin/geom/class/raid3/graid3.8 projects/geom-events/sys/geom/raid3/g_raid3_ctl.c Modified: projects/geom-events/sbin/geom/class/raid3/geom_raid3.c ============================================================================== --- projects/geom-events/sbin/geom/class/raid3/geom_raid3.c Tue Oct 4 15:06:11 2011 (r225983) +++ projects/geom-events/sbin/geom/class/raid3/geom_raid3.c Tue Oct 4 16:47:18 2011 (r225984) @@ -76,10 +76,10 @@ struct g_command class_commands[] = { { "insert", G_FLAG_VERBOSE, NULL, { { 'h', "hardcode", NULL, G_TYPE_BOOL }, - { 'n', "number", NULL, G_TYPE_NUMBER }, + { 'n', "number", G_VAL_OPTIONAL, G_TYPE_NUMBER }, G_OPT_SENTINEL }, - "[-hv] <-n number> name prov" + "[-hv] [-n number] name prov" }, { "label", G_FLAG_VERBOSE, raid3_main, { Modified: projects/geom-events/sbin/geom/class/raid3/graid3.8 ============================================================================== --- projects/geom-events/sbin/geom/class/raid3/graid3.8 Tue Oct 4 15:06:11 2011 (r225983) +++ projects/geom-events/sbin/geom/class/raid3/graid3.8 Tue Oct 4 16:47:18 2011 (r225984) @@ -53,7 +53,7 @@ .Nm .Cm insert .Op Fl hv -.Fl n Ar number +.Op Fl n Ar number .Ar name .Ar prov .Nm @@ -171,6 +171,8 @@ Add the given component to the existing removed previously with the .Cm remove command or if one component is missing and will not be connected again. +If no number is given, the new component will be added instead of the first +missed component. .Pp Additional options include: .Bl -tag -width ".Fl h" Modified: projects/geom-events/sys/geom/raid3/g_raid3_ctl.c ============================================================================== --- projects/geom-events/sys/geom/raid3/g_raid3_ctl.c Tue Oct 4 15:06:11 2011 (r225983) +++ projects/geom-events/sys/geom/raid3/g_raid3_ctl.c Tue Oct 4 16:47:18 2011 (r225984) @@ -404,7 +404,7 @@ g_raid3_ctl_insert(struct gctl_req *req, u_char *sector; off_t compsize; intmax_t *no; - int *hardcode, *nargs, error; + int *hardcode, *nargs, error, autono; nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs)); if (nargs == NULL) { @@ -425,11 +425,10 @@ g_raid3_ctl_insert(struct gctl_req *req, gctl_error(req, "No 'arg%u' argument.", 1); return; } - no = gctl_get_paraml(req, "number", sizeof(*no)); - if (no == NULL) { - gctl_error(req, "No '%s' argument.", "no"); - return; - } + if (gctl_get_param(req, "number", NULL) != NULL) + no = gctl_get_paraml(req, "number", sizeof(*no)); + else + no = NULL; if (strncmp(name, "/dev/", 5) == 0) name += 5; g_topology_lock(); @@ -465,16 +464,28 @@ g_raid3_ctl_insert(struct gctl_req *req, gctl_error(req, "No such device: %s.", name); goto end; } - if (*no >= sc->sc_ndisks) { - sx_xunlock(&sc->sc_lock); - gctl_error(req, "Invalid component number."); - goto end; - } - disk = &sc->sc_disks[*no]; - if (disk->d_state != G_RAID3_DISK_STATE_NODISK) { - sx_xunlock(&sc->sc_lock); - gctl_error(req, "Component %jd is already connected.", *no); - goto end; + if (no != NULL) { + if (*no >= sc->sc_ndisks) { + sx_xunlock(&sc->sc_lock); + gctl_error(req, "Invalid component number."); + goto end; + } + disk = &sc->sc_disks[*no]; + if (disk->d_state != G_RAID3_DISK_STATE_NODISK) { + sx_xunlock(&sc->sc_lock); + gctl_error(req, "Component %jd is already connected.", *no); + goto end; + } + } else { + disk = NULL; + for (autono = 0; autono < sc->sc_ndisks && disk == NULL; autono++) + if (sc->sc_disks[autono].d_state == G_RAID3_DISK_STATE_NODISK) + disk = &sc->sc_disks[autono]; + if (disk == NULL) { + sx_xunlock(&sc->sc_lock); + gctl_error(req, "No unconnected components."); + goto end; + } } if (((sc->sc_sectorsize / (sc->sc_ndisks - 1)) % pp->sectorsize) != 0) { sx_xunlock(&sc->sc_lock); From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 16:48:57 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6DAF5106564A; Tue, 4 Oct 2011 16:48:57 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5C3928FC0A; Tue, 4 Oct 2011 16:48:57 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94Gmvun066236; Tue, 4 Oct 2011 16:48:57 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94Gmvq9066231; Tue, 4 Oct 2011 16:48:57 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041648.p94Gmvq9066231@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 16:48:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225985 - in projects/geom-events/usr.sbin: . ggetmode X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 16:48:57 -0000 Author: lev (ports committer) Date: Tue Oct 4 16:48:57 2011 New Revision: 225985 URL: http://svn.freebsd.org/changeset/base/225985 Log: Add ggetmode(8) - utility to check open mode of geom provider. Added: projects/geom-events/usr.sbin/ggetmode/ projects/geom-events/usr.sbin/ggetmode/Makefile projects/geom-events/usr.sbin/ggetmode/ggetmode.8 projects/geom-events/usr.sbin/ggetmode/ggetmode.c Modified: projects/geom-events/usr.sbin/Makefile Modified: projects/geom-events/usr.sbin/Makefile ============================================================================== --- projects/geom-events/usr.sbin/Makefile Tue Oct 4 16:47:18 2011 (r225984) +++ projects/geom-events/usr.sbin/Makefile Tue Oct 4 16:48:57 2011 (r225985) @@ -28,6 +28,7 @@ SUBDIR= adduser \ fwcontrol \ getfmac \ getpmac \ + ggetmode \ gstat \ i2c \ ifmcstat \ Added: projects/geom-events/usr.sbin/ggetmode/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/ggetmode/Makefile Tue Oct 4 16:48:57 2011 (r225985) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +PROG= ggetmode +MAN= ggetmode.8 +DPADD= ${LIBGEOM} +LDADD= -lgeom + +.include Added: projects/geom-events/usr.sbin/ggetmode/ggetmode.8 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/ggetmode/ggetmode.8 Tue Oct 4 16:48:57 2011 (r225985) @@ -0,0 +1,57 @@ +.\" Copyright (c) 2011 Lev Serebryakov +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 14, 2011 +.Dt GGETMODE 8 +.Os +.Sh NAME +.Nm ggetmode +.Nd prints open mode of the given geom provider represented as the device node. +.Sh SYNOPSIS +.Nm ggetmode +.Ar device_name +.Sh DESCRIPTION +.Nm +utility prints open mode of the given device in standard +.Xr geom 4 +notation +.Em "rXwYeZ" . +String of +.Em "r0w0e0" +means, that given device isn't used by any consumer and is availiable. +.Sh EXIT STATUS +.Ex -std ggetmode +.Sh SEE ALSO +.Xr geom 8 , +.Xr geom 4 +.Sh HISTORY +The +.Nm +utility and manual page first appeared in +.Fx 10.0 . +.Sh AUTHORS +This utility and manual page was written by +.An Lev Serebryakov Aq lev@FreeBSD.org . Added: projects/geom-events/usr.sbin/ggetmode/ggetmode.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/ggetmode/ggetmode.c Tue Oct 4 16:48:57 2011 (r225985) @@ -0,0 +1,85 @@ +/*- + * Copyright (c) 2011 Lev Serebryakov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static char pathdev[] = _PATH_DEV; + +int +main(int argc, char *argv[]) +{ + struct gmesh mesh; + struct gclass *mp; + struct ggeom *gp; + struct gprovider *pp; + int error; + char mode[16] = ""; + char *device; + + if (argc != 2) + errx(EX_USAGE, "Syntax: %s ", basename(argv[0])); + + device = argv[1]; + if (!strncmp(device, pathdev, sizeof(pathdev) - 1)) + device += sizeof(pathdev) - 1; + + error = geom_gettree(&mesh); + if (error != 0) + errc(EX_UNAVAILABLE, error, "Can not get GEOM configuration: "); + + LIST_FOREACH(mp, &mesh.lg_class, lg_class) { + LIST_FOREACH(gp, &mp->lg_geom, lg_geom) { + LIST_FOREACH(pp, &gp->lg_provider, lg_provider) { + if (!strcmp(pp->lg_name, device)) { + strlcpy(mode, pp->lg_mode, sizeof(mode) - 1); + goto end; + } + } + } + } +end: + geom_deletetree(&mesh); + if (mode[0]) + printf("%s\n", mode); + else + errx(EX_DATAERR, "%s not found", argv[1]); + + return (EX_OK); +} From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 16:52:00 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 64D21106564A; Tue, 4 Oct 2011 16:52:00 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5175A8FC13; Tue, 4 Oct 2011 16:52:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94Gq0ne066446; Tue, 4 Oct 2011 16:52:00 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94Gq0XE066442; Tue, 4 Oct 2011 16:52:00 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041652.p94Gq0XE066442@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 16:52:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225986 - in projects/geom-events/sys: conf geom X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 16:52:00 -0000 Author: lev (ports committer) Date: Tue Oct 4 16:51:59 2011 New Revision: 225986 URL: http://svn.freebsd.org/changeset/base/225986 Log: Add g_notify_* wrappers around devctl_notify(). Added: projects/geom-events/sys/geom/geom_notify.c Modified: projects/geom-events/sys/conf/files projects/geom-events/sys/geom/geom.h Modified: projects/geom-events/sys/conf/files ============================================================================== --- projects/geom-events/sys/conf/files Tue Oct 4 16:48:57 2011 (r225985) +++ projects/geom-events/sys/conf/files Tue Oct 4 16:51:59 2011 (r225986) @@ -2191,6 +2191,7 @@ geom/geom_kern.c standard geom/geom_map.c optional geom_map geom/geom_mbr.c optional geom_mbr geom/geom_mbr_enc.c optional geom_mbr +geom/geom_notify.c standard geom/geom_pc98.c optional geom_pc98 geom/geom_pc98_enc.c optional geom_pc98 geom/geom_redboot.c optional geom_redboot Modified: projects/geom-events/sys/geom/geom.h ============================================================================== --- projects/geom-events/sys/geom/geom.h Tue Oct 4 16:48:57 2011 (r225985) +++ projects/geom-events/sys/geom/geom.h Tue Oct 4 16:51:59 2011 (r225986) @@ -393,4 +393,19 @@ struct g_class *gctl_get_class(struct gc struct g_geom *gctl_get_geom(struct gctl_req *req, struct g_class *mpr, char const *arg); struct g_provider *gctl_get_provider(struct gctl_req *req, char const *arg); +/* geom_notify.c */ + +#ifdef _KERNEL + +#define G_NOTIFY_DISCONNECT_FIXABLE 'F' +#define G_NOTIFY_DISCONNECT_ALIVE 'A' +#define G_NOTIFY_DISCONNECT_DEAD 'D' +#define G_NOTIFY_DISCONNECT_UNKNOWN '?' +void g_notify_disconnect(struct g_provider *pp, struct g_consumer *cp, char state); +void g_notify_sync_start(struct g_provider *pp); +void g_notify_sync_stop(struct g_provider *pp, boolean_t complete); +void g_notify_destroyed(struct g_provider *pp); + +#endif /* _KERNEL */ + #endif /* _GEOM_GEOM_H_ */ Added: projects/geom-events/sys/geom/geom_notify.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/sys/geom/geom_notify.c Tue Oct 4 16:51:59 2011 (r225986) @@ -0,0 +1,129 @@ +/*- + * Copyright (c) 2011 Lev Serebryakov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static void +g_devctl_notify(struct g_provider *pp, const char *event, const char *format, ...) +{ + char *full_data; + char *additional_data; + char *subsystem; + va_list args; + int len; + int i; + + subsystem = g_malloc(strlen(pp->geom->class->name) + 1, M_WAITOK); + if (subsystem == NULL) + return; + for (i = 0; pp->geom->class->name[i]; i++) + subsystem[i] = tolower(pp->geom->class->name[i]); + subsystem[i] = 0; + + if (format != NULL) { + additional_data = g_malloc(1024, M_WAITOK); + if (additional_data == NULL) { + g_free(subsystem); + return; + } + va_start(args, format); + len = vsnprintf(additional_data, 1024, format, args); + va_end(args); + } else { + additional_data = NULL; + len = 0; + } + + /* Add more space for mandatory arguments, space and zero */ + len += sizeof("geom=") + strlen(pp->geom->name) + + sizeof("provider=") + strlen(pp->name) + 2; + full_data = g_malloc(len, M_WAITOK); + if (full_data == NULL) { + g_free(subsystem); + if (additional_data != NULL) + g_free(additional_data); + return; + } + + if (additional_data != NULL) + snprintf(full_data, len, "geom=%s provider=%s %s", + pp->geom->name, pp->name, additional_data); + else + snprintf(full_data, len, "geom=%s provider=%s", + pp->geom->name, pp->name); + + devctl_notify("GEOM", subsystem, event, full_data); + g_free(subsystem); + if (additional_data != NULL) + g_free(additional_data); + g_free(full_data); +} + + +void +g_notify_disconnect(struct g_provider *pp, struct g_consumer *cp, char state) +{ + g_devctl_notify(pp, "DISCONNECT", "disk=%s state=%c", + (cp != NULL && cp->provider != NULL && cp->provider->name != NULL)? + cp->provider->name:"[unknown]", + state); +} + +void +g_notify_sync_start(struct g_provider *pp) +{ + g_devctl_notify(pp, "SYNCSTART", NULL); +} + +void +g_notify_sync_stop(struct g_provider *pp, boolean_t complete) +{ + g_devctl_notify(pp, "SYNCSTOP", "complete=%c", complete?'Y':'N'); +} + +void +g_notify_destroyed(struct g_provider *pp) +{ + g_devctl_notify(pp, "DESTROYED", NULL); +} From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 16:54:22 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 43EBB106566C; Tue, 4 Oct 2011 16:54:22 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3155F8FC13; Tue, 4 Oct 2011 16:54:22 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94GsMbF066887; Tue, 4 Oct 2011 16:54:22 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94GsM24066876; Tue, 4 Oct 2011 16:54:22 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041654.p94GsM24066876@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 16:54:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225989 - in projects/geom-events: etc etc/devd sbin/geom/core usr.sbin usr.sbin/geom-events X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 16:54:22 -0000 Author: lev (ports committer) Date: Tue Oct 4 16:54:21 2011 New Revision: 225989 URL: http://svn.freebsd.org/changeset/base/225989 Log: Add geom-events(8) script ad all needeed configuration files and references. More details are in geom-events(8). Added: projects/geom-events/etc/devd/geom.conf projects/geom-events/etc/geom-events.conf projects/geom-events/usr.sbin/geom-events/ projects/geom-events/usr.sbin/geom-events/Makefile projects/geom-events/usr.sbin/geom-events/geom-events.8 projects/geom-events/usr.sbin/geom-events/geom-events.conf.5 projects/geom-events/usr.sbin/geom-events/geom-events.sh Modified: projects/geom-events/etc/Makefile projects/geom-events/etc/devd/Makefile projects/geom-events/sbin/geom/core/geom.8 projects/geom-events/usr.sbin/Makefile Modified: projects/geom-events/etc/Makefile ============================================================================== --- projects/geom-events/etc/Makefile Tue Oct 4 16:53:11 2011 (r225988) +++ projects/geom-events/etc/Makefile Tue Oct 4 16:54:21 2011 (r225989) @@ -10,7 +10,7 @@ SUBDIR= sendmail BIN1= auth.conf \ crontab devd.conf devfs.conf \ ddb.conf dhclient.conf disktab fbtab \ - ftpusers gettytab group \ + ftpusers geom-events.conf gettytab group \ hosts hosts.allow hosts.equiv \ inetd.conf libalias.conf login.access login.conf mac.conf motd \ netconfig network.subr networks newsyslog.conf nsswitch.conf \ Modified: projects/geom-events/etc/devd/Makefile ============================================================================== --- projects/geom-events/etc/devd/Makefile Tue Oct 4 16:53:11 2011 (r225988) +++ projects/geom-events/etc/devd/Makefile Tue Oct 4 16:54:21 2011 (r225989) @@ -1,6 +1,6 @@ # $FreeBSD$ -FILES= asus.conf uath.conf usb.conf +FILES= asus.conf geom.conf uath.conf usb.conf NO_OBJ= FILESDIR= /etc/devd Added: projects/geom-events/etc/devd/geom.conf ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/etc/devd/geom.conf Tue Oct 4 16:54:21 2011 (r225989) @@ -0,0 +1,32 @@ +# $FreeBSD$ +# +# GEOM Events processing + +notify 100 { + match "system" "GEOM"; + match "type" "DISCONNECT"; + action "/usr/sbin/geom-events $type $subsystem $geom $provider $disk $state"; +}; + +notify 100 { + match "system" "GEOM"; + match "type" "SYNCSTART"; + action "/usr/sbin/geom-events $type $subsystem $geom $provider"; +}; + +notify 100 { + match "system" "GEOM"; + match "type" "SYNCSTOP"; + action "/usr/sbin/geom-events $type $subsystem $geom $provider $complete"; +}; + +notify 100 { + match "system" "GEOM"; + match "type" "DESTROYED"; + action "/usr/sbin/geom-events $type $subsystem $geom $provider"; +}; + +notify 0 { + match "system" "GEOM"; + action "/usr/sbin/geom-events $type $subsystem $geom $provider"; +}; Added: projects/geom-events/etc/geom-events.conf ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/etc/geom-events.conf Tue Oct 4 16:54:21 2011 (r225989) @@ -0,0 +1,52 @@ +# $FreeBSD$ +# +# Settings for GEOM events processing +# +# This file contains "system-wide" settings. Variables in this file could be +# overwritten with class- and device-specific configs. +# +# Class-specific configs are read from +# /etc/geom-events/${class}.conf +# /usr/local/etc/geom-events/${class}.conf +# +# Device-specific configs are read from +# /etc/geom-events/${class}/${device}.conf +# /usr/local/etc/geom-events/${class}/${device}.conf +# +# Spare disks are selected by peculiarity of config variables, +# not by config file, in which variables were set. +# +# Please, consult to geom-events(8) for details. +# + +geom_events_notify=root # E-mail or user to sent reports about GEOM events to +geom_events_log="YES" # Log all events with logger(1) + +########################################### +# Special commands for non-standard classes +########################################### +geom_insert_cmd_multipath='/sbin/g${class} add ${geom} ${spare}' + +geom_remove_cmd_mirror='/sbin/g${class} forget ${geom}' + +###################################### +# Example of spare disks configuration +###################################### + +# Default spares. They will be used, if no more specific settings could be +# found +#geom_spares="ada2 ada3 ada4" + +# Spares for class "mirror". they will be used only for geom_mirror(8), +# if no more specific setting weill be found +#geom_spares_mirror="da0 da1" + +# Spares for class "raid3", device name "data". +#geom_spares_raid3_data="da2 da3" + +# Spares to replace very specific component in mirror with name "homes" +# This is most-specific form. +#geom_spares_mirror_homes_ada4="ada5 ada6" + +# Disable spares for all geom_raid(8) instances +#geom_spares_raid="" Modified: projects/geom-events/sbin/geom/core/geom.8 ============================================================================== --- projects/geom-events/sbin/geom/core/geom.8 Tue Oct 4 16:53:11 2011 (r225988) +++ projects/geom-events/sbin/geom/core/geom.8 Tue Oct 4 16:54:21 2011 (r225989) @@ -182,6 +182,7 @@ geom md unload .Sh SEE ALSO .Xr libgeom 3 , .Xr geom 4 , +.Xr geom-events 8 , .Xr gcache 8 , .Xr gconcat 8 , .Xr geli 8 , Modified: projects/geom-events/usr.sbin/Makefile ============================================================================== --- projects/geom-events/usr.sbin/Makefile Tue Oct 4 16:53:11 2011 (r225988) +++ projects/geom-events/usr.sbin/Makefile Tue Oct 4 16:54:21 2011 (r225989) @@ -26,6 +26,7 @@ SUBDIR= adduser \ extattrctl \ fifolog \ fwcontrol \ + geom-events \ getfmac \ getpmac \ ggetmode \ Added: projects/geom-events/usr.sbin/geom-events/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/geom-events/Makefile Tue Oct 4 16:54:21 2011 (r225989) @@ -0,0 +1,6 @@ +# $FreeBSD$ + +SCRIPTS=geom-events.sh +MAN= geom-events.conf.5 geom-events.8 + +.include Added: projects/geom-events/usr.sbin/geom-events/geom-events.8 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/geom-events/geom-events.8 Tue Oct 4 16:54:21 2011 (r225989) @@ -0,0 +1,398 @@ +.\" +.\" Copyright (c) 2011 Lev Serebryakov +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 12, 2011 +.Dt GEOM-EVENTS 8 +.Os +.Sh NAME +.Nm geom-events +.Nd command for processing +.Xr geom 4 +events passed to +.Xr devd 8 . +.Sh SYNOPSIS +.Nm +.Ar event-name +.Ar geom-class-name +.Ar geom-name +.Ar provider-name +.Op Ar ... +.Sh DESCRIPTION +The +.Nm +utility is a shell script which processes different events from +.Xr geom 4 +system via +.Xr devd 8 +mechanism. +Its main functions are to notify the administrator about these events +by e-mail, to log such events with +.Xr logger 1 +and to replace failed components with spare drives for +.Xr geom 4 +classes which supports redundancy. +.Pp +Every event has these mandatory attributes, passed as arguments +to +.Nm : +.Bl -tag -width "PROVIDER" -offset indent +.It Ar TYPE +Type of the event. See section +.Sx EVENT_TYPES . +.It Ar CLASS +Class of geom that sends the given event. Class name should be in lower case, +as used in first argument to userland +.Xr geom 8 +utility. +.It Ar GEOM +Name of geom that sends the given event. It is usable as an argument for +various userland utilities like +.Xr gmirror 8 , +.Xr graid3 8 +and more general +.Xr geom 8 . +.It Ar PROVIDER +Name of provider to which the given event is related. Most of geom classes have +only one provider and this attribute is redundant, as it the same as +.Ar GEOM , +maybe prefixed with +.Ar CLASS/ , +but some classes could have more than one providers. Examples of such classes +are +.Xr gpart 8 +and +.Xr graid 8 . +.El +.Sh EVENT TYPES +.Ss DISCONNECT +This event is sent when geom loses one of its components. The component is +a provider of some other geom. +.Pp +This event is +sent only by geoms which use many components. For +example, +.Xr gmirror 8 +sends this message, and +.Xr geli 8 +doens't. +.Pp +Additional attributes passed with this event are +.Va component +and +.Va state . +.Pp +The first one is the name of the disconnected component (provider of +underlying geom). It is a name as it is seen in +.Pa /dev +tree, without +.Pa /dev +prefix itself, like +.Pa ada0 +or +.Pa mirror/gm0 +.Pp +.Va state +is state of geom after disconnection. It could be one of four values: +.Bl -tag -width "FIXABLE" -offset indent +.It Fixable +This state means that geom is accessible (could be read and written) and +the disconnected component could be replaced with a spare drive. In this case, +.Nm +tries to find a configured spare drive and use it to fix geom. +.Pp +This state is typical for geoms which implement volumes +with redundancy, as +.Xr gmirror 8 +and +.Xr graid3 8 +.It Alive +This state means that geom is accessible, but maybe not fully-functional, or +no automatic replacement is possible, and operator needs to perform some manual +operations to be sure that the disconnection is repaired. +.Pp +This state is typical for geoms which implement volumes +without redundancy, like +.Xr gstripe 8 . +.It Dead +This state means that geom's provider is completely destroyed by the +disconnection and will be removed from system. +.El +.Pp +.Nm +tries to replace disconnected component in fixable cases. List of +spare components should be configured in config files (see +.Sx CONFIGURATION ) . +.Pp +.Nm +checks every configured spare drive with +.Xr ggetmode 8 +utility to ensure that the drive isn't used. +.Pp +It then +tries to remove the failed component from geom, if configured to do so by +.Va geom_remove_verb_ Ns Ao Ar class Ac +variable. +By default, no removal command is called. +.Pp +After that, +.Nm +calls shell command to insert the new +component into array. Default command is +.Bd -literal -offset indent +/sbin/g${class} insert ${geom} ${spare} +.Ed +.Pp +and after parameter substitution looks like this: +.Bd -literal -offset indent +/sbin/gmirror insert data ada12 +.Ed +.Pp +This command could be configured, see +variable +.Va geom_remove_verb_ Ns Ao Ar class Ac +in +.Sx CONFIGURATION +section. +.Pp +.Nm +repeats trying till success or end of available spare drives. +.Pp +If +.Va geom_events_notify +variable is set, +.Nm +sents e-mail to the specified address with report about +a component disconnection and all oprations with spare drives, +including configured list, availiable drives and the result +of the insert command. +.Pp +Message for +.Xr syslogd 8 +includes class and name of device, +disconnected component, status of device (whether disconnect was fatal or not) +and the result of the component replacement, if one succeeded. +.Pp +Manual component removals should not trigger this event. +.Ss SYNCSTART +This event is sent when geom starts rebuilding parity or synchronization +of the volume. No additional parameters are passed. +.Pp +.Nm +sents mail and/or logs this event with +.Xr syslogd 8 +if configured to do so. +.Pp +Manual request for rebuilding or synchronization will trigger this +event, as here is no way to distinguish the reason for rebuilding +in most cases. +.Ss SYNCSTOP +This event is sent when geom stops rebuilding parity or synchronization +of the volume. One additional parameter is passed which indicates +whether synchronization was finished successfully or not. +.Pp +.Nm +sents mail and/or logs this event with +.Xr syslogd 8 +if configured to do so. The message includes the name of the device and +the reason for stopping. +.Pp +Manual request for abort of rebuilding will trigger this +event, as here is no way to distinguish reason of stopping in +most cases. +.Ss DESTROYED +This event is sent when geom destroys its provider due to errors. +.Pp +.Nm +sents mail and/or logs this event with +.Xr syslogd 8 +if configured to do so. Message includes only name of device. +.Pp +Manual request for geom removal will not trigger this +event. +.Ss UNKNOWN EVENTS +All unknown events are reported by e-mail and logged to system log with +.Xr logger 1 +if configured to do so. Reported information includes class and name of device +and name of event. +.Sh CONFIGURATION +The +.Nm +utility reads its configuration information from several files. +The main configuration file which is always read, if it is present, is +.Pa /etc/geom-events.conf . +After that, +.Nm +determines which class and device has sent event and reads these files +in this particular order: +.Bl -enum -offset indent -compact +.It +.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf +.It +.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf +.It +.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar geom Ac Ns Pa .conf +.It +.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar geom Ac Ns Pa .conf +.El +These files are read as any +.Pa rc.conf - like +configuration files by sourcing them into script. +.Pp +.Nm +uses these variabels from this config files: +.Bl -tag -width indent-two +.It Va geom_events_notify +.Pq Vt str +Set to e-mail for sending notifications about events to. If it is left empty +or unset, no e-mail notifications will be sent. +.It Va geom_events_log +.Pq Vt bool +If set to +.Dq Li YES , +enables logging events with +.Xr logger 1 +.It Va geom_insert_cmd_ Ns Ao Ar class Ac +.Pq Vt str +Set to +.Xr sh 1 +command is used instead of the default one when +.Nm +tries to replace the disconnected component. If no +variable is set for given class, default +.Ql /sbin/g${class} insert ${geom} ${spare} +is used. +.Pp +This command could contain references to special +shell variables +.Va ${class} , ${geom} , ${provider} +and +.Va ${spare} +which will be substituted at execution time. Please note that +configuration file is a shell script by itsef, so you need +to quote commandcontaining variables with single quotes or escape +varaible references with backslashes. +.It Va geom_remove_cmd_ Ns Ao Ar class Ac +.Pq Vt str +Set to +.Xr sh 1 +command which should be used by +.Nm +to completely remove the failed component from geom +before replacing it with a spare. By default, no such command +is configured and no removal is performed. +.Pp +This command could contain references to special +shell variables +.Va ${class} , ${geom} , ${provider} +and +.Va ${failed} +which will be substituted at execution time. Same precautions should +be used as with +.Va geom_remove_cmd_ Ns Ao Ar class Ac . +.It Va geom_spares +.Pq Vt str +Set to list of spare drives (or other geom providers) to use. This is the most +non-specific list. +.Nm +will use more sepcific spare lists if they are configured. +.It Va geom_spares_ Ns Ao Ar class Ac +.Pq Vt str +Set to list of spare drivers (or other geom providers) to use when +.Nm +needs to replace the disconnected component in geom with class +.Aq Ar class . +.Pp +Could be overwritten for specific geom instance. +.It Va geom_spares_ Ns Ao Ar class Ac Ns Va _ Ns Ao Ar geom Ac +.Pq Vt str +Set to list of spare drivers (or other geom providers) to use when +.Nm +needs to replace the disconnected component in geom with class +.Aq Ar class +and name +.Aq Ar geom . +.It Va geom_spares_ Ns Ao Ar class Ac Ns Va _ Ns Ao Ar geom Ac _ Ns Ao Ar component Ac +.Pq Vt str +Set to list of the spare drivers (or other geom providers) to use when +.Nm +needs to replace disconnected component with name +.Aq Ar component +in geom with class +.Aq Ar class +and name +.Aq Ar geom . +.El +.Pp +.Nm +selects the most specific variable for spare devices. The variable is +selected if it is set. An empty variable counts as a set one. +.Pp +If your have such configuration: +.Bd -literal -offset indent +geom_spares_raid3="ada2 ada3" +geom_spares_raid3_test="" +.Ed +.Pp +.Nm +will select +.Qq ada2 ada3 +as spare list for any +.Em raid3 +geom except one, named +.Em test . +And +.Em raid3 +geom +.Em test +will have no spare drives configured. +.Pp +Please note that +.Nm +doesn't distinguish source file of configuration variables. So, more specific +variables could be placed in less specific config files and will be choosen by +.Nm Ns . +.Pp +When variable name is constructed from geom or component name, all characters +which could not be used in a variable names, are replaced with underscores. +.Sh FILES +.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf +.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf +.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar geom Ac Ns Pa .conf +.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar geom Ac Ns Pa .conf +.Sh SEE ALSO +.Xr geom-events 8 , +.Xr devd 8 , +.Xr geom 8 , +.Xr geom 4 +.Sh HISTORY +The +.Nm +utility and manual page first appeared in +.Fx 10.0 . +.Sh AUTHORS +This utility and manual page was written by +.An Lev Serebryakov Aq lev@FreeBSD.org . Added: projects/geom-events/usr.sbin/geom-events/geom-events.conf.5 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/geom-events/geom-events.conf.5 Tue Oct 4 16:54:21 2011 (r225989) @@ -0,0 +1,70 @@ +.\" +.\" Copyright (c) 2011 Lev Serebryakov +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD$ +.\" +.Dd September 12, 2011 +.Dt GEOM-EVENTS.CONF 5 +.Os +.Sh NAME +.Nm geom-events.conf +.Nd +.Xr geom-events 8 +configuration file +.Sh DESCRIPTION +The +.Bl -item -compact +.It +.Pa /etc/geom-events.conf +.It +.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf +.It +.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa .conf +.It +.Pa /etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar device Ac Ns Pa .conf +.It +.Pa /usr/local/etc/geom-events/ Ns Ao Ar class Ac Ns Pa / Ns Ao Ar device Ac Ns Pa .conf +.El +.Pp +configuration files contains configuration for +.Xr geom-events 8 +script. Exact description of how they are processed, +please see in +.Sx CONFIGURATION +section of +.Xr geom-events 8 +.Sh SEE ALSO +.Xr geom-events 8 , +.Xr devd 8 , +.Xr geom 8 , +.Xr geom 4 +.Sh HISTORY +The +.Nm +manual page first appeared in +.Fx 10.0 . +.Sh AUTHORS +This manual page was written by +.An Lev Serebryakov Aq lev@FreeBSD.org . Added: projects/geom-events/usr.sbin/geom-events/geom-events.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/geom-events/usr.sbin/geom-events/geom-events.sh Tue Oct 4 16:54:21 2011 (r225989) @@ -0,0 +1,298 @@ +#!/bin/sh +# +# Copyright (c) 2011 Lev Serebryakov . All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# $FreeBSD$ +# + +# usage: geom-events [...] - process +# event. +# + +usage () { + echo "usage: $0 $1" 1>&2 + exit 1 +} + +event_DISCONNECT () { + local component state removecmd insertcmd repls repla replr replu replb remfm replfm msg _err _i _gm + if [ $# -ne 2 ] ; then + usage " " + fi + component=$1 + state=$2 + if [ "${state}" = 'F' ] ; then + # Get removal/forget command for class, no default + removecmd=`get_var geom_remove_cmd ${CLASS}` + + # Get insert command for class, with resonable default + insertcmd=`get_var geom_insert_cmd ${CLASS}` + [ -z "${insertcmd}" ] && insertcmd='/sbin/g${class} insert ${geom} ${spare}' + + # Search for ready-to-use spare providers + repla=`get_var geom_spares ${CLASS} ${GEOM} ${component}` + for _i in ${repla} ; do + _gm=`/usr/sbin/ggetmode ${_i} 2> /dev/null` + if [ $? -ne 0 ] ; then + replu="${replu} ${_i}" + elif [ "${_gm}" != "r0w0e0" ] ; then + replb="${replb} ${_i}" + else + replr="${replr} ${_i}" + fi + done + + # Remove old component, if needed + if [ -n "${removecmd}" ] ; then + _err=`/usr/bin/env -i class=${CLASS} geom=${GEOM} provider=${PROVIDER} failed=${component} \ + /bin/sh -c "${removecmd}"` + [ $? -ne 0 ] && remfm="${_err}" + fi + # Try insert command for any availiable pare till success + for _i in ${replr} ; do + _err=`/usr/bin/env -i class=${CLASS} geom=${GEOM} provider=${PROVIDER} spare=${_i} \ + /bin/sh -c "${insertcmd}"` + if [ $? -eq 0 ] ; then + repls=${_i} + break + fi + replfm="${replfm}|${_i} - ${_err}" + done + fi + # Write line to log, if configured + if check_yesno geom_events_log ; then + msg="${CLASS} ${GEOM}:${PROVIDER} lost component ${component}" + case "${state}" in + 'D') + msg="${msg} (fatal)" + ;; + 'A') + msg="${msg} (not fatal)" + ;; + 'F') + msg="${msg} (fixable)" + ;; + '?') + msg="${msg} (unknown)" + ;; + *) + msg="${msg} (invalid status: ${fatal})" + ;; + esac + [ -n "${repls}" ] && msg="${msg}, replaced with ${repls}" + /usr/bin/logger -t GEOM "${msg}" + + fi + # Send mail to user, if configured + if [ -n "${geom_events_notify}" ] ; then + ( + echo "${CLASS} device ${GEOM}:${PROVIDER} lost component ${component}" + case "${state}" in + 'D') + echo "It is fatal for ${PROVIDER} and it died. No replacement of disconnected component was possible." + ;; + 'A') + echo "It is non-fatal for ${PROVIDER}, but replacement of disconnected component is not possible." + ;; + 'F') + echo "It is non-fatal for ${PROVIDER}. Replacement of disconnected component is possible." + if [ -n "${repla}" ] ; then + echo "Spare drives were configured for this device: ${repla}." + if [ -n "${repls}" ] ; then + echo "Disconnected component was replaced with ${repls}." + else + echo "Replacement of disconnected component failed." + fi + [ -n "${replu}" ] && echo "Spare drives with unknown status: ${replu}" + [ -n "${replb}" ] && echo "Busy spare drives: ${replb}" + [ -n "${remfm}" ] && echo "Removal of disconnected component failed: ${remfm}" + if [ -n "${replfm}" ] ; then + echo "Failed replacements trys:" + echo "${replfm}" | tr \| \\n + fi + else + echo "Spare drive was not configured for this device." + fi + ;; + '?') + echo "${PROVIDER} has unknown status, replacement of disconnected component is not possible." + ;; + *) + echo "${PROVIDER} has invalid status ${state}, replacement of disconnected component is not possible." + ;; + esac + ) | mail -s "${CLASS} ${GEOM}:${PROVIDER} lost component ${component}" ${geom_events_notify} + fi +} + +event_SYNCSTART () { + if [ $# -ne 0 ] ; then + usage + fi + # Write line to log, if configured + if check_yesno geom_events_log ; then + /usr/bin/logger -t GEOM "${CLASS} ${GEOM}:${PROVIDER} starts rebuilding" + fi + # Send mail to user, if configured + if [ -n "${geom_events_notify}" ] ; then + ( + echo "${CLASS} ${GEOM}:${PROVIDER} starts rebuilding or synchronization" + ) | mail -s "${CLASS} ${GEOM}:${PROVIDER} starts rebuilding" ${geom_events_notify} + fi +} + +event_SYNCSTOP () { + local stopact + if [ $# -ne 1 ] ; then + usage "" + fi + if [ "$1" = 'Y' ] ; then + stopact="finished" + else + stopact="aborted" + fi + # Write line to log, if configured + if check_yesno geom_events_log ; then + /usr/bin/logger -t GEOM "Rebuilding of ${CLASS} ${GEOM}:${PROVIDER} ${stopact}" + fi + # Send mail to user, if configured + if [ -n "${geom_events_notify}" ] ; then + ( + echo "Rebuilding or synchronization of ${CLASS} ${GEOM}:${PROVIDER} ${stopact}" + ) | mail -s "Rebuilding of ${CLASS} ${GEOM}:${PROVIDER} ${stopact}" ${geom_events_notify} + fi +} + +event_DESTROYED () { + if [ $# -ne 0 ] ; then + usage + fi + # Write line to log, if configured + if check_yesno geom_events_log ; then + /usr/bin/logger -t GEOM "${CLASS} ${GEOM}:${PROVIDER} destroyed" + fi + # Send mail to user, if configured + if [ -n "${geom_events_notify}" ] ; then + ( + echo "${CLASS} ${GEOM}:${PROVIDER} destroyed" + ) | mail -s "${CLASS} ${GEOM}:${PROVIDER} destroyed" ${geom_events_notify} + fi +} + +event_UNKNOWN () { + local msg + msg="Unknown event ${EVENT} was sent by GEOM class ${CLASS}, device ${GEOM}:${PROVIDER}" + check_yesno geom_events_log && /usr/bin/logger -t GEOM "${msg}" + [ -n "${geom_events_notify}" ] && echo "${msg}" | \ + mail -s "${CLASS} ${GEOM}:${PROVIDER} sent event ${EVENT}" ${geom_events_notify} +} + +normalize_name () { + echo -n $1 | /usr/bin/tr -c "_a-zA-Z0-9" _ +} + +copy_var_if_unset_and_set () { + local to from _unset + to=$1 + from=$2 + eval _unset=\${${to}-__UNSET__} + [ "${_unset}" != "__UNSET__" ] && return + eval _unset=\${${from}-__UNSET__} + [ "${_unset}" != "__UNSET__" ] && eval $to=\${${from}} +} + +get_var () { + local name class device component val _n _unset + name=`normalize_name $1` + class=`normalize_name $2` + geom=`normalize_name $3` + component=`normalize_name $4` + [ "${component}" = '_unknown_' ] && component="" + if [ -n "${class}" ] ; then + if [ -n "${geom}" ] ; then + if [ -n "${component}" ] ; then + copy_var_if_unset_and_set val "${name}_${class}_${geom}_${component}" + fi + copy_var_if_unset_and_set val "${name}_${class}_${geom}" + fi + copy_var_if_unset_and_set val "${name}_${class}" + fi + copy_var_if_unset_and_set val "${name}" + echo "${val}" +} + +check_yesno() +{ + eval _value=\$${1} + case $_value in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + return 0 + ;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) + return 1 + ;; + *) + return 1 + ;; + esac +} + +if [ $# -lt 4 ] ; then + usage "[...]" +fi + +# Set three variables, which should be set for any event +EVENT=$1 ; shift +CLASS=$1 ; shift +GEOM=$1 ; shift +PROVIDER=$1 ; shift + +# Include generic configuration +[ -r /etc/geom-events.conf ] && . /etc/geom-events.conf + +# Include class-specific configuration +[ -r /etc/geom-events.d/${CLASS}.conf ] && . /etc/geom-events.d/${CLASS}.conf +[ -r /usr/local/etc/geom-events.d/${CLASS}.conf ] && . /usr/local/etc/geom-events.d/${CLASS}.conf + +# Include class- and geom-specific configuration +[ -r /etc/geom-events.d/${CLASS}/${GEOM}.conf ] && . /etc/geom-events.d/${CLASS}/${GEOM}.conf +[ -r /usr/local/etc/geom-events.d/${CLASS}/${GEOM}.conf ] && . /usr/local/etc/geom-events.d/${CLASS}/${GEOM}.conf + +# Ok, process events +case ${EVENT} in + DISCONNECT) + event_DISCONNECT "$@" + ;; + SYNCSTART) + event_SYNCSTART "$@" + ;; + SYNCSTOP) + event_SYNCSTOP "$@" + ;; + DESTROYED) + event_DESTROYED "$@" + ;; + *) + event_UNKNOWN "$@" + ;; +esac From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 16:59:52 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0AFD5106564A; Tue, 4 Oct 2011 16:59:52 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EEE6C8FC0C; Tue, 4 Oct 2011 16:59:51 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94Gxp64067877; Tue, 4 Oct 2011 16:59:51 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94Gxpdn067875; Tue, 4 Oct 2011 16:59:51 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041659.p94Gxpdn067875@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 16:59:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225992 - projects/geom-events/sys/geom/bde X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 16:59:52 -0000 Author: lev (ports committer) Date: Tue Oct 4 16:59:51 2011 New Revision: 225992 URL: http://svn.freebsd.org/changeset/base/225992 Log: Add g_notify_*() calls to geom_bde Modified: projects/geom-events/sys/geom/bde/g_bde.c Modified: projects/geom-events/sys/geom/bde/g_bde.c ============================================================================== --- projects/geom-events/sys/geom/bde/g_bde.c Tue Oct 4 16:58:20 2011 (r225991) +++ projects/geom-events/sys/geom/bde/g_bde.c Tue Oct 4 16:59:51 2011 (r225992) @@ -88,6 +88,9 @@ g_bde_orphan(struct g_consumer *cp) sc = gp->softc; gp->flags |= G_GEOM_WITHER; error = cp->provider->error; + + g_notify_destroyed(LIST_FIRST(&gp->provider)); + LIST_FOREACH(pp, &gp->provider, provider) g_orphan_provider(pp, error); bzero(sc, sizeof(struct g_bde_softc)); /* destroy evidence */ From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:00:26 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 490351065672; Tue, 4 Oct 2011 17:00:26 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 38CBF8FC12; Tue, 4 Oct 2011 17:00:26 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H0Qtr068018; Tue, 4 Oct 2011 17:00:26 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H0QiD068016; Tue, 4 Oct 2011 17:00:26 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041700.p94H0QiD068016@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:00:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225993 - projects/geom-events/sys/geom/cache X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:00:26 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:00:25 2011 New Revision: 225993 URL: http://svn.freebsd.org/changeset/base/225993 Log: Add g_notify_*() calls to geom_cache Modified: projects/geom-events/sys/geom/cache/g_cache.c Modified: projects/geom-events/sys/geom/cache/g_cache.c ============================================================================== --- projects/geom-events/sys/geom/cache/g_cache.c Tue Oct 4 16:59:51 2011 (r225992) +++ projects/geom-events/sys/geom/cache/g_cache.c Tue Oct 4 17:00:25 2011 (r225993) @@ -444,8 +444,8 @@ g_cache_access(struct g_provider *pp, in static void g_cache_orphan(struct g_consumer *cp) { - g_topology_assert(); + g_notify_destroyed(LIST_FIRST(&cp->geom->provider)); g_cache_destroy(cp->geom->softc, 1); } From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:00:39 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EBAD4106566B; Tue, 4 Oct 2011 17:00:39 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DBBFC8FC1A; Tue, 4 Oct 2011 17:00:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H0d0b068089; Tue, 4 Oct 2011 17:00:39 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H0d0i068087; Tue, 4 Oct 2011 17:00:39 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041700.p94H0d0i068087@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:00:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225994 - projects/geom-events/sys/geom/concat X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:00:40 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:00:39 2011 New Revision: 225994 URL: http://svn.freebsd.org/changeset/base/225994 Log: Add g_notify_*() calls to geom_concat Modified: projects/geom-events/sys/geom/concat/g_concat.c Modified: projects/geom-events/sys/geom/concat/g_concat.c ============================================================================== --- projects/geom-events/sys/geom/concat/g_concat.c Tue Oct 4 17:00:25 2011 (r225993) +++ projects/geom-events/sys/geom/concat/g_concat.c Tue Oct 4 17:00:39 2011 (r225994) @@ -154,11 +154,19 @@ g_concat_orphan(struct g_consumer *cp) disk = cp->private; if (disk == NULL) /* Possible? */ return; + + g_notify_disconnect(sc->sc_provider, cp, + ((g_concat_nvalid(sc) == 1)? + G_NOTIFY_DISCONNECT_DEAD: + G_NOTIFY_DISCONNECT_ALIVE)); + g_concat_remove_disk(disk); /* If there are no valid disks anymore, remove device. */ - if (g_concat_nvalid(sc) == 0) + if (g_concat_nvalid(sc) == 0) { + g_notify_destroyed(sc->sc_provider); g_concat_destroy(sc, 1); + } } static int From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:00:52 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 34B6F106564A; Tue, 4 Oct 2011 17:00:52 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 24DA58FC0C; Tue, 4 Oct 2011 17:00:52 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H0q9h068171; Tue, 4 Oct 2011 17:00:52 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H0qSe068169; Tue, 4 Oct 2011 17:00:52 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041700.p94H0qSe068169@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:00:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225996 - projects/geom-events/sys/geom/eli X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:00:52 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:00:51 2011 New Revision: 225996 URL: http://svn.freebsd.org/changeset/base/225996 Log: Add g_notify_*() calls to geom_eli Modified: projects/geom-events/sys/geom/eli/g_eli.c Modified: projects/geom-events/sys/geom/eli/g_eli.c ============================================================================== --- projects/geom-events/sys/geom/eli/g_eli.c Tue Oct 4 17:00:50 2011 (r225995) +++ projects/geom-events/sys/geom/eli/g_eli.c Tue Oct 4 17:00:51 2011 (r225996) @@ -250,6 +250,7 @@ g_eli_orphan(struct g_consumer *cp) sc = cp->geom->softc; if (sc == NULL) return; + g_notify_destroyed(LIST_FIRST(&cp->geom->provider)); g_eli_destroy(sc, TRUE); } From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:01:06 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 26ED71065672; Tue, 4 Oct 2011 17:01:06 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 171928FC16; Tue, 4 Oct 2011 17:01:06 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H15M4068239; Tue, 4 Oct 2011 17:01:05 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H15Gc068237; Tue, 4 Oct 2011 17:01:05 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041701.p94H15Gc068237@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:01:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225997 - projects/geom-events/sys/geom X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:01:06 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:01:05 2011 New Revision: 225997 URL: http://svn.freebsd.org/changeset/base/225997 Log: Add g_notify_*() calls to geom_aes Modified: projects/geom-events/sys/geom/geom_aes.c Modified: projects/geom-events/sys/geom/geom_aes.c ============================================================================== --- projects/geom-events/sys/geom/geom_aes.c Tue Oct 4 17:00:51 2011 (r225996) +++ projects/geom-events/sys/geom/geom_aes.c Tue Oct 4 17:01:05 2011 (r225997) @@ -246,6 +246,7 @@ g_aes_orphan(struct g_consumer *cp) gp = cp->geom; sc = gp->softc; + g_notify_destroyed(LIST_FIRST(&gp->provider)); g_wither_geom(gp, cp->provider->error); bzero(sc, sizeof(struct g_aes_softc)); /* destroy evidence */ g_free(sc); From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:01:19 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B7B391065676; Tue, 4 Oct 2011 17:01:19 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A7DE28FC1C; Tue, 4 Oct 2011 17:01:19 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H1JU0068312; Tue, 4 Oct 2011 17:01:19 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H1JU4068310; Tue, 4 Oct 2011 17:01:19 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041701.p94H1JU4068310@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:01:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225998 - projects/geom-events/sys/geom X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:01:19 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:01:19 2011 New Revision: 225998 URL: http://svn.freebsd.org/changeset/base/225998 Log: Add g_notify_*() calls to geom_fox Modified: projects/geom-events/sys/geom/geom_fox.c Modified: projects/geom-events/sys/geom/geom_fox.c ============================================================================== --- projects/geom-events/sys/geom/geom_fox.c Tue Oct 4 17:01:05 2011 (r225997) +++ projects/geom-events/sys/geom/geom_fox.c Tue Oct 4 17:01:19 2011 (r225998) @@ -181,7 +181,12 @@ g_fox_orphan(struct g_consumer *cp) mark = 0; } mtx_unlock(&sc->lock); - + + g_notify_disconnect(LIST_FIRST(&gp->provider), cp, + (LIST_NEXT(LIST_FIRST(&gp->consumer), consumer) == NULL)? + G_NOTIFY_DISCONNECT_DEAD: + G_NOTIFY_DISCONNECT_ALIVE); + g_access(cp, -cp->acr, -cp->acw, -cp->ace); error = cp->provider->error; g_detach(cp); @@ -191,6 +196,7 @@ g_fox_orphan(struct g_consumer *cp) g_post_event(g_fox_select_path, gp, M_WAITOK, gp, NULL); return; } + g_notify_destroyed(LIST_FIRST(&gp->provider)); mtx_destroy(&sc->lock); g_free(gp->softc); From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:01:31 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EEBC310657F1; Tue, 4 Oct 2011 17:01:31 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DE3458FC1A; Tue, 4 Oct 2011 17:01:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H1VqQ068385; Tue, 4 Oct 2011 17:01:31 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H1VWH068383; Tue, 4 Oct 2011 17:01:31 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041701.p94H1VWH068383@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:01:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225999 - projects/geom-events/sys/geom/journal X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:01:32 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:01:31 2011 New Revision: 225999 URL: http://svn.freebsd.org/changeset/base/225999 Log: Add g_notify_*() calls to geom_journal Modified: projects/geom-events/sys/geom/journal/g_journal.c Modified: projects/geom-events/sys/geom/journal/g_journal.c ============================================================================== --- projects/geom-events/sys/geom/journal/g_journal.c Tue Oct 4 17:01:19 2011 (r225998) +++ projects/geom-events/sys/geom/journal/g_journal.c Tue Oct 4 17:01:31 2011 (r225999) @@ -393,6 +393,11 @@ g_journal_orphan(struct g_consumer *cp) sc = cp->geom->softc; strlcpy(name, cp->provider->name, sizeof(name)); GJ_DEBUG(0, "Lost provider %s.", name); + + /* Notify */ + g_notify_disconnect(LIST_FIRST(&sc->sc_geom->provider), cp, G_NOTIFY_DISCONNECT_DEAD); + g_notify_destroyed(LIST_FIRST(&sc->sc_geom->provider)); + if (sc == NULL) return; error = g_journal_destroy(sc); From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:01:45 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C91621065673; Tue, 4 Oct 2011 17:01:45 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 804828FC08; Tue, 4 Oct 2011 17:01:45 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H1jt8068464; Tue, 4 Oct 2011 17:01:45 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H1jrG068462; Tue, 4 Oct 2011 17:01:45 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041701.p94H1jrG068462@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:01:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226000 - projects/geom-events/sys/geom/label X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:01:45 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:01:45 2011 New Revision: 226000 URL: http://svn.freebsd.org/changeset/base/226000 Log: Add g_notify_*() calls to geom_label Modified: projects/geom-events/sys/geom/label/g_label.c Modified: projects/geom-events/sys/geom/label/g_label.c ============================================================================== --- projects/geom-events/sys/geom/label/g_label.c Tue Oct 4 17:01:31 2011 (r225999) +++ projects/geom-events/sys/geom/label/g_label.c Tue Oct 4 17:01:45 2011 (r226000) @@ -109,6 +109,7 @@ g_label_orphan(struct g_consumer *cp) G_LABEL_DEBUG(1, "Label %s removed.", LIST_FIRST(&cp->geom->provider)->name); + g_notify_destroyed(LIST_FIRST(&cp->geom->provider)); g_slice_orphan(cp); } From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:01:58 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A7DEE106578A; Tue, 4 Oct 2011 17:01:58 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 97D998FC17; Tue, 4 Oct 2011 17:01:58 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H1wgF068535; Tue, 4 Oct 2011 17:01:58 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H1w5H068533; Tue, 4 Oct 2011 17:01:58 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041701.p94H1w5H068533@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:01:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226001 - projects/geom-events/sys/geom/linux_lvm X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:01:58 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:01:58 2011 New Revision: 226001 URL: http://svn.freebsd.org/changeset/base/226001 Log: Add g_notify_*() calls to geom_linux_lvm Modified: projects/geom-events/sys/geom/linux_lvm/g_linux_lvm.c Modified: projects/geom-events/sys/geom/linux_lvm/g_linux_lvm.c ============================================================================== --- projects/geom-events/sys/geom/linux_lvm/g_linux_lvm.c Tue Oct 4 17:01:45 2011 (r226000) +++ projects/geom-events/sys/geom/linux_lvm/g_linux_lvm.c Tue Oct 4 17:01:58 2011 (r226001) @@ -332,6 +332,11 @@ g_llvm_remove_disk(struct g_llvm_vg *vg, } } if (found) { + g_notify_disconnect(lv->lv_gprov, cp, + G_NOTIFY_DISCONNECT_DEAD); + /* We always destroy whole LVM after disc removal */ + g_notify_destroyed(lv->lv_gprov); + G_LLVM_DEBUG(0, "Device %s removed.", lv->lv_gprov->name); g_orphan_provider(lv->lv_gprov, ENXIO); From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:02:11 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 19148106564A; Tue, 4 Oct 2011 17:02:11 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 08E438FC13; Tue, 4 Oct 2011 17:02:11 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H2AVs068613; Tue, 4 Oct 2011 17:02:10 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H2Aeu068611; Tue, 4 Oct 2011 17:02:10 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041702.p94H2Aeu068611@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:02:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226002 - projects/geom-events/sys/geom/mirror X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:02:11 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:02:10 2011 New Revision: 226002 URL: http://svn.freebsd.org/changeset/base/226002 Log: Add g_notify_*() calls to geom_mirror Modified: projects/geom-events/sys/geom/mirror/g_mirror.c Modified: projects/geom-events/sys/geom/mirror/g_mirror.c ============================================================================== --- projects/geom-events/sys/geom/mirror/g_mirror.c Tue Oct 4 17:01:58 2011 (r226001) +++ projects/geom-events/sys/geom/mirror/g_mirror.c Tue Oct 4 17:02:10 2011 (r226002) @@ -1998,6 +1998,8 @@ g_mirror_sync_stop(struct g_mirror_disk G_MIRROR_DEBUG(0, "Device %s: rebuilding provider %s stopped.", sc->sc_name, g_mirror_get_diskname(disk)); } + g_notify_sync_stop(sc->sc_provider, !type); + free(disk->d_sync.ds_bios, M_MIRROR); disk->d_sync.ds_bios = NULL; cp = disk->d_sync.ds_consumer; @@ -2353,6 +2355,7 @@ g_mirror_update_device(struct g_mirror_s * No active disks or no disks at all, * so destroy device. */ + g_notify_destroyed(sc->sc_provider); if (sc->sc_provider != NULL) g_mirror_destroy_provider(sc); sc->sc_flags |= G_MIRROR_DEVICE_FLAG_DESTROY; @@ -2529,6 +2532,9 @@ again: g_mirror_disk_state2str(disk->d_state))); DISK_STATE_CHANGED(); + /* Send notification */ + g_notify_sync_start(sc->sc_provider); + if (disk->d_state == G_MIRROR_DISK_STATE_NEW) disk->d_flags &= ~G_MIRROR_DISK_FLAG_DIRTY; disk->d_state = state; @@ -2580,6 +2586,11 @@ again: G_MIRROR_DEBUG(0, "Device %s: provider %s disconnected.", sc->sc_name, g_mirror_get_diskname(disk)); + g_notify_disconnect(sc->sc_provider, disk->d_consumer, + ((g_mirror_ndisks(sc, -1) == 1)? + G_NOTIFY_DISCONNECT_DEAD: + G_NOTIFY_DISCONNECT_FIXABLE)); + g_mirror_destroy_disk(disk); break; case G_MIRROR_DISK_STATE_DESTROY: From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:02:23 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DE2B5106564A; Tue, 4 Oct 2011 17:02:23 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CE35E8FC16; Tue, 4 Oct 2011 17:02:23 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H2Nwu068686; Tue, 4 Oct 2011 17:02:23 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H2NO6068684; Tue, 4 Oct 2011 17:02:23 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041702.p94H2NO6068684@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:02:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226003 - projects/geom-events/sys/geom/mountver X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:02:24 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:02:23 2011 New Revision: 226003 URL: http://svn.freebsd.org/changeset/base/226003 Log: Add g_notify_*() calls to geom_mountver Modified: projects/geom-events/sys/geom/mountver/g_mountver.c Modified: projects/geom-events/sys/geom/mountver/g_mountver.c ============================================================================== --- projects/geom-events/sys/geom/mountver/g_mountver.c Tue Oct 4 17:02:10 2011 (r226002) +++ projects/geom-events/sys/geom/mountver/g_mountver.c Tue Oct 4 17:02:23 2011 (r226003) @@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$"); #include #include +FEATURE(geom_mountver, "GEOM mountver support"); SYSCTL_DECL(_kern_geom); SYSCTL_NODE(_kern_geom, OID_AUTO, mountver, CTLFLAG_RW, @@ -454,6 +455,9 @@ g_mountver_orphan(struct g_consumer *cp) g_access(cp, -cp->acr, -cp->acw, -cp->ace); g_detach(cp); G_MOUNTVER_DEBUG(0, "%s is offline. Mount verification in progress.", sc->sc_provider_name); + + g_notify_disconnect(LIST_FIRST(&cp->geom->provider), cp, + G_NOTIFY_DISCONNECT_ALIVE); } static int From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:02:36 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0ACC1106567C; Tue, 4 Oct 2011 17:02:36 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EEC378FC12; Tue, 4 Oct 2011 17:02:35 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H2ZkE068748; Tue, 4 Oct 2011 17:02:35 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H2ZSa068746; Tue, 4 Oct 2011 17:02:35 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041702.p94H2ZSa068746@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:02:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226004 - projects/geom-events/sys/geom/multipath X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:02:36 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:02:35 2011 New Revision: 226004 URL: http://svn.freebsd.org/changeset/base/226004 Log: Add g_notify_*() calls to geom_multipath Modified: projects/geom-events/sys/geom/multipath/g_multipath.c Modified: projects/geom-events/sys/geom/multipath/g_multipath.c ============================================================================== --- projects/geom-events/sys/geom/multipath/g_multipath.c Tue Oct 4 17:02:23 2011 (r226003) +++ projects/geom-events/sys/geom/multipath/g_multipath.c Tue Oct 4 17:02:35 2011 (r226004) @@ -188,6 +188,10 @@ g_multipath_done_error(struct bio *bp) cp->index |= MP_POSTED; g_post_event(g_mpd, cp, M_NOWAIT, NULL); } + + /* It is fixable in any case, as multipath never destroy itself */ + g_notify_disconnect(sc->pp, cp, G_NOTIFY_DISCONNECT_FIXABLE); + if (cp == sc->cp_active) { struct g_consumer *lcp; printf("GEOM_MULTIPATH: %s failed in %s\n", From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:02:49 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8EA2A106566B; Tue, 4 Oct 2011 17:02:49 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7E8D08FC16; Tue, 4 Oct 2011 17:02:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H2nv6068818; Tue, 4 Oct 2011 17:02:49 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H2naN068816; Tue, 4 Oct 2011 17:02:49 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041702.p94H2naN068816@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:02:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226005 - projects/geom-events/sys/geom/nop X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:02:49 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:02:49 2011 New Revision: 226005 URL: http://svn.freebsd.org/changeset/base/226005 Log: Add g_notify_*() calls to geom_nop Modified: projects/geom-events/sys/geom/nop/g_nop.c Modified: projects/geom-events/sys/geom/nop/g_nop.c ============================================================================== --- projects/geom-events/sys/geom/nop/g_nop.c Tue Oct 4 17:02:35 2011 (r226004) +++ projects/geom-events/sys/geom/nop/g_nop.c Tue Oct 4 17:02:49 2011 (r226005) @@ -68,6 +68,7 @@ g_nop_orphan(struct g_consumer *cp) { g_topology_assert(); + g_notify_destroyed(LIST_FIRST(&cp->geom->provider)); g_nop_destroy(cp->geom, 1); } From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:03:01 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EABD41065670; Tue, 4 Oct 2011 17:03:01 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DAB1E8FC0C; Tue, 4 Oct 2011 17:03:01 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H31vA068869; Tue, 4 Oct 2011 17:03:01 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H3132068867; Tue, 4 Oct 2011 17:03:01 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041703.p94H3132068867@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:03:01 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226006 - projects/geom-events/sys/geom/shsec X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:03:02 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:03:01 2011 New Revision: 226006 URL: http://svn.freebsd.org/changeset/base/226006 Log: Add g_notify_*() calls to geom_shsec Modified: projects/geom-events/sys/geom/shsec/g_shsec.c Modified: projects/geom-events/sys/geom/shsec/g_shsec.c ============================================================================== --- projects/geom-events/sys/geom/shsec/g_shsec.c Tue Oct 4 17:02:49 2011 (r226005) +++ projects/geom-events/sys/geom/shsec/g_shsec.c Tue Oct 4 17:03:01 2011 (r226006) @@ -180,10 +180,17 @@ g_shsec_orphan(struct g_consumer *cp) if (sc == NULL) return; + g_notify_disconnect(sc->sc_provider, cp, + ((g_shsec_nvalid(sc) > 1)? + G_NOTIFY_DISCONNECT_ALIVE: + G_NOTIFY_DISCONNECT_DEAD)); + g_shsec_remove_disk(cp); /* If there are no valid disks anymore, remove device. */ - if (g_shsec_nvalid(sc) == 0) + if (g_shsec_nvalid(sc) == 0) { + g_notify_destroyed(sc->sc_provider); g_shsec_destroy(sc, 1); + } } static int From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:03:15 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4973D106566C; Tue, 4 Oct 2011 17:03:15 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 396408FC16; Tue, 4 Oct 2011 17:03:15 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H3FmS068942; Tue, 4 Oct 2011 17:03:15 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H3FBi068940; Tue, 4 Oct 2011 17:03:15 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041703.p94H3FBi068940@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:03:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226007 - projects/geom-events/sys/geom/stripe X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:03:15 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:03:14 2011 New Revision: 226007 URL: http://svn.freebsd.org/changeset/base/226007 Log: Add g_notify_*() calls to geom_stripe Modified: projects/geom-events/sys/geom/stripe/g_stripe.c Modified: projects/geom-events/sys/geom/stripe/g_stripe.c ============================================================================== --- projects/geom-events/sys/geom/stripe/g_stripe.c Tue Oct 4 17:03:01 2011 (r226006) +++ projects/geom-events/sys/geom/stripe/g_stripe.c Tue Oct 4 17:03:14 2011 (r226007) @@ -196,10 +196,17 @@ g_stripe_orphan(struct g_consumer *cp) if (sc == NULL) return; + g_notify_disconnect(sc->sc_provider, cp, + ((g_stripe_nvalid(sc) > 1)? + G_NOTIFY_DISCONNECT_ALIVE: + G_NOTIFY_DISCONNECT_DEAD)); + g_stripe_remove_disk(cp); /* If there are no valid disks anymore, remove device. */ - if (g_stripe_nvalid(sc) == 0) + if (g_stripe_nvalid(sc) == 0) { + g_notify_destroyed(sc->sc_provider); g_stripe_destroy(sc, 1); + } } static int From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:03:27 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CDBD81065680; Tue, 4 Oct 2011 17:03:27 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BDD178FC0A; Tue, 4 Oct 2011 17:03:27 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H3R4D069018; Tue, 4 Oct 2011 17:03:27 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H3RQN069016; Tue, 4 Oct 2011 17:03:27 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041703.p94H3RQN069016@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:03:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226008 - projects/geom-events/sys/geom/uzip X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:03:27 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:03:27 2011 New Revision: 226008 URL: http://svn.freebsd.org/changeset/base/226008 Log: Add g_notify_*() calls to geom_uzip Modified: projects/geom-events/sys/geom/uzip/g_uzip.c Modified: projects/geom-events/sys/geom/uzip/g_uzip.c ============================================================================== --- projects/geom-events/sys/geom/uzip/g_uzip.c Tue Oct 4 17:03:14 2011 (r226007) +++ projects/geom-events/sys/geom/uzip/g_uzip.c Tue Oct 4 17:03:27 2011 (r226008) @@ -315,8 +315,10 @@ g_uzip_orphan(struct g_consumer *cp) g_topology_assert(); KASSERT(cp->provider->error != 0, ("g_uzip_orphan with error == 0")); - gp = cp->geom; + + g_notify_destroyed(LIST_FIRST(&gp->provider)); + g_uzip_softc_free(gp->softc, gp); gp->softc = NULL; g_wither_geom(gp, cp->provider->error); From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:03:40 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4E8FE106567D; Tue, 4 Oct 2011 17:03:40 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3E68B8FC17; Tue, 4 Oct 2011 17:03:40 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H3eaQ069088; Tue, 4 Oct 2011 17:03:40 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H3eig069086; Tue, 4 Oct 2011 17:03:40 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041703.p94H3eig069086@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:03:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226009 - projects/geom-events/sys/geom/virstor X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:03:40 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:03:39 2011 New Revision: 226009 URL: http://svn.freebsd.org/changeset/base/226009 Log: Add g_notify_*() calls to geom_virstor Modified: projects/geom-events/sys/geom/virstor/g_virstor.c Modified: projects/geom-events/sys/geom/virstor/g_virstor.c ============================================================================== --- projects/geom-events/sys/geom/virstor/g_virstor.c Tue Oct 4 17:03:27 2011 (r226008) +++ projects/geom-events/sys/geom/virstor/g_virstor.c Tue Oct 4 17:03:39 2011 (r226009) @@ -1394,9 +1394,17 @@ g_virstor_orphan(struct g_consumer *cp) comp = cp->private; KASSERT(comp != NULL, ("%s: No component in private part of consumer", __func__)); + + g_notify_disconnect(sc->provider, cp, + ((virstor_valid_components(sc) > 1)? + G_NOTIFY_DISCONNECT_ALIVE: + G_NOTIFY_DISCONNECT_DEAD)); + remove_component(sc, comp, FALSE); - if (virstor_valid_components(sc) == 0) + if (virstor_valid_components(sc) == 0) { + g_notify_destroyed(sc->provider); virstor_geom_destroy(sc, TRUE, FALSE); + } } /* From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:07:57 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 56396106564A; Tue, 4 Oct 2011 17:07:57 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3BCAA8FC08; Tue, 4 Oct 2011 17:07:57 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H7vV7069860; Tue, 4 Oct 2011 17:07:57 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H7vqp069856; Tue, 4 Oct 2011 17:07:57 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041707.p94H7vqp069856@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:07:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226010 - projects/geom-events/sys/geom/raid3 X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:07:57 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:07:56 2011 New Revision: 226010 URL: http://svn.freebsd.org/changeset/base/226010 Log: Add geom_notify_*() calls to geom_raid3. This is more than a trivial change. Replace calls with DISCONNECTED disk state with calls REMOVED disk state to all manual operations. Modified: projects/geom-events/sys/geom/raid3/g_raid3.c projects/geom-events/sys/geom/raid3/g_raid3.h projects/geom-events/sys/geom/raid3/g_raid3_ctl.c Modified: projects/geom-events/sys/geom/raid3/g_raid3.c ============================================================================== --- projects/geom-events/sys/geom/raid3/g_raid3.c Tue Oct 4 17:03:39 2011 (r226009) +++ projects/geom-events/sys/geom/raid3/g_raid3.c Tue Oct 4 17:07:56 2011 (r226010) @@ -151,6 +151,8 @@ g_raid3_disk_state2str(int state) return ("SYNCHRONIZING"); case G_RAID3_DISK_STATE_DISCONNECTED: return ("DISCONNECTED"); + case G_RAID3_DISK_STATE_REMOVE: + return ("REMOVE"); default: return ("INVALID"); } @@ -2275,6 +2277,8 @@ g_raid3_sync_start(struct g_raid3_softc else g_io_request(bp, disk->d_sync.ds_consumer); } + + g_notify_sync_start(sc->sc_provider); } /* @@ -2310,6 +2314,8 @@ g_raid3_sync_stop(struct g_raid3_softc * G_RAID3_DEBUG(0, "Device %s: rebuilding provider %s stopped.", sc->sc_name, g_raid3_get_diskname(disk)); } + g_notify_sync_stop(sc->sc_provider, !type); + free(disk->d_sync.ds_bios, M_RAID3); disk->d_sync.ds_bios = NULL; cp = disk->d_sync.ds_consumer; @@ -2621,8 +2627,10 @@ g_raid3_update_device(struct g_raid3_sof return; if (g_raid3_ndisks(sc, G_RAID3_DISK_STATE_ACTIVE) < sc->sc_ndisks - 1) { - if (sc->sc_provider != NULL) + if (sc->sc_provider != NULL) { + g_notify_destroyed(sc->sc_provider); g_raid3_destroy_provider(sc); + } sc->sc_flags |= G_RAID3_DEVICE_FLAG_DESTROY; return; } @@ -2821,6 +2829,7 @@ again: } break; case G_RAID3_DISK_STATE_DISCONNECTED: + case G_RAID3_DISK_STATE_REMOVE: /* * Possible scenarios: * 1. Device wasn't running yet, but disk disappear. @@ -2864,6 +2873,13 @@ again: G_RAID3_DEBUG(0, "Device %s: provider %s disconnected.", sc->sc_name, g_raid3_get_diskname(disk)); + /* Don't notify about manual destroy */ + if (state == G_RAID3_DISK_STATE_DISCONNECTED) + g_notify_disconnect(sc->sc_provider, disk->d_consumer, + ((g_raid3_ndisks(sc, -1) < sc->sc_ndisks)? + G_NOTIFY_DISCONNECT_DEAD: + G_NOTIFY_DISCONNECT_FIXABLE)); + g_raid3_destroy_disk(disk); break; default: Modified: projects/geom-events/sys/geom/raid3/g_raid3.h ============================================================================== --- projects/geom-events/sys/geom/raid3/g_raid3.h Tue Oct 4 17:03:39 2011 (r226009) +++ projects/geom-events/sys/geom/raid3/g_raid3.h Tue Oct 4 17:07:56 2011 (r226010) @@ -136,7 +136,7 @@ struct g_raid3_device_sync { #define G_RAID3_DISK_STATE_STALE 4 #define G_RAID3_DISK_STATE_SYNCHRONIZING 5 #define G_RAID3_DISK_STATE_DISCONNECTED 6 -#define G_RAID3_DISK_STATE_DESTROY 7 +#define G_RAID3_DISK_STATE_REMOVE 7 struct g_raid3_disk { u_int d_no; /* Disk number. */ struct g_consumer *d_consumer; /* Consumer. */ Modified: projects/geom-events/sys/geom/raid3/g_raid3_ctl.c ============================================================================== --- projects/geom-events/sys/geom/raid3/g_raid3_ctl.c Tue Oct 4 17:03:39 2011 (r226009) +++ projects/geom-events/sys/geom/raid3/g_raid3_ctl.c Tue Oct 4 17:07:56 2011 (r226010) @@ -250,7 +250,7 @@ g_raid3_ctl_configure(struct gctl_req *r * component will not be retasted. */ g_raid3_event_send(disk, - G_RAID3_DISK_STATE_DISCONNECTED, + G_RAID3_DISK_STATE_REMOVE, G_RAID3_EVENT_DONTWAIT); } } @@ -317,7 +317,7 @@ g_raid3_ctl_rebuild(struct gctl_req *req g_topology_lock(); error = g_raid3_read_metadata(disk->d_consumer, &md); g_topology_unlock(); - g_raid3_event_send(disk, G_RAID3_DISK_STATE_DISCONNECTED, + g_raid3_event_send(disk, G_RAID3_DISK_STATE_REMOVE, G_RAID3_EVENT_WAIT); if (error != 0) { gctl_error(req, "Cannot read metadata from %s.", pp->name); @@ -592,7 +592,7 @@ g_raid3_ctl_remove(struct gctl_req *req, g_raid3_get_diskname(disk)); } else { g_raid3_event_send(disk, - G_RAID3_DISK_STATE_DISCONNECTED, + G_RAID3_DISK_STATE_REMOVE, G_RAID3_EVENT_DONTWAIT); } break; From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:08:24 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D12731065675; Tue, 4 Oct 2011 17:08:24 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C10E68FC12; Tue, 4 Oct 2011 17:08:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H8OxE069979; Tue, 4 Oct 2011 17:08:24 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H8O8f069977; Tue, 4 Oct 2011 17:08:24 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041708.p94H8O8f069977@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:08:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226011 - projects/geom-events/sys/geom/part X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:08:24 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:08:24 2011 New Revision: 226011 URL: http://svn.freebsd.org/changeset/base/226011 Log: Add g_notify_*() calls to geom_part Modified: projects/geom-events/sys/geom/part/g_part.c Modified: projects/geom-events/sys/geom/part/g_part.c ============================================================================== --- projects/geom-events/sys/geom/part/g_part.c Tue Oct 4 17:07:56 2011 (r226010) +++ projects/geom-events/sys/geom/part/g_part.c Tue Oct 4 17:08:24 2011 (r226011) @@ -2016,6 +2016,7 @@ g_part_orphan(struct g_consumer *cp) { struct g_provider *pp; struct g_part_table *table; + struct g_part_entry *e; pp = cp->provider; KASSERT(pp != NULL, ("%s", __func__)); @@ -2026,6 +2027,11 @@ g_part_orphan(struct g_consumer *cp) table = cp->geom->softc; if (table != NULL && table->gpt_opened) g_access(cp, -1, -1, -1); + + LIST_FOREACH(e, &table->gpt_entry, gpe_entry) { + g_notify_destroyed(e->gpe_pp); + } + g_part_wither(cp->geom, pp->error); } From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:09:10 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B3E71106564A; Tue, 4 Oct 2011 17:09:10 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A25C08FC08; Tue, 4 Oct 2011 17:09:10 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94H9AD5070160; Tue, 4 Oct 2011 17:09:10 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94H9A18070147; Tue, 4 Oct 2011 17:09:10 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041709.p94H9A18070147@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:09:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226012 - projects/geom-events/sys/geom/raid X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:09:10 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:09:10 2011 New Revision: 226012 URL: http://svn.freebsd.org/changeset/base/226012 Log: Add geom_notify_*() calls to geom_raid. It is not a trivial change. To determine state of volume(s) after disk disconnection, new method to raid transformation object interface (g_raid_tr) was added: METHOD int getvolstatus { struct g_raid_tr_object *tr; struct g_raid_volume *volume; }; This method should return state (G_RAID_VOLUME_S_XXX) of the given voulme. Also, some trnasformation modules have status detection code factored out from g_raid_tr_update_state_NAME code. And some hasn't, as they perform active actions in this method and getvolstatus() method should be passive one. Modified: projects/geom-events/sys/geom/raid/g_raid.c projects/geom-events/sys/geom/raid/g_raid.h projects/geom-events/sys/geom/raid/g_raid_tr_if.m projects/geom-events/sys/geom/raid/md_intel.c projects/geom-events/sys/geom/raid/md_jmicron.c projects/geom-events/sys/geom/raid/md_nvidia.c projects/geom-events/sys/geom/raid/md_promise.c projects/geom-events/sys/geom/raid/md_sii.c projects/geom-events/sys/geom/raid/tr_concat.c projects/geom-events/sys/geom/raid/tr_raid0.c projects/geom-events/sys/geom/raid/tr_raid1.c projects/geom-events/sys/geom/raid/tr_raid1e.c Modified: projects/geom-events/sys/geom/raid/g_raid.c ============================================================================== --- projects/geom-events/sys/geom/raid/g_raid.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/g_raid.c Tue Oct 4 17:09:10 2011 (r226012) @@ -585,6 +585,36 @@ g_raid_get_subdisk(struct g_raid_volume return (NULL); } +/* + * Send event about disk disconnection for volume with proper status + */ +void +g_raid_notify_volume(struct g_raid_volume *vol, struct g_raid_disk *disk) +{ + if (!vol->v_tr) { + g_notify_disconnect(vol->v_provider, disk->d_consumer, G_NOTIFY_DISCONNECT_UNKNOWN); + return; + } + switch (G_RAID_TR_GETVOLSTATUS(vol->v_tr, vol)) { + case G_RAID_VOLUME_S_BROKEN: + g_notify_disconnect(vol->v_provider, disk->d_consumer, G_NOTIFY_DISCONNECT_DEAD); + break; + case G_RAID_VOLUME_S_DEGRADED: + case G_RAID_VOLUME_S_SUBOPTIMAL: + g_notify_disconnect(vol->v_provider, disk->d_consumer, G_NOTIFY_DISCONNECT_FIXABLE); + break; + case G_RAID_VOLUME_S_OPTIMAL: + g_notify_disconnect(vol->v_provider, disk->d_consumer, G_NOTIFY_DISCONNECT_ALIVE); + break; + case G_RAID_VOLUME_S_STARTING: + case G_RAID_VOLUME_S_UNSUPPORTED: + case G_RAID_VOLUME_S_STOPPED: + default: + g_notify_disconnect(vol->v_provider, disk->d_consumer, G_NOTIFY_DISCONNECT_UNKNOWN); + break; + } +} + struct g_consumer * g_raid_open_consumer(struct g_raid_softc *sc, const char *name) { Modified: projects/geom-events/sys/geom/raid/g_raid.h ============================================================================== --- projects/geom-events/sys/geom/raid/g_raid.h Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/g_raid.h Tue Oct 4 17:09:10 2011 (r226012) @@ -397,6 +397,8 @@ int g_raid_lock_range(struct g_raid_volu struct bio *ignore, void *argp); int g_raid_unlock_range(struct g_raid_volume *vol, off_t off, off_t len); +void g_raid_notify_volume(struct g_raid_volume *vol, struct g_raid_disk *disk); + g_ctl_req_t g_raid_ctl; #endif /* _KERNEL */ Modified: projects/geom-events/sys/geom/raid/g_raid_tr_if.m ============================================================================== --- projects/geom-events/sys/geom/raid/g_raid_tr_if.m Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/g_raid_tr_if.m Tue Oct 4 17:09:10 2011 (r226012) @@ -100,6 +100,12 @@ METHOD int kerneldump { size_t length; } DEFAULT g_raid_tr_kerneldump_common; +# getvolstatus() - check status of volume, based on status of subdisks +METHOD int getvolstatus { + struct g_raid_tr_object *tr; + struct g_raid_volume *volume; +}; + # locked() - callback method for lock(). METHOD int locked { struct g_raid_tr_object *tr; Modified: projects/geom-events/sys/geom/raid/md_intel.c ============================================================================== --- projects/geom-events/sys/geom/raid/md_intel.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/md_intel.c Tue Oct 4 17:09:10 2011 (r226012) @@ -1323,20 +1323,23 @@ g_raid_md_event_intel(struct g_raid_md_o /* If disk was assigned, just update statuses. */ if (pd->pd_disk_pos >= 0) { g_raid_change_disk_state(disk, G_RAID_DISK_S_OFFLINE); - if (disk->d_consumer) { - g_raid_kill_consumer(sc, disk->d_consumer); - disk->d_consumer = NULL; - } TAILQ_FOREACH(sd, &disk->d_subdisks, sd_next) { g_raid_change_subdisk_state(sd, G_RAID_SUBDISK_S_NONE); g_raid_event_send(sd, G_RAID_SUBDISK_E_DISCONNECTED, G_RAID_EVENT_SUBDISK); + /* Notify about changes in volume */ + g_raid_notify_volume(sd->sd_volume, disk); + } + if (disk->d_consumer) { + g_raid_kill_consumer(sc, disk->d_consumer); + disk->d_consumer = NULL; } } else { /* Otherwise -- delete. */ g_raid_change_disk_state(disk, G_RAID_DISK_S_NONE); g_raid_destroy_disk(disk); + /* Disk was not assigned, so no volumes, nothing to report */ } /* Write updated metadata to all disks. */ Modified: projects/geom-events/sys/geom/raid/md_jmicron.c ============================================================================== --- projects/geom-events/sys/geom/raid/md_jmicron.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/md_jmicron.c Tue Oct 4 17:09:10 2011 (r226012) @@ -986,20 +986,24 @@ g_raid_md_event_jmicron(struct g_raid_md /* If disk was assigned, just update statuses. */ if (pd->pd_disk_pos >= 0) { g_raid_change_disk_state(disk, G_RAID_DISK_S_OFFLINE); - if (disk->d_consumer) { - g_raid_kill_consumer(sc, disk->d_consumer); - disk->d_consumer = NULL; - } TAILQ_FOREACH(sd, &disk->d_subdisks, sd_next) { g_raid_change_subdisk_state(sd, G_RAID_SUBDISK_S_NONE); g_raid_event_send(sd, G_RAID_SUBDISK_E_DISCONNECTED, G_RAID_EVENT_SUBDISK); + + /* Notify about changes in volume */ + g_raid_notify_volume(sd->sd_volume, disk); + } + if (disk->d_consumer) { + g_raid_kill_consumer(sc, disk->d_consumer); + disk->d_consumer = NULL; } } else { /* Otherwise -- delete. */ g_raid_change_disk_state(disk, G_RAID_DISK_S_NONE); g_raid_destroy_disk(disk); + /* Disk was not assigned, so no volumes, nothing to report */ } /* Write updated metadata to all disks. */ Modified: projects/geom-events/sys/geom/raid/md_nvidia.c ============================================================================== --- projects/geom-events/sys/geom/raid/md_nvidia.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/md_nvidia.c Tue Oct 4 17:09:10 2011 (r226012) @@ -982,20 +982,24 @@ g_raid_md_event_nvidia(struct g_raid_md_ /* If disk was assigned, just update statuses. */ if (pd->pd_disk_pos >= 0) { g_raid_change_disk_state(disk, G_RAID_DISK_S_OFFLINE); - if (disk->d_consumer) { - g_raid_kill_consumer(sc, disk->d_consumer); - disk->d_consumer = NULL; - } TAILQ_FOREACH(sd, &disk->d_subdisks, sd_next) { g_raid_change_subdisk_state(sd, G_RAID_SUBDISK_S_NONE); g_raid_event_send(sd, G_RAID_SUBDISK_E_DISCONNECTED, G_RAID_EVENT_SUBDISK); + + /* Notify about changes in volume */ + g_raid_notify_volume(sd->sd_volume, disk); + } + if (disk->d_consumer) { + g_raid_kill_consumer(sc, disk->d_consumer); + disk->d_consumer = NULL; } } else { /* Otherwise -- delete. */ g_raid_change_disk_state(disk, G_RAID_DISK_S_NONE); g_raid_destroy_disk(disk); + /* Disk was not assigned, so no volumes, nothing to report */ } if (mdi->mdio_started) { Modified: projects/geom-events/sys/geom/raid/md_promise.c ============================================================================== --- projects/geom-events/sys/geom/raid/md_promise.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/md_promise.c Tue Oct 4 17:09:10 2011 (r226012) @@ -1154,12 +1154,17 @@ g_raid_md_event_promise(struct g_raid_md struct g_raid_disk *disk, u_int event) { struct g_raid_softc *sc; + struct g_raid_subdisk *sd; sc = md->mdo_softc; if (disk == NULL) return (-1); switch (event) { case G_RAID_DISK_E_DISCONNECTED: + TAILQ_FOREACH(sd, &disk->d_subdisks, sd_next) { + /* Notify about changes in volume */ + g_raid_notify_volume(sd->sd_volume, disk); + } /* Delete disk. */ g_raid_change_disk_state(disk, G_RAID_DISK_S_NONE); g_raid_destroy_disk(disk); Modified: projects/geom-events/sys/geom/raid/md_sii.c ============================================================================== --- projects/geom-events/sys/geom/raid/md_sii.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/md_sii.c Tue Oct 4 17:09:10 2011 (r226012) @@ -1073,20 +1073,23 @@ g_raid_md_event_sii(struct g_raid_md_obj /* If disk was assigned, just update statuses. */ if (pd->pd_disk_pos >= 0) { g_raid_change_disk_state(disk, G_RAID_DISK_S_OFFLINE); - if (disk->d_consumer) { - g_raid_kill_consumer(sc, disk->d_consumer); - disk->d_consumer = NULL; - } TAILQ_FOREACH(sd, &disk->d_subdisks, sd_next) { g_raid_change_subdisk_state(sd, G_RAID_SUBDISK_S_NONE); g_raid_event_send(sd, G_RAID_SUBDISK_E_DISCONNECTED, G_RAID_EVENT_SUBDISK); + /* Notify about changes in volume */ + g_raid_notify_volume(sd->sd_volume, disk); + } + if (disk->d_consumer) { + g_raid_kill_consumer(sc, disk->d_consumer); + disk->d_consumer = NULL; } } else { /* Otherwise -- delete. */ g_raid_change_disk_state(disk, G_RAID_DISK_S_NONE); g_raid_destroy_disk(disk); + /* Disk was not assigned, so no volumes, nothing to report */ } /* Write updated metadata to all disks. */ Modified: projects/geom-events/sys/geom/raid/tr_concat.c ============================================================================== --- projects/geom-events/sys/geom/raid/tr_concat.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/tr_concat.c Tue Oct 4 17:09:10 2011 (r226012) @@ -55,6 +55,7 @@ static g_raid_tr_stop_t g_raid_tr_stop_c static g_raid_tr_iostart_t g_raid_tr_iostart_concat; static g_raid_tr_iodone_t g_raid_tr_iodone_concat; static g_raid_tr_kerneldump_t g_raid_tr_kerneldump_concat; +static g_raid_tr_getvolstatus_t g_raid_tr_getvolstatus_concat; static g_raid_tr_free_t g_raid_tr_free_concat; static kobj_method_t g_raid_tr_concat_methods[] = { @@ -65,6 +66,7 @@ static kobj_method_t g_raid_tr_concat_me KOBJMETHOD(g_raid_tr_iostart, g_raid_tr_iostart_concat), KOBJMETHOD(g_raid_tr_iodone, g_raid_tr_iodone_concat), KOBJMETHOD(g_raid_tr_kerneldump, g_raid_tr_kerneldump_concat), + KOBJMETHOD(g_raid_tr_getvolstatus, g_raid_tr_getvolstatus_concat), KOBJMETHOD(g_raid_tr_free, g_raid_tr_free_concat), { 0, 0 } }; @@ -98,25 +100,11 @@ g_raid_tr_update_state_concat(struct g_r struct g_raid_softc *sc; off_t size; u_int s; - int i, n, f; + int i; sc = vol->v_softc; trs = (struct g_raid_tr_concat_object *)vol->v_tr; - if (trs->trso_stopped) - s = G_RAID_VOLUME_S_STOPPED; - else if (trs->trso_starting) - s = G_RAID_VOLUME_S_STARTING; - else { - n = g_raid_nsubdisks(vol, G_RAID_SUBDISK_S_ACTIVE); - f = g_raid_nsubdisks(vol, G_RAID_SUBDISK_S_FAILED); - if (n + f == vol->v_disks_count) { - if (f == 0) - s = G_RAID_VOLUME_S_OPTIMAL; - else - s = G_RAID_VOLUME_S_SUBOPTIMAL; - } else - s = G_RAID_VOLUME_S_BROKEN; - } + s = g_raid_tr_getvolstatus_concat(vol->v_tr, vol); if (s != vol->v_state) { /* @@ -316,6 +304,31 @@ g_raid_tr_kerneldump_concat(struct g_rai return (0); } +static int +g_raid_tr_getvolstatus_concat(struct g_raid_tr_object *tr, struct g_raid_volume *volume) +{ + struct g_raid_tr_concat_object *trs; + int n, f; + + trs = (struct g_raid_tr_concat_object *)tr; + KASSERT(tr == volume->v_tr, ("Invalid transformation object")); + if (trs->trso_stopped) + return G_RAID_VOLUME_S_STOPPED; + else if (trs->trso_starting) + return G_RAID_VOLUME_S_STARTING; + else { + n = g_raid_nsubdisks(volume, G_RAID_SUBDISK_S_ACTIVE); + f = g_raid_nsubdisks(volume, G_RAID_SUBDISK_S_FAILED); + if (n + f == volume->v_disks_count) { + if (f == 0) + return G_RAID_VOLUME_S_OPTIMAL; + else + return G_RAID_VOLUME_S_SUBOPTIMAL; + } + } + return G_RAID_VOLUME_S_BROKEN; +} + static void g_raid_tr_iodone_concat(struct g_raid_tr_object *tr, struct g_raid_subdisk *sd,struct bio *bp) Modified: projects/geom-events/sys/geom/raid/tr_raid0.c ============================================================================== --- projects/geom-events/sys/geom/raid/tr_raid0.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/tr_raid0.c Tue Oct 4 17:09:10 2011 (r226012) @@ -55,6 +55,7 @@ static g_raid_tr_stop_t g_raid_tr_stop_r static g_raid_tr_iostart_t g_raid_tr_iostart_raid0; static g_raid_tr_iodone_t g_raid_tr_iodone_raid0; static g_raid_tr_kerneldump_t g_raid_tr_kerneldump_raid0; +static g_raid_tr_getvolstatus_t g_raid_tr_getvolstatus_raid0; static g_raid_tr_free_t g_raid_tr_free_raid0; static kobj_method_t g_raid_tr_raid0_methods[] = { @@ -65,6 +66,7 @@ static kobj_method_t g_raid_tr_raid0_met KOBJMETHOD(g_raid_tr_iostart, g_raid_tr_iostart_raid0), KOBJMETHOD(g_raid_tr_iodone, g_raid_tr_iodone_raid0), KOBJMETHOD(g_raid_tr_kerneldump, g_raid_tr_kerneldump_raid0), + KOBJMETHOD(g_raid_tr_getvolstatus, g_raid_tr_getvolstatus_raid0), KOBJMETHOD(g_raid_tr_free, g_raid_tr_free_raid0), { 0, 0 } }; @@ -95,25 +97,10 @@ g_raid_tr_update_state_raid0(struct g_ra struct g_raid_tr_raid0_object *trs; struct g_raid_softc *sc; u_int s; - int n, f; sc = vol->v_softc; trs = (struct g_raid_tr_raid0_object *)vol->v_tr; - if (trs->trso_stopped) - s = G_RAID_VOLUME_S_STOPPED; - else if (trs->trso_starting) - s = G_RAID_VOLUME_S_STARTING; - else { - n = g_raid_nsubdisks(vol, G_RAID_SUBDISK_S_ACTIVE); - f = g_raid_nsubdisks(vol, G_RAID_SUBDISK_S_FAILED); - if (n + f == vol->v_disks_count) { - if (f == 0) - s = G_RAID_VOLUME_S_OPTIMAL; - else - s = G_RAID_VOLUME_S_SUBOPTIMAL; - } else - s = G_RAID_VOLUME_S_BROKEN; - } + s = g_raid_tr_getvolstatus_raid0(vol->v_tr, vol); if (s != vol->v_state) { g_raid_event_send(vol, G_RAID_VOLUME_S_ALIVE(s) ? G_RAID_VOLUME_E_UP : G_RAID_VOLUME_E_DOWN, @@ -299,6 +286,31 @@ g_raid_tr_kerneldump_raid0(struct g_raid return (0); } +static int +g_raid_tr_getvolstatus_raid0(struct g_raid_tr_object *tr, struct g_raid_volume *volume) +{ + struct g_raid_tr_raid0_object *trs; + int n, f; + + trs = (struct g_raid_tr_raid0_object *)tr; + KASSERT(tr == volume->v_tr, ("Invalid transformation object")); + if (trs->trso_stopped) + return G_RAID_VOLUME_S_STOPPED; + else if (trs->trso_starting) + return G_RAID_VOLUME_S_STARTING; + else { + n = g_raid_nsubdisks(volume, G_RAID_SUBDISK_S_ACTIVE); + f = g_raid_nsubdisks(volume, G_RAID_SUBDISK_S_FAILED); + if (n + f == volume->v_disks_count) { + if (f == 0) + return G_RAID_VOLUME_S_OPTIMAL; + else + return G_RAID_VOLUME_S_SUBOPTIMAL; + } + } + return G_RAID_VOLUME_S_BROKEN; +} + static void g_raid_tr_iodone_raid0(struct g_raid_tr_object *tr, struct g_raid_subdisk *sd,struct bio *bp) Modified: projects/geom-events/sys/geom/raid/tr_raid1.c ============================================================================== --- projects/geom-events/sys/geom/raid/tr_raid1.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/tr_raid1.c Tue Oct 4 17:09:10 2011 (r226012) @@ -109,6 +109,7 @@ static g_raid_tr_stop_t g_raid_tr_stop_r static g_raid_tr_iostart_t g_raid_tr_iostart_raid1; static g_raid_tr_iodone_t g_raid_tr_iodone_raid1; static g_raid_tr_kerneldump_t g_raid_tr_kerneldump_raid1; +static g_raid_tr_getvolstatus_t g_raid_tr_getvolstatus_raid1; static g_raid_tr_locked_t g_raid_tr_locked_raid1; static g_raid_tr_idle_t g_raid_tr_idle_raid1; static g_raid_tr_free_t g_raid_tr_free_raid1; @@ -120,7 +121,8 @@ static kobj_method_t g_raid_tr_raid1_met KOBJMETHOD(g_raid_tr_stop, g_raid_tr_stop_raid1), KOBJMETHOD(g_raid_tr_iostart, g_raid_tr_iostart_raid1), KOBJMETHOD(g_raid_tr_iodone, g_raid_tr_iodone_raid1), - KOBJMETHOD(g_raid_tr_kerneldump, g_raid_tr_kerneldump_raid1), + KOBJMETHOD(g_raid_tr_kerneldump, g_raid_tr_kerneldump_raid1), + KOBJMETHOD(g_raid_tr_getvolstatus, g_raid_tr_getvolstatus_raid1), KOBJMETHOD(g_raid_tr_locked, g_raid_tr_locked_raid1), KOBJMETHOD(g_raid_tr_idle, g_raid_tr_idle_raid1), KOBJMETHOD(g_raid_tr_free, g_raid_tr_free_raid1), @@ -306,6 +308,7 @@ g_raid_tr_raid1_rebuild_finish(struct g_ g_raid_change_subdisk_state(sd, G_RAID_SUBDISK_S_ACTIVE); sd->sd_rebuild_pos = 0; g_raid_tr_raid1_rebuild_done(trs); + g_notify_sync_stop(sd->sd_volume->v_provider, 1); } static void @@ -340,6 +343,7 @@ g_raid_tr_raid1_rebuild_abort(struct g_r } g_raid_tr_raid1_rebuild_done(trs); } + g_notify_sync_stop(vol->v_provider, 0); } static void @@ -402,6 +406,9 @@ g_raid_tr_raid1_rebuild_start(struct g_r trs->trso_type = TR_RAID1_REBUILD; trs->trso_buffer = malloc(g_raid1_rebuild_slab, M_TR_RAID1, M_WAITOK); trs->trso_meta_update = g_raid1_rebuild_meta_update; + + g_notify_sync_start(vol->v_provider); + g_raid_tr_raid1_rebuild_some(tr); } @@ -947,6 +954,33 @@ g_raid_tr_kerneldump_raid1(struct g_raid } static int +g_raid_tr_getvolstatus_raid1(struct g_raid_tr_object *tr, struct g_raid_volume *volume) +{ + struct g_raid_tr_raid1_object *trs; + int na, ns; + + trs = (struct g_raid_tr_raid1_object *)tr; + KASSERT(tr == volume->v_tr, ("Invalid transformation object")); + if (trs->trso_stopping && + (trs->trso_flags & TR_RAID1_F_DOING_SOME) == 0) + return G_RAID_VOLUME_S_STOPPED; + else if (trs->trso_starting) + return G_RAID_VOLUME_S_STARTING; + else { + na = g_raid_nsubdisks(volume, G_RAID_SUBDISK_S_ACTIVE); + ns = g_raid_nsubdisks(volume, G_RAID_SUBDISK_S_STALE) + + g_raid_nsubdisks(volume, G_RAID_SUBDISK_S_RESYNC); + if (na == volume->v_disks_count) + return G_RAID_VOLUME_S_OPTIMAL; + else if (na + ns == volume->v_disks_count) + return G_RAID_VOLUME_S_SUBOPTIMAL; + else if (na > 0) + return G_RAID_VOLUME_S_DEGRADED; + } + return G_RAID_VOLUME_S_BROKEN; +} + +static int g_raid_tr_locked_raid1(struct g_raid_tr_object *tr, void *argp) { struct bio *bp; Modified: projects/geom-events/sys/geom/raid/tr_raid1e.c ============================================================================== --- projects/geom-events/sys/geom/raid/tr_raid1e.c Tue Oct 4 17:08:24 2011 (r226011) +++ projects/geom-events/sys/geom/raid/tr_raid1e.c Tue Oct 4 17:09:10 2011 (r226012) @@ -113,6 +113,7 @@ static g_raid_tr_stop_t g_raid_tr_stop_r static g_raid_tr_iostart_t g_raid_tr_iostart_raid1e; static g_raid_tr_iodone_t g_raid_tr_iodone_raid1e; static g_raid_tr_kerneldump_t g_raid_tr_kerneldump_raid1e; +static g_raid_tr_getvolstatus_t g_raid_tr_getvolstatus_raid1e; static g_raid_tr_locked_t g_raid_tr_locked_raid1e; static g_raid_tr_idle_t g_raid_tr_idle_raid1e; static g_raid_tr_free_t g_raid_tr_free_raid1e; @@ -124,7 +125,8 @@ static kobj_method_t g_raid_tr_raid1e_me KOBJMETHOD(g_raid_tr_stop, g_raid_tr_stop_raid1e), KOBJMETHOD(g_raid_tr_iostart, g_raid_tr_iostart_raid1e), KOBJMETHOD(g_raid_tr_iodone, g_raid_tr_iodone_raid1e), - KOBJMETHOD(g_raid_tr_kerneldump, g_raid_tr_kerneldump_raid1e), + KOBJMETHOD(g_raid_tr_kerneldump, g_raid_tr_kerneldump_raid1e), + KOBJMETHOD(g_raid_tr_getvolstatus, g_raid_tr_getvolstatus_raid1e), KOBJMETHOD(g_raid_tr_locked, g_raid_tr_locked_raid1e), KOBJMETHOD(g_raid_tr_idle, g_raid_tr_idle_raid1e), KOBJMETHOD(g_raid_tr_free, g_raid_tr_free_raid1e), @@ -194,6 +196,88 @@ g_raid_tr_taste_raid1e(struct g_raid_tr_ } static int +g_raid_tr_getvolstatus_raid1e_even(struct g_raid_volume *vol) +{ + struct g_raid_softc *sc; + struct g_raid_subdisk *sd, *bestsd, *worstsd; + int i, j, state, sstate; + + sc = vol->v_softc; + state = G_RAID_VOLUME_S_OPTIMAL; + for (i = 0; i < vol->v_disks_count / N; i++) { + bestsd = &vol->v_subdisks[i * N]; + for (j = 1; j < N; j++) { + sd = &vol->v_subdisks[i * N + j]; + if (sd->sd_state > bestsd->sd_state) + bestsd = sd; + else if (sd->sd_state == bestsd->sd_state && + (sd->sd_state == G_RAID_SUBDISK_S_REBUILD || + sd->sd_state == G_RAID_SUBDISK_S_RESYNC) && + sd->sd_rebuild_pos > bestsd->sd_rebuild_pos) + bestsd = sd; + } + worstsd = &vol->v_subdisks[i * N]; + for (j = 1; j < N; j++) { + sd = &vol->v_subdisks[i * N + j]; + if (sd->sd_state < worstsd->sd_state) + worstsd = sd; + } + if (worstsd->sd_state == G_RAID_SUBDISK_S_ACTIVE) + sstate = G_RAID_VOLUME_S_OPTIMAL; + else if (worstsd->sd_state >= G_RAID_SUBDISK_S_STALE) + sstate = G_RAID_VOLUME_S_SUBOPTIMAL; + else if (bestsd->sd_state == G_RAID_SUBDISK_S_ACTIVE) + sstate = G_RAID_VOLUME_S_DEGRADED; + else + sstate = G_RAID_VOLUME_S_BROKEN; + if (sstate < state) + state = sstate; + } + return (state); +} + +static int +g_raid_tr_getvolstatus_raid1e_odd(struct g_raid_volume *vol) +{ + struct g_raid_softc *sc; + struct g_raid_subdisk *sd, *bestsd, *worstsd; + int i, j, state, sstate; + + sc = vol->v_softc; + if (g_raid_nsubdisks(vol, G_RAID_SUBDISK_S_ACTIVE) == + vol->v_disks_count) + return (G_RAID_VOLUME_S_OPTIMAL); + state = G_RAID_VOLUME_S_OPTIMAL; + for (i = 0; i < vol->v_disks_count; i++) { + bestsd = &vol->v_subdisks[i]; + worstsd = &vol->v_subdisks[i]; + for (j = 1; j < N; j++) { + sd = &vol->v_subdisks[(i + j) % vol->v_disks_count]; + if (sd->sd_state > bestsd->sd_state) + bestsd = sd; + else if (sd->sd_state == bestsd->sd_state && + (sd->sd_state == G_RAID_SUBDISK_S_REBUILD || + sd->sd_state == G_RAID_SUBDISK_S_RESYNC) && + sd->sd_rebuild_pos > bestsd->sd_rebuild_pos) + bestsd = sd; + if (sd->sd_state < worstsd->sd_state) + worstsd = sd; + } + if (worstsd->sd_state == G_RAID_SUBDISK_S_ACTIVE) + sstate = G_RAID_VOLUME_S_OPTIMAL; + else if (worstsd->sd_state >= G_RAID_SUBDISK_S_STALE) + sstate = G_RAID_VOLUME_S_SUBOPTIMAL; + else if (bestsd->sd_state >= G_RAID_SUBDISK_S_STALE) + sstate = G_RAID_VOLUME_S_DEGRADED; + else + sstate = G_RAID_VOLUME_S_BROKEN; + if (sstate < state) + state = sstate; + } + return (state); +} + +static int g_raid_tr_update_state_raid1e_even(struct g_raid_volume *vol) { struct g_raid_softc *sc; @@ -386,6 +470,7 @@ g_raid_tr_raid1e_rebuild_finish(struct g g_raid_change_subdisk_state(sd, G_RAID_SUBDISK_S_ACTIVE); sd->sd_rebuild_pos = 0; g_raid_tr_raid1e_rebuild_done(trs); + g_notify_sync_stop(sd->sd_volume->v_provider, 1); } static void @@ -417,6 +502,7 @@ g_raid_tr_raid1e_rebuild_abort(struct g_ } g_raid_tr_raid1e_rebuild_done(trs); } + g_notify_sync_stop(vol->v_provider, 0); } static void @@ -548,6 +634,9 @@ g_raid_tr_raid1e_rebuild_start(struct g_ trs->trso_type = TR_RAID1E_REBUILD; trs->trso_buffer = malloc(g_raid1e_rebuild_slab, M_TR_RAID1E, M_WAITOK); trs->trso_meta_update = g_raid1e_rebuild_meta_update; + + g_notify_sync_start(vol->v_provider); + g_raid_tr_raid1e_rebuild_some(tr); } @@ -1173,6 +1262,26 @@ nextdisk: } static int +g_raid_tr_getvolstatus_raid1e(struct g_raid_tr_object *tr, struct g_raid_volume *volume) +{ + struct g_raid_tr_raid1e_object *trs; + + trs = (struct g_raid_tr_raid1e_object *)tr; + KASSERT(tr == volume->v_tr, ("Invalid transformation object")); + if (trs->trso_stopping && + (trs->trso_flags & TR_RAID1E_F_DOING_SOME) == 0) + return G_RAID_VOLUME_S_STOPPED; + else if (trs->trso_starting) + return G_RAID_VOLUME_S_STARTING; + else { + if ((volume->v_disks_count % N) == 0) + return g_raid_tr_getvolstatus_raid1e_even(volume); + else + return g_raid_tr_getvolstatus_raid1e_odd(volume); + } +} + +static int g_raid_tr_locked_raid1e(struct g_raid_tr_object *tr, void *argp) { struct bio *bp; From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:15:00 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 81E02106566C; Tue, 4 Oct 2011 17:15:00 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6E8D78FC0A; Tue, 4 Oct 2011 17:15:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94HF0Nv071276; Tue, 4 Oct 2011 17:15:00 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94HF0K9071260; Tue, 4 Oct 2011 17:15:00 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041715.p94HF0K9071260@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:15:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226014 - in projects/geom-events: contrib/top lib/libc/sys share/mk sys/arm/arm sys/arm/include sys/arm/mv sys/kern sys/pc98/pc98 usr.bin/csup usr.bin/fetch X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:15:00 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:14:59 2011 New Revision: 226014 URL: http://svn.freebsd.org/changeset/base/226014 Log: Merge head into projects/geom-events Modified: projects/geom-events/lib/libc/sys/ptrace.2 projects/geom-events/sys/arm/arm/elf_machdep.c projects/geom-events/sys/arm/arm/elf_trampoline.c projects/geom-events/sys/arm/arm/pmap.c projects/geom-events/sys/arm/arm/trap.c projects/geom-events/sys/arm/include/proc.h projects/geom-events/sys/arm/include/vmparam.h projects/geom-events/sys/arm/mv/common.c projects/geom-events/sys/arm/mv/mv_machdep.c projects/geom-events/sys/kern/kern_racct.c projects/geom-events/sys/pc98/pc98/machdep.c projects/geom-events/usr.bin/csup/fixups.c projects/geom-events/usr.bin/csup/updater.c projects/geom-events/usr.bin/fetch/fetch.1 Directory Properties: projects/geom-events/ (props changed) projects/geom-events/cddl/contrib/opensolaris/ (props changed) projects/geom-events/contrib/bind9/ (props changed) projects/geom-events/contrib/binutils/ (props changed) projects/geom-events/contrib/bzip2/ (props changed) projects/geom-events/contrib/compiler-rt/ (props changed) projects/geom-events/contrib/dialog/ (props changed) projects/geom-events/contrib/ee/ (props changed) projects/geom-events/contrib/expat/ (props changed) projects/geom-events/contrib/file/ (props changed) projects/geom-events/contrib/gcc/ (props changed) projects/geom-events/contrib/gdb/ (props changed) projects/geom-events/contrib/gdtoa/ (props changed) projects/geom-events/contrib/gnu-sort/ (props changed) projects/geom-events/contrib/groff/ (props changed) projects/geom-events/contrib/less/ (props changed) projects/geom-events/contrib/libpcap/ (props changed) projects/geom-events/contrib/libstdc++/ (props changed) projects/geom-events/contrib/llvm/ (props changed) projects/geom-events/contrib/llvm/tools/clang/ (props changed) projects/geom-events/contrib/ncurses/ (props changed) projects/geom-events/contrib/netcat/ (props changed) projects/geom-events/contrib/ntp/ (props changed) projects/geom-events/contrib/one-true-awk/ (props changed) projects/geom-events/contrib/openbsm/ (props changed) projects/geom-events/contrib/openpam/ (props changed) projects/geom-events/contrib/openresolv/ (props changed) projects/geom-events/contrib/pf/ (props changed) projects/geom-events/contrib/sendmail/ (props changed) projects/geom-events/contrib/tcpdump/ (props changed) projects/geom-events/contrib/tcsh/ (props changed) projects/geom-events/contrib/tnftp/ (props changed) projects/geom-events/contrib/top/ (props changed) projects/geom-events/contrib/top/install-sh (props changed) projects/geom-events/contrib/tzcode/stdtime/ (props changed) projects/geom-events/contrib/tzcode/zic/ (props changed) projects/geom-events/contrib/tzdata/ (props changed) projects/geom-events/contrib/wpa/ (props changed) projects/geom-events/contrib/xz/ (props changed) projects/geom-events/crypto/heimdal/ (props changed) projects/geom-events/crypto/openssh/ (props changed) projects/geom-events/crypto/openssl/ (props changed) projects/geom-events/gnu/lib/ (props changed) projects/geom-events/gnu/usr.bin/binutils/ (props changed) projects/geom-events/gnu/usr.bin/cc/cc_tools/ (props changed) projects/geom-events/gnu/usr.bin/gdb/ (props changed) projects/geom-events/lib/libc/ (props changed) projects/geom-events/lib/libc/stdtime/ (props changed) projects/geom-events/lib/libutil/ (props changed) projects/geom-events/lib/libz/ (props changed) projects/geom-events/sbin/ (props changed) projects/geom-events/sbin/ipfw/ (props changed) projects/geom-events/share/mk/bsd.arch.inc.mk (props changed) projects/geom-events/share/zoneinfo/ (props changed) projects/geom-events/sys/ (props changed) projects/geom-events/sys/amd64/include/xen/ (props changed) projects/geom-events/sys/boot/ (props changed) projects/geom-events/sys/boot/i386/efi/ (props changed) projects/geom-events/sys/boot/ia64/efi/ (props changed) projects/geom-events/sys/boot/ia64/ski/ (props changed) projects/geom-events/sys/boot/powerpc/boot1.chrp/ (props changed) projects/geom-events/sys/boot/powerpc/ofw/ (props changed) projects/geom-events/sys/cddl/contrib/opensolaris/ (props changed) projects/geom-events/sys/conf/ (props changed) projects/geom-events/sys/contrib/dev/acpica/ (props changed) projects/geom-events/sys/contrib/octeon-sdk/ (props changed) projects/geom-events/sys/contrib/pf/ (props changed) projects/geom-events/sys/contrib/x86emu/ (props changed) projects/geom-events/usr.bin/calendar/ (props changed) projects/geom-events/usr.bin/csup/ (props changed) projects/geom-events/usr.bin/procstat/ (props changed) projects/geom-events/usr.sbin/ndiscvt/ (props changed) projects/geom-events/usr.sbin/rtadvctl/ (props changed) projects/geom-events/usr.sbin/rtadvd/ (props changed) projects/geom-events/usr.sbin/rtsold/ (props changed) projects/geom-events/usr.sbin/zic/ (props changed) Modified: projects/geom-events/lib/libc/sys/ptrace.2 ============================================================================== --- projects/geom-events/lib/libc/sys/ptrace.2 Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/lib/libc/sys/ptrace.2 Tue Oct 4 17:14:59 2011 (r226014) @@ -2,7 +2,7 @@ .\" $NetBSD: ptrace.2,v 1.2 1995/02/27 12:35:37 cgd Exp $ .\" .\" This file is in the public domain. -.Dd January 23, 2011 +.Dd October 3, 2011 .Dt PTRACE 2 .Os .Sh NAME @@ -606,4 +606,4 @@ The .Dv PL_FLAG_SCX and .Dv PL_FLAG_EXEC -are not implemented for MIPS and ARM architectures. +are not implemented for MIPS architecture. Modified: projects/geom-events/sys/arm/arm/elf_machdep.c ============================================================================== --- projects/geom-events/sys/arm/arm/elf_machdep.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/arm/arm/elf_machdep.c Tue Oct 4 17:14:59 2011 (r226014) @@ -76,7 +76,7 @@ struct sysentvec elf32_freebsd_sysvec = .sv_maxssiz = NULL, .sv_flags = SV_ABI_FREEBSD | SV_ILP32, .sv_set_syscall_retval = cpu_set_syscall_retval, - .sv_fetch_syscall_args = NULL, /* XXXKIB */ + .sv_fetch_syscall_args = cpu_fetch_syscall_args, .sv_syscallnames = syscallnames, .sv_schedtail = NULL, }; Modified: projects/geom-events/sys/arm/arm/elf_trampoline.c ============================================================================== --- projects/geom-events/sys/arm/arm/elf_trampoline.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/arm/arm/elf_trampoline.c Tue Oct 4 17:14:59 2011 (r226014) @@ -22,6 +22,13 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +/* + * Since we are compiled outside of the normal kernel build process, we + * need to include opt_global.h manually. + */ +#include "opt_global.h" +#include "opt_kernname.h" + #include __FBSDID("$FreeBSD$"); #include @@ -33,13 +40,6 @@ __FBSDID("$FreeBSD$"); #include #include -/* - * Since we are compiled outside of the normal kernel build process, we - * need to include opt_global.h manually. - */ -#include "opt_global.h" -#include "opt_kernname.h" - extern char kernel_start[]; extern char kernel_end[]; Modified: projects/geom-events/sys/arm/arm/pmap.c ============================================================================== --- projects/geom-events/sys/arm/arm/pmap.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/arm/arm/pmap.c Tue Oct 4 17:14:59 2011 (r226014) @@ -185,6 +185,9 @@ int pmap_debug_level = 0; #endif /* PMAP_DEBUG */ extern struct pv_addr systempage; + +extern int last_fault_code; + /* * Internal function prototypes */ @@ -2054,9 +2057,8 @@ pmap_fault_fixup(pmap_t pm, vm_offset_t * the TLB. */ if (rv == 0 && pm->pm_l1->l1_domain_use_count == 1) { - extern int last_fault_code; printf("fixup: pm %p, va 0x%lx, ftype %d - nothing to do!\n", - pm, va, ftype); + pm, (u_long)va, ftype); printf("fixup: l2 %p, l2b %p, ptep %p, pl1pd %p\n", l2, l2b, ptep, pl1pd); printf("fixup: pte 0x%x, l1pd 0x%x, last code 0x%x\n", @@ -4012,13 +4014,6 @@ pmap_zero_page_generic(vm_paddr_t phys, char *dstpg; #endif -#ifdef DEBUG - struct vm_page *pg = PHYS_TO_VM_PAGE(phys); - - if (pg->md.pvh_list != NULL) - panic("pmap_zero_page: page has mappings"); -#endif - if (_arm_bzero && size >= _min_bzero_size && _arm_bzero((void *)(phys + off), size, IS_PHYSICAL) == 0) return; @@ -4290,13 +4285,6 @@ pmap_copy_page_generic(vm_paddr_t src, v #if 0 struct vm_page *src_pg = PHYS_TO_VM_PAGE(src); #endif -#ifdef DEBUG - struct vm_page *dst_pg = PHYS_TO_VM_PAGE(dst); - - if (dst_pg->md.pvh_list != NULL) - panic("pmap_copy_page: dst page has mappings"); -#endif - /* * Clean the source page. Hold the source page's lock for @@ -4342,13 +4330,6 @@ pmap_copy_page_xscale(vm_paddr_t src, vm /* XXX: Only needed for pmap_clean_page(), which is commented out. */ struct vm_page *src_pg = PHYS_TO_VM_PAGE(src); #endif -#ifdef DEBUG - struct vm_page *dst_pg = PHYS_TO_VM_PAGE(dst); - - if (dst_pg->md.pvh_list != NULL) - panic("pmap_copy_page: dst page has mappings"); -#endif - /* * Clean the source page. Hold the source page's lock for Modified: projects/geom-events/sys/arm/arm/trap.c ============================================================================== --- projects/geom-events/sys/arm/arm/trap.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/arm/arm/trap.c Tue Oct 4 17:14:59 2011 (r226014) @@ -861,98 +861,68 @@ badaddr_read(void *addr, size_t size, vo return (rv); } -#define MAXARGS 8 +int +cpu_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +{ + struct proc *p; + register_t *ap; + int error; + + sa->code = sa->insn & 0x000fffff; + ap = &td->td_frame->tf_r0; + if (sa->code == SYS_syscall) { + sa->code = *ap++; + sa->nap--; + } else if (sa->code == SYS___syscall) { + sa->code = ap[_QUAD_LOWWORD]; + sa->nap -= 2; + ap += 2; + } + p = td->td_proc; + if (p->p_sysent->sv_mask) + sa->code &= p->p_sysent->sv_mask; + if (sa->code >= p->p_sysent->sv_size) + sa->callp = &p->p_sysent->sv_table[0]; + else + sa->callp = &p->p_sysent->sv_table[sa->code]; + sa->narg = sa->callp->sy_narg; + error = 0; + memcpy(sa->args, ap, sa->nap * sizeof(register_t)); + if (sa->narg > sa->nap) { + error = copyin((void *)td->td_frame->tf_usr_sp, sa->args + + sa->nap, (sa->narg - sa->nap) * sizeof(register_t)); + } + if (error == 0) { + td->td_retval[0] = 0; + td->td_retval[1] = 0; + } + return (error); +} + +#include "../../kern/subr_syscall.c" + static void syscall(struct thread *td, trapframe_t *frame, u_int32_t insn) { - struct proc *p = td->td_proc; - int code, error; - u_int nap, nargs; - register_t *ap, *args, copyargs[MAXARGS]; - struct sysent *callp; + struct syscall_args sa; + int error; - PCPU_INC(cnt.v_syscall); - td->td_pticks = 0; - if (td->td_ucred != td->td_proc->p_ucred) - cred_update_thread(td); + td->td_frame = frame; + sa.insn = insn; switch (insn & SWI_OS_MASK) { case 0: /* XXX: we need our own one. */ - nap = 4; + sa.nap = 4; break; default: call_trapsignal(td, SIGILL, 0); userret(td, frame); return; } - code = insn & 0x000fffff; - td->td_pticks = 0; - ap = &frame->tf_r0; - if (code == SYS_syscall) { - code = *ap++; - - nap--; - } else if (code == SYS___syscall) { - code = ap[_QUAD_LOWWORD]; - nap -= 2; - ap += 2; - } - if (p->p_sysent->sv_mask) - code &= p->p_sysent->sv_mask; - if (code >= p->p_sysent->sv_size) - callp = &p->p_sysent->sv_table[0]; - else - callp = &p->p_sysent->sv_table[code]; - nargs = callp->sy_narg; - memcpy(copyargs, ap, nap * sizeof(register_t)); - if (nargs > nap) { - error = copyin((void *)frame->tf_usr_sp, copyargs + nap, - (nargs - nap) * sizeof(register_t)); - if (error) - goto bad; - } - args = copyargs; - error = 0; -#ifdef KTRACE - if (KTRPOINT(td, KTR_SYSCALL)) - ktrsyscall(code, nargs, args); -#endif - - CTR4(KTR_SYSC, "syscall enter thread %p pid %d proc %s code %d", td, - td->td_proc->p_pid, td->td_name, code); - if (error == 0) { - td->td_retval[0] = 0; - td->td_retval[1] = 0; - STOPEVENT(p, S_SCE, callp->sy_narg); - PTRACESTOP_SC(p, td, S_PT_SCE); - AUDIT_SYSCALL_ENTER(code, td); - error = (*callp->sy_call)(td, args); - AUDIT_SYSCALL_EXIT(error, td); - KASSERT(td->td_ar == NULL, - ("returning from syscall with td_ar set!")); - } -bad: - cpu_set_syscall_retval(td, error); - - WITNESS_WARN(WARN_PANIC, NULL, "System call %s returning", - (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???"); - KASSERT(td->td_critnest == 0, - ("System call %s returning in a critical section", - (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???")); - KASSERT(td->td_locks == 0, - ("System call %s returning with %d locks held", - (code >= 0 && code < SYS_MAXSYSCALL) ? syscallnames[code] : "???", - td->td_locks)); - - userret(td, frame); - CTR4(KTR_SYSC, "syscall exit thread %p pid %d proc %s code %d", td, - td->td_proc->p_pid, td->td_name, code); - - STOPEVENT(p, S_SCX, code); - PTRACESTOP_SC(p, td, S_PT_SCX); -#ifdef KTRACE - if (KTRPOINT(td, KTR_SYSRET)) - ktrsysret(code, error, td->td_retval[0]); -#endif + + error = syscallenter(td, &sa); + KASSERT(error != 0 || td->td_ar == NULL, + ("returning from syscall with td_ar set!")); + syscallret(td, error, &sa); } void Modified: projects/geom-events/sys/arm/include/proc.h ============================================================================== --- projects/geom-events/sys/arm/include/proc.h Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/arm/include/proc.h Tue Oct 4 17:14:59 2011 (r226014) @@ -62,4 +62,15 @@ struct mdproc { #define KINFO_PROC_SIZE 792 +#define MAXARGS 8 +struct syscall_args { + u_int code; + struct sysent *callp; + register_t args[MAXARGS]; + int narg; + u_int nap; + u_int32_t insn; +}; +#define HAVE_SYSCALL_ARGS_DEF 1 + #endif /* !_MACHINE_PROC_H_ */ Modified: projects/geom-events/sys/arm/include/vmparam.h ============================================================================== --- projects/geom-events/sys/arm/include/vmparam.h Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/arm/include/vmparam.h Tue Oct 4 17:14:59 2011 (r226014) @@ -141,11 +141,21 @@ #endif #define MAXTSIZ (16*1024*1024) +#ifndef DFLDSIZ #define DFLDSIZ (128*1024*1024) +#endif +#ifndef MAXDSIZ #define MAXDSIZ (512*1024*1024) +#endif +#ifndef DFLSSIZ #define DFLSSIZ (2*1024*1024) +#endif +#ifndef MAXSSIZ #define MAXSSIZ (8*1024*1024) +#endif +#ifndef SGROWSIZ #define SGROWSIZ (128*1024) +#endif #ifdef ARM_USE_SMALL_ALLOC #define UMA_MD_SMALL_ALLOC Modified: projects/geom-events/sys/arm/mv/common.c ============================================================================== --- projects/geom-events/sys/arm/mv/common.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/arm/mv/common.c Tue Oct 4 17:14:59 2011 (r226014) @@ -49,9 +49,6 @@ __FBSDID("$FreeBSD$"); #define MAX_CPU_WIN 5 -#define DEBUG -#undef DEBUG - #ifdef DEBUG #define debugf(fmt, args...) do { printf("%s(): ", __func__); \ printf(fmt,##args); } while (0) Modified: projects/geom-events/sys/arm/mv/mv_machdep.c ============================================================================== --- projects/geom-events/sys/arm/mv/mv_machdep.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/arm/mv/mv_machdep.c Tue Oct 4 17:14:59 2011 (r226014) @@ -91,9 +91,6 @@ __FBSDID("$FreeBSD$"); #include /* XXX eventually this should be eliminated */ #include -#define DEBUG -#undef DEBUG - #ifdef DEBUG #define debugf(fmt, args...) printf(fmt, ##args) #else Modified: projects/geom-events/sys/kern/kern_racct.c ============================================================================== --- projects/geom-events/sys/kern/kern_racct.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/kern/kern_racct.c Tue Oct 4 17:14:59 2011 (r226014) @@ -567,6 +567,12 @@ racct_proc_fork(struct proc *parent, str PROC_LOCK(child); mtx_lock(&racct_lock); +#ifdef RCTL + error = rctl_proc_fork(parent, child); + if (error != 0) + goto out; +#endif + /* * Inherit resource usage. */ @@ -581,12 +587,6 @@ racct_proc_fork(struct proc *parent, str goto out; } -#ifdef RCTL - error = rctl_proc_fork(parent, child); - if (error != 0) - goto out; -#endif - error = racct_add_locked(child, RACCT_NPROC, 1); error += racct_add_locked(child, RACCT_NTHR, 1); Modified: projects/geom-events/sys/pc98/pc98/machdep.c ============================================================================== --- projects/geom-events/sys/pc98/pc98/machdep.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/sys/pc98/pc98/machdep.c Tue Oct 4 17:14:59 2011 (r226014) @@ -1117,7 +1117,7 @@ void cpu_halt(void) { for (;;) - __asm__ ("hlt"); + halt(); } static int idle_mwait = 1; /* Use MONITOR/MWAIT for short idle. */ @@ -1136,9 +1136,22 @@ cpu_idle_hlt(int busy) state = (int *)PCPU_PTR(monitorbuf); *state = STATE_SLEEPING; + /* - * We must absolutely guarentee that hlt is the next instruction - * after sti or we introduce a timing window. + * Since we may be in a critical section from cpu_idle(), if + * an interrupt fires during that critical section we may have + * a pending preemption. If the CPU halts, then that thread + * may not execute until a later interrupt awakens the CPU. + * To handle this race, check for a runnable thread after + * disabling interrupts and immediately return if one is + * found. Also, we must absolutely guarentee that hlt is + * the next instruction after sti. This ensures that any + * interrupt that fires after the call to disable_intr() will + * immediately awaken the CPU from hlt. Finally, please note + * that on x86 this works fine because of interrupts enabled only + * after the instruction following sti takes place, while IF is set + * to 1 immediately, allowing hlt instruction to acknowledge the + * interrupt. */ disable_intr(); if (sched_runnable()) @@ -1164,11 +1177,19 @@ cpu_idle_mwait(int busy) state = (int *)PCPU_PTR(monitorbuf); *state = STATE_MWAIT; - if (!sched_runnable()) { - cpu_monitor(state, 0, 0); - if (*state == STATE_MWAIT) - cpu_mwait(0, MWAIT_C1); + + /* See comments in cpu_idle_hlt(). */ + disable_intr(); + if (sched_runnable()) { + enable_intr(); + *state = STATE_RUNNING; + return; } + cpu_monitor(state, 0, 0); + if (*state == STATE_MWAIT) + __asm __volatile("sti; mwait" : : "a" (MWAIT_C1), "c" (0)); + else + enable_intr(); *state = STATE_RUNNING; } @@ -1180,6 +1201,12 @@ cpu_idle_spin(int busy) state = (int *)PCPU_PTR(monitorbuf); *state = STATE_RUNNING; + + /* + * The sched_runnable() call is racy but as long as there is + * a loop missing it one time will have just a little impact if any + * (and it is much better than missing the check at all). + */ for (i = 0; i < 1000; i++) { if (sched_runnable()) return; Modified: projects/geom-events/usr.bin/csup/fixups.c ============================================================================== --- projects/geom-events/usr.bin/csup/fixups.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/usr.bin/csup/fixups.c Tue Oct 4 17:14:59 2011 (r226014) @@ -141,7 +141,7 @@ fixups_get(struct fixups *f) fixups_lock(f); while (f->size == 0 && !f->closed) pthread_cond_wait(&f->cond, &f->lock); - if (f->closed) { + if (f->closed && f->size == 0) { fixups_unlock(f); return (NULL); } Modified: projects/geom-events/usr.bin/csup/updater.c ============================================================================== --- projects/geom-events/usr.bin/csup/updater.c Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/usr.bin/csup/updater.c Tue Oct 4 17:14:59 2011 (r226014) @@ -238,7 +238,7 @@ updater(void *arg) /* * Make sure to close the fixups even in case of an error, - * so that the lister thread doesn't block indefinitely. + * so that the detailer thread doesn't block indefinitely. */ fixups_close(up->config->fixups); if (!error) Modified: projects/geom-events/usr.bin/fetch/fetch.1 ============================================================================== --- projects/geom-events/usr.bin/fetch/fetch.1 Tue Oct 4 17:11:38 2011 (r226013) +++ projects/geom-events/usr.bin/fetch/fetch.1 Tue Oct 4 17:14:59 2011 (r226014) @@ -1,5 +1,5 @@ .\"- -.\" Copyright (c) 2000-2011 Dag-Erling Smørgrav +.\" Copyright (c) 2000-2011 Dag-Erling Smørgrav .\" All rights reserved. .\" Portions Copyright (c) 1999 Massachusetts Institute of Technology; used .\" by permission. From owner-svn-src-projects@FreeBSD.ORG Tue Oct 4 17:50:22 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 67ACC106566C; Tue, 4 Oct 2011 17:50:22 +0000 (UTC) (envelope-from lev@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 57D598FC15; Tue, 4 Oct 2011 17:50:22 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p94HoMIJ072772; Tue, 4 Oct 2011 17:50:22 GMT (envelope-from lev@svn.freebsd.org) Received: (from lev@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p94HoMlA072770; Tue, 4 Oct 2011 17:50:22 GMT (envelope-from lev@svn.freebsd.org) Message-Id: <201110041750.p94HoMlA072770@svn.freebsd.org> From: "Lev A. Serebryakov" Date: Tue, 4 Oct 2011 17:50:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226019 - projects/geom-events/sys/geom X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Oct 2011 17:50:22 -0000 Author: lev (ports committer) Date: Tue Oct 4 17:50:22 2011 New Revision: 226019 URL: http://svn.freebsd.org/changeset/base/226019 Log: Use proper memory allocation flags for GEOM fast path Modified: projects/geom-events/sys/geom/geom_notify.c Modified: projects/geom-events/sys/geom/geom_notify.c ============================================================================== --- projects/geom-events/sys/geom/geom_notify.c Tue Oct 4 17:49:19 2011 (r226018) +++ projects/geom-events/sys/geom/geom_notify.c Tue Oct 4 17:50:22 2011 (r226019) @@ -54,7 +54,7 @@ g_devctl_notify(struct g_provider *pp, c int len; int i; - subsystem = g_malloc(strlen(pp->geom->class->name) + 1, M_WAITOK); + subsystem = g_malloc(strlen(pp->geom->class->name) + 1, M_NOWAIT); if (subsystem == NULL) return; for (i = 0; pp->geom->class->name[i]; i++) @@ -62,7 +62,7 @@ g_devctl_notify(struct g_provider *pp, c subsystem[i] = 0; if (format != NULL) { - additional_data = g_malloc(1024, M_WAITOK); + additional_data = g_malloc(1024, M_NOWAIT); if (additional_data == NULL) { g_free(subsystem); return; @@ -78,7 +78,7 @@ g_devctl_notify(struct g_provider *pp, c /* Add more space for mandatory arguments, space and zero */ len += sizeof("geom=") + strlen(pp->geom->name) + sizeof("provider=") + strlen(pp->name) + 2; - full_data = g_malloc(len, M_WAITOK); + full_data = g_malloc(len, M_NOWAIT); if (full_data == NULL) { g_free(subsystem); if (additional_data != NULL) From owner-svn-src-projects@FreeBSD.ORG Wed Oct 5 05:10:48 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D819C1065890; Wed, 5 Oct 2011 05:10:48 +0000 (UTC) (envelope-from bu7cher@yandex.ru) Received: from forward15.mail.yandex.net (forward15.mail.yandex.net [IPv6:2a02:6b8:0:801::5]) by mx1.freebsd.org (Postfix) with ESMTP id 5356C8FC12; Wed, 5 Oct 2011 05:10:48 +0000 (UTC) Received: from smtp14.mail.yandex.net (smtp14.mail.yandex.net [95.108.131.192]) by forward15.mail.yandex.net (Yandex) with ESMTP id 9A6409E3A24; Wed, 5 Oct 2011 09:10:46 +0400 (MSD) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1317791446; bh=LKKq3G16Qdksod2wmwDzNfOBkbIgM691irgyZtn4x0Q=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=tKWSePKyr2jPg9AAZUp527oA2IkAhpDefEd8XUMzTVQBWzBSRPCWpcwSg+bQhpn/y ul61nF1CUDNEbl2fgj+hFOx60JCur2NlScZPY5fLAkIqvUrwgX7KknIG6FqBnTalg0 aau7+GytTF71J2mKTldvX0Y6VcIEkyZQ/vHQNrdE= Received: from smtp14.mail.yandex.net (localhost [127.0.0.1]) by smtp14.mail.yandex.net (Yandex) with ESMTP id 710B41B602EE; Wed, 5 Oct 2011 09:10:46 +0400 (MSD) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1317791446; bh=LKKq3G16Qdksod2wmwDzNfOBkbIgM691irgyZtn4x0Q=; h=Message-ID:Date:From:MIME-Version:To:CC:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=tKWSePKyr2jPg9AAZUp527oA2IkAhpDefEd8XUMzTVQBWzBSRPCWpcwSg+bQhpn/y ul61nF1CUDNEbl2fgj+hFOx60JCur2NlScZPY5fLAkIqvUrwgX7KknIG6FqBnTalg0 aau7+GytTF71J2mKTldvX0Y6VcIEkyZQ/vHQNrdE= Received: from ns.kirov.so-ups.ru (ns.kirov.so-ups.ru [178.74.170.1]) by smtp14.mail.yandex.net (nwsmtp/Yandex) with ESMTP id AjOSAW1Z-AkOqYQj1; Wed, 5 Oct 2011 09:10:46 +0400 X-Yandex-Spam: 1 Message-ID: <4E8BE6D5.9030107@yandex.ru> Date: Wed, 05 Oct 2011 09:10:45 +0400 From: "Andrey V. Elsukov" User-Agent: Mozilla Thunderbird 1.5 (FreeBSD/20051231) MIME-Version: 1.0 To: "Lev A. Serebryakov" References: <201110041708.p94H8O8f069977@svn.freebsd.org> In-Reply-To: <201110041708.p94H8O8f069977@svn.freebsd.org> X-Enigmail-Version: 1.3.2 Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: 7bit Cc: svn-src-projects@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r226011 - projects/geom-events/sys/geom/part X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Oct 2011 05:10:48 -0000 On 04.10.2011 21:08, Lev A. Serebryakov wrote: > Author: lev (ports committer) > Date: Tue Oct 4 17:08:24 2011 > New Revision: 226011 > URL: http://svn.freebsd.org/changeset/base/226011 > > Log: > Add g_notify_*() calls to geom_part > > Modified: > projects/geom-events/sys/geom/part/g_part.c > > Modified: projects/geom-events/sys/geom/part/g_part.c > ============================================================================== > --- projects/geom-events/sys/geom/part/g_part.c Tue Oct 4 17:07:56 2011 (r226010) > +++ projects/geom-events/sys/geom/part/g_part.c Tue Oct 4 17:08:24 2011 (r226011) > @@ -2016,6 +2016,7 @@ g_part_orphan(struct g_consumer *cp) > { > struct g_provider *pp; > struct g_part_table *table; > + struct g_part_entry *e; > > pp = cp->provider; > KASSERT(pp != NULL, ("%s", __func__)); > @@ -2026,6 +2027,11 @@ g_part_orphan(struct g_consumer *cp) > table = cp->geom->softc; > if (table != NULL && table->gpt_opened) > g_access(cp, -1, -1, -1); > + > + LIST_FOREACH(e, &table->gpt_entry, gpe_entry) { > + g_notify_destroyed(e->gpe_pp); > + } > + In some cases you can get panic here. Also geom_part can destroy its providers in several places, not only when it is orphaned. -- WBR, Andrey V. Elsukov From owner-svn-src-projects@FreeBSD.ORG Wed Oct 5 06:58:48 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 959091065670; Wed, 5 Oct 2011 06:58:48 +0000 (UTC) (envelope-from to.my.trociny@gmail.com) Received: from mail-ey0-f182.google.com (mail-ey0-f182.google.com [209.85.215.182]) by mx1.freebsd.org (Postfix) with ESMTP id D21418FC0A; Wed, 5 Oct 2011 06:58:47 +0000 (UTC) Received: by eyg7 with SMTP id 7so1752640eyg.13 for ; Tue, 04 Oct 2011 23:58:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:organization:references:sender:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=8bpLdMGDWNCpxs+nGN3h7RGB8kYLiUz4YlJBY6M5Qek=; b=NI7Bpa4z2oRgXtHBbx6NU8pbcVuXrEB6vsGwfkB23UxqC/qZxEdcUYnzUcD0oPYu/+ 4os2PWcDoUN5NurtNV8D56Jq7SZPPXHfWJ0a+1pX07wcKbwlu1shGUcmJ0WsRk9B51DP OC39uJbRDico0zidDpxt8FF6GcisQokpyQRmw= Received: by 10.223.97.214 with SMTP id m22mr3090385fan.29.1317796207950; Tue, 04 Oct 2011 23:30:07 -0700 (PDT) Received: from localhost ([94.27.39.186]) by mx.google.com with ESMTPS id v17sm937384fai.18.2011.10.04.23.30.03 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 04 Oct 2011 23:30:04 -0700 (PDT) From: Mikolaj Golub To: "Lev A. Serebryakov" Organization: TOA Ukraine References: <201110041700.p94H0QiD068016@svn.freebsd.org> Sender: Mikolaj Golub Date: Wed, 05 Oct 2011 09:30:02 +0300 In-Reply-To: <201110041700.p94H0QiD068016@svn.freebsd.org> (Lev A. Serebryakov's message of "Tue, 4 Oct 2011 17:00:26 +0000 (UTC)") Message-ID: <86ty7o0x3p.fsf@in138.ua3> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: svn-src-projects@freebsd.org, src-committers@freebsd.org Subject: Re: svn commit: r225993 - projects/geom-events/sys/geom/cache X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Oct 2011 06:58:48 -0000 On Tue, 4 Oct 2011 17:00:26 +0000 (UTC) Lev A. Serebryakov wrote: LAS> Author: lev (ports committer) LAS> Date: Tue Oct 4 17:00:25 2011 LAS> New Revision: 225993 LAS> URL: http://svn.freebsd.org/changeset/base/225993 LAS> Log: LAS> Add g_notify_*() calls to geom_cache LAS> Modified: LAS> projects/geom-events/sys/geom/cache/g_cache.c LAS> Modified: projects/geom-events/sys/geom/cache/g_cache.c LAS> ============================================================================== LAS> --- projects/geom-events/sys/geom/cache/g_cache.c Tue Oct 4 16:59:51 2011 (r225992) LAS> +++ projects/geom-events/sys/geom/cache/g_cache.c Tue Oct 4 17:00:25 2011 (r225993) LAS> @@ -444,8 +444,8 @@ g_cache_access(struct g_provider *pp, in LAS> static void LAS> g_cache_orphan(struct g_consumer *cp) LAS> { LAS> - Note, the empty line (if the function has no local variables) is required by style(9). LAS> g_topology_assert(); LAS> + g_notify_destroyed(LIST_FIRST(&cp->geom->provider)); LAS> g_cache_destroy(cp->geom->softc, 1); LAS> } LAS> -- Mikolaj Golub From owner-svn-src-projects@FreeBSD.ORG Thu Oct 6 21:22:27 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 44A86106564A; Thu, 6 Oct 2011 21:22:27 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1C6CC8FC16; Thu, 6 Oct 2011 21:22:27 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p96LMRZH078266; Thu, 6 Oct 2011 21:22:27 GMT (envelope-from thompsa@svn.freebsd.org) Received: (from thompsa@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p96LMQes078265; Thu, 6 Oct 2011 21:22:26 GMT (envelope-from thompsa@svn.freebsd.org) Message-Id: <201110062122.p96LMQes078265@svn.freebsd.org> From: Andrew Thompson Date: Thu, 6 Oct 2011 21:22:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226075 - projects/onewire X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Oct 2011 21:22:27 -0000 Author: thompsa Date: Thu Oct 6 21:22:26 2011 New Revision: 226075 URL: http://svn.freebsd.org/changeset/base/226075 Log: Add a branch for the OpenBSD onewire implementation. Added: projects/onewire/ From owner-svn-src-projects@FreeBSD.ORG Thu Oct 6 21:23:06 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E53DA106566B; Thu, 6 Oct 2011 21:23:06 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id BCB4B8FC1C; Thu, 6 Oct 2011 21:23:06 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p96LN6r2078318; Thu, 6 Oct 2011 21:23:06 GMT (envelope-from thompsa@svn.freebsd.org) Received: (from thompsa@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p96LN6Gk078317; Thu, 6 Oct 2011 21:23:06 GMT (envelope-from thompsa@svn.freebsd.org) Message-Id: <201110062123.p96LN6Gk078317@svn.freebsd.org> From: Andrew Thompson Date: Thu, 6 Oct 2011 21:23:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226076 - projects/onewire/sys X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Oct 2011 21:23:07 -0000 Author: thompsa Date: Thu Oct 6 21:23:06 2011 New Revision: 226076 URL: http://svn.freebsd.org/changeset/base/226076 Log: Branch head-sys Added: - copied from r226075, head/sys/ Directory Properties: projects/onewire/sys/ (props changed) From owner-svn-src-projects@FreeBSD.ORG Thu Oct 6 21:31:22 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4783F106564A; Thu, 6 Oct 2011 21:31:22 +0000 (UTC) (envelope-from thompsa@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 360BA8FC0C; Thu, 6 Oct 2011 21:31:22 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p96LVMqv078596; Thu, 6 Oct 2011 21:31:22 GMT (envelope-from thompsa@svn.freebsd.org) Received: (from thompsa@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p96LVMZq078588; Thu, 6 Oct 2011 21:31:22 GMT (envelope-from thompsa@svn.freebsd.org) Message-Id: <201110062131.p96LVMZq078588@svn.freebsd.org> From: Andrew Thompson Date: Thu, 6 Oct 2011 21:31:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226077 - in projects/onewire/sys: conf dev/gpio dev/onewire X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Oct 2011 21:31:22 -0000 Author: thompsa Date: Thu Oct 6 21:31:21 2011 New Revision: 226077 URL: http://svn.freebsd.org/changeset/base/226077 Log: Add the OpenBSD onewire stack as a work in progress. A DS18B20 attaches as owtemp0 and reads the temp via a gpio pin. Locking isnt really done and there are many rough edges. Obtained from: OpenBSD Added: projects/onewire/sys/dev/gpio/gpio1wire.c (contents, props changed) projects/onewire/sys/dev/onewire/ projects/onewire/sys/dev/onewire/devlist2h.awk (contents, props changed) projects/onewire/sys/dev/onewire/onewire.c (contents, props changed) projects/onewire/sys/dev/onewire/onewirebb.c (contents, props changed) projects/onewire/sys/dev/onewire/onewirebus.c (contents, props changed) projects/onewire/sys/dev/onewire/onewiredevs projects/onewire/sys/dev/onewire/onewiredevs.h (contents, props changed) projects/onewire/sys/dev/onewire/onewiredevs_data.h (contents, props changed) projects/onewire/sys/dev/onewire/onewirereg.h (contents, props changed) projects/onewire/sys/dev/onewire/onewirevar.h (contents, props changed) projects/onewire/sys/dev/onewire/owbb_if.m projects/onewire/sys/dev/onewire/owbus_if.m projects/onewire/sys/dev/onewire/owctr.c (contents, props changed) projects/onewire/sys/dev/onewire/owid.c (contents, props changed) projects/onewire/sys/dev/onewire/owsbm.c (contents, props changed) projects/onewire/sys/dev/onewire/owtemp.c (contents, props changed) Modified: projects/onewire/sys/conf/files Modified: projects/onewire/sys/conf/files ============================================================================== --- projects/onewire/sys/conf/files Thu Oct 6 21:23:06 2011 (r226076) +++ projects/onewire/sys/conf/files Thu Oct 6 21:31:21 2011 (r226077) @@ -1099,6 +1099,7 @@ dev/gpio/gpiobus.c optional gpio \ dependency "gpiobus_if.h" dev/gpio/gpioc.c optional gpio \ dependency "gpio_if.h" +dev/gpio/gpio1wire.c optional gpio1w dev/gpio/gpioiic.c optional gpioiic dev/gpio/gpioled.c optional gpioled dev/gpio/gpio_if.m optional gpio @@ -1526,6 +1527,14 @@ dev/nmdm/nmdm.c optional nmdm dev/nsp/nsp.c optional nsp dev/nsp/nsp_pccard.c optional nsp pccard dev/null/null.c standard +dev/onewire/onewire.c optional onewire +dev/onewire/onewirebus.c optional onewire \ + dependency "owbus_if.h" +dev/onewire/onewirebb.c optional onewirebb \ + dependency "owbb_if.h" +dev/onewire/owtemp.c optional owtemp +dev/onewire/owbus_if.m optional onewire +dev/onewire/owbb_if.m optional onewirebb dev/patm/if_patm.c optional patm pci dev/patm/if_patm_attach.c optional patm pci dev/patm/if_patm_intr.c optional patm pci Added: projects/onewire/sys/dev/gpio/gpio1wire.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/onewire/sys/dev/gpio/gpio1wire.c Thu Oct 6 21:31:21 2011 (r226077) @@ -0,0 +1,162 @@ +/*- + * Copyright (c) 2009 Oleksandr Tymoshenko + * Copyright (c) 2010 Luiz Otavio O Souza + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "gpiobus_if.h" + +#include +#include "owbus_if.h" +#include "owbb_if.h" + +#define ONEWIRE_PIN 0 /* Only one pin */ + +struct gpio1w_softc +{ + device_t sc_dev; + device_t sc_busdev; +}; + +static int gpio1w_probe(device_t); +static int gpio1w_attach(device_t); + +/* owbb interface */ +static void gpio1w_rx(device_t); +static void gpio1w_tx(device_t); +static int gpio1w_get(device_t); +static void gpio1w_set(device_t, int); + +static int +gpio1w_probe(device_t dev) +{ + + device_set_desc(dev, "GPIO 1wire bit-banging driver"); + return (0); +} + +static int +gpio1w_attach(device_t dev) +{ + struct gpio1w_softc *sc = device_get_softc(dev); + device_t bitbang; + + sc->sc_dev = dev; + sc->sc_busdev = device_get_parent(dev); + + /* add generic bit-banging code */ + bitbang = device_add_child(dev, "owbb", -1); + device_probe_and_attach(bitbang); + + return (0); +} + +/* + * Reset bus by setting SDA first and then SCL. + * Must always be called with gpio bus locked. + */ +static void +gpio1w_rx(device_t dev) +{ + struct gpio1w_softc *sc = device_get_softc(dev); + + GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, ONEWIRE_PIN, + GPIO_PIN_INPUT); +} + +static void +gpio1w_tx(device_t dev) +{ + struct gpio1w_softc *sc = device_get_softc(dev); + + GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, ONEWIRE_PIN, + GPIO_PIN_OUTPUT); +} + +static int +gpio1w_get(device_t dev) +{ + struct gpio1w_softc *sc = device_get_softc(dev); + unsigned int val; + + GPIOBUS_LOCK_BUS(sc->sc_busdev); + GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, ONEWIRE_PIN, &val); + GPIOBUS_UNLOCK_BUS(sc->sc_busdev); + + return (val); +} + +static void +gpio1w_set(device_t dev, int value) +{ + struct gpio1w_softc *sc = device_get_softc(dev); + + GPIOBUS_LOCK_BUS(sc->sc_busdev); + GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, ONEWIRE_PIN, value ? 1:0); + GPIOBUS_UNLOCK_BUS(sc->sc_busdev); +} + +static devclass_t gpio1w_devclass; + +static device_method_t gpio1w_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, gpio1w_probe), + DEVMETHOD(device_attach, gpio1w_attach), + DEVMETHOD(device_detach, bus_generic_detach), + + /* owbb interface */ + DEVMETHOD(owbb_rx, gpio1w_rx), + DEVMETHOD(owbb_tx, gpio1w_tx), + DEVMETHOD(owbb_get, gpio1w_get), + DEVMETHOD(owbb_set, gpio1w_set), + + { 0, 0 } +}; + +static driver_t gpio1w_driver = { + "gpio1w", + gpio1w_methods, + sizeof(struct gpio1w_softc), +}; + +DRIVER_MODULE(gpio1w, gpiobus, gpio1w_driver, gpio1w_devclass, 0, 0); +DRIVER_MODULE(owbb, gpio1w, owbb_driver, owbb_devclass, 0, 0); +MODULE_DEPEND(gpio1w, owbb, 1, 1, 1); +MODULE_DEPEND(gpio1w, gpiobus, 1, 1, 1); Added: projects/onewire/sys/dev/onewire/devlist2h.awk ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/onewire/sys/dev/onewire/devlist2h.awk Thu Oct 6 21:31:21 2011 (r226077) @@ -0,0 +1,62 @@ +# $OpenBSD: devlist2h.awk,v 1.4 2007/02/28 22:31:32 deraadt Exp $ + +# +# Copyright (c) 2006 Alexander Yurchenko +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# + +BEGIN { + hfile = "onewiredevs.h" + dfile = "onewiredevs_data.h" +} + +NR == 1 { + VERSION = $0 + gsub("\\$", "", VERSION) + + printf("/*\t\$OpenBSD\$\t*/\n\n" \ + "/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \ + " *\n * Generated from:\n *\t%s\n */\n\n", VERSION) > hfile + + printf("/*\t\$OpenBSD\$\t*/\n\n" \ + "/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \ + " *\n * Generated from:\n *\t%s\n */\n\n", VERSION) > dfile + + printf("struct onewire_family {\n") > dfile + printf("\tint\t\tof_type;\n") > dfile + printf("\tconst char\t*of_name;\n") > dfile + printf("};\n\n") > dfile + + printf("static const struct onewire_family " \ + "onewire_famtab[] = {\n") > dfile +} + +$1 == "family" { + printf("#define ONEWIRE_FAMILY_%s\t%s\n", toupper($2), $3) > hfile + printf("\t{ ONEWIRE_FAMILY_%s, \"", toupper($2)) > dfile + + f = 4 + while (f <= NF) { + if (f > 4) + printf(" ") > dfile + printf("%s", $f) > dfile + f++ + } + printf("\" },\n") > dfile + next +} + +END { + printf("\t{ 0, NULL }\n};\n") > dfile +} Added: projects/onewire/sys/dev/onewire/onewire.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/onewire/sys/dev/onewire/onewire.c Thu Oct 6 21:31:21 2011 (r226077) @@ -0,0 +1,264 @@ +/* $OpenBSD: onewire_subr.c,v 1.4 2010/07/19 23:44:09 deraadt Exp $ */ + +/* + * Copyright (c) 2006 Alexander Yurchenko + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * 1-Wire bus routines. + */ + +#include +#include +#include + +#include +#include +#include + +#ifdef ONEWIREVERBOSE +#include +#endif + +#include "owbus_if.h" + +static const uint8_t crc8_table[] = { + 0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, + 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, + 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, + 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc, + 0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c, 0xfe, 0xa0, + 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde, 0x3c, 0x62, + 0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, + 0x7c, 0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff, + 0x46, 0x18, 0xfa, 0xa4, 0x27, 0x79, 0x9b, 0xc5, + 0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07, + 0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, + 0x19, 0x47, 0xa5, 0xfb, 0x78, 0x26, 0xc4, 0x9a, + 0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, + 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24, + 0xf8, 0xa6, 0x44, 0x1a, 0x99, 0xc7, 0x25, 0x7b, + 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9, + 0x8c, 0xd2, 0x30, 0x6e, 0xed, 0xb3, 0x51, 0x0f, + 0x4e, 0x10, 0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd, + 0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, + 0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50, + 0xaf, 0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, + 0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee, + 0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1, + 0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73, + 0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, + 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5, 0x8b, + 0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, + 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16, + 0xe9, 0xb7, 0x55, 0x0b, 0x88, 0xd6, 0x34, 0x6a, + 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8, + 0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, + 0xb6, 0xe8, 0x0a, 0x54, 0xd7, 0x89, 0x6b, 0x35 +}; + +static const uint8_t crc16_table_low[] = { + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x00, 0xc1, 0x81, 0x40, 0x01, 0xc0, 0x80, 0x41, + 0x01, 0xc0, 0x80, 0x41, 0x00, 0xc1, 0x81, 0x40 +}; + +static const uint8_t crc16_table_high[] = { + 0x00, 0xc0, 0xc1, 0x01, 0xc3, 0x03, 0x02, 0xc2, + 0xc6, 0x06, 0x07, 0xc7, 0x05, 0xc5, 0xc4, 0x04, + 0xcc, 0x0c, 0x0d, 0xcd, 0x0f, 0xcf, 0xce, 0x0e, + 0x0a, 0xca, 0xcb, 0x0b, 0xc9, 0x09, 0x08, 0xc8, + 0xd8, 0x18, 0x19, 0xd9, 0x1b, 0xdb, 0xda, 0x1a, + 0x1e, 0xde, 0xdf, 0x1f, 0xdd, 0x1d, 0x1c, 0xdc, + 0x14, 0xd4, 0xd5, 0x15, 0xd7, 0x17, 0x16, 0xd6, + 0xd2, 0x12, 0x13, 0xd3, 0x11, 0xd1, 0xd0, 0x10, + 0xf0, 0x30, 0x31, 0xf1, 0x33, 0xf3, 0xf2, 0x32, + 0x36, 0xf6, 0xf7, 0x37, 0xf5, 0x35, 0x34, 0xf4, + 0x3c, 0xfc, 0xfd, 0x3d, 0xff, 0x3f, 0x3e, 0xfe, + 0xfa, 0x3a, 0x3b, 0xfb, 0x39, 0xf9, 0xf8, 0x38, + 0x28, 0xe8, 0xe9, 0x29, 0xeb, 0x2b, 0x2a, 0xea, + 0xee, 0x2e, 0x2f, 0xef, 0x2d, 0xed, 0xec, 0x2c, + 0xe4, 0x24, 0x25, 0xe5, 0x27, 0xe7, 0xe6, 0x26, + 0x22, 0xe2, 0xe3, 0x23, 0xe1, 0x21, 0x20, 0xe0, + 0xa0, 0x60, 0x61, 0xa1, 0x63, 0xa3, 0xa2, 0x62, + 0x66, 0xa6, 0xa7, 0x67, 0xa5, 0x65, 0x64, 0xa4, + 0x6c, 0xac, 0xad, 0x6d, 0xaf, 0x6f, 0x6e, 0xae, + 0xaa, 0x6a, 0x6b, 0xab, 0x69, 0xa9, 0xa8, 0x68, + 0x78, 0xb8, 0xb9, 0x79, 0xbb, 0x7b, 0x7a, 0xba, + 0xbe, 0x7e, 0x7f, 0xbf, 0x7d, 0xbd, 0xbc, 0x7c, + 0xb4, 0x74, 0x75, 0xb5, 0x77, 0xb7, 0xb6, 0x76, + 0x72, 0xb2, 0xb3, 0x73, 0xb1, 0x71, 0x70, 0xb0, + 0x50, 0x90, 0x91, 0x51, 0x93, 0x53, 0x52, 0x92, + 0x96, 0x56, 0x57, 0x97, 0x55, 0x95, 0x94, 0x54, + 0x9c, 0x5c, 0x5d, 0x9d, 0x5f, 0x9f, 0x9e, 0x5e, + 0x5a, 0x9a, 0x9b, 0x5b, 0x99, 0x59, 0x58, 0x98, + 0x88, 0x48, 0x49, 0x89, 0x4b, 0x8b, 0x8a, 0x4a, + 0x4e, 0x8e, 0x8f, 0x4f, 0x8d, 0x4d, 0x4c, 0x8c, + 0x44, 0x84, 0x85, 0x45, 0x87, 0x47, 0x46, 0x86, + 0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40 +}; + +void +onewire_lock(device_t dev) +{ + return (OWBUS_LOCK_BUS(dev)); +} + +void +onewire_unlock(device_t dev) +{ + return (OWBUS_UNLOCK_BUS(dev)); +} + +int +onewire_reset(device_t dev) +{ + return (OWBUS_RESET(dev)); +} + +int +onewire_bit(device_t dev, int val) +{ + return (OWBUS_BIT(dev, val)); +} + +int +onewire_read_byte(device_t dev) +{ + return (OWBUS_READ_BYTE(dev)); +} + +void +onewire_write_byte(device_t dev, int val) +{ + return (OWBUS_WRITE_BYTE(dev, val)); +} + +void +onewire_read_block(device_t dev, void *buf, int len) +{ + return (OWBUS_READ_BLOCK(dev, buf, len)); +} + +void +onewire_write_block(device_t dev, const void *buf, int len) +{ + return (OWBUS_WRITE_BLOCK(dev, buf, len)); +} + +int +onewire_triplet(device_t dev, int dir) +{ + return (OWBUS_TRIPLET(dev, dir)); +} + +void +onewire_matchrom(device_t dev, uint64_t rom) +{ + return (OWBUS_MATCHROM(dev, rom)); +} + +int +onewire_search(device_t dev, uint64_t *buf, int size, uint64_t startrom) +{ + return (OWBUS_SEARCH(dev, buf, size, startrom)); +} + +int +onewire_crc(const void *buf, int len) +{ + const uint8_t *p = buf; + uint8_t crc = 0; + + while (len--) + crc = crc8_table[crc ^ *p++]; + + return (crc); +} + +uint16_t +onewire_crc16(const void *buf, int len) +{ + const uint8_t *p = buf; + uint16_t crc = 0; + uint16_t tmpcrc; + int idx; + + while (len--) { + idx = (crc & 0xff) ^ *p++; + tmpcrc = crc16_table_high[idx] << 8; + tmpcrc |= crc16_table_low[idx] ^ (crc >> 8); + crc = tmpcrc; + } + + return (crc); +} + +const char * +onewire_famname(int type) +{ +#ifdef ONEWIREVERBOSE + const struct onewire_family *of; + + for (of = onewire_famtab; of->of_name != NULL; of++) + if (of->of_type == type) + return (of->of_name); +#endif + + return (NULL); +} + +const struct onewire_matchfam * +onewire_matchbyfam(struct onewire_attach_args *oa, + const struct onewire_matchfam *fams, int nent) +{ + const struct onewire_matchfam *om; + int i; + + for (i = 0, om = fams; i < nent; i++, om++) + if (ONEWIRE_ROM_FAMILY_TYPE(oa->oa_rom) == om->om_type) + return (om); + + return (NULL); +} Added: projects/onewire/sys/dev/onewire/onewirebb.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/onewire/sys/dev/onewire/onewirebb.c Thu Oct 6 21:31:21 2011 (r226077) @@ -0,0 +1,343 @@ +/* $OpenBSD: onewire_bitbang.c,v 1.2 2010/07/02 03:13:42 tedu Exp $ */ + +/* + * Copyright (c) 2006 Alexander Yurchenko + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * 1-Wire bus bit-banging routines. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "owbb_if.h" +#include "owbus_if.h" + +struct owbb_softc { + device_t owbus; +}; + +static int owbb_probe(device_t); +static int owbb_attach(device_t); +static int owbb_detach(device_t); + +static int owbb_reset(device_t); +static int owbb_bit(device_t, int); +static int owbb_read_byte(device_t); +static void owbb_write_byte(device_t, int); +static void owbb_read_block(device_t, void *, int); +static void owbb_write_block(device_t, const void *, int); +static int owbb_triplet(device_t, int); +static void owbb_matchrom(device_t, uint64_t); +static int owbb_search(device_t, uint64_t *, int, uint64_t); + +static int +owbb_probe(device_t dev) +{ + device_set_desc(dev, "1wire bit-banging driver"); + + return (0); +} + +static int +owbb_attach(device_t dev) +{ + struct owbb_softc *sc = (struct owbb_softc *)device_get_softc(dev); + + sc->owbus = device_add_child(dev, "owbus", -1); + if (!sc->owbus) + return (ENXIO); + bus_generic_attach(dev); + + return (0); +} + +static int +owbb_detach(device_t dev) +{ + struct owbb_softc *sc = (struct owbb_softc *)device_get_softc(dev); + device_t child; + + /* + * We need to save child because the detach indirectly causes + * sc->owbus to be zeroed. Since we added the device + * unconditionally in owbb_attach, we need to make sure we + * delete it here. See owbb_child_detached. We need that + * callback in case newbus detached our children w/o detaching + * us (say owbus is a module and unloaded w/o owbb being + * unloaded). + */ + child = sc->owbus; + bus_generic_detach(dev); + if (child) + device_delete_child(dev, child); + + return (0); +} + +static void +owbb_child_detached( device_t dev, device_t child ) +{ + struct owbb_softc *sc = (struct owbb_softc *)device_get_softc(dev); + + if (child == sc->owbus) + sc->owbus = NULL; +} + +static int +owbb_reset(device_t dev) +{ + device_t pdev = device_get_parent(dev); + int rv, i; + + OWBB_TX(pdev); + OWBB_SET(pdev, 0); + DELAY(480); + OWBB_SET(pdev, 1); + OWBB_RX(pdev); + DELAY(30); + for (i = 0; i < 6; i++) { + if ((rv = OWBB_GET(pdev)) == 0) + break; + DELAY(20); + } + DELAY(450); + + return (rv); +} + +static int +owbb_bit(device_t dev, int value) +{ + device_t pdev = device_get_parent(dev); + int rv, i; + + OWBB_TX(pdev); + OWBB_SET(pdev, 0); + DELAY(2); + rv = 0; + if (value) { + OWBB_SET(pdev, 1); + OWBB_RX(pdev); + for (i = 0; i < 15; i++) { + if ((rv = OWBB_GET(pdev)) == 0) + break; + DELAY(2); + } + OWBB_TX(pdev); + } + DELAY(60); + OWBB_SET(pdev, 1); + DELAY(5); + + return (rv); +} + +static int +owbb_read_byte(device_t dev) +{ + uint8_t value = 0; + int i; + + for (i = 0; i < 8; i++) + value |= (owbb_bit(dev, 1) << i); + + return (value); +} + +static void +owbb_write_byte(device_t dev, int value) +{ + int i; + + for (i = 0; i < 8; i++) + owbb_bit(dev, (value >> i) & 0x1); +} + +static void +owbb_read_block(device_t dev, void *buf, int len) +{ + uint8_t *p = buf; + + while (len--) + *p++ = owbb_read_byte(dev); +} + +static void +owbb_write_block(device_t dev, const void *buf, int len) +{ + const uint8_t *p = buf; + + while (len--) + owbb_write_byte(dev, *p++); +} + +static int +owbb_triplet(device_t dev, int dir) +{ + int rv; + + rv = owbb_bit(dev, 1); + rv <<= 1; + rv |= owbb_bit(dev, 1); + + switch (rv) { + case 0x0: + owbb_bit(dev, dir); + break; + case 0x1: + owbb_bit(dev, 0); + break; + default: + owbb_bit(dev, 1); + } + + return (rv); +} + +static void +owbb_matchrom(device_t dev, uint64_t rom) +{ + int i; + + owbb_write_byte(dev, ONEWIRE_CMD_MATCH_ROM); + for (i = 0; i < 8; i++) + owbb_write_byte(dev, (rom >> (i * 8)) & 0xff); +} + +static int +owbb_search(device_t dev, uint64_t *buf, int size, uint64_t startrom) +{ + int search = 1, count = 0, lastd = -1, dir, rv, i, i0; + uint64_t mask, rom = startrom, lastrom; + uint8_t data[8]; + + while (search && count < size) { + /* XXX: yield processor */ + tsleep(dev, PWAIT, "owscan", hz / 10); + + /* + * Start new search. Go through the previous path to + * the point we made a decision last time and make an + * opposite decision. If we didn't make any decision + * stop searching. + */ + lastrom = rom; + rom = 0; + OWBUS_LOCK_BUS(dev); + owbb_reset(dev); + owbb_write_byte(dev, ONEWIRE_CMD_SEARCH_ROM); + for (i = 0, i0 = -1; i < 64; i++) { + dir = (lastrom >> i) & 0x1; + if (i == lastd) + dir = 1; + else if (i > lastd) + dir = 0; + rv = owbb_triplet(dev, dir); + switch (rv) { + case 0x0: + if (i != lastd && dir == 0) + i0 = i; + mask = dir; + break; + case 0x1: + mask = 0; + break; + case 0x2: + mask = 1; + break; + default: + printf("%s: search triplet error 0x%x, " + "step %d\n", + device_get_nameunit(dev), rv, i); + OWBUS_UNLOCK_BUS(dev); + return (-1); + } + rom |= (mask << i); + } + OWBUS_UNLOCK_BUS(dev); + + if ((lastd = i0) == -1) + search = 0; + + if (rom == 0) + continue; + + /* + * The last byte of the ROM code contains a CRC calculated + * from the first 7 bytes. Re-calculate it to make sure + * we found a valid device. + */ + for (i = 0; i < 8; i++) + data[i] = (rom >> (i * 8)) & 0xff; + if (onewire_crc(data, 7) != data[7]) + continue; + + buf[count++] = rom; + } + + return (count); +} +static device_method_t owbb_methods[] = { + /* device interface */ + DEVMETHOD(device_probe, owbb_probe), + DEVMETHOD(device_attach, owbb_attach), + DEVMETHOD(device_detach, owbb_detach), + + /* bus interface */ + DEVMETHOD(bus_child_detached, owbb_child_detached), + + /* ONEWIRE protocol */ + DEVMETHOD(owbus_bit, owbb_bit), + DEVMETHOD(owbus_reset, owbb_reset), + DEVMETHOD(owbus_read_byte, owbb_read_byte), + DEVMETHOD(owbus_write_byte, owbb_write_byte), + DEVMETHOD(owbus_read_block, owbb_read_block), + DEVMETHOD(owbus_write_block, owbb_write_block), + DEVMETHOD(owbus_triplet, owbb_triplet), + DEVMETHOD(owbus_matchrom, owbb_matchrom), + DEVMETHOD(owbus_search, owbb_search), + + + { 0, 0 } +}; + +driver_t owbb_driver = { + "owbb", + owbb_methods, + sizeof(struct owbb_softc), +}; + +devclass_t owbb_devclass; + +DRIVER_MODULE(owbus, owbb, owbus_driver, owbus_devclass, 0, 0); + +MODULE_DEPEND(owbb, owbus, 1, 1, 1); +MODULE_VERSION(owbb, 1); Added: projects/onewire/sys/dev/onewire/onewirebus.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/onewire/sys/dev/onewire/onewirebus.c Thu Oct 6 21:31:21 2011 (r226077) @@ -0,0 +1,371 @@ +/* $OpenBSD: onewire.c,v 1.12 2011/07/03 15:47:16 matthew Exp $ */ + +/* + * Copyright (c) 2006 Alexander Yurchenko + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * 1-Wire bus driver. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "owbus_if.h" + +#define ONEWIRE_DEBUG +#ifdef ONEWIRE_DEBUG +#define DPRINTF(x) printf x +#else +#define DPRINTF(x) +#endif + +#define OWBUS_IVAR(d) (struct owbus_ivar *) device_get_ivars(d) +#define OWBUS_SOFTC(d) (struct owbus_softc *) device_get_softc(d) + +#define OWBUS_LOCK(_sc) mtx_lock(&(_sc)->sc_mtx) +#define OWBUS_UNLOCK(_sc) mtx_unlock(&(_sc)->sc_mtx) +#define OWBUS_LOCK_INIT(_sc) \ + mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->sc_busdev), \ + "owbus", MTX_DEF) +#define OWBUS_LOCK_DESTROY(_sc) mtx_destroy(&_sc->sc_mtx); +#define OWBUS_ASSERT_LOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_OWNED); +#define OWBUS_ASSERT_UNLOCKED(_sc) mtx_assert(&_sc->sc_mtx, MA_NOTOWNED); + +struct onewire_device +{ + TAILQ_ENTRY(onewire_device) d_list; + struct device * d_dev; /* may be NULL */ + uint64_t d_rom; + int d_present; +}; + +struct owbus_softc +{ + struct mtx sc_mtx; /* bus mutex */ + device_t sc_busdev; /* bus device */ + device_t sc_owner; /* bus owner */ + device_t sc_dev; /* driver device */ + struct proc *sc_p; + uint64_t sc_rombuf[ONEWIRE_MAXDEVS]; + TAILQ_HEAD(, onewire_device) sc_devs; +}; + +static int owbus_probe(device_t); +static int owbus_attach(device_t); +static int owbus_detach(device_t); + +static void owbus_lock_bus(device_t); +static void owbus_unlock_bus(device_t); +static int owbus_reset(device_t); +static int owbus_bit(device_t, int); +static int owbus_read_byte(device_t); +static void owbus_write_byte(device_t, int); +static void owbus_read_block(device_t, void *, int); +static void owbus_write_block(device_t, const void *, int); +static int owbus_triplet(device_t, int); +static void owbus_matchrom(device_t, uint64_t); +static int owbus_search(device_t, uint64_t *, int, uint64_t); + +static void owbus_thread(void *); +static void owbus_scan(struct owbus_softc *); + +static int +owbus_probe(device_t dev) +{ + device_set_desc(dev, "onewire bus"); + return (0); +} + +static int +owbus_attach(device_t dev) +{ + struct owbus_softc *sc = OWBUS_SOFTC(dev); + + sc->sc_busdev = dev; + sc->sc_dev = device_get_parent(dev); + OWBUS_LOCK_INIT(sc); + TAILQ_INIT(&sc->sc_devs); + + kproc_create(&owbus_thread, sc, &sc->sc_p, 0, 0, "%s scan", device_get_nameunit(dev)); + + return (bus_generic_attach(dev)); +} + +int +owbus_detach(struct device *dev) +{ + struct owbus_softc *sc = OWBUS_SOFTC(dev); + + OWBUS_LOCK_DESTROY(sc); + + return (0); *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Fri Oct 7 04:26:24 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A89A0106564A; Fri, 7 Oct 2011 04:26:24 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 452258FC13; Fri, 7 Oct 2011 04:26:24 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p974QOMD092323; Fri, 7 Oct 2011 04:26:24 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p974QOsa092322; Fri, 7 Oct 2011 04:26:24 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110070426.p974QOsa092322@svn.freebsd.org> From: Lawrence Stewart Date: Fri, 7 Oct 2011 04:26:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226084 - in projects: tcp_cc_7.x tcp_cc_8.x tcp_cc_head X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 04:26:24 -0000 Author: lstewart Date: Fri Oct 7 04:26:23 2011 New Revision: 226084 URL: http://svn.freebsd.org/changeset/base/226084 Log: The modular congestion control framework has been merged to head, so the project branches are no longer needed. Deleted: projects/tcp_cc_7.x/ projects/tcp_cc_8.x/ projects/tcp_cc_head/ From owner-svn-src-projects@FreeBSD.ORG Fri Oct 7 04:28:33 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AFAE1106564A; Fri, 7 Oct 2011 04:28:33 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 867538FC08; Fri, 7 Oct 2011 04:28:33 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p974SXma092631; Fri, 7 Oct 2011 04:28:33 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p974SXqB092630; Fri, 7 Oct 2011 04:28:33 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110070428.p974SXqB092630@svn.freebsd.org> From: Lawrence Stewart Date: Fri, 7 Oct 2011 04:28:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226085 - in projects: tcp_ffcaia2008_8.x tcp_ffcaia2008_head X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 04:28:33 -0000 Author: lstewart Date: Fri Oct 7 04:28:33 2011 New Revision: 226085 URL: http://svn.freebsd.org/changeset/base/226085 Log: The relevant work from these branches has been merged to head, so the project branches are no longer needed. Deleted: projects/tcp_ffcaia2008_8.x/ projects/tcp_ffcaia2008_head/ From owner-svn-src-projects@FreeBSD.ORG Fri Oct 7 04:32:40 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0906F1065686; Fri, 7 Oct 2011 04:32:40 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id ED95E8FC0A; Fri, 7 Oct 2011 04:32:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p974WdUA092905; Fri, 7 Oct 2011 04:32:39 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p974WdiB092904; Fri, 7 Oct 2011 04:32:39 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110070432.p974WdiB092904@svn.freebsd.org> From: Lawrence Stewart Date: Fri, 7 Oct 2011 04:32:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226086 - projects/diffused_head X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 04:32:40 -0000 Author: lstewart Date: Fri Oct 7 04:32:39 2011 New Revision: 226086 URL: http://svn.freebsd.org/changeset/base/226086 Log: Create a temporary project branch for the FreeBSD Foundation sponsored "DIFFUSED" (DIFFUSE for freebsD) project. The project will integrate the DIFFUSE (DIstributed Firewall and Flow-shaper Using Statistical Evidence) prototype developed at Swinburne University of Technology's Centre for Advanced Internet Architectures into FreeBSD, with code cleanup/auditing and some feature development along the way. More details about the project are available at: http://caia.swin.edu.au/freebsd/diffused/ Sponsored by: Cisco URP, FreeBSD Foundation Added: - copied from r226085, head/ Directory Properties: projects/diffused_head/ (props changed) From owner-svn-src-projects@FreeBSD.ORG Fri Oct 7 05:08:08 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D84811065675; Fri, 7 Oct 2011 05:08:08 +0000 (UTC) (envelope-from grehan@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C70E58FC08; Fri, 7 Oct 2011 05:08:08 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p97588nW093994; Fri, 7 Oct 2011 05:08:08 GMT (envelope-from grehan@svn.freebsd.org) Received: (from grehan@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p97588c0093985; Fri, 7 Oct 2011 05:08:08 GMT (envelope-from grehan@svn.freebsd.org) Message-Id: <201110070508.p97588c0093985@svn.freebsd.org> From: Peter Grehan Date: Fri, 7 Oct 2011 05:08:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226087 - in projects/virtio/sys/dev/virtio: . block network pci X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 05:08:08 -0000 Author: grehan Date: Fri Oct 7 05:08:08 2011 New Revision: 226087 URL: http://svn.freebsd.org/changeset/base/226087 Log: Sync to the most recent change #162494 in Bryan Venteicher's hg repo Modified: projects/virtio/sys/dev/virtio/block/virtio_blk.c projects/virtio/sys/dev/virtio/network/if_vtnet.c projects/virtio/sys/dev/virtio/network/if_vtnetvar.h projects/virtio/sys/dev/virtio/pci/virtio_pci.c projects/virtio/sys/dev/virtio/virtio.c projects/virtio/sys/dev/virtio/virtio.h projects/virtio/sys/dev/virtio/virtqueue.c projects/virtio/sys/dev/virtio/virtqueue.h Modified: projects/virtio/sys/dev/virtio/block/virtio_blk.c ============================================================================== --- projects/virtio/sys/dev/virtio/block/virtio_blk.c Fri Oct 7 04:32:39 2011 (r226086) +++ projects/virtio/sys/dev/virtio/block/virtio_blk.c Fri Oct 7 05:08:08 2011 (r226087) @@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include @@ -69,8 +68,11 @@ struct vtblk_softc { struct mtx vtblk_mtx; uint64_t vtblk_features; uint32_t vtblk_flags; -#define VTBLK_FLAG_READONLY 0x0001 -#define VTBLK_FLAG_DETACHING 0x0002 +#define VTBLK_FLAG_INDIRECT 0x0001 +#define VTBLK_FLAG_READONLY 0x0002 +#define VTBLK_FLAG_DETACHING 0x0004 +#define VTBLK_FLAG_SUSPENDED 0x0008 +#define VTBLK_FLAG_DUMPING 0x0010 struct virtqueue *vtblk_vq; struct sglist *vtblk_sglist; @@ -78,6 +80,8 @@ struct vtblk_softc { struct bio_queue_head vtblk_bioq; TAILQ_HEAD(, vtblk_request) + vtblk_req_free; + TAILQ_HEAD(, vtblk_request) vtblk_req_ready; struct taskqueue *vtblk_tq; @@ -86,6 +90,9 @@ struct vtblk_softc { int vtblk_sector_size; int vtblk_max_nsegs; int vtblk_unit; + int vtblk_request_count; + + struct vtblk_request vtblk_dump_request; }; static struct virtio_feature_desc vtblk_feature_desc[] = { @@ -112,6 +119,8 @@ static int vtblk_resume(device_t); static int vtblk_shutdown(device_t); static void vtblk_negotiate_features(struct vtblk_softc *); +static int vtblk_maximum_segments(struct vtblk_softc *, + struct virtio_blk_config *); static int vtblk_alloc_virtqueue(struct vtblk_softc *); static void vtblk_alloc_disk(struct vtblk_softc *, struct virtio_blk_config *); @@ -126,7 +135,7 @@ static void vtblk_strategy(struct bio *) static void vtblk_startio(struct vtblk_softc *); static struct vtblk_request * vtblk_bio_request(struct vtblk_softc *); static int vtblk_execute_request(struct vtblk_softc *, - struct vtblk_request **); + struct vtblk_request *); static int vtblk_vq_intr(void *); static void vtblk_intr_task(void *, int); @@ -135,16 +144,20 @@ static void vtblk_stop(struct vtblk_soft static void vtblk_get_ident(struct vtblk_softc *); static void vtblk_prepare_dump(struct vtblk_softc *); -static int vtblk_write_dump(struct vtblk_softc *, void *, off_t, - size_t, struct vtblk_request **); -static int vtblk_flush_dump(struct vtblk_softc *, - struct vtblk_request **); +static int vtblk_write_dump(struct vtblk_softc *, void *, off_t, size_t); +static int vtblk_flush_dump(struct vtblk_softc *); static int vtblk_poll_request(struct vtblk_softc *, - struct vtblk_request **); + struct vtblk_request *); static void vtblk_drain_vq(struct vtblk_softc *, int); static void vtblk_drain(struct vtblk_softc *); +static int vtblk_alloc_requests(struct vtblk_softc *); +static void vtblk_free_requests(struct vtblk_softc *); +static struct vtblk_request * vtblk_dequeue_request(struct vtblk_softc *); +static void vtblk_enqueue_request(struct vtblk_softc *, + struct vtblk_request *); + static struct vtblk_request * vtblk_dequeue_ready(struct vtblk_softc *); static void vtblk_enqueue_ready(struct vtblk_softc *, struct vtblk_request *); @@ -164,7 +177,7 @@ TUNABLE_INT("hw.vtblk.no_ident", &vtblk_ VIRTIO_BLK_F_RO | \ VIRTIO_BLK_F_BLK_SIZE | \ VIRTIO_BLK_F_FLUSH | \ - VIRTIO_F_RING_INDIRECT_DESC) + VIRTIO_RING_F_INDIRECT_DESC) #define VTBLK_MTX(_sc) &(_sc)->vtblk_mtx #define VTBLK_LOCK_INIT(_sc, _name) \ @@ -178,8 +191,16 @@ TUNABLE_INT("hw.vtblk.no_ident", &vtblk_ #define VTBLK_LOCK_ASSERT_NOTOWNED(_sc) \ mtx_assert(VTBLK_MTX((_sc)), MA_NOTOWNED) +#define VTBLK_BIO_SEGMENTS(_bp) sglist_count((_bp)->bio_data, (_bp)->bio_bcount) + #define VTBLK_DISK_NAME "vtbd" +/* + * Each block request uses at least two segments - one for the header + * and one for the status. + */ +#define VTBLK_MIN_SEGMENTS 2 + static uma_zone_t vtblk_req_zone; static device_method_t vtblk_methods[] = { @@ -264,11 +285,18 @@ vtblk_attach(device_t dev) VTBLK_LOCK_INIT(sc, device_get_nameunit(dev)); bioq_init(&sc->vtblk_bioq); + TAILQ_INIT(&sc->vtblk_req_free); TAILQ_INIT(&sc->vtblk_req_ready); virtio_set_feature_desc(dev, vtblk_feature_desc); vtblk_negotiate_features(sc); + if (virtio_with_feature(dev, VIRTIO_RING_F_INDIRECT_DESC)) + sc->vtblk_flags |= VTBLK_FLAG_INDIRECT; + + if (virtio_with_feature(dev, VIRTIO_BLK_F_RO)) + sc->vtblk_flags |= VTBLK_FLAG_READONLY; + /* Get local copy of config. */ if (virtio_with_feature(dev, VIRTIO_BLK_F_TOPOLOGY) == 0) { bzero(&blkcfg, sizeof(struct virtio_blk_config)); @@ -284,26 +312,16 @@ vtblk_attach(device_t dev) * segments are coalesced. For now, just make sure it's larger * than the maximum supported transfer size. */ - if (virtio_with_feature(dev, VIRTIO_BLK_F_SIZE_MAX) && - blkcfg.size_max < MAXPHYS) { - error = ENOTSUP; - device_printf(dev, "host requires unsupported maximum segment " - "size feature\n"); - goto fail; + if (virtio_with_feature(dev, VIRTIO_BLK_F_SIZE_MAX)) { + if (blkcfg.size_max < MAXPHYS) { + error = ENOTSUP; + device_printf(dev, "host requires unsupported " + "maximum segment size feature\n"); + goto fail; + } } - /* Two segments are needed for the header and status. */ - sc->vtblk_max_nsegs = 2; - - if (virtio_with_feature(dev, VIRTIO_BLK_F_SEG_MAX)) { - sc->vtblk_max_nsegs += MIN(blkcfg.seg_max, - MAXPHYS/PAGE_SIZE + 1); - } else - sc->vtblk_max_nsegs += 1; - - if (virtio_with_feature(dev, VIRTIO_F_RING_INDIRECT_DESC)) - if (sc->vtblk_max_nsegs > VIRTIO_MAX_INDIRECT) - sc->vtblk_max_nsegs = VIRTIO_MAX_INDIRECT; + sc->vtblk_max_nsegs = vtblk_maximum_segments(sc, &blkcfg); /* * Allocate working sglist. The number of segments may be too @@ -322,8 +340,11 @@ vtblk_attach(device_t dev) goto fail; } - if (virtio_with_feature(dev, VIRTIO_BLK_F_RO)) - sc->vtblk_flags |= VTBLK_FLAG_READONLY; + error = vtblk_alloc_requests(sc); + if (error) { + device_printf(dev, "cannot preallocate requests\n"); + goto fail; + } vtblk_alloc_disk(sc, &blkcfg); @@ -399,7 +420,10 @@ vtblk_suspend(device_t dev) sc = device_get_softc(dev); - /* TODO */ + VTBLK_LOCK(sc); + sc->vtblk_flags |= VTBLK_FLAG_SUSPENDED; + /* TODO Wait for any inflight IO to complete? */ + VTBLK_UNLOCK(sc); return (0); } @@ -411,7 +435,10 @@ vtblk_resume(device_t dev) sc = device_get_softc(dev); - /* TODO */ + VTBLK_LOCK(sc); + sc->vtblk_flags &= ~VTBLK_FLAG_SUSPENDED; + /* TODO Resume IO? */ + VTBLK_UNLOCK(sc); return (0); } @@ -420,7 +447,7 @@ static int vtblk_shutdown(device_t dev) { - return (vtblk_suspend(dev)); + return (0); } static int @@ -461,10 +488,8 @@ static int vtblk_dump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) { - static struct vtblk_request *req = NULL; - static struct bio buf; - struct vtblk_softc *sc; struct disk *dp; + struct vtblk_softc *sc; int error; dp = arg; @@ -475,31 +500,19 @@ vtblk_dump(void *arg, void *virtual, vm_ if (VTBLK_TRYLOCK(sc) == 0) { device_printf(sc->vtblk_dev, - "softc lock already acquired, cannot dump...\n"); + "softc already locked, cannot dump...\n"); return (EBUSY); } - if (req == NULL) { - /* - * Allocate request structure. It isn't safe to use one - * off the stack because it could cross a page boundary. - */ - req = uma_zalloc(vtblk_req_zone, M_NOWAIT | M_ZERO); - if (req == NULL) { - VTBLK_UNLOCK(sc); - return (ENOMEM); - } - + if ((sc->vtblk_flags & VTBLK_FLAG_DUMPING) == 0) { vtblk_prepare_dump(sc); + sc->vtblk_flags |= VTBLK_FLAG_DUMPING; } - req->vbr_bp = &buf; - bzero(req->vbr_bp, sizeof(struct bio)); - if (length > 0) - error = vtblk_write_dump(sc, virtual, offset, length, &req); + error = vtblk_write_dump(sc, virtual, offset, length); else if (virtual == NULL && offset == 0) - error = vtblk_flush_dump(sc, &req); + error = vtblk_flush_dump(sc); VTBLK_UNLOCK(sc); @@ -526,6 +539,18 @@ vtblk_strategy(struct bio *bp) return; } + /* + * Prevent read/write buffers spanning too many segments from + * getting into the queue. + */ + if (bp->bio_cmd == BIO_READ || bp->bio_cmd == BIO_WRITE) { + KASSERT(VTBLK_BIO_SEGMENTS(bp) <= sc->vtblk_max_nsegs - + VTBLK_MIN_SEGMENTS, + ("bio spanned too many segments: %d, max: %d", + VTBLK_BIO_SEGMENTS(bp), + sc->vtblk_max_nsegs - VTBLK_MIN_SEGMENTS)); + } + VTBLK_LOCK(sc); if ((sc->vtblk_flags & VTBLK_FLAG_DETACHING) == 0) { bioq_disksort(&sc->vtblk_bioq, bp); @@ -548,6 +573,26 @@ vtblk_negotiate_features(struct vtblk_so } static int +vtblk_maximum_segments(struct vtblk_softc *sc, + struct virtio_blk_config *blkcfg) +{ + device_t dev; + int nsegs; + + dev = sc->vtblk_dev; + nsegs = VTBLK_MIN_SEGMENTS; + + if (virtio_with_feature(dev, VIRTIO_BLK_F_SEG_MAX)) { + nsegs += MIN(blkcfg->seg_max, MAXPHYS / PAGE_SIZE + 1); + if (sc->vtblk_flags & VTBLK_FLAG_INDIRECT) + nsegs = MIN(nsegs, VIRTIO_MAX_INDIRECT); + } else + nsegs += 1; + + return (nsegs); +} + +static int vtblk_alloc_virtqueue(struct vtblk_softc *sc) { device_t dev; @@ -596,15 +641,16 @@ vtblk_alloc_disk(struct vtblk_softc *sc, * However, FreeBSD limits I/O size by logical buffer size, not * by physically contiguous pages. Therefore, we have to assume * no pages are contiguous. This may impose an artificially low - * maximum I/O size. But in practice, since QEMU/KVM advertises - * 128 segments, this gives us a max IO size of 125 * PAGE_SIZE, + * maximum I/O size. But in practice, since QEMU advertises 128 + * segments, this gives us a maxinum IO size of 125 * PAGE_SIZE, * which is typically greater than MAXPHYS. Eventually we should * just advertise MAXPHYS and split buffers that are too big. * - * Note three segments are reserved for the header, ack and non + * Note we must subtract one additional segment in case of non * page aligned buffers. */ - dp->d_maxsize = (sc->vtblk_max_nsegs - 3) * PAGE_SIZE; + dp->d_maxsize = (sc->vtblk_max_nsegs - VTBLK_MIN_SEGMENTS - 1) * + PAGE_SIZE; if (dp->d_maxsize < PAGE_SIZE) dp->d_maxsize = PAGE_SIZE; /* XXX */ @@ -631,19 +677,16 @@ vtblk_startio(struct vtblk_softc *sc) VTBLK_LOCK_ASSERT(sc); + if (sc->vtblk_flags & VTBLK_FLAG_SUSPENDED) + return; + while (!virtqueue_full(vq)) { if ((req = vtblk_dequeue_ready(sc)) == NULL) req = vtblk_bio_request(sc); if (req == NULL) break; - if (vtblk_execute_request(sc, &req) != 0) { - if (req == NULL) - continue; - /* - * Requeue request; we will process it - * first later. - */ + if (vtblk_execute_request(sc, req) != 0) { vtblk_enqueue_ready(sc, req); break; } @@ -667,7 +710,7 @@ vtblk_bio_request(struct vtblk_softc *sc if (bioq_first(bioq) == NULL) return (NULL); - req = uma_zalloc(vtblk_req_zone, M_NOWAIT | M_ZERO); + req = vtblk_dequeue_request(sc); if (req == NULL) return (NULL); @@ -701,14 +744,12 @@ vtblk_bio_request(struct vtblk_softc *sc } static int -vtblk_execute_request(struct vtblk_softc *sc, struct vtblk_request **reqp) +vtblk_execute_request(struct vtblk_softc *sc, struct vtblk_request *req) { - struct vtblk_request *req; struct sglist *sg; struct bio *bp; int writable, error; - req = *reqp; sg = sc->vtblk_sglist; bp = req->vbr_bp; writable = 0; @@ -718,23 +759,13 @@ vtblk_execute_request(struct vtblk_softc sglist_reset(sg); error = sglist_append(sg, &req->vbr_hdr, sizeof(struct virtio_blk_outhdr)); - KASSERT(error == 0 && sg->sg_nseg == 1, ("error adding header " - "to sglist; error=%d, nsegs=%d", error, sg->sg_nseg)); + KASSERT(error == 0, ("error adding header to sglist")); + KASSERT(sg->sg_nseg == 1, + ("header spanned multiple segments: %d", sg->sg_nseg)); if (bp->bio_cmd == BIO_READ || bp->bio_cmd == BIO_WRITE) { error = sglist_append(sg, bp->bio_data, bp->bio_bcount); - if (error) { - device_printf(sc->vtblk_dev, - "buffer spanned too many segments; max: %d; " - "needed: %d\n", sc->vtblk_max_nsegs, - sglist_count(bp->bio_data, bp->bio_bcount)); - - *reqp = NULL; - uma_zfree(vtblk_req_zone, req); - vtblk_bio_error(bp, E2BIG); - - return (error); - } + KASSERT(error == 0, ("error adding buffer to sglist")); /* BIO_READ means the host writes into our buffer. */ if (bp->bio_cmd == BIO_READ) @@ -745,6 +776,9 @@ vtblk_execute_request(struct vtblk_softc KASSERT(error == 0, ("error adding ack to sglist")); writable++; + KASSERT(sg->sg_nseg >= VTBLK_MIN_SEGMENTS, + ("fewer than min segments: %d", sg->sg_nseg)); + error = virtqueue_enqueue(sc->vtblk_vq, req, sg, sg->sg_nseg - writable, writable); @@ -795,7 +829,7 @@ vtblk_intr_task(void *arg, int pending) } biodone(bp); - uma_zfree(vtblk_req_zone, req); + vtblk_enqueue_request(sc, req); } vtblk_startio(sc); @@ -830,7 +864,7 @@ vtblk_get_ident(struct vtblk_softc *sc) dp = sc->vtblk_disk; len = MIN(VIRTIO_BLK_ID_BYTES, DISK_IDENT_SIZE); - req = uma_zalloc(vtblk_req_zone, M_NOWAIT | M_ZERO); + req = vtblk_dequeue_request(sc); if (req == NULL) return; @@ -847,15 +881,14 @@ vtblk_get_ident(struct vtblk_softc *sc) buf.bio_bcount = len; VTBLK_LOCK(sc); - error = vtblk_poll_request(sc, &req); + error = vtblk_poll_request(sc, req); + vtblk_enqueue_request(sc, req); VTBLK_UNLOCK(sc); - if (req != NULL) - uma_zfree(vtblk_req_zone, req); - - if (error) - device_printf(sc->vtblk_dev, "error getting device " - "identifier\n"); + if (error) { + device_printf(sc->vtblk_dev, + "error getting device identifier: %d\n", error); + } } static void @@ -886,78 +919,78 @@ vtblk_prepare_dump(struct vtblk_softc *s static int vtblk_write_dump(struct vtblk_softc *sc, void *virtual, off_t offset, - size_t length, struct vtblk_request **reqp) + size_t length) { + struct bio buf; struct vtblk_request *req; - struct bio *bp; - - req = *reqp; + req = &sc->vtblk_dump_request; req->vbr_ack = -1; req->vbr_hdr.type = VIRTIO_BLK_T_OUT; req->vbr_hdr.ioprio = 1; req->vbr_hdr.sector = offset / 512; - bp = req->vbr_bp; - bp->bio_cmd = BIO_WRITE; - bp->bio_data = virtual; - bp->bio_bcount = length; + req->vbr_bp = &buf; + bzero(&buf, sizeof(struct bio)); - return (vtblk_poll_request(sc, reqp)); + buf.bio_cmd = BIO_WRITE; + buf.bio_data = virtual; + buf.bio_bcount = length; + + return (vtblk_poll_request(sc, req)); } static int -vtblk_flush_dump(struct vtblk_softc *sc, struct vtblk_request **reqp) +vtblk_flush_dump(struct vtblk_softc *sc) { + struct bio buf; struct vtblk_request *req; - struct bio *bp; - - req = *reqp; + req = &sc->vtblk_dump_request; req->vbr_ack = -1; req->vbr_hdr.type = VIRTIO_BLK_T_FLUSH; req->vbr_hdr.ioprio = 1; req->vbr_hdr.sector = 0; - bp = req->vbr_bp; - bp->bio_cmd = BIO_FLUSH; - bp->bio_data = NULL; - bp->bio_bcount = 0; - bp->bio_done = NULL; + req->vbr_bp = &buf; + bzero(&buf, sizeof(struct bio)); + + buf.bio_cmd = BIO_FLUSH; - return (vtblk_poll_request(sc, reqp)); + return (vtblk_poll_request(sc, req)); } static int -vtblk_poll_request(struct vtblk_softc *sc, struct vtblk_request **reqp) +vtblk_poll_request(struct vtblk_softc *sc, struct vtblk_request *req) { device_t dev; struct virtqueue *vq; - struct vtblk_request *r, *req; + struct vtblk_request *r; int error; dev = sc->vtblk_dev; vq = sc->vtblk_vq; - req = *reqp; if (!virtqueue_empty(vq)) return (EBUSY); - error = vtblk_execute_request(sc, reqp); + error = vtblk_execute_request(sc, req); if (error) return (error); + virtqueue_notify(vq); - while ((r = virtqueue_dequeue(vq, NULL)) == NULL) - cpu_spinwait(); - KASSERT(r == req, ("vtblk_poll_request: unexpected request response")); + r = virtqueue_poll(vq, NULL); + KASSERT(r == req, ("unexpected request response")); if (req->vbr_ack != VIRTIO_BLK_S_OK) { - device_printf(dev, "vtblk_poll_request: I/O error\n"); - return (EIO); + error = req->vbr_ack == VIRTIO_BLK_S_UNSUPP ? ENOTSUP : EIO; + if (bootverbose) + device_printf(dev, + "vtblk_poll_request: IO error: %d\n", error); } - return (0); + return (error); } static void @@ -974,7 +1007,7 @@ vtblk_drain_vq(struct vtblk_softc *sc, i if (!skip_done) vtblk_bio_error(req->vbr_bp, ENXIO); - uma_zfree(vtblk_req_zone, req); + vtblk_enqueue_request(sc, req); } KASSERT(virtqueue_empty(vq), ("virtqueue not empty")); @@ -994,13 +1027,76 @@ vtblk_drain(struct vtblk_softc *sc) while ((req = vtblk_dequeue_ready(sc)) != NULL) { vtblk_bio_error(req->vbr_bp, ENXIO); - uma_zfree(vtblk_req_zone, req); + vtblk_enqueue_request(sc, req); } while (bioq_first(bioq) != NULL) { bp = bioq_takefirst(bioq); vtblk_bio_error(bp, ENXIO); } + + vtblk_free_requests(sc); +} + +static int +vtblk_alloc_requests(struct vtblk_softc *sc) +{ + struct vtblk_request *req; + int i, size; + + size = virtqueue_size(sc->vtblk_vq); + + /* + * Preallocate sufficient requests to keep the virtqueue full. Each + * request consumes VTBLK_MIN_SEGMENTS or more descriptors so reduce + * the number allocated when indirect descriptors are not available. + */ + if ((sc->vtblk_flags & VTBLK_FLAG_INDIRECT) == 0) + size /= VTBLK_MIN_SEGMENTS; + + for (i = 0; i < size; i++) { + req = uma_zalloc(vtblk_req_zone, M_NOWAIT); + if (req == NULL) + return (ENOMEM); + + sc->vtblk_request_count++; + vtblk_enqueue_request(sc, req); + } + + return (0); +} + +static void +vtblk_free_requests(struct vtblk_softc *sc) +{ + struct vtblk_request *req; + + while ((req = vtblk_dequeue_request(sc)) != NULL) { + sc->vtblk_request_count--; + uma_zfree(vtblk_req_zone, req); + } + + KASSERT(sc->vtblk_request_count == 0, ("leaked requests")); +} + +static struct vtblk_request * +vtblk_dequeue_request(struct vtblk_softc *sc) +{ + struct vtblk_request *req; + + req = TAILQ_FIRST(&sc->vtblk_req_free); + if (req != NULL) + TAILQ_REMOVE(&sc->vtblk_req_free, req, vbr_link); + + return (req); +} + +static void +vtblk_enqueue_request(struct vtblk_softc *sc, struct vtblk_request *req) +{ + + bzero(req, sizeof(struct vtblk_request)); + TAILQ_INSERT_HEAD(&sc->vtblk_req_free, req, vbr_link); } static struct vtblk_request * Modified: projects/virtio/sys/dev/virtio/network/if_vtnet.c ============================================================================== --- projects/virtio/sys/dev/virtio/network/if_vtnet.c Fri Oct 7 04:32:39 2011 (r226086) +++ projects/virtio/sys/dev/virtio/network/if_vtnet.c Fri Oct 7 05:08:08 2011 (r226087) @@ -624,8 +624,8 @@ vtnet_negotiate_features(struct vtnet_so * available. */ - if (virtio_with_feature(dev, VIRTIO_F_RING_INDIRECT_DESC)) - sc->vtnet_flags |= VTNET_FLAG_LRO_NOMGR; + if (virtio_with_feature(dev, VIRTIO_RING_F_INDIRECT_DESC)) + sc->vtnet_flags |= VTNET_FLAG_LRO_NOMRG; else { sc->vtnet_features = virtio_negotiate_features(dev, features & ~VTNET_LRO_FEATURES); @@ -655,7 +655,7 @@ vtnet_alloc_virtqueues(struct vtnet_soft * always physically contiguous. */ if ((sc->vtnet_flags & VTNET_FLAG_MRG_RXBUFS) == 0) { - rxsegs = sc->vtnet_flags & VTNET_FLAG_LRO_NOMGR ? + rxsegs = sc->vtnet_flags & VTNET_FLAG_LRO_NOMRG ? VTNET_MAX_RX_SEGS : VTNET_MIN_RX_SEGS; } else rxsegs = 0; @@ -1096,8 +1096,8 @@ vtnet_alloc_rxbuf(struct vtnet_softc *sc m_tail = m_head; if (nbufs > 1) { - KASSERT(sc->vtnet_flags & VTNET_FLAG_LRO_NOMGR, - ("chained Rx mbuf requested without LRO_NOMGR")); + KASSERT(sc->vtnet_flags & VTNET_FLAG_LRO_NOMRG, + ("chained Rx mbuf requested without LRO_NOMRG")); for (i = 0; i < nbufs - 1; i++) { m = m_getjcl(M_DONTWAIT, MT_DATA, 0, clsize); @@ -1130,18 +1130,19 @@ vtnet_replace_rxbuf(struct vtnet_softc * int len, clsize, nreplace, error; m = m0; + m_prev = NULL; len = len0; - m_tail = m_prev = NULL; + m_tail = NULL; clsize = sc->vtnet_rx_mbuf_size; nreplace = 0; if (m->m_next != NULL) - KASSERT(sc->vtnet_flags & VTNET_FLAG_LRO_NOMGR, - ("chained Rx mbuf without LRO_NOMGR")); + KASSERT(sc->vtnet_flags & VTNET_FLAG_LRO_NOMRG, + ("chained Rx mbuf without LRO_NOMRG")); /* - * Since LRO_NOMGR mbuf chains are so large, we want to avoid + * Since LRO_NOMRG mbuf chains are so large, we want to avoid * allocating an entire chain for each received frame. When * the received frame's length is less than that of the chain, * the unused mbufs are reassigned to the new chain. @@ -1268,7 +1269,7 @@ vtnet_enqueue_rxbuf(struct vtnet_softc * int offset, error; VTNET_LOCK_ASSERT(sc); - if ((sc->vtnet_flags & VTNET_FLAG_LRO_NOMGR) == 0) + if ((sc->vtnet_flags & VTNET_FLAG_LRO_NOMRG) == 0) KASSERT(m->m_next == NULL, ("chained Rx mbuf")); sglist_init(&sg, VTNET_MAX_RX_SEGS, segs); @@ -2295,9 +2296,7 @@ vtnet_exec_ctrl_cmd(struct vtnet_softc * * virtqueues. We do not support sharing both a Vq and config * changed notification on the same MSIX vector. */ - while ((c = virtqueue_dequeue(vq, NULL)) == NULL) - cpu_spinwait(); - + c = virtqueue_poll(vq, NULL); KASSERT(c == cookie, ("unexpected control command response")); } Modified: projects/virtio/sys/dev/virtio/network/if_vtnetvar.h ============================================================================== --- projects/virtio/sys/dev/virtio/network/if_vtnetvar.h Fri Oct 7 04:32:39 2011 (r226086) +++ projects/virtio/sys/dev/virtio/network/if_vtnetvar.h Fri Oct 7 05:08:08 2011 (r226087) @@ -63,7 +63,7 @@ struct vtnet_softc { #define VTNET_FLAG_VLAN_FILTER 0x0010 #define VTNET_FLAG_TSO_ECN 0x0020 #define VTNET_FLAG_MRG_RXBUFS 0x0040 -#define VTNET_FLAG_LRO_NOMGR 0x0080 +#define VTNET_FLAG_LRO_NOMRG 0x0080 struct virtqueue *vtnet_rx_vq; struct virtqueue *vtnet_tx_vq; @@ -184,7 +184,7 @@ CTASSERT(sizeof(struct vtnet_mac_filter) VIRTIO_NET_F_GUEST_TSO6 | \ VIRTIO_NET_F_GUEST_ECN | \ VIRTIO_NET_F_MRG_RXBUF | \ - VIRTIO_F_RING_INDIRECT_DESC) + VIRTIO_RING_F_INDIRECT_DESC) /* * The VIRTIO_NET_F_GUEST_TSO[46] features permit the host to send us @@ -218,7 +218,7 @@ CTASSERT(((VTNET_MAX_TX_SEGS - 1) * MCLB * hold both the vtnet_rx_header and the maximum receivable data. */ #define VTNET_NEEDED_RX_MBUFS(_sc) \ - ((_sc)->vtnet_flags & VTNET_FLAG_LRO_NOMGR) == 0 ? 1 : \ + ((_sc)->vtnet_flags & VTNET_FLAG_LRO_NOMRG) == 0 ? 1 : \ howmany(sizeof(struct vtnet_rx_header) + VTNET_MAX_RX_SIZE, \ (_sc)->vtnet_rx_mbuf_size) Modified: projects/virtio/sys/dev/virtio/pci/virtio_pci.c ============================================================================== --- projects/virtio/sys/dev/virtio/pci/virtio_pci.c Fri Oct 7 04:32:39 2011 (r226086) +++ projects/virtio/sys/dev/virtio/pci/virtio_pci.c Fri Oct 7 05:08:08 2011 (r226087) @@ -81,7 +81,7 @@ struct vtpci_softc { struct vtpci_virtqueue { struct virtqueue *vq; - /* Index into vtpci_intr_res[] below, Unused, then -1. */ + /* Index into vtpci_intr_res[] below. Unused, then -1. */ int ires_idx; } vtpci_vqx[VIRTIO_MAX_VIRTQUEUES]; @@ -651,6 +651,9 @@ vtpci_set_status(device_t dev, uint8_t s sc = device_get_softc(dev); + if (status != VIRTIO_CONFIG_STATUS_RESET) + status |= vtpci_get_status(dev); + vtpci_write_config_1(sc, VIRTIO_PCI_STATUS, status); } @@ -822,7 +825,7 @@ static int vtpci_alloc_msi(struct vtpci_softc *sc) { device_t dev; - int nmsi, cnt; + int nmsi, cnt; dev = sc->vtpci_dev; nmsi = pci_msi_count(dev); Modified: projects/virtio/sys/dev/virtio/virtio.c ============================================================================== --- projects/virtio/sys/dev/virtio/virtio.c Fri Oct 7 04:32:39 2011 (r226086) +++ projects/virtio/sys/dev/virtio/virtio.c Fri Oct 7 05:08:08 2011 (r226087) @@ -57,6 +57,7 @@ static struct virtio_ident { { VIRTIO_ID_CONSOLE, "Console" }, { VIRTIO_ID_ENTROPY, "Entropy" }, { VIRTIO_ID_BALLOON, "Balloon" }, + { VIRTIO_ID_IOMEMORY, "IOMemory" }, { VIRTIO_ID_9P, "9P Transport" }, { 0, NULL } @@ -65,7 +66,8 @@ static struct virtio_ident { /* Device independent features. */ static struct virtio_feature_desc virtio_common_feature_desc[] = { { VIRTIO_F_NOTIFY_ON_EMPTY, "NotifyOnEmpty" }, - { VIRTIO_F_RING_INDIRECT_DESC, "RingIndirect" }, + { VIRTIO_RING_F_INDIRECT_DESC, "RingIndirect" }, + { VIRTIO_RING_F_EVENT_IDX, "EventIdx" }, { VIRTIO_F_BAD_FEATURE, "BadFeature" }, { 0, NULL } Modified: projects/virtio/sys/dev/virtio/virtio.h ============================================================================== --- projects/virtio/sys/dev/virtio/virtio.h Fri Oct 7 04:32:39 2011 (r226086) +++ projects/virtio/sys/dev/virtio/virtio.h Fri Oct 7 05:08:08 2011 (r226087) @@ -18,6 +18,7 @@ struct vq_alloc_info; #define VIRTIO_ID_CONSOLE 0x03 #define VIRTIO_ID_ENTROPY 0x04 #define VIRTIO_ID_BALLOON 0x05 +#define VIRTIO_ID_IOMEMORY 0x06 #define VIRTIO_ID_9P 0x09 /* Status byte for guest to report progress. */ Modified: projects/virtio/sys/dev/virtio/virtqueue.c ============================================================================== --- projects/virtio/sys/dev/virtio/virtqueue.c Fri Oct 7 04:32:39 2011 (r226086) +++ projects/virtio/sys/dev/virtio/virtqueue.c Fri Oct 7 05:08:08 2011 (r226087) @@ -40,9 +40,9 @@ __FBSDID("$FreeBSD$"); #include #include -#include - +#include #include +#include #include #include #include @@ -135,7 +135,7 @@ virtqueue_filter_features(uint64_t featu uint64_t mask; mask = (1 << VIRTIO_TRANSPORT_F_START) - 1; - mask |= VIRTIO_F_RING_INDIRECT_DESC; + mask |= VIRTIO_RING_F_INDIRECT_DESC; return (features & mask); } @@ -221,7 +221,7 @@ virtqueue_init_indirect(struct virtqueue dev = vq->vq_dev; - if (VIRTIO_BUS_WITH_FEATURE(dev, VIRTIO_F_RING_INDIRECT_DESC) == 0) { + if (VIRTIO_BUS_WITH_FEATURE(dev, VIRTIO_RING_F_INDIRECT_DESC) == 0) { /* * Indirect descriptors requested by the driver but not * negotiated. Return zero to keep the initialization @@ -532,6 +532,17 @@ virtqueue_dequeue(struct virtqueue *vq, } void * +virtqueue_poll(struct virtqueue *vq, uint32_t *len) +{ + void *cookie; + + while ((cookie = virtqueue_dequeue(vq, len)) == NULL) + cpu_spinwait(); + + return (cookie); +} + +void * virtqueue_drain(struct virtqueue *vq, int *last) { void *cookie; @@ -599,7 +610,7 @@ vq_ring_update_avail(struct virtqueue *v * it usable to the host. The chain is made available now rather than * deferring to virtqueue_notify() in the hopes that if the host is * currently running on another CPU, we can keep it processing the new - * frames. + * descriptor. */ avail_idx = vq->vq_ring.avail->idx & (vq->vq_nentries - 1); vq->vq_ring.avail->ring[avail_idx] = desc_idx; Modified: projects/virtio/sys/dev/virtio/virtqueue.h ============================================================================== --- projects/virtio/sys/dev/virtio/virtqueue.h Fri Oct 7 04:32:39 2011 (r226086) +++ projects/virtio/sys/dev/virtio/virtqueue.h Fri Oct 7 05:08:08 2011 (r226087) @@ -35,7 +35,14 @@ struct virtqueue; struct sglist; /* Support for indirect buffer descriptors. */ -#define VIRTIO_F_RING_INDIRECT_DESC (1 << 28) +#define VIRTIO_RING_F_INDIRECT_DESC (1 << 28) + +/* The guest publishes the used index for which it expects an interrupt + * at the end of the avail ring. Host should ignore the avail->flags field. + * The host publishes the avail index for which it expects a kick + * at the end of the used ring. Guest should ignore the used->flags field. + */ +#define VIRTIO_RING_F_EVENT_IDX (1 << 29) /* Device callback for a virtqueue interrupt. */ typedef int virtqueue_intr_t(void *); @@ -86,5 +93,6 @@ void virtqueue_dump(struct virtqueue *v int virtqueue_enqueue(struct virtqueue *vq, void *cookie, struct sglist *sg, int readable, int writable); void *virtqueue_dequeue(struct virtqueue *vq, uint32_t *len); +void *virtqueue_poll(struct virtqueue *vq, uint32_t *len); #endif /* _VIRTIO_VIRTQUEUE_H */ From owner-svn-src-projects@FreeBSD.ORG Fri Oct 7 05:45:39 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3BD17106564A; Fri, 7 Oct 2011 05:45:39 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 221BB8FC0C; Fri, 7 Oct 2011 05:45:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p975jdlp095175; Fri, 7 Oct 2011 05:45:39 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p975jcwq095171; Fri, 7 Oct 2011 05:45:38 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110070545.p975jcwq095171@svn.freebsd.org> From: Lawrence Stewart Date: Fri, 7 Oct 2011 05:45:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226088 - projects/diffused_head/sys/netinet X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 05:45:39 -0000 Author: lstewart Date: Fri Oct 7 05:45:38 2011 New Revision: 226088 URL: http://svn.freebsd.org/changeset/base/226088 Log: Add the necessary infrastructure for the DIFFUSE control raw socket, which will be used to communicate between userspace and the forthcoming DIFFUSE kernel module. Sponsored by: FreeBSD Foundation Reviewed by: bz Modified: projects/diffused_head/sys/netinet/in.h projects/diffused_head/sys/netinet/ip_var.h projects/diffused_head/sys/netinet/raw_ip.c Modified: projects/diffused_head/sys/netinet/in.h ============================================================================== --- projects/diffused_head/sys/netinet/in.h Fri Oct 7 05:08:08 2011 (r226087) +++ projects/diffused_head/sys/netinet/in.h Fri Oct 7 05:45:38 2011 (r226088) @@ -436,6 +436,7 @@ __END_DECLS #define IP_FW_TABLE_GETSIZE 43 /* get table size */ #define IP_FW_TABLE_LIST 44 /* list table contents */ +#define IP_DIFFUSE 47 /* ipfw DIFFUSE options */ #define IP_FW3 48 /* generic ipfw v.3 sockopts */ #define IP_DUMMYNET3 49 /* generic dummynet v.3 sockopts */ Modified: projects/diffused_head/sys/netinet/ip_var.h ============================================================================== --- projects/diffused_head/sys/netinet/ip_var.h Fri Oct 7 05:08:08 2011 (r226087) +++ projects/diffused_head/sys/netinet/ip_var.h Fri Oct 7 05:45:38 2011 (r226088) @@ -305,6 +305,9 @@ extern int (*ng_ipfw_input_p)(struct mbu extern int (*ip_dn_ctl_ptr)(struct sockopt *); extern int (*ip_dn_io_ptr)(struct mbuf **, int, struct ip_fw_args *); +/* DIFFUSE. */ +extern int (*diffuse_ctl_ptr)(struct sockopt *); + VNET_DECLARE(int, ip_do_randomid); #define V_ip_do_randomid VNET(ip_do_randomid) #define ip_newid() ((V_ip_do_randomid != 0) ? ip_randomid() : \ Modified: projects/diffused_head/sys/netinet/raw_ip.c ============================================================================== --- projects/diffused_head/sys/netinet/raw_ip.c Fri Oct 7 05:08:08 2011 (r226087) +++ projects/diffused_head/sys/netinet/raw_ip.c Fri Oct 7 05:45:38 2011 (r226088) @@ -99,6 +99,7 @@ int (*ip_dn_io_ptr)(struct mbuf **, int, void (*ip_divert_ptr)(struct mbuf *, int); int (*ng_ipfw_input_p)(struct mbuf **, int, struct ip_fw_args *, int); +int (*diffuse_ctl_ptr)(struct sockopt *); /* Hook for telling pf that the destination address changed */ void (*m_addr_chg_pf_p)(struct mbuf *m); @@ -583,6 +584,13 @@ rip_ctloutput(struct socket *so, struct error = ENOPROTOOPT; break ; + case IP_DIFFUSE: /* IPFW DIFFUSE functions. */ + if (diffuse_ctl_ptr != NULL) + error = diffuse_ctl_ptr(sopt); + else + error = ENOPROTOOPT; + break; + case MRT_INIT: case MRT_DONE: case MRT_ADD_VIF: @@ -648,6 +656,13 @@ rip_ctloutput(struct socket *so, struct error = ENOPROTOOPT ; break ; + case IP_DIFFUSE: /* IPFW DIFFUSE functions. */ + if (diffuse_ctl_ptr != NULL) + error = diffuse_ctl_ptr(sopt); + else + error = ENOPROTOOPT; + break; + case IP_RSVP_ON: error = priv_check(curthread, PRIV_NETINET_MROUTE); if (error != 0) From owner-svn-src-projects@FreeBSD.ORG Fri Oct 7 08:55:37 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 51408106566C; Fri, 7 Oct 2011 08:55:37 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 409998FC0A; Fri, 7 Oct 2011 08:55:37 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p978tbM7001441; Fri, 7 Oct 2011 08:55:37 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p978tbcS001439; Fri, 7 Oct 2011 08:55:37 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201110070855.p978tbcS001439@svn.freebsd.org> From: Peter Holm Date: Fri, 7 Oct 2011 08:55:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226093 - projects/stress2/misc X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 08:55:37 -0000 Author: pho Date: Fri Oct 7 08:55:36 2011 New Revision: 226093 URL: http://svn.freebsd.org/changeset/base/226093 Log: Added two scenarios for SU problem with flush of inodes. Added: projects/stress2/misc/linger3.sh (contents, props changed) projects/stress2/misc/linger4.sh (contents, props changed) Added: projects/stress2/misc/linger3.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/stress2/misc/linger3.sh Fri Oct 7 08:55:36 2011 (r226093) @@ -0,0 +1,136 @@ +#!/bin/sh + +# +# Copyright (c) 2011 Peter Holm +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# Test for SU problem with false EMLINK + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > linger3.c +cc -o linger3 -Wall -Wextra -O2 linger3.c +rm -f linger3.c + +mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +[ $# -eq 1 ] && opt="$1" +[ $# -eq 0 ] && opt=-U # The default is "-U" +echo "newfs $opt md${mdstart}$part" +newfs $opt md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +cd $mntpoint +chmod 777 $mntpoint + +su $testuser -c "/tmp/linger3" + +cd $here + +while mount | grep -q $mntpoint; do + umount ${mntpoint} 2> /dev/null || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/linger3 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 +#define ND ((32767 / PARALLEL) - 2) + +static pid_t p; + +void +setup(int loop) +{ + int d; + char name[128]; + + for (d = 0; d < ND; d++) { + snprintf(name, sizeof(name), "d%06d.%03d", p, d); + if (mkdir(name, 00700) == -1) + err(1, "mkdir(%s) @ loop #%d", name, loop); + } +} + +void +prune(int loop) +{ + int d; + char name[128]; + + for (d = 0; d < ND; d++) { + snprintf(name, sizeof(name), "d%06d.%03d", p, d); + if (rmdir(name) == -1) + err(1, "rmdir(%s) @ loop #%d", name, loop); + } +} + +int +main() +{ + int i, j; + int linger = 0; + + if (getenv("LINGER")) + linger = atoi(getenv("LINGER")); + + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) { + p = getpid(); + for (j = 0; j < 10; j++) { + setup(j); + prune(j); + if (linger != 0) + sleep(linger); + } + _exit(0); + } + } + + for (i = 0; i < PARALLEL; i++) + wait(NULL); + + return (0); +} Added: projects/stress2/misc/linger4.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/stress2/misc/linger4.sh Fri Oct 7 08:55:36 2011 (r226093) @@ -0,0 +1,149 @@ +#!/bin/sh + +# +# Copyright (c) 2011 Peter Holm +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# Test for SU problem with "out of inodes" for CREAT + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > linger3.c +cc -o linger4 -Wall -Wextra -O2 linger3.c +rm -f linger4.c + +mount | grep "$mntpoint" | grep -q md$mdstart && umount $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 2g -u $mdstart +bsdlabel -w md$mdstart auto +[ $# -eq 1 ] && opt="$1" +[ $# -eq 0 ] && opt=-U # The default is "-U" +echo "newfs $opt md${mdstart}$part" +newfs $opt md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +cd $mntpoint +chmod 777 $mntpoint + +su $testuser -c "/tmp/linger4" + +cd $here + +while mount | grep -q $mntpoint; do + umount ${mntpoint} 2> /dev/null || sleep 1 +done +mdconfig -d -u $mdstart +rm -f /tmp/linger4 +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PARALLEL 4 + +#define NUMBER 80000 / PARALLEL /* Number of files to use. Max is 131068 */ + +void +Creat(int loopno) +{ + int e, fd, i, j; + char file[128]; + char path[128]; + pid_t pid; + + e = 0; + pid = getpid(); + sprintf(path, "f%06d", pid); + if (mkdir(path, 0770) == -1) + warn("mkdir(%s), %s:%d, loop #%d", path, __FILE__, __LINE__, loopno); + chdir(path); + + for (j = 0; j < NUMBER; j++) { + sprintf(file,"p%05d.%05d", pid, j); + if ((fd = creat(file, 0660)) == -1) { + if (errno != EINTR) { + warn("creat(%s). %s:%d, loop #%d", file, __FILE__, __LINE__, loopno); + e = 1; + break; + } + } + if (fd != -1 && close(fd) == -1) + err(2, "close(%d)", j); + + } + + for (i = --j; i >= 0; i--) { + sprintf(file,"p%05d.%05d", pid, i); + if (unlink(file) == -1) + err(3, "unlink(%s)", file); + + } + chdir (".."); + if (rmdir(path) == -1) + err(1, "rmdir(%s), %s:%d, loop #%d", path, __FILE__, __LINE__, loopno); + + _exit(e); +} + + +int +main() +{ + int e, i, j, status; + + for (j = 0; j < 300; j++) { + for (i = 0; i < PARALLEL; i++) { + if (fork() == 0) + Creat(j); + } + + for (i = 0; i < PARALLEL; i++) { + wait(&status); + e += status; + } + if (e != 0) + break; +// sleep(60); /* No problems if this is included */ + } + system("ls -la /mnt; df -i /mnt"); + + return (0); +} From owner-svn-src-projects@FreeBSD.ORG Fri Oct 7 08:56:52 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 14ABA106564A; Fri, 7 Oct 2011 08:56:52 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DFBD38FC17; Fri, 7 Oct 2011 08:56:51 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p978upLt001512; Fri, 7 Oct 2011 08:56:51 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p978upLW001511; Fri, 7 Oct 2011 08:56:51 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201110070856.p978upLW001511@svn.freebsd.org> From: Peter Holm Date: Fri, 7 Oct 2011 08:56:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226094 - projects/stress2/misc X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 08:56:52 -0000 Author: pho Date: Fri Oct 7 08:56:51 2011 New Revision: 226094 URL: http://svn.freebsd.org/changeset/base/226094 Log: Added MEMGUARD scenario for SU problem. Added: projects/stress2/misc/memguard.sh (contents, props changed) Added: projects/stress2/misc/memguard.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/stress2/misc/memguard.sh Fri Oct 7 08:56:51 2011 (r226094) @@ -0,0 +1,68 @@ +#!/bin/sh + +# +# Copyright (c) 2011 Peter Holm +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + + +# MEMGUARD(9) test scenario: Page fault seen in softdep_setup_inomapdep(). + +. ../default.cfg + +sysctl vm | grep -q memguard || { echo "MEMGUARD(9) not enabled"; exit 1; } + +mount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint +mdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 20m -u $mdstart || exit 1 +bsdlabel -w md$mdstart auto + +newfs -U md${mdstart}$part > /dev/null + +mount /dev/md${mdstart}$part $mntpoint +chmod 777 $mntpoint + +export runRUNTIME=5m +export RUNDIR=$mntpoint/stressX +set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` +export KBLOCKS=$(($1 * 2)) +export INODES=$(($2 * 2)) + +sysctl vm.memguard.options=3 > /dev/null +sysctl vm.memguard.desc=inodedep + +su $testuser -c 'cd ..; ./run.sh disk.cfg' > /dev/null + +sysctl vm.memguard.desc="" > /dev/null +sysctl vm.memguard.options=1 > /dev/null + +while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 +done +mdconfig -d -u $mdstart From owner-svn-src-projects@FreeBSD.ORG Fri Oct 7 09:30:20 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EAA82106566C; Fri, 7 Oct 2011 09:30:20 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id C15488FC12; Fri, 7 Oct 2011 09:30:20 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p979UKIW002627; Fri, 7 Oct 2011 09:30:20 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p979UKxi002626; Fri, 7 Oct 2011 09:30:20 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201110070930.p979UKxi002626@svn.freebsd.org> From: Peter Holm Date: Fri, 7 Oct 2011 09:30:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226096 - projects/stress2/misc X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 09:30:21 -0000 Author: pho Date: Fri Oct 7 09:30:20 2011 New Revision: 226096 URL: http://svn.freebsd.org/changeset/base/226096 Log: Missing SUJ and quota test scenario added. Added: projects/stress2/misc/suj18.sh (contents, props changed) Added: projects/stress2/misc/suj18.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/stress2/misc/suj18.sh Fri Oct 7 09:30:20 2011 (r226096) @@ -0,0 +1,60 @@ +#!/bin/sh + +# +# Copyright (c) 2011 Peter Holm +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# SUJ and quota test scenario. +# "panic: check_inode_unwritten: busy inode" seen. + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep "${mntpoint}" | grep -q md${mdstart} && umount ${mntpoint} +mdconfig -l | grep -q md${mdstart} && mdconfig -d -u ${mdstart} + +mdconfig -a -t swap -s 1g -u ${mdstart} +bsdlabel -w md${mdstart} auto +newfs -j md${mdstart}${part} > /dev/null +export PATH_FSTAB=/tmp/fstab +echo "/dev/md${mdstart}${part} ${mntpoint} ufs rw,userquota 2 2" > $PATH_FSTAB +mount ${mntpoint} +set `df -ik ${mntpoint} | tail -1 | awk '{print $4,$7}'` +export QK=$(($1 / 10 * 8)) +export QI=$(($2 / 10 * 8)) +edquota -u -f ${mntpoint} -e ${mntpoint}:$((QK - 50)):$QK:$((QI - 50 )):$QI ${testuser} +quotaon ${mntpoint} +export RUNDIR=${mntpoint}/stressX +chmod 777 ${mntpoint} +su ${testuser} -c 'sh -c "(cd ..;runRUNTIME=20m ./run.sh disk.cfg > /dev/null 2>&1)"' + +while mount | grep -q ${mntpoint}; do + umount ${mntpoint} || sleep 1 +done +mdconfig -d -u ${mdstart} +rm -f $PATH_FSTAB From owner-svn-src-projects@FreeBSD.ORG Fri Oct 7 09:35:17 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 83C2E106564A; Fri, 7 Oct 2011 09:35:17 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5A84C8FC12; Fri, 7 Oct 2011 09:35:17 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p979ZHa3002829; Fri, 7 Oct 2011 09:35:17 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p979ZHKN002827; Fri, 7 Oct 2011 09:35:17 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201110070935.p979ZHKN002827@svn.freebsd.org> From: Peter Holm Date: Fri, 7 Oct 2011 09:35:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226097 - projects/stress2/misc X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Oct 2011 09:35:17 -0000 Author: pho Date: Fri Oct 7 09:35:17 2011 New Revision: 226097 URL: http://svn.freebsd.org/changeset/base/226097 Log: Added SU+J scenario plus some cleanup of the scenarios. Modified: projects/stress2/misc/fs.sh Modified: projects/stress2/misc/fs.sh ============================================================================== --- projects/stress2/misc/fs.sh Fri Oct 7 09:30:20 2011 (r226096) +++ projects/stress2/misc/fs.sh Fri Oct 7 09:35:17 2011 (r226097) @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright (c) 2008 Peter Holm +# Copyright (c) 2008, 2011 Peter Holm # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -28,30 +28,34 @@ # $FreeBSD$ # -# Caused panic: ffs_truncate3 +# Run a simple test on different FS variations, with and without disk full. [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 . ../default.cfg -ftest () { # fstype, soft update, disk full - echo "newfs -O $1 `[ $2 -eq 1 ] && echo \"-U\"` md${mdstart}${part}" - newfs -O $1 `[ $2 -eq 1 ] && echo "-U"` md${mdstart}${part} > /dev/null - mount /dev/md${mdstart}${part} ${mntpoint} - - export RUNDIR=${mntpoint}/stressX - disk=$(($3 + 1)) # 1 or 2 - set `df -ik ${mntpoint} | tail -1 | awk '{print $4,$7}'` - export KBLOCKS=$(($1 * disk)) - export INODES=$(($2 * disk)) - - for i in `jot 10`; do - (cd ../testcases/rw;./rw -t 2m -i 20) - done - - while mount | grep -q ${mntpoint}; do - umount $([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f") ${mntpoint} > /dev/null 2>&1 - done +ftest () { # option, disk full + [ $2 -eq 1 ] && df=", disk full" || df="" + echo "`date '+%T'` newfs $1 md${mdstart}${part}$df" + newfs $1 md${mdstart}$part > /dev/null + mount /dev/md${mdstart}$part $mntpoint + chmod 777 $mntpoint + + export RUNDIR=${mntpoint}/stressX + export runRUNTIME=2m + disk=$(($2 + 1)) # 1 or 2 + set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` + export KBLOCKS=$(($1 * disk)) + export INODES=$(($2 * disk)) + + for i in `jot 2`; do + rm -rf /tmp/stressX.control $RUNDIR + su $testuser -c "(cd ..; ./run.sh disk.cfg)" > /dev/null 2>&1 + done + + while mount | grep $mntpoint | grep -q /dev/md; do + umount $mntpoint || sleep 1 + done } @@ -61,11 +65,13 @@ mdconfig -l | grep md${mdstart} > /dev/n mdconfig -a -t swap -s 20m -u ${mdstart} bsdlabel -w md${mdstart} auto -ftest 1 0 0 # ufs1 -ftest 1 0 1 # ufs1, disk full -ftest 2 0 0 # ufs2 -ftest 2 0 1 # ufs2, disk full -ftest 2 1 0 # ufs2 + soft update -ftest 2 1 1 # ufs2 + soft update, disk full +ftest "-O 1" 0 # ufs1 +ftest "-O 1" 1 # ufs1, disk full +ftest "-O 2" 0 # ufs2 +ftest "-O 2" 1 # ufs2, disk full +ftest "-U" 0 # ufs2 + soft update +ftest "-U" 1 # ufs2 + soft update, disk full +ftest "-j" 0 # ufs2 + SU+J +ftest "-j" 1 # ufs2 + SU+J, disk full mdconfig -d -u ${mdstart} From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 02:58:24 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0B147106564A; Sat, 8 Oct 2011 02:58:24 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id ED56A8FC0C; Sat, 8 Oct 2011 02:58:23 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p982wNFx039046; Sat, 8 Oct 2011 02:58:23 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p982wNHN039039; Sat, 8 Oct 2011 02:58:23 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080258.p982wNHN039039@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 02:58:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226125 - in projects/diffused_head/sys/netinet: . ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 02:58:24 -0000 Author: lstewart Date: Sat Oct 8 02:58:23 2011 New Revision: 226125 URL: http://svn.freebsd.org/changeset/base/226125 Log: Integrate DIFFUSE related hooks and supporting infrastructure into the IPFW kernel code. DIFFUSE is called both as part of packet processing (for per-flow management, feature calculation and classification) and IPFW related configuration (for handling DIFFUSE related rule configuration). The interface between IPFW and DIFFUSE was intentionally kept hook based to ensure minimal coupling between them. It should therefore be quite simple to integrate DIFFUSE with other firewalls in future if desired. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/netinet/ip_diffuse.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_common.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_private.h (contents, props changed) Modified: projects/diffused_head/sys/netinet/ip_fw.h projects/diffused_head/sys/netinet/ipfw/ip_fw2.c projects/diffused_head/sys/netinet/ipfw/ip_fw_private.h projects/diffused_head/sys/netinet/ipfw/ip_fw_sockopt.c Added: projects/diffused_head/sys/netinet/ip_diffuse.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ip_diffuse.h Sat Oct 8 02:58:23 2011 (r226125) @@ -0,0 +1,333 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _NETINET_IP_DIFFUSE_H_ +#define _NETINET_IP_DIFFUSE_H_ + +/* + * Definition of the kernel-userland API for DIFFUSE. + * Use the same type of interface as dummynet. + * + * Setsockopt() and getsockopt() pass a batch of objects, each of them starting + * with a "struct di_oid" which should fully identify the object and its + * relation with others in the sequence. + * The first object in each request should have: + * type = DI_CMD_*, id = DI_API_VERSION. + * For other objects, type and subtype specify the object, len indicates the + * total length including the header, and 'id' identifies the specific object. + */ + +/* Max feature/classifier name string length (including terminator). */ +#define DI_MAX_NAME_STR_LEN 8 + +#define DI_MAX_MODEL_STR_LEN 256 + +/* Max action parameter string length (including terminator). */ +#define DI_MAX_PARAM_STR_LEN 16 + +/* Max number of features in list. */ +#define DI_MAX_FEATURES 12 + +/* Max number of statistics/features used by classifier. */ +#define DI_MAX_FEATURE_STATS 64 + +/* Max number of classes/tags used by classifier. */ +#define DI_MAX_CLASSES 25 + +/* Char to indicate class numbers. */ +#define DI_CLASS_NO_CHAR '#' + +#define DI_API_VERSION 1 +#define DI_MAX_ID 0x10000 + +#define DI_UNIDIRECTIONAL 0x00 +#define DI_BIDIRECTIONAL 0x01 + +#define DI_ACTION_TYPE_UNIDIRECTIONAL DI_UNIDIRECTIONAL +#define DI_ACTION_TYPE_BIDIRECTIONAL DI_BIDIRECTIONAL +#define DI_FEATURE_ALG_UNIDIRECTIONAL DI_UNIDIRECTIONAL +#define DI_FEATURE_ALG_BIDIRECTIONAL DI_BIDIRECTIONAL +#define DI_FLOW_TYPE_UNIDIRECTIONAL DI_UNIDIRECTIONAL +#define DI_FLOW_TYPE_BIDIRECTIONAL DI_BIDIRECTIONAL + +/* Enable debugging output. */ +/* #define DIFFUSE_DEBUG 1 */ + +/* Enable more debugging output. */ +/* #define DIFFUSE_DEBUG2 1 */ + +/* Debugging support. */ +#ifdef DIFFUSE_DEBUG +#define DID(fmt, ...) printf("diffuse: %-10s: " fmt "\n", __func__, \ + ## __VA_ARGS__) +#else +#define DID(fmt, ...) do {} while (0) +#endif + +#ifdef DIFFUSE_DEBUG2 +#define DID2(fmt, ...) printf("diffuse: %-10s: " fmt "\n", __func__, \ + ## __VA_ARGS__) +#else +#define DID2(fmt, ...) do {} while (0) +#endif + +struct di_oid { + uint32_t len; /* Total obj len including this header + * (16 bit too small for flowtable show). */ + uint32_t id; /* Generic id. */ + uint16_t flags; /* Data we can pass in the oid. */ + uint8_t type; /* Type, e.g. delete or show. */ + uint8_t subtype; /* Object, e.g. feature, classifier. */ +}; + +/* + * These values are in the type field of struct di_oid. To preserve the ABI, + * never rearrange the list or delete entries with the exception of DI_LAST. + */ +enum { + DI_NONE = 0, + + DI_CMD_CONFIG, /* Objects follow. */ + DI_CMD_DELETE, /* Subtype + list of entries. */ + DI_CMD_GET, /* Subtype + list of entries. */ + DI_CMD_FLUSH, + DI_CMD_ZERO, + + DI_FEATURE, + DI_FEATURE_CONFIG, + DI_CLASSIFIER, + DI_CLASSIFIER_CONFIG, + DI_EXPORT, + DI_FLOW_TABLE, + + DI_LAST +}; + +/* Flow table export. */ +#define DI_FT_GET_NONE 0x00 +#define DI_FT_GET_EXPIRED 0x01 + +struct di_ft_flow_class { + char cname[DI_MAX_NAME_STR_LEN]; + uint16_t class; +}; + +/* This is the data sent to userspace for a show command. */ +struct di_ft_export_entry { + uint16_t ruleno; + uint16_t setno; + + struct ipfw_flow_id id; /* (masked) flow id */ + uint64_t pcnt; /* Packet match counter. */ + uint64_t bcnt; /* Byte match counter. */ + uint32_t expire; /* Expire time. */ + uint32_t bucket; /* Which bucket in hash table. */ + uint32_t state; /* State of this rule (typically a + * combination of TCP flags). */ + uint8_t fcnt; /* Number of features. */ + uint8_t tcnt; /* Number of class tags. */ + uint8_t final; /* Equals 1 if final entry. */ + uint8_t ftype; /* Bidirectional vs unidirectional. */ +#if 0 + /* + * The variable length data component which will appear after the above + * fixed size header is structured as follows: + */ + uint8_t fidx[fcnt]; /* Index for each feature in feature + * list. */ + uint8_t scnt[fcnt]; /* Number of stats per feature. */ + uint32_t fwd_svals[fcnt][scnt]; /* Forward statistics. */ + uint32_t bck_svals[fcnt][scnt]; /* Backward statistics. */ + di_ft_flow_class_t class_tags[tcnt]; /* Class tags. */ +#endif +}; + +/* Feature related types. */ +struct di_ctl_feature +{ + struct di_oid oid; + char name[DI_MAX_NAME_STR_LEN]; /* Feature name. */ + char mod_name[DI_MAX_NAME_STR_LEN]; /* Algorithm name. */ +}; + +struct di_feature_stat { + uint8_t fdir; /* Flow direction. */ + char sname[DI_MAX_NAME_STR_LEN]; /* Stat name. */ + char fname[DI_MAX_NAME_STR_LEN]; /* Feature name. */ +}; + +/* Classifier related types. */ +struct di_ctl_classifier +{ + struct di_oid oid; + char name[DI_MAX_NAME_STR_LEN]; /* Classifier name. */ + char mod_name[DI_MAX_NAME_STR_LEN]; /* Algorithm name. */ + uint16_t confirm; /* Confirm threshold for + * classification. */ + uint8_t ccnt; /* Number of class names. */ + uint8_t fscnt; /* Number of feature stats. */ + struct di_feature_stat fstats[]; /* Features. */ +}; + +/* Exporter related types. */ +struct di_export_config { + uint8_t proto; /* Fixed to UDP for now. */ + uint8_t addr_type; /* 4=ip4, 6=ip6 */ + uint16_t port; /* Port exporter is listening. */ + struct in_addr ip; /* IPv4 address of exporter. */ + struct in6_addr ip6; /* IPv6 address of exporter. */ + + uint16_t confirm; /* Need N consistent consecutive + * classifications. */ + uint16_t min_batch; + uint16_t max_batch; + uint32_t max_delay; /* Max ms delay for exporting. */ + uint32_t flags; /* e.g. retransmit. */ + uint8_t atype; /* Uni vs bidirectional action. */ + char action[DI_MAX_NAME_STR_LEN]; /* Opaque action for action node. */ + char action_param[DI_MAX_PARAM_STR_LEN]; /* Opaque action params. */ +}; + +struct di_ctl_export +{ + struct di_oid oid; + char name[DI_MAX_NAME_STR_LEN]; + struct di_export_config conf; +}; + +/* Classification policy defines. */ +#define DI_MATCH_ONCE 1 +#define DI_MATCH_SAMPLE_REG 2 +#define DI_MATCH_SAMPLE_RAND 3 +#define DI_MATCH_ONCE_CLASS 4 +#define DI_MATCH_ONCE_EXP 5 + +/* + * Instruction definitions. + */ + +typedef struct _ipfw_insn_features { + ipfw_insn o; + uint8_t ftype; /* Bidirectional, unidirectional, ... */ + uint8_t fcnt; /* Number of features. */ + uint16_t sample_int; /* Regular sampling interval. */ + uint32_t sample_prob; /* Random sampling. */ + char fnames[DI_MAX_FEATURES][DI_MAX_NAME_STR_LEN]; + struct di_feature *fptrs[DI_MAX_FEATURES]; /* Feature ptrs. */ +} ipfw_insn_features; + +/* Feature match instruction. */ +#define DI_MATCH_DIR_NONE 0x00 +#define DI_MATCH_DIR_FWD 0x01 +#define DI_MATCH_DIR_BCK 0x02 + +enum di_comp_types { + DI_COMP_LT = 0, + DI_COMP_LE, + DI_COMP_EQ, + DI_COMP_GE, + DI_COMP_GT +}; + +typedef struct _ipfw_insn_feature_match { + ipfw_insn o; + struct di_feature *fptr; /* Feature ptr. */ + int32_t thresh; /* Value we compare against. */ + uint8_t sidx; /* Stat index. */ + uint8_t fdir; /* Feature direction. */ + uint8_t comp; /* Comparison type. */ + char sname[DI_MAX_NAME_STR_LEN]; /* Feature statistic. */ + char fname[DI_MAX_NAME_STR_LEN]; /* Feature name. */ +} ipfw_insn_feature_match; + +/* Match if class instruction. */ + +/* Max number of classes in match-if. */ +#define DI_MAX_MATCH_CLASSES 1 + +typedef struct _ipfw_insn_match_if_class { + ipfw_insn o; + uint8_t mcnt; /* Number of classes that match. */ + uint8_t match_classes[DI_MAX_MATCH_CLASSES]; /* Class number of matching + * classes. */ + struct di_classifier *clptr; /* Classifier ptr. */ + char cname[DI_MAX_NAME_STR_LEN]; /* Classifier name. */ + char clnames[][DI_MAX_NAME_STR_LEN]; /* Class names. */ +} ipfw_insn_match_if_class; + +/* Tag using ipfw tags. */ +typedef struct _ipfw_insn_class_tags { + ipfw_insn o; + char cname[DI_MAX_NAME_STR_LEN]; /* Classifier + * name. */ + struct di_classifier *clptr; /* Classifier ptr. */ + uint8_t tcnt; /* Number of tags + * (<= number of classes). */ + uint16_t tags[]; /* One tag per class. */ +} ipfw_insn_class_tags; + +/* Classifier action instruction. */ +typedef struct _ipfw_insn_ml_classify { + ipfw_insn o; + char cname[DI_MAX_NAME_STR_LEN]; /* Classifier + * name. */ + struct di_classifier *clptr; /* Classifier ptr. */ + struct _ipfw_insn_class_tags *tcmd; /* Link to optional tag command. */ +} ipfw_insn_ml_classify; + +/* Export action instruction. */ +typedef struct _ipfw_insn_export { + ipfw_insn o; + char ename[DI_MAX_NAME_STR_LEN]; /* Export name. */ + struct di_export *eptr; /* Export instance ptr. */ +} ipfw_insn_export; + +/* + * Stores all the persistent data required across multiple calls to + * diffuse_chk_pkt(). + */ +struct di_chk_pkt_args { + struct di_ft_entry *q; + ipfw_insn_class_tags *tcmd; + int no_class; +}; + +/* + * Stores all the persistent data required (currently none) across multiple + * calls to diffuse_chk_rule_cmd(). + */ +struct di_chk_rule_cmd_args { +}; + +#endif /* _NETINET_IP_DIFFUSE_H_ */ Modified: projects/diffused_head/sys/netinet/ip_fw.h ============================================================================== --- projects/diffused_head/sys/netinet/ip_fw.h Sat Oct 8 00:01:17 2011 (r226124) +++ projects/diffused_head/sys/netinet/ip_fw.h Sat Oct 8 02:58:23 2011 (r226125) @@ -205,6 +205,28 @@ enum ipfw_opcodes { /* arguments (4 byt O_FORWARD_IP6, /* fwd sockaddr_in6 */ + /* + * Actions for DIFFUSE. + */ + O_DI_FEATURES, /* feature list */ + O_DI_FEATURES_IMPLICIT, /* feature list (implicitely configured) */ + O_DI_FLOW_TABLE, /* check flow table and update features */ + O_DI_FEATURE_MATCH, /* feature match */ + O_DI_AFTER_EACH_RULE, /* pseudo opcode, used after match for rule was + decided */ + O_DI_CLASS_TAGS, /* tags used for classified packets */ + O_DI_ML_CLASSIFY, /* classify sub flow (action) */ + O_DI_ML_CLASSIFY_IMPLICIT, /* classify sub flow + (implicit -> non-action) */ + O_DI_MATCH_IF_CLASS, /* match if classified as class x */ + O_DI_EXPORT, /* export rules */ + O_DI_BEFORE_ALL_RULES, /* pseudo opcode, before matching rules, + _inside_ lock */ + O_DI_AFTER_ALL_RULES, /* pseudo opcode, after all rules, _outside_ + lock */ + O_DI_BEFORE_RULE_CHK, /* pseudo opcode, called before rule checks */ + O_DI_AFTER_RULE_CHK, /* pseudo opcode, called after rule checks */ + O_LAST_OPCODE /* not an opcode! */ }; Added: projects/diffused_head/sys/netinet/ipfw/diffuse_common.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_common.h Sat Oct 8 02:58:23 2011 (r226125) @@ -0,0 +1,123 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _NETINET_IPFW_DIFFUSE_COMMON_H_ +#define _NETINET_IPFW_DIFFUSE_COMMON_H_ + +/* MSVC does not support designated initializers so we need this ugly macro. */ +#ifdef _WIN32 +#define _FI(fld) +#else +#define _FI(fld) fld +#endif + +/* Feature or classifier instance data. */ +struct di_cdata { + void *conf; /* Instance configuration ptr. */ +}; + +/* Flow data. */ +struct di_fdata { + void *data; /* Work data ptr. */ + int32_t *stats; /* Stats ptr. */ +}; + +/* + * Fast fixed point division with rounding for dividing by a number of 2. + * a is the divident and b is the power of the divisor. + */ +static inline uint64_t +fixp_div(uint64_t a, int b) +{ + uint64_t q, r; + + if (b <= 0) + return (a); + + q = a >> b; + r = a & (b - 1); + if ((r << 1) >= ((uint64_t)1 << b)) + return (q + 1); + else + return (q); +} + +static inline uint32_t +fixp_sqrt(uint64_t x) +{ + uint64_t rem_hi, rem_lo, test_div; + uint32_t root; + int count; + + rem_hi = 0; + rem_lo = x; + root = 0; + count = 31; + + do { + rem_hi = (rem_hi << 2) | (rem_lo >> 62); + rem_lo <<= 2; /* Get 2 bits of arg. */ + root <<= 1; /* Get ready for the next bit in the root. */ + test_div = (root << 1) + 1; /* Test radical. */ + if (rem_hi >= test_div) { + rem_hi -= test_div; + root++; + } + } while (count-- != 0); + + return (root); +} + +/* Similar to timevalsub, but ensures the timeval returned will be >= 0. */ +static inline struct timeval +tv_sub0(struct timeval *num, struct timeval *sub) +{ + struct timeval rv; + + rv.tv_sec = num->tv_sec - sub->tv_sec; + rv.tv_usec = num->tv_usec - sub->tv_usec; + + if (rv.tv_usec < 0) { + rv.tv_usec += 1000000; + rv.tv_sec--; + } + if (rv.tv_sec < 0) { + rv.tv_sec = 0; + rv.tv_usec = 0; + } + + return (rv); +} + +#endif /* _NETINET_IPFW_DIFFUSE_COMMON_H_ */ Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature.h Sat Oct 8 02:58:23 2011 (r226125) @@ -0,0 +1,149 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DIFFUSE feature computation module parts. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_FEATURE_H_ +#define _NETINET_IPFW_DIFFUSE_FEATURE_H_ + +struct di_cdata; +struct di_fdata; +struct mbuf; + +/* + * Descriptor for a feature. A feature is actually a list of related + * statistics. Contains all function pointers for a given feature. This is + * typically created when a module is loaded, and stored in a global list of + * feature instances. + */ +struct di_feature_alg { + const char *name; /* Feature name. */ + const int type; /* Unidirectional or bidirectional. */ + volatile int ref_count; /* Number of instances in the system */ + + /* + * Init instance. + * param1: pointer to instance config + * param2: config from userspace + * return: non-zero on error + */ + int (*init_instance)(struct di_cdata *, struct di_oid *); + + /* + * Destroy instance. + * param1: pointer to instance config + * return: non-zero on error + */ + int (*destroy_instance)(struct di_cdata *); + + /* + * Init state for flow. + * param1: pointer to instance config + * param2: pointer to flow work and stats data + * return: non-zero on error + */ + int (*init_stats)(struct di_cdata *, struct di_fdata *); + + /* + * Destroy flow state. + * param1: pointer to instance config + * param2: pointer to flow work and stats data + * return: non-zero on error + */ + int (*destroy_stats)(struct di_cdata *, struct di_fdata *); + + /* + * Update feature, called for each packet. + * pre: the packet is an IPv4 or IPv6 packet and the caller has done a + * pullup on the mbuf prior to calling. + * param1: pointer to instance config + * param2: pointer to flow work and stats data + * param3: packet (mbuf chain) + * param4: protocol on top of IP + * param5: pointer to upper layer protocol (e.g. UDP, TCP) + * param6: direction of the packet (MATCH_FORWARD or MATCH_REVERSE) + * return: non-zero on error + */ + int (*update_stats)(struct di_cdata *, struct di_fdata *, struct mbuf *, + int proto, void *ulp, int dir); + + /* + * Reset stats. + * param1: pointer to instance config + * param2: pointer to flow work and stats data + * return: non-zero on error + */ + int (*reset_stats)(struct di_cdata *, struct di_fdata *); + + /* + * Get feature statistics. + * param1: pointer to instance config + * param2: pointer to flow work and stats data + * param3: pointer to stats + * return: non-zero on error + */ + int (*get_stats)(struct di_cdata *, struct di_fdata *, int32_t **); + + /* + * Get one feature statistics. + * param1: pointer to instance config + * param2: pointer to flow work and stats data + * param3: which one + * param4: pointer to stat + * return: non-zero on error + */ + int (*get_stat)(struct di_cdata *, struct di_fdata *, int, int32_t *); + + /* + * Get names of statistics. + * param1: array of names + * return: non-zero on error + */ + int (*get_stat_names)(char **[]); + + /* + * Get configuration data. + * param1: pointer to instance config + * param2: pointer to configuration + * param3: only compute size (if 1) + * return: non-zero on error + */ + int (*get_conf)(struct di_cdata *, struct di_oid *, int); + + SLIST_ENTRY(di_feature_alg) next; /* Next feature in the list. */ +}; + +#endif /* _NETINET_IPFW_DIFFUSE_FEATURE_H_ */ Added: projects/diffused_head/sys/netinet/ipfw/diffuse_private.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_private.h Sat Oct 8 02:58:23 2011 (r226125) @@ -0,0 +1,307 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * Internal stuff for DIFFUSE. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_PRIVATE_H_ +#define _NETINET_IPFW_DIFFUSE_PRIVATE_H_ + +/* + * For platforms that do not have SYSCTL support, we wrap the SYSCTL_* into a + * function (one per file) to collect the values into an array at module + * initialization. The wrapping macros, SYSBEGIN() and SYSEND, are empty in the + * default case. + */ +#ifndef SYSBEGIN +#define SYSBEGIN(x) +#endif +#ifndef SYSEND +#define SYSEND +#endif + +MALLOC_DECLARE(M_DIFFUSE); + +#define DI_LOCK_INIT() rw_init(&di_conf.mtx, "diffuse main lock") +#define DI_LOCK_DESTROY() rw_destroy(&di_conf.mtx) +#define DI_RLOCK() rw_rlock(&di_conf.mtx) +#define DI_WLOCK() rw_wlock(&di_conf.mtx) +#define DI_UNLOCK() rw_unlock(&di_conf.mtx) +#define DI_RLOCK_ASSERT() rw_assert(&di_conf.mtx, RA_RLOCKED) +#define DI_WLOCK_ASSERT() rw_assert(&di_conf.mtx, RA_WLOCKED) +#define DI_LOCK_ASSERT() rw_assert(&di_conf.mtx, RA_LOCKED) + +SLIST_HEAD(di_feature_alg_head, di_feature_alg); +LIST_HEAD(di_features_head, di_feature); +SLIST_HEAD(di_classifier_alg_head, di_classifier_alg); +LIST_HEAD(di_classifier_head, di_classifier); +LIST_HEAD(di_export_head, di_export); +/* One (big) list of export records (fifo) - double linked for fast removals. */ +TAILQ_HEAD(di_export_rec_head, di_export_rec); + +/* + * Configuration and global data for DIFFUSE. + * + * When a configuration is modified from userland, 'id' is incremented + * so we can use the value to check for stale pointers. + */ +struct di_parms { + uint32_t id; /* Configuration version. */ + + int debug; + int init_done; + + int an_rule_removal; /* Explicit remove messages or timeouts. */ + + /* Counters of objects -- used for reporting space. */ + int feature_count; /* Number of feature instances. */ + int classifier_count; /* Number of classifier instances. */ + int export_count; /* Number of exports. */ + int export_rec_count; /* Number of exports recs. */ + + /* List of feature algorithms. */ + struct di_feature_alg_head feature_list; + /* List of feature instances. */ + struct di_features_head feature_inst_list; + + /* List of classifier algorithms. */ + struct di_classifier_alg_head classifier_list; + /* List of classifier instances. */ + struct di_classifier_head classifier_inst_list; + + /* List of export instances. */ + struct di_export_head export_list; + + /* List of export records. */ + struct di_export_rec_head export_rec_list; + +#ifdef _KERNEL + /* + * This file is normally used in the kernel, unless we do some userland + * tests, in which case we do not need a mtx. + */ +#if defined( __linux__ ) || defined( _WIN32 ) + spinlock_t mtx; +#else + struct rwlock mtx; +#endif +#endif /* _KERNEL */ +}; + +/* List of flow table timeouts. */ +struct di_to_entry { + struct di_ft_entry *flow; + LIST_ENTRY(di_to_entry) next; +}; + +typedef struct di_export_rec *(*di_to_handler_fn_t) + (struct di_ft_entry *q, struct di_export *, int); + +/* List of flow classes. */ +struct di_flow_class { + char cname[DI_MAX_NAME_STR_LEN]; /* Classifier name. */ + uint16_t class; /* Class ID. */ + int16_t prev_class; /* Prev class id, -1 if no previous class. */ + uint16_t confirm; /* How many identical consecutive classifications. */ + SLIST_ENTRY(di_flow_class) next; +}; + +SLIST_HEAD(di_flow_class_head, di_flow_class); + +/* List of exporters. */ +struct di_exp { + struct di_export *ex; + SLIST_ENTRY(di_exp) next; +}; + +SLIST_HEAD(di_exp_list_head, di_exp); + +/* Flow table entry. */ +struct di_ft_entry { + struct di_ft_entry *next; /* Linked list of rules. */ + struct ip_fw *rule; /* Used to pass up the rule number. */ + struct ipfw_flow_id id; /* (masked) flow id. */ + uint64_t pcnt; /* Packet match counter. */ + uint64_t bcnt; /* Byte match counter. */ + uint32_t expire; /* Expire time. */ + uint32_t bucket; /* Which bucket in hash table. */ + uint32_t state; /* State of this rule (typically a + * combination of TCP flags). */ + uint8_t ftype; /* Bidir vs unidir, match limiting. */ + uint8_t fcnt; /* Number of features. */ + uint8_t tcnt; /* Number of class tags. */ + uint16_t sample_int; /* Sample interval. */ + uint32_t sample_prob; /* Sample probability. */ + uint16_t pkts_after_last; /* Match limiting: packets n */ + struct di_feature *features[DI_MAX_FEATURES]; /* Feature ptrs. */ + struct di_fdata fwd_data[DI_MAX_FEATURES]; + struct di_fdata bck_data[DI_MAX_FEATURES]; + struct timeval ex_time; /* Time last exported. */ + struct di_flow_class_head flow_classes; /* List of class tags. */ + struct di_to_entry *to; /* Timeout list entry ptr. */ + struct di_exp_list_head ex_list; /* Ptrs to exporters. */ +}; + +/* Export data record. */ +struct di_export_rec { + char ename[DI_MAX_NAME_STR_LEN]; /* Generating export instance. */ + struct ipfw_flow_id id; /* IPs, ports. */ + struct timeval time; /* Generation time. */ + struct timeval no_earlier; /* Don't send before. */ + /* XXX: Flow label, TOS missing */ + uint8_t mtype; /* Message type. */ + uint8_t fcnt; /* Number of features. */ + uint8_t tcnt; /* Number of tags. */ + uint8_t ftype; /* Bidir vs unidir. */ + uint8_t match_dir; + uint8_t action_dir; /* Bidir vs unidir. */ + uint8_t ttype; /* Timeout type. */ + uint16_t tval; /* Timeout value in seconds. */ + uint32_t pcnt; /* Flow packet counter. */ + uint64_t bcnt; /* Flow byte counter. */ + struct di_ft_flow_class class_tags[DI_MAX_CLASSES]; + char action[DI_MAX_NAME_STR_LEN]; + char act_params[DI_MAX_PARAM_STR_LEN]; + struct di_ft_entry *ft_rec; /* Flow entry ptr. */ + TAILQ_ENTRY(di_export_rec) next; +}; + +/* Feature. */ +struct di_feature { + char *name; /* Instance name. */ + volatile int ref_count; /* Num rules referencing feature. */ + struct di_cdata conf; + struct di_feature_alg *alg; /* Feature algorithm ptr. */ + LIST_ENTRY(di_feature) next; /* Next in list. */ +}; + +/* Classifier. */ +struct di_feature_stat_ptr { + struct di_feature *fptr; /* Pointer to feature. */ + uint8_t sidx; /* Statistic index. */ +}; + +struct di_classifier { + char *name; /* Instance name. */ + volatile int ref_count; /* Num rules referencing classifier. */ + struct di_classifier_alg *alg; /* Classifier algorithm ptr. */ + struct di_cdata conf; + int32_t id; /* Unique id used for tag cookie. */ + uint16_t *tags; + uint16_t confirm; /* How many identical consecutive + * classifications. */ + uint8_t fscnt; /* Number of features. */ + uint8_t ccnt; /* Number of classes. */ + uint8_t tcnt; /* Tag count (ipfw tags). */ + struct di_feature_stat *fstats; /* Features + classes. */ + struct di_feature_stat_ptr *fstats_ptr; /* Feature indices. */ + LIST_ENTRY(di_classifier) next; /* Next in list. */ +}; + +/* Export. */ +struct di_export { + char *name; /* Instance name. */ + volatile int ref_count; /* Num rules referencing exporter. */ + struct di_export_config conf; /* Config from userspace. */ + struct socket *sock; /* Protocol socket. */ + uint32_t seq_no; /* Sequence number. */ + struct timeval last_pkt_time; /* Most recently sent packet. */ + struct mbuf *mh; /* First mbuf of export packet chain. */ + struct mbuf *mt; /* Last mbuf of export packet chain. */ + LIST_ENTRY(di_export) next; /* Next in list. */ +}; + +/* For tagging mbufs (packets) with classes. */ +#define MTAG_DIFFUSE_CLASS 1243750889 + +struct di_class_tag { + struct m_tag tag; + int class; + int prev_class; + int confirm; +}; + +/* Global configuration. */ +extern struct di_parms di_conf; + +/* Function prototypes. */ + +/* ip_diffuse.c */ +int diffuse_get_feature_idx(const char *name); + +/* diffuse_flowtable.c */ +void diffuse_ft_attach(void); +void diffuse_ft_detach(void); +void diffuse_ft_init(void); +void diffuse_ft_uninit(void); +int diffuse_ft_len(int expired); +struct di_ft_entry * diffuse_ft_install_state(struct ip_fw *rule, + ipfw_insn_features *cmd, struct ip_fw_args *args, void *ulp, int pktlen); +struct di_ft_entry * diffuse_ft_lookup_entry(struct ipfw_flow_id *pkt, + struct ip_fw_args *args, void *ulp, int pktlen, int *match_direction); +void diffuse_get_ft(char **pbp, const char *ep, int expired); +int diffuse_ft_entries(void); +void diffuse_ft_remove_entries(struct ip_fw *rule); +void diffuse_ft_add_class(struct di_ft_entry *e, char *cname, int class, + int *prev_class, int *confirm); +int diffuse_ft_get_class(struct di_ft_entry *e, char *cname, int *prev_class, + int *confirm); +void diffuse_ft_remove_class(struct di_ft_entry *e, char *cname); +void diffuse_ft_unlock(void); +void diffuse_ft_check_timeouts(di_to_handler_fn_t f); +void diffuse_ft_add_export(struct di_ft_entry *e, + struct di_export_rec *ex_rec, struct di_export *nex); +void diffuse_ft_flush(int reset_counters_only); +int diffuse_ft_get_stat(struct di_ft_entry *q, int fdir, + struct di_feature *fptr, int sidx, int32_t *val); +int diffuse_ft_get_stats(struct di_ft_entry *q, int fscnt, + struct di_feature_stat *fstats, struct di_feature_stat_ptr *fstats_ptr, + int32_t *fvec); +int diffuse_ft_do_export(struct di_ft_entry *q, uint16_t confirm); +int diffuse_ft_update_features(struct di_ft_entry *q, + ipfw_insn_features *cmd, struct ip_fw_args *args, void *ulp); + +/* diffuse_export.c */ +int diffuse_export_remove_recs(char *ename); +struct di_export_rec * diffuse_export_add_rec(struct di_ft_entry *q, + struct di_export *ex, int add_command); +struct socket *diffuse_export_open(struct di_export_config *conf); +int diffuse_export_send(struct di_export *ex); +void diffuse_export_close(struct socket *s); +void diffuse_export_init(void); +void diffuse_export_uninit(void); +void diffuse_export_prune_recs(void); + +#endif /* _NETINET_IPFW_DIFFUSE_PRIVATE_H_ */ Modified: projects/diffused_head/sys/netinet/ipfw/ip_fw2.c ============================================================================== --- projects/diffused_head/sys/netinet/ipfw/ip_fw2.c Sat Oct 8 00:01:17 2011 (r226124) +++ projects/diffused_head/sys/netinet/ipfw/ip_fw2.c Sat Oct 8 02:58:23 2011 (r226125) @@ -73,7 +73,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include +#include #include #include #include @@ -89,12 +89,18 @@ __FBSDID("$FreeBSD$"); #include #endif +#include +#include + #include /* XXX for in_cksum */ #ifdef MAC #include #endif +/* DIFFUSE */ +ipfw_ext_t *ipfw_diffuse_ext = NULL; + /* * static variables followed by global ones. * All ipfw global variables are here. @@ -914,6 +920,8 @@ ipfw_chk(struct ip_fw_args *args) * MATCH_FORWARD or MATCH_REVERSE otherwise (q != NULL) */ int dyn_dir = MATCH_UNKNOWN; + /* For DIFFUSE features. */ + int flow_dir = MATCH_UNKNOWN; ipfw_dyn_rule *q = NULL; struct ip_fw_chain *chain = &V_layer3_chain; @@ -935,6 +943,12 @@ ipfw_chk(struct ip_fw_args *args) int done = 0; /* flag to exit the outer loop */ + /* + * DIFFUSE data container required for persistent storage between *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 03:58:21 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1C4D71065673; Sat, 8 Oct 2011 03:58:21 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 097468FC16; Sat, 8 Oct 2011 03:58:21 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p983wLT0041197; Sat, 8 Oct 2011 03:58:21 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p983wK5b041188; Sat, 8 Oct 2011 03:58:20 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080358.p983wK5b041188@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 03:58:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226126 - in projects/diffused_head/sys: modules modules/diffuse modules/diffuse/diffuse netinet netinet/ipfw sys X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 03:58:21 -0000 Author: lstewart Date: Sat Oct 8 03:58:20 2011 New Revision: 226126 URL: http://svn.freebsd.org/changeset/base/226126 Log: Add the core DIFFUSE kernel module code and supporting build infrastructure. This module provides the kernel-side support for handling DIFFUSE's IPFW configuration extensions, rule exporting, classifier/feature modules and flow-related housekeeping. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/modules/diffuse/ projects/diffused_head/sys/modules/diffuse/Makefile (contents, props changed) projects/diffused_head/sys/modules/diffuse/diffuse/ projects/diffused_head/sys/modules/diffuse/diffuse/Makefile (contents, props changed) projects/diffused_head/sys/netinet/ip_diffuse_export.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_classifier.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_module.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_export.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_module.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_flowtable.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_user_compat.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/ip_diffuse.c (contents, props changed) Modified: projects/diffused_head/sys/modules/Makefile projects/diffused_head/sys/sys/time.h Modified: projects/diffused_head/sys/modules/Makefile ============================================================================== --- projects/diffused_head/sys/modules/Makefile Sat Oct 8 02:58:23 2011 (r226125) +++ projects/diffused_head/sys/modules/Makefile Sat Oct 8 03:58:20 2011 (r226126) @@ -78,6 +78,7 @@ SUBDIR= ${_3dfx} \ dcons \ dcons_crom \ de \ + ${_diffuse} \ ${_dpms} \ ${_dpt} \ ${_drm} \ @@ -365,6 +366,7 @@ _random= random .endif .if ${MK_INET_SUPPORT} != "no" || defined(ALL_MODULES) +_diffuse= diffuse _if_gre= if_gre .endif Added: projects/diffused_head/sys/modules/diffuse/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 03:58:20 2011 (r226126) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +SUBDIR= diffuse + +.include Added: projects/diffused_head/sys/modules/diffuse/diffuse/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/diffuse/Makefile Sat Oct 8 03:58:20 2011 (r226126) @@ -0,0 +1,24 @@ +# $FreeBSD$ + +.include + +.PATH: ${.CURDIR}/../../../netinet/ipfw + +KMOD= diffuse +SRCS= diffuse_export.c \ + diffuse_flowtable.c \ + ip_diffuse.c \ + opt_inet6.h + +.if !defined(KERNBUILDDIR) +.if ${MK_INET_SUPPORT} != "no" +opt_inet.h: + echo "#define INET 1" > ${.TARGET} +.endif +.if ${MK_INET6_SUPPORT} != "no" +opt_inet6.h: + echo "#define INET6 1" > ${.TARGET} +.endif +.endif + +.include Added: projects/diffused_head/sys/netinet/ip_diffuse_export.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ip_diffuse_export.h Sat Oct 8 03:58:20 2011 (r226126) @@ -0,0 +1,148 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * The public header file for DIFFUSE export protocol stuff. + */ + +#ifndef _NETINET_IP_DIFFUSE_EXPORT_H_ +#define _NETINET_IP_DIFFUSE_EXPORT_H_ + +/* DIFFUSE protocol version. */ +#define DIP_VERSION 1 + +/* Used if querying MTU from routing table fails. */ +#define DIP_DEFAULT_MTU 1500 + +enum dip_msg_types { + DIP_MSG_ADD = 0, + DIP_MSG_REMOVE +}; + +enum dip_timeout_types { + DIP_TIMEOUT_NONE = 0, + DIP_TIMEOUT_RULE, + DIP_TIMEOUT_FLOW +}; + +enum dip_info_element_types { + DIP_IE_NOP = 0, + DIP_IE_SRC_IPV4, + DIP_IE_DST_IPV4, + DIP_IE_SRC_PORT, + DIP_IE_DST_PORT, + DIP_IE_PROTO, + DIP_IE_SRC_IPV6, + DIP_IE_DST_IPV6, + DIP_IE_IPV4_TOS, + DIP_IE_IPV6_LABEL, + DIP_IE_CLASS_LABEL, + DIP_IE_MATCH_DIR, + DIP_IE_MSG_TYPE, /* Add or remove. */ + DIP_IE_TIMEOUT_TYPE, /* Rule timeout vs flow timeout. */ + DIP_IE_TIMEOUT, /* Timeout value. */ + DIP_IE_ACTION_FLAGS, /* Bidir. */ + DIP_IE_PCKT_CNT, /* Current number of packets. */ + DIP_IE_KBYTE_CNT, /* Current number of bytes. */ + DIP_IE_ACTION, /* Type of action. */ + DIP_IE_ACTION_PARAMS, /* Opaque, passed on to packet filter. */ + DIP_IE_EXPORT_NAME, /* Name of export. */ + DIP_IE_CLASSIFIER_NAME, /* Name of classifier. */ + DIP_IE_CLASSES /* Classifier names/classes. */ +}; + +#define DI_IS_FIXED_LEN(x) (((x) & 0xC000) == 0x0) +#define DI_IS_VARIABLE_LEN(x) (((x) & 0xC000) == 0x8000) +#define DI_IS_DYNAMIC_LEN(x) (((x) & 0xC000) == 0xC000) + +struct dip_info_element { + uint16_t idx; + uint16_t id; + int16_t len; +}; + +struct dip_info_descr { + uint16_t idx; + uint16_t id; + int16_t len; /* Length in bytes, 0/-1 = var/dynamic length. */ + char *name; +}; + +struct dip_header { + uint16_t version; + uint16_t msg_len; + uint32_t seq_no; + uint32_t time; +}; + +struct dip_set_header { + uint16_t set_id; + uint16_t set_len; +}; + +struct dip_templ_header { + uint16_t templ_id; + uint16_t flags; +}; + +#if defined(WITH_DIP_INFO) +static struct dip_info_descr dip_info[] = { + {DIP_IE_NOP, 0, 0, "NOP"}, + {DIP_IE_SRC_IPV4, 1, 4, "SrcIP"}, + {DIP_IE_DST_IPV4, 2, 4, "DstIP"}, + {DIP_IE_SRC_PORT, 3, 2, "SrcPort"}, + {DIP_IE_DST_PORT, 4, 2, "DstPort"}, + {DIP_IE_PROTO, 5, 1, "Proto"}, + {DIP_IE_SRC_IPV6, 6, 16, "SrcIP6"}, + {DIP_IE_DST_IPV6, 7, 16, "DstIP6"}, + {DIP_IE_IPV4_TOS, 8, 1, "ToS"}, + {DIP_IE_IPV6_LABEL, 9, 3, "IP6Label"}, + {DIP_IE_CLASS_LABEL, 10, 2, "Class"}, + {DIP_IE_MATCH_DIR, 11, 1, "MatchDir"}, + {DIP_IE_MSG_TYPE, 12, 1, "MsgType"}, + {DIP_IE_TIMEOUT_TYPE, 13, 1, "TimeoutType"}, + {DIP_IE_TIMEOUT, 14, 2, "TimeoutValue"}, + {DIP_IE_ACTION_FLAGS, 15, 2, "ActionFlags"}, + {DIP_IE_PCKT_CNT, 16, 4, "Packets"}, + {DIP_IE_KBYTE_CNT, 17, 4, "KBytes"}, + {DIP_IE_ACTION, 32768, 0, "Action"}, + {DIP_IE_ACTION_PARAMS, 32769, 0, "ActionParams"}, + {DIP_IE_EXPORT_NAME, 32770, 0, "ExportName"}, + {DIP_IE_CLASSIFIER_NAME, 32771, 0, "ClassName"}, + {DIP_IE_CLASSES, 49152, -1, "ClassNames"}, + {DIP_IE_NOP, 0, 0, "Unknown"} +}; +#endif + +#endif /* _NETINET_IP_DIFFUSE_EXPORT_H_ */ Added: projects/diffused_head/sys/netinet/ipfw/diffuse_classifier.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_classifier.h Sat Oct 8 03:58:20 2011 (r226126) @@ -0,0 +1,100 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _NETINET_IPFW_DIFFUSE_CLASSIFIER_H_ +#define _NETINET_IPFW_DIFFUSE_CLASSIFIER_H_ + +struct di_cdata; +struct di_fdata; + +/* + * Descriptor for a classifier. Contains all function pointers for a given + * classifier. This is typically created when a module is loaded, and stored in + * a global list of classifiers. + */ +struct di_classifier_alg { + const char *name; /* Classifier name. */ + volatile int ref_count; /* Number of instances in the system. */ + + /* + * Init instance. + * param1: pointer to instance config + * param2: config from userspace + * return: non-zero on error + */ + int (*init_instance)(struct di_cdata *, struct di_oid *); + + /* + * Destroy instance. + * param1: pointer to instance config + * return: non-zero on error + */ + int (*destroy_instance)(struct di_cdata *); + + /* + * Classify packet (sub flow). + * param1: pointer to instance config + * param2: pointer to features + * param3: number of features + * return: class + */ + int (*classify)(struct di_cdata *, int32_t *, int); + + /* + * Get configuration data. + * param1: pointer to instance config + * param2: pointer to configuration + * param3: only compute size (if 1) + * return: number of stats + */ + int (*get_conf)(struct di_cdata *, struct di_oid *, int); + + /* + * Get number of features needed. + * param1: pointer to instance config + * return: number of features + */ + int (*get_feature_cnt)(struct di_cdata *); + + /* + * Get number of classes. + * param1: pointer to instance config + * return: number of classes + */ + int (*get_class_cnt)(struct di_cdata *); + + SLIST_ENTRY(di_classifier_alg) next; /* Next in the list. */ +}; + +#endif /* _NETINET_IPFW_DIFFUSE_CLASSIFIER_H_ */ Added: projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_module.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_module.h Sat Oct 8 03:58:20 2011 (r226126) @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _NETINET_IPFW_DIFFUSE_CLASSIFIER_MODULE_H_ +#define _NETINET_IPFW_DIFFUSE_CLASSIFIER_MODULE_H_ + +#define DECLARE_DIFFUSE_CLASSIFIER_MODULE(cname, cstruct) \ + static moduledata_t di_classifier_##cname = { \ + .name = #cname, \ + .evhand = diffuse_classifier_modevent, \ + .priv = cstruct \ + }; \ + DECLARE_MODULE(cname, di_classifier_##cname, \ + SI_SUB_PROTO_IFATTACHDOMAIN, SI_ORDER_ANY); \ + MODULE_DEPEND(cname, diffuse, 1, 1, 1) + +int diffuse_classifier_modevent(module_t mod, int cmd, void *arg); + +#endif /* _NETINET_IPFW_DIFFUSE_CLASSIFIER_MODULE_H_ */ Added: projects/diffused_head/sys/netinet/ipfw/diffuse_export.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_export.c Sat Oct 8 03:58:20 2011 (r226126) @@ -0,0 +1,750 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Functions to manage the export protocol. + */ + +#include +__FBSDID("$FreeBSD$"); + +#if !defined(KLD_MODULE) +#include "opt_ipfw.h" +#include "opt_inet.h" +#ifndef INET +#error DIFFUSE requires INET. +#endif /* INET */ +#endif + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#define WITH_DIP_INFO 1 +#include +#include +#include + +#include +#include + +static VNET_DEFINE(uint32_t, ex_max_qsize); +#define V_ex_max_qsize VNET(ex_max_qsize) + +static uma_zone_t di_rec_zone; + +#ifndef __FreeBSD__ +DEFINE_SPINLOCK(di_er_mtx); +#else +static struct mtx di_er_mtx; /* Mutex guarding dynamic rules. */ +#endif + +#define DI_ER_LOCK() mtx_lock(&di_er_mtx) +#define DI_ER_UNLOCK() mtx_unlock(&di_er_mtx) +#define DI_ER_LOCK_ASSERT() mtx_assert(&di_er_mtx, MA_OWNED) +#define DI_ER_LOCK_DESTROY() mtx_destroy(&di_er_mtx) +#define DI_ER_LOCK_INIT() mtx_init(&di_er_mtx, \ + "DIFFUSE export record list", NULL, MTX_DEF) + +uint16_t def_template[15] = { + DIP_IE_EXPORT_NAME, + DIP_IE_MSG_TYPE, + DIP_IE_SRC_IPV4, + DIP_IE_DST_IPV4, + DIP_IE_SRC_PORT, + DIP_IE_DST_PORT, + DIP_IE_PROTO, + DIP_IE_PCKT_CNT, + DIP_IE_KBYTE_CNT, + DIP_IE_CLASSES, + DIP_IE_TIMEOUT_TYPE, + DIP_IE_TIMEOUT, + DIP_IE_ACTION, + DIP_IE_ACTION_FLAGS, + DIP_IE_ACTION_PARAMS +}; + +#define N_TEMPLATE_ITEMS (sizeof(def_template) / sizeof(*def_template)) + +/* + * Length of the fixed size, per-packet header on outgoing flow rule template + * based export packets. + * The packet header consists of the following parts (in order): + * - struct dip_header + * - struct dip_set_header + * - struct dip_templ_header + * - A uint16_t ID field for each information element (IE) + * - A uint16_t length field for variable length IEs (there are currently 4) + */ +#define DIP_FIXED_HDR_LEN (sizeof(struct dip_header) + \ + sizeof(struct dip_set_header) + sizeof(struct dip_templ_header) + \ + (N_TEMPLATE_ITEMS * sizeof(uint16_t)) + 4 * sizeof(uint16_t)) + +/* Size for one data set. */ +static int def_data_size; + +/* Offset into mhead where the data set header starts. */ +static int def_data_shdr_offs; + +/* Template for packet header. */ +static struct mbuf *mhead; + +#ifdef SYSCTL_NODE +SYSBEGIN(xxx) +SYSCTL_DECL(_net_inet_ip_diffuse); +SYSCTL_VNET_UINT(_net_inet_ip_diffuse, OID_AUTO, ex_max_qsize, CTLFLAG_RW, + &VNET_NAME(ex_max_qsize), 0, "Max export record queue size"); +SYSEND +#endif /* SYSCTL_NODE */ + +/* Compute static size of one data set according to template. */ +static int +_get_data_size(void) +{ + int i, n, size; + + size = 0; + + for (i = 0; i < N_TEMPLATE_ITEMS; i++) { + n = dip_info[def_template[i]].len; + if (n > 0) + size += n; + else if (n == 0) { + if (def_template[i] == DIP_IE_ACTION || + def_template[i] == DIP_IE_EXPORT_NAME || + def_template[i] == DIP_IE_CLASSIFIER_NAME) { + size += DI_MAX_NAME_STR_LEN; + } else if (def_template[i] == DIP_IE_ACTION_PARAMS) { + size += DI_MAX_PARAM_STR_LEN; + } + } + /* Do not count dynamic length fields here. */ + } + + return (size); +} + +/* Compute dynamic size of record r. */ +static int +get_data_size(struct di_export_rec *r) +{ + int i, l, slen; + + l = 0; + + for (i = 0; i < r->tcnt; i++) { + slen = strlen(r->class_tags[i].cname); + /* String, null, class. */ + l += slen + 1 + dip_info[DIP_IE_CLASS_LABEL].len; + } + l++; /* Field length byte. */ + + return (def_data_size + l); +} + +static inline uint32_t +tv_sub0_ms(struct timeval *num, struct timeval *sub) +{ + struct timeval rv; + + rv = tv_sub0(num, sub); + + return (tvtoms(&rv)); +} + +static void +remove_rec(struct di_export_rec *r) +{ + + DI_ER_LOCK_ASSERT(); + + TAILQ_REMOVE(&di_conf.export_rec_list, r, next); + uma_zfree(di_rec_zone, r); + di_conf.export_rec_count--; +} + +struct di_export_rec * +diffuse_export_add_rec(struct di_ft_entry *q, struct di_export *ex, + int add_command) +{ + struct di_export_rec *r, *s; + struct di_flow_class *c; + int have_entry; + + r = NULL; + have_entry = 0; + + /* We don't handle exporting v6 flow records yet. */ + if (q->id.addr_type == 6) + return (NULL); + + DI_ER_LOCK(); + + /* Update and export entry if we have one for this flow already. */ + TAILQ_FOREACH(s, &di_conf.export_rec_list, next) { + /* + * Only compare pointer for speed. If new flow with same 5-tuple + * we may add another record for same 5-tuple + */ + if (s->ft_rec == q) { + have_entry = 1; + r = s; + break; + } + } + + if (!have_entry) { + r = uma_zalloc(di_rec_zone, M_NOWAIT | M_ZERO); + if (r == NULL) { + DI_ER_UNLOCK(); + return (NULL); + } + strcpy(r->ename, ex->name); + r->ft_rec = q; + } + + getmicrotime(&r->time); + r->id = q->id; + r->fcnt = q->fcnt; + r->ftype = q->ftype; + r->mtype = add_command ? DIP_MSG_ADD : DIP_MSG_REMOVE; + r->ttype = di_conf.an_rule_removal; + r->pcnt = q->pcnt; + /* + * The flow byte count we send across the wire is in KBytes + * (see DIP_IE_KBYTE_CNT in ). + */ + r->bcnt = q->bcnt / 1000; + if (add_command) { + r->tval = (uint16_t) (q->expire > time_uptime) ? + q->expire - time_uptime : 0; + r->tval++; /* Make it slightly larger. */ + } else { + r->tval = 0; + } + + /* Class tags (only confirmed!). */ + r->tcnt = 0; + SLIST_FOREACH(c, &q->flow_classes, next) { + if (r->tcnt >= DI_MAX_CLASSES) + break; + + if (c->confirm >= ex->conf.confirm) { + strcpy(r->class_tags[r->tcnt].cname, c->cname); + r->class_tags[r->tcnt].class = c->class; + r->tcnt++; + } + } + + if (!have_entry) { + if (r->ftype & DI_FLOW_TYPE_BIDIRECTIONAL || + ex->conf.atype & DI_ACTION_TYPE_BIDIRECTIONAL) + r->action_dir = DI_ACTION_TYPE_BIDIRECTIONAL; + else + r->action_dir = DI_ACTION_TYPE_UNIDIRECTIONAL; + + strcpy(r->action, ex->conf.action); + strcpy(r->act_params, ex->conf.action_param); + TAILQ_INSERT_TAIL(&di_conf.export_rec_list, r, next); + di_conf.export_rec_count++; + r->no_earlier.tv_sec = r->no_earlier.tv_usec = 0; + } + + DI_ER_UNLOCK(); + + return (r); +} + +/* Limit total number of records. */ +void +diffuse_export_prune_recs(void) +{ + struct di_export_rec *r; + + DI_ER_LOCK(); + + if (V_ex_max_qsize > 65535) + V_ex_max_qsize = 65535; + + if (V_ex_max_qsize < 0) + V_ex_max_qsize = 0; + + while (di_conf.export_rec_count > V_ex_max_qsize) { + r = TAILQ_FIRST(&di_conf.export_rec_list); + remove_rec(r); + } + + DI_ER_UNLOCK(); +} + +int +diffuse_export_remove_recs(char *ename) +{ + struct di_export_rec *r, *tmp; + + DI_ER_LOCK(); + + TAILQ_FOREACH_SAFE(r, &di_conf.export_rec_list, next, tmp) { + if (ename == NULL || !strcmp(r->ename, ename)) + remove_rec(r); + } + + DI_ER_UNLOCK(); + + return (0); +} + +/* Open and bind socket. */ +struct socket * +diffuse_export_open(struct di_export_config *conf) +{ + struct socket *sock; + struct thread *td; + int ret; + + sock = NULL; + td = curthread; + + if (mhead != NULL) { + /* Open UDP socket. */ + ret = socreate(AF_INET, &sock, SOCK_DGRAM, IPPROTO_UDP, + td->td_ucred, td); + if (ret) + DID("socket create error %d", ret); + } + + return (sock); +} + +/* + * Prepare the packet header for later use. Every packet contains one rule spec + * template followed by data. + */ +static void +prepare_header(void) +{ +#define SET_ID_OPTS_TPL 0 +#define SET_ID_FLOWRULE_TPL 1 +#define SET_ID_DATA 256 + + struct dip_header *hdr; + struct dip_set_header *shdr; + struct dip_templ_header *thdr; + int i, offs; + char *buf; + + /* + * Ensures we will be able to shoehorn the entire fixed length header + * into a single mbuf. + */ + CTASSERT(MHLEN >= DIP_FIXED_HDR_LEN); + + offs = 0; + + mhead = m_gethdr(M_WAITOK, MT_DATA); + mhead->m_next = NULL; + buf = mtod(mhead, char *); + hdr = (struct dip_header *)buf; + hdr->version = htons((uint16_t)DIP_VERSION); + hdr->msg_len = 0; + hdr->seq_no = 0; + hdr->time = 0; + offs += sizeof(struct dip_header); + + shdr = (struct dip_set_header *)(buf + offs); + shdr->set_id = htons((uint16_t)SET_ID_FLOWRULE_TPL); + shdr->set_len = 0; + offs += sizeof(struct dip_set_header); + + thdr = (struct dip_templ_header *)(buf + offs); + thdr->templ_id = htons((uint16_t)SET_ID_DATA); + thdr->flags = 0; + offs += sizeof(struct dip_templ_header); + + for (i = 0; i < N_TEMPLATE_ITEMS; i++) { + *((uint16_t *)(buf + offs)) = + htons(dip_info[def_template[i]].id); + offs += sizeof(uint16_t); + if (def_template[i] == DIP_IE_ACTION || + def_template[i] == DIP_IE_EXPORT_NAME || + def_template[i] == DIP_IE_CLASSIFIER_NAME) { + *((uint16_t *)(buf + offs)) = + htons((uint16_t)DI_MAX_NAME_STR_LEN); + offs += sizeof(uint16_t); + } else if (def_template[i] == DIP_IE_ACTION_PARAMS) { + *((uint16_t *)(buf + offs)) = + htons((uint16_t)DI_MAX_PARAM_STR_LEN); + offs += sizeof(uint16_t); + } + } + + shdr->set_len = htons(offs - sizeof(struct dip_header)); + def_data_shdr_offs = offs; + shdr = (struct dip_set_header *)(buf + offs); + shdr->set_id = htons((uint16_t)SET_ID_DATA); + shdr->set_len = htons(sizeof(struct dip_set_header)); + offs += sizeof(struct dip_set_header); + + hdr->msg_len = htons(offs); + mhead->m_len = offs; + + m_fixhdr(mhead); + mhead->m_pkthdr.rcvif = NULL; +} + +/* + * If r is not NULL we add data and possibly send if packet length reached. + * If r is NULL we just send packet if we have an mbuf. + */ +static void +add_record(struct di_export *ex, struct di_export_rec *r, + struct timeval *tv, int dyn_rsize) +{ + struct dip_header *hdr; + struct dip_set_header *shdr; + struct di_export_config *conf; + struct mbuf *md; + char *buf; + int i, new_header, offs, slen; + unsigned char *lfield; + + DI_ER_LOCK_ASSERT(); + + conf = &ex->conf; + new_header = offs = 0; + + if (ex->mh == NULL) { + ex->mh = m_dup(mhead, MT_DATA); + ex->mh->m_next = NULL; + ex->mh->m_nextpkt = NULL; + ex->mt = ex->mh; + /* Make sure IPFW/DIFFUSE skips exporter packets. */ + ex->mh->m_flags |= M_SKIP_FIREWALL; + new_header = 1; + } + + /* Update stuff in packet header. */ + buf = mtod(ex->mh, char *); + hdr = (struct dip_header *)buf; + if (new_header) + hdr->seq_no = htonl(ex->seq_no++); + + hdr->time = htonl(tv->tv_sec); + hdr->msg_len = htons(ntohs(hdr->msg_len) + dyn_rsize); + + /* Update stuff in data set header. */ + shdr = (struct dip_set_header *)(buf + def_data_shdr_offs); + shdr->set_len = htons(ntohs(shdr->set_len) + dyn_rsize); + + /* Find space for data, add new mbuf if required. */ + if (ex->mt == ex->mh || (MLEN - ex->mt->m_len) < dyn_rsize) { + /* Add new mbuf to chain. */ + md = m_get(M_NOWAIT, MT_DATA); + if (!md) + return; + md->m_next = NULL; + ex->mt->m_next = md; + ex->mt = md; + } + + buf = mtod(ex->mt, char *); + offs = ex->mt->m_len; + + /* Fill in data. */ + /* XXX: Create function with a switch for all IEs. */ + memcpy((char *)(buf + offs), r->ename, DI_MAX_NAME_STR_LEN); + offs += DI_MAX_NAME_STR_LEN; + *((uint8_t *)(buf + offs)) = r->mtype; + offs += sizeof(uint8_t); + *((uint32_t *)(buf + offs)) = htonl(r->id.src_ip); + offs += sizeof(uint32_t); + *((uint32_t *)(buf + offs)) = htonl(r->id.dst_ip); + offs += sizeof(uint32_t); + *((uint16_t *)(buf + offs)) = htons(r->id.src_port); + offs += sizeof(uint16_t); + *((uint16_t *)(buf + offs)) = htons(r->id.dst_port); + offs += sizeof(uint16_t); + *((uint8_t *)(buf + offs)) = r->id.proto; + offs += sizeof(uint8_t); + *((uint32_t *)(buf + offs)) = htonl(r->pcnt); + offs += sizeof(uint32_t); + *((uint32_t *)(buf + offs)) = htonl(r->bcnt); + offs += sizeof(uint32_t); + + lfield = buf + offs; + offs++; + *lfield = 1; + /* + * tcnt will be <= DI_MAX_CLASSES which is set so that lfield will + * never overflow. + */ + for (i = 0; i < r->tcnt; i++) { + slen = strlen(r->class_tags[i].cname); + memcpy((char *)(buf + offs), r->class_tags[i].cname, slen + 1); + offs += slen + 1; + *((uint16_t *)(buf + offs)) = htons(r->class_tags[i].class); + offs += sizeof(uint16_t); + KASSERT((*lfield + slen + 1 + sizeof(uint16_t) < + (1 << sizeof(*lfield))), ("%s: lfield overflowed", + __func__)); + *lfield += slen + 1 + sizeof(uint16_t); + } + *((uint8_t *)(buf + offs)) = r->ttype; + offs += sizeof(uint8_t); + *((uint16_t *)(buf + offs)) = htons(r->tval); + offs += sizeof(uint16_t); + memcpy((char *)(buf + offs), r->action, DI_MAX_NAME_STR_LEN); + offs += DI_MAX_NAME_STR_LEN; + *((uint16_t *)(buf + offs)) = htons((uint16_t)r->action_dir); + offs += sizeof(uint16_t); + memcpy((char *)(buf + offs), r->act_params, DI_MAX_PARAM_STR_LEN); + offs += DI_MAX_PARAM_STR_LEN; + + ex->mt->m_len = offs; + + /* Fix chain header, e.g. adjust chain length. */ + m_fixhdr(ex->mh); + ex->mh->m_pkthdr.rcvif = NULL; +} + +static inline int +queue_tx_pkt_if(struct di_export *ex, int dyn_rsize, struct timeval *tv, + struct mbuf **tx_pkt_queue, int force) +{ + struct route sro; + struct sockaddr_in *dst; + unsigned long mtu; + int ready_to_send; + + DI_ER_LOCK_ASSERT(); + + ready_to_send = 0; + mtu = DIP_DEFAULT_MTU; + + bzero(&sro, sizeof(sro)); + dst = (struct sockaddr_in *)&sro.ro_dst; + dst->sin_family = AF_INET; + dst->sin_len = sizeof(*dst); + dst->sin_addr = ex->conf.ip; + in_rtalloc_ign(&sro, 0, ex->sock->so_fibnum); + + if (sro.ro_rt != NULL) { + if (sro.ro_rt->rt_rmx.rmx_mtu == 0) + mtu = sro.ro_rt->rt_ifp->if_mtu; + else + mtu = min(sro.ro_rt->rt_rmx.rmx_mtu, + sro.ro_rt->rt_ifp->if_mtu); + RTFREE(sro.ro_rt); + } + + /* + * If the export packet currently being constructed (chain headed by + * ex->mh) would be overfilled by adding a record of size dyn_rsize, + * move the chain to the tx_pkt_queue and set the ex chain headers to + * NULL so that add_record() will start a new chain. + */ + if (force || (ex->mt->m_len + dyn_rsize) >= + (mtu - sizeof(struct ip) + sizeof(struct udphdr))) { + /* Add to queue. */ + if (*tx_pkt_queue == NULL) { + *tx_pkt_queue = ex->mh; + } else { + while ((*tx_pkt_queue)->m_nextpkt != NULL) + tx_pkt_queue = &((*tx_pkt_queue)->m_nextpkt); + + (*tx_pkt_queue)->m_nextpkt = ex->mh; + } + + ex->mh = NULL; + ex->mt = NULL; + ex->last_pkt_time = *tv; + ready_to_send = 1; + } + + return (ready_to_send); +} + +int +diffuse_export_send(struct di_export *ex) +{ + static int waiting = 0; /* Number of records waiting to be sent. */ + struct thread *td; + struct di_export_rec *r, *tmp; + struct di_export_config *conf; + struct timeval tv; + /* Copies for sending outside lock. */ + struct socket *sock; + struct sockaddr_in sin; + struct mbuf *next_tx_pkt, *tx_pkt_queue; + int cnt, dyn_rsize, ret; + + td = curthread; + sock = NULL; + tx_pkt_queue = NULL; + conf = &ex->conf; + cnt = waiting; /* Number of records processed */ + + DI_ER_LOCK(); + + if (di_conf.export_rec_count == 0 || + waiting + di_conf.export_rec_count < conf->min_batch) { + DI_ER_UNLOCK(); + return (0); + } + + getmicrotime(&tv); + *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 04:16:19 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F06D8106564A; Sat, 8 Oct 2011 04:16:19 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D77A08FC17; Sat, 8 Oct 2011 04:16:19 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p984GJiC042021; Sat, 8 Oct 2011 04:16:19 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p984GJfN042015; Sat, 8 Oct 2011 04:16:19 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080416.p984GJfN042015@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 04:16:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226130 - in projects/diffused_head/sys: modules/diffuse modules/diffuse/diffuse_feature_iat netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 04:16:20 -0000 Author: lstewart Date: Sat Oct 8 04:16:19 2011 New Revision: 226130 URL: http://svn.freebsd.org/changeset/base/226130 Log: A DIFFUSE feature kernel module which calculates per-flow minimum, mean, maximum and standard deviation interarrival time statistics for use in classification decisions. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_iat/ projects/diffused_head/sys/modules/diffuse/diffuse_feature_iat/Makefile (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat_common.h (contents, props changed) Modified: projects/diffused_head/sys/modules/diffuse/Makefile Modified: projects/diffused_head/sys/modules/diffuse/Makefile ============================================================================== --- projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 04:09:23 2011 (r226129) +++ projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 04:16:19 2011 (r226130) @@ -1,5 +1,6 @@ # $FreeBSD$ -SUBDIR= diffuse +SUBDIR= diffuse \ + diffuse_feature_iat .include Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_iat/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/diffuse_feature_iat/Makefile Sat Oct 8 04:16:19 2011 (r226130) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../netinet/ipfw + +KMOD= diffuse_feature_iat +SRCS= diffuse_feature_iat.c + +.include Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.c Sat Oct 8 04:16:19 2011 (r226130) @@ -0,0 +1,468 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * DIFFUSE packet inter-arrival time feature. + */ + +#include +__FBSDID("$FreeBSD$"); + +#ifdef _KERNEL +#include +#include +#include +#include +#include +#endif /* _KERNEL */ +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#ifdef _KERNEL +#include +#include +#endif /* _KERNEL */ + +#ifndef _KERNEL +#include +#include +#include +#define KPI_USER_COMPAT +#include /* Must come after stdlib.h */ +#endif + +/* + * Feature inter-arrival time computes minimum, mean, maximum and std deviation + * of inter-arrival time (time between two consecutive packets). + */ + +/* If we are linked from userspace, only put the declaration here. */ +#ifdef _KERNEL +DI_IAT_STAT_NAMES; +#else +DI_IAT_STAT_NAMES_DECL; +#endif + +/* State for jump windows. */ +struct di_iat_jump_win_state { + uint32_t min; + uint32_t max; + uint64_t sum; + uint64_t sqsum; + int jump; + int first; +}; + +/* Per flow data (ring buffer). */ +struct di_iat_fdata { + int full; + int changed; + int index; + struct timeval last_abs_time; + /* + * We can only store intervals <= 4294 seconds and stats are signed so + * can only be <= 2147 seconds, but default flow timeouts are much + * smaller. + */ + uint32_t *iats; + struct di_iat_jump_win_state *jstate; +}; + +static int iat_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata); + +static int +iat_init_instance(struct di_cdata *cdata, struct di_oid *params) +{ + struct di_feature_iat_config *conf, *p; + + cdata->conf = malloc(sizeof(struct di_feature_iat_config), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (cdata->conf == NULL) + return (ENOMEM); + + conf = (struct di_feature_iat_config *)cdata->conf; + + /* Set default configuration. */ + conf->iat_window = DI_DEFAULT_IAT_WINDOW; + conf->iat_partial_window = 0; + conf->iat_ts_acc = DI_IAT_TS_ACC_NORMAL; + conf->iat_jump_window = 0; + conf->iat_prec = 1; + + /* Set configuration. */ + if (params != NULL) { + p = (struct di_feature_iat_config *)params; + + if (p->iat_window != -1) + conf->iat_window = p->iat_window; + + if (p->iat_partial_window != -1) + conf->iat_partial_window = p->iat_partial_window; + + if (p->iat_ts_acc != -1) + conf->iat_ts_acc = p->iat_ts_acc; + + if (p->iat_jump_window != -1) + conf->iat_jump_window = p->iat_jump_window; + + if (p->iat_prec != -1) + conf->iat_prec = p->iat_prec; + } + + return (0); +} + +static int +iat_destroy_instance(struct di_cdata *cdata) +{ + + free(cdata->conf, M_DIFFUSE); + + return (0); +} + +static int +iat_get_conf(struct di_cdata *cdata, struct di_oid *cbuf, int size_only) +{ + + if (!size_only) + memcpy(cbuf, cdata->conf, sizeof(struct di_feature_iat_config)); + + return (sizeof(struct di_feature_iat_config)); +} + +static int +iat_init_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_iat_config *conf; + struct di_iat_fdata *data; + + conf = (struct di_feature_iat_config *)cdata->conf; + + fdata->data = malloc(sizeof(struct di_iat_fdata), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (fdata->data == NULL) + return (ENOMEM); + + data = (struct di_iat_fdata *)fdata->data; + + if (!conf->iat_jump_window) + data->iats = malloc((conf->iat_window - 1) * sizeof(uint32_t), + M_DIFFUSE, M_NOWAIT | M_ZERO); + else + data->jstate = malloc(sizeof(struct di_iat_jump_win_state), + M_DIFFUSE, M_NOWAIT | M_ZERO); + + fdata->stats = malloc(DI_IAT_NO_STATS * sizeof(int32_t), M_DIFFUSE, + M_NOWAIT | M_ZERO); + + if (data->iats == NULL || data->jstate == NULL || + fdata->stats == NULL) { + free(fdata->stats, M_DIFFUSE); + free(data->jstate, M_DIFFUSE); + free(data->iats, M_DIFFUSE); + free(fdata->data, M_DIFFUSE); + + return (ENOMEM); + } + + iat_reset_stats(cdata, fdata); + + return (0); +} + +static int +iat_destroy_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_iat_config *conf; + struct di_iat_fdata *data; + + conf = (struct di_feature_iat_config *)cdata->conf; + data = (struct di_iat_fdata *)fdata->data; + + if (!conf->iat_jump_window) + free(data->iats, M_DIFFUSE); + else + free(data->jstate, M_DIFFUSE); + + free(fdata->data, M_DIFFUSE); + free(fdata->stats, M_DIFFUSE); + + return (0); +} + +static void +reset_jump_win_state(struct di_iat_jump_win_state *state) +{ + + state->min = 0x7FFFFFFF; + state->max = 0; + state->sum = 0; + state->sqsum = 0; + state->jump = 0; +} + +static int +iat_update_stats(struct di_cdata *cdata, struct di_fdata *fdata, + struct mbuf *mbuf, int proto, void *ulp, int dir) +{ + struct di_feature_iat_config *conf; + struct di_iat_fdata *data; + struct timeval t, tv_diff; + uint32_t diff; + + conf = (struct di_feature_iat_config *)cdata->conf; + data = (struct di_iat_fdata *)fdata->data; + t.tv_sec = t.tv_usec = 0; + +#if !defined(__linux__) && defined(_KERNEL) + /* Get from external source if possible (hardware), see bpf.c. */ + if (mbuf != NULL) { + struct m_tag *tag = m_tag_locate(mbuf, MTAG_BPF, + MTAG_BPF_TIMESTAMP, NULL); + if (tag != NULL) { + struct bintime bt = *(struct bintime *)(tag + 1); + bintime2timeval(&bt, &t); + } + } +#endif + + if (t.tv_sec == 0 && t.tv_usec == 0) { + if (conf->iat_ts_acc == DI_IAT_TS_ACC_ACCURATE) + getmicrouptime(&t); + else + microuptime(&t); + } + + if (data->last_abs_time.tv_sec > 0 || data->last_abs_time.tv_usec > 0) { + /* Get inter-arrival time. */ + tv_diff = tv_sub0(&t, &data->last_abs_time); + diff = (tv_diff.tv_sec * 1000000 + tv_diff.tv_usec) / + conf->iat_prec; /* XXX: round() */ + + if (!conf->iat_jump_window) { + data->iats[data->index++] = diff; + } else { + if (diff < data->jstate->min) + data->jstate->min = diff; + + if (diff > data->jstate->max) + data->jstate->max = diff; + + data->jstate->sum += diff; + data->jstate->sqsum += (uint64_t)diff * diff; + data->index++; + + if (data->index == (conf->iat_window - 1)) { + data->jstate->jump = 1; + if (data->jstate->first) + data->jstate->first = 0; + } + } + + if (!data->full && data->index == (conf->iat_window - 1)) + data->full = 1; + + data->changed = 1; + if (data->index == conf->iat_window - 1) + data->index = 0; + } + data->last_abs_time = t; + + return (0); +} + +static int +iat_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_iat_config *conf; + struct di_iat_fdata *data; + int i; + + conf = (struct di_feature_iat_config *)cdata->conf; + data = (struct di_iat_fdata *)fdata->data; + + fdata->stats[0] = 0x7FFFFFFF; + for (i = 1; i < DI_IAT_NO_STATS; i++) + fdata->stats[i] = 0; + + if (!conf->iat_jump_window) { + for (i = 0; i < (conf->iat_window - 1); i++) + data->iats[i] = 0; + } else { + reset_jump_win_state(data->jstate); + data->jstate->first = 1; + } + data->full = 0; + data->changed = 0; + data->index = 0; + + return (0); +} + +/* + * XXX: Potential overflow of square sum for jumping windows otherwise overflow + * only possible if flow timeouts would be set much higher than default. + */ +static int +iat_get_stats(struct di_cdata *cdata, struct di_fdata *fdata, int32_t **stats) +{ +#define DI_IAT_MIN fdata->stats[0] +#define DI_IAT_MEAN fdata->stats[1] +#define DI_IAT_MAX fdata->stats[2] +#define DI_IAT_STDEV fdata->stats[3] + struct di_feature_iat_config *conf; + struct di_iat_fdata *data; + uint64_t sqsum, sum; + int i, wsize; + + conf = (struct di_feature_iat_config *)cdata->conf; + data = (struct di_iat_fdata *)fdata->data; + + if (!data->full && !(conf->iat_partial_window && data->index > 1)) + return (0); /* Window is not full yet. */ + + /* Compute stats only if we need update. */ + if ((!conf->iat_jump_window && data->changed) || + (conf->iat_jump_window && (data->jstate->jump || + (conf->iat_partial_window && data->jstate->first)))) { + wsize = conf->iat_window - 1; + if (!data->full) + wsize = data->index; + + if (!conf->iat_jump_window) { + sum = 0; + sqsum = 0; + + DI_IAT_MIN = 0x7FFFFFFF; + DI_IAT_MAX = 0; + for (i = 0; i < wsize; i++) { + if (data->iats[i] < DI_IAT_MIN) + DI_IAT_MIN = data->iats[i]; + + if (data->iats[i] > DI_IAT_MAX) + DI_IAT_MAX = data->iats[i]; + + sum += data->iats[i]; + } + + DI_IAT_MEAN = sum / wsize; + if (wsize > 1) { + /* Need a second loop or sqsum may overflow. */ + for (i = 0; i < wsize; i++) { + sqsum += + ((int64_t)data->iats[i] - + DI_IAT_MEAN) * + ((int64_t)data->iats[i] - + DI_IAT_MEAN); + } + DI_IAT_STDEV = fixp_sqrt(sqsum / wsize); + } + } else { + DI_IAT_MIN = data->jstate->min; + DI_IAT_MAX = data->jstate->max; + DI_IAT_MEAN = data->jstate->sum / wsize; + if (wsize > 1) { + DI_IAT_STDEV = + fixp_sqrt((data->jstate->sqsum - + (data->jstate->sum * + data->jstate->sum / wsize)) / (wsize - 1)); + } + + reset_jump_win_state(data->jstate); + } + data->changed = 0; + } + *stats = fdata->stats; + + return (DI_IAT_NO_STATS); +} + +static int +iat_get_stat(struct di_cdata *cdata, struct di_fdata *fdata, int which, + int32_t *stat) +{ + int32_t *stats; + + if (which < 0 || which > DI_IAT_NO_STATS) + return (-1); + + if (!iat_get_stats(cdata, fdata, &stats)) + return (0); + + *stat = stats[which]; + + return (1); +} + +static int +iat_get_stat_names(char **names[]) +{ + + *names = di_iat_stat_names; + + return (DI_IAT_NO_STATS); +} + +static struct di_feature_alg di_iat_desc = { + _FI( .name = ) DI_IAT_NAME, + _FI( .type = ) DI_IAT_TYPE, + _FI( .ref_count = ) 0, + + _FI( .init_instance = ) iat_init_instance, + _FI( .destroy_instance = ) iat_destroy_instance, + _FI( .init_stats = ) iat_init_stats, + _FI( .destroy_stats = ) iat_destroy_stats, + _FI( .update_stats = ) iat_update_stats, + _FI( .reset_stats = ) iat_reset_stats, + _FI( .get_stats = ) iat_get_stats, + _FI( .get_stat = ) iat_get_stat, + _FI( .get_stat_names = ) iat_get_stat_names, + _FI( .get_conf = ) iat_get_conf, +}; + +DECLARE_DIFFUSE_FEATURE_MODULE(iat, &di_iat_desc); Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h Sat Oct 8 04:16:19 2011 (r226130) @@ -0,0 +1,59 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DIFFUSE packet inter-arrival time feature. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_FEATURE_IAT_H_ +#define _NETINET_IPFW_DIFFUSE_FEATURE_IAT_H_ + +#define DI_DEFAULT_IAT_WINDOW 15 + +/* Main properties, used in kernel and userspace. */ +#define DI_IAT_NAME "iat" +#define DI_IAT_TYPE DI_FEATURE_ALG_UNIDIRECTIONAL +#define DI_IAT_NO_STATS 4 +#define DI_IAT_STAT_NAMES_DECL char *di_iat_stat_names[DI_IAT_NO_STATS] +#define DI_IAT_STAT_NAMES DI_IAT_STAT_NAMES_DECL = \ +{ \ + "min", \ + "mean", \ + "max", \ + "stdev" \ +}; + +struct di_feature_module *iat_module(void); + +#endif /* _NETINET_IPFW_DIFFUSE_FEATURE_IAT_H_ */ Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat_common.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat_common.h Sat Oct 8 04:16:19 2011 (r226130) @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _NETINET_IPFW_DIFFUSE_FEATURE_IAT_COMMON_H_ +#define _NETINET_IPFW_DIFFUSE_FEATURE_IAT_COMMON_H_ + +#define DI_IAT_TS_ACC_NORMAL 0 +#define DI_IAT_TS_ACC_ACCURATE 1 + +struct di_feature_iat_config { + struct di_oid oid; + + /* Sliding/jumping window as number of packets. */ + int iat_window; + /* Compute stats for partial windows. */ + int iat_partial_window; + /* Accuracy of timestamp. */ + int iat_ts_acc; + /* If = 1 we have jumping windows. */ + int iat_jump_window; + /* Precision in us. */ + int iat_prec; +}; + +#endif /* _NETINET_IPFW_DIFFUSE_FEATURE_IAT_COMMON_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 04:26:56 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8169C106566B; Sat, 8 Oct 2011 04:26:56 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6EB3F8FC0A; Sat, 8 Oct 2011 04:26:56 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p984Qu2c042393; Sat, 8 Oct 2011 04:26:56 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p984Qu2l042388; Sat, 8 Oct 2011 04:26:56 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080426.p984Qu2l042388@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 04:26:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226131 - in projects/diffused_head/sys: modules/diffuse modules/diffuse/diffuse_feature_iatbd netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 04:26:56 -0000 Author: lstewart Date: Sat Oct 8 04:26:56 2011 New Revision: 226131 URL: http://svn.freebsd.org/changeset/base/226131 Log: A DIFFUSE feature kernel module which calculates per-flow, bidirectional minimum, mean, maximum and standard deviation interarrival time statistics for use in classification decisions. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_iatbd/ projects/diffused_head/sys/modules/diffuse/diffuse_feature_iatbd/Makefile (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.h (contents, props changed) Modified: projects/diffused_head/sys/modules/diffuse/Makefile Modified: projects/diffused_head/sys/modules/diffuse/Makefile ============================================================================== --- projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 04:16:19 2011 (r226130) +++ projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 04:26:56 2011 (r226131) @@ -1,6 +1,7 @@ # $FreeBSD$ SUBDIR= diffuse \ - diffuse_feature_iat + diffuse_feature_iat \ + diffuse_feature_iatbd .include Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_iatbd/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/diffuse_feature_iatbd/Makefile Sat Oct 8 04:26:56 2011 (r226131) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../netinet/ipfw + +KMOD= diffuse_feature_iatbd +SRCS= diffuse_feature_iatbd.c + +.include Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.c Sat Oct 8 04:26:56 2011 (r226131) @@ -0,0 +1,593 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#ifdef _KERNEL +#include +#include +#include +#include +#include +#endif /* _KERNEL */ +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#ifdef _KERNEL +#include +#include +#include +#endif /* _KERNEL */ + +#ifndef _KERNEL +#include +#include +#include +#define KPI_USER_COMPAT +#include /* Must come after stdlib.h */ +#endif + +/* + * Feature inter-arrival time bidirectional computes minimum, mean, maximum and + * std deviation of inter-arrival time (time between two consecutive packets) + * for both directions of traffic flow. + */ + +/* If we are linked from userspace only put the declaration here. */ +#ifdef _KERNEL +DI_IATBD_STAT_NAMES; +#else +DI_IATBD_STAT_NAMES_DECL; +#endif + +/* State for jump windows. */ +struct di_iatbd_jump_win_state { + uint32_t fmin; + uint32_t fmax; + uint64_t fsum; + uint64_t fsqsum; + uint32_t bmin; + uint32_t bmax; + uint64_t bsum; + uint64_t bsqsum; + uint16_t fcnt; + uint16_t bcnt; + int jump; + int first; +}; + +/* Per flow data (ring buffer). */ +struct di_iatbd_fdata { + int full; + int changed; + int index; + struct timeval flast_abs_time; + struct timeval blast_abs_time; + /* + * We can only store intervals <= 4294 seconds and stats are signed so + * can only be <= 2147 seconds, but default flow timeouts are much + * smaller. + */ + uint32_t *iats; + uint8_t *dirs; + struct di_iatbd_jump_win_state *jstate; +}; + +static int iatbd_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata); + +static int +iatbd_init_instance(struct di_cdata *cdata, struct di_oid *params) +{ + struct di_feature_iatbd_config *conf, *p; + + cdata->conf = malloc(sizeof(struct di_feature_iatbd_config), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (cdata->conf == NULL) + return (ENOMEM); + + conf = (struct di_feature_iatbd_config *)cdata->conf; + + /* Set default configuration. */ + conf->iat_window = DI_DEFAULT_IATBD_WINDOW; + conf->iat_partial_window = 0; + conf->iat_ts_acc = DI_IAT_TS_ACC_NORMAL; + conf->iat_jump_window = 0; + conf->iat_prec = 1; + + /* Set configuration. */ + if (params != NULL) { + p = (struct di_feature_iatbd_config *)params; + + if (p->iat_window != -1) + conf->iat_window = p->iat_window; + + if (p->iat_partial_window != -1) + conf->iat_partial_window = p->iat_partial_window; + + if (p->iat_ts_acc != -1) + conf->iat_ts_acc = p->iat_ts_acc; + + if (p->iat_jump_window != -1) + conf->iat_jump_window = p->iat_jump_window; + + if (p->iat_prec != -1) + conf->iat_prec = p->iat_prec; + } + + return (0); +} + +static int +iatbd_destroy_instance(struct di_cdata *cdata) +{ + + free(cdata->conf, M_DIFFUSE); + + return (0); +} + +static int +iatbd_get_conf(struct di_cdata *cdata, struct di_oid *cbuf, int size_only) +{ + + if (!size_only) + memcpy(cbuf, cdata->conf, sizeof(struct di_feature_iatbd_config)); + + return (sizeof(struct di_feature_iatbd_config)); +} + +static int +iatbd_init_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_iatbd_config *conf; + struct di_iatbd_fdata *data; + + conf = (struct di_feature_iatbd_config *)cdata->conf; + + fdata->data = malloc(sizeof(struct di_iatbd_fdata), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (fdata->data == NULL) + return (ENOMEM); + + data = (struct di_iatbd_fdata *)fdata->data; + + if (!conf->iat_jump_window) { + data->iats = malloc((conf->iat_window - 1) * sizeof(uint32_t), + M_DIFFUSE, M_NOWAIT | M_ZERO); + data->dirs = malloc((conf->iat_window - 1) * sizeof(uint8_t), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } else { + data->jstate = malloc(sizeof(struct di_iatbd_jump_win_state), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } + fdata->stats = malloc(DI_IATBD_NO_STATS * sizeof(int32_t), M_DIFFUSE, + M_NOWAIT | M_ZERO); + + if (data->iats == NULL || data->dirs == NULL || data->jstate == NULL || + fdata->stats == NULL) { + free(fdata->stats, M_DIFFUSE); + free(data->jstate, M_DIFFUSE); + free(data->dirs, M_DIFFUSE); + free(data->iats, M_DIFFUSE); + free(fdata->data, M_DIFFUSE); + + return (ENOMEM); + } + + iatbd_reset_stats(cdata, fdata); + + return (0); +} + +static int +iatbd_destroy_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_iatbd_config *conf; + struct di_iatbd_fdata *data; + + conf = (struct di_feature_iatbd_config *)cdata->conf; + data = (struct di_iatbd_fdata *)fdata->data; + + if (!conf->iat_jump_window) { + free(data->iats, M_DIFFUSE); + free(data->dirs, M_DIFFUSE); + } else { + free(data->jstate, M_DIFFUSE); + } + free(fdata->data, M_DIFFUSE); + free(fdata->stats, M_DIFFUSE); + + return (0); +} + +static void +reset_jump_win_state(struct di_iatbd_jump_win_state *state) +{ + + state->fmin = 0x7FFFFFFF; + state->fmax = 0; + state->fsum = 0; + state->fsqsum = 0; + state->bmin = 0x7FFFFFFF; + state->bmax = 0; + state->bsum = 0; + state->bsqsum = 0; + state->fcnt = 0; + state->bcnt = 0; + state->jump = 0; +} + +static int +iatbd_update_stats(struct di_cdata *cdata, struct di_fdata *fdata, + struct mbuf *mbuf, int proto, void *ulp, int dir) +{ + struct di_iatbd_fdata *data; + struct di_feature_iatbd_config *conf; + struct timeval t, tv_diff; + uint32_t diff; + + conf = (struct di_feature_iatbd_config *)cdata->conf; + data = (struct di_iatbd_fdata *)fdata->data; + t.tv_sec = t.tv_usec = 0; + +#if !defined(__linux__) && defined(_KERNEL) + /* Get from external source if possible (hardware), see bpf.c. */ + if (mbuf != NULL) { + struct m_tag *tag = m_tag_locate(mbuf, MTAG_BPF, + MTAG_BPF_TIMESTAMP, NULL); + if (tag != NULL) { + struct bintime bt = *(struct bintime *)(tag + 1); + bintime2timeval(&bt, &t); + } + } +#endif + + if (t.tv_sec == 0 && t.tv_usec == 0) { + if (conf->iat_ts_acc == DI_IAT_TS_ACC_ACCURATE) + getmicrouptime(&t); + else + microuptime(&t); + } + + if ((dir == MATCH_FORWARD && + (data->flast_abs_time.tv_sec > 0 || + data->flast_abs_time.tv_usec > 0)) || + (dir == MATCH_REVERSE && + (data->blast_abs_time.tv_sec > 0 || + data->blast_abs_time.tv_usec > 0))) { + /* Get inter-arrival time. */ + if (dir == MATCH_FORWARD) + tv_diff = tv_sub0(&t, &data->flast_abs_time); + else + tv_diff = tv_sub0(&t, &data->blast_abs_time); + + diff = (tv_diff.tv_sec * 1000000 + tv_diff.tv_usec) / + conf->iat_prec; /* XXX: round() */ + + if (!conf->iat_jump_window) { + data->iats[data->index] = diff; + data->dirs[data->index++] = dir; + } else { + if (dir == MATCH_FORWARD) { + if (diff < data->jstate->fmin) + data->jstate->fmin = diff; + + if (diff > data->jstate->fmax) + data->jstate->fmax = diff; + + data->jstate->fsum += diff; + data->jstate->fsqsum += (uint64_t)diff * diff; + data->jstate->fcnt++; + } else { + if (diff < data->jstate->bmin) + data->jstate->bmin = diff; + + if (diff > data->jstate->bmax) + data->jstate->bmax = diff; + + data->jstate->bsum += diff; + data->jstate->bsqsum += (uint64_t)diff * diff; + data->jstate->bcnt++; + } + data->index++; + + if (data->index == (conf->iat_window - 1)) { + data->jstate->jump = 1; + if (data->jstate->first) + data->jstate->first = 0; + } + } + + if (!data->full && data->index == (conf->iat_window - 1)) + data->full = 1; + + data->changed = 1; + if (data->index == conf->iat_window - 1) + data->index = 0; + } + if (dir == MATCH_FORWARD) + data->flast_abs_time = t; + else + data->blast_abs_time = t; + + return (0); +} + +static int +iatbd_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_iatbd_config *conf; + struct di_iatbd_fdata *data; + int i; + + conf = (struct di_feature_iatbd_config *)cdata->conf; + data = (struct di_iatbd_fdata *)fdata->data; + + fdata->stats[0] = 0x7FFFFFFF; + fdata->stats[1] = 0; + fdata->stats[2] = 0; + fdata->stats[3] = 0; + fdata->stats[4] = 0x7FFFFFFF; + fdata->stats[5] = 0; + fdata->stats[6] = 0; + fdata->stats[7] = 0; + if (!conf->iat_jump_window) { + for (i = 0; i < (conf->iat_window - 1); i++) + data->iats[i] = 0; + } else { + reset_jump_win_state(data->jstate); + data->jstate->first = 1; + } + data->full = 0; + data->changed = 0; + data->index = 0; + + return (0); +} + +/* + * XXX: potential overflow of square sum for jumping windows otherwise overflow + * only possible if flow timeouts would be set much higher than default. + */ +static int +iatbd_get_stats(struct di_cdata *cdata, struct di_fdata *fdata, int32_t **stats) +{ +#define DI_IAT_FMIN fdata->stats[0] +#define DI_IAT_FMEAN fdata->stats[1] +#define DI_IAT_FMAX fdata->stats[2] +#define DI_IAT_FSTDEV fdata->stats[3] +#define DI_IAT_BMIN fdata->stats[4] +#define DI_IAT_BMEAN fdata->stats[5] +#define DI_IAT_BMAX fdata->stats[6] +#define DI_IAT_BSTDEV fdata->stats[7] + struct di_feature_iatbd_config *conf; + struct di_iatbd_fdata *data; + uint64_t bsum, fsum, sqsum; + uint16_t bcnt, fcnt; + int i, wsize; + + conf = (struct di_feature_iatbd_config *)cdata->conf; + data = (struct di_iatbd_fdata *)fdata->data; + + if (!data->full && !(conf->iat_partial_window && data->index > 1)) + return (0); /* Window is not full yet. */ + + /* Compute stats only if we need update. */ + if ((!conf->iat_jump_window && data->changed) || + (conf->iat_jump_window && (data->jstate->jump || + (conf->iat_partial_window && data->jstate->first)))) { + wsize = conf->iat_window - 1; + if (!data->full) + wsize = data->index; + + if (!conf->iat_jump_window) { + bsum = fsum = 0; + bcnt = fcnt = 0; + + DI_IAT_FMIN = 0x7FFFFFFF; + DI_IAT_FMAX = 0; + DI_IAT_BMIN = 0x7FFFFFFF; + DI_IAT_BMAX = 0; + + for (i = 0; i < wsize; i++) { + if (data->dirs[i] == MATCH_FORWARD) { + if (data->iats[i] < DI_IAT_FMIN) + DI_IAT_FMIN = data->iats[i]; + + if (data->iats[i] > DI_IAT_FMAX) + DI_IAT_FMAX = data->iats[i]; + + fsum += data->iats[i]; + fcnt++; + } else { + if (data->iats[i] < DI_IAT_BMIN) + DI_IAT_BMIN = data->iats[i]; + + if (data->iats[i] > DI_IAT_BMAX) + DI_IAT_BMAX = data->iats[i]; + + bsum += data->iats[i]; + bcnt++; + } + } + + if (fcnt > 0) { + DI_IAT_FMEAN = fsum / fcnt; + } else { + DI_IAT_FMIN = 0; + DI_IAT_FMEAN = 0; + } + if (bcnt > 0) { + DI_IAT_BMEAN = bsum / bcnt; + } else { + DI_IAT_BMIN = 0; + DI_IAT_BMEAN = 0; + } + + if (fcnt > 1) { + sqsum = 0; + /* Need a second loop or sqsum may overflow. */ + for (i = 0; i < fcnt; i++) { + if (data->dirs[i] == MATCH_FORWARD) { + sqsum += + ((int64_t)data->iats[i] - + DI_IAT_FMEAN) * + ((int64_t)data->iats[i] - + DI_IAT_FMEAN); + } + } + DI_IAT_FSTDEV = fixp_sqrt(sqsum / fcnt); + } else { + DI_IAT_FSTDEV = 0; + } + if (bcnt > 1) { + sqsum = 0; + /* Need a second loop or sqsum may overflow. */ + for (i = 0; i < bcnt; i++) { + if (data->dirs[i] == MATCH_REVERSE) { + sqsum += + ((int64_t)data->iats[i] - + DI_IAT_BMEAN) * + ((int64_t)data->iats[i] - + DI_IAT_BMEAN); + } + } + DI_IAT_BSTDEV = fixp_sqrt(sqsum / bcnt); + } else { + DI_IAT_BSTDEV = 0; + } + + } else { + DI_IAT_FMIN = data->jstate->fmin; + DI_IAT_FMAX = data->jstate->fmax; + DI_IAT_BMIN = data->jstate->bmin; + DI_IAT_BMAX = data->jstate->bmax; + + if (data->jstate->fcnt > 0) + DI_IAT_FMEAN = data->jstate->fsum / + data->jstate->fcnt; + else + DI_IAT_FMIN = 0; + + if (data->jstate->fcnt > 1) { + DI_IAT_FSTDEV = fixp_sqrt( + (data->jstate->fsqsum - + (data->jstate->fsum * + data->jstate->fsum / + data->jstate->fcnt)) / + (data->jstate->fcnt - 1)); + } + if (data->jstate->bcnt > 0) + DI_IAT_BMEAN = data->jstate->bsum / + data->jstate->bcnt; + else + DI_IAT_BMIN = 0; + + if (data->jstate->bcnt > 1) { + DI_IAT_BSTDEV = fixp_sqrt( + (data->jstate->bsqsum - + (data->jstate->bsum * + data->jstate->bsum / + data->jstate->bcnt)) / + (data->jstate->bcnt - 1)); + } + + if (data->jstate->jump) + reset_jump_win_state(data->jstate); + } + data->changed = 0; + } + *stats = fdata->stats; + + return (DI_IATBD_NO_STATS); +} + +static int +iatbd_get_stat(struct di_cdata *cdata, struct di_fdata *fdata, int which, + int32_t *stat) +{ + int32_t *stats; + + if (which < 0 || which > DI_IATBD_NO_STATS) + return (-1); + + if (!iatbd_get_stats(cdata, fdata, &stats)) + return (0); + + *stat = stats[which]; + + return (1); +} + +static int +iatbd_get_stat_names(char **names[]) +{ + + *names = di_iatbd_stat_names; + + return (DI_IATBD_NO_STATS); +} + +static struct di_feature_alg di_iatbd_desc = { + _FI( .name = ) DI_IATBD_NAME, + _FI( .type = ) DI_IATBD_TYPE, + _FI( .ref_count = ) 0, + + _FI( .init_instance = ) iatbd_init_instance, + _FI( .destroy_instance = ) iatbd_destroy_instance, + _FI( .init_stats = ) iatbd_init_stats, + _FI( .destroy_stats = ) iatbd_destroy_stats, + _FI( .update_stats = ) iatbd_update_stats, + _FI( .reset_stats = ) iatbd_reset_stats, + _FI( .get_stats = ) iatbd_get_stats, + _FI( .get_stat = ) iatbd_get_stat, + _FI( .get_stat_names = ) iatbd_get_stat_names, + _FI( .get_conf = ) iatbd_get_conf, +}; + +DECLARE_DIFFUSE_FEATURE_MODULE(iatbd, &di_iatbd_desc); Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.h Sat Oct 8 04:26:56 2011 (r226131) @@ -0,0 +1,65 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DIFFUSE bidirectional packet inter-arrival time feature. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_FEATURE_IATBD_H_ +#define _NETINET_IPFW_DIFFUSE_FEATURE_IATBD_H_ + +#define DI_DEFAULT_IATBD_WINDOW 25 + +#define di_feature_iatbd_config di_feature_iat_config + +/* Main properties, used in kernel and userspace. */ +#define DI_IATBD_NAME "iatbd" +#define DI_IATBD_TYPE DI_FEATURE_ALG_BIDIRECTIONAL +#define DI_IATBD_NO_STATS 8 +#define DI_IATBD_STAT_NAMES_DECL char *di_iatbd_stat_names[DI_IATBD_NO_STATS] +#define DI_IATBD_STAT_NAMES DI_IATBD_STAT_NAMES_DECL = \ +{ \ + "fmin", \ + "fmean", \ + "fmax", \ + "fstdev", \ + "bmin", \ + "bmean", \ + "bmax", \ + "bstdev" \ +}; + +struct di_feature_module *iatbd_module(void); + +#endif /* _NETINET_IPFW_DIFFUSE_FEATURE_IATBD_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 04:36:16 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E04F4106566C; Sat, 8 Oct 2011 04:36:16 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CDAEF8FC12; Sat, 8 Oct 2011 04:36:16 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p984aGx7042694; Sat, 8 Oct 2011 04:36:16 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p984aGqw042689; Sat, 8 Oct 2011 04:36:16 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080436.p984aGqw042689@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 04:36:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226132 - in projects/diffused_head/sys: modules/diffuse modules/diffuse/diffuse_feature_pcnt netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 04:36:17 -0000 Author: lstewart Date: Sat Oct 8 04:36:16 2011 New Revision: 226132 URL: http://svn.freebsd.org/changeset/base/226132 Log: A DIFFUSE feature kernel module which calculates per-flow forward/reverse packet count and ratio statistics for use in classification decisions. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_pcnt/ projects/diffused_head/sys/modules/diffuse/diffuse_feature_pcnt/Makefile (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_pcnt.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_pcnt.h (contents, props changed) Modified: projects/diffused_head/sys/modules/diffuse/Makefile Modified: projects/diffused_head/sys/modules/diffuse/Makefile ============================================================================== --- projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 04:26:56 2011 (r226131) +++ projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 04:36:16 2011 (r226132) @@ -2,6 +2,7 @@ SUBDIR= diffuse \ diffuse_feature_iat \ - diffuse_feature_iatbd + diffuse_feature_iatbd \ + diffuse_feature_pcnt .include Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_pcnt/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/diffuse_feature_pcnt/Makefile Sat Oct 8 04:36:16 2011 (r226132) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../netinet/ipfw + +KMOD= diffuse_feature_pcnt +SRCS= diffuse_feature_pcnt.c + +.include Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_pcnt.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_pcnt.c Sat Oct 8 04:36:16 2011 (r226132) @@ -0,0 +1,383 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * DIFFUSE packet count feature. + */ + +#include +__FBSDID("$FreeBSD$"); + +#ifdef _KERNEL +#include +#include +#include +#include +#include +#endif +#include + +#include + +#include +#include +#include +#include + +#include +#include +#include +#ifdef _KERNEL +#include +#include +#include +#endif /* _KERNEL */ + +#ifndef _KERNEL +#include +#include +#include +#define KPI_USER_COMPAT +#include /* Must come after stdlib.h */ +#endif + +/* + * Feature packet count computes number of forward packets, backward packets and + * ratio. + */ + +/* If we are linked from userspace only put the declaration here. */ +#ifdef _KERNEL +DI_PCNT_STAT_NAMES; +#else +DI_PCNT_STAT_NAMES_DECL; +#endif + +/* State for jump windows. */ +struct di_pcnt_jump_win_state { + uint16_t fpkts; + uint16_t bpkts; + int jump; + int first; +}; + +/* Per flow data (ring buffer). */ +struct di_pcnt_fdata { + int full; + int changed; + int index; + uint8_t *pdirs; + struct di_pcnt_jump_win_state *jstate; +}; + +static int pcnt_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata); + +static int +pcnt_init_instance(struct di_cdata *cdata, struct di_oid *params) +{ + struct di_feature_pcnt_config *conf, *p; + + cdata->conf = malloc(sizeof(struct di_feature_pcnt_config), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (cdata->conf == NULL) + return (ENOMEM); + + conf = (struct di_feature_pcnt_config *)cdata->conf; + + /* Set default configuration. */ + conf->pcnt_window = DI_DEFAULT_PCNT_WINDOW; + conf->pcnt_partial_window = 0; + conf->pcnt_jump_window = 0; + + /* Set configuration */ + if (params != NULL) { + p = (struct di_feature_pcnt_config *)params; + + if (p->pcnt_window != -1) + conf->pcnt_window = p->pcnt_window; + + if (p->pcnt_partial_window != -1) + conf->pcnt_partial_window = p->pcnt_partial_window; + + if (p->pcnt_jump_window != -1) + conf->pcnt_jump_window = p->pcnt_jump_window; + } + + return (0); +} + +static int +pcnt_destroy_instance(struct di_cdata *cdata) +{ + + free(cdata->conf, M_DIFFUSE); + + return (0); +} + +static int +pcnt_get_conf(struct di_cdata *cdata, struct di_oid *cbuf, int size_only) +{ + + if (!size_only) + memcpy(cbuf, cdata->conf, + sizeof(struct di_feature_pcnt_config)); + + return (sizeof(struct di_feature_pcnt_config)); +} + +static int +pcnt_init_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_pcnt_config *conf; + struct di_pcnt_fdata *data; + + conf = (struct di_feature_pcnt_config *)cdata->conf; + + fdata->data = malloc(sizeof(struct di_pcnt_fdata), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (fdata->data == NULL) + return (ENOMEM); + + data = (struct di_pcnt_fdata *)fdata->data; + + if (!conf->pcnt_jump_window) { + data->pdirs = malloc(conf->pcnt_window * sizeof(uint8_t), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } else { + data->jstate = malloc(sizeof(struct di_pcnt_jump_win_state), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } + fdata->stats = malloc(DI_PCNT_NO_STATS * sizeof(int32_t), M_DIFFUSE, + M_NOWAIT | M_ZERO); + + if (data->pdirs == NULL || data->jstate == NULL || + fdata->stats == NULL) { + free(fdata->stats, M_DIFFUSE); + free(data->jstate, M_DIFFUSE); + free(data->pdirs, M_DIFFUSE); + free(fdata->data, M_DIFFUSE); + + return (ENOMEM); + } + + pcnt_reset_stats(cdata, fdata); + + return (0); +} + +static int +pcnt_destroy_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_pcnt_config *conf; + struct di_pcnt_fdata *data; + + conf = (struct di_feature_pcnt_config *)cdata->conf; + data = (struct di_pcnt_fdata *)fdata->data; + + if (!conf->pcnt_jump_window) + free(data->pdirs, M_DIFFUSE); + else + free(data->jstate, M_DIFFUSE); + + free(fdata->data, M_DIFFUSE); + free(fdata->stats, M_DIFFUSE); + + return (0); +} + +static void +reset_jump_win_state(struct di_pcnt_jump_win_state *state) +{ + + state->fpkts = 0; + state->bpkts = 0; + state->jump = 0; +} + +static int +pcnt_update_stats(struct di_cdata *cdata, struct di_fdata *fdata, + struct mbuf *mbuf, int proto, void *ulp, int dir) +{ + struct di_feature_pcnt_config *conf; + struct di_pcnt_fdata *data; + + conf = (struct di_feature_pcnt_config *)cdata->conf; + data = (struct di_pcnt_fdata *)fdata->data; + + if (!conf->pcnt_jump_window) { + data->pdirs[data->index++] = dir; + } else { + if (dir == MATCH_FORWARD) + data->jstate->fpkts++; + else + data->jstate->bpkts++; + + data->index++; + + if (data->index == conf->pcnt_window) { + data->jstate->jump = 1; + if (data->jstate->first) + data->jstate->first = 0; + } + } + + if (!data->full && data->index == conf->pcnt_window) + data->full = 1; + + data->changed = 1; + if (data->index == conf->pcnt_window) + data->index = 0; + + return (0); +} + +static int +pcnt_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_pcnt_config *conf; + struct di_pcnt_fdata *data; + int i; + + conf = (struct di_feature_pcnt_config *)cdata->conf; + data = (struct di_pcnt_fdata *)fdata->data; + + for (i = 0; i < DI_PCNT_NO_STATS; i++) + fdata->stats[i] = 0; + + if (!conf->pcnt_jump_window) { + for (i = 0; i < conf->pcnt_window; i++) + data->pdirs[i] = 0; + } else { + reset_jump_win_state(data->jstate); + data->jstate->first = 1; + } + data->full = 0; + data->changed = 0; + data->index = 0; + + return (0); +} + +static int +pcnt_get_stats(struct di_cdata *cdata, struct di_fdata *fdata, int32_t **stats) +{ +#define DI_PCNT_FPKTS fdata->stats[0] +#define DI_PCNT_BPKTS fdata->stats[1] +#define DI_PCNT_RATIO fdata->stats[2] + struct di_feature_pcnt_config *conf; + struct di_pcnt_fdata *data; + int i, wsize; + + conf = (struct di_feature_pcnt_config *)cdata->conf; + data = (struct di_pcnt_fdata *)fdata->data; + + if (!data->full && !(conf->pcnt_partial_window && data->index > 0)) + return (0); /* Window is not full yet. */ + + /* Compute stats only if we need update. */ + if ((!conf->pcnt_jump_window && data->changed) || + (conf->pcnt_jump_window && (data->jstate->jump || + (conf->pcnt_partial_window && data->jstate->first)))) { + wsize = conf->pcnt_window; + if (!data->full) + wsize = data->index; + + if (!conf->pcnt_jump_window) { + DI_PCNT_FPKTS = 0; + DI_PCNT_BPKTS = 0; + for(i = 0; i < wsize; i++) { + if (data->pdirs[i] == MATCH_FORWARD) + DI_PCNT_FPKTS++; + else + DI_PCNT_BPKTS++; + } + } else { + DI_PCNT_FPKTS = data->jstate->fpkts; + DI_PCNT_BPKTS = data->jstate->bpkts; + reset_jump_win_state(data->jstate); + } + DI_PCNT_RATIO = 0; + if (DI_PCNT_BPKTS > 0) + DI_PCNT_RATIO = (DI_PCNT_FPKTS * 1000) / DI_PCNT_BPKTS; + + data->changed = 0; + } + *stats = fdata->stats; + + return (DI_PCNT_NO_STATS); +} + +static int +pcnt_get_stat(struct di_cdata *cdata, struct di_fdata *fdata, int which, + int32_t *stat) +{ + int32_t *stats; + + if (which < 0 || which > DI_PCNT_NO_STATS) + return (-1); + + if (!pcnt_get_stats(cdata, fdata, &stats)) + return (0); + + *stat = stats[which]; + + return (1); +} + +static int +pcnt_get_stat_names(char **names[]) +{ + + *names = di_pcnt_stat_names; + + return (DI_PCNT_NO_STATS); +} + +static struct di_feature_alg di_pcnt_desc = { + _FI( .name = ) DI_PCNT_NAME, + _FI( .type = ) DI_PCNT_TYPE, + _FI( .ref_count = ) 0, + + _FI( .init_instance = ) pcnt_init_instance, + _FI( .destroy_instance = ) pcnt_destroy_instance, + _FI( .init_stats = ) pcnt_init_stats, + _FI( .destroy_stats = ) pcnt_destroy_stats, + _FI( .update_stats = ) pcnt_update_stats, + _FI( .reset_stats = ) pcnt_reset_stats, + _FI( .get_stats = ) pcnt_get_stats, + _FI( .get_stat = ) pcnt_get_stat, + _FI( .get_stat_names = ) pcnt_get_stat_names, + _FI( .get_conf = ) pcnt_get_conf, +}; + +DECLARE_DIFFUSE_FEATURE_MODULE(pcnt, &di_pcnt_desc); Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_pcnt.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_pcnt.h Sat Oct 8 04:36:16 2011 (r226132) @@ -0,0 +1,69 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DIFFUSE packet count feature. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_FEATURE_PCNT_H_ +#define _NETINET_IPFW_DIFFUSE_FEATURE_PCNT_H_ + +#define DI_DEFAULT_PCNT_WINDOW 15 + +struct di_feature_pcnt_config { + struct di_oid oid; + + /* Sliding/jumping window as number of packets. */ + int pcnt_window; + /* Compute stats for partial windows. */ + int pcnt_partial_window; + /* If =1 we have jumping windows. */ + int pcnt_jump_window; +}; + +/* Main properties, used in kernel and userspace. */ +#define DI_PCNT_NAME "pcnt" +#define DI_PCNT_TYPE DI_FEATURE_ALG_BIDIRECTIONAL +#define DI_PCNT_NO_STATS 3 +#define DI_PCNT_STAT_NAMES_DECL char *di_pcnt_stat_names[DI_PCNT_NO_STATS] +#define DI_PCNT_STAT_NAMES DI_PCNT_STAT_NAMES_DECL = \ +{ \ + "fpckts", \ + "bpckts", \ + "ratio" /* fpckts / bpckts * 1000 */ \ +}; + +struct di_feature_module * pcnt_module(void); + +#endif /* _NETINET_IPFW_DIFFUSE_FEATURE_PCNT_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 04:49:28 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 10AA5106566C; Sat, 8 Oct 2011 04:49:28 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F20F78FC12; Sat, 8 Oct 2011 04:49:27 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p984nRvl043101; Sat, 8 Oct 2011 04:49:27 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p984nRNe043095; Sat, 8 Oct 2011 04:49:27 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080449.p984nRNe043095@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 04:49:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226133 - in projects/diffused_head/sys: modules/diffuse modules/diffuse/diffuse_feature_plen netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 04:49:28 -0000 Author: lstewart Date: Sat Oct 8 04:49:27 2011 New Revision: 226133 URL: http://svn.freebsd.org/changeset/base/226133 Log: A DIFFUSE feature kernel module which calculates per-flow minimum, mean, maximum, standard deviation and sum packet length statistics for use in classification decisions. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_plen/ projects/diffused_head/sys/modules/diffuse/diffuse_feature_plen/Makefile (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plen.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plen.h (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plen_common.h (contents, props changed) Modified: projects/diffused_head/sys/modules/diffuse/Makefile Modified: projects/diffused_head/sys/modules/diffuse/Makefile ============================================================================== --- projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 04:36:16 2011 (r226132) +++ projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 04:49:27 2011 (r226133) @@ -3,6 +3,7 @@ SUBDIR= diffuse \ diffuse_feature_iat \ diffuse_feature_iatbd \ - diffuse_feature_pcnt + diffuse_feature_pcnt \ + diffuse_feature_plen .include Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_plen/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/diffuse_feature_plen/Makefile Sat Oct 8 04:49:27 2011 (r226133) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../netinet/ipfw + +KMOD= diffuse_feature_plen +SRCS= diffuse_feature_plen.c + +.include Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plen.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plen.c Sat Oct 8 04:49:27 2011 (r226133) @@ -0,0 +1,447 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * DIFFUSE packet length feature. + */ + +#include +__FBSDID("$FreeBSD$"); + +#ifdef _KERNEL +#include +#include +#include +#include +#include +#endif /* _KERNEL */ +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#ifdef _KERNEL +#include +#include +#endif /* _KERNEL */ + +#ifndef _KERNEL +#include +#include +#include +#define KPI_USER_COMPAT +#include /* Must come after stdlib.h */ +#endif + +/* + * Feature packet length computes minimum, mean, maximum and std deviation of + * packet length (length = length of IP data or length of UDP/TCP data). + */ + +/* If we are linked from userspace only put the declaration here. */ +#ifdef _KERNEL +DI_PLEN_STAT_NAMES; +#else +DI_PLEN_STAT_NAMES_DECL; +#endif + +/* State for jump windows. */ +struct di_plen_jump_win_state { + uint16_t min; + uint16_t max; + uint32_t sum; + uint64_t sqsum; + int jump; + int first; +}; + +/* Per flow data (ring buffer). */ +struct di_plen_fdata { + int full; + int changed; + int index; + uint16_t *plens; + struct di_plen_jump_win_state *jstate; +}; + +static int plen_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata); + +static int +plen_init_instance(struct di_cdata *cdata, struct di_oid *params) +{ + struct di_feature_plen_config *conf, *p; + + cdata->conf = malloc(sizeof(struct di_feature_plen_config), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (cdata->conf == NULL) + return (ENOMEM); + + conf = (struct di_feature_plen_config *)cdata->conf; + + /* Set default configuration. */ + conf->plen_window = DI_DEFAULT_PLEN_WINDOW; + conf->plen_partial_window = 0; + conf->plen_len_type = DI_PLEN_LEN_FULL; + conf->plen_jump_window = 0; + + /* Set configuration. */ + if (params != NULL) { + p = (struct di_feature_plen_config *)params; + + if (p->plen_window != -1) + conf->plen_window = p->plen_window; + + if (p->plen_partial_window != -1) + conf->plen_partial_window = p->plen_partial_window; + + if (p->plen_len_type != -1) + conf->plen_len_type = p->plen_len_type; + + if (p->plen_jump_window != -1) + conf->plen_jump_window = p->plen_jump_window; + } + + return (0); +} + +static int +plen_destroy_instance(struct di_cdata *cdata) +{ + + free(cdata->conf, M_DIFFUSE); + + return (0); +} + +static int +plen_get_conf(struct di_cdata *cdata, struct di_oid *cbuf, int size_only) +{ + + if (!size_only) + memcpy(cbuf, cdata->conf, + sizeof(struct di_feature_plen_config)); + + return (sizeof(struct di_feature_plen_config)); +} + +static int +plen_init_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_plen_config *conf; + struct di_plen_fdata *data; + + conf = (struct di_feature_plen_config *)cdata->conf; + + fdata->data = malloc(sizeof(struct di_plen_fdata), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (fdata->data == NULL) + return (ENOMEM); + + data = (struct di_plen_fdata *)fdata->data; + + if (!conf->plen_jump_window) { + data->plens = malloc(conf->plen_window * sizeof(uint16_t), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } else { + data->jstate = malloc(sizeof(struct di_plen_jump_win_state), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } + fdata->stats = malloc(DI_PLEN_NO_STATS * sizeof(int32_t), M_DIFFUSE, + M_NOWAIT | M_ZERO); + + if (data->plens == NULL || data->jstate == NULL || + fdata->stats == NULL) { + free(fdata->stats, M_DIFFUSE); + free(data->jstate, M_DIFFUSE); + free(data->plens, M_DIFFUSE); + free(fdata->data, M_DIFFUSE); + + return (ENOMEM); + } + + plen_reset_stats(cdata, fdata); + + return (0); +} + +static int +plen_destroy_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_plen_fdata *data; + struct di_feature_plen_config *conf; + + conf = (struct di_feature_plen_config *)cdata->conf; + data = (struct di_plen_fdata *)fdata->data; + + if (!conf->plen_jump_window) + free(data->plens, M_DIFFUSE); + else + free(data->jstate, M_DIFFUSE); + + free(fdata->data, M_DIFFUSE); + free(fdata->stats, M_DIFFUSE); + + return (0); +} + +static void +reset_jump_win_state(struct di_plen_jump_win_state *state) +{ + + state->min = 0xFFFF; + state->max = 0; + state->sum = 0; + state->sqsum = 0; + state->jump = 0; +} + +static int +plen_update_stats(struct di_cdata *cdata, struct di_fdata *fdata, + struct mbuf *mbuf, int proto, void *ulp, int dir) +{ + struct di_feature_plen_config *conf; + struct di_plen_fdata *data; + struct ip *ip; + struct ip6_hdr *ip6; + struct tcphdr *tcp; + uint16_t plen; + int iplen; + + conf = (struct di_feature_plen_config *)cdata->conf; + data = (struct di_plen_fdata *)fdata->data; + ip = mtod(mbuf, struct ip *); + plen = 0; + + /* Length of data in IP. */ + if (conf->plen_len_type == DI_PLEN_LEN_FULL) { + plen = m_length(mbuf, NULL); + } else { + iplen = 0; + if (ip->ip_v == 6) { + ip6 = (struct ip6_hdr *)ip; + iplen = ntohs(ip6->ip6_plen); + } else { + iplen = ntohs(ip->ip_len) - ip->ip_hl * 4; + } + if (conf->plen_len_type == DI_PLEN_LEN_IPDATA) { + plen = iplen; + } else { + /* Length of data in UDP or TCP. */ + if (proto != 0 && ulp != NULL) { + if (proto == IPPROTO_TCP) { + tcp = (struct tcphdr *)ulp; + plen = iplen - tcp->th_off * 4; + } else if (proto == IPPROTO_UDP) { + plen = iplen - sizeof(struct udphdr); + } + } + } + } + + if (!conf->plen_jump_window) { + data->plens[data->index++] = plen; + } else { + if (plen < data->jstate->min) + data->jstate->min = plen; + + if (plen > data->jstate->max) + data->jstate->max = plen; + + data->jstate->sum += plen; + data->jstate->sqsum += (uint64_t)plen * plen; + data->index++; + + if (data->index == conf->plen_window) { + data->jstate->jump = 1; + if (data->jstate->first) + data->jstate->first = 0; + } + } + + if (!data->full && data->index == conf->plen_window) + data->full = 1; + + data->changed = 1; + if (data->index == conf->plen_window) + data->index = 0; + + return (0); +} + +static int +plen_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_plen_config *conf; + struct di_plen_fdata *data; + int i; + + conf = (struct di_feature_plen_config *)cdata->conf; + data = (struct di_plen_fdata *)fdata->data; + + fdata->stats[0] = 0x7FFFFFFF; + for (i = 1; i < DI_PLEN_NO_STATS; i++) + fdata->stats[i] = 0; + + if (!conf->plen_jump_window) { + for (i = 0; i < conf->plen_window; i++) + data->plens[i] = 0; + } else { + reset_jump_win_state(data->jstate); + data->jstate->first = 1; + } + data->full = 0; + data->changed = 0; + data->index = 0; + + return (0); +} + +static int +plen_get_stats(struct di_cdata *cdata, struct di_fdata *fdata, int32_t **stats) +{ +#define DI_PLEN_MIN fdata->stats[0] +#define DI_PLEN_MEAN fdata->stats[1] +#define DI_PLEN_MAX fdata->stats[2] +#define DI_PLEN_STDEV fdata->stats[3] +#define DI_PLEN_SUM fdata->stats[4] + struct di_feature_plen_config *conf; + struct di_plen_fdata *data; + uint64_t sqsum = 0; + uint32_t sum = 0; + int i, wsize; + + conf = (struct di_feature_plen_config *)cdata->conf; + data = (struct di_plen_fdata *)fdata->data; + sqsum = 0; + sum = 0; + + if (!data->full && !(conf->plen_partial_window && data->index > 0)) + return (0); /* Window is not full yet. */ + + /* Compute stats only if we need update. */ + if ((!conf->plen_jump_window && data->changed) || + (conf->plen_jump_window && (data->jstate->jump || + (conf->plen_partial_window && data->jstate->first)))) { + wsize = conf->plen_window; + if (!data->full) + wsize = data->index; + + if (!conf->plen_jump_window) { + DI_PLEN_MIN = 0x7FFFFFFF; + DI_PLEN_MAX = 0; + for (i = 0; i < wsize; i++) { + if (data->plens[i] < DI_PLEN_MIN) + DI_PLEN_MIN = data->plens[i]; + + if (data->plens[i] > DI_PLEN_MAX) + DI_PLEN_MAX = data->plens[i]; + + sum += data->plens[i]; + sqsum += (uint64_t)data->plens[i] * + data->plens[i]; + } + } else { + DI_PLEN_MIN = data->jstate->min; + DI_PLEN_MAX = data->jstate->max; + sum = data->jstate->sum; + sqsum = data->jstate->sqsum; + reset_jump_win_state(data->jstate); + } + DI_PLEN_MEAN = sum / wsize; + if (wsize > 1) { + DI_PLEN_STDEV = fixp_sqrt((sqsum - + ((uint64_t)sum * sum / wsize)) / (wsize - 1)); + } + DI_PLEN_SUM = sum; + data->changed = 0; + } + *stats = fdata->stats; + + return (DI_PLEN_NO_STATS); +} + +static int +plen_get_stat(struct di_cdata *cdata, struct di_fdata *fdata, int which, + int32_t *stat) +{ + int32_t *stats; + + if (which < 0 || which > DI_PLEN_NO_STATS) + return (-1); + + if (!plen_get_stats(cdata, fdata, &stats)) + return (0); + + *stat = stats[which]; + + return (1); +} + +static int +plen_get_stat_names(char **names[]) +{ + + *names = di_plen_stat_names; + + return (DI_PLEN_NO_STATS); +} + +static struct di_feature_alg di_plen_desc = { + _FI( .name = ) DI_PLEN_NAME, + _FI( .type = ) DI_PLEN_TYPE, + _FI( .ref_count = ) 0, + + _FI( .init_instance = ) plen_init_instance, + _FI( .destroy_instance = ) plen_destroy_instance, + _FI( .init_stats = ) plen_init_stats, + _FI( .destroy_stats = ) plen_destroy_stats, + _FI( .update_stats = ) plen_update_stats, + _FI( .reset_stats = ) plen_reset_stats, + _FI( .get_stats = ) plen_get_stats, + _FI( .get_stat = ) plen_get_stat, + _FI( .get_stat_names = ) plen_get_stat_names, + _FI( .get_conf = ) plen_get_conf, +}; + +DECLARE_DIFFUSE_FEATURE_MODULE(plen, &di_plen_desc); Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plen.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plen.h Sat Oct 8 04:49:27 2011 (r226133) @@ -0,0 +1,60 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DIFFUSE packet length feature. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_FEATURE_PLEN_H_ +#define _NETINET_IPFW_DIFFUSE_FEATURE_PLEN_H_ + +#define DI_DEFAULT_PLEN_WINDOW 15 + +/* Main properties, used in kernel and userspace. */ +#define DI_PLEN_NAME "plen" +#define DI_PLEN_TYPE DI_FEATURE_ALG_UNIDIRECTIONAL +#define DI_PLEN_NO_STATS 5 +#define DI_PLEN_STAT_NAMES_DECL char *di_plen_stat_names[DI_PLEN_NO_STATS] +#define DI_PLEN_STAT_NAMES DI_PLEN_STAT_NAMES_DECL = \ +{ \ + "min", \ + "mean", \ + "max", \ + "stdev", \ + "sum" \ +}; + +struct di_feature_module * plen_module(void); + +#endif /* _NETINET_IPFW_DIFFUSE_FEATURE_PLEN_H_ */ Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plen_common.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plen_common.h Sat Oct 8 04:49:27 2011 (r226133) @@ -0,0 +1,56 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _NETINET_IPFW_DIFFUSE_FEATURE_PLEN_COMMON_H_ +#define _NETINET_IPFW_DIFFUSE_FEATURE_PLEN_COMMON_H_ + +/* Length computation methods. */ +#define DI_PLEN_LEN_FULL 0 /* Full length including IP header. */ +#define DI_PLEN_LEN_IPDATA 1 /* IP data length. */ +#define DI_PLEN_LEN_PAYLOAD 2 /* UDP/TCP data length. */ + +struct di_feature_plen_config { + struct di_oid oid; + + /* Sliding/jumping window as number of packets. */ + int plen_window; + /* Compute stats for partial windows. */ + int plen_partial_window; + /* Type of length (see PLEN_LEN_* defines). */ + int plen_len_type; + /* If =1 we have jumping windows. */ + int plen_jump_window; +}; + +#endif /* _NETINET_IPFW_DIFFUSE_FEATURE_PLEN_COMMON_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 05:07:09 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 47CE9106566C; Sat, 8 Oct 2011 05:07:09 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 350E98FC0C; Sat, 8 Oct 2011 05:07:09 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p98579fj043714; Sat, 8 Oct 2011 05:07:09 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p98579Fi043709; Sat, 8 Oct 2011 05:07:09 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080507.p98579Fi043709@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 05:07:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226134 - in projects/diffused_head/sys: modules/diffuse modules/diffuse/diffuse_feature_plenbd netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 05:07:09 -0000 Author: lstewart Date: Sat Oct 8 05:07:08 2011 New Revision: 226134 URL: http://svn.freebsd.org/changeset/base/226134 Log: A DIFFUSE feature kernel module which calculates per-flow, bidirectional minimum, mean, maximum, standard deviation and sum packet length statistics for use in classification decisions. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_plenbd/ projects/diffused_head/sys/modules/diffuse/diffuse_feature_plenbd/Makefile (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plenbd.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plenbd.h (contents, props changed) Modified: projects/diffused_head/sys/modules/diffuse/Makefile Modified: projects/diffused_head/sys/modules/diffuse/Makefile ============================================================================== --- projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 04:49:27 2011 (r226133) +++ projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 05:07:08 2011 (r226134) @@ -4,6 +4,7 @@ SUBDIR= diffuse \ diffuse_feature_iat \ diffuse_feature_iatbd \ diffuse_feature_pcnt \ - diffuse_feature_plen + diffuse_feature_plen \ + diffuse_feature_plenbd .include Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_plenbd/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/diffuse_feature_plenbd/Makefile Sat Oct 8 05:07:08 2011 (r226134) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../netinet/ipfw + +KMOD= diffuse_feature_plenbd +SRCS= diffuse_feature_plenbd.c + +.include Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plenbd.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plenbd.c Sat Oct 8 05:07:08 2011 (r226134) @@ -0,0 +1,537 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#ifdef _KERNEL +#include +#include +#include +#include +#include +#endif /* _KERNEL */ +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#ifdef _KERNEL +#include +#include +#include +#endif /* _KERNEL */ + +#ifndef _KERNEL +#include +#include +#include +#define KPI_USER_COMPAT +#include /* Must come after stdlib.h */ +#endif + +/* + * Feature packet length bidirectional computes minimum, mean, maximum and std + * deviation of packet length (length = length of IP data or length of UDP/TCP + * data) for both directions of traffic flow. + */ + +/* If we are linked from userspace only put the declaration here. */ +#ifdef _KERNEL +DI_PLENBD_STAT_NAMES; +#else +DI_PLENBD_STAT_NAMES_DECL; +#endif + +/* State for jump windows. */ +struct di_plenbd_jump_win_state { + uint16_t fmin; + uint16_t fmax; + uint32_t fsum; + uint64_t fsqsum; + uint16_t bmin; + uint16_t bmax; + uint32_t bsum; + uint64_t bsqsum; + uint16_t fcnt; + uint16_t bcnt; + int jump; + int first; +}; + +/* Per flow data (ring buffer). */ +struct di_plenbd_fdata { + int full; + int changed; + int index; + uint16_t *plens; + uint8_t *dirs; + struct di_plenbd_jump_win_state *jstate; +}; + +static int plenbd_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata); + +static int +plenbd_init_instance(struct di_cdata *cdata, struct di_oid *params) +{ + struct di_feature_plenbd_config *conf, *p; + + cdata->conf = malloc(sizeof(struct di_feature_plenbd_config), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (cdata->conf) + return (ENOMEM); + + conf = (struct di_feature_plenbd_config *)cdata->conf; + + /* Set default configuration. */ + conf->plen_window = DI_DEFAULT_PLENBD_WINDOW; + conf->plen_partial_window = 0; + conf->plen_len_type = DI_PLEN_LEN_FULL; + conf->plen_jump_window = 0; + + /* Set configuration. */ + if (params != NULL) { + p = (struct di_feature_plenbd_config *)params; + + if (p->plen_window != -1) + conf->plen_window = p->plen_window; + + if (p->plen_partial_window != -1) + conf->plen_partial_window = p->plen_partial_window; + + if (p->plen_len_type != -1) + conf->plen_len_type = p->plen_len_type; + + if (p->plen_jump_window != -1) + conf->plen_jump_window = p->plen_jump_window; + } + + return (0); +} + +static int +plenbd_destroy_instance(struct di_cdata *cdata) +{ + + free(cdata->conf, M_DIFFUSE); + + return (0); +} + +static int +plenbd_get_conf(struct di_cdata *cdata, struct di_oid *cbuf, int size_only) +{ + + if (!size_only) + memcpy(cbuf, cdata->conf, + sizeof(struct di_feature_plenbd_config)); + + return (sizeof(struct di_feature_plenbd_config)); +} + +static int +plenbd_init_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_plenbd_config *conf; + struct di_plenbd_fdata *data; + + conf = (struct di_feature_plenbd_config *)cdata->conf; + + fdata->data = malloc(sizeof(struct di_plenbd_fdata), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (fdata->data == NULL) + return (ENOMEM); + + data = (struct di_plenbd_fdata *)fdata->data; + + if (!conf->plen_jump_window) { + data->plens = malloc(conf->plen_window * sizeof(uint16_t), + M_DIFFUSE, M_NOWAIT | M_ZERO); + data->dirs = malloc(conf->plen_window * sizeof(uint8_t), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } else { + data->jstate = malloc(sizeof(struct di_plenbd_jump_win_state), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } + fdata->stats = malloc(DI_PLENBD_NO_STATS * sizeof(int32_t), M_DIFFUSE, + M_NOWAIT | M_ZERO); + + if (data->plens == NULL || data->dirs == NULL || data->jstate == NULL || + fdata->stats == NULL) { + free(fdata->stats, M_DIFFUSE); + free(data->jstate, M_DIFFUSE); + free(data->dirs, M_DIFFUSE); + free(data->plens, M_DIFFUSE); + free(fdata->data, M_DIFFUSE); + + return (ENOMEM); + } + + plenbd_reset_stats(cdata, fdata); + + return (0); +} + +static int +plenbd_destroy_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_plenbd_config *conf; + struct di_plenbd_fdata *data; + + conf = (struct di_feature_plenbd_config *)cdata->conf; + data = (struct di_plenbd_fdata *)fdata->data; + + if (!conf->plen_jump_window) { + free(data->plens, M_DIFFUSE); + free(data->dirs, M_DIFFUSE); + } else { + free(data->jstate, M_DIFFUSE); + } + free(fdata->data, M_DIFFUSE); + free(fdata->stats, M_DIFFUSE); + + return (0); +} + +static void +reset_jump_win_state(struct di_plenbd_jump_win_state *state) +{ + + state->fmin = 0xFFFF; + state->fmax = 0; + state->fsum = 0; + state->fsqsum = 0; + state->bmin = 0xFFFF; + state->bmax = 0; + state->bsum = 0; + state->bsqsum = 0; + state->fcnt = 0; + state->bcnt = 0; + state->jump = 0; +} + +static int +plenbd_update_stats(struct di_cdata *cdata, struct di_fdata *fdata, struct mbuf *mbuf, + int proto, void *ulp, int dir) +{ + struct di_feature_plenbd_config *conf; + struct di_plenbd_fdata *data; + struct ip *ip; + struct ip6_hdr *ip6; + struct tcphdr *tcp; + uint16_t plen; + int iplen; + + conf = (struct di_feature_plenbd_config *)cdata->conf; + data = (struct di_plenbd_fdata *)fdata->data; + ip = mtod(mbuf, struct ip *); + plen = 0; + + /* Length of data in IP. */ + if (conf->plen_len_type == DI_PLEN_LEN_FULL) { + plen = m_length(mbuf, NULL); + } else { + iplen = 0; + if (ip->ip_v == 6) { + ip6 = (struct ip6_hdr *)ip; + iplen = ntohs(ip6->ip6_plen); + } else { + iplen = ntohs(ip->ip_len) - ip->ip_hl * 4; + } + if (conf->plen_len_type == DI_PLEN_LEN_IPDATA) { + plen = iplen; + } else { + /* Length of data in UDP or TCP. */ + if (proto != 0 && ulp != NULL) { + if (proto == IPPROTO_TCP) { + tcp = (struct tcphdr *)ulp; + plen = iplen - tcp->th_off * 4; + } else if (proto == IPPROTO_UDP) { + plen = iplen - sizeof(struct udphdr); + } + } + } + } + + if (!conf->plen_jump_window) { + data->plens[data->index] = plen; + data->dirs[data->index++] = dir; + } else { + if (dir == MATCH_FORWARD) { + if (plen < data->jstate->fmin) + data->jstate->fmin = plen; + + if (plen > data->jstate->fmax) + data->jstate->fmax = plen; + + data->jstate->fsum += plen; + data->jstate->fsqsum += (uint64_t)plen * plen; + data->jstate->fcnt++; + } else { + if (plen < data->jstate->bmin) + data->jstate->bmin = plen; + + if (plen > data->jstate->bmax) + data->jstate->bmax = plen; + + data->jstate->bsum += plen; + data->jstate->bsqsum += (uint64_t)plen * plen; + data->jstate->bcnt++; + } + data->index++; + + if (data->index == conf->plen_window) { + data->jstate->jump = 1; + if (data->jstate->first) + data->jstate->first = 0; + } + } + + if (!data->full && data->index == conf->plen_window) + data->full = 1; + + data->changed = 1; + if (data->index == conf->plen_window) + data->index = 0; + + return (0); +} + +static int +plenbd_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_plenbd_config *conf; + struct di_plenbd_fdata *data; + int i; + + conf = (struct di_feature_plenbd_config *)cdata->conf; + data = (struct di_plenbd_fdata *)fdata->data; + + fdata->stats[0] = 0x7FFFFFFF; + fdata->stats[1] = 0; + fdata->stats[2] = 0; + fdata->stats[3] = 0; + fdata->stats[4] = 0; + fdata->stats[5] = 0x7FFFFFFF; + fdata->stats[6] = 0; + fdata->stats[7] = 0; + fdata->stats[8] = 0; + fdata->stats[9] = 0; + + if (!conf->plen_jump_window) { + for (i = 0; i < conf->plen_window; i++) { + data->plens[i] = 0; + data->dirs[i] = 0; + } + } else { + reset_jump_win_state(data->jstate); + data->jstate->first = 1; + } + data->full = 0; + data->changed = 0; + data->index = 0; + + return (0); +} + +static int +plenbd_get_stats(struct di_cdata *cdata, struct di_fdata *fdata, + int32_t **stats) +{ +#define DI_PLEN_FMIN fdata->stats[0] +#define DI_PLEN_FMEAN fdata->stats[1] +#define DI_PLEN_FMAX fdata->stats[2] +#define DI_PLEN_FSTDEV fdata->stats[3] +#define DI_PLEN_FSUM fdata->stats[4] +#define DI_PLEN_BMIN fdata->stats[5] +#define DI_PLEN_BMEAN fdata->stats[6] +#define DI_PLEN_BMAX fdata->stats[7] +#define DI_PLEN_BSTDEV fdata->stats[8] +#define DI_PLEN_BSUM fdata->stats[9] + struct di_feature_plenbd_config *conf; + struct di_plenbd_fdata *data; + uint32_t bcnt, bsum, fcnt, fsum; + uint64_t bsqsum, fsqsum; + int i, wsize; + + conf = (struct di_feature_plenbd_config *)cdata->conf; + data = (struct di_plenbd_fdata *)fdata->data; + bcnt = bsum = fcnt = fsum = 0; + bsqsum = fsqsum = 0; + + if (!data->full && !(conf->plen_partial_window && data->index > 0)) + return (0); /* Window is not full yet. */ + + /* Compute stats only if we need update. */ + if ((!conf->plen_jump_window && data->changed) || + (conf->plen_jump_window && (data->jstate->jump || + (conf->plen_partial_window && data->jstate->first)))) { + wsize = conf->plen_window; + if (!data->full) + wsize = data->index; + + if (!conf->plen_jump_window) { + DI_PLEN_FMIN = 0x7FFFFFFF; + DI_PLEN_FMAX = 0; + DI_PLEN_BMIN = 0x7FFFFFFF; + DI_PLEN_BMAX = 0; + for (i = 0; i < wsize; i++) { + if (data->dirs[i] == MATCH_FORWARD) { + if (data->plens[i] < DI_PLEN_FMIN) + DI_PLEN_FMIN = data->plens[i]; + + if (data->plens[i] > DI_PLEN_FMAX) + DI_PLEN_FMAX = data->plens[i]; + + fsum += data->plens[i]; + fsqsum += (uint64_t)data->plens[i] * + data->plens[i]; + fcnt++; + } else { + if (data->plens[i] < DI_PLEN_BMIN) + DI_PLEN_BMIN = data->plens[i]; + + if (data->plens[i] > DI_PLEN_BMAX) + DI_PLEN_BMAX = data->plens[i]; + + bsum += data->plens[i]; + bsqsum += (uint64_t)data->plens[i] * + data->plens[i]; + bcnt++; + } + } + } else { + DI_PLEN_FMIN = data->jstate->fmin; + DI_PLEN_FMAX = data->jstate->fmax; + DI_PLEN_BMIN = data->jstate->bmin; + DI_PLEN_BMAX = data->jstate->bmax; + fsum = data->jstate->fsum; + fsqsum = data->jstate->fsqsum; + bsum = data->jstate->bsum; + bsqsum = data->jstate->bsqsum; + fcnt = data->jstate->fcnt; + bcnt = data->jstate->bcnt; + + if (data->jstate->jump) + reset_jump_win_state(data->jstate); + } + + DI_PLEN_FSUM = fsum; + DI_PLEN_BSUM = bsum; + + if (fcnt > 0) { + DI_PLEN_FMEAN = fsum / fcnt; + } else { + DI_PLEN_FMIN = 0; + DI_PLEN_FMEAN = 0; + } + if (fcnt > 1) { + DI_PLEN_FSTDEV = fixp_sqrt((fsqsum - + ((uint64_t)fsum * fsum / fcnt)) / (fcnt - 1)); + } else { + DI_PLEN_FSTDEV = 0; + } + if (bcnt > 0) { + DI_PLEN_BMEAN = bsum / bcnt; + } else { + DI_PLEN_BMIN = 0; + DI_PLEN_BMEAN = 0; + } + if (bcnt > 1) { + DI_PLEN_BSTDEV = fixp_sqrt((bsqsum - + ((uint64_t)bsum * bsum / bcnt)) / (bcnt - 1)); + } else { + DI_PLEN_BSTDEV = 0; + } + + data->changed = 0; + } + *stats = fdata->stats; + + return (DI_PLENBD_NO_STATS); +} + +static int +plenbd_get_stat(struct di_cdata *cdata, struct di_fdata *fdata, int which, int32_t *stat) +{ + int32_t *stats; + + if (which < 0 || which > DI_PLENBD_NO_STATS) + return (-1); + + if (!plenbd_get_stats(cdata, fdata, &stats)) + return (0); + + *stat = stats[which]; + + return (1); +} + +static int +plenbd_get_stat_names(char **names[]) +{ + + *names = di_plenbd_stat_names; + + return (DI_PLENBD_NO_STATS); +} + +static struct di_feature_alg di_plenbd_desc = { + _FI( .name = ) DI_PLENBD_NAME, + _FI( .type = ) DI_PLENBD_TYPE, + _FI( .ref_count = ) 0, + + _FI( .init_instance = ) plenbd_init_instance, + _FI( .destroy_instance = ) plenbd_destroy_instance, + _FI( .init_stats = ) plenbd_init_stats, + _FI( .destroy_stats = ) plenbd_destroy_stats, + _FI( .update_stats = ) plenbd_update_stats, + _FI( .reset_stats = ) plenbd_reset_stats, + _FI( .get_stats = ) plenbd_get_stats, + _FI( .get_stat = ) plenbd_get_stat, + _FI( .get_stat_names = ) plenbd_get_stat_names, + _FI( .get_conf = ) plenbd_get_conf, +}; + +DECLARE_DIFFUSE_FEATURE_MODULE(plenbd, &di_plenbd_desc); Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plenbd.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_plenbd.h Sat Oct 8 05:07:08 2011 (r226134) @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DIFFUSE bidirectional packet length feature. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_FEATURE_PLENBD_H_ +#define _NETINET_IPFW_DIFFUSE_FEATURE_PLENBD_H_ + +#define DI_DEFAULT_PLENBD_WINDOW 25 + +#define di_feature_plenbd_config di_feature_plen_config + +/* Main properties, used in kernel and userspace. */ +#define DI_PLENBD_NAME "plenbd" +#define DI_PLENBD_TYPE DI_FEATURE_ALG_BIDIRECTIONAL +#define DI_PLENBD_NO_STATS 10 +#define DI_PLENBD_STAT_NAMES_DECL char *di_plenbd_stat_names[DI_PLENBD_NO_STATS] +#define DI_PLENBD_STAT_NAMES DI_PLENBD_STAT_NAMES_DECL = \ +{ \ + "fmin", \ + "fmean", \ + "fmax", \ + "fstdev", \ + "fsum", \ + "bmin", \ + "bmean", \ + "bmax", \ + "bstdev", \ + "bsum" \ +}; + +struct di_feature_module * plenbd_module(void); + +#endif /* _NETINET_IPFW_DIFFUSE_FEATURE_PLENBD_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 05:15:13 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 870E3106564A; Sat, 8 Oct 2011 05:15:13 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 744CE8FC12; Sat, 8 Oct 2011 05:15:13 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p985FDtT043995; Sat, 8 Oct 2011 05:15:13 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p985FDE0043990; Sat, 8 Oct 2011 05:15:13 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080515.p985FDE0043990@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 05:15:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226135 - in projects/diffused_head/sys: modules/diffuse modules/diffuse/diffuse_feature_skype netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 05:15:13 -0000 Author: lstewart Date: Sat Oct 8 05:15:13 2011 New Revision: 226135 URL: http://svn.freebsd.org/changeset/base/226135 Log: A DIFFUSE feature kernel module which calculates per-flow statistics for the mean, absolute two packet difference and ratio of the packet payload lengths for use in classification decisions. This module calculates features which have been empirically found to be useful in identifying Skype flows. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_skype/ projects/diffused_head/sys/modules/diffuse/diffuse_feature_skype/Makefile (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_skype.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_feature_skype.h (contents, props changed) Modified: projects/diffused_head/sys/modules/diffuse/Makefile Modified: projects/diffused_head/sys/modules/diffuse/Makefile ============================================================================== --- projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 05:07:08 2011 (r226134) +++ projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 05:15:13 2011 (r226135) @@ -5,6 +5,7 @@ SUBDIR= diffuse \ diffuse_feature_iatbd \ diffuse_feature_pcnt \ diffuse_feature_plen \ - diffuse_feature_plenbd + diffuse_feature_plenbd \ + diffuse_feature_skype .include Added: projects/diffused_head/sys/modules/diffuse/diffuse_feature_skype/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/diffuse_feature_skype/Makefile Sat Oct 8 05:15:13 2011 (r226135) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../netinet/ipfw + +KMOD= diffuse_feature_skype +SRCS= diffuse_feature_skype.c + +.include Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_skype.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_skype.c Sat Oct 8 05:15:13 2011 (r226135) @@ -0,0 +1,504 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Rozanna Jesudasan. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * DIFFUSE Skype Feature. + */ + +#include +__FBSDID("$FreeBSD$"); + +#ifdef _KERNEL +#include +#include +#include +#include +#include +#endif /* _KERNEL */ +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#ifdef _KERNEL +#include +#include +#include +#endif /* _KERNEL */ + +#ifndef _KERNEL +#include +#include +#include +#define KPI_USER_COMPAT +#include /* Must come after stdlib.h */ +#endif + +/* + * Feature Skype computes mean, ratio and the absolute two packet difference of + * packet length (length = length of only the data, length of UDP/TCP data, or + * length of IP data). + */ + +/* If we are linked from userspace only put the declaration here. */ +#ifdef _KERNEL +DI_SKYPE_STAT_NAMES; +#else +DI_SKYPE_STAT_NAMES_DECL; +#endif + +/* State for jump windows. */ +struct di_skype_jump_win_state { + uint32_t fwdsum; + uint32_t revsum; + uint64_t atpdsum; + int32_t plen1; + int32_t plen2; + int jump; + int first; +}; + +/* Per flow data (ring buffer). */ +struct di_skype_fdata { + int full; + int changed; + int index; + uint16_t *plens; + uint8_t *dirs; + struct di_skype_jump_win_state *jstate; +}; + +static int skype_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata); + +static int +skype_init_instance(struct di_cdata *cdata, struct di_oid *params) +{ + struct di_feature_skype_config *conf, *p; + + cdata->conf = malloc(sizeof(struct di_feature_skype_config), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (cdata->conf == NULL) + return (ENOMEM); + + conf = (struct di_feature_skype_config *)cdata->conf; + + /* Set default configuration. */ + conf->plen_window = DI_DEFAULT_SKYPE_WINDOW; + conf->plen_partial_window = 0; + conf->plen_len_type = DI_PLEN_LEN_PAYLOAD; + conf->plen_jump_window = 0; + + /* Set configuration */ + if (params != NULL) { + p = (struct di_feature_skype_config *)params; + + if (p->plen_window != -1) + conf->plen_window = p->plen_window; + + if (p->plen_partial_window != -1) + conf->plen_partial_window = p->plen_partial_window; + + if (p->plen_len_type != -1) + conf->plen_len_type = p->plen_len_type; + + if (p->plen_jump_window != -1) + conf->plen_jump_window = p->plen_jump_window; + } + + return (0); +} + +static int +skype_destroy_instance(struct di_cdata *cdata) +{ + + free(cdata->conf, M_DIFFUSE); + + return (0); +} + +static int +skype_get_conf(struct di_cdata *cdata, struct di_oid *cbuf, int size_only) +{ + + if (!size_only) + memcpy(cbuf, cdata->conf, + sizeof(struct di_feature_skype_config)); + + return (sizeof(struct di_feature_skype_config)); +} + +static int +skype_init_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_skype_config *conf; + struct di_skype_fdata *data; + + conf = (struct di_feature_skype_config *)cdata->conf; + + fdata->data = malloc(sizeof(struct di_skype_fdata), M_DIFFUSE, + M_NOWAIT | M_ZERO); + if (fdata->data == NULL) + return (ENOMEM); + + data = (struct di_skype_fdata *)fdata->data; + + if (!conf->plen_jump_window) { + data->plens = malloc(conf->plen_window * sizeof(uint16_t), + M_DIFFUSE, M_NOWAIT | M_ZERO); + data->dirs = malloc(conf->plen_window * sizeof(uint8_t), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } else { + data->jstate = malloc(sizeof(struct di_skype_jump_win_state), + M_DIFFUSE, M_NOWAIT | M_ZERO); + } + + fdata->stats = malloc(DI_SKYPE_NO_STATS * sizeof(int32_t), M_DIFFUSE, + M_NOWAIT | M_ZERO); + + if (data->plens == NULL || data->dirs == NULL || data->jstate == NULL || + fdata->stats == NULL) { + free(fdata->stats, M_DIFFUSE); + free(data->jstate, M_DIFFUSE); + free(data->dirs, M_DIFFUSE); + free(data->plens, M_DIFFUSE); + free(fdata->data, M_DIFFUSE); + + return (ENOMEM); + } + + skype_reset_stats(cdata, fdata); + + return (0); +} + +static int +skype_destroy_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_skype_config *conf; + struct di_skype_fdata *data; + + conf = (struct di_feature_skype_config *)cdata->conf; + data = (struct di_skype_fdata *)fdata->data; + + if (!conf->plen_jump_window) { + free(data->plens, M_DIFFUSE); + free(data->dirs, M_DIFFUSE); + } else { + free(data->jstate, M_DIFFUSE); + } + + free(fdata->data, M_DIFFUSE); + free(fdata->stats, M_DIFFUSE); + + return (0); +} + +static int +skype_update_stats(struct di_cdata *cdata, struct di_fdata *fdata, + struct mbuf *mbuf, int proto, void *ulp, int dir) +{ + struct di_feature_skype_config *conf; + struct di_skype_fdata *data; + struct ip *ip; + struct ip6_hdr *ip6; + struct tcphdr *tcp; + uint16_t plen; + int iplen; + + conf = (struct di_feature_skype_config *)cdata->conf; + data = (struct di_skype_fdata *)fdata->data; + ip = mtod(mbuf, struct ip *); + plen = 0; + + /* Length of data in IP */ + if (conf->plen_len_type == DI_PLEN_LEN_FULL) { + plen = m_length(mbuf, NULL); + + } else { + iplen = 0; + if (ip->ip_v == 6) { + ip6 = (struct ip6_hdr *)ip; + iplen = ntohs(ip6->ip6_plen); + } else { + iplen = ntohs(ip->ip_len) - ip->ip_hl * 4; + } + if (conf->plen_len_type == DI_PLEN_LEN_IPDATA) { + plen = iplen; + + } else { + /* Length of data in UDP or TCP. */ + if (proto != 0 && ulp != NULL) { + if (proto == IPPROTO_TCP) { + tcp = (struct tcphdr*)ulp; + plen = iplen - tcp->th_off * 4; + + } else if (proto == IPPROTO_UDP) { + plen = iplen - sizeof(struct udphdr); + } + } + } + } + + if (!conf->plen_jump_window) { + data->plens[data->index] = plen; + data->dirs[data->index++] = dir; + } else { + + if (dir == MATCH_FORWARD) + data->jstate->fwdsum += plen; + else + data->jstate->revsum += plen; + + if (data->jstate->plen1 != -1) { + data->jstate->atpdsum += (plen > data->jstate->plen1) ? + (plen - data->jstate->plen1) : + (data->jstate->plen1 - plen); + + if (data->jstate->plen2 != -1) { + data->jstate->atpdsum += + (plen > data->jstate->plen2) ? + (plen - data->jstate->plen2) : + (data->jstate->plen2 - plen); + } + } + + data->jstate->plen2 = data->jstate->plen1; + data->jstate->plen1 = plen; + data->index++; + + if (data->index == conf->plen_window) { + data->jstate->jump = 1; + if (data->jstate->first) + data->jstate->first = 0; + } + } + + if (!data->full && data->index == conf->plen_window) + data->full = 1; + + data->changed = 1; + if (data->index == conf->plen_window) + data->index = 0; + + return (0); +} + +static void +reset_jump_win_state(struct di_skype_jump_win_state *state) +{ + + state->fwdsum = 0; + state->revsum = 0; + state->atpdsum = 0; + state->plen1 = -1; + state->plen2 = -1; + state->jump = 0; +} + +static int +skype_reset_stats(struct di_cdata *cdata, struct di_fdata *fdata) +{ + struct di_feature_skype_config *conf; + struct di_skype_fdata *data; + int i; + + conf = (struct di_feature_skype_config *)cdata->conf; + data = (struct di_skype_fdata *)fdata->data; + + for (i = 1; i < DI_SKYPE_NO_STATS; i++) + fdata->stats[i] = 0; + + if (!conf->plen_jump_window) { + for (i = 0; i < conf->plen_window; i++) { + data->plens[i] = 0; + data->dirs[i] = 0; + } + } else { + reset_jump_win_state(data->jstate); + data->jstate->first = 1; + } + data->full = 0; + data->changed = 0; + data->index = 0; + + return (0); +} + +/* + * Calculates the attributes mean, absolute two packet difference and ratio of + * the packet payload lengths for a traffic flow or subflow. The statistics + * calculated are stored in the fdata structure stats array and are used for + * classification. The attribute two packet difference is the difference in + * payload length between two consecutive packets. The ratio is calculated for + * the payload length in the forward and reverse directions of the flow. + */ +static int +skype_get_stats(struct di_cdata *cdata, struct di_fdata *fdata, int32_t **stats) +{ +#define PL_MEAN fdata->stats[0] +#define PL_ATPD fdata->stats[1] +#define PL_RATIO fdata->stats[2] + struct di_feature_skype_config *conf; + struct di_skype_fdata *data; + uint32_t atpdsum, fwdsum, revsum, sum; + int32_t plen1, plen2; + int i, wsize; + + conf = (struct di_feature_skype_config *)cdata->conf; + data = (struct di_skype_fdata *)fdata->data; + atpdsum = fwdsum = revsum = sum = 0; + plen1 = plen2 = -1; + + if (!data->full && !(conf->plen_partial_window && data->index > 0)) + return (0); /* Window is not full yet. */ + + /* Compute stats only if we need update. */ + if ((!conf->plen_jump_window && data->changed) || + (conf->plen_jump_window && (data->jstate->jump || + (conf->plen_partial_window && data->jstate->first)))) { + wsize = conf->plen_window; + if (!data->full) + wsize = data->index; + + if (!conf->plen_jump_window) { + for (i = 0; i < wsize; i++) { + + if (data->dirs[i] == MATCH_FORWARD) + fwdsum += data->plens[i]; + else + revsum += data->plens[i]; + + sum += data->plens[i]; + + /* + * Get stats for the absolute two packet + * difference. + */ + if (plen1 != -1) { + atpdsum += (data->plens[i] > plen1) ? + (data->plens[i] - plen1) : + (plen1 - data->plens[i]); + + if (plen2 != -1) { + atpdsum += + (data->plens[i] > plen2) ? + (data->plens[i] - plen2) : + (plen2 - data->plens[i]); + } + } + plen2 = plen1; + plen1 = data->plens[i]; + } + } else { + sum = data->jstate->fwdsum + data->jstate->revsum; + revsum = data->jstate->revsum; + fwdsum = data->jstate->fwdsum; + atpdsum = data->jstate->atpdsum; + reset_jump_win_state(data->jstate); + } + + /* Calculate ratio. */ + if (fwdsum >= revsum && fwdsum > 0) + PL_RATIO = (revsum * 1000) / fwdsum; + + if (revsum > fwdsum && revsum > 0) + PL_RATIO = (fwdsum * 1000) / revsum; + + /* Calculate absolute two packet difference. */ + if (sum > 0) + PL_ATPD = (atpdsum * 1000) / (sum * 2); + + /* Calculate the mean. */ + PL_MEAN = sum / wsize; + data->changed = 0; + } + + *stats = fdata->stats; + + return (DI_SKYPE_NO_STATS); +} + +static int +skype_get_stat(struct di_cdata *cdata, struct di_fdata *fdata, int which, + int32_t *stat) +{ + int32_t *stats; + + if (which < 0 || which > DI_SKYPE_NO_STATS) + return (-1); + + if (!skype_get_stats(cdata, fdata, &stats)) + return (0); + + *stat = stats[which]; + + return (1); +} + +static int +skype_get_stat_names(char **names[]) +{ + + *names = di_skype_stat_names; + + return (DI_SKYPE_NO_STATS); +} + +static struct di_feature_alg di_skype_desc = { + _FI( .name = ) DI_SKYPE_NAME, + _FI( .type = ) DI_SKYPE_TYPE, + _FI( .ref_count = ) 0, + + _FI( .init_instance = ) skype_init_instance, + _FI( .destroy_instance = ) skype_destroy_instance, + _FI( .init_stats = ) skype_init_stats, + _FI( .destroy_stats = ) skype_destroy_stats, + _FI( .update_stats = ) skype_update_stats, + _FI( .reset_stats = ) skype_reset_stats, + _FI( .get_stats = ) skype_get_stats, + _FI( .get_stat = ) skype_get_stat, + _FI( .get_stat_names = ) skype_get_stat_names, + _FI( .get_conf = ) skype_get_conf, +}; + +DECLARE_DIFFUSE_FEATURE_MODULE(skype, &di_skype_desc); Added: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_skype.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_skype.h Sat Oct 8 05:15:13 2011 (r226135) @@ -0,0 +1,58 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Rozanna Jesudasan. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DIFFUSE Skype feature. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_FEATURE_SKYPE_H_ +#define _NETINET_IPFW_DIFFUSE_FEATURE_SKYPE_H_ + +#define DI_DEFAULT_SKYPE_WINDOW 100 + +#define di_feature_skype_config di_feature_plen_config + +/* Main properties, used in kernel and userspace. */ +#define DI_SKYPE_NAME "skype" +#define DI_SKYPE_TYPE DI_FEATURE_ALG_BIDIRECTIONAL +#define DI_SKYPE_NO_STATS 3 +#define DI_SKYPE_STAT_NAMES_DECL char *di_skype_stat_names[DI_SKYPE_NO_STATS] +#define DI_SKYPE_STAT_NAMES DI_SKYPE_STAT_NAMES_DECL = \ +{ \ + "mean", \ + "atpd", \ + "ratio" \ +}; + +struct di_feature_module * skype_module(void); + +#endif /* _NETINET_IPFW_DIFFUSE_FEATURE_SKYPE_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 05:28:18 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1A83F106564A; Sat, 8 Oct 2011 05:28:18 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 079788FC0C; Sat, 8 Oct 2011 05:28:18 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p985SHoQ044402; Sat, 8 Oct 2011 05:28:17 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p985SHJM044397; Sat, 8 Oct 2011 05:28:17 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080528.p985SHJM044397@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 05:28:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226136 - in projects/diffused_head/sys: modules/diffuse modules/diffuse/diffuse_classifier_c45 netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 05:28:18 -0000 Author: lstewart Date: Sat Oct 8 05:28:17 2011 New Revision: 226136 URL: http://svn.freebsd.org/changeset/base/226136 Log: A C4.5 decision tree classifier implementation in the form of a DIFFUSE classifier kernel module. This type of classifier has been empirically shown to perform the fastest and highest accuracy classifications compared to a set of common classification algorithms. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/modules/diffuse/diffuse_classifier_c45/ projects/diffused_head/sys/modules/diffuse/diffuse_classifier_c45/Makefile (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_c45.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_c45.h (contents, props changed) Modified: projects/diffused_head/sys/modules/diffuse/Makefile Modified: projects/diffused_head/sys/modules/diffuse/Makefile ============================================================================== --- projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 05:15:13 2011 (r226135) +++ projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 05:28:17 2011 (r226136) @@ -1,6 +1,7 @@ # $FreeBSD$ SUBDIR= diffuse \ + diffuse_classifier_c45 \ diffuse_feature_iat \ diffuse_feature_iatbd \ diffuse_feature_pcnt \ Added: projects/diffused_head/sys/modules/diffuse/diffuse_classifier_c45/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/diffuse_classifier_c45/Makefile Sat Oct 8 05:28:17 2011 (r226136) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../netinet/ipfw + +KMOD= diffuse_classifier_c45 +SRCS= diffuse_classifier_c45.c + +.include Added: projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_c45.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_c45.c Sat Oct 8 05:28:17 2011 (r226136) @@ -0,0 +1,237 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * DIFFUSE C4.5 classifier. + */ + +#include +__FBSDID("$FreeBSD$"); + +#ifdef _KERNEL +#include +#include +#include +#include +#include +#endif /* _KERNEL */ +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#ifdef _KERNEL +#include +#include +#endif + +#ifdef _KERNEL + +/* Computes the buffer size needed to store classifier. */ +static int +get_size(struct di_classifier_c45_config *c) +{ + + return (sizeof(struct di_classifier_c45_config) + c->tree_len); +} + +/* Assumes target memory is allocated. */ +static void +cpy_conf(struct di_classifier_c45_config *f, struct di_classifier_c45_config *t) +{ + + t->oid = f->oid; + strcpy(t->model_name, f->model_name); + t->feature_cnt = f->feature_cnt; + t->class_cnt = f->class_cnt; + t->multi = f->multi; + t->tree_len = f->tree_len; + memcpy(t->nodes, f->nodes, f->tree_len); +} + +static int +c45_init_instance(struct di_cdata *cdata, struct di_oid *params) +{ + struct di_classifier_c45_config *c, *conf; + + c = (struct di_classifier_c45_config *)params; + + DID("class cnt %d", c->class_cnt); + DID("attr cnt %d", c->feature_cnt); + DID("multi %d", (1 << c->multi)); + DID("tree_len %d", c->tree_len); + DID("want size %d", get_size(c)); + + cdata->conf = malloc(get_size(c), M_DIFFUSE, M_NOWAIT | M_ZERO); + if (cdata->conf == NULL) + return (ENOMEM); + + conf = (struct di_classifier_c45_config *)cdata->conf; + cpy_conf(c, conf); + + return (0); +} + +static int +c45_destroy_instance(struct di_cdata *cdata) +{ + + free(cdata->conf, M_DIFFUSE); + + return (0); +} + +static int +c45_get_conf(struct di_cdata *cdata, struct di_oid *cbuf, int size_only) +{ + int len; + + len = get_size((struct di_classifier_c45_config*)cdata->conf); + + if (!size_only) + cpy_conf((struct di_classifier_c45_config *)cdata->conf, + (struct di_classifier_c45_config *)cbuf); + + return (len); +} + +#endif + +int +c45_classify(struct di_cdata *cdata, int32_t *features, int fcnt) +{ + struct di_classifier_c45_config *conf; + struct di_c45_node_real *nodes; + uint64_t fval; + int n; + + conf = (struct di_classifier_c45_config *)cdata->conf; + nodes = (struct di_c45_node_real *)conf->nodes; + n = 0; + +#ifdef DIFFUSE_DEBUG2 + printf("DIFFUSE: %-10s features ", __func__); + for (int i = 0; i < fcnt; i++) + printf("%u ", features[i]); + printf("\n"); +#endif + + while (n < conf->tree_len / sizeof(struct di_c45_node_real)) { + if (nodes[n].nid.feature > fcnt - 1) + return (-1); /* Should never happen. */ + + fval = features[nodes[n].nid.feature] * (1 << conf->multi); + + switch (nodes[n].nid.type) { + case DI_C45_REAL: + if (fval <= nodes[n].val) { + if (nodes[n].le_type & DI_C45_CLASS) + return (nodes[n].le_id); + else + n = nodes[n].le_id; + } else { + if (nodes[n].gt_type & DI_C45_CLASS) + return (nodes[n].gt_id); + else + n = nodes[n].gt_id; + } + break; + + case DI_C45_BNOM: + if (fval == nodes[n].val) { + if (nodes[n].le_type & DI_C45_CLASS) + return (nodes[n].le_id); + else + n = nodes[n].le_id; + } else { + if (nodes[n].gt_type & DI_C45_CLASS) + return (nodes[n].gt_id); + else + n = nodes[n].gt_id; + } + break; + + case DI_C45_NOM: + /* XXX: Not supported yet. */ + return (-1); + break; + + default: + break; + } + } + + return (-1); +} + +#ifdef _KERNEL + +static int +c45_get_feature_cnt(struct di_cdata *cdata) +{ + + return (((struct di_classifier_c45_config *)cdata->conf)->feature_cnt); +} + +static int +c45_get_class_cnt(struct di_cdata *cdata) +{ + + return (((struct di_classifier_c45_config *)cdata->conf)->class_cnt); +} + +static struct di_classifier_alg di_c45_desc = { + _FI( .name = ) "c4.5", + _FI( .ref_count = ) 0, + + _FI( .init_instance = ) c45_init_instance, + _FI( .destroy_instance = ) c45_destroy_instance, + _FI( .get_conf = ) c45_get_conf, + _FI( .classify = ) c45_classify, + _FI( .get_feature_cnt = ) c45_get_feature_cnt, + _FI( .get_class_cnt = ) c45_get_class_cnt, +}; + +DECLARE_DIFFUSE_CLASSIFIER_MODULE(c45, &di_c45_desc); + +#endif Added: projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_c45.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_c45.h Sat Oct 8 05:28:17 2011 (r226136) @@ -0,0 +1,115 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DIFFUSE C4.5 classifier. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_CLASSIFIER_C45_H_ +#define _NETINET_IPFW_DIFFUSE_CLASSIFIER_C45_H_ + +/* Bit flags for struct di_c45_node_real gt_type/le_type fields. */ +#define DI_C45_CLASS 0x01 +#define DI_C45_NODE 0x02 +#define DI_C45_FEAT 0x04 + +/* Values for struct di_c45_node type field. */ +#define DI_C45_BNOM 1 +#define DI_C45_NOM 2 +#define DI_C45_REAL 3 + +/* NOTE: Number of classes, features limited to 256. */ + +struct di_c45_node { + /* Node type (split node vs leaf), value type (nominal vs real). */ + uint16_t type; + /* Feature number. */ + uint8_t feature; + /* Class if feature missing. */ + uint8_t missing_class; +}; + +struct di_c45_node_real { + struct di_c45_node nid; + + /* Split value. */ + int64_t val; + /* + * le = less-equal class (class or node depending on type). + * ge = greater-than class (class or node depending on type). + */ + uint16_t le_id; + uint16_t gt_id; + uint8_t le_type; + uint8_t gt_type; +}; + +struct di_c45_node_bin_nominal { + struct di_c45_node nid; + + int64_t val; + /* eq = equal class (class or node depending on type). */ + uint16_t eq_id; + /* ne = non-equal class (class or node depending on type). */ + uint16_t ne_id; + uint8_t eq_type; + uint8_t ne_type; +}; + +/* XXX: No support for non-binary nominal yet. */ + +struct di_classifier_c45_config +{ + struct di_oid oid; + + char model_name[DI_MAX_MODEL_STR_LEN]; + /* Number of features. */ + uint16_t feature_cnt; + /* Number of classes. */ + uint16_t class_cnt; + /* Precsion, multipler for double->int. */ + uint16_t multi; + /* Length of nodes. */ + uint16_t tree_len; + /* Tree. */ + struct di_c45_node nodes[]; +}; + +struct di_classifier_module * c45_module(void); + +struct di_cdata; + +int c45_classify(struct di_cdata *cdata, int32_t *features, int fcnt); + +#endif /* _NETINET_IPFW_DIFFUSE_CLASSIFIER_C45_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 05:41:20 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 06781106566C; Sat, 8 Oct 2011 05:41:20 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DF8E48FC0A; Sat, 8 Oct 2011 05:41:19 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p985fJ1f044816; Sat, 8 Oct 2011 05:41:19 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p985fJKS044811; Sat, 8 Oct 2011 05:41:19 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080541.p985fJKS044811@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 05:41:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226137 - in projects/diffused_head/sys: modules/diffuse modules/diffuse/diffuse_classifier_nbayes netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 05:41:20 -0000 Author: lstewart Date: Sat Oct 8 05:41:19 2011 New Revision: 226137 URL: http://svn.freebsd.org/changeset/base/226137 Log: A fixed-point math based naive-bayes classifier implementation in the form of a DIFFUSE classifier kernel module. It classifies using discretised feature values, and has been empirically shown to perform classifications quickly and with high accuracy. Sponsored by: FreeBSD Foundation Reviewed by: bz Added: projects/diffused_head/sys/modules/diffuse/diffuse_classifier_nbayes/ projects/diffused_head/sys/modules/diffuse/diffuse_classifier_nbayes/Makefile (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_nbayes.c (contents, props changed) projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_nbayes.h (contents, props changed) Modified: projects/diffused_head/sys/modules/diffuse/Makefile Modified: projects/diffused_head/sys/modules/diffuse/Makefile ============================================================================== --- projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 05:28:17 2011 (r226136) +++ projects/diffused_head/sys/modules/diffuse/Makefile Sat Oct 8 05:41:19 2011 (r226137) @@ -2,6 +2,7 @@ SUBDIR= diffuse \ diffuse_classifier_c45 \ + diffuse_classifier_nbayes \ diffuse_feature_iat \ diffuse_feature_iatbd \ diffuse_feature_pcnt \ Added: projects/diffused_head/sys/modules/diffuse/diffuse_classifier_nbayes/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/modules/diffuse/diffuse_classifier_nbayes/Makefile Sat Oct 8 05:41:19 2011 (r226137) @@ -0,0 +1,8 @@ +# $FreeBSD$ + +.PATH: ${.CURDIR}/../../../netinet/ipfw + +KMOD= diffuse_classifier_nbayes +SRCS= diffuse_classifier_nbayes.c + +.include Added: projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_nbayes.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_nbayes.c Sat Oct 8 05:41:19 2011 (r226137) @@ -0,0 +1,302 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * DIFFUSE Naive Bayes classifier. + */ + +#include +__FBSDID("$FreeBSD$"); + +#ifdef _KERNEL +#include +#include +#include +#include +#else +#include +#include +#endif /* _KERNEL */ +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#ifdef _KERNEL +#include +#include +#endif + +#ifdef _KERNEL + +/* Computes the buffer size needed to store classifier. */ +static int +get_size(struct di_classifier_nbayes_config *c) +{ + + return (sizeof(struct di_classifier_nbayes_config) + c->fdist_len); +} + +/* Copy, assumes target memory is allocated. */ +static void +cpy_conf(struct di_classifier_nbayes_config *f, + struct di_classifier_nbayes_config *t) +{ + + t->oid = f->oid; + strcpy(t->model_name, f->model_name); + t->feature_cnt = f->feature_cnt; + t->class_cnt = f->class_cnt; + t->multi = f->multi; + t->fdist_len = f->fdist_len; + memcpy(t->fdist, f->fdist, f->fdist_len); +} + +static int +nbayes_init_instance(struct di_cdata *cdata, struct di_oid *params) +{ + struct di_classifier_nbayes_config *c, *conf; + + c = (struct di_classifier_nbayes_config *)params; + + DID("class cnt %d", c->class_cnt); + DID("attr cnt %d", c->feature_cnt); + DID("multi %d", (1 << c->multi)); + DID("fdist_len %d", c->fdist_len); + DID("want size %d", get_size(c)); + + cdata->conf = malloc(get_size(c), M_DIFFUSE, M_NOWAIT | M_ZERO); + if (cdata->conf == NULL) + return (ENOMEM); + + conf = (struct di_classifier_nbayes_config *)cdata->conf; + cpy_conf(c, conf); + + return (0); +} + +static int +nbayes_destroy_instance(struct di_cdata *cdata) +{ + + free(cdata->conf, M_DIFFUSE); + + return (0); +} + +static int +nbayes_get_conf(struct di_cdata *cdata, struct di_oid *cbuf, int size_only) +{ + int len; + + len = get_size((struct di_classifier_nbayes_config *)cdata->conf); + + if (!size_only) + cpy_conf((struct di_classifier_nbayes_config *)cdata->conf, + (struct di_classifier_nbayes_config *)cbuf); + + return (len); +} + +#endif /* _KERNEL */ + +#define LINEAR_SEARCH_THRESHOLD 5 + +static inline struct di_nbayes_attr_disc_val * +find_val(struct di_nbayes_attr_disc_val *first, int val_cnt, int class_cnt, + int32_t fval) +{ + struct di_nbayes_attr_disc_val *val; + int h, l, j, m; + + val = NULL; + + if (val_cnt <= LINEAR_SEARCH_THRESHOLD) { + /* Linear search. */ + for (j = 0; j < val_cnt; j++) { + val = (struct di_nbayes_attr_disc_val *) + (((char *)first) + + (sizeof(struct di_nbayes_attr_disc_val) + + class_cnt * sizeof(uint32_t)) * j); + if (fval <= val->high_val) + break; + } + + } else { + /* Binary search. */ + l = 0; + h = val_cnt - 1; + while (l < h) { + m = l + ((h - l) / 2); + val = (struct di_nbayes_attr_disc_val *) + (((char *)first) + + (sizeof(struct di_nbayes_attr_disc_val) + + class_cnt * sizeof(uint32_t)) * m); + + if (val->high_val < fval) + l = m + 1; + else + h = m; + } + + val = (struct di_nbayes_attr_disc_val *)(((char *)first) + + (sizeof(struct di_nbayes_attr_disc_val) + class_cnt * + sizeof(uint32_t)) * h); + } + + return (val); +} + +int +nbayes_classify(struct di_cdata *cdata, int32_t *features, int fcnt) +{ + struct di_classifier_nbayes_config *conf = + (struct di_classifier_nbayes_config *)cdata->conf; + struct di_nbayes_attr_prior *ap; + struct di_nbayes_attr_disc *ad; + struct di_nbayes_attr_disc_val *val; + struct di_nbayes_attr_id *attr; + char *d; + uint64_t probs[conf->class_cnt]; + uint64_t max_prob; + int divs[conf->class_cnt]; + int best_class, divs_max, f, i, l, len; + + max_prob = 0; + best_class = divs_max = 0; + +#ifdef DIFFUSE_DEBUG2 + printf("DIFFUSE: %-10s features ", __func__); + for (i = 0; i < fcnt; i++) + printf("%u ", features[i]); + printf("\n"); +#endif + + for (i = 0; i < conf->class_cnt; i++) { + divs[i] = 0; + + for (l = conf->fdist_len, d = (char *)conf->fdist, f = -1; + l > 0; l -= len, d += len, f++) { + attr = (struct di_nbayes_attr_id *)d; + len = attr->len; + + DID("type %d(%d)", attr->type, attr->len); + + if (f >= fcnt) + return (-1); /* Should never happen. */ + + if (attr->type == DI_NBAYES_ATTR_PRIOR) { + ap = (struct di_nbayes_attr_prior *)attr; + probs[i] = ap->prior_p[i]; + } else if (attr->type == DI_NBAYES_ATTR_DISC) { + ad = (struct di_nbayes_attr_disc *)attr; + + val = find_val(ad->val, ad->val_cnt, + conf->class_cnt, features[f]); + probs[i] *= val->cond_p[i]; + + if (probs[i] > + ((uint64_t)1 << (64 - conf->multi))) { + /* + * Divide by 2^(conf->multi - 1) to avoid + * overflow. + */ + probs[i] = fixp_div(probs[i], conf->multi); + divs[i]++; + if (divs[i] > divs_max) + divs_max = divs[i]; + } + } else if (attr->type == DI_NBAYES_ATTR_NORM) { + return (-1); /* XXX: Not supported yet. */ + } + } + } + + /* Make sure the divisor is the same for all probs and find max prob. */ + for (i = 0; i < conf->class_cnt; i++) { + probs[i] = fixp_div(probs[i], conf->multi * + (divs_max - divs[i]) - (divs_max - divs[i] - 1)); + + DID2("class %u prob %llu %i", i, probs[i], divs[i]); + + if (probs[i] > max_prob) { + max_prob = probs[i]; + best_class = i; + } + } + + return (best_class); +} + +#ifdef _KERNEL + +static int +nbayes_get_feature_cnt(struct di_cdata *cdata) +{ + + return (((struct di_classifier_nbayes_config *) + cdata->conf)->feature_cnt); +} + +static int +nbayes_get_class_cnt(struct di_cdata *cdata) +{ + + return (((struct di_classifier_nbayes_config *)cdata->conf)->class_cnt); +} + +static struct di_classifier_alg di_nbayes_desc = { + _FI( .name = ) "nbayes", + _FI( .ref_count = ) 0, + + _FI( .init_instance = ) nbayes_init_instance, + _FI( .destroy_instance = ) nbayes_destroy_instance, + _FI( .get_conf = ) nbayes_get_conf, + _FI( .classify = ) nbayes_classify, + _FI( .get_feature_cnt = ) nbayes_get_feature_cnt, + _FI( .get_class_cnt = ) nbayes_get_class_cnt, +}; + +DECLARE_DIFFUSE_CLASSIFIER_MODULE(nbayes, &di_nbayes_desc); + +#endif Added: projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_nbayes.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_classifier_nbayes.h Sat Oct 8 05:41:19 2011 (r226137) @@ -0,0 +1,115 @@ +/*- + * Copyright (c) 2010-2011 + * Swinburne University of Technology, Melbourne, Australia. + * All rights reserved. + * + * This software was developed at the Centre for Advanced Internet + * Architectures, Swinburne University of Technology, by Sebastian Zander, made + * possible in part by a gift from The Cisco University Research Program Fund, a + * corporate advised fund of Silicon Valley Community Foundation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +/* + * DIFFUSE Naive Bayes classifier. + */ + +#ifndef _NETINET_IPFW_DIFFUSE_CLASSIFIER_NBAYES_H_ +#define _NETINET_IPFW_DIFFUSE_CLASSIFIER_NBAYES_H_ + +#define DI_NBAYES_ATTR_PRIOR 0 +#define DI_NBAYES_ATTR_DISC 1 +#define DI_NBAYES_ATTR_NORM 2 + +struct di_nbayes_attr_id +{ + uint16_t type; + uint16_t len; +}; + +struct di_nbayes_attr_disc_val +{ + int32_t high_val; + uint32_t cond_p[]; +}; + +struct di_nbayes_attr_disc +{ + struct di_nbayes_attr_id id; + /* Number of values/intervals. */ + uint32_t val_cnt; + /* Interval values and conditional probs. */ + struct di_nbayes_attr_disc_val val[]; +}; + +struct di_nbayes_attr_norm_class +{ + int32_t mean; + uint32_t stddev; + int32_t wsum; + uint32_t prec; +}; + +/* One per real attribute. */ +struct di_nbayes_attr_norm +{ + struct di_nbayes_attr_id id; + /* class_cnt structs. */ + struct di_nbayes_attr_norm_class class[]; +}; + +/* Priors, not really an attribute. */ +struct di_nbayes_attr_prior +{ + struct di_nbayes_attr_id id; + /* class_cnt prior probs. */ + uint32_t prior_p[]; +}; + +struct di_classifier_nbayes_config +{ + struct di_oid oid; + + /* Model name. */ + char model_name[DI_MAX_MODEL_STR_LEN]; + /* Number of features. */ + uint16_t feature_cnt; + /* Number of classes. */ + uint16_t class_cnt; + /* Precision, multiplier for double->int. */ + uint16_t multi; + /* Length of fdists. */ + uint16_t fdist_len; + /* feature_cnt feature distributions. */ + struct di_nbayes_attr_id fdist[]; +}; + +struct di_classifier_module * nbayes_module(void); + +struct di_cdata; + +int nbayes_classify(struct di_cdata *cdata, int32_t *features, int fcnt); + +#endif /* _NETINET_IPFW_DIFFUSE_CLASSIFIER_NBAYES_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 05:48:14 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B59C91065670; Sat, 8 Oct 2011 05:48:14 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A50BA8FC08; Sat, 8 Oct 2011 05:48:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p985mED8045063; Sat, 8 Oct 2011 05:48:14 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p985mExL045061; Sat, 8 Oct 2011 05:48:14 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080548.p985mExL045061@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 05:48:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226138 - projects/diffused_head/sys/netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 05:48:14 -0000 Author: lstewart Date: Sat Oct 8 05:48:14 2011 New Revision: 226138 URL: http://svn.freebsd.org/changeset/base/226138 Log: Fix a whitespace nit. Sponsored by: FreeBSD Foundation Modified: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h Modified: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h ============================================================================== --- projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h Sat Oct 8 05:41:19 2011 (r226137) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h Sat Oct 8 05:48:14 2011 (r226138) @@ -54,6 +54,6 @@ "stdev" \ }; -struct di_feature_module *iat_module(void); +struct di_feature_module * iat_module(void); #endif /* _NETINET_IPFW_DIFFUSE_FEATURE_IAT_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 05:48:38 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B33C11065675; Sat, 8 Oct 2011 05:48:38 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A2E6E8FC14; Sat, 8 Oct 2011 05:48:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p985mcrN045108; Sat, 8 Oct 2011 05:48:38 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p985mc0X045106; Sat, 8 Oct 2011 05:48:38 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080548.p985mc0X045106@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 05:48:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226139 - projects/diffused_head/sys/netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 05:48:38 -0000 Author: lstewart Date: Sat Oct 8 05:48:38 2011 New Revision: 226139 URL: http://svn.freebsd.org/changeset/base/226139 Log: Fix a whitespace nit. Sponsored by: FreeBSD Foundation Modified: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.h Modified: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.h ============================================================================== --- projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.h Sat Oct 8 05:48:14 2011 (r226138) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iatbd.h Sat Oct 8 05:48:38 2011 (r226139) @@ -60,6 +60,6 @@ "bstdev" \ }; -struct di_feature_module *iatbd_module(void); +struct di_feature_module * iatbd_module(void); #endif /* _NETINET_IPFW_DIFFUSE_FEATURE_IATBD_H_ */ From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 05:50:39 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 77745106566C; Sat, 8 Oct 2011 05:50:39 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 66F7D8FC13; Sat, 8 Oct 2011 05:50:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p985odO2045223; Sat, 8 Oct 2011 05:50:39 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p985odkT045221; Sat, 8 Oct 2011 05:50:39 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <201110080550.p985odkT045221@svn.freebsd.org> From: Lawrence Stewart Date: Sat, 8 Oct 2011 05:50:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226140 - projects/diffused_head/sys/netinet/ipfw X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 05:50:39 -0000 Author: lstewart Date: Sat Oct 8 05:50:39 2011 New Revision: 226140 URL: http://svn.freebsd.org/changeset/base/226140 Log: Fix another whitespace nit. Sponsored by: FreeBSD Foundation Modified: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h Modified: projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h ============================================================================== --- projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h Sat Oct 8 05:48:38 2011 (r226139) +++ projects/diffused_head/sys/netinet/ipfw/diffuse_feature_iat.h Sat Oct 8 05:50:39 2011 (r226140) @@ -46,12 +46,12 @@ #define DI_IAT_TYPE DI_FEATURE_ALG_UNIDIRECTIONAL #define DI_IAT_NO_STATS 4 #define DI_IAT_STAT_NAMES_DECL char *di_iat_stat_names[DI_IAT_NO_STATS] -#define DI_IAT_STAT_NAMES DI_IAT_STAT_NAMES_DECL = \ -{ \ - "min", \ - "mean", \ - "max", \ - "stdev" \ +#define DI_IAT_STAT_NAMES DI_IAT_STAT_NAMES_DECL = \ +{ \ + "min", \ + "mean", \ + "max", \ + "stdev" \ }; struct di_feature_module * iat_module(void); From owner-svn-src-projects@FreeBSD.ORG Sat Oct 8 12:27:13 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5B4941065672; Sat, 8 Oct 2011 12:27:13 +0000 (UTC) (envelope-from pho@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4B8638FC17; Sat, 8 Oct 2011 12:27:13 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p98CRD89062482; Sat, 8 Oct 2011 12:27:13 GMT (envelope-from pho@svn.freebsd.org) Received: (from pho@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p98CRDGL062481; Sat, 8 Oct 2011 12:27:13 GMT (envelope-from pho@svn.freebsd.org) Message-Id: <201110081227.p98CRDGL062481@svn.freebsd.org> From: Peter Holm Date: Sat, 8 Oct 2011 12:27:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r226152 - projects/stress2/misc X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 08 Oct 2011 12:27:13 -0000 Author: pho Date: Sat Oct 8 12:27:12 2011 New Revision: 226152 URL: http://svn.freebsd.org/changeset/base/226152 Log: Added regression test for kern/156545. Added: projects/stress2/misc/rename5.sh (contents, props changed) Added: projects/stress2/misc/rename5.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ projects/stress2/misc/rename5.sh Sat Oct 8 12:27:12 2011 (r226152) @@ -0,0 +1,135 @@ +#!/bin/sh + +# +# Copyright (c) 2011 Peter Holm +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# Rename scenario from kern/156545 by Konstantin, +# konstantin malov kaspersky com + +# On 8.2-STABLE fsck reports +# "xxx IS AN EXTRANEOUS HARD LINK TO DIRECTORY yyy" +# Fixed by r220986 + +[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 + +. ../default.cfg + +mount | grep -q "$mntpoint" && umount $mntpoint +mdconfig -l | grep -q $mdstart && mdconfig -d -u $mdstart + +mdconfig -a -t swap -s 1g -u $mdstart +bsdlabel -w md${mdstart} auto + +newfs -U md${mdstart}$part > /dev/null +mount /dev/md${mdstart}$part $mntpoint + +here=`pwd` +cd /tmp +sed '1,/^EOF/d' < $here/$0 > rename5.c +cc -o rename5 -Wall -Wextra -O2 rename5.c +rm -f rename5.c + +cd $mntpoint + +/tmp/rename5 + +cd $here +rm -f /tmp/rename5 + +while mount | grep -q md${mdstart}$part; do + umount $mntpoint || sleep 1 +done + +checkfs /dev/md${mdstart}$part + +mdconfig -d -u $mdstart +exit 0 +EOF +#include +#include +#include +#include +#include +#include +#include + +#define N 1000 + + +void +test(void) +{ + pid_t pid; + int i; + char from[128], to[128]; + + pid = getpid(); + for (i = 0; i < N; i++) { + snprintf(from, sizeof(from), "src/dir.%06d", i); + snprintf(to , sizeof(to), "src/dir.%06d.%06d", i, pid); + (void)rename(from, to); + } + _exit(0); +} + +int +main() +{ + int fd, i, j; + char dir[128], file[128]; + + for (j = 0; j < 50; j++) { + if (mkdir("src", 0700) == -1) + err(1, "mkdir(src)"); + + for (i = 0; i < N; i++) { + snprintf(dir, sizeof(dir), "src/dir.%06d", i); + if (mkdir(dir, 0700) == -1) + err(1, "mkdir(%s)", dir); + snprintf(file, sizeof(file), "%s/meta", dir); + if ((fd = open(file, O_RDWR | O_CREAT, 0600)) < 0) + err(1, "open(%s)", file); + close(fd); + snprintf(file, sizeof(file), "%s/data", dir); + if ((fd = open(file, O_RDWR | O_CREAT, 0600)) < 0) + err(1, "open(%s)", file); + close(fd); + } + + for (i = 0; i < 2; i++) { + if (fork() == 0) + test(); + } + for (i = 0; i < 2; i++) + wait(NULL); + + system("rm -rf src > /dev/null 2>&1"); + } + + return (0); +}