From: Sahithi R V Date: Thu, 28 Jan 2016 17:46:25 +0000 (+0530) Subject: rbd_fuse:replaced pthread_mutex*() functions with ceph Mutex wrapper X-Git-Tag: v10.0.4~113^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=fa7470a0bb8af4bdd23a97b167db1b5180087982;p=ceph-ci.git rbd_fuse:replaced pthread_mutex*() functions with ceph Mutex wrapper Signed-off-by: Sahithi R V --- diff --git a/src/rbd_fuse/rbd-fuse.cc b/src/rbd_fuse/rbd-fuse.cc index 9e92441b65d..c55f513f3c4 100644 --- a/src/rbd_fuse/rbd-fuse.cc +++ b/src/rbd_fuse/rbd-fuse.cc @@ -26,6 +26,7 @@ #include "include/compat.h" #include "include/rbd/librbd.h" +#include "common/Mutex.h" static int gotrados = 0; char *pool_name; @@ -33,7 +34,7 @@ char *mount_image_name; rados_t cluster; rados_ioctx_t ioctx; -static pthread_mutex_t readdir_lock; +Mutex readdir_lock("read_dir"); struct rbd_stat { u_char valid; @@ -212,11 +213,11 @@ iter_images(void *cookie, { struct rbd_image *im; - pthread_mutex_lock(&readdir_lock); - + readdir_lock.Lock(); + for (im = rbd_image_data.images; im != NULL; im = im->next) iter(cookie, im->image_name); - pthread_mutex_unlock(&readdir_lock); + readdir_lock.Unlock(); } static void count_images_cb(void *cookie, const char *image) @@ -228,9 +229,9 @@ static int count_images(void) { unsigned int count = 0; - pthread_mutex_lock(&readdir_lock); + readdir_lock.Lock(); enumerate_images(&rbd_image_data); - pthread_mutex_unlock(&readdir_lock); + readdir_lock.Unlock(); iter_images(&count, count_images_cb); return count; @@ -269,9 +270,9 @@ static int rbdfs_getattr(const char *path, struct stat *stbuf) } if (!in_opendir) { - pthread_mutex_lock(&readdir_lock); + readdir_lock.Lock(); enumerate_images(&rbd_image_data); - pthread_mutex_unlock(&readdir_lock); + readdir_lock.Unlock(); } fd = open_rbd_image(path + 1); if (fd < 0) @@ -303,9 +304,9 @@ static int rbdfs_open(const char *path, struct fuse_file_info *fi) if (path[0] == 0) return -ENOENT; - pthread_mutex_lock(&readdir_lock); + readdir_lock.Lock(); enumerate_images(&rbd_image_data); - pthread_mutex_unlock(&readdir_lock); + readdir_lock.Unlock(); fd = open_rbd_image(path + 1); if (fd < 0) return -ENOENT; @@ -401,9 +402,9 @@ static int rbdfs_statfs(const char *path, struct statvfs *buf) num[0] = 1; num[1] = 0; - pthread_mutex_lock(&readdir_lock); + readdir_lock.Lock(); enumerate_images(&rbd_image_data); - pthread_mutex_unlock(&readdir_lock); + readdir_lock.Unlock(); iter_images(num, rbdfs_statfs_image_cb); #define RBDFS_BSIZE 4096 @@ -434,10 +435,10 @@ static int rbdfs_fsync(const char *path, int datasync, static int rbdfs_opendir(const char *path, struct fuse_file_info *fi) { // only one directory, so global "in_opendir" flag should be fine - pthread_mutex_lock(&readdir_lock); + readdir_lock.Lock(); in_opendir++; enumerate_images(&rbd_image_data); - pthread_mutex_unlock(&readdir_lock); + readdir_lock.Unlock(); return 0; } @@ -475,9 +476,9 @@ static int rbdfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler, static int rbdfs_releasedir(const char *path, struct fuse_file_info *fi) { // see opendir comments - pthread_mutex_lock(&readdir_lock); + readdir_lock.Lock(); in_opendir--; - pthread_mutex_unlock(&readdir_lock); + readdir_lock.Unlock(); return 0; } @@ -883,7 +884,5 @@ int main(int argc, char *argv[]) exit(1); } - pthread_mutex_init(&readdir_lock, NULL); - return fuse_main(args.argc, args.argv, &rbdfs_oper, NULL); }