[SCM] Samba Shared Repository - branch v3-2-test updated - release-3-2-0pre2-687-ga0cefd4

Alexander Bokovoy ab at samba.org
Tue Apr 8 11:20:35 GMT 2008


The branch, v3-2-test has been updated
       via  a0cefd44009d414fa00ec6e08c70d21b74acdbcb (commit)
       via  1faa97d5cc51277abbc6cb5c37d31c429bea04e4 (commit)
      from  09852899cadc48abe2f2651ecbceaf881198e648 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-2-test


- Log -----------------------------------------------------------------
commit a0cefd44009d414fa00ec6e08c70d21b74acdbcb
Author: Alexander Bokovoy <ab at samba.org>
Date:   Tue Apr 8 15:19:01 2008 +0400

    Destroy DMAPI session when main smbd daemon exits.
    
    DMAPI session is precious resource maintained at kernel level. We open one of them and use across multiple smbd daemons
    but once last of them exits, DMAPI session needs to be destroyed. There are some HSM implementations which fail to
    shutdown when opened DMAPI sessions left. Ensure we shutdown our session when it is really not needed anymore.
    This is what recommended by DMAPI specification anyway.

commit 1faa97d5cc51277abbc6cb5c37d31c429bea04e4
Author: Alexander Bokovoy <ab at samba.org>
Date:   Tue Apr 8 15:17:53 2008 +0400

    Allow broader range of HSM systems in vfs_tsmsm
    
        Allow to specify value of DMAPI attribute returned during offline file checks, 'tsmsm: dmapi value'.
        Previously tsmsm module has supported only IBM TSM SM engine which reports file state by *existence*
        of a certain DMAPI attribute. Other HSM systems report a certain value as DMAPI request's result.
        Port from Tridge's v3-0-ctdb git tree.

-----------------------------------------------------------------------

Summary of changes:
 source/modules/vfs_tsmsm.c |   36 +++++++++++++++++++++++++++++++-----
 source/smbd/dmapi.c        |   24 ++++++++++++++++++++++++
 source/smbd/server.c       |    9 +++++++++
 3 files changed, 64 insertions(+), 5 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source/modules/vfs_tsmsm.c b/source/modules/vfs_tsmsm.c
index aa0f945..7dc8b38 100644
--- a/source/modules/vfs_tsmsm.c
+++ b/source/modules/vfs_tsmsm.c
@@ -72,6 +72,7 @@ struct tsmsm_struct {
 	float online_ratio;
 	char *hsmscript;
 	const char *attrib_name;
+	const char *attrib_value;
 };
 
 static void tsmsm_free_data(void **pptr) {
@@ -111,7 +112,11 @@ static int tsmsm_connect(struct vfs_handle_struct *handle,
 	tsmd->attrib_name = lp_parm_talloc_string(SNUM(handle->conn), tsmname, 
 						  "dmapi attribute", DM_ATTRIB_OBJECT);
 	talloc_steal(tsmd, tsmd->attrib_name);
-
+	
+	tsmd->attrib_value = lp_parm_talloc_string(SNUM(handle->conn), "tsmsm", 
+						   "dmapi value", NULL);
+	talloc_steal(tsmd, tsmd->attrib_value);
+	
 	/* retrieve 'online ratio'. In case of error default to FILE_IS_ONLINE_RATIO */
 	fres = lp_parm_const_string(SNUM(handle->conn), tsmname, 
 				    "online ratio", NULL);
@@ -143,7 +148,8 @@ static bool tsmsm_is_offline(struct vfs_handle_struct *handle,
 	dm_attrname_t dmname;
 	int ret, lerrno;
 	bool offline;
-	char buf[1];
+	char *buf;
+	int buflen;
 
         /* if the file has more than FILE_IS_ONLINE_RATIO of blocks available,
 	   then assume it is not offline (it may not be 100%, as it could be sparse) */
@@ -181,11 +187,24 @@ static bool tsmsm_is_offline(struct vfs_handle_struct *handle,
 	memset(&dmname, 0, sizeof(dmname));
 	strlcpy((char *)&dmname.an_chars[0], tsmd->attrib_name, sizeof(dmname.an_chars));
 
+	if (tsmd->attrib_value != NULL) {
+		buflen = strlen(tsmd->attrib_value);
+	} else {
+		buflen = 1;
+	}
+	buf = talloc_zero_size(tsmd, buflen);
+	if (buf == NULL) {
+		DEBUG(0,("out of memory in tsmsm_is_offline -- assuming online (%s)\n", path));
+		errno = ENOMEM;
+		offline = false;
+		goto done;
+	}
+
 	lerrno = 0;
 
 	do {
 		ret = dm_get_dmattr(*dmsession_id, dmhandle, dmhandle_len, 
-				    DM_NO_TOKEN, &dmname, sizeof(buf), buf, &rlen);
+				    DM_NO_TOKEN, &dmname, buflen, buf, &rlen);
 		if (ret == -1 && errno == EINVAL) {
 			DEBUG(0, ("Stale DMAPI session, re-creating it.\n"));
 			lerrno = EINVAL;
@@ -202,8 +221,14 @@ static bool tsmsm_is_offline(struct vfs_handle_struct *handle,
 		}
 	} while (ret == -1 && lerrno == EINVAL);
 
-	/* its offline if the specified DMAPI attribute exists */
-	offline = (ret == 0 || (ret == -1 && errno == E2BIG));
+	/* check if we need a specific attribute value */
+	if (tsmd->attrib_value != NULL) {
+		offline = (ret == 0 && rlen == buflen && 
+			    memcmp(buf, tsmd->attrib_value, buflen) == 0);
+	} else {
+		/* its offline if the specified DMAPI attribute exists */
+		offline = (ret == 0 || (ret == -1 && errno == E2BIG));
+	}
 
 	DEBUG(10,("dm_get_dmattr %s ret=%d (%s)\n", path, ret, strerror(errno)));
 
@@ -212,6 +237,7 @@ static bool tsmsm_is_offline(struct vfs_handle_struct *handle,
 	dm_handle_free(dmhandle, dmhandle_len);	
 
 done:
+	talloc_free(buf);
 	unbecome_root();
 	return offline;
 }
diff --git a/source/smbd/dmapi.c b/source/smbd/dmapi.c
index fab0d5f..fd252e9 100644
--- a/source/smbd/dmapi.c
+++ b/source/smbd/dmapi.c
@@ -213,6 +213,30 @@ bool dmapi_new_session(void)
 }
 
 /* 
+    only call this when exiting from master smbd process. DMAPI sessions
+    are long-lived kernel resources we ought to share across smbd processes.
+    However, we must free them when all smbd processes are finished to
+    allow other subsystems clean up properly. Not freeing DMAPI session
+    blocks certain HSM implementations from proper shutdown.
+*/
+bool dmapi_destroy_session(void)
+{
+	if (samba_dmapi_session != DM_NO_SESSION) {
+		become_root();
+		if (!dm_destroy_session(samba_dmapi_session)) {
+			session_num--;
+			samba_dmapi_session = DM_NO_SESSION;
+		} else {
+			DEBUG(0,("Couldn't destroy DMAPI session: %s\n",
+				 strerror(errno)));
+		}
+		unbecome_root();
+	}
+	return samba_dmapi_session == DM_NO_SESSION;
+}
+
+
+/* 
    This is default implementation of dmapi_file_flags() that is 
    called from VFS is_offline() call to know whether file is offline.
    For GPFS-specific version see modules/vfs_tsmsm.c. It might be
diff --git a/source/smbd/server.c b/source/smbd/server.c
index 179d480..7a6e171 100644
--- a/source/smbd/server.c
+++ b/source/smbd/server.c
@@ -918,6 +918,15 @@ static void exit_server_common(enum server_exit_reason how,
 	}
 #endif
 
+#ifdef USE_DMAPI
+	/* Destroy Samba DMAPI session only if we are master smbd process */
+	if (am_parent) {
+		if (!dmapi_destroy_session()) {
+			DEBUG(0,("Unable to close Samba DMAPI session\n"));
+		}
+	}
+#endif
+
 	locking_end();
 	printing_end();
 


-- 
Samba Shared Repository


More information about the samba-cvs mailing list