diff mbox

[1/2] procfs: Add function to lookup a subdirectory name

Message ID 1387580357-28440-1-git-send-email-abbas_raza@mentor.com
State New, archived
Headers show

Commit Message

Abbas Raza Dec. 20, 2013, 10:59 p.m. UTC
From: Abbas Raza <Abbas_Raza@mentor.com>

Add function to lookup a subdirectory in a directory by given name

Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Abbas Raza <Abbas_Raza@mentor.com>
---
 fs/proc/generic.c       | 18 ++++++++++++++++++
 include/linux/proc_fs.h |  4 ++++
 2 files changed, 22 insertions(+)

Comments

Theodore Ts'o Dec. 22, 2013, 1:20 a.m. UTC | #1
On Sat, Dec 21, 2013 at 03:59:16AM +0500, Abbas Raza wrote:
>  /*
> + * Lookup if a subdirectory is present in the given directory by name
> + */
> +int proc_lookup_subdir_by_name(struct proc_dir_entry *dir, const char *name)
> +{

I'm not sure this is the best way to solve the problem you are trying
to get at in patch 2/2.  First of all, this solution is fundamentally
racy; the moment you release proc_subdir_lock, there's always a chance
that some other process will come in and create the proc file in the
subdirectory.  Sure, it's not likely in the case of the ext4 use case,
but as a generic function to be added to fs/proc/generic.c, I suspent
Al is going to NACK this.

Secondly, there is a bigger problem that this is papering over, which
is we don't have a good way of dealing with an unclean eject.  If the
the system was in the middle of reading or writing to the file system
at the time of the unclean eject, there will be all sorts of warnings
and file system errors that will be logged.  That's because we don't
have a way for the block device layer to let the file system know that
the block device has disappeared, and we need to revoke open file
descriptors, and accept the fact that any dirty pages in the cache
cache need to be deleted, lest it clog the system memory forever.

Given the larger problem, I have to admit it's hard for me to get
excited about trying to suppress this particular warning message.  If
we are going to do this, it may be better to simply add a new
proc_mkdir_flags() interface which extends proc_mkdir_data() with a
new integer flags parameter, for which we define a new flag, which
suppresses the warning.

Regards,

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index b796da2..e4f2320 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -406,6 +406,24 @@  static const struct dentry_operations proc_dentry_operations =
 };
 
 /*
+ * Lookup if a subdirectory is present in the given directory by name
+ */
+int proc_lookup_subdir_by_name(struct proc_dir_entry *dir, const char *name)
+{
+	struct proc_dir_entry *tmp;
+	int ret = -ENOENT;
+
+	spin_lock(&proc_subdir_lock);
+	for (tmp = dir->subdir; tmp; tmp = tmp->next)
+		if (strcmp(tmp->name, name) == 0)
+			ret = 0;
+	spin_unlock(&proc_subdir_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(proc_lookup_subdir_by_name);
+
+/*
  * Don't create negative dentries here, return -ENOENT by hand
  * instead.
  */
diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
index 32676b3..82acc6c 100644
--- a/include/linux/proc_fs.h
+++ b/include/linux/proc_fs.h
@@ -152,6 +152,8 @@  extern struct proc_dir_entry *proc_symlink(const char *,
 extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
 extern struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
 			struct proc_dir_entry *parent);
+extern int proc_lookup_subdir_by_name(struct proc_dir_entry *,
+			const char *name);
 
 static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
 	struct proc_dir_entry *parent, const struct file_operations *proc_fops)
@@ -213,6 +215,8 @@  static inline struct proc_dir_entry *proc_mkdir(const char *name,
 	struct proc_dir_entry *parent) {return NULL;}
 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
 	umode_t mode, struct proc_dir_entry *parent) { return NULL; }
+static inline int proc_lookup_subdir_by_name(struct proc_dir_entry *,
+			const char *name) { return -ENOENT; }
 
 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
 	umode_t mode, struct proc_dir_entry *base,