summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@zresearch.com>2009-04-16 23:55:55 -0700
committerAnand V. Avati <avati@amp.gluster.com>2009-04-17 13:43:42 +0530
commite18b8031ab4c7ce763e1e7d57bf5c98a1cbe7167 (patch)
tree3ebee39129db0cdf82064e9e701ab62e191badd0 /libglusterfsclient
parent9193494d20a8555a90126b9d23e848b0b8ca196e (diff)
libglusterfsclient: Add ftruncate API
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'libglusterfsclient')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index de26203e618..9a97b6d619d 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -3778,6 +3778,83 @@ out:
return op_ret;
}
+int
+libgf_client_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *xlator
+ ,int32_t op_ret, int32_t op_errno,
+ struct stat *buf)
+{
+ libgf_client_local_t *local = frame->local;
+
+ local->reply_stub = fop_ftruncate_cbk_stub (frame, NULL, op_ret,
+ op_errno, buf);
+
+ LIBGF_REPLY_NOTIFY (local);
+
+ return 0;
+}
+
+int
+libgf_client_ftruncate (libglusterfs_client_ctx_t *ctx, fd_t *fd,
+ off_t length)
+{
+ libgf_client_local_t *local = NULL;
+ call_stub_t *stub = NULL;
+ int op_ret = -1;
+ libglusterfs_client_fd_ctx_t *fdctx = NULL;
+
+ if (!(fd->flags & O_RDWR) && (!(fd->flags & O_WRONLY))) {
+ errno = EBADF;
+ goto out;
+ }
+
+ LIBGF_CLIENT_FOP (ctx, stub, ftruncate, local, fd, length);
+
+ op_ret = stub->args.ftruncate_cbk.op_ret;
+ errno = stub->args.ftruncate_cbk.op_errno;
+
+ if (op_ret == -1)
+ goto out;
+ libgf_update_iattr_cache (fd->inode, LIBGF_UPDATE_STAT,
+ &stub->args.ftruncate_cbk.buf);
+
+ fdctx = libgf_get_fd_ctx (fd);
+ if (!fd) {
+ errno = EINVAL;
+ op_ret = -1;
+ goto out;
+ }
+
+ pthread_mutex_lock (&fdctx->lock);
+ {
+ fdctx->offset = stub->args.ftruncate_cbk.buf.st_size;
+ }
+ pthread_mutex_lock (&fdctx->lock);
+
+out:
+ call_stub_destroy (stub);
+ return op_ret;
+}
+
+int
+glusterfs_ftruncate (glusterfs_file_t fd, off_t length)
+{
+ libglusterfs_client_fd_ctx_t *fdctx = NULL;
+ int op_ret = -1;
+
+ GF_VALIDATE_OR_GOTO (LIBGF_XL_NAME, fd, out);
+
+ fdctx = libgf_get_fd_ctx (fd);
+ if (!fdctx) {
+ errno = EBADF;
+ goto out;
+ }
+
+ op_ret = libgf_client_ftruncate (fdctx->ctx, fd, length);
+
+out:
+ return op_ret;
+}
+
static struct xlator_fops libgf_client_fops = {
};