Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1795570imm; Wed, 16 May 2018 03:15:04 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrU5z95LY4VRNeYdK/EhT2HsxfYvSwd3yu5Kuf65Rz1f5XteNwMjtq75yI+j/T82AYn5c3Z X-Received: by 2002:a17:902:41:: with SMTP id 59-v6mr248989pla.345.1526465704411; Wed, 16 May 2018 03:15:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526465704; cv=none; d=google.com; s=arc-20160816; b=sAvh9VZJb+qDyxychmssLJUY2JrNkEggULXTTB//NxAg9NWRBhfJS7GcuEZaVz6fEX GfZ5C1cAl0LeMpVE/KCI6n48IGB5q32d6s3bXjxIJ5ISNwnropRM8SgtOgRZoCs3SFiD /iRDfnxuLi3RBOtCPrsMuWdrpJBDS7lp2acfZ/ZAq3Y6yCPtuxLIdBUitR+184Vd1zJ6 n5aZeciwQwbV65dKLIlhWpDyIKOjjLb04MSWrr7BDvefPyiBI9puMuzrpT2Vj5D5Cpm9 bK8lrgP1bKD4tvSpSuC+TuLdpCW9WK1JnUGKuf3i/HViGdG2nfV2sXmeD5eOFnrjpsj7 dkSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=TMuCfKKQjyWim4anhqnZA2laNKWSZisLMOm6l0WLu9Q=; b=tsv+ZRmB/kuRhtcg8jKhTIk/m0kyBtKIQL6K/P4LIW1x2xCAORc6OlLUy0X0Bx+Qhc ELNUyOpmJ6Leg2pztBdYD5Tw8WdTyQzoVNorJk/H1dSjn3TUeiYnXXi3iH+uCrJUcA6V ra9YeDP4Vq7vRfQRrdA8/F6aid2nlx72PRZiCHp+O0p/TJ8lOoOjg3WHo7Vz7fYLOMtN 8b/gEJXv4PiyJj+onzI89taKeUelSQ3ouiyqGOnJK8TJgShLaojaRMk//UVbK4BiSUZ8 6/w9tsjHGroQGhbH6oKm77FqysadXa6AoJB6d1QjVfGgbpt0syhqsbb3+bz6XdTBUbTg nuVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=J4dKZwDF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si2085485plr.483.2018.05.16.03.14.49; Wed, 16 May 2018 03:15:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=J4dKZwDF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753040AbeEPKMY (ORCPT + 99 others); Wed, 16 May 2018 06:12:24 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:47154 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752684AbeEPJow (ORCPT ); Wed, 16 May 2018 05:44:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=TMuCfKKQjyWim4anhqnZA2laNKWSZisLMOm6l0WLu9Q=; b=J4dKZwDFMQHEeymLZY2C3pCJ7 ykZ95xNd8ZKCaVoXYUcqgVU/pA/qSoqYop+rFMe+c92Jh05q3Xb/zBEFQFk3uDzk0fCHIpWVrHzlK QUc2zq86tVrdsLK+4vLgcKiXJiyG/5qja/JJRddaJD0i8QWXf/NmWPXnb3ZCMsUYPTBoLPzsSoRfT Zxsz2RC5/ZP/SMELL8b/DBV51g8wt7dutyP9B4kJ9G8CpmvUskSTLwEBm7YKBL5hxUnTtDCBFbYI/ 2/9VJckOz2X6Po85YeISux8ZShTlLo/mWSn1gaZ1XTlQ7Xw+j+jHtFe5qurs578kG0fZIItYYWcdu wmubgefFA==; Received: from 089144199016.atnat0008.highway.a1.net ([89.144.199.16] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIsz5-0005BH-Jm; Wed, 16 May 2018 09:44:36 +0000 From: Christoph Hellwig To: Andrew Morton , Alexander Viro Cc: Alexey Dobriyan , Greg Kroah-Hartman , Jiri Slaby , Alessandro Zummo , Alexandre Belloni , linux-acpi@vger.kernel.org, drbd-dev@lists.linbit.com, linux-ide@vger.kernel.org, netdev@vger.kernel.org, linux-rtc@vger.kernel.org, megaraidlinux.pdl@broadcom.com, linux-scsi@vger.kernel.org, devel@driverdev.osuosl.org, linux-afs@lists.infradead.org, linux-ext4@vger.kernel.org, jfs-discussion@lists.sourceforge.net, netfilter-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/42] ipv{4,6}/tcp: simplify procfs registration Date: Wed, 16 May 2018 11:43:14 +0200 Message-Id: <20180516094346.20506-11-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180516094346.20506-1-hch@lst.de> References: <20180516094346.20506-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Avoid most of the afinfo indirections and just call the proc helpers directly. Signed-off-by: Christoph Hellwig --- include/net/tcp.h | 11 ++---- net/ipv4/tcp_ipv4.c | 85 +++++++++++++++++---------------------------- net/ipv6/tcp_ipv6.c | 27 +++++++++----- 3 files changed, 53 insertions(+), 70 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 9c9b3768b350..51dc7a26a2fa 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1747,27 +1747,22 @@ enum tcp_seq_states { TCP_SEQ_STATE_ESTABLISHED, }; -int tcp_seq_open(struct inode *inode, struct file *file); +void *tcp_seq_start(struct seq_file *seq, loff_t *pos); +void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos); +void tcp_seq_stop(struct seq_file *seq, void *v); struct tcp_seq_afinfo { - char *name; sa_family_t family; - const struct file_operations *seq_fops; - struct seq_operations seq_ops; }; struct tcp_iter_state { struct seq_net_private p; - sa_family_t family; enum tcp_seq_states state; struct sock *syn_wait_sk; int bucket, offset, sbucket, num; loff_t last_pos; }; -int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo); -void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo); - extern struct request_sock_ops tcp_request_sock_ops; extern struct request_sock_ops tcp6_request_sock_ops; diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index f70586b50838..645f259d0972 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1961,6 +1961,7 @@ EXPORT_SYMBOL(tcp_v4_destroy_sock); */ static void *listening_get_next(struct seq_file *seq, void *cur) { + struct tcp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file)); struct tcp_iter_state *st = seq->private; struct net *net = seq_file_net(seq); struct inet_listen_hashbucket *ilb; @@ -1983,7 +1984,7 @@ static void *listening_get_next(struct seq_file *seq, void *cur) sk_for_each_from(sk) { if (!net_eq(sock_net(sk), net)) continue; - if (sk->sk_family == st->family) + if (sk->sk_family == afinfo->family) return sk; } spin_unlock(&ilb->lock); @@ -2020,6 +2021,7 @@ static inline bool empty_bucket(const struct tcp_iter_state *st) */ static void *established_get_first(struct seq_file *seq) { + struct tcp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file)); struct tcp_iter_state *st = seq->private; struct net *net = seq_file_net(seq); void *rc = NULL; @@ -2036,7 +2038,7 @@ static void *established_get_first(struct seq_file *seq) spin_lock_bh(lock); sk_nulls_for_each(sk, node, &tcp_hashinfo.ehash[st->bucket].chain) { - if (sk->sk_family != st->family || + if (sk->sk_family != afinfo->family || !net_eq(sock_net(sk), net)) { continue; } @@ -2051,6 +2053,7 @@ static void *established_get_first(struct seq_file *seq) static void *established_get_next(struct seq_file *seq, void *cur) { + struct tcp_seq_afinfo *afinfo = PDE_DATA(file_inode(seq->file)); struct sock *sk = cur; struct hlist_nulls_node *node; struct tcp_iter_state *st = seq->private; @@ -2062,7 +2065,8 @@ static void *established_get_next(struct seq_file *seq, void *cur) sk = sk_nulls_next(sk); sk_nulls_for_each_from(sk, node) { - if (sk->sk_family == st->family && net_eq(sock_net(sk), net)) + if (sk->sk_family == afinfo->family && + net_eq(sock_net(sk), net)) return sk; } @@ -2135,7 +2139,7 @@ static void *tcp_seek_last_pos(struct seq_file *seq) return rc; } -static void *tcp_seq_start(struct seq_file *seq, loff_t *pos) +void *tcp_seq_start(struct seq_file *seq, loff_t *pos) { struct tcp_iter_state *st = seq->private; void *rc; @@ -2156,8 +2160,9 @@ static void *tcp_seq_start(struct seq_file *seq, loff_t *pos) st->last_pos = *pos; return rc; } +EXPORT_SYMBOL(tcp_seq_start); -static void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos) +void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct tcp_iter_state *st = seq->private; void *rc = NULL; @@ -2186,8 +2191,9 @@ static void *tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos) st->last_pos = *pos; return rc; } +EXPORT_SYMBOL(tcp_seq_next); -static void tcp_seq_stop(struct seq_file *seq, void *v) +void tcp_seq_stop(struct seq_file *seq, void *v) { struct tcp_iter_state *st = seq->private; @@ -2202,47 +2208,7 @@ static void tcp_seq_stop(struct seq_file *seq, void *v) break; } } - -int tcp_seq_open(struct inode *inode, struct file *file) -{ - struct tcp_seq_afinfo *afinfo = PDE_DATA(inode); - struct tcp_iter_state *s; - int err; - - err = seq_open_net(inode, file, &afinfo->seq_ops, - sizeof(struct tcp_iter_state)); - if (err < 0) - return err; - - s = ((struct seq_file *)file->private_data)->private; - s->family = afinfo->family; - s->last_pos = 0; - return 0; -} -EXPORT_SYMBOL(tcp_seq_open); - -int tcp_proc_register(struct net *net, struct tcp_seq_afinfo *afinfo) -{ - int rc = 0; - struct proc_dir_entry *p; - - afinfo->seq_ops.start = tcp_seq_start; - afinfo->seq_ops.next = tcp_seq_next; - afinfo->seq_ops.stop = tcp_seq_stop; - - p = proc_create_data(afinfo->name, 0444, net->proc_net, - afinfo->seq_fops, afinfo); - if (!p) - rc = -ENOMEM; - return rc; -} -EXPORT_SYMBOL(tcp_proc_register); - -void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo) -{ - remove_proc_entry(afinfo->name, net->proc_net); -} -EXPORT_SYMBOL(tcp_proc_unregister); +EXPORT_SYMBOL(tcp_seq_stop); static void get_openreq4(const struct request_sock *req, struct seq_file *f, int i) @@ -2377,6 +2343,19 @@ static int tcp4_seq_show(struct seq_file *seq, void *v) return 0; } +static const struct seq_operations tcp4_seq_ops = { + .show = tcp4_seq_show, + .start = tcp_seq_start, + .next = tcp_seq_next, + .stop = tcp_seq_stop, +}; + +static int tcp_seq_open(struct inode *inode, struct file *file) +{ + return seq_open_net(inode, file, &tcp4_seq_ops, + sizeof(struct tcp_iter_state)); +} + static const struct file_operations tcp_afinfo_seq_fops = { .open = tcp_seq_open, .read = seq_read, @@ -2385,22 +2364,20 @@ static const struct file_operations tcp_afinfo_seq_fops = { }; static struct tcp_seq_afinfo tcp4_seq_afinfo = { - .name = "tcp", .family = AF_INET, - .seq_fops = &tcp_afinfo_seq_fops, - .seq_ops = { - .show = tcp4_seq_show, - }, }; static int __net_init tcp4_proc_init_net(struct net *net) { - return tcp_proc_register(net, &tcp4_seq_afinfo); + if (!proc_create_data("tcp", 0444, net->proc_net, + &tcp_afinfo_seq_fops, &tcp4_seq_afinfo)) + return -ENOMEM; + return 0; } static void __net_exit tcp4_proc_exit_net(struct net *net) { - tcp_proc_unregister(net, &tcp4_seq_afinfo); + remove_proc_entry("tcp", net->proc_net); } static struct pernet_operations tcp4_net_ops = { diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 6d664d83cd16..c0329bb1692f 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1909,30 +1909,41 @@ static int tcp6_seq_show(struct seq_file *seq, void *v) return 0; } +static const struct seq_operations tcp6_seq_ops = { + .show = tcp6_seq_show, + .start = tcp_seq_start, + .next = tcp_seq_next, + .stop = tcp_seq_stop, +}; + +static int tcp6_seq_open(struct inode *inode, struct file *file) +{ + return seq_open_net(inode, file, &tcp6_seq_ops, + sizeof(struct tcp_iter_state)); +} + static const struct file_operations tcp6_afinfo_seq_fops = { - .open = tcp_seq_open, + .open = tcp6_seq_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_net }; static struct tcp_seq_afinfo tcp6_seq_afinfo = { - .name = "tcp6", .family = AF_INET6, - .seq_fops = &tcp6_afinfo_seq_fops, - .seq_ops = { - .show = tcp6_seq_show, - }, }; int __net_init tcp6_proc_init(struct net *net) { - return tcp_proc_register(net, &tcp6_seq_afinfo); + if (!proc_create_data("tcp6", 0444, net->proc_net, + &tcp6_afinfo_seq_fops, &tcp6_seq_afinfo)) + return -ENOMEM; + return 0; } void tcp6_proc_exit(struct net *net) { - tcp_proc_unregister(net, &tcp6_seq_afinfo); + remove_proc_entry("tcp6", net->proc_net); } #endif -- 2.17.0