[Pvfs2-cvs] commit by pcarns in pvfs2-1/src/common/misc:
pint-cached-config.c
CVS commit program
cvs at parl.clemson.edu
Mon May 19 09:18:26 EDT 2008
Update of /projects/cvsroot/pvfs2-1/src/common/misc
In directory parlweb1:/tmp/cvs-serv24886
Modified Files:
pint-cached-config.c
Log Message:
Introduce more noise into random seeding for PINT_cached_config interface().
Using time in seconds was prone to collision if many clients initialized
concurrently with NTP or some other time synchronization method.
Index: pint-cached-config.c
===================================================================
RCS file: /projects/cvsroot/pvfs2-1/src/common/misc/pint-cached-config.c,v
diff -p -u -r1.24 -r1.25
--- pint-cached-config.c 16 May 2008 14:12:13 -0000 1.24
+++ pint-cached-config.c 19 May 2008 13:18:26 -0000 1.25
@@ -8,7 +8,10 @@
#include <string.h>
#include <assert.h>
#include <stdlib.h>
+#include <sys/time.h>
#include <time.h>
+#include <sys/types.h>
+#include <unistd.h>
#include "pvfs2-types.h"
#include "pvfs2-attr.h"
@@ -114,12 +117,41 @@ static int io_randomized = 0;
*/
int PINT_cached_config_initialize(void)
{
+ struct timeval tv;
+ unsigned int seed = 0;
+ char hostname[HOST_NAME_MAX];
+ int ret;
+ int i;
+ int hostnamelen;
+
if (!PINT_fsid_config_cache_table)
{
PINT_fsid_config_cache_table =
qhash_init(hash_fsid_compare,hash_fsid,11);
}
- srand((unsigned int)time(NULL));
+
+ /* include time, pid, and hostname in random seed in order to help avoid
+ * collisions on object placement when many clients are launched
+ * concurrently
+ */
+ gettimeofday(&tv, NULL);
+ seed += tv.tv_sec;
+ seed += tv.tv_usec;
+
+ seed += getpid();
+
+ ret = gethostname(hostname, HOST_NAME_MAX);
+ if(ret == 0)
+ {
+ hostnamelen = strlen(hostname);
+ for(i=0; i<hostnamelen; i++)
+ {
+ seed += (hostname[hostnamelen - i - 1] + i*256);
+ }
+ }
+
+ srand(seed);
+
return (PINT_fsid_config_cache_table ? 0 : -PVFS_ENOMEM);
}
More information about the Pvfs2-cvs
mailing list