]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd_fuse:replaced pthread_mutex*() functions with ceph Mutex wrapper
authorSahithi R V <tansy.rv@gmail.com>
Thu, 28 Jan 2016 17:46:25 +0000 (23:16 +0530)
committerSahithi R V <tansy.rv@gmail.com>
Fri, 29 Jan 2016 11:45:07 +0000 (17:15 +0530)
Signed-off-by: Sahithi R V <tansy.rv@gmail.com>
src/rbd_fuse/rbd-fuse.cc

index 9e92441b65d007dd7f3ea1ec30a785f799969890..c55f513f3c46a10140f538d2a7cd8f5f8a280984 100644 (file)
@@ -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);
 }