summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfsclient')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c91
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.h26
2 files changed, 117 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index 11ee08d03..89c57182e 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -6888,6 +6888,97 @@ glusterfs_sendfile (int out_fd, glusterfs_file_t in_fd, off_t *offset,
return ret;
}
+
+static int32_t
+libgf_client_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this,
+ int32_t op_ret, int32_t op_errno, struct flock *lock)
+{
+ libgf_client_local_t *local = frame->local;
+
+ local->reply_stub = fop_lk_cbk_stub (frame, NULL, op_ret, op_errno,
+ lock);
+
+ LIBGF_REPLY_NOTIFY (local);
+
+ return 0;
+}
+
+
+int
+libgf_client_lk (libglusterfs_client_ctx_t *ctx, fd_t *fd, int cmd,
+ struct flock *lock)
+{
+ call_stub_t *stub = NULL;
+ int32_t op_ret;
+ libgf_client_local_t *local = NULL;
+
+ LIBGF_CLIENT_FOP(ctx, stub, lk, local, fd, cmd, lock);
+
+ op_ret = stub->args.lk_cbk.op_ret;
+ errno = stub->args.lk_cbk.op_errno;
+ if (op_ret == 0) {
+ *lock = stub->args.lk_cbk.lock;
+ }
+
+ call_stub_destroy (stub);
+ return op_ret;
+}
+
+
+int
+glusterfs_fcntl (glusterfs_file_t fd, int cmd, ...)
+{
+ int ret = -1;
+ struct flock *lock = NULL;
+ va_list ap;
+ libglusterfs_client_ctx_t *ctx = NULL;
+ libglusterfs_client_fd_ctx_t *fd_ctx = NULL;
+
+ GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, fd, out);
+
+ fd_ctx = libgf_get_fd_ctx (fd);
+ if (!fd_ctx) {
+ errno = EBADF;
+ goto out;
+ }
+
+ ctx = fd_ctx->ctx;
+
+ switch (cmd) {
+ case F_SETLK:
+ case F_SETLKW:
+ case F_GETLK:
+#if F_SETLK != F_SETLK64
+ case F_SETLK64:
+#endif
+#if F_SETLKW != F_SETLKW64
+ case F_SETLKW64:
+#endif
+#if F_GETLK != F_GETLK64
+ case F_GETLK64:
+#endif
+ va_start (ap, cmd);
+ lock = va_arg (ap, struct flock *);
+ va_end (ap);
+
+ if (!lock) {
+ errno = EINVAL;
+ goto out;
+ }
+
+ ret = libgf_client_lk (ctx, fd, cmd, lock);
+ break;
+
+ default:
+ errno = EINVAL;
+ break;
+ }
+
+out:
+ return ret;
+}
+
+
static struct xlator_fops libgf_client_fops = {
};
diff --git a/libglusterfsclient/src/libglusterfsclient.h b/libglusterfsclient/src/libglusterfsclient.h
index 7ce7288f8..795857c9c 100755
--- a/libglusterfsclient/src/libglusterfsclient.h
+++ b/libglusterfsclient/src/libglusterfsclient.h
@@ -1277,6 +1277,32 @@ ssize_t
glusterfs_sendfile (int out_fd, glusterfs_file_t in_fd, off_t *offset,
size_t count);
+/* manipulate file descriptor
+ * This api can have 3 forms similar to fcntl(2).
+ *
+ * int
+ * glusterfs_fcntl (glusterfs_file_t fd, int cmd)
+ *
+ * int
+ * glusterfs_fcntl (glusterfs_file_t fd, int cmd, long arg)
+ *
+ * int
+ * glusterfs_fcntl (glusterfs_file_t fd, int cmd, struct flock *lock)
+ *
+ * @fd : file handle returned by glusterfs_open or glusterfs_create.
+ * @cmd : Though the aim is to implement all possible commands supported by
+ * fcntl(2), currently following commands are supported.
+ * F_SETLK, F_SETLKW, F_GETLK - used to acquire, release, and test for
+ * the existence of record locks (also
+ * known as file-segment or file-region
+ * locks). More detailed explanation is
+ * found in 'man 2 fcntl'
+ */
+
+int
+glusterfs_fcntl (glusterfs_file_t fd, int cmd, ...);
+
+
/* FIXME: review the need for these apis */
/* added for log related initialization in booster fork implementation */
void