From owner-svn-src-user@FreeBSD.ORG Mon Dec 21 03:10:27 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 587D51065672; Mon, 21 Dec 2009 03:10:27 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 47F2E8FC18; Mon, 21 Dec 2009 03:10:27 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBL3ARXW082296; Mon, 21 Dec 2009 03:10:27 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBL3ARvY082294; Mon, 21 Dec 2009 03:10:27 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200912210310.nBL3ARvY082294@svn.freebsd.org> From: Kip Macy Date: Mon, 21 Dec 2009 03:10:27 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200762 - user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2009 03:10:27 -0000 Author: kmacy Date: Mon Dec 21 03:10:26 2009 New Revision: 200762 URL: http://svn.freebsd.org/changeset/base/200762 Log: align hash table locks Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Sun Dec 20 22:55:27 2009 (r200761) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Mon Dec 21 03:10:26 2009 (r200762) @@ -548,7 +548,7 @@ struct ht_lock { typedef struct buf_hash_table { uint64_t ht_mask; arc_buf_hdr_t **ht_table; - struct ht_lock ht_locks[BUF_LOCKS]; + struct ht_lock ht_locks[BUF_LOCKS] __aligned(128); } buf_hash_table_t; static buf_hash_table_t buf_hash_table; From owner-svn-src-user@FreeBSD.ORG Mon Dec 21 03:11:22 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 29CB6106568B; Mon, 21 Dec 2009 03:11:22 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 190508FC08; Mon, 21 Dec 2009 03:11:22 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBL3BL5a082366; Mon, 21 Dec 2009 03:11:21 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBL3BL2L082364; Mon, 21 Dec 2009 03:11:21 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200912210311.nBL3BL2L082364@svn.freebsd.org> From: Kip Macy Date: Mon, 21 Dec 2009 03:11:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200763 - user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2009 03:11:22 -0000 Author: kmacy Date: Mon Dec 21 03:11:21 2009 New Revision: 200763 URL: http://svn.freebsd.org/changeset/base/200763 Log: add function to determine if a buffer can be recycled within the ARC Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h Mon Dec 21 03:10:26 2009 (r200762) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h Mon Dec 21 03:11:21 2009 (r200763) @@ -420,6 +420,14 @@ extern int zio_handle_fault_injection(zi extern int zio_handle_device_injection(vdev_t *vd, int error); extern int zio_handle_label_injection(zio_t *zio, int error); + +static __inline int +zio_recycleable(int64_t size) +{ + + return ((size > 0) && (size & PAGE_MASK)); +} + #ifdef __cplusplus } #endif From owner-svn-src-user@FreeBSD.ORG Mon Dec 21 10:01:04 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E5091106566C; Mon, 21 Dec 2009 10:01:03 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D0CDC8FC08; Mon, 21 Dec 2009 10:01:03 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBLA13w1090606; Mon, 21 Dec 2009 10:01:03 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBLA13vV090583; Mon, 21 Dec 2009 10:01:03 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912211001.nBLA13vV090583@svn.freebsd.org> From: Luigi Rizzo Date: Mon, 21 Dec 2009 10:01:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200767 - in user/luigi/ipfw3-head: . cddl/contrib/opensolaris/cmd/zdb contrib/top lib/libjail share/man/man4 share/man/man9 sys/amd64/conf sys/boot/i386/libi386 sys/boot/pc98/libpc98 s... X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2009 10:01:04 -0000 Author: luigi Date: Mon Dec 21 10:01:03 2009 New Revision: 200767 URL: http://svn.freebsd.org/changeset/base/200767 Log: Merging r200605 through r200766 Added: user/luigi/ipfw3-head/usr.sbin/service/ - copied from r200766, head/usr.sbin/service/ Modified: user/luigi/ipfw3-head/UPDATING user/luigi/ipfw3-head/cddl/contrib/opensolaris/cmd/zdb/zdb_il.c user/luigi/ipfw3-head/lib/libjail/jail.c user/luigi/ipfw3-head/share/man/man4/mwlfw.4 user/luigi/ipfw3-head/share/man/man4/psm.4 user/luigi/ipfw3-head/share/man/man4/vge.4 user/luigi/ipfw3-head/share/man/man9/LOCK_PROFILING.9 user/luigi/ipfw3-head/sys/amd64/conf/NOTES user/luigi/ipfw3-head/sys/boot/i386/libi386/biosdisk.c user/luigi/ipfw3-head/sys/boot/pc98/libpc98/biosdisk.c user/luigi/ipfw3-head/sys/boot/uboot/lib/glue.c user/luigi/ipfw3-head/sys/cam/scsi/scsi_cd.c user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_object.c user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_send.c user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dnode.c user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c user/luigi/ipfw3-head/sys/compat/linux/linux_signal.c user/luigi/ipfw3-head/sys/conf/NOTES user/luigi/ipfw3-head/sys/dev/agp/agp_via.c user/luigi/ipfw3-head/sys/dev/ata/ata-pci.h user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-ite.c user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-promise.c user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-serverworks.c user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-via.c user/luigi/ipfw3-head/sys/dev/atkbdc/psm.c user/luigi/ipfw3-head/sys/dev/ciss/ciss.c user/luigi/ipfw3-head/sys/dev/e1000/if_igb.c user/luigi/ipfw3-head/sys/dev/hwpmc/hwpmc_intel.c user/luigi/ipfw3-head/sys/dev/ipmi/ipmi.c user/luigi/ipfw3-head/sys/dev/ips/ips_pci.c user/luigi/ipfw3-head/sys/dev/mii/ip1000phy.c user/luigi/ipfw3-head/sys/dev/usb/serial/u3g.c user/luigi/ipfw3-head/sys/dev/usb/usb_device.c user/luigi/ipfw3-head/sys/dev/usb/usb_dynamic.c user/luigi/ipfw3-head/sys/dev/usb/usb_dynamic.h user/luigi/ipfw3-head/sys/dev/usb/usbdevs user/luigi/ipfw3-head/sys/dev/usb/usbdi.h user/luigi/ipfw3-head/sys/dev/vge/if_vge.c user/luigi/ipfw3-head/sys/dev/vge/if_vgereg.h user/luigi/ipfw3-head/sys/dev/vge/if_vgevar.h user/luigi/ipfw3-head/sys/fs/devfs/devfs_vnops.c user/luigi/ipfw3-head/sys/i386/conf/NOTES user/luigi/ipfw3-head/sys/kern/kern_exit.c user/luigi/ipfw3-head/sys/kern/kern_proc.c user/luigi/ipfw3-head/sys/kern/subr_acl_nfs4.c user/luigi/ipfw3-head/sys/kern/subr_eventhandler.c user/luigi/ipfw3-head/sys/kern/subr_turnstile.c user/luigi/ipfw3-head/sys/kern/tty_pts.c user/luigi/ipfw3-head/sys/kern/uipc_syscalls.c user/luigi/ipfw3-head/sys/modules/ipfw/Makefile user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_table.c user/luigi/ipfw3-head/sys/pc98/conf/NOTES user/luigi/ipfw3-head/sys/powerpc/booke/clock.c user/luigi/ipfw3-head/sys/sys/proc.h user/luigi/ipfw3-head/usr.bin/calendar/calendars/calendar.all user/luigi/ipfw3-head/usr.bin/calendar/calendars/calendar.dutch user/luigi/ipfw3-head/usr.bin/calendar/io.c user/luigi/ipfw3-head/usr.bin/calendar/ostern.c user/luigi/ipfw3-head/usr.bin/make/arch.c user/luigi/ipfw3-head/usr.bin/make/make.c user/luigi/ipfw3-head/usr.bin/truss/main.c user/luigi/ipfw3-head/usr.bin/truss/syscalls.c user/luigi/ipfw3-head/usr.bin/uniq/uniq.1 user/luigi/ipfw3-head/usr.bin/uniq/uniq.c user/luigi/ipfw3-head/usr.bin/yacc/defs.h user/luigi/ipfw3-head/usr.sbin/Makefile user/luigi/ipfw3-head/usr.sbin/mergemaster/mergemaster.sh Directory Properties: user/luigi/ipfw3-head/ (props changed) user/luigi/ipfw3-head/cddl/contrib/opensolaris/ (props changed) user/luigi/ipfw3-head/contrib/bind9/ (props changed) user/luigi/ipfw3-head/contrib/cpio/ (props changed) user/luigi/ipfw3-head/contrib/csup/ (props changed) user/luigi/ipfw3-head/contrib/ee/ (props changed) user/luigi/ipfw3-head/contrib/expat/ (props changed) user/luigi/ipfw3-head/contrib/file/ (props changed) user/luigi/ipfw3-head/contrib/gdb/ (props changed) user/luigi/ipfw3-head/contrib/gdtoa/ (props changed) user/luigi/ipfw3-head/contrib/less/ (props changed) user/luigi/ipfw3-head/contrib/libpcap/ (props changed) user/luigi/ipfw3-head/contrib/ncurses/ (props changed) user/luigi/ipfw3-head/contrib/netcat/ (props changed) user/luigi/ipfw3-head/contrib/ntp/ (props changed) user/luigi/ipfw3-head/contrib/openbsm/ (props changed) user/luigi/ipfw3-head/contrib/openpam/ (props changed) user/luigi/ipfw3-head/contrib/pf/ (props changed) user/luigi/ipfw3-head/contrib/sendmail/ (props changed) user/luigi/ipfw3-head/contrib/tcpdump/ (props changed) user/luigi/ipfw3-head/contrib/tcsh/ (props changed) user/luigi/ipfw3-head/contrib/top/ (props changed) user/luigi/ipfw3-head/contrib/top/install-sh (props changed) user/luigi/ipfw3-head/contrib/wpa/ (props changed) user/luigi/ipfw3-head/crypto/openssh/ (props changed) user/luigi/ipfw3-head/crypto/openssl/ (props changed) user/luigi/ipfw3-head/lib/libc/ (props changed) user/luigi/ipfw3-head/lib/libc/stdtime/ (props changed) user/luigi/ipfw3-head/lib/libutil/ (props changed) user/luigi/ipfw3-head/sbin/ (props changed) user/luigi/ipfw3-head/sbin/ipfw/ (props changed) user/luigi/ipfw3-head/share/zoneinfo/ (props changed) user/luigi/ipfw3-head/sys/ (props changed) user/luigi/ipfw3-head/sys/amd64/include/xen/ (props changed) user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/ (props changed) user/luigi/ipfw3-head/sys/contrib/dev/acpica/ (props changed) user/luigi/ipfw3-head/sys/contrib/pf/ (props changed) user/luigi/ipfw3-head/sys/dev/xen/xenpci/ (props changed) user/luigi/ipfw3-head/usr.bin/csup/ (props changed) user/luigi/ipfw3-head/usr.bin/procstat/ (props changed) user/luigi/ipfw3-head/usr.sbin/zic/ (props changed) Modified: user/luigi/ipfw3-head/UPDATING ============================================================================== --- user/luigi/ipfw3-head/UPDATING Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/UPDATING Mon Dec 21 10:01:03 2009 (r200767) @@ -22,6 +22,19 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 9. machines to maximize performance. (To disable malloc debugging, run ln -s aj /etc/malloc.conf.) +20091202: + The rc.firewall and rc.firewall6 were unified, and + rc.firewall6 and rc.d/ip6fw were removed. + According to the removal of rc.d/ip6fw, ipv6_firewall_* rc + variables are obsoleted. Instead, the following new rc + variables are added to rc.d/ipfw: + + firewall_client_net_ipv6, firewall_simple_iif_ipv6, + firewall_simple_inet_ipv6, firewall_simple_oif_ipv6, + firewall_simple_onet_ipv6, firewall_trusted_ipv6 + + The meanings correspond to the relevant IPv4 variables. + 20091113: The default terminal emulation for syscons(4) has been changed from cons25 to xterm on all platforms except pc98. This means Modified: user/luigi/ipfw3-head/cddl/contrib/opensolaris/cmd/zdb/zdb_il.c ============================================================================== --- user/luigi/ipfw3-head/cddl/contrib/opensolaris/cmd/zdb/zdb_il.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/cddl/contrib/opensolaris/cmd/zdb/zdb_il.c Mon Dec 21 10:01:03 2009 (r200767) @@ -19,12 +19,10 @@ * CDDL HEADER END */ /* - * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * Print intent log header and statistics. */ @@ -345,8 +343,10 @@ dump_intent_log(zilog_t *zilog) if (zh->zh_log.blk_birth == 0 || verbose < 2) return; - (void) printf("\n ZIL header: claim_txg %llu, seq %llu\n", - (u_longlong_t)zh->zh_claim_txg, (u_longlong_t)zh->zh_replay_seq); + (void) printf("\n ZIL header: claim_txg %llu, claim_seq %llu", + (u_longlong_t)zh->zh_claim_txg, (u_longlong_t)zh->zh_claim_seq); + (void) printf(" replay_seq %llu, flags 0x%llx\n", + (u_longlong_t)zh->zh_replay_seq, (u_longlong_t)zh->zh_flags); if (verbose >= 4) print_log_bp(&zh->zh_log, "\n\tfirst block: "); Modified: user/luigi/ipfw3-head/lib/libjail/jail.c ============================================================================== --- user/luigi/ipfw3-head/lib/libjail/jail.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/lib/libjail/jail.c Mon Dec 21 10:01:03 2009 (r200767) @@ -532,7 +532,7 @@ jailparam_get(struct jailparam *jp, unsi } jp_key = jp_lastjid ? jp_lastjid : jp_jid && jp_jid->jp_valuelen == sizeof(int) && - *(int *)jp_jid->jp_value ? jp_jid : jp_name; + jp_jid->jp_value && *(int *)jp_jid->jp_value ? jp_jid : jp_name; if (jp_key == NULL || jp_key->jp_value == NULL) { strlcpy(jail_errmsg, "no jail specified", JAIL_ERRMSGLEN); errno = ENOENT; Modified: user/luigi/ipfw3-head/share/man/man4/mwlfw.4 ============================================================================== --- user/luigi/ipfw3-head/share/man/man4/mwlfw.4 Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/share/man/man4/mwlfw.4 Mon Dec 21 10:01:03 2009 (r200767) @@ -49,4 +49,4 @@ It may be statically linked into the kernel, or loaded as a module. .Sh SEE ALSO .Xr mwl 4 , -.Xr firmware 8 +.Xr firmware 9 Modified: user/luigi/ipfw3-head/share/man/man4/psm.4 ============================================================================== --- user/luigi/ipfw3-head/share/man/man4/psm.4 Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/share/man/man4/psm.4 Mon Dec 21 10:01:03 2009 (r200767) @@ -359,6 +359,18 @@ at boot-time. This will enable .Nm to handle packets from guest devices (sticks) and extra buttons. +.Pp +Tap and drag gestures can be disabled by setting +.Va hw.psm.tap_enabled +to +.Em 0 +at boot-time. +Currently, this is only supported on Synaptics touchpads with Extended +support disabled. The behaviour may be changed after boot by setting +the sysctl with the same name and by restarting +.Xr moused 8 +using +.Pa /etc/rc.d/moused . .Sh IOCTLS There are a few .Xr ioctl 2 Modified: user/luigi/ipfw3-head/share/man/man4/vge.4 ============================================================================== --- user/luigi/ipfw3-head/share/man/man4/vge.4 Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/share/man/man4/vge.4 Mon Dec 21 10:01:03 2009 (r200767) @@ -30,12 +30,12 @@ .\" .\" $FreeBSD$ .\" -.Dd February 21, 2007 +.Dd December 18, 2009 .Dt VGE 4 .Os .Sh NAME .Nm vge -.Nd "VIA Networking Technologies VT6122 PCI Gigabit Ethernet adapter driver" +.Nd "VIA Networking Technologies Velocity Gigabit Ethernet adapter driver" .Sh SYNOPSIS To compile this driver into the kernel, place the following lines in your @@ -55,22 +55,23 @@ if_vge_load="YES" The .Nm driver provides support for various NICs and embedded Ethernet interfaces -based on the VIA Networking Technologies VT6122 Gigabit Ethernet -controller chips. +based on the VIA Technologies VT6120, VT6122, VT6130 and VT6132 Velocity +Family Gigabit Ethernet controller chips. .Pp -The VT6122 is a 33/66Mhz 64-bit PCI device which combines a tri-speed MAC with -an integrated 10/100/1000 copper PHY. +The VT6120/VT6122 is a 33/66Mhz 64-bit PCI device which combines a tri-speed +MAC with an integrated 10/100/1000 copper PHY. (Some older cards use an external PHY.) +The VT6130/VT6132 is the PCI express version of Velocity family. The MAC supports TCP/IP hardware checksums (IPv4 only), TCP large send, VLAN tag insertion and stripping, as well as VLAN filtering, a 64-entry CAM filter and a 64-entry VLAN filter, 64-bit multicast hash filter, 4 separate transmit DMA queues, flow control and jumbo frames up to 16K in size. -The VT6122 has a 16K receive FIFO and 48K transmit FIFO. +The Velocity family controllers have a 16K receive FIFO and 48K transmit FIFO. .Pp The .Nm -driver takes advantage of the VT6122's checksum offload and VLAN +driver takes advantage of the controller's checksum offload and VLAN tagging features, as well as the jumbo frame and CAM filter support. The CAM filter is used for multicast address filtering to provide 64 perfect multicast address filter support. @@ -162,7 +163,7 @@ For more information on configuring this .Sh HARDWARE The .Nm -driver supports VIA Networking VT3119 and VT6122 based +driver supports VIA Networking VT6120, VT6122, VT6130 and VT6132 based Gigabit Ethernet adapters including: .Pp .Bl -bullet -compact @@ -173,6 +174,38 @@ ZyXEL GN650-T 64-bit PCI Gigabit Etherne .It ZyXEL GN670-T 32-bit PCI Gigabit Ethernet NIC (ZX1702) .El +.Sh LOADER TUNABLES +Tunables can be set at the +.Xr loader 8 +prompt before booting the kernel or stored in +.Xr loader.conf 5 . +.Bl -tag -width "xxxxxx" +.It Va hw.vge.msi_disable +This tunable disables MSI support on the Ethernet hardware. +The default value is 0. +.El +.Sh SYSCTL VARIABLES +The following variables are available as both +.Xr sysctl 8 +variables and +.Xr loader 8 +tunables: +.Bl -tag -width "xxxxxx" +.It Va dev.vge.%d.int_holdoff +Maximum number of time to delay interrupts. +The valid range is 0 to 5100 in units of 1us, the default is +150 (150us). +The resolution of of timer is about 20us so finer tuning than +20us wouldn't be available. +The interface should be brought down and up again before a change +takes effect. +.It Va dev.vge.%d.rx_coal_pkt +Maximum number of packets to fire Rx completion interrupt. +The valid range is 1 to 255, the default is 64. +.It Va dev.vge.%d.tx_coal_pkt +Maximum number of packets to fire Tx completion interrupt. +The valid range is 1 to 255, the default is 128. +.El .Sh DIAGNOSTICS .Bl -diag .It "vge%d: couldn't map memory" Modified: user/luigi/ipfw3-head/share/man/man9/LOCK_PROFILING.9 ============================================================================== --- user/luigi/ipfw3-head/share/man/man9/LOCK_PROFILING.9 Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/share/man/man9/LOCK_PROFILING.9 Mon Dec 21 10:01:03 2009 (r200767) @@ -114,6 +114,8 @@ The columns are as follows, from left to .Bl -tag -width ".Va cnt_hold" .It Va max The longest continuous hold time in microseconds. +.It Va wait_max +The longest continuous wait time in microseconds. .It Va total The total (accumulated) hold time in microseconds. .It Va wait_total Modified: user/luigi/ipfw3-head/sys/amd64/conf/NOTES ============================================================================== --- user/luigi/ipfw3-head/sys/amd64/conf/NOTES Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/amd64/conf/NOTES Mon Dec 21 10:01:03 2009 (r200767) @@ -277,7 +277,6 @@ options DRM_DEBUG # Include debug print # iwn: Intel Wireless WiFi Link 4965AGN 802.11 network adapters # nfe: nVidia nForce MCP on-board Ethernet Networking (BSD open source) # nve: nVidia nForce MCP on-board Ethernet Networking -# ral: Ralink Technology IEEE 802.11 wireless adapter # wpi: Intel 3945ABG Wireless LAN controller device ed @@ -289,16 +288,8 @@ device iwn device ipw device nfe device nve -device ral device wpi -device ath # Atheros pci/cardbus NIC's -device ath_hal # pci/cardbus chip support -options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors -device ath_rate_sample # SampleRate tx rate control for ath -#device ath_rate_amrr # AMRR rate control for ath driver -#device ath_rate_onoe # Onoe rate control for ath driver - # #XXX this stores pointers in a 32bit field that is defined by the hardware #device pst Modified: user/luigi/ipfw3-head/sys/boot/i386/libi386/biosdisk.c ============================================================================== --- user/luigi/ipfw3-head/sys/boot/i386/libi386/biosdisk.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/boot/i386/libi386/biosdisk.c Mon Dec 21 10:01:03 2009 (r200767) @@ -1266,11 +1266,11 @@ bd_io(struct open_disk *od, daddr_t dblk } if (write) - DEBUG("%d sectors from %lld to %p (0x%x) %s", x, dblk, p, VTOP(p), - result ? "failed" : "ok"); + DEBUG("Write %d sector(s) from %p (0x%x) to %lld %s", x, + p, VTOP(p), dblk, result ? "failed" : "ok"); else - DEBUG("%d sectors from %p (0x%x) to %lld %s", x, p, VTOP(p), dblk, - result ? "failed" : "ok"); + DEBUG("Read %d sector(s) from %lld to %p (0x%x) %s", x, + dblk, p, VTOP(p), result ? "failed" : "ok"); if (result) { return(-1); } Modified: user/luigi/ipfw3-head/sys/boot/pc98/libpc98/biosdisk.c ============================================================================== --- user/luigi/ipfw3-head/sys/boot/pc98/libpc98/biosdisk.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/boot/pc98/libpc98/biosdisk.c Mon Dec 21 10:01:03 2009 (r200767) @@ -906,11 +906,11 @@ bd_io(struct open_disk *od, daddr_t dblk } if (write) - DEBUG("%d sectors from %lld to %p (0x%x) %s", x, dblk, p, VTOP(p), - result ? "failed" : "ok"); + DEBUG("Write %d sector(s) from %p (0x%x) to %lld %s", x, + p, VTOP(p), dblk, result ? "failed" : "ok"); else - DEBUG("%d sectors from %p (0x%x) to %lld %s", x, p, VTOP(p), dblk, - result ? "failed" : "ok"); + DEBUG("Read %d sector(s) from %lld to %p (0x%x) %s", x, + dblk, p, VTOP(p), result ? "failed" : "ok"); if (result) { return(-1); } Modified: user/luigi/ipfw3-head/sys/boot/uboot/lib/glue.c ============================================================================== --- user/luigi/ipfw3-head/sys/boot/uboot/lib/glue.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/boot/uboot/lib/glue.c Mon Dec 21 10:01:03 2009 (r200767) @@ -568,17 +568,16 @@ ub_env_enum(const char *last) const char *env, *str; int i; - env = NULL; - /* * It's OK to pass only the name piece as last (and not the whole * 'name=val' string), since the API_ENUM_ENV call uses envmatch() * internally, which handles such case */ - if (!syscall(API_ENV_ENUM, NULL, (uint32_t)last, (uint32_t)&env)) + env = NULL; + if (syscall(API_ENV_ENUM, NULL, (uint32_t)last, (uint32_t)&env) != 0) return (NULL); - if (!env) + if (env == NULL) /* no more env. variables to enumerate */ return (NULL); Modified: user/luigi/ipfw3-head/sys/cam/scsi/scsi_cd.c ============================================================================== --- user/luigi/ipfw3-head/sys/cam/scsi/scsi_cd.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/cam/scsi/scsi_cd.c Mon Dec 21 10:01:03 2009 (r200767) @@ -1464,8 +1464,6 @@ cdstart(struct cam_periph *periph, union } else { bioq_remove(&softc->bio_queue, bp); - devstat_start_transaction_bio(softc->disk->d_devstat, bp); - scsi_read_write(&start_ccb->csio, /*retries*/cd_retry_count, /* cbfcnp */ cddone, Modified: user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_object.c ============================================================================== --- user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_object.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_object.c Mon Dec 21 10:01:03 2009 (r200767) @@ -19,12 +19,10 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include #include #include @@ -108,19 +106,51 @@ dmu_object_claim(objset_t *os, uint64_t int dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot, - int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx) + int blocksize, dmu_object_type_t bonustype, int bonuslen) { dnode_t *dn; + dmu_tx_t *tx; + int nblkptr; int err; - if (object == DMU_META_DNODE_OBJECT && !dmu_tx_private_ok(tx)) + if (object == DMU_META_DNODE_OBJECT) return (EBADF); err = dnode_hold_impl(os->os, object, DNODE_MUST_BE_ALLOCATED, FTAG, &dn); if (err) return (err); + + if (dn->dn_type == ot && dn->dn_datablksz == blocksize && + dn->dn_bonustype == bonustype && dn->dn_bonuslen == bonuslen) { + /* nothing is changing, this is a noop */ + dnode_rele(dn, FTAG); + return (0); + } + + tx = dmu_tx_create(os); + dmu_tx_hold_bonus(tx, object); + err = dmu_tx_assign(tx, TXG_WAIT); + if (err) { + dmu_tx_abort(tx); + dnode_rele(dn, FTAG); + return (err); + } + + nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT); + + /* + * If we are losing blkptrs or changing the block size this must + * be a new file instance. We must clear out the previous file + * contents before we can change this type of metadata in the dnode. + */ + if (dn->dn_nblkptr > nblkptr || dn->dn_datablksz != blocksize) + dmu_free_long_range(os, object, 0, DMU_OBJECT_END); + dnode_reallocate(dn, ot, blocksize, bonustype, bonuslen, tx); + + dmu_tx_commit(tx); + dnode_rele(dn, FTAG); return (0); Modified: user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_send.c ============================================================================== --- user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_send.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dmu_send.c Mon Dec 21 10:01:03 2009 (r200767) @@ -828,11 +828,7 @@ restore_object(struct restorearg *ra, ob { int err; dmu_tx_t *tx; - - err = dmu_object_info(os, drro->drr_object, NULL); - - if (err != 0 && err != ENOENT) - return (EINVAL); + void *data = NULL; if (drro->drr_type == DMU_OT_NONE || drro->drr_type >= DMU_OT_NUMTYPES || @@ -846,12 +842,15 @@ restore_object(struct restorearg *ra, ob return (EINVAL); } - tx = dmu_tx_create(os); + err = dmu_object_info(os, drro->drr_object, NULL); + + if (err != 0 && err != ENOENT) + return (EINVAL); if (err == ENOENT) { /* currently free, want to be allocated */ + tx = dmu_tx_create(os); dmu_tx_hold_bonus(tx, DMU_NEW_OBJECT); - dmu_tx_hold_write(tx, DMU_NEW_OBJECT, 0, 1); err = dmu_tx_assign(tx, TXG_WAIT); if (err) { dmu_tx_abort(tx); @@ -860,45 +859,41 @@ restore_object(struct restorearg *ra, ob err = dmu_object_claim(os, drro->drr_object, drro->drr_type, drro->drr_blksz, drro->drr_bonustype, drro->drr_bonuslen, tx); + dmu_tx_commit(tx); } else { /* currently allocated, want to be allocated */ - dmu_tx_hold_bonus(tx, drro->drr_object); - /* - * We may change blocksize and delete old content, - * so need to hold_write and hold_free. - */ - dmu_tx_hold_write(tx, drro->drr_object, 0, 1); - dmu_tx_hold_free(tx, drro->drr_object, 0, DMU_OBJECT_END); - err = dmu_tx_assign(tx, TXG_WAIT); - if (err) { - dmu_tx_abort(tx); - return (err); - } err = dmu_object_reclaim(os, drro->drr_object, drro->drr_type, drro->drr_blksz, - drro->drr_bonustype, drro->drr_bonuslen, tx); + drro->drr_bonustype, drro->drr_bonuslen); } - if (err) { - dmu_tx_commit(tx); + if (err) return (EINVAL); + + if (drro->drr_bonuslen) { + data = restore_read(ra, P2ROUNDUP(drro->drr_bonuslen, 8)); + if (ra->err) + return (ra->err); + } + + tx = dmu_tx_create(os); + dmu_tx_hold_bonus(tx, drro->drr_object); + err = dmu_tx_assign(tx, TXG_WAIT); + if (err) { + dmu_tx_abort(tx); + return (err); } dmu_object_set_checksum(os, drro->drr_object, drro->drr_checksum, tx); dmu_object_set_compress(os, drro->drr_object, drro->drr_compress, tx); - if (drro->drr_bonuslen) { + if (data != NULL) { dmu_buf_t *db; - void *data; + VERIFY(0 == dmu_bonus_hold(os, drro->drr_object, FTAG, &db)); dmu_buf_will_dirty(db, tx); ASSERT3U(db->db_size, >=, drro->drr_bonuslen); - data = restore_read(ra, P2ROUNDUP(drro->drr_bonuslen, 8)); - if (data == NULL) { - dmu_tx_commit(tx); - return (ra->err); - } bcopy(data, db->db_data, drro->drr_bonuslen); if (ra->byteswap) { dmu_ot[drro->drr_bonustype].ot_byteswap(db->db_data, Modified: user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dnode.c ============================================================================== --- user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dnode.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/dnode.c Mon Dec 21 10:01:03 2009 (r200767) @@ -415,8 +415,7 @@ void dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx) { - int i, nblkptr; - dmu_buf_impl_t *db = NULL; + int nblkptr; ASSERT3U(blocksize, >=, SPA_MINBLOCKSIZE); ASSERT3U(blocksize, <=, SPA_MAXBLOCKSIZE); @@ -428,42 +427,25 @@ dnode_reallocate(dnode_t *dn, dmu_object ASSERT3U(bonustype, <, DMU_OT_NUMTYPES); ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN); - for (i = 0; i < TXG_SIZE; i++) - ASSERT(!list_link_active(&dn->dn_dirty_link[i])); - /* clean up any unreferenced dbufs */ dnode_evict_dbufs(dn); - ASSERT3P(list_head(&dn->dn_dbufs), ==, NULL); - - /* - * XXX I should really have a generation number to tell if we - * need to do this... - */ - if (blocksize != dn->dn_datablksz || - dn->dn_bonustype != bonustype || dn->dn_bonuslen != bonuslen) { - /* free all old data */ - dnode_free_range(dn, 0, -1ULL, tx); - } - - nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT); - /* change blocksize */ rw_enter(&dn->dn_struct_rwlock, RW_WRITER); - if (blocksize != dn->dn_datablksz && - (!BP_IS_HOLE(&dn->dn_phys->dn_blkptr[0]) || - list_head(&dn->dn_dbufs) != NULL)) { - db = dbuf_hold(dn, 0, FTAG); - dbuf_new_size(db, blocksize, tx); - } - dnode_setdblksz(dn, blocksize); dnode_setdirty(dn, tx); - dn->dn_next_bonuslen[tx->tx_txg&TXG_MASK] = bonuslen; - dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = blocksize; + if (dn->dn_datablksz != blocksize) { + /* change blocksize */ + ASSERT(dn->dn_maxblkid == 0 && + (BP_IS_HOLE(&dn->dn_phys->dn_blkptr[0]) || + dnode_block_freed(dn, 0))); + dnode_setdblksz(dn, blocksize); + dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = blocksize; + } + if (dn->dn_bonuslen != bonuslen) + dn->dn_next_bonuslen[tx->tx_txg&TXG_MASK] = bonuslen; + nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT); if (dn->dn_nblkptr != nblkptr) dn->dn_next_nblkptr[tx->tx_txg&TXG_MASK] = nblkptr; rw_exit(&dn->dn_struct_rwlock); - if (db) - dbuf_rele(db, FTAG); /* change type */ dn->dn_type = ot; @@ -1187,11 +1169,6 @@ dnode_block_freed(dnode_t *dn, uint64_t if (dn->dn_free_txg) return (TRUE); - /* - * If dn_datablkshift is not set, then there's only a single - * block, in which case there will never be a free range so it - * won't matter. - */ range_tofind.fr_blkid = blkid; mutex_enter(&dn->dn_mtx); for (i = 0; i < TXG_SIZE; i++) { Modified: user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h ============================================================================== --- user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/dmu.h Mon Dec 21 10:01:03 2009 (r200767) @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -237,7 +237,7 @@ uint64_t dmu_object_alloc(objset_t *os, int dmu_object_claim(objset_t *os, uint64_t object, dmu_object_type_t ot, int blocksize, dmu_object_type_t bonus_type, int bonus_len, dmu_tx_t *tx); int dmu_object_reclaim(objset_t *os, uint64_t object, dmu_object_type_t ot, - int blocksize, dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); + int blocksize, dmu_object_type_t bonustype, int bonuslen); /* * Free an object from this objset. Modified: user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h ============================================================================== --- user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zil.h Mon Dec 21 10:01:03 2009 (r200767) @@ -19,7 +19,7 @@ * CDDL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ @@ -56,10 +56,16 @@ typedef struct zil_header { uint64_t zh_replay_seq; /* highest replayed sequence number */ blkptr_t zh_log; /* log chain */ uint64_t zh_claim_seq; /* highest claimed sequence number */ - uint64_t zh_pad[5]; + uint64_t zh_flags; /* header flags */ + uint64_t zh_pad[4]; } zil_header_t; /* + * zh_flags bit settings + */ +#define ZIL_REPLAY_NEEDED 0x1 /* replay needed - internal only */ + +/* * Log block trailer - structure at the end of the header and each log block * * The zit_bt contains a zbt_cksum which for the intent log is Modified: user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c ============================================================================== --- user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zil.c Mon Dec 21 10:01:03 2009 (r200767) @@ -502,6 +502,25 @@ zil_rollback_destroy(zilog_t *zilog, dmu tx, zh->zh_claim_txg); } +/* + * return true if the initial log block is not valid + */ +static boolean_t +zil_empty(zilog_t *zilog) +{ + const zil_header_t *zh = zilog->zl_header; + arc_buf_t *abuf = NULL; + + if (BP_IS_HOLE(&zh->zh_log)) + return (B_TRUE); + + if (zil_read_log_block(zilog, &zh->zh_log, &abuf) != 0) + return (B_TRUE); + + VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1); + return (B_FALSE); +} + int zil_claim(char *osname, void *txarg) { @@ -522,6 +541,21 @@ zil_claim(char *osname, void *txarg) zh = zil_header_in_syncing_context(zilog); /* + * Record here whether the zil has any records to replay. + * If the header block pointer is null or the block points + * to the stubby then we know there are no valid log records. + * We use the header to store this state as the the zilog gets + * freed later in dmu_objset_close(). + * The flags (and the rest of the header fields) are cleared in + * zil_sync() as a result of a zil_destroy(), after replaying the log. + * + * Note, the intent log can be empty but still need the + * stubby to be claimed. + */ + if (!zil_empty(zilog)) + zh->zh_flags |= ZIL_REPLAY_NEEDED; + + /* * Claim all log blocks if we haven't already done so, and remember * the highest claimed sequence number. This ensures that if we can * read only part of the log now (e.g. due to a missing device), @@ -1345,25 +1379,6 @@ zil_free(zilog_t *zilog) } /* - * return true if the initial log block is not valid - */ -static boolean_t -zil_empty(zilog_t *zilog) -{ - const zil_header_t *zh = zilog->zl_header; - arc_buf_t *abuf = NULL; - - if (BP_IS_HOLE(&zh->zh_log)) - return (B_TRUE); - - if (zil_read_log_block(zilog, &zh->zh_log, &abuf) != 0) - return (B_TRUE); - - VERIFY(arc_buf_remove_ref(abuf, &abuf) == 1); - return (B_FALSE); -} - -/* * Open an intent log. */ zilog_t * @@ -1418,7 +1433,7 @@ zil_suspend(zilog_t *zilog) const zil_header_t *zh = zilog->zl_header; mutex_enter(&zilog->zl_lock); - if (zh->zh_claim_txg != 0) { /* unplayed log */ + if (zh->zh_flags & ZIL_REPLAY_NEEDED) { /* unplayed log */ mutex_exit(&zilog->zl_lock); return (EBUSY); } @@ -1645,7 +1660,7 @@ zil_replay(objset_t *os, void *arg, uint const zil_header_t *zh = zilog->zl_header; zil_replay_arg_t zr; - if (zil_empty(zilog)) { + if ((zh->zh_flags & ZIL_REPLAY_NEEDED) == 0) { zil_destroy(zilog, B_TRUE); return; } Modified: user/luigi/ipfw3-head/sys/compat/linux/linux_signal.c ============================================================================== --- user/luigi/ipfw3-head/sys/compat/linux/linux_signal.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/compat/linux/linux_signal.c Mon Dec 21 10:01:03 2009 (r200767) @@ -565,7 +565,7 @@ linux_do_tkill(struct thread *td, l_int AUDIT_ARG_PROCESS(p); error = p_cansignal(td, p, signum); - if (error) + if (error != 0 || signum == 0) goto out; error = ESRCH; Modified: user/luigi/ipfw3-head/sys/conf/NOTES ============================================================================== --- user/luigi/ipfw3-head/sys/conf/NOTES Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/conf/NOTES Mon Dec 21 10:01:03 2009 (r200767) @@ -1812,14 +1812,47 @@ device puc # # Network interfaces: # -# MII bus support is required for some PCI 10/100 ethernet NICs, +# MII bus support is required for many PCI Ethernet NICs, # namely those which use MII-compliant transceivers or implement -# transceiver control interfaces that operate like an MII. Adding +# transceiver control interfaces that operate like an MII. Adding # "device miibus" to the kernel config pulls in support for # the generic miibus API and all of the PHY drivers, including a # generic one for PHYs that aren't specifically handled by an -# individual driver. -device miibus +# individual driver. Support for specific PHYs may be built by adding +# "device mii" then adding the appropriate PHY driver. +device miibus # MII support including all PHYs +device mii # Minimal MII support + +device acphy # Altima Communications AC101 +device amphy # AMD AM79c873 / Davicom DM910{1,2} +device atphy # Attansic/Atheros F1 +device axphy # Asix Semiconductor AX88x9x +device bmtphy # Broadcom BCM5201/BCM5202 and 3Com 3c905C +device brgphy # Broadcom BCM54xx/57xx 1000baseTX +device ciphy # Cicada/Vitesse CS/VSC8xxx +device e1000phy # Marvell 88E1000 1000/100/10-BT +device exphy # 3Com internal PHY +device gentbi # Generic 10-bit 1000BASE-{LX,SX} fiber ifaces +device icsphy # ICS ICS1889-1893 +device inphy # Intel 82553/82555 +device ip1000phy # IC Plus IP1000A/IP1001 +device jmphy # JMicron JMP211/JMP202 +device lxtphy # Level One LXT-970 +device mlphy # Micro Linear 6692 +device nsgphy # NatSemi DP8361/DP83865/DP83891 +device nsphy # NatSemi DP83840A +device nsphyter # NatSemi DP83843/DP83815 +device pnaphy # HomePNA +device qsphy # Quality Semiconductor QS6612 +device rgephy # RealTek 8169S/8110S/8211B/8211C +device rlphy # RealTek 8139 +device rlswitch # RealTek 8305 +device ruephy # RealTek RTL8150 +device smcphy # SMSC LAN91C111 +device tdkphy # TDK 89Q2120 +device tlphy # Texas Instruments ThunderLAN +device truephy # LSI TruePHY +device xmphy # XaQti XMAC II # an: Aironet 4500/4800 802.11 wireless adapters. Supports the PCMCIA, # PCI and ISA varieties. @@ -1829,6 +1862,7 @@ device miibus # L1 PCI express gigabit ethernet controllers. # alc: Support for Atheros AR8131/AR8132 PCIe ethernet controllers. # ale: Support for Atheros AR8121/AR8113/AR8114 PCIe ethernet controllers. +# ath: Atheros a/b/g WiFi adapters (requires ath_hal and wlan) # bce: Broadcom NetXtreme II (BCM5706/BCM5708) PCI/PCIe Gigabit Ethernet # adapters. # bfe: Broadcom BCM4401 Ethernet adapter. @@ -1887,6 +1921,7 @@ device miibus # pcn(4) driver is left out of the kernel. The le(4) driver does not # support the additional features like the MII bus and burst mode of # the PCnet-FAST and greater chipsets though. +# ral: Ralink Technology IEEE 802.11 wireless adapter # re: RealTek 8139C+/8169/816xS/811xS/8101E PCI/PCIe Ethernet adapter # rl: Support for PCI fast ethernet adapters based on the RealTek 8129/8139 # chipset. Note that the RealTek driver defaults to using programmed @@ -2006,7 +2041,6 @@ device wb # Winbond W89C840F device xl # 3Com 3c90x (``Boomerang'', ``Cyclone'') # PCI Ethernet NICs. -device bwi # Broadcom BCM430* BCM431* device de # DEC/Intel DC21x4x (``Tulip'') device em # Intel Pro/1000 Gigabit Ethernet device igb # Intel Pro/1000 PCIE Gigabit Ethernet @@ -2025,6 +2059,26 @@ device fpa # PCI WAN adapters. device lmc +# PCI IEEE 802.11 Wireless NICs +device ath # Atheros pci/cardbus NIC's +device ath_hal # pci/cardbus chip support +#device ath_ar5210 # AR5210 chips +#device ath_ar5211 # AR5211 chips +#device ath_ar5212 # AR5212 chips +#device ath_rf2413 +#device ath_rf2417 +#device ath_rf2425 +#device ath_rf5111 +#device ath_rf5112 +#device ath_rf5413 +#device ath_ar5416 # AR5416 chips +options AH_SUPPORT_AR5416 # enable AR5416 tx/rx descriptors +#device ath_ar9160 # AR9160 chips +#device ath_ar9280 # AR9280 chips +device ath_rate_sample # SampleRate tx rate control for ath +device bwi # Broadcom BCM430* BCM431* +device ral # Ralink Technology RT2500 wireless NICs. + # Use "private" jumbo buffers allocated exclusively for the ti(4) driver. # This option is incompatible with the TI_JUMBO_HDRSPLIT option below. #options TI_PRIVATE_JUMBOS Modified: user/luigi/ipfw3-head/sys/dev/agp/agp_via.c ============================================================================== --- user/luigi/ipfw3-head/sys/dev/agp/agp_via.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/dev/agp/agp_via.c Mon Dec 21 10:01:03 2009 (r200767) @@ -165,39 +165,16 @@ agp_via_attach(device_t dev) struct agp_gatt *gatt; int error; u_int32_t agpsel; + u_int32_t capid; - /* XXX: This should be keying off of whether the bridge is AGP3 capable, - * rather than a bunch of device ids for chipsets that happen to do 8x. - */ - switch (pci_get_devid(dev)) { - case 0x01981106: - case 0x02591106: - case 0x02691106: - case 0x02961106: - case 0x03141106: - case 0x03241106: - case 0x03271106: - case 0x03641106: - case 0x31231106: - case 0x31681106: - case 0x31891106: - case 0x32051106: - case 0x32581106: - case 0xb1981106: - /* The newer VIA chipsets will select the AGP version based on - * what AGP versions the card supports. We still have to - * program it using the v2 registers if it has chosen to use - * compatibility mode. - */ + sc->regs = via_v2_regs; + + /* Look at the capability register to see if we handle AGP3 */ + capid = pci_read_config(dev, agp_find_caps(dev) + AGP_CAPID, 4); + if (((capid >> 20) & 0x0f) >= 3) { agpsel = pci_read_config(dev, AGP_VIA_AGPSEL, 1); if ((agpsel & (1 << 1)) == 0) sc->regs = via_v3_regs; - else - sc->regs = via_v2_regs; - break; - default: - sc->regs = via_v2_regs; - break; } error = agp_generic_attach(dev); @@ -235,7 +212,7 @@ agp_via_attach(device_t dev) pci_write_config(dev, sc->regs[REG_ATTBASE], gatt->ag_physical, 4); /* Enable the aperture. */ - gartctrl = pci_read_config(dev, sc->regs[REG_ATTBASE], 4); + gartctrl = pci_read_config(dev, sc->regs[REG_GARTCTRL], 4); pci_write_config(dev, sc->regs[REG_GARTCTRL], gartctrl | (3 << 7), 4); } @@ -268,7 +245,7 @@ agp_via_get_aperture(device_t dev) u_int32_t apsize; if (sc->regs == via_v2_regs) { - apsize = pci_read_config(dev, sc->regs[REG_APSIZE], 1) & 0x1f; + apsize = pci_read_config(dev, sc->regs[REG_APSIZE], 1); /* * The size is determined by the number of low bits of @@ -295,8 +272,14 @@ agp_via_get_aperture(device_t dev) return 0x04000000; case 0xf38: return 0x02000000; + case 0xf3c: + return 0x01000000; + case 0xf3e: + return 0x00800000; + case 0xf3f: + return 0x00400000; default: - device_printf(dev, "Invalid aperture setting 0x%x", + device_printf(dev, "Invalid aperture setting 0x%x\n", pci_read_config(dev, sc->regs[REG_APSIZE], 2)); return 0; } @@ -345,6 +328,15 @@ agp_via_set_aperture(device_t dev, u_int case 0x02000000: key = 0xf38; break; + case 0x01000000: + key = 0xf3c; + break; + case 0x00800000: + key = 0xf3e; + break; + case 0x00400000: + key = 0xf3f; + break; default: device_printf(dev, "Invalid aperture size (%dMb)\n", aperture / 1024 / 1024); Modified: user/luigi/ipfw3-head/sys/dev/ata/ata-pci.h ============================================================================== --- user/luigi/ipfw3-head/sys/dev/ata/ata-pci.h Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/dev/ata/ata-pci.h Mon Dec 21 10:01:03 2009 (r200767) @@ -482,6 +482,11 @@ struct ata_pci_controller { #define ATA_VIA6410 0x31641106 #define ATA_VIA6420 0x31491106 #define ATA_VIA6421 0x32491106 +#define ATA_VIACX700IDE 0x05811106 +#define ATA_VIACX700 0x83241106 +#define ATA_VIASATAIDE 0x53241106 +#define ATA_VIAVX800 0x83531106 +#define ATA_VIAVX855 0x84091106 /* global prototypes ata-pci.c */ int ata_pci_probe(device_t dev); Modified: user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-ite.c ============================================================================== --- user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-ite.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-ite.c Mon Dec 21 10:01:03 2009 (r200767) @@ -105,6 +105,8 @@ ata_ite_chipinit(device_t dev) pci_write_config(dev, 0x56, 0x31, 1); ctlr->setmode = ata_ite_821x_setmode; + /* No timing restrictions initally. */ + ctlr->chipset_data = (void *)0; } ctlr->ch_attach = ata_ite_ch_attach; return 0; @@ -129,6 +131,7 @@ ata_ite_821x_setmode(device_t dev, int t struct ata_channel *ch = device_get_softc(dev); int devno = (ch->unit << 1) + target; int piomode; + uint8_t *timings = (uint8_t*)(&ctlr->chipset_data); u_int8_t udmatiming[] = { 0x44, 0x42, 0x31, 0x21, 0x11, 0xa2, 0x91 }; u_int8_t chtiming[] = @@ -158,11 +161,10 @@ ata_ite_821x_setmode(device_t dev, int t (1 << (devno + 3)), 1); piomode = mode; } + timings[devno] = chtiming[ata_mode2idx(piomode)]; /* set active and recover timing (shared between master & slave) */ - if (pci_read_config(parent, 0x54 + (ch->unit << 2), 1) < - chtiming[ata_mode2idx(piomode)]) - pci_write_config(parent, 0x54 + (ch->unit << 2), - chtiming[ata_mode2idx(piomode)], 1); + pci_write_config(parent, 0x54 + (ch->unit << 2), + max(timings[ch->unit << 1], timings[(ch->unit << 1) + 1]), 1); return (mode); } Modified: user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-promise.c ============================================================================== --- user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-promise.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-promise.c Mon Dec 21 10:01:03 2009 (r200767) @@ -957,6 +957,7 @@ ata_promise_mio_dmainit(device_t dev) ata_dmainit(dev); /* note start and stop are not used here */ ch->dma.setprd = ata_promise_mio_setprd; + ch->dma.max_iosize = 65536; } Modified: user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-serverworks.c ============================================================================== --- user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-serverworks.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-serverworks.c Mon Dec 21 10:01:03 2009 (r200767) @@ -80,7 +80,7 @@ ata_serverworks_probe(device_t dev) { struct ata_pci_controller *ctlr = device_get_softc(dev); static struct ata_chip_id ids[] = - {{ ATA_ROSB4, 0x00, SWKS_33, 0, ATA_UDMA2, "ROSB4" }, + {{ ATA_ROSB4, 0x00, SWKS_33, 0, ATA_WDMA2, "ROSB4" }, { ATA_CSB5, 0x92, SWKS_100, 0, ATA_UDMA5, "CSB5" }, { ATA_CSB5, 0x00, SWKS_66, 0, ATA_UDMA4, "CSB5" }, { ATA_CSB6, 0x00, SWKS_100, 0, ATA_UDMA5, "CSB6" }, @@ -388,10 +388,12 @@ ata_serverworks_setmode(device_t dev, in piomode = mode; } /* Set PIO mode and timings, calculated above. */ - pci_write_config(parent, 0x4a, + if (ctlr->chip->cfg1 != SWKS_33) { + pci_write_config(parent, 0x4a, (pci_read_config(parent, 0x4a, 2) & ~(0xf << (devno << 2))) | ((piomode - ATA_PIO0) << (devno<<2)),2); + } pci_write_config(parent, 0x40, (pci_read_config(parent, 0x40, 4) & ~(0xff << offset)) | Modified: user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-via.c ============================================================================== --- user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-via.c Mon Dec 21 06:24:44 2009 (r200766) +++ user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-via.c Mon Dec 21 10:01:03 2009 (r200767) @@ -59,6 +59,9 @@ static void ata_via_reset(device_t dev); static int ata_via_old_setmode(device_t dev, int target, int mode); static void ata_via_southbridge_fixup(device_t dev); static int ata_via_new_setmode(device_t dev, int target, int mode); +static int ata_via_sata_ch_attach(device_t dev); +static int ata_via_sata_getrev(device_t dev, int target); +static int ata_via_sata_setmode(device_t dev, int target, int mode); /* misc defines */ #define VIA33 0 @@ -70,6 +73,7 @@ static int ata_via_new_setmode(device_t #define VIABUG 0x02 #define VIABAR 0x04 #define VIAAHCI 0x08 +#define VIASATA 0x10 /* @@ -98,6 +102,9 @@ ata_via_probe(device_t dev) *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Mon Dec 21 15:16:38 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6235B106568F; Mon, 21 Dec 2009 15:16:38 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 367D78FC15; Mon, 21 Dec 2009 15:16:38 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id E807C46B23; Mon, 21 Dec 2009 10:16:37 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.9]) by bigwig.baldwin.cx (Postfix) with ESMTPA id E7E0C8A01F; Mon, 21 Dec 2009 10:16:36 -0500 (EST) From: John Baldwin To: Kip Macy Date: Mon, 21 Dec 2009 08:50:36 -0500 User-Agent: KMail/1.12.1 (FreeBSD/7.2-CBSD-20091103; KDE/4.3.1; amd64; ; ) References: <200912210310.nBL3ARvY082294@svn.freebsd.org> In-Reply-To: <200912210310.nBL3ARvY082294@svn.freebsd.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <200912210850.36446.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0.1 (bigwig.baldwin.cx); Mon, 21 Dec 2009 10:16:37 -0500 (EST) X-Virus-Scanned: clamav-milter 0.95.1 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.5 required=4.2 tests=AWL,BAYES_00,RDNS_NONE autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on bigwig.baldwin.cx Cc: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: Re: svn commit: r200762 - user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2009 15:16:38 -0000 On Sunday 20 December 2009 10:10:27 pm Kip Macy wrote: > Author: kmacy > Date: Mon Dec 21 03:10:26 2009 > New Revision: 200762 > URL: http://svn.freebsd.org/changeset/base/200762 > > Log: > align hash table locks > > Modified: > user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c > > Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c > ============================================================================== > --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Sun Dec 20 22:55:27 2009 (r200761) > +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/arc.c Mon Dec 21 03:10:26 2009 (r200762) > @@ -548,7 +548,7 @@ struct ht_lock { > typedef struct buf_hash_table { > uint64_t ht_mask; > arc_buf_hdr_t **ht_table; > - struct ht_lock ht_locks[BUF_LOCKS]; > + struct ht_lock ht_locks[BUF_LOCKS] __aligned(128); > } buf_hash_table_t; FYI, there is a CACHE_LINE_SIZE constant in you can use instead of hardcoding an x86-specific value. -- John Baldwin From owner-svn-src-user@FreeBSD.ORG Mon Dec 21 17:55:10 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EEDA1106566C; Mon, 21 Dec 2009 17:55:10 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DCBFF8FC17; Mon, 21 Dec 2009 17:55:10 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBLHtAf9035236; Mon, 21 Dec 2009 17:55:10 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBLHtAZm035231; Mon, 21 Dec 2009 17:55:10 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912211755.nBLHtAZm035231@svn.freebsd.org> From: Luigi Rizzo Date: Mon, 21 Dec 2009 17:55:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200782 - in user/luigi/ipfw3-head/sys/netinet: . ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2009 17:55:11 -0000 Author: luigi Date: Mon Dec 21 17:55:10 2009 New Revision: 200782 URL: http://svn.freebsd.org/changeset/base/200782 Log: partial code to reduce contention on the ipfw lock and especially remove some O(N) sections of code with the write lock held from userland. 1. introduce a IPFW_UH_LOCK to arbitrate requests from the upper half of the kernel. Some things, such as 'ipfw show' can be done holding this lock in read mode, whereas insert and delete require IPFW_UH_WLOCK. 2. introduce a mapping structure to keep rules together. This replaces the 'next' chain currently used in ipfw rules. At the moment the map is a simple array (sorted by rule number and then rule_id), so we can find a rule quickly instead of having to scan the list. 3. when an expensive operation (such as insert or delete) is done by userland, we grab IPFW_UH_WLOCK, create a new copy of the map without blocking the bottom half of the kernel, then acquire IPFW_WLOCK and quickly update pointers to the map and related info. After dropping IPFW_LOCK we can then continue the cleanup protected by IPFW_UH_LOCK. 4. do not pass pointers to rules through dummynet, netgraph, divert etc, but rather pass a pair that lets us do a lookup quickly. All the above does not change the ABI. 5. a similar type of protection should be applied to references from dynamic rules to their parent (not done yet, will require changes to the structure of dynamic rules which are known to userland too). Modified: user/luigi/ipfw3-head/sys/netinet/ip_fw.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Modified: user/luigi/ipfw3-head/sys/netinet/ip_fw.h ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ip_fw.h Mon Dec 21 17:41:57 2009 (r200781) +++ user/luigi/ipfw3-head/sys/netinet/ip_fw.h Mon Dec 21 17:55:10 2009 (r200782) @@ -461,7 +461,7 @@ typedef struct _ipfw_insn_icmp6 { */ struct ip_fw { - struct ip_fw *next; /* linked list of rules */ + struct ip_fw *x_next; /* linked list of rules */ struct ip_fw *next_rule; /* ptr to next [skipto] rule */ /* 'next_rule' is used to pass up 'set_disable' status */ Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Mon Dec 21 17:41:57 2009 (r200781) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Mon Dec 21 17:55:10 2009 (r200782) @@ -629,31 +629,6 @@ send_reject(struct ip_fw_args *args, int args->m = NULL; } -/** - * Return the pointer to the skipto target. - * - * IMPORTANT: this should only be called on SKIPTO rules, and the - * jump target is taken from the 'rulenum' argument, which may come - * from the rule itself (direct skipto) or not (tablearg) - * - * The function never returns NULL: if the requested rule is not - * present, it returns the next rule in the chain. - * This also happens in case of a bogus argument > 65535 - */ -static struct ip_fw * -lookup_next_rule(struct ip_fw *me, uint32_t rulenum) -{ - struct ip_fw *rule; - - for (rule = me->next; rule ; rule = rule->next) { - if (rule->rulenum >= rulenum) - break; - } - if (rule == NULL) /* failure or not a skipto */ - rule = me->next ? me->next : me; - return rule; -} - /* * Support for uid/gid/jail lookup. These tests are expensive * (because we may need to look into the list of active sockets) @@ -738,6 +713,14 @@ check_uidgid(ipfw_insn_u32 *insn, int pr return match; } +static inline void +set_match(struct ip_fw_args *args, struct ip_fw *f, struct ip_fw_chain *chain) +{ + args->rule = (void *)(uintptr_t)f->rulenum; + args->rule_id = f->id; + args->chain_id = chain->id; +} + /* * The main check routine for the firewall. * @@ -830,6 +813,7 @@ ipfw_chk(struct ip_fw_args *args) struct ifnet *oif = args->oif; struct ip_fw *f = NULL; /* matching rule */ + int f_pos = 0; /* index of f in the array */ int retval = 0; /* @@ -1167,22 +1151,14 @@ do { \ * if still present, otherwise use the default rule. * XXX If fw_one_pass != 0 then just accept it, though * the caller should never pass us such packets. + * XXX rule is now the rule number so we can do a lookup */ if (V_fw_one_pass) { IPFW_RUNLOCK(chain); return (IP_FW_PASS); } - if (chain->id == args->chain_id) { /* pointer still valid */ - f = args->rule->next; - } else { /* must revalidate the pointer */ - for (f = chain->rules; f != NULL; f = f->next) - if (f == args->rule && f->id == args->rule_id) { - f = args->rule->next; - break; - } - } - if (f == NULL) /* in case of errors, use default; */ - f = chain->default_rule; + f_pos = ipfw_find_rule(chain, (uint32_t)(args->rule), args->rule_id+1); + f = chain->map[f_pos]; } else { /* * Find the starting rule. It can be either the first @@ -1191,17 +1167,14 @@ do { \ int skipto = mtag ? divert_cookie(mtag) : 0; f = chain->rules; + f_pos = 0; if (args->eh == NULL && skipto != 0) { if (skipto >= IPFW_DEFAULT_RULE) { IPFW_RUNLOCK(chain); return (IP_FW_DENY); /* invalid */ } - while (f && f->rulenum <= skipto) - f = f->next; - if (f == NULL) { /* drop packet */ - IPFW_RUNLOCK(chain); - return (IP_FW_DENY); - } + f_pos = ipfw_find_rule(chain, skipto, 0); + f = chain->map[f_pos]; } } /* reset divert rule to avoid confusion later */ @@ -1229,12 +1202,13 @@ do { \ * We can restart the inner loop by setting l>0 and f, cmd * as needed. */ - for (; f; f = f->next) { + for (; f_pos < chain->n_rules; f_pos++) { ipfw_insn *cmd; uint32_t tablearg = 0; int l, cmdlen, skip_or; /* skip rest of OR block */ /* again: */ + f = chain->map[f_pos]; if (V_set_disable & (1 << f->set) ) continue; @@ -1917,6 +1891,8 @@ do { \ q->pcnt++; q->bcnt += pktlen; f = q->rule; + /* the pointer is valid so we can do a lookup */ + f_pos = ipfw_find_rule(chain, f->rulenum, f->id); cmd = ACTION_PTR(f); l = f->cmd_len - f->act_ofs; ipfw_dyn_unlock(); @@ -1942,9 +1918,7 @@ do { \ case O_PIPE: case O_QUEUE: - args->rule = f; /* report matching rule */ - args->rule_id = f->id; - args->chain_id = chain->id; + set_match(args, f, chain); if (cmd->arg1 == IP_FW_TABLEARG) args->cookie = tablearg; else @@ -1990,14 +1964,11 @@ do { \ break; } /* skipto: */ - if (cmd->arg1 == IP_FW_TABLEARG) { - f = lookup_next_rule(f, tablearg); - } else { /* direct skipto */ - /* update f->next_rule if not set */ - if (f->next_rule == NULL) - f->next_rule = - lookup_next_rule(f, cmd->arg1); - f = f->next_rule; + { + int i = (cmd->arg1 == IP_FW_TABLEARG) ? tablearg : cmd->arg1; + if (i <= f->rulenum) + i = f->rulenum + 1; /* no backward jumps */ + f_pos = ipfw_find_rule(chain, i, 0); } /* * Skip disabled rules, and @@ -2005,14 +1976,11 @@ do { \ * with the correct f, l and cmd. * Also clear cmdlen and skip_or */ - while (f && (V_set_disable & (1 << f->set))) - f = f->next; - if (f) { /* found a valid rule */ - l = f->cmd_len; - cmd = f->cmd; - } else { /* should not happen */ - l = 0; /* exit inner loop */ - } + for (; f_pos < chain->n_rules - 1 && (V_set_disable & (1 << chain->map[f_pos]->set)); f_pos++) + ; + f = chain->map[f_pos]; + l = f->cmd_len; + cmd = f->cmd; match = 1; cmdlen = 0; skip_or = 0; @@ -2077,9 +2045,7 @@ do { \ case O_NETGRAPH: case O_NGTEE: - args->rule = f; /* report matching rule */ - args->rule_id = f->id; - args->chain_id = chain->id; + set_match(args, f, chain); if (cmd->arg1 == IP_FW_TABLEARG) args->cookie = tablearg; else @@ -2106,14 +2072,12 @@ do { \ struct cfg_nat *t; int nat_id; - args->rule = f; /* Report matching rule. */ - args->rule_id = f->id; - args->chain_id = chain->id; + set_match(args, f, chain); t = ((ipfw_insn_nat *)cmd)->nat; if (t == NULL) { nat_id = (cmd->arg1 == IP_FW_TABLEARG) ? tablearg : cmd->arg1; - t = (*lookup_nat_ptr)(&V_layer3_chain.nat, nat_id); + t = (*lookup_nat_ptr)(&chain->nat, nat_id); if (t == NULL) { retval = IP_FW_DENY; @@ -2175,9 +2139,7 @@ do { \ else ip->ip_sum = in_cksum(m, hlen); retval = IP_FW_REASS; - args->rule = f; - args->rule_id = f->id; - args->chain_id = chain->id; + set_match(args, f, chain); } done = 1; /* exit outer loop */ break; @@ -2310,50 +2272,53 @@ static int vnet_ipfw_init(const void *unused) { int error; - struct ip_fw default_rule; + struct ip_fw *rule = NULL; + struct ip_fw_chain *chain; + + chain = &V_layer3_chain; /* First set up some values that are compile time options */ + V_autoinc_step = 100; /* bounded to 1..1000 in add_rule() */ + V_fw_deny_unknown_exthdrs = 1; #ifdef IPFIREWALL_VERBOSE V_fw_verbose = 1; #endif #ifdef IPFIREWALL_VERBOSE_LIMIT V_verbose_limit = IPFIREWALL_VERBOSE_LIMIT; #endif - - error = ipfw_init_tables(&V_layer3_chain); - if (error) { - panic("init_tables"); /* XXX Marko fix this ! */ - } #ifdef IPFIREWALL_NAT - LIST_INIT(&V_layer3_chain.nat); + LIST_INIT(chain->nat); #endif - V_autoinc_step = 100; /* bounded to 1..1000 in add_rule() */ - - V_fw_deny_unknown_exthdrs = 1; - - V_layer3_chain.rules = NULL; - IPFW_LOCK_INIT(&V_layer3_chain); - - bzero(&default_rule, sizeof default_rule); - default_rule.act_ofs = 0; - default_rule.rulenum = IPFW_DEFAULT_RULE; - default_rule.cmd_len = 1; - default_rule.set = RESVD_SET; - default_rule.cmd[0].len = 1; - default_rule.cmd[0].opcode = default_to_accept ? O_ACCEPT : O_DENY; - error = ipfw_add_rule(&V_layer3_chain, &default_rule); - - if (error != 0) { - printf("ipfw2: error %u initializing default rule " - "(support disabled)\n", error); - IPFW_LOCK_DESTROY(&V_layer3_chain); - printf("leaving ipfw_iattach (1) with error %d\n", error); - return (error); + /* insert the default rule and create the initial map */ + chain->n_rules = 1; + chain->static_len = sizeof(struct ip_fw); + chain->map = malloc(sizeof(struct ip_fw *), M_IPFW, M_NOWAIT | M_ZERO); + if (chain->map) + rule = malloc(chain->static_len, M_IPFW, M_NOWAIT | M_ZERO); + if (rule == NULL) { + if (chain->map) + free(chain->map, M_IPFW); + printf("ipfw2: ENOSPC initializing default rule " + "(support disabled)\n"); + return (ENOSPC); + } + error = ipfw_init_tables(chain); + if (error) { + panic("init_tables"); /* XXX Marko fix this ! */ } - V_layer3_chain.default_rule = V_layer3_chain.rules; + /* fill and insert the default rule */ + rule->act_ofs = 0; + rule->rulenum = IPFW_DEFAULT_RULE; + rule->cmd_len = 1; + rule->set = RESVD_SET; + rule->cmd[0].len = 1; + rule->cmd[0].opcode = default_to_accept ? O_ACCEPT : O_DENY; + chain->rules = chain->default_rule = chain->map[0] = rule; + chain->id = rule->id = 1; + IPFW_LOCK_INIT(chain); ipfw_dyn_init(); /* First set up some values that are compile time options */ Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h Mon Dec 21 17:41:57 2009 (r200781) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h Mon Dec 21 17:55:10 2009 (r200782) @@ -174,9 +174,13 @@ struct ip_fw_chain { struct ip_fw *rules; /* list of rules */ struct ip_fw *reap; /* list of rules to reap */ struct ip_fw *default_rule; + int n_rules; /* number of static rules */ + int static_len; /* total len of static rules */ + struct ip_fw **map; /* array of rule ptrs to ease lookup */ LIST_HEAD(nat_list, cfg_nat) nat; /* list of nat entries */ struct radix_node_head *tables[IPFW_TABLES_MAX]; struct rwlock rwmtx; + struct rwlock uh_lock; /* lock for upper half */ uint32_t id; /* ruleset id */ }; @@ -187,9 +191,16 @@ struct sockopt; /* used by tcp_var.h */ * so the variable and the macros must be here. */ -#define IPFW_LOCK_INIT(_chain) \ - rw_init(&(_chain)->rwmtx, "IPFW static rules") -#define IPFW_LOCK_DESTROY(_chain) rw_destroy(&(_chain)->rwmtx) +#define IPFW_LOCK_INIT(_chain) do { \ + rw_init(&(_chain)->rwmtx, "IPFW static rules"); \ + rw_init(&(_chain)->uh_lock, "IPFW UH lock"); \ + } while (0) + +#define IPFW_LOCK_DESTROY(_chain) do { \ + rw_destroy(&(_chain)->rwmtx); \ + rw_destroy(&(_chain)->uh_lock); \ + } while (0) + #define IPFW_WLOCK_ASSERT(_chain) rw_assert(&(_chain)->rwmtx, RA_WLOCKED) #define IPFW_RLOCK(p) rw_rlock(&(p)->rwmtx) @@ -197,7 +208,12 @@ struct sockopt; /* used by tcp_var.h */ #define IPFW_WLOCK(p) rw_wlock(&(p)->rwmtx) #define IPFW_WUNLOCK(p) rw_wunlock(&(p)->rwmtx) +#define IPFW_UH_RLOCK(p) rw_rlock(&(p)->uh_lock) +#define IPFW_UH_RUNLOCK(p) rw_runlock(&(p)->uh_lock) +#define IPFW_UH_WLOCK(p) rw_wlock(&(p)->uh_lock) +#define IPFW_UH_WUNLOCK(p) rw_wunlock(&(p)->uh_lock) /* In ip_fw_sockopt.c */ +int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id); int ipfw_add_rule(struct ip_fw_chain *chain, struct ip_fw *input_rule); int ipfw_ctl(struct sockopt *sopt); int ipfw_chk(struct ip_fw_args *args); Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Mon Dec 21 17:41:57 2009 (r200781) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Mon Dec 21 17:55:10 2009 (r200782) @@ -80,16 +80,10 @@ MALLOC_DEFINE(M_IPFW, "IpFw/IpAcct", "Ip * static variables followed by global ones */ -static VNET_DEFINE(u_int32_t, static_count); /* # of static rules */ -#define V_static_count VNET(static_count) - -static VNET_DEFINE(u_int32_t, static_len); /* bytes of static rules */ -#define V_static_len VNET(static_len) - #ifdef SYSCTL_NODE SYSCTL_DECL(_net_inet_ip_fw); SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, static_count, - CTLFLAG_RD, &VNET_NAME(static_count), 0, + CTLFLAG_RD, &VNET_NAME(layer3_chain.n_rules), 0, "Number of static rules"); #endif /* SYSCTL_NODE */ @@ -101,97 +95,175 @@ SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUT static void flush_rule_ptrs(struct ip_fw_chain *chain) { +#if 0 struct ip_fw *rule; IPFW_WLOCK_ASSERT(chain); - chain->id++; - for (rule = chain->rules; rule; rule = rule->next) rule->next_rule = NULL; +#endif + chain->id++; +} + +/* + * Find the smallest rule >= key, id. + * In case of multiple rules with the same number finds the first one. + * We could use bsearch but it is so simple that we code it directly + */ +int +ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id) +{ + int i, lo, hi; + struct ip_fw *r; + + printf("looking for rule %d:%d\n", key, id); + for (lo = 0, hi = chain->n_rules - 1; lo < hi;) { + printf(" -- looking for rule %d:%d [%d-%d]\n", key, id, lo, hi); + i = (lo + hi) / 2; + r = chain->map[i]; + if (r->rulenum < key) + lo = i + 1; + else if (r->rulenum > key) + hi = i; // i - 1; + else if (r->id < id) + lo = i + 1; + else if (r->id > id) + hi = i; // i - 1; + else + hi = i; + }; + printf("search end lo %d hi %d\n",lo, hi); + if (hi < 0) + hi = 0; + if (lo >= chain->n_rules - 1) + lo = chain->n_rules - 1; + printf(" -- looking for rule %d:%d found at %d\n", key, id, hi); + return hi; +} + +/* + * allocate a new map, returns the chain locked. extra is the number + * of entries to add or delete. + */ +static struct ip_fw ** +get_map(struct ip_fw_chain *chain, int extra, int locked) +{ + struct ip_fw **map; + + for (;;) { + int i = chain->n_rules + extra; + map = malloc( (1 + i) * sizeof(struct ip_fw *), M_IPFW, M_WAITOK); + if (map == NULL) { + printf("%s: cannot allocate map\n", __FUNCTION__); + break; + } + if (!locked) + IPFW_UH_WLOCK(chain); + if (i >= chain->n_rules + extra) + break; + /* otherwise we lost the race, free and retry */ + if (!locked) + IPFW_UH_WUNLOCK(chain); + free(map, M_IPFW); + } + return map; +} + +/* swap the maps. It is supposed to be called with IPFW_UH_WLOCK + * so we can do the remaining housekeepking outside + */ +static struct ip_fw ** +swap_map(struct ip_fw_chain *chain, struct ip_fw **new_map, int new_len) +{ + struct ip_fw **old_map; + int i, lim; + + IPFW_WLOCK(chain); + printf("%s %p %d --> %p %d\n", __FUNCTION__, + chain->map, chain->n_rules, + new_map, new_len); + flush_rule_ptrs(chain); + lim = chain->n_rules < new_len ? new_len : chain->n_rules; + for (i=0; i < lim; i++) + printf("%3d %p %p\n", i, + (in_rules) ? chain->map[i] : NULL, + (iid incremented inside flush_rule_ptrs() */ + chain->n_rules = new_len; + old_map = chain->map; + chain->map = new_map; + IPFW_WUNLOCK(chain); + return old_map; } /* * Add a new rule to the list. Copy the rule into a malloc'ed area, then * possibly create a rule number and add the rule to the list. * Update the rule_number in the input struct so the caller knows it as well. + * XXX not good for the default rule. */ int ipfw_add_rule(struct ip_fw_chain *chain, struct ip_fw *input_rule) { - struct ip_fw *rule, *f, *prev; + struct ip_fw *rule; int l = RULESIZE(input_rule); + int i, insert_before; + struct ip_fw **map; /* the new array of pointers */ - if (chain->rules == NULL && input_rule->rulenum != IPFW_DEFAULT_RULE) + if (chain->rules == NULL || input_rule->rulenum > IPFW_DEFAULT_RULE-1) return (EINVAL); - rule = malloc(l, M_IPFW, M_NOWAIT | M_ZERO); + rule = malloc(l, M_IPFW, M_WAITOK | M_ZERO); if (rule == NULL) return (ENOSPC); + map = get_map(chain, 1, 0 /* not locked */); + if (map == NULL) { + free(map, M_IPFW); + return ENOSPC; + } bcopy(input_rule, rule, l); - - rule->next = NULL; - rule->next_rule = NULL; + rule->x_next = NULL; + //rule->next_rule = NULL; rule->pcnt = 0; rule->bcnt = 0; rule->timestamp = 0; - IPFW_WLOCK(chain); - - if (chain->rules == NULL) { /* default rule */ - chain->rules = rule; - rule->id = ++chain->id; - goto done; - } - - /* - * If rulenum is 0, find highest numbered rule before the - * default rule, and add autoinc_step - */ if (V_autoinc_step < 1) V_autoinc_step = 1; else if (V_autoinc_step > 1000) V_autoinc_step = 1000; + /* find the insertion point */ + insert_before = rule->rulenum ? rule->rulenum + 1 : IPFW_DEFAULT_RULE; + i = ipfw_find_rule(chain, insert_before, 0); + /* duplicate first part */ + printf("insert %d before %d (%d) at pos %d, +copy %d\n", + rule->rulenum, insert_before, + i>= 0 ? chain->map[i]->rulenum : -1, i, chain->n_rules - i); + if (i > 0) + bcopy(chain->map, map, i * sizeof(struct ip_fw *)); + map[i] = rule; + /* duplicate remaining part, we always have the default rule */ + bcopy(chain->map + i, map + i + 1, sizeof(struct ip_fw *) *(chain->n_rules - i)); if (rule->rulenum == 0) { - /* - * locate the highest numbered rule before default - */ - for (f = chain->rules; f; f = f->next) { - if (f->rulenum == IPFW_DEFAULT_RULE) - break; - rule->rulenum = f->rulenum; - } + /* set the number */ + rule->rulenum = map[i]->rulenum; if (rule->rulenum < IPFW_DEFAULT_RULE - V_autoinc_step) rule->rulenum += V_autoinc_step; input_rule->rulenum = rule->rulenum; } - /* - * Now insert the new rule in the right place in the sorted list. - */ - for (prev = NULL, f = chain->rules; f; prev = f, f = f->next) { - if (f->rulenum > rule->rulenum) { /* found the location */ - if (prev) { - rule->next = f; - prev->next = rule; - } else { /* head insert */ - rule->next = chain->rules; - chain->rules = rule; - } - break; - } - } - flush_rule_ptrs(chain); - /* chain->id incremented inside flush_rule_ptrs() */ - rule->id = chain->id; -done: - V_static_count++; - V_static_len += l; - IPFW_WUNLOCK(chain); + rule->id = chain->id + 1; + map = swap_map(chain, map, chain->n_rules + 1); + chain->static_len += l; + IPFW_UH_WUNLOCK(chain); + if (map) + free(map, M_IPFW); DEB(printf("ipfw: installed rule %d, static count now %d\n", - rule->rulenum, V_static_count);) + rule->rulenum, chain->n_rules);) return (0); } @@ -203,28 +275,15 @@ done: * @return a pointer to the next entry. * Arguments are not checked, so they better be correct. */ -static struct ip_fw * -remove_rule(struct ip_fw_chain *chain, struct ip_fw *rule, - struct ip_fw *prev) +static void +remove_rule(struct ip_fw_chain *chain, struct ip_fw *rule) { - struct ip_fw *n; int l = RULESIZE(rule); - IPFW_WLOCK_ASSERT(chain); - - n = rule->next; + chain->static_len -= l; ipfw_remove_dyn_children(rule); - if (prev == NULL) - chain->rules = n; - else - prev->next = n; - V_static_count--; - V_static_len -= l; - - rule->next = chain->reap; + rule->x_next = chain->reap; chain->reap = rule; - - return n; } /* @@ -238,7 +297,7 @@ ipfw_reap_rules(struct ip_fw *head) struct ip_fw *rule; while ((rule = head) != NULL) { - head = head->next; + head = head->x_next; free(rule, M_IPFW); } } @@ -251,6 +310,7 @@ ipfw_reap_rules(struct ip_fw *head) void ipfw_free_chain(struct ip_fw_chain *chain, int kill_default) { +#if 0 // XXX struct ip_fw *prev, *rule; IPFW_WLOCK_ASSERT(chain); @@ -259,11 +319,12 @@ ipfw_free_chain(struct ip_fw_chain *chai flush_rule_ptrs(chain); /* more efficient to do outside the loop */ for (prev = NULL, rule = chain->rules; rule ; ) if (kill_default || rule->set != RESVD_SET) - rule = remove_rule(chain, rule, prev); + rule = remove_rule(chain, rule); else { prev = rule; rule = rule->next; } +#endif } /** @@ -283,9 +344,12 @@ ipfw_free_chain(struct ip_fw_chain *chai static int del_entry(struct ip_fw_chain *chain, u_int32_t arg) { - struct ip_fw *prev = NULL, *rule; + struct ip_fw *rule; u_int16_t rulenum; /* rule or old_set */ u_int8_t cmd, new_set; + int start, end, i, ofs, n; + struct ip_fw **map = NULL; + int error = 0; rulenum = arg & 0xffff; cmd = (arg >> 24) & 0xff; @@ -301,62 +365,130 @@ del_entry(struct ip_fw_chain *chain, u_i return EINVAL; } - IPFW_WLOCK(chain); - rule = chain->rules; /* common starting point */ + IPFW_UH_WLOCK(chain); /* prevent conflicts among the writers */ chain->reap = NULL; /* prepare for deletions */ switch (cmd) { case 0: /* delete rules with given number */ - /* - * locate first rule to delete - */ - for (; rule->rulenum < rulenum; prev = rule, rule = rule->next) - ; - if (rule->rulenum != rulenum) { - IPFW_WUNLOCK(chain); - return EINVAL; + /* locate first rule to delete */ + start = ipfw_find_rule(chain, rulenum, 0); + /* count matching rules and end of range */ + for (end = start, n = 0; end < chain->n_rules; end++) { + rule = chain->map[end]; + if (rule->rulenum != rulenum) + break; + if (rule->set != RESVD_SET) + n++; } - - /* - * flush pointers outside the loop, then delete all matching - * rules. prev remains the same throughout the cycle. - */ - flush_rule_ptrs(chain); - while (rule->rulenum == rulenum) - rule = remove_rule(chain, rule, prev); + printf("must delete %d rules between %d and %d\n", n, start, end); + /* allocate the map, if needed */ + if (n > 0) + map = get_map(chain, -n, 1 /* locked */); + if (n == 0 || map == NULL) { + error = EINVAL; + goto done; + } + /* copy the initial part of the map */ + if (start > 0) + bcopy(chain->map, map, start * sizeof(struct ip_fw *)); + /* copy active rules between start and end */ + for (i = ofs = start; i < end; i++) { + rule = chain->map[i]; + if (rule->set == RESVD_SET) + map[ofs++] = chain->map[i]; + } + /* finally the tail */ + bcopy(chain->map + end, map + ofs, + (chain->n_rules - end) * sizeof(struct ip_fw *)); + map = swap_map(chain, map, chain->n_rules - n); + /* now remove the rules deleted */ + for (i = start; i < end; i++) { + rule = map[i]; + printf("about to remove rule %p at %d\n", + rule, i); + if (rule->set != RESVD_SET) + remove_rule(chain, rule); + } + printf("done with removals\n"); break; case 1: /* delete all rules with given set number */ - flush_rule_ptrs(chain); - while (rule->rulenum < IPFW_DEFAULT_RULE) { - if (rule->set == rulenum) - rule = remove_rule(chain, rule, prev); - else { - prev = rule; - rule = rule->next; + IPFW_UH_WLOCK(chain); + /* locate first rule to delete */ + for (start = 0; start < chain->n_rules; start++) { + rule = chain->map[start]; + if (rule->set != rulenum) + break; + } + for (n = 0, end = i = start; i < chain->n_rules; i++) { + rule = chain->map[i]; + if (rule->set == rulenum) { + end = i; + n++; } } + end++; /* first non-matching */ + printf("must delete %d rules between %d and %d\n", n, start, end); + /* allocate the map, if needed */ + if (n > 0) + map = get_map(chain, -n, 1 /* locked */); + if (n == 0 || map == NULL) { + error = EINVAL; + goto done; + } + /* copy the initial part of the map */ + if (start > 0) + bcopy(chain->map, map, start * sizeof(struct ip_fw *)); + /* copy reserved rules */ + for (i = ofs = start; i < end; i++) { + rule = chain->map[i]; + if (rule->set != rulenum) + map[ofs++] = chain->map[i]; + } + /* finally the tail */ + bcopy(chain->map + end, map + ofs, + (chain->n_rules - end) * sizeof(struct ip_fw *)); + map = swap_map(chain, map, chain->n_rules - n); + /* now remove the rules deleted */ + for (i = start; i < end; i++) { + rule = map[i]; + if (rule->set == rulenum) + remove_rule(chain, map[i]); + } break; case 2: /* move rules with given number to new set */ - for (; rule->rulenum < IPFW_DEFAULT_RULE; rule = rule->next) + IPFW_UH_WLOCK(chain); + for (i = 0; i < chain->n_rules; i++) { + rule = chain->map[i]; if (rule->rulenum == rulenum) rule->set = new_set; + } + IPFW_UH_WUNLOCK(chain); break; case 3: /* move rules with given set number to new set */ - for (; rule->rulenum < IPFW_DEFAULT_RULE; rule = rule->next) + IPFW_UH_WLOCK(chain); + for (i = 0; i < chain->n_rules; i++) { + rule = chain->map[i]; if (rule->set == rulenum) rule->set = new_set; + } + IPFW_UH_WUNLOCK(chain); break; case 4: /* swap two sets */ - for (; rule->rulenum < IPFW_DEFAULT_RULE; rule = rule->next) + IPFW_UH_WLOCK(chain); + for (i = 0; i < chain->n_rules; i++) { + rule = chain->map[i]; if (rule->set == rulenum) rule->set = new_set; else if (rule->set == new_set) rule->set = rulenum; + } + IPFW_UH_WUNLOCK(chain); break; +#if 0 // XXX case 5 is a restriction of 1 case 5: /* delete rules with given number and with given set number. * rulenum - given rule number; * new_set - given set number. @@ -376,16 +508,20 @@ del_entry(struct ip_fw_chain *chain, u_i rule = rule->next; } } +#endif } /* * Look for rules to reclaim. We grab the list before * releasing the lock then reclaim them w/o the lock to * avoid a LOR with dummynet. */ +done: rule = chain->reap; - IPFW_WUNLOCK(chain); + IPFW_UH_WUNLOCK(chain); ipfw_reap_rules(rule); - return 0; + if (map) + free(map, M_IPFW); + return error; } /* @@ -419,6 +555,7 @@ zero_entry(struct ip_fw_chain *chain, u_ { struct ip_fw *rule; char *msg; + int i; uint16_t rulenum = arg & 0xffff; uint8_t set = (arg >> 16) & 0xff; @@ -429,11 +566,12 @@ zero_entry(struct ip_fw_chain *chain, u_ if (cmd == 1 && set > RESVD_SET) return (EINVAL); - IPFW_WLOCK(chain); + IPFW_UH_RLOCK(chain); if (rulenum == 0) { V_norule_counter = 0; - for (rule = chain->rules; rule; rule = rule->next) { - /* Skip rules from another set. */ + for (i = 0; i < chain->n_rules; i++) { + rule = chain->map[i]; + /* Skip rules not in our set. */ if (cmd == 1 && rule->set != set) continue; clear_counters(rule, log_only); @@ -442,27 +580,23 @@ zero_entry(struct ip_fw_chain *chain, u_ "Accounting cleared"; } else { int cleared = 0; - /* - * We can have multiple rules with the same number, so we - * need to clear them all. - */ - for (rule = chain->rules; rule; rule = rule->next) + for (i = 0; i < chain->n_rules; i++) { + rule = chain->map[i]; if (rule->rulenum == rulenum) { - while (rule && rule->rulenum == rulenum) { - if (cmd == 0 || rule->set == set) - clear_counters(rule, log_only); - rule = rule->next; - } + if (cmd == 0 || rule->set == set) + clear_counters(rule, log_only); cleared = 1; - break; } + if (rule->rulenum > rulenum) + break; + } if (!cleared) { /* we did not find any matching rules */ IPFW_WUNLOCK(chain); return (EINVAL); } msg = log_only ? "logging count reset" : "cleared"; } - IPFW_WUNLOCK(chain); + IPFW_UH_RUNLOCK(chain); if (V_fw_verbose) { int lev = LOG_SECURITY | LOG_NOTICE; @@ -794,13 +928,16 @@ ipfw_getrules(struct ip_fw_chain *chain, char *bp = buf; char *ep = bp + space; struct ip_fw *rule; - int i; + int i, ix; time_t boot_seconds; boot_seconds = boottime.tv_sec; /* XXX this can take a long time and locking will block packet flow */ - IPFW_RLOCK(chain); - for (rule = chain->rules; rule ; rule = rule->next) { + IPFW_UH_RLOCK(chain); + printf("%s map %p %d\n", __FUNCTION__, chain->map, chain->n_rules); + for (ix = 0; ix < chain->n_rules; ix++) { + rule = chain->map[ix]; + printf("rule %d %p\n", ix, rule); /* * Verify the entry fits in the buffer in case the * rules changed between calculating buffer space and @@ -823,7 +960,7 @@ ipfw_getrules(struct ip_fw_chain *chain, bp += i; } } - IPFW_RUNLOCK(chain); + IPFW_UH_RUNLOCK(chain); ipfw_get_dynamic(&bp, ep); /* protected by the dynamic lock */ return (bp - (char *)buf); } @@ -839,6 +976,7 @@ ipfw_ctl(struct sockopt *sopt) int error; size_t size; struct ip_fw *buf, *rule; + struct ip_fw_chain *chain; u_int32_t rulenum[2]; error = priv_check(sopt->sopt_td, PRIV_NETINET_IPFW); @@ -856,6 +994,7 @@ ipfw_ctl(struct sockopt *sopt) return (error); } + chain = &V_layer3_chain; error = 0; switch (sopt->sopt_name) { @@ -871,7 +1010,8 @@ ipfw_ctl(struct sockopt *sopt) * change between calculating the size and returning the * data in which case we'll just return what fits. */ - size = V_static_len; /* size of static rules */ + size = chain->static_len; /* size of static rules */ + printf("static len %d\n", chain->static_len); size += ipfw_dyn_len(); if (size >= sopt->sopt_valsize) @@ -883,7 +1023,7 @@ ipfw_ctl(struct sockopt *sopt) */ buf = malloc(size, M_TEMP, M_WAITOK); error = sooptcopyout(sopt, buf, - ipfw_getrules(&V_layer3_chain, buf, size)); + ipfw_getrules(chain, buf, size)); free(buf, M_TEMP); break; @@ -901,10 +1041,10 @@ ipfw_ctl(struct sockopt *sopt) * the old list without the need for a lock. */ - IPFW_WLOCK(&V_layer3_chain); - ipfw_free_chain(&V_layer3_chain, 0 /* keep default rule */); - rule = V_layer3_chain.reap; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Mon Dec 21 21:04:41 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 713281065692; Mon, 21 Dec 2009 21:04:41 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 477518FC08; Mon, 21 Dec 2009 21:04:41 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBLL4fuK040764; Mon, 21 Dec 2009 21:04:41 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBLL4fVF040763; Mon, 21 Dec 2009 21:04:41 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200912212104.nBLL4fVF040763@svn.freebsd.org> From: Edwin Groothuis Date: Mon, 21 Dec 2009 21:04:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200812 - user/edwin/calendar X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2009 21:04:41 -0000 Author: edwin Date: Mon Dec 21 21:04:41 2009 New Revision: 200812 URL: http://svn.freebsd.org/changeset/base/200812 Log: Move to my own part for experimenting on proper multiyear handling and non-solar calendars. Added: - copied from r200811, head/usr.bin/calendar/ Directory Properties: user/edwin/calendar/ (props changed) From owner-svn-src-user@FreeBSD.ORG Mon Dec 21 21:18:00 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 019D0106568B; Mon, 21 Dec 2009 21:18:00 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E3B588FC1C; Mon, 21 Dec 2009 21:17:59 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBLLHxVt041091; Mon, 21 Dec 2009 21:17:59 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBLLHxTB041085; Mon, 21 Dec 2009 21:17:59 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200912212117.nBLLHxTB041085@svn.freebsd.org> From: Edwin Groothuis Date: Mon, 21 Dec 2009 21:17:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200813 - user/edwin/calendar X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2009 21:18:00 -0000 Author: edwin Date: Mon Dec 21 21:17:59 2009 New Revision: 200813 URL: http://svn.freebsd.org/changeset/base/200813 Log: Currently calendar(1) is not able to handle longer periods, mostly due to the way Easter and other special days are calculated. This will be an attempt to overcome this issue and add proper support for non-solar-based events (Easter, Chinese New Year, Jewish calendar, moon phases (for the vampires :-)) So far: - Rewriten the parser to return more detailed reoccuring events (ran against calendar.full to catch the fall-out). Modified: user/edwin/calendar/Makefile user/edwin/calendar/calendar.c user/edwin/calendar/calendar.h user/edwin/calendar/day.c user/edwin/calendar/io.c Modified: user/edwin/calendar/Makefile ============================================================================== --- user/edwin/calendar/Makefile Mon Dec 21 21:04:41 2009 (r200812) +++ user/edwin/calendar/Makefile Mon Dec 21 21:17:59 2009 (r200813) @@ -1,6 +1,8 @@ # @(#)Makefile 8.1 (Berkeley) 6/6/93 # $FreeBSD$ +CFLAGS= -pipe -g -std=gnu99 -fstack-protector -Wall + PROG= calendar SRCS= calendar.c io.c day.c ostern.c paskha.c INTER= de_AT.ISO_8859-15 de_DE.ISO8859-1 fr_FR.ISO8859-1 \ Modified: user/edwin/calendar/calendar.c ============================================================================== --- user/edwin/calendar/calendar.c Mon Dec 21 21:04:41 2009 (r200812) +++ user/edwin/calendar/calendar.c Mon Dec 21 21:17:59 2009 (r200813) @@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$"); struct passwd *pw; int doall = 0; +int debug = 0; time_t f_time = 0; int f_dayAfter = 0; /* days after current date */ @@ -74,7 +75,7 @@ main(int argc, char *argv[]) (void)setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "-A:aB:F:f:t:W:")) != -1) + while ((ch = getopt(argc, argv, "-A:aB:dF:f:t:W:")) != -1) switch (ch) { case '-': /* backward contemptible */ case 'a': @@ -95,8 +96,8 @@ main(int argc, char *argv[]) case 'W': /* we don't need no steenking Fridays */ Friday = -1; - /* FALLTHROUGH */ + case 'A': /* days after current date */ f_dayAfter = atoi(optarg); break; @@ -109,6 +110,10 @@ main(int argc, char *argv[]) Friday = atoi(optarg); break; + case 'd': + debug = 1; + break; + case '?': default: usage(); @@ -124,7 +129,7 @@ main(int argc, char *argv[]) if (f_time <= 0) (void)time(&f_time); - settime(f_time); + settimes(f_time, f_dayBefore, f_dayAfter); if (doall) while ((pw = getpwent()) != NULL) { Modified: user/edwin/calendar/calendar.h ============================================================================== --- user/edwin/calendar/calendar.h Mon Dec 21 21:04:41 2009 (r200812) +++ user/edwin/calendar/calendar.h Mon Dec 21 21:17:59 2009 (r200813) @@ -36,38 +36,59 @@ #include #include +#define SECSPERDAY 24 * 60 * 60 + extern struct passwd *pw; extern int doall; extern struct iovec header[]; -extern struct tm *tp; +extern struct tm tp1, tp2; +extern time_t t1, t2; extern const char *calendarFile; extern int *cumdays; extern int yrdays; -extern struct fixs neaster, npaskha; +extern struct fixs neaster, npaskha, ncny; void cal(void); void closecal(FILE *); +int checkdayofweek(char *, int *len, int *offset, char **dow); +char * getdayofweekname(int); +int checkmonth(char *, int *len, int *offset, char **month); +char * getmonthname(int); int getday(char *); int getdayvar(char *); -int getfield(char *, char **, int *); +int getfield(char *, int *); int getmonth(char *); int geteaster(char *, int); int getpaskha(char *, int); int easter(int); -int isnow(char *, int *, int *, int *); +int parsedaymonth(char *, int *, int *, int *); FILE *opencal(void); -void settime(time_t); +void settimes(time_t,int, int); time_t Mktime(char *); void setnnames(void); #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) -/* some flags */ -#define F_ISMONTH 0x01 /* month (January ...) */ -#define F_ISDAY 0x02 /* day of week (Sun, Mon, ...) */ -#define F_ISDAYVAR 0x04 /* variables day of week, like SundayLast */ -#define F_EASTER 0x08 /* Easter or easter depending days */ +/* Flags to determine the returned values by determinestyle() */ +#define F_NONE 0x000 +#define F_MONTH 0x001 +#define F_DAYOFWEEK 0x002 +#define F_DAYOFMONTH 0x004 +#define F_MODIFIERINDEX 0x008 +#define F_MODIFIEROFFSET 0x010 +#define F_SPECIALDAY 0x020 +#define F_ALLMONTH 0x040 +#define F_ALLDAY 0x080 +#define F_VARIABLE 0x100 +#define F_EASTER 0x200 +#define F_CNY 0x400 +#define F_PASKHA 0x800 + +#define STRING_EASTER "Easter" +#define STRING_PASKHA "Paskha" +#define STRING_CNY "ChineseNewYear" +extern int debug; /* show parsing of the input */ extern int f_dayAfter; /* days after current date */ extern int f_dayBefore; /* days before current date */ extern int Friday; /* day before weekend */ Modified: user/edwin/calendar/day.c ============================================================================== --- user/edwin/calendar/day.c Mon Dec 21 21:04:41 2009 (r200812) +++ user/edwin/calendar/day.c Mon Dec 21 21:17:59 2009 (r200813) @@ -46,7 +46,8 @@ __FBSDID("$FreeBSD$"); #include "calendar.h" -struct tm *tp; +struct tm tp1, tp2; +time_t time1, time2; static const struct tm tm0; int *cumdays, yrdays; char dayname[10]; @@ -58,13 +59,23 @@ int daytab[][14] = { {0, -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, }; +static char const *fdays[] = { + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", + "Saturday", NULL, +}; + static char const *days[] = { - "sun", "mon", "tue", "wed", "thu", "fri", "sat", NULL, + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL, +}; + +static const char *fmonths[] = { + "January", "February", "March", "April", "May", "June", "Juli", + "August", "September", "October", "November", "December", NULL, }; static const char *months[] = { - "jan", "feb", "mar", "apr", "may", "jun", - "jul", "aug", "sep", "oct", "nov", "dec", NULL, + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL, }; static struct fixs fndays[8]; /* full national days names */ @@ -73,6 +84,9 @@ static struct fixs ndays[8]; /* short n static struct fixs fnmonths[13]; /* full national months names */ static struct fixs nmonths[13]; /* short national month names */ +static char *showflags(int flags); +static int isonlydigits(char *s, int star); + void setnnames(void) @@ -137,12 +151,13 @@ setnnames(void) } void -settime(time_t now) +settimes(time_t now, int before, int after) { char *oldl, *lbufp; + struct tm tp; - tp = localtime(&now); - if (isleap(tp->tm_year + 1900)) { + localtime_r(&now, &tp); + if (isleap(tp.tm_year + 1900)) { yrdays = 366; cumdays = daytab[1]; } else { @@ -151,7 +166,13 @@ settime(time_t now) } /* Friday displays Monday's events */ if (f_dayAfter == 0 && f_dayBefore == 0 && Friday != -1) - f_dayAfter = tp->tm_wday == Friday ? 3 : 1; + f_dayAfter = tp.tm_wday == Friday ? 3 : 1; + + time1 = now - SECSPERDAY * f_dayBefore; + localtime_r(&time1, &tp1); + time2 = now + SECSPERDAY * f_dayAfter; + localtime_r(&time2, &tp2); + header[5].iov_base = dayname; oldl = NULL; @@ -159,7 +180,7 @@ settime(time_t now) if (lbufp != NULL && (oldl = strdup(lbufp)) == NULL) errx(1, "cannot allocate memory"); (void)setlocale(LC_TIME, "C"); - header[5].iov_len = strftime(dayname, sizeof(dayname), "%A", tp); + header[5].iov_len = strftime(dayname, sizeof(dayname), "%A", &tp); (void)setlocale(LC_TIME, (oldl != NULL ? oldl : "")); if (oldl != NULL) free(oldl); @@ -175,15 +196,15 @@ Mktime(char *dp) { time_t t; int d, m, y; - struct tm tm; + struct tm tm, tp; (void)time(&t); - tp = localtime(&t); + localtime_r(&t, &tp); tm = tm0; - tm.tm_mday = tp->tm_mday; - tm.tm_mon = tp->tm_mon; - tm.tm_year = tp->tm_year; + tm.tm_mday = tp.tm_mday; + tm.tm_mon = tp.tm_mon; + tm.tm_year = tp.tm_year; switch (sscanf(dp, "%d.%d.%d", &d, &m, &y)) { case 3: @@ -206,6 +227,231 @@ Mktime(char *dp) } /* + * Expected styles: + * + * Date ::= Month . ' ' . DayOfMonth | + * Month . ' ' . DayOfWeek . ModifierIndex | + * Month . '/' . DayOfMonth | + * Month . '/' . DayOfWeek . ModifierIndex | + * DayOfMonth . ' ' . Month | + * DayOfMonth . '/' . Month | + * DayOfWeek . ModifierIndex . ' ' .Month | + * DayOfWeek . ModifierIndex . '/' .Month | + * DayOfWeek . ModifierIndex | + * SpecialDay . ModifierOffset + * + * Month ::= MonthName | MonthNumber | '*' + * MonthNumber ::= '0' ... '9' | '00' ... '09' | '10' ... '12' + * MonthName ::= MonthNameShort | MonthNameLong + * MonthNameLong ::= 'January' ... 'December' + * MonthNameShort ::= 'Jan' ... 'Dec' | 'Jan.' ... 'Dec.' + * + * DayOfWeek ::= DayOfWeekShort | DayOfWeekLong + * DayOfWeekShort ::= 'Mon' .. 'Sun' + * DayOfWeekLong ::= 'Monday' .. 'Sunday' + * DayOfMonth ::= '0' ... '9' | '00' ... '09' | '10' ... '29' | + * '30' ... '31' | '*' + * + * ModifierOffset ::= '' | '+' . ModifierNumber | '-' . ModifierNumber + * ModifierNumber ::= '0' ... '9' | '00' ... '99' | '000' ... '299' | + * '300' ... '359' | '360' ... '365' + * ModifierIndex ::= 'Second' | 'Third' | 'Fourth' | 'Fifth' | + * 'First' | 'Last' + * + * SpecialDay ::= 'Easter' | 'Pashka' | 'ChineseNewYear' + * + */ +int +determinestyle(char *date, int *flags, + char *month, int *imonth, char *dayofmonth, int *idayofmonth, + char *dayofweek, int *idayofweek, char *modifieroffset, + char *modifierindex, char *specialday) +{ + char *p, *dow, *pmonth, *p1, *p2; + char pold; + int len, offset; + + *flags = F_NONE; + *month = '\0'; + *imonth = 0; + *dayofmonth = '\0'; + *idayofmonth = 0; + *dayofweek = '\0'; + *idayofweek = 0; + *modifieroffset = '\0'; + *modifierindex = '\0'; + *specialday = '\0'; + +#define CHECKSPECIAL(s1, s2, lens2, type) \ + if (s2 != NULL && strncmp(s1, s2, lens2) == 0) { \ + *flags |= F_SPECIALDAY; \ + *flags |= type; \ + *flags |= F_VARIABLE; \ + if (strlen(s1) == lens2) { \ + strcpy(specialday, s1); \ + return (1); \ + } \ + strncpy(specialday, s1, lens2); \ + specialday[lens2] = '\0'; \ + strcpy(modifieroffset, s1 + lens2); \ + *flags |= F_MODIFIEROFFSET; \ + return (1); \ + } + + if ((p = strchr(date, ' ')) == NULL) { + if ((p = strchr(date, '/')) == NULL) { + CHECKSPECIAL(date, STRING_CNY, strlen(STRING_CNY), + F_CNY); + CHECKSPECIAL(date, ncny.name, ncny.len, F_CNY); + CHECKSPECIAL(date, STRING_PASKHA, + strlen(STRING_PASKHA), F_PASKHA); + CHECKSPECIAL(date, npaskha.name, npaskha.len, F_PASKHA); + CHECKSPECIAL(date, STRING_EASTER, + strlen(STRING_EASTER), F_EASTER); + CHECKSPECIAL(date, neaster.name, neaster.len, F_EASTER); + if (checkdayofweek(date, &len, &offset, &dow) != 0) { + *flags |= F_DAYOFWEEK; + *flags |= F_VARIABLE; + *idayofweek = offset; + if (strlen(date) == len) { + strcpy(dayofweek, date); + return (1); + } + strncpy(dayofweek, date, len); + dayofweek[len] = '\0'; + strcpy(modifierindex, date + len); + *flags |= F_MODIFIERINDEX; + return (1); + } + if (isonlydigits(date, 1)) { + /* Assume month number only */ + *flags |= F_MONTH; + *imonth = (int)strtol(date, (char **)NULL, 10); + strcpy(month, getmonthname(*imonth)); + return(1); + } + return (0); + } + } + + /* + * After this, leave by goto-ing to "allfine" or "fail" to restore the + * original data in `date'. + */ + pold = *p; + *p = 0; + p1 = date; + p2 = p + 1; + /* Now p2 points to the next field and p1 to the first field */ + + /* Check if there is a month-string in the date */ + if ((checkmonth(p1, &len, &offset, &pmonth) != 0) + || (checkmonth(p2, &len, &offset, &pmonth) != 0 && (p2 = p1))) { + /* p2 is the non-month part */ + *flags |= F_MONTH; + *imonth = offset; + + strcpy(month, getmonthname(offset)); + if (isonlydigits(p2, 1)) { + strcpy(dayofmonth, p2); + *idayofmonth = (int)strtol(p2, (char **)NULL, 10); + *flags |= F_DAYOFMONTH; + goto allfine; + } + if (strcmp(p2, "*") == 0) { + *flags |= F_ALLDAY; + goto allfine; + } + + if (checkdayofweek(p2, &len, &offset, &dow) != 0) { + *flags |= F_DAYOFWEEK; + *flags |= F_VARIABLE; + *idayofweek = offset; + strcpy(dayofweek, getdayofweekname(offset)); + if (strlen(p2) == len) + goto allfine; + strcpy(modifierindex, p2 + len); + *flags |= F_MODIFIERINDEX; + goto allfine; + } + + goto fail; + } + + /* Check if there is an every-day or every-month in the string */ + if ((strcmp(p1, "*") == 0 && isonlydigits(p2, 1)) + || (strcmp(p2, "*") == 0 && isonlydigits(p1, 1) && (p2 = p1))) { + int d; + + *flags |= F_ALLMONTH; + *flags |= F_DAYOFMONTH; + d = (int)strtol(p2, (char **)NULL, 10); + *idayofmonth = d; + sprintf(dayofmonth, "%d", d); + goto allfine; + } + + /* Month as a number, then a weekday */ + if (isonlydigits(p1, 1) + && checkdayofweek(p2, &len, &offset, &dow) != 0) { + int d; + + *flags |= F_MONTH; + *flags |= F_DAYOFWEEK; + *flags |= F_VARIABLE; + + *idayofweek = offset; + d = (int)strtol(p1, (char **)NULL, 10); + *imonth = d; + strcpy(month, getmonthname(d)); + + strcpy(dayofweek, getdayofweekname(offset)); + if (strlen(p2) == len) + goto allfine; + strcpy(modifierindex, p2 + len); + *flags |= F_MODIFIERINDEX; + goto allfine; + } + + /* If both the month and date are specified as numbers */ + if (isonlydigits(p1, 1) && isonlydigits(p2, 0)) { + /* Now who wants to be this ambigious? :-( */ + int m, d; + + if (strchr(p2, '*') != NULL) + *flags |= F_VARIABLE; + + m = (int)strtol(p1, (char **)NULL, 10); + d = (int)strtol(p2, (char **)NULL, 10); + + *flags |= F_MONTH; + *flags |= F_DAYOFMONTH; + + if (m > 12) { + *imonth = d; + *idayofmonth = m; + strcpy(month, getmonthname(d)); + sprintf(dayofmonth, "%d", m); + } else { + *imonth = m; + *idayofmonth = d; + strcpy(month, getmonthname(m)); + sprintf(dayofmonth, "%d", d); + } + goto allfine; + } + + /* FALLTHROUGH */ +fail: + *p = pold; + return (0); +allfine: + *p = pold; + return (1); + +} + +/* * Possible date formats include any combination of: * 3-charmonth (January, Jan, Jan) * 3-charweekday (Friday, Monday, mon.) @@ -216,9 +462,11 @@ Mktime(char *dp) * along with the matched line. */ int -isnow(char *endp, int *monthp, int *dayp, int *varp) +parsedaymonth(char *date, int *monthp, int *dayp, int *flags) { - int day, flags, month = 0, v1, v2; + char month[100], dayofmonth[100], dayofweek[100], modifieroffset[100]; + char modifierindex[100], specialday[100]; + int idayofweek, imonth, idayofmonth; /* * CONVENTION @@ -226,15 +474,46 @@ isnow(char *endp, int *monthp, int *dayp * Month: 1-12 * Monthname: Jan .. Dec * Day: 1-31 - * Weekday: Mon-Sun + * Weekday: Mon .. Sun * */ - flags = 0; + *flags = 0; - /* read first field */ - /* didn't recognize anything, skip it */ - if (!(v1 = getfield(endp, &endp, &flags))) + if (debug) + printf("-------\ndate: |%s|\n", date); + if (determinestyle(date, flags, month, &imonth, dayofmonth, + &idayofmonth, dayofweek, &idayofweek, modifieroffset, + modifierindex, specialday) == 0) { + if (debug) + printf("Failed!\n"); + return (0); + } + + if (debug) { + printf("flags: %x - %s\n", *flags, showflags(*flags)); + if (modifieroffset[0] != '\0') + printf("modifieroffset: |%s|\n", modifieroffset); + if (modifierindex[0] != '\0') + printf("modifierindex: |%s|\n", modifierindex); + if (month[0] != '\0') + printf("month: |%s| (%d)\n", month, imonth); + if (dayofmonth[0] != '\0') + printf("dayofmonth: |%s| (%d)\n", dayofmonth, + idayofmonth); + if (dayofweek[0] != '\0') + printf("dayofweek: |%s| (%d)\n", dayofweek, idayofweek); + if (specialday[0] != '\0') + printf("specialday: |%s|\n", specialday); + } + + if ((*flags & !F_VARIABLE) == (F_MONTH | F_DAYOFMONTH)) { + } + + return (0); + +#ifdef NOTDEF + if (!(v1 = getfield(date, &flags))) return (0); /* Easter or Easter depending days */ @@ -254,7 +533,7 @@ isnow(char *endp, int *monthp, int *dayp /* {Day,Weekday} {Month,Monthname} ... */ /* if no recognizable month, assume just a day alone * in other words, find month or use current month */ - if (!(month = getfield(endp, &endp, &flags))) + if (!(month = getfield(endp, &flags))) month = tp->tm_mon + 1; } @@ -264,13 +543,13 @@ isnow(char *endp, int *monthp, int *dayp /* Monthname {day,weekday} */ /* if no recognizable day, assume the first day in month */ - if (!(day = getfield(endp, &endp, &flags))) + if (!(day = getfield(endp, &flags))) day = 1; } /* Hm ... */ else { - v2 = getfield(endp, &endp, &flags); + v2 = getfield(endp, &flags); /* * {Day} {Monthname} ... @@ -399,45 +678,145 @@ isnow(char *endp, int *monthp, int *dayp if (day >= before) return (1); } - +#endif return (0); } +static char * +showflags(int flags) +{ + static char s[1000]; + s[0] = '\0'; + + if ((flags & F_MONTH) != 0) + strcat(s, "month "); + if ((flags & F_DAYOFWEEK) != 0) + strcat(s, "dayofweek "); + if ((flags & F_DAYOFMONTH) != 0) + strcat(s, "dayofmonth "); + if ((flags & F_MODIFIERINDEX) != 0) + strcat(s, "modifierindex "); + if ((flags & F_MODIFIEROFFSET) != 0) + strcat(s, "modifieroffset "); + if ((flags & F_SPECIALDAY) != 0) + strcat(s, "specialday "); + if ((flags & F_ALLMONTH) != 0) + strcat(s, "allmonth "); + if ((flags & F_ALLDAY) != 0) + strcat(s, "allday "); + if ((flags & F_VARIABLE) != 0) + strcat(s, "variable "); + if ((flags & F_CNY) != 0) + strcat(s, "chinesenewyear "); + if ((flags & F_PASKHA) != 0) + strcat(s, "paskha "); + if ((flags & F_EASTER) != 0) + strcat(s, "easter "); + + return s; +} + +char * +getmonthname(int i) +{ + if (nmonths[i - 1].len != 0 && nmonths[i - 1].name != NULL) + return (nmonths[i - 1].name); + return ((char *)months[i - 1]); +} + int -getmonth(char *s) +checkmonth(char *s, int *len, int *offset, char **month) { - const char **p; struct fixs *n; + int i; - for (n = fnmonths; n->name; ++n) - if (!strncasecmp(s, n->name, n->len)) - return ((n - fnmonths) + 1); - for (n = nmonths; n->name; ++n) - if (!strncasecmp(s, n->name, n->len)) - return ((n - nmonths) + 1); - for (p = months; *p; ++p) - if (!strncasecmp(s, *p, 3)) - return ((p - months) + 1); + for (i = 0; fnmonths[i].name != NULL; i++) { + n = fnmonths + i; + if (strncasecmp(s, n->name, n->len) == 0) { + *len = n->len; + *month = n->name; + *offset = i + 1; + return (1); + } + } + for (i = 0; nmonths[i].name != NULL; i++) { + n = nmonths + i; + if (strncasecmp(s, n->name, n->len) == 0) { + *len = n->len; + *month = n->name; + *offset = i + 1; + return (1); + } + } + for (i = 0; fmonths[i] != NULL; i++) { + *len = strlen(fmonths[i]); + if (strncasecmp(s, fmonths[i], *len) == 0) { + *month = (char *)fmonths[i]; + *offset = i + 1; + return (1); + } + } + for (i = 0; months[i] != NULL; i++) { + if (strncasecmp(s, months[i], 3) == 0) { + *len = 3; + *month = (char *)months[i]; + *offset = i + 1; + return (1); + } + } return (0); } +char * +getdayofweekname(int i) +{ + if (ndays[i].len != 0 && ndays[i].name != NULL) + return (ndays[i].name); + return ((char *)days[i]); +} + int -getday(char *s) +checkdayofweek(char *s, int *len, int *offset, char **dow) { - const char **p; struct fixs *n; + int i; - for (n = fndays; n->name; ++n) - if (!strncasecmp(s, n->name, n->len)) - return ((n - fndays) + 1); - for (n = ndays; n->name; ++n) - if (!strncasecmp(s, n->name, n->len)) - return ((n - ndays) + 1); - for (p = days; *p; ++p) - if (!strncasecmp(s, *p, 3)) - return ((p - days) + 1); + for (i = 0; fndays[i].name != NULL; i++) { + n = fndays + i; + if (strncasecmp(s, n->name, n->len) == 0) { + *len = n->len; + *dow = n->name; + *offset = i; + return (1); + } + } + for (i = 0; ndays[i].name != NULL; i++) { + n = ndays + i; + if (strncasecmp(s, n->name, n->len) == 0) { + *len = n->len; + *dow = n->name; + *offset = i; + return (1); + } + } + for (i = 0; fdays[i] != NULL; i++) { + *len = strlen(fdays[i]); + if (strncasecmp(s, fdays[i], *len) == 0) { + *dow = (char *)fdays[i]; + *offset = i; + return (1); + } + } + for (i = 0; days[i] != NULL; i++) { + if (strncasecmp(s, days[i], 3) == 0) { + *len = 3; + *dow = (char *)days[i]; + *offset = i; + return (1); + } + } return (0); } @@ -483,3 +862,18 @@ getdayvar(char *s) /* no offset detected */ return (0); } + + +static int +isonlydigits(char *s, int nostar) +{ + int i; + for (i = 0; s[i] != '\0'; i++) { + if (nostar == 0 && s[i] == '*' && s[i + 1] == '\0') + return 1; + if (!isdigit(s[i])) + return (0); + } + return (1); +} + Modified: user/edwin/calendar/io.c ============================================================================== --- user/edwin/calendar/io.c Mon Dec 21 21:04:41 2009 (r200812) +++ user/edwin/calendar/io.c Mon Dec 21 21:17:59 2009 (r200813) @@ -90,7 +90,7 @@ const char *calendarNoMail = "nomail"; / char path[MAXPATHLEN]; -struct fixs neaster, npaskha; +struct fixs neaster, npaskha, ncny; struct iovec header[] = { {"From: ", 6}, @@ -102,26 +102,37 @@ struct iovec header[] = { {"'s Calendar\nPrecedence: bulk\n\n", 30}, }; +#define MAXCOUNT 55 void cal(void) { - int printing; - char *p; + char *pp, p; FILE *fp; int ch, l; - int month; - int day; - int var; + int count, i; + int month[MAXCOUNT]; + int day[MAXCOUNT]; + int flags; static int d_first = -1; char buf[2048 + 1]; - struct event *events = NULL; + struct event *events[MAXCOUNT]; + struct event *eventshead = NULL; + struct tm tm; + char dbuf[80]; + + /* Unused */ + tm.tm_sec = 0; + tm.tm_min = 0; + tm.tm_hour = 0; + tm.tm_wday = 0; if ((fp = opencal()) == NULL) return; - for (printing = 0; fgets(buf, sizeof(buf), stdin) != NULL;) { - if ((p = strchr(buf, '\n')) != NULL) - *p = '\0'; + while (fgets(buf, sizeof(buf), stdin) != NULL) { + if ((pp = strchr(buf, '\n')) != NULL) + *pp = '\0'; else + /* Flush this line */ while ((ch = getchar()) != '\n' && ch != EOF); for (l = strlen(buf); l > 0 && isspace((unsigned char)buf[l - 1]); @@ -130,6 +141,8 @@ cal(void) buf[l] = '\0'; if (buf[0] == '\0') continue; + + /* Parse special definitions: LANG, Easter and Paskha */ if (strncmp(buf, "LANG=", 5) == 0) { (void)setlocale(LC_ALL, buf + 5); d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); @@ -152,38 +165,54 @@ cal(void) npaskha.len = strlen(buf + 7); continue; } - if (buf[0] != '\t') { - printing = isnow(buf, &month, &day, &var) ? 1 : 0; - if ((p = strchr(buf, '\t')) == NULL) - continue; - if (p > buf && p[-1] == '*') - var = 1; - if (printing) { - struct tm tm; - char dbuf[80]; - - if (d_first < 0) - d_first = - (*nl_langinfo(D_MD_ORDER) == 'd'); - tm.tm_sec = 0; /* unused */ - tm.tm_min = 0; /* unused */ - tm.tm_hour = 0; /* unused */ - tm.tm_wday = 0; /* unused */ - tm.tm_mon = month - 1; - tm.tm_mday = day; - tm.tm_year = tp->tm_year; /* unused */ - (void)strftime(dbuf, sizeof(dbuf), - d_first ? "%e %b" : "%b %e", &tm); - events = event_add(events, month, day, dbuf, - var, p); - } - } else { - if (printing) - event_continue(events, buf); + + /* + * If the line starts with a tab, the data has to be + * added to the previous line + */ + if (buf[0] == '\t') { + for (i = 0; i < count; i++) + event_continue(events[i], buf); + continue; + } + + /* Get rid of leading spaces (non-standard) */ + while (isspace(buf[0])) + memcpy(buf, buf + 1, strlen(buf) - 1); + + /* No tab in the line, then not a valid line */ + if ((pp = strchr(buf, '\t')) == NULL) + continue; + + /* Trim spaces in front of the tab */ + while (isspace(pp[-1])) + pp--; + p = *pp; + *pp = '\0'; + if ((count = parsedaymonth(buf, month, day, &flags)) == 0) + continue; + *pp = p; + /* Find the last tab */ + while (pp[1] == '\t') + pp++; + + if (d_first < 0) + d_first = + (*nl_langinfo(D_MD_ORDER) == 'd'); + + for (i = 0; i < count; i++) { + tm.tm_mon = month[i] - 1; + tm.tm_mday = day[i]; + tm.tm_year = tp1.tm_year; /* unused */ + (void)strftime(dbuf, sizeof(dbuf), + d_first ? "%e %b" : "%b %e", &tm); + eventshead = event_add(eventshead, month[i], day[i], + dbuf, (flags &= F_VARIABLE != 0) ? 1 : 0, pp); + events[i] = eventshead; } } - event_print_all(fp, events); + event_print_all(fp, eventshead); closecal(fp); } @@ -263,7 +292,7 @@ event_print_all(FILE *fp, struct event * */ for (daycounter = 0; daycounter <= f_dayAfter + f_dayBefore; daycounter++) { - day = tp->tm_yday - f_dayBefore + daycounter; + day = tp1.tm_yday - f_dayBefore + daycounter; if (day < 0) day += yrdays; if (day >= yrdays) @@ -303,74 +332,77 @@ event_print_all(FILE *fp, struct event * } } -int -getfield(char *p, char **endp, int *flags) -{ - int val, var; - char *start, savech; - - for (; !isdigit((unsigned char)*p) && !isalpha((unsigned char)*p) - && *p != '*'; ++p) - ; - if (*p == '*') { /* `*' is current month */ - *flags |= F_ISMONTH; - *endp = p + 1; - return (tp->tm_mon + 1); - } - if (isdigit((unsigned char)*p)) { - val = strtol(p, &p, 10); /* if 0, it's failure */ - for (; !isdigit((unsigned char)*p) - && !isalpha((unsigned char)*p) && *p != '*'; ++p); - *endp = p; - return (val); - } - for (start = p; isalpha((unsigned char)*++p);); - - /* Sunday-1 */ - if (*p == '+' || *p == '-') - for(; isdigit((unsigned char)*++p);) - ; - - savech = *p; - *p = '\0'; - - /* Month */ - if ((val = getmonth(start)) != 0) - *flags |= F_ISMONTH; - - /* Day */ - else if ((val = getday(start)) != 0) { - *flags |= F_ISDAY; - - /* variable weekday */ - if ((var = getdayvar(start)) != 0) { - if (var <= 5 && var >= -4) - val += var * 10; -#ifdef DEBUG - printf("var: %d\n", var); +#ifdef NOTDEF +//int +//getfield(char *p, int *flags) +//{ +// int val, var; +// char *start, savech; +// +// if (*p == '\0') +// return(0); +// +// /* Find the first digit, alpha or * */ +// for (; !isdigit((unsigned char)*p) && !isalpha((unsigned char)*p) +// && *p != '*'; ++p) +// ; +// if (*p == '*') { /* `*' is current month */ +// *flags |= F_ISMONTH; +// return (tp->tm_mon + 1); +// } +// if (isdigit((unsigned char)*p)) { +// val = strtol(p, &p, 10); /* if 0, it's failure */ +// for (; !isdigit((unsigned char)*p) +// && !isalpha((unsigned char)*p) && *p != '*'; ++p); +// return (val); +// } +// for (start = p; isalpha((unsigned char)*++p);); +// +// /* Sunday-1 */ +// if (*p == '+' || *p == '-') +// for(; isdigit((unsigned char)*++p);) +// ; +// +// savech = *p; +// *p = '\0'; +// +// /* Month */ +// if ((val = getmonth(start)) != 0) +// *flags |= F_ISMONTH; *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Tue Dec 22 06:09:00 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 506641065670; Tue, 22 Dec 2009 06:09:00 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 3E3988FC0C; Tue, 22 Dec 2009 06:09:00 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBM690Ga052313; Tue, 22 Dec 2009 06:09:00 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBM690xD052311; Tue, 22 Dec 2009 06:09:00 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200912220609.nBM690xD052311@svn.freebsd.org> From: Kip Macy Date: Tue, 22 Dec 2009 06:09:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200828 - user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 06:09:00 -0000 Author: kmacy Date: Tue Dec 22 06:09:00 2009 New Revision: 200828 URL: http://svn.freebsd.org/changeset/base/200828 Log: - re-write comments to reflect API changes - implement hash table for mapping VA to struct buf * - remove va splay tree code - re-implement zio_sync_cache so that all page cache synchronization logic occurs there - implement zio_cache_valid Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Tue Dec 22 02:15:36 2009 (r200827) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Tue Dec 22 06:09:00 2009 (r200828) @@ -30,51 +30,51 @@ POSSIBILITY OF SUCH DAMAGE. /************************************************************************** This module integrates the caching af pages associated with ARC buffers in a per-SPA vm object. Each SPA also has an associated "zio_state_t" which -tracks bufs allocated for the SPA in two splay trees. +tracks mapped bufs allocated for the SPA in a splay tree. -The first splay tree tracks bufs by the data pointer's virtual address. -It is used for malloc'ed buffers, and buffers that are VMIO but do not have -any pages in the SPA's vm object(s). - -Buffers are malloced if: - 1) the size is not a multiple of PAGE_SIZE - 2) the buffer is cloned - -There are two reasons why a VMIO buf would not have any pages in the vm object: - 1) the buffer has not yet been assigned an address on disk (and thus - has no offset in the vm object) - 2) the buffer did have pages in the vm object, but they were evicted - and replaced by a newer - -The second splay tree tracks buffers by block address and is only used -to track buffers whose pages are referenced by the vm object. It is used to +A global lookup table (currently splay tree, subject to change) is used to +map the data KVA to the struct buf. This allows us to provide page cache +integration without churning ZFS' malloc-centric interfaces that only pass +the data address around. + +Buffers are malloced if the size is not a multiple of PAGE_SIZE, and thus +the buffer could not be an integer number of pages. + +ZFS does not provide any block information when allocating a buffer. +Thus, even page backed buffers are unmapped at allocation time. Buffers +are mapped to an address in zio_sync_cache (called from zio_create), +where they are either added to or removed from the page cache backing +the vdev. Once the buffer is mapped a second splay tree tracks buffers +by block address whose pages are referenced by the vm object. It is used to ensure that buffers that belong to an older transaction group don't have their pages mapped by buffers belonging to a newer transaction group. -zfs_bio assumes that buffers that are cloned and buffers whose pages -are evicted from the vm object are not used for I/O (will not be referenced -from zfs_bio_sync_cache). - -Pages in the vm object are marked valid on completion of a read or before the -initiation of a write. - +Pages in the vm object are marked valid before the initiation of a write +and on completion of a read. -There are two places where we synchronize the ARC with the vm object's -page cache: getblk and sync_cache. - -In getblk for a malloced buffer we check if the page at the corresponding offset -is valid, if it is map it in and copy it in to the new buffer. For a VMIO buffer -we need to remove the pages for any existing overlapping buffers and free any -other pages in the vm object. - -In sync_cache for a malloced buffer we need to evict pages belonging to overlapping -VMIO buffers, then copy to/from any pages still in the vm object. For an unmapped -VMIO buffer, we need to remove pages belonging to any existing buffers and free -any remaining overlapping pages in the vm object. We then add the VMIO buffers -pages to a VM object. If the buffer is already mapped we mark the pages valid on a -write, on a read we set a flag in the zio and mark the pages valid before calling -the io_done I/O completion function. +Logic in sync_cache: + B_MALLOC: + evict older txg + READ: + copyin from page cache + WRITE: + copyout to page cache + !B_MALLOC: + READ: + evict older txg + if (cached pages all valid) + free current buffer pages and map in cached pages + else + remove all pages from object + insert current buffer's pages + WRITE: + evict older txg + pages + mark buffer's pages as valid + insert buffer's pages in the object + mark buffer B_VMIO + B_VMIO: + No work to do **************************************************************************/ @@ -97,11 +97,6 @@ __FBSDID("$FreeBSD$"); #ifdef _KERNEL -#define BUF_EMPTY(buf) \ - ((buf)->b_dva.dva_word[0] == 0 && \ - (buf)->b_dva.dva_word[1] == 0 && \ - (buf)->b_birth == 0) - SYSCTL_DECL(_vfs_zfs); int zfs_page_cache_disable = 1; TUNABLE_INT("vfs.zfs.page_cache_disable", &zfs_page_cache_disable); @@ -109,9 +104,9 @@ SYSCTL_INT(_vfs_zfs, OID_AUTO, page_cach &zfs_page_cache_disable, 0, "Disable backing ARC with page cache "); static eventhandler_tag zfs_bio_event_shutdown = NULL; -struct zio_state; -typedef struct zio_state zio_state_t; -typedef struct buf buf_t; +struct zio_spa_state; +typedef struct zio_spa_state * zio_spa_state_t; +typedef struct buf * buf_t; MALLOC_DEFINE(M_ZFS_BIO, "zfs_bio", "zfs buffer cache / vm"); @@ -132,29 +127,182 @@ MALLOC_DEFINE(M_ZFS_BIO, "zfs_bio", "zfs #define b_state b_fsprivate3 -struct zio_state { - struct mtx mtx; - buf_t *blkno_root; /* track buf by blkno */ - buf_t *va_root; /* track buf by data address */ - spa_t *spa; - int generation; - int resident_count; - TAILQ_HEAD(, buf) blkno_memq; /* list of resident buffers */ - TAILQ_HEAD(, buf) va_memq; /* list of resident buffers */ +struct zio_spa_state { + struct mtx zss_mtx; + buf_t zss_blkno_root; /* track buf by blkno */ + + spa_t *zss_spa; + int zss_generation; + int zss_resident_count; + TAILQ_HEAD(, buf) zss_blkno_memq; /* list of resident buffers */ }; +/* + * Hash table routines + */ -static zio_state_t global_state; +#define HT_LOCK_PAD 128 -#define ZIO_STATE_LOCK(zs) mtx_lock(&(zs)->mtx) -#define ZIO_STATE_UNLOCK(zs) mtx_unlock(&(zs)->mtx) +struct ht_lock { + struct mtx ht_lock; +#ifdef _KERNEL + unsigned char pad[(HT_LOCK_PAD - sizeof (struct mtx))]; +#endif +}; -#define spa_get_zio_state(spa) ((zio_state_t *)spa_get_vnode((spa))->v_data) +typedef struct cluster_list_head * buf_head_t; + +#define BUF_LOCKS 256 +typedef struct buf_hash_table { + uint64_t ht_mask; + buf_head_t ht_table; + struct ht_lock ht_locks[BUF_LOCKS] __aligned(128); +} buf_hash_table_t; + +static buf_hash_table_t buf_hash_table; + +#define BUF_HASH_INDEX(va, size) \ + (buf_hash(va, size) & buf_hash_table.ht_mask) +#define BUF_HASH_LOCK_NTRY(idx) (buf_hash_table.ht_locks[idx & (BUF_LOCKS-1)]) +#define BUF_HASH_LOCK(idx) (&(BUF_HASH_LOCK_NTRY(idx).ht_lock)) + +#define ZIO_SPA_STATE_LOCK(zs) mtx_lock(&(zs)->zss_mtx) +#define ZIO_SPA_STATE_UNLOCK(zs) mtx_unlock(&(zs)->zss_mtx) + +#define spa_get_zio_state(spa) ((zio_spa_state_t)spa_get_vnode((spa))->v_data) #define spa_get_vm_object(spa) spa_get_vnode((spa))->v_object -#define zio_buf_get_spa(bp) (((zio_state_t *)bp->b_state)->spa) +#define zio_buf_get_spa(bp) (((zio_spa_state_t)bp->b_state)->zss_spa) #define zio_buf_get_vm_object(bp) spa_get_vm_object(zio_buf_get_spa((bp))) -static void zio_buf_blkno_remove(buf_t *bp); -static void zio_buf_va_insert(buf_t *bp); +static uint64_t +buf_hash(caddr_t va, uint64_t size) +{ + uint8_t *vav = (uint8_t *)&va; + uint64_t crc = -1ULL; + int i; + + ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY); + + for (i = i; i < sizeof (caddr_t); i++) + crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ vav[i]) & 0xFF]; + + crc ^= (size>>9); + + return (crc); +} + +static void +buf_init(void) +{ + uint64_t *ct; + uint64_t hsize = 1ULL << 12; + int i, j; + + /* + * The hash table is big enough to fill all of physical memory + * with an average 64K block size. The table will take up + * totalmem*sizeof(void*)/64K (eg. 128KB/GB with 8-byte pointers). + */ + while (hsize * 65536 < (uint64_t)physmem * PAGESIZE) + hsize <<= 1; +retry: + buf_hash_table.ht_mask = hsize - 1; + buf_hash_table.ht_table = + malloc(hsize * sizeof (buf_head_t), M_ZFS_BIO, M_WAITOK|M_ZERO); + if (buf_hash_table.ht_table == NULL) { + ASSERT(hsize > (1ULL << 8)); + hsize >>= 1; + goto retry; + } + + for (i = 0; i < hsize; i++) + TAILQ_INIT(&buf_hash_table.ht_table[i]); + + for (i = 0; i < BUF_LOCKS; i++) + mtx_init(&buf_hash_table.ht_locks[i].ht_lock, "ht_lock", NULL, MTX_DEF); +} + +/* + * zio_buf_insert: [ internal use only ] + * + * Inserts the given buf into the state splay tree and state list. + * + * The object and page must be locked. + * This routine may not block. + */ +static void +zio_buf_va_insert(buf_t bp) +{ + caddr_t va = bp->b_data; + uint64_t idx, size = bp->b_bcount; + struct mtx *lock; + buf_head_t bh; + + idx = BUF_HASH_INDEX(va, size); + lock = BUF_HASH_LOCK(idx); + bh = &buf_hash_table.ht_table[idx]; + mtx_lock(lock); + TAILQ_INSERT_HEAD(bh, bp, b_bobufs); + mtx_unlock(lock); +} + +/* + * zio_buf_va_lookup: + * + * Returns the range associated with the object/offset + * pair specified; if none is found, NULL is returned. + * + * The object must be locked. + * This routine may not block. + * This is a critical path routine + */ +static buf_t +zio_buf_va_lookup(caddr_t va, uint64_t size) +{ + buf_t bp; + uint64_t idx; + struct mtx *lock; + buf_head_t bh; + + idx = BUF_HASH_INDEX(va, size); + lock = BUF_HASH_LOCK(idx); + bh = &buf_hash_table.ht_table[idx]; + mtx_lock(lock); + TAILQ_FOREACH(bp, bh, b_bobufs) + if (bp->b_data == va) + break; + mtx_unlock(lock); + return (bp); +} + +/* + * zio_buf_va_remove: + * + * Removes the given buf from the spa's state tree + * buf list + * + * The state and buf must be locked. + * This routine may not block. + */ +static buf_t +zio_buf_va_remove(caddr_t va, uint64_t size) +{ + uint64_t idx; + struct mtx *lock; + buf_head_t bh; + buf_t bp; + + idx = BUF_HASH_INDEX(va, size); + lock = BUF_HASH_LOCK(idx); + bh = &buf_hash_table.ht_table[idx]; + mtx_lock(lock); + TAILQ_FOREACH(bp, bh, b_bobufs) + if (bp->b_data == va) { + TAILQ_REMOVE(bh, bp, b_bobufs); + break; + } + mtx_unlock(lock); + return (bp); +} /* * zio_buf_blkno_splay: [ internal use only ] @@ -164,15 +312,15 @@ static void zio_buf_va_insert(buf_t *bp) * lblkno is not found in the tree, returns a buf that is * adjacent to the pindex, coming before or after it. */ -static buf_t * -zio_buf_blkno_splay(daddr_t blkno, buf_t *root) +static buf_t +zio_buf_blkno_splay(daddr_t blkno, buf_t root) { - buf_t dummy; - buf_t *lefttreemax, *righttreemin, *y; + struct buf dummy; + buf_t lefttreemax, righttreemin, y; if (root == NULL) return (root); - lefttreemax = righttreemin = &dummy; + lefttreemax = righttreemin = (buf_t)&dummy; for (;; root = y) { if (blkno < root->b_blkno) { if ((y = root->b_left) == NULL) @@ -213,55 +361,6 @@ zio_buf_blkno_splay(daddr_t blkno, buf_t return (root); } -static buf_t * -zio_buf_va_splay(caddr_t va, buf_t *root) -{ - buf_t dummy; - buf_t *lefttreemax, *righttreemin, *y; - - if (root == NULL) - return (root); - lefttreemax = righttreemin = &dummy; - for (;; root = y) { - if (va < root->b_data) { - if ((y = root->b_left) == NULL) - break; - if (va < y->b_data) { - /* Rotate right. */ - root->b_left = y->b_right; - y->b_right = root; - root = y; - if ((y = root->b_left) == NULL) - break; - } - /* Link into the new root's right tree. */ - righttreemin->b_left = root; - righttreemin = root; - } else if (va > root->b_data) { - if ((y = root->b_right) == NULL) - break; - if (va > y->b_data) { - /* Rotate left. */ - root->b_right = y->b_left; - y->b_left = root; - root = y; - if ((y = root->b_right) == NULL) - break; - } - /* Link into the new root's left tree. */ - lefttreemax->b_right = root; - lefttreemax = root; - } else - break; - } - /* Assemble the new root. */ - lefttreemax->b_right = root->b_left; - righttreemin->b_left = root->b_right; - root->b_left = dummy.b_right; - root->b_right = dummy.b_left; - return (root); -} - /* * zio_buf_blkno_insert: [ internal use only ] * @@ -271,19 +370,19 @@ zio_buf_va_splay(caddr_t va, buf_t *root * This routine may not block. */ static void -zio_buf_blkno_insert(buf_t *bp, zio_state_t *object) +zio_buf_blkno_insert(buf_t bp, zio_spa_state_t object) { - buf_t *root; + buf_t root; daddr_t root_blkno_end, blkno, blkno_end; blkno = bp->b_blkno; blkno_end = bp->b_blkno + btos(bp->b_bcount); - root = object->blkno_root; + root = object->zss_blkno_root; if (root == NULL) { bp->b_left = NULL; bp->b_right = NULL; - TAILQ_INSERT_TAIL(&object->blkno_memq, bp, b_bobufs); + TAILQ_INSERT_TAIL(&object->zss_blkno_memq, bp, b_bobufs); } else { root = zio_buf_blkno_splay(bp->b_blkno, root); root_blkno_end = root->b_blkno + btos(root->b_bcount); @@ -302,61 +401,39 @@ zio_buf_blkno_insert(buf_t *bp, zio_stat bp->b_right = root->b_right; bp->b_left = root; root->b_right = NULL; - TAILQ_INSERT_AFTER(&object->blkno_memq, root, bp, b_bobufs); + TAILQ_INSERT_AFTER(&object->zss_blkno_memq, root, bp, b_bobufs); } } - object->blkno_root = bp; - object->generation++; + object->zss_blkno_root = bp; + object->zss_generation++; /* * show that the object has one more resident buffer. */ - object->resident_count++; + object->zss_resident_count++; } /* - * zio_buf_insert: [ internal use only ] + * zio_buf_blkno_lookup: * - * Inserts the given buf into the state splay tree and state list. + * Returns the range associated with the object/offset + * pair specified; if none is found, NULL is returned. * - * The object and page must be locked. + * The object must be locked. * This routine may not block. + * This is a critical path routine */ -static void -zio_buf_va_insert(buf_t *bp) +static buf_t +zio_buf_blkno_lookup(zio_spa_state_t state, daddr_t blkno) { - buf_t *root; - caddr_t va = bp->b_data; - zio_state_t *object = &global_state; + buf_t bp; - root = object->va_root; - if (root == NULL) { - bp->b_left = NULL; - bp->b_right = NULL; - TAILQ_INSERT_TAIL(&object->va_memq, bp, b_bobufs); - } else { - root = zio_buf_va_splay(bp->b_data, root); - if (va < root->b_data) { - bp->b_left = root->b_left; - bp->b_right = root; - root->b_left = NULL; - TAILQ_INSERT_BEFORE(root, bp, b_bobufs); - } else if (va == root->b_data) { - panic("zio_buf_va_insert: address already allocated"); - } else { - bp->b_right = root->b_right; - bp->b_left = root; - root->b_right = NULL; - TAILQ_INSERT_AFTER(&object->va_memq, root, bp, b_bobufs); - } + if ((bp = state->zss_blkno_root) != NULL && bp->b_blkno != blkno) { + bp = zio_buf_blkno_splay(blkno, bp); + if ((state->zss_blkno_root = bp)->b_blkno != blkno) + bp = NULL; } - object->va_root = bp; - object->generation++; - - /* - * show that the object has one more resident buffer. - */ - object->resident_count++; + return (bp); } /* @@ -369,10 +446,10 @@ zio_buf_va_insert(buf_t *bp) * This routine may not block. */ static void -zio_buf_blkno_remove(buf_t *bp) +zio_buf_blkno_remove(buf_t bp) { - zio_state_t *state; - buf_t *root; + zio_spa_state_t state; + buf_t root; daddr_t blkno, blkno_end; if ((state = bp->b_state) == NULL) @@ -381,113 +458,26 @@ zio_buf_blkno_remove(buf_t *bp) /* * Now remove from the object's list of backed pages. */ - if (bp != state->blkno_root) - zio_buf_blkno_splay(bp->b_blkno, state->blkno_root); + if (bp != state->zss_blkno_root) + zio_buf_blkno_splay(bp->b_blkno, state->zss_blkno_root); if (bp->b_left == NULL) root = bp->b_right; else { root = zio_buf_blkno_splay(bp->b_blkno, bp->b_left); root->b_right = bp->b_right; } - state->blkno_root = root; - TAILQ_REMOVE(&state->blkno_memq, bp, b_bobufs); - - /* - * And show that the object has one fewer resident page. - */ - state->resident_count--; - state->generation++; -} - -/* - * zio_buf_va_remove: - * - * Removes the given buf from the spa's state tree - * buf list - * - * The state and buf must be locked. - * This routine may not block. - */ -static void -zio_buf_va_remove(buf_t *bp) -{ - zio_state_t *state; - buf_t *root; - vm_offset_t va; - - if ((state = bp->b_state) == NULL) - return; - - /* - * Now remove from the object's list of backed pages. - */ - if (bp != state->va_root) - zio_buf_va_splay(bp->b_data, state->va_root); - if (bp->b_left == NULL) - root = bp->b_right; - else { - root = zio_buf_va_splay(bp->b_data, bp->b_left); - root->b_right = bp->b_right; - } - state->va_root = root; - TAILQ_REMOVE(&state->va_memq, bp, b_bobufs); + state->zss_blkno_root = root; + TAILQ_REMOVE(&state->zss_blkno_memq, bp, b_bobufs); /* * And show that the object has one fewer resident page. */ - state->resident_count--; - state->generation++; + state->zss_resident_count--; + state->zss_generation++; } -/* - * zio_buf_va_lookup: - * - * Returns the range associated with the object/offset - * pair specified; if none is found, NULL is returned. - * - * The object must be locked. - * This routine may not block. - * This is a critical path routine - */ -static buf_t * -zio_buf_va_lookup(caddr_t va) -{ - buf_t *bp; - - if ((bp = global_state.va_root) != NULL && bp->b_data != va) { - bp = zio_buf_va_splay(va, bp); - if ((global_state.va_root = bp)->b_data != va) - bp = NULL; - } - return (bp); -} - - -/* - * zio_buf_blkno_lookup: - * - * Returns the range associated with the object/offset - * pair specified; if none is found, NULL is returned. - * - * The object must be locked. - * This routine may not block. - * This is a critical path routine - */ -static buf_t * -zio_buf_blkno_lookup(zio_state_t *state, daddr_t blkno) -{ - buf_t *bp; - - if ((bp = state->blkno_root) != NULL && bp->b_blkno != blkno) { - bp = zio_buf_blkno_splay(blkno, bp); - if ((state->blkno_root = bp)->b_blkno != blkno) - bp = NULL; - } - return (bp); -} - -static void -zio_buf_vm_object_copy(buf_t *bp, int direction) +static __inline void +zio_buf_vm_object_copy(buf_t bp, int direction) { vm_object_t object; vm_pindex_t start, end; @@ -540,21 +530,21 @@ done: } static void -zio_buf_vm_object_copyout(buf_t *bp) +zio_buf_vm_object_copyout(buf_t bp) { zio_buf_vm_object_copy(bp, ZB_COPYOUT); } static void -zio_buf_vm_object_copyin(buf_t *bp) +zio_buf_vm_object_copyin(buf_t bp) { zio_buf_vm_object_copy(bp, ZB_COPYIN); } static void -zio_buf_vm_object_evict(buf_t *bp) +zio_buf_vm_object_evict(buf_t bp) { int i; vm_page_t m; @@ -578,7 +568,7 @@ zio_buf_vm_object_evict(buf_t *bp) } static void -zio_buf_vm_object_insert_locked(buf_t *bp, struct vnode *vp, +zio_buf_vm_object_insert_locked(buf_t bp, struct vnode *vp, vm_object_t object, int valid) { vm_page_t m; @@ -604,7 +594,7 @@ zio_buf_vm_object_insert_locked(buf_t *b } static void -zio_buf_vm_object_insert(buf_t *bp, int valid) +zio_buf_vm_object_insert(buf_t bp, int valid) { spa_t *spa = zio_buf_get_spa(bp); struct vnode *vp = spa_get_vnode(spa); @@ -627,17 +617,17 @@ zio_buf_vm_object_insert(buf_t *bp, int * This routine may not block. */ static void -zio_buf_evict_overlap_locked(daddr_t blkno, int size, zio_state_t *state, +zio_buf_evict_overlap_locked(daddr_t blkno, int size, zio_spa_state_t state, uint64_t txg, int evict_op, vm_object_t object) { - buf_t *root, *tmpbp; + buf_t root, tmpbp; daddr_t blkno_end, tmpblkno, tmpblkno_end; struct cluster_list_head clh; int i, collisions; uint64_t tmptxg; vm_pindex_t start, end; - if ((root = state->blkno_root) == NULL) + if ((root = state->zss_blkno_root) == NULL) goto done; collisions = 0; @@ -671,12 +661,11 @@ zio_buf_evict_overlap_locked(daddr_t blk KASSERT(tmpbp->b_flags & B_EVICTED == 0, ("buffer has already been evicted")); tmpbp->b_flags |= B_EVICTED; - state->blkno_root = tmpbp; + state->zss_blkno_root = tmpbp; /* * move buffer to the unmanaged tree */ zio_buf_blkno_remove(tmpbp); - zio_buf_va_insert(tmpbp); } done: if (!(collisions == 1 && tmpbp->b_blkno == blkno && tmpbp->b_bcount == size) @@ -695,10 +684,10 @@ done: } static void -zio_buf_evict_overlap(daddr_t blkno, int size, zio_state_t *state, +zio_buf_evict_overlap(daddr_t blkno, int size, zio_spa_state_t state, uint64_t txg, int evict_op) { - vm_object_t object = spa_get_vm_object(state->spa); + vm_object_t object = spa_get_vm_object(state->zss_spa); VM_OBJECT_LOCK(object); zio_buf_evict_overlap_locked(blkno, size, state, txg, evict_op, object); @@ -707,6 +696,39 @@ zio_buf_evict_overlap(daddr_t blkno, int /* + * scan blkno + size range in object to verify that all the pages are + * resident and valid + */ +static int +vm_pages_valid_locked(vm_object_t object, uint64_t blkno, uint64_t size) +{ + + return (0); +} + +static int +vm_pages_valid(vm_object_t object, uint64_t blkno, uint64_t size) +{ + int valid; + + VM_OBJECT_LOCK(object); + valid = vm_pages_valid_locked(object, blkno, size); + VM_OBJECT_UNLOCK(object); + + return (valid); +} + +/* + * insert pages from object in to bp's b_pages + * and wire + */ +static void +vm_object_reference_pages(vm_object_t object, buf_t bp) +{ + +} + +/* Cases: A) B_MALLOC / address is known @@ -739,10 +761,10 @@ D) !B_MALLOC / address is known */ -static buf_t * +static buf_t _zio_getblk_malloc(uint64_t size, int flags) { - buf_t *newbp; + buf_t newbp; void *data; if (flags & GB_NODUMP) @@ -755,10 +777,10 @@ _zio_getblk_malloc(uint64_t size, int fl newbp->b_bcount = size; } -static buf_t * +static buf_t _zio_getblk_vmio(uint64_t size, int flags) { - buf_t *newbp; + buf_t newbp; newbp = geteblk(size, flags); BUF_KERNPROC(newbp); @@ -769,7 +791,7 @@ _zio_getblk_vmio(uint64_t size, int flag void * zio_getblk(uint64_t size, int flags) { - buf_t *newbp; + buf_t newbp; if (size & PAGE_MASK) newbp = _zio_getblk_malloc(size, flags); @@ -783,10 +805,9 @@ zio_getblk(uint64_t size, int flags) void zio_relse(void *data, size_t size) { - buf_t *bp; + buf_t bp; - bp = zio_buf_va_lookup(data); - zio_buf_va_remove(bp); + bp = zio_buf_va_remove(data, size); if (bp->b_flags & B_ASSIGNED) zio_buf_blkno_remove(bp); @@ -809,10 +830,10 @@ zio_relse(void *data, size_t size) int _zio_sync_cache(spa_t *spa, blkptr_t *blkp, uint64_t txg, void *data, - uint64_t size, zio_type_t bio_op) + uint64_t size, zio_type_t zio_op) { - buf_t *bp; - zio_state_t *state = spa_get_zio_state(spa); + buf_t bp; + zio_spa_state_t state = spa_get_zio_state(spa); dva_t dva = *BP_IDENTITY(blkp); daddr_t blkno = dva.dva_word[1] & ~(1ULL<<63); struct vnode *vp = spa_get_vnode(spa); @@ -821,47 +842,63 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl vm_page_t m; int i, io_bypass = FALSE; - /* - * XXX incomplete - */ - + bp = zio_buf_va_lookup(data, size); - if ((bp = zio_buf_va_lookup(data)) != NULL) { - KASSERT(bp->b_flags & B_EVICTED == 0, - ("doing I/O with cloned or evicted buffer 0x%x", bp->b_flags)); - - if (bp->b_flags & B_MALLOC) { - zio_buf_evict_overlap(blkno, size, state, txg, ZB_EVICT_BUFFERED); - - if (bio_op == BIO_READ) { - /* - * if page resident - copy in - * update zio pipeline - */ - zio_buf_vm_object_copyin(bp); - if (bp->b_flags & B_CACHE) { - /* update zio pipeline */ - io_bypass = TRUE; - } - } else { - zio_buf_vm_object_copyout(bp); + KASSERT(bp->b_flags & B_EVICTED == 0, + ("doing I/O with cloned or evicted buffer 0x%x", bp->b_flags)); + + if (bp->b_flags & B_MALLOC) { + zio_buf_evict_overlap(blkno, size, state, txg, ZB_EVICT_BUFFERED); + + if (zio_op == ZIO_TYPE_READ) { + /* + * if page resident - copy in + * update zio pipeline + */ + zio_buf_vm_object_copyin(bp); + if (bp->b_flags & B_CACHE) { + /* update zio pipeline */ + io_bypass = TRUE; } } else { - zio_buf_va_remove(bp); - VM_OBJECT_LOCK(object); - zio_buf_evict_overlap_locked(blkno, size, state, NO_TXG, - ZB_EVICT_ALL, object); - bp->b_blkno = bp->b_lblkno = blkno; - bp->b_flags |= (B_VMIO|B_ASSIGNED); - zio_buf_blkno_insert(bp, state); - zio_buf_vm_object_insert_locked(bp, vp, object, bio_op == BIO_WRITE); - VM_OBJECT_UNLOCK(object); + zio_buf_vm_object_copyout(bp); } + } else if (bp->b_flags & B_VMIO) { + KASSERT(bp == zio_buf_blkno_lookup(state, blkno), + ("VMIO buffer not mapped")); + if (zio_op == ZIO_TYPE_READ && (bp->b_flags & (B_CACHE|B_INVAL)) == B_CACHE) + io_bypass = TRUE; + } else if ((zio_op == ZIO_TYPE_WRITE) || !vm_pages_valid(object, blkno, size)) { + /* + * XXX still need to handle the case where the pages in the page cache are valid + * and we are doing a read + */ + + VM_OBJECT_LOCK(object); + zio_buf_evict_overlap_locked(blkno, size, state, NO_TXG, + ZB_EVICT_ALL, object); + bp->b_blkno = bp->b_lblkno = blkno; + bp->b_flags |= (B_VMIO|B_ASSIGNED); + bp->b_birth = txg; + zio_buf_blkno_insert(bp, state); + zio_buf_vm_object_insert_locked(bp, vp, object, zio_op == ZIO_TYPE_WRITE); + VM_OBJECT_UNLOCK(object); } else { - bp = zio_buf_blkno_lookup(state, blkno); - if (bio_op == BIO_READ && (bp->b_flags & (B_CACHE|B_INVAL)) == B_CACHE) - io_bypass = TRUE; - KASSERT(bp != NULL, ("blkno=%ld data=%p unmanaged", blkno, bp->b_data)); + KASSERT(zio_op == ZIO_TYPE_READ, ("unexpected op %d", zio_op)); + zio_buf_evict_overlap_locked(blkno, size, state, NO_TXG, + ZB_EVICT_BUFFERED, object); + bp->b_blkno = bp->b_lblkno = blkno; + bp->b_flags |= (B_VMIO|B_ASSIGNED); + bp->b_birth = txg; + zio_buf_blkno_insert(bp, state); + VM_OBJECT_LOCK(object); + if (vm_pages_valid_locked(object, blkno, size)) { + for (i = 0; i < bp->b_npages; i++) + vm_page_free(bp->b_pages[i]); + vm_object_reference_pages(object, bp); + } else + zio_buf_vm_object_insert_locked(bp, vp, object, FALSE); + VM_OBJECT_UNLOCK(object); } return (io_bypass); @@ -870,8 +907,14 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl void _zio_cache_valid(void *data, uint64_t size) { + buf_t bp; + int i; - + bp = zio_buf_va_lookup(data, size); + for (i = 0; i < bp->b_npages; i++) + bp->b_pages[i]->valid = VM_PAGE_BITS_ALL; + bp->b_flags &= ~B_INVAL; + bp->b_flags |= B_CACHE; } static void From owner-svn-src-user@FreeBSD.ORG Tue Dec 22 15:08:07 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 49D6610656C0; Tue, 22 Dec 2009 15:08:07 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 397778FC19; Tue, 22 Dec 2009 15:08:07 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBMF87Z3067515; Tue, 22 Dec 2009 15:08:07 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBMF87cF067513; Tue, 22 Dec 2009 15:08:07 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912221508.nBMF87cF067513@svn.freebsd.org> From: Luigi Rizzo Date: Tue, 22 Dec 2009 15:08:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200843 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 15:08:07 -0000 Author: luigi Date: Tue Dec 22 15:08:06 2009 New Revision: 200843 URL: http://svn.freebsd.org/changeset/base/200843 Log: remove extra whitespace Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Tue Dec 22 14:58:44 2009 (r200842) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Tue Dec 22 15:08:06 2009 (r200843) @@ -140,7 +140,6 @@ again: args.rule = dt->rule; args.rule_id = dt->rule_id; args.chain_id = dt->chain_id; - m_tag_delete(*m0, dn_tag); } @@ -273,7 +272,6 @@ again: args.rule = dt->rule; args.rule_id = dt->rule_id; args.chain_id = dt->chain_id; - m_tag_delete(*m0, dn_tag); } From owner-svn-src-user@FreeBSD.ORG Tue Dec 22 15:45:39 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1790310656A6; Tue, 22 Dec 2009 15:45:39 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 071BB8FC16; Tue, 22 Dec 2009 15:45:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBMFjcsk068404; Tue, 22 Dec 2009 15:45:38 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBMFjcKj068402; Tue, 22 Dec 2009 15:45:38 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912221545.nBMFjcKj068402@svn.freebsd.org> From: Luigi Rizzo Date: Tue, 22 Dec 2009 15:45:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200846 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 15:45:39 -0000 Author: luigi Date: Tue Dec 22 15:45:38 2009 New Revision: 200846 URL: http://svn.freebsd.org/changeset/base/200846 Log: add a comment on locking Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_table.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_table.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_table.c Tue Dec 22 15:41:58 2009 (r200845) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_table.c Tue Dec 22 15:45:38 2009 (r200846) @@ -34,6 +34,9 @@ __FBSDID("$FreeBSD$"); * keys are network prefixes (addr/masklen), and values are integers. * As a degenerate case we can interpret keys as 32-bit integers * (with a /32 mask). + * + * The table is protected by the IPFW lock even for manipulation coming + * from userland, because operations are typically fast. */ #if !defined(KLD_MODULE) From owner-svn-src-user@FreeBSD.ORG Tue Dec 22 16:06:39 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1E3451065697; Tue, 22 Dec 2009 16:06:39 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0C0A48FC1B; Tue, 22 Dec 2009 16:06:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBMG6d4q068953; Tue, 22 Dec 2009 16:06:39 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBMG6c65068942; Tue, 22 Dec 2009 16:06:38 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912221606.nBMG6c65068942@svn.freebsd.org> From: Luigi Rizzo Date: Tue, 22 Dec 2009 16:06:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200850 - in user/luigi/ipfw3-head/sys: net netgraph netinet netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 16:06:39 -0000 Author: luigi Date: Tue Dec 22 16:06:38 2009 New Revision: 200850 URL: http://svn.freebsd.org/changeset/base/200850 Log: complete the code for improved rule lookup in ipfw. Now we should have the following (Old is the code in HEAD; "Now" means the code in this commit; "Planned" is what i expect to achieve with small changes): Function Old Now Planned ------------------------------------------------------------------- + skipto X, non cached O(N) O(log N) XXX skipto X, cached O(1) O(log N) O(1) NOTE 1 XXX dynamic rule lookup O(1) O(log N) O(1) NOTE 1 + skipto tablearg O(N) O(log N) O(1) NOTE 2 + reinject from dummynet, non cached O(N) O(log N) + reinject from dummynet, cached O(1) O(1) + kernel blocked during setsockopt() O(N) O(1) NOTE 1: validating the cached entries requires an extra field in the rule structure, which in turn requires a bit of work to preserve the kernel-userland ABI. NOTE 2: currently there is no cache for skipto tablearg. It can be implemented rather trivially to achieve O(1) time on repeated jumps to the same target. As you can see there are a couple of places where we have a bit of regression, but in most cases there is a huge improvement, especially in the interference between userland and kernel. Modified: user/luigi/ipfw3-head/sys/net/if_bridge.c user/luigi/ipfw3-head/sys/net/if_ethersubr.c user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.c user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.h user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Modified: user/luigi/ipfw3-head/sys/net/if_bridge.c ============================================================================== --- user/luigi/ipfw3-head/sys/net/if_bridge.c Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/net/if_bridge.c Tue Dec 22 16:06:38 2009 (r200850) @@ -3039,20 +3039,23 @@ bridge_pfil(struct mbuf **mp, struct ifn goto bad; } + /* XXX this section is also in if_ethersubr.c */ if (V_ip_fw_chk_ptr && pfil_ipfw != 0 && dir == PFIL_OUT && ifp != NULL) { struct dn_pkt_tag *dn_tag; error = -1; dn_tag = ip_dn_claim_tag(*mp); - if (dn_tag != NULL) { - if (dn_tag->rule != NULL && V_fw_one_pass) + if (dn_tag == NULL) { + args.slot = 0; + } else { + if (dn_tag->slot != 0 && V_fw_one_pass) /* packet already partially processed */ goto ipfwpass; - args.rule = dn_tag->rule; /* matching rule to restart */ - args.rule_id = dn_tag->rule_id; + args.slot = dn_tag->slot; /* next rule to use */ args.chain_id = dn_tag->chain_id; - } else - args.rule = NULL; + args.rulenum = dn_tag->rulenum; + args.rule_id = dn_tag->rule_id; + } args.m = *mp; args.oif = ifp; Modified: user/luigi/ipfw3-head/sys/net/if_ethersubr.c ============================================================================== --- user/luigi/ipfw3-head/sys/net/if_ethersubr.c Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/net/if_ethersubr.c Tue Dec 22 16:06:38 2009 (r200850) @@ -471,15 +471,17 @@ ether_ipfw_chk(struct mbuf **m0, struct dn_tag = ip_dn_claim_tag(*m0); - if (dn_tag != NULL) { - if (dn_tag->rule != NULL && V_fw_one_pass) + if (dn_tag == NULL) { + args.slot = 0; + } else { + if (dn_tag->slot != 0 && V_fw_one_pass) /* dummynet packet, already partially processed */ return (1); - args.rule = dn_tag->rule; /* matching rule to restart */ + args.slot = dn_tag->slot; /* matching rule to restart */ + args.rulenum = dn_tag->rulenum; args.rule_id = dn_tag->rule_id; args.chain_id = dn_tag->chain_id; - } else - args.rule = NULL; + } /* * I need some amt of data to be contiguous, and in case others need Modified: user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.c ============================================================================== --- user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.c Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.c Tue Dec 22 16:06:38 2009 (r200850) @@ -293,7 +293,8 @@ ng_ipfw_input(struct mbuf **m0, int dir, m_freem(m); return (ENOMEM); } - ngit->rule = fwa->rule; + ngit->slot = fwa->slot; + ngit->rulenum = fwa->rulenum; ngit->rule_id = fwa->rule_id; ngit->chain_id = fwa->chain_id; ngit->dir = dir; Modified: user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.h ============================================================================== --- user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.h Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.h Tue Dec 22 16:06:38 2009 (r200850) @@ -37,7 +37,8 @@ extern ng_ipfw_input_t *ng_ipfw_input_p; struct ng_ipfw_tag { struct m_tag mt; /* tag header */ - struct ip_fw *rule; /* matching rule */ + uint32_t slot; /* slot for next rule */ + uint32_t rulenum; /* matching rule number */ uint32_t rule_id; /* matching rule id */ uint32_t chain_id; /* ruleset id */ struct ifnet *ifp; /* interface, for ip_output */ Modified: user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h Tue Dec 22 16:06:38 2009 (r200850) @@ -112,7 +112,8 @@ struct dn_heap { * processing requirements. */ struct dn_pkt_tag { - struct ip_fw *rule; /* matching rule */ + uint32_t slot; /* slot of next rule to use */ + uint32_t rulenum; /* matching rule number */ uint32_t rule_id; /* matching rule id */ uint32_t chain_id; /* ruleset id */ int dn_dir; /* action when packet comes out. */ Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Tue Dec 22 16:06:38 2009 (r200850) @@ -1367,20 +1367,11 @@ dummynet_io(struct mbuf **m0, int dir, s struct dn_pipe *pipe; uint64_t len = m->m_pkthdr.len; struct dn_flow_queue *q = NULL; - int is_pipe; - ipfw_insn *cmd = ACTION_PTR(fwa->rule); + int is_pipe = fwa->cookie & 0x8000000 ? 0 : 1; KASSERT(m->m_nextpkt == NULL, ("dummynet_io: mbuf queue passed to dummynet")); - if (cmd->opcode == O_LOG) - cmd += F_LEN(cmd); - if (cmd->opcode == O_ALTQ) - cmd += F_LEN(cmd); - if (cmd->opcode == O_TAG) - cmd += F_LEN(cmd); - is_pipe = (cmd->opcode == O_PIPE); - DUMMYNET_LOCK(); io_pkt++; /* @@ -1390,11 +1381,11 @@ dummynet_io(struct mbuf **m0, int dir, s * below can be simplified. */ if (is_pipe) { - pipe = locate_pipe(fwa->cookie); + pipe = locate_pipe(fwa->cookie & 0xffff); if (pipe != NULL) fs = &(pipe->fs); } else - fs = locate_flowset(fwa->cookie); + fs = locate_flowset(fwa->cookie & 0xffff); if (fs == NULL) goto dropit; /* This queue/pipe does not exist! */ @@ -1440,7 +1431,8 @@ dummynet_io(struct mbuf **m0, int dir, s * Ok, i can handle the pkt now... * Build and enqueue packet + parameters. */ - pkt->rule = fwa->rule; + pkt->slot = fwa->slot; + pkt->rulenum = fwa->rulenum; pkt->rule_id = fwa->rule_id; pkt->chain_id = fwa->chain_id; pkt->dn_dir = dir; Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Tue Dec 22 16:06:38 2009 (r200850) @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2002 Luigi Rizzo, Universita` di Pisa + * Copyright (c) 2002-2009 Luigi Rizzo, Universita` di Pisa * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -131,12 +131,10 @@ VNET_DEFINE(u_int32_t, set_disable); #define V_set_disable VNET(set_disable) VNET_DEFINE(int, fw_verbose); -//#define V_verbose_limit VNET(verbose_limit) /* counter for ipfw_log(NULL...) */ VNET_DEFINE(u_int64_t, norule_counter); VNET_DEFINE(int, verbose_limit); - /* layer3_chain contains the list of rules for layer 3 */ VNET_DEFINE(struct ip_fw_chain, layer3_chain); @@ -147,8 +145,6 @@ ipfw_nat_cfg_t *ipfw_nat_del_ptr; ipfw_nat_cfg_t *ipfw_nat_get_cfg_ptr; ipfw_nat_cfg_t *ipfw_nat_get_log_ptr; -extern int ipfw_chg_hook(SYSCTL_HANDLER_ARGS); - #ifdef SYSCTL_NODE SYSCTL_NODE(_net_inet_ip, OID_AUTO, fw, CTLFLAG_RW, 0, "Firewall"); SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, one_pass, @@ -173,6 +169,9 @@ SYSCTL_INT(_net_inet_ip_fw, OID_AUTO, de &default_to_accept, 0, "Make the default rule accept all packets."); TUNABLE_INT("net.inet.ip.fw.default_to_accept", &default_to_accept); +SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, static_count, + CTLFLAG_RD, &VNET_NAME(layer3_chain.n_rules), 0, + "Number of static rules"); #ifdef INET6 SYSCTL_DECL(_net_inet6_ip6); @@ -713,12 +712,17 @@ check_uidgid(ipfw_insn_u32 *insn, int pr return match; } +/* + * Helper function to write the matching rule into args + */ static inline void -set_match(struct ip_fw_args *args, struct ip_fw *f, struct ip_fw_chain *chain) +set_match(struct ip_fw_args *args, int slot, + struct ip_fw *f, struct ip_fw_chain *chain) { - args->rule = (void *)(uintptr_t)f->rulenum; - args->rule_id = f->id; args->chain_id = chain->id; + args->slot = slot + 1; /* we use 0 as a marker */ + args->rule_id = f->id; + args->rulenum = f->rulenum; } /* @@ -812,8 +816,7 @@ ipfw_chk(struct ip_fw_args *args) */ struct ifnet *oif = args->oif; - struct ip_fw *f = NULL; /* matching rule */ - int f_pos = 0; /* index of f in the array */ + int f_pos = 0; /* index of current rule in the array */ int retval = 0; /* @@ -1142,23 +1145,21 @@ do { \ return (IP_FW_PASS); /* accept */ } mtag = m_tag_find(m, PACKET_TAG_DIVERT, NULL); - if (args->rule) { + if (args->slot) { /* * Packet has already been tagged as a result of a previous * match on rule args->rule aka args->rule_id (PIPE, QUEUE, * REASS, NETGRAPH and similar, never a skipto). - * Validate the pointer and continue from args->rule->next - * if still present, otherwise use the default rule. - * XXX If fw_one_pass != 0 then just accept it, though - * the caller should never pass us such packets. - * XXX rule is now the rule number so we can do a lookup + * Validate the slot and continue from the next one + * if still present, otherwise do a lookup. */ if (V_fw_one_pass) { IPFW_RUNLOCK(chain); return (IP_FW_PASS); } - f_pos = ipfw_find_rule(chain, (uint32_t)(args->rule), args->rule_id+1); - f = chain->map[f_pos]; + f_pos = (args->chain_id == chain->id) ? + args->slot /* already incremented */ : + ipfw_find_rule(chain, args->rulenum, args->rule_id+1); } else { /* * Find the starting rule. It can be either the first @@ -1166,7 +1167,6 @@ do { \ */ int skipto = mtag ? divert_cookie(mtag) : 0; - f = chain->rules; f_pos = 0; if (args->eh == NULL && skipto != 0) { if (skipto >= IPFW_DEFAULT_RULE) { @@ -1174,7 +1174,6 @@ do { \ return (IP_FW_DENY); /* invalid */ } f_pos = ipfw_find_rule(chain, skipto, 0); - f = chain->map[f_pos]; } } /* reset divert rule to avoid confusion later */ @@ -1206,8 +1205,8 @@ do { \ ipfw_insn *cmd; uint32_t tablearg = 0; int l, cmdlen, skip_or; /* skip rest of OR block */ + struct ip_fw *f; -/* again: */ f = chain->map[f_pos]; if (V_set_disable & (1 << f->set) ) continue; @@ -1890,9 +1889,14 @@ do { \ */ q->pcnt++; q->bcnt += pktlen; + /* XXX we would like to have f_pos + * readily accessible in the dynamic + * rule, instead of having to + * looku q->rule. + */ f = q->rule; - /* the pointer is valid so we can do a lookup */ - f_pos = ipfw_find_rule(chain, f->rulenum, f->id); + f_pos = ipfw_find_rule(chain, + f->rulenum, f->id); cmd = ACTION_PTR(f); l = f->cmd_len - f->act_ofs; ipfw_dyn_unlock(); @@ -1918,11 +1922,11 @@ do { \ case O_PIPE: case O_QUEUE: - set_match(args, f, chain); - if (cmd->arg1 == IP_FW_TABLEARG) - args->cookie = tablearg; - else - args->cookie = cmd->arg1; + set_match(args, f_pos, f, chain); + args->cookie = (cmd->arg1 == IP_FW_TABLEARG) ? + tablearg : cmd->arg1; + if (cmd->opcode == O_QUEUE) + args->cookie |= 0x80000000; retval = IP_FW_DUMMYNET; l = 0; /* exit inner loop */ done = 1; /* exit outer loop */ @@ -1956,6 +1960,9 @@ do { \ case O_COUNT: case O_SKIPTO: + { + int i; + f->pcnt++; /* update stats */ f->bcnt += pktlen; f->timestamp = time_uptime; @@ -1964,12 +1971,13 @@ do { \ break; } /* skipto: */ - { - int i = (cmd->arg1 == IP_FW_TABLEARG) ? tablearg : cmd->arg1; - if (i <= f->rulenum) - i = f->rulenum + 1; /* no backward jumps */ - f_pos = ipfw_find_rule(chain, i, 0); - } + i = (cmd->arg1 == IP_FW_TABLEARG) ? + tablearg : cmd->arg1; + /* make sure we do not jump backward */ + if (i <= f->rulenum) + i = f->rulenum + 1; + f_pos = ipfw_find_rule(chain, i, 0); + } /* * Skip disabled rules, and * re-enter the inner loop @@ -1978,7 +1986,6 @@ do { \ */ for (; f_pos < chain->n_rules - 1 && (V_set_disable & (1 << chain->map[f_pos]->set)); f_pos++) ; - f = chain->map[f_pos]; l = f->cmd_len; cmd = f->cmd; match = 1; @@ -2045,11 +2052,9 @@ do { \ case O_NETGRAPH: case O_NGTEE: - set_match(args, f, chain); - if (cmd->arg1 == IP_FW_TABLEARG) - args->cookie = tablearg; - else - args->cookie = cmd->arg1; + set_match(args, f_pos, f, chain); + args->cookie = (cmd->arg1 == IP_FW_TABLEARG) ? + tablearg : cmd->arg1; retval = (cmd->opcode == O_NETGRAPH) ? IP_FW_NETGRAPH : IP_FW_NGTEE; l = 0; /* exit inner loop */ @@ -2072,7 +2077,7 @@ do { \ struct cfg_nat *t; int nat_id; - set_match(args, f, chain); + set_match(args, f_pos, f, chain); t = ((ipfw_insn_nat *)cmd)->nat; if (t == NULL) { nat_id = (cmd->arg1 == IP_FW_TABLEARG) ? @@ -2139,7 +2144,7 @@ do { \ else ip->ip_sum = in_cksum(m, hlen); retval = IP_FW_REASS; - set_match(args, f, chain); + set_match(args, f_pos, f, chain); } done = 1; /* exit outer loop */ break; @@ -2173,10 +2178,11 @@ do { \ } /* end of outer for, scan rules */ if (done) { + struct ip_fw *rule = chain->map[f_pos]; /* Update statistics */ - f->pcnt++; - f->bcnt += pktlen; - f->timestamp = time_uptime; + rule->pcnt++; + rule->bcnt += pktlen; + rule->timestamp = time_uptime; } else { retval = IP_FW_DENY; printf("ipfw: ouch!, skip past end of rules, denying packet\n"); @@ -2287,7 +2293,7 @@ vnet_ipfw_init(const void *unused) V_verbose_limit = IPFIREWALL_VERBOSE_LIMIT; #endif #ifdef IPFIREWALL_NAT - LIST_INIT(chain->nat); + LIST_INIT(&chain->nat); #endif /* insert the default rule and create the initial map */ @@ -2350,7 +2356,9 @@ vnet_ipfw_init(const void *unused) static int vnet_ipfw_uninit(const void *unused) { - struct ip_fw *reap; + struct ip_fw *reap, *rule; + struct ip_fw_chain *chain = &V_layer3_chain; + int i; V_ipfw_vnet_ready = 0; /* tell new callers to go away */ /* @@ -2364,22 +2372,29 @@ vnet_ipfw_uninit(const void *unused) #endif V_ip_fw_chk_ptr = NULL; V_ip_fw_ctl_ptr = NULL; - - IPFW_WLOCK(&V_layer3_chain); - /* We wait on the wlock here until the last user leaves */ - IPFW_WUNLOCK(&V_layer3_chain); - IPFW_WLOCK(&V_layer3_chain); + IPFW_UH_WLOCK(chain); + IPFW_UH_WUNLOCK(chain); + IPFW_UH_WLOCK(chain); + + IPFW_WLOCK(chain); + IPFW_WUNLOCK(chain); + IPFW_WLOCK(chain); ipfw_dyn_uninit(0); /* run the callout_drain */ - ipfw_flush_tables(&V_layer3_chain); - V_layer3_chain.reap = NULL; - ipfw_free_chain(&V_layer3_chain, 1 /* kill default rule */); - reap = V_layer3_chain.reap; - V_layer3_chain.reap = NULL; - IPFW_WUNLOCK(&V_layer3_chain); + ipfw_flush_tables(chain); + reap = NULL; + for (i = 0; i < chain->n_rules; i++) { + rule = chain->map[i]; + rule->x_next = reap; + reap = rule; + } + if (chain->map) + free(chain->map, M_IPFW); + IPFW_WUNLOCK(chain); + IPFW_UH_WUNLOCK(chain); if (reap != NULL) ipfw_reap_rules(reap); - IPFW_LOCK_DESTROY(&V_layer3_chain); + IPFW_LOCK_DESTROY(chain); ipfw_dyn_uninit(1); /* free the remaining parts */ return 0; } Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Tue Dec 22 16:06:38 2009 (r200850) @@ -125,7 +125,8 @@ ipfw_check_in(void *arg, struct mbuf **m if (ng_tag != NULL) { KASSERT(ng_tag->dir == NG_IPFW_IN, ("ng_ipfw tag with wrong direction")); - args.rule = ng_tag->rule; + args.slot = ng_tag->slot; + args.rulenum = ng_tag->rulenum; args.rule_id = ng_tag->rule_id; args.chain_id = ng_tag->chain_id; m_tag_delete(*m0, (struct m_tag *)ng_tag); @@ -137,7 +138,8 @@ again: struct dn_pkt_tag *dt; dt = (struct dn_pkt_tag *)(dn_tag+1); - args.rule = dt->rule; + args.slot = dt->slot; + args.rulenum = dt->rulenum; args.rule_id = dt->rule_id; args.chain_id = dt->chain_id; m_tag_delete(*m0, dn_tag); @@ -147,7 +149,7 @@ again: args.inp = inp; tee = 0; - if (V_fw_one_pass == 0 || args.rule == NULL) { + if (V_fw_one_pass == 0 || args.slot == 0) { ipfw = ipfw_chk(&args); *m0 = args.m; } else @@ -200,7 +202,7 @@ again: *m0 = NULL; return 0; /* packet consumed */ } else { - args.rule = NULL; + args.slot = 0; goto again; /* continue with packet */ } @@ -257,7 +259,8 @@ ipfw_check_out(void *arg, struct mbuf ** if (ng_tag != NULL) { KASSERT(ng_tag->dir == NG_IPFW_OUT, ("ng_ipfw tag with wrong direction")); - args.rule = ng_tag->rule; + args.slot = ng_tag->slot; + args.rulenum = ng_tag->rulenum; args.rule_id = ng_tag->rule_id; args.chain_id = ng_tag->chain_id; m_tag_delete(*m0, (struct m_tag *)ng_tag); @@ -269,7 +272,8 @@ again: struct dn_pkt_tag *dt; dt = (struct dn_pkt_tag *)(dn_tag+1); - args.rule = dt->rule; + args.slot = dt->slot; + args.rulenum = dt->rulenum; args.rule_id = dt->rule_id; args.chain_id = dt->chain_id; m_tag_delete(*m0, dn_tag); @@ -280,7 +284,7 @@ again: args.inp = inp; tee = 0; - if (V_fw_one_pass == 0 || args.rule == NULL) { + if (V_fw_one_pass == 0 || args.slot == 0) { ipfw = ipfw_chk(&args); *m0 = args.m; } else @@ -339,7 +343,7 @@ again: *m0 = NULL; return 0; /* packet consumed */ } else { - args.rule = NULL; + args.slot = 0; goto again; /* continue with packet */ } Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h Tue Dec 22 16:06:38 2009 (r200850) @@ -78,9 +78,16 @@ struct ip_fw_args { struct mbuf *m; /* the mbuf chain */ struct ifnet *oif; /* output interface */ struct sockaddr_in *next_hop; /* forward address */ - struct ip_fw *rule; /* matching rule */ - uint32_t rule_id; /* matching rule id */ - uint32_t chain_id; /* ruleset id */ + + /* chain_id validates 'slot', the location of the pointer to + * a matching rule. + * If invalid, we can lookup the rule using rule_id and rulenum + */ + uint32_t slot; /* slot for matching rule */ + uint32_t rulenum; /* matching rule number */ + uint32_t rule_id; /* matching rule id */ + uint32_t chain_id; /* ruleset id */ + struct ether_header *eh; /* for bridged packets */ struct ipfw_flow_id f_id; /* grabbed from IP header */ @@ -212,13 +219,13 @@ struct sockopt; /* used by tcp_var.h */ #define IPFW_UH_RUNLOCK(p) rw_runlock(&(p)->uh_lock) #define IPFW_UH_WLOCK(p) rw_wlock(&(p)->uh_lock) #define IPFW_UH_WUNLOCK(p) rw_wunlock(&(p)->uh_lock) + /* In ip_fw_sockopt.c */ int ipfw_find_rule(struct ip_fw_chain *chain, uint32_t key, uint32_t id); int ipfw_add_rule(struct ip_fw_chain *chain, struct ip_fw *input_rule); int ipfw_ctl(struct sockopt *sopt); int ipfw_chk(struct ip_fw_args *args); void ipfw_reap_rules(struct ip_fw *head); -void ipfw_free_chain(struct ip_fw_chain *chain, int kill_default); /* In ip_fw_table.c */ struct radix_node; Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Tue Dec 22 16:05:28 2009 (r200849) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Tue Dec 22 16:06:38 2009 (r200850) @@ -77,38 +77,11 @@ __FBSDID("$FreeBSD$"); MALLOC_DEFINE(M_IPFW, "IpFw/IpAcct", "IpFw/IpAcct chain's"); /* - * static variables followed by global ones + * static variables followed by global ones (none in this file) */ -#ifdef SYSCTL_NODE -SYSCTL_DECL(_net_inet_ip_fw); -SYSCTL_VNET_INT(_net_inet_ip_fw, OID_AUTO, static_count, - CTLFLAG_RD, &VNET_NAME(layer3_chain.n_rules), 0, - "Number of static rules"); - -#endif /* SYSCTL_NODE */ - /* - * When a rule is added/deleted, clear the next_rule pointers in all rules. - * These will be reconstructed on the fly as packets are matched. - */ -static void -flush_rule_ptrs(struct ip_fw_chain *chain) -{ -#if 0 - struct ip_fw *rule; - - IPFW_WLOCK_ASSERT(chain); - - for (rule = chain->rules; rule; rule = rule->next) - rule->next_rule = NULL; -#endif - chain->id++; -} - -/* - * Find the smallest rule >= key, id. - * In case of multiple rules with the same number finds the first one. + * Find the smallest rule >= key, id. * We could use bsearch but it is so simple that we code it directly */ int @@ -117,28 +90,18 @@ ipfw_find_rule(struct ip_fw_chain *chain int i, lo, hi; struct ip_fw *r; - printf("looking for rule %d:%d\n", key, id); for (lo = 0, hi = chain->n_rules - 1; lo < hi;) { - printf(" -- looking for rule %d:%d [%d-%d]\n", key, id, lo, hi); i = (lo + hi) / 2; r = chain->map[i]; if (r->rulenum < key) - lo = i + 1; + lo = i + 1; /* continue from the next one */ else if (r->rulenum > key) - hi = i; // i - 1; + hi = i; /* this might be good */ else if (r->id < id) - lo = i + 1; - else if (r->id > id) - hi = i; // i - 1; - else - hi = i; + lo = i + 1; /* continue from the next one */ + else /* r->id >= id */ + hi = i; /* this might be good */ }; - printf("search end lo %d hi %d\n",lo, hi); - if (hi < 0) - hi = 0; - if (lo >= chain->n_rules - 1) - lo = chain->n_rules - 1; - printf(" -- looking for rule %d:%d found at %d\n", key, id, hi); return hi; } @@ -149,48 +112,38 @@ ipfw_find_rule(struct ip_fw_chain *chain static struct ip_fw ** get_map(struct ip_fw_chain *chain, int extra, int locked) { - struct ip_fw **map; for (;;) { - int i = chain->n_rules + extra; - map = malloc( (1 + i) * sizeof(struct ip_fw *), M_IPFW, M_WAITOK); + struct ip_fw **map; + int i; + + i = chain->n_rules + extra; + map = malloc(i * sizeof(struct ip_fw *), M_IPFW, M_WAITOK); if (map == NULL) { printf("%s: cannot allocate map\n", __FUNCTION__); - break; + return NULL; } if (!locked) IPFW_UH_WLOCK(chain); - if (i >= chain->n_rules + extra) - break; + if (i >= chain->n_rules + extra) /* good */ + return map; /* otherwise we lost the race, free and retry */ if (!locked) IPFW_UH_WUNLOCK(chain); free(map, M_IPFW); } - return map; } -/* swap the maps. It is supposed to be called with IPFW_UH_WLOCK - * so we can do the remaining housekeepking outside +/* + * swap the maps. It is supposed to be called with IPFW_UH_WLOCK */ static struct ip_fw ** swap_map(struct ip_fw_chain *chain, struct ip_fw **new_map, int new_len) { struct ip_fw **old_map; - int i, lim; IPFW_WLOCK(chain); - printf("%s %p %d --> %p %d\n", __FUNCTION__, - chain->map, chain->n_rules, - new_map, new_len); - flush_rule_ptrs(chain); - lim = chain->n_rules < new_len ? new_len : chain->n_rules; - for (i=0; i < lim; i++) - printf("%3d %p %p\n", i, - (in_rules) ? chain->map[i] : NULL, - (iid incremented inside flush_rule_ptrs() */ + chain->id++; chain->n_rules = new_len; old_map = chain->map; chain->map = new_map; @@ -202,25 +155,27 @@ swap_map(struct ip_fw_chain *chain, stru * Add a new rule to the list. Copy the rule into a malloc'ed area, then * possibly create a rule number and add the rule to the list. * Update the rule_number in the input struct so the caller knows it as well. - * XXX not good for the default rule. + * XXX DO NOT USE FOR THE DEFAULT RULE. + * Must be called without IPFW_UH held */ int ipfw_add_rule(struct ip_fw_chain *chain, struct ip_fw *input_rule) { struct ip_fw *rule; - int l = RULESIZE(input_rule); - int i, insert_before; + int i, l, insert_before; struct ip_fw **map; /* the new array of pointers */ if (chain->rules == NULL || input_rule->rulenum > IPFW_DEFAULT_RULE-1) return (EINVAL); + l = RULESIZE(input_rule); rule = malloc(l, M_IPFW, M_WAITOK | M_ZERO); if (rule == NULL) return (ENOSPC); + /* get_map returns with IPFW_UH_WLOCK if successful */ map = get_map(chain, 1, 0 /* not locked */); if (map == NULL) { - free(map, M_IPFW); + free(rule, M_IPFW); return ENOSPC; } @@ -236,21 +191,19 @@ ipfw_add_rule(struct ip_fw_chain *chain, V_autoinc_step = 1; else if (V_autoinc_step > 1000) V_autoinc_step = 1000; - /* find the insertion point */ + /* find the insertion point, we will insert before */ insert_before = rule->rulenum ? rule->rulenum + 1 : IPFW_DEFAULT_RULE; i = ipfw_find_rule(chain, insert_before, 0); /* duplicate first part */ - printf("insert %d before %d (%d) at pos %d, +copy %d\n", - rule->rulenum, insert_before, - i>= 0 ? chain->map[i]->rulenum : -1, i, chain->n_rules - i); if (i > 0) bcopy(chain->map, map, i * sizeof(struct ip_fw *)); map[i] = rule; /* duplicate remaining part, we always have the default rule */ - bcopy(chain->map + i, map + i + 1, sizeof(struct ip_fw *) *(chain->n_rules - i)); + bcopy(chain->map + i, map + i + 1, + sizeof(struct ip_fw *) *(chain->n_rules - i)); if (rule->rulenum == 0) { - /* set the number */ - rule->rulenum = map[i]->rulenum; + /* write back the number */ + rule->rulenum = i > 0 ? map[i-1]->rulenum : 0; if (rule->rulenum < IPFW_DEFAULT_RULE - V_autoinc_step) rule->rulenum += V_autoinc_step; input_rule->rulenum = rule->rulenum; @@ -262,30 +215,9 @@ ipfw_add_rule(struct ip_fw_chain *chain, IPFW_UH_WUNLOCK(chain); if (map) free(map, M_IPFW); - DEB(printf("ipfw: installed rule %d, static count now %d\n", - rule->rulenum, chain->n_rules);) return (0); } -/** - * Remove a static rule (including derived * dynamic rules) - * and place it on the ``reap list'' for later reclamation. - * The caller is in charge of clearing rule pointers to avoid - * dangling pointers. - * @return a pointer to the next entry. - * Arguments are not checked, so they better be correct. - */ -static void -remove_rule(struct ip_fw_chain *chain, struct ip_fw *rule) -{ - int l = RULESIZE(rule); - - chain->static_len -= l; - ipfw_remove_dyn_children(rule); - rule->x_next = chain->reap; - chain->reap = rule; -} - /* * Reclaim storage associated with a list of rules. This is * typically the list created using remove_rule. @@ -302,31 +234,6 @@ ipfw_reap_rules(struct ip_fw *head) } } -/* - * Remove all rules from a chain (except rules in set RESVD_SET - * unless kill_default = 1). The caller is responsible for - * reclaiming storage for the rules left in chain->reap. - */ -void -ipfw_free_chain(struct ip_fw_chain *chain, int kill_default) -{ -#if 0 // XXX - struct ip_fw *prev, *rule; - - IPFW_WLOCK_ASSERT(chain); - - chain->reap = NULL; - flush_rule_ptrs(chain); /* more efficient to do outside the loop */ - for (prev = NULL, rule = chain->rules; rule ; ) - if (kill_default || rule->set != RESVD_SET) - rule = remove_rule(chain, rule); - else { - prev = rule; - rule = rule->next; - } -#endif -} - /** * Remove all rules with given number, and also do set manipulation. * Assumes chain != NULL && *chain != NULL. @@ -345,9 +252,9 @@ static int del_entry(struct ip_fw_chain *chain, u_int32_t arg) { struct ip_fw *rule; - u_int16_t rulenum; /* rule or old_set */ - u_int8_t cmd, new_set; - int start, end, i, ofs, n; + uint32_t rulenum; /* rule or old_set */ + uint8_t cmd, new_set; + int start, end = 0, i, ofs, n; struct ip_fw **map = NULL; int error = 0; @@ -367,81 +274,54 @@ del_entry(struct ip_fw_chain *chain, u_i IPFW_UH_WLOCK(chain); /* prevent conflicts among the writers */ chain->reap = NULL; /* prepare for deletions */ - switch (cmd) { - case 0: /* delete rules with given number */ - /* locate first rule to delete */ - start = ipfw_find_rule(chain, rulenum, 0); - /* count matching rules and end of range */ - for (end = start, n = 0; end < chain->n_rules; end++) { - rule = chain->map[end]; - if (rule->rulenum != rulenum) - break; - if (rule->set != RESVD_SET) - n++; - } - printf("must delete %d rules between %d and %d\n", n, start, end); - /* allocate the map, if needed */ - if (n > 0) - map = get_map(chain, -n, 1 /* locked */); - if (n == 0 || map == NULL) { - error = EINVAL; - goto done; - } - /* copy the initial part of the map */ - if (start > 0) - bcopy(chain->map, map, start * sizeof(struct ip_fw *)); - /* copy active rules between start and end */ - for (i = ofs = start; i < end; i++) { - rule = chain->map[i]; - if (rule->set == RESVD_SET) - map[ofs++] = chain->map[i]; - } - /* finally the tail */ - bcopy(chain->map + end, map + ofs, - (chain->n_rules - end) * sizeof(struct ip_fw *)); - map = swap_map(chain, map, chain->n_rules - n); - /* now remove the rules deleted */ - for (i = start; i < end; i++) { - rule = map[i]; - printf("about to remove rule %p at %d\n", - rule, i); - if (rule->set != RESVD_SET) - remove_rule(chain, rule); - } - printf("done with removals\n"); - break; - case 1: /* delete all rules with given set number */ - IPFW_UH_WLOCK(chain); - /* locate first rule to delete */ - for (start = 0; start < chain->n_rules; start++) { - rule = chain->map[start]; - if (rule->set != rulenum) - break; - } - for (n = 0, end = i = start; i < chain->n_rules; i++) { - rule = chain->map[i]; - if (rule->set == rulenum) { + switch (cmd) { + case 0: /* delete rules with given number (0 is special means all) */ + case 1: /* delete all rules with given set number, rule->set == rulenum */ + case 5: /* delete rules with given number and with given set number. + * rulenum - given rule number; + * new_set - given set number. + */ + /* locate first rule to delete (start), the one after the + * last one (end), and count how many rules to delete (n) + */ + n = 0; + if (cmd == 1) { /* look for a specific set, must scan all */ + for (start = -1, i = 0; i < chain->n_rules; i++) { + if (chain->map[start]->set != rulenum) + continue; + if (start < 0) + start = i; end = i; n++; } + end++; /* first non-matching */ + } else { + start = ipfw_find_rule(chain, rulenum, 0); + for (end = start; end < chain->n_rules; end++) { + rule = chain->map[end]; + if (rulenum > 0 && rule->rulenum != rulenum) + break; + if (rule->set != RESVD_SET && + (cmd == 0 || rule->set == new_set) ) + n++; + } } - end++; /* first non-matching */ - printf("must delete %d rules between %d and %d\n", n, start, end); /* allocate the map, if needed */ if (n > 0) map = get_map(chain, -n, 1 /* locked */); if (n == 0 || map == NULL) { error = EINVAL; - goto done; + break; } /* copy the initial part of the map */ if (start > 0) bcopy(chain->map, map, start * sizeof(struct ip_fw *)); - /* copy reserved rules */ + /* copy active rules between start and end */ for (i = ofs = start; i < end; i++) { rule = chain->map[i]; - if (rule->set != rulenum) + if (!(rule->set != RESVD_SET && + (cmd == 0 || rule->set == new_set) )) map[ofs++] = chain->map[i]; } /* finally the tail */ @@ -451,8 +331,15 @@ del_entry(struct ip_fw_chain *chain, u_i /* now remove the rules deleted */ for (i = start; i < end; i++) { rule = map[i]; - if (rule->set == rulenum) - remove_rule(chain, map[i]); + if (rule->set != RESVD_SET && + (cmd == 0 || rule->set == new_set) ) { + int l = RULESIZE(rule); + + chain->static_len -= l; + ipfw_remove_dyn_children(rule); + rule->x_next = chain->reap; + chain->reap = rule; + } } break; @@ -487,36 +374,9 @@ del_entry(struct ip_fw_chain *chain, u_i } IPFW_UH_WUNLOCK(chain); break; - -#if 0 // XXX case 5 is a restriction of 1 - case 5: /* delete rules with given number and with given set number. - * rulenum - given rule number; - * new_set - given set number. - */ - for (; rule->rulenum < rulenum; prev = rule, rule = rule->next) - ; - if (rule->rulenum != rulenum) { - IPFW_WUNLOCK(chain); - return (EINVAL); - } - flush_rule_ptrs(chain); - while (rule->rulenum == rulenum) { - if (rule->set == new_set) - rule = remove_rule(chain, rule, prev); - else { - prev = rule; - rule = rule->next; - } - } -#endif } - /* - * Look for rules to reclaim. We grab the list before - * releasing the lock then reclaim them w/o the lock to *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Tue Dec 22 17:02:57 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id AC8D8106566C; Tue, 22 Dec 2009 17:02:57 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9B4258FC27; Tue, 22 Dec 2009 17:02:57 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBMH2vkJ070133; Tue, 22 Dec 2009 17:02:57 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBMH2vcK070130; Tue, 22 Dec 2009 17:02:57 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912221702.nBMH2vcK070130@svn.freebsd.org> From: Luigi Rizzo Date: Tue, 22 Dec 2009 17:02:57 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200851 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 17:02:57 -0000 Author: luigi Date: Tue Dec 22 17:02:57 2009 New Revision: 200851 URL: http://svn.freebsd.org/changeset/base/200851 Log: restore the skipto cache, so we have O(1) cost for direct skipto. Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Tue Dec 22 16:06:38 2009 (r200850) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Tue Dec 22 17:02:57 2009 (r200851) @@ -1189,7 +1189,7 @@ do { \ * need to break out of one or both loops, or re-enter one of * the loops with updated variables. Loop variables are: * - * f (outer loop) points to the current rule. + * f_pos (outer loop) points to the current rule. * On output it points to the matching rule. * done (outer loop) is used as a flag to break the loop. * l (inner loop) residual length of current rule. @@ -1198,7 +1198,7 @@ do { \ * We break the inner loop by setting l=0 and possibly * cmdlen=0 if we don't want to advance cmd. * We break the outer loop by setting done=1 - * We can restart the inner loop by setting l>0 and f, cmd + * We can restart the inner loop by setting l>0 and f_pos, f, cmd * as needed. */ for (; f_pos < chain->n_rules; f_pos++) { @@ -1827,8 +1827,8 @@ do { \ * Exceptions: * O_COUNT and O_SKIPTO actions: * instead of terminating, we jump to the next rule - * (setting l=0), or to the SKIPTO target (by - * setting f, cmd and l as needed), respectively. + * (setting l=0), or to the SKIPTO target (setting + * f/f_len, cmd and l as needed), respectively. * * O_TAG, O_LOG and O_ALTQ action parameters: * perform some action and set match = 1; @@ -1892,7 +1892,7 @@ do { \ /* XXX we would like to have f_pos * readily accessible in the dynamic * rule, instead of having to - * looku q->rule. + * lookup q->rule. */ f = q->rule; f_pos = ipfw_find_rule(chain, @@ -1959,39 +1959,57 @@ do { \ break; case O_COUNT: - case O_SKIPTO: - { - int i; - f->pcnt++; /* update stats */ f->bcnt += pktlen; f->timestamp = time_uptime; - if (cmd->opcode == O_COUNT) { - l = 0; /* exit inner loop */ - break; - } - /* skipto: */ - i = (cmd->arg1 == IP_FW_TABLEARG) ? + l = 0; /* exit inner loop */ + break; + + case O_SKIPTO: + f->pcnt++; /* update stats */ + f->bcnt += pktlen; + f->timestamp = time_uptime; + /* If possible use cached f_pos (in f->next_rule), + * whose version is written in f->next_rule + * (horrible hacks to avoid changing the ABI). + */ + if (cmd->arg1 != IP_FW_TABLEARG && + (uint32_t)f->x_next == chain->id) { + f_pos = (uint32_t)f->next_rule; + } else { + int i = (cmd->arg1 == IP_FW_TABLEARG) ? tablearg : cmd->arg1; /* make sure we do not jump backward */ if (i <= f->rulenum) - i = f->rulenum + 1; + i = f->rulenum + 1; f_pos = ipfw_find_rule(chain, i, 0); + /* update the cache */ + if (cmd->arg1 != IP_FW_TABLEARG) { + f->next_rule = + (void *)(uintptr_t)f_pos; + f->x_next = + (void *)(uintptr_t)chain->id; + } } - /* - * Skip disabled rules, and - * re-enter the inner loop - * with the correct f, l and cmd. - * Also clear cmdlen and skip_or - */ - for (; f_pos < chain->n_rules - 1 && (V_set_disable & (1 << chain->map[f_pos]->set)); f_pos++) - ; - l = f->cmd_len; - cmd = f->cmd; - match = 1; - cmdlen = 0; - skip_or = 0; - break; + /* + * Skip disabled rules, and re-enter + * the inner loop with the correct + * f_pos, f, l and cmd. + * Also clear cmdlen and skip_or + */ + for (; f_pos < chain->n_rules - 1 && + (V_set_disable & + (1 << chain->map[f_pos]->set)); + f_pos++) + ; + /* prepare to enter the inner loop */ + f = chain->map[f_pos]; + l = f->cmd_len; + cmd = f->cmd; + match = 1; + cmdlen = 0; + skip_or = 0; + break; case O_REJECT: /* Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Tue Dec 22 16:06:38 2009 (r200850) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Tue Dec 22 17:02:57 2009 (r200851) @@ -180,9 +180,9 @@ ipfw_add_rule(struct ip_fw_chain *chain, } bcopy(input_rule, rule, l); + /* clear fields not settable from userland */ rule->x_next = NULL; - //rule->next_rule = NULL; - + rule->next_rule = NULL; rule->pcnt = 0; rule->bcnt = 0; rule->timestamp = 0; From owner-svn-src-user@FreeBSD.ORG Tue Dec 22 17:44:57 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 228761065679; Tue, 22 Dec 2009 17:44:57 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 11EAA8FC12; Tue, 22 Dec 2009 17:44:57 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBMHiuls071032; Tue, 22 Dec 2009 17:44:56 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBMHiuWp071030; Tue, 22 Dec 2009 17:44:56 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912221744.nBMHiuWp071030@svn.freebsd.org> From: Luigi Rizzo Date: Tue, 22 Dec 2009 17:44:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200852 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 17:44:57 -0000 Author: luigi Date: Tue Dec 22 17:44:56 2009 New Revision: 200852 URL: http://svn.freebsd.org/changeset/base/200852 Log: simplify set_match Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Tue Dec 22 17:02:57 2009 (r200851) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Tue Dec 22 17:44:56 2009 (r200852) @@ -717,12 +717,12 @@ check_uidgid(ipfw_insn_u32 *insn, int pr */ static inline void set_match(struct ip_fw_args *args, int slot, - struct ip_fw *f, struct ip_fw_chain *chain) + struct ip_fw_chain *chain) { args->chain_id = chain->id; args->slot = slot + 1; /* we use 0 as a marker */ - args->rule_id = f->id; - args->rulenum = f->rulenum; + args->rule_id = chain->map[slot]->id; + args->rulenum = chain->map[slot]->rulenum; } /* @@ -1922,7 +1922,7 @@ do { \ case O_PIPE: case O_QUEUE: - set_match(args, f_pos, f, chain); + set_match(args, f_pos, chain); args->cookie = (cmd->arg1 == IP_FW_TABLEARG) ? tablearg : cmd->arg1; if (cmd->opcode == O_QUEUE) @@ -2070,7 +2070,7 @@ do { \ case O_NETGRAPH: case O_NGTEE: - set_match(args, f_pos, f, chain); + set_match(args, f_pos, chain); args->cookie = (cmd->arg1 == IP_FW_TABLEARG) ? tablearg : cmd->arg1; retval = (cmd->opcode == O_NETGRAPH) ? @@ -2095,7 +2095,7 @@ do { \ struct cfg_nat *t; int nat_id; - set_match(args, f_pos, f, chain); + set_match(args, f_pos, chain); t = ((ipfw_insn_nat *)cmd)->nat; if (t == NULL) { nat_id = (cmd->arg1 == IP_FW_TABLEARG) ? @@ -2162,7 +2162,7 @@ do { \ else ip->ip_sum = in_cksum(m, hlen); retval = IP_FW_REASS; - set_match(args, f_pos, f, chain); + set_match(args, f_pos, chain); } done = 1; /* exit outer loop */ break; From owner-svn-src-user@FreeBSD.ORG Tue Dec 22 20:37:40 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5CFC01065692; Tue, 22 Dec 2009 20:37:40 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4B6E18FC16; Tue, 22 Dec 2009 20:37:40 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBMKbeA1075888; Tue, 22 Dec 2009 20:37:40 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBMKbe2g075881; Tue, 22 Dec 2009 20:37:40 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200912222037.nBMKbe2g075881@svn.freebsd.org> From: Edwin Groothuis Date: Tue, 22 Dec 2009 20:37:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200870 - user/edwin/calendar X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 20:37:40 -0000 Author: edwin Date: Tue Dec 22 20:37:40 2009 New Revision: 200870 URL: http://svn.freebsd.org/changeset/base/200870 Log: Split the current (and partly new) code into modules with functions with similar functionalities. Added: user/edwin/calendar/events.c user/edwin/calendar/locale.c user/edwin/calendar/parsedata.c Modified: user/edwin/calendar/Makefile user/edwin/calendar/calendar.c user/edwin/calendar/calendar.h user/edwin/calendar/day.c user/edwin/calendar/io.c Modified: user/edwin/calendar/Makefile ============================================================================== --- user/edwin/calendar/Makefile Tue Dec 22 20:33:27 2009 (r200869) +++ user/edwin/calendar/Makefile Tue Dec 22 20:37:40 2009 (r200870) @@ -4,7 +4,7 @@ CFLAGS= -pipe -g -std=gnu99 -fstack-protector -Wall PROG= calendar -SRCS= calendar.c io.c day.c ostern.c paskha.c +SRCS= calendar.c locale.c events.c parsedata.c io.c day.c ostern.c paskha.c INTER= de_AT.ISO_8859-15 de_DE.ISO8859-1 fr_FR.ISO8859-1 \ hr_HR.ISO8859-2 hu_HU.ISO8859-2 ru_RU.KOI8-R uk_UA.KOI8-U DE_LINKS= de_DE.ISO8859-15 Modified: user/edwin/calendar/calendar.c ============================================================================== --- user/edwin/calendar/calendar.c Tue Dec 22 20:33:27 2009 (r200869) +++ user/edwin/calendar/calendar.c Tue Dec 22 20:37:40 2009 (r200870) @@ -153,6 +153,6 @@ usage(void) fprintf(stderr, "%s\n%s\n", "usage: calendar [-a] [-A days] [-B days] [-F friday] " "[-f calendarfile]", - " [-t dd[.mm[.year]]] [-W days]"); + " [-d] [-t dd[.mm[.year]]] [-W days]"); exit(1); } Modified: user/edwin/calendar/calendar.h ============================================================================== --- user/edwin/calendar/calendar.h Tue Dec 22 20:33:27 2009 (r200869) +++ user/edwin/calendar/calendar.h Tue Dec 22 20:37:40 2009 (r200870) @@ -38,6 +38,8 @@ #define SECSPERDAY 24 * 60 * 60 +/* Not yet categorized */ + extern struct passwd *pw; extern int doall; extern struct iovec header[]; @@ -48,28 +50,9 @@ extern int *cumdays; extern int yrdays; extern struct fixs neaster, npaskha, ncny; -void cal(void); -void closecal(FILE *); -int checkdayofweek(char *, int *len, int *offset, char **dow); -char * getdayofweekname(int); -int checkmonth(char *, int *len, int *offset, char **month); -char * getmonthname(int); -int getday(char *); -int getdayvar(char *); -int getfield(char *, int *); -int getmonth(char *); -int geteaster(char *, int); -int getpaskha(char *, int); -int easter(int); -int parsedaymonth(char *, int *, int *, int *); -FILE *opencal(void); -void settimes(time_t,int, int); -time_t Mktime(char *); -void setnnames(void); - #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0) -/* Flags to determine the returned values by determinestyle() */ +/* Flags to determine the returned values by determinestyle() in parsedata.c */ #define F_NONE 0x000 #define F_MONTH 0x001 #define F_DAYOFWEEK 0x002 @@ -93,7 +76,57 @@ extern int f_dayAfter; /* days after cur extern int f_dayBefore; /* days before current date */ extern int Friday; /* day before weekend */ +/* events.c */ +/* + * Event sorting related functions: + * - Use event_add() to create a new event + * - Use event_continue() to add more text to the last added event + * - Use event_print_all() to display them in time chronological order + */ +struct event *event_add(struct event *, int, int, char *, int, char *); +void event_continue(struct event *events, char *txt); +void event_print_all(FILE *fp, struct event *events); +struct event { + int month; + int day; + int var; + char *date; + char *text; + struct event *next; +}; + +/* locale.c */ + struct fixs { char *name; int len; }; + +extern struct fixs fndays[8]; /* full national days names */ +extern struct fixs ndays[8]; /* short national days names */ +extern struct fixs fnmonths[13]; /* full national months names */ +extern struct fixs nmonths[13]; /* short national month names */ +extern const char *months[]; +extern const char *fmonths[]; +extern const char *days[]; +extern const char *fdays[]; + +void setnnames(void); + +/* day.c */ +void settimes(time_t,int, int); +time_t Mktime(char *); + +/* parsedata.c */ +int parsedaymonth(char *, int *, int *, int *); + +/* io.c */ +void cal(void); +void closecal(FILE *); +FILE *opencal(void); + +/* ostern.c / pashka.c */ +int geteaster(char *, int); +int getpaskha(char *, int); +int easter(int); + Modified: user/edwin/calendar/day.c ============================================================================== --- user/edwin/calendar/day.c Tue Dec 22 20:33:27 2009 (r200869) +++ user/edwin/calendar/day.c Tue Dec 22 20:37:40 2009 (r200870) @@ -34,9 +34,6 @@ #include __FBSDID("$FreeBSD$"); -#include -#include -#include #include #include #include @@ -59,96 +56,6 @@ int daytab[][14] = { {0, -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, }; -static char const *fdays[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", - "Saturday", NULL, -}; - -static char const *days[] = { - "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", NULL, -}; - -static const char *fmonths[] = { - "January", "February", "March", "April", "May", "June", "Juli", - "August", "September", "October", "November", "December", NULL, -}; - -static const char *months[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", NULL, -}; - -static struct fixs fndays[8]; /* full national days names */ -static struct fixs ndays[8]; /* short national days names */ - -static struct fixs fnmonths[13]; /* full national months names */ -static struct fixs nmonths[13]; /* short national month names */ - -static char *showflags(int flags); -static int isonlydigits(char *s, int star); - - -void -setnnames(void) -{ - char buf[80]; - int i, l; - struct tm tm; - - for (i = 0; i < 7; i++) { - tm.tm_wday = i; - strftime(buf, sizeof(buf), "%a", &tm); - for (l = strlen(buf); - l > 0 && isspace((unsigned char)buf[l - 1]); - l--) - ; - buf[l] = '\0'; - if (ndays[i].name != NULL) - free(ndays[i].name); - if ((ndays[i].name = strdup(buf)) == NULL) - errx(1, "cannot allocate memory"); - ndays[i].len = strlen(buf); - - strftime(buf, sizeof(buf), "%A", &tm); - for (l = strlen(buf); - l > 0 && isspace((unsigned char)buf[l - 1]); - l--) - ; - buf[l] = '\0'; - if (fndays[i].name != NULL) - free(fndays[i].name); - if ((fndays[i].name = strdup(buf)) == NULL) - errx(1, "cannot allocate memory"); - fndays[i].len = strlen(buf); - } - - for (i = 0; i < 12; i++) { - tm.tm_mon = i; - strftime(buf, sizeof(buf), "%b", &tm); - for (l = strlen(buf); - l > 0 && isspace((unsigned char)buf[l - 1]); - l--) - ; - buf[l] = '\0'; - if (nmonths[i].name != NULL) - free(nmonths[i].name); - if ((nmonths[i].name = strdup(buf)) == NULL) - errx(1, "cannot allocate memory"); - nmonths[i].len = strlen(buf); - - strftime(buf, sizeof(buf), "%B", &tm); - for (l = strlen(buf); - l > 0 && isspace((unsigned char)buf[l - 1]); - l--) - ; - buf[l] = '\0'; - if (fnmonths[i].name != NULL) - free(fnmonths[i].name); - if ((fnmonths[i].name = strdup(buf)) == NULL) - errx(1, "cannot allocate memory"); - fnmonths[i].len = strlen(buf); - } -} void settimes(time_t now, int before, int after) @@ -226,599 +133,7 @@ Mktime(char *dp) return (mktime(&tm)); } -/* - * Expected styles: - * - * Date ::= Month . ' ' . DayOfMonth | - * Month . ' ' . DayOfWeek . ModifierIndex | - * Month . '/' . DayOfMonth | - * Month . '/' . DayOfWeek . ModifierIndex | - * DayOfMonth . ' ' . Month | - * DayOfMonth . '/' . Month | - * DayOfWeek . ModifierIndex . ' ' .Month | - * DayOfWeek . ModifierIndex . '/' .Month | - * DayOfWeek . ModifierIndex | - * SpecialDay . ModifierOffset - * - * Month ::= MonthName | MonthNumber | '*' - * MonthNumber ::= '0' ... '9' | '00' ... '09' | '10' ... '12' - * MonthName ::= MonthNameShort | MonthNameLong - * MonthNameLong ::= 'January' ... 'December' - * MonthNameShort ::= 'Jan' ... 'Dec' | 'Jan.' ... 'Dec.' - * - * DayOfWeek ::= DayOfWeekShort | DayOfWeekLong - * DayOfWeekShort ::= 'Mon' .. 'Sun' - * DayOfWeekLong ::= 'Monday' .. 'Sunday' - * DayOfMonth ::= '0' ... '9' | '00' ... '09' | '10' ... '29' | - * '30' ... '31' | '*' - * - * ModifierOffset ::= '' | '+' . ModifierNumber | '-' . ModifierNumber - * ModifierNumber ::= '0' ... '9' | '00' ... '99' | '000' ... '299' | - * '300' ... '359' | '360' ... '365' - * ModifierIndex ::= 'Second' | 'Third' | 'Fourth' | 'Fifth' | - * 'First' | 'Last' - * - * SpecialDay ::= 'Easter' | 'Pashka' | 'ChineseNewYear' - * - */ -int -determinestyle(char *date, int *flags, - char *month, int *imonth, char *dayofmonth, int *idayofmonth, - char *dayofweek, int *idayofweek, char *modifieroffset, - char *modifierindex, char *specialday) -{ - char *p, *dow, *pmonth, *p1, *p2; - char pold; - int len, offset; - - *flags = F_NONE; - *month = '\0'; - *imonth = 0; - *dayofmonth = '\0'; - *idayofmonth = 0; - *dayofweek = '\0'; - *idayofweek = 0; - *modifieroffset = '\0'; - *modifierindex = '\0'; - *specialday = '\0'; - -#define CHECKSPECIAL(s1, s2, lens2, type) \ - if (s2 != NULL && strncmp(s1, s2, lens2) == 0) { \ - *flags |= F_SPECIALDAY; \ - *flags |= type; \ - *flags |= F_VARIABLE; \ - if (strlen(s1) == lens2) { \ - strcpy(specialday, s1); \ - return (1); \ - } \ - strncpy(specialday, s1, lens2); \ - specialday[lens2] = '\0'; \ - strcpy(modifieroffset, s1 + lens2); \ - *flags |= F_MODIFIEROFFSET; \ - return (1); \ - } - - if ((p = strchr(date, ' ')) == NULL) { - if ((p = strchr(date, '/')) == NULL) { - CHECKSPECIAL(date, STRING_CNY, strlen(STRING_CNY), - F_CNY); - CHECKSPECIAL(date, ncny.name, ncny.len, F_CNY); - CHECKSPECIAL(date, STRING_PASKHA, - strlen(STRING_PASKHA), F_PASKHA); - CHECKSPECIAL(date, npaskha.name, npaskha.len, F_PASKHA); - CHECKSPECIAL(date, STRING_EASTER, - strlen(STRING_EASTER), F_EASTER); - CHECKSPECIAL(date, neaster.name, neaster.len, F_EASTER); - if (checkdayofweek(date, &len, &offset, &dow) != 0) { - *flags |= F_DAYOFWEEK; - *flags |= F_VARIABLE; - *idayofweek = offset; - if (strlen(date) == len) { - strcpy(dayofweek, date); - return (1); - } - strncpy(dayofweek, date, len); - dayofweek[len] = '\0'; - strcpy(modifierindex, date + len); - *flags |= F_MODIFIERINDEX; - return (1); - } - if (isonlydigits(date, 1)) { - /* Assume month number only */ - *flags |= F_MONTH; - *imonth = (int)strtol(date, (char **)NULL, 10); - strcpy(month, getmonthname(*imonth)); - return(1); - } - return (0); - } - } - - /* - * After this, leave by goto-ing to "allfine" or "fail" to restore the - * original data in `date'. - */ - pold = *p; - *p = 0; - p1 = date; - p2 = p + 1; - /* Now p2 points to the next field and p1 to the first field */ - - /* Check if there is a month-string in the date */ - if ((checkmonth(p1, &len, &offset, &pmonth) != 0) - || (checkmonth(p2, &len, &offset, &pmonth) != 0 && (p2 = p1))) { - /* p2 is the non-month part */ - *flags |= F_MONTH; - *imonth = offset; - - strcpy(month, getmonthname(offset)); - if (isonlydigits(p2, 1)) { - strcpy(dayofmonth, p2); - *idayofmonth = (int)strtol(p2, (char **)NULL, 10); - *flags |= F_DAYOFMONTH; - goto allfine; - } - if (strcmp(p2, "*") == 0) { - *flags |= F_ALLDAY; - goto allfine; - } - - if (checkdayofweek(p2, &len, &offset, &dow) != 0) { - *flags |= F_DAYOFWEEK; - *flags |= F_VARIABLE; - *idayofweek = offset; - strcpy(dayofweek, getdayofweekname(offset)); - if (strlen(p2) == len) - goto allfine; - strcpy(modifierindex, p2 + len); - *flags |= F_MODIFIERINDEX; - goto allfine; - } - - goto fail; - } - - /* Check if there is an every-day or every-month in the string */ - if ((strcmp(p1, "*") == 0 && isonlydigits(p2, 1)) - || (strcmp(p2, "*") == 0 && isonlydigits(p1, 1) && (p2 = p1))) { - int d; - - *flags |= F_ALLMONTH; - *flags |= F_DAYOFMONTH; - d = (int)strtol(p2, (char **)NULL, 10); - *idayofmonth = d; - sprintf(dayofmonth, "%d", d); - goto allfine; - } - - /* Month as a number, then a weekday */ - if (isonlydigits(p1, 1) - && checkdayofweek(p2, &len, &offset, &dow) != 0) { - int d; - - *flags |= F_MONTH; - *flags |= F_DAYOFWEEK; - *flags |= F_VARIABLE; - - *idayofweek = offset; - d = (int)strtol(p1, (char **)NULL, 10); - *imonth = d; - strcpy(month, getmonthname(d)); - - strcpy(dayofweek, getdayofweekname(offset)); - if (strlen(p2) == len) - goto allfine; - strcpy(modifierindex, p2 + len); - *flags |= F_MODIFIERINDEX; - goto allfine; - } - - /* If both the month and date are specified as numbers */ - if (isonlydigits(p1, 1) && isonlydigits(p2, 0)) { - /* Now who wants to be this ambigious? :-( */ - int m, d; - - if (strchr(p2, '*') != NULL) - *flags |= F_VARIABLE; - - m = (int)strtol(p1, (char **)NULL, 10); - d = (int)strtol(p2, (char **)NULL, 10); - - *flags |= F_MONTH; - *flags |= F_DAYOFMONTH; - - if (m > 12) { - *imonth = d; - *idayofmonth = m; - strcpy(month, getmonthname(d)); - sprintf(dayofmonth, "%d", m); - } else { - *imonth = m; - *idayofmonth = d; - strcpy(month, getmonthname(m)); - sprintf(dayofmonth, "%d", d); - } - goto allfine; - } - - /* FALLTHROUGH */ -fail: - *p = pold; - return (0); -allfine: - *p = pold; - return (1); - -} - -/* - * Possible date formats include any combination of: - * 3-charmonth (January, Jan, Jan) - * 3-charweekday (Friday, Monday, mon.) - * numeric month or day (1, 2, 04) - * - * Any character may separate them, or they may not be separated. Any line, - * following a line that is matched, that starts with "whitespace", is shown - * along with the matched line. - */ -int -parsedaymonth(char *date, int *monthp, int *dayp, int *flags) -{ - char month[100], dayofmonth[100], dayofweek[100], modifieroffset[100]; - char modifierindex[100], specialday[100]; - int idayofweek, imonth, idayofmonth; - - /* - * CONVENTION - * - * Month: 1-12 - * Monthname: Jan .. Dec - * Day: 1-31 - * Weekday: Mon .. Sun - * - */ - - *flags = 0; - - if (debug) - printf("-------\ndate: |%s|\n", date); - if (determinestyle(date, flags, month, &imonth, dayofmonth, - &idayofmonth, dayofweek, &idayofweek, modifieroffset, - modifierindex, specialday) == 0) { - if (debug) - printf("Failed!\n"); - return (0); - } - - if (debug) { - printf("flags: %x - %s\n", *flags, showflags(*flags)); - if (modifieroffset[0] != '\0') - printf("modifieroffset: |%s|\n", modifieroffset); - if (modifierindex[0] != '\0') - printf("modifierindex: |%s|\n", modifierindex); - if (month[0] != '\0') - printf("month: |%s| (%d)\n", month, imonth); - if (dayofmonth[0] != '\0') - printf("dayofmonth: |%s| (%d)\n", dayofmonth, - idayofmonth); - if (dayofweek[0] != '\0') - printf("dayofweek: |%s| (%d)\n", dayofweek, idayofweek); - if (specialday[0] != '\0') - printf("specialday: |%s|\n", specialday); - } - - if ((*flags & !F_VARIABLE) == (F_MONTH | F_DAYOFMONTH)) { - } - - return (0); - -#ifdef NOTDEF - if (!(v1 = getfield(date, &flags))) - return (0); - - /* Easter or Easter depending days */ - if (flags & F_EASTER) - day = v1 - 1; /* days since January 1 [0-365] */ - - /* - * 1. {Weekday,Day} XYZ ... - * - * where Day is > 12 - */ - else if (flags & F_ISDAY || v1 > 12) { - - /* found a day; day: 1-31 or weekday: 1-7 */ - day = v1; - - /* {Day,Weekday} {Month,Monthname} ... */ - /* if no recognizable month, assume just a day alone - * in other words, find month or use current month */ - if (!(month = getfield(endp, &flags))) - month = tp->tm_mon + 1; - } - - /* 2. {Monthname} XYZ ... */ - else if (flags & F_ISMONTH) { - month = v1; - - /* Monthname {day,weekday} */ - /* if no recognizable day, assume the first day in month */ - if (!(day = getfield(endp, &flags))) - day = 1; - } - - /* Hm ... */ - else { - v2 = getfield(endp, &flags); - - /* - * {Day} {Monthname} ... - * where Day <= 12 - */ - if (flags & F_ISMONTH) { - day = v1; - month = v2; - *varp = 0; - } - - /* {Month} {Weekday,Day} ... */ - else { - /* F_ISDAY set, v2 > 12, or no way to tell */ - month = v1; - /* if no recognizable day, assume the first */ - day = v2 ? v2 : 1; - *varp = 0; - } - } - - /* convert Weekday into *next* Day, - * e.g.: 'Sunday' -> 22 - * 'SundayLast' -> ?? - */ - if (flags & F_ISDAY) { -#ifdef DEBUG - fprintf(stderr, "\nday: %d %s month %d\n", day, endp, month); -#endif - - *varp = 1; - /* variable weekday, SundayLast, MondayFirst ... */ - if (day < 0 || day >= 10) { - - /* negative offset; last, -4 .. -1 */ - if (day < 0) { - v1 = day / 10 - 1; /* offset -4 ... -1 */ - day = 10 + (day % 10); /* day 1 ... 7 */ - - /* day, eg '22nd' */ - v2 = tp->tm_mday + - (((day - 1) - tp->tm_wday + 7) % 7); - - /* (month length - day) / 7 + 1 */ - if (cumdays[month + 1] - cumdays[month] >= v2 - && ((int)((cumdays[month + 1] - - cumdays[month] - v2) / 7) + 1) == -v1) - day = v2; /* bingo ! */ - - /* set to yesterday */ - else { - day = tp->tm_mday - 1; - if (day == 0) - return (0); - } - } - - /* first, second ... +1 ... +5 */ - else { - /* offset: +1 (first Sunday) ... */ - v1 = day / 10; - day = day % 10; - - /* day, eg '22th' */ - v2 = tp->tm_mday + - (((day - 1) - tp->tm_wday + 7) % 7); - - /* Hurrah! matched */ - if (((v2 - 1 + 7) / 7) == v1 ) - day = v2; - - else { - /* set to yesterday */ - day = tp->tm_mday - 1; - if (day == 0) - return (0); - } - } - } else { - /* wired */ - day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7); - *varp = 1; - } - } - - if (!(flags & F_EASTER)) { - if (day + cumdays[month] > cumdays[month + 1]) { - /* off end of month, adjust */ - day -= (cumdays[month + 1] - cumdays[month]); - /* next year */ - if (++month > 12) - month = 1; - } - *monthp = month; - *dayp = day; - day = cumdays[month] + day; - } else { - for (v1 = 0; day > cumdays[v1]; v1++) - ; - *monthp = v1 - 1; - *dayp = day - cumdays[v1 - 1]; - *varp = 1; - } - -#ifdef DEBUG - fprintf(stderr, "day2: day %d(%d-%d) yday %d\n", - *dayp, day, cumdays[month], tp->tm_yday); -#endif - - /* When days before or days after is specified */ - /* no year rollover */ - if (day >= tp->tm_yday - f_dayBefore && - day <= tp->tm_yday + f_dayAfter) - return (1); - - /* next year */ - if (tp->tm_yday + f_dayAfter >= yrdays) { - int end = tp->tm_yday + f_dayAfter - yrdays; - if (day <= end) - return (1); - } - - /* previous year */ - if (tp->tm_yday - f_dayBefore < 0) { - int before = yrdays + (tp->tm_yday - f_dayBefore); - if (day >= before) - return (1); - } -#endif - return (0); -} - - -static char * -showflags(int flags) -{ - static char s[1000]; - s[0] = '\0'; - - if ((flags & F_MONTH) != 0) - strcat(s, "month "); - if ((flags & F_DAYOFWEEK) != 0) - strcat(s, "dayofweek "); - if ((flags & F_DAYOFMONTH) != 0) - strcat(s, "dayofmonth "); - if ((flags & F_MODIFIERINDEX) != 0) - strcat(s, "modifierindex "); - if ((flags & F_MODIFIEROFFSET) != 0) - strcat(s, "modifieroffset "); - if ((flags & F_SPECIALDAY) != 0) - strcat(s, "specialday "); - if ((flags & F_ALLMONTH) != 0) - strcat(s, "allmonth "); - if ((flags & F_ALLDAY) != 0) - strcat(s, "allday "); - if ((flags & F_VARIABLE) != 0) - strcat(s, "variable "); - if ((flags & F_CNY) != 0) - strcat(s, "chinesenewyear "); - if ((flags & F_PASKHA) != 0) - strcat(s, "paskha "); - if ((flags & F_EASTER) != 0) - strcat(s, "easter "); - - return s; -} - -char * -getmonthname(int i) -{ - if (nmonths[i - 1].len != 0 && nmonths[i - 1].name != NULL) - return (nmonths[i - 1].name); - return ((char *)months[i - 1]); -} - -int -checkmonth(char *s, int *len, int *offset, char **month) -{ - struct fixs *n; - int i; - for (i = 0; fnmonths[i].name != NULL; i++) { - n = fnmonths + i; - if (strncasecmp(s, n->name, n->len) == 0) { - *len = n->len; - *month = n->name; - *offset = i + 1; - return (1); - } - } - for (i = 0; nmonths[i].name != NULL; i++) { - n = nmonths + i; - if (strncasecmp(s, n->name, n->len) == 0) { - *len = n->len; - *month = n->name; - *offset = i + 1; - return (1); - } - } - for (i = 0; fmonths[i] != NULL; i++) { - *len = strlen(fmonths[i]); - if (strncasecmp(s, fmonths[i], *len) == 0) { - *month = (char *)fmonths[i]; - *offset = i + 1; - return (1); - } - } - for (i = 0; months[i] != NULL; i++) { - if (strncasecmp(s, months[i], 3) == 0) { - *len = 3; - *month = (char *)months[i]; - *offset = i + 1; - return (1); - } - } - return (0); -} - - -char * -getdayofweekname(int i) -{ - if (ndays[i].len != 0 && ndays[i].name != NULL) - return (ndays[i].name); - return ((char *)days[i]); -} - -int -checkdayofweek(char *s, int *len, int *offset, char **dow) -{ - struct fixs *n; - int i; - - for (i = 0; fndays[i].name != NULL; i++) { - n = fndays + i; - if (strncasecmp(s, n->name, n->len) == 0) { - *len = n->len; - *dow = n->name; - *offset = i; - return (1); - } - } - for (i = 0; ndays[i].name != NULL; i++) { - n = ndays + i; - if (strncasecmp(s, n->name, n->len) == 0) { - *len = n->len; - *dow = n->name; - *offset = i; - return (1); - } - } - for (i = 0; fdays[i] != NULL; i++) { - *len = strlen(fdays[i]); - if (strncasecmp(s, fdays[i], *len) == 0) { - *dow = (char *)fdays[i]; - *offset = i; - return (1); - } - } - for (i = 0; days[i] != NULL; i++) { - if (strncasecmp(s, days[i], 3) == 0) { - *len = 3; - *dow = (char *)days[i]; - *offset = i; - return (1); - } - } - return (0); -} /* return offset for variable weekdays * -1 -> last weekday in month @@ -863,17 +178,3 @@ getdayvar(char *s) return (0); } - -static int -isonlydigits(char *s, int nostar) -{ - int i; - for (i = 0; s[i] != '\0'; i++) { - if (nostar == 0 && s[i] == '*' && s[i + 1] == '\0') - return 1; - if (!isdigit(s[i])) - return (0); - } - return (1); -} - Added: user/edwin/calendar/events.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/edwin/calendar/events.c Tue Dec 22 20:37:40 2009 (r200870) @@ -0,0 +1,160 @@ +/* + * Copyright (c) 1989, 1993, 1994 + * The Regents of the University of California. 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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: user/edwin/calendar/io.c 200813 2009-12-21 21:17:59Z edwin $"); + +#include +#include +#include +#include +#include + +#include "pathnames.h" +#include "calendar.h" + +struct event * +event_add(struct event *events, int month, int day, + char *date, int var, char *txt) +{ + struct event *e; + + /* + * Creating a new event: + * - Create a new event + * - Copy the machine readable day and month + * - Copy the human readable and language specific date + * - Copy the text of the event + */ + e = (struct event *)calloc(1, sizeof(struct event)); + if (e == NULL) + errx(1, "event_add: cannot allocate memory"); + e->month = month; + e->day = day; + e->var = var; + e->date = strdup(date); + if (e->date == NULL) + errx(1, "event_add: cannot allocate memory"); + e->text = strdup(txt); + if (e->text == NULL) + errx(1, "event_add: cannot allocate memory"); + e->next = events; + + return e; +} + +void +event_continue(struct event *e, char *txt) +{ + char *text; + + /* + * Adding text to the event: + * - Save a copy of the old text (unknown length, so strdup()) + * - Allocate enough space for old text + \n + new text + 0 + * - Store the old text + \n + new text + * - Destroy the saved copy. + */ + text = strdup(e->text); + if (text == NULL) + errx(1, "event_continue: cannot allocate memory"); + + free(e->text); + e->text = (char *)malloc(strlen(text) + strlen(txt) + 3); + if (e->text == NULL) + errx(1, "event_continue: cannot allocate memory"); + strcpy(e->text, text); + strcat(e->text, "\n"); + strcat(e->text, txt); + free(text); + + return; +} + +void +event_print_all(FILE *fp, struct event *events) +{ + struct event *e, *e_next; + int daycounter; + int day, month; + + /* + * Print all events: + * - We know the number of days to be counted (f_dayAfter + f_dayBefore) + * - We know the current day of the year ("now" - f_dayBefore + counter) + * - We know the number of days in the year (yrdays, set in settime()) + * - So we know the date on which the current daycounter is on the + * calendar in days and months. + * - Go through the list of events, and print all matching dates + */ + for (daycounter = 0; daycounter <= f_dayAfter + f_dayBefore; + daycounter++) { + day = tp1.tm_yday - f_dayBefore + daycounter; + if (day < 0) + day += yrdays; + if (day >= yrdays) + day -= yrdays; + + /* + * When we know the day of the year, we can determine the day + * of the month and the month. + */ + month = 1; + while (month <= 12) { + if (day <= cumdays[month]) + break; + month++; + } + month--; + day -= cumdays[month]; + +#ifdef DEBUG + fprintf(stderr, "event_print_allmonth: %d, day: %d\n", + month, day); +#endif + + /* + * Go through all events and print the text of the matching + * dates + */ + for (e = events; e != NULL; e = e_next) { *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Tue Dec 22 22:38:54 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5CEA6106566B; Tue, 22 Dec 2009 22:38:54 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4B0088FC1A; Tue, 22 Dec 2009 22:38:54 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBMMcsSI078764; Tue, 22 Dec 2009 22:38:54 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBMMcsSf078762; Tue, 22 Dec 2009 22:38:54 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200912222238.nBMMcsSf078762@svn.freebsd.org> From: Kip Macy Date: Tue, 22 Dec 2009 22:38:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200882 - user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 22:38:54 -0000 Author: kmacy Date: Tue Dec 22 22:38:54 2009 New Revision: 200882 URL: http://svn.freebsd.org/changeset/base/200882 Log: - remove _locked and !_locked function names where only the _locked variant is ever used - implement vm_pages_valid(_locked) - implement vm_object_reference_pages Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Tue Dec 22 22:15:52 2009 (r200881) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Tue Dec 22 22:38:54 2009 (r200882) @@ -568,16 +568,18 @@ zio_buf_vm_object_evict(buf_t bp) } static void -zio_buf_vm_object_insert_locked(buf_t bp, struct vnode *vp, +zio_buf_vm_object_insert(buf_t bp, struct vnode *vp, vm_object_t object, int valid) { vm_page_t m; - vm_pindex_t start = OFF_TO_IDX(stob(bp->b_blkno)); + vm_pindex_t start; int i; + VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); /* * Insert buffer pages in the object */ + start = OFF_TO_IDX(stob(bp->b_blkno)); for (i = 0; i < bp->b_npages; i++) { m = bp->b_pages[i]; if (valid) @@ -593,18 +595,6 @@ zio_buf_vm_object_insert_locked(buf_t bp vm_page_unlock_queues(); } -static void -zio_buf_vm_object_insert(buf_t bp, int valid) -{ - spa_t *spa = zio_buf_get_spa(bp); - struct vnode *vp = spa_get_vnode(spa); - vm_object_t object = vp->v_object; - - VM_OBJECT_LOCK(object); - zio_buf_vm_object_insert_locked(bp, vp, object, valid); - VM_OBJECT_UNLOCK(object); -} - /* * zio_buf_evict_overlap: [ internal use only ] * @@ -617,8 +607,8 @@ zio_buf_vm_object_insert(buf_t bp, int v * This routine may not block. */ static void -zio_buf_evict_overlap_locked(daddr_t blkno, int size, zio_spa_state_t state, - uint64_t txg, int evict_op, vm_object_t object) +zio_buf_evict_overlap(vm_object_t object, daddr_t blkno, int size, + zio_spa_state_t state, uint64_t txg, int evict_op) { buf_t root, tmpbp; daddr_t blkno_end, tmpblkno, tmpblkno_end; @@ -672,6 +662,7 @@ done: && (evict_op == ZB_EVICT_ALL)) { start = OFF_TO_IDX(stob(blkno)); end = start + OFF_TO_IDX(size); + VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); vm_page_cache_free(object, start, end); vm_object_page_remove(object, start, end, FALSE); #ifdef INVARIANTS @@ -683,18 +674,6 @@ done: } } -static void -zio_buf_evict_overlap(daddr_t blkno, int size, zio_spa_state_t state, - uint64_t txg, int evict_op) -{ - vm_object_t object = spa_get_vm_object(state->zss_spa); - - VM_OBJECT_LOCK(object); - zio_buf_evict_overlap_locked(blkno, size, state, txg, evict_op, object); - VM_OBJECT_UNLOCK(object); -} - - /* * scan blkno + size range in object to verify that all the pages are * resident and valid @@ -702,8 +681,16 @@ zio_buf_evict_overlap(daddr_t blkno, int static int vm_pages_valid_locked(vm_object_t object, uint64_t blkno, uint64_t size) { + vm_pindex_t start; + vm_page_t m; + int i; - return (0); + start = OFF_TO_IDX(stob(blkno)); + for (i = 0; i < OFF_TO_IDX(size); i++) + if ((m = vm_page_lookup(object, start + i)) == NULL || + (m->valid != VM_PAGE_BITS_ALL)) + return (0); + return (1); } static int @@ -725,7 +712,19 @@ vm_pages_valid(vm_object_t object, uint6 static void vm_object_reference_pages(vm_object_t object, buf_t bp) { - + uint64_t blkno, size; + vm_pindex_t start; + vm_page_t m; + int i; + + start = OFF_TO_IDX(stob(blkno)); + vm_page_lock_queues(); + for (i = 0; i < bp->b_npages; i++) { + m = vm_page_lookup(object, start + i); + vm_page_wire(m); + bp->b_pages[i] = m; + } + vm_page_unlock_queues(); } /* @@ -848,7 +847,7 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl ("doing I/O with cloned or evicted buffer 0x%x", bp->b_flags)); if (bp->b_flags & B_MALLOC) { - zio_buf_evict_overlap(blkno, size, state, txg, ZB_EVICT_BUFFERED); + zio_buf_evict_overlap(object, blkno, size, state, txg, ZB_EVICT_BUFFERED); if (zio_op == ZIO_TYPE_READ) { /* @@ -875,18 +874,18 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl */ VM_OBJECT_LOCK(object); - zio_buf_evict_overlap_locked(blkno, size, state, NO_TXG, - ZB_EVICT_ALL, object); + zio_buf_evict_overlap(object, blkno, size, state, NO_TXG, + ZB_EVICT_ALL); bp->b_blkno = bp->b_lblkno = blkno; bp->b_flags |= (B_VMIO|B_ASSIGNED); bp->b_birth = txg; zio_buf_blkno_insert(bp, state); - zio_buf_vm_object_insert_locked(bp, vp, object, zio_op == ZIO_TYPE_WRITE); + zio_buf_vm_object_insert(bp, vp, object, zio_op == ZIO_TYPE_WRITE); VM_OBJECT_UNLOCK(object); } else { KASSERT(zio_op == ZIO_TYPE_READ, ("unexpected op %d", zio_op)); - zio_buf_evict_overlap_locked(blkno, size, state, NO_TXG, - ZB_EVICT_BUFFERED, object); + zio_buf_evict_overlap(object, blkno, size, state, NO_TXG, + ZB_EVICT_BUFFERED); bp->b_blkno = bp->b_lblkno = blkno; bp->b_flags |= (B_VMIO|B_ASSIGNED); bp->b_birth = txg; @@ -897,7 +896,7 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl vm_page_free(bp->b_pages[i]); vm_object_reference_pages(object, bp); } else - zio_buf_vm_object_insert_locked(bp, vp, object, FALSE); + zio_buf_vm_object_insert(bp, vp, object, FALSE); VM_OBJECT_UNLOCK(object); } From owner-svn-src-user@FreeBSD.ORG Tue Dec 22 22:45:03 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E81F6106566B; Tue, 22 Dec 2009 22:45:03 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D6D648FC0A; Tue, 22 Dec 2009 22:45:03 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBMMj3ah078924; Tue, 22 Dec 2009 22:45:03 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBMMj313078921; Tue, 22 Dec 2009 22:45:03 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200912222245.nBMMj313078921@svn.freebsd.org> From: Kip Macy Date: Tue, 22 Dec 2009 22:45:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200883 - user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Dec 2009 22:45:04 -0000 Author: kmacy Date: Tue Dec 22 22:45:03 2009 New Revision: 200883 URL: http://svn.freebsd.org/changeset/base/200883 Log: call zfs_bio initialization functions Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Tue Dec 22 22:38:54 2009 (r200882) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Tue Dec 22 22:45:03 2009 (r200883) @@ -963,6 +963,7 @@ zfs_bio_init(void) zfs_bio_event_shutdown = EVENTHANDLER_REGISTER(shutdown_pre_sync, zfs_bio_shutdown, NULL, EVENTHANDLER_PRI_FIRST); + buf_init(); } void Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c Tue Dec 22 22:38:54 2009 (r200882) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c Tue Dec 22 22:45:03 2009 (r200883) @@ -143,6 +143,7 @@ zio_init(void) #endif zio_inject_init(); + zfs_bio_init(); } void @@ -170,6 +171,7 @@ zio_fini(void) kmem_cache_destroy(zio_cache); + zfs_bio_fini(); zio_inject_fini(); } From owner-svn-src-user@FreeBSD.ORG Wed Dec 23 05:15:41 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 07F49106568B; Wed, 23 Dec 2009 05:15:41 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EA1FC8FC16; Wed, 23 Dec 2009 05:15:40 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBN5FeQ3086979; Wed, 23 Dec 2009 05:15:40 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBN5Fesj086977; Wed, 23 Dec 2009 05:15:40 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200912230515.nBN5Fesj086977@svn.freebsd.org> From: Kip Macy Date: Wed, 23 Dec 2009 05:15:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200890 - user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Dec 2009 05:15:41 -0000 Author: kmacy Date: Wed Dec 23 05:15:40 2009 New Revision: 200890 URL: http://svn.freebsd.org/changeset/base/200890 Log: - malloc the hash table locks - malloc a TAILQ_HEAD array and not an array of pointers to TAILQ_HEADs - switch to using the freelist entry - don't inline on debug kernels Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Wed Dec 23 04:48:42 2009 (r200889) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Wed Dec 23 05:15:40 2009 (r200890) @@ -103,7 +103,7 @@ TUNABLE_INT("vfs.zfs.page_cache_disable" SYSCTL_INT(_vfs_zfs, OID_AUTO, page_cache_disable, CTLFLAG_RDTUN, &zfs_page_cache_disable, 0, "Disable backing ARC with page cache "); -static eventhandler_tag zfs_bio_event_shutdown = NULL; +static eventhandler_tag zfs_bio_event_shutdown; struct zio_spa_state; typedef struct zio_spa_state * zio_spa_state_t; typedef struct buf * buf_t; @@ -155,7 +155,7 @@ typedef struct cluster_list_head * buf_h typedef struct buf_hash_table { uint64_t ht_mask; buf_head_t ht_table; - struct ht_lock ht_locks[BUF_LOCKS] __aligned(128); + struct ht_lock *ht_locks; } buf_hash_table_t; static buf_hash_table_t buf_hash_table; @@ -173,6 +173,12 @@ static buf_hash_table_t buf_hash_table; #define zio_buf_get_spa(bp) (((zio_spa_state_t)bp->b_state)->zss_spa) #define zio_buf_get_vm_object(bp) spa_get_vm_object(zio_buf_get_spa((bp))) +#ifndef DEBUG +#define INLINE static __inline +#else +#define INLINE +#endif + static uint64_t buf_hash(caddr_t va, uint64_t size) { @@ -190,7 +196,10 @@ buf_hash(caddr_t va, uint64_t size) return (crc); } -static void +const char *buf_lock = "ht_lock"; + + +void buf_init(void) { uint64_t *ct; @@ -207,18 +216,20 @@ buf_init(void) retry: buf_hash_table.ht_mask = hsize - 1; buf_hash_table.ht_table = - malloc(hsize * sizeof (buf_head_t), M_ZFS_BIO, M_WAITOK|M_ZERO); + malloc(hsize * sizeof (struct cluster_list_head), M_ZFS_BIO, M_NOWAIT|M_ZERO); if (buf_hash_table.ht_table == NULL) { ASSERT(hsize > (1ULL << 8)); hsize >>= 1; goto retry; } - + buf_hash_table.ht_locks = + malloc(BUF_LOCKS*128, M_ZFS_BIO, M_WAITOK|M_ZERO); + for (i = 0; i < hsize; i++) TAILQ_INIT(&buf_hash_table.ht_table[i]); for (i = 0; i < BUF_LOCKS; i++) - mtx_init(&buf_hash_table.ht_locks[i].ht_lock, "ht_lock", NULL, MTX_DEF); + mtx_init(&(buf_hash_table.ht_locks[i].ht_lock), buf_lock, NULL, MTX_DEF|MTX_DUPOK); } /* @@ -229,7 +240,7 @@ retry: * The object and page must be locked. * This routine may not block. */ -static void +INLINE void zio_buf_va_insert(buf_t bp) { caddr_t va = bp->b_data; @@ -241,7 +252,7 @@ zio_buf_va_insert(buf_t bp) lock = BUF_HASH_LOCK(idx); bh = &buf_hash_table.ht_table[idx]; mtx_lock(lock); - TAILQ_INSERT_HEAD(bh, bp, b_bobufs); + TAILQ_INSERT_HEAD(bh, bp, b_freelist); mtx_unlock(lock); } @@ -255,7 +266,7 @@ zio_buf_va_insert(buf_t bp) * This routine may not block. * This is a critical path routine */ -static buf_t +INLINE buf_t zio_buf_va_lookup(caddr_t va, uint64_t size) { buf_t bp; @@ -267,7 +278,7 @@ zio_buf_va_lookup(caddr_t va, uint64_t s lock = BUF_HASH_LOCK(idx); bh = &buf_hash_table.ht_table[idx]; mtx_lock(lock); - TAILQ_FOREACH(bp, bh, b_bobufs) + TAILQ_FOREACH(bp, bh, b_freelist) if (bp->b_data == va) break; mtx_unlock(lock); @@ -283,7 +294,7 @@ zio_buf_va_lookup(caddr_t va, uint64_t s * The state and buf must be locked. * This routine may not block. */ -static buf_t +INLINE buf_t zio_buf_va_remove(caddr_t va, uint64_t size) { uint64_t idx; @@ -295,12 +306,13 @@ zio_buf_va_remove(caddr_t va, uint64_t s lock = BUF_HASH_LOCK(idx); bh = &buf_hash_table.ht_table[idx]; mtx_lock(lock); - TAILQ_FOREACH(bp, bh, b_bobufs) + TAILQ_FOREACH(bp, bh, b_freelist) if (bp->b_data == va) { - TAILQ_REMOVE(bh, bp, b_bobufs); + TAILQ_REMOVE(bh, bp, b_freelist); break; } mtx_unlock(lock); + KASSERT(bp != NULL, ("no buffer found for va=%p size=%lld", va, size)); return (bp); } @@ -382,7 +394,7 @@ zio_buf_blkno_insert(buf_t bp, zio_spa_s if (root == NULL) { bp->b_left = NULL; bp->b_right = NULL; - TAILQ_INSERT_TAIL(&object->zss_blkno_memq, bp, b_bobufs); + TAILQ_INSERT_TAIL(&object->zss_blkno_memq, bp, b_freelist); } else { root = zio_buf_blkno_splay(bp->b_blkno, root); root_blkno_end = root->b_blkno + btos(root->b_bcount); @@ -392,7 +404,7 @@ zio_buf_blkno_insert(buf_t bp, zio_spa_s bp->b_left = root->b_left; bp->b_right = root; root->b_left = NULL; - TAILQ_INSERT_BEFORE(root, bp, b_bobufs); + TAILQ_INSERT_BEFORE(root, bp, b_freelist); } else if (blkno == root->b_blkno) { panic("zio_buf_blkno_insert: blkno already allocated"); } else { @@ -401,7 +413,7 @@ zio_buf_blkno_insert(buf_t bp, zio_spa_s bp->b_right = root->b_right; bp->b_left = root; root->b_right = NULL; - TAILQ_INSERT_AFTER(&object->zss_blkno_memq, root, bp, b_bobufs); + TAILQ_INSERT_AFTER(&object->zss_blkno_memq, root, bp, b_freelist); } } object->zss_blkno_root = bp; @@ -467,7 +479,7 @@ zio_buf_blkno_remove(buf_t bp) root->b_right = bp->b_right; } state->zss_blkno_root = root; - TAILQ_REMOVE(&state->zss_blkno_memq, bp, b_bobufs); + TAILQ_REMOVE(&state->zss_blkno_memq, bp, b_freelist); /* * And show that the object has one fewer resident page. @@ -624,7 +636,7 @@ zio_buf_evict_overlap(vm_object_t object root = zio_buf_blkno_splay(blkno, root); TAILQ_INIT(&clh); if (blkno < root->b_blkno) - tmpbp = TAILQ_PREV(root, cluster_list_head, b_bobufs); + tmpbp = TAILQ_PREV(root, cluster_list_head, b_freelist); /* * Find all existing buffers that overlap with this range @@ -641,7 +653,7 @@ zio_buf_evict_overlap(vm_object_t object TAILQ_INSERT_TAIL(&clh, tmpbp, b_freelist); collisions++; } - tmpbp = TAILQ_NEXT(tmpbp, b_bobufs); + tmpbp = TAILQ_NEXT(tmpbp, b_freelist); } while (!TAILQ_EMPTY(&clh)) { tmpbp = TAILQ_FIRST(&clh); @@ -961,9 +973,10 @@ zfs_bio_init(void) if (zfs_page_cache_disable) return; + buf_init(); + zfs_bio_event_shutdown = EVENTHANDLER_REGISTER(shutdown_pre_sync, zfs_bio_shutdown, NULL, EVENTHANDLER_PRI_FIRST); - buf_init(); } void From owner-svn-src-user@FreeBSD.ORG Thu Dec 24 04:50:18 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 82EED1065676; Thu, 24 Dec 2009 04:50:18 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 70E418FC15; Thu, 24 Dec 2009 04:50:18 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBO4oIi3019324; Thu, 24 Dec 2009 04:50:18 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBO4oIVD019320; Thu, 24 Dec 2009 04:50:18 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200912240450.nBO4oIVD019320@svn.freebsd.org> From: Kip Macy Date: Thu, 24 Dec 2009 04:50:18 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200932 - in user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 04:50:18 -0000 Author: kmacy Date: Thu Dec 24 04:50:18 2009 New Revision: 200932 URL: http://svn.freebsd.org/changeset/base/200932 Log: - use VMIO to indicate assignment - remove gratuitous flags - allocate spa state structure at vdev vnode allocation time - pass object pointer to copyin / copyout Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_bio.h user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_bio.h ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_bio.h Thu Dec 24 01:28:26 2009 (r200931) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_bio.h Thu Dec 24 04:50:18 2009 (r200932) @@ -46,8 +46,7 @@ zio_sync_cache(spa_t *spa, blkptr_t *bp, { int io_bypass = 0; - if (!zfs_page_cache_disable && - ((vd != NULL) && (vd->vdev_vnode != NULL)) && + if (!zfs_page_cache_disable && (vd == NULL) && ((type == ZIO_TYPE_WRITE) || (type == ZIO_TYPE_READ))) io_bypass = _zio_sync_cache(spa, bp, txg, data, size, type); @@ -59,12 +58,13 @@ zio_cache_valid(void *data, uint64_t siz { if ((vd != NULL) && (type == ZIO_TYPE_READ) && - (vd->vdev_vnode != NULL) && (size & PAGE_MASK) == 0) + (size & PAGE_MASK) == 0) _zio_cache_valid(data, size); } void *zio_getblk(uint64_t size, int flags); void zio_relse(void *data, size_t size); +void *zio_spa_state_alloc(spa_t *spa); #ifdef _KERNEL void zfs_bio_init(void); Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c Thu Dec 24 01:28:26 2009 (r200931) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev.c Thu Dec 24 04:50:18 2009 (r200932) @@ -40,6 +40,10 @@ #include #include +#ifdef _KERNEL +#include +#endif + SYSCTL_DECL(_vfs_zfs); SYSCTL_NODE(_vfs_zfs, OID_AUTO, vdev, CTLFLAG_RW, 0, "ZFS VDEV"); @@ -1077,6 +1081,7 @@ vdev_open(vdev_t *vd) vp->v_type = VREG; vnode_create_vobject(vp, 512, curthread); vd->vdev_vnode = vp; + vp->v_data = zio_spa_state_alloc(vd->vdev_spa); VOP_UNLOCK(vp, 0); KASSERT(vp->v_object != NULL, ("vnode_create_vobject failed")); Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Thu Dec 24 01:28:26 2009 (r200931) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Thu Dec 24 04:50:18 2009 (r200932) @@ -110,9 +110,7 @@ typedef struct buf * buf_t; MALLOC_DEFINE(M_ZFS_BIO, "zfs_bio", "zfs buffer cache / vm"); -#define B_EVICTED B_00000800 #define B_DATA B_00001000 -#define B_ASSIGNED B_00004000 #define ZB_EVICT_ALL 0x1 #define ZB_EVICT_BUFFERED 0x2 @@ -182,16 +180,16 @@ static buf_hash_table_t buf_hash_table; static uint64_t buf_hash(caddr_t va, uint64_t size) { - uint8_t *vav = (uint8_t *)&va; uint64_t crc = -1ULL; + uint8_t *vav = (uint8_t *)&va; int i; ASSERT(zfs_crc64_table[128] == ZFS_CRC64_POLY); - for (i = i; i < sizeof (caddr_t); i++) + for (i = 0; i < sizeof (caddr_t); i++) crc = (crc >> 8) ^ zfs_crc64_table[(crc ^ vav[i]) & 0xFF]; - crc ^= (size>>9); + crc ^= (size>>4); return (crc); } @@ -232,6 +230,21 @@ retry: mtx_init(&(buf_hash_table.ht_locks[i].ht_lock), buf_lock, NULL, MTX_DEF|MTX_DUPOK); } +void * +zio_spa_state_alloc(spa_t *spa) +{ + struct zio_spa_state *zss; + + zss = malloc(sizeof(struct zio_spa_state), M_ZFS_BIO, M_WAITOK|M_ZERO); + + zss->zss_spa = spa; + mtx_init(&zss->zss_mtx, "zio_spa_state", NULL, MTX_DEF); + TAILQ_INIT(&zss->zss_blkno_memq); + + return (zss); +} + + /* * zio_buf_insert: [ internal use only ] * @@ -244,13 +257,16 @@ INLINE void zio_buf_va_insert(buf_t bp) { caddr_t va = bp->b_data; - uint64_t idx, size = bp->b_bcount; + long idx, size = bp->b_bcount; struct mtx *lock; buf_head_t bh; idx = BUF_HASH_INDEX(va, size); lock = BUF_HASH_LOCK(idx); bh = &buf_hash_table.ht_table[idx]; + + CTR3(KTR_SPARE3, "va_insert(va=%p size=%ld) idx=%ld", va, size, idx); + mtx_lock(lock); TAILQ_INSERT_HEAD(bh, bp, b_freelist); mtx_unlock(lock); @@ -297,7 +313,7 @@ zio_buf_va_lookup(caddr_t va, uint64_t s INLINE buf_t zio_buf_va_remove(caddr_t va, uint64_t size) { - uint64_t idx; + long idx; struct mtx *lock; buf_head_t bh; buf_t bp; @@ -305,6 +321,9 @@ zio_buf_va_remove(caddr_t va, uint64_t s idx = BUF_HASH_INDEX(va, size); lock = BUF_HASH_LOCK(idx); bh = &buf_hash_table.ht_table[idx]; + + + CTR3(KTR_SPARE3, "va_remove(va=%p size=%ld) idx=%ld", va, (long)size, idx); mtx_lock(lock); TAILQ_FOREACH(bp, bh, b_freelist) if (bp->b_data == va) { @@ -489,9 +508,8 @@ zio_buf_blkno_remove(buf_t bp) } static __inline void -zio_buf_vm_object_copy(buf_t bp, int direction) +zio_buf_vm_object_copy(vm_object_t object, buf_t bp, int direction) { - vm_object_t object; vm_pindex_t start, end; vm_offset_t offset; uint64_t byte_offset; @@ -501,7 +519,6 @@ zio_buf_vm_object_copy(buf_t bp, int dir vm_page_t m; struct sf_buf *sf; - object = zio_buf_get_vm_object(bp); byte_offset = stob(bp->b_blkno); page_offset = byte_offset & PAGE_MASK; start = OFF_TO_IDX(byte_offset); @@ -542,17 +559,17 @@ done: } static void -zio_buf_vm_object_copyout(buf_t bp) +zio_buf_vm_object_copyout(vm_object_t object, buf_t bp) { - zio_buf_vm_object_copy(bp, ZB_COPYOUT); + zio_buf_vm_object_copy(object, bp, ZB_COPYOUT); } static void -zio_buf_vm_object_copyin(buf_t bp) +zio_buf_vm_object_copyin(vm_object_t object, buf_t bp) { - zio_buf_vm_object_copy(bp, ZB_COPYIN); + zio_buf_vm_object_copy(object, bp, ZB_COPYIN); } static void @@ -660,9 +677,7 @@ zio_buf_evict_overlap(vm_object_t object TAILQ_REMOVE(&clh, tmpbp, b_freelist); zio_buf_vm_object_evict(tmpbp); - KASSERT(tmpbp->b_flags & B_EVICTED == 0, - ("buffer has already been evicted")); - tmpbp->b_flags |= B_EVICTED; + tmpbp->b_flags &= ~B_VMIO; state->zss_blkno_root = tmpbp; /* * move buffer to the unmanaged tree @@ -776,16 +791,18 @@ static buf_t _zio_getblk_malloc(uint64_t size, int flags) { buf_t newbp; - void *data; - if (flags & GB_NODUMP) - data = _zio_data_buf_alloc(size); - else - data = _zio_buf_alloc(size); newbp = malloc(sizeof(struct buf), M_ZFS_BIO, M_WAITOK|M_ZERO); - newbp->b_data = data; newbp->b_flags = (B_MALLOC|B_INVAL); newbp->b_bcount = size; + + if (flags & GB_NODUMP) { + newbp->b_flags |= B_DATA; + newbp->b_data = _zio_data_buf_alloc(size); + } else + newbp->b_data = _zio_buf_alloc(size); + + return (newbp); } static buf_t @@ -820,7 +837,7 @@ zio_relse(void *data, size_t size) bp = zio_buf_va_remove(data, size); - if (bp->b_flags & B_ASSIGNED) + if (bp->b_flags & B_VMIO) zio_buf_blkno_remove(bp); if (bp->b_flags & B_MALLOC) { @@ -855,9 +872,6 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl bp = zio_buf_va_lookup(data, size); - KASSERT(bp->b_flags & B_EVICTED == 0, - ("doing I/O with cloned or evicted buffer 0x%x", bp->b_flags)); - if (bp->b_flags & B_MALLOC) { zio_buf_evict_overlap(object, blkno, size, state, txg, ZB_EVICT_BUFFERED); @@ -866,13 +880,13 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl * if page resident - copy in * update zio pipeline */ - zio_buf_vm_object_copyin(bp); + zio_buf_vm_object_copyin(object, bp); if (bp->b_flags & B_CACHE) { /* update zio pipeline */ io_bypass = TRUE; } } else { - zio_buf_vm_object_copyout(bp); + zio_buf_vm_object_copyout(object, bp); } } else if (bp->b_flags & B_VMIO) { KASSERT(bp == zio_buf_blkno_lookup(state, blkno), @@ -889,7 +903,7 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl zio_buf_evict_overlap(object, blkno, size, state, NO_TXG, ZB_EVICT_ALL); bp->b_blkno = bp->b_lblkno = blkno; - bp->b_flags |= (B_VMIO|B_ASSIGNED); + bp->b_flags |= B_VMIO; bp->b_birth = txg; zio_buf_blkno_insert(bp, state); zio_buf_vm_object_insert(bp, vp, object, zio_op == ZIO_TYPE_WRITE); @@ -899,7 +913,7 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl zio_buf_evict_overlap(object, blkno, size, state, NO_TXG, ZB_EVICT_BUFFERED); bp->b_blkno = bp->b_lblkno = blkno; - bp->b_flags |= (B_VMIO|B_ASSIGNED); + bp->b_flags |= B_VMIO; bp->b_birth = txg; zio_buf_blkno_insert(bp, state); VM_OBJECT_LOCK(object); From owner-svn-src-user@FreeBSD.ORG Thu Dec 24 17:06:55 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8C277106566B; Thu, 24 Dec 2009 17:06:55 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 782618FC19; Thu, 24 Dec 2009 17:06:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBOH6tUN036090; Thu, 24 Dec 2009 17:06:55 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBOH6tV2036062; Thu, 24 Dec 2009 17:06:55 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912241706.nBOH6tV2036062@svn.freebsd.org> From: Luigi Rizzo Date: Thu, 24 Dec 2009 17:06:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200949 - in user/luigi/ipfw3-head: bin/pax bin/sh contrib/pf/man contrib/pf/pfctl contrib/top etc include lib/libc/stdio lib/libc/stdtime lib/libpmc lib/libstand release sbin/dumpfs sb... X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 17:06:55 -0000 Author: luigi Date: Thu Dec 24 17:06:54 2009 New Revision: 200949 URL: http://svn.freebsd.org/changeset/base/200949 Log: merge from head up to rev 200946 Added: user/luigi/ipfw3-head/lib/libpmc/pmc.xscale.3 - copied unchanged from r200946, head/lib/libpmc/pmc.xscale.3 user/luigi/ipfw3-head/sys/dev/hwpmc/hwpmc_xscale.c - copied unchanged from r200946, head/sys/dev/hwpmc/hwpmc_xscale.c user/luigi/ipfw3-head/sys/dev/hwpmc/hwpmc_xscale.h - copied unchanged from r200946, head/sys/dev/hwpmc/hwpmc_xscale.h user/luigi/ipfw3-head/tools/regression/acltools/02.t - copied unchanged from r200946, head/tools/regression/acltools/02.t user/luigi/ipfw3-head/tools/tools/notescheck/ - copied from r200946, head/tools/tools/notescheck/ Modified: user/luigi/ipfw3-head/bin/pax/sel_subs.c user/luigi/ipfw3-head/bin/sh/main.c user/luigi/ipfw3-head/bin/sh/var.c user/luigi/ipfw3-head/contrib/pf/man/pf.conf.5 user/luigi/ipfw3-head/contrib/pf/pfctl/parse.y user/luigi/ipfw3-head/contrib/pf/pfctl/pf_print_state.c user/luigi/ipfw3-head/contrib/pf/pfctl/pfctl_parser.c user/luigi/ipfw3-head/etc/rc.subr user/luigi/ipfw3-head/include/signal.h user/luigi/ipfw3-head/lib/libc/stdio/sprintf.c user/luigi/ipfw3-head/lib/libc/stdio/sscanf.c user/luigi/ipfw3-head/lib/libc/stdio/vsscanf.c user/luigi/ipfw3-head/lib/libc/stdtime/localtime.c user/luigi/ipfw3-head/lib/libc/stdtime/tzfile.5 user/luigi/ipfw3-head/lib/libpmc/Makefile user/luigi/ipfw3-head/lib/libpmc/libpmc.c user/luigi/ipfw3-head/lib/libstand/bzipfs.c user/luigi/ipfw3-head/lib/libstand/gzipfs.c user/luigi/ipfw3-head/release/Makefile user/luigi/ipfw3-head/sbin/dumpfs/dumpfs.c user/luigi/ipfw3-head/sbin/mount/mntopts.h user/luigi/ipfw3-head/sbin/mount/mount.8 user/luigi/ipfw3-head/sbin/mount/mount.c user/luigi/ipfw3-head/sbin/tunefs/tunefs.8 user/luigi/ipfw3-head/sbin/tunefs/tunefs.c user/luigi/ipfw3-head/share/examples/etc/make.conf user/luigi/ipfw3-head/share/man/man4/watchdog.4 user/luigi/ipfw3-head/share/man/man9/Makefile user/luigi/ipfw3-head/share/man/man9/usbdi.9 user/luigi/ipfw3-head/share/zoneinfo/asia user/luigi/ipfw3-head/share/zoneinfo/europe user/luigi/ipfw3-head/share/zoneinfo/zone.tab user/luigi/ipfw3-head/sys/arm/conf/AVILA user/luigi/ipfw3-head/sys/arm/conf/CAMBRIA user/luigi/ipfw3-head/sys/arm/include/pmc_mdep.h user/luigi/ipfw3-head/sys/arm/xscale/ixp425/files.ixp425 user/luigi/ipfw3-head/sys/boot/common/dev_net.c user/luigi/ipfw3-head/sys/boot/i386/Makefile user/luigi/ipfw3-head/sys/boot/pc98/kgzldr/crt.s user/luigi/ipfw3-head/sys/boot/sparc64/loader/main.c user/luigi/ipfw3-head/sys/conf/files.arm user/luigi/ipfw3-head/sys/conf/files.sun4v user/luigi/ipfw3-head/sys/contrib/pf/net/if_pfsync.c user/luigi/ipfw3-head/sys/contrib/pf/net/if_pfsync.h user/luigi/ipfw3-head/sys/contrib/pf/net/pf.c user/luigi/ipfw3-head/sys/contrib/pf/net/pfvar.h user/luigi/ipfw3-head/sys/dev/ahci/ahci.c user/luigi/ipfw3-head/sys/dev/ata/ata-pci.h user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-amd.c user/luigi/ipfw3-head/sys/dev/ata/chipsets/ata-intel.c user/luigi/ipfw3-head/sys/dev/auxio/auxio.c user/luigi/ipfw3-head/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c user/luigi/ipfw3-head/sys/dev/hwpmc/hwpmc_arm.c user/luigi/ipfw3-head/sys/dev/hwpmc/pmc_events.h user/luigi/ipfw3-head/sys/dev/if_ndis/if_ndis_usb.c user/luigi/ipfw3-head/sys/dev/mxge/if_mxge.c user/luigi/ipfw3-head/sys/dev/sound/usb/uaudio.c user/luigi/ipfw3-head/sys/dev/ste/if_ste.c user/luigi/ipfw3-head/sys/dev/ste/if_stereg.h user/luigi/ipfw3-head/sys/dev/uart/uart_bus_acpi.c user/luigi/ipfw3-head/sys/dev/uart/uart_bus_ebus.c user/luigi/ipfw3-head/sys/dev/uart/uart_cpu_sparc64.c user/luigi/ipfw3-head/sys/dev/usb/controller/ehci_pci.c user/luigi/ipfw3-head/sys/dev/usb/controller/ohci_pci.c user/luigi/ipfw3-head/sys/dev/usb/quirk/usb_quirk.c user/luigi/ipfw3-head/sys/dev/usb/quirk/usb_quirk.h user/luigi/ipfw3-head/sys/dev/usb/serial/uftdi.c user/luigi/ipfw3-head/sys/dev/usb/storage/umass.c user/luigi/ipfw3-head/sys/dev/usb/usbdevs user/luigi/ipfw3-head/sys/geom/concat/g_concat.c user/luigi/ipfw3-head/sys/geom/geom_dev.c user/luigi/ipfw3-head/sys/geom/mirror/g_mirror.c user/luigi/ipfw3-head/sys/geom/raid3/g_raid3.c user/luigi/ipfw3-head/sys/geom/raid3/g_raid3.h user/luigi/ipfw3-head/sys/geom/stripe/g_stripe.c user/luigi/ipfw3-head/sys/ia64/ia64/clock.c user/luigi/ipfw3-head/sys/ia64/ia64/machdep.c user/luigi/ipfw3-head/sys/ia64/include/clock.h user/luigi/ipfw3-head/sys/ia64/include/mca.h user/luigi/ipfw3-head/sys/ia64/include/md_var.h user/luigi/ipfw3-head/sys/kern/vfs_subr.c user/luigi/ipfw3-head/sys/net/if_var.h user/luigi/ipfw3-head/sys/net/netisr.c user/luigi/ipfw3-head/sys/netinet/ip_fw.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c user/luigi/ipfw3-head/sys/netinet/tcp.h user/luigi/ipfw3-head/sys/netinet/tcp_usrreq.c user/luigi/ipfw3-head/sys/netinet6/mld6.c user/luigi/ipfw3-head/sys/netinet6/mld6_var.h user/luigi/ipfw3-head/sys/sparc64/central/central.c user/luigi/ipfw3-head/sys/sparc64/ebus/ebus.c user/luigi/ipfw3-head/sys/sparc64/fhc/fhc.c user/luigi/ipfw3-head/sys/sparc64/include/bus_common.h user/luigi/ipfw3-head/sys/sparc64/include/iommureg.h user/luigi/ipfw3-head/sys/sparc64/include/iommuvar.h user/luigi/ipfw3-head/sys/sparc64/isa/ofw_isa.c user/luigi/ipfw3-head/sys/sparc64/pci/apb.c user/luigi/ipfw3-head/sys/sparc64/pci/ofw_pci.h user/luigi/ipfw3-head/sys/sparc64/pci/ofw_pcib.c user/luigi/ipfw3-head/sys/sparc64/pci/ofw_pcibus.c user/luigi/ipfw3-head/sys/sparc64/sbus/dma_sbus.c user/luigi/ipfw3-head/sys/sparc64/sbus/sbus.c user/luigi/ipfw3-head/sys/sparc64/sparc64/identcpu.c user/luigi/ipfw3-head/sys/sparc64/sparc64/interrupt.S user/luigi/ipfw3-head/sys/sparc64/sparc64/intr_machdep.c user/luigi/ipfw3-head/sys/sparc64/sparc64/iommu.c user/luigi/ipfw3-head/sys/sparc64/sparc64/nexus.c user/luigi/ipfw3-head/sys/sparc64/sparc64/ofw_machdep.c user/luigi/ipfw3-head/sys/sparc64/sparc64/rtc.c user/luigi/ipfw3-head/sys/sparc64/sparc64/upa.c user/luigi/ipfw3-head/sys/sun4v/conf/NOTES user/luigi/ipfw3-head/sys/sys/acl.h user/luigi/ipfw3-head/sys/sys/disk.h user/luigi/ipfw3-head/sys/sys/mount.h user/luigi/ipfw3-head/sys/sys/vnode.h user/luigi/ipfw3-head/sys/ufs/ffs/ffs_rawread.c user/luigi/ipfw3-head/sys/ufs/ffs/ffs_vfsops.c user/luigi/ipfw3-head/sys/ufs/ffs/fs.h user/luigi/ipfw3-head/sys/ufs/ufs/acl.h user/luigi/ipfw3-head/sys/ufs/ufs/ufs_acl.c user/luigi/ipfw3-head/sys/ufs/ufs/ufs_lookup.c user/luigi/ipfw3-head/sys/ufs/ufs/ufs_vnops.c user/luigi/ipfw3-head/sys/vm/vm_object.c user/luigi/ipfw3-head/sys/vm/vm_object.h user/luigi/ipfw3-head/tools/tools/README user/luigi/ipfw3-head/usr.bin/finger/finger.c user/luigi/ipfw3-head/usr.bin/sockstat/sockstat.1 user/luigi/ipfw3-head/usr.bin/truss/amd64-fbsd32.c user/luigi/ipfw3-head/usr.bin/truss/i386-fbsd.c user/luigi/ipfw3-head/usr.bin/truss/syscalls.c user/luigi/ipfw3-head/usr.bin/unzip/unzip.c user/luigi/ipfw3-head/usr.sbin/apm/apm.8 user/luigi/ipfw3-head/usr.sbin/apm/apm.c user/luigi/ipfw3-head/usr.sbin/burncd/burncd.8 user/luigi/ipfw3-head/usr.sbin/burncd/burncd.c user/luigi/ipfw3-head/usr.sbin/newsyslog/newsyslog.c user/luigi/ipfw3-head/usr.sbin/powerd/powerd.8 user/luigi/ipfw3-head/usr.sbin/service/service.8 user/luigi/ipfw3-head/usr.sbin/service/service.sh user/luigi/ipfw3-head/usr.sbin/watchdogd/watchdogd.c user/luigi/ipfw3-head/usr.sbin/zic/Theory Directory Properties: user/luigi/ipfw3-head/ (props changed) user/luigi/ipfw3-head/cddl/contrib/opensolaris/ (props changed) user/luigi/ipfw3-head/contrib/bind9/ (props changed) user/luigi/ipfw3-head/contrib/cpio/ (props changed) user/luigi/ipfw3-head/contrib/csup/ (props changed) user/luigi/ipfw3-head/contrib/ee/ (props changed) user/luigi/ipfw3-head/contrib/expat/ (props changed) user/luigi/ipfw3-head/contrib/file/ (props changed) user/luigi/ipfw3-head/contrib/gdb/ (props changed) user/luigi/ipfw3-head/contrib/gdtoa/ (props changed) user/luigi/ipfw3-head/contrib/less/ (props changed) user/luigi/ipfw3-head/contrib/libpcap/ (props changed) user/luigi/ipfw3-head/contrib/ncurses/ (props changed) user/luigi/ipfw3-head/contrib/netcat/ (props changed) user/luigi/ipfw3-head/contrib/ntp/ (props changed) user/luigi/ipfw3-head/contrib/openbsm/ (props changed) user/luigi/ipfw3-head/contrib/openpam/ (props changed) user/luigi/ipfw3-head/contrib/pf/ (props changed) user/luigi/ipfw3-head/contrib/sendmail/ (props changed) user/luigi/ipfw3-head/contrib/tcpdump/ (props changed) user/luigi/ipfw3-head/contrib/tcsh/ (props changed) user/luigi/ipfw3-head/contrib/top/ (props changed) user/luigi/ipfw3-head/contrib/top/install-sh (props changed) user/luigi/ipfw3-head/contrib/wpa/ (props changed) user/luigi/ipfw3-head/crypto/openssh/ (props changed) user/luigi/ipfw3-head/crypto/openssl/ (props changed) user/luigi/ipfw3-head/lib/libc/ (props changed) user/luigi/ipfw3-head/lib/libc/stdtime/ (props changed) user/luigi/ipfw3-head/lib/libutil/ (props changed) user/luigi/ipfw3-head/sbin/ (props changed) user/luigi/ipfw3-head/sbin/ipfw/ (props changed) user/luigi/ipfw3-head/share/zoneinfo/ (props changed) user/luigi/ipfw3-head/sys/ (props changed) user/luigi/ipfw3-head/sys/amd64/include/xen/ (props changed) user/luigi/ipfw3-head/sys/cddl/contrib/opensolaris/ (props changed) user/luigi/ipfw3-head/sys/contrib/dev/acpica/ (props changed) user/luigi/ipfw3-head/sys/contrib/pf/ (props changed) user/luigi/ipfw3-head/sys/dev/xen/xenpci/ (props changed) user/luigi/ipfw3-head/usr.bin/csup/ (props changed) user/luigi/ipfw3-head/usr.bin/procstat/ (props changed) user/luigi/ipfw3-head/usr.sbin/zic/ (props changed) Modified: user/luigi/ipfw3-head/bin/pax/sel_subs.c ============================================================================== --- user/luigi/ipfw3-head/bin/pax/sel_subs.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/bin/pax/sel_subs.c Thu Dec 24 17:06:54 2009 (r200949) @@ -396,6 +396,7 @@ trng_add(char *str) default: paxwarn(1, "Bad option %c with time range %s", *flgpt, str); + free(pt); goto out; } ++flgpt; Modified: user/luigi/ipfw3-head/bin/sh/main.c ============================================================================== --- user/luigi/ipfw3-head/bin/sh/main.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/bin/sh/main.c Thu Dec 24 17:06:54 2009 (r200949) @@ -315,7 +315,6 @@ find_dot_file(char *basename) int dotcmd(int argc, char **argv) { - struct strlist *sp; char *fullname; if (argc < 2) @@ -323,9 +322,6 @@ dotcmd(int argc, char **argv) exitstatus = 0; - for (sp = cmdenviron; sp ; sp = sp->next) - setvareq(savestr(sp->text), VSTRFIXED|VTEXTFIXED); - fullname = find_dot_file(argv[1]); setinputfile(fullname, 1); commandname = fullname; Modified: user/luigi/ipfw3-head/bin/sh/var.c ============================================================================== --- user/luigi/ipfw3-head/bin/sh/var.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/bin/sh/var.c Thu Dec 24 17:06:54 2009 (r200949) @@ -607,7 +607,6 @@ exportcmd(int argc, char **argv) if (values && argc != 0) error("-p requires no arguments"); - listsetvar(cmdenviron); if (argc != 0) { while ((name = *argv++) != NULL) { if ((p = strchr(name, '=')) != NULL) { Modified: user/luigi/ipfw3-head/contrib/pf/man/pf.conf.5 ============================================================================== --- user/luigi/ipfw3-head/contrib/pf/man/pf.conf.5 Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/contrib/pf/man/pf.conf.5 Thu Dec 24 17:06:54 2009 (r200949) @@ -28,7 +28,7 @@ .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd October 30, 2006 +.Dd June 10, 2008 .Dt PF.CONF 5 .Os .Sh NAME @@ -2059,6 +2059,13 @@ Changes the timeout values used for stat For a list of all valid timeout names, see .Sx OPTIONS above. +.It Ar sloppy +Uses a sloppy TCP connection tracker that does not check sequence +numbers at all, which makes insertion and ICMP teardown attacks way +easier. +This is intended to be used in situations where one does not see all +packets of a connection, i.e. in asymmetric routing situations. +Cannot be used with modulate or synproxy state. .El .Pp Multiple options can be specified, separated by commas: @@ -2923,7 +2930,7 @@ tos = "tos" ( "lowdelay" | "t [ "0x" ] number ) state-opts = state-opt [ [ "," ] state-opts ] -state-opt = ( "max" number | "no-sync" | timeout | +state-opt = ( "max" number | "no-sync" | timeout | sloppy | "source-track" [ ( "rule" | "global" ) ] | "max-src-nodes" number | "max-src-states" number | "max-src-conn" number | Modified: user/luigi/ipfw3-head/contrib/pf/pfctl/parse.y ============================================================================== --- user/luigi/ipfw3-head/contrib/pf/pfctl/parse.y Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/contrib/pf/pfctl/parse.y Thu Dec 24 17:06:54 2009 (r200949) @@ -128,7 +128,7 @@ enum { PF_STATE_OPT_MAX, PF_STATE_OPT_NO PF_STATE_OPT_MAX_SRC_STATES, PF_STATE_OPT_MAX_SRC_CONN, PF_STATE_OPT_MAX_SRC_CONN_RATE, PF_STATE_OPT_MAX_SRC_NODES, PF_STATE_OPT_OVERLOAD, PF_STATE_OPT_STATELOCK, - PF_STATE_OPT_TIMEOUT }; + PF_STATE_OPT_TIMEOUT, PF_STATE_OPT_SLOPPY }; enum { PF_SRCTRACK_NONE, PF_SRCTRACK, PF_SRCTRACK_GLOBAL, PF_SRCTRACK_RULE }; @@ -423,7 +423,7 @@ typedef struct { %token QUEUE PRIORITY QLIMIT RTABLE %token LOAD RULESET_OPTIMIZATION %token STICKYADDRESS MAXSRCSTATES MAXSRCNODES SOURCETRACK GLOBAL RULE -%token MAXSRCCONN MAXSRCCONNRATE OVERLOAD FLUSH +%token MAXSRCCONN MAXSRCCONNRATE OVERLOAD FLUSH SLOPPY %token TAGGED TAG IFBOUND FLOATING STATEPOLICY ROUTE %token STRING %token PORTBINARY @@ -1891,6 +1891,14 @@ pfrule : action dir logquick interface statelock = 1; r.rule_flag |= o->data.statelock; break; + case PF_STATE_OPT_SLOPPY: + if (r.rule_flag & PFRULE_STATESLOPPY) { + yyerror("state sloppy option: " + "multiple definitions"); + YYERROR; + } + r.rule_flag |= PFRULE_STATESLOPPY; + break; case PF_STATE_OPT_TIMEOUT: if (o->data.timeout.number == PFTM_ADAPTIVE_START || @@ -3216,6 +3224,14 @@ state_opt_item : MAXIMUM number { $$->next = NULL; $$->tail = $$; } + | SLOPPY { + $$ = calloc(1, sizeof(struct node_state_opt)); + if ($$ == NULL) + err(1, "state_opt_item: calloc"); + $$->type = PF_STATE_OPT_SLOPPY; + $$->next = NULL; + $$->tail = $$; + } | STRING number { int i; @@ -4101,6 +4117,13 @@ filter_consistent(struct pf_rule *r, int yyerror("keep state on block rules doesn't make sense"); problems++; } + if (r->rule_flag & PFRULE_STATESLOPPY && + (r->keep_state == PF_STATE_MODULATE || + r->keep_state == PF_STATE_SYNPROXY)) { + yyerror("sloppy state matching cannot be used with " + "synproxy state or modulate state"); + problems++; + } return (-problems); } @@ -4969,6 +4992,7 @@ lookup(char *s) { "scrub", SCRUB}, { "set", SET}, { "skip", SKIP}, + { "sloppy", SLOPPY}, { "source-hash", SOURCEHASH}, { "source-track", SOURCETRACK}, { "state", STATE}, Modified: user/luigi/ipfw3-head/contrib/pf/pfctl/pf_print_state.c ============================================================================== --- user/luigi/ipfw3-head/contrib/pf/pfctl/pf_print_state.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/contrib/pf/pfctl/pf_print_state.c Thu Dec 24 17:06:54 2009 (r200949) @@ -294,6 +294,8 @@ print_state(struct pf_state *s, int opts printf(", anchor %u", s->anchor.nr); if (s->rule.nr != -1) printf(", rule %u", s->rule.nr); + if (s->state_flags & PFSTATE_SLOPPY) + printf(", sloppy"); if (s->src_node != NULL) printf(", source-track"); if (s->nat_src_node != NULL) Modified: user/luigi/ipfw3-head/contrib/pf/pfctl/pfctl_parser.c ============================================================================== --- user/luigi/ipfw3-head/contrib/pf/pfctl/pfctl_parser.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/contrib/pf/pfctl/pfctl_parser.c Thu Dec 24 17:06:54 2009 (r200949) @@ -873,6 +873,8 @@ print_rule(struct pf_rule *r, const char opts = 1; if (r->rule_flag & PFRULE_IFBOUND) opts = 1; + if (r->rule_flag & PFRULE_STATESLOPPY) + opts = 1; for (i = 0; !opts && i < PFTM_MAX; ++i) if (r->timeout[i]) opts = 1; @@ -939,6 +941,12 @@ print_rule(struct pf_rule *r, const char printf("if-bound"); opts = 0; } + if (r->rule_flag & PFRULE_STATESLOPPY) { + if (!opts) + printf(", "); + printf("sloppy"); + opts = 0; + } for (i = 0; i < PFTM_MAX; ++i) if (r->timeout[i]) { int j; Modified: user/luigi/ipfw3-head/etc/rc.subr ============================================================================== --- user/luigi/ipfw3-head/etc/rc.subr Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/etc/rc.subr Thu Dec 24 17:06:54 2009 (r200949) @@ -390,7 +390,7 @@ wait_for_pids() _list=$_nlist echo -n ${_prefix:-"Waiting for PIDS: "}$_list _prefix=", " - sleep 2 + pwait $_list 2>/dev/null || sleep 2 done if [ -n "$_prefix" ]; then echo "." Modified: user/luigi/ipfw3-head/include/signal.h ============================================================================== --- user/luigi/ipfw3-head/include/signal.h Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/include/signal.h Thu Dec 24 17:06:54 2009 (r200949) @@ -99,12 +99,12 @@ int sigwaitinfo(const sigset_t * __restr #if __XSI_VISIBLE int killpg(__pid_t, int); int sigaltstack(const stack_t * __restrict, stack_t * __restrict); -int sighold(int sig); -int sigignore(int sig); -int sigpause(int sigmask); -int sigrelse(int sig); -void (*sigset(int sig, void (*disp)(int)))(int); -int xsi_sigpause(int sig); +int sighold(int); +int sigignore(int); +int sigpause(int); +int sigrelse(int); +void (*sigset(int, void (*)(int)))(int); +int xsi_sigpause(int); #endif #if __XSI_VISIBLE >= 600 Modified: user/luigi/ipfw3-head/lib/libc/stdio/sprintf.c ============================================================================== --- user/luigi/ipfw3-head/lib/libc/stdio/sprintf.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/lib/libc/stdio/sprintf.c Thu Dec 24 17:06:54 2009 (r200949) @@ -46,17 +46,9 @@ sprintf(char * __restrict str, char cons { int ret; va_list ap; - FILE f; - f._file = -1; - f._flags = __SWR | __SSTR; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._w = INT_MAX; - f._orientation = 0; - memset(&f._mbstate, 0, sizeof(mbstate_t)); va_start(ap, fmt); - ret = __vfprintf(&f, fmt, ap); + ret = vsprintf(str, fmt, ap); va_end(ap); - *f._p = 0; return (ret); } Modified: user/luigi/ipfw3-head/lib/libc/stdio/sscanf.c ============================================================================== --- user/luigi/ipfw3-head/lib/libc/stdio/sscanf.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/lib/libc/stdio/sscanf.c Thu Dec 24 17:06:54 2009 (r200949) @@ -41,37 +41,14 @@ __FBSDID("$FreeBSD$"); #include #include "local.h" -static int eofread(void *, char *, int); - -/* ARGSUSED */ -static int -eofread(cookie, buf, len) - void *cookie; - char *buf; - int len; -{ - - return (0); -} - int sscanf(const char * __restrict str, char const * __restrict fmt, ...) { int ret; va_list ap; - FILE f; - f._file = -1; - f._flags = __SRD; - f._bf._base = f._p = (unsigned char *)str; - f._bf._size = f._r = strlen(str); - f._read = eofread; - f._ub._base = NULL; - f._lb._base = NULL; - f._orientation = 0; - memset(&f._mbstate, 0, sizeof(mbstate_t)); va_start(ap, fmt); - ret = __svfscanf(&f, fmt, ap); + ret = vsscanf(str, fmt, ap); va_end(ap); return (ret); } Modified: user/luigi/ipfw3-head/lib/libc/stdio/vsscanf.c ============================================================================== --- user/luigi/ipfw3-head/lib/libc/stdio/vsscanf.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/lib/libc/stdio/vsscanf.c Thu Dec 24 17:06:54 2009 (r200949) @@ -45,20 +45,15 @@ eofread(void *, char *, int); /* ARGSUSED */ static int -eofread(cookie, buf, len) - void *cookie; - char *buf; - int len; +eofread(void *cookie, char *buf, int len) { return (0); } int -vsscanf(str, fmt, ap) - const char * __restrict str; - const char * __restrict fmt; - __va_list ap; +vsscanf(const char * __restrict str, const char * __restrict fmt, + __va_list ap) { FILE f; Modified: user/luigi/ipfw3-head/lib/libc/stdtime/localtime.c ============================================================================== --- user/luigi/ipfw3-head/lib/libc/stdtime/localtime.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/lib/libc/stdtime/localtime.c Thu Dec 24 17:06:54 2009 (r200949) @@ -237,6 +237,9 @@ static char lcl_TZname[TZ_STRLEN_MAX + static int lcl_is_set; static pthread_once_t gmt_once = PTHREAD_ONCE_INIT; static pthread_rwlock_t lcl_rwlock = PTHREAD_RWLOCK_INITIALIZER; +static pthread_once_t localtime_once = PTHREAD_ONCE_INIT; +static pthread_key_t localtime_key; +static int localtime_key_error; char * tzname[2] = { wildabbr, @@ -1406,27 +1409,24 @@ struct tm * const tmp; return result; } +static void +localtime_key_init(void) +{ + + localtime_key_error = _pthread_key_create(&localtime_key, free); +} + struct tm * localtime(timep) const time_t * const timep; { - static pthread_mutex_t localtime_mutex = PTHREAD_MUTEX_INITIALIZER; - static pthread_key_t localtime_key = -1; struct tm *p_tm; - int r; if (__isthreaded != 0) { - if (localtime_key < 0) { - _pthread_mutex_lock(&localtime_mutex); - if (localtime_key < 0) { - if ((r = _pthread_key_create(&localtime_key, - free)) != 0) { - _pthread_mutex_unlock(&localtime_mutex); - errno = r; - return(NULL); - } - } - _pthread_mutex_unlock(&localtime_mutex); + _once(&localtime_once, localtime_key_init); + if (localtime_key_error != 0) { + errno = localtime_key_error; + return(NULL); } p_tm = _pthread_getspecific(localtime_key); if (p_tm == NULL) { Modified: user/luigi/ipfw3-head/lib/libc/stdtime/tzfile.5 ============================================================================== --- user/luigi/ipfw3-head/lib/libc/stdtime/tzfile.5 Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/lib/libc/stdtime/tzfile.5 Thu Dec 24 17:06:54 2009 (r200949) @@ -147,6 +147,6 @@ such instants). .Xr ctime 3 , .Xr time2posix 3 , .Xr zic 8 -.\" @(#)tzfile.5 8.2 +.\" @(#)tzfile.5 8.3 .\" This file is in the public domain, so clarified as of .\" 1996-06-05 by Arthur David Olson. Modified: user/luigi/ipfw3-head/lib/libpmc/Makefile ============================================================================== --- user/luigi/ipfw3-head/lib/libpmc/Makefile Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/lib/libpmc/Makefile Thu Dec 24 17:06:54 2009 (r200949) @@ -35,6 +35,8 @@ MAN+= pmc.p4.3 MAN+= pmc.p5.3 MAN+= pmc.p6.3 MAN+= pmc.tsc.3 +.elif ${MACHINE_ARCH} == "arm" && ${CPUTYPE} == "xscale" +MAN+= pmc.xscale.3 .endif MLINKS+= \ Modified: user/luigi/ipfw3-head/lib/libpmc/libpmc.c ============================================================================== --- user/luigi/ipfw3-head/lib/libpmc/libpmc.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/lib/libpmc/libpmc.c Thu Dec 24 17:06:54 2009 (r200949) @@ -69,6 +69,10 @@ static int p6_allocate_pmc(enum pmc_even static int tsc_allocate_pmc(enum pmc_event _pe, char *_ctrspec, struct pmc_op_pmcallocate *_pmc_config); #endif +#if defined(__XSCALE__) +static int xscale_allocate_pmc(enum pmc_event _pe, char *_ctrspec, + struct pmc_op_pmcallocate *_pmc_config); +#endif #define PMC_CALL(cmd, params) \ syscall(pmc_syscall, PMC_OP_##cmd, (params)) @@ -132,6 +136,7 @@ PMC_CLASSDEP_TABLE(k8, K8); PMC_CLASSDEP_TABLE(p4, P4); PMC_CLASSDEP_TABLE(p5, P5); PMC_CLASSDEP_TABLE(p6, P6); +PMC_CLASSDEP_TABLE(xscale, XSCALE); #undef __PMC_EV_ALIAS #define __PMC_EV_ALIAS(N,CODE) { N, PMC_EV_##CODE }, @@ -176,6 +181,7 @@ PMC_MDEP_TABLE(k8, K8, PMC_CLASS_TSC); PMC_MDEP_TABLE(p4, P4, PMC_CLASS_TSC); PMC_MDEP_TABLE(p5, P5, PMC_CLASS_TSC); PMC_MDEP_TABLE(p6, P6, PMC_CLASS_TSC); +PMC_MDEP_TABLE(xscale, XSCALE, PMC_CLASS_XSCALE); static const struct pmc_event_descr tsc_event_table[] = { @@ -216,6 +222,9 @@ PMC_CLASS_TABLE_DESC(p6, P6, p6, p6); #if defined(__i386__) || defined(__amd64__) PMC_CLASS_TABLE_DESC(tsc, TSC, tsc, tsc); #endif +#if defined(__XSCALE__) +PMC_CLASS_TABLE_DESC(xscale, XSCALE, xscale, xscale); +#endif #undef PMC_CLASS_TABLE_DESC @@ -2008,6 +2017,29 @@ tsc_allocate_pmc(enum pmc_event pe, char } #endif +#if defined(__XSCALE__) + +static struct pmc_event_alias xscale_aliases[] = { + EV_ALIAS("branches", "BRANCH_RETIRED"), + EV_ALIAS("branch-mispredicts", "BRANCH_MISPRED"), + EV_ALIAS("dc-misses", "DC_MISS"), + EV_ALIAS("ic-misses", "IC_MISS"), + EV_ALIAS("instructions", "INSTR_RETIRED"), + EV_ALIAS(NULL, NULL) +}; +static int +xscale_allocate_pmc(enum pmc_event pe, char *ctrspec __unused, + struct pmc_op_pmcallocate *pmc_config __unused) +{ + switch (pe) { + default: + break; + } + + return (0); +} +#endif + /* * Match an event name `name' with its canonical form. * @@ -2335,6 +2367,10 @@ pmc_event_names_of_class(enum pmc_class ev = p6_event_table; count = PMC_EVENT_TABLE_SIZE(p6); break; + case PMC_CLASS_XSCALE: + ev = xscale_event_table; + count = PMC_EVENT_TABLE_SIZE(xscale); + break; default: errno = EINVAL; return (-1); @@ -2520,6 +2556,12 @@ pmc_init(void) pmc_class_table[n] = &p4_class_table_descr; break; #endif +#if defined(__XSCALE__) + case PMC_CPU_INTEL_XSCALE: + PMC_MDEP_INIT(xscale); + pmc_class_table[n] = &xscale_class_table_descr; + break; +#endif default: @@ -2635,6 +2677,9 @@ _pmc_name_of_event(enum pmc_event pe, en } else if (pe >= PMC_EV_P6_FIRST && pe <= PMC_EV_P6_LAST) { ev = p6_event_table; evfence = p6_event_table + PMC_EVENT_TABLE_SIZE(p6); + } else if (pe >= PMC_EV_XSCALE_FIRST && pe <= PMC_EV_XSCALE_LAST) { + ev = xscale_event_table; + evfence = xscale_event_table + PMC_EVENT_TABLE_SIZE(xscale); } else if (pe == PMC_EV_TSC_TSC) { ev = tsc_event_table; evfence = tsc_event_table + PMC_EVENT_TABLE_SIZE(tsc); Copied: user/luigi/ipfw3-head/lib/libpmc/pmc.xscale.3 (from r200946, head/lib/libpmc/pmc.xscale.3) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/luigi/ipfw3-head/lib/libpmc/pmc.xscale.3 Thu Dec 24 17:06:54 2009 (r200949, copy of r200946, head/lib/libpmc/pmc.xscale.3) @@ -0,0 +1,39 @@ +.\" Copyright (c) 2009 Rui Paulo. 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 Joseph Koshy ``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 Joseph Koshy 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 December 23, 2009 +.Os +.Dt PMC.XSCALE 3 +.Sh NAME +.Nm pmc.xscale +.Nd measurement events for +.Tn Intel +.Tn XScale +family CPUs +.Sh LIBRARY +.Lb libpmc +.Sh SYNOPSIS +.In pmc.h +.Sh DESCRIPTION Modified: user/luigi/ipfw3-head/lib/libstand/bzipfs.c ============================================================================== --- user/luigi/ipfw3-head/lib/libstand/bzipfs.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/lib/libstand/bzipfs.c Thu Dec 24 17:06:54 2009 (r200949) @@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$"); #ifndef REGRESSION #include "stand.h" #else +#include #include #include #include @@ -42,7 +43,7 @@ struct open_file { }; #define F_READ 0x0001 /* file opened for reading */ #define EOFFSET (ELAST+8) /* relative seek not supported */ -static inline u_int min(u_int a, u_int b) { return (a < b ? a : b); } +static inline u_int min(u_int a, u_int b) { return(a < b ? a : b); } #define panic(x, y) abort() #endif @@ -174,6 +175,8 @@ bzf_open(const char *fname, struct open_ /* Construct new name */ bzfname = malloc(strlen(fname) + 5); + if (bzfname == NULL) + return(ENOMEM); sprintf(bzfname, "%s.bz2", fname); /* Try to open the compressed datafile */ @@ -195,13 +198,14 @@ bzf_open(const char *fname, struct open_ /* Allocate a bz_file structure, populate it */ bzf = malloc(sizeof(struct bz_file)); + if (bzf == NULL) + return(ENOMEM); bzero(bzf, sizeof(struct bz_file)); bzf->bzf_rawfd = rawfd; - /* Verify that the file is bzipped (XXX why do this afterwards?) */ + /* Verify that the file is bzipped */ if (check_header(bzf)) { close(bzf->bzf_rawfd); - BZ2_bzDecompressEnd(&(bzf->bzf_bzstream)); free(bzf); return(EFTYPE); } @@ -247,7 +251,7 @@ bzf_read(struct open_file *f, void *buf, if (bzf->bzf_bzstream.avail_in == 0) { /* oops, unexpected EOF */ printf("bzf_read: unexpected EOF\n"); if (bzf->bzf_bzstream.avail_out == size) - return (EIO); + return(EIO); break; } @@ -266,6 +270,50 @@ bzf_read(struct open_file *f, void *buf, return(0); } +static int +bzf_rewind(struct open_file *f) +{ + struct bz_file *bzf = (struct bz_file *)f->f_fsdata; + struct bz_file *bzf_tmp; + + /* + * Since bzip2 does not have an equivalent inflateReset function a crude + * one needs to be provided. The functions all called in such a way that + * at any time an error occurs a role back can be done (effectively making + * this rewind 'atomic', either the reset occurs successfully or not at all, + * with no 'undefined' state happening). + */ + + /* Allocate a bz_file structure, populate it */ + bzf_tmp = malloc(sizeof(struct bz_file)); + if (bzf_tmp == NULL) + return(-1); + bzero(bzf_tmp, sizeof(struct bz_file)); + bzf_tmp->bzf_rawfd = bzf->bzf_rawfd; + + /* Initialise the inflation engine */ + if (BZ2_bzDecompressInit(&(bzf_tmp->bzf_bzstream), 0, 1) != BZ_OK) { + free(bzf_tmp); + return(-1); + } + + /* Seek back to the beginning of the file */ + if (lseek(bzf->bzf_rawfd, 0, SEEK_SET) == -1) { + BZ2_bzDecompressEnd(&(bzf_tmp->bzf_bzstream)); + free(bzf_tmp); + return(-1); + } + + /* Free old bz_file data */ + BZ2_bzDecompressEnd(&(bzf->bzf_bzstream)); + free(bzf); + + /* Use the new bz_file data */ + f->f_fsdata = bzf_tmp; + + return(0); +} + static off_t bzf_seek(struct open_file *f, off_t offset, int where) { @@ -284,14 +332,17 @@ bzf_seek(struct open_file *f, off_t offs target = -1; default: errno = EINVAL; - return (-1); + return(-1); } /* Can we get there from here? */ - if (target < bzf->bzf_bzstream.total_out_lo32) { + if (target < bzf->bzf_bzstream.total_out_lo32 && bzf_rewind(f) != 0) { errno = EOFFSET; return -1; - } + } + + /* if bzf_rewind was called then bzf has changed */ + bzf = (struct bz_file *)f->f_fsdata; /* skip forwards if required */ while (target > bzf->bzf_bzstream.total_out_lo32) { @@ -301,7 +352,7 @@ bzf_seek(struct open_file *f, off_t offs return(-1); } /* This is where we are (be honest if we overshot) */ - return (bzf->bzf_bzstream.total_out_lo32); + return(bzf->bzf_bzstream.total_out_lo32); } static int Modified: user/luigi/ipfw3-head/lib/libstand/gzipfs.c ============================================================================== --- user/luigi/ipfw3-head/lib/libstand/gzipfs.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/lib/libstand/gzipfs.c Thu Dec 24 17:06:54 2009 (r200949) @@ -212,10 +212,9 @@ zf_open(const char *fname, struct open_f bzero(zf, sizeof(struct z_file)); zf->zf_rawfd = rawfd; - /* Verify that the file is gzipped (XXX why do this afterwards?) */ + /* Verify that the file is gzipped */ if (check_header(zf)) { close(zf->zf_rawfd); - inflateEnd(&(zf->zf_zstream)); free(zf); return(EFTYPE); } @@ -261,7 +260,7 @@ zf_read(struct open_file *f, void *buf, if (zf->zf_zstream.avail_in == 0) { /* oops, unexpected EOF */ printf("zf_read: unexpected EOF\n"); if (zf->zf_zstream.avail_out == size) - return (EIO); + return(EIO); break; } @@ -286,12 +285,13 @@ zf_rewind(struct open_file *f) struct z_file *zf = (struct z_file *)f->f_fsdata; if (lseek(zf->zf_rawfd, zf->zf_dataoffset, SEEK_SET) == -1) - return -1; + return(-1); zf->zf_zstream.avail_in = 0; zf->zf_zstream.next_in = NULL; + zf->zf_endseen = 0; (void)inflateReset(&zf->zf_zstream); - return 0; + return(0); } static off_t @@ -312,12 +312,12 @@ zf_seek(struct open_file *f, off_t offse target = -1; default: errno = EINVAL; - return (-1); + return(-1); } /* rewind if required */ if (target < zf->zf_zstream.total_out && zf_rewind(f) != 0) - return -1; + return(-1); /* skip forwards if required */ while (target > zf->zf_zstream.total_out) { @@ -327,7 +327,7 @@ zf_seek(struct open_file *f, off_t offse return(-1); } /* This is where we are (be honest if we overshot) */ - return (zf->zf_zstream.total_out); + return(zf->zf_zstream.total_out); } Modified: user/luigi/ipfw3-head/release/Makefile ============================================================================== --- user/luigi/ipfw3-head/release/Makefile Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/release/Makefile Thu Dec 24 17:06:54 2009 (r200949) @@ -1128,36 +1128,36 @@ iso.1: .if defined(CD_BOOT) @sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh ${BOOTABLE} \ FreeBSD_bootonly \ - ${CD}/${BUILDNAME}-${TARGET}-bootonly.iso ${CD_BOOT} + ${CD}/FreeBSD-${BUILDNAME}-${TARGET}-bootonly.iso ${CD_BOOT} .endif @sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh ${BOOTABLE} \ FreeBSD_Install \ - ${CD}/${BUILDNAME}-${TARGET}-disc1.iso ${CD_DISC1} \ + ${CD}/FreeBSD-${BUILDNAME}-${TARGET}-disc1.iso ${CD_DISC1} \ ${CD_DISC1_PKGS} @sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh \ FreeBSD_Packages \ - ${CD}/${BUILDNAME}-${TARGET}-disc2.iso ${CD_DISC2} \ + ${CD}/FreeBSD-${BUILDNAME}-${TARGET}-disc2.iso ${CD_DISC2} \ ${CD_DISC2_PKGS} .if defined(MAKE_DVD) @sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh ${BOOTABLE} \ FreeBSD_Install \ - ${CD}/${BUILDNAME}-${TARGET}-dvd1.iso ${CD_DVD1} \ + ${CD}/FreeBSD-${BUILDNAME}-${TARGET}-dvd1.iso ${CD_DVD1} \ ${CD_DVD1_PKGS} .endif .if !defined(NODOC) @sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh \ FreeBSD_Documentation \ - ${CD}/${BUILDNAME}-${TARGET}-disc3.iso ${CD_DOCS} \ + ${CD}/FreeBSD-${BUILDNAME}-${TARGET}-disc3.iso ${CD_DOCS} \ ${CD_DOCS_PKGS} .endif .if defined(SEPARATE_LIVEFS) @sh ${.CURDIR}/${TARGET_ARCH}/mkisoimages.sh ${BOOTABLE} \ FreeBSD_LiveFS \ - ${CD}/${BUILDNAME}-${TARGET}-livefs.iso ${CD_LIVEFS} + ${CD}/FreeBSD-${BUILDNAME}-${TARGET}-livefs.iso ${CD_LIVEFS} .endif @echo "Generating MD5 and SHA256 sums..." - @(cd ${CD} && md5 *.iso > ${BUILDNAME}-${TARGET}-iso.CHECKSUM.MD5) - @(cd ${CD} && sha256 *.iso > ${BUILDNAME}-${TARGET}-iso.CHECKSUM.SHA256) + @(cd ${CD} && md5 *.iso > FreeBSD-${BUILDNAME}-${TARGET}-iso.CHECKSUM.MD5) + @(cd ${CD} && sha256 *.iso > FreeBSD-${BUILDNAME}-${TARGET}-iso.CHECKSUM.SHA256) touch ${.TARGET} .else @echo "Do not know how to create an ISO for ${TARGET_ARCH}." Modified: user/luigi/ipfw3-head/sbin/dumpfs/dumpfs.c ============================================================================== --- user/luigi/ipfw3-head/sbin/dumpfs/dumpfs.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/sbin/dumpfs/dumpfs.c Thu Dec 24 17:06:54 2009 (r200949) @@ -251,8 +251,11 @@ dumpfs(const char *name) printf("gjournal "); if (fsflags & FS_FLAGS_UPDATED) printf("fs_flags expanded "); + if (fsflags & FS_NFS4ACLS) + printf("nfsv4acls "); fsflags &= ~(FS_UNCLEAN | FS_DOSOFTDEP | FS_NEEDSFSCK | FS_INDEXDIRS | - FS_ACLS | FS_MULTILABEL | FS_GJOURNAL | FS_FLAGS_UPDATED); + FS_ACLS | FS_MULTILABEL | FS_GJOURNAL | FS_FLAGS_UPDATED | + FS_NFS4ACLS); if (fsflags != 0) printf("unknown flags (%#x)", fsflags); putchar('\n'); Modified: user/luigi/ipfw3-head/sbin/mount/mntopts.h ============================================================================== --- user/luigi/ipfw3-head/sbin/mount/mntopts.h Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/sbin/mount/mntopts.h Thu Dec 24 17:06:54 2009 (r200949) @@ -54,6 +54,7 @@ struct mntopt { #define MOPT_SNAPSHOT { "snapshot", 0, MNT_SNAPSHOT, 0 } #define MOPT_MULTILABEL { "multilabel", 0, MNT_MULTILABEL, 0 } #define MOPT_ACLS { "acls", 0, MNT_ACLS, 0 } +#define MOPT_NFS4ACLS { "nfsv4acls", 0, MNT_NFS4ACLS, 0 } /* Control flags. */ #define MOPT_FORCE { "force", 0, MNT_FORCE, 0 } @@ -87,7 +88,8 @@ struct mntopt { MOPT_NOCLUSTERR, \ MOPT_NOCLUSTERW, \ MOPT_MULTILABEL, \ - MOPT_ACLS + MOPT_ACLS, \ + MOPT_NFS4ACLS void getmntopts(const char *, const struct mntopt *, int *, int *); void rmslashes(char *, char *); Modified: user/luigi/ipfw3-head/sbin/mount/mount.8 ============================================================================== --- user/luigi/ipfw3-head/sbin/mount/mount.8 Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/sbin/mount/mount.8 Thu Dec 24 17:06:54 2009 (r200949) @@ -120,11 +120,14 @@ takes effect. The following options are available: .Bl -tag -width indent .It Cm acls -Enable Access Control Lists, or ACLS, which can be customized via the +Enable POSIX.1e Access Control Lists, or ACLs, which can be customized via the .Xr setfacl 1 and .Xr getfacl 1 commands. +This flag is mutually exclusive with +.Cm nfsv4acls +flag. .It Cm async All .Tn I/O @@ -186,6 +189,15 @@ See .Xr mac 4 for more information, which cause the multilabel mount flag to be set automatically at mount-time. +.It Cm nfsv4acls +Enable NFSv4 ACLs, which can be customized via the +.Xr setfacl 1 +and +.Xr getfacl 1 +commands. +This flag is mutually exclusive with +.Cm acls +flag. .It Cm noasync Metadata I/O should be done synchronously, while data I/O should be done asynchronously. Modified: user/luigi/ipfw3-head/sbin/mount/mount.c ============================================================================== --- user/luigi/ipfw3-head/sbin/mount/mount.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/sbin/mount/mount.c Thu Dec 24 17:06:54 2009 (r200949) @@ -111,6 +111,7 @@ static struct opt { { MNT_SOFTDEP, "soft-updates" }, { MNT_MULTILABEL, "multilabel" }, { MNT_ACLS, "acls" }, + { MNT_NFS4ACLS, "nfsv4acls" }, { MNT_GJOURNAL, "gjournal" }, { 0, NULL } }; @@ -918,6 +919,7 @@ flags2opts(int flags) if (flags & MNT_SUIDDIR) res = catopt(res, "suiddir"); if (flags & MNT_MULTILABEL) res = catopt(res, "multilabel"); if (flags & MNT_ACLS) res = catopt(res, "acls"); + if (flags & MNT_NFS4ACLS) res = catopt(res, "nfsv4acls"); return (res); } Modified: user/luigi/ipfw3-head/sbin/tunefs/tunefs.8 ============================================================================== --- user/luigi/ipfw3-head/sbin/tunefs/tunefs.8 Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/sbin/tunefs/tunefs.8 Thu Dec 24 17:06:54 2009 (r200949) @@ -44,6 +44,7 @@ .Op Fl L Ar volname .Op Fl l Cm enable | disable .Op Fl m Ar minfree +.Op Fl N Cm enable | disable .Op Fl n Cm enable | disable .Op Fl o Cm space | time .Op Fl p @@ -70,7 +71,7 @@ this option will cause all backups to be primary super-block. This is potentially dangerous - use with caution. .It Fl a Cm enable | disable -Turn on/off the administrative ACL enable flag. +Turn on/off the administrative POSIX.1e ACL enable flag. .It Fl e Ar maxbpg Indicate the maximum number of blocks any single file can allocate out of a cylinder group before it is forced to begin @@ -114,6 +115,8 @@ factor of three over the performance obt If the value is raised above the current usage level, users will be unable to allocate files until enough files have been deleted to get under the higher threshold. +.It Fl N Cm enable | disable +Turn on/off the administrative NFSv4 ACL enable flag. .It Fl n Cm enable | disable Turn on/off soft updates. .It Fl o Cm space | time Modified: user/luigi/ipfw3-head/sbin/tunefs/tunefs.c ============================================================================== --- user/luigi/ipfw3-head/sbin/tunefs/tunefs.c Thu Dec 24 15:43:37 2009 (r200948) +++ user/luigi/ipfw3-head/sbin/tunefs/tunefs.c Thu Dec 24 17:06:54 2009 (r200949) @@ -76,12 +76,12 @@ void printfs(void); int main(int argc, char *argv[]) { - char *avalue, *Jvalue, *Lvalue, *lvalue, *nvalue; + char *avalue, *Jvalue, *Lvalue, *lvalue, *Nvalue, *nvalue; const char *special, *on; const char *name; int active; int Aflag, aflag, eflag, evalue, fflag, fvalue, Jflag, Lflag, lflag; - int mflag, mvalue, nflag, oflag, ovalue, pflag, sflag, svalue; + int mflag, mvalue, Nflag, nflag, oflag, ovalue, pflag, sflag, svalue; int ch, found_arg, i; const char *chg[2]; struct ufs_args args; @@ -90,12 +90,12 @@ main(int argc, char *argv[]) if (argc < 3) usage(); Aflag = aflag = eflag = fflag = Jflag = Lflag = lflag = mflag = 0; - nflag = oflag = pflag = sflag = 0; - avalue = Jvalue = Lvalue = lvalue = nvalue = NULL; + Nflag = nflag = oflag = pflag = sflag = 0; + avalue = Jvalue = Lvalue = lvalue = Nvalue = nvalue = NULL; evalue = fvalue = mvalue = ovalue = svalue = 0; active = 0; found_arg = 0; /* At least one arg is required. */ - while ((ch = getopt(argc, argv, "Aa:e:f:J:L:l:m:n:o:ps:")) != -1) + while ((ch = getopt(argc, argv, "Aa:e:f:J:L:l:m:N:n:o:ps:")) != -1) switch (ch) { case 'A': @@ -105,7 +105,7 @@ main(int argc, char *argv[]) case 'a': found_arg = 1; - name = "ACLs"; + name = "POSIX.1e ACLs"; avalue = optarg; if (strcmp(avalue, "enable") && strcmp(avalue, "disable")) { @@ -187,6 +187,18 @@ main(int argc, char *argv[]) mflag = 1; break; + case 'N': + found_arg = 1; + name = "NFSv4 ACLs"; + Nvalue = optarg; + if (strcmp(Nvalue, "enable") && + strcmp(Nvalue, "disable")) { + errx(10, "bad %s (options are %s)", + name, "`enable' or `disable'"); + } + Nflag = 1; + break; + case 'n': found_arg = 1; name = "soft updates"; @@ -255,10 +267,13 @@ main(int argc, char *argv[]) strlcpy(sblock.fs_volname, Lvalue, MAXVOLLEN); } if (aflag) { - name = "ACLs"; + name = "POSIX.1e ACLs"; if (strcmp(avalue, "enable") == 0) { if (sblock.fs_flags & FS_ACLS) { warnx("%s remains unchanged as enabled", name); + } else if (sblock.fs_flags & FS_NFS4ACLS) { + warnx("%s and NFSv4 ACLs are mutually " + "exclusive", name); } else { sblock.fs_flags |= FS_ACLS; warnx("%s set", name); @@ -349,6 +364,29 @@ main(int argc, char *argv[]) warnx(OPTWARN, "space", "<", MINFREE); } } + if (Nflag) { + name = "NFSv4 ACLs"; + if (strcmp(Nvalue, "enable") == 0) { + if (sblock.fs_flags & FS_NFS4ACLS) { + warnx("%s remains unchanged as enabled", name); + } else if (sblock.fs_flags & FS_ACLS) { + warnx("%s and POSIX.1e ACLs are mutually " + "exclusive", name); + } else { + sblock.fs_flags |= FS_NFS4ACLS; + warnx("%s set", name); + } + } else if (strcmp(Nvalue, "disable") == 0) { + if ((~sblock.fs_flags & FS_NFS4ACLS) == + FS_NFS4ACLS) { + warnx("%s remains unchanged as disabled", + name); + } else { + sblock.fs_flags &= ~FS_NFS4ACLS; + warnx("%s cleared", name); + } + } + } if (nflag) { name = "soft updates"; if (strcmp(nvalue, "enable") == 0) { @@ -423,16 +461,18 @@ usage(void) fprintf(stderr, "%s\n%s\n%s\n%s\n", "usage: tunefs [-A] [-a enable | disable] [-e maxbpg] [-f avgfilesize]", " [-J enable | disable ] [-L volname] [-l enable | disable]", -" [-m minfree] [-n enable | disable] [-o space | time] [-p]", -" [-s avgfpdir] special | filesystem"); +" [-m minfree] [-N enable | disable] [-n enable | disable]", +" [-o space | time] [-p] [-s avgfpdir] special | filesystem"); exit(2); } void printfs(void) { - warnx("ACLs: (-a) %s", + warnx("POSIX.1e ACLs: (-a) %s", *** DIFF OUTPUT TRUNCATED AT 1000 LINES *** From owner-svn-src-user@FreeBSD.ORG Thu Dec 24 17:35:48 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BB6AA1065670; Thu, 24 Dec 2009 17:35:48 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AB1B28FC1C; Thu, 24 Dec 2009 17:35:48 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBOHZmAS036725; Thu, 24 Dec 2009 17:35:48 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBOHZmqc036723; Thu, 24 Dec 2009 17:35:48 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912241735.nBOHZmqc036723@svn.freebsd.org> From: Luigi Rizzo Date: Thu, 24 Dec 2009 17:35:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200952 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 17:35:48 -0000 Author: luigi Date: Thu Dec 24 17:35:48 2009 New Revision: 200952 URL: http://svn.freebsd.org/changeset/base/200952 Log: remove duplicate block Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Thu Dec 24 17:35:28 2009 (r200951) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Thu Dec 24 17:35:48 2009 (r200952) @@ -882,9 +882,6 @@ ipfw_ctl(struct sockopt *sopt) if (size >= want) break; } - if (size >= want) - break; - } break; case IP_FW_FLUSH: From owner-svn-src-user@FreeBSD.ORG Thu Dec 24 18:50:59 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 13CB91065693; Thu, 24 Dec 2009 18:50:59 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 02C498FC18; Thu, 24 Dec 2009 18:50:59 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBOIowSs038309; Thu, 24 Dec 2009 18:50:58 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBOIowAg038302; Thu, 24 Dec 2009 18:50:58 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912241850.nBOIowAg038302@svn.freebsd.org> From: Luigi Rizzo Date: Thu, 24 Dec 2009 18:50:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200957 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 18:50:59 -0000 Author: luigi Date: Thu Dec 24 18:50:58 2009 New Revision: 200957 URL: http://svn.freebsd.org/changeset/base/200957 Log: Make the code a bit more portable doing the ip_len/ip_off controlled by a HAVE_NET_IPLEN macro (which is not defined on FreeBSD so we use ip_len and ip_off in host order on layer3). Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_dynamic.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Thu Dec 24 18:41:14 2009 (r200956) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Thu Dec 24 18:50:58 2009 (r200957) @@ -991,8 +991,10 @@ dummynet_send(struct mbuf *m) break ; case DN_TO_IP_IN : ip = mtod(m, struct ip *); +#ifndef HAVE_NET_IPLEN ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); +#endif netisr_dispatch(NETISR_IP, m); break; #ifdef INET6 Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Thu Dec 24 18:41:14 2009 (r200956) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Thu Dec 24 18:50:58 2009 (r200957) @@ -607,8 +607,10 @@ send_reject(struct ip_fw_args *args, int if (code != ICMP_REJECT_RST) { /* Send an ICMP unreach */ /* We need the IP header in host order for icmp_error(). */ if (args->eh != NULL) { +#ifndef HAVE_NET_IPLEN ip->ip_len = ntohs(ip->ip_len); ip->ip_off = ntohs(ip->ip_off); +#endif /* !HAVE_NET_IPLEN */ } icmp_error(args->m, ICMP_UNREACH, code, 0L, 0); } else if (args->f_id.proto == IPPROTO_TCP) { @@ -1094,10 +1096,13 @@ do { \ proto = ip->ip_p; src_ip = ip->ip_src; dst_ip = ip->ip_dst; +#ifndef HAVE_NET_IPLEN if (args->eh != NULL) { /* layer 2 packets are as on the wire */ offset = ntohs(ip->ip_off) & IP_OFFMASK; ip_len = ntohs(ip->ip_len); - } else { + } else +#endif /* !HAVE_NET_IPLEN */ + { offset = ip->ip_off & IP_OFFMASK; ip_len = ip->ip_len; } @@ -2124,8 +2129,13 @@ do { \ f->bcnt += pktlen; l = 0; /* in any case exit inner loop */ - ip_off = (args->eh != NULL) ? - ntohs(ip->ip_off) : ip->ip_off; +#ifndef HAVE_NET_IPLEN + if (args->eh == NULL) + ip_off = ip->ip_off; + else +#endif /* !HAVE_NET_IPLEN */ + ip_off = ntohs(ip->ip_off); + /* if not fragmented, go to next rule */ if ((ip_off & (IP_MF | IP_OFFMASK)) == 0) break; @@ -2134,10 +2144,12 @@ do { \ * byte order: fix them in case we come * from layer2. */ +#ifndef HAVE_NET_IPLEN if (args->eh != NULL) { ip->ip_len = ntohs(ip->ip_len); ip->ip_off = ntohs(ip->ip_off); } +#endif /* !HAVE_NET_IPLEN */ args->m = m = ip_reass(m); @@ -2153,9 +2165,11 @@ do { \ ip = mtod(m, struct ip *); hlen = ip->ip_hl << 2; +#ifndef HAVE_NET_IPLEN /* revert len & off for layer2 pkts */ if (args->eh != NULL) ip->ip_len = htons(ip->ip_len); +#endif /* !HAVE_NET_IPLEN */ ip->ip_sum = 0; if (hlen == sizeof(struct ip)) ip->ip_sum = in_cksum_hdr(ip); Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_dynamic.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_dynamic.c Thu Dec 24 18:41:14 2009 (r200956) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_dynamic.c Thu Dec 24 18:50:58 2009 (r200957) @@ -1002,7 +1002,11 @@ ipfw_send_pkt(struct mbuf *replyto, stru h->ip_hl = sizeof(*h) >> 2; h->ip_tos = IPTOS_LOWDELAY; h->ip_off = 0; +#ifdef HAVE_NET_IPLEN + h->ip_len = htons(len); +#else h->ip_len = len; +#endif h->ip_ttl = V_ip_defttl; h->ip_sum = 0; break; Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Thu Dec 24 18:41:14 2009 (r200956) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Thu Dec 24 18:50:58 2009 (r200957) @@ -158,18 +158,22 @@ ipfw_log(struct ip_fw *f, u_int hlen, st * more info in the header */ mh.mh_data = "DDDDDDSSSSSS\x08\x00"; +#ifndef HAVE_NET_IPLEN if (args->f_id.addr_type == 4) { /* restore wire format */ ip->ip_off = ntohs(ip->ip_off); ip->ip_len = ntohs(ip->ip_len); } +#endif /* !HAVE_NET_IPLEN */ } BPF_MTAP(log_if, (struct mbuf *)&mh); +#ifndef HAVE_NET_IPLEN if (args->eh == NULL && args->f_id.addr_type == 4) { /* restore host format */ ip->ip_off = htons(ip->ip_off); ip->ip_len = htons(ip->ip_len); } +#endif /* !HAVE_NET_IPLEN */ return; } /* the old 'log' function */ @@ -404,10 +408,13 @@ ipfw_log(struct ip_fw *f, u_int hlen, st #endif { int ip_off, ip_len; +#ifndef HAVE_NET_IPLEN if (eh != NULL) { /* layer 2 packets are as on the wire */ ip_off = ntohs(ip->ip_off); ip_len = ntohs(ip->ip_len); - } else { + } else +#endif /* !HAVE_NET_IPLEN */ + { ip_off = ip->ip_off; ip_len = ip->ip_len; } Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c Thu Dec 24 18:41:14 2009 (r200956) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c Thu Dec 24 18:50:58 2009 (r200957) @@ -222,10 +222,12 @@ ipfw_nat(struct ip_fw_args *args, struct return (IP_FW_DENY); } ip = mtod(mcl, struct ip *); +#ifndef HAVE_NET_IPLEN if (args->eh == NULL) { ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); } +#endif /* !HAVE_NET_IPLEN */ /* * XXX - Libalias checksum offload 'duct tape': @@ -335,12 +337,12 @@ ipfw_nat(struct ip_fw_args *args, struct } ip->ip_len = htons(ip->ip_len); } - +#ifndef HAVE_NET_IPLEN if (args->eh == NULL) { ip->ip_len = ntohs(ip->ip_len); ip->ip_off = ntohs(ip->ip_off); } - +#endif /* !HAVE_NET_IPLEN */ args->m = mcl; return (IP_FW_NAT); } Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Thu Dec 24 18:41:14 2009 (r200956) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Thu Dec 24 18:50:58 2009 (r200957) @@ -425,8 +425,10 @@ ipfw_divert(struct mbuf **m, int incomin if (reass != NULL) { ip = mtod(reass, struct ip *); hlen = ip->ip_hl << 2; +#ifndef HAVE_NET_IPLEN ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); +#endif /* !HAVE_NET_IPLEN */ ip->ip_sum = 0; if (hlen == sizeof(struct ip)) ip->ip_sum = in_cksum_hdr(ip); @@ -436,9 +438,11 @@ ipfw_divert(struct mbuf **m, int incomin } else clone = NULL; } else { +#ifndef HAVE_NET_IPLEN /* Convert header to network byte order. */ ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); +#endif /* !HAVE_NET_IPLEN */ } /* Do the dirty job... */ From owner-svn-src-user@FreeBSD.ORG Thu Dec 24 19:06:13 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 93CC41065676; Thu, 24 Dec 2009 19:06:13 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6A2748FC18; Thu, 24 Dec 2009 19:06:13 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBOJ6DMR038722; Thu, 24 Dec 2009 19:06:13 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBOJ6Dp9038720; Thu, 24 Dec 2009 19:06:13 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912241906.nBOJ6Dp9038720@svn.freebsd.org> From: Luigi Rizzo Date: Thu, 24 Dec 2009 19:06:13 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200959 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 19:06:13 -0000 Author: luigi Date: Thu Dec 24 19:06:13 2009 New Revision: 200959 URL: http://svn.freebsd.org/changeset/base/200959 Log: better form of endiannes adaptation Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Thu Dec 24 18:50:59 2009 (r200958) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Thu Dec 24 19:06:13 2009 (r200959) @@ -606,11 +606,12 @@ send_reject(struct ip_fw_args *args, int #endif if (code != ICMP_REJECT_RST) { /* Send an ICMP unreach */ /* We need the IP header in host order for icmp_error(). */ - if (args->eh != NULL) { #ifndef HAVE_NET_IPLEN + if (args->eh != NULL) +#endif /* !HAVE_NET_IPLEN */ + { ip->ip_len = ntohs(ip->ip_len); ip->ip_off = ntohs(ip->ip_off); -#endif /* !HAVE_NET_IPLEN */ } icmp_error(args->m, ICMP_UNREACH, code, 0L, 0); } else if (args->f_id.proto == IPPROTO_TCP) { @@ -1097,14 +1098,14 @@ do { \ src_ip = ip->ip_src; dst_ip = ip->ip_dst; #ifndef HAVE_NET_IPLEN - if (args->eh != NULL) { /* layer 2 packets are as on the wire */ - offset = ntohs(ip->ip_off) & IP_OFFMASK; - ip_len = ntohs(ip->ip_len); - } else -#endif /* !HAVE_NET_IPLEN */ - { + if (args->eh == NULL) { /* on l3 these are in host format */ offset = ip->ip_off & IP_OFFMASK; ip_len = ip->ip_len; + } else +#endif /* !HAVE_NET_IPLEN */ + { /* otherwise they are in net format */ + offset = ntohs(ip->ip_off) & IP_OFFMASK; + ip_len = ntohs(ip->ip_len); } pktlen = ip_len < pktlen ? ip_len : pktlen; @@ -2166,10 +2167,13 @@ do { \ ip = mtod(m, struct ip *); hlen = ip->ip_hl << 2; #ifndef HAVE_NET_IPLEN - /* revert len & off for layer2 pkts */ + /* revert len. & off to net format if needed */ if (args->eh != NULL) - ip->ip_len = htons(ip->ip_len); #endif /* !HAVE_NET_IPLEN */ + { + ip->ip_len = htons(ip->ip_len); + ip->ip_off = htons(ip->ip_off); + } ip->ip_sum = 0; if (hlen == sizeof(struct ip)) ip->ip_sum = in_cksum_hdr(ip); From owner-svn-src-user@FreeBSD.ORG Thu Dec 24 23:26:03 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3D5E4106566C; Thu, 24 Dec 2009 23:26:03 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2C7F68FC16; Thu, 24 Dec 2009 23:26:03 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBONQ3ia044078; Thu, 24 Dec 2009 23:26:03 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBONQ3c6044076; Thu, 24 Dec 2009 23:26:03 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200912242326.nBONQ3c6044076@svn.freebsd.org> From: Kip Macy Date: Thu, 24 Dec 2009 23:26:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200970 - user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 23:26:03 -0000 Author: kmacy Date: Thu Dec 24 23:26:02 2009 New Revision: 200970 URL: http://svn.freebsd.org/changeset/base/200970 Log: - replace page validation with vm_pages_valid_locked - move vm_pages_valid up before first use - remove stale comment Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Modified: user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c ============================================================================== --- user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Thu Dec 24 21:54:44 2009 (r200969) +++ user/kmacy/releng_8_fcs_buf_xen/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_bio.c Thu Dec 24 23:26:02 2009 (r200970) @@ -244,6 +244,35 @@ zio_spa_state_alloc(spa_t *spa) return (zss); } +/* + * scan blkno + size range in object to verify that all the pages are + * resident and valid + */ +static int +vm_pages_valid_locked(vm_object_t object, uint64_t blkno, uint64_t size) +{ + vm_page_t m; + uint64_t i; + + for (i = stob(blkno); i < stob(blkno) + size; i += PAGE_SIZE) + if ((m = vm_page_lookup(object, OFF_TO_IDX(i))) == NULL || + (m->valid != VM_PAGE_BITS_ALL)) + return (0); + return (1); +} + +static int +vm_pages_valid(vm_object_t object, uint64_t blkno, uint64_t size) +{ + int valid; + + VM_OBJECT_LOCK(object); + valid = vm_pages_valid_locked(object, blkno, size); + VM_OBJECT_UNLOCK(object); + + return (valid); +} + /* * zio_buf_insert: [ internal use only ] @@ -322,7 +351,6 @@ zio_buf_va_remove(caddr_t va, uint64_t s lock = BUF_HASH_LOCK(idx); bh = &buf_hash_table.ht_table[idx]; - CTR3(KTR_SPARE3, "va_remove(va=%p size=%ld) idx=%ld", va, (long)size, idx); mtx_lock(lock); TAILQ_FOREACH(bp, bh, b_freelist) @@ -525,15 +553,9 @@ zio_buf_vm_object_copy(vm_object_t objec end = OFF_TO_IDX(byte_offset + bp->b_bcount); VM_OBJECT_LOCK(object); - for (bp->b_npages = i = 0; start + i < end; i++) { - m = vm_page_lookup(object, start + i); - - if ((m == NULL) || (m->valid != VM_PAGE_BITS_ALL)) - goto done; + if (vm_pages_valid_locked(object, bp->b_blkno, bp->b_bcount) == 0) + goto done; - bp->b_pages[i] = m; - bp->b_npages++; - } for (i = 0; i < bp->b_npages; i++) { sf = sf_buf_alloc(bp->b_pages[i], 0); va = (caddr_t)sf_buf_kva(sf); @@ -685,8 +707,8 @@ zio_buf_evict_overlap(vm_object_t object zio_buf_blkno_remove(tmpbp); } done: - if (!(collisions == 1 && tmpbp->b_blkno == blkno && tmpbp->b_bcount == size) - && (evict_op == ZB_EVICT_ALL)) { + if (!(collisions == 1 && tmpbp->b_blkno == blkno && + tmpbp->b_bcount == size) && (evict_op == ZB_EVICT_ALL)) { start = OFF_TO_IDX(stob(blkno)); end = start + OFF_TO_IDX(size); VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); @@ -702,37 +724,6 @@ done: } /* - * scan blkno + size range in object to verify that all the pages are - * resident and valid - */ -static int -vm_pages_valid_locked(vm_object_t object, uint64_t blkno, uint64_t size) -{ - vm_pindex_t start; - vm_page_t m; - int i; - - start = OFF_TO_IDX(stob(blkno)); - for (i = 0; i < OFF_TO_IDX(size); i++) - if ((m = vm_page_lookup(object, start + i)) == NULL || - (m->valid != VM_PAGE_BITS_ALL)) - return (0); - return (1); -} - -static int -vm_pages_valid(vm_object_t object, uint64_t blkno, uint64_t size) -{ - int valid; - - VM_OBJECT_LOCK(object); - valid = vm_pages_valid_locked(object, blkno, size); - VM_OBJECT_UNLOCK(object); - - return (valid); -} - -/* * insert pages from object in to bp's b_pages * and wire */ @@ -894,11 +885,6 @@ _zio_sync_cache(spa_t *spa, blkptr_t *bl if (zio_op == ZIO_TYPE_READ && (bp->b_flags & (B_CACHE|B_INVAL)) == B_CACHE) io_bypass = TRUE; } else if ((zio_op == ZIO_TYPE_WRITE) || !vm_pages_valid(object, blkno, size)) { - /* - * XXX still need to handle the case where the pages in the page cache are valid - * and we are doing a read - */ - VM_OBJECT_LOCK(object); zio_buf_evict_overlap(object, blkno, size, state, NO_TXG, ZB_EVICT_ALL); From owner-svn-src-user@FreeBSD.ORG Thu Dec 24 23:54:58 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B567B1065672; Thu, 24 Dec 2009 23:54:58 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A54978FC27; Thu, 24 Dec 2009 23:54:58 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBONsw30044589; Thu, 24 Dec 2009 23:54:58 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBONswDV044585; Thu, 24 Dec 2009 23:54:58 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912242354.nBONswDV044585@svn.freebsd.org> From: Luigi Rizzo Date: Thu, 24 Dec 2009 23:54:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200971 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Dec 2009 23:54:58 -0000 Author: luigi Date: Thu Dec 24 23:54:58 2009 New Revision: 200971 URL: http://svn.freebsd.org/changeset/base/200971 Log: more corrections on HAVE_NET_IPLEN Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Thu Dec 24 23:26:02 2009 (r200970) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Thu Dec 24 23:54:58 2009 (r200971) @@ -994,7 +994,7 @@ dummynet_send(struct mbuf *m) #ifndef HAVE_NET_IPLEN ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); -#endif +#endif /* !HAVE_NET_IPLEN */ netisr_dispatch(NETISR_IP, m); break; #ifdef INET6 Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Thu Dec 24 23:26:02 2009 (r200970) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Thu Dec 24 23:54:58 2009 (r200971) @@ -605,14 +605,13 @@ send_reject(struct ip_fw_args *args, int m_adj(m, args->L3offset); #endif if (code != ICMP_REJECT_RST) { /* Send an ICMP unreach */ - /* We need the IP header in host order for icmp_error(). */ #ifndef HAVE_NET_IPLEN - if (args->eh != NULL) -#endif /* !HAVE_NET_IPLEN */ - { + /* We need the IP header in host order for icmp_error(). */ + if (args->eh != NULL) { ip->ip_len = ntohs(ip->ip_len); ip->ip_off = ntohs(ip->ip_off); } +#endif /* !HAVE_NET_IPLEN */ icmp_error(args->m, ICMP_UNREACH, code, 0L, 0); } else if (args->f_id.proto == IPPROTO_TCP) { struct tcphdr *const tcp = @@ -2140,12 +2139,12 @@ do { \ /* if not fragmented, go to next rule */ if ((ip_off & (IP_MF | IP_OFFMASK)) == 0) break; +#ifndef HAVE_NET_IPLEN /* * ip_reass() expects len & off in host * byte order: fix them in case we come * from layer2. */ -#ifndef HAVE_NET_IPLEN if (args->eh != NULL) { ip->ip_len = ntohs(ip->ip_len); ip->ip_off = ntohs(ip->ip_off); @@ -2168,12 +2167,11 @@ do { \ hlen = ip->ip_hl << 2; #ifndef HAVE_NET_IPLEN /* revert len. & off to net format if needed */ - if (args->eh != NULL) -#endif /* !HAVE_NET_IPLEN */ - { + if (args->eh != NULL) { ip->ip_len = htons(ip->ip_len); ip->ip_off = htons(ip->ip_off); } +#endif /* !HAVE_NET_IPLEN */ ip->ip_sum = 0; if (hlen == sizeof(struct ip)) ip->ip_sum = in_cksum_hdr(ip); Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Thu Dec 24 23:26:02 2009 (r200970) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Thu Dec 24 23:54:58 2009 (r200971) @@ -409,14 +409,14 @@ ipfw_log(struct ip_fw *f, u_int hlen, st { int ip_off, ip_len; #ifndef HAVE_NET_IPLEN - if (eh != NULL) { /* layer 2 packets are as on the wire */ - ip_off = ntohs(ip->ip_off); - ip_len = ntohs(ip->ip_len); + if (eh == NULL) { + ip_off = ip->ip_off; + ip_len = ip->ip_len; } else #endif /* !HAVE_NET_IPLEN */ { - ip_off = ip->ip_off; - ip_len = ip->ip_len; + ip_off = ntohs(ip->ip_off); + ip_len = ntohs(ip->ip_len); } if (ip_off & (IP_MF | IP_OFFMASK)) snprintf(SNPARGS(fragment, 0), From owner-svn-src-user@FreeBSD.ORG Fri Dec 25 00:37:30 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 551D8106566C; Fri, 25 Dec 2009 00:37:30 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2BB938FC17; Fri, 25 Dec 2009 00:37:30 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBP0bUDi045511; Fri, 25 Dec 2009 00:37:30 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBP0bU8b045509; Fri, 25 Dec 2009 00:37:30 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912250037.nBP0bU8b045509@svn.freebsd.org> From: Luigi Rizzo Date: Fri, 25 Dec 2009 00:37:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200973 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2009 00:37:30 -0000 Author: luigi Date: Fri Dec 25 00:37:29 2009 New Revision: 200973 URL: http://svn.freebsd.org/changeset/base/200973 Log: document the assumption on the layout of addr and mask in the table code, and use a couple of macros to make sure the assumptions hold. Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_table.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_table.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_table.c Fri Dec 25 00:23:47 2009 (r200972) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_table.c Fri Dec 25 00:37:29 2009 (r200973) @@ -79,6 +79,18 @@ struct table_entry { u_int32_t value; }; +/* + * The radix code expects addr and mask to be array of bytes, + * with the first byte being the length of the array. rn_inithead + * is called with the offset in bits of the lookup key within the + * array. If we use a sockaddr_in as the underlying type, + * sin_len is conveniently located at offset 0, sin_addr is at + * offset 4 and normally aligned. + * But for portability, let's avoid assumption and make the code explicit + */ +#define KEY_LEN(v) *((uint8_t *)&(v)) +#define KEY_OFS (8*offsetof(struct sockaddr_in, sin_addr)) + int ipfw_add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr, uint8_t mlen, uint32_t value) @@ -94,7 +106,7 @@ ipfw_add_table_entry(struct ip_fw_chain if (ent == NULL) return (ENOMEM); ent->value = value; - ent->addr.sin_len = ent->mask.sin_len = 8; + KEY_LEN(ent->addr) = KEY_LEN(ent->mask) = 8; ent->mask.sin_addr.s_addr = htonl(mlen ? ~((1 << (32 - mlen)) - 1) : 0); ent->addr.sin_addr.s_addr = addr & ent->mask.sin_addr.s_addr; IPFW_WLOCK(ch); @@ -119,7 +131,7 @@ ipfw_del_table_entry(struct ip_fw_chain if (tbl >= IPFW_TABLES_MAX) return (EINVAL); rnh = ch->tables[tbl]; - sa.sin_len = mask.sin_len = 8; + KEY_LEN(sa) = KEY_LEN(mask) = 8; mask.sin_addr.s_addr = htonl(mlen ? ~((1 << (32 - mlen)) - 1) : 0); sa.sin_addr.s_addr = addr & mask.sin_addr.s_addr; IPFW_WLOCK(ch); @@ -179,7 +191,7 @@ ipfw_init_tables(struct ip_fw_chain *ch) uint16_t j; for (i = 0; i < IPFW_TABLES_MAX; i++) { - if (!rn_inithead((void **)&ch->tables[i], 32)) { + if (!rn_inithead((void **)&ch->tables[i], KEY_OFS)) { for (j = 0; j < i; j++) { (void) ipfw_flush_table(ch, j); } @@ -200,7 +212,7 @@ ipfw_lookup_table(struct ip_fw_chain *ch if (tbl >= IPFW_TABLES_MAX) return (0); rnh = ch->tables[tbl]; - sa.sin_len = 8; + KEY_LEN(sa) = 8; sa.sin_addr.s_addr = addr; ent = (struct table_entry *)(rnh->rnh_lookup(&sa, NULL, rnh)); if (ent != NULL) { From owner-svn-src-user@FreeBSD.ORG Fri Dec 25 00:45:38 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BDE0D10656A4; Fri, 25 Dec 2009 00:45:38 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id A1F738FC1F; Fri, 25 Dec 2009 00:45:38 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBP0jcdW045795; Fri, 25 Dec 2009 00:45:38 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBP0jcAc045793; Fri, 25 Dec 2009 00:45:38 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912250045.nBP0jcAc045793@svn.freebsd.org> From: Luigi Rizzo Date: Fri, 25 Dec 2009 00:45:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200974 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2009 00:45:38 -0000 Author: luigi Date: Fri Dec 25 00:45:38 2009 New Revision: 200974 URL: http://svn.freebsd.org/changeset/base/200974 Log: remove a useless local variable Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Fri Dec 25 00:37:29 2009 (r200973) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Fri Dec 25 00:45:38 2009 (r200974) @@ -138,7 +138,6 @@ ipfw_log(struct ip_fw *f, u_int hlen, st struct mbuf *m, struct ifnet *oif, u_short offset, uint32_t tablearg, struct ip *ip) { - struct ether_header *eh = args->eh; char *action; int limit_reached = 0; char action2[40], proto[128], fragment[32]; @@ -409,7 +408,7 @@ ipfw_log(struct ip_fw *f, u_int hlen, st { int ip_off, ip_len; #ifndef HAVE_NET_IPLEN - if (eh == NULL) { + if (args->eh == NULL) { ip_off = ip->ip_off; ip_len = ip->ip_len; } else From owner-svn-src-user@FreeBSD.ORG Fri Dec 25 01:15:41 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 5B1181065679; Fri, 25 Dec 2009 01:15:41 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id B988C8FC14; Fri, 25 Dec 2009 01:15:39 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBP1Fd9w046395; Fri, 25 Dec 2009 01:15:39 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBP1FdGP046393; Fri, 25 Dec 2009 01:15:39 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912250115.nBP1FdGP046393@svn.freebsd.org> From: Luigi Rizzo Date: Fri, 25 Dec 2009 01:15:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200975 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2009 01:15:41 -0000 Author: luigi Date: Fri Dec 25 01:15:39 2009 New Revision: 200975 URL: http://svn.freebsd.org/changeset/base/200975 Log: remove some headers that seem to be unnecessary Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c Fri Dec 25 00:45:38 2009 (r200974) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_nat.c Fri Dec 25 01:15:39 2009 (r200975) @@ -29,14 +29,11 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include #include #include -#include -#include #include #define IPFW_INTERNAL /* Access to protected data structures in ip_fw.h. */ From owner-svn-src-user@FreeBSD.ORG Fri Dec 25 11:41:05 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 37D641065692; Fri, 25 Dec 2009 11:41:05 +0000 (UTC) (envelope-from edwin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2709A8FC13; Fri, 25 Dec 2009 11:41:05 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBPBf51n060234; Fri, 25 Dec 2009 11:41:05 GMT (envelope-from edwin@svn.freebsd.org) Received: (from edwin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBPBf4Tw060225; Fri, 25 Dec 2009 11:41:04 GMT (envelope-from edwin@svn.freebsd.org) Message-Id: <200912251141.nBPBf4Tw060225@svn.freebsd.org> From: Edwin Groothuis Date: Fri, 25 Dec 2009 11:41:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200984 - user/edwin/calendar X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2009 11:41:05 -0000 Author: edwin Date: Fri Dec 25 11:41:04 2009 New Revision: 200984 URL: http://svn.freebsd.org/changeset/base/200984 Log: Intermittent commit: - Fix the handling of the years (leapyear / nonleapyear, span over multiple years) in Paskha and Easter handling. - Add code to properly handle absurd long intervals. Added: user/edwin/calendar/dates.c Modified: user/edwin/calendar/Makefile user/edwin/calendar/calendar.c user/edwin/calendar/calendar.h user/edwin/calendar/day.c user/edwin/calendar/events.c user/edwin/calendar/ostern.c user/edwin/calendar/paskha.c Modified: user/edwin/calendar/Makefile ============================================================================== --- user/edwin/calendar/Makefile Fri Dec 25 11:12:05 2009 (r200983) +++ user/edwin/calendar/Makefile Fri Dec 25 11:41:04 2009 (r200984) @@ -4,7 +4,8 @@ CFLAGS= -pipe -g -std=gnu99 -fstack-protector -Wall PROG= calendar -SRCS= calendar.c locale.c events.c parsedata.c io.c day.c ostern.c paskha.c +SRCS= calendar.c locale.c events.c dates.c parsedata.c io.c day.c \ + ostern.c paskha.c INTER= de_AT.ISO_8859-15 de_DE.ISO8859-1 fr_FR.ISO8859-1 \ hr_HR.ISO8859-2 hu_HU.ISO8859-2 ru_RU.KOI8-R uk_UA.KOI8-U DE_LINKS= de_DE.ISO8859-15 Modified: user/edwin/calendar/calendar.c ============================================================================== --- user/edwin/calendar/calendar.c Fri Dec 25 11:12:05 2009 (r200983) +++ user/edwin/calendar/calendar.c Fri Dec 25 11:41:04 2009 (r200984) @@ -129,7 +129,9 @@ main(int argc, char *argv[]) if (f_time <= 0) (void)time(&f_time); - settimes(f_time, f_dayBefore, f_dayAfter); + settimes(f_time, f_dayBefore, f_dayAfter, &tp1, &tp2); + generatedates(&tp1, &tp2); + dumpdates(); if (doall) while ((pw = getpwent()) != NULL) { Modified: user/edwin/calendar/calendar.h ============================================================================== --- user/edwin/calendar/calendar.h Fri Dec 25 11:12:05 2009 (r200983) +++ user/edwin/calendar/calendar.h Fri Dec 25 11:41:04 2009 (r200984) @@ -46,7 +46,6 @@ extern struct iovec header[]; extern struct tm tp1, tp2; extern time_t t1, t2; extern const char *calendarFile; -extern int *cumdays; extern int yrdays; extern struct fixs neaster, npaskha, ncny; @@ -114,7 +113,8 @@ extern const char *fdays[]; void setnnames(void); /* day.c */ -void settimes(time_t,int, int); +extern const struct tm tm0; +void settimes(time_t,int, int, struct tm *tp1, struct tm *tp2); time_t Mktime(char *); /* parsedata.c */ @@ -126,7 +126,10 @@ void closecal(FILE *); FILE *opencal(void); /* ostern.c / pashka.c */ -int geteaster(char *, int); -int getpaskha(char *, int); +int paskha(int); int easter(int); +/* dates.c */ +extern int cumdaytab[][14]; +void generatedates(struct tm *tp1, struct tm *tp2); +void dumpdates(void); Added: user/edwin/calendar/dates.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/edwin/calendar/dates.c Fri Dec 25 11:41:04 2009 (r200984) @@ -0,0 +1,226 @@ +#include +#include +#include +#include + +#include "calendar.h" + +struct cal_year { + int year; /* 19xx, 20xx, 21xx */ + int easter; /* Julian day */ + int paskha; /* Julian day */ + int cny; /* Julian day */ + int firstdayofweek; /* 0 .. 6 */ + struct cal_month *months; + struct cal_year *nextyear; +} cal_year; + +struct cal_month { + int month; /* 01 .. 12 */ + int firstdayjulian; /* 000 .. 366 */ + int firstdayofweek; /* 0 .. 6 */ + struct cal_year *year; /* points back */ + struct cal_day *days; + struct cal_month *nextmonth; +} cal_month; + +struct cal_day { + int dayofmonth; /* 01 .. 31 */ + int julianday; /* 000 .. 366 */ + int dayofweek; /* 0 .. 6 */ + struct cal_day *nextday; + struct cal_month *month; + struct cal_year *year; + struct event *events; +} cal_day; + +struct cal_year *hyear = NULL; + +/* 1-based month, 0-based days, cumulative */ +int *cumdays; +int cumdaytab[][14] = { + {0, -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364}, + {0, -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, +}; +/* 1-based month, individual */ +int *mondays; +int mondaytab[][14] = { + {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30}, + {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 30}, +}; + +static void +createdate(int y, int m, int d) +{ + struct cal_year *py, *pyp; + struct cal_month *pm, *pmp; + struct cal_day *pd, *pdp; + int *cumday; + + pyp = NULL; + py = hyear; + while (py != NULL) { + if (py->year == y + 1900) + break; + pyp = py; + py = py->nextyear; + } + + if (py == NULL) { + struct tm td; + time_t t; + py = (struct cal_year *)calloc(1, sizeof(struct cal_year)); + py->year = y + 1900; + py->easter = easter(y); + py->paskha = paskha(y); + + td = tm0; + td.tm_year = y; + td.tm_mday = 1; + t = mktime(&td); + localtime_r(&t, &td); + py->firstdayofweek = td.tm_wday; + + if (pyp != NULL) + pyp->nextyear = py; + } + if (pyp == NULL) { + /* The very very very first one */ + hyear = py; + } + + pmp = NULL; + pm = py->months; + while (pm != NULL) { + if (pm->month == m) + break; + pmp = pm; + pm = pm->nextmonth; + } + + if (pm == NULL) { + pm = (struct cal_month *)calloc(1, sizeof(struct cal_month)); + pm->year = py; + pm->month = m; + cumday = cumdaytab[isleap(y)]; + pm->firstdayjulian = cumday[m] + 2; + pm->firstdayofweek = + (py->firstdayofweek + pm->firstdayjulian -1) % 7; + if (pmp != NULL) + pmp->nextmonth = pm; + } + if (pmp == NULL) + py->months = pm; + + pdp = NULL; + pd = pm->days; + while (pd != NULL) { + pdp = pd; + pd = pd->nextday; + } + + if (pd == NULL) { /* Always true */ + pd = (struct cal_day *)calloc(1, sizeof(struct cal_day)); + pd->month = pm; + pd->year = py; + pd->dayofmonth = d; + pd->julianday = pm->firstdayjulian + d - 1; + pd->dayofweek = (pm->firstdayofweek + d - 1) % 7; + if (pdp != NULL) + pdp->nextday = pd; + } + if (pdp == NULL) + pm->days = pd; +} + +void +generatedates(struct tm *tp1, struct tm *tp2) +{ + int y1, m1, d1; + int y2, m2, d2; + int y, m, d; + int *mondays; + + y1 = tp1->tm_year; + m1 = tp1->tm_mon + 1; + d1 = tp1->tm_mday; + y2 = tp2->tm_year; + m2 = tp2->tm_mon + 1; + d2 = tp2->tm_mday; + + if (y1 == y2) { + if (m1 == m2) { + /* Same year, same month. Easy! */ + for (d = d1; d <= d2; d++) + createdate(y1, m1, d); + return; + } + /* + * Same year, different month. + * - Take the leftover days from m1 + * - Take all days from + * - Take the first days from m2 + */ + mondays = mondaytab[isleap(y1)]; + for (d = d1; d <= mondays[m1]; d++) + createdate(y1, m1, d); + for (m = m1 + 1; m < m2; m++) + for (d = 1; d <= mondays[m]; d++) + createdate(y1, m, d); + for (d = 1; d <= d2; d++) + createdate(y1, m2, d); + return; + } + /* + * Different year, different month. + * - Take the leftover days from y1-m1 + * - Take all days from y1- + * - Take all days from y2-[1 .. m2> + * - Take the first days of y2-m2 + */ + mondays = mondaytab[isleap(y1)]; + for (d = d1; d <= mondays[m1]; d++) + createdate(y1, m1, d); + for (m = m1 + 1; m <= 12; m++) + for (d = 1; d <= mondays[m]; d++) + createdate(y1, m, d); + for (y = y1 + 1; y < y2; y++) { + mondays = mondaytab[isleap(y)]; + for (m = 1; m <= 12; m++) + for (d = 1; d <= mondays[m]; d++) + createdate(y, m, d); + } + mondays = mondaytab[isleap(y2)]; + for (m = 1; m < m2; m++) + for (d = 1; d <= mondays[m]; d++) + createdate(y2, m, d); + for (d = 1; d <= d2; d++) + createdate(y2, m2, d); +} + +void +dumpdates(void) +{ + struct cal_year *y; + struct cal_month *m; + struct cal_day *d; + + y = hyear; + while (y != NULL) { + printf("%-5d (wday:%d)\n", y->year, y->firstdayofweek); + m = y->months; + while (m != NULL) { + printf("-- %-5d (julian:%d, dow:%d)\n", m->month, + m->firstdayjulian, m->firstdayofweek); + d = m->days; + while (d != NULL) { + printf(" -- %-5d (julian:%d, dow:%d)\n", + d->dayofmonth, d->julianday, d->dayofweek); + d = d->nextday; + } + m = m->nextmonth; + } + y = y->nextyear; + } +} Modified: user/edwin/calendar/day.c ============================================================================== --- user/edwin/calendar/day.c Fri Dec 25 11:12:05 2009 (r200983) +++ user/edwin/calendar/day.c Fri Dec 25 11:41:04 2009 (r200984) @@ -45,40 +45,26 @@ __FBSDID("$FreeBSD$"); struct tm tp1, tp2; time_t time1, time2; -static const struct tm tm0; -int *cumdays, yrdays; +const struct tm tm0; char dayname[10]; -/* 1-based month, 0-based days, cumulative */ -int daytab[][14] = { - {0, -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364}, - {0, -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}, -}; - - void -settimes(time_t now, int before, int after) +settimes(time_t now, int before, int after, struct tm *tp1, struct tm *tp2) { char *oldl, *lbufp; struct tm tp; localtime_r(&now, &tp); - if (isleap(tp.tm_year + 1900)) { - yrdays = 366; - cumdays = daytab[1]; - } else { - yrdays = 365; - cumdays = daytab[0]; - } + /* Friday displays Monday's events */ if (f_dayAfter == 0 && f_dayBefore == 0 && Friday != -1) f_dayAfter = tp.tm_wday == Friday ? 3 : 1; time1 = now - SECSPERDAY * f_dayBefore; - localtime_r(&time1, &tp1); + localtime_r(&time1, tp1); time2 = now + SECSPERDAY * f_dayAfter; - localtime_r(&time2, &tp2); + localtime_r(&time2, tp2); header[5].iov_base = dayname; Modified: user/edwin/calendar/events.c ============================================================================== --- user/edwin/calendar/events.c Fri Dec 25 11:12:05 2009 (r200983) +++ user/edwin/calendar/events.c Fri Dec 25 11:41:04 2009 (r200984) @@ -120,23 +120,23 @@ event_print_all(FILE *fp, struct event * for (daycounter = 0; daycounter <= f_dayAfter + f_dayBefore; daycounter++) { day = tp1.tm_yday - f_dayBefore + daycounter; - if (day < 0) - day += yrdays; - if (day >= yrdays) - day -= yrdays; +// if (day < 0) +// day += yrdays; +// if (day >= yrdays) +// day -= yrdays; /* * When we know the day of the year, we can determine the day * of the month and the month. */ - month = 1; - while (month <= 12) { - if (day <= cumdays[month]) - break; - month++; - } - month--; - day -= cumdays[month]; +// month = 1; +// while (month <= 12) { +// if (day <= cumdays[month]) +// break; +// month++; +// } +// month--; +// day -= cumdays[month]; #ifdef DEBUG fprintf(stderr, "event_print_allmonth: %d, day: %d\n", Modified: user/edwin/calendar/ostern.c ============================================================================== --- user/edwin/calendar/ostern.c Fri Dec 25 11:12:05 2009 (r200983) +++ user/edwin/calendar/ostern.c Fri Dec 25 11:41:04 2009 (r200984) @@ -60,7 +60,7 @@ easter(int year) /* 0 ... abcd, NOT sinc L = I - J; - if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) + if (isleap(year)) return 31 + 29 + 21 + L + 7; else return 31 + 28 + 21 + L + 7; Modified: user/edwin/calendar/paskha.c ============================================================================== --- user/edwin/calendar/paskha.c Fri Dec 25 11:12:05 2009 (r200983) +++ user/edwin/calendar/paskha.c Fri Dec 25 11:41:04 2009 (r200984) @@ -36,24 +36,24 @@ __FBSDID("$FreeBSD$"); #define PASKHA "paskha" #define PASKHALEN (sizeof(PASKHA) - 1) -static int paskha(int); - /* return year day for Orthodox Easter using Gauss formula */ /* (old style result) */ -static int +int paskha(int R) /*year*/ { int a, b, c, d, e; static int x = 15; static int y = 6; + int *cumday; a = R % 19; b = R % 4; c = R % 7; d = (19 * a + x) % 30; e = (2 * b + 4 * c + 6 * d + y) % 7; - return (((cumdays[3] + 1) + 22) + (d + e)); + cumday = cumdaytab[isleap(R)]; + return (((cumday[3] + 1) + 22) + (d + e)); } /* return year day for Orthodox Easter depending days */ From owner-svn-src-user@FreeBSD.ORG Fri Dec 25 14:59:11 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 01E1D1065692; Fri, 25 Dec 2009 14:59:11 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id E53928FC16; Fri, 25 Dec 2009 14:59:10 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBPExApr064070; Fri, 25 Dec 2009 14:59:10 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBPExAqu064068; Fri, 25 Dec 2009 14:59:10 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912251459.nBPExAqu064068@svn.freebsd.org> From: Luigi Rizzo Date: Fri, 25 Dec 2009 14:59:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200985 - user/luigi/ipfw3-head/sys/netinet X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2009 14:59:11 -0000 Author: luigi Date: Fri Dec 25 14:59:10 2009 New Revision: 200985 URL: http://svn.freebsd.org/changeset/base/200985 Log: remove an unused function Modified: user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h Modified: user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h Fri Dec 25 11:41:04 2009 (r200984) +++ user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h Fri Dec 25 14:59:10 2009 (r200985) @@ -377,21 +377,4 @@ struct dn_pipe_max { SLIST_HEAD(dn_pipe_head, dn_pipe); -#ifdef _KERNEL - -/* - * Return the dummynet tag; if any. - * Make sure that the dummynet tag is not reused by lower layers. - */ -static __inline struct dn_pkt_tag * -ip_dn_claim_tag(struct mbuf *m) -{ - struct m_tag *mtag = m_tag_find(m, PACKET_TAG_DUMMYNET, NULL); - if (mtag != NULL) { - mtag->m_tag_id = PACKET_TAG_NONE; - return ((struct dn_pkt_tag *)(mtag + 1)); - } else - return (NULL); -} -#endif #endif /* _IP_DUMMYNET_H */ From owner-svn-src-user@FreeBSD.ORG Fri Dec 25 14:59:55 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2D56B1065670; Fri, 25 Dec 2009 14:59:55 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1CAC08FC12; Fri, 25 Dec 2009 14:59:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBPExtrO064115; Fri, 25 Dec 2009 14:59:55 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBPExsDq064113; Fri, 25 Dec 2009 14:59:55 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912251459.nBPExsDq064113@svn.freebsd.org> From: Luigi Rizzo Date: Fri, 25 Dec 2009 14:59:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200986 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2009 14:59:55 -0000 Author: luigi Date: Fri Dec 25 14:59:54 2009 New Revision: 200986 URL: http://svn.freebsd.org/changeset/base/200986 Log: remove unnecessary dependencies. The info from ng_ipfw and dummynet tags is handled in ip_fw_pfil.c, and the same should be done for divert. Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Fri Dec 25 14:59:10 2009 (r200985) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw2.c Fri Dec 25 14:59:54 2009 (r200986) @@ -75,7 +75,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include @@ -83,8 +82,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include - #include #include #ifdef INET6 @@ -1149,6 +1146,7 @@ do { \ IPFW_RUNLOCK(chain); return (IP_FW_PASS); /* accept */ } + /* XXX divert should be handled same as other tags */ mtag = m_tag_find(m, PACKET_TAG_DIVERT, NULL); if (args->slot) { /* From owner-svn-src-user@FreeBSD.ORG Fri Dec 25 16:53:15 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 45935106568F; Fri, 25 Dec 2009 16:53:15 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 340488FC16; Fri, 25 Dec 2009 16:53:15 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBPGrF1f066455; Fri, 25 Dec 2009 16:53:15 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBPGrFBK066452; Fri, 25 Dec 2009 16:53:15 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912251653.nBPGrFBK066452@svn.freebsd.org> From: Luigi Rizzo Date: Fri, 25 Dec 2009 16:53:15 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200989 - user/luigi/ipfw3-head/sys/net X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2009 16:53:15 -0000 Author: luigi Date: Fri Dec 25 16:53:14 2009 New Revision: 200989 URL: http://svn.freebsd.org/changeset/base/200989 Log: expand inline a function removed from the header Modified: user/luigi/ipfw3-head/sys/net/if_bridge.c user/luigi/ipfw3-head/sys/net/if_ethersubr.c Modified: user/luigi/ipfw3-head/sys/net/if_bridge.c ============================================================================== --- user/luigi/ipfw3-head/sys/net/if_bridge.c Fri Dec 25 15:29:18 2009 (r200988) +++ user/luigi/ipfw3-head/sys/net/if_bridge.c Fri Dec 25 16:53:14 2009 (r200989) @@ -3041,13 +3041,17 @@ bridge_pfil(struct mbuf **mp, struct ifn /* XXX this section is also in if_ethersubr.c */ if (V_ip_fw_chk_ptr && pfil_ipfw != 0 && dir == PFIL_OUT && ifp != NULL) { - struct dn_pkt_tag *dn_tag; + struct m_tag *mtag; error = -1; - dn_tag = ip_dn_claim_tag(*mp); - if (dn_tag == NULL) { + mtag = m_tag_find(*mp, PACKET_TAG_DUMMYNET, NULL); + if (mtag == NULL) { args.slot = 0; } else { + struct dn_pkt_tag *dn_tag; + + mtag->m_tag_id = PACKET_TAG_NONE; + dn_tag = (struct dn_pkt_tag *)(mtag + 1); if (dn_tag->slot != 0 && V_fw_one_pass) /* packet already partially processed */ goto ipfwpass; Modified: user/luigi/ipfw3-head/sys/net/if_ethersubr.c ============================================================================== --- user/luigi/ipfw3-head/sys/net/if_ethersubr.c Fri Dec 25 15:29:18 2009 (r200988) +++ user/luigi/ipfw3-head/sys/net/if_ethersubr.c Fri Dec 25 16:53:14 2009 (r200989) @@ -467,13 +467,16 @@ ether_ipfw_chk(struct mbuf **m0, struct struct mbuf *m; int i; struct ip_fw_args args; - struct dn_pkt_tag *dn_tag; + struct m_tag *mtag; - dn_tag = ip_dn_claim_tag(*m0); - - if (dn_tag == NULL) { + mtag = m_tag_find(*m0, PACKET_TAG_DUMMYNET, NULL); + if (mtag == NULL) { args.slot = 0; } else { + struct dn_pkt_tag *dn_tag; + + mtag->m_tag_id = PACKET_TAG_NONE; + dn_tag = (struct dn_pkt_tag *)(mtag + 1); if (dn_tag->slot != 0 && V_fw_one_pass) /* dummynet packet, already partially processed */ return (1); From owner-svn-src-user@FreeBSD.ORG Fri Dec 25 17:05:55 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E719D1065672; Fri, 25 Dec 2009 17:05:55 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D5B558FC08; Fri, 25 Dec 2009 17:05:55 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBPH5t2U066787; Fri, 25 Dec 2009 17:05:55 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBPH5tpW066785; Fri, 25 Dec 2009 17:05:55 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912251705.nBPH5tpW066785@svn.freebsd.org> From: Luigi Rizzo Date: Fri, 25 Dec 2009 17:05:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r200990 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Dec 2009 17:05:56 -0000 Author: luigi Date: Fri Dec 25 17:05:55 2009 New Revision: 200990 URL: http://svn.freebsd.org/changeset/base/200990 Log: make it possible to omit the bpf support Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Fri Dec 25 16:53:14 2009 (r200989) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_log.c Fri Dec 25 17:05:55 2009 (r200990) @@ -87,6 +87,12 @@ __FBSDID("$FreeBSD$"); #define SNPARGS(buf, len) buf + len, sizeof(buf) > len ? sizeof(buf) - len : 0 #define SNP(buf) buf, sizeof(buf) +#ifdef WITHOUT_BPF +void +ipfw_log_bpf(int onoff) +{ +} +#else /* !WITHOUT_BPF */ static struct ifnet *log_if; /* hook to attach to bpf */ /* we use this dummy function for all ifnet callbacks */ @@ -128,6 +134,7 @@ ipfw_log_bpf(int onoff) log_if = NULL; } } +#endif /* !WITHOUT_BPF */ /* * We enter here when we have a rule with O_LOG. @@ -143,6 +150,7 @@ ipfw_log(struct ip_fw *f, u_int hlen, st char action2[40], proto[128], fragment[32]; if (V_fw_verbose == 0) { +#ifndef WITHOUT_BPF struct m_hdr mh; if (log_if == NULL || log_if->if_bpf == NULL) @@ -173,6 +181,7 @@ ipfw_log(struct ip_fw *f, u_int hlen, st ip->ip_len = htons(ip->ip_len); } #endif /* !HAVE_NET_IPLEN */ +#endif /* !WITHOUT_BPF */ return; } /* the old 'log' function */ From owner-svn-src-user@FreeBSD.ORG Sat Dec 26 02:36:49 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 4064E1065672; Sat, 26 Dec 2009 02:36:49 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2EAE98FC1D; Sat, 26 Dec 2009 02:36:49 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBQ2anhk078402; Sat, 26 Dec 2009 02:36:49 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBQ2amC6078392; Sat, 26 Dec 2009 02:36:48 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912260236.nBQ2amC6078392@svn.freebsd.org> From: Luigi Rizzo Date: Sat, 26 Dec 2009 02:36:48 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r201011 - in user/luigi/ipfw3-head/sys: net netgraph netinet netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Dec 2009 02:36:49 -0000 Author: luigi Date: Sat Dec 26 02:36:48 2009 New Revision: 201011 URL: http://svn.freebsd.org/changeset/base/201011 Log: Preparation work to simplify the code used for reinject and ipfilter: - move most of ng_ipfw.h into ip_fw_private.h, as this code is ipfw-specific. This removes a dependency on ng_ipfw.h from some files. - move many equivalent definitions of direction (IN, OUT) for reinjected packets into ip_fw_private.h - document the structure of the packet tags used for dummynet and netgraph; Modified: user/luigi/ipfw3-head/sys/net/if_bridge.c user/luigi/ipfw3-head/sys/net/if_ethersubr.c user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.c user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.h user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Modified: user/luigi/ipfw3-head/sys/net/if_bridge.c ============================================================================== --- user/luigi/ipfw3-head/sys/net/if_bridge.c Sat Dec 26 00:46:05 2009 (r201010) +++ user/luigi/ipfw3-head/sys/net/if_bridge.c Sat Dec 26 02:36:48 2009 (r201011) @@ -3085,7 +3085,7 @@ bridge_pfil(struct mbuf **mp, struct ifn * packet will return to us via bridge_dummynet(). */ args.oif = ifp; - ip_dn_io_ptr(mp, DN_TO_IFB_FWD, &args); + ip_dn_io_ptr(mp, DIR_FWD | PROTO_IFB, &args); return (error); } Modified: user/luigi/ipfw3-head/sys/net/if_ethersubr.c ============================================================================== --- user/luigi/ipfw3-head/sys/net/if_ethersubr.c Sat Dec 26 00:46:05 2009 (r201010) +++ user/luigi/ipfw3-head/sys/net/if_ethersubr.c Sat Dec 26 02:36:48 2009 (r201011) @@ -535,6 +535,7 @@ ether_ipfw_chk(struct mbuf **m0, struct return 1; if (ip_dn_io_ptr && (i == IP_FW_DUMMYNET)) { + int dir; /* * Pass the pkt to dummynet, which consumes it. * If shared, make a copy and keep the original. @@ -550,7 +551,8 @@ ether_ipfw_chk(struct mbuf **m0, struct */ *m0 = NULL ; } - ip_dn_io_ptr(&m, dst ? DN_TO_ETH_OUT: DN_TO_ETH_DEMUX, &args); + dir = PROTO_LAYER2 | (dst ? DIR_OUT : DIR_IN); + ip_dn_io_ptr(&m, dir, &args); return 0; } /* Modified: user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.c ============================================================================== --- user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.c Sat Dec 26 00:46:05 2009 (r201010) +++ user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.c Sat Dec 26 02:36:48 2009 (r201011) @@ -234,7 +234,7 @@ ng_ipfw_rcvdata(hook_p hook, item_p item }; switch (ngit->dir) { - case NG_IPFW_OUT: + case DIR_OUT: { struct ip *ip; @@ -249,7 +249,7 @@ ng_ipfw_rcvdata(hook_p hook, item_p item return ip_output(m, NULL, NULL, IP_FORWARDING, NULL, NULL); } - case NG_IPFW_IN: + case DIR_IN: ip_input(m); return (0); default: @@ -298,7 +298,7 @@ ng_ipfw_input(struct mbuf **m0, int dir, ngit->rule_id = fwa->rule_id; ngit->chain_id = fwa->chain_id; ngit->dir = dir; - ngit->ifp = fwa->oif; +// ngit->ifp = fwa->oif; /* XXX do we use it ? */ m_tag_prepend(m, &ngit->mt); } else Modified: user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.h ============================================================================== --- user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.h Sat Dec 26 00:46:05 2009 (r201010) +++ user/luigi/ipfw3-head/sys/netgraph/ng_ipfw.h Sat Dec 26 02:36:48 2009 (r201011) @@ -26,27 +26,7 @@ * $FreeBSD$ */ +#ifndef _NG_IPFW_H +#define _NG_IPFW_H #define NG_IPFW_NODE_TYPE "ipfw" -#define NGM_IPFW_COOKIE 1105988990 - -#ifdef _KERNEL - -typedef int ng_ipfw_input_t(struct mbuf **, int, struct ip_fw_args *, int); -extern ng_ipfw_input_t *ng_ipfw_input_p; -#define NG_IPFW_LOADED (ng_ipfw_input_p != NULL) - -struct ng_ipfw_tag { - struct m_tag mt; /* tag header */ - uint32_t slot; /* slot for next rule */ - uint32_t rulenum; /* matching rule number */ - uint32_t rule_id; /* matching rule id */ - uint32_t chain_id; /* ruleset id */ - struct ifnet *ifp; /* interface, for ip_output */ - int dir; -#define NG_IPFW_OUT 0 -#define NG_IPFW_IN 1 -}; - -#define TAGSIZ (sizeof(struct ng_ipfw_tag) - sizeof(struct m_tag)) - -#endif /* _KERNEL */ +#endif /* _NG_IPFW_H */ Modified: user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h Sat Dec 26 00:46:05 2009 (r201010) +++ user/luigi/ipfw3-head/sys/netinet/ip_dummynet.h Sat Dec 26 02:36:48 2009 (r201011) @@ -110,21 +110,19 @@ struct dn_heap { * them that carries their dummynet state. This is used within * the dummynet code as well as outside when checking for special * processing requirements. + * Note that the first part is the reinject info and is common to + * other forms of packet reinjection. */ struct dn_pkt_tag { + /* first part, reinject info */ uint32_t slot; /* slot of next rule to use */ uint32_t rulenum; /* matching rule number */ uint32_t rule_id; /* matching rule id */ uint32_t chain_id; /* ruleset id */ + + /* second part, dummynet specific */ int dn_dir; /* action when packet comes out. */ -#define DN_TO_IP_OUT 1 -#define DN_TO_IP_IN 2 -/* Obsolete: #define DN_TO_BDG_FWD 3 */ -#define DN_TO_ETH_DEMUX 4 -#define DN_TO_ETH_OUT 5 -#define DN_TO_IP6_IN 6 -#define DN_TO_IP6_OUT 7 -#define DN_TO_IFB_FWD 8 + /* see ip_fw_private.h */ dn_key output_time; /* when the pkt is due for delivery */ struct ifnet *ifp; /* interface, for ip_output */ Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Sat Dec 26 00:46:05 2009 (r201010) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Sat Dec 26 02:36:48 2009 (r201011) @@ -986,10 +986,10 @@ dummynet_send(struct mbuf *m) } switch (dst) { - case DN_TO_IP_OUT: + case DIR_OUT: ip_output(m, NULL, NULL, IP_FORWARDING, NULL, NULL); break ; - case DN_TO_IP_IN : + case DIR_IN : ip = mtod(m, struct ip *); #ifndef HAVE_NET_IPLEN ip->ip_len = htons(ip->ip_len); @@ -998,22 +998,22 @@ dummynet_send(struct mbuf *m) netisr_dispatch(NETISR_IP, m); break; #ifdef INET6 - case DN_TO_IP6_IN: + case DIR_IN | PROTO_IPV6: netisr_dispatch(NETISR_IPV6, m); break; - case DN_TO_IP6_OUT: + case DIR_OUT | PROTO_IPV6: ip6_output(m, NULL, NULL, IPV6_FORWARDING, NULL, NULL, NULL); break; #endif - case DN_TO_IFB_FWD: + case DIR_FWD | PROTO_IFB: /* DN_TO_IFB_FWD: */ if (bridge_dn_p != NULL) ((*bridge_dn_p)(m, pkt->ifp)); else printf("dummynet: if_bridge not loaded\n"); break; - case DN_TO_ETH_DEMUX: + case DIR_IN | PROTO_LAYER2: /* DN_TO_ETH_DEMUX: */ /* * The Ethernet code assumes the Ethernet header is * contiguous in the first mbuf header. @@ -1027,7 +1027,7 @@ dummynet_send(struct mbuf *m) } ether_demux(m->m_pkthdr.rcvif, m); break; - case DN_TO_ETH_OUT: + case DIR_OUT | PROTO_LAYER2: /* N_TO_ETH_OUT: */ ether_output_frame(pkt->ifp, m); break; @@ -1550,8 +1550,8 @@ dummynet_io(struct mbuf **m0, int dir, s } } done: - if (head == m && dir != DN_TO_IFB_FWD && dir != DN_TO_ETH_DEMUX && - dir != DN_TO_ETH_OUT) { /* Fast io. */ + if (head == m && (dir & PROTO_LAYER2) == 0 ) { + /* Fast io. */ io_pkt_fast++; if (m->m_nextpkt != NULL) printf("dummynet: fast io: pkt chain detected!\n"); Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Sat Dec 26 00:46:05 2009 (r201010) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Sat Dec 26 02:36:48 2009 (r201011) @@ -64,8 +64,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include - #include static VNET_DEFINE(int, fw_enable) = 1; @@ -86,8 +84,6 @@ ng_ipfw_input_t *ng_ipfw_input_p = NULL; /* Forward declarations. */ static int ipfw_divert(struct mbuf **, int, int); -#define DIV_DIR_IN 1 -#define DIV_DIR_OUT 0 #ifdef SYSCTL_NODE SYSCTL_DECL(_net_inet_ip_fw); @@ -123,7 +119,7 @@ ipfw_check_in(void *arg, struct mbuf **m ng_tag = (struct ng_ipfw_tag *)m_tag_locate(*m0, NGM_IPFW_COOKIE, 0, NULL); if (ng_tag != NULL) { - KASSERT(ng_tag->dir == NG_IPFW_IN, + KASSERT(ng_tag->dir == DIR_IN, ("ng_ipfw tag with wrong direction")); args.slot = ng_tag->slot; args.rulenum = ng_tag->rulenum; @@ -185,9 +181,9 @@ again: if (ip_dn_io_ptr == NULL) goto drop; if (mtod(*m0, struct ip *)->ip_v == 4) - ip_dn_io_ptr(m0, DN_TO_IP_IN, &args); + ip_dn_io_ptr(m0, DIR_IN, &args); else if (mtod(*m0, struct ip *)->ip_v == 6) - ip_dn_io_ptr(m0, DN_TO_IP6_IN, &args); + ip_dn_io_ptr(m0, DIR_IN | PROTO_IPV6, &args); if (*m0 != NULL) goto again; return 0; /* packet consumed */ @@ -197,7 +193,7 @@ again: /* fall through */ case IP_FW_DIVERT: - divert = ipfw_divert(m0, DIV_DIR_IN, tee); + divert = ipfw_divert(m0, DIR_IN, tee); if (divert) { *m0 = NULL; return 0; /* packet consumed */ @@ -209,13 +205,13 @@ again: case IP_FW_NGTEE: if (!NG_IPFW_LOADED) goto drop; - (void)ng_ipfw_input_p(m0, NG_IPFW_IN, &args, 1); + (void)ng_ipfw_input_p(m0, DIR_IN, &args, 1); goto again; /* continue with packet */ case IP_FW_NETGRAPH: if (!NG_IPFW_LOADED) goto drop; - return ng_ipfw_input_p(m0, NG_IPFW_IN, &args, 0); + return ng_ipfw_input_p(m0, DIR_IN, &args, 0); case IP_FW_NAT: goto again; /* continue with packet */ @@ -257,7 +253,7 @@ ipfw_check_out(void *arg, struct mbuf ** ng_tag = (struct ng_ipfw_tag *)m_tag_locate(*m0, NGM_IPFW_COOKIE, 0, NULL); if (ng_tag != NULL) { - KASSERT(ng_tag->dir == NG_IPFW_OUT, + KASSERT(ng_tag->dir == DIR_OUT, ("ng_ipfw tag with wrong direction")); args.slot = ng_tag->slot; args.rulenum = ng_tag->rulenum; @@ -324,9 +320,9 @@ again: if (ip_dn_io_ptr == NULL) break; if (mtod(*m0, struct ip *)->ip_v == 4) - ip_dn_io_ptr(m0, DN_TO_IP_OUT, &args); + ip_dn_io_ptr(m0, DIR_OUT, &args); else if (mtod(*m0, struct ip *)->ip_v == 6) - ip_dn_io_ptr(m0, DN_TO_IP6_OUT, &args); + ip_dn_io_ptr(m0, DIR_OUT | PROTO_IPV6, &args); if (*m0 != NULL) goto again; return 0; /* packet consumed */ @@ -338,7 +334,7 @@ again: /* fall through */ case IP_FW_DIVERT: - divert = ipfw_divert(m0, DIV_DIR_OUT, tee); + divert = ipfw_divert(m0, DIR_OUT, tee); if (divert) { *m0 = NULL; return 0; /* packet consumed */ @@ -350,13 +346,13 @@ again: case IP_FW_NGTEE: if (!NG_IPFW_LOADED) goto drop; - (void)ng_ipfw_input_p(m0, NG_IPFW_OUT, &args, 1); + (void)ng_ipfw_input_p(m0, DIR_OUT, &args, 1); goto again; /* continue with packet */ case IP_FW_NETGRAPH: if (!NG_IPFW_LOADED) goto drop; - return ng_ipfw_input_p(m0, NG_IPFW_OUT, &args, 0); + return ng_ipfw_input_p(m0, DIR_OUT, &args, 0); case IP_FW_NAT: goto again; /* continue with packet */ @@ -584,20 +580,14 @@ ipfw_chg_hook(SYSCTL_HANDLER_ARGS) return (0); if (arg1 == &VNET_NAME(fw_enable)) { - if (enable) - error = ipfw_hook(); - else - error = ipfw_unhook(); + error = (enable) ? ipfw_hook() : ipfw_unhook(); if (error) return (error); V_fw_enable = enable; } #ifdef INET6 else if (arg1 == &VNET_NAME(fw6_enable)) { - if (enable) - error = ipfw6_hook(); - else - error = ipfw6_unhook(); + error = (enable) ? ipfw6_hook() : ipfw6_unhook(); if (error) return (error); V_fw6_enable = enable; Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h Sat Dec 26 00:46:05 2009 (r201010) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_private.h Sat Dec 26 02:36:48 2009 (r201011) @@ -101,11 +101,32 @@ struct ip_fw_args { MALLOC_DECLARE(M_IPFW); /* + * Hooks sometime need to know the direction of the packet + * (divert, dummynet, netgraph, ...) + * We use a generic definition here, with bit0-1 indicating the + * direction, bit 2 indicating layer2 or 3, bit 3-4 indicating the + * specific protocol + * indicating the protocol (if necessary) + */ +enum { + DIR_MASK = 0x3, + DIR_OUT = 0, + DIR_IN = 1, + DIR_FWD = 2, + DIR_DROP = 3, + PROTO_LAYER2 = 0x4, /* set for layer 2 */ + /* PROTO_DEFAULT = 0, */ + PROTO_IPV4 = 0x08, + PROTO_IPV6 = 0x10, + PROTO_IFB = 0x0c, /* layer2 + ifbridge */ + /* PROTO_OLDBDG = 0x14, unused, old bridge */ +}; + +/* * Function definitions. */ /* Firewall hooks */ - int ipfw_check_in(void *, struct mbuf **, struct ifnet *, int, struct inpcb *inp); int ipfw_check_out(void *, struct mbuf **, struct ifnet *, @@ -257,5 +278,27 @@ extern ipfw_nat_cfg_t *ipfw_nat_del_ptr; extern ipfw_nat_cfg_t *ipfw_nat_get_cfg_ptr; extern ipfw_nat_cfg_t *ipfw_nat_get_log_ptr; +/* netgraph prototypes */ +#define NGM_IPFW_COOKIE 1105988990 + +typedef int ng_ipfw_input_t(struct mbuf **, int, struct ip_fw_args *, int); +extern ng_ipfw_input_t *ng_ipfw_input_p; +#define NG_IPFW_LOADED (ng_ipfw_input_p != NULL) + +struct ng_ipfw_tag { + struct m_tag mt; /* tag header */ + /* reinject info */ + uint32_t slot; /* slot for next rule */ + uint32_t rulenum; /* matching rule number */ + uint32_t rule_id; /* matching rule id */ + uint32_t chain_id; /* ruleset id */ + int dir; + +// struct ifnet *ifp; /* interface, for ip_output */ +}; + +#define TAGSIZ (sizeof(struct ng_ipfw_tag) - sizeof(struct m_tag)) + + #endif /* _KERNEL */ #endif /* _IPFW2_PRIVATE_H */ Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Sat Dec 26 00:46:05 2009 (r201010) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_sockopt.c Sat Dec 26 02:36:48 2009 (r201011) @@ -67,8 +67,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include - #ifdef MAC #include #endif From owner-svn-src-user@FreeBSD.ORG Sat Dec 26 02:56:59 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0699A1065692; Sat, 26 Dec 2009 02:56:59 +0000 (UTC) (envelope-from luigi@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id EA1128FC19; Sat, 26 Dec 2009 02:56:58 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id nBQ2uwRi078832; Sat, 26 Dec 2009 02:56:58 GMT (envelope-from luigi@svn.freebsd.org) Received: (from luigi@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id nBQ2uwcW078830; Sat, 26 Dec 2009 02:56:58 GMT (envelope-from luigi@svn.freebsd.org) Message-Id: <200912260256.nBQ2uwcW078830@svn.freebsd.org> From: Luigi Rizzo Date: Sat, 26 Dec 2009 02:56:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r201012 - user/luigi/ipfw3-head/sys/netinet/ipfw X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 26 Dec 2009 02:56:59 -0000 Author: luigi Date: Sat Dec 26 02:56:58 2009 New Revision: 201012 URL: http://svn.freebsd.org/changeset/base/201012 Log: another small simplification Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Sat Dec 26 02:36:48 2009 (r201011) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_fw_pfil.c Sat Dec 26 02:56:58 2009 (r201012) @@ -46,9 +46,7 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include -#include #include #include @@ -239,7 +237,7 @@ ipfw_check_out(void *arg, struct mbuf ** struct ip_fw_args args; struct ng_ipfw_tag *ng_tag; struct m_tag *dn_tag; - int ipfw = 0; + int ipfw; int divert; int tee; #ifdef IPFIREWALL_FORWARD @@ -392,14 +390,14 @@ ipfw_divert(struct mbuf **m, int incomin goto nodivert; /* Cloning needed for tee? */ - if (tee) + if (tee) { clone = m_dup(*m, M_DONTWAIT); - else + /* In case m_dup was unable to allocate mbufs. */ + if (clone == NULL) + return 0; + } else clone = *m; - /* In case m_dup was unable to allocate mbufs. */ - if (clone == NULL) - goto teeout; /* * Divert listeners can only handle non-fragmented packets. @@ -445,7 +443,6 @@ ipfw_divert(struct mbuf **m, int incomin if (clone && ip_divert_ptr != NULL) ip_divert_ptr(clone, incoming); -teeout: /* * For tee we leave the divert tag attached to original packet. * It will then continue rule evaluation after the tee rule.