Skip to content

Commit 1fbc9a5

Browse files
committed
pmix3x: dstore/pmix: flock portability
Using the fcntl-locking instead of the flock (back-ported from upstream openpmix/openpmix@3030a0c)
1 parent bf6c887 commit 1fbc9a5

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

opal/mca/pmix/pmix3x/pmix/src/dstore/pmix_esh.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ pmix_dstore_base_module_t pmix_dstore_esh_module = {
6161
#define EXT_SLOT_SIZE (PMIX_MAX_KEYLEN + 1 + 2*sizeof(size_t)) /* in ext slot new offset will be stored in case if new data were added for the same process during next commit */
6262
#define KVAL_SIZE(size) (PMIX_MAX_KEYLEN + 1 + sizeof(size_t) + size)
6363

64+
#define _ESH_LOCK(lockfd, operation) \
65+
do{ \
66+
struct flock fl = {0}; \
67+
fl.l_type = operation; \
68+
fl.l_whence = SEEK_SET; \
69+
fcntl(lockfd, F_SETLKW, &fl); \
70+
}while(0)
71+
6472
static int _store_data_for_rank(ns_track_elem_t *ns_info, pmix_rank_t rank, pmix_buffer_t *buf);
6573
static seg_desc_t *_create_new_segment(segment_type type, char *nsname, uint32_t id);
6674
static seg_desc_t *_attach_new_segment(segment_type type, char *nsname, uint32_t id);
@@ -302,7 +310,7 @@ int _esh_store(const char *nspace, pmix_rank_t rank, pmix_kval_t *kv)
302310
__FILE__, __LINE__, __func__, nspace, rank));
303311

304312
/* set exclusive lock */
305-
flock(_lockfd, LOCK_EX);
313+
_ESH_LOCK(_lockfd, _ESH_LOCK_EX);
306314

307315
/* First of all, we go through local track list (list of ns_track_elem_t structures)
308316
* and look for an element for the target namespace.
@@ -318,7 +326,7 @@ int _esh_store(const char *nspace, pmix_rank_t rank, pmix_kval_t *kv)
318326
if (NULL == elem) {
319327
PMIX_ERROR_LOG(PMIX_ERROR);
320328
/* unset lock */
321-
flock(_lockfd, LOCK_UN);
329+
_ESH_LOCK(_lockfd, _ESH_LOCK_UN);
322330
return PMIX_ERROR;
323331
}
324332

@@ -332,7 +340,7 @@ int _esh_store(const char *nspace, pmix_rank_t rank, pmix_kval_t *kv)
332340
if (PMIX_SUCCESS != rc || NULL == elem->meta_seg || NULL == elem->data_seg) {
333341
PMIX_ERROR_LOG(rc);
334342
/* unset lock */
335-
flock(_lockfd, LOCK_UN);
343+
_ESH_LOCK(_lockfd, _ESH_LOCK_UN);
336344
return PMIX_ERROR;
337345
}
338346

@@ -345,7 +353,7 @@ int _esh_store(const char *nspace, pmix_rank_t rank, pmix_kval_t *kv)
345353
if (PMIX_SUCCESS != rc) {
346354
PMIX_ERROR_LOG(rc);
347355
/* unset lock */
348-
flock(_lockfd, LOCK_UN);
356+
_ESH_LOCK(_lockfd, _ESH_LOCK_UN);
349357
return rc;
350358
}
351359
}
@@ -366,7 +374,7 @@ int _esh_store(const char *nspace, pmix_rank_t rank, pmix_kval_t *kv)
366374
PMIX_DESTRUCT(&pbkt);
367375

368376
/* unset lock */
369-
flock(_lockfd, LOCK_UN);
377+
_ESH_LOCK(_lockfd, _ESH_LOCK_UN);
370378
return rc;
371379
}
372380

@@ -407,7 +415,7 @@ int _esh_fetch(const char *nspace, pmix_rank_t rank, const char *key, pmix_value
407415
}
408416

409417
/* set shared lock */
410-
flock(_lockfd, LOCK_SH);
418+
_ESH_LOCK(_lockfd, _ESH_LOCK_SH);
411419

412420
/* First of all, we go through all initial segments and look at their field.
413421
* If it’s 1, then generate name of next initial segment incrementing id by one and attach to it.
@@ -432,7 +440,7 @@ int _esh_fetch(const char *nspace, pmix_rank_t rank, const char *key, pmix_value
432440
"%s:%d:%s: no data for ns %s is found in the shared memory.",
433441
__FILE__, __LINE__, __func__, nspace));
434442
/* unset lock */
435-
flock(_lockfd, LOCK_UN);
443+
_ESH_LOCK(_lockfd, _ESH_LOCK_UN);
436444
return PMIX_ERROR;
437445
}
438446

@@ -441,7 +449,7 @@ int _esh_fetch(const char *nspace, pmix_rank_t rank, const char *key, pmix_value
441449
if (NULL == elem) {
442450
PMIX_ERROR_LOG(PMIX_ERROR);
443451
/* unset lock */
444-
flock(_lockfd, LOCK_UN);
452+
_ESH_LOCK(_lockfd, _ESH_LOCK_UN);
445453
return PMIX_ERROR;
446454
}
447455
/* need to update tracker:
@@ -451,7 +459,7 @@ int _esh_fetch(const char *nspace, pmix_rank_t rank, const char *key, pmix_value
451459
if (PMIX_SUCCESS != rc) {
452460
PMIX_ERROR_LOG(PMIX_ERROR);
453461
/* unset lock */
454-
flock(_lockfd, LOCK_UN);
462+
_ESH_LOCK(_lockfd, _ESH_LOCK_UN);
455463
return PMIX_ERROR;
456464
}
457465

@@ -558,7 +566,7 @@ int _esh_fetch(const char *nspace, pmix_rank_t rank, const char *key, pmix_value
558566

559567
done:
560568
/* unset lock */
561-
flock(_lockfd, LOCK_UN);
569+
_ESH_LOCK(_lockfd, _ESH_LOCK_UN);
562570
return rc;
563571
}
564572

opal/mca/pmix/pmix3x/pmix/src/dstore/pmix_esh.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ BEGIN_C_DECLS
2525

2626
#define PMIX_DSTORE_ESH_BASE_PATH "PMIX_DSTORE_ESH_BASE_PATH"
2727

28+
#define _ESH_LOCK_EX F_WRLCK
29+
#define _ESH_LOCK_SH F_RDLCK
30+
#define _ESH_LOCK_UN F_UNLCK
31+
2832
typedef enum {
2933
INITIAL_SEGMENT,
3034
NS_META_SEGMENT,

0 commit comments

Comments
 (0)