All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_fsr: use /proc/mounts if available
@ 2010-09-12 16:34 Christoph Hellwig
  2010-09-13  4:35 ` Eric Sandeen
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2010-09-12 16:34 UTC (permalink / raw)
  To: xfs

Prefer /proc/mounts if it exists over /etc/mtab to get a correct picture
of the kernels mount table for this process.  This works arounds some
userspace like pam_mount polluting /etc/mtab with incorrect entries.

Also remove the "mtab" global variable and instead pass it explicitly
to fsrallfs, like we already do for other functions.

Signed-off-by: Christoph Hellwig <hch@lst.de>

Index: xfsprogs-dev/fsr/xfs_fsr.c
===================================================================
--- xfsprogs-dev.orig/fsr/xfs_fsr.c	2010-09-11 20:06:15.000000000 +0000
+++ xfsprogs-dev/fsr/xfs_fsr.c	2010-09-12 16:28:17.000000000 +0000
@@ -42,7 +42,9 @@
 #define XFS_XFLAG_NODEFRAG 0x00002000 /* src dependancy, remove later */
 #endif
 
-#define _PATH_FSRLAST	"/var/tmp/.fsrlast_xfs"
+#define _PATH_FSRLAST		"/var/tmp/.fsrlast_xfs"
+#define _PATH_PROC_MOUNTS	"/proc/mounts"
+
 
 char *progname;
 
@@ -79,7 +81,6 @@ static __int64_t	minimumfree = 2048;
 
 static time_t howlong = 7200;		/* default seconds of reorganizing */
 static char *leftofffile = _PATH_FSRLAST; /* where we left off last */
-static char *mtab = MOUNTED;
 static time_t endtime;
 static time_t starttime;
 static xfs_ino_t	leftoffino = 0;
@@ -94,7 +95,7 @@ static int  packfile(char *fname, char *
 static void fsrdir(char *dirname);
 static int  fsrfs(char *mntdir, xfs_ino_t ino, int targetrange);
 static void initallfs(char *mtab);
-static void fsrallfs(int howlong, char *leftofffile);
+static void fsrallfs(char *mtab, int howlong, char *leftofffile);
 static void fsrall_cleanup(int timeout);
 static int  getnextents(int);
 int xfsrtextsize(int fd);
@@ -187,6 +188,7 @@ main(int argc, char **argv)
 	struct mntent mntpref;
 	register struct mntent *mntp;
 	struct mntent ment;
+	char *mtab = NULL;
 	register FILE *mtabp;
 
 	setlinebuf(stdout);
@@ -198,7 +200,7 @@ main(int argc, char **argv)
 
 	gflag = ! isatty(0);
 
-	while ((c = getopt(argc, argv, "C:p:e:MgsdnvTt:f:m:b:N:FV")) != -1 )
+	while ((c = getopt(argc, argv, "C:p:e:MgsdnvTt:f:m:b:N:FV")) != -1) {
 		switch (c) {
 		case 'M':
 			Mflag = 1;
@@ -250,6 +252,22 @@ main(int argc, char **argv)
 		default:
 			usage(1);
 		}
+	}
+
+	/*
+	 * If the user did not specify an explicit mount table, try to use
+	 * /proc/mounts if it is available, else /etc/mtab.  We prefer
+	 * /proc/mounts because it is kernel controlled, while /etc/mtab
+	 * may contain garbage that userspace tools like pam_mounts wrote
+	 * into it.
+	 */
+	if (!mtab) {
+		if (access(_PATH_PROC_MOUNTS, R_OK) == 0)
+			mtab = _PATH_PROC_MOUNTS;
+		else
+			mtab = _PATH_MOUNTED;
+	}
+
 	if (vflag)
 		setbuf(stdout, NULL);
 
@@ -330,7 +348,7 @@ main(int argc, char **argv)
 		}
 	} else {
 		initallfs(mtab);
-		fsrallfs(howlong, leftofffile);
+		fsrallfs(mtab, howlong, leftofffile);
 	}
 	return 0;
 }
@@ -447,7 +465,7 @@ initallfs(char *mtab)
 }
 
 static void
-fsrallfs(int howlong, char *leftofffile)
+fsrallfs(char *mtab, int howlong, char *leftofffile)
 {
 	int fd;
 	int error;

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] xfs_fsr: use /proc/mounts if available
  2010-09-12 16:34 [PATCH] xfs_fsr: use /proc/mounts if available Christoph Hellwig
@ 2010-09-13  4:35 ` Eric Sandeen
  0 siblings, 0 replies; 2+ messages in thread
From: Eric Sandeen @ 2010-09-13  4:35 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: xfs

Christoph Hellwig wrote:
> Prefer /proc/mounts if it exists over /etc/mtab to get a correct picture
> of the kernels mount table for this process.  This works arounds some
> userspace like pam_mount polluting /etc/mtab with incorrect entries.
> 
> Also remove the "mtab" global variable and instead pass it explicitly
> to fsrallfs, like we already do for other functions.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Eric Sandeen <sandeen@sandeen.net>

> Index: xfsprogs-dev/fsr/xfs_fsr.c
> ===================================================================
> --- xfsprogs-dev.orig/fsr/xfs_fsr.c	2010-09-11 20:06:15.000000000 +0000
> +++ xfsprogs-dev/fsr/xfs_fsr.c	2010-09-12 16:28:17.000000000 +0000
> @@ -42,7 +42,9 @@
>  #define XFS_XFLAG_NODEFRAG 0x00002000 /* src dependancy, remove later */
>  #endif
>  
> -#define _PATH_FSRLAST	"/var/tmp/.fsrlast_xfs"
> +#define _PATH_FSRLAST		"/var/tmp/.fsrlast_xfs"
> +#define _PATH_PROC_MOUNTS	"/proc/mounts"
> +
>  
>  char *progname;
>  
> @@ -79,7 +81,6 @@ static __int64_t	minimumfree = 2048;
>  
>  static time_t howlong = 7200;		/* default seconds of reorganizing */
>  static char *leftofffile = _PATH_FSRLAST; /* where we left off last */
> -static char *mtab = MOUNTED;
>  static time_t endtime;
>  static time_t starttime;
>  static xfs_ino_t	leftoffino = 0;
> @@ -94,7 +95,7 @@ static int  packfile(char *fname, char *
>  static void fsrdir(char *dirname);
>  static int  fsrfs(char *mntdir, xfs_ino_t ino, int targetrange);
>  static void initallfs(char *mtab);
> -static void fsrallfs(int howlong, char *leftofffile);
> +static void fsrallfs(char *mtab, int howlong, char *leftofffile);
>  static void fsrall_cleanup(int timeout);
>  static int  getnextents(int);
>  int xfsrtextsize(int fd);
> @@ -187,6 +188,7 @@ main(int argc, char **argv)
>  	struct mntent mntpref;
>  	register struct mntent *mntp;
>  	struct mntent ment;
> +	char *mtab = NULL;
>  	register FILE *mtabp;
>  
>  	setlinebuf(stdout);
> @@ -198,7 +200,7 @@ main(int argc, char **argv)
>  
>  	gflag = ! isatty(0);
>  
> -	while ((c = getopt(argc, argv, "C:p:e:MgsdnvTt:f:m:b:N:FV")) != -1 )
> +	while ((c = getopt(argc, argv, "C:p:e:MgsdnvTt:f:m:b:N:FV")) != -1) {
>  		switch (c) {
>  		case 'M':
>  			Mflag = 1;
> @@ -250,6 +252,22 @@ main(int argc, char **argv)
>  		default:
>  			usage(1);
>  		}
> +	}
> +
> +	/*
> +	 * If the user did not specify an explicit mount table, try to use
> +	 * /proc/mounts if it is available, else /etc/mtab.  We prefer
> +	 * /proc/mounts because it is kernel controlled, while /etc/mtab
> +	 * may contain garbage that userspace tools like pam_mounts wrote
> +	 * into it.
> +	 */
> +	if (!mtab) {
> +		if (access(_PATH_PROC_MOUNTS, R_OK) == 0)
> +			mtab = _PATH_PROC_MOUNTS;
> +		else
> +			mtab = _PATH_MOUNTED;
> +	}
> +
>  	if (vflag)
>  		setbuf(stdout, NULL);
>  
> @@ -330,7 +348,7 @@ main(int argc, char **argv)
>  		}
>  	} else {
>  		initallfs(mtab);
> -		fsrallfs(howlong, leftofffile);
> +		fsrallfs(mtab, howlong, leftofffile);
>  	}
>  	return 0;
>  }
> @@ -447,7 +465,7 @@ initallfs(char *mtab)
>  }
>  
>  static void
> -fsrallfs(int howlong, char *leftofffile)
> +fsrallfs(char *mtab, int howlong, char *leftofffile)
>  {
>  	int fd;
>  	int error;
> 
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
> 

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-09-13  4:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-12 16:34 [PATCH] xfs_fsr: use /proc/mounts if available Christoph Hellwig
2010-09-13  4:35 ` Eric Sandeen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.