[PATCH] s3-vfs: handle calling chdir after disconnect

Yan, Zheng zyan at redhat.com
Tue Jan 13 19:19:16 MST 2015


close_cnum() in smbd/service.c calls SMB_VFS_DISCONNECT(), then
calls vfs_ChDir(). ceph mount is shutdown when the last connection
is disconnected. So we need to handle vfs_ChDir() when there is no
ceph mount

Signed-off-by: Yan, Zheng <zyan at redhat.com>
---
 source3/modules/vfs_ceph.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/source3/modules/vfs_ceph.c b/source3/modules/vfs_ceph.c
index ec72312..ab81190 100644
--- a/source3/modules/vfs_ceph.c
+++ b/source3/modules/vfs_ceph.c
@@ -152,6 +152,7 @@ static void cephwrap_disconnect(struct vfs_handle_struct *handle)
 	ceph_shutdown(cmount);
 
 	cmount = NULL;  /* Make it safe */
+	handle->data = NULL;
 }
 
 /* Disk operations */
@@ -223,6 +224,10 @@ static int cephwrap_statvfs(struct vfs_handle_struct *handle,  const char *path,
 	struct statvfs statvfs_buf;
 	int ret;
 
+	if (!handle->data) {
+		WRAP_RETURN(-ENOTCONN);
+	}
+
 	ret = ceph_statfs(handle->data, path, &statvfs_buf);
 	if (ret < 0) {
 		WRAP_RETURN(ret);
@@ -726,6 +731,10 @@ static int cephwrap_chdir(struct vfs_handle_struct *handle,  const char *path)
 {
 	int result = -1;
 	DEBUG(10, ("[CEPH] chdir(%p, %s)\n", handle, path));
+
+	if (!handle->data) {
+		WRAP_RETURN(-ENOTCONN);
+	}
 	/*
 	 * If the path is just / use chdir because Ceph is below / and
 	 * cannot deal with changing directory above its mount point
@@ -740,7 +749,11 @@ static int cephwrap_chdir(struct vfs_handle_struct *handle,  const char *path)
 
 static char *cephwrap_getwd(struct vfs_handle_struct *handle)
 {
-	const char *cwd = ceph_getcwd(handle->data);
+	const char *cwd;
+	if (handle->data)
+		cwd = ceph_getcwd(handle->data);
+	else
+		cwd = "/";
 	DEBUG(10, ("[CEPH] getwd(%p) = %s\n", handle, cwd));
 	return SMB_STRDUP(cwd);
 }
-- 
1.9.3



More information about the samba-technical mailing list