diff options
author | Pavel Emelyanov <xemul@openvz.org> | 2007-11-07 05:23:38 -0500 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2007-11-07 07:15:04 -0500 |
commit | b733c007edad6f3e05109951bacc6f87dd807917 (patch) | |
tree | fa267da7ccba5bae081997064d953f5993c3dbf3 /net/core/sock.c | |
parent | 4999f3621f4da622e77931b3d33ada6c7083c705 (diff) |
[NET]: Clean proto_(un)register from in-code ifdefs
The struct proto has the per-cpu "inuse" counter, which is handled
with a special care. All the handling code hides under the ifdef
CONFIG_SMP and it introduces some code duplication and makes it
look worse than it could.
Clean this.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/sock.c')
-rw-r--r-- | net/core/sock.c | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/net/core/sock.c b/net/core/sock.c index e077f263b730..8fc2f84209e4 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -1819,23 +1819,48 @@ static int inuse_get(const struct proto *prot) | |||
1819 | res += per_cpu_ptr(prot->inuse_ptr, cpu)[0]; | 1819 | res += per_cpu_ptr(prot->inuse_ptr, cpu)[0]; |
1820 | return res; | 1820 | return res; |
1821 | } | 1821 | } |
1822 | #endif | ||
1823 | 1822 | ||
1824 | int proto_register(struct proto *prot, int alloc_slab) | 1823 | static int inuse_init(struct proto *prot) |
1825 | { | 1824 | { |
1826 | char *request_sock_slab_name = NULL; | ||
1827 | char *timewait_sock_slab_name; | ||
1828 | int rc = -ENOBUFS; | ||
1829 | |||
1830 | #ifdef CONFIG_SMP | ||
1831 | if (!prot->inuse_getval || !prot->inuse_add) { | 1825 | if (!prot->inuse_getval || !prot->inuse_add) { |
1832 | prot->inuse_ptr = alloc_percpu(int); | 1826 | prot->inuse_ptr = alloc_percpu(int); |
1833 | if (prot->inuse_ptr == NULL) | 1827 | if (prot->inuse_ptr == NULL) |
1834 | goto out; | 1828 | return -ENOBUFS; |
1829 | |||
1835 | prot->inuse_getval = inuse_get; | 1830 | prot->inuse_getval = inuse_get; |
1836 | prot->inuse_add = inuse_add; | 1831 | prot->inuse_add = inuse_add; |
1837 | } | 1832 | } |
1833 | return 0; | ||
1834 | } | ||
1835 | |||
1836 | static void inuse_fini(struct proto *prot) | ||
1837 | { | ||
1838 | if (prot->inuse_ptr != NULL) { | ||
1839 | free_percpu(prot->inuse_ptr); | ||
1840 | prot->inuse_ptr = NULL; | ||
1841 | prot->inuse_getval = NULL; | ||
1842 | prot->inuse_add = NULL; | ||
1843 | } | ||
1844 | } | ||
1845 | #else | ||
1846 | static inline int inuse_init(struct proto *prot) | ||
1847 | { | ||
1848 | return 0; | ||
1849 | } | ||
1850 | |||
1851 | static inline void inuse_fini(struct proto *prot) | ||
1852 | { | ||
1853 | } | ||
1838 | #endif | 1854 | #endif |
1855 | |||
1856 | int proto_register(struct proto *prot, int alloc_slab) | ||
1857 | { | ||
1858 | char *request_sock_slab_name = NULL; | ||
1859 | char *timewait_sock_slab_name; | ||
1860 | |||
1861 | if (inuse_init(prot)) | ||
1862 | goto out; | ||
1863 | |||
1839 | if (alloc_slab) { | 1864 | if (alloc_slab) { |
1840 | prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0, | 1865 | prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0, |
1841 | SLAB_HWCACHE_ALIGN, NULL); | 1866 | SLAB_HWCACHE_ALIGN, NULL); |
@@ -1887,9 +1912,8 @@ int proto_register(struct proto *prot, int alloc_slab) | |||
1887 | write_lock(&proto_list_lock); | 1912 | write_lock(&proto_list_lock); |
1888 | list_add(&prot->node, &proto_list); | 1913 | list_add(&prot->node, &proto_list); |
1889 | write_unlock(&proto_list_lock); | 1914 | write_unlock(&proto_list_lock); |
1890 | rc = 0; | 1915 | return 0; |
1891 | out: | 1916 | |
1892 | return rc; | ||
1893 | out_free_timewait_sock_slab_name: | 1917 | out_free_timewait_sock_slab_name: |
1894 | kfree(timewait_sock_slab_name); | 1918 | kfree(timewait_sock_slab_name); |
1895 | out_free_request_sock_slab: | 1919 | out_free_request_sock_slab: |
@@ -1903,15 +1927,9 @@ out_free_sock_slab: | |||
1903 | kmem_cache_destroy(prot->slab); | 1927 | kmem_cache_destroy(prot->slab); |
1904 | prot->slab = NULL; | 1928 | prot->slab = NULL; |
1905 | out_free_inuse: | 1929 | out_free_inuse: |
1906 | #ifdef CONFIG_SMP | 1930 | inuse_fini(prot); |
1907 | if (prot->inuse_ptr != NULL) { | 1931 | out: |
1908 | free_percpu(prot->inuse_ptr); | 1932 | return -ENOBUFS; |
1909 | prot->inuse_ptr = NULL; | ||
1910 | prot->inuse_getval = NULL; | ||
1911 | prot->inuse_add = NULL; | ||
1912 | } | ||
1913 | #endif | ||
1914 | goto out; | ||
1915 | } | 1933 | } |
1916 | 1934 | ||
1917 | EXPORT_SYMBOL(proto_register); | 1935 | EXPORT_SYMBOL(proto_register); |
@@ -1922,14 +1940,7 @@ void proto_unregister(struct proto *prot) | |||
1922 | list_del(&prot->node); | 1940 | list_del(&prot->node); |
1923 | write_unlock(&proto_list_lock); | 1941 | write_unlock(&proto_list_lock); |
1924 | 1942 | ||
1925 | #ifdef CONFIG_SMP | 1943 | inuse_fini(prot); |
1926 | if (prot->inuse_ptr != NULL) { | ||
1927 | free_percpu(prot->inuse_ptr); | ||
1928 | prot->inuse_ptr = NULL; | ||
1929 | prot->inuse_getval = NULL; | ||
1930 | prot->inuse_add = NULL; | ||
1931 | } | ||
1932 | #endif | ||
1933 | if (prot->slab != NULL) { | 1944 | if (prot->slab != NULL) { |
1934 | kmem_cache_destroy(prot->slab); | 1945 | kmem_cache_destroy(prot->slab); |
1935 | prot->slab = NULL; | 1946 | prot->slab = NULL; |