summaryrefslogtreecommitdiffstats
path: root/api/src
diff options
context:
space:
mode:
authorAnand Avati <avati@redhat.com>2013-04-15 09:52:35 -0700
committerVijay Bellur <vbellur@redhat.com>2013-04-24 01:06:05 -0700
commit1bcb1c4d5225e197464d1c64bafd4e7ef4042e78 (patch)
tree7830fb42d61e6f8c845dc3199b7701007283eaee /api/src
parentd37b2198dc8f763205f5b7e56a0e40252ccf97fe (diff)
gfapi: POSIX locking support
Change-Id: I37d9e1fb4a715094876be6af3856c1b4cf398021 BUG: 953694 Signed-off-by: Anand Avati <avati@redhat.com> Reviewed-on: http://review.gluster.org/4881 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'api/src')
-rw-r--r--api/src/glfs-fops.c46
-rw-r--r--api/src/glfs.c1
-rw-r--r--api/src/glfs.h6
3 files changed, 53 insertions, 0 deletions
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c
index 3ce930f27..61c524eaf 100644
--- a/api/src/glfs-fops.c
+++ b/api/src/glfs-fops.c
@@ -2315,3 +2315,49 @@ out:
return buf;
}
+
+
+static void
+gf_flock_to_flock (struct gf_flock *gf_flock, struct flock *flock)
+{
+ flock->l_type = gf_flock->l_type;
+ flock->l_whence = gf_flock->l_whence;
+ flock->l_start = gf_flock->l_start;
+ flock->l_len = gf_flock->l_len;
+ flock->l_pid = gf_flock->l_pid;
+}
+
+
+static void
+gf_flock_from_flock (struct gf_flock *gf_flock, struct flock *flock)
+{
+ gf_flock->l_type = flock->l_type;
+ gf_flock->l_whence = flock->l_whence;
+ gf_flock->l_start = flock->l_start;
+ gf_flock->l_len = flock->l_len;
+ gf_flock->l_pid = flock->l_pid;
+}
+
+
+int
+glfs_posix_lock (struct glfs_fd *glfd, int cmd, struct flock *flock)
+{
+ int ret = -1;
+ xlator_t *subvol = NULL;
+ struct gf_flock gf_flock = {0, };
+
+ __glfs_entry_fd (glfd);
+
+ subvol = glfs_fd_subvol (glfd);
+ if (!subvol) {
+ ret = -1;
+ errno = EIO;
+ goto out;
+ }
+
+ gf_flock_from_flock (&gf_flock, flock);
+ ret = syncop_lk (subvol, glfd->fd, cmd, &gf_flock);
+ gf_flock_to_flock (&gf_flock, flock);
+out:
+ return ret;
+}
diff --git a/api/src/glfs.c b/api/src/glfs.c
index 21cded39c..01c3494e2 100644
--- a/api/src/glfs.c
+++ b/api/src/glfs.c
@@ -11,6 +11,7 @@
/*
TODO:
+ - merge locks in glfs_posix_lock for lock self-healing
- refresh fs->cwd inode on graph switch
- set proper pid/lk_owner to call frames (currently buried in syncop)
- fix logging.c/h to store logfp and loglevel in glusterfs_ctx_t and
diff --git a/api/src/glfs.h b/api/src/glfs.h
index 06849d0c7..7fecffb69 100644
--- a/api/src/glfs.h
+++ b/api/src/glfs.h
@@ -453,6 +453,12 @@ int glfs_fchdir (glfs_fd_t *fd);
char *glfs_realpath (glfs_t *fs, const char *path, char *resolved_path);
+/*
+ * @cmd and @flock are as specified in man fcntl(2).
+ */
+int glfs_posix_lock (glfs_fd_t *fd, int cmd, struct flock *flock);
+
+
__END_DECLS
#endif /* !_GLFS_H */