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

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