Pre Merge pull request from zjucx/master

This commit is contained in:
zjucx 2021-07-05 06:43:38 +00:00 committed by Gitee
commit 8722d3c0e9
7 changed files with 39 additions and 14 deletions
README.mdREADME_zh.md
interfaces/kits/registry
samgr/source
samgr_endpoint/source
samgr_server/source

View File

@ -627,7 +627,7 @@ Main objects of the SA framework:
## Repositories Involved<a name="section10365113863719"></a>
[Distributed Scheduler subsystem](en-us_topic_0000001115719369.md)
Distributed Scheduler subsystem
**[samgr\_lite](https://gitee.com/openharmony/distributedschedule_services_samgr_lite)**
**samgr\_lite**

View File

@ -627,7 +627,7 @@
## 涉及仓<a name="section10365113863719"></a>
**[分布式任务调度子系统](zh-cn_topic_0000001115719369.md)**
分布式任务调度子系统
[samgr\_lite](https://gitee.com/openharmony/distributedschedule_services_samgr_lite)
**samgr\_lite**

View File

@ -52,7 +52,7 @@ extern "C" {
#endif
#endif
#define CLIENT_PROXY_VER 0x40
#define CLIENT_PROXY_VER (0x40 | (uint16)DEFAULT_VERSION)
/**
* @brief Indicates the inherited macro of the client proxy.

View File

@ -27,7 +27,7 @@
#define DONT_WAIT 0
#define WAIT_FOREVER (-1)
static int32 SharedSend(MQueueId queueId, Exchange *exchange);
static int32 SharedSend(MQueueId queueId, Exchange *exchange, int initRef);
static BOOL FreeReference(Exchange *exchange);
int32 SAMGR_SendRequest(const Identity *identity, const Request *request, Handler handler)
@ -54,7 +54,7 @@ int32 SAMGR_SendResponse(const Request *request, const Response *response)
}
Exchange *exchange = GET_OBJECT(request, Exchange, request);
if (exchange->type == MSG_NON) {
if (exchange->type != MSG_CON) {
return EC_INVALID;
}
@ -76,7 +76,7 @@ int32 SAMGR_SendResponse(const Request *request, const Response *response)
}
// Send back to the origin to process the task.
int32 ret = SharedSend(exchange->id.queueId, exchange);
int32 ret = SharedSend(exchange->id.queueId, exchange, 1);
if (ret != EC_SUCCESS) {
exchange->handler(&exchange->request, &exchange->response);
(void)FreeReference(exchange);
@ -123,7 +123,7 @@ uint32 *SAMGR_SendSharedRequest(const Identity *identity, const Request *request
Exchange exchange = {*identity, *request, {NULL, 0}, MSG_NON, handler, token};
exchange.type = (handler == NULL) ? MSG_NON : MSG_CON;
exchange.id.queueId = NULL;
int32 err = SharedSend(identity->queueId, &exchange);
int32 err = SharedSend(identity->queueId, &exchange, 0);
if (err != EC_SUCCESS) {
HILOG_ERROR(HILOG_MODULE_SAMGR, "SharedSend [%p] failed(%d)!", identity->queueId, err);
(void)FreeReference(&exchange);
@ -152,7 +152,7 @@ int32 SAMGR_SendSharedDirectRequest(const Identity *id, const Request *req, cons
exchange.type = MSG_DIRECT;
exchange.id = *id;
exchange.id.queueId = NULL;
int32 err = SharedSend(id->queueId, &exchange);
int32 err = SharedSend(id->queueId, &exchange, 0);
if (err != EC_SUCCESS) {
HILOG_ERROR(HILOG_MODULE_SAMGR, "SharedSend [%p] failed(%d)!", id->queueId, err);
(void)FreeReference(&exchange);
@ -177,7 +177,7 @@ int32 SAMGR_SendResponseByIdentity(const Identity *id, const Request *request, c
return SAMGR_SendResponse(request, response);
}
static int32 SharedSend(MQueueId queueId, Exchange *exchange)
static int32 SharedSend(MQueueId queueId, Exchange *exchange, int initRef)
{
/* if the msg data and response is NULL, we just direct copy, no need shared the message. */
if ((exchange->request.data == NULL || exchange->request.len <= 0) &&
@ -188,12 +188,12 @@ static int32 SharedSend(MQueueId queueId, Exchange *exchange)
/* 1.add reference */
MUTEX_GlobalLock();
if (exchange->sharedRef == NULL) {
exchange->sharedRef = (uint32 *)SAMGR_Malloc(sizeof(uint32));
exchange->sharedRef = (uint32*)SAMGR_Malloc(sizeof(uint32));
if (exchange->sharedRef == NULL) {
MUTEX_GlobalUnlock();
return EC_NOMEMORY;
}
*(exchange->sharedRef) = 0;
*(exchange->sharedRef) = initRef;
}
(*(exchange->sharedRef))++;
MUTEX_GlobalUnlock();

View File

@ -162,6 +162,29 @@ int SASTORA_FindHandleByPid(SAStore *saStore, pid_t callingPid, PidHandle *handl
return INVALID_INDEX;
}
int SASTORA_FindHandleByUidPid(SAStore *saStore, uid_t callingUid, pid_t callingPid, PidHandle *handle)
{
if (saStore == NULL || saStore->maps == NULL || handle == NULL) {
return INVALID_INDEX;
}
int16 high = saStore->mapTop - 1;
int16 low = 0;
while (low <= high) {
// binary search need div 2
int16 mid = (high + low) / 2;
if (saStore->maps[mid].pid == callingPid && saStore->maps[mid].uid == callingUid) {
*handle = saStore->maps[mid];
return mid;
}
if (saStore->maps[mid].pid < callingPid) {
low = mid + 1;
continue;
}
high = mid - 1;
}
return INVALID_INDEX;
}
PidHandle SASTORA_FindPidHandleByIpcHandle(const SAStore *saStore, uint32 handle)
{
PidHandle pidHandle = {INVALID_INDEX, INVALID_INDEX, INVALID_INDEX, INVALID_INDEX};

View File

@ -75,6 +75,7 @@ static inline void SASTORA_Init(SAStore *saStore)
int SASTORA_Save(SAStore *saStore, const char *service, const char *feature, const SvcIdentity *identity);
int SASTORA_SaveHandleByPid(SAStore *saStore, PidHandle handle);
int SASTORA_FindHandleByPid(SAStore *saStore, pid_t callingPid, PidHandle *handle);
int SASTORA_FindHandleByUidPid(SAStore *saStore, uid_t callingUid, pid_t callingPid, PidHandle *handle);
SvcIdentity SASTORA_Find(SAStore *saStore, const char *service, const char *feature);
int SASTORA_ClearByPid(SAStore *saStore, pid_t pid);
PidHandle SASTORA_FindPidHandleByIpcHandle(const SAStore *saStore, uint32 handle);

View File

@ -194,10 +194,11 @@ static int32 ProcPutFeature(SamgrServer *server, const void *origin, IpcIo *req,
return EC_INVALID;
}
pid_t pid = GetCallingPid(origin);
uid_t uid = GetCallingUid(origin);
char *feature = IpcIoPopBool(req) ? NULL : (char *)IpcIoPopString(req, &len);
MUTEX_Lock(server->mtx);
PidHandle handle;
int index = SASTORA_FindHandleByPid(&server->store, pid, &handle);
int index = SASTORA_FindHandleByUidPid(&server->store, uid, pid, &handle);
if (index == INVALID_INDEX) {
MUTEX_Unlock(server->mtx);
HILOG_ERROR(HILOG_MODULE_SAMGR, "Endpoint[%d] is not register", pid);