/*
Copyright (c) 2010-2011 Gluster, Inc. <http://www.gluster.com>
This file is part of GlusterFS.
GlusterFS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
GlusterFS is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
<http://www.gnu.org/licenses/>.
*/
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
#include "client.h"
#include "glusterfs3-xdr.h"
#include "glusterfs3.h"
#include "compat-errno.h"
int32_t client3_getspec (call_frame_t *frame, xlator_t *this, void *data);
void client_start_ping (void *data);
rpc_clnt_prog_t clnt3_1_fop_prog;
int
client_submit_vec_request (xlator_t *this, void *req, call_frame_t *frame,
rpc_clnt_prog_t *prog, int procnum,
fop_cbk_fn_t cbkfn,
struct iovec *payload, int payloadcnt,
struct iobref *iobref, xdrproc_t xdrproc)
{
int ret = 0;
clnt_conf_t *conf = NULL;
struct iovec iov = {0, };
struct iobuf *iobuf = NULL;
int count = 0;
int start_ping = 0;
struct iobref *new_iobref = NULL;
ssize_t xdr_size = 0;
struct rpc_req rpcreq = {0, };
start_ping = 0;
conf = this->private;
if (req && xdrproc) {
xdr_size = xdr_sizeof (xdrproc, req);
iobuf = iobuf_get2 (this->ctx->iobuf_pool, xdr_size);
if (!iobuf) {
goto unwind;
};
new_iobref = iobref_new ();
if (!new_iobref) {
goto unwind;
}
if (iobref != NULL) {
ret = iobref_merge (new_iobref, iobref);
if (ret != 0) {
gf_log (this->name, GF_LOG_WARNING,
"cannot merge iobref passed from caller "
"into new_iobref");
}
}
ret = iobref_add (new_iobref, iobuf);
if (ret != 0) {
gf_log (this->name, GF_LOG_WARNING,
"cannot add iobuf into iobref");
goto unwind;
}
iov.iov_base = iobuf->ptr;
iov.iov_len = iobuf_size (iobuf);
/* Create the xdr payload */
ret = xdr_serialize_generic (iov, req, xdrproc);
if (ret == -1) {
gf_log_callingfn ("", GF_LOG_WARNING,
"XDR function failed");
goto unwind;
}
iov.iov_len = ret;
count = 1;
}
/* Send the msg */
ret = rpc_clnt_submit (conf->rpc, prog, procnum, cbkfn, &iov, count,
payload, payloadcnt, new_iobref, frame, NULL, 0,
NULL, 0, NULL);
if (ret < 0) {
gf_log (this->name, GF_LOG_DEBUG, "rpc_clnt_submit failed");
}
if (ret == 0) {
pthread_mutex_lock (&conf->rpc->conn.lock);
{
if (!conf->rpc->conn.ping_started) {
start_ping = 1;
}
}
pthread_mutex_unlock (&conf->rpc->conn.lock);
}
if (start_ping)
client_start_ping ((void *) this);
if (new_iobref != NULL) {
iobref_unref (new_iobref);
}
iobuf_unref (iobuf);
return ret;
unwind:
rpcreq.rpc_status = -1;
cbkfn (&rpcreq, NULL, 0, frame);
if (new_iobref != NULL) {
iobref_unref (new_iobref);
}
iobuf_unref (iobuf);
return ret;
}
/* CBK */
int
client3_1_symlink_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
gfs3_symlink_rsp rsp = {0,};
struct iatt stbuf = {0,};
struct iatt preparent = {0,};
struct iatt postparent = {0,};
int ret = 0;
clnt_local_t *local = NULL;
inode_t *inode = NULL;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
local = frame->local;
inode = local->loc.inode;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_symlink_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.stat, &stbuf);
gf_stat_to_iatt (&rsp.preparent, &preparent);
gf_stat_to_iatt (&rsp.postparent, &postparent);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: %s",
strerror (gf_error_to_errno (rsp.op_errno)),
(local) ? local->loc.path : "--");
}
CLIENT_STACK_UNWIND (symlink, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), inode, &stbuf,
&preparent, &postparent, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_mknod_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
gfs3_mknod_rsp rsp = {0,};
struct iatt stbuf = {0,};
struct iatt preparent = {0,};
struct iatt postparent = {0,};
int ret = 0;
clnt_local_t *local = NULL;
inode_t *inode = NULL;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
local = frame->local;
inode = local->loc.inode;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_mknod_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.stat, &stbuf);
gf_stat_to_iatt (&rsp.preparent, &preparent);
gf_stat_to_iatt (&rsp.postparent, &postparent);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: %s",
strerror (gf_error_to_errno (rsp.op_errno)),
(local) ? local->loc.path : "--");
}
CLIENT_STACK_UNWIND (mknod, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), inode,
&stbuf, &preparent, &postparent, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_mkdir_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
gfs3_mkdir_rsp rsp = {0,};
struct iatt stbuf = {0,};
struct iatt preparent = {0,};
struct iatt postparent = {0,};
int ret = 0;
clnt_local_t *local = NULL;
inode_t *inode = NULL;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
local = frame->local;
inode = local->loc.inode;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_mkdir_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.stat, &stbuf);
gf_stat_to_iatt (&rsp.preparent, &preparent);
gf_stat_to_iatt (&rsp.postparent, &postparent);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: %s",
strerror (gf_error_to_errno (rsp.op_errno)),
(local) ? local->loc.path : "--");
}
CLIENT_STACK_UNWIND (mkdir, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), inode,
&stbuf, &preparent, &postparent, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_open_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
clnt_local_t *local = NULL;
clnt_conf_t *conf = NULL;
clnt_fd_ctx_t *fdctx = NULL;
call_frame_t *frame = NULL;
fd_t *fd = NULL;
int ret = 0;
gfs3_open_rsp rsp = {0,};
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
local = frame->local;
conf = frame->this->private;
fd = local->fd;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_open_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
fdctx = GF_CALLOC (1, sizeof (*fdctx),
gf_client_mt_clnt_fdctx_t);
if (!fdctx) {
rsp.op_ret = -1;
rsp.op_errno = ENOMEM;
goto out;
}
fdctx->remote_fd = rsp.fd;
fdctx->inode = inode_ref (fd->inode);
fdctx->flags = local->flags;
fdctx->wbflags = local->wbflags;
fdctx->lk_ctx = fd_lk_ctx_ref (fd->lk_ctx);
fdctx->lk_heal_state = GF_LK_HEAL_DONE;
INIT_LIST_HEAD (&fdctx->sfd_pos);
INIT_LIST_HEAD (&fdctx->lock_list);
this_fd_set_ctx (fd, frame->this, &local->loc, fdctx);
pthread_mutex_lock (&conf->lock);
{
list_add_tail (&fdctx->sfd_pos, &conf->saved_fds);
}
pthread_mutex_unlock (&conf->lock);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: %s",
strerror (gf_error_to_errno (rsp.op_errno)),
(local) ? local->loc.path : "--");
}
CLIENT_STACK_UNWIND (open, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), fd, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_stat_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
gfs3_stat_rsp rsp = {0,};
call_frame_t *frame = NULL;
struct iatt iatt = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_stat_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.stat, &iatt);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (stat, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), &iatt, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_readlink_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
gfs3_readlink_rsp rsp = {0,};
call_frame_t *frame = NULL;
struct iatt iatt = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_readlink_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.buf, &iatt);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (readlink, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), rsp.path,
&iatt, xdata);
/* This is allocated by the libc while decoding RPC msg */
/* Hence no 'GF_FREE', but just 'free' */
if (rsp.path)
free (rsp.path);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_unlink_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
gfs3_unlink_rsp rsp = {0,};
struct iatt preparent = {0,};
struct iatt postparent = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_unlink_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.preparent, &preparent);
gf_stat_to_iatt (&rsp.postparent, &postparent);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (unlink, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), &preparent,
&postparent, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_rmdir_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
gfs3_rmdir_rsp rsp = {0,};
call_frame_t *frame = NULL;
struct iatt preparent = {0,};
struct iatt postparent = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_rmdir_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.preparent, &preparent);
gf_stat_to_iatt (&rsp.postparent, &postparent);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (rmdir, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), &preparent,
&postparent, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_truncate_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
gfs3_truncate_rsp rsp = {0,};
call_frame_t *frame = NULL;
struct iatt prestat = {0,};
struct iatt poststat = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_truncate_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.prestat, &prestat);
gf_stat_to_iatt (&rsp.poststat, &poststat);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (truncate, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), &prestat,
&poststat, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_statfs_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
gfs3_statfs_rsp rsp = {0,};
call_frame_t *frame = NULL;
struct statvfs statfs = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_statfs_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_statfs_to_statfs (&rsp.statfs, &statfs);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (statfs, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), &statfs, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_writev_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
gfs3_write_rsp rsp = {0,};
call_frame_t *frame = NULL;
struct iatt prestat = {0,};
struct iatt poststat = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_truncate_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.prestat, &prestat);
gf_stat_to_iatt (&rsp.poststat, &poststat);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (writev, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), &prestat,
&poststat, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_flush_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
clnt_local_t *local = NULL;
xlator_t *this = NULL;
dict_t *xdata = NULL;
gf_common_rsp rsp = {0,};
int ret = 0;
frame = myframe;
this = THIS;
local = frame->local;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (rsp.op_ret >= 0 && !fd_is_anonymous (local->fd)) {
/* Delete all saved locks of the owner issuing flush */
ret = delete_granted_locks_owner (local->fd, &local->owner);
gf_log (this->name, GF_LOG_TRACE,
"deleting locks of owner (%s) returned %d",
lkowner_utoa (&local->owner), ret);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (flush, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_fsync_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
gfs3_fsync_rsp rsp = {0,};
call_frame_t *frame = NULL;
struct iatt prestat = {0,};
struct iatt poststat = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_truncate_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
if (-1 != rsp.op_ret) {
gf_stat_to_iatt (&rsp.prestat, &prestat);
gf_stat_to_iatt (&rsp.poststat, &poststat);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (fsync, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), &prestat,
&poststat, xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_setxattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
gf_common_rsp rsp = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (setxattr, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_getxattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
dict_t *dict = NULL;
int op_errno = EINVAL;
gfs3_getxattr_rsp rsp = {0,};
int ret = 0;
clnt_local_t *local = NULL;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
local = frame->local;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_getxattr_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
op_errno = EINVAL;
goto out;
}
op_errno = gf_error_to_errno (rsp.op_errno);
if (-1 != rsp.op_ret) {
GF_PROTOCOL_DICT_UNSERIALIZE (frame->this, dict,
(rsp.dict.dict_val),
(rsp.dict.dict_len), rsp.op_ret,
op_errno, out);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s. Path: %s",
strerror (op_errno),
(local) ? local->loc.path : "--");
}
CLIENT_STACK_UNWIND (getxattr, frame, rsp.op_ret, op_errno, dict, xdata);
/* don't use GF_FREE, this memory was allocated by libc */
if (rsp.dict.dict_val)
free (rsp.dict.dict_val);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
if (dict)
dict_unref (dict);
return 0;
}
int
client3_1_fgetxattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
dict_t *dict = NULL;
gfs3_fgetxattr_rsp rsp = {0,};
int ret = 0;
int op_errno = EINVAL;
clnt_local_t *local = NULL;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
local = frame->local;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs3_fgetxattr_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
op_errno = EINVAL;
goto out;
}
op_errno = gf_error_to_errno (rsp.op_errno);
if (-1 != rsp.op_ret) {
GF_PROTOCOL_DICT_UNSERIALIZE (frame->this, dict,
(rsp.dict.dict_val),
(rsp.dict.dict_len), rsp.op_ret,
op_errno, out);
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING,
"remote operation failed: %s",
strerror (op_errno));
}
CLIENT_STACK_UNWIND (fgetxattr, frame, rsp.op_ret, op_errno, dict, xdata);
if (rsp.dict.dict_val)
free (rsp.dict.dict_val);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
if (dict)
dict_unref (dict);
return 0;
}
int
client3_1_removexattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
gf_common_rsp rsp = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (removexattr, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_fremovexattr_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
gf_common_rsp rsp = {0,};
int ret = 0;
xlator_t *this = NULL;
dict_t *xdata = NULL;
this = THIS;
frame = myframe;
if (-1 == req->rpc_status) {
rsp.op_ret = -1;
rsp.op_errno = ENOTCONN;
goto out;
}
ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gf_common_rsp);
if (ret < 0) {
gf_log (this->name, GF_LOG_ERROR, "XDR decoding failed");
rsp.op_ret = -1;
rsp.op_errno = EINVAL;
goto out;
}
GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val),
(rsp.xdata.xdata_len), ret,
rsp.op_errno, out);
out:
if (rsp.op_ret == -1) {
gf_log (this->name, GF_LOG_WARNING, "remote operation failed: %s",
strerror (gf_error_to_errno (rsp.op_errno)));
}
CLIENT_STACK_UNWIND (fremovexattr, frame, rsp.op_ret,
gf_error_to_errno (rsp.op_errno), xdata);
if (rsp.xdata.xdata_val)
free (rsp.xdata.xdata_val);
if (xdata)
dict_unref (xdata);
return 0;
}
int
client3_1_fsyncdir_cbk (struct rpc_req *req, struct iovec *iov, int count,
void *myframe)
{
call_frame_t *frame = NULL;
gf_common_rsp rsp = {0,};
int ret = 0;
xlator_t *this = NULL;
|