Skip to contentSkip to conversation

Close etab file's file descriptor on stat error.

PATCH In review Malahal Naineni 3 participants 4 messages Oct 28, 2015 – Nov 4, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Close etab file's file descriptor on stat error.

Also, fixed erroneously closing file descriptor 0 at init time.

---
 utils/mountd/auth.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
utils/mountd/auth.c +14 -3
index 330cab5..894a7a5 100644
@@ -85,7 +85,7 @@ auth_reload()
 {
 	struct stat		stb;
 	static ino_t		last_inode;
-	static int		last_fd;
+	static int		last_fd = -1;
 	static unsigned int	counter;
 	int			fd;
 
@@ -93,11 +93,22 @@ auth_reload()
 		xlog(L_FATAL, "couldn't open %s", _PATH_ETAB);
 	} else if (fstat(fd, &stb) < 0) {
 		xlog(L_FATAL, "couldn't stat %s", _PATH_ETAB);
-	} else if (stb.st_ino == last_inode) {
+		close(fd);
+	} else if (last_fd != -1 && stb.st_ino == last_inode) {
+		/* We opened the etab file before, and its inode
+		 * number hasn't changed since then.
+		 */
 		close(fd);
 		return counter;
 	} else {
-		close(last_fd);
+		/* Need to process entries from the etab file.  Close
+		 * the file descriptor from the previous open (last_fd),
+		 * and keep the current file descriptor open to prevent
+		 * the file system reusing the current inode number
+		 * (last_inode).
+		 */
+		if (last_fd != -1)
+			close(last_fd);
 		last_fd = fd;
 		last_inode = stb.st_ino;
 	}
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 1 line · Malahal Naineni

Also, fixed erroneously closing file descriptor 0 at init time.

Thanks, that's interesting. Did that extra close(0) have any user-visible consequences?

Quoted 20 lines
---
 utils/mountd/auth.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
utils/mountd/auth.c +1 -1
index 330cab5..894a7a5 100644
@@ -85,7 +85,7 @@ auth_reload()
 {
 	struct stat		stb;
 	static ino_t		last_inode;
-	static int		last_fd;
+	static int		last_fd = -1;
 	static unsigned int	counter;
 	int			fd;
 

utils/mountd/auth.c auth_reload() · line 97

Quoted 6 lines
utils/mountd/auth.c +2 -1
@@ -93,11 +93,22 @@ auth_reload()
 		xlog(L_FATAL, "couldn't open %s", _PATH_ETAB);
 	} else if (fstat(fd, &stb) < 0) {
 		xlog(L_FATAL, "couldn't stat %s", _PATH_ETAB);
-	} else if (stb.st_ino == last_inode) {
+		close(fd);
+	} else if (last_fd != -1 && stb.st_ino == last_inode) {

I think that (last_fd != -1) is actually unnecessary (basically because last_inode is initially 0, which isn't a legal inode number), but... it's probably clearer this way, OK.

Patch looks OK to me.--b.

Quoted 25 lines
utils/mountd/auth.c +11 -1
+		/* We opened the etab file before, and its inode
+		 * number hasn't changed since then.
+		 */
 		close(fd);
 		return counter;
 	} else {
-		close(last_fd);
+		/* Need to process entries from the etab file.  Close
+		 * the file descriptor from the previous open (last_fd),
+		 * and keep the current file descriptor open to prevent
+		 * the file system reusing the current inode number
+		 * (last_inode).
+		 */
+		if (last_fd != -1)
+			close(last_fd);
 		last_fd = fd;
 		last_inode = stb.st_ino;
 	}
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

I wondered that myself! gdb (of course, running in foreground) showed 0,1,2 as a pty as expected. file descriptor 3 was some socket! Maybe, I will debug it to find out what socket that was and what issues a user could get into!

Regards, Malahal.

Quoted 65 lines · J. Bruce Fields [[email protected]] wrote:
Quoted 1 line · Malahal Naineni

Also, fixed erroneously closing file descriptor 0 at init time.

Thanks, that's interesting. Did that extra close(0) have any user-visible consequences?

Quoted 20 lines
---
 utils/mountd/auth.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
utils/mountd/auth.c +1 -1
index 330cab5..894a7a5 100644
@@ -85,7 +85,7 @@ auth_reload()
 {
 	struct stat		stb;
 	static ino_t		last_inode;
-	static int		last_fd;
+	static int		last_fd = -1;
 	static unsigned int	counter;
 	int			fd;
 

utils/mountd/auth.c auth_reload() · line 97

Quoted 6 lines
utils/mountd/auth.c +2 -1
@@ -93,11 +93,22 @@ auth_reload()
 		xlog(L_FATAL, "couldn't open %s", _PATH_ETAB);
 	} else if (fstat(fd, &stb) < 0) {
 		xlog(L_FATAL, "couldn't stat %s", _PATH_ETAB);
-	} else if (stb.st_ino == last_inode) {
+		close(fd);
+	} else if (last_fd != -1 && stb.st_ino == last_inode) {

I think that (last_fd != -1) is actually unnecessary (basically because last_inode is initially 0, which isn't a legal inode number), but... it's probably clearer this way, OK.

Patch looks OK to me.--b.

Quoted 25 lines
utils/mountd/auth.c +11 -1
+		/* We opened the etab file before, and its inode
+		 * number hasn't changed since then.
+		 */
 		close(fd);
 		return counter;
 	} else {
-		close(last_fd);
+		/* Need to process entries from the etab file.  Close
+		 * the file descriptor from the previous open (last_fd),
+		 * and keep the current file descriptor open to prevent
+		 * the file system reusing the current inode number
+		 * (last_inode).
+		 */
+		if (last_fd != -1)
+			close(last_fd);
 		last_fd = fd;
 		last_inode = stb.st_ino;
 	}
Signature · 6 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
In reply to Malahal Naineni
Quoted 3 lines · Malahal Naineni

Also, fixed erroneously closing file descriptor 0 at init time.

Committed...

steved.

Quoted 43 lines
---
 utils/mountd/auth.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
utils/mountd/auth.c +14 -3
index 330cab5..894a7a5 100644
@@ -85,7 +85,7 @@ auth_reload()
 {
 	struct stat		stb;
 	static ino_t		last_inode;
-	static int		last_fd;
+	static int		last_fd = -1;
 	static unsigned int	counter;
 	int			fd;
 
@@ -93,11 +93,22 @@ auth_reload()
 		xlog(L_FATAL, "couldn't open %s", _PATH_ETAB);
 	} else if (fstat(fd, &stb) < 0) {
 		xlog(L_FATAL, "couldn't stat %s", _PATH_ETAB);
-	} else if (stb.st_ino == last_inode) {
+		close(fd);
+	} else if (last_fd != -1 && stb.st_ino == last_inode) {
+		/* We opened the etab file before, and its inode
+		 * number hasn't changed since then.
+		 */
 		close(fd);
 		return counter;
 	} else {
-		close(last_fd);
+		/* Need to process entries from the etab file.  Close
+		 * the file descriptor from the previous open (last_fd),
+		 * and keep the current file descriptor open to prevent
+		 * the file system reusing the current inode number
+		 * (last_inode).
+		 */
+		if (last_fd != -1)
+			close(last_fd);
 		last_fd = fd;
 		last_inode = stb.st_ino;
 	}