* [PATCH 1/2] pshared: Add mutex_init_pshared_with_type()
2020-05-28 12:56 [PATCH 0/2] Fix compilation error on BSD Shin'ichiro Kawasaki
@ 2020-05-28 12:56 ` Shin'ichiro Kawasaki
2020-05-28 12:56 ` [PATCH 2/2] zbd: Fix compilation error on BSD Shin'ichiro Kawasaki
2020-05-28 16:36 ` [PATCH 0/2] " Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Shin'ichiro Kawasaki @ 2020-05-28 12:56 UTC (permalink / raw)
To: fio, Jens Axboe; +Cc: Tomohiro Kusumi, Damien Le Moal, Shinichiro Kawasaki
To initialize mutex to be shared across processes, the helper function
mutex_init_pshared() is available. However, it does not allow to set
mutex attribute types such as POSIX_MUTEX_RECURSIVE.
To allow setting mutex attribute types, introduce another helper function
mutex_init_pshared_with_type(). It initialize mutex for sharing across
processes and set attribute types specified as its argument.
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
pshared.c | 15 ++++++++++++++-
pshared.h | 1 +
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/pshared.c b/pshared.c
index 21192556..791faf95 100644
--- a/pshared.c
+++ b/pshared.c
@@ -39,7 +39,7 @@ int cond_init_pshared(pthread_cond_t *cond)
return 0;
}
-int mutex_init_pshared(pthread_mutex_t *mutex)
+int mutex_init_pshared_with_type(pthread_mutex_t *mutex, int type)
{
pthread_mutexattr_t mattr;
int ret;
@@ -60,6 +60,14 @@ int mutex_init_pshared(pthread_mutex_t *mutex)
return ret;
}
#endif
+ if (type) {
+ ret = pthread_mutexattr_settype(&mattr, type);
+ if (ret) {
+ log_err("pthread_mutexattr_settype: %s\n",
+ strerror(ret));
+ return ret;
+ }
+ }
ret = pthread_mutex_init(mutex, &mattr);
if (ret) {
log_err("pthread_mutex_init: %s\n", strerror(ret));
@@ -69,6 +77,11 @@ int mutex_init_pshared(pthread_mutex_t *mutex)
return 0;
}
+int mutex_init_pshared(pthread_mutex_t *mutex)
+{
+ return mutex_init_pshared_with_type(mutex, 0);
+}
+
int mutex_cond_init_pshared(pthread_mutex_t *mutex, pthread_cond_t *cond)
{
int ret;
diff --git a/pshared.h b/pshared.h
index a58df6fe..f33be462 100644
--- a/pshared.h
+++ b/pshared.h
@@ -3,6 +3,7 @@
#include <pthread.h>
+extern int mutex_init_pshared_with_type(pthread_mutex_t *, int);
extern int mutex_init_pshared(pthread_mutex_t *);
extern int cond_init_pshared(pthread_cond_t *);
extern int mutex_cond_init_pshared(pthread_mutex_t *, pthread_cond_t *);
--
2.25.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] zbd: Fix compilation error on BSD
2020-05-28 12:56 [PATCH 0/2] Fix compilation error on BSD Shin'ichiro Kawasaki
2020-05-28 12:56 ` [PATCH 1/2] pshared: Add mutex_init_pshared_with_type() Shin'ichiro Kawasaki
@ 2020-05-28 12:56 ` Shin'ichiro Kawasaki
2020-05-28 16:36 ` [PATCH 0/2] " Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Shin'ichiro Kawasaki @ 2020-05-28 12:56 UTC (permalink / raw)
To: fio, Jens Axboe; +Cc: Tomohiro Kusumi, Damien Le Moal, Shinichiro Kawasaki
Commit b76949618d55 ("fio: Generalize zonemode=zbd") enabled zbd.c
compilation on other operating systems than Linux. This caused a
compilation error on NetBSD as follows:
ld: zbd.o: in function `parse_zone_info':
fio/zbd.c:422: undefined reference to `pthread_mutexattr_setpshared'
ld: zbd.o: in function `init_zone_info':
fio/zbd.c:378: undefined reference to `pthread_mutexattr_setpshared'
gmake: *** [Makefile:483: fio] Error 1
Same error is expected on other BSD OSes.
Fix this by initializing mutex using helper functions pshared.c provides.
To initialize mutex with POSIX_MUTEX_RECURSIVE attribute type, utilize
mutex_init_pshared_with_type().
Reported-by: Tomohiro Kusumi <kusumi.tomohiro@gmail.com>
Fixes: b76949618d55 ("fio: Generalize zonemode=zbd")
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
---
zbd.c | 22 +++++++---------------
1 file changed, 7 insertions(+), 15 deletions(-)
diff --git a/zbd.c b/zbd.c
index 72352db0..a7572c9a 100644
--- a/zbd.c
+++ b/zbd.c
@@ -19,6 +19,7 @@
#include "oslib/asprintf.h"
#include "smalloc.h"
#include "verify.h"
+#include "pshared.h"
#include "zbd.h"
/**
@@ -353,7 +354,6 @@ static int init_zone_info(struct thread_data *td, struct fio_file *f)
struct fio_zone_info *p;
uint64_t zone_size = td->o.zone_size;
struct zoned_block_device_info *zbd_info = NULL;
- pthread_mutexattr_t attr;
int i;
if (zone_size == 0) {
@@ -374,14 +374,12 @@ static int init_zone_info(struct thread_data *td, struct fio_file *f)
if (!zbd_info)
return -ENOMEM;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_setpshared(&attr, true);
- pthread_mutex_init(&zbd_info->mutex, &attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+ mutex_init_pshared(&zbd_info->mutex);
zbd_info->refcount = 1;
p = &zbd_info->zone_info[0];
for (i = 0; i < nr_zones; i++, p++) {
- pthread_mutex_init(&p->mutex, &attr);
+ mutex_init_pshared_with_type(&p->mutex,
+ PTHREAD_MUTEX_RECURSIVE);
p->start = i * zone_size;
p->wp = p->start + zone_size;
p->type = ZBD_ZONE_TYPE_SWR;
@@ -395,7 +393,6 @@ static int init_zone_info(struct thread_data *td, struct fio_file *f)
f->zbd_info->zone_size_log2 = is_power_of_2(zone_size) ?
ilog2(zone_size) : 0;
f->zbd_info->nr_zones = nr_zones;
- pthread_mutexattr_destroy(&attr);
return 0;
}
@@ -415,12 +412,8 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f)
struct fio_zone_info *p;
uint64_t zone_size, offset;
struct zoned_block_device_info *zbd_info = NULL;
- pthread_mutexattr_t attr;
int i, j, ret = 0;
- pthread_mutexattr_init(&attr);
- pthread_mutexattr_setpshared(&attr, true);
-
zones = calloc(ZBD_REPORT_MAX_ZONES, sizeof(struct zbd_zone));
if (!zones)
goto out;
@@ -454,14 +447,14 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f)
ret = -ENOMEM;
if (!zbd_info)
goto out;
- pthread_mutex_init(&zbd_info->mutex, &attr);
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+ mutex_init_pshared(&zbd_info->mutex);
zbd_info->refcount = 1;
p = &zbd_info->zone_info[0];
for (offset = 0, j = 0; j < nr_zones;) {
z = &zones[0];
for (i = 0; i < nrz; i++, j++, z++, p++) {
- pthread_mutex_init(&p->mutex, &attr);
+ mutex_init_pshared_with_type(&p->mutex,
+ PTHREAD_MUTEX_RECURSIVE);
p->start = z->start;
switch (z->cond) {
case ZBD_ZONE_COND_NOT_WP:
@@ -512,7 +505,6 @@ static int parse_zone_info(struct thread_data *td, struct fio_file *f)
out:
sfree(zbd_info);
free(zones);
- pthread_mutexattr_destroy(&attr);
return ret;
}
--
2.25.4
^ permalink raw reply related [flat|nested] 4+ messages in thread