Date: Tue, 5 Jan 2010 17:05:12 +0000 (UTC) From: Luigi Rizzo <luigi@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r201595 - user/luigi/ipfw3-head/sys/netinet/ipfw Message-ID: <201001051705.o05H5CNL058426@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: luigi Date: Tue Jan 5 17:05:12 2010 New Revision: 201595 URL: http://svn.freebsd.org/changeset/base/201595 Log: simplify a function Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Modified: user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c ============================================================================== --- user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Tue Jan 5 17:04:39 2010 (r201594) +++ user/luigi/ipfw3-head/sys/netinet/ipfw/ip_dummynet.c Tue Jan 5 17:05:12 2010 (r201595) @@ -38,7 +38,6 @@ __FBSDID("$FreeBSD$"); * Description of the data structures used is in ip_dummynet.h * Here you mainly find the following blocks of code: * + variable declarations; - * + heap management functions; * + scheduler and dummynet functions; * + configuration and initialization. * @@ -1624,6 +1623,7 @@ config_pipe(struct dn_pipe *p) pipe = locate_pipe(p->pipe_nr); /* locate pipe */ if (pipe == NULL) { /* new pipe */ + /* space for pipe + 3 heaps right after the pipe */ pipe = malloc(sizeof(struct dn_pipe) + 3 * sizeof(struct dn_heap), M_DUMMYNET, M_NOWAIT | M_ZERO); @@ -1633,7 +1633,6 @@ config_pipe(struct dn_pipe *p) return (ENOMEM); } - /* the heaps are right after the pipe */ pipe->scheduler_heap = (struct dn_heap *)(pipe + 1); pipe->not_eligible_heap = pipe->scheduler_heap + 1; pipe->idle_heap = pipe->scheduler_heap + 2; @@ -1820,22 +1819,21 @@ dummynet_drain(void) static int delete_pipe(struct dn_pipe *p) { - - if (p->pipe_nr == 0 && p->fs.fs_nr == 0) - return EINVAL ; - if (p->pipe_nr != 0 && p->fs.fs_nr != 0) + struct dn_pipe *pipe; + struct dn_flow_set *fs; + int err = 0; + + if (p->pipe_nr != 0 && p->fs.fs_nr != 0) /* cannot have both set */ return EINVAL ; + DUMMYNET_LOCK(); if (p->pipe_nr != 0) { /* this is an old-style pipe */ - struct dn_pipe *pipe; - struct dn_flow_set *fs; int i; - DUMMYNET_LOCK(); pipe = locate_pipe(p->pipe_nr); /* locate pipe */ if (pipe == NULL) { - DUMMYNET_UNLOCK(); - return (ENOENT); /* not found */ + err = ENOENT; /* not found */ + goto done; } /* Unlink from list of pipes. */ @@ -1857,18 +1855,14 @@ delete_pipe(struct dn_pipe *p) /* remove reference to here from extract_heap and wfq_ready_heap */ heap_scan(&extract_heap, scan_remove_pipe, (uintptr_t)pipe); heap_scan(&wfq_ready_heap, scan_remove_pipe, (uintptr_t)pipe); - DUMMYNET_UNLOCK(); - - free_pipe(pipe); } else { /* this is a WF2Q queue (dn_flow_set) */ - struct dn_flow_set *fs; + pipe = NULL; - DUMMYNET_LOCK(); fs = locate_flowset(p->fs.fs_nr); /* locate set */ if (fs == NULL) { - DUMMYNET_UNLOCK(); - return (ENOENT); /* not found */ + err = ENOENT; /* not found */ + goto done; } /* Unlink from list of flowsets. */ @@ -1879,14 +1873,15 @@ delete_pipe(struct dn_pipe *p) fs->pipe->sum -= fs->weight * fs->backlogged ; fs_remove_from_heap(fs->pipe->not_eligible_heap, fs); fs_remove_from_heap(fs->pipe->scheduler_heap, fs); -#if 1 /* XXX should i remove from idle_heap as well ? */ fs_remove_from_heap(fs->pipe->idle_heap, fs); -#endif } purge_flow_set(fs, 1); - DUMMYNET_UNLOCK(); } - return 0 ; +done: + DUMMYNET_UNLOCK(); + if (pipe) + free_pipe(pipe); + return err; } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001051705.o05H5CNL058426>