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

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