mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, devel@driverdev.osuosl.org,
	Tommi Rantala <tt.rantala@gmail.com>,
	Bill Pemberton <wfp5p@virginia.edu>,
	viro@zeniv.linux.org.uk
Subject: [PATCH 21/28] dgrp: Clean up the use of procfs [RFC]
Date: Tue, 16 Apr 2013 19:27:13 +0100	[thread overview]
Message-ID: <20130416182713.27773.66239.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20130416182550.27773.89310.stgit@warthog.procyon.org.uk>

Clean up the use of procfs by the dgrp driver:

 (1) Use remove_proc_subtree() for the mass slaughter of a subdir full of proc
     files rather than doing it manually.

 (2) When creating files, only call ID_TO_CHAR() once to generate the name.

Signed-off-by : David Howells <dhowells@redhat.com>
cc: Bill Pemberton <wfp5p@virginia.edu>
cc: Tommi Rantala <tt.rantala@gmail.com>
cc: devel@driverdev.osuosl.org
---

 drivers/staging/dgrp/dgrp_specproc.c |   82 ++++++++++++----------------------
 1 file changed, 28 insertions(+), 54 deletions(-)

diff --git a/drivers/staging/dgrp/dgrp_specproc.c b/drivers/staging/dgrp/dgrp_specproc.c
index 205d80e..e3c16a9 100644
--- a/drivers/staging/dgrp/dgrp_specproc.c
+++ b/drivers/staging/dgrp/dgrp_specproc.c
@@ -45,13 +45,8 @@
 
 #include "dgrp_common.h"
 
-static struct proc_dir_entry *dgrp_proc_dir_entry;
-
 static int dgrp_add_id(long id);
 static int dgrp_remove_nd(struct nd_struct *nd);
-static struct proc_dir_entry *add_proc_file(struct nd_struct *node,
-				 struct proc_dir_entry *root,
-				 const struct file_operations *fops);
 
 /* File operation declarations */
 static int parse_write_config(char *);
@@ -94,51 +89,23 @@ static struct proc_dir_entry *mon_entry_pointer;
 static struct proc_dir_entry *dpa_entry_pointer;
 static struct proc_dir_entry *ports_entry_pointer;
 
-static void remove_files(struct nd_struct *nd)
-{
-	char buf[3];
-	ID_TO_CHAR(nd->nd_ID, buf);
-	dgrp_remove_node_class_sysfs_files(nd);
-	if (nd->nd_net_de)
-		remove_proc_entry(buf, net_entry_pointer);
-	if (nd->nd_mon_de)
-		remove_proc_entry(buf, mon_entry_pointer);
-	if (nd->nd_dpa_de)
-		remove_proc_entry(buf, dpa_entry_pointer);
-	if (nd->nd_ports_de)
-		remove_proc_entry(buf, ports_entry_pointer);
-}
-
 void dgrp_unregister_proc(void)
 {
+	struct nd_struct *nd;
+
 	net_entry_pointer = NULL;
 	mon_entry_pointer = NULL;
 	dpa_entry_pointer = NULL;
 	ports_entry_pointer = NULL;
 
-	if (dgrp_proc_dir_entry) {
-		struct nd_struct *nd;
-		list_for_each_entry(nd, &nd_struct_list, list)
-			remove_files(nd);
-		remove_proc_entry("dgrp/config", NULL);
-		remove_proc_entry("dgrp/info", NULL);
-		remove_proc_entry("dgrp/nodeinfo", NULL);
-		remove_proc_entry("dgrp/net", NULL);
-		remove_proc_entry("dgrp/mon", NULL);
-		remove_proc_entry("dgrp/dpa", NULL);
-		remove_proc_entry("dgrp/ports", NULL);
-		remove_proc_entry("dgrp", NULL);
-		dgrp_proc_dir_entry = NULL;
-	}
+	list_for_each_entry(nd, &nd_struct_list, list)
+		dgrp_remove_node_class_sysfs_files(nd);
+	remove_proc_subtree("dgrp", NULL);
 }
 
 void dgrp_register_proc(void)
 {
-	/*
-	 *	Register /proc/dgrp
-	 */
-	dgrp_proc_dir_entry = proc_mkdir("dgrp", NULL);
-	if (!dgrp_proc_dir_entry)
+	if (!proc_mkdir("dgrp", NULL))
 		return;
 	proc_create("dgrp/config", 0644, NULL, &config_proc_file_ops);
 	proc_create("dgrp/info", 0644, NULL, &info_proc_file_ops);
@@ -455,6 +422,14 @@ static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file)
 	return seq_open(file, &nodeinfo_ops);
 }
 
+static struct proc_dir_entry *add_proc_file(struct nd_struct *nd,
+					    const char *name,
+					    struct proc_dir_entry *root,
+					    const struct file_operations *fops)
+{
+	return proc_create_data(name, 0600, root, fops, nd);
+}
+
 /**
  * dgrp_add_id() -- creates new nd struct and adds it to list
  * @id: id of device to add
@@ -462,6 +437,7 @@ static int dgrp_nodeinfo_proc_open(struct inode *inode, struct file *file)
 static int dgrp_add_id(long id)
 {
 	struct nd_struct *nd;
+	char name[3];
 	int ret;
 	int i;
 
@@ -496,11 +472,11 @@ static int dgrp_add_id(long id)
 		goto error_out;
 
 	dgrp_create_node_class_sysfs_files(nd);
-	nd->nd_net_de = add_proc_file(nd, net_entry_pointer, &dgrp_net_ops);
-	nd->nd_mon_de = add_proc_file(nd, mon_entry_pointer, &dgrp_mon_ops);
-	nd->nd_dpa_de = add_proc_file(nd, dpa_entry_pointer, &dgrp_dpa_ops);
-	nd->nd_ports_de = add_proc_file(nd, ports_entry_pointer,
-					&dgrp_ports_ops);
+	ID_TO_CHAR(nd->nd_ID, name);
+	add_proc_file(nd, name, net_entry_pointer, &dgrp_net_ops);
+	add_proc_file(nd, name, mon_entry_pointer, &dgrp_mon_ops);
+	add_proc_file(nd, name, dpa_entry_pointer, &dgrp_dpa_ops);
+	add_proc_file(nd, name, ports_entry_pointer, &dgrp_ports_ops);
 	return 0;
 
 	/* FIXME this guy should free the tty driver stored in nd and destroy
@@ -513,13 +489,20 @@ error_out:
 
 static int dgrp_remove_nd(struct nd_struct *nd)
 {
+	char name[3];
 	int ret;
 
 	/* Check to see if the selected structure is in use */
 	if (nd->nd_tty_ref_cnt)
 		return -EBUSY;
 
-	remove_files(nd);
+
+	dgrp_remove_node_class_sysfs_files(nd);
+	ID_TO_CHAR(nd->nd_ID, name);
+	remove_proc_entry(name, net_entry_pointer);
+	remove_proc_entry(name, mon_entry_pointer);
+	remove_proc_entry(name, dpa_entry_pointer);
+	remove_proc_entry(name, ports_entry_pointer);
 
 	dgrp_tty_uninit(nd);
 
@@ -530,12 +513,3 @@ static int dgrp_remove_nd(struct nd_struct *nd)
 	kfree(nd);
 	return 0;
 }
-
-static struct proc_dir_entry *add_proc_file(struct nd_struct *node,
-				 struct proc_dir_entry *root,
-				 const struct file_operations *fops)
-{
-	char buf[3];
-	ID_TO_CHAR(node->nd_ID, buf);
-	return proc_create_data(buf, 0600, root, fops, node);
-}


  parent reply	other threads:[~2013-04-16 18:29 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-16 18:25 [PATCH 00/28] Privatise procfs internals [RFC] David Howells
2013-04-16 18:25 ` [PATCH 01/28] Include missing linux/slab.h inclusions [RFC] David Howells
2013-04-17  0:56   ` Greg KH
2013-04-16 18:25 ` [PATCH 02/28] Include missing linux/magic.h " David Howells
2013-04-16 18:26 ` [PATCH 03/28] proc: Split kcore bits from linux/procfs.h into linux/kcore.h [RFC] David Howells
2013-04-16 21:37   ` KOSAKI Motohiro
2013-04-16 22:07   ` David Howells
2013-04-16 22:13     ` KOSAKI Motohiro
2013-04-17  9:13   ` Ralf Baechle
2013-04-16 18:26 ` [PATCH 04/28] proc: Supply PDE attribute setting accessor functions [RFC] David Howells
2013-04-16 21:37   ` Mauro Carvalho Chehab
2013-04-18 16:42   ` Bjorn Helgaas
2013-04-25 15:22   ` Vasant Hegde
2013-04-16 18:26 ` [PATCH 05/28] proc: Uninline pid_delete_dentry() [RFC] David Howells
2013-04-16 18:26 ` [PATCH 06/28] proc: Move proc_fd() to fs/proc/fd.h [RFC] David Howells
2013-04-16 18:26 ` [PATCH 07/28] proc: Split the namespace stuff out into linux/proc_ns.h [RFC] David Howells
2013-04-16 18:26 ` [PATCH 08/28] proc: Move PDE_NET() to fs/proc/proc_net.c [RFC] David Howells
2013-04-16 18:26 ` [PATCH 09/28] proc: Move some bits from linux/proc_fs.h to linux/{of.h, signal.h, tty.h} [RFC] David Howells
2013-04-17  0:57   ` Greg Kroah-Hartman
2013-04-17 14:59   ` Grant Likely
2013-04-16 18:26 ` [PATCH 10/28] proc: Add proc_mkdir_data() [RFC] David Howells
2013-04-16 21:39   ` Mauro Carvalho Chehab
2013-04-17  0:58   ` Greg KH
2013-04-16 18:26 ` [PATCH 11/28] rtl8187se: Use a dir under /proc/net/r8180/ [RFC] David Howells
2013-04-17  0:59   ` Greg KH
2013-04-16 18:26 ` [PATCH 12/28] rtl8192u: Don't need to save device proc dir PDE [RFC] David Howells
2013-04-17  1:00   ` Greg KH
2013-04-16 18:26 ` [PATCH 13/28] airo: Use remove_proc_subtree() [RFC] David Howells
2013-04-16 18:26 ` [PATCH 14/28] proc: Supply an accessor for getting the data from a PDE's parent [RFC] David Howells
2013-04-17  1:01   ` Greg KH
2013-04-16 18:26 ` [PATCH 15/28] reiserfs: Don't access the proc_dir_entry in r_open(), r_start() r_show() [RFC] David Howells
2013-04-16 18:26 ` [PATCH 16/28] zoran: Don't print proc_dir_entry data in debug [RFC] David Howells
2013-04-16 21:32   ` Mauro Carvalho Chehab
2013-04-16 18:26 ` [PATCH 17/28] drm: Constify drm_proc_list[] [RFC] David Howells
2013-04-16 18:27 ` [PATCH 18/28] drm: proc: Use minor->index to label things, not PDE->name [RFC] David Howells
2013-04-16 18:27 ` [PATCH 19/28] drm: proc: Use remove_proc_subtree() [RFC] David Howells
2013-04-16 18:27 ` [PATCH 20/28] hostap: " David Howells
2013-04-16 18:27 ` David Howells [this message]
2013-04-17  1:02   ` [PATCH 21/28] dgrp: Clean up the use of procfs [RFC] Greg KH
2013-04-16 18:27 ` [PATCH 22/28] ppc: Clean up rtas_flash driver somewhat [RFC] David Howells
2013-04-25 14:33   ` Vasant Hegde
2013-04-16 18:27 ` [PATCH 23/28] ppc: Clean up scanlog [RFC] David Howells
2013-04-25 15:01   ` Vasant Hegde
2013-04-16 18:27 ` [PATCH 24/28] proc: Supply an accessor to get the name in a proc_dir_entry struct [RFC] David Howells
2013-04-16 22:20   ` Harald Welte
2013-04-16 18:27 ` [PATCH 25/28] proc: Supply an accessor to get the process ID associated with some proc files [RFC] David Howells
2013-04-17  1:53   ` Li Zefan
2013-04-18 18:39   ` Tejun Heo
2013-04-16 18:27 ` [PATCH 26/28] proc: Supply a function to remove a proc entry by PDE [RFC] David Howells
2013-04-17 15:03   ` Grant Likely
2013-04-18 16:41   ` Bjorn Helgaas
2013-04-18 20:34   ` David Howells
2013-04-21 22:01   ` Rafael J. Wysocki
2013-04-16 18:27 ` [PATCH 27/28] proc: Make the PROC_I() and PDE() macros internal to procfs [RFC] David Howells
2013-04-16 18:27 ` [PATCH 28/28] proc: Move non-public stuff from linux/proc_fs.h to fs/proc/internal.h [RFC] David Howells
2013-05-01 20:51 ` [PATCH 00/28] Privatise procfs internals [RFC] Geert Uytterhoeven
2013-05-03 20:27   ` Geert Uytterhoeven

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130416182713.27773.66239.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tt.rantala@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    --cc=wfp5p@virginia.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®