diff options
Diffstat (limited to 'xlators/cluster/nsr-server/src/etcd-sim.c')
-rw-r--r-- | xlators/cluster/nsr-server/src/etcd-sim.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/xlators/cluster/nsr-server/src/etcd-sim.c b/xlators/cluster/nsr-server/src/etcd-sim.c index 782b5f617..d0bea12c7 100644 --- a/xlators/cluster/nsr-server/src/etcd-sim.c +++ b/xlators/cluster/nsr-server/src/etcd-sim.c @@ -34,6 +34,8 @@ #include <fcntl.h> #include <sys/file.h> +#include "mem-pool.h" + /* * Mock implementation of etcd * The etcd file is simulated in /tmp/<server-names> @@ -244,3 +246,35 @@ etcd_watch (etcd_session this, char *pfx, char **keyp, char **valuep, { return ETCD_WTF; } + +etcd_result +etcd_lock (etcd_session session_as_void, char *key, unsigned int ttl, + char *index_in, char **index_out) +{ + char *path; + int fd; + + if (!index_in) { + if (gf_asprintf(&path,"/var/tmp/%s",key) < 0) { + return ETCD_WTF; + } + fd = open(path,O_RDWR|O_CREAT,0666); + GF_FREE(path); + if (fd < 0) { + return ETCD_WTF; + } + if (flock(fd,LOCK_EX) < 0) { + close(fd); + return ETCD_WTF; + } + *index_out = strdup("42"); + } + + /* + * Yes, we leak an fd by not closing it here (and nobody else even + * knows about it). That would be awful in any other context, but + * for test scripts it won't matter. + */ + return ETCD_OK; +} + |