diff --git a/qnx/src/ipc3x_dev/ti/syslink/utils/hlos/knl/NameServer_daemon.c b/qnx/src/ipc3x_dev/ti/syslink/utils/hlos/knl/NameServer_daemon.c
index 03c1a4f4bf48248d989460915512d9a76e02e407..5fb5d6f891859c13ca30d8f284158a993802bc19 100644 (file)
/* Internal stuff: */
#include <_MessageQCopy.h>
#include <_NameServer.h>
+#include <_NameServer_daemon.h>
#include <ti/ipc/namesrv/_NameServerRemoteRpmsg.h>
-#include <_IpcLog.h>
+#include <ti/syslink/utils/Trace.h>
#define MESSAGEQ_RPMSG_PORT 61
#define NAME_SERVER_RPMSG_ADDR 0
pthread_mutex_t modGate;
} NameServer_ModuleObject;
-#define CIRCLEQ_destruct(head) { \
- (head)->cqh_first = NULL; \
- (head)->cqh_last = NULL; \
-}
-
#define CIRCLEQ_elemClear(elem) { \
(elem)->cqe_next = (elem)->cqe_prev = (Void *)(elem); \
}
@@ -237,8 +233,9 @@ static void NameServerRemote_processMessage(NameServerRemote_Msg * msg, UInt16 p
int waitFd = NameServer_module->waitFdW;
if (msg->request == NAMESERVER_REQUEST) {
- LOG2("NameServer Request: instanceName: %s, name: %s\n",
- (String)msg->instanceName, (String)msg->name)
+ GT_2trace(curTrace, GT_1CLASS, "NameServer Request: "
+ "instanceName: %s, name: %s",
+ (String)msg->instanceName, (String)msg->name);
assert(msg->valueLen <= MAXVALUELEN);
@@ -251,45 +248,65 @@ static void NameServerRemote_processMessage(NameServerRemote_Msg * msg, UInt16 p
if (handle != NULL) {
/* Search for the NameServer entry */
if (msg->valueLen <= sizeof (Bits32)) {
- LOG0("Calling NameServer_getLocalUInt32...\n")
+ GT_0trace(curTrace, GT_1CLASS, "Calling NameServer_getLocalUInt32...");
status = NameServer_getLocalUInt32(handle,
(String)msg->name, &msg->value);
}
else {
- LOG0("Calling NameServer_getLocal...\n")
+ GT_0trace(curTrace, GT_1CLASS, "Calling NameServer_getLocal...");
status = NameServer_getLocal(handle,
(String)msg->name, (Ptr)msg->valueBuf, &msg->valueLen);
}
}
- LOG2("NameServer Response: instanceName: %s, name: %s,",
- (String)msg->instanceName, (String)msg->name)
+ GT_2trace(curTrace, GT_1CLASS,
+ "NameServer Response: instanceName: %s, name: %s,",
+ (String)msg->instanceName, (String)msg->name);
/* set the request status */
if (status < 0) {
- LOG1(" Value not found, status: %d\n", status)
+ GT_1trace(curTrace, GT_1CLASS, " Value not found, status: %d",
+ status);
msg->requestStatus = 0;
}
else {
msg->requestStatus = 1;
- LOG1(" Value: 0x%x\n", msg->value)
+ GT_1trace(curTrace, GT_1CLASS, " Value: 0x%x", msg->value);
}
/* specify message as a response */
msg->request = NAMESERVER_RESPONSE;
msg->reserved = NAMESERVER_MSG_TOKEN;
- /* send response message to remote processor */
- status = MessageQCopy_send(procId, MultiProc_self(),
- MESSAGEQ_RPMSG_PORT, RPMSG_RESERVED_ADDRESSES, msg,
- sizeof(NameServerRemote_Msg), TRUE);
- if (status < 0) {
- LOG0("NameServer: MessageQCopy_send failed\n")
+ pthread_mutex_lock(&NameServer_module->modGate);
+
+ /*
+ * Check if MessageQCopy object is valid. If not, we received a request
+ * but we are not able to respond to it due to recovery.
+ * We will simply drop the request.
+ */
+ if (NameServer_module->mq == NULL) {
+ GT_0trace(curTrace, GT_3CLASS,
+ "NameServerRemote_processMessage: MessageQCopy not ready."
+ " Request dropped.");
+ }
+ else {
+ /* send response message to remote processor */
+ status = MessageQCopy_send(procId, MultiProc_self(),
+ MESSAGEQ_RPMSG_PORT, RPMSG_RESERVED_ADDRESSES, msg,
+ sizeof(NameServerRemote_Msg), TRUE);
+ if (status < 0) {
+ GT_setFailureReason(curTrace, GT_4CLASS,
+ "NameServerRemote_processMessage",
+ status, "MessageQCopy_send failed");
+ }
}
+
+ pthread_mutex_unlock(&NameServer_module->modGate);
}
else {
- LOG2("NameServer Reply: instanceName: %s, name: %s",
- (String)msg->instanceName, (String)msg->name)
- LOG1(", value: 0x%x\n", msg->value)
+ GT_3trace(curTrace, GT_1CLASS, "NameServer Reply: instanceName: %s, "
+ "name: %s, value: 0x%x", (String)msg->instanceName,
+ (String)msg->name, msg->value);
/* Save the response message. */
memcpy(&NameServer_module->nsMsg, msg, sizeof(NameServerRemote_Msg));
{
NameServerRemote_Msg msg;
- LOG0("listener_cb: Entered Listener thread.\n")
+ GT_6trace(curTrace, GT_ENTER, "_listener_cb", handle, data, len, priv, src, srcProc);
- LOG1("NameServer: Listener got NameServer message "
+ GT_1trace(curTrace, GT_1CLASS, "NameServer: Listener got NameServer message "
"from MessageQCopy: 0x%p!\n", handle);
/* Get NameServer message and process: */
memcpy(&msg, data, len);
if (len != sizeof(NameServerRemote_Msg)) {
- LOG1("NameServer: got bad NameServerRemote_Msg len (%d)\n",
- len)
+ GT_1trace(curTrace, GT_4CLASS, "NameServer: got bad "
+ "NameServerRemote_Msg len (%d)\n", len);
}
else {
- LOG1("listener_cb: read from MessageQCopy 0x%p\n", handle)
- LOG2("\tReceived ns msg: byte count: %d, from addr: %d, ",
- len, src)
- LOG1("from vproc: %d\n", srcProc)
+ GT_1trace(curTrace, GT_1CLASS, "listener_cb: "
+ "read from MessageQCopy 0x%p", handle);
+ GT_3trace(curTrace, GT_1CLASS, "\tReceived ns msg: "
+ "byte count: %d, from addr: %d, from vproc: %d",
+ len, src, srcProc);
NameServerRemote_processMessage(&msg, srcProc);
}
}
pthread_mutex_lock(&NameServer_module->modGate);
- LOG1("NameServer_setup: entered, refCount=%d\n", NameServer_module->refCount)
+ GT_1trace(curTrace, GT_ENTER, "NameServer_setup: refCount",
+ NameServer_module->refCount);
NameServer_module->refCount++;
if (NameServer_module->refCount > 1) {
- LOG0("NameServer_setup: already setup\n")
+ GT_0trace(curTrace, GT_1CLASS, "NameServer_setup: already setup");
status = NameServer_S_ALREADYSETUP;
goto exit;
}
if (pipe(fd) == -1) {
status = NameServer_E_FAIL;
- LOG0("NameServer_setup: failed to create waitFd.\n")
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_setup", status,
+ "failed to create waitFd.");
goto exit;
}
NameServer_module->waitFdW = fd[1];
if (NameServer_module->mq == NULL) {
status = NameServer_E_FAIL;
- LOG0("NameServer_setup: failed to create MessageQCopy instance.\n")
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_setup", status,
+ "failed to create MessageQCopy instance.");
goto exit;
}
CIRCLEQ_INIT(&NameServer_module->objList);
exit:
- LOG1("NameServer_setup: exiting, refCount=%d\n", \
- NameServer_module->refCount)
+ GT_1trace(curTrace, GT_LEAVE, "NameServer_setup: refCount",
+ NameServer_module->refCount);
pthread_mutex_unlock(&NameServer_module->modGate);
pthread_mutex_lock(&NameServer_module->modGate);
- LOG1("NameServer_destroy: entered, refCount=%d\n", NameServer_module->refCount)
+ GT_1trace(curTrace, GT_ENTER, "NameServer_destroy: refCount",
+ NameServer_module->refCount);
NameServer_module->refCount--;
if (NameServer_module->refCount > 0) {
- LOG1("NameServer_destroy(): refCount(%d) > 0, exiting\n", NameServer_module->refCount)
+ GT_1trace(curTrace, GT_1CLASS,
+ "NameServer_destroy(): refCount(%d) > 0, exiting",
+ NameServer_module->refCount);
status = NameServer_S_SUCCESS;
goto exit;
MessageQCopy_delete(&NameServer_module->mq);
}
- CIRCLEQ_destruct(&NameServer_module->objList);
+ /* TODO: delete any remaining instances */
close(NameServer_module->waitFdW);
close(NameServer_module->waitFdR);
exit:
- LOG1("NameServer_destroy: exiting, refCount=%d\n", NameServer_module->refCount)
+ GT_1trace(curTrace, GT_LEAVE, "NameServer_destroy: refCount",
+ NameServer_module->refCount);
pthread_mutex_unlock(&NameServer_module->modGate);
assert(name != NULL);
assert(NameServer_module->refCount != 0);
- LOG1("NameServer_create(): '%s'\n", name)
+ GT_1trace(curTrace, GT_1CLASS, "NameServer_create(): '%s'\n", name);
pthread_mutex_lock(&NameServer_module->modGate);
handle->refCount++;
}
else {
- LOG0("NameServer_create: NameServer params mismatch\n")
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_create",
+ NameServer_E_FAIL, "NameServer params mismatch");
handle = NULL;
}
goto leave;
}
if (!handle) {
- LOG0("NameServer_create: NameServer_Handle alloc failed\n")
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_create",
+ NameServer_E_FAIL, "NameServer_Handle alloc failed");
goto leave;
}
handle->refCount = 1;
handle->name = (String)malloc(strlen(name) + 1u);
if (!handle->name) {
- LOG0("NameServer_create: instance name alloc failed\n")
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_create",
+ NameServer_E_FAIL, "instance name alloc failed");
goto cleanup;
}
strncpy(handle->name, name, strlen (name) + 1u);
}
-/* Function to delete a name server. */
-Int NameServer_delete(NameServer_Handle * handle)
+/*
+ * ======== NameServer_delete ========
+ * Delete a name server instance
+ */
+Int NameServer_delete(NameServer_Handle *handle)
{
Int status = NameServer_S_SUCCESS;
+ struct NameServer_Object *obj;
assert(handle != NULL);
assert(*handle != NULL);
- assert((*handle)->count == 0);
assert(NameServer_module->refCount != 0);
+ obj = *(struct NameServer_Object **)handle;
+
pthread_mutex_lock(&NameServer_module->modGate);
- (*handle)->refCount--;
- if ((*handle)->refCount != 0) {
+ obj->refCount--;
+ if (obj->refCount != 0) {
goto leave;
}
- if ((*handle)->count == 0) {
- CIRCLEQ_REMOVE(&NameServer_module->objList, *handle, elem);
+ /* delete each entry on the name list */
+ while (obj->nameList.cqh_first != (void *)&obj->nameList) {
+ NameServer_removeEntry(*handle, (Ptr)(obj->nameList.cqh_first));
+ }
+
+ /* free the instance name */
+ if (obj->name != NULL) {
+ free(obj->name);
+ obj->name = NULL;
+ }
- if ((*handle)->name != NULL) {
- free((*handle)->name);
- (*handle)->name = NULL;
- }
+ /* destroy the mutex */
+ pthread_mutex_destroy(&obj->gate);
- CIRCLEQ_destruct(&(*handle)->nameList);
+ /* remove from objList */
+ CIRCLEQ_REMOVE(&NameServer_module->objList, obj, elem);
- free((*handle));
- (*handle) = NULL;
- }
+ /* finally, free the instance object */
+ free(obj);
+
+ /* set the caller's handle to null */
+ (*handle) = NULL;
leave:
pthread_mutex_unlock(&NameServer_module->modGate);
if (strlen(name) > handle->params.maxNameLen - 1) {
status = NameServer_E_INVALIDARG;
- LOG0("NameServer_add: name length exceeded maximum!\n")
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_add", status,
+ "name length exceeded maximum!");
new_node = NULL;
goto exit;
}
if (len > handle->params.maxValueLen) {
status = NameServer_E_INVALIDARG;
- LOG0("NameServer_add: value length exceeded maximum!\n")
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_add", status,
+ "value length exceeded maximum!");
new_node = NULL;
goto exit;
}
if (strcmp(node->name, name) == 0) {
if (handle->params.checkExisting == TRUE) {
status = NameServer_E_INVALIDARG;
- LOG1("NameServer_add: '%s' - duplicate entry found!\n", name)
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_add", status, "duplicate entry found!");
+ GT_1trace(curTrace, GT_3CLASS, "\t'%s' - duplicate entry found!", name);
break;
}
}
new_node = (NameServer_TableEntry *)malloc(sizeof(NameServer_TableEntry));
if (new_node == NULL) {
status = NameServer_E_MEMORY;
- LOG1("NameServer_add: %d - malloc new_node failed!\n", status)
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_add", status,
+ "malloc new_node failed!");
goto exit;
}
handle->count++;
- LOG2("NameServer_add: Entered key: '%s', data: 0x%x\n",
- name, *(UInt32 *)buf)
-
+ /* Only print a single byte of buf. Address may not be 32-bit aligned */
+ GT_2trace(curTrace, GT_1CLASS,
+ "NameServer_add: Entered key: '%s', data: 0x%x",
+ name, *(UInt8 *)buf);
exit:
pthread_mutex_unlock(&handle->gate);
if (done == FALSE) {
status = NameServer_E_INVALIDARG;
- LOG1("NameServer_remove %d Entry not found!\n", status)
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_remove", status,
+ " Entry not found!");
}
pthread_mutex_unlock(&handle->gate);
Bool done = FALSE;
if (strlen(name) >= MAXNAMEINCHAR) {
- LOG0("Name is too long in remote query\n");
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+ NameServer_E_NAMETOOLONG,
+ "Name is too long in remote query");
return NameServer_E_NAMETOOLONG;
}
if (strlen(obj->name) >= MAXNAMEINCHAR) {
- LOG0("Instance name is too long for remote query\n");
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+ NameServer_E_NAMETOOLONG,
+ "Instance name is too long for remote query");
return NameServer_E_NAMETOOLONG;
}
strncpy((char *)nsMsg.instanceName, obj->name, strlen(obj->name) + 1);
strncpy((char *)nsMsg.name, name, strlen(name) + 1);
- LOG2("NameServer_getRemote: Requesting from procId %d, %s:",
- procId, (String)nsMsg.instanceName)
- LOG1("%s...\n", (String)nsMsg.name)
+ GT_3trace(curTrace, GT_1CLASS,
+ "NameServer_getRemote: Requesting from procId %d, %s:%s...",
+ procId, (String)nsMsg.instanceName, (String)nsMsg.name);
+
+ /*
+ * Check if MessageQCopy object is valid. Technically we don't need it
+ * to send, but it is an indication of whether recovery is in process
+ */
+ if (NameServer_module->mq == NULL) {
+ status = NameServer_E_NOTFOUND;
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+ status, "MessageQCopy not ready");
+ goto exit;
+ }
/* send message */
mqcStatus = MessageQCopy_send(procId, MultiProc_self(), MESSAGEQ_RPMSG_PORT,
RPMSG_RESERVED_ADDRESSES, &nsMsg, sizeof(NameServerRemote_Msg),
- TRUE);
+ TRUE);
if (mqcStatus < 0) {
- LOG0("NameServer_getRemote: Can't send to remote endpoint\n")
status = NameServer_E_NOTFOUND;
+ GT_1trace(curTrace, GT_3CLASS, "NameServer_getRemote: "
+ "Can't send to remote endpoint on procId %d", procId);
goto exit;
}
FD_ZERO(&rfds);
FD_SET(waitFd, &rfds);
maxfd = waitFd + 1;
- LOG1("NameServer_getRemote: pending on waitFd: %d\n", waitFd)
+ GT_1trace(curTrace, GT_1CLASS, "NameServer_getRemote: pending on waitFd: %d\n", waitFd);
ret = select(maxfd, &rfds, NULL, NULL, &tv);
if (ret == -1) {
- LOG0("NameServer_getRemote: select failed.")
status = NameServer_E_FAIL;
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+ status, "select failed.");
goto exit;
}
else if (!ret) {
- LOG0("NameServer_getRemote: select timed out.\n")
status = NameServer_E_TIMEOUT;
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+ status, "select timed out.");
goto exit;
}
/* Read, just to balance the write: */
numBytes = read(waitFd, &buf, sizeof(buf));
if (numBytes == -1) {
- LOG0("NameServer_getRemote: read failure\n")
status = NameServer_E_FAIL;
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_getRemote",
+ status, "read failure");
goto exit;
}
/* set the contents of value */
if (*len <= sizeof (Bits32)) {
*(UInt32 *)value = (UInt32)replyMsg->value;
- LOG2("NameServer_getRemote: Reply from: %d, %s:",
- procId, (String)replyMsg->instanceName)
- LOG2("%s, value: 0x%x...\n",
- (String)replyMsg->name, *(UInt32 *)value)
+ GT_4trace(curTrace, GT_1CLASS, "NameServer_getRemote: "
+ "Reply from: %d, %s:%s, value: 0x%x...", procId,
+ (String)replyMsg->instanceName,
+ (String)replyMsg->name, *(UInt32 *)value);
}
else {
memcpy(value, replyMsg->valueBuf, *len);
- LOG2("NameServer_getRemote: Reply from: %d, %s:",
- procId, (String)replyMsg->instanceName)
- LOG2("%s, value buffer at address: 0x%p...\n",
- (String)replyMsg->name, value)
+ GT_4trace(curTrace, GT_1CLASS, "NameServer_getRemote: "
+ "Reply from: %d, %s:%s, value buffer at address:"
+ " 0x%p...", procId,
+ (String)replyMsg->instanceName,
+ (String)replyMsg->name, value);
}
goto exit;
}
else {
/* name is not found */
- LOG2("NameServer_getRemote: value for %s:%s not found.\n",
- (String)replyMsg->instanceName, (String)replyMsg->name)
+ GT_2trace(curTrace, GT_3CLASS, "NameServer_getRemote: "
+ "value for %s:%s not found.",
+ (String)replyMsg->instanceName,
+ (String)replyMsg->name);
/* set status to not found */
status = NameServer_E_NOTFOUND;
pthread_mutex_unlock(&handle->gate);
if (done == FALSE) {
- LOG1("NameServer_getLocal: entry key: '%s' not found!\n", name)
+ GT_1trace(curTrace, GT_1CLASS,
+ "NameServer_getLocal: entry key: '%s' not found!", name);
}
else {
- LOG2("NameServer_getLocal: Found entry key: '%s', data: 0x%x\n",
- node->name, (UInt32)node->value)
+ GT_2trace(curTrace, GT_1CLASS, "NameServer_getLocal: Found entry key: "
+ "'%s', data: 0x%x", node->name, (UInt32)node->value);
status = NameServer_S_SUCCESS;
}
@@ -1103,12 +1174,51 @@ Int NameServer_getLocalUInt32(NameServer_Handle handle, String name, Ptr value)
assert(value != NULL);
assert(NameServer_module->refCount != 0);
- LOG0("NameServer_getLocalUInt32: calling NameServer_getLocal()...\n")
+ GT_0trace(curTrace, GT_1CLASS,
+ "NameServer_getLocalUInt32: calling NameServer_getLocal()...");
status = NameServer_getLocal(handle, name, value, &len);
return (status);
}
+Void NameServer_preRecovery(Void)
+{
+ Int status;
+
+ pthread_mutex_lock(&NameServer_module->modGate);
+
+ if (NameServer_module->mq != NULL) {
+ status = MessageQCopy_delete(&NameServer_module->mq);
+ if (status < 0) {
+ GT_setFailureReason(curTrace, GT_3CLASS, "NameServer_preRecovery", status,
+ "Cannot delete MessageQCopy");
+ }
+ NameServer_module->mq = NULL;
+ }
+
+ pthread_mutex_unlock(&NameServer_module->modGate);
+}
+
+Int NameServer_postRecovery(Void)
+{
+ Int status = NameServer_S_SUCCESS;
+
+ pthread_mutex_lock(&NameServer_module->modGate);
+
+ /* Create the MessageQCopy for receiving messages from all remote proc */
+ NameServer_module->mq = MessageQCopy_create(NAME_SERVER_RPMSG_ADDR,
+ NULL, _listener_cb, NULL, &NameServer_module->recvAddr);
+
+ if (NameServer_module->mq == NULL) {
+ status = NameServer_E_FAIL;
+ GT_setFailureReason(curTrace, GT_4CLASS, "NameServer_postRecovery", status,
+ "failed to create MessageQCopy instance.");
+ }
+
+ pthread_mutex_unlock(&NameServer_module->modGate);
+
+ return (status);
+}
#if defined (__cplusplus)
}