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

Message ID 1449481577-19927-1-git-send-email-yoyang@redhat.com
State New, archived
Headers show

Commit Message

Yongcheng Yang Dec. 7, 2015, 9:46 a.m. UTC
From: Yongcheng Yang <yongcheng.yang@gmail.com>

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."

Signed-off-by: Yongcheng Yang <yongcheng.yang@gmail.com>
---
 utils/exportfs/exportfs.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Steve Dickson Dec. 12, 2015, 12:12 p.m. UTC | #1
On 12/07/2015 04:46 AM, Yongcheng Yang wrote:
> From: Yongcheng Yang <yongcheng.yang@gmail.com>
> 
> 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."
> 
> Signed-off-by: Yongcheng Yang <yongcheng.yang@gmail.com>
Committed... 

steved.

> ---
>  utils/exportfs/exportfs.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
> index c7a79a6..a9151ff 100644
> --- a/utils/exportfs/exportfs.c
> +++ b/utils/exportfs/exportfs.c
> @@ -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;
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c
index c7a79a6..a9151ff 100644
--- a/utils/exportfs/exportfs.c
+++ b/utils/exportfs/exportfs.c
@@ -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;