diff options
author | Sage Weil <sage@inktank.com> | 2012-12-31 15:22:23 -0800 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2012-12-31 15:26:54 -0800 |
commit | a10054bc52a209b5abfeaa214d14f6c9ca9df018 (patch) | |
tree | 0e348c587b4adf3f07e35137eef8aa5531a7b967 /src/libcephfs.cc | |
parent | e2fef38dfdb075a13ac242eeaed7215e80065ee3 (diff) | |
download | ceph-a10054bc52a209b5abfeaa214d14f6c9ca9df018.tar.gz |
libcephfs: choose more unique nonce
We were using a per-process counter combined with the pid. A short
running process can easily loop through and reuse the same pid later.
Instead, go for 48 bits of randomness and the pid. This way if we get
a dup pid we'll only get a dup nonce once out of 2^48 tries.
Avoids #3630 when running a libcephfs test in a loop (so that the pid
is eventually reused). This is a better fix than the broken
8b599083705c2495810c00f9f5fd5bb8ace7f32e. The real solution on the MDS
side involves cleaning up the msgr/MDS interaction with session
shutdown.
Signed-off-by: Sage Weil <sage@inktank.com>
Diffstat (limited to 'src/libcephfs.cc')
-rw-r--r-- | src/libcephfs.cc | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 55bcfed1ff7..0bb508ff912 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -17,6 +17,7 @@ #include <string.h> #include <string> +#include "auth/Crypto.h" #include "client/Client.h" #include "include/cephfs/libcephfs.h" #include "common/Mutex.h" @@ -222,10 +223,13 @@ extern "C" const char *ceph_version(int *pmajor, int *pminor, int *ppatch) extern "C" int ceph_create_with_context(struct ceph_mount_info **cmount, CephContext *cct) { - // Function-static variables are thread-safe in gcc and in the forthcoming C++ standard - static int nonce_seed = 0; + uint64_t nonce = 0; + + // 6 bytes of random and 2 bytes of pid + get_random_bytes((char*)&nonce, sizeof(nonce)); + nonce &= ~0xffff; + nonce |= (uint64_t)getpid(); - uint64_t nonce = (uint64_t)++nonce_seed * 1000000ull + (uint64_t)getpid(); *cmount = new struct ceph_mount_info(nonce, cct); return 0; } |