diff options
-rw-r--r-- | api/src/glfs-fops.c | 46 | ||||
-rw-r--r-- | api/src/glfs.c | 1 | ||||
-rw-r--r-- | api/src/glfs.h | 6 | ||||
-rw-r--r-- | libglusterfs/src/syncop.c | 34 | ||||
-rw-r--r-- | libglusterfs/src/syncop.h | 3 |
5 files changed, 90 insertions, 0 deletions
diff --git a/api/src/glfs-fops.c b/api/src/glfs-fops.c index 3ce930f2745..61c524eaf78 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 21cded39c69..01c3494e28e 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 06849d0c731..7fecffb697a 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 */ diff --git a/libglusterfs/src/syncop.c b/libglusterfs/src/syncop.c index 1a335d147e9..4e3c93a45f8 100644 --- a/libglusterfs/src/syncop.c +++ b/libglusterfs/src/syncop.c @@ -1803,3 +1803,37 @@ syncop_access (xlator_t *subvol, loc_t *loc, int32_t mask) errno = args.op_errno; return args.op_ret; } + + +int +syncop_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int op_ret, int op_errno, struct gf_flock *flock, + dict_t *xdata) +{ + struct syncargs *args = NULL; + + args = cookie; + + args->op_ret = op_ret; + args->op_errno = op_errno; + if (flock) + args->flock = *flock; + __wake (args); + + return 0; +} + + +int +syncop_lk (xlator_t *subvol, fd_t *fd, int cmd, struct gf_flock *flock) +{ + struct syncargs args = {0, }; + + SYNCOP (subvol, (&args), syncop_lk_cbk, subvol->fops->lk, + fd, cmd, flock, NULL); + + errno = args.op_errno; + *flock = args.flock; + + return args.op_ret; +} diff --git a/libglusterfs/src/syncop.h b/libglusterfs/src/syncop.h index 0bb34a24156..cf044d40f36 100644 --- a/libglusterfs/src/syncop.h +++ b/libglusterfs/src/syncop.h @@ -120,6 +120,7 @@ struct syncargs { struct iobref *iobref; char *buffer; dict_t *xdata; + struct gf_flock flock; /* some more _cbk needs */ uuid_t uuid; @@ -325,4 +326,6 @@ int syncop_access (xlator_t *subvol, loc_t *loc, int32_t mask); int syncop_rename (xlator_t *subvol, loc_t *oldloc, loc_t *newloc); +int syncop_lk (xlator_t *subvol, fd_t *fd, int cmd, struct gf_flock *flock); + #endif /* _SYNCOP_H */ |