Skip to contentSkip to conversation

exportfs: Deal with path's trailing "/" in unexportfs_parsed()

PATCH In review Yongcheng Yang 2 participants 2 messages Dec 7, 2015 – Dec 12, 2015

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

PATCH 1/1 exportfs: Deal with path's trailing "/" in unexportfs_parsed()

From: Yongcheng Yang <[email protected]>

When unexport directory, it's possible that the specified path ends with a '/'. So we need to deal with it to find the matched entry.

If not, there will be error like "Could not find '*:/some_path/' to unexport."

---
 utils/exportfs/exportfs.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
utils/exportfs/exportfs.c +10 -1
index c7a79a6..a9151ff 100644
@@ -405,8 +405,17 @@ unexportfs_parsed(char *hname, char *path, int verbose)
 			hname = ai->ai_canonname;
 	}
 
+	/*
+	 * It's possible the specified path ends with a '/'. But
+	 * the entry from exportlist won't has the trailing '/',
+	 * so need to deal with it.
+	*/
+	size_t nlen = strlen(path);
+	while (path[nlen - 1] == '/')
+		nlen--;
+
 	for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
-		if (path && strcmp(path, exp->m_export.e_path))
+		if (path && strncmp(path, exp->m_export.e_path, nlen))
 			continue;
 		if (htype != exp->m_client->m_type)
 			continue;
Signature · 1 line
2.1.0
#1 lore raw
Quoted 8 lines · Yongcheng Yang

From: Yongcheng Yang <[email protected]>

When unexport directory, it's possible that the specified path ends with a '/'. So we need to deal with it to find the matched entry.

If not, there will be error like "Could not find '*:/some_path/' to unexport."

Committed...

steved.

Quoted 28 lines
---
 utils/exportfs/exportfs.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
utils/exportfs/exportfs.c +10 -1
index c7a79a6..a9151ff 100644
@@ -405,8 +405,17 @@ unexportfs_parsed(char *hname, char *path, int verbose)
 			hname = ai->ai_canonname;
 	}
 
+	/*
+	 * It's possible the specified path ends with a '/'. But
+	 * the entry from exportlist won't has the trailing '/',
+	 * so need to deal with it.
+	*/
+	size_t nlen = strlen(path);
+	while (path[nlen - 1] == '/')
+		nlen--;
+
 	for (exp = exportlist[htype].p_head; exp; exp = exp->m_next) {
-		if (path && strcmp(path, exp->m_export.e_path))
+		if (path && strncmp(path, exp->m_export.e_path, nlen))
 			continue;
 		if (htype != exp->m_client->m_type)
 			continue;