Commit d5e619c5 authored by Adam Wujek's avatar Adam Wujek 💬

arch-wrs: check shmem consistency in wrs_shm_get_and_check

Commit based on the commit from wrs-switch-sw repo described below. It does
not have impact on PPSI, just for consistency.

userspace/libwr: check shmem consistency in wrs_shm_get_and_check

Check the consistency of shmem during opening with wrs_shm_get_and_check.
It was possible that sequence number was increased during the opening, but it
was interpreted as version error.

Add defines describing different return errors.

This change is backward compatible.
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 15076cb6
......@@ -45,6 +45,12 @@ struct wrs_shm_head {
#define WRS_SHM_LOCK_MASK 0x0001
/* return values of wrs_shm_get_and_check */
#define WRS_SHM_OPEN_OK 0x0001
#define WRS_SHM_OPEN_FAILED 0x0001
#define WRS_SHM_WRONG_VERSION 0x0002
#define WRS_SHM_INCONSISTENT_DATA 0x0003
/* Set custom path for shmem */
void wrs_shm_set_path(char *new_path);
......
......@@ -141,25 +141,33 @@ int wrs_shm_put(void *headptr)
/* Open shmem and check if data is available
* return 0 when ok, otherwise error
* 1 when openning shmem failed
* 2 when version is 0 */
* 2 when version is 0
* 3 when data in shmem is inconsistent, function shall be called again
*/
int wrs_shm_get_and_check(enum wrs_shm_name shm_name,
struct wrs_shm_head **head)
{
int ii;
int version;
int ret;
/* try to open shmem */
if (!(*head) && !(*head = wrs_shm_get(shm_name, "",
WRS_SHM_READ | WRS_SHM_LOCKED))) {
return 1;
return WRS_SHM_OPEN_FAILED;
}
ii = wrs_shm_seqbegin(*head);
/* read head version */
version = (*head)->version;
if (wrs_shm_seqretry(*head, ii) || !version) {
/* data in shmem available and version not zero */
return 2;
ret = wrs_shm_seqretry(*head, ii);
if (ret) {
/* inconsistent data in shmem */
return WRS_SHM_INCONSISTENT_DATA;
}
if (!version) {
/* data in shmem available and version is zero */
return WRS_SHM_WRONG_VERSION;
}
/* all ok */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment