All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Luis R. Rodriguez" <mcgrof@do-not-panic.com>
To: backports@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, "Luis R. Rodriguez" <mcgrof@do-not-panic.com>
Subject: [RFC] backports: add remove_proc_subtree() backport
Date: Sun, 12 May 2013 21:31:38 -0700	[thread overview]
Message-ID: <1368419498-15809-1-git-send-email-mcgrof@do-not-panic.com> (raw)

From: "Luis R. Rodriguez" <mcgrof@do-not-panic.com>

Intorduced in next-20130429 and Linus has merged it
onto v3.10-rc1. Backport this for older kernels.

The new in-kernel implementation relies on internal
mechanisms for parent directory parsing and then traversal
but these rely on internal procfs locking primatives which
we cannot use externally. This limits our implementation
with the assumption your procfs implementation is correct.

This implementation uses recursion then if subdirs are found
otherwise it treats it as a regular remove_proc_entry()

commit 8ce584c7416d8a85a6f3edc17d1cddefe331e87e
Author: Al Viro <viro@zeniv.linux.org.uk>
Date:   Sat Mar 30 20:13:46 2013 -0400

    procfs: add proc_remove_subtree()

    just what it sounds like; do that only to procfs subtrees you've
    created - doing that to something shared with another driver is
    not only antisocial, but might cause interesting races with
    proc_create() and its ilk.

    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Cc: viro@zeniv.linux.org.uk
Signed-off-by: Luis R. Rodriguez <mcgrof@do-not-panic.com>
---

Al, I tried to backport remove_proc_subtree() as best as
I could but I am not confident on this solution and would
appreciate a review on your part if possible.

 backport/backport-include/linux/proc_fs.h |    7 +++++
 backport/compat/backport-3.10.c           |   48 +++++++++++++++++++++++++++--
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/backport/backport-include/linux/proc_fs.h b/backport/backport-include/linux/proc_fs.h
index 5a1bec1..a85b4fb 100644
--- a/backport/backport-include/linux/proc_fs.h
+++ b/backport/backport-include/linux/proc_fs.h
@@ -12,6 +12,13 @@ static inline void *PDE_DATA(const struct inode *inode)
 {
 	return PROC_I(inode)->pde->data;
 }
+
+#ifdef CONFIG_PROC_FS
+extern int remove_proc_subtree(const char *name, struct proc_dir_entry *parent);
+#else
+#define remove_proc_subtree(name, parent) do {} while (0)
+#endif /* CONFIG_PROC_FS */
+
 #endif
 
 #endif /* __BACKPORT_PROC_FS_H */
diff --git a/backport/compat/backport-3.10.c b/backport/compat/backport-3.10.c
index 69c3788..0ddffbf 100644
--- a/backport/compat/backport-3.10.c
+++ b/backport/compat/backport-3.10.c
@@ -8,14 +8,17 @@
  * published by the Free Software Foundation.
  */
 
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
 #include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/proc_fs.h>
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
 #include <linux/init.h>
 #include <linux/debugfs.h>
 #include <linux/device.h>
 #include <linux/slab.h>
 #include <linux/async.h>
-#include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/suspend.h>
 #include <linux/delay.h>
@@ -26,8 +29,47 @@
 #include <linux/regulator/consumer.h>
 #include <linux/regulator/driver.h>
 #include <linux/regulator/machine.h>
-#include <linux/module.h>
+#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
+#ifdef CONFIG_PROC_FS
 
+static void backport_proc_subdir_remove(struct proc_dir_entry *dir)
+{
+	struct proc_dir_entry *pe, *tmp;
+	pe = dir->subdir;
+	while (pe) {
+		tmp = pe->next;
+		backport_proc_subdir_remove(pe);
+		remove_proc_entry(pe->name, dir);
+		pe = tmp;
+	}
+};
+
+int remove_proc_subtree(const char *name, struct proc_dir_entry *parent)
+{
+	struct proc_dir_entry *pe, *tmp;
+
+	if (!parent)
+		goto out;
+
+	pe = parent->subdir;
+	while (pe) {
+		tmp = pe->next;
+		backport_proc_subdir_remove(pe);
+		remove_proc_entry(pe->name, parent);
+		pe = tmp;
+	}
+
+out:
+	remove_proc_entry(name, parent);
+
+	return 0;
+}
+#endif /* CONFIG_PROC_FS */
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0))
 /**
  * regulator_map_voltage_ascend - map_voltage() for ascendant voltage list
  *
-- 
1.7.10.4


             reply	other threads:[~2013-05-13  4:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-13  4:31 Luis R. Rodriguez [this message]
2013-05-13  5:03 ` [RFC] backports: add remove_proc_subtree() backport Al Viro
2013-05-13  5:21   ` Luis R. Rodriguez
2013-05-13  5:40     ` Al Viro
2013-05-13  6:14       ` Luis R. Rodriguez

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=1368419498-15809-1-git-send-email-mcgrof@do-not-panic.com \
    --to=mcgrof@do-not-panic.com \
    --cc=backports@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.