Blame SOURCES/autofs-5.0.8-change-walk_tree-to-take-ap.patch

4d476f
autofs-5.0.8 - change walk_tree() to take ap
4d476f
4d476f
From: Ian Kent <raven@themaw.net>
4d476f
4d476f
Change walk_tree() to take an autofs_point pointer instead of
4d476f
logopt.
4d476f
---
4d476f
 CHANGELOG           |    1 +
4d476f
 daemon/automount.c  |   49 +++++++++++++++++++++++++++++--------------------
4d476f
 daemon/direct.c     |    2 +-
4d476f
 daemon/indirect.c   |    6 +++---
4d476f
 include/automount.h |    4 ++--
4d476f
 5 files changed, 36 insertions(+), 26 deletions(-)
4d476f
4d476f
--- autofs-5.0.7.orig/CHANGELOG
4d476f
+++ autofs-5.0.7/CHANGELOG
4d476f
@@ -90,6 +90,7 @@
4d476f
 - fix master map type check.
4d476f
 - fix bad mkdir permission on create.
4d476f
 - fix macro_addvar() and move init to main thread.
4d476f
+- change walk_tree() to take ap.
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
@@ -254,10 +254,12 @@ int rmdir_path(struct autofs_point *ap,
4d476f
 /* Like ftw, except fn gets called twice: before a directory is
4d476f
    entered, and after.  If the before call returns 0, the directory
4d476f
    isn't entered. */
4d476f
-static int walk_tree(const char *base, int (*fn) (unsigned logopt,
4d476f
+static int walk_tree(const char *base, int (*fn) (struct autofs_point *ap,
4d476f
 						  const char *file,
4d476f
 						  const struct stat * st,
4d476f
-						  int, void *), int incl, unsigned logopt, void *arg)
4d476f
+						  int, void *), int incl,
4d476f
+						  struct autofs_point *ap,
4d476f
+						  void *arg)
4d476f
 {
4d476f
 	char buf[PATH_MAX + 1];
4d476f
 	struct stat st, *pst = &st;
4d476f
@@ -270,7 +272,7 @@ static int walk_tree(const char *base, i
4d476f
 		ret = 0;
4d476f
 	}
4d476f
 
4d476f
-	if (ret != -1 && (fn) (logopt, base, pst, 0, arg)) {
4d476f
+	if (ret != -1 && (fn) (ap, base, pst, 0, arg)) {
4d476f
 		if (S_ISDIR(st.st_mode)) {
4d476f
 			struct dirent **de;
4d476f
 			int n;
4d476f
@@ -298,18 +300,20 @@ static int walk_tree(const char *base, i
4d476f
 					return -1;
4d476f
 				}
4d476f
 
4d476f
-				walk_tree(buf, fn, 1, logopt, arg);
4d476f
+				walk_tree(buf, fn, 1, ap, arg);
4d476f
 				free(de[n]);
4d476f
 			}
4d476f
 			free(de);
4d476f
 		}
4d476f
 		if (incl)
4d476f
-			(fn) (logopt, base, pst, 1, arg);
4d476f
+			(fn) (ap, base, pst, 1, arg);
4d476f
 	}
4d476f
 	return 0;
4d476f
 }
4d476f
 
4d476f
-static int rm_unwanted_fn(unsigned logopt, const char *file, const struct stat *st, int when, void *arg)
4d476f
+static int rm_unwanted_fn(struct autofs_point *ap,
4d476f
+			  const char *file, const struct stat *st,
4d476f
+			  int when, void *arg)
4d476f
 {
4d476f
 	dev_t dev = *(dev_t *) arg;
4d476f
 	char buf[MAX_ERR_BUF];
4d476f
@@ -325,38 +329,40 @@ static int rm_unwanted_fn(unsigned logop
4d476f
 	}
4d476f
 
4d476f
 	if (lstat(file, &newst)) {
4d476f
-		crit(logopt, "unable to stat file, possible race condition");
4d476f
+		crit(ap->logopt,
4d476f
+		     "unable to stat file, possible race condition");
4d476f
 		return 0;
4d476f
 	}
4d476f
 
4d476f
 	if (newst.st_dev != dev) {
4d476f
-		crit(logopt, "file %s has the wrong device, possible race condition",
4d476f
+		crit(ap->logopt,
4d476f
+		     "file %s has the wrong device, possible race condition",
4d476f
 		     file);
4d476f
 		return 0;
4d476f
 	}
4d476f
 
4d476f
 	if (S_ISDIR(newst.st_mode)) {
4d476f
-		debug(logopt, "removing directory %s", file);
4d476f
+		debug(ap->logopt, "removing directory %s", file);
4d476f
 		if (rmdir(file)) {
4d476f
 			char *estr = strerror_r(errno, buf, MAX_ERR_BUF);
4d476f
-			warn(logopt,
4d476f
+			warn(ap->logopt,
4d476f
 			      "unable to remove directory %s: %s", file, estr);
4d476f
 			return 0;
4d476f
 		}
4d476f
 	} else if (S_ISREG(newst.st_mode)) {
4d476f
-		crit(logopt, "attempting to remove files from a mounted "
4d476f
+		crit(ap->logopt, "attempting to remove files from a mounted "
4d476f
 		     "directory. file %s", file);
4d476f
 		return 0;
4d476f
 	} else if (S_ISLNK(newst.st_mode)) {
4d476f
-		debug(logopt, "removing symlink %s", file);
4d476f
+		debug(ap->logopt, "removing symlink %s", file);
4d476f
 		unlink(file);
4d476f
 	}
4d476f
 	return 1;
4d476f
 }
4d476f
 
4d476f
-void rm_unwanted(unsigned logopt, const char *path, int incl, dev_t dev)
4d476f
+void rm_unwanted(struct autofs_point *ap, const char *path, int incl)
4d476f
 {
4d476f
-	walk_tree(path, rm_unwanted_fn, incl, logopt, &dev;;
4d476f
+	walk_tree(path, rm_unwanted_fn, incl, ap, &ap->dev);
4d476f
 }
4d476f
 
4d476f
 struct counter_args {
4d476f
@@ -364,7 +370,8 @@ struct counter_args {
4d476f
 	dev_t dev;
4d476f
 };
4d476f
 
4d476f
-static int counter_fn(unsigned logopt, const char *file, const struct stat *st, int when, void *arg)
4d476f
+static int counter_fn(struct autofs_point *ap, const char *file,
4d476f
+		      const struct stat *st, int when, void *arg)
4d476f
 {
4d476f
 	struct counter_args *counter = (struct counter_args *) arg;
4d476f
 
4d476f
@@ -378,14 +385,14 @@ static int counter_fn(unsigned logopt, c
4d476f
 }
4d476f
 
4d476f
 /* Count mounted filesystems and symlinks */
4d476f
-int count_mounts(unsigned logopt, const char *path, dev_t dev)
4d476f
+int count_mounts(struct autofs_point *ap, const char *path, dev_t dev)
4d476f
 {
4d476f
 	struct counter_args counter;
4d476f
 
4d476f
 	counter.count = 0;
4d476f
 	counter.dev = dev;
4d476f
 	
4d476f
-	if (walk_tree(path, counter_fn, 0, logopt, &counter) == -1)
4d476f
+	if (walk_tree(path, counter_fn, 0, ap, &counter) == -1)
4d476f
 		return -1;
4d476f
 
4d476f
 	return counter.count;
4d476f
@@ -409,9 +416,9 @@ static void check_rm_dirs(struct autofs_
4d476f
 	    (ap->state == ST_SHUTDOWN_PENDING ||
4d476f
 	     ap->state == ST_SHUTDOWN_FORCE ||
4d476f
 	     ap->state == ST_SHUTDOWN))
4d476f
-		rm_unwanted(ap->logopt, path, incl, ap->dev);
4d476f
+		rm_unwanted(ap, path, incl);
4d476f
 	else if ((ap->flags & MOUNT_FLAG_GHOST) && (ap->type == LKP_INDIRECT))
4d476f
-		rm_unwanted(ap->logopt, path, 0, ap->dev);
4d476f
+		rm_unwanted(ap, path, 0);
4d476f
 }
4d476f
 
4d476f
 /* Try to purge cache entries kept around due to existing mounts */
4d476f
@@ -553,7 +560,9 @@ int umount_multi(struct autofs_point *ap
4d476f
 	left += umount_subtree_mounts(ap, path, is_autofs_fs);
4d476f
 
4d476f
 	/* Delete detritus like unwanted mountpoints and symlinks */
4d476f
-	if (left == 0 && ap->state != ST_READMAP) {
4d476f
+	if (left == 0 &&
4d476f
+	    ap->state != ST_READMAP &&
4d476f
+	    !count_mounts(ap, path, ap->dev)) {
4d476f
 		update_map_cache(ap, path);
4d476f
 		check_rm_dirs(ap, path, incl);
4d476f
 	}
4d476f
--- autofs-5.0.7.orig/daemon/direct.c
4d476f
+++ autofs-5.0.7/daemon/direct.c
4d476f
@@ -912,7 +912,7 @@ void *expire_proc_direct(void *arg)
4d476f
 			cache_writelock(me->mc);
4d476f
 			if (me->ioctlfd != -1 && 
4d476f
 			    fstat(me->ioctlfd, &st) != -1 &&
4d476f
-			    !count_mounts(ap->logopt, next->path, st.st_dev)) {
4d476f
+			    !count_mounts(ap, next->path, st.st_dev)) {
4d476f
 				ops->close(ap->logopt, me->ioctlfd);
4d476f
 				me->ioctlfd = -1;
4d476f
 				cache_unlock(me->mc);
4d476f
--- autofs-5.0.7.orig/daemon/indirect.c
4d476f
+++ autofs-5.0.7/daemon/indirect.c
4d476f
@@ -365,7 +365,7 @@ force_umount:
4d476f
 	} else {
4d476f
 		info(ap->logopt, "umounted indirect mount %s", mountpoint);
4d476f
 		if (ap->submount)
4d476f
-			rm_unwanted(ap->logopt, mountpoint, 1, ap->dev);
4d476f
+			rm_unwanted(ap, mountpoint, 1);
4d476f
 	}
4d476f
 
4d476f
 	return rv;
4d476f
@@ -476,7 +476,7 @@ void *expire_proc_indirect(void *arg)
4d476f
 
4d476f
 				/* Check for manual umount */
4d476f
 				if (fstat(me->ioctlfd, &st) == -1 ||
4d476f
-				    !count_mounts(ap->logopt, me->key, st.st_dev)) {
4d476f
+				    !count_mounts(ap, me->key, st.st_dev)) {
4d476f
 					ops->close(ap->logopt, me->ioctlfd);
4d476f
 					me->ioctlfd = -1;
4d476f
 				}
4d476f
@@ -538,7 +538,7 @@ void *expire_proc_indirect(void *arg)
4d476f
 	 * so we need to umount or unlink them here.
4d476f
 	 */
4d476f
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
4d476f
-	retries = (count_mounts(ap->logopt, ap->path, ap->dev) + 1);
4d476f
+	retries = (count_mounts(ap, ap->path, ap->dev) + 1);
4d476f
 	while (retries--) {
4d476f
 		ret = ops->expire(ap->logopt, ap->ioctlfd, ap->path, now);
4d476f
 		if (ret)
4d476f
--- autofs-5.0.7.orig/include/automount.h
4d476f
+++ autofs-5.0.7/include/automount.h
4d476f
@@ -526,8 +526,8 @@ int handle_packet_expire_indirect(struct
4d476f
 int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_direct_t *pkt);
4d476f
 int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missing_indirect_t *pkt);
4d476f
 int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_direct_t *pkt);
4d476f
-void rm_unwanted(unsigned logopt, const char *path, int incl, dev_t dev);
4d476f
-int count_mounts(unsigned logopt, const char *path, dev_t dev);
4d476f
+void rm_unwanted(struct autofs_point *ap, const char *path, int incl);
4d476f
+int count_mounts(struct autofs_point *ap, const char *path, dev_t dev);
4d476f
 
4d476f
 #define mounts_mutex_lock(ap) \
4d476f
 do { \