linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Carmeli Tamir <carmeli.tamir@gmail.com>
To: carmeli.tamir@gmail.com, viro@zeniv.linux.org.uk,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] Use list.h instead of file_system_type next
Date: Sat,  4 May 2019 05:45:48 -0400	[thread overview]
Message-ID: <20190504094549.10021-2-carmeli.tamir@gmail.com> (raw)
In-Reply-To: <20190504094549.10021-1-carmeli.tamir@gmail.com>

From: Tamir <carmeli.tamir@gmail.com>

Changed file_system_type next field to list_head and refactored
the code to use list.h functions.

Signed-off-by: Carmeli Tamir <carmeli.tamir@gmail.com>
---
 fs/filesystems.c   | 68 ++++++++++++++++++++++++----------------------
 include/linux/fs.h |  2 +-
 2 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/fs/filesystems.c b/fs/filesystems.c
index 9135646e41ac..f12b98f2f079 100644
--- a/fs/filesystems.c
+++ b/fs/filesystems.c
@@ -31,7 +31,7 @@
  *	Once the reference is obtained we can drop the spinlock.
  */
 
-static struct file_system_type *file_systems;
+static LIST_HEAD(file_systems);
 static DEFINE_RWLOCK(file_systems_lock);
 
 /* WARNING: This can be used only if we _already_ own a reference */
@@ -46,14 +46,16 @@ void put_filesystem(struct file_system_type *fs)
 	module_put(fs->owner);
 }
 
-static struct file_system_type **find_filesystem(const char *name, unsigned len)
+static struct file_system_type *find_filesystem(const char *name, unsigned len)
 {
-	struct file_system_type **p;
-	for (p = &file_systems; *p; p = &(*p)->next)
-		if (strncmp((*p)->name, name, len) == 0 &&
-		    !(*p)->name[len])
-			break;
-	return p;
+	struct file_system_type *p;
+
+	list_for_each_entry(p, &file_systems, fs_types) {
+		if (strncmp(p->name, name, len) == 0 &&
+		    !p->name[len])
+			return p;
+	}
+	return NULL;
 }
 
 /**
@@ -72,20 +74,21 @@ static struct file_system_type **find_filesystem(const char *name, unsigned len)
 int register_filesystem(struct file_system_type * fs)
 {
 	int res = 0;
-	struct file_system_type ** p;
+	struct file_system_type *p;
 
 	if (fs->parameters && !fs_validate_description(fs->parameters))
 		return -EINVAL;
 
 	BUG_ON(strchr(fs->name, '.'));
-	if (fs->next)
-		return -EBUSY;
+
+	INIT_LIST_HEAD(&fs->fs_types);
+
 	write_lock(&file_systems_lock);
 	p = find_filesystem(fs->name, strlen(fs->name));
-	if (*p)
+	if (p)
 		res = -EBUSY;
 	else
-		*p = fs;
+		list_add_tail(&fs->fs_types, &file_systems);
 	write_unlock(&file_systems_lock);
 	return res;
 }
@@ -106,19 +109,16 @@ EXPORT_SYMBOL(register_filesystem);
  
 int unregister_filesystem(struct file_system_type * fs)
 {
-	struct file_system_type ** tmp;
+	struct file_system_type *tmp;
 
 	write_lock(&file_systems_lock);
-	tmp = &file_systems;
-	while (*tmp) {
-		if (fs == *tmp) {
-			*tmp = fs->next;
-			fs->next = NULL;
+	list_for_each_entry(tmp, &file_systems, fs_types) {
+		if (fs == tmp) {
+			list_del(&tmp->fs_types);
 			write_unlock(&file_systems_lock);
 			synchronize_rcu();
 			return 0;
 		}
-		tmp = &(*tmp)->next;
 	}
 	write_unlock(&file_systems_lock);
 
@@ -141,7 +141,8 @@ static int fs_index(const char __user * __name)
 
 	err = -EINVAL;
 	read_lock(&file_systems_lock);
-	for (tmp=file_systems, index=0 ; tmp ; tmp=tmp->next, index++) {
+	list_for_each_entry(tmp, &file_systems, fs_types) {
+		index++;
 		if (strcmp(tmp->name, name->name) == 0) {
 			err = index;
 			break;
@@ -158,9 +159,11 @@ static int fs_name(unsigned int index, char __user * buf)
 	int len, res;
 
 	read_lock(&file_systems_lock);
-	for (tmp = file_systems; tmp; tmp = tmp->next, index--)
+	list_for_each_entry(tmp, &file_systems, fs_types) {
+		index--;
 		if (index <= 0 && try_module_get(tmp->owner))
 			break;
+	}
 	read_unlock(&file_systems_lock);
 	if (!tmp)
 		return -EINVAL;
@@ -174,12 +177,13 @@ static int fs_name(unsigned int index, char __user * buf)
 
 static int fs_maxindex(void)
 {
-	struct file_system_type * tmp;
-	int index;
+	struct list_head *pos;
+	int index = 0;
 
 	read_lock(&file_systems_lock);
-	for (tmp = file_systems, index = 0 ; tmp ; tmp = tmp->next, index++)
-		;
+	list_for_each(pos, &file_systems) {
+		index++;
+	}
 	read_unlock(&file_systems_lock);
 	return index;
 }
@@ -214,12 +218,12 @@ int __init get_filesystem_list(char *buf)
 	struct file_system_type * tmp;
 
 	read_lock(&file_systems_lock);
-	tmp = file_systems;
-	while (tmp && len < PAGE_SIZE - 80) {
+	list_for_each_entry(tmp, &file_systems, fs_types) {
+		if (len >= PAGE_SIZE - 80)
+			break;
 		len += sprintf(buf+len, "%s\t%s\n",
 			(tmp->fs_flags & FS_REQUIRES_DEV) ? "" : "nodev",
 			tmp->name);
-		tmp = tmp->next;
 	}
 	read_unlock(&file_systems_lock);
 	return len;
@@ -231,12 +235,10 @@ static int filesystems_proc_show(struct seq_file *m, void *v)
 	struct file_system_type * tmp;
 
 	read_lock(&file_systems_lock);
-	tmp = file_systems;
-	while (tmp) {
+	list_for_each_entry(tmp, &file_systems, fs_types) {
 		seq_printf(m, "%s\t%s\n",
 			(tmp->fs_flags & FS_REQUIRES_DEV) ? "" : "nodev",
 			tmp->name);
-		tmp = tmp->next;
 	}
 	read_unlock(&file_systems_lock);
 	return 0;
@@ -255,7 +257,7 @@ static struct file_system_type *__get_fs_type(const char *name, int len)
 	struct file_system_type *fs;
 
 	read_lock(&file_systems_lock);
-	fs = *(find_filesystem(name, len));
+	fs = find_filesystem(name, len);
 	if (fs && !try_module_get(fs->owner))
 		fs = NULL;
 	read_unlock(&file_systems_lock);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index dd28e7679089..833ada15bc8a 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2182,7 +2182,7 @@ struct file_system_type {
 		       const char *, void *);
 	void (*kill_sb) (struct super_block *);
 	struct module *owner;
-	struct file_system_type * next;
+	struct list_head fs_types; /* All registered file_system_type structs */
 	struct hlist_head fs_supers;
 
 	struct lock_class_key s_lock_key;
-- 
2.19.1


  reply	other threads:[~2019-05-04  9:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-04  9:45 [PATCH 0/2] Refactor file_systems to use the kernel's list Carmeli Tamir
2019-05-04  9:45 ` Carmeli Tamir [this message]
2019-05-04 13:20   ` [PATCH 1/2] Use list.h instead of file_system_type next Al Viro
2019-05-04 13:45   ` Matthew Wilcox
2019-05-05 18:25     ` Tamir Carmeli
2019-05-06  2:49       ` Matthew Wilcox
2019-05-06 15:16   ` kbuild test robot
2019-05-06 17:33   ` kbuild test robot
2019-05-04  9:45 ` [PATCH 2/2] Changed unsigned param type to unsigned int Carmeli Tamir

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=20190504094549.10021-2-carmeli.tamir@gmail.com \
    --to=carmeli.tamir@gmail.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).