Blame SOURCES/autofs-5.1.1-improve-scalability-of-direct-mount-path-component-creation.patch

4d476f
autofs-5.1.1 - improve scalability of direct mount path component
4d476f
4d476f
From: Jeff Mahoney <jeffm@suse.com>
4d476f
4d476f
With direct mounts, we want to avoid creating path components on
4d476f
remote file systems unless that file system is the root file system.
4d476f
4d476f
The check boils down to allowing the mkdir if:
4d476f
1/ If it's the root directory, or
4d476f
2/ If it's not a remote file system, or
4d476f
3/ If it's a remote file system that's the root file system
4d476f
4d476f
We can do that without parsing the mount table and can
4d476f
improve startup time for all cases.
4d476f
4d476f
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
4d476f
Signed-off-by: Ian Kent <raven@themaw.net>
4d476f
---
4d476f
 CHANGELOG           |    1 
4d476f
 daemon/automount.c  |   56 +++++++++++++++++++++++++++++++++++++++-------------
4d476f
 include/automount.h |    2 +
4d476f
 include/mounts.h    |    1 
4d476f
 lib/mounts.c        |   45 -----------------------------------------
4d476f
 5 files changed, 45 insertions(+), 60 deletions(-)
4d476f
4d476f
--- autofs-5.0.7.orig/CHANGELOG
4d476f
+++ autofs-5.0.7/CHANGELOG
4d476f
@@ -245,6 +245,7 @@
4d476f
 - use autofs_point to store expire timeout where possibe.
4d476f
 - fix possible NULL derefernce.
4d476f
 - fix work around sss startup delay.
4d476f
+- improve scalability of direct mount path component.
4d476f
 
4d476f
 25/07/2012 autofs-5.0.7
4d476f
 =======================
4d476f
--- autofs-5.0.7.orig/daemon/automount.c
4d476f
+++ autofs-5.0.7/daemon/automount.c
4d476f
@@ -135,10 +135,25 @@ void set_thread_mount_request_log_id(str
4d476f
 	}
4d476f
 }
4d476f
 
4d476f
+static int is_remote_fstype(unsigned int fs_type)
4d476f
+{
4d476f
+	int ret = 0;
4d476f
+	switch (fs_type) {
4d476f
+	case SMB_SUPER_MAGIC:
4d476f
+	case CIFS_MAGIC_NUMBER:
4d476f
+	case NCP_SUPER_MAGIC:
4d476f
+	case NFS_SUPER_MAGIC:
4d476f
+		ret = 1;
4d476f
+		break;
4d476f
+	};
4d476f
+	return ret;
4d476f
+}
4d476f
+
4d476f
 static int do_mkdir(const char *parent, const char *path, mode_t mode)
4d476f
 {
4d476f
 	int status;
4d476f
-	struct stat st;
4d476f
+	mode_t mask;
4d476f
+	struct stat st, root;
4d476f
 	struct statfs fs;
4d476f
 
4d476f
 	/* If path exists we're done */
4d476f
@@ -151,24 +166,37 @@ static int do_mkdir(const char *parent,
4d476f
 	}
4d476f
 
4d476f
 	/*
4d476f
-	 * If we're trying to create a directory within an autofs fs
4d476f
-	 * or the path is contained in a localy mounted fs go ahead.
4d476f
+	 * We don't want to create the path on a remote file system
4d476f
+	 * unless it's the root file system.
4d476f
+	 * An empty parent means it's the root directory and always ok.
4d476f
 	 */
4d476f
-	status = -1;
4d476f
-	if (*parent)
4d476f
+	if (*parent) {
4d476f
 		status = statfs(parent, &fs);
4d476f
-	if ((status != -1 && fs.f_type == (__SWORD_TYPE) AUTOFS_SUPER_MAGIC) ||
4d476f
-	    contained_in_local_fs(path)) {
4d476f
-		mode_t mask = umask(0022);
4d476f
-		int ret = mkdir(path, mode);
4d476f
-		(void) umask(mask);
4d476f
-		if (ret == -1) {
4d476f
-			errno = EACCES;
4d476f
-			return 0;
4d476f
+		if (status == -1)
4d476f
+			goto fail;
4d476f
+
4d476f
+		if (is_remote_fstype(fs.f_type)) {
4d476f
+			status = stat(parent, &st);
4d476f
+			if (status == -1)
4d476f
+				goto fail;
4d476f
+
4d476f
+			status = stat("/", &root);
4d476f
+			if (status == -1)
4d476f
+				goto fail;
4d476f
+
4d476f
+			if (st.st_dev != root.st_dev)
4d476f
+				goto fail;
4d476f
 		}
4d476f
-		return 1;
4d476f
 	}
4d476f
 
4d476f
+	mask = umask(0022);
4d476f
+	status = mkdir(path, mode);
4d476f
+	(void) umask(mask);
4d476f
+	if (status == -1)
4d476f
+		goto fail;
4d476f
+
4d476f
+	return 1;
4d476f
+fail:
4d476f
 	errno = EACCES;
4d476f
 	return 0;
4d476f
 }
4d476f
--- autofs-5.0.7.orig/include/automount.h
4d476f
+++ autofs-5.0.7/include/automount.h
4d476f
@@ -75,6 +75,8 @@ int load_autofs4_module(void);
4d476f
 #define AUTOFS_SUPER_MAGIC 0x00000187L
4d476f
 #define SMB_SUPER_MAGIC    0x0000517BL
4d476f
 #define CIFS_MAGIC_NUMBER  0xFF534D42L
4d476f
+#define NCP_SUPER_MAGIC    0x0000564CL
4d476f
+#define NFS_SUPER_MAGIC    0x00006969L
4d476f
 
4d476f
 #define ATTEMPT_ID_SIZE 24
4d476f
 
4d476f
--- autofs-5.0.7.orig/include/mounts.h
4d476f
+++ autofs-5.0.7/include/mounts.h
4d476f
@@ -101,7 +101,6 @@ int ext_mount_remove(struct list_head *,
4d476f
 struct mnt_list *get_mnt_list(const char *table, const char *path, int include);
4d476f
 struct mnt_list *reverse_mnt_list(struct mnt_list *list);
4d476f
 void free_mnt_list(struct mnt_list *list);
4d476f
-int contained_in_local_fs(const char *path);
4d476f
 int is_mounted(const char *table, const char *path, unsigned int type);
4d476f
 int has_fstab_option(const char *opt);
4d476f
 void tree_free_mnt_tree(struct mnt_list *tree);
4d476f
--- autofs-5.0.7.orig/lib/mounts.c
4d476f
+++ autofs-5.0.7/lib/mounts.c
4d476f
@@ -941,51 +941,6 @@ void free_mnt_list(struct mnt_list *list
4d476f
 	}
4d476f
 }
4d476f
 
4d476f
-int contained_in_local_fs(const char *path)
4d476f
-{
4d476f
-	struct mnt_list *mnts, *this;
4d476f
-	size_t pathlen = strlen(path);
4d476f
-	int ret;
4d476f
-
4d476f
-	if (!path || !pathlen || pathlen > PATH_MAX)
4d476f
-		return 0;
4d476f
-
4d476f
-	mnts = get_mnt_list(_PATH_MOUNTED, "/", 1);
4d476f
-	if (!mnts)
4d476f
-		return 0;
4d476f
-
4d476f
-	ret = 0;
4d476f
-
4d476f
-	for (this = mnts; this != NULL; this = this->next) {
4d476f
-		size_t len = strlen(this->path);
4d476f
-
4d476f
-		if (!strncmp(path, this->path, len)) {
4d476f
-			if (len > 1 && pathlen > len && path[len] != '/')
4d476f
-				continue;
4d476f
-			else if (len == 1 && this->path[0] == '/') {
4d476f
-				/*
4d476f
-				 * always return true on rootfs, we don't
4d476f
-				 * want to break diskless clients.
4d476f
-				 */
4d476f
-				ret = 1;
4d476f
-			} else if (this->fs_name[0] == '/') {
4d476f
-				if (strlen(this->fs_name) > 1) {
4d476f
-					if (this->fs_name[1] != '/')
4d476f
-						ret = 1;
4d476f
-				} else
4d476f
-					ret = 1;
4d476f
-			} else if (!strncmp("LABEL=", this->fs_name, 6) ||
4d476f
-				   !strncmp("UUID=", this->fs_name, 5))
4d476f
-				ret = 1;
4d476f
-			break;
4d476f
-		}
4d476f
-	}
4d476f
-
4d476f
-	free_mnt_list(mnts);
4d476f
-
4d476f
-	return ret;
4d476f
-}
4d476f
-
4d476f
 static int table_is_mounted(const char *table, const char *path, unsigned int type)
4d476f
 {
4d476f
 	struct mntent *mnt;