summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Adam <obnox@samba.org>2012-08-06 16:35:46 +0200
committerStefan Metzmacher <metze@samba.org>2012-08-17 20:07:07 +0200
commit471a853e343e336adb14a219fba2d2ead9a1db62 (patch)
treed4e72720ee227e6b142f676ef4adc419567a1409
parent3cdf441da1ff0c969c89285cfd9fd0f968f1a4e9 (diff)
downloadsamba-471a853e343e336adb14a219fba2d2ead9a1db62.tar.gz
samba-471a853e343e336adb14a219fba2d2ead9a1db62.tar.bz2
samba-471a853e343e336adb14a219fba2d2ead9a1db62.zip
lib/util: add server_id_set_disconnected() and server_id_is_disconnected()
Utility functions for handling the special placeholder server-id value for disconnected clients (to be used for durable handles). Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>
-rw-r--r--lib/util/samba_util.h12
-rw-r--r--lib/util/server_id.c37
2 files changed, 48 insertions, 1 deletions
diff --git a/lib/util/samba_util.h b/lib/util/samba_util.h
index e69aa7c40c..4a6dd3bc80 100644
--- a/lib/util/samba_util.h
+++ b/lib/util/samba_util.h
@@ -904,4 +904,16 @@ char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id);
struct server_id server_id_from_string(uint32_t local_vnn,
const char *pid_string);
+/**
+ * Set the serverid to the special value that represents a disconnected
+ * client for (e.g.) durable handles.
+ */
+void server_id_set_disconnected(struct server_id *id);
+
+/**
+ * check whether a serverid is the special placeholder for
+ * a disconnected client
+ */
+bool server_id_is_disconnected(const struct server_id *id);
+
#endif /* _SAMBA_UTIL_H_ */
diff --git a/lib/util/server_id.c b/lib/util/server_id.c
index 722230354c..a06891d80c 100644
--- a/lib/util/server_id.c
+++ b/lib/util/server_id.c
@@ -43,7 +43,9 @@ bool server_id_equal(const struct server_id *p1, const struct server_id *p2)
char *server_id_str(TALLOC_CTX *mem_ctx, const struct server_id *id)
{
- if (id->vnn == NONCLUSTER_VNN && id->task_id == 0) {
+ if (server_id_is_disconnected(id)) {
+ return talloc_strdup(mem_ctx, "disconnected");
+ } else if (id->vnn == NONCLUSTER_VNN && id->task_id == 0) {
return talloc_asprintf(mem_ctx,
"%llu",
(unsigned long long)id->pid);
@@ -95,9 +97,42 @@ struct server_id server_id_from_string(uint32_t local_vnn,
} else if (sscanf(pid_string, "%llu", &pid) == 1) {
result.vnn = local_vnn;
result.pid = pid;
+ } else if (strcmp(pid_string, "disconnected") ==0) {
+ server_id_set_disconnected(&result);
} else {
result.vnn = NONCLUSTER_VNN;
result.pid = UINT64_MAX;
}
return result;
}
+
+/**
+ * Set the serverid to the special value that represents a disconnected
+ * client for (e.g.) durable handles.
+ */
+void server_id_set_disconnected(struct server_id *id)
+{
+ SMB_ASSERT(id != NULL);
+
+ id->pid = UINT64_MAX;
+ id->task_id = UINT32_MAX;
+ id->vnn = NONCLUSTER_VNN;
+ id->unique_id = SERVERID_UNIQUE_ID_NOT_TO_VERIFY;
+
+ return;
+}
+
+/**
+ * check whether a serverid is the special placeholder for
+ * a disconnected client
+ */
+bool server_id_is_disconnected(const struct server_id *id)
+{
+ struct server_id dis;
+
+ SMB_ASSERT(id != NULL);
+
+ server_id_set_disconnected(&dis);
+
+ return server_id_equal(id, &dis);
+}