diff options
19 files changed, 18796 insertions, 879 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c index 8a6fbb21d4b..d1a64c4a3a2 100644 --- a/libglusterfs/src/dict.c +++ b/libglusterfs/src/dict.c @@ -29,8 +29,6 @@ #include "libglusterfs-messages.h" #include "glusterfs-fops.h" -#include "rpc-common-xdr.h" -#include "glusterfs3.h" struct dict_cmp { dict_t *dict; @@ -3251,210 +3249,3 @@ unlock: UNLOCK (&dict->lock); return 0; } - -/* dict_to_xdr () */ -int -dict_to_xdr (dict_t *this, gfx_dict *dict) -{ - int ret = -1; - int i = 0; - int index = 0; - data_pair_t *dpair = NULL; - gfx_dict_pair *xpair = NULL; - - /* This is a failure as we expect destination to be valid */ - if (!dict) - goto out; - - /* This is OK as dictionary can be null, in which case, destination - will be set as 0 sized dictionary */ - if (!this) { - ret = 0; - dict->count = 0; - dict->pairs.pairs_len = 0; - goto out; - } - - dict->pairs.pairs_val = GF_CALLOC (1, (this->count * - sizeof (gfx_dict_pair)), - gf_common_mt_char); - if (!dict->pairs.pairs_val) - goto out; - - dpair = this->members_list; - for (i = 0; i < this->count; i++) { - xpair = &dict->pairs.pairs_val[index]; - - xpair->value.type = dpair->value->data_type; - xpair->key.key_val = dpair->key; - xpair->key.key_len = strlen (dpair->key) + 1; - - switch (dpair->value->data_type) { - /* Add more type here */ - case GF_DATA_TYPE_INT: - index++; - data_to_int64_ptr (dpair->value, &xpair->value.gfx_value_u.value_int); - break; - case GF_DATA_TYPE_UINT: - index++; - data_to_uint64_ptr (dpair->value, &xpair->value.gfx_value_u.value_uint); - break; - case GF_DATA_TYPE_DOUBLE: - index++; - data_to_double_ptr (dpair->value, - &xpair->value.gfx_value_u.value_dbl); - break; - case GF_DATA_TYPE_STR: - index++; - xpair->value.gfx_value_u.val_string.val_string_val = dpair->value->data; - xpair->value.gfx_value_u.val_string.val_string_len = dpair->value->len; - break; - case GF_DATA_TYPE_IATT: - index++; - gf_stat_from_iatt (&xpair->value.gfx_value_u.iatt, - (struct iatt *)dpair->value->data); - break; - case GF_DATA_TYPE_GFUUID: - index++; - memcpy (&xpair->value.gfx_value_u.uuid, - dpair->value->data, sizeof (uuid_t)); - break; - - case GF_DATA_TYPE_PTR: - index++; - /* Ideally, each type of data stored in dictionary - should have type. A pointer type shouldn't be - sent on wire */ - - /* This is done for backward compatibility as dict is - heavily used for transporting data over wire. - Ideally, whereever there is an issue, fix and move on */ - xpair->value.gfx_value_u.other.other_val = - dpair->value->data; - xpair->value.gfx_value_u.other.other_len = - dpair->value->len; - - /* Change this to INFO, after taking the above down */ - gf_msg ("dict", GF_LOG_INFO, EINVAL, - LG_MSG_DICT_SERIAL_FAILED, - "key '%s' is would not be sent on wire in future", - dpair->key); - break; - default: - /* Unknown type and ptr type is not sent on wire */ - gf_msg ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_DICT_SERIAL_FAILED, - "key '%s' is not sent on wire", dpair->key); - break; - } - - dpair = dpair->next; - } - - dict->pairs.pairs_len = index; - dict->count = index; - ret = 0; -out: - return ret; -} - -int -xdr_to_dict (gfx_dict *dict, dict_t **to) -{ - int ret = -1; - int index = 0; - char *key = NULL; - char *value = NULL; - gfx_dict_pair *xpair = NULL; - dict_t *this = NULL; - unsigned char *uuid = NULL; - struct iatt *iatt = NULL; - - if (!to || !dict) - goto out; - - this = dict_new(); - if (!this) - goto out; - - for (index = 0; index < dict->pairs.pairs_len; index++) { - ret = -1; - xpair = &dict->pairs.pairs_val[index]; - - key = xpair->key.key_val; - switch (xpair->value.type) { - /* Add more type here */ - case GF_DATA_TYPE_INT: - ret = dict_set_int64 (this, key, - xpair->value.gfx_value_u.value_int); - break; - case GF_DATA_TYPE_UINT: - ret = dict_set_uint64 (this, key, - xpair->value.gfx_value_u.value_uint); - break; - case GF_DATA_TYPE_DOUBLE: - ret = dict_set_double (this, key, - xpair->value.gfx_value_u.value_dbl); - break; - case GF_DATA_TYPE_STR: - value = gf_strdup (xpair->value.gfx_value_u.val_string.val_string_val); - if (!value) { - errno = ENOMEM; - goto out; - } - free (xpair->value.gfx_value_u.val_string.val_string_val); - ret = dict_set_dynstr (this, key, value); - break; - case GF_DATA_TYPE_GFUUID: - uuid = GF_CALLOC (1, 20, gf_common_mt_uuid_t); - if (!uuid) { - errno = ENOMEM; - goto out; - } - memcpy (uuid, xpair->value.gfx_value_u.uuid, 16); - ret = dict_set_gfuuid (this, key, uuid, false); - break; - case GF_DATA_TYPE_IATT: - iatt = GF_CALLOC (1, sizeof (struct iatt), gf_common_mt_char); - if (!iatt) { - errno = ENOMEM; - goto out; - } - gf_stat_to_iatt (&xpair->value.gfx_value_u.iatt, iatt); - ret = dict_set_iatt (this, key, iatt, false); - break; - case GF_DATA_TYPE_PTR: - value = gf_memdup (xpair->value.gfx_value_u.other.other_val, - xpair->value.gfx_value_u.other.other_len); - if (!value) { - errno = ENOMEM; - goto out; - } - free (xpair->value.gfx_value_u.other.other_val); - ret = dict_set_dynptr (this, key, value, - xpair->value.gfx_value_u.other.other_len); - break; - default: - ret = 0; - /* Unknown type and ptr type is not sent on wire */ - break; - } - if (ret) { - gf_msg_debug ("dict", ENOMEM, - "failed to set the key (%s) into dict", - key); - } - free (xpair->key.key_val); - } - - free (dict->pairs.pairs_val); - ret = 0; - - /* If everything is fine, assign the dictionary to target */ - *to = this; - this = NULL; -out: - if (this) - dict_unref (this); - - return ret; -} diff --git a/rpc/xdr/src/glusterfs3.h b/rpc/xdr/src/glusterfs3.h index eef39416b5c..bbe231139b3 100644 --- a/rpc/xdr/src/glusterfs3.h +++ b/rpc/xdr/src/glusterfs3.h @@ -314,7 +314,6 @@ gf_stat_to_iatt (struct gf_iatt *gf_stat, struct iatt *iatt) iatt->ia_ctime_nsec = gf_stat->ia_ctime_nsec ; } - static inline void gf_stat_from_iatt (struct gf_iatt *gf_stat, struct iatt *iatt) { @@ -324,7 +323,7 @@ gf_stat_from_iatt (struct gf_iatt *gf_stat, struct iatt *iatt) memcpy (gf_stat->ia_gfid, iatt->ia_gfid, 16); gf_stat->ia_ino = iatt->ia_ino ; gf_stat->ia_dev = iatt->ia_dev ; - gf_stat->mode = st_mode_from_ia (iatt->ia_prot, iatt->ia_type); + gf_stat->mode = st_mode_from_ia (iatt->ia_prot, iatt->ia_type); gf_stat->ia_nlink = iatt->ia_nlink ; gf_stat->ia_uid = iatt->ia_uid ; gf_stat->ia_gid = iatt->ia_gid ; @@ -575,7 +574,303 @@ out: return ret; } -extern int dict_to_xdr (dict_t *this, gfx_dict *xdict); -extern int xdr_to_dict (gfx_dict *xdict, dict_t **to); +static inline void +gfx_stat_to_iattx (struct gfx_iattx *gf_stat, struct iatt *iatt) +{ + if (!iatt || !gf_stat) + return; + + memcpy (iatt->ia_gfid, gf_stat->ia_gfid, 16); + + iatt->ia_flags = gf_stat->ia_flags; + iatt->ia_ino = gf_stat->ia_ino ; + iatt->ia_dev = gf_stat->ia_dev ; + iatt->ia_rdev = gf_stat->ia_rdev ; + iatt->ia_size = gf_stat->ia_size ; + iatt->ia_nlink = gf_stat->ia_nlink ; + iatt->ia_uid = gf_stat->ia_uid ; + iatt->ia_gid = gf_stat->ia_gid ; + iatt->ia_blksize = gf_stat->ia_blksize ; + iatt->ia_blocks = gf_stat->ia_blocks ; + iatt->ia_atime = gf_stat->ia_atime ; + iatt->ia_atime_nsec = gf_stat->ia_atime_nsec ; + iatt->ia_mtime = gf_stat->ia_mtime ; + iatt->ia_mtime_nsec = gf_stat->ia_mtime_nsec ; + iatt->ia_ctime = gf_stat->ia_ctime ; + iatt->ia_ctime_nsec = gf_stat->ia_ctime_nsec ; + iatt->ia_btime = gf_stat->ia_btime ; + iatt->ia_btime_nsec = gf_stat->ia_btime_nsec ; + iatt->ia_attributes = gf_stat->ia_attributes; + iatt->ia_attributes_mask = gf_stat->ia_attributes_mask; + + iatt->ia_type = ia_type_from_st_mode (gf_stat->mode); + iatt->ia_prot = ia_prot_from_st_mode (gf_stat->mode); +} + + +static inline void +gfx_stat_from_iattx (struct gfx_iattx *gf_stat, struct iatt *iatt) +{ + if (!iatt || !gf_stat) + return; + + memcpy (gf_stat->ia_gfid, iatt->ia_gfid, 16); + gf_stat->ia_ino = iatt->ia_ino ; + gf_stat->ia_dev = iatt->ia_dev ; + + gf_stat->ia_nlink = iatt->ia_nlink ; + gf_stat->ia_uid = iatt->ia_uid ; + gf_stat->ia_gid = iatt->ia_gid ; + gf_stat->ia_rdev = iatt->ia_rdev ; + gf_stat->ia_size = iatt->ia_size ; + gf_stat->ia_blksize = iatt->ia_blksize ; + gf_stat->ia_blocks = iatt->ia_blocks ; + gf_stat->ia_atime = iatt->ia_atime ; + gf_stat->ia_atime_nsec = iatt->ia_atime_nsec ; + gf_stat->ia_mtime = iatt->ia_mtime ; + gf_stat->ia_mtime_nsec = iatt->ia_mtime_nsec ; + gf_stat->ia_ctime = iatt->ia_ctime ; + gf_stat->ia_ctime_nsec = iatt->ia_ctime_nsec ; + + gf_stat->ia_flags = iatt->ia_flags; + gf_stat->ia_btime = iatt->ia_btime ; + gf_stat->ia_btime_nsec = iatt->ia_btime_nsec ; + gf_stat->ia_attributes = iatt->ia_attributes; + gf_stat->ia_attributes_mask = iatt->ia_attributes_mask; + + gf_stat->mode = st_mode_from_ia (iatt->ia_prot, iatt->ia_type); +} + +/* dict_to_xdr () */ +static inline int +dict_to_xdr (dict_t *this, gfx_dict *dict) +{ + int ret = -1; + int i = 0; + int index = 0; + data_pair_t *dpair = NULL; + gfx_dict_pair *xpair = NULL; + ssize_t size = 0; + + /* This is a failure as we expect destination to be valid */ + if (!dict) + goto out; + + /* This is OK as dictionary can be null, in which case, destination + should also know that it is NULL. */ + if (!this) { + /* encode special meaning data here, + while decoding, you know it is NULL dict */ + dict->count = -1; + /* everything else is normal */ + dict->pairs.pairs_len = 0; + ret = 0; + goto out; + } + + dict->pairs.pairs_val = GF_CALLOC (1, (this->count * + sizeof (gfx_dict_pair)), + gf_common_mt_char); + if (!dict->pairs.pairs_val) + goto out; + + dpair = this->members_list; + for (i = 0; i < this->count; i++) { + xpair = &dict->pairs.pairs_val[index]; + + xpair->key.key_val = dpair->key; + xpair->key.key_len = strlen (dpair->key) + 1; + xpair->value.type = dpair->value->data_type; + switch (dpair->value->data_type) { + /* Add more type here */ + case GF_DATA_TYPE_INT: + index++; + xpair->value.gfx_value_u.value_int = + strtoll (dpair->value->data, NULL, 0); + break; + case GF_DATA_TYPE_UINT: + index++; + xpair->value.gfx_value_u.value_uint = + strtoull (dpair->value->data, NULL, 0); + break; + case GF_DATA_TYPE_DOUBLE: + index++; + xpair->value.gfx_value_u.value_dbl = + strtod (dpair->value->data, NULL); + break; + case GF_DATA_TYPE_STR: + index++; + xpair->value.gfx_value_u.val_string.val_string_val = dpair->value->data; + xpair->value.gfx_value_u.val_string.val_string_len = dpair->value->len; + break; + case GF_DATA_TYPE_IATT: + index++; + gfx_stat_from_iattx (&xpair->value.gfx_value_u.iatt, + (struct iatt *)dpair->value->data); + break; + case GF_DATA_TYPE_GFUUID: + index++; + memcpy (&xpair->value.gfx_value_u.uuid, + dpair->value->data, sizeof (uuid_t)); + break; + + case GF_DATA_TYPE_PTR: + index++; + /* Ideally, each type of data stored in dictionary + should have type. A pointer type shouldn't be + sent on wire */ + + /* This is done for backward compatibility as dict is + heavily used for transporting data over wire. + Ideally, whereever there is an issue, fix and move on */ + xpair->value.gfx_value_u.other.other_val = + dpair->value->data; + xpair->value.gfx_value_u.other.other_len = + dpair->value->len; + + /* Change this to INFO, after taking the above down */ + gf_msg ("dict", GF_LOG_INFO, EINVAL, + LG_MSG_DICT_SERIAL_FAILED, + "key '%s' is would not be sent on wire in future", + dpair->key); + break; + default: + /* Unknown type and ptr type is not sent on wire */ + gf_msg ("dict", GF_LOG_WARNING, EINVAL, LG_MSG_DICT_SERIAL_FAILED, + "key '%s' is not sent on wire", dpair->key); + break; + } + dpair = dpair->next; + } + + dict->pairs.pairs_len = index; + dict->count = index; + + /* This is required mainly in the RPC layer to understand the + boundary for proper payload. Hence only send the size of + variable XDR size. ie, the formula should be: + xdr_size = total size - (xdr_size + count + pairs.pairs_len)) */ + size = xdr_sizeof ((xdrproc_t) xdr_gfx_dict, dict); + + dict->xdr_size = (size > 12) ? (size - 12) : 0; + + ret = 0; +out: + return ret; +} + +static inline int +xdr_to_dict (gfx_dict *dict, dict_t **to) +{ + int ret = -1; + int index = 0; + char *key = NULL; + char *value = NULL; + gfx_dict_pair *xpair = NULL; + dict_t *this = NULL; + unsigned char *uuid = NULL; + struct iatt *iatt = NULL; + + if (!to || !dict) + goto out; + + if (dict->count < 0) { + /* indicates NULL dict was passed for encoding */ + ret = 0; + goto out; + } + + this = dict_new(); + if (!this) + goto out; + + for (index = 0; index < dict->pairs.pairs_len; index++) { + ret = -1; + xpair = &dict->pairs.pairs_val[index]; + + key = xpair->key.key_val; + switch (xpair->value.type) { + /* Add more type here */ + case GF_DATA_TYPE_INT: + ret = dict_set_int64 (this, key, + xpair->value.gfx_value_u.value_int); + break; + case GF_DATA_TYPE_UINT: + ret = dict_set_uint64 (this, key, + xpair->value.gfx_value_u.value_uint); + break; + case GF_DATA_TYPE_DOUBLE: + ret = dict_set_double (this, key, + xpair->value.gfx_value_u.value_dbl); + break; + case GF_DATA_TYPE_STR: + value = GF_CALLOC (1, xpair->value.gfx_value_u.val_string.val_string_len + 1, + gf_common_mt_char); + if (!value) { + errno = ENOMEM; + goto out; + } + memcpy (value, xpair->value.gfx_value_u.val_string.val_string_val, + xpair->value.gfx_value_u.val_string.val_string_len); + free (xpair->value.gfx_value_u.val_string.val_string_val); + ret = dict_set_dynstr (this, key, value); + break; + case GF_DATA_TYPE_GFUUID: + uuid = GF_CALLOC (1, sizeof (uuid_t), gf_common_mt_uuid_t); + if (!uuid) { + errno = ENOMEM; + goto out; + } + memcpy (uuid, xpair->value.gfx_value_u.uuid, sizeof (uuid_t)); + ret = dict_set_gfuuid (this, key, uuid, false); + break; + case GF_DATA_TYPE_IATT: + iatt = GF_CALLOC (1, sizeof (struct iatt), gf_common_mt_char); + if (!iatt) { + errno = ENOMEM; + goto out; + } + gfx_stat_to_iattx (&xpair->value.gfx_value_u.iatt, iatt); + ret = dict_set_iatt (this, key, iatt, false); + break; + case GF_DATA_TYPE_PTR: + value = GF_CALLOC (1, xpair->value.gfx_value_u.other.other_len + 1, + gf_common_mt_char); + if (!value) { + errno = ENOMEM; + goto out; + } + memcpy (value, xpair->value.gfx_value_u.other.other_val, + xpair->value.gfx_value_u.other.other_len); + free (xpair->value.gfx_value_u.other.other_val); + ret = dict_set_dynptr (this, key, value, + xpair->value.gfx_value_u.other.other_len); + break; + default: + ret = 0; + /* Unknown type and ptr type is not sent on wire */ + break; + } + if (ret) { + gf_msg_debug (THIS->name, ENOMEM, + "failed to set the key (%s) into dict", + key); + } + free (xpair->key.key_val); + } + + free (dict->pairs.pairs_val); + ret = 0; + + /* If everything is fine, assign the dictionary to target */ + *to = this; + this = NULL; + +out: + if (this) + dict_unref (this); + + return ret; +} #endif /* !_GLUSTERFS3_H */ diff --git a/rpc/xdr/src/glusterfs4-xdr.x b/rpc/xdr/src/glusterfs4-xdr.x index 9e3223b58b5..bf92c8db9de 100644 --- a/rpc/xdr/src/glusterfs4-xdr.x +++ b/rpc/xdr/src/glusterfs4-xdr.x @@ -16,6 +16,36 @@ %#include "glusterfs3-xdr.h" +/* Need to consume iattx and new dict in all the fops */ +struct gfx_iattx { + opaque ia_gfid[16]; + + unsigned hyper ia_flags; + unsigned hyper ia_ino; /* inode number */ + unsigned hyper ia_dev; /* backing device ID */ + unsigned hyper ia_rdev; /* device ID (if special file) */ + unsigned hyper ia_size; /* file size in bytes */ + unsigned hyper ia_blocks; /* number of 512B blocks allocated */ + unsigned hyper ia_attributes; /* chattr related:compressed, immutable, + * append only, encrypted etc.*/ + unsigned hyper ia_attributes_mask; /* Mask for the attributes */ + + hyper ia_atime; /* last access time */ + hyper ia_mtime; /* last modification time */ + hyper ia_ctime; /* last status change time */ + hyper ia_btime; /* creation time. Fill using statx */ + + unsigned int ia_atime_nsec; + unsigned int ia_mtime_nsec; + unsigned int ia_ctime_nsec; + unsigned int ia_btime_nsec; + unsigned int ia_nlink; /* Link count */ + unsigned int ia_uid; /* user ID of owner */ + unsigned int ia_gid; /* group ID of owner */ + unsigned int ia_blksize; /* blocksize for filesystem I/O */ + unsigned int mode; /* type of file and rwx mode */ +}; + union gfx_value switch (gf_dict_data_type_t type) { case GF_DATA_TYPE_INT: hyper value_int; @@ -26,9 +56,9 @@ union gfx_value switch (gf_dict_data_type_t type) { case GF_DATA_TYPE_STR: opaque val_string<>; case GF_DATA_TYPE_IATT: - gf_iatt iatt; + gfx_iattx iatt; case GF_DATA_TYPE_GFUUID: - opaque uuid[20]; + opaque uuid[16]; case GF_DATA_TYPE_PTR: opaque other<>; }; @@ -64,52 +94,773 @@ struct gfx_dict_pair { }; struct gfx_dict { - unsigned int count; + unsigned int xdr_size; + int count; gfx_dict_pair pairs<>; }; -/* fops */ - struct gfs3_fsetattr_req_v2 { +/* FOPS */ +struct gfx_common_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_common_iatt_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + gfx_iattx stat; +}; + +struct gfx_common_2iatt_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + gfx_iattx prestat; + gfx_iattx poststat; +}; + +struct gfx_common_3iatt_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_iattx stat; + gfx_iattx preparent; + gfx_iattx postparent; +}; + +struct gfx_fsetattr_req { opaque gfid[16]; hyper fd; - struct gf_iatt stbuf; + gfx_iattx stbuf; int valid; - opaque xdata<>; /* Extra data */ -} ; + gfx_dict xdata; /* Extra data */ +}; - struct gfs3_rchecksum_req_v2 { +struct gfx_rchecksum_req { opaque gfid[16]; hyper fd; unsigned hyper offset; unsigned int len; - opaque xdata<>; /* Extra data */ + unsigned int flags; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_icreate_req { + opaque gfid[16]; + unsigned int mode; + gfx_dict xdata; +}; + +struct gfx_namelink_req { + opaque pargfid[16]; + string bname<>; + gfx_dict xdata; +}; + +/* Define every fops */ +/* Changes from Version 3: + 1. Dict has its own type instead of being opaque + 2. Iattx instead of iatt on wire + 3. gfid has 4 extra bytes so it can be used for future +*/ +struct gfx_stat_req { + opaque gfid[16]; + gfx_dict xdata; +}; + +struct gfx_readlink_req { + opaque gfid[16]; + unsigned int size; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_readlink_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_iattx buf; + string path<>; /* NULL terminated */ +}; + +struct gfx_mknod_req { + opaque pargfid[16]; + u_quad_t dev; + unsigned int mode; + unsigned int umask; + string bname<>; /* NULL terminated */ + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_mkdir_req { + opaque pargfid[16]; + unsigned int mode; + unsigned int umask; + string bname<>; /* NULL terminated */ + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_unlink_req { + opaque pargfid[16]; + string bname<>; /* NULL terminated */ + unsigned int xflags; + gfx_dict xdata; /* Extra data */ +}; + + +struct gfx_rmdir_req { + opaque pargfid[16]; + int xflags; + string bname<>; /* NULL terminated */ + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_symlink_req { + opaque pargfid[16]; + string bname<>; + unsigned int umask; + string linkname<>; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_rename_req { + opaque oldgfid[16]; + opaque newgfid[16]; + string oldbname<>; /* NULL terminated */ + string newbname<>; /* NULL terminated */ + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_rename_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_iattx stat; + gfx_iattx preoldparent; + gfx_iattx postoldparent; + gfx_iattx prenewparent; + gfx_iattx postnewparent; +}; + + + struct gfx_link_req { + opaque oldgfid[16]; + opaque newgfid[16]; + string newbname<>; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_truncate_req { + opaque gfid[16]; + u_quad_t offset; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_open_req { + opaque gfid[16]; + unsigned int flags; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_open_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + quad_t fd; +}; + +struct gfx_opendir_req { + opaque gfid[16]; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_read_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + unsigned int size; + unsigned int flag; + gfx_dict xdata; /* Extra data */ +}; + struct gfx_read_rsp { + int op_ret; + int op_errno; + gfx_iattx stat; + unsigned int size; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_lookup_req { + opaque gfid[16]; + opaque pargfid[16]; + unsigned int flags; + string bname<>; + gfx_dict xdata; /* Extra data */ +}; + + + struct gfx_write_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + unsigned int size; + unsigned int flag; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_statfs_req { + opaque gfid[16]; + gfx_dict xdata; /* Extra data */ +} ; + struct gfx_statfs_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gf_statfs statfs; +} ; + + struct gfx_lk_req { + opaque gfid[16]; + int64_t fd; + unsigned int cmd; + unsigned int type; + gf_proto_flock flock; + gfx_dict xdata; /* Extra data */ +} ; + struct gfx_lk_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gf_proto_flock flock; +} ; + +struct gfx_lease_req { + opaque gfid[16]; + gf_proto_lease lease; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_lease_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gf_proto_lease lease; +} ; + +struct gfx_recall_lease_req { + opaque gfid[16]; + unsigned int lease_type; + opaque tid[16]; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_inodelk_req { + opaque gfid[16]; + unsigned int cmd; + unsigned int type; + gf_proto_flock flock; + string volume<>; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_finodelk_req { + opaque gfid[16]; + quad_t fd; + unsigned int cmd; + unsigned int type; + gf_proto_flock flock; + string volume<>; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_flush_req { + opaque gfid[16]; + quad_t fd; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_fsync_req { + opaque gfid[16]; + quad_t fd; + unsigned int data; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_setxattr_req { + opaque gfid[16]; + unsigned int flags; + gfx_dict dict; + gfx_dict xdata; /* Extra data */ +} ; + + + + struct gfx_fsetxattr_req { + opaque gfid[16]; + int64_t fd; + unsigned int flags; + gfx_dict dict; + gfx_dict xdata; /* Extra data */ +} ; + + + + struct gfx_xattrop_req { + opaque gfid[16]; + unsigned int flags; + gfx_dict dict; + gfx_dict xdata; /* Extra data */ } ; -struct gfs4_icreate_rsp { +struct gfx_common_dict_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_dict dict; + gfx_iattx prestat; + gfx_iattx poststat; +}; + + + struct gfx_fxattrop_req { + opaque gfid[16]; + quad_t fd; + unsigned int flags; + gfx_dict dict; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_getxattr_req { + opaque gfid[16]; + unsigned int namelen; + string name<>; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_fgetxattr_req { + opaque gfid[16]; + quad_t fd; + unsigned int namelen; + string name<>; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_removexattr_req { + opaque gfid[16]; + string name<>; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_fremovexattr_req { + opaque gfid[16]; + quad_t fd; + string name<>; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_fsyncdir_req { + opaque gfid[16]; + quad_t fd; + int data; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_readdir_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + unsigned int size; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_readdirp_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + unsigned int size; + gfx_dict xdata; +} ; + + +struct gfx_access_req { + opaque gfid[16]; + unsigned int mask; + gfx_dict xdata; /* Extra data */ +} ; + + +struct gfx_create_req { + opaque pargfid[16]; + unsigned int flags; + unsigned int mode; + unsigned int umask; + string bname<>; + gfx_dict xdata; /* Extra data */ +} ; +struct gfx_create_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + gfx_iattx stat; + u_quad_t fd; + gfx_iattx preparent; + gfx_iattx postparent; +} ; + +struct gfx_ftruncate_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + gfx_dict xdata; /* Extra data */ +} ; + + +struct gfx_fstat_req { + opaque gfid[16]; + quad_t fd; + gfx_dict xdata; /* Extra data */ +} ; + + +struct gfx_entrylk_req { + opaque gfid[16]; + unsigned int cmd; + unsigned int type; + u_quad_t namelen; + string name<>; + string volume<>; + gfx_dict xdata; /* Extra data */ +}; + +struct gfx_fentrylk_req { + opaque gfid[16]; + quad_t fd; + unsigned int cmd; + unsigned int type; + u_quad_t namelen; + string name<>; + string volume<>; + gfx_dict xdata; /* Extra data */ +}; + + struct gfx_setattr_req { + opaque gfid[16]; + gfx_iattx stbuf; + int valid; + gfx_dict xdata; /* Extra data */ +} ; + + struct gfx_fallocate_req { + opaque gfid[16]; + quad_t fd; + unsigned int flags; + u_quad_t offset; + u_quad_t size; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_discard_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + u_quad_t size; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_zerofill_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + u_quad_t size; + gfx_dict xdata; +} ; + +struct gfx_rchecksum_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; /* Extra data */ + unsigned int flags; + unsigned int weak_checksum; + opaque strong_checksum<>; +} ; + + +struct gfx_ipc_req { + int op; + gfx_dict xdata; +}; + + +struct gfx_seek_req { + opaque gfid[16]; + quad_t fd; + u_quad_t offset; + int what; + gfx_dict xdata; +}; + +struct gfx_seek_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + u_quad_t offset; +}; + + + struct gfx_setvolume_req { + gfx_dict dict; +} ; + struct gfx_setvolume_rsp { + int op_ret; + int op_errno; + gfx_dict dict; +} ; + + + struct gfx_getspec_req { + unsigned int flags; + string key<>; + gfx_dict xdata; /* Extra data */ +} ; + struct gfx_getspec_rsp { + int op_ret; + int op_errno; + string spec<>; + gfx_dict xdata; /* Extra data */ +} ; + + + struct gfx_notify_req { + unsigned int flags; + string buf<>; + gfx_dict xdata; /* Extra data */ +} ; + struct gfx_notify_rsp { + int op_ret; + int op_errno; + unsigned int flags; + string buf<>; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_releasedir_req { + opaque gfid[16]; + quad_t fd; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_release_req { + opaque gfid[16]; + quad_t fd; + gfx_dict xdata; /* Extra data */ +} ; + +struct gfx_dirlist { + u_quad_t d_ino; + u_quad_t d_off; + unsigned int d_len; + unsigned int d_type; + string name<>; + gfx_dirlist *nextentry; +}; + + +struct gfx_readdir_rsp { int op_ret; int op_errno; - gf_iatt stat; - opaque xdata<>; + gfx_dict xdata; /* Extra data */ + gfx_dirlist *reply; }; -struct gfs4_icreate_req { - opaque gfid[16]; - unsigned int mode; - opaque xdata<>; +struct gfx_dirplist { + u_quad_t d_ino; + u_quad_t d_off; + unsigned int d_len; + unsigned int d_type; + string name<>; + gfx_iattx stat; + gfx_dict dict; + gfx_dirplist *nextentry; }; -struct gfs4_namelink_rsp { +struct gfx_readdirp_rsp { int op_ret; int op_errno; - gf_iatt preparent; - gf_iatt postparent; - opaque xdata<>; + gfx_dict xdata; /* Extra data */ + gfx_dirplist *reply; }; -struct gfs4_namelink_req { - opaque pargfid[16]; - string bname<>; - opaque xdata<>; +struct gfx_set_lk_ver_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + int lk_ver; +}; + +struct gfx_set_lk_ver_req { + string uid<>; + int lk_ver; +}; + +struct gfx_event_notify_req { + int op; + gfx_dict dict; +}; + + +struct gfx_getsnap_name_uuid_req { + gfx_dict dict; +}; + +struct gfx_getsnap_name_uuid_rsp { + int op_ret; + int op_errno; + gfx_dict dict; + string op_errstr<>; +}; + +struct gfx_getactivelk_rsp { + int op_ret; + int op_errno; + gfx_dict xdata; + gfs3_locklist *reply; +}; + +struct gfx_getactivelk_req { + opaque gfid[16]; + gfx_dict xdata; +}; + +struct gfx_setactivelk_req { + opaque gfid[16]; + gfs3_locklist *request; + gfx_dict xdata; +}; + +union compound_req_v2 switch (glusterfs_fop_t fop_enum) { + case GF_FOP_STAT: gfx_stat_req compound_stat_req; + case GF_FOP_READLINK: gfx_readlink_req compound_readlink_req; + case GF_FOP_MKNOD: gfx_mknod_req compound_mknod_req; + case GF_FOP_MKDIR: gfx_mkdir_req compound_mkdir_req; + case GF_FOP_UNLINK: gfx_unlink_req compound_unlink_req; + case GF_FOP_RMDIR: gfx_rmdir_req compound_rmdir_req; + case GF_FOP_SYMLINK: gfx_symlink_req compound_symlink_req; + case GF_FOP_RENAME: gfx_rename_req compound_rename_req; + case GF_FOP_LINK: gfx_link_req compound_link_req; + case GF_FOP_TRUNCATE: gfx_truncate_req compound_truncate_req; + case GF_FOP_OPEN: gfx_open_req compound_open_req; + case GF_FOP_READ: gfx_read_req compound_read_req; + case GF_FOP_WRITE: gfx_write_req compound_write_req; + case GF_FOP_STATFS: gfx_statfs_req compound_statfs_req; + case GF_FOP_FLUSH: gfx_flush_req compound_flush_req; + case GF_FOP_FSYNC: gfx_fsync_req compound_fsync_req; + case GF_FOP_GETXATTR: gfx_getxattr_req compound_getxattr_req; + case GF_FOP_SETXATTR: gfx_setxattr_req compound_setxattr_req; + case GF_FOP_REMOVEXATTR: gfx_removexattr_req compound_removexattr_req; + case GF_FOP_OPENDIR: gfx_opendir_req compound_opendir_req; + case GF_FOP_FSYNCDIR: gfx_fsyncdir_req compound_fsyncdir_req; + case GF_FOP_ACCESS: gfx_access_req compound_access_req; + case GF_FOP_CREATE: gfx_create_req compound_create_req; + case GF_FOP_FTRUNCATE: gfx_ftruncate_req compound_ftruncate_req; + case GF_FOP_FSTAT: gfx_fstat_req compound_fstat_req; + case GF_FOP_LK: gfx_lk_req compound_lk_req; + case GF_FOP_LOOKUP: gfx_lookup_req compound_lookup_req; + case GF_FOP_READDIR: gfx_readdir_req compound_readdir_req; + case GF_FOP_INODELK: gfx_inodelk_req compound_inodelk_req; + case GF_FOP_FINODELK: gfx_finodelk_req compound_finodelk_req; + case GF_FOP_ENTRYLK: gfx_entrylk_req compound_entrylk_req; + case GF_FOP_FENTRYLK: gfx_fentrylk_req compound_fentrylk_req; + case GF_FOP_XATTROP: gfx_xattrop_req compound_xattrop_req; + case GF_FOP_FXATTROP: gfx_fxattrop_req compound_fxattrop_req; + case GF_FOP_FGETXATTR: gfx_fgetxattr_req compound_fgetxattr_req; + case GF_FOP_FSETXATTR: gfx_fsetxattr_req compound_fsetxattr_req; + case GF_FOP_RCHECKSUM: gfx_rchecksum_req compound_rchecksum_req; + case GF_FOP_SETATTR: gfx_setattr_req compound_setattr_req; + case GF_FOP_FSETATTR: gfx_fsetattr_req compound_fsetattr_req; + case GF_FOP_READDIRP: gfx_readdirp_req compound_readdirp_req; + case GF_FOP_RELEASE: gfx_release_req compound_release_req; + case GF_FOP_RELEASEDIR: gfx_releasedir_req compound_releasedir_req; + case GF_FOP_FREMOVEXATTR: gfx_fremovexattr_req compound_fremovexattr_req; + case GF_FOP_FALLOCATE: gfx_fallocate_req compound_fallocate_req; + case GF_FOP_DISCARD: gfx_discard_req compound_discard_req; + case GF_FOP_ZEROFILL: gfx_zerofill_req compound_zerofill_req; + case GF_FOP_IPC: gfx_ipc_req compound_ipc_req; + case GF_FOP_SEEK: gfx_seek_req compound_seek_req; + case GF_FOP_LEASE: gfx_lease_req compound_lease_req; + default: void; +}; + +struct gfx_compound_req { + int compound_version; + glusterfs_compound_fop_t compound_fop_enum; + compound_req_v2 compound_req_array<>; + gfx_dict xdata; +}; + +union compound_rsp_v2 switch (glusterfs_fop_t fop_enum) { + case GF_FOP_STAT: gfx_common_iatt_rsp compound_stat_rsp; + case GF_FOP_READLINK: gfx_readlink_rsp compound_readlink_rsp; + case GF_FOP_MKNOD: gfx_common_3iatt_rsp compound_mknod_rsp; + case GF_FOP_MKDIR: gfx_common_3iatt_rsp compound_mkdir_rsp; + case GF_FOP_UNLINK: gfx_common_2iatt_rsp compound_unlink_rsp; + case GF_FOP_RMDIR: gfx_common_2iatt_rsp compound_rmdir_rsp; + case GF_FOP_SYMLINK: gfx_common_3iatt_rsp compound_symlink_rsp; + case GF_FOP_RENAME: gfx_rename_rsp compound_rename_rsp; + case GF_FOP_LINK: gfx_common_3iatt_rsp compound_link_rsp; + case GF_FOP_TRUNCATE: gfx_common_2iatt_rsp compound_truncate_rsp; + case GF_FOP_OPEN: gfx_open_rsp compound_open_rsp; + case GF_FOP_READ: gfx_read_rsp compound_read_rsp; + case GF_FOP_WRITE: gfx_common_2iatt_rsp compound_write_rsp; + case GF_FOP_STATFS: gfx_statfs_rsp compound_statfs_rsp; + case GF_FOP_FLUSH: gfx_common_rsp compound_flush_rsp; + case GF_FOP_FSYNC: gfx_common_2iatt_rsp compound_fsync_rsp; + case GF_FOP_GETXATTR: gfx_common_dict_rsp compound_getxattr_rsp; + case GF_FOP_SETXATTR: gfx_common_rsp compound_setxattr_rsp; + case GF_FOP_REMOVEXATTR: gfx_common_rsp compound_removexattr_rsp; + case GF_FOP_OPENDIR: gfx_open_rsp compound_opendir_rsp; + case GF_FOP_FSYNCDIR: gfx_common_rsp compound_fsyncdir_rsp; + case GF_FOP_ACCESS: gfx_common_rsp compound_access_rsp; + case GF_FOP_CREATE: gfx_create_rsp compound_create_rsp; + case GF_FOP_FTRUNCATE: gfx_common_2iatt_rsp compound_ftruncate_rsp; + case GF_FOP_FSTAT: gfx_common_iatt_rsp compound_fstat_rsp; + case GF_FOP_LK: gfx_lk_rsp compound_lk_rsp; + case GF_FOP_LOOKUP: gfx_common_2iatt_rsp compound_lookup_rsp; + case GF_FOP_READDIR: gfx_readdir_rsp compound_readdir_rsp; + case GF_FOP_INODELK: gfx_common_rsp compound_inodelk_rsp; + case GF_FOP_FINODELK: gfx_common_rsp compound_finodelk_rsp; + case GF_FOP_ENTRYLK: gfx_common_rsp compound_entrylk_rsp; + case GF_FOP_FENTRYLK: gfx_common_rsp compound_fentrylk_rsp; + case GF_FOP_XATTROP: gfx_common_dict_rsp compound_xattrop_rsp; + case GF_FOP_FXATTROP: gfx_common_dict_rsp compound_fxattrop_rsp; + case GF_FOP_FGETXATTR: gfx_common_dict_rsp compound_fgetxattr_rsp; + case GF_FOP_FSETXATTR: gfx_common_rsp compound_fsetxattr_rsp; + case GF_FOP_RCHECKSUM: gfx_rchecksum_rsp compound_rchecksum_rsp; + case GF_FOP_SETATTR: gfx_common_2iatt_rsp compound_setattr_rsp; + case GF_FOP_FSETATTR: gfx_common_2iatt_rsp compound_fsetattr_rsp; + case GF_FOP_READDIRP: gfx_readdirp_rsp compound_readdirp_rsp; + case GF_FOP_RELEASE: gfx_common_rsp compound_release_rsp; + case GF_FOP_RELEASEDIR: gfx_common_rsp compound_releasedir_rsp; + case GF_FOP_FREMOVEXATTR: gfx_common_rsp compound_fremovexattr_rsp; + case GF_FOP_FALLOCATE: gfx_common_2iatt_rsp compound_fallocate_rsp; + case GF_FOP_DISCARD: gfx_common_2iatt_rsp compound_discard_rsp; + case GF_FOP_ZEROFILL: gfx_common_2iatt_rsp compound_zerofill_rsp; + case GF_FOP_IPC: gfx_common_rsp compound_ipc_rsp; + case GF_FOP_SEEK: gfx_seek_rsp compound_seek_rsp; + case GF_FOP_LEASE: gfx_lease_rsp compound_lease_rsp; + default: void; +}; + +struct gfx_compound_rsp { + int op_ret; + int op_errno; + compound_rsp_v2 compound_rsp_array<>; + gfx_dict xdata; }; struct gfs4_inodelk_contention_req { diff --git a/rpc/xdr/src/libgfxdr.sym b/rpc/xdr/src/libgfxdr.sym index f6aa300544a..89fc513eda7 100644 --- a/rpc/xdr/src/libgfxdr.sym +++ b/rpc/xdr/src/libgfxdr.sym @@ -249,3 +249,97 @@ xdr_to_setattr3args xdr_to_symlink3args xdr_to_write3args xdr_vector_round_up +xdr_gfx_read_rsp +xdr_gfx_iattx +xdr_gfx_value +xdr_gfx_dict_pair +xdr_gfx_dict +xdr_gfx_common_rsp +xdr_gfx_common_iatt_rsp +xdr_gfx_common_2iatt_rsp +xdr_gfx_common_3iatt_rsp +xdr_gfx_fsetattr_req +xdr_gfx_rchecksum_req +xdr_gfx_icreate_req +xdr_gfx_namelink_req +xdr_gfx_stat_req +xdr_gfx_readlink_req +xdr_gfx_readlink_rsp +xdr_gfx_mknod_req +xdr_gfx_mkdir_req +xdr_gfx_unlink_req +xdr_gfx_rmdir_req +xdr_gfx_symlink_req +xdr_gfx_rename_req +xdr_gfx_rename_rsp +xdr_gfx_link_req +xdr_gfx_truncate_req +xdr_gfx_open_req +xdr_gfx_open_rsp +xdr_gfx_opendir_req +xdr_gfx_read_req +xdr_gfx_read_rsp +xdr_gfx_lookup_req +xdr_gfx_write_req +xdr_gfx_statfs_req +xdr_gfx_statfs_rsp +xdr_gfx_lk_req +xdr_gfx_lk_rsp +xdr_gfx_lease_req +xdr_gfx_lease_rsp +xdr_gfx_recall_lease_req +xdr_gfx_inodelk_req +xdr_gfx_finodelk_req +xdr_gfx_flush_req +xdr_gfx_fsync_req +xdr_gfx_setxattr_req +xdr_gfx_fsetxattr_req +xdr_gfx_xattrop_req +xdr_gfx_common_dict_rsp +xdr_gfx_fxattrop_req +xdr_gfx_getxattr_req +xdr_gfx_fgetxattr_req +xdr_gfx_removexattr_req +xdr_gfx_fremovexattr_req +xdr_gfx_fsyncdir_req +xdr_gfx_readdir_req +xdr_gfx_readdirp_req +xdr_gfx_access_req +xdr_gfx_create_req +xdr_gfx_create_rsp +xdr_gfx_ftruncate_req +xdr_gfx_fstat_req +xdr_gfx_entrylk_req +xdr_gfx_fentrylk_req +xdr_gfx_setattr_req +xdr_gfx_fallocate_req +xdr_gfx_discard_req +xdr_gfx_zerofill_req +xdr_gfx_rchecksum_rsp +xdr_gfx_ipc_req +xdr_gfx_seek_req +xdr_gfx_seek_rsp +xdr_gfx_setvolume_req +xdr_gfx_setvolume_rsp +xdr_gfx_getspec_req +xdr_gfx_getspec_rsp +xdr_gfx_notify_req +xdr_gfx_notify_rsp +xdr_gfx_releasedir_req +xdr_gfx_release_req +xdr_gfx_dirlist +xdr_gfx_readdir_rsp +xdr_gfx_dirplist +xdr_gfx_readdirp_rsp +xdr_gfx_set_lk_ver_rsp +xdr_gfx_set_lk_ver_req +xdr_gfx_event_notify_req +xdr_gfx_getsnap_name_uuid_req +xdr_gfx_getsnap_name_uuid_rsp +xdr_gfx_getactivelk_rsp +xdr_gfx_getactivelk_req +xdr_gfx_setactivelk_req +xdr_compound_req_v2 +xdr_gfx_compound_req +xdr_compound_rsp_v2 +xdr_gfx_compound_rsp diff --git a/xlators/protocol/client/src/Makefile.am b/xlators/protocol/client/src/Makefile.am index 899db91e683..785a51fc3b4 100644 --- a/xlators/protocol/client/src/Makefile.am +++ b/xlators/protocol/client/src/Makefile.am @@ -9,7 +9,8 @@ client_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(top_builddir)/rpc/xdr/src/libgfxdr.la client_la_SOURCES = client.c client-helpers.c client-rpc-fops.c \ - client-handshake.c client-callback.c client-lk.c client-common.c + client-handshake.c client-callback.c client-lk.c client-common.c \ + client-rpc-fops_v2.c noinst_HEADERS = client.h client-mem-types.h client-messages.h client-common.h diff --git a/xlators/protocol/client/src/client-common.c b/xlators/protocol/client/src/client-common.c index 873b0f0f4ae..3b4dea1aff1 100644 --- a/xlators/protocol/client/src/client-common.c +++ b/xlators/protocol/client/src/client-common.c @@ -12,6 +12,7 @@ #include "xlator.h" #include "rpc-common-xdr.h" #include "glusterfs3-xdr.h" +#include "glusterfs4-xdr.h" #include "glusterfs3.h" #include "client.h" @@ -2159,3 +2160,1443 @@ client_post_lease (xlator_t *this, gfs3_lease_rsp *rsp, struct gf_lease *lease, out: return ret; } + + +/* New PRE and POST functions */ + +int +client_post_common_iatt (xlator_t *this, gfx_common_iatt_rsp *rsp, struct iatt *iatt, + dict_t **xdata) +{ + if (-1 != rsp->op_ret) { + gfx_stat_to_iattx (&rsp->stat, iatt); + } + + return xdr_to_dict (&rsp->xdata, xdata); +} + +int +client_post_common_2iatt (xlator_t *this, gfx_common_2iatt_rsp *rsp, struct iatt *iatt, + struct iatt *iatt2, dict_t **xdata) +{ + if (-1 != rsp->op_ret) { + gfx_stat_to_iattx (&rsp->prestat, iatt); + gfx_stat_to_iattx (&rsp->poststat, iatt2); + } + + return xdr_to_dict (&rsp->xdata, xdata); +} + +int +client_post_common_3iatt (xlator_t *this, gfx_common_3iatt_rsp *rsp, struct iatt *iatt, + struct iatt *iatt2, struct iatt *iatt3, dict_t **xdata) +{ + if (-1 != rsp->op_ret) { + gfx_stat_to_iattx (&rsp->stat, iatt); + gfx_stat_to_iattx (&rsp->preparent, iatt2); + gfx_stat_to_iattx (&rsp->postparent, iatt3); + } + + return xdr_to_dict (&rsp->xdata, xdata); +} + +int +client_post_common_dict (xlator_t *this, gfx_common_dict_rsp *rsp, dict_t **dict, + dict_t **xdata) +{ + int ret = 0; + ret = xdr_to_dict (&rsp->dict, dict); + if (ret) + gf_msg_debug (this->name, EINVAL, + "while decoding found empty dictionary"); + xdr_to_dict (&rsp->xdata, xdata); + + return ret; +} + +int +client_post_readv_v2 (xlator_t *this, gfx_read_rsp *rsp, struct iobref **iobref, + struct iobref *rsp_iobref, struct iatt *stat, + struct iovec *vector, struct iovec *rsp_vector, + int *rspcount, dict_t **xdata) +{ + int ret = -1; + + if (rsp->op_ret != -1) { + *iobref = rsp_iobref; + gfx_stat_to_iattx (&rsp->stat, stat); + + vector[0].iov_len = rsp->op_ret; + if (rsp->op_ret > 0) + vector[0].iov_base = rsp_vector->iov_base; + *rspcount = 1; + } + + ret = xdr_to_dict (&rsp->xdata, xdata); + +#ifdef GF_TESTING_IO_XDATA + dict_dump_to_log (xdata); +#endif + return ret; +} + +int +client_pre_stat_v2 (xlator_t *this, gfx_stat_req *req, loc_t *loc, + dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_readlink_v2 (xlator_t *this, gfx_readlink_req *req, loc_t *loc, + size_t size, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + req->size = size; + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_mknod_v2 (xlator_t *this, gfx_mknod_req *req, loc_t *loc, + mode_t mode, dev_t rdev, mode_t umask, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->parent)) + goto out; + + if (!gf_uuid_is_null (loc->parent->gfid)) + memcpy (req->pargfid, loc->parent->gfid, 16); + else + memcpy (req->pargfid, loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->pargfid)), + out, op_errno, EINVAL); + req->bname = (char *)loc->name; + req->mode = mode; + req->dev = rdev; + req->umask = umask; + + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_mkdir_v2 (xlator_t *this, gfx_mkdir_req *req, loc_t *loc, + mode_t mode, mode_t umask, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->parent)) + goto out; + + if (!gf_uuid_is_null (loc->parent->gfid)) + memcpy (req->pargfid, loc->parent->gfid, 16); + else + memcpy (req->pargfid, loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->pargfid)), + out, op_errno, EINVAL); + + req->bname = (char *)loc->name; + req->mode = mode; + req->umask = umask; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_unlink_v2 (xlator_t *this, gfx_unlink_req *req, loc_t *loc, + int32_t flags, dict_t *xdata) +{ + int op_errno = 0; + + if (!(loc && loc->parent)) + goto out; + + if (!gf_uuid_is_null (loc->parent->gfid)) + memcpy (req->pargfid, loc->parent->gfid, 16); + else + memcpy (req->pargfid, loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->pargfid)), + out, op_errno, EINVAL); + req->bname = (char *)loc->name; + req->xflags = flags; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_rmdir_v2 (xlator_t *this, gfx_rmdir_req *req, loc_t *loc, + int32_t flags, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->parent)) + goto out; + + if (!gf_uuid_is_null (loc->parent->gfid)) + memcpy (req->pargfid, loc->parent->gfid, 16); + else + memcpy (req->pargfid, loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->pargfid)), + out, op_errno, EINVAL); + req->bname = (char *)loc->name; + req->xflags = flags; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_symlink_v2 (xlator_t *this, gfx_symlink_req *req, loc_t *loc, + const char *linkname, mode_t umask, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->parent)) + goto out; + + if (!gf_uuid_is_null (loc->parent->gfid)) + memcpy (req->pargfid, loc->parent->gfid, 16); + else + memcpy (req->pargfid, loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->pargfid)), + out, op_errno, EINVAL); + req->linkname = (char *)linkname; + req->bname = (char *)loc->name; + req->umask = umask; + + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_rename_v2 (xlator_t *this, gfx_rename_req *req, loc_t *oldloc, + loc_t *newloc, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(oldloc && newloc && oldloc->parent && + newloc->parent)) + goto out; + + if (!gf_uuid_is_null (oldloc->parent->gfid)) + memcpy (req->oldgfid, oldloc->parent->gfid, 16); + else + memcpy (req->oldgfid, oldloc->pargfid, 16); + + if (!gf_uuid_is_null (newloc->parent->gfid)) + memcpy (req->newgfid, newloc->parent->gfid, 16); + else + memcpy (req->newgfid, newloc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->oldgfid)), + out, op_errno, EINVAL); + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->newgfid)), + out, op_errno, EINVAL); + req->oldbname = (char *)oldloc->name; + req->newbname = (char *)newloc->name; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_link_v2 (xlator_t *this, + gfx_link_req *req, loc_t *oldloc, loc_t *newloc, + dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(oldloc && oldloc->inode && newloc && + newloc->parent)) + goto out; + + if (!gf_uuid_is_null (oldloc->inode->gfid)) + memcpy (req->oldgfid, oldloc->inode->gfid, 16); + else + memcpy (req->oldgfid, oldloc->gfid, 16); + + if (!gf_uuid_is_null (newloc->parent->gfid)) + memcpy (req->newgfid, newloc->parent->gfid, 16); + else + memcpy (req->newgfid, newloc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->oldgfid)), + out, op_errno, EINVAL); + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->newgfid)), + out, op_errno, EINVAL); + req->newbname = (char *)newloc->name; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_truncate_v2 (xlator_t *this, gfx_truncate_req *req, + loc_t *loc, off_t offset, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + req->offset = offset; + + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_open_v2 (xlator_t *this, gfx_open_req *req, loc_t *loc, fd_t *fd, + int32_t flags, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + req->flags = gf_flags_from_flags (flags); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_readv_v2 (xlator_t *this, gfx_read_req *req, fd_t *fd, size_t size, + off_t offset, int32_t flags, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, FALLBACK_TO_ANON_FD, + remote_fd, op_errno, out); + + req->size = size; + req->offset = offset; + req->fd = remote_fd; + req->flag = flags; + + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_writev_v2 (xlator_t *this, gfx_write_req *req, + fd_t *fd, size_t size, off_t offset, int32_t flags, + dict_t **xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, FALLBACK_TO_ANON_FD, + remote_fd, op_errno, out); + + req->size = size; + req->offset = offset; + req->fd = remote_fd; + req->flag = flags; + + memcpy (req->gfid, fd->inode->gfid, 16); + +#ifdef GF_TESTING_IO_XDATA + if (!*xdata) + *xdata = dict_new (); + + ret = dict_set_str (*xdata, "testing-the-xdata-key", + "testing-the-xdata-value"); +#endif + + dict_to_xdr (*xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_statfs_v2 (xlator_t *this, gfx_statfs_req *req, loc_t *loc, + dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!loc) + goto out; + + if (loc->inode) { + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + } else { + req->gfid[15] = 1; + } + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_flush_v2 (xlator_t *this, gfx_flush_req *req, fd_t *fd, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fsync_v2 (xlator_t *this, gfx_fsync_req *req, fd_t *fd, + int32_t flags, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = 0; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + req->data = flags; + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_setxattr_v2 (xlator_t *this, gfx_setxattr_req *req, loc_t *loc, + dict_t *xattr, int32_t flags, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + if (xattr) { + dict_to_xdr (xattr, &req->dict); + } + + req->flags = flags; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_getxattr_v2 (xlator_t *this, gfx_getxattr_req *req, loc_t *loc, + const char *name, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!loc) { + op_errno = EINVAL; + goto out; + } + + if (loc->inode && !gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + req->namelen = 1; /* Use it as a flag */ + + req->name = (char *)name; + if (!req->name) { + req->name = ""; + req->namelen = 0; + } + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_removexattr_v2 (xlator_t *this, gfx_removexattr_req *req, + loc_t *loc, const char *name, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + req->name = (char *)name; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_opendir_v2 (xlator_t *this, + gfx_opendir_req *req, loc_t *loc, + fd_t *fd, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fsyncdir_v2 (xlator_t *this, gfx_fsyncdir_req *req, fd_t *fd, + int32_t flags, dict_t *xdata) +{ + int32_t op_errno = ESTALE; + int64_t remote_fd = -1; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + req->data = flags; + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_access_v2 (xlator_t *this, gfx_access_req *req, loc_t *loc, + int32_t mask, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + req->mask = mask; + + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_create_v2 (xlator_t *this, gfx_create_req *req, + loc_t *loc, fd_t *fd, mode_t mode, + int32_t flags, mode_t umask, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->parent)) + goto out; + + if (!gf_uuid_is_null (loc->parent->gfid)) + memcpy (req->pargfid, loc->parent->gfid, 16); + else + memcpy (req->pargfid, loc->pargfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->pargfid)), + out, op_errno, EINVAL); + req->bname = (char *)loc->name; + req->mode = mode; + req->flags = gf_flags_from_flags (flags); + req->umask = umask; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_ftruncate_v2 (xlator_t *this, gfx_ftruncate_req *req, fd_t *fd, + off_t offset, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = EINVAL; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->offset = offset; + req->fd = remote_fd; + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_fstat_v2 (xlator_t *this, gfx_fstat_req *req, fd_t *fd, + dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_lk_v2 (xlator_t *this, gfx_lk_req *req, + int32_t cmd, struct gf_flock *flock, fd_t *fd, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + int32_t gf_cmd = 0; + int32_t gf_type = 0; + int ret = 0; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + ret = client_cmd_to_gf_cmd (cmd, &gf_cmd); + if (ret) { + op_errno = EINVAL; + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + PC_MSG_INVALID_ENTRY, "Unknown cmd (%d)!", gf_cmd); + goto out; + } + + switch (flock->l_type) { + case F_RDLCK: + gf_type = GF_LK_F_RDLCK; + break; + case F_WRLCK: + gf_type = GF_LK_F_WRLCK; + break; + case F_UNLCK: + gf_type = GF_LK_F_UNLCK; + break; + } + + req->fd = remote_fd; + req->cmd = gf_cmd; + req->type = gf_type; + gf_proto_flock_from_flock (&req->flock, flock); + + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_lookup_v2 (xlator_t *this, gfx_lookup_req *req, loc_t *loc, + dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if ((loc->parent) && (!gf_uuid_is_null (loc->parent->gfid))) + memcpy (req->pargfid, loc->parent->gfid, 16); + else + memcpy (req->pargfid, loc->pargfid, 16); + + if ((loc->inode) && (!gf_uuid_is_null (loc->inode->gfid))) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + + if (loc->name) + req->bname = (char *)loc->name; + else + req->bname = ""; + + if (xdata) { + dict_to_xdr (xdata, &req->xdata); + } + return 0; +out: + return -op_errno; +} + +int +client_pre_readdir_v2 (xlator_t *this, gfx_readdir_req *req, fd_t *fd, + size_t size, off_t offset, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->size = size; + req->offset = offset; + req->fd = remote_fd; + + memcpy (req->gfid, fd->inode->gfid, 16); + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_inodelk_v2 (xlator_t *this, gfx_inodelk_req *req, loc_t *loc, + int cmd, struct gf_flock *flock, const char *volume, + dict_t *xdata) +{ + int op_errno = ESTALE; + int32_t gf_cmd = 0; + int32_t gf_type = 0; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->gfid)) + memcpy (req->gfid, loc->gfid, 16); + else + memcpy (req->gfid, loc->inode->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + if (cmd == F_GETLK || cmd == F_GETLK64) + gf_cmd = GF_LK_GETLK; + else if (cmd == F_SETLK || cmd == F_SETLK64) + gf_cmd = GF_LK_SETLK; + else if (cmd == F_SETLKW || cmd == F_SETLKW64) + gf_cmd = GF_LK_SETLKW; + else { + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + PC_MSG_INVALID_ENTRY, "Unknown cmd (%d)!", gf_cmd); + op_errno = EINVAL; + goto out; + } + + switch (flock->l_type) { + case F_RDLCK: + gf_type = GF_LK_F_RDLCK; + break; + case F_WRLCK: + gf_type = GF_LK_F_WRLCK; + break; + case F_UNLCK: + gf_type = GF_LK_F_UNLCK; + break; + } + + req->volume = (char *)volume; + req->cmd = gf_cmd; + req->type = gf_type; + gf_proto_flock_from_flock (&req->flock, flock); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_finodelk_v2 (xlator_t *this, gfx_finodelk_req *req, fd_t *fd, + int cmd, struct gf_flock *flock, const char *volume, + dict_t *xdata) +{ + int op_errno = ESTALE; + int64_t remote_fd = -1; + int32_t gf_type = 0; + int32_t gf_cmd = 0; + + CLIENT_GET_REMOTE_FD (this, fd, FALLBACK_TO_ANON_FD, + remote_fd, op_errno, out); + + if (cmd == F_GETLK || cmd == F_GETLK64) + gf_cmd = GF_LK_GETLK; + else if (cmd == F_SETLK || cmd == F_SETLK64) + gf_cmd = GF_LK_SETLK; + else if (cmd == F_SETLKW || cmd == F_SETLKW64) + gf_cmd = GF_LK_SETLKW; + else { + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + PC_MSG_INVALID_ENTRY, "Unknown cmd (%d)!", gf_cmd); + goto out; + } + + switch (flock->l_type) { + case F_RDLCK: + gf_type = GF_LK_F_RDLCK; + break; + case F_WRLCK: + gf_type = GF_LK_F_WRLCK; + break; + case F_UNLCK: + gf_type = GF_LK_F_UNLCK; + break; + } + + req->volume = (char *)volume; + req->fd = remote_fd; + req->cmd = gf_cmd; + req->type = gf_type; + gf_proto_flock_from_flock (&req->flock, flock); + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_entrylk_v2 (xlator_t *this, gfx_entrylk_req *req, loc_t *loc, + entrylk_cmd cmd_entrylk, entrylk_type type, + const char *volume, const char *basename, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->gfid)) + memcpy (req->gfid, loc->gfid, 16); + else + memcpy (req->gfid, loc->inode->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + req->cmd = cmd_entrylk; + req->type = type; + req->volume = (char *)volume; + req->name = ""; + if (basename) { + req->name = (char *)basename; + req->namelen = 1; + } + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fentrylk_v2 (xlator_t *this, gfx_fentrylk_req *req, fd_t *fd, + entrylk_cmd cmd_entrylk, entrylk_type type, + const char *volume, const char *basename, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + req->cmd = cmd_entrylk; + req->type = type; + req->volume = (char *)volume; + req->name = ""; + if (basename) { + req->name = (char *)basename; + req->namelen = 1; + } + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_xattrop_v2 (xlator_t *this, gfx_xattrop_req *req, loc_t *loc, + dict_t *xattr, int32_t flags, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + dict_to_xdr (xattr, &req->dict); + + req->flags = flags; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fxattrop_v2 (xlator_t *this, gfx_fxattrop_req *req, fd_t *fd, + dict_t *xattr, int32_t flags, dict_t *xdata) +{ + int op_errno = ESTALE; + int64_t remote_fd = -1; + + CLIENT_GET_REMOTE_FD (this, fd, FALLBACK_TO_ANON_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + req->flags = flags; + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xattr, &req->dict); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fgetxattr_v2 (xlator_t *this, gfx_fgetxattr_req *req, fd_t *fd, + const char *name, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->namelen = 1; /* Use it as a flag */ + req->fd = remote_fd; + req->name = (char *)name; + if (!req->name) { + req->name = ""; + req->namelen = 0; + } + memcpy (req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fsetxattr_v2 (xlator_t *this, gfx_fsetxattr_req *req, fd_t *fd, + int32_t flags, dict_t *xattr, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + req->flags = flags; + memcpy (req->gfid, fd->inode->gfid, 16); + + if (xattr) { + dict_to_xdr (xattr, &req->dict); + } + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_rchecksum_v2 (xlator_t *this, gfx_rchecksum_req *req, fd_t *fd, + int32_t len, off_t offset, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->len = len; + req->offset = offset; + req->fd = remote_fd; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_setattr_v2 (xlator_t *this, gfx_setattr_req *req, loc_t *loc, + int32_t valid, struct iatt *stbuf, dict_t *xdata) +{ + int op_errno = ESTALE; + + if (!(loc && loc->inode)) + return -op_errno; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + + req->valid = valid; + gfx_stat_from_iattx (&req->stbuf, stbuf); + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fsetattr_v2 (xlator_t *this, gfx_fsetattr_req *req, fd_t *fd, + int32_t valid, struct iatt *stbuf, dict_t *xdata) +{ + int op_errno = ESTALE; + int64_t remote_fd = -1; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + memcpy (req->gfid, fd->inode->gfid, 16); + req->fd = remote_fd; + req->valid = valid; + gfx_stat_from_iattx (&req->stbuf, stbuf); + + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_readdirp_v2 (xlator_t *this, gfx_readdirp_req *req, fd_t *fd, + size_t size, off_t offset, dict_t *xdata) +{ + int op_errno = ESTALE; + int64_t remote_fd = -1; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->size = size; + req->offset = offset; + req->fd = remote_fd; + memcpy (req->gfid, fd->inode->gfid, 16); + + /* dict itself is 'xdata' here */ + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fremovexattr_v2 (xlator_t *this, gfx_fremovexattr_req *req, fd_t *fd, + const char *name, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + if (!(fd && fd->inode)) + goto out; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + memcpy (req->gfid, fd->inode->gfid, 16); + req->name = (char *)name; + req->fd = remote_fd; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_fallocate_v2 (xlator_t *this, gfx_fallocate_req *req, fd_t *fd, + int32_t flags, off_t offset, size_t size, dict_t *xdata) +{ + int op_errno = ESTALE; + int64_t remote_fd = -1; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + req->flags = flags; + req->offset = offset; + req->size = size; + memcpy(req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_discard_v2 (xlator_t *this, gfx_discard_req *req, fd_t *fd, + off_t offset, size_t size, dict_t *xdata) +{ + int op_errno = ESTALE; + int64_t remote_fd = -1; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + req->offset = offset; + req->size = size; + memcpy(req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_zerofill_v2 (xlator_t *this, gfx_zerofill_req *req, fd_t *fd, + off_t offset, size_t size, dict_t *xdata) +{ + int op_errno = ESTALE; + int64_t remote_fd = -1; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + req->fd = remote_fd; + req->offset = offset; + req->size = size; + memcpy(req->gfid, fd->inode->gfid, 16); + + dict_to_xdr (xdata, &req->xdata); + return 0; +out: + return -op_errno; +} + +int +client_pre_ipc_v2 (xlator_t *this, gfx_ipc_req *req, int32_t cmd, + dict_t *xdata) +{ + req->op = cmd; + + dict_to_xdr (xdata, &req->xdata); + return 0; +} + +int +client_pre_seek_v2 (xlator_t *this, gfx_seek_req *req, fd_t *fd, + off_t offset, gf_seek_what_t what, dict_t *xdata) +{ + int64_t remote_fd = -1; + int op_errno = ESTALE; + + CLIENT_GET_REMOTE_FD (this, fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, out); + + memcpy (req->gfid, fd->inode->gfid, 16); + req->fd = remote_fd; + req->offset = offset; + req->what = what; + + dict_to_xdr (xdata, &req->xdata); + + return 0; +out: + return -op_errno; +} + +int +client_pre_lease_v2 (xlator_t *this, gfx_lease_req *req, loc_t *loc, + struct gf_lease *lease, dict_t *xdata) +{ + int op_errno = 0; + + if (!(loc && loc->inode)) + goto out; + + if (!gf_uuid_is_null (loc->inode->gfid)) + memcpy (req->gfid, loc->inode->gfid, 16); + else + memcpy (req->gfid, loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req->gfid)), + out, op_errno, EINVAL); + + gf_proto_lease_from_lease (&req->lease, lease); + + dict_to_xdr (xdata, &req->xdata); +out: + return -op_errno; +} + +int +client_post_create_v2 (xlator_t *this, gfx_create_rsp *rsp, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, + clnt_local_t *local, dict_t **xdata) +{ + if (-1 != rsp->op_ret) { + gfx_stat_to_iattx (&rsp->stat, stbuf); + + gfx_stat_to_iattx (&rsp->preparent, preparent); + gfx_stat_to_iattx (&rsp->postparent, postparent); + gf_uuid_copy (local->loc.gfid, stbuf->ia_gfid); + } + return xdr_to_dict (&rsp->xdata, xdata); +} + +int +client_post_lease_v2 (xlator_t *this, gfx_lease_rsp *rsp, struct gf_lease *lease, + dict_t **xdata) +{ + if (rsp->op_ret >= 0) { + gf_proto_lease_to_lease (&rsp->lease, lease); + } + + return xdr_to_dict (&rsp->xdata, xdata); +} + +int +client_post_lk_v2 (xlator_t *this, gfx_lk_rsp *rsp, struct gf_flock *lock, + dict_t **xdata) +{ + if (rsp->op_ret >= 0) { + gf_proto_flock_to_flock (&rsp->flock, lock); + } + return xdr_to_dict (&rsp->xdata, xdata); +} + +int +client_post_readdir_v2 (xlator_t *this, gfx_readdir_rsp *rsp, + gf_dirent_t *entries, dict_t **xdata) +{ + if (rsp->op_ret > 0) { + unserialize_rsp_dirent_v2 (this, rsp, entries); + } + return xdr_to_dict (&rsp->xdata, xdata); +} + +int +client_post_readdirp_v2 (xlator_t *this, gfx_readdirp_rsp *rsp, + fd_t *fd, gf_dirent_t *entries, + dict_t **xdata) +{ + if (rsp->op_ret > 0) { + unserialize_rsp_direntp_v2 (this, fd, rsp, entries); + } + return xdr_to_dict (&rsp->xdata, xdata); +} + + + +int +client_post_rename_v2 (xlator_t *this, gfx_rename_rsp *rsp, struct iatt *stbuf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t **xdata) +{ + if (-1 != rsp->op_ret) { + gfx_stat_to_iattx (&rsp->stat, stbuf); + + gfx_stat_to_iattx (&rsp->preoldparent, preoldparent); + gfx_stat_to_iattx (&rsp->postoldparent, postoldparent); + + gfx_stat_to_iattx (&rsp->prenewparent, prenewparent); + gfx_stat_to_iattx (&rsp->postnewparent, postnewparent); + } + + return xdr_to_dict (&rsp->xdata, xdata); +} diff --git a/xlators/protocol/client/src/client-common.h b/xlators/protocol/client/src/client-common.h index fd3fba869f5..76ec0e9279d 100644 --- a/xlators/protocol/client/src/client-common.h +++ b/xlators/protocol/client/src/client-common.h @@ -15,6 +15,7 @@ #include "xlator.h" #include "rpc-common-xdr.h" #include "glusterfs3-xdr.h" +#include "glusterfs4-xdr.h" #include "glusterfs3.h" #include "client.h" @@ -400,4 +401,243 @@ client_post_seek (xlator_t *this, gfs3_seek_rsp *rsp, dict_t **xdata); int client_post_lease (xlator_t *this, gfs3_lease_rsp *rsp, struct gf_lease *lease, dict_t **xdata); + +/* New functions for version 4 */ +int +client_post_common_dict (xlator_t *this, gfx_common_dict_rsp *rsp, dict_t **dict, + dict_t **xdata); +int +client_post_common_3iatt (xlator_t *this, gfx_common_3iatt_rsp *rsp, struct iatt *iatt, + struct iatt *iatt2, struct iatt *iatt3, dict_t **xdata); +int +client_post_common_2iatt (xlator_t *this, gfx_common_2iatt_rsp *rsp, struct iatt *iatt, + struct iatt *iatt2, dict_t **xdata); +int +client_post_common_iatt (xlator_t *this, gfx_common_iatt_rsp *rsp, struct iatt *iatt, + dict_t **xdata); +int +client_post_common_rsp (xlator_t *this, gfx_common_rsp *rsp, dict_t **xdata); + + +int +client_pre_stat_v2 (xlator_t *this, gfx_stat_req *req, loc_t *loc, + dict_t *xdata); + +int +client_pre_readlink_v2 (xlator_t *this, gfx_readlink_req *req, loc_t *loc, + size_t size, dict_t *xdata); + +int +client_pre_mknod_v2 (xlator_t *this, gfx_mknod_req *req, loc_t *loc, + mode_t mode, dev_t rdev, mode_t umask, dict_t *xdata); + +int +client_pre_mkdir_v2 (xlator_t *this, gfx_mkdir_req *req, loc_t *loc, + mode_t mode, mode_t umask, dict_t *xdata); + +int +client_pre_unlink_v2 (xlator_t *this, gfx_unlink_req *req, loc_t *loc, + int32_t flags, dict_t *xdata); + +int +client_pre_rmdir_v2 (xlator_t *this, gfx_rmdir_req *req, loc_t *loc, + int32_t flags, dict_t *xdata); + +int +client_pre_symlink_v2 (xlator_t *this, gfx_symlink_req *req, loc_t *loc, + const char *linkname, mode_t umask, dict_t *xdata); + +int +client_pre_rename_v2 (xlator_t *this, gfx_rename_req *req, loc_t *oldloc, + loc_t *newloc, dict_t *xdata); + +int +client_pre_link_v2 (xlator_t *this, + gfx_link_req *req, loc_t *oldloc, loc_t *newloc, + dict_t *xdata); + +int +client_pre_truncate_v2 (xlator_t *this, gfx_truncate_req *req, + loc_t *loc, off_t offset, dict_t *xdata); + +int +client_pre_open_v2 (xlator_t *this, gfx_open_req *req, loc_t *loc, fd_t *fd, + int32_t flags, dict_t *xdata); + +int +client_pre_readv_v2 (xlator_t *this, gfx_read_req *req, fd_t *fd, size_t size, + off_t offset, int32_t flags, dict_t *xdata); + +int +client_pre_writev_v2 (xlator_t *this, gfx_write_req *req, + fd_t *fd, size_t size, off_t offset, int32_t flags, + dict_t **xdata); + +int +client_pre_statfs_v2 (xlator_t *this, gfx_statfs_req *req, loc_t *loc, + dict_t *xdata); + +int +client_pre_flush_v2 (xlator_t *this, gfx_flush_req *req, fd_t *fd, dict_t *xdata); + +int +client_pre_fsync_v2 (xlator_t *this, gfx_fsync_req *req, fd_t *fd, + int32_t flags, dict_t *xdata); + +int +client_pre_setxattr_v2 (xlator_t *this, gfx_setxattr_req *req, loc_t *loc, + dict_t *xattr, int32_t flags, dict_t *xdata); + +int +client_pre_getxattr_v2 (xlator_t *this, gfx_getxattr_req *req, loc_t *loc, + const char *name, dict_t *xdata); + +int +client_pre_removexattr_v2 (xlator_t *this, gfx_removexattr_req *req, + loc_t *loc, const char *name, dict_t *xdata); + +int +client_pre_opendir_v2 (xlator_t *this, + gfx_opendir_req *req, loc_t *loc, + fd_t *fd, dict_t *xdata); + +int +client_pre_fsyncdir_v2 (xlator_t *this, gfx_fsyncdir_req *req, fd_t *fd, + int32_t flags, dict_t *xdata); + +int +client_pre_access_v2 (xlator_t *this, gfx_access_req *req, loc_t *loc, + int32_t mask, dict_t *xdata); + +int +client_pre_create_v2 (xlator_t *this, gfx_create_req *req, + loc_t *loc, fd_t *fd, mode_t mode, + int32_t flags, mode_t umask, dict_t *xdata); + +int +client_pre_ftruncate_v2 (xlator_t *this, gfx_ftruncate_req *req, fd_t *fd, + off_t offset, dict_t *xdata); + +int +client_pre_fstat_v2 (xlator_t *this, gfx_fstat_req *req, fd_t *fd, + dict_t *xdata); + +int +client_pre_lk_v2 (xlator_t *this, gfx_lk_req *req, + int32_t cmd, struct gf_flock *flock, fd_t *fd, dict_t *xdata); + +int +client_pre_lookup_v2 (xlator_t *this, gfx_lookup_req *req, loc_t *loc, + dict_t *xdata); + +int +client_pre_readdir_v2 (xlator_t *this, gfx_readdir_req *req, fd_t *fd, + size_t size, off_t offset, dict_t *xdata); + +int +client_pre_inodelk_v2 (xlator_t *this, gfx_inodelk_req *req, loc_t *loc, + int cmd, struct gf_flock *flock, const char *volume, + dict_t *xdata); + +int +client_pre_finodelk_v2 (xlator_t *this, gfx_finodelk_req *req, fd_t *fd, + int cmd, struct gf_flock *flock, const char *volume, + dict_t *xdata); + +int +client_pre_entrylk_v2 (xlator_t *this, gfx_entrylk_req *req, loc_t *loc, + entrylk_cmd cmd_entrylk, entrylk_type type, + const char *volume, const char *basename, dict_t *xdata); + +int +client_pre_fentrylk_v2 (xlator_t *this, gfx_fentrylk_req *req, fd_t *fd, + entrylk_cmd cmd_entrylk, entrylk_type type, + const char *volume, const char *basename, dict_t *xdata); + +int +client_pre_xattrop_v2 (xlator_t *this, gfx_xattrop_req *req, loc_t *loc, + dict_t *xattr, int32_t flags, dict_t *xdata); + +int +client_pre_fxattrop_v2 (xlator_t *this, gfx_fxattrop_req *req, fd_t *fd, + dict_t *xattr, int32_t flags, dict_t *xdata); + +int +client_pre_fgetxattr_v2 (xlator_t *this, gfx_fgetxattr_req *req, fd_t *fd, + const char *name, dict_t *xdata); + +int +client_pre_fsetxattr_v2 (xlator_t *this, gfx_fsetxattr_req *req, fd_t *fd, + int32_t flags, dict_t *xattr, dict_t *xdata); +int +client_pre_seek_v2 (xlator_t *this, gfx_seek_req *req, fd_t *fd, + off_t offset, gf_seek_what_t what, dict_t *xdata); + +int +client_pre_rchecksum_v2 (xlator_t *this, gfx_rchecksum_req *req, fd_t *fd, + int32_t len, off_t offset, dict_t *xdata); + +int +client_pre_setattr_v2 (xlator_t *this, gfx_setattr_req *req, loc_t *loc, + int32_t valid, struct iatt *stbuf, dict_t *xdata); +int +client_pre_fsetattr_v2 (xlator_t *this, gfx_fsetattr_req *req, fd_t *fd, + int32_t valid, struct iatt *stbuf, dict_t *xdata); + +int +client_pre_readdirp_v2 (xlator_t *this, gfx_readdirp_req *req, fd_t *fd, + size_t size, off_t offset, dict_t *xdata); + +int +client_pre_fremovexattr_v2 (xlator_t *this, gfx_fremovexattr_req *req, fd_t *fd, + const char *name, dict_t *xdata); + +int +client_pre_fallocate_v2 (xlator_t *this, gfx_fallocate_req *req, fd_t *fd, + int32_t flags, off_t offset, size_t size, dict_t *xdata); +int +client_pre_discard_v2 (xlator_t *this, gfx_discard_req *req, fd_t *fd, + off_t offset, size_t size, dict_t *xdata); +int +client_pre_zerofill_v2 (xlator_t *this, gfx_zerofill_req *req, fd_t *fd, + off_t offset, size_t size, dict_t *xdata); +int +client_pre_ipc_v2 (xlator_t *this, gfx_ipc_req *req, int32_t cmd, + dict_t *xdata); + +int +client_pre_lease_v2 (xlator_t *this, gfx_lease_req *req, loc_t *loc, + struct gf_lease *lease, dict_t *xdata); + +int +client_post_readv_v2 (xlator_t *this, gfx_read_rsp *rsp, struct iobref **iobref, + struct iobref *rsp_iobref, struct iatt *stat, + struct iovec *vector, struct iovec *rsp_vector, + int *rspcount, dict_t **xdata); + + +int +client_post_create_v2 (xlator_t *this, gfx_create_rsp *rsp, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, + clnt_local_t *local, dict_t **xdata); +int +client_post_lease_v2 (xlator_t *this, gfx_lease_rsp *rsp, struct gf_lease *lease, + dict_t **xdata); +int +client_post_lk_v2 (xlator_t *this, gfx_lk_rsp *rsp, struct gf_flock *lock, + dict_t **xdata); +int +client_post_readdir_v2 (xlator_t *this, gfx_readdir_rsp *rsp, + gf_dirent_t *entries, dict_t **xdata); +int +client_post_readdirp_v2 (xlator_t *this, gfx_readdirp_rsp *rsp, + fd_t *fd, gf_dirent_t *entries, + dict_t **xdata); +int +client_post_rename_v2 (xlator_t *this, gfx_rename_rsp *rsp, struct iatt *stbuf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t **xdata); + #endif /* __CLIENT_COMMON_H__ */ diff --git a/xlators/protocol/client/src/client-helpers.c b/xlators/protocol/client/src/client-helpers.c index c078b88b84d..465de2a52d4 100644 --- a/xlators/protocol/client/src/client-helpers.c +++ b/xlators/protocol/client/src/client-helpers.c @@ -142,7 +142,6 @@ client_local_wipe (clnt_local_t *local) return 0; } - int unserialize_rsp_dirent (xlator_t *this, struct gfs3_readdir_rsp *rsp, gf_dirent_t *entries) @@ -272,6 +271,113 @@ clnt_readdirp_rsp_cleanup (gfs3_readdirp_rsp *rsp) } int +unserialize_rsp_dirent_v2 (xlator_t *this, struct gfx_readdir_rsp *rsp, + gf_dirent_t *entries) +{ + struct gfx_dirlist *trav = NULL; + gf_dirent_t *entry = NULL; + int entry_len = 0; + int ret = -1; + clnt_conf_t *conf = NULL; + + conf = this->private; + + trav = rsp->reply; + while (trav) { + entry_len = gf_dirent_size (trav->name); + entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t); + if (!entry) + goto out; + + entry->d_ino = trav->d_ino; + gf_itransform (this, trav->d_off, &entry->d_off, + conf->client_id); + entry->d_len = trav->d_len; + entry->d_type = trav->d_type; + + strcpy (entry->d_name, trav->name); + + list_add_tail (&entry->list, &entries->list); + + trav = trav->nextentry; + } + + ret = 0; +out: + return ret; +} + +int +unserialize_rsp_direntp_v2 (xlator_t *this, fd_t *fd, + struct gfx_readdirp_rsp *rsp, gf_dirent_t *entries) +{ + struct gfx_dirplist *trav = NULL; + gf_dirent_t *entry = NULL; + inode_table_t *itable = NULL; + int entry_len = 0; + int ret = -1; + clnt_conf_t *conf = NULL; + + trav = rsp->reply; + + if (fd) + itable = fd->inode->table; + + conf = this->private; + if (!conf) + goto out; + + while (trav) { + entry_len = gf_dirent_size (trav->name); + entry = GF_CALLOC (1, entry_len, gf_common_mt_gf_dirent_t); + if (!entry) + goto out; + + entry->d_ino = trav->d_ino; + gf_itransform (this, trav->d_off, &entry->d_off, + conf->client_id); + entry->d_len = trav->d_len; + entry->d_type = trav->d_type; + + gfx_stat_to_iattx (&trav->stat, &entry->d_stat); + + strcpy (entry->d_name, trav->name); + + xdr_to_dict (&trav->dict, &entry->dict); + + entry->inode = inode_find (itable, entry->d_stat.ia_gfid); + if (!entry->inode) + entry->inode = inode_new (itable); + + list_add_tail (&entry->list, &entries->list); + + trav = trav->nextentry; + } + + ret = 0; +out: + return ret; +} + +int +clnt_readdirp_rsp_cleanup_v2 (gfx_readdirp_rsp *rsp) +{ + gfx_dirplist *prev = NULL; + gfx_dirplist *trav = NULL; + + trav = rsp->reply; + prev = trav; + while (trav) { + trav = trav->nextentry; + free (prev->name); + free (prev); + prev = trav; + } + + return 0; +} + +int clnt_readdir_rsp_cleanup (gfs3_readdir_rsp *rsp) { gfs3_dirlist *prev = NULL; @@ -291,6 +397,25 @@ clnt_readdir_rsp_cleanup (gfs3_readdir_rsp *rsp) } int +clnt_readdir_rsp_cleanup_v2 (gfx_readdir_rsp *rsp) +{ + gfx_dirlist *prev = NULL; + gfx_dirlist *trav = NULL; + + trav = rsp->reply; + prev = trav; + while (trav) { + trav = trav->nextentry; + /* on client, the rpc lib allocates this */ + free (prev->name); + free (prev); + prev = trav; + } + + return 0; +} + +int client_get_remote_fd (xlator_t *this, fd_t *fd, int flags, int64_t *remote_fd) { clnt_fd_ctx_t *fdctx = NULL; @@ -1650,6 +1775,21 @@ clnt_getactivelk_rsp_cleanup (gfs3_getactivelk_rsp *rsp) } } +void +clnt_getactivelk_rsp_cleanup_v2 (gfx_getactivelk_rsp *rsp) +{ + gfs3_locklist *trav = NULL; + gfs3_locklist *next = NULL; + + trav = rsp->reply; + + while (trav) { + next = trav->nextentry; + free (trav->client_uid); + free (trav); + trav = next; + } +} int clnt_unserialize_rsp_locklist (xlator_t *this, struct gfs3_getactivelk_rsp *rsp, lock_migration_info_t *lmi) @@ -1689,6 +1829,46 @@ clnt_unserialize_rsp_locklist (xlator_t *this, struct gfs3_getactivelk_rsp *rsp, out: return ret; } +int +clnt_unserialize_rsp_locklist_v2 (xlator_t *this, struct gfx_getactivelk_rsp *rsp, + lock_migration_info_t *lmi) +{ + struct gfs3_locklist *trav = NULL; + lock_migration_info_t *temp = NULL; + int ret = -1; + clnt_conf_t *conf = NULL; + + trav = rsp->reply; + + conf = this->private; + if (!conf) + goto out; + + while (trav) { + temp = GF_CALLOC (1, sizeof (*lmi), gf_common_mt_lock_mig); + if (temp == NULL) { + gf_msg (this->name, GF_LOG_ERROR, 0, 0, "No memory"); + goto out; + } + + INIT_LIST_HEAD (&temp->list); + + gf_proto_flock_to_flock (&trav->flock, &temp->flock); + + temp->lk_flags = trav->lk_flags; + + temp->client_uid = gf_strdup (trav->client_uid); + + list_add_tail (&temp->list, &lmi->list); + + trav = trav->nextentry; + } + + ret = 0; +out: + return ret; +} + void clnt_setactivelk_req_cleanup (gfs3_setactivelk_req *req) @@ -1706,6 +1886,22 @@ clnt_setactivelk_req_cleanup (gfs3_setactivelk_req *req) } } +void +clnt_setactivelk_req_cleanup_v2 (gfx_setactivelk_req *req) +{ + gfs3_locklist *trav = NULL; + gfs3_locklist *next = NULL; + + trav = req->request; + + while (trav) { + next = trav->nextentry; + GF_FREE (trav->client_uid); + GF_FREE (trav); + trav = next; + } +} + int serialize_req_locklist (lock_migration_info_t *locklist, gfs3_setactivelk_req *req) @@ -1770,6 +1966,71 @@ out: return ret; } + +int +serialize_req_locklist_v2 (lock_migration_info_t *locklist, + gfx_setactivelk_req *req) +{ + lock_migration_info_t *tmp = NULL; + gfs3_locklist *trav = NULL; + gfs3_locklist *prev = NULL; + int ret = -1; + + GF_VALIDATE_OR_GOTO ("server", locklist, out); + GF_VALIDATE_OR_GOTO ("server", req, out); + + list_for_each_entry (tmp, &locklist->list, list) { + trav = GF_CALLOC (1, sizeof (*trav), + gf_client_mt_clnt_lock_request_t); + if (!trav) + goto out; + + switch (tmp->flock.l_type) { + case F_RDLCK: + tmp->flock.l_type = GF_LK_F_RDLCK; + break; + case F_WRLCK: + tmp->flock.l_type = GF_LK_F_WRLCK; + break; + case F_UNLCK: + tmp->flock.l_type = GF_LK_F_UNLCK; + break; + + default: + gf_msg (THIS->name, GF_LOG_ERROR, 0, 0, + "Unknown lock type: %"PRId32"!", + tmp->flock.l_type); + break; + } + + gf_proto_flock_from_flock (&trav->flock, &tmp->flock); + + trav->lk_flags = tmp->lk_flags; + + trav->client_uid = gf_strdup (tmp->client_uid); + if (!trav->client_uid) { + gf_msg (THIS->name, GF_LOG_ERROR, 0, 0, + "client_uid could not be allocated"); + ret = -1; + goto out; + } + + if (prev) + prev->nextentry = trav; + else + req->request = trav; + + prev = trav; + trav = NULL; + } + + ret = 0; +out: + GF_FREE (trav); + + return ret; +} + void client_compound_rsp_cleanup (gfs3_compound_rsp *rsp, int len) { @@ -1974,3 +2235,1042 @@ client_compound_rsp_cleanup (gfs3_compound_rsp *rsp, int len) } return; } + +/* compound v2 */ +int +client_handle_fop_requirements_v2 (xlator_t *this, call_frame_t *frame, + gfx_compound_req *req, + clnt_local_t *local, + struct iobref **req_iobref, + struct iobref **rsp_iobref, + struct iovec *req_vector, + struct iovec *rsp_vector, int *req_count, + int *rsp_count, default_args_t *args, + int fop_enum, int index) +{ + int ret = 0; + int op_errno = ENOMEM; + struct iobuf *rsp_iobuf = NULL; + int64_t remote_fd = -1; + compound_req_v2 *this_req = &req->compound_req_array.compound_req_array_val[index]; + + this_req->fop_enum = fop_enum; + + switch (fop_enum) { + case GF_FOP_STAT: + CLIENT4_PRE_FOP (stat, this, + &this_req->compound_req_v2_u.compound_stat_req, + op_errno, out, + &args->loc, args->xdata); + break; + case GF_FOP_READLINK: + CLIENT4_PRE_FOP (readlink, this, + &this_req->compound_req_v2_u.compound_readlink_req, + op_errno, out, + &args->loc, args->size, args->xdata); + break; + case GF_FOP_MKNOD: + CLIENT4_PRE_FOP (mknod, this, + &this_req->compound_req_v2_u.compound_mknod_req, + op_errno, out, + &args->loc, args->mode, args->rdev, + args->umask, args->xdata); + loc_copy (&local->loc, &args->loc); + loc_path (&local->loc, NULL); + break; + case GF_FOP_MKDIR: + CLIENT4_PRE_FOP (mkdir, this, + &this_req->compound_req_v2_u.compound_mkdir_req, + op_errno, out, + &args->loc, args->mode, + args->umask, args->xdata); + loc_copy (&local->loc, &args->loc); + loc_path (&local->loc, NULL); + break; + case GF_FOP_UNLINK: + CLIENT4_PRE_FOP (unlink, this, + &this_req->compound_req_v2_u.compound_unlink_req, + op_errno, out, + &args->loc, args->xflag, args->xdata); + break; + case GF_FOP_RMDIR: + CLIENT4_PRE_FOP (rmdir, this, + &this_req->compound_req_v2_u.compound_rmdir_req, + op_errno, out, + &args->loc, args->flags, args->xdata); + break; + case GF_FOP_SYMLINK: + CLIENT4_PRE_FOP (symlink, this, + &this_req->compound_req_v2_u.compound_symlink_req, + op_errno, out, + &args->loc, args->linkname, args->umask, + args->xdata); + loc_copy (&local->loc, &args->loc); + loc_path (&local->loc, NULL); + break; + case GF_FOP_RENAME: + CLIENT4_PRE_FOP (rename, this, + &this_req->compound_req_v2_u.compound_rename_req, + op_errno, out, + &args->loc, &args->loc2, args->xdata); + break; + case GF_FOP_LINK: + CLIENT4_PRE_FOP (link, this, + &this_req->compound_req_v2_u.compound_link_req, + op_errno, out, + &args->loc, &args->loc2, args->xdata); + break; + case GF_FOP_TRUNCATE: + CLIENT4_PRE_FOP (truncate, this, + &this_req->compound_req_v2_u.compound_truncate_req, + op_errno, out, + &args->loc, args->offset, args->xdata); + break; + case GF_FOP_OPEN: + CLIENT4_PRE_FOP (open, this, + &this_req->compound_req_v2_u.compound_open_req, + op_errno, out, + &args->loc, args->fd, args->flags, + args->xdata); + if (!local->fd) + local->fd = fd_ref (args->fd); + break; + case GF_FOP_READ: + op_errno = client_pre_readv_v2 (this, + &this_req->compound_req_v2_u.compound_read_req, + args->fd, args->size, args->offset, + args->flags, args->xdata); + + if (op_errno) { + op_errno = -op_errno; + goto out; + } + if (!local->fd) + local->fd = fd_ref (args->fd); + local->attempt_reopen = client_is_reopen_needed + (args->fd, this, remote_fd); + rsp_iobuf = iobuf_get2 (this->ctx->iobuf_pool, args->size); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto out; + } + + if (!*rsp_iobref) { + *rsp_iobref = iobref_new (); + if (*rsp_iobref == NULL) { + op_errno = ENOMEM; + goto out; + } + } + + iobref_add (*rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + + if (*rsp_count + 1 >= MAX_IOVEC) { + op_errno = ENOMEM; + goto out; + } + rsp_vector[*rsp_count].iov_base = iobuf_ptr (rsp_iobuf); + rsp_vector[*rsp_count].iov_len = iobuf_pagesize (rsp_iobuf); + rsp_iobuf = NULL; + if (args->size > rsp_vector[*rsp_count].iov_len) { + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, + PC_MSG_NO_MEMORY, + "read-size (%lu) is bigger than iobuf size " + "(%lu)", + (unsigned long)args->size, + (unsigned long)rsp_vector[*rsp_count].iov_len); + op_errno = EINVAL; + goto out; + } + *rsp_count += 1; + + break; + case GF_FOP_WRITE: + op_errno = client_pre_writev_v2 (this, + &this_req->compound_req_v2_u.compound_write_req, + args->fd, iov_length (args->vector, args->count), + args->offset, args->flags, &args->xdata); + + if (op_errno) { + op_errno = -op_errno; + goto out; + } + if (!local->fd) + local->fd = fd_ref (args->fd); + local->attempt_reopen = client_is_reopen_needed + (args->fd, this, remote_fd); + + if (*req_count + args->count >= MAX_IOVEC) { + op_errno = ENOMEM; + goto out; + } + memcpy (&req_vector[*req_count], args->vector, + (args->count * sizeof(req_vector[0]))); + *req_count += args->count; + + if (!*req_iobref) + *req_iobref = args->iobref; + else + if (iobref_merge (*req_iobref, args->iobref)) + goto out; + break; + case GF_FOP_STATFS: + CLIENT4_PRE_FOP (statfs, this, + &this_req->compound_req_v2_u.compound_statfs_req, + op_errno, out, + &args->loc, args->xdata); + break; + case GF_FOP_FLUSH: + CLIENT4_PRE_FOP (flush, this, + &this_req->compound_req_v2_u.compound_flush_req, + op_errno, out, + args->fd, args->xdata); + if (!local->fd) + local->fd = fd_ref (args->fd); + local->owner = frame->root->lk_owner; + break; + case GF_FOP_FSYNC: + CLIENT4_PRE_FOP (fsync, this, + &this_req->compound_req_v2_u.compound_fsync_req, + op_errno, out, + args->fd, args->datasync, args->xdata); + break; + case GF_FOP_SETXATTR: + CLIENT4_PRE_FOP (setxattr, this, + &this_req->compound_req_v2_u.compound_setxattr_req, + op_errno, out, + &args->loc, args->xattr, args->flags, + args->xdata); + break; + case GF_FOP_GETXATTR: + CLIENT4_PRE_FOP (getxattr, this, + &this_req->compound_req_v2_u.compound_getxattr_req, + op_errno, out, + &args->loc, args->name, args->xdata); + loc_copy (&local->loc, &args->loc); + loc_path (&local->loc, NULL); + break; + case GF_FOP_REMOVEXATTR: + CLIENT4_PRE_FOP (removexattr, this, + &this_req->compound_req_v2_u.compound_removexattr_req, + op_errno, out, + &args->loc, args->name, args->xdata); + break; + case GF_FOP_OPENDIR: + CLIENT4_PRE_FOP (opendir, this, + &this_req->compound_req_v2_u.compound_opendir_req, + op_errno, out, + &args->loc, args->fd, args->xdata); + if (!local->fd) + local->fd = fd_ref (args->fd); + loc_copy (&local->loc, &args->loc); + loc_path (&local->loc, NULL); + break; + case GF_FOP_FSYNCDIR: + CLIENT4_PRE_FOP (fsyncdir, this, + &this_req->compound_req_v2_u.compound_fsyncdir_req, + op_errno, out, + args->fd, args->datasync, args->xdata); + break; + case GF_FOP_ACCESS: + CLIENT4_PRE_FOP (access, this, + &this_req->compound_req_v2_u.compound_access_req, + op_errno, out, + &args->loc, args->mask, args->xdata); + break; + case GF_FOP_CREATE: + CLIENT4_PRE_FOP (create, this, + &this_req->compound_req_v2_u.compound_create_req, + op_errno, out, + &args->loc, args->fd, args->mode, args->flags, + args->umask, args->xdata); + if (!local->fd) + local->fd = fd_ref (args->fd); + + loc_copy (&local->loc, &args->loc); + loc_path (&local->loc, NULL); + break; + case GF_FOP_FTRUNCATE: + CLIENT4_PRE_FOP (ftruncate, this, + &this_req->compound_req_v2_u.compound_ftruncate_req, + op_errno, out, + args->fd, args->offset, args->xdata); + break; + case GF_FOP_FSTAT: + CLIENT4_PRE_FOP (fstat, this, + &this_req->compound_req_v2_u.compound_fstat_req, + op_errno, out, + args->fd, args->xdata); + break; + case GF_FOP_LK: + CLIENT4_PRE_FOP (lk, this, + &this_req->compound_req_v2_u.compound_lk_req, + op_errno, out, + args->cmd, &args->lock, args->fd, args->xdata); + if (!local->fd) + local->fd = fd_ref (args->fd); + local->owner = frame->root->lk_owner; + break; + case GF_FOP_LOOKUP: + CLIENT4_PRE_FOP (lookup, this, + &this_req->compound_req_v2_u.compound_lookup_req, + op_errno, out, + &args->loc, args->xdata); + loc_copy (&local->loc, &args->loc); + loc_path (&local->loc, NULL); + break; + case GF_FOP_READDIR: + CLIENT4_PRE_FOP (readdir, this, + &this_req->compound_req_v2_u.compound_readdir_req, + op_errno, out, + args->fd, args->size, args->offset, + args->xdata); + break; + case GF_FOP_INODELK: + CLIENT4_PRE_FOP (inodelk, this, + &this_req->compound_req_v2_u.compound_inodelk_req, + op_errno, out, + &args->loc, args->cmd, &args->lock, + args->volume, args->xdata); + break; + case GF_FOP_FINODELK: + CLIENT4_PRE_FOP (finodelk, this, + &this_req->compound_req_v2_u.compound_finodelk_req, + op_errno, out, + args->fd, args->cmd, &args->lock, + args->volume, args->xdata); + if (!local->fd) + local->fd = fd_ref (args->fd); + local->attempt_reopen = client_is_reopen_needed + (args->fd, this, remote_fd); + break; + case GF_FOP_ENTRYLK: + CLIENT4_PRE_FOP (entrylk, this, + &this_req->compound_req_v2_u.compound_entrylk_req, + op_errno, out, + &args->loc, args->entrylkcmd, + args->entrylktype, args->volume, + args->name, args->xdata); + break; + case GF_FOP_FENTRYLK: + CLIENT4_PRE_FOP (fentrylk, this, + &this_req->compound_req_v2_u.compound_fentrylk_req, + op_errno, out, + args->fd, args->entrylkcmd, + args->entrylktype, args->volume, + args->name, args->xdata); + break; + case GF_FOP_XATTROP: + CLIENT4_PRE_FOP (xattrop, this, + &this_req->compound_req_v2_u.compound_xattrop_req, + op_errno, out, + &args->loc, args->xattr, args->optype, + args->xdata); + break; + case GF_FOP_FXATTROP: + CLIENT4_PRE_FOP (fxattrop, this, + &this_req->compound_req_v2_u.compound_fxattrop_req, + op_errno, out, + args->fd, args->xattr, args->optype, + args->xdata); + if (!local->fd) + local->fd = fd_ref (args->fd); + local->attempt_reopen = client_is_reopen_needed + (args->fd, this, remote_fd); + break; + case GF_FOP_FGETXATTR: + CLIENT4_PRE_FOP (fgetxattr, this, + &this_req->compound_req_v2_u.compound_fgetxattr_req, + op_errno, out, + args->fd, args->name, args->xdata); + break; + case GF_FOP_FSETXATTR: + CLIENT4_PRE_FOP (fsetxattr, this, + &this_req->compound_req_v2_u.compound_fsetxattr_req, + op_errno, out, + args->fd, args->flags, args->xattr, + args->xdata); + break; + case GF_FOP_RCHECKSUM: + CLIENT4_PRE_FOP (rchecksum, this, + &this_req->compound_req_v2_u.compound_rchecksum_req, + op_errno, out, + args->fd, args->size, args->offset, + args->xdata); + break; + case GF_FOP_SETATTR: + CLIENT4_PRE_FOP (setattr, this, + &this_req->compound_req_v2_u.compound_setattr_req, + op_errno, out, + &args->loc, args->valid, &args->stat, + args->xdata); + break; + case GF_FOP_FSETATTR: + CLIENT4_PRE_FOP (fsetattr, this, + &this_req->compound_req_v2_u.compound_fsetattr_req, + op_errno, out, + args->fd, args->valid, &args->stat, + args->xdata); + break; + case GF_FOP_READDIRP: + CLIENT4_PRE_FOP (readdirp, this, + &this_req->compound_req_v2_u.compound_readdirp_req, + op_errno, out, + args->fd, args->size, args->offset, + args->xdata); + if (!local->fd) + local->fd = fd_ref (args->fd); + break; + case GF_FOP_FREMOVEXATTR: + CLIENT4_PRE_FOP (fremovexattr, this, + &this_req->compound_req_v2_u.compound_fremovexattr_req, + op_errno, out, + args->fd, args->name, args->xdata); + break; + case GF_FOP_FALLOCATE: + CLIENT4_PRE_FOP (fallocate, this, + &this_req->compound_req_v2_u.compound_fallocate_req, + op_errno, out, + args->fd, args->flags, args->offset, + args->size, args->xdata); + break; + case GF_FOP_DISCARD: + CLIENT4_PRE_FOP (discard, this, + &this_req->compound_req_v2_u.compound_discard_req, + op_errno, out, + args->fd, args->offset, args->size, + args->xdata); + break; + case GF_FOP_ZEROFILL: + CLIENT4_PRE_FOP (zerofill, this, + &this_req->compound_req_v2_u.compound_zerofill_req, + op_errno, out, + args->fd, args->offset, args->size, + args->xdata); + break; + case GF_FOP_IPC: + CLIENT4_PRE_FOP (ipc, this, + &this_req->compound_req_v2_u.compound_ipc_req, + op_errno, out, + args->cmd, args->xdata); + break; + case GF_FOP_SEEK: + CLIENT4_PRE_FOP (seek, this, + &this_req->compound_req_v2_u.compound_seek_req, + op_errno, out, + args->fd, args->offset, args->what, + args->xdata); + break; + case GF_FOP_LEASE: + CLIENT4_PRE_FOP (lease, this, + &this_req->compound_req_v2_u.compound_lease_req, + op_errno, out, &args->loc, &args->lease, + args->xdata); + break; + default: + return ENOTSUP; + } + return 0; +out: + return op_errno; +} + +void +compound_request_cleanup_v2 (gfx_compound_req *req) +{ + int i = 0; + int length = req->compound_req_array.compound_req_array_len; + compound_req_v2 *curr_req = NULL; + + if (!req->compound_req_array.compound_req_array_val) + return; + + for (i = 0; i < length; i++) { + curr_req = &req->compound_req_array.compound_req_array_val[i]; + + switch (curr_req->fop_enum) { + case GF_FOP_STAT: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, stat); + break; + case GF_FOP_READLINK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, readlink); + break; + case GF_FOP_MKNOD: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, mknod); + break; + case GF_FOP_MKDIR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, mkdir); + break; + case GF_FOP_UNLINK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, unlink); + break; + case GF_FOP_RMDIR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, rmdir); + break; + case GF_FOP_SYMLINK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, symlink); + break; + case GF_FOP_RENAME: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, rename); + break; + case GF_FOP_LINK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, link); + break; + case GF_FOP_TRUNCATE: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, truncate); + break; + case GF_FOP_OPEN: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, open); + break; + case GF_FOP_READ: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, read); + break; + case GF_FOP_WRITE: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, write); + break; + case GF_FOP_STATFS: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, statfs); + break; + case GF_FOP_FLUSH: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, flush); + break; + case GF_FOP_FSYNC: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fsync); + break; + case GF_FOP_SETXATTR: + { + gfx_setxattr_req *args = &CPD4_REQ_FIELD (curr_req, + setxattr); + GF_FREE (args->dict.pairs.pairs_val); + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, setxattr); + break; + } + case GF_FOP_GETXATTR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, getxattr); + break; + case GF_FOP_REMOVEXATTR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, removexattr); + break; + case GF_FOP_OPENDIR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, opendir); + break; + case GF_FOP_FSYNCDIR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fsyncdir); + break; + case GF_FOP_ACCESS: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, access); + break; + case GF_FOP_CREATE: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, create); + break; + case GF_FOP_FTRUNCATE: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, ftruncate); + break; + case GF_FOP_FSTAT: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fstat); + break; + case GF_FOP_LK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, lk); + break; + case GF_FOP_LOOKUP: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, lookup); + break; + case GF_FOP_READDIR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, readdir); + break; + case GF_FOP_INODELK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, inodelk); + break; + case GF_FOP_FINODELK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, finodelk); + break; + case GF_FOP_ENTRYLK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, entrylk); + break; + case GF_FOP_FENTRYLK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fentrylk); + break; + case GF_FOP_XATTROP: + { + gfx_xattrop_req *args = &CPD4_REQ_FIELD (curr_req, + xattrop); + GF_FREE (args->dict.pairs.pairs_val); + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, xattrop); + break; + } + case GF_FOP_FXATTROP: + { + gfx_fxattrop_req *args = &CPD4_REQ_FIELD (curr_req, + fxattrop); + GF_FREE (args->dict.pairs.pairs_val); + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fxattrop); + break; + } + case GF_FOP_FGETXATTR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fgetxattr); + break; + case GF_FOP_FSETXATTR: + { + gfx_fsetxattr_req *args = &CPD4_REQ_FIELD(curr_req, + fsetxattr); + GF_FREE (args->dict.pairs.pairs_val); + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fsetxattr); + break; + } + case GF_FOP_RCHECKSUM: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, rchecksum); + break; + case GF_FOP_SETATTR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, setattr); + break; + case GF_FOP_FSETATTR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fsetattr); + break; + case GF_FOP_READDIRP: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, readdirp); + break; + case GF_FOP_FREMOVEXATTR: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fremovexattr); + break; + case GF_FOP_FALLOCATE: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, fallocate); + break; + case GF_FOP_DISCARD: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, discard); + break; + case GF_FOP_ZEROFILL: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, zerofill); + break; + case GF_FOP_IPC: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, ipc); + break; + case GF_FOP_SEEK: + CLIENT4_COMPOUND_FOP_CLEANUP (curr_req, seek); + break; + default: + break; + } + } + + GF_FREE (req->compound_req_array.compound_req_array_val); + return; +} + + +void +client_compound_rsp_cleanup_v2 (gfx_compound_rsp *rsp, int len) +{ + int i = 0; + compound_rsp_v2 *this_rsp = NULL; + + for (i = 0; i < len; i++) { + this_rsp = &rsp->compound_rsp_array.compound_rsp_array_val[i]; + switch (this_rsp->fop_enum) { + /* fops that need extra cleanup */ + case GF_FOP_LK: + { + gfx_lk_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, lk); + free (tmp_rsp->flock.lk_owner.lk_owner_val); + break; + } + case GF_FOP_READLINK: + { + gfx_readlink_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, + readlink); + free (tmp_rsp->path); + break; + } + case GF_FOP_READDIR: + { + + gfx_readdir_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, + readdir); + clnt_readdir_rsp_cleanup_v2 (tmp_rsp); + break; + } + case GF_FOP_READDIRP: + { + + gfx_readdirp_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, + readdirp); + clnt_readdirp_rsp_cleanup_v2 (tmp_rsp); + break; + } + case GF_FOP_RCHECKSUM: + { + + gfx_rchecksum_rsp *rck = &CPD4_RSP_FIELD(this_rsp, + rchecksum); + if (rck->strong_checksum.strong_checksum_val) { + free (rck->strong_checksum.strong_checksum_val); + } + break; + } + default: + break; + } + } + return; +} + +int +client_process_response_v2 (call_frame_t *frame, xlator_t *this, + struct rpc_req *req, gfx_compound_rsp *rsp, + compound_args_cbk_t *args_cbk, + int index) +{ + int ret = 0; + dict_t *xdata = NULL; + dict_t *xattr = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + gf_dirent_t entries; + default_args_cbk_t *this_args_cbk = &args_cbk->rsp_list[index]; + clnt_local_t *local = frame->local; + compound_rsp_v2 *this_rsp = NULL; + compound_args_t *args = local->compound_args; + + this_rsp = &rsp->compound_rsp_array.compound_rsp_array_val[index]; + args_cbk->enum_list[index] = this_rsp->fop_enum; + + INIT_LIST_HEAD (&entries.list); + + switch (args_cbk->enum_list[index]) { + + case GF_FOP_STAT: + case GF_FOP_FSTAT: + { + gfx_common_iatt_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_stat_rsp; + + client_post_common_iatt (this, tmp_rsp, &this_args_cbk->stat, &xdata); + + CLIENT4_POST_FOP_TYPE (stat, common_iatt, this_rsp, this_args_cbk, + &this_args_cbk->stat, xdata); + break; + } + case GF_FOP_READLINK: + { + gfx_readlink_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_readlink_rsp; + + gfx_stat_to_iattx (&tmp_rsp->buf, &this_args_cbk->stat); + xdr_to_dict (&tmp_rsp->xdata, &xdata); + + CLIENT4_POST_FOP_TYPE (readlink, readlink, this_rsp, this_args_cbk, + tmp_rsp->path, &this_args_cbk->stat, + xdata); + break; + } + case GF_FOP_MKDIR: + case GF_FOP_MKNOD: + case GF_FOP_SYMLINK: + case GF_FOP_LINK: + { + gfx_common_3iatt_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_mknod_rsp; + + client_post_common_3iatt (this, tmp_rsp, &this_args_cbk->stat, + &this_args_cbk->preparent, + &this_args_cbk->postparent, &xdata); + CLIENT4_POST_FOP_TYPE (mknod, common_3iatt, this_rsp, this_args_cbk, + local->loc.inode, &this_args_cbk->stat, + &this_args_cbk->preparent, + &this_args_cbk->postparent, xdata); + break; + } + case GF_FOP_UNLINK: + case GF_FOP_RMDIR: + { + gfx_common_2iatt_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_unlink_rsp; + + client_post_common_2iatt (this, tmp_rsp, &this_args_cbk->preparent, + &this_args_cbk->postparent, &xdata); + CLIENT4_POST_FOP_TYPE (unlink, common_2iatt, this_rsp, this_args_cbk, + &this_args_cbk->preparent, + &this_args_cbk->postparent, xdata); + break; + } + case GF_FOP_RENAME: + { + gfx_rename_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_rename_rsp; + + client_post_rename_v2 (this, tmp_rsp, &this_args_cbk->stat, + &this_args_cbk->preparent, + &this_args_cbk->postparent, + &this_args_cbk->preparent2, + &this_args_cbk->postparent2, &xdata); + CLIENT4_POST_FOP_TYPE (rename, rename, this_rsp, this_args_cbk, + &this_args_cbk->stat, + &this_args_cbk->preparent, + &this_args_cbk->postparent, + &this_args_cbk->preparent2, + &this_args_cbk->postparent2, xdata); + break; + } + case GF_FOP_WRITE: + case GF_FOP_TRUNCATE: + case GF_FOP_FTRUNCATE: + case GF_FOP_FSYNC: + case GF_FOP_ZEROFILL: + case GF_FOP_DISCARD: + case GF_FOP_FALLOCATE: + case GF_FOP_FSETATTR: + case GF_FOP_SETATTR: + { + gfx_common_2iatt_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_truncate_rsp; + + client_post_common_2iatt (this, tmp_rsp, &this_args_cbk->prestat, + &this_args_cbk->poststat, &xdata); + CLIENT4_POST_FOP_TYPE (truncate, common_2iatt, this_rsp, this_args_cbk, + &this_args_cbk->prestat, + &this_args_cbk->poststat, xdata); + break; + } + case GF_FOP_OPEN: + { + gfx_open_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_open_rsp; + + xdr_to_dict (&tmp_rsp->xdata, &xdata); + CLIENT4_POST_FOP_TYPE (open, open, this_rsp, this_args_cbk, local->fd, + xdata); + if (-1 != this_args_cbk->op_ret) + ret = client_add_fd_to_saved_fds (this, local->fd, + &local->loc, + args->req_list[index].flags, + tmp_rsp->fd, + 0); + break; + } + case GF_FOP_READ: + { + gfx_read_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_read_rsp; + + client_post_readv_v2 (this, tmp_rsp, &this_args_cbk->iobref, + req->rsp_iobref, &this_args_cbk->stat, + vector, &req->rsp[1], &this_args_cbk->count, + &xdata); + + /* Each read should be given read response that only + * corresponds to its request. + * Modify the iovecs accordingly. + * After each read, store the length of data already read + * so that the next ones can continue from there. + */ + if (local->read_length) { + vector[0].iov_base += local->read_length; + local->read_length += tmp_rsp->op_ret; + } else { + local->read_length = tmp_rsp->op_ret; + } + + args_readv_cbk_store (this_args_cbk, tmp_rsp->op_ret, + gf_error_to_errno (tmp_rsp->op_errno), + vector, this_args_cbk->count, + &this_args_cbk->stat, + this_args_cbk->iobref, xdata); + + if (tmp_rsp->op_ret >= 0) + if (local->attempt_reopen) + client_attempt_reopen (local->fd, this); + + break; + } + case GF_FOP_STATFS: + { + gfx_statfs_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_statfs_rsp; + + gf_statfs_to_statfs (&tmp_rsp->statfs, &this_args_cbk->statvfs); + xdr_to_dict (&tmp_rsp->xdata, &xdata); + + CLIENT4_POST_FOP_TYPE (statfs, statfs, this_rsp, this_args_cbk, + &this_args_cbk->statvfs, xdata); + break; + } + case GF_FOP_FLUSH: + { + gfx_common_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_flush_rsp; + + xdr_to_dict (&tmp_rsp->xdata, &xdata); + + CLIENT4_POST_FOP (flush, this_rsp, this_args_cbk, xdata); + if (this_args_cbk->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_msg_trace (this->name, 0, + "deleting locks of owner (%s) returned %d", + lkowner_utoa (&local->owner), ret); + } + break; + } + case GF_FOP_FSYNCDIR: + case GF_FOP_ACCESS: + case GF_FOP_REMOVEXATTR: + case GF_FOP_FREMOVEXATTR: + case GF_FOP_FSETXATTR: + case GF_FOP_SETXATTR: + case GF_FOP_INODELK: + case GF_FOP_FINODELK: + case GF_FOP_ENTRYLK: + case GF_FOP_FENTRYLK: + case GF_FOP_IPC: + { + gfx_common_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_setxattr_rsp; + + xdr_to_dict (&tmp_rsp->xdata, &xdata); + + CLIENT4_POST_FOP (setxattr, this_rsp, this_args_cbk, xdata); + break; + } + case GF_FOP_GETXATTR: + case GF_FOP_FGETXATTR: + case GF_FOP_XATTROP: + case GF_FOP_FXATTROP: + { + gfx_common_dict_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_getxattr_rsp; + + client_post_common_dict (this, tmp_rsp, &xattr, &xdata); + + CLIENT4_POST_FOP_TYPE (getxattr, common_dict, this_rsp, this_args_cbk, xattr, + xdata); + break; + } + case GF_FOP_OPENDIR: + { + gfx_open_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_opendir_rsp; + + xdr_to_dict (&tmp_rsp->xdata, &xdata); + + CLIENT4_POST_FOP_TYPE (opendir, open, this_rsp, this_args_cbk, + local->fd, xdata); + if (-1 != this_args_cbk->op_ret) + ret = client_add_fd_to_saved_fds (this, local->fd, + &local->loc, + args->req_list[index].flags, + tmp_rsp->fd, 0); + break; + } + case GF_FOP_CREATE: + { + gfx_create_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_create_rsp; + + client_post_create_v2 (this, tmp_rsp, &this_args_cbk->stat, + &this_args_cbk->preparent, + &this_args_cbk->postparent, local, &xdata); + + CLIENT4_POST_FOP_TYPE (create, create, this_rsp, this_args_cbk, + local->fd, local->loc.inode, + &this_args_cbk->stat, + &this_args_cbk->preparent, + &this_args_cbk->postparent, xdata); + if (-1 != this_args_cbk->op_ret) + ret = client_add_fd_to_saved_fds (this, local->fd, + &local->loc, + args->req_list[index].flags, + tmp_rsp->fd, 0); + break; + } + case GF_FOP_LK: + { + gfx_lk_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_lk_rsp; + + client_post_lk_v2 (this, tmp_rsp, &this_args_cbk->lock, &xdata); + + CLIENT4_POST_FOP_TYPE (lk, lk, this_rsp, this_args_cbk, + &this_args_cbk->lock, xdata); + break; + } + case GF_FOP_LOOKUP: + { + gfx_common_2iatt_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_lookup_rsp; + + client_post_common_2iatt (this, tmp_rsp, &this_args_cbk->stat, + &this_args_cbk->postparent, &xdata); + CLIENT4_POST_FOP_TYPE (lookup, common_2iatt, this_rsp, this_args_cbk, + local->loc.inode, &this_args_cbk->stat, + xdata, &this_args_cbk->postparent); + break; + } + case GF_FOP_READDIR: + { + gfx_readdir_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_readdir_rsp; + + client_post_readdir_v2 (this, tmp_rsp, &entries, &xdata); + + CLIENT4_POST_FOP_TYPE (readdir, readdir, this_rsp, this_args_cbk, + &entries, xdata); + break; + } + case GF_FOP_RCHECKSUM: + { + gfx_rchecksum_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_rchecksum_rsp; + + xdr_to_dict (&tmp_rsp->xdata, &xdata); + + CLIENT4_POST_FOP_TYPE (rchecksum, rchecksum, this_rsp, this_args_cbk, + tmp_rsp->weak_checksum, + (uint8_t *)tmp_rsp->strong_checksum.strong_checksum_val, + xdata); + break; + } + case GF_FOP_READDIRP: + { + gfx_readdirp_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_readdirp_rsp; + + client_post_readdirp_v2 (this, tmp_rsp, local->fd, &entries, + &xdata); + + CLIENT4_POST_FOP_TYPE (readdirp, readdirp, this_rsp, this_args_cbk, + &entries, xdata); + break; + } + case GF_FOP_SEEK: + { + gfx_seek_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_seek_rsp; + + xdr_to_dict (&tmp_rsp->xdata, &xdata); + + CLIENT4_POST_FOP_TYPE (seek, seek, this_rsp, this_args_cbk, + tmp_rsp->offset, xdata); + break; + } + case GF_FOP_LEASE: + { + gfx_lease_rsp *tmp_rsp = NULL; + tmp_rsp = &this_rsp->compound_rsp_v2_u.compound_lease_rsp; + + client_post_lease_v2 (this, tmp_rsp, &this_args_cbk->lease, + &xdata); + + CLIENT4_POST_FOP_TYPE (lease, lease, this_rsp, this_args_cbk, + &this_args_cbk->lease, xdata); + break; + } + default: + return -ENOTSUP; + } + + if (xdata) + dict_unref (xdata); + if (xattr) + dict_unref (xattr); + gf_dirent_free (&entries); + return 0; +} diff --git a/xlators/protocol/client/src/client-rpc-fops.c b/xlators/protocol/client/src/client-rpc-fops.c index c8d1cc14f77..ead439eab7e 100644 --- a/xlators/protocol/client/src/client-rpc-fops.c +++ b/xlators/protocol/client/src/client-rpc-fops.c @@ -3150,102 +3150,6 @@ out: return 0; } -int32_t -client3_3_namelink_cbk (struct rpc_req *req, - struct iovec *iov, int count, void *myframe) -{ - int32_t ret = 0; - xlator_t *this = NULL; - struct iatt prebuf = {0,}; - struct iatt postbuf = {0,}; - dict_t *xdata = NULL; - call_frame_t *frame = NULL; - gfs4_namelink_rsp rsp = {0,}; - - this = THIS; - frame = myframe; - - if (req->rpc_status == -1) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs4_namelink_rsp); - if (ret < 0) { - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (rsp.op_ret != -1) { - gf_stat_to_iatt (&rsp.preparent, &prebuf); - gf_stat_to_iatt (&rsp.postparent, &postbuf); - } - - GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), - (rsp.xdata.xdata_len), ret, - rsp.op_errno, out); - - out: - CLIENT_STACK_UNWIND (namelink, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), - &prebuf, &postbuf, xdata); - free (rsp.xdata.xdata_val); - if (xdata) - dict_unref (xdata); - return 0; -} - -int32_t -client3_3_icreate_cbk (struct rpc_req *req, - struct iovec *iov, int count, void *myframe) -{ - int32_t ret = 0; - inode_t *inode = NULL; - clnt_local_t *local = NULL; - xlator_t *this = NULL; - struct iatt stbuf = {0,}; - dict_t *xdata = NULL; - call_frame_t *frame = NULL; - gfs4_icreate_rsp rsp = {0,}; - - this = THIS; - frame = myframe; - local = frame->local; - - inode = local->loc.inode; - - if (req->rpc_status == -1) { - rsp.op_ret = -1; - rsp.op_errno = ENOTCONN; - goto out; - } - - ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfs4_icreate_rsp); - if (ret < 0) { - rsp.op_ret = -1; - rsp.op_errno = EINVAL; - goto out; - } - - if (rsp.op_ret != -1) - gf_stat_to_iatt (&rsp.stat, &stbuf); - - GF_PROTOCOL_DICT_UNSERIALIZE (this, xdata, (rsp.xdata.xdata_val), - (rsp.xdata.xdata_len), ret, - rsp.op_errno, out); - - out: - CLIENT_STACK_UNWIND (icreate, frame, rsp.op_ret, - gf_error_to_errno (rsp.op_errno), - inode, &stbuf, xdata); - free (rsp.xdata.xdata_val); - if (xdata) - dict_unref (xdata); - return 0; -} - int client_fdctx_destroy (xlator_t *this, clnt_fd_ctx_t *fdctx) { @@ -6345,197 +6249,6 @@ unwind: return 0; } -int32_t -client3_3_namelink (call_frame_t *frame, xlator_t *this, void *data) -{ - int32_t ret = 0; - int32_t op_errno = EINVAL; - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - gfs4_namelink_req req = {{0,},}; - - GF_ASSERT (frame); - - args = data; - conf = this->private; - - if (!(args->loc && args->loc->parent)) - goto unwind; - - if (!gf_uuid_is_null (args->loc->parent->gfid)) - memcpy (req.pargfid, args->loc->parent->gfid, sizeof (uuid_t)); - else - memcpy (req.pargfid, args->loc->pargfid, sizeof (uuid_t)); - - GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, - !gf_uuid_is_null (*((uuid_t *)req.pargfid)), - unwind, op_errno, EINVAL); - - req.bname = (char *)args->loc->name; - - GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), - req.xdata.xdata_len, op_errno, unwind); - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_NAMELINK, client3_3_namelink_cbk, - NULL, NULL, 0, NULL, 0, NULL, - (xdrproc_t)xdr_gfs4_namelink_req); - if (ret) { - gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, - "failed to send the fop"); - } - - GF_FREE (req.xdata.xdata_val); - return 0; - - unwind: - CLIENT_STACK_UNWIND (namelink, frame, -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -client3_3_icreate (call_frame_t *frame, xlator_t *this, void *data) -{ - int32_t ret = 0; - int32_t op_errno = EINVAL; - clnt_conf_t *conf = NULL; - clnt_args_t *args = NULL; - clnt_local_t *local = NULL; - gfs4_icreate_req req = {{0,},}; - - GF_ASSERT (frame); - - args = data; - conf = this->private; - - if (!(args->loc && args->loc->inode)) - goto unwind; - - local = mem_get0 (this->local_pool); - if (!local) { - op_errno = ENOMEM; - goto unwind; - } - frame->local = local; - - loc_copy (&local->loc, args->loc); - - req.mode = args->mode; - memcpy (req.gfid, args->loc->gfid, sizeof (uuid_t)); - - op_errno = ESTALE; - GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), - req.xdata.xdata_len, op_errno, unwind); - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_ICREATE, client3_3_icreate_cbk, - NULL, NULL, 0, NULL, 0, NULL, - (xdrproc_t) xdr_gfs4_icreate_req); - if (ret) - goto free_reqdata; - GF_FREE (req.xdata.xdata_val); - return 0; - - free_reqdata: - GF_FREE (req.xdata.xdata_val); - unwind: - CLIENT_STACK_UNWIND (icreate, frame, - -1, op_errno, NULL, NULL, NULL); - return 0; -} - -int32_t -client4_0_fsetattr (call_frame_t *frame, xlator_t *this, void *data) -{ - clnt_args_t *args = NULL; - int64_t remote_fd = -1; - clnt_conf_t *conf = NULL; - gfs3_fsetattr_req_v2 req = {{0},}; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - CLIENT_GET_REMOTE_FD(this, args->fd, DEFAULT_REMOTE_FD, - remote_fd, op_errno, unwind); - - req.fd = remote_fd; - req.valid = args->valid; - gf_stat_from_iatt (&req.stbuf, args->stbuf); - memcpy (req.gfid, args->fd->inode->gfid, 16); - - GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), - req.xdata.xdata_len, op_errno, unwind); - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_FSETATTR, - client3_3_fsetattr_cbk, NULL, - NULL, 0, NULL, 0, - NULL, (xdrproc_t)xdr_gfs3_fsetattr_req_v2); - if (ret) { - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); - } - - GF_FREE (req.xdata.xdata_val); - - return 0; -unwind: - CLIENT_STACK_UNWIND (fsetattr, frame, -1, op_errno, NULL, NULL, NULL); - GF_FREE (req.xdata.xdata_val); - - return 0; -} - -int32_t -client4_0_rchecksum (call_frame_t *frame, xlator_t *this, - void *data) -{ - clnt_args_t *args = NULL; - int64_t remote_fd = -1; - clnt_conf_t *conf = NULL; - gfs3_rchecksum_req_v2 req = {{0},}; - int op_errno = ESTALE; - int ret = 0; - - if (!frame || !this || !data) - goto unwind; - - args = data; - conf = this->private; - - CLIENT_GET_REMOTE_FD(this, args->fd, DEFAULT_REMOTE_FD, - remote_fd, op_errno, unwind); - - req.len = args->len; - req.offset = args->offset; - req.fd = remote_fd; - memcpy (req.gfid, args->fd->inode->gfid, 16); - - GF_PROTOCOL_DICT_SERIALIZE (this, args->xdata, (&req.xdata.xdata_val), - req.xdata.xdata_len, op_errno, unwind); - - ret = client_submit_request (this, &req, frame, conf->fops, - GFS3_OP_RCHECKSUM, - client3_3_rchecksum_cbk, NULL, - NULL, 0, NULL, - 0, NULL, - (xdrproc_t)xdr_gfs3_rchecksum_req_v2); - if (ret) { - gf_log (this->name, GF_LOG_WARNING, "failed to send the fop"); - } - - GF_FREE (req.xdata.xdata_val); - - return 0; -unwind: - CLIENT_STACK_UNWIND (rchecksum, frame, -1, op_errno, 0, NULL, NULL); - GF_FREE (req.xdata.xdata_val); - - return 0; -} /* Table Specific to FOPS */ rpc_clnt_procedure_t clnt3_3_fop_actors[GF_FOP_MAXVALUE] = { @@ -6650,8 +6363,6 @@ char *clnt3_3_fop_names[GFS3_OP_MAXVALUE] = { [GFS3_OP_GETACTIVELK] = "GETACTIVELK", [GFS3_OP_SETACTIVELK] = "SETACTIVELK", [GFS3_OP_COMPOUND] = "COMPOUND", - [GFS3_OP_ICREATE] = "ICREATE", - [GFS3_OP_NAMELINK] = "NAMELINK", }; rpc_clnt_prog_t clnt3_3_fop_prog = { @@ -6701,9 +6412,9 @@ rpc_clnt_procedure_t clnt4_0_fop_actors[GF_FOP_MAXVALUE] = { [GF_FOP_FXATTROP] = { "FXATTROP", client3_3_fxattrop }, [GF_FOP_FGETXATTR] = { "FGETXATTR", client3_3_fgetxattr }, [GF_FOP_FSETXATTR] = { "FSETXATTR", client3_3_fsetxattr }, - [GF_FOP_RCHECKSUM] = { "RCHECKSUM", client4_0_rchecksum }, + [GF_FOP_RCHECKSUM] = { "RCHECKSUM", client3_3_rchecksum }, [GF_FOP_SETATTR] = { "SETATTR", client3_3_setattr }, - [GF_FOP_FSETATTR] = { "FSETATTR", client4_0_fsetattr }, + [GF_FOP_FSETATTR] = { "FSETATTR", client3_3_fsetattr }, [GF_FOP_READDIRP] = { "READDIRP", client3_3_readdirp }, [GF_FOP_FALLOCATE] = { "FALLOCATE", client3_3_fallocate }, [GF_FOP_DISCARD] = { "DISCARD", client3_3_discard }, @@ -6718,8 +6429,6 @@ rpc_clnt_procedure_t clnt4_0_fop_actors[GF_FOP_MAXVALUE] = { [GF_FOP_GETACTIVELK] = { "GETACTIVELK", client3_3_getactivelk}, [GF_FOP_SETACTIVELK] = { "SETACTIVELK", client3_3_setactivelk}, [GF_FOP_COMPOUND] = { "COMPOUND", client3_3_compound }, - [GF_FOP_ICREATE] = { "ICREATE", client3_3_icreate}, - [GF_FOP_NAMELINK] = { "NAMELINK", client3_3_namelink}, }; diff --git a/xlators/protocol/client/src/client-rpc-fops_v2.c b/xlators/protocol/client/src/client-rpc-fops_v2.c new file mode 100644 index 00000000000..4a4df478a67 --- /dev/null +++ b/xlators/protocol/client/src/client-rpc-fops_v2.c @@ -0,0 +1,5952 @@ +/* + Copyright (c) 2008-2012 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#include "client.h" +#include "rpc-common-xdr.h" +#include "glusterfs4-xdr.h" +#include "glusterfs3.h" +#include "compat-errno.h" +#include "client-messages.h" +#include "defaults.h" +#include "client-common.h" +#include "compound-fop-utils.h" + +extern int32_t +client3_getspec (call_frame_t *frame, xlator_t *this, void *data); + +extern 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 +client4_0_symlink_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_3iatt_rsp rsp = {0,}; + call_frame_t *frame = NULL; + 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_gfx_common_3iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_3iatt (this, &rsp, &stbuf, &preparent, + &postparent, &xdata); + +out: + if (rsp.op_ret == -1) { + if (GF_IGNORE_IF_GSYNCD_SAFE_ERROR(frame, rsp.op_errno)) { + /* no need to print the gfid, because it will be null, + * since symlink operation failed. + */ + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed. Path: (%s to %s)", + local->loc.path, local->loc2.path); + } + } + + CLIENT_STACK_UNWIND (symlink, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), inode, &stbuf, + &preparent, &postparent, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client4_0_mknod_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_3iatt_rsp rsp = {0,}; + call_frame_t *frame = NULL; + 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_gfx_common_3iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_3iatt (this, &rsp, &stbuf, &preparent, &postparent, + &xdata); + +out: + if (rsp.op_ret == -1 && + GF_IGNORE_IF_GSYNCD_SAFE_ERROR(frame, rsp.op_errno)) { + gf_msg (this->name, fop_log_level (GF_FOP_MKNOD, + gf_error_to_errno (rsp.op_errno)), + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed. Path: %s", + local->loc.path); + } + + CLIENT_STACK_UNWIND (mknod, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), inode, + &stbuf, &preparent, &postparent, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_mkdir_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_3iatt_rsp rsp = {0,}; + call_frame_t *frame = NULL; + 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_gfx_common_3iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_3iatt (this, &rsp, &stbuf, &preparent, &postparent, + &xdata); + +out: + if (rsp.op_ret == -1 && + GF_IGNORE_IF_GSYNCD_SAFE_ERROR(frame, rsp.op_errno)) { + gf_msg (this->name, fop_log_level (GF_FOP_MKDIR, + gf_error_to_errno (rsp.op_errno)), + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed. Path: %s", + local->loc.path); + } + + CLIENT_STACK_UNWIND (mkdir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), inode, + &stbuf, &preparent, &postparent, xdata); + + + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_open_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + clnt_local_t *local = NULL; + call_frame_t *frame = NULL; + fd_t *fd = NULL; + int ret = 0; + gfx_open_rsp rsp = {0,}; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + + this = THIS; + + frame = myframe; + local = frame->local; + + 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_gfx_open_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + ret = client_add_fd_to_saved_fds (frame->this, fd, &local->loc, + local->flags, rsp.fd, 0); + if (ret) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + goto out; + } + } + + ret = xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, fop_log_level (GF_FOP_OPEN, + gf_error_to_errno (rsp.op_errno)), + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed. Path: %s (%s)", + local->loc.path, loc_gfid_utoa (&local->loc)); + } + + CLIENT_STACK_UNWIND (open, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), fd, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client4_0_stat_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_iatt_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_gfx_common_iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_iatt (this, &rsp, &iatt, &xdata); +out: + if (rsp.op_ret == -1) { + /* stale filehandles are possible during normal operations, no + * need to spam the logs with these */ + if (rsp.op_errno == ESTALE) { + gf_msg_debug (this->name, 0, + "remote operation failed: %s", + strerror (gf_error_to_errno + (rsp.op_errno))); + } else { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + } + + CLIENT_STACK_UNWIND (stat, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &iatt, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_readlink_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_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_gfx_readlink_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + gfx_stat_to_iattx (&rsp.buf, &iatt); + + ret = xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + if (gf_error_to_errno(rsp.op_errno) == ENOENT) { + gf_msg_debug (this->name, 0, "remote operation failed:" + " %s", strerror + (gf_error_to_errno (rsp.op_errno))); + } else { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "remote operation " + "failed"); + } + } + + 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' */ + free (rsp.path); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_unlink_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_common_2iatt_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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &preparent, &postparent, + &xdata); + +out: + if (rsp.op_ret == -1) { + if (gf_error_to_errno(rsp.op_errno) == ENOENT) { + gf_msg_debug (this->name, 0, "remote operation failed:" + " %s", strerror + (gf_error_to_errno (rsp.op_errno))); + } else { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "remote operation " + "failed"); + } + } + + CLIENT_STACK_UNWIND (unlink, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &preparent, + &postparent, xdata); + + + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_rmdir_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_2iatt_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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &preparent, &postparent, + &xdata); + +out: + if (rsp.op_ret == -1) { + if (GF_IGNORE_IF_GSYNCD_SAFE_ERROR(frame, rsp.op_errno)) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + } + CLIENT_STACK_UNWIND (rmdir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &preparent, + &postparent, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client4_0_truncate_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_2iatt_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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &prestat, &poststat, + &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (truncate, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client4_0_statfs_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_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_gfx_statfs_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "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); + } + ret = xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (statfs, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &statfs, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client4_0_writev_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_2iatt_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; + clnt_local_t *local = NULL; + + this = THIS; + + frame = myframe; + 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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &prestat, &poststat, &xdata); + if (ret < 0) + goto out; +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } else if (rsp.op_ret >= 0) { + if (local->attempt_reopen) + client_attempt_reopen (local->fd, this); + } + CLIENT_STACK_UNWIND (writev, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_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; + gfx_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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "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_msg_trace (this->name, 0, + "deleting locks of owner (%s) returned %d", + lkowner_utoa (&local->owner), ret); + } + + xdr_to_dict (&rsp.xdata, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, fop_log_level (GF_FOP_FLUSH, + gf_error_to_errno (rsp.op_errno)), + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (flush, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_fsync_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_2iatt_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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &prestat, &poststat, + &xdata); + if (ret < 0) + goto out; + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (fsync, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_setxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_common_rsp rsp = {0,}; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + int op_errno = EINVAL; + + 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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); + if (ret < 0) + goto out; + +out: + op_errno = gf_error_to_errno (rsp.op_errno); + if (rsp.op_ret == -1) { + if (op_errno == ENOTSUP) { + gf_msg_debug (this->name, 0, "remote operation failed:" + " %s", strerror (op_errno)); + } else { + gf_msg (this->name, GF_LOG_WARNING, op_errno, + PC_MSG_REMOTE_OP_FAILED, "remote operation " + "failed"); + } + } + + CLIENT_STACK_UNWIND (setxattr, frame, rsp.op_ret, op_errno, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_getxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_dict_rsp rsp = {0,}; + call_frame_t *frame = NULL; + dict_t *dict = NULL; + int op_errno = EINVAL; + 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_gfx_common_dict_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + op_errno = gf_error_to_errno (rsp.op_errno); + ret = client_post_common_dict (this, &rsp, &dict, &xdata); + if (ret) { + op_errno = -ret; + goto out; + } + +out: + if (rsp.op_ret == -1) { + if ((op_errno == ENOTSUP) || (op_errno == ENODATA) || + (op_errno == ESTALE) || (op_errno == ENOENT)) { + gf_msg_debug (this->name, 0, + "remote operation failed: %s. Path: %s " + "(%s). Key: %s", strerror (op_errno), + local->loc.path, + loc_gfid_utoa (&local->loc), + (local->name) ? local->name : "(null)"); + } else { + gf_msg (this->name, GF_LOG_WARNING, op_errno, + PC_MSG_REMOTE_OP_FAILED, "remote operation " + "failed. Path: %s (%s). Key: %s", + local->loc.path, + loc_gfid_utoa (&local->loc), + (local->name) ? local->name : "(null)"); + } + } + + CLIENT_STACK_UNWIND (getxattr, frame, rsp.op_ret, op_errno, dict, xdata); + + if (xdata) + dict_unref (xdata); + + if (dict) + dict_unref (dict); + + return 0; +} + +int +client4_0_fgetxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_dict_rsp rsp = {0,}; + call_frame_t *frame = NULL; + dict_t *dict = NULL; + int ret = 0; + int op_errno = EINVAL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + op_errno = ENOTCONN; + goto out; + } + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfx_common_dict_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + op_errno = gf_error_to_errno (rsp.op_errno); + ret = client_post_common_dict (this, &rsp, &dict, &xdata); + if (ret) { + op_errno = -ret; + goto out; + } +out: + if (rsp.op_ret == -1) { + if ((op_errno == ENOTSUP) || (op_errno == ERANGE) || + (op_errno == ENODATA) || (op_errno == ENOENT)) { + gf_msg_debug (this->name, 0, + "remote operation failed: %s", + strerror (op_errno)); + } else { + gf_msg (this->name, GF_LOG_WARNING, op_errno, + PC_MSG_REMOTE_OP_FAILED, "remote operation " + "failed"); + } + } + + CLIENT_STACK_UNWIND (fgetxattr, frame, rsp.op_ret, op_errno, dict, xdata); + + if (xdata) + dict_unref (xdata); + + if (dict) + dict_unref (dict); + + return 0; +} + +int +client4_0_removexattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_common_rsp rsp = {0,}; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + gf_loglevel_t loglevel = GF_LOG_NONE; + + 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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + if ((ENODATA == rsp.op_errno) || (ENOATTR == rsp.op_errno)) + loglevel = GF_LOG_DEBUG; + else + loglevel = GF_LOG_WARNING; + + gf_msg (this->name, loglevel, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + + CLIENT_STACK_UNWIND (removexattr, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_fremovexattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (fremovexattr, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_fsyncdir_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (fsyncdir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_access_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (access, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client4_0_ftruncate_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_2iatt_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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &prestat, &poststat, + &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (ftruncate, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_fstat_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_iatt_rsp rsp = {0,}; + call_frame_t *frame = NULL; + struct iatt stat = {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_gfx_common_iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_iatt (this, &rsp, &stat, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (fstat, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &stat, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client4_0_inodelk_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, fop_log_level (GF_FOP_INODELK, + gf_error_to_errno (rsp.op_errno)), + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "remote operation failed"); + } + CLIENT_STACK_UNWIND (inodelk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_finodelk_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_common_rsp rsp = {0,}; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + clnt_local_t *local = NULL; + + frame = myframe; + this = frame->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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, fop_log_level (GF_FOP_FINODELK, + gf_error_to_errno (rsp.op_errno)), + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "remote operation failed"); + } else if (rsp.op_ret == 0) { + if (local->attempt_reopen) + client_attempt_reopen (local->fd, this); + } + CLIENT_STACK_UNWIND (finodelk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_entrylk_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, fop_log_level (GF_FOP_ENTRYLK, + gf_error_to_errno (rsp.op_errno)), + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "remote operation failed"); + } + + CLIENT_STACK_UNWIND (entrylk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_fentrylk_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); + +out: + if ((rsp.op_ret == -1) && + (EAGAIN != gf_error_to_errno (rsp.op_errno))) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + + CLIENT_STACK_UNWIND (fentrylk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_xattrop_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + dict_t *dict = NULL; + gfx_common_dict_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_gfx_common_dict_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + op_errno = rsp.op_errno; + ret = client_post_common_dict (this, &rsp, &dict, &xdata); + if (ret) { + op_errno = -ret; + goto out; + } +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, fop_log_level (GF_FOP_XATTROP, op_errno), + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "remote operation failed. " + "Path: %s (%s)", + local->loc.path, loc_gfid_utoa (&local->loc)); + } + + CLIENT_STACK_UNWIND (xattrop, frame, rsp.op_ret, + gf_error_to_errno (op_errno), dict, xdata); + + if (xdata) + dict_unref (xdata); + + if (dict) + dict_unref (dict); + + return 0; +} + +int +client4_0_fxattrop_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + dict_t *dict = NULL; + dict_t *xdata = NULL; + gfx_common_dict_rsp rsp = {0,}; + int ret = 0; + int op_errno = 0; + clnt_local_t *local = NULL; + xlator_t *this = 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_gfx_common_dict_rsp); + if (ret < 0) { + rsp.op_ret = -1; + op_errno = EINVAL; + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + goto out; + } + op_errno = rsp.op_errno; + ret = client_post_common_dict (this, &rsp, &dict, &xdata); + if (ret) { + rsp.op_ret = -1; + op_errno = -ret; + goto out; + } +out: + + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } else if (rsp.op_ret == 0) { + if (local->attempt_reopen) + client_attempt_reopen (local->fd, this); + } + CLIENT_STACK_UNWIND (fxattrop, frame, rsp.op_ret, + gf_error_to_errno (op_errno), dict, xdata); + if (xdata) + dict_unref (xdata); + + if (dict) + dict_unref (dict); + + return 0; +} + +int +client4_0_fsetxattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_common_rsp rsp = {0,}; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + int op_errno = EINVAL; + + 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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); + +out: + op_errno = gf_error_to_errno (rsp.op_errno); + if (rsp.op_ret == -1) { + if (op_errno == ENOTSUP) { + gf_msg_debug (this->name, 0, "remote operation failed:" + " %s", strerror (op_errno)); + } else { + gf_msg (this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_REMOTE_OP_FAILED, "remote operation " + "failed"); + } + } + + CLIENT_STACK_UNWIND (fsetxattr, frame, rsp.op_ret, op_errno, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_fallocate_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_common_2iatt_rsp rsp = {0,}; + 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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &prestat, &poststat, &xdata); + if (ret < 0) + goto out; + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (fallocate, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_discard_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_2iatt_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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &prestat, &poststat, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (discard, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_zerofill_cbk(struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_common_2iatt_rsp rsp = {0,}; + 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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &prestat, &poststat, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (zerofill, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_ipc_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (ipc, frame, + rsp.op_ret, gf_error_to_errno (rsp.op_errno), + xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client4_0_seek_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + struct gfx_seek_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_gfx_seek_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (seek, frame, + rsp.op_ret, gf_error_to_errno (rsp.op_errno), + rsp.offset, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_setattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_2iatt_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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &prestat, &poststat, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (setattr, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_fsetattr_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_2iatt_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_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_2iatt (this, &rsp, &prestat, &poststat, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (fsetattr, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &prestat, + &poststat, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_create_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + fd_t *fd = NULL; + inode_t *inode = NULL; + struct iatt stbuf = {0, }; + struct iatt preparent = {0, }; + struct iatt postparent = {0, }; + int32_t ret = -1; + clnt_local_t *local = NULL; + gfx_create_rsp rsp = {0,}; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + fd = local->fd; + 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_gfx_create_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + ret = client_post_create_v2 (this, &rsp, &stbuf, + &preparent, &postparent, + local, &xdata); + if (ret < 0) + goto out; + ret = client_add_fd_to_saved_fds (frame->this, fd, &local->loc, + local->flags, rsp.fd, 0); + if (ret) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + goto out; + } + } + + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed. Path: %s", + local->loc.path); + } + + CLIENT_STACK_UNWIND (create, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), fd, inode, + &stbuf, &preparent, &postparent, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_lease_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + struct gf_lease lease = {0,}; + gfx_lease_rsp rsp = {0,}; + int ret = 0; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + + if (-1 == req->rpc_status) { + gf_msg (this->name, GF_LOG_ERROR, ENOTCONN, + PC_MSG_REMOTE_OP_FAILED, "Lease fop failed"); + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfx_lease_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_lease_v2 (this, &rsp, &lease, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + + CLIENT_STACK_UNWIND (lease, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &lease, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_lk_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + struct gf_flock lock = {0,}; + gfx_lk_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_gfx_lk_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret >= 0) { + ret = client_post_lk_v2 (this, &rsp, &lock, &xdata); + if (ret < 0) + goto out; + } + + /* Save the lock to the client lock cache to be able + to recover in the case of server reboot.*/ + /* + temporarily + if (local->cmd == F_SETLK || local->cmd == F_SETLKW) { + ret = client_add_lock_for_recovery (local->fd, &lock, + local->owner, local->cmd); + if (ret < 0) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + } + } + */ + +out: + if ((rsp.op_ret == -1) && + (EAGAIN != gf_error_to_errno (rsp.op_errno))) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + + CLIENT_STACK_UNWIND (lk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &lock, xdata); + + free (rsp.flock.lk_owner.lk_owner_val); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_readdir_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_readdir_rsp rsp = {0,}; + int32_t ret = 0; + clnt_local_t *local = NULL; + gf_dirent_t entries; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + INIT_LIST_HEAD (&entries.list); + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfx_readdir_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_readdir_v2 (this, &rsp, &entries, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed: remote_fd = %d", + local->cmd); + } + CLIENT_STACK_UNWIND (readdir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &entries, xdata); + + if (rsp.op_ret != -1) { + gf_dirent_free (&entries); + } + + if (xdata) + dict_unref (xdata); + + clnt_readdir_rsp_cleanup_v2 (&rsp); + + return 0; +} + +int +client4_0_readdirp_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_readdirp_rsp rsp = {0,}; + int32_t ret = 0; + clnt_local_t *local = NULL; + gf_dirent_t entries; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + INIT_LIST_HEAD (&entries.list); + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfx_readdirp_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_readdirp_v2 (this, &rsp, local->fd, &entries, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (readdirp, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &entries, xdata); + + if (rsp.op_ret != -1) { + gf_dirent_free (&entries); + } + + + if (xdata) + dict_unref (xdata); + + clnt_readdirp_rsp_cleanup_v2 (&rsp); + + return 0; +} + +int +client4_0_rename_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_rename_rsp rsp = {0,}; + struct iatt stbuf = {0,}; + struct iatt preoldparent = {0,}; + struct iatt postoldparent = {0,}; + struct iatt prenewparent = {0,}; + struct iatt postnewparent = {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_gfx_rename_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + client_post_rename_v2 (this, &rsp, &stbuf, &preoldparent, + &postoldparent, &prenewparent, + &postnewparent, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (rename, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), + &stbuf, &preoldparent, &postoldparent, + &prenewparent, &postnewparent, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_link_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_3iatt_rsp rsp = {0,}; + call_frame_t *frame = NULL; + 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_gfx_common_3iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_common_3iatt (this, &rsp, &stbuf, &preparent, + &postparent, &xdata); +out: + if (rsp.op_ret == -1) { + if (GF_IGNORE_IF_GSYNCD_SAFE_ERROR(frame, rsp.op_errno)) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed: (%s -> %s)", + local->loc.path, local->loc2.path); + } + } + + CLIENT_STACK_UNWIND (link, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), inode, + &stbuf, &preparent, &postparent, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_opendir_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + clnt_local_t *local = NULL; + call_frame_t *frame = NULL; + fd_t *fd = NULL; + int ret = 0; + gfx_open_rsp rsp = {0,}; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + + fd = local->fd; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + /* open and opendir are two operations dealing with same thing, + but separated by fop number only */ + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfx_open_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (-1 != rsp.op_ret) { + ret = client_add_fd_to_saved_fds (frame->this, fd, &local->loc, + 0, rsp.fd, 1); + if (ret) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + goto out; + } + } + + ret = xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, fop_log_level (GF_FOP_OPENDIR, + gf_error_to_errno (rsp.op_errno)), + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, "remote operation failed." + " Path: %s (%s)", + local->loc.path, loc_gfid_utoa (&local->loc)); + } + CLIENT_STACK_UNWIND (opendir, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), fd, xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int +client4_0_lookup_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_common_2iatt_rsp rsp = {0,}; + clnt_local_t *local = NULL; + call_frame_t *frame = NULL; + int ret = 0; + struct iatt stbuf = {0,}; + struct iatt postparent = {0,}; + int op_errno = EINVAL; + dict_t *xdata = NULL; + inode_t *inode = NULL; + xlator_t *this = NULL; + + this = THIS; + + frame = myframe; + local = frame->local; + inode = local->loc.inode; + + if (-1 == req->rpc_status) { + rsp.op_ret = -1; + op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfx_common_2iatt_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + op_errno = EINVAL; + goto out; + } + + /* Preserve the op_errno received from the server */ + op_errno = gf_error_to_errno (rsp.op_errno); + + ret = client_post_common_2iatt (this, &rsp, &stbuf, &postparent, &xdata); + if (ret < 0) { + /* Don't change the op_errno if the fop failed on server */ + if (rsp.op_ret == 0) + op_errno = rsp.op_errno; + rsp.op_ret = -1; + goto out; + } + + if (rsp.op_ret < 0) + goto out; + + if ((!gf_uuid_is_null (inode->gfid)) + && (gf_uuid_compare (stbuf.ia_gfid, inode->gfid) != 0)) { + gf_msg_debug (frame->this->name, 0, + "gfid changed for %s", local->loc.path); + + rsp.op_ret = -1; + op_errno = ESTALE; + if (xdata) + ret = dict_set_int32 (xdata, "gfid-changed", 1); + + goto out; + } + + rsp.op_ret = 0; + +out: + /* Restore the correct op_errno to rsp.op_errno */ + rsp.op_errno = op_errno; + if (rsp.op_ret == -1) { + /* any error other than ENOENT */ + if (!(local->loc.name && rsp.op_errno == ENOENT) && + !(rsp.op_errno == ESTALE)) + gf_msg (this->name, GF_LOG_WARNING, rsp.op_errno, + PC_MSG_REMOTE_OP_FAILED, "remote operation " + "failed. Path: %s (%s)", + local->loc.path, + loc_gfid_utoa (&local->loc)); + else + gf_msg_trace (this->name, 0, "not found on remote " + "node"); + + } + + CLIENT_STACK_UNWIND (lookup, frame, rsp.op_ret, rsp.op_errno, inode, + &stbuf, xdata, &postparent); + + if (xdata) + dict_unref (xdata); + + + + return 0; +} + +int +client4_0_readv_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + struct iobref *iobref = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + struct iatt stat = {0,}; + gfx_read_rsp rsp = {0,}; + int ret = 0, rspcount = 0; + clnt_local_t *local = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + + this = THIS; + + memset (vector, 0, sizeof (vector)); + + frame = myframe; + 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_gfx_read_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + ret = client_post_readv_v2 (this, &rsp, &iobref, req->rsp_iobref, + &stat, vector, &req->rsp[1], + &rspcount, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } else if (rsp.op_ret >= 0) { + if (local->attempt_reopen) + client_attempt_reopen (local->fd, this); + } + CLIENT_STACK_UNWIND (readv, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), vector, rspcount, + &stat, iobref, xdata); + + + + if (xdata) + dict_unref (xdata); + + return 0; +} + +int +client4_0_release_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + + frame = myframe; + STACK_DESTROY (frame->root); + return 0; +} +int +client4_0_releasedir_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + + frame = myframe; + STACK_DESTROY (frame->root); + return 0; +} + +int +client4_0_getactivelk_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_getactivelk_rsp rsp = {0,}; + int32_t ret = 0; + lock_migration_info_t locklist; + 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_gfx_getactivelk_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + INIT_LIST_HEAD (&locklist.list); + + if (rsp.op_ret > 0) { + clnt_unserialize_rsp_locklist_v2 (this, &rsp, &locklist); + } + + xdr_to_dict (&rsp.xdata, &xdata); + +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + + CLIENT_STACK_UNWIND (getactivelk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), &locklist, + xdata); + if (xdata) + dict_unref (xdata); + + clnt_getactivelk_rsp_cleanup_v2 (&rsp); + + return 0; +} + +int +client4_0_setactivelk_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_common_rsp rsp = {0,}; + int32_t 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_gfx_common_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + + CLIENT_STACK_UNWIND (setactivelk, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), xdata); + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int32_t +client4_0_releasedir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + gf_boolean_t destroy = _gf_false; + + if (!this || !data) + goto out; + + args = data; + conf = this->private; + + pthread_mutex_lock (&conf->lock); + { + fdctx = this_fd_del_ctx (args->fd, this); + if (fdctx != NULL) { + remote_fd = fdctx->remote_fd; + + /* fdctx->remote_fd == -1 indicates a reopen attempt + in progress. Just mark ->released = 1 and let + reopen_cbk handle releasing + */ + + if (remote_fd == -1) { + fdctx->released = 1; + } else { + list_del_init (&fdctx->sfd_pos); + destroy = _gf_true; + } + } + } + pthread_mutex_unlock (&conf->lock); + + if (destroy) + client_fdctx_destroy (this, fdctx); + +out: + + return 0; +} + +int32_t +client4_0_release (call_frame_t *frame, xlator_t *this, + void *data) +{ + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + clnt_fd_ctx_t *fdctx = NULL; + clnt_args_t *args = NULL; + lk_heal_state_t lk_heal_state = GF_LK_HEAL_DONE; + gf_boolean_t destroy = _gf_false; + + if (!this || !data) + goto out; + + args = data; + conf = this->private; + + pthread_mutex_lock (&conf->lock); + { + fdctx = this_fd_del_ctx (args->fd, this); + if (fdctx != NULL) { + remote_fd = fdctx->remote_fd; + lk_heal_state = fdctx->lk_heal_state; + + /* fdctx->remote_fd == -1 indicates a reopen attempt + in progress. Just mark ->released = 1 and let + reopen_cbk handle releasing + */ + if (remote_fd == -1) { + fdctx->released = 1; + } else if (lk_heal_state == GF_LK_HEAL_DONE) { + list_del_init (&fdctx->sfd_pos); + destroy = _gf_true; + } + } + } + pthread_mutex_unlock (&conf->lock); + + if (destroy) + client_fdctx_destroy (this, fdctx); +out: + return 0; +} + + +int32_t +client4_0_lookup (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + clnt_args_t *args = NULL; + gfx_lookup_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + data_t *content = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + int count = 0; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + + if (!frame || !this || !data) + goto unwind; + + memset (vector, 0, sizeof (vector)); + + conf = this->private; + args = data; + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + + if (args->xdata) { + content = dict_get (args->xdata, GF_CONTENT_KEY); + if (content != NULL) { + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + goto unwind; + } + + /* TODO: what is the size we should send ? */ + /* This change very much depends on quick-read + changes */ + rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); + if (rsp_iobuf == NULL) { + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + iobuf_unref (rsp_iobuf); + rsp_iobuf = NULL; + rsp_iobref = NULL; + } + } + + ret = client_pre_lookup_v2 (this, &req, args->loc, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_LOOKUP, client4_0_lookup_cbk, + NULL, rsphdr, count, + NULL, 0, local->iobref, + (xdrproc_t)xdr_gfx_lookup_req); + + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (lookup, frame, -1, op_errno, NULL, NULL, NULL, + NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + return 0; +} + +int32_t +client4_0_stat (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_stat_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_stat_v2 (this, &req, args->loc, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_STAT, client4_0_stat_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_stat_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (stat, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_truncate (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_truncate_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_truncate_v2 (this, &req, args->loc, args->offset, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_TRUNCATE, + client4_0_truncate_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_truncate_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (truncate, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_ftruncate (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_ftruncate_req req = {{0,},}; + int op_errno = EINVAL; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + conf = this->private; + + ret = client_pre_ftruncate_v2 (this, &req, args->fd, args->offset, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FTRUNCATE, + client4_0_ftruncate_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_ftruncate_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (ftruncate, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_access (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_access_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + conf = this->private; + + + ret = client_pre_access_v2 (this, &req, args->loc, args->mask, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_ACCESS, + client4_0_access_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_access_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (access, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_readlink (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_readlink_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + clnt_local_t *local = NULL; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + frame->local = local; + + ret = client_pre_readlink_v2 (this, &req, args->loc, args->size, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_READLINK, + client4_0_readlink_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_readlink_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + + CLIENT_STACK_UNWIND (readlink, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_unlink (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_unlink_req req = {{0,},}; + int ret = 0; + int op_errno = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_unlink_v2 (this, &req, args->loc, args->flags, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_UNLINK, + client4_0_unlink_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_unlink_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (unlink, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_rmdir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_rmdir_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_rmdir_v2 (this, &req, args->loc, args->flags, + args->xdata); + + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_RMDIR, client4_0_rmdir_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_rmdir_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (rmdir, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_symlink (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_symlink_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + frame->local = local; + + if (!(args->loc && args->loc->parent)) + goto unwind; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + + local->loc2.path = gf_strdup (args->linkname); + + ret = client_pre_symlink_v2 (this, &req, args->loc, + args->linkname, args->umask, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_SYMLINK, client4_0_symlink_cbk, + NULL, NULL, 0, NULL, + 0, NULL, (xdrproc_t)xdr_gfx_symlink_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + + CLIENT_STACK_UNWIND (symlink, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_rename (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_rename_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_rename_v2 (this, &req, args->oldloc, args->newloc, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_RENAME, client4_0_rename_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_rename_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (rename, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_link (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_link_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + frame->local = local; + + ret = client_pre_link_v2 (this, &req, args->oldloc, args->newloc, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + loc_copy (&local->loc, args->oldloc); + loc_path (&local->loc, NULL); + loc_copy (&local->loc2, args->newloc); + loc_path (&local->loc2, NULL); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_LINK, client4_0_link_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_link_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (link, frame, -1, op_errno, NULL, NULL, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_mknod (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_mknod_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + + ret = client_pre_mknod_v2 (this, &req, args->loc, + args->mode, args->rdev, args->umask, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_MKNOD, client4_0_mknod_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_mknod_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (mknod, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_mkdir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_mkdir_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + if (!args->xdata || !dict_get (args->xdata, "gfid-req")) { + op_errno = EPERM; + gf_msg_callingfn (this->name, GF_LOG_WARNING, op_errno, + PC_MSG_GFID_NULL, "mkdir: %s is received " + "without gfid-req %p", args->loc->path, + args->xdata); + goto unwind; + } + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + if (!(args->loc && args->loc->parent)) + goto unwind; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + + ret = client_pre_mkdir_v2 (this, &req, args->loc, args->mode, + args->umask, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_MKDIR, client4_0_mkdir_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_mkdir_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (mkdir, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_create (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_create_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + local->fd = fd_ref (args->fd); + local->flags = args->flags; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + + ret = client_pre_create_v2 (this, &req, args->loc, + args->fd, args->mode, + args->flags, args->umask, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_CREATE, client4_0_create_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_create_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (create, frame, -1, op_errno, NULL, NULL, NULL, + NULL, NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_open (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_open_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + local->flags = args->flags; + + local->fd = fd_ref (args->fd); + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + + ret = client_pre_open_v2 (this, &req, args->loc, args->fd, args->flags, + args->xdata); + + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_OPEN, client4_0_open_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_open_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (open, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_readv (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + int op_errno = ESTALE; + gfx_read_req req = {{0,},}; + int ret = 0; + struct iovec rsp_vec = {0, }; + struct iobuf *rsp_iobuf = NULL; + struct iobref *rsp_iobref = NULL; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_readv_v2 (this, &req, args->fd, args->size, + args->offset, args->flags, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_fd_fop_prepare_local (frame, args->fd, req.fd); + if (ret) { + op_errno = -ret; + goto unwind; + } + local = frame->local; + + rsp_iobuf = iobuf_get2 (this->ctx->iobuf_pool, args->size); + if (rsp_iobuf == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + op_errno = ENOMEM; + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + rsp_vec.iov_base = iobuf_ptr (rsp_iobuf); + rsp_vec.iov_len = iobuf_pagesize (rsp_iobuf); + local->iobref = rsp_iobref; + iobuf_unref (rsp_iobuf); + rsp_iobref = NULL; + rsp_iobuf = NULL; + + if (args->size > rsp_vec.iov_len) { + gf_msg (this->name, GF_LOG_WARNING, ENOMEM, PC_MSG_NO_MEMORY, + "read-size (%lu) is bigger than iobuf size (%lu)", + (unsigned long)args->size, + (unsigned long)rsp_vec.iov_len); + op_errno = EINVAL; + goto unwind; + } + + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_READ, client4_0_readv_cbk, NULL, + NULL, 0, &rsp_vec, 1, + local->iobref, + (xdrproc_t)xdr_gfx_read_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + if (rsp_iobuf) + iobuf_unref (rsp_iobuf); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + CLIENT_STACK_UNWIND (readv, frame, -1, op_errno, NULL, 0, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_writev (call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_write_req req = {{0,},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_writev_v2 (this, &req, args->fd, args->size, + args->offset, args->flags, &args->xdata); + + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_fd_fop_prepare_local (frame, args->fd, req.fd); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_vec_request (this, &req, frame, conf->fops, + GFS3_OP_WRITE, client4_0_writev_cbk, + args->vector, args->count, + args->iobref, + (xdrproc_t)xdr_gfx_write_req); + if (ret) { + /* + * If the lower layers fail to submit a request, they'll also + * do the unwind for us (see rpc_clnt_submit), so don't unwind + * here in such cases. + */ + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (writev, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_flush (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfx_flush_req req = {{0,},}; + clnt_conf_t *conf = NULL; + clnt_local_t *local = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + frame->local = local; + + local->fd = fd_ref (args->fd); + local->owner = frame->root->lk_owner; + ret = client_pre_flush_v2 (this, &req, args->fd, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FLUSH, client4_0_flush_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_flush_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + + return 0; + +unwind: + CLIENT_STACK_UNWIND (flush, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_fsync (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfx_fsync_req req = {{0,},}; + clnt_conf_t *conf = NULL; + int op_errno = 0; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_fsync_v2 (this, &req, args->fd, args->flags, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSYNC, client4_0_fsync_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_fsync_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (fsync, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_fstat (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfx_fstat_req req = {{0,},}; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_fstat_v2 (this, &req, args->fd, args->xdata); + + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSTAT, client4_0_fstat_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_fstat_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (fstat, frame, -1, op_errno, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_opendir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_opendir_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + local->fd = fd_ref (args->fd); + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + + ret = client_pre_opendir_v2 (this, &req, args->loc, args->fd, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_OPENDIR, client4_0_opendir_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_opendir_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (opendir, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_fsyncdir (call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_fsyncdir_req req = {{0,},}; + int ret = 0; + int32_t op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_fsyncdir_v2 (this, &req, args->fd, args->flags, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSYNCDIR, client4_0_fsyncdir_cbk, + NULL, NULL, 0, + NULL, 0, NULL, + (xdrproc_t)xdr_gfx_fsyncdir_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (fsyncdir, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_statfs (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_statfs_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + conf = this->private; + + ret = client_pre_statfs_v2 (this, &req, args->loc, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_STATFS, client4_0_statfs_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_statfs_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; + +unwind: + CLIENT_STACK_UNWIND (statfs, frame, -1, op_errno, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_setxattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_setxattr_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_setxattr_v2 (this, &req, args->loc, args->xattr, + args->flags, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_SETXATTR, client4_0_setxattr_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_setxattr_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + GF_FREE (req.dict.pairs.pairs_val); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (setxattr, frame, -1, op_errno, NULL); + GF_FREE (req.dict.pairs.pairs_val); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_fsetxattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_fsetxattr_req req = {{0,},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_fsetxattr_v2 (this, &req, args->fd, args->flags, + args->xattr, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSETXATTR, client4_0_fsetxattr_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_fsetxattr_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.dict.pairs.pairs_val); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fsetxattr, frame, -1, op_errno, NULL); + GF_FREE (req.dict.pairs.pairs_val); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_fgetxattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_fgetxattr_req req = {{0,},}; + int op_errno = ESTALE; + int ret = 0; + clnt_local_t *local = NULL; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + ret = client_pre_fgetxattr_v2 (this, &req, args->fd, args->name, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FGETXATTR, + client4_0_fgetxattr_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_fgetxattr_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fgetxattr, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_getxattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_getxattr_req req = {{0,},}; + dict_t *dict = NULL; + int ret = 0; + int32_t op_ret = -1; + int op_errno = ESTALE; + clnt_local_t *local = NULL; + + if (!frame || !this || !data) { + op_errno = 0; + goto unwind; + } + args = data; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + + frame->local = local; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + + if (args->name) + local->name = gf_strdup (args->name); + + conf = this->private; + + if (args && args->name) { + if (is_client_dump_locks_cmd ((char *)args->name)) { + dict = dict_new (); + + if (!dict) { + op_errno = ENOMEM; + goto unwind; + } + + ret = client_dump_locks ((char *)args->name, + args->loc->inode, + dict); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + PC_MSG_INVALID_ENTRY, "Client dump " + "locks failed"); + op_errno = ENOMEM; + goto unwind; + } + + GF_ASSERT (dict); + op_ret = 0; + op_errno = 0; + goto unwind; + } + } + + ret = client_pre_getxattr_v2 (this, &req, args->loc, args->name, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_GETXATTR, + client4_0_getxattr_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_getxattr_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (getxattr, frame, op_ret, op_errno, dict, NULL); + + if (dict) { + dict_unref(dict); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_xattrop (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_xattrop_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + clnt_local_t *local = NULL; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + loc_copy (&local->loc, args->loc); + loc_path (&local->loc, NULL); + conf = this->private; + + ret = client_pre_xattrop_v2 (this, &req, args->loc, args->xattr, + args->flags, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_XATTROP, + client4_0_xattrop_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_xattrop_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.dict.pairs.pairs_val); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (xattrop, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.dict.pairs.pairs_val); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_fxattrop (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_fxattrop_req req = {{0,},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_fxattrop_v2 (this, &req, args->fd, args->xattr, + args->flags, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_fd_fop_prepare_local (frame, args->fd, req.fd); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FXATTROP, + client4_0_fxattrop_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_fxattrop_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.dict.pairs.pairs_val); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fxattrop, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.dict.pairs.pairs_val); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_removexattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_removexattr_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_removexattr_v2 (this, &req, args->loc, args->name, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_REMOVEXATTR, + client4_0_removexattr_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_removexattr_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (removexattr, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_fremovexattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_fremovexattr_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + conf = this->private; + + ret = client_pre_fremovexattr_v2 (this, &req, args->fd, args->name, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FREMOVEXATTR, + client4_0_fremovexattr_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_fremovexattr_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fremovexattr, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_lease (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfx_lease_req req = {{0,},}; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + + GF_VALIDATE_OR_GOTO ("client", this, unwind); + GF_VALIDATE_OR_GOTO (this->name, frame, unwind); + GF_VALIDATE_OR_GOTO (this->name, data, unwind); + + args = data; + conf = this->private; + + ret = client_pre_lease_v2 (this, &req, args->loc, args->lease, + args->xdata); + if (ret < 0) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, GFS3_OP_LEASE, + client4_0_lease_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_lease_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (lease, frame, -1, op_errno, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_lk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfx_lk_req req = {{0,},}; + int32_t gf_cmd = 0; + clnt_local_t *local = NULL; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + ret = client_cmd_to_gf_cmd (args->cmd, &gf_cmd); + if (ret) { + op_errno = EINVAL; + gf_msg (this->name, GF_LOG_WARNING, EINVAL, + PC_MSG_INVALID_ENTRY, "Unknown cmd (%d)!", gf_cmd); + goto unwind; + } + + local->owner = frame->root->lk_owner; + local->cmd = args->cmd; + local->fd = fd_ref (args->fd); + + ret = client_pre_lk_v2 (this, &req, args->cmd, args->flock, + args->fd, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, GFS3_OP_LK, + client4_0_lk_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_lk_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (lk, frame, -1, op_errno, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_inodelk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_inodelk_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_inodelk_v2 (this, &req, args->loc, args->cmd, + args->flock, args->volume, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_INODELK, + client4_0_inodelk_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_inodelk_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (inodelk, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_finodelk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfx_finodelk_req req = {{0,},}; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_finodelk_v2 (this, &req, args->fd, + args->cmd, args->flock, args->volume, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_fd_fop_prepare_local (frame, args->fd, req.fd); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FINODELK, + client4_0_finodelk_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_finodelk_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + return 0; +unwind: + CLIENT_STACK_UNWIND (finodelk, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_entrylk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_entrylk_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + + conf = this->private; + + ret = client_pre_entrylk_v2 (this, &req, args->loc, args->cmd_entrylk, + args->type, args->volume, args->basename, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_ENTRYLK, + client4_0_entrylk_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_entrylk_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (entrylk, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + + +int32_t +client4_0_fentrylk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfx_fentrylk_req req = {{0,},}; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_fentrylk_v2 (this, &req, args->fd, args->cmd_entrylk, + args->type, args->volume, args->basename, + args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FENTRYLK, + client4_0_fentrylk_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_fentrylk_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fentrylk, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_readdir (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfx_readdir_req req = {{0,},}; + gfx_readdir_rsp rsp = {0, }; + clnt_local_t *local = NULL; + int op_errno = ESTALE; + int ret = 0; + int count = 0; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + int readdir_rsp_size = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + readdir_rsp_size = xdr_sizeof ((xdrproc_t) xdr_gfx_readdir_rsp, &rsp) + + args->size; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + local->cmd = remote_fd; + + if ((readdir_rsp_size + GLUSTERFS_RPC_REPLY_SIZE + GLUSTERFS_RDMA_MAX_HEADER_SIZE) + > (GLUSTERFS_RDMA_INLINE_THRESHOLD)) { + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + goto unwind; + } + + /* TODO: what is the size we should send ? */ + /* This iobuf will live for only receiving the response, + so not harmful */ + rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); + if (rsp_iobuf == NULL) { + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + iobuf_unref (rsp_iobuf); + rsp_iobuf = NULL; + rsp_iobref = NULL; + } + + ret = client_pre_readdir_v2 (this, &req, args->fd, args->size, + args->offset, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_READDIR, + client4_0_readdir_cbk, NULL, + rsphdr, count, + NULL, 0, rsp_iobref, + (xdrproc_t)xdr_gfx_readdir_req); + + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; + +unwind: + if (rsp_iobref) + iobref_unref (rsp_iobref); + + CLIENT_STACK_UNWIND (readdir, frame, -1, op_errno, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_readdirp (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + gfx_readdirp_req req = {{0,},}; + gfx_readdirp_rsp rsp = {0,}; + clnt_conf_t *conf = NULL; + int op_errno = ESTALE; + int ret = 0; + int count = 0; + int readdirp_rsp_size = 0; + struct iobref *rsp_iobref = NULL; + struct iobuf *rsp_iobuf = NULL; + struct iovec *rsphdr = NULL; + struct iovec vector[MAX_IOVEC] = {{0}, }; + clnt_local_t *local = NULL; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + ret = client_pre_readdirp_v2 (this, &req, args->fd, args->size, + args->offset, args->xdata); + + if (ret) { + op_errno = -ret; + goto unwind; + } + + readdirp_rsp_size = xdr_sizeof ((xdrproc_t) xdr_gfx_readdirp_rsp, &rsp) + + args->size; + + if ((readdirp_rsp_size + GLUSTERFS_RPC_REPLY_SIZE + + GLUSTERFS_RDMA_MAX_HEADER_SIZE) + > (GLUSTERFS_RDMA_INLINE_THRESHOLD)) { + rsp_iobref = iobref_new (); + if (rsp_iobref == NULL) { + goto unwind; + } + + /* TODO: what is the size we should send ? */ + /* This iobuf will live for only receiving the response, + so not harmful */ + rsp_iobuf = iobuf_get (this->ctx->iobuf_pool); + if (rsp_iobuf == NULL) { + goto unwind; + } + + iobref_add (rsp_iobref, rsp_iobuf); + iobuf_unref (rsp_iobuf); + + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsp_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsp_iobuf); + count = 1; + local->iobref = rsp_iobref; + rsp_iobuf = NULL; + rsp_iobref = NULL; + } + + local->fd = fd_ref (args->fd); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_READDIRP, + client4_0_readdirp_cbk, NULL, + rsphdr, count, NULL, + 0, rsp_iobref, + (xdrproc_t)xdr_gfx_readdirp_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + if (rsp_iobref) + iobref_unref (rsp_iobref); + + GF_FREE (req.xdata.pairs.pairs_val); + + CLIENT_STACK_UNWIND (readdirp, frame, -1, op_errno, NULL, NULL); + return 0; +} + + +int32_t +client4_0_setattr (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_setattr_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_setattr_v2 (this, &req, args->loc, args->valid, + args->stbuf, args->xdata); + + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_SETATTR, + client4_0_setattr_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_setattr_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (setattr, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_fallocate(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_fallocate_req req = {{0},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_fallocate_v2 (this, &req, args->fd, args->flags, + args->offset, args->size, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FALLOCATE, + client4_0_fallocate_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_fallocate_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fallocate, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_discard(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_discard_req req = {{0},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_discard_v2 (this, &req, args->fd, args->offset, + args->size, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_DISCARD, client4_0_discard_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_discard_req); + if (ret) + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(discard, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_zerofill(call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_zerofill_req req = {{0},}; + int op_errno = ESTALE; + int ret = 0; + + GF_ASSERT (frame); + + if (!this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_zerofill_v2 (this, &req, args->fd, args->offset, + args->size, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_ZEROFILL, client4_0_zerofill_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_zerofill_req); + if (ret) + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(zerofill, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_ipc (call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_ipc_req req = {0,}; + int op_errno = ESTALE; + int ret = 0; + + GF_ASSERT (frame); + + if (!this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_ipc_v2 (this, &req, args->cmd, args->xdata); + + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_IPC, client4_0_ipc_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_ipc_req); + if (ret) + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(ipc, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_seek (call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + struct gfx_seek_req req = {{0,},}; + int op_errno = ESTALE; + int ret = 0; + + GF_ASSERT (frame); + + if (!this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_seek_v2 (this, &req, args->fd, + args->offset, args->what, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + + ret = client_submit_request(this, &req, frame, conf->fops, + GFS3_OP_SEEK, client4_0_seek_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_seek_req); + if (ret) + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND(ipc, frame, -1, op_errno, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + + +int32_t +client4_0_getactivelk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_getactivelk_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + if (!(args->loc && args->loc->inode)) + goto unwind; + + if (!gf_uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req.gfid)), + unwind, op_errno, EINVAL); + conf = this->private; + + dict_to_xdr (args->xdata, &req.xdata); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_GETACTIVELK, + client4_0_getactivelk_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_getactivelk_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (getactivelk, frame, -1, op_errno, NULL, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_setactivelk (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_setactivelk_req req = {{0,},}; + int ret = 0; + int op_errno = ESTALE; + + if (!frame || !this || !data) + goto unwind; + + args = data; + if (!(args->loc && args->loc->inode && args->locklist)) + goto unwind; + + if (!gf_uuid_is_null (args->loc->inode->gfid)) + memcpy (req.gfid, args->loc->inode->gfid, 16); + else + memcpy (req.gfid, args->loc->gfid, 16); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req.gfid)), + unwind, op_errno, EINVAL); + conf = this->private; + + dict_to_xdr (args->xdata, &req.xdata); + ret = serialize_req_locklist_v2 (args->locklist, &req); + + if (ret) + goto unwind; + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_SETACTIVELK, client4_0_setactivelk_cbk, NULL, + NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_setactivelk_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + + clnt_setactivelk_req_cleanup_v2 (&req); + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; + +unwind: + + CLIENT_STACK_UNWIND (setactivelk, frame, -1, op_errno, NULL); + + GF_FREE (req.xdata.pairs.pairs_val); + + clnt_setactivelk_req_cleanup_v2 (&req); + + return 0; +} + + +int +client4_rchecksum_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + call_frame_t *frame = NULL; + gfx_rchecksum_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_gfx_rchecksum_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + xdr_to_dict (&rsp.xdata, &xdata); +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + + CLIENT_STACK_UNWIND (rchecksum, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), + rsp.weak_checksum, + (uint8_t *)rsp.strong_checksum.strong_checksum_val, + xdata); + + if (rsp.strong_checksum.strong_checksum_val) { + /* This is allocated by the libc while decoding RPC msg */ + /* Hence no 'GF_FREE', but just 'free' */ + free (rsp.strong_checksum.strong_checksum_val); + } + + if (xdata) + dict_unref (xdata); + + return 0; +} + + +int32_t +client4_namelink_cbk (struct rpc_req *req, + struct iovec *iov, int count, void *myframe) +{ + int32_t ret = 0; + struct iatt prebuf = {0,}; + struct iatt postbuf = {0,}; + dict_t *xdata = NULL; + call_frame_t *frame = NULL; + gfx_common_2iatt_rsp rsp = {0,}; + + frame = myframe; + + if (req->rpc_status == -1) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfx_common_2iatt_rsp); + if (ret < 0) { + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret != -1) { + gfx_stat_to_iattx (&rsp.prestat, &prebuf); + gfx_stat_to_iattx (&rsp.poststat, &postbuf); + } + + xdr_to_dict (&rsp.xdata, &xdata); + out: + CLIENT_STACK_UNWIND (namelink, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), + &prebuf, &postbuf, xdata); + if (xdata) + dict_unref (xdata); + return 0; +} + +int32_t +client4_icreate_cbk (struct rpc_req *req, + struct iovec *iov, int count, void *myframe) +{ + int32_t ret = 0; + inode_t *inode = NULL; + clnt_local_t *local = NULL; + struct iatt stbuf = {0,}; + dict_t *xdata = NULL; + call_frame_t *frame = NULL; + gfx_common_iatt_rsp rsp = {0,}; + + frame = myframe; + local = frame->local; + + inode = local->loc.inode; + + if (req->rpc_status == -1) { + rsp.op_ret = -1; + rsp.op_errno = ENOTCONN; + goto out; + } + + ret = xdr_to_generic (*iov, &rsp, (xdrproc_t)xdr_gfx_common_iatt_rsp); + if (ret < 0) { + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + if (rsp.op_ret != -1) + gfx_stat_to_iattx (&rsp.stat, &stbuf); + + xdr_to_dict (&rsp.xdata, &xdata); + out: + CLIENT_STACK_UNWIND (icreate, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), + inode, &stbuf, xdata); + if (xdata) + dict_unref (xdata); + return 0; +} +int32_t +client4_namelink (call_frame_t *frame, xlator_t *this, void *data) +{ + int32_t ret = 0; + int32_t op_errno = EINVAL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + gfx_namelink_req req = {{0,},}; + + GF_ASSERT (frame); + + args = data; + conf = this->private; + + if (!(args->loc && args->loc->parent)) + goto unwind; + + if (!gf_uuid_is_null (args->loc->parent->gfid)) + memcpy (req.pargfid, args->loc->parent->gfid, sizeof (uuid_t)); + else + memcpy (req.pargfid, args->loc->pargfid, sizeof (uuid_t)); + + GF_ASSERT_AND_GOTO_WITH_ERROR (this->name, + !gf_uuid_is_null (*((uuid_t *)req.pargfid)), + unwind, op_errno, EINVAL); + + req.bname = (char *)args->loc->name; + + dict_to_xdr (args->xdata, &req.xdata); + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_NAMELINK, client4_namelink_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_namelink_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + return 0; + + unwind: + CLIENT_STACK_UNWIND (namelink, frame, -1, op_errno, NULL, NULL, NULL); + return 0; +} + +int32_t +client4_icreate (call_frame_t *frame, xlator_t *this, void *data) +{ + int32_t ret = 0; + int32_t op_errno = EINVAL; + clnt_conf_t *conf = NULL; + clnt_args_t *args = NULL; + clnt_local_t *local = NULL; + gfx_icreate_req req = {{0,},}; + + GF_ASSERT (frame); + + args = data; + conf = this->private; + + if (!(args->loc && args->loc->inode)) + goto unwind; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + loc_copy (&local->loc, args->loc); + + req.mode = args->mode; + memcpy (req.gfid, args->loc->gfid, sizeof (uuid_t)); + + op_errno = ESTALE; + dict_to_xdr (args->xdata, &req.xdata); + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_ICREATE, client4_icreate_cbk, + NULL, NULL, 0, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_icreate_req); + if (ret) + goto free_reqdata; + GF_FREE (req.xdata.pairs.pairs_val); + return 0; + + free_reqdata: + GF_FREE (req.xdata.pairs.pairs_val); + unwind: + CLIENT_STACK_UNWIND (icreate, frame, + -1, op_errno, NULL, NULL, NULL); + return 0; +} + +int32_t +client4_0_fsetattr (call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_args_t *args = NULL; + clnt_conf_t *conf = NULL; + gfx_fsetattr_req req = {{0},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + ret = client_pre_fsetattr_v2 (this, &req, args->fd, args->valid, + args->stbuf, args->xdata); + if (ret) { + op_errno = -ret; + goto unwind; + } + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_FSETATTR, + client4_0_fsetattr_cbk, NULL, + NULL, 0, NULL, 0, + NULL, (xdrproc_t)xdr_gfx_fsetattr_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (fsetattr, frame, -1, op_errno, NULL, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int32_t +client4_0_rchecksum (call_frame_t *frame, xlator_t *this, + void *data) +{ + clnt_args_t *args = NULL; + int64_t remote_fd = -1; + clnt_conf_t *conf = NULL; + gfx_rchecksum_req req = {{0},}; + int op_errno = ESTALE; + int ret = 0; + + if (!frame || !this || !data) + goto unwind; + + args = data; + conf = this->private; + + CLIENT_GET_REMOTE_FD(this, args->fd, DEFAULT_REMOTE_FD, + remote_fd, op_errno, unwind); + + req.len = args->len; + req.offset = args->offset; + req.fd = remote_fd; + memcpy (req.gfid, args->fd->inode->gfid, 16); + + dict_to_xdr (args->xdata, &req.xdata); + + ret = client_submit_request (this, &req, frame, conf->fops, + GFS3_OP_RCHECKSUM, + client4_rchecksum_cbk, NULL, + NULL, 0, NULL, + 0, NULL, + (xdrproc_t)xdr_gfx_rchecksum_req); + if (ret) { + gf_msg (this->name, GF_LOG_WARNING, 0, PC_MSG_FOP_SEND_FAILED, + "failed to send the fop"); + } + + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +unwind: + CLIENT_STACK_UNWIND (rchecksum, frame, -1, op_errno, 0, NULL, NULL); + GF_FREE (req.xdata.pairs.pairs_val); + + return 0; +} + +int +client4_0_compound_cbk (struct rpc_req *req, struct iovec *iov, int count, + void *myframe) +{ + gfx_compound_rsp rsp = {0,}; + compound_args_cbk_t *args_cbk = NULL; + call_frame_t *frame = NULL; + xlator_t *this = NULL; + dict_t *xdata = NULL; + clnt_local_t *local = NULL; + int i = 0; + int length = 0; + int ret = -1; + + this = THIS; + + frame = myframe; + 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_gfx_compound_rsp); + if (ret < 0) { + gf_msg (this->name, GF_LOG_ERROR, EINVAL, + PC_MSG_XDR_DECODING_FAILED, "XDR decoding failed"); + rsp.op_ret = -1; + rsp.op_errno = EINVAL; + goto out; + } + + length = local->length; + + xdr_to_dict (&rsp.xdata, &xdata); + + args_cbk = compound_args_cbk_alloc (length, xdata); + if (!args_cbk) { + rsp.op_ret = -1; + rsp.op_errno = ENOMEM; + goto out; + } + + /* TODO: see https://bugzilla.redhat.com/show_bug.cgi?id=1376328 */ + for (i = 0; i < args_cbk->fop_length; i++) { + ret = client_process_response_v2 (frame, this, req, &rsp, + args_cbk, i); + if (ret) { + rsp.op_ret = -1; + rsp.op_errno = -ret; + goto out; + } + + } + rsp.op_ret = 0; +out: + if (rsp.op_ret == -1) { + gf_msg (this->name, GF_LOG_WARNING, + gf_error_to_errno (rsp.op_errno), + PC_MSG_REMOTE_OP_FAILED, + "remote operation failed"); + } + CLIENT_STACK_UNWIND (compound, frame, rsp.op_ret, + gf_error_to_errno (rsp.op_errno), args_cbk, xdata); + + client_compound_rsp_cleanup_v2 (&rsp, length); + free (rsp.compound_rsp_array.compound_rsp_array_val); + + if (xdata) + dict_unref (xdata); + + compound_args_cbk_cleanup (args_cbk); + return 0; +} + + +/* Brief explanation of gfs3_compound_req structure : + * 1) It consists of version of compounding. + * 2) A compound-fop enum, new enum for compound fops + * 3) A 'compound_req_arrray' structure that has + * a) array len - based on the number of fops compounded + * b) compound_req_array_val - pointer to an array of compound_req's + * 4) compound_req - structure that contains: + * a) fop enum of type glusterfs_fop_t + * b) union of structures of xdr requests of all fops. + */ + +int32_t +client4_0_compound (call_frame_t *frame, xlator_t *this, void *data) +{ + clnt_conf_t *conf = NULL; + compound_args_t *c_args = data; + gfx_compound_req req = {0,}; + clnt_local_t *local = NULL; + int op_errno = ENOMEM; + int ret = 0; + int i = 0; + int rsp_count = 0; + struct iovec rsp_vector[MAX_IOVEC] = {{0}, }; + struct iovec req_vector[MAX_IOVEC] = {{0}, }; + struct iovec vector[MAX_IOVEC] = {{0}, }; + struct iovec *rsphdr = NULL; + struct iobref *req_iobref = NULL; + struct iobref *rsp_iobref = NULL; + struct iobref *rsphdr_iobref = NULL; + struct iobuf *rsphdr_iobuf = NULL; + int rsphdr_count = 0; + int req_count = 0; + dict_t *xdata = c_args->xdata; + + GF_ASSERT (frame); + + if (!this) + goto unwind; + + memset (req_vector, 0, sizeof (req_vector)); + memset (rsp_vector, 0, sizeof (rsp_vector)); + + conf = this->private; + + local = mem_get0 (this->local_pool); + if (!local) { + op_errno = ENOMEM; + goto unwind; + } + frame->local = local; + + local->length = c_args->fop_length; + local->compound_args = c_args; + + rsphdr_iobref = iobref_new (); + if (rsphdr_iobref == NULL) { + goto unwind; + } + + /* TODO: what is the size we should send ? */ + rsphdr_iobuf = iobuf_get (this->ctx->iobuf_pool); + if (rsphdr_iobuf == NULL) { + goto unwind; + } + + iobref_add (rsphdr_iobref, rsphdr_iobuf); + iobuf_unref (rsphdr_iobuf); + rsphdr = &vector[0]; + rsphdr->iov_base = iobuf_ptr (rsphdr_iobuf); + rsphdr->iov_len = iobuf_pagesize (rsphdr_iobuf); + rsphdr_count = 1; + rsphdr_iobuf = NULL; + + req.compound_fop_enum = c_args->fop_enum; + req.compound_req_array.compound_req_array_len = c_args->fop_length; + req.compound_version = 0; + dict_to_xdr (xdata, &req.xdata); + + req.compound_req_array.compound_req_array_val = GF_CALLOC (local->length, + sizeof (compound_req_v2), + gf_client_mt_compound_req_t); + + if (!req.compound_req_array.compound_req_array_val) { + op_errno = ENOMEM; + goto unwind; + } + + for (i = 0; i < local->length; i++) { + ret = client_handle_fop_requirements_v2 (this, frame, + &req, local, + &req_iobref, &rsp_iobref, + req_vector, + rsp_vector, &req_count, + &rsp_count, + &c_args->req_list[i], + c_args->enum_list[i], + i); + if (ret) { + op_errno = ret; + goto unwind; + } + } + + local->iobref = rsp_iobref; + rsp_iobref = NULL; + + ret = client_submit_compound_request (this, &req, frame, conf->fops, + GFS3_OP_COMPOUND, client4_0_compound_cbk, + req_vector, req_count, req_iobref, + rsphdr, rsphdr_count, + rsp_vector, rsp_count, + local->iobref, + (xdrproc_t) xdr_gfx_compound_req); + + GF_FREE (req.xdata.pairs.pairs_val); + + iobref_unref (rsphdr_iobref); + + compound_request_cleanup_v2 (&req); + return 0; +unwind: + CLIENT_STACK_UNWIND (compound, frame, -1, op_errno, NULL, NULL); + + if (rsp_iobref) + iobref_unref (rsp_iobref); + + if (rsphdr_iobref) + iobref_unref (rsphdr_iobref); + + GF_FREE (req.xdata.pairs.pairs_val); + + compound_request_cleanup_v2 (&req); + return 0; +} + +/* Used From RPC-CLNT library to log proper name of procedure based on number */ +char *clnt4_0_fop_names[GFS3_OP_MAXVALUE] = { + [GFS3_OP_NULL] = "NULL", + [GFS3_OP_STAT] = "STAT", + [GFS3_OP_READLINK] = "READLINK", + [GFS3_OP_MKNOD] = "MKNOD", + [GFS3_OP_MKDIR] = "MKDIR", + [GFS3_OP_UNLINK] = "UNLINK", + [GFS3_OP_RMDIR] = "RMDIR", + [GFS3_OP_SYMLINK] = "SYMLINK", + [GFS3_OP_RENAME] = "RENAME", + [GFS3_OP_LINK] = "LINK", + [GFS3_OP_TRUNCATE] = "TRUNCATE", + [GFS3_OP_OPEN] = "OPEN", + [GFS3_OP_READ] = "READ", + [GFS3_OP_WRITE] = "WRITE", + [GFS3_OP_STATFS] = "STATFS", + [GFS3_OP_FLUSH] = "FLUSH", + [GFS3_OP_FSYNC] = "FSYNC", + [GFS3_OP_SETXATTR] = "SETXATTR", + [GFS3_OP_GETXATTR] = "GETXATTR", + [GFS3_OP_REMOVEXATTR] = "REMOVEXATTR", + [GFS3_OP_OPENDIR] = "OPENDIR", + [GFS3_OP_FSYNCDIR] = "FSYNCDIR", + [GFS3_OP_ACCESS] = "ACCESS", + [GFS3_OP_CREATE] = "CREATE", + [GFS3_OP_FTRUNCATE] = "FTRUNCATE", + [GFS3_OP_FSTAT] = "FSTAT", + [GFS3_OP_LK] = "LK", + [GFS3_OP_LOOKUP] = "LOOKUP", + [GFS3_OP_READDIR] = "READDIR", + [GFS3_OP_INODELK] = "INODELK", + [GFS3_OP_FINODELK] = "FINODELK", + [GFS3_OP_ENTRYLK] = "ENTRYLK", + [GFS3_OP_FENTRYLK] = "FENTRYLK", + [GFS3_OP_XATTROP] = "XATTROP", + [GFS3_OP_FXATTROP] = "FXATTROP", + [GFS3_OP_FGETXATTR] = "FGETXATTR", + [GFS3_OP_FSETXATTR] = "FSETXATTR", + [GFS3_OP_RCHECKSUM] = "RCHECKSUM", + [GFS3_OP_SETATTR] = "SETATTR", + [GFS3_OP_FSETATTR] = "FSETATTR", + [GFS3_OP_READDIRP] = "READDIRP", + [GFS3_OP_RELEASE] = "RELEASE", + [GFS3_OP_RELEASEDIR] = "RELEASEDIR", + [GFS3_OP_FREMOVEXATTR] = "FREMOVEXATTR", + [GFS3_OP_FALLOCATE] = "FALLOCATE", + [GFS3_OP_DISCARD] = "DISCARD", + [GFS3_OP_ZEROFILL] = "ZEROFILL", + [GFS3_OP_IPC] = "IPC", + [GFS3_OP_SEEK] = "SEEK", + [GFS3_OP_LEASE] = "LEASE", + [GFS3_OP_GETACTIVELK] = "GETACTIVELK", + [GFS3_OP_SETACTIVELK] = "SETACTIVELK", + [GFS3_OP_COMPOUND] = "COMPOUND", + [GFS3_OP_ICREATE] = "ICREATE", + [GFS3_OP_NAMELINK] = "NAMELINK", +}; diff --git a/xlators/protocol/client/src/client.h b/xlators/protocol/client/src/client.h index dd3ee4dd4f0..003a2bef397 100644 --- a/xlators/protocol/client/src/client.h +++ b/xlators/protocol/client/src/client.h @@ -134,6 +134,54 @@ typedef enum { client_local_wipe (__local); \ } while (0) +/* compound v2 */ +#define CPD4_REQ_FIELD(v, f) ((v)->compound_req_v2_u.compound_##f##_req) +#define CPD4_RSP_FIELD(v, f) ((v)->compound_rsp_v2_u.compound_##f##_rsp) + +#define CLIENT4_POST_FOP(fop, this_rsp_u, this_args_cbk, params ...) \ + do { \ + gfx_common_rsp *_this_rsp = &CPD4_RSP_FIELD(this_rsp_u, fop); \ + int _op_ret = 0; \ + int _op_errno = 0; \ + \ + _op_ret = _this_rsp->op_ret; \ + _op_errno = gf_error_to_errno (_this_rsp->op_errno); \ + args_##fop##_cbk_store (this_args_cbk, _op_ret, _op_errno, \ + params); \ + } while (0) + +#define CLIENT4_POST_FOP_TYPE(fop, rsp_type, this_rsp_u, this_args_cbk, params ...) \ + do { \ + gfx_##rsp_type##_rsp *_this_rsp = &CPD4_RSP_FIELD(this_rsp_u, fop); \ + int _op_ret = 0; \ + int _op_errno = 0; \ + \ + _op_ret = _this_rsp->op_ret; \ + _op_errno = gf_error_to_errno (_this_rsp->op_errno); \ + args_##fop##_cbk_store (this_args_cbk, _op_ret, _op_errno, \ + params); \ + } while (0) + +#define CLIENT4_PRE_FOP(fop, xl, compound_req, op_errno, label, params ...) \ + do { \ + gfx_##fop##_req *_req = (gfx_##fop##_req *)compound_req; \ + int _ret = 0; \ + \ + _ret = client_pre_##fop##_v2 (xl, _req, params); \ + if (_ret < 0) { \ + op_errno = -ret; \ + goto label; \ + } \ + } while (0) + +#define CLIENT4_COMPOUND_FOP_CLEANUP(curr_req, fop) \ + do { \ + gfx_##fop##_req *_req = &CPD4_REQ_FIELD(curr_req, fop); \ + \ + GF_FREE (_req->xdata.pairs.pairs_val); \ + } while (0) + + struct clnt_options { char *remote_subvolume; @@ -402,4 +450,47 @@ serialize_req_locklist (lock_migration_info_t *locklist, void client_compound_rsp_cleanup (gfs3_compound_rsp *rsp, int len); + +void +clnt_getactivelk_rsp_cleanup_v2 (gfx_getactivelk_rsp *rsp); + +void +clnt_setactivelk_req_cleanup_v2 (gfx_setactivelk_req *req); + +int +serialize_req_locklist_v2 (lock_migration_info_t *locklist, + gfx_setactivelk_req *req); + +int +clnt_unserialize_rsp_locklist_v2 (xlator_t *this, struct gfx_getactivelk_rsp *rsp, + lock_migration_info_t *lmi); + +int unserialize_rsp_dirent_v2 (xlator_t *this, struct gfx_readdir_rsp *rsp, + gf_dirent_t *entries); +int unserialize_rsp_direntp_v2 (xlator_t *this, fd_t *fd, + struct gfx_readdirp_rsp *rsp, gf_dirent_t *entries); + +int clnt_readdir_rsp_cleanup_v2 (gfx_readdir_rsp *rsp); +int clnt_readdirp_rsp_cleanup_v2 (gfx_readdirp_rsp *rsp); + +int +client_handle_fop_requirements_v2 (xlator_t *this, call_frame_t *frame, + gfx_compound_req *req, + clnt_local_t *local, + struct iobref **req_iobref, + struct iobref **rsp_iobref, + struct iovec *req_vector, + struct iovec *rsp_vector, int *req_count, + int *rsp_count, default_args_t *args, + int fop_enum, int index); +int +client_process_response_v2 (call_frame_t *frame, xlator_t *this, + struct rpc_req *req, + gfx_compound_rsp *rsp, compound_args_cbk_t *args_cbk, + int index); +void +compound_request_cleanup_v2 (gfx_compound_req *req); +void +client_compound_rsp_cleanup_v2 (gfx_compound_rsp *rsp, int len); + #endif /* !_CLIENT_H */ diff --git a/xlators/protocol/server/src/Makefile.am b/xlators/protocol/server/src/Makefile.am index 72f811e97fb..9c273cae222 100644 --- a/xlators/protocol/server/src/Makefile.am +++ b/xlators/protocol/server/src/Makefile.am @@ -8,7 +8,8 @@ server_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la \ $(top_builddir)/rpc/xdr/src/libgfxdr.la server_la_SOURCES = server.c server-resolve.c server-helpers.c \ - server-rpc-fops.c server-handshake.c authenticate.c server-common.c + server-rpc-fops.c server-handshake.c authenticate.c \ + server-common.c server-rpc-fops_v2.c server_la_HEADERS = server.h server-helpers.h server-mem-types.h \ authenticate.h server-messages.h server-common.h diff --git a/xlators/protocol/server/src/server-common.c b/xlators/protocol/server/src/server-common.c index 9c38706dbcb..17660ef475e 100644 --- a/xlators/protocol/server/src/server-common.c +++ b/xlators/protocol/server/src/server-common.c @@ -5,6 +5,7 @@ #include "glusterfs3.h" #include "compat-errno.h" #include "server-messages.h" +#include "server-helpers.h" #include "defaults.h" #include "fd.h" #include "xdr-nfs3.h" @@ -229,9 +230,9 @@ server_post_lk (xlator_t *this, gfs3_lk_rsp *rsp, struct gf_flock *lock) int server_post_readdir (gfs3_readdir_rsp *rsp, gf_dirent_t *entries) { - int ret = 0; + int ret = 0; - ret = serialize_rsp_dirent (entries, rsp); + ret = serialize_rsp_dirent (entries, rsp); return ret; } @@ -268,9 +269,9 @@ server_post_seek (gfs3_seek_rsp *rsp, off_t offset) int server_post_readdirp (gfs3_readdirp_rsp *rsp, gf_dirent_t *entries) { - int ret = 0; + int ret = 0; - ret = serialize_rsp_direntp (entries, rsp); + ret = serialize_rsp_direntp (entries, rsp); return ret; } @@ -512,3 +513,368 @@ server_post_lease (gfs3_lease_rsp *rsp, struct gf_lease *lease) { gf_proto_lease_from_lease (&rsp->lease, lease); } + + +/* Version 4 helpers */ + +void +server4_post_readlink (gfx_readlink_rsp *rsp, struct iatt *stbuf, + const char *buf) +{ + gfx_stat_from_iattx (&rsp->buf, stbuf); + rsp->path = (char *)buf; +} + +void +server4_post_common_3iatt (server_state_t *state, gfx_common_3iatt_rsp *rsp, + inode_t *inode, struct iatt *stbuf, + struct iatt *preparent, struct iatt *postparent) +{ + inode_t *link_inode = NULL; + + gfx_stat_from_iattx (&rsp->stat, stbuf); + if (state->client->subdir_mount && + !gf_uuid_compare (preparent->ia_gfid, + state->client->subdir_gfid)) { + /* This is very important as when we send iatt of + root-inode, fuse/client expect the gfid to be 1, + along with inode number. As for subdirectory mount, + we use inode table which is shared by everyone, but + make sure we send fops only from subdir and below, + we have to alter inode gfid and send it to client */ + uuid_t gfid = {0,}; + + gfid[15] = 1; + preparent->ia_ino = 1; + postparent->ia_ino = 1; + gf_uuid_copy (preparent->ia_gfid, gfid); + gf_uuid_copy (postparent->ia_gfid, gfid); + } + + gfx_stat_from_iattx (&rsp->preparent, preparent); + gfx_stat_from_iattx (&rsp->postparent, postparent); + + link_inode = inode_link (inode, state->loc.parent, + state->loc.name, stbuf); + inode_lookup (link_inode); + inode_unref (link_inode); +} + +void +server4_post_common_2iatt (gfx_common_2iatt_rsp *rsp, struct iatt *prebuf, + struct iatt *postbuf) +{ + gfx_stat_from_iattx (&rsp->prestat, prebuf); + gfx_stat_from_iattx (&rsp->poststat, postbuf); +} + +void +server4_post_entry_remove (server_state_t *state, gfx_common_2iatt_rsp *rsp, + struct iatt *prebuf, struct iatt *postbuf) +{ + inode_unlink (state->loc.inode, state->loc.parent, + state->loc.name); + /* parent should not be found for directories after + * inode_unlink, since directories cannot have + * hardlinks. + */ + forget_inode_if_no_dentry (state->loc.inode); + + gfx_stat_from_iattx (&rsp->prestat, prebuf); + gfx_stat_from_iattx (&rsp->poststat, postbuf); +} + + +void +server4_post_statfs (gfx_statfs_rsp *rsp, struct statvfs *stbuf) +{ + gf_statfs_from_statfs (&rsp->statfs, stbuf); +} + +void +server4_post_common_iatt (server_state_t *state, gfx_common_iatt_rsp *rsp, + struct iatt *stbuf) +{ + if (state->client->subdir_mount && + !gf_uuid_compare (stbuf->ia_gfid, + state->client->subdir_gfid)) { + /* This is very important as when we send iatt of + root-inode, fuse/client expect the gfid to be 1, + along with inode number. As for subdirectory mount, + we use inode table which is shared by everyone, but + make sure we send fops only from subdir and below, + we have to alter inode gfid and send it to client */ + uuid_t gfid = {0,}; + + gfid[15] = 1; + stbuf->ia_ino = 1; + gf_uuid_copy (stbuf->ia_gfid, gfid); + } + + gfx_stat_from_iattx (&rsp->stat, stbuf); +} + +void +server4_post_lk (xlator_t *this, gfx_lk_rsp *rsp, struct gf_flock *lock) +{ + switch (lock->l_type) { + case F_RDLCK: + lock->l_type = GF_LK_F_RDLCK; + break; + case F_WRLCK: + lock->l_type = GF_LK_F_WRLCK; + break; + case F_UNLCK: + lock->l_type = GF_LK_F_UNLCK; + break; + default: + gf_msg (this->name, GF_LOG_ERROR, 0, PS_MSG_LOCK_ERROR, + "Unknown lock type: %"PRId32"!", lock->l_type); + break; + } + + gf_proto_flock_from_flock (&rsp->flock, lock); +} + +int +server4_post_readdir (gfx_readdir_rsp *rsp, gf_dirent_t *entries) +{ + int ret = 0; + + ret = serialize_rsp_dirent_v2 (entries, rsp); + + return ret; +} + +void +server4_post_seek (gfx_seek_rsp *rsp, off_t offset) +{ + rsp->offset = offset; +} + +int +server4_post_readdirp (gfx_readdirp_rsp *rsp, gf_dirent_t *entries) +{ + int ret = 0; + + ret = serialize_rsp_direntp_v2 (entries, rsp); + + return ret; +} + +void +server4_post_rchecksum (gfx_rchecksum_rsp *rsp, uint32_t weak_checksum, + uint8_t *strong_checksum) +{ + rsp->weak_checksum = weak_checksum; + + rsp->strong_checksum.strong_checksum_val = (char *)strong_checksum; + rsp->strong_checksum.strong_checksum_len = SHA256_DIGEST_LENGTH; + +} + +void +server4_post_rename (call_frame_t *frame, + server_state_t *state, gfx_rename_rsp *rsp, + struct iatt *stbuf, + struct iatt *preoldparent, + struct iatt *postoldparent, + struct iatt *prenewparent, + struct iatt *postnewparent) +{ + inode_t *tmp_inode = NULL; + + stbuf->ia_type = state->loc.inode->ia_type; + + /* TODO: log gfid of the inodes */ + gf_msg_trace (frame->root->client->bound_xl->name, 0, "%"PRId64": " + "RENAME_CBK %s ==> %s", frame->root->unique, + state->loc.name, state->loc2.name); + + /* Before renaming the inode, we have to get the inode for the + * destination entry (i.e. inode with state->loc2.parent as + * parent and state->loc2.name as name). If it exists, then + * unlink that inode, and send forget on that inode if the + * unlinked entry is the last entry. In case of fuse client + * the fuse kernel module itself sends the forget on the + * unlinked inode. + */ + tmp_inode = inode_grep (state->loc.inode->table, + state->loc2.parent, state->loc2.name); + if (tmp_inode) { + inode_unlink (tmp_inode, state->loc2.parent, + state->loc2.name); + forget_inode_if_no_dentry (tmp_inode); + inode_unref (tmp_inode); + } + + inode_rename (state->itable, + state->loc.parent, state->loc.name, + state->loc2.parent, state->loc2.name, + state->loc.inode, stbuf); + gfx_stat_from_iattx (&rsp->stat, stbuf); + + gfx_stat_from_iattx (&rsp->preoldparent, preoldparent); + gfx_stat_from_iattx (&rsp->postoldparent, postoldparent); + + gfx_stat_from_iattx (&rsp->prenewparent, prenewparent); + gfx_stat_from_iattx (&rsp->postnewparent, postnewparent); + +} + +int +server4_post_open (call_frame_t *frame, xlator_t *this, + gfx_open_rsp *rsp, fd_t *fd) +{ + server_ctx_t *serv_ctx = NULL; + uint64_t fd_no = 0; + + serv_ctx = server_ctx_get (frame->root->client, this); + if (serv_ctx == NULL) { + gf_msg (this->name, GF_LOG_INFO, 0, + PS_MSG_SERVER_CTX_GET_FAILED, "server_ctx_get() " + "failed"); + return -1; + } + + fd_bind (fd); + fd_ref (fd); + fd_no = gf_fd_unused_get (serv_ctx->fdtable, fd); + rsp->fd = fd_no; + + return 0; +} + +void +server4_post_readv (gfx_read_rsp *rsp, struct iatt *stbuf, int op_ret) +{ + gfx_stat_from_iattx (&rsp->stat, stbuf); + rsp->size = op_ret; +} + +int +server4_post_create (call_frame_t *frame, gfx_create_rsp *rsp, + server_state_t *state, + xlator_t *this, fd_t *fd, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent) +{ + server_ctx_t *serv_ctx = NULL; + inode_t *link_inode = NULL; + uint64_t fd_no = 0; + int op_errno = 0; + + link_inode = inode_link (inode, state->loc.parent, + state->loc.name, stbuf); + + if (!link_inode) { + op_errno = ENOENT; + goto out; + } + + if (link_inode != inode) { + /* + VERY racy code (if used anywhere else) + -- don't do this without understanding + */ + + inode_ctx_merge (fd, fd->inode, link_inode); + inode_unref (fd->inode); + fd->inode = inode_ref (link_inode); + } + + inode_lookup (link_inode); + inode_unref (link_inode); + + serv_ctx = server_ctx_get (frame->root->client, this); + if (serv_ctx == NULL) { + gf_msg (this->name, GF_LOG_INFO, 0, + PS_MSG_SERVER_CTX_GET_FAILED, "server_ctx_get() " + "failed"); + goto out; + } + + fd_bind (fd); + fd_ref (fd); + fd_no = gf_fd_unused_get (serv_ctx->fdtable, fd); + + if ((fd_no > UINT64_MAX) || (fd == 0)) { + op_errno = errno; + } + + rsp->fd = fd_no; + gfx_stat_from_iattx (&rsp->stat, stbuf); + gfx_stat_from_iattx (&rsp->preparent, preparent); + gfx_stat_from_iattx (&rsp->postparent, postparent); + + return 0; +out: + return -op_errno; +} + +/*TODO: Handle revalidate path */ +void +server4_post_lookup (gfx_common_2iatt_rsp *rsp, call_frame_t *frame, + server_state_t *state, + inode_t *inode, struct iatt *stbuf) +{ + inode_t *root_inode = NULL; + inode_t *link_inode = NULL; + uuid_t rootgfid = {0,}; + + root_inode = frame->root->client->bound_xl->itable->root; + + if (!__is_root_gfid (inode->gfid)) { + link_inode = inode_link (inode, state->loc.parent, + state->loc.name, stbuf); + if (link_inode) { + inode_lookup (link_inode); + inode_unref (link_inode); + } + } + + if ((inode == root_inode) || + (state->client->subdir_mount && + (inode == state->client->subdir_inode))) { + /* we just looked up root ("/") OR + subdir mount directory, which is root ('/') in client */ + /* This is very important as when we send iatt of + root-inode, fuse/client expect the gfid to be 1, + along with inode number. As for subdirectory mount, + we use inode table which is shared by everyone, but + make sure we send fops only from subdir and below, + we have to alter inode gfid and send it to client */ + stbuf->ia_ino = 1; + rootgfid[15] = 1; + gf_uuid_copy (stbuf->ia_gfid, rootgfid); + if (inode->ia_type == 0) + inode->ia_type = stbuf->ia_type; + } + + gfx_stat_from_iattx (&rsp->prestat, stbuf); +} + +void +server4_post_lease (gfx_lease_rsp *rsp, struct gf_lease *lease) +{ + gf_proto_lease_from_lease (&rsp->lease, lease); +} + +void +server4_post_link (server_state_t *state, gfx_common_3iatt_rsp *rsp, + inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + inode_t *link_inode = NULL; + + gfx_stat_from_iattx (&rsp->stat, stbuf); + gfx_stat_from_iattx (&rsp->preparent, preparent); + gfx_stat_from_iattx (&rsp->postparent, postparent); + + link_inode = inode_link (inode, state->loc2.parent, + state->loc2.name, stbuf); + inode_lookup (link_inode); + inode_unref (link_inode); + +} diff --git a/xlators/protocol/server/src/server-common.h b/xlators/protocol/server/src/server-common.h index 3fa972e68db..e272235a192 100644 --- a/xlators/protocol/server/src/server-common.h +++ b/xlators/protocol/server/src/server-common.h @@ -135,3 +135,74 @@ server_post_lookup (gfs3_lookup_rsp *rsp, call_frame_t *frame, void server_post_lease (gfs3_lease_rsp *rsp, struct gf_lease *lease); + +void +server4_post_readlink (gfx_readlink_rsp *rsp, struct iatt *stbuf, + const char *buf); + +void +server4_post_statfs (gfx_statfs_rsp *rsp, struct statvfs *stbuf); + +void +server4_post_lk (xlator_t *this, gfx_lk_rsp *rsp, struct gf_flock *lock); + +int +server4_post_readdir (gfx_readdir_rsp *rsp, gf_dirent_t *entries); + +void +server4_post_seek (gfx_seek_rsp *rsp, off_t offset); + +int +server4_post_readdirp (gfx_readdirp_rsp *rsp, gf_dirent_t *entries); + +void +server4_post_rchecksum (gfx_rchecksum_rsp *rsp, uint32_t weak_checksum, + uint8_t *strong_checksum); + +void +server4_post_rename (call_frame_t *frame, server_state_t *state, + gfx_rename_rsp *rsp, + struct iatt *stbuf, + struct iatt *preoldparent, + struct iatt *postoldparent, + struct iatt *prenewparent, + struct iatt *postnewparent); + +int +server4_post_open (call_frame_t *frame, xlator_t *this, + gfx_open_rsp *rsp, fd_t *fd); +void +server4_post_readv (gfx_read_rsp *rsp, struct iatt *stbuf, int op_ret); + +int +server4_post_create (call_frame_t *frame, gfx_create_rsp *rsp, + server_state_t *state, + xlator_t *this, fd_t *fd, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent); + +void +server4_post_common_2iatt (gfx_common_2iatt_rsp *rsp, + struct iatt *stbuf1, struct iatt *stbuf2); + +void +server4_post_entry_remove (server_state_t *state, gfx_common_2iatt_rsp *rsp, + struct iatt *stbuf1, struct iatt *stbuf2); + +void +server4_post_common_3iatt (server_state_t *state, gfx_common_3iatt_rsp *rsp, + inode_t *inode, struct iatt *stbuf, struct iatt *pre, + struct iatt *post); +void +server4_post_common_iatt (server_state_t *state, gfx_common_iatt_rsp *rsp, + struct iatt *stbuf); +void +server4_post_lease (gfx_lease_rsp *rsp, struct gf_lease *lease); +void +server4_post_lookup (gfx_common_2iatt_rsp *rsp, call_frame_t *frame, + server_state_t *state, + inode_t *inode, struct iatt *stbuf); +void +server4_post_link (server_state_t *state, gfx_common_3iatt_rsp *rsp, + inode_t *inode, struct iatt *stbuf, struct iatt *pre, + struct iatt *post); diff --git a/xlators/protocol/server/src/server-helpers.c b/xlators/protocol/server/src/server-helpers.c index 1f9e9e8acb2..7a58d2592ba 100644 --- a/xlators/protocol/server/src/server-helpers.c +++ b/xlators/protocol/server/src/server-helpers.c @@ -925,6 +925,48 @@ out: int +serialize_rsp_direntp_v2 (gf_dirent_t *entries, gfx_readdirp_rsp *rsp) +{ + gf_dirent_t *entry = NULL; + gfx_dirplist *trav = NULL; + gfx_dirplist *prev = NULL; + int ret = -1; + + GF_VALIDATE_OR_GOTO ("server", entries, out); + GF_VALIDATE_OR_GOTO ("server", rsp, out); + + list_for_each_entry (entry, &entries->list, list) { + trav = GF_CALLOC (1, sizeof (*trav), gf_server_mt_dirent_rsp_t); + if (!trav) + goto out; + + trav->d_ino = entry->d_ino; + trav->d_off = entry->d_off; + trav->d_len = entry->d_len; + trav->d_type = entry->d_type; + trav->name = entry->d_name; + + gfx_stat_from_iattx (&trav->stat, &entry->d_stat); + dict_to_xdr (entry->dict, &trav->dict); + + if (prev) + prev->nextentry = trav; + else + rsp->reply = trav; + + prev = trav; + trav = NULL; + } + + ret = 0; +out: + GF_FREE (trav); + + return ret; +} + + +int serialize_rsp_dirent (gf_dirent_t *entries, gfs3_readdir_rsp *rsp) { gf_dirent_t *entry = NULL; @@ -932,8 +974,41 @@ serialize_rsp_dirent (gf_dirent_t *entries, gfs3_readdir_rsp *rsp) gfs3_dirlist *prev = NULL; int ret = -1; + GF_VALIDATE_OR_GOTO ("server", rsp, out); GF_VALIDATE_OR_GOTO ("server", entries, out); + + list_for_each_entry (entry, &entries->list, list) { + trav = GF_CALLOC (1, sizeof (*trav), gf_server_mt_dirent_rsp_t); + if (!trav) + goto out; + trav->d_ino = entry->d_ino; + trav->d_off = entry->d_off; + trav->d_len = entry->d_len; + trav->d_type = entry->d_type; + trav->name = entry->d_name; + if (prev) + prev->nextentry = trav; + else + rsp->reply = trav; + + prev = trav; + } + + ret = 0; +out: + return ret; +} + +int +serialize_rsp_dirent_v2 (gf_dirent_t *entries, gfx_readdir_rsp *rsp) +{ + gf_dirent_t *entry = NULL; + gfx_dirlist *trav = NULL; + gfx_dirlist *prev = NULL; + int ret = -1; + GF_VALIDATE_OR_GOTO ("server", rsp, out); + GF_VALIDATE_OR_GOTO ("server", entries, out); list_for_each_entry (entry, &entries->list, list) { trav = GF_CALLOC (1, sizeof (*trav), gf_server_mt_dirent_rsp_t); @@ -958,6 +1033,7 @@ out: } + int readdir_rsp_cleanup (gfs3_readdir_rsp *rsp) { @@ -995,16 +1071,51 @@ readdirp_rsp_cleanup (gfs3_readdirp_rsp *rsp) } int -serialize_rsp_locklist (lock_migration_info_t *locklist, - gfs3_getactivelk_rsp *rsp) +readdir_rsp_cleanup_v2 (gfx_readdir_rsp *rsp) +{ + gfx_dirlist *prev = NULL; + gfx_dirlist *trav = NULL; + + trav = rsp->reply; + prev = trav; + while (trav) { + trav = trav->nextentry; + GF_FREE (prev); + prev = trav; + } + + return 0; +} + + +int +readdirp_rsp_cleanup_v2 (gfx_readdirp_rsp *rsp) { + gfx_dirplist *prev = NULL; + gfx_dirplist *trav = NULL; + + trav = rsp->reply; + prev = trav; + while (trav) { + trav = trav->nextentry; + GF_FREE (prev->dict.pairs.pairs_val); + GF_FREE (prev); + prev = trav; + } + + return 0; +} + + +static int +common_rsp_locklist (lock_migration_info_t *locklist, + gfs3_locklist **reply) { lock_migration_info_t *tmp = NULL; gfs3_locklist *trav = NULL; gfs3_locklist *prev = NULL; int ret = -1; GF_VALIDATE_OR_GOTO ("server", locklist, out); - GF_VALIDATE_OR_GOTO ("server", rsp, out); list_for_each_entry (tmp, &locklist->list, list) { trav = GF_CALLOC (1, sizeof (*trav), gf_server_mt_lock_mig_t); @@ -1038,7 +1149,7 @@ serialize_rsp_locklist (lock_migration_info_t *locklist, if (prev) prev->nextentry = trav; else - rsp->reply = trav; + *reply = trav; prev = trav; trav = NULL; @@ -1051,6 +1162,30 @@ out: } int +serialize_rsp_locklist (lock_migration_info_t *locklist, + gfs3_getactivelk_rsp *rsp) +{ + int ret = 0; + + GF_VALIDATE_OR_GOTO ("server", rsp, out); + ret = common_rsp_locklist (locklist, &rsp->reply); +out: + return ret; +} +int +serialize_rsp_locklist_v2 (lock_migration_info_t *locklist, + gfx_getactivelk_rsp *rsp) +{ + int ret = 0; + + GF_VALIDATE_OR_GOTO ("server", rsp, out); + ret = common_rsp_locklist (locklist, &rsp->reply); +out: + return ret; +} + + +int getactivelkinfo_rsp_cleanup (gfs3_getactivelk_rsp *rsp) { gfs3_locklist *prev = NULL; @@ -1067,6 +1202,23 @@ getactivelkinfo_rsp_cleanup (gfs3_getactivelk_rsp *rsp) return 0; } +int +getactivelkinfo_rsp_cleanup_v2 (gfx_getactivelk_rsp *rsp) +{ + gfs3_locklist *prev = NULL; + gfs3_locklist *trav = NULL; + + trav = rsp->reply; + prev = trav; + + while (trav) { + trav = trav->nextentry; + GF_FREE (prev); + prev = trav; + } + + return 0; +} int gf_server_check_getxattr_cmd (call_frame_t *frame, const char *key) @@ -1360,6 +1512,43 @@ out: } int +unserialize_req_locklist_v2 (gfx_setactivelk_req *req, + lock_migration_info_t *lmi) +{ + struct gfs3_locklist *trav = NULL; + lock_migration_info_t *temp = NULL; + int ret = -1; + + trav = req->request; + + INIT_LIST_HEAD (&lmi->list); + + while (trav) { + temp = GF_CALLOC (1, sizeof (*lmi), gf_common_mt_lock_mig); + if (temp == NULL) { + gf_msg (THIS->name, GF_LOG_ERROR, 0, 0, "No memory"); + goto out; + } + + INIT_LIST_HEAD (&temp->list); + + gf_proto_flock_to_flock (&trav->flock, &temp->flock); + + temp->lk_flags = trav->lk_flags; + + temp->client_uid = gf_strdup (trav->client_uid); + + list_add_tail (&temp->list, &lmi->list); + + trav = trav->nextentry; + } + + ret = 0; +out: + return ret; +} + +int server_populate_compound_request (gfs3_compound_req *req, call_frame_t *frame, default_args_t *this_args, int index) @@ -4222,3 +4411,2027 @@ server_compound_req_cleanup (gfs3_compound_req *req, int len) return; } + +/* compound v2 */ +int +server_populate_compound_request_v2 (gfx_compound_req *req, call_frame_t *frame, + default_args_t *this_args, + int index) +{ + int op_errno = 0; + dict_t *xdata = NULL; + dict_t *xattr = NULL; + struct iovec req_iovec[MAX_IOVEC] = { {0,} }; + compound_req_v2 *this_req = NULL; + server_state_t *state = CALL_STATE (frame); + + this_req = &req->compound_req_array.compound_req_array_val[index]; + + switch (this_req->fop_enum) { + case GF_FOP_STAT: + { + gfx_stat_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_stat_req; + + xdr_to_dict (&args->xdata, &xdata); + args_stat_store (this_args, &state->loc, xdata); + break; + } + case GF_FOP_READLINK: + { + gfx_readlink_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_readlink_req; + + xdr_to_dict (&args->xdata, &xdata); + args_readlink_store (this_args, &state->loc, args->size, xdata); + break; + } + case GF_FOP_MKNOD: + { + gfx_mknod_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_mknod_req; + + xdr_to_dict (&args->xdata, &xdata); + args_mknod_store (this_args, &state->loc, args->mode, args->dev, + args->umask, xdata); + break; + } + case GF_FOP_MKDIR: + { + gfx_mkdir_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_mkdir_req; + + xdr_to_dict (&args->xdata, &xdata); + args_mkdir_store (this_args, &state->loc, args->mode, + args->umask, xdata); + break; + } + case GF_FOP_UNLINK: + { + gfx_unlink_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_unlink_req; + + xdr_to_dict (&args->xdata, &xdata); + args_unlink_store (this_args, &state->loc, args->xflags, xdata); + break; + } + case GF_FOP_RMDIR: + { + gfx_rmdir_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_rmdir_req; + + xdr_to_dict (&args->xdata, &xdata); + args_rmdir_store (this_args, &state->loc, args->xflags, xdata); + break; + } + case GF_FOP_SYMLINK: + { + gfx_symlink_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_symlink_req; + + xdr_to_dict (&args->xdata, &xdata); + args_symlink_store (this_args, args->linkname, &state->loc, + args->umask, xdata); + + this_args->loc.inode = inode_new (state->itable); + + break; + } + case GF_FOP_RENAME: + { + gfx_rename_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_rename_req; + + xdr_to_dict (&args->xdata, &xdata); + + args_rename_store (this_args, &state->loc, &state->loc2, xdata); + break; + } + case GF_FOP_LINK: + { + gfx_link_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_link_req; + + xdr_to_dict (&args->xdata, &xdata); + args_link_store (this_args, &state->loc, &state->loc2, xdata); + + this_args->loc2.inode = inode_ref (this_args->loc.inode); + + break; + } + case GF_FOP_TRUNCATE: + { + gfx_truncate_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_truncate_req; + + xdr_to_dict (&args->xdata, &xdata); + args_truncate_store (this_args, &state->loc, args->offset, + xdata); + break; + } + case GF_FOP_OPEN: + { + gfx_open_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_open_req; + + xdr_to_dict (&args->xdata, &xdata); + args_open_store (this_args, &state->loc, args->flags, state->fd, + xdata); + + this_args->fd = fd_create (this_args->loc.inode, + frame->root->pid); + this_args->fd->flags = this_args->flags; + + break; + } + case GF_FOP_READ: + { + gfx_read_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_read_req; + + xdr_to_dict (&args->xdata, &xdata); + args_readv_store (this_args, state->fd, args->size, + args->offset, args->flag, xdata); + break; + } + case GF_FOP_WRITE: + { + gfx_write_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_write_req; + + /*TODO : What happens when payload count is more than one? */ + req_iovec[0].iov_base = state->payload_vector[0].iov_base + + state->write_length; + req_iovec[0].iov_len = args->size; + + xdr_to_dict (&args->xdata, &xdata); + /* The way writev fop works : + * xdr args of write along with other args contains + * write length not count. But when the call is wound to posix, + * this length is not used. It is taken from the request + * write vector that is passed down. Posix needs the vector + * count to determine the amount of write to be done. + * This count for writes that come as part of compound fops + * will be 1. The vectors are merged into one under + * GF_FOP_WRITE section of client_handle_fop_requirements() + * in protocol client. + */ + args_writev_store (this_args, state->fd, req_iovec, 1, + args->offset, args->flag, state->iobref, + xdata); + state->write_length += req_iovec[0].iov_len; + break; + } + case GF_FOP_STATFS: + { + gfx_statfs_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_statfs_req; + + xdr_to_dict (&args->xdata, &xdata); + args_statfs_store (this_args, &state->loc, xdata); + break; + } + case GF_FOP_FLUSH: + { + gfx_flush_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_flush_req; + + xdr_to_dict (&args->xdata, &xdata); + args_flush_store (this_args, state->fd, xdata); + break; + } + case GF_FOP_FSYNC: + { + gfx_fsync_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fsync_req; + + xdr_to_dict (&args->xdata, &xdata); + args_fsync_store (this_args, state->fd, args->data, xdata); + break; + } + case GF_FOP_SETXATTR: + { + gfx_setxattr_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_setxattr_req; + + xdr_to_dict (&args->dict, &xattr); + xdr_to_dict (&args->xdata, &xdata); + args_setxattr_store (this_args, &state->loc, xattr, args->flags, + xdata); + break; + } + case GF_FOP_GETXATTR: + { + gfx_getxattr_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_getxattr_req; + + xdr_to_dict (&args->xdata, &xdata); + gf_server_check_getxattr_cmd (frame, args->name); + + args_getxattr_store (this_args, &state->loc, args->name, xdata); + break; + } + case GF_FOP_REMOVEXATTR: + { + gfx_removexattr_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_removexattr_req; + + xdr_to_dict (&args->xdata, &xdata); + args_removexattr_store (this_args, &state->loc, args->name, + xdata); + break; + } + case GF_FOP_OPENDIR: + { + gfx_opendir_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_opendir_req; + + this_args->fd = fd_create (this_args->loc.inode, + frame->root->pid); + if (!this_args->fd) { + gf_msg ("server", GF_LOG_ERROR, 0, + PS_MSG_FD_CREATE_FAILED, + "could not create the fd"); + goto out; + } + xdr_to_dict (&args->xdata, &xdata); + + args_opendir_store (this_args, &state->loc, state->fd, xdata); + break; + } + case GF_FOP_FSYNCDIR: + { + gfx_fsyncdir_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fsyncdir_req; + + xdr_to_dict (&args->xdata, &xdata); + args_fsyncdir_store (this_args, state->fd, args->data, xdata); + break; + } + case GF_FOP_ACCESS: + { + gfx_access_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_access_req; + + xdr_to_dict (&args->xdata, &xdata); + args_access_store (this_args, &state->loc, args->mask, xdata); + break; + } + case GF_FOP_CREATE: + { + gfx_create_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_create_req; + + state->loc.inode = inode_new (state->itable); + + state->fd = fd_create (state->loc.inode, frame->root->pid); + if (!state->fd) { + gf_msg ("server", GF_LOG_ERROR, 0, + PS_MSG_FD_CREATE_FAILED, + "fd creation for the inode %s failed", + state->loc.inode ? + uuid_utoa (state->loc.inode->gfid):NULL); + goto out; + } + state->fd->flags = state->flags; + + xdr_to_dict (&args->xdata, &xdata); + args_create_store (this_args, &state->loc, args->flags, + args->mode, args->umask, state->fd, xdata); + break; + } + case GF_FOP_FTRUNCATE: + { + gfx_ftruncate_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_ftruncate_req; + + xdr_to_dict (&args->xdata, &xdata); + args_ftruncate_store (this_args, state->fd, args->offset, + xdata); + break; + } + case GF_FOP_FSTAT: + { + gfx_fstat_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fstat_req; + + xdr_to_dict (&args->xdata, &xdata); + args_fstat_store (this_args, state->fd, xdata); + break; + } + case GF_FOP_LK: + { + gfx_lk_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_lk_req; + + xdr_to_dict (&args->xdata, &xdata); + + switch (args->cmd) { + case GF_LK_GETLK: + this_args->cmd = F_GETLK; + break; + case GF_LK_SETLK: + this_args->cmd = F_SETLK; + break; + case GF_LK_SETLKW: + this_args->cmd = F_SETLKW; + break; + case GF_LK_RESLK_LCK: + this_args->cmd = F_RESLK_LCK; + break; + case GF_LK_RESLK_LCKW: + this_args->cmd = F_RESLK_LCKW; + break; + case GF_LK_RESLK_UNLCK: + this_args->cmd = F_RESLK_UNLCK; + break; + case GF_LK_GETLK_FD: + this_args->cmd = F_GETLK_FD; + break; + } + + gf_proto_flock_to_flock (&args->flock, &this_args->lock); + + switch (args->type) { + case GF_LK_F_RDLCK: + this_args->lock.l_type = F_RDLCK; + break; + case GF_LK_F_WRLCK: + this_args->lock.l_type = F_WRLCK; + break; + case GF_LK_F_UNLCK: + this_args->lock.l_type = F_UNLCK; + break; + default: + gf_msg (frame->root->client->bound_xl->name, + GF_LOG_ERROR, + 0, PS_MSG_LOCK_ERROR, "fd - %"PRId64" (%s):" + " Unknown " + "lock type: %"PRId32"!", state->resolve.fd_no, + uuid_utoa (state->fd->inode->gfid), + args->type); + break; + } + args_lk_store (this_args, state->fd, this_args->cmd, + &this_args->lock, xdata); + break; + } + case GF_FOP_LOOKUP: + { + gfx_lookup_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_lookup_req; + + if (this_args->loc.inode) + this_args->loc.inode = server_inode_new (state->itable, + state->loc.gfid); + else + state->is_revalidate = 1; + + xdr_to_dict (&args->xdata, &xdata); + args_lookup_store (this_args, &state->loc, xdata); + break; + } + case GF_FOP_READDIR: + { + gfx_readdir_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_readdir_req; + + xdr_to_dict (&args->xdata, &xdata); + args_readdir_store (this_args, state->fd, args->size, + args->offset, xdata); + break; + } + case GF_FOP_INODELK: + { + gfx_inodelk_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_inodelk_req; + + switch (args->cmd) { + case GF_LK_GETLK: + this_args->cmd = F_GETLK; + break; + case GF_LK_SETLK: + this_args->cmd = F_SETLK; + break; + case GF_LK_SETLKW: + this_args->cmd = F_SETLKW; + break; + } + + gf_proto_flock_to_flock (&args->flock, &this_args->lock); + + switch (args->type) { + case GF_LK_F_RDLCK: + this_args->lock.l_type = F_RDLCK; + break; + case GF_LK_F_WRLCK: + this_args->lock.l_type = F_WRLCK; + break; + case GF_LK_F_UNLCK: + this_args->lock.l_type = F_UNLCK; + break; + } + + xdr_to_dict (&args->xdata, &xdata); + args_inodelk_store (this_args, args->volume, &state->loc, + this_args->cmd, &this_args->lock, xdata); + break; + } + case GF_FOP_FINODELK: + { + gfx_finodelk_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_finodelk_req; + + xdr_to_dict (&args->xdata, &xdata); + + switch (args->cmd) { + case GF_LK_GETLK: + this_args->cmd = F_GETLK; + break; + case GF_LK_SETLK: + this_args->cmd = F_SETLK; + break; + case GF_LK_SETLKW: + this_args->cmd = F_SETLKW; + break; + } + + gf_proto_flock_to_flock (&args->flock, &this_args->lock); + + switch (args->type) { + case GF_LK_F_RDLCK: + this_args->lock.l_type = F_RDLCK; + break; + case GF_LK_F_WRLCK: + this_args->lock.l_type = F_WRLCK; + break; + case GF_LK_F_UNLCK: + this_args->lock.l_type = F_UNLCK; + break; + } + args_finodelk_store (this_args, args->volume, state->fd, + this_args->cmd, &this_args->lock, xdata); + break; + } + case GF_FOP_ENTRYLK: + { + gfx_entrylk_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_entrylk_req; + + xdr_to_dict (&args->xdata, &xdata); + args_entrylk_store (this_args, args->volume, &state->loc, + args->name, args->cmd, args->type, xdata); + break; + } + case GF_FOP_FENTRYLK: + { + gfx_fentrylk_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fentrylk_req; + + xdr_to_dict (&args->xdata, &xdata); + args_fentrylk_store (this_args, args->volume, state->fd, + args->name, args->cmd, args->type, xdata); + break; + } + case GF_FOP_XATTROP: + { + gfx_xattrop_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_xattrop_req; + + xdr_to_dict (&args->dict, &xattr); + + xdr_to_dict (&args->xdata, &xdata); + args_xattrop_store (this_args, &state->loc, args->flags, + xattr, xdata); + break; + } + case GF_FOP_FXATTROP: + { + gfx_fxattrop_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fxattrop_req; + + xdr_to_dict (&args->dict, &xattr); + + xdr_to_dict (&args->xdata, &xdata); + + args_fxattrop_store (this_args, state->fd, args->flags, xattr, + xdata); + break; + } + case GF_FOP_FGETXATTR: + { + gfx_fgetxattr_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fgetxattr_req; + + xdr_to_dict (&args->xdata, &xdata); + + args_fgetxattr_store (this_args, state->fd, args->name, xdata); + break; + } + case GF_FOP_FSETXATTR: + { + gfx_fsetxattr_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fsetxattr_req; + + xdr_to_dict (&args->dict, &xattr); + + xdr_to_dict (&args->xdata, &xdata); + + args_fsetxattr_store (this_args, state->fd, xattr, args->flags, + xdata); + break; + } + case GF_FOP_RCHECKSUM: + { + gfx_rchecksum_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_rchecksum_req; + + xdr_to_dict (&args->xdata, &xdata); + + args_rchecksum_store (this_args, state->fd, args->offset, + args->len, xdata); + break; + } + case GF_FOP_SETATTR: + { + gfx_setattr_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_setattr_req; + + xdr_to_dict (&args->xdata, &xdata); + + gfx_stat_to_iattx (&args->stbuf, &this_args->stat); + + args_setattr_store (this_args, &state->loc, &this_args->stat, + args->valid, xdata); + break; + } + case GF_FOP_FSETATTR: + { + gfx_fsetattr_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fsetattr_req; + + xdr_to_dict (&args->xdata, &xdata); + + gfx_stat_to_iattx (&args->stbuf, &this_args->stat); + + args_fsetattr_store (this_args, state->fd, &this_args->stat, + args->valid, xdata); + break; + } + case GF_FOP_READDIRP: + { + gfx_readdirp_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_readdirp_req; + + xdr_to_dict (&args->xdata, &xdata); + + args_readdirp_store (this_args, state->fd, args->size, + args->offset, xattr); + break; + } + case GF_FOP_FREMOVEXATTR: + { + gfx_fremovexattr_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fremovexattr_req; + + xdr_to_dict (&args->xdata, &xdata); + + args_fremovexattr_store (this_args, state->fd, args->name, + xdata); + break; + } + case GF_FOP_FALLOCATE: + { + gfx_fallocate_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_fallocate_req; + + xdr_to_dict (&args->xdata, &xdata); + args_fallocate_store (this_args, state->fd, args->flags, + args->offset, args->size, xdata); + break; + } + case GF_FOP_DISCARD: + { + gfx_discard_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_discard_req; + + xdr_to_dict (&args->xdata, &xdata); + + args_discard_store (this_args, state->fd, args->offset, + args->size, xdata); + break; + } + case GF_FOP_ZEROFILL: + { + gfx_zerofill_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_zerofill_req; + + xdr_to_dict (&args->xdata, &xdata); + args_zerofill_store (this_args, state->fd, args->offset, + args->size, xdata); + break; + } + case GF_FOP_SEEK: + { + gfx_seek_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_seek_req; + + xdr_to_dict (&args->xdata, &xdata); + args_seek_store (this_args, state->fd, args->offset, args->what, + xdata); + break; + } + case GF_FOP_LEASE: + { + gfx_lease_req *args = NULL; + + args = &this_req->compound_req_v2_u.compound_lease_req; + + xdr_to_dict (&args->xdata, &xdata); + + gf_proto_lease_to_lease (&args->lease, &state->lease); + + args_lease_store (this_args, &state->loc, &state->lease, xdata); + break; + } + default: + return ENOTSUP; + } +out: + if (xattr) + dict_unref (xattr); + if (xdata) + dict_unref (xdata); + return op_errno; +} + +int +server_populate_compound_response_v2 (xlator_t *this, gfx_compound_rsp *rsp, + call_frame_t *frame, + compound_args_cbk_t *args_cbk, int index) +{ + int op_errno = EINVAL; + default_args_cbk_t *this_args_cbk = NULL; + compound_rsp_v2 *this_rsp = NULL; + server_state_t *state = NULL; + int ret = 0; + + state = CALL_STATE (frame); + this_rsp = &rsp->compound_rsp_array.compound_rsp_array_val[index]; + + this_args_cbk = &args_cbk->rsp_list[index]; + this_rsp->fop_enum = args_cbk->enum_list[index]; + + switch (this_rsp->fop_enum) { + case GF_FOP_FSTAT: + case GF_FOP_STAT: + { + gfx_common_iatt_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_stat_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + if (!this_args_cbk->op_ret) { + server4_post_common_iatt (state, rsp_args, + &this_args_cbk->stat); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_READLINK: + { + gfx_readlink_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_readlink_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + if (this_args_cbk->op_ret >= 0) { + server4_post_readlink (rsp_args, &this_args_cbk->stat, + this_args_cbk->buf); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + if (!rsp_args->path) + rsp_args->path = ""; + break; + } + case GF_FOP_MKNOD: + case GF_FOP_MKDIR: + case GF_FOP_SYMLINK: + case GF_FOP_LINK: + { + gfx_common_3iatt_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_mknod_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + if (!this_args_cbk->op_ret) { + server4_post_common_3iatt (state, rsp_args, + this_args_cbk->inode, + &this_args_cbk->stat, + &this_args_cbk->preparent, + &this_args_cbk->postparent); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_UNLINK: + case GF_FOP_RMDIR: + { + gfx_common_2iatt_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_unlink_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + if (!this_args_cbk->op_ret) { + server4_post_entry_remove (state, rsp_args, + &this_args_cbk->preparent, + &this_args_cbk->postparent); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_RENAME: + { + gfx_rename_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_rename_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + if (!this_args_cbk->op_ret) { + server4_post_rename (frame, state, rsp_args, + &this_args_cbk->stat, + &this_args_cbk->preparent, + &this_args_cbk->postparent, + &this_args_cbk->preparent2, + &this_args_cbk->postparent2); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_FALLOCATE: + case GF_FOP_ZEROFILL: + case GF_FOP_DISCARD: + case GF_FOP_SETATTR: + case GF_FOP_FSETATTR: + case GF_FOP_FTRUNCATE: + case GF_FOP_TRUNCATE: + case GF_FOP_WRITE: + case GF_FOP_FSYNC: + { + gfx_common_2iatt_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_truncate_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + if (!this_args_cbk->op_ret) { + server4_post_common_2iatt (rsp_args, + &this_args_cbk->prestat, + &this_args_cbk->poststat); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_OPEN: + case GF_FOP_OPENDIR: + { + gfx_open_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_open_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + if (!this_args_cbk->op_ret) { + server4_post_open (frame, this, rsp_args, + this_args_cbk->fd); + + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_READ: + { + gfx_read_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_read_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + if (this_args_cbk->op_ret >= 0) { + server4_post_readv (rsp_args, &this_args_cbk->stat, + this_args_cbk->op_ret); + + if (!state->rsp_iobref) { + state->rsp_iobref = this_args_cbk->iobref; + state->rsp_count = 0; + } + iobref_merge (state->rsp_iobref, + this_args_cbk->iobref); + memcpy (&state->rsp_vector[state->rsp_count], + this_args_cbk->vector, + (this_args_cbk->count * + sizeof(state->rsp_vector[0]))); + state->rsp_count += this_args_cbk->count; + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_STATFS: + { + gfx_statfs_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_statfs_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + if (!this_args_cbk->op_ret) { + server4_post_statfs (rsp_args, + &this_args_cbk->statvfs); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_FLUSH: + case GF_FOP_SETXATTR: + case GF_FOP_FSETXATTR: + case GF_FOP_REMOVEXATTR: + case GF_FOP_FREMOVEXATTR: + case GF_FOP_FSYNCDIR: + case GF_FOP_ACCESS: + case GF_FOP_INODELK: + case GF_FOP_FINODELK: + case GF_FOP_ENTRYLK: + case GF_FOP_FENTRYLK: + { + gfx_common_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_flush_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_FGETXATTR: + case GF_FOP_GETXATTR: + case GF_FOP_XATTROP: + case GF_FOP_FXATTROP: + { + gfx_common_dict_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_getxattr_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + if (-1 != this_args_cbk->op_ret) { + dict_to_xdr (this_args_cbk->xattr, &rsp_args->dict); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_CREATE: + { + gfx_create_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_create_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + + if (!this_args_cbk->op_ret) { + rsp_args->op_ret = server4_post_create (frame, + rsp_args, state, this, + this_args_cbk->fd, + this_args_cbk->inode, + &this_args_cbk->stat, + &this_args_cbk->preparent, + &this_args_cbk->postparent); + if (rsp_args->op_ret) { + rsp_args->op_errno = -rsp_args->op_ret; + rsp_args->op_ret = -1; + } + } + break; + } + case GF_FOP_LK: + { + gfx_lk_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_lk_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + if (!this_args_cbk->op_ret) { + server4_post_lk (this, rsp_args, &this_args_cbk->lock); + } + + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_LOOKUP: + { + gfx_common_2iatt_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_lookup_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + gfx_stat_from_iattx (&rsp_args->poststat, + &this_args_cbk->postparent); + + if (!this_args_cbk->op_ret) { + server4_post_lookup (rsp_args, frame, state, + this_args_cbk->inode, + &this_args_cbk->stat); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_READDIR: + { + gfx_readdir_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_readdir_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + + if (this_args_cbk->op_ret > 0) { + ret = server4_post_readdir (rsp_args, + &this_args_cbk->entries); + if (ret < 0) { + rsp_args->op_ret = ret; + rsp_args->op_errno = ENOMEM; + } + } + break; + } + case GF_FOP_RCHECKSUM: + { + gfx_rchecksum_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_rchecksum_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + if (!this_args_cbk->op_ret) { + server4_post_rchecksum (rsp_args, + this_args_cbk->weak_checksum, + this_args_cbk->strong_checksum); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_READDIRP: + { + gfx_readdirp_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_readdirp_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + if (this_args_cbk->op_ret > 0) { + ret = server4_post_readdirp (rsp_args, + &this_args_cbk->entries); + if (ret < 0) { + rsp_args->op_ret = ret; + rsp_args->op_errno = ENOMEM; + goto out; + } + gf_link_inodes_from_dirent (this, state->fd->inode, + &this_args_cbk->entries); + } + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_SEEK: + { + gfx_seek_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_seek_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + case GF_FOP_LEASE: + { + gfx_lease_rsp *rsp_args = NULL; + + rsp_args = &this_rsp->compound_rsp_v2_u.compound_lease_rsp; + + dict_to_xdr (this_args_cbk->xdata, &rsp_args->xdata); + + if (!this_args_cbk->op_ret) { + server4_post_lease (rsp_args, &this_args_cbk->lease); + } + + rsp_args->op_ret = this_args_cbk->op_ret; + rsp_args->op_errno = gf_errno_to_error + (this_args_cbk->op_errno); + break; + } + default: + return ENOTSUP; + } + op_errno = 0; +out: + return op_errno; +} +/* This works only when the compound fop acts on one loc/inode/gfid. + * If compound fops on more than one inode is required, multiple + * resolve and resumes will have to be done. This will have to change. + * Right now, multiple unlinks, rmdirs etc is are not supported. + * This can be added for future enhancements. + */ +int +server_get_compound_resolve_v2 (server_state_t *state, gfx_compound_req *req) +{ + int i = 0; + compound_req_v2 *array = NULL; + + array = &req->compound_req_array.compound_req_array_val[i]; + + switch (array->fop_enum) { + case GF_FOP_STAT: + { + gfx_stat_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_stat_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_READLINK: + { + gfx_readlink_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_readlink_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_MKNOD: + { + gfx_mknod_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_mknod_req; + + state->resolve.type = RESOLVE_NOT; + memcpy (state->resolve.pargfid, this_req.pargfid, 16); + state->resolve.bname = gf_strdup + (this_req.bname); + break; + } + case GF_FOP_MKDIR: + { + gfx_mkdir_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_mkdir_req; + + state->resolve.type = RESOLVE_NOT; + memcpy (state->resolve.pargfid, this_req.pargfid, 16); + state->resolve.bname = gf_strdup + (this_req.bname); + break; + } + case GF_FOP_UNLINK: + { + gfx_unlink_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_unlink_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.pargfid, this_req.pargfid, 16); + state->resolve.bname = gf_strdup + (this_req.bname); + break; + } + case GF_FOP_RMDIR: + { + gfx_rmdir_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_rmdir_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.pargfid, this_req.pargfid, 16); + state->resolve.bname = gf_strdup + (this_req.bname); + break; + } + case GF_FOP_SYMLINK: + { + gfx_symlink_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_symlink_req; + + state->resolve.type = RESOLVE_NOT; + memcpy (state->resolve.pargfid, this_req.pargfid, 16); + state->resolve.bname = gf_strdup + (this_req.bname); + break; + } + case GF_FOP_RENAME: + { + gfx_rename_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_rename_req; + + state->resolve.type = RESOLVE_MUST; + state->resolve.bname = gf_strdup + (this_req.oldbname); + memcpy (state->resolve.pargfid, this_req.oldgfid, 16); + + state->resolve2.type = RESOLVE_MAY; + state->resolve2.bname = gf_strdup + (this_req.newbname); + memcpy (state->resolve2.pargfid, this_req.newgfid, 16); + break; + } + case GF_FOP_LINK: + { + gfx_link_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_link_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, this_req.oldgfid, 16); + + state->resolve2.type = RESOLVE_NOT; + state->resolve2.bname = gf_strdup + (this_req.newbname); + memcpy (state->resolve2.pargfid, this_req.newgfid, 16); + break; + } + case GF_FOP_TRUNCATE: + { + gfx_truncate_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_truncate_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_OPEN: + { + gfx_open_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_open_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_READ: + { + gfx_read_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_read_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_WRITE: + { + gfx_write_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_write_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_STATFS: + { + gfx_statfs_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_statfs_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_FLUSH: + { + gfx_flush_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_flush_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_FSYNC: + { + gfx_fsync_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fsync_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_SETXATTR: + { + gfx_setxattr_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_setxattr_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_GETXATTR: + { + gfx_getxattr_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_getxattr_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_REMOVEXATTR: + { + gfx_removexattr_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_removexattr_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_OPENDIR: + { + gfx_opendir_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_opendir_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_FSYNCDIR: + { + gfx_fsyncdir_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fsyncdir_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_ACCESS: + { + gfx_access_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_access_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_CREATE: + { + gfx_create_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_create_req; + + state->flags = gf_flags_to_flags (this_req.flags); + if (state->flags & O_EXCL) { + state->resolve.type = RESOLVE_NOT; + } else { + state->resolve.type = RESOLVE_DONTCARE; + } + + memcpy (state->resolve.pargfid, this_req.pargfid, 16); + state->resolve.bname = gf_strdup + (this_req.bname); + break; + } + case GF_FOP_FTRUNCATE: + { + gfx_ftruncate_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_ftruncate_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_FSTAT: + { + gfx_fstat_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fstat_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_LK: + { + gfx_lk_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_lk_req; + + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_LOOKUP: + { + gfx_lookup_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_lookup_req; + state->resolve.type = RESOLVE_DONTCARE; + + if (this_req.bname && strcmp (this_req.bname, "")) { + memcpy (state->resolve.pargfid, this_req.pargfid, 16); + state->resolve.bname = gf_strdup + (this_req.bname); + } else { + memcpy (state->resolve.gfid, this_req.gfid, 16); + } + break; + } + case GF_FOP_READDIR: + { + gfx_readdir_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_readdir_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_INODELK: + { + gfx_inodelk_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_inodelk_req; + + state->resolve.type = RESOLVE_EXACT; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_FINODELK: + { + gfx_finodelk_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_finodelk_req; + + state->resolve.type = RESOLVE_EXACT; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_ENTRYLK: + { + gfx_entrylk_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_entrylk_req; + + state->resolve.type = RESOLVE_EXACT; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_FENTRYLK: + { + gfx_fentrylk_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fentrylk_req; + + state->resolve.type = RESOLVE_EXACT; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_XATTROP: + { + gfx_xattrop_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_xattrop_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_FXATTROP: + { + gfx_fxattrop_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fxattrop_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_FGETXATTR: + { + gfx_fgetxattr_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fgetxattr_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_FSETXATTR: + { + gfx_fsetxattr_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fsetxattr_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_RCHECKSUM: + { + gfx_rchecksum_req this_req = { {0,},}; + + this_req = array[i].compound_req_v2_u.compound_rchecksum_req; + + state->resolve.type = RESOLVE_MAY; + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_SETATTR: + { + gfx_setattr_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_setattr_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + break; + } + case GF_FOP_FSETATTR: + { + gfx_fsetattr_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fsetattr_req; + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_READDIRP: + { + gfx_readdirp_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_readdirp_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_FREMOVEXATTR: + { + gfx_fremovexattr_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fremovexattr_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_FALLOCATE: + { + gfx_fallocate_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_fallocate_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_DISCARD: + { + gfx_discard_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_discard_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_ZEROFILL: + { + gfx_zerofill_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_zerofill_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_SEEK: + { + gfx_seek_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_seek_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, + this_req.gfid, 16); + state->resolve.fd_no = this_req.fd; + break; + } + case GF_FOP_LEASE: + { + gfx_lease_req this_req = { {0,} }; + + this_req = array[i].compound_req_v2_u.compound_lease_req; + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, this_req.gfid, 16); + break; + } + default: + return ENOTSUP; + } + return 0; +} + +void +server_compound_rsp_cleanup_v2 (gfx_compound_rsp *rsp, compound_args_cbk_t *args) +{ + int i, len = 0; + compound_rsp_v2 *this_rsp = NULL; + + if (!rsp->compound_rsp_array.compound_rsp_array_val) + return; + + len = rsp->compound_rsp_array.compound_rsp_array_len; + + for (i = 0; i < len; i++) { + this_rsp = &rsp->compound_rsp_array.compound_rsp_array_val[i]; + switch (args->enum_list[i]) { + case GF_FOP_STAT: + SERVER4_FOP_RSP_CLEANUP (rsp, stat, i, common_iatt); + break; + case GF_FOP_MKNOD: + SERVER4_FOP_RSP_CLEANUP (rsp, mknod, i, common_3iatt); + break; + case GF_FOP_MKDIR: + SERVER4_FOP_RSP_CLEANUP (rsp, mkdir, i, common_3iatt); + break; + case GF_FOP_UNLINK: + SERVER4_FOP_RSP_CLEANUP (rsp, unlink, i, common_2iatt); + break; + case GF_FOP_RMDIR: + SERVER4_FOP_RSP_CLEANUP (rsp, rmdir, i, common_2iatt); + break; + case GF_FOP_SYMLINK: + SERVER4_FOP_RSP_CLEANUP (rsp, symlink, i, common_3iatt); + break; + case GF_FOP_RENAME: + SERVER4_FOP_RSP_CLEANUP (rsp, rename, i, rename); + break; + case GF_FOP_LINK: + SERVER4_FOP_RSP_CLEANUP (rsp, link, i, common_3iatt); + break; + case GF_FOP_TRUNCATE: + SERVER4_FOP_RSP_CLEANUP (rsp, truncate, i, common_2iatt); + break; + case GF_FOP_OPEN: + SERVER4_FOP_RSP_CLEANUP (rsp, open, i, open); + break; + case GF_FOP_READ: + SERVER4_FOP_RSP_CLEANUP (rsp, read, i, read); + break; + case GF_FOP_WRITE: + SERVER4_FOP_RSP_CLEANUP (rsp, write, i, common_2iatt); + break; + case GF_FOP_STATFS: + SERVER4_FOP_RSP_CLEANUP (rsp, statfs, i, statfs); + break; + case GF_FOP_FSYNC: + SERVER4_FOP_RSP_CLEANUP (rsp, fsync, i, common_2iatt); + break; + case GF_FOP_OPENDIR: + SERVER4_FOP_RSP_CLEANUP (rsp, opendir, i, open); + break; + case GF_FOP_CREATE: + SERVER4_FOP_RSP_CLEANUP (rsp, create, i, create); + break; + case GF_FOP_FTRUNCATE: + SERVER4_FOP_RSP_CLEANUP (rsp, ftruncate, i, common_2iatt); + break; + case GF_FOP_FSTAT: + SERVER4_FOP_RSP_CLEANUP (rsp, fstat, i, common_iatt); + break; + case GF_FOP_LK: + SERVER4_FOP_RSP_CLEANUP (rsp, lk, i, lk); + break; + case GF_FOP_LOOKUP: + SERVER4_FOP_RSP_CLEANUP (rsp, lookup, i, common_2iatt); + break; + case GF_FOP_SETATTR: + SERVER4_FOP_RSP_CLEANUP (rsp, setattr, i, common_2iatt); + break; + case GF_FOP_FSETATTR: + SERVER4_FOP_RSP_CLEANUP (rsp, fsetattr, i, common_2iatt); + break; + case GF_FOP_FALLOCATE: + SERVER4_FOP_RSP_CLEANUP (rsp, fallocate, i, common_2iatt); + break; + case GF_FOP_DISCARD: + SERVER4_FOP_RSP_CLEANUP (rsp, discard, i, common_2iatt); + break; + case GF_FOP_ZEROFILL: + SERVER4_FOP_RSP_CLEANUP (rsp, zerofill, i, common_2iatt); + break; + case GF_FOP_SEEK: + SERVER4_FOP_RSP_CLEANUP (rsp, seek, i, seek); + break; + case GF_FOP_LEASE: + SERVER4_FOP_RSP_CLEANUP (rsp, lease, i, lease); + break; + case GF_FOP_READLINK: + SERVER4_FOP_RSP_CLEANUP (rsp, readlink, i, readlink); + break; + case GF_FOP_RCHECKSUM: + SERVER4_FOP_RSP_CLEANUP (rsp, rchecksum, i, rchecksum); + break; + /* fops that use gfx_common_rsp */ + case GF_FOP_IPC: + SERVER4_COMMON_RSP_CLEANUP (rsp, ipc, i); + break; + case GF_FOP_FLUSH: + SERVER4_COMMON_RSP_CLEANUP (rsp, flush, i); + break; + case GF_FOP_SETXATTR: + SERVER4_COMMON_RSP_CLEANUP (rsp, setxattr, i); + break; + case GF_FOP_REMOVEXATTR: + SERVER4_COMMON_RSP_CLEANUP (rsp, removexattr, i); + break; + case GF_FOP_FSETXATTR: + SERVER4_COMMON_RSP_CLEANUP (rsp, fsetxattr, i); + break; + case GF_FOP_FREMOVEXATTR: + SERVER4_COMMON_RSP_CLEANUP (rsp, fremovexattr, i); + break; + case GF_FOP_FSYNCDIR: + SERVER4_COMMON_RSP_CLEANUP (rsp, fsyncdir, i); + break; + case GF_FOP_ACCESS: + SERVER4_COMMON_RSP_CLEANUP (rsp, access, i); + break; + case GF_FOP_INODELK: + SERVER4_COMMON_RSP_CLEANUP (rsp, inodelk, i); + break; + case GF_FOP_FINODELK: + SERVER4_COMMON_RSP_CLEANUP (rsp, finodelk, i); + break; + case GF_FOP_ENTRYLK: + SERVER4_COMMON_RSP_CLEANUP (rsp, entrylk, i); + break; + case GF_FOP_FENTRYLK: + SERVER4_COMMON_RSP_CLEANUP (rsp, fentrylk, i); + break; + /* fops that need extra cleanup */ + case GF_FOP_XATTROP: + { + gfx_common_dict_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, + xattrop); + SERVER4_FOP_RSP_CLEANUP (rsp, xattrop, i, common_dict); + GF_FREE (tmp_rsp->dict.pairs.pairs_val); + break; + } + case GF_FOP_FXATTROP: + { + gfx_common_dict_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, + fxattrop); + SERVER4_FOP_RSP_CLEANUP (rsp, fxattrop, i, common_dict); + GF_FREE (tmp_rsp->dict.pairs.pairs_val); + break; + } + case GF_FOP_READDIR: + { + gfx_readdir_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, + readdir); + SERVER4_FOP_RSP_CLEANUP (rsp, readdir, i, readdir); + readdir_rsp_cleanup_v2 (tmp_rsp); + break; + } + case GF_FOP_READDIRP: + { + gfx_readdirp_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, + readdirp); + SERVER4_FOP_RSP_CLEANUP (rsp, readdirp, i, readdirp); + readdirp_rsp_cleanup_v2 (tmp_rsp); + break; + } + case GF_FOP_GETXATTR: + { + gfx_common_dict_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, + getxattr); + SERVER4_FOP_RSP_CLEANUP (rsp, getxattr, i, common_dict); + GF_FREE (tmp_rsp->dict.pairs.pairs_val); + break; + } + case GF_FOP_FGETXATTR: + { + gfx_common_dict_rsp *tmp_rsp = &CPD4_RSP_FIELD(this_rsp, + fgetxattr); + SERVER4_FOP_RSP_CLEANUP (rsp, fgetxattr, i, common_dict); + GF_FREE (tmp_rsp->dict.pairs.pairs_val); + break; + } + default: + break; + } + } + GF_FREE (rsp->compound_rsp_array.compound_rsp_array_val); + return; +} + +void +server_compound_req_cleanup_v2 (gfx_compound_req *req, int len) +{ + int i = 0; + compound_req_v2 *curr_req = NULL; + + + if (!req->compound_req_array.compound_req_array_val) + return; + + for (i = 0; i < len; i++) { + curr_req = &req->compound_req_array.compound_req_array_val[i]; + + switch (curr_req->fop_enum) { + case GF_FOP_MKDIR: + { + gfx_mkdir_req *args = &CPD4_REQ_FIELD (curr_req, mkdir); + + free (args->bname); + break; + } + case GF_FOP_UNLINK: + { + gfx_unlink_req *args = &CPD4_REQ_FIELD (curr_req, + unlink); + free (args->bname); + break; + } + case GF_FOP_RMDIR: + { + gfx_rmdir_req *args = &CPD4_REQ_FIELD (curr_req, + rmdir); + free (args->bname); + break; + } + case GF_FOP_SYMLINK: + { + gfx_symlink_req *args = &CPD4_REQ_FIELD (curr_req, + symlink); + free (args->bname); + free (args->linkname); + break; + } + case GF_FOP_RENAME: + { + gfx_rename_req *args = &CPD4_REQ_FIELD (curr_req, + rename); + free (args->oldbname); + free (args->newbname); + break; + } + case GF_FOP_LINK: + { + gfx_link_req *args = &CPD4_REQ_FIELD (curr_req, + link); + free (args->newbname); + break; + } + case GF_FOP_GETXATTR: + { + gfx_getxattr_req *args = &CPD4_REQ_FIELD (curr_req, + getxattr); + + free (args->name); + break; + } + case GF_FOP_REMOVEXATTR: + { + gfx_removexattr_req *args = &CPD4_REQ_FIELD (curr_req, + removexattr); + + free (args->name); + break; + } + case GF_FOP_CREATE: + { + gfx_create_req *args = &CPD4_REQ_FIELD (curr_req, + create); + + free (args->bname); + break; + } + case GF_FOP_LK: + { + gfx_lk_req *args = &CPD4_REQ_FIELD (curr_req, lk); + free (args->flock.lk_owner.lk_owner_val); + break; + } + case GF_FOP_LOOKUP: + { + gfx_lookup_req *args = &CPD4_REQ_FIELD (curr_req, + lookup); + free (args->bname); + break; + } + case GF_FOP_INODELK: + { + gfx_inodelk_req *args = &CPD4_REQ_FIELD (curr_req, + inodelk); + + free (args->volume); + free (args->flock.lk_owner.lk_owner_val); + break; + } + case GF_FOP_FINODELK: + { + gfx_finodelk_req *args = &CPD4_REQ_FIELD (curr_req, + finodelk); + + free (args->volume); + free (args->flock.lk_owner.lk_owner_val); + break; + } + case GF_FOP_ENTRYLK: + { + gfx_entrylk_req *args = &CPD4_REQ_FIELD (curr_req, + entrylk); + + free (args->volume); + free (args->name); + break; + } + case GF_FOP_FENTRYLK: + { + gfx_fentrylk_req *args = &CPD4_REQ_FIELD (curr_req, + fentrylk); + + free (args->volume); + free (args->name); + break; + } + case GF_FOP_FGETXATTR: + { + gfx_fgetxattr_req *args = &CPD4_REQ_FIELD (curr_req, + fgetxattr); + + free (args->name); + break; + } + case GF_FOP_FREMOVEXATTR: + { + gfx_fremovexattr_req *args = &CPD4_REQ_FIELD(curr_req, + fremovexattr); + free (args->name); + break; + } + default: + break; + } + } + + return; +} diff --git a/xlators/protocol/server/src/server-helpers.h b/xlators/protocol/server/src/server-helpers.h index 1f47bc9dff1..9fe60fd231b 100644 --- a/xlators/protocol/server/src/server-helpers.h +++ b/xlators/protocol/server/src/server-helpers.h @@ -54,6 +54,8 @@ int serialize_rsp_dirent (gf_dirent_t *entries, gfs3_readdir_rsp *rsp); int serialize_rsp_direntp (gf_dirent_t *entries, gfs3_readdirp_rsp *rsp); int readdirp_rsp_cleanup (gfs3_readdirp_rsp *rsp); int readdir_rsp_cleanup (gfs3_readdir_rsp *rsp); +int readdirp_rsp_cleanup_v2 (gfx_readdirp_rsp *rsp); +int readdir_rsp_cleanup_v2 (gfx_readdir_rsp *rsp); int auth_set_username_passwd (dict_t *input_params, dict_t *config_params, struct _client *client); @@ -65,10 +67,15 @@ server_inode_new (inode_table_t *itable, uuid_t gfid); int serialize_rsp_locklist (lock_migration_info_t *locklist, - gfs3_getactivelk_rsp *rsp); + gfs3_getactivelk_rsp *rsp); +int +serialize_rsp_locklist_v2 (lock_migration_info_t *locklist, + gfx_getactivelk_rsp *rsp); int getactivelkinfo_rsp_cleanup (gfs3_getactivelk_rsp *rsp); +int +getactivelkinfo_rsp_cleanup_v2 (gfx_getactivelk_rsp *rsp); int server_populate_compound_response (xlator_t *this, gfs3_compound_rsp *rsp, @@ -86,4 +93,43 @@ server_compound_rsp_cleanup (gfs3_compound_rsp *rsp, compound_args_cbk_t *args); void server_compound_req_cleanup (gfs3_compound_req *req, int len); + +int +unserialize_req_locklist (gfs3_setactivelk_req *req, + lock_migration_info_t *lmi); + +int +unserialize_req_locklist_v2 (gfx_setactivelk_req *req, + lock_migration_info_t *lmi); + +int +serialize_rsp_dirent (gf_dirent_t *entries, gfs3_readdir_rsp *rsp); + +int +serialize_rsp_direntp (gf_dirent_t *entries, gfs3_readdirp_rsp *rsp); + +int +serialize_rsp_dirent_v2 (gf_dirent_t *entries, gfx_readdir_rsp *rsp); + +int +serialize_rsp_direntp_v2 (gf_dirent_t *entries, gfx_readdirp_rsp *rsp); + +int +server_populate_compound_response_v2 (xlator_t *this, gfx_compound_rsp *rsp, + call_frame_t *frame, + compound_args_cbk_t *args_cbk, int index); +int +server_get_compound_resolve_v2 (server_state_t *state, gfx_compound_req *req); + +int +server_populate_compound_request_v2 (gfx_compound_req *req, call_frame_t *frame, + default_args_t *this_args, + int index); +void +server_compound_rsp_cleanup_v2 (gfx_compound_rsp *rsp, compound_args_cbk_t *args); + +void +server_compound_req_cleanup_v2 (gfx_compound_req *req, int len); + + #endif /* !_SERVER_HELPERS_H */ diff --git a/xlators/protocol/server/src/server-rpc-fops.c b/xlators/protocol/server/src/server-rpc-fops.c index 1b87abaafda..7f2bd5e0312 100644 --- a/xlators/protocol/server/src/server-rpc-fops.c +++ b/xlators/protocol/server/src/server-rpc-fops.c @@ -46,7 +46,7 @@ forget_inode_if_no_dentry (inode_t *inode) return; } -static void +void set_resolve_gfid (client_t *client, uuid_t resolve_gfid, char *on_wire_gfid) { @@ -882,7 +882,7 @@ out: } /* print every key */ -static int +int _gf_server_log_setxattr_failure (dict_t *d, char *k, data_t *v, void *tmp) { @@ -2207,97 +2207,6 @@ out: return 0; } -int -server_namelink_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) -{ - gfs4_namelink_rsp rsp = {0,}; - rpcsvc_request_t *req = NULL; - - GF_PROTOCOL_DICT_SERIALIZE (this, xdata, &rsp.xdata.xdata_val, - rsp.xdata.xdata_len, op_errno, out); - - if (op_ret < 0) - goto out; - - gf_stat_from_iatt (&rsp.preparent, prebuf); - gf_stat_from_iatt (&rsp.postparent, postbuf); - - /** - * no point in linking inode here -- there's no stbuf anyway and a - * lookup() for this name entry would be a negative lookup. - */ - -out: - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - req = frame->local; - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gfs4_namelink_rsp); - - GF_FREE (rsp.xdata.xdata_val); - - return 0; -} - -int -server_icreate_cbk (call_frame_t *frame, - void *cookie, xlator_t *this, - int32_t op_ret, int32_t op_errno, - inode_t *inode, struct iatt *stbuf, dict_t *xdata) -{ - server_state_t *state = NULL; - inode_t *link_inode = NULL; - rpcsvc_request_t *req = NULL; - gfs3_create_rsp rsp = {0,}; - - GF_PROTOCOL_DICT_SERIALIZE (this, xdata, &rsp.xdata.xdata_val, - rsp.xdata.xdata_len, op_errno, out); - - state = CALL_STATE (frame); - - if (op_ret < 0) { - gf_msg (this->name, GF_LOG_INFO, op_errno, PS_MSG_CREATE_INFO, - "%"PRId64": ICREATE [%s] ==> (%s)", - frame->root->unique, uuid_utoa (state->resolve.gfid), - strerror (op_errno)); - goto out; - } - - gf_msg_trace (frame->root->client->bound_xl->name, 0, "%"PRId64": " - "ICREATE [%s]", frame->root->unique, - uuid_utoa (stbuf->ia_gfid)); - - link_inode = inode_link (inode, - state->loc.parent, state->loc.name, stbuf); - - if (!link_inode) { - op_ret = -1; - op_errno = ENOENT; - goto out; - } - - inode_lookup (link_inode); - inode_unref (link_inode); - - gf_stat_from_iatt (&rsp.stat, stbuf); - -out: - rsp.op_ret = op_ret; - rsp.op_errno = gf_errno_to_error (op_errno); - - req = frame->local; - server_submit_reply (frame, req, &rsp, NULL, 0, NULL, - (xdrproc_t)xdr_gfs4_icreate_rsp); - - GF_FREE (rsp.xdata.xdata_val); - - return 0; -} - /* Resume function section */ int @@ -3543,56 +3452,8 @@ err: return ret; } -int -server_namelink_resume (call_frame_t *frame, xlator_t *bound_xl) -{ - server_state_t *state = NULL; - - state = CALL_STATE (frame); - - if (state->resolve.op_ret != 0) - goto err; - - state->loc.inode = inode_new (state->itable); - - STACK_WIND (frame, server_namelink_cbk, - bound_xl, bound_xl->fops->namelink, - &(state->loc), state->xdata); - return 0; - - err: - server_namelink_cbk (frame, NULL, - frame->this, - state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL); - return 0; -} - -int -server_icreate_resume (call_frame_t *frame, xlator_t *bound_xl) -{ - server_state_t *state = NULL; - - state = CALL_STATE (frame); - - if (state->resolve.op_ret != 0) - goto err; - - state->loc.inode = inode_new (state->itable); - - STACK_WIND (frame, server_icreate_cbk, - bound_xl, bound_xl->fops->icreate, - &(state->loc), state->mode, state->xdata); - - return 0; -err: - server_icreate_cbk (frame, NULL, frame->this, state->resolve.op_ret, - state->resolve.op_errno, NULL, NULL, NULL); - return 0; -} - /* Fop section */ -static inline int +int rpc_receive_common (rpcsvc_request_t *req, call_frame_t **fr, server_state_t **st, ssize_t *xdrlen, void *args, void *xdrfn, glusterfs_fop_t fop) @@ -6228,186 +6089,6 @@ out: return ret; } -int -server3_3_namelink (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs4_namelink_req args = {{0,},}; - int ret = -1; - int op_errno = 0; - - if (!req) - return ret; - - ret = rpc_receive_common (req, &frame, &state, NULL, &args, - xdr_gfs4_namelink_req, GF_FOP_NAMELINK); - - if (ret != 0) - goto out; - - state->resolve.bname = gf_strdup (args.bname); - memcpy (state->resolve.pargfid, args.pargfid, sizeof (uuid_t)); - - state->resolve.type = RESOLVE_NOT; - - /* TODO: can do alloca for xdata field instead of stdalloc */ - GF_PROTOCOL_DICT_UNSERIALIZE (frame->root->client->bound_xl, - state->xdata, - args.xdata.xdata_val, - args.xdata.xdata_len, ret, - op_errno, out); - - ret = 0; - resolve_and_resume (frame, server_namelink_resume); - -out: - /* memory allocated by libc, don't use GF_FREE */ - free (args.xdata.xdata_val); - - if (op_errno) - SERVER_REQ_SET_ERROR (req, ret); - - return ret; - -} - -int -server3_3_icreate (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs4_icreate_req args = {{0,},}; - int ret = -1; - int op_errno = 0; - uuid_t gfid = {0,}; - - if (!req) - return ret; - - ret = rpc_receive_common (req, &frame, &state, NULL, &args, - xdr_gfs4_icreate_req, GF_FOP_ICREATE); - - if (ret != 0) - goto out; - - memcpy (gfid, args.gfid, sizeof (uuid_t)); - - state->mode = args.mode; - gf_asprintf (&state->resolve.bname, INODE_PATH_FMT, uuid_utoa (gfid)); - - /* parent is an auxillary inode number */ - memset (state->resolve.pargfid, 0, sizeof (uuid_t)); - state->resolve.pargfid[15] = GF_AUXILLARY_PARGFID; - - state->resolve.type = RESOLVE_NOT; - - /* TODO: can do alloca for xdata field instead of stdalloc */ - GF_PROTOCOL_DICT_UNSERIALIZE (frame->root->client->bound_xl, - state->xdata, - args.xdata.xdata_val, - args.xdata.xdata_len, ret, - op_errno, out); - - ret = 0; - resolve_and_resume (frame, server_icreate_resume); - -out: - /* memory allocated by libc, don't use GF_FREE */ - free (args.xdata.xdata_val); - - if (op_errno) - SERVER_REQ_SET_ERROR (req, ret); - - return ret; -} - -int -server4_0_fsetattr (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_fsetattr_req_v2 args = {{0},}; - int ret = -1; - int op_errno = 0; - - if (!req) - return ret; - - ret = rpc_receive_common (req, &frame, &state, NULL, &args, - xdr_gfs3_fsetattr_req_v2, - GF_FOP_FSETATTR); - if (ret != 0) { - goto out; - } - - state->resolve.type = RESOLVE_MUST; - state->resolve.fd_no = args.fd; - memcpy (state->resolve.gfid, args.gfid, 16); - - gf_stat_to_iatt (&args.stbuf, &state->stbuf); - state->valid = args.valid; - - GF_PROTOCOL_DICT_UNSERIALIZE (frame->root->client->bound_xl, - state->xdata, (args.xdata.xdata_val), - (args.xdata.xdata_len), ret, - op_errno, out); - - ret = 0; - resolve_and_resume (frame, server_fsetattr_resume); - -out: - free (args.xdata.xdata_val); - - if (op_errno) - SERVER_REQ_SET_ERROR (req, ret); - - return ret; -} - -int -server4_0_rchecksum (rpcsvc_request_t *req) -{ - server_state_t *state = NULL; - call_frame_t *frame = NULL; - gfs3_rchecksum_req_v2 args = {{0},}; - int ret = -1; - int op_errno = 0; - - if (!req) - return ret; - - ret = rpc_receive_common (req, &frame, &state, NULL, &args, - xdr_gfs3_rchecksum_req_v2, - GF_FOP_RCHECKSUM); - if (ret != 0) { - goto out; - } - - state->resolve.type = RESOLVE_MAY; - state->resolve.fd_no = args.fd; - state->offset = args.offset; - state->size = args.len; - - memcpy (state->resolve.gfid, args.gfid, 16); - - GF_PROTOCOL_DICT_UNSERIALIZE (frame->root->client->bound_xl, - state->xdata, (args.xdata.xdata_val), - (args.xdata.xdata_len), ret, - op_errno, out); - - ret = 0; - resolve_and_resume (frame, server_rchecksum_resume); -out: - free (args.xdata.xdata_val); - - if (op_errno) - SERVER_REQ_SET_ERROR (req, ret); - - return ret; -} - - rpcsvc_actor_t glusterfs3_3_fop_actors[GLUSTER_FOP_PROCCNT] = { [GFS3_OP_NULL] = {"NULL", GFS3_OP_NULL, server_null, NULL, 0, DRC_NA}, @@ -6513,9 +6194,9 @@ rpcsvc_actor_t glusterfs4_0_fop_actors[] = { [GFS3_OP_FXATTROP] = { "FXATTROP", GFS3_OP_FXATTROP, server3_3_fxattrop, NULL, 0}, [GFS3_OP_FGETXATTR] = { "FGETXATTR", GFS3_OP_FGETXATTR, server3_3_fgetxattr, NULL, 0}, [GFS3_OP_FSETXATTR] = { "FSETXATTR", GFS3_OP_FSETXATTR, server3_3_fsetxattr, NULL, 0}, - [GFS3_OP_RCHECKSUM] = { "RCHECKSUM", GFS3_OP_RCHECKSUM, server4_0_rchecksum, NULL, 0}, + [GFS3_OP_RCHECKSUM] = { "RCHECKSUM", GFS3_OP_RCHECKSUM, server3_3_rchecksum, NULL, 0}, [GFS3_OP_SETATTR] = { "SETATTR", GFS3_OP_SETATTR, server3_3_setattr, NULL, 0}, - [GFS3_OP_FSETATTR] = { "FSETATTR", GFS3_OP_FSETATTR, server4_0_fsetattr, NULL, 0}, + [GFS3_OP_FSETATTR] = { "FSETATTR", GFS3_OP_FSETATTR, server3_3_fsetattr, NULL, 0}, [GFS3_OP_READDIRP] = { "READDIRP", GFS3_OP_READDIRP, server3_3_readdirp, NULL, 0}, [GFS3_OP_RELEASE] = { "RELEASE", GFS3_OP_RELEASE, server3_3_release, NULL, 0}, [GFS3_OP_RELEASEDIR] = { "RELEASEDIR", GFS3_OP_RELEASEDIR, server3_3_releasedir, NULL, 0}, @@ -6529,8 +6210,6 @@ rpcsvc_actor_t glusterfs4_0_fop_actors[] = { [GFS3_OP_GETACTIVELK] = {"GETACTIVELK", GFS3_OP_GETACTIVELK, server3_3_getactivelk, NULL, 0, DRC_NA}, [GFS3_OP_SETACTIVELK] = {"SETACTIVELK", GFS3_OP_SETACTIVELK, server3_3_setactivelk, NULL, 0, DRC_NA}, [GFS3_OP_COMPOUND] = {"COMPOUND", GFS3_OP_COMPOUND, server3_3_compound, NULL, 0, DRC_NA}, - [GFS3_OP_ICREATE] = {"ICREATE", GFS3_OP_ICREATE, server3_3_icreate, NULL, 0, DRC_NA}, - [GFS3_OP_NAMELINK] = {"NAMELINK", GFS3_OP_NAMELINK, server3_3_namelink, NULL, 0, DRC_NA}, }; diff --git a/xlators/protocol/server/src/server-rpc-fops_v2.c b/xlators/protocol/server/src/server-rpc-fops_v2.c new file mode 100644 index 00000000000..dca88ab85f5 --- /dev/null +++ b/xlators/protocol/server/src/server-rpc-fops_v2.c @@ -0,0 +1,5859 @@ +/* + Copyright (c) 2017 Red Hat, Inc. <http://www.redhat.com> + This file is part of GlusterFS. + + This file is licensed to you under your choice of the GNU Lesser + General Public License, version 3 or any later version (LGPLv3 or + later), or the GNU General Public License, version 2 (GPLv2), in all + cases as published by the Free Software Foundation. +*/ + +#include <openssl/md5.h> + +#include "server.h" +#include "server-helpers.h" +#include "rpc-common-xdr.h" +#include "glusterfs4-xdr.h" +#include "glusterfs3.h" +#include "compat-errno.h" +#include "server-messages.h" +#include "defaults.h" +#include "default-args.h" +#include "server-common.h" +#include "xlator.h" +#include "compound-fop-utils.h" + +#include "xdr-nfs3.h" + +#define SERVER_REQ_SET_ERROR(req, ret) \ + do { \ + rpcsvc_request_seterr (req, GARBAGE_ARGS); \ + ret = RPCSVC_ACTOR_ERROR; \ + } while (0) + +extern int +server3_3_getxattr (rpcsvc_request_t *req); +extern int +server3_3_fgetxattr (rpcsvc_request_t *req); +extern int +server3_3_setxattr (rpcsvc_request_t *req); +extern int +server3_3_fsetxattr (rpcsvc_request_t *req); +extern int +server3_3_xattrop (rpcsvc_request_t *req); +extern int +server3_3_fxattrop (rpcsvc_request_t *req); + +extern void +set_resolve_gfid (client_t *client, uuid_t resolve_gfid, + char *on_wire_gfid); +extern int +_gf_server_log_setxattr_failure (dict_t *d, char *k, data_t *v, + void *tmp); +extern int +rpc_receive_common (rpcsvc_request_t *req, call_frame_t **fr, + server_state_t **st, ssize_t *xdrlen, void *args, + void *xdrfn, glusterfs_fop_t fop); + + +/* Callback function section */ +int +server4_statfs_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct statvfs *buf, + dict_t *xdata) +{ + gfx_statfs_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + gf_msg (this->name, GF_LOG_WARNING, op_errno, PS_MSG_STATFS, + "%"PRId64": STATFS, client: %s, error-xlator: %s", + frame->root->unique, STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_statfs (&rsp, buf); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_statfs_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_lookup_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + inode_t *inode, struct iatt *stbuf, dict_t *xdata, + struct iatt *postparent) +{ + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + loc_t fresh_loc = {0,}; + gfx_common_2iatt_rsp rsp = {0,}; + + state = CALL_STATE (frame); + + if (state->is_revalidate == 1 && op_ret == -1) { + state->is_revalidate = 2; + loc_copy (&fresh_loc, &state->loc); + inode_unref (fresh_loc.inode); + fresh_loc.inode = server_inode_new (state->itable, + fresh_loc.gfid); + + STACK_WIND (frame, server4_lookup_cbk, + frame->root->client->bound_xl, + frame->root->client->bound_xl->fops->lookup, + &fresh_loc, state->xdata); + + loc_wipe (&fresh_loc); + return 0; + } + + gfx_stat_from_iattx (&rsp.poststat, postparent); + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + if (state->is_revalidate && op_errno == ENOENT) { + if (!__is_root_gfid (state->resolve.gfid)) { + inode_unlink (state->loc.inode, + state->loc.parent, + state->loc.name); + /** + * If the entry is not present, then just + * unlinking the associated dentry is not + * suffecient. This condition should be + * treated as unlink of the entry. So along + * with deleting the entry, its also important + * to forget the inode for it (if the dentry + * being considered was the last dentry). + * Otherwise it might lead to inode leak. + * It also might lead to wrong decisions being + * taken if the future lookups on this inode are + * successful since they are able to find the + * inode in the inode table (atleast gfid based + * lookups will be successful, if the lookup + * is a soft lookup) + */ + forget_inode_if_no_dentry (state->loc.inode); + } + } + goto out; + } + + server4_post_lookup (&rsp, frame, state, inode, stbuf); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + if (op_ret) { + if (state->resolve.bname) { + gf_msg (this->name, + fop_log_level (GF_FOP_LOOKUP, op_errno), + op_errno, PS_MSG_LOOKUP_INFO, + "%"PRId64": LOOKUP %s (%s/%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, + uuid_utoa (state->resolve.pargfid), + state->resolve.bname, + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + } else { + gf_msg (this->name, + fop_log_level (GF_FOP_LOOKUP, op_errno), + op_errno, PS_MSG_LOOKUP_INFO, + "%"PRId64": LOOKUP %s (%s), client: %s, " + "error-xlator: %s", + frame->root->unique, state->loc.path, + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + } + } + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_lease_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct gf_lease *lease, + dict_t *xdata) +{ + gfx_lease_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_LEASE, op_errno), + op_errno, PS_MSG_LK_INFO, + "%"PRId64": LEASE %s (%s), client: %s, error-xlator: %s", + frame->root->unique, state->loc.path, + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + server4_post_lease (&rsp, lease); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_lease_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_lk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct gf_flock *lock, + dict_t *xdata) +{ + gfx_lk_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_LK, op_errno), + op_errno, PS_MSG_LK_INFO, + "%"PRId64": LK %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_lk (this, &rsp, lock); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_lk_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_inodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret < 0) { + gf_msg (this->name, fop_log_level (GF_FOP_INODELK, op_errno), + op_errno, PS_MSG_INODELK_INFO, + "%"PRId64": INODELK %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_finodelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret < 0) { + gf_msg (this->name, fop_log_level (GF_FOP_FINODELK, op_errno), + op_errno, PS_MSG_INODELK_INFO, + "%"PRId64": FINODELK %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_entrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret < 0) { + gf_msg (this->name, fop_log_level (GF_FOP_ENTRYLK, op_errno), + op_errno, PS_MSG_ENTRYLK_INFO, + "%"PRId64": ENTRYLK %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_fentrylk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret < 0) { + gf_msg (this->name, fop_log_level (GF_FOP_FENTRYLK, op_errno), + op_errno, PS_MSG_ENTRYLK_INFO, + "%"PRId64": FENTRYLK %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_access_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + state = CALL_STATE (frame); + gf_msg (this->name, GF_LOG_INFO, + op_errno, PS_MSG_ACCESS_INFO, + "%"PRId64": ACCESS %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + (state->loc.path) ? state->loc.path : "", + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_rmdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret) { + gf_msg (this->name, GF_LOG_INFO, + op_errno, PS_MSG_DIR_INFO, + "%"PRId64": RMDIR %s (%s/%s), client: %s, " + "error-xlator: %s", frame->root->unique, + (state->loc.path) ? state->loc.path : "", + uuid_utoa (state->resolve.pargfid), + state->resolve.bname, STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_entry_remove (state, &rsp, preparent, postparent); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_mkdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + gfx_common_3iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret < 0) { + gf_msg (this->name, fop_log_level (GF_FOP_MKDIR, op_errno), + op_errno, PS_MSG_DIR_INFO, + "%"PRId64": MKDIR %s (%s/%s) client: %s, " + "error-xlator: %s", frame->root->unique, + (state->loc.path) ? state->loc.path : "", + uuid_utoa (state->resolve.pargfid), + state->resolve.bname, + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_3iatt (state, &rsp, inode, stbuf, preparent, + postparent); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_3iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_mknod_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + inode_t *inode, struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + gfx_common_3iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret < 0) { + gf_msg (this->name, fop_log_level (GF_FOP_MKNOD, op_errno), + op_errno, PS_MSG_MKNOD_INFO, + "%"PRId64": MKNOD %s (%s/%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.pargfid), + state->resolve.bname, STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_3iatt (state, &rsp, inode, stbuf, preparent, + postparent); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_3iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_fsyncdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_FSYNCDIR, op_errno), + op_errno, PS_MSG_DIR_INFO, + "%"PRId64": FSYNCDIR %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_readdir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) +{ + gfx_readdir_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + int ret = 0; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_READDIR, op_errno), + op_errno, PS_MSG_DIR_INFO, + "%"PRId64": READDIR %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + /* (op_ret == 0) is valid, and means EOF */ + if (op_ret) { + ret = server4_post_readdir (&rsp, entries); + if (ret == -1) { + op_ret = -1; + op_errno = ENOMEM; + goto out; + } + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_readdir_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + readdir_rsp_cleanup_v2 (&rsp); + + return 0; +} + +int +server4_opendir_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) +{ + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + gfx_open_rsp rsp = {0,}; + uint64_t fd_no = 0; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_OPENDIR, op_errno), + op_errno, PS_MSG_DIR_INFO, + "%"PRId64": OPENDIR %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + (state->loc.path) ? state->loc.path : "", + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + + op_ret = server4_post_open (frame, this, &rsp, fd); + if (op_ret) + goto out; +out: + if (op_ret) + rsp.fd = fd_no; + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_open_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_removexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + gf_loglevel_t loglevel = GF_LOG_NONE; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret == -1) { + state = CALL_STATE (frame); + if (ENODATA == op_errno || ENOATTR == op_errno) + loglevel = GF_LOG_DEBUG; + else + loglevel = GF_LOG_INFO; + + gf_msg (this->name, loglevel, op_errno, + PS_MSG_REMOVEXATTR_INFO, + "%"PRId64": REMOVEXATTR %s (%s) of key %s, client: %s, " + "error-xlator: %s", + frame->root->unique, state->loc.path, + uuid_utoa (state->resolve.gfid), + state->name, STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_fremovexattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret == -1) { + state = CALL_STATE (frame); + gf_msg (this->name, + fop_log_level (GF_FOP_FREMOVEXATTR, op_errno), op_errno, + PS_MSG_REMOVEXATTR_INFO, + "%"PRId64": FREMOVEXATTR %"PRId64" (%s) (%s), " + "client: %s, error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + state->name, STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_getxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) +{ + gfx_common_dict_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret == -1) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_GETXATTR, op_errno), + op_errno, PS_MSG_GETXATTR_INFO, + "%"PRId64": GETXATTR %s (%s) (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.gfid), + state->name, STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + dict_to_xdr (dict, &rsp.dict); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_dict_rsp); + + GF_FREE (rsp.dict.pairs.pairs_val); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_fgetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) +{ + gfx_common_dict_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret == -1) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_FGETXATTR, op_errno), + op_errno, PS_MSG_GETXATTR_INFO, + "%"PRId64": FGETXATTR %"PRId64" (%s) (%s), " + "client: %s, error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + state->name, STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + dict_to_xdr (dict, &rsp.dict); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_dict_rsp); + + GF_FREE (rsp.dict.pairs.pairs_val); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_setxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret == -1) { + state = CALL_STATE (frame); + if (op_errno != ENOTSUP) + dict_foreach (state->dict, + _gf_server_log_setxattr_failure, + frame); + + if (op_errno == ENOTSUP) { + gf_msg_debug (THIS->name, 0, "%s", + strerror (op_errno)); + } else { + gf_msg (THIS->name, GF_LOG_INFO, op_errno, + PS_MSG_SETXATTR_INFO, "client: %s, " + "error-xlator: %s", + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + } + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_fsetxattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret == -1) { + state = CALL_STATE (frame); + if (op_errno != ENOTSUP) { + dict_foreach (state->dict, + _gf_server_log_setxattr_failure, + frame); + } + if (op_errno == ENOTSUP) { + gf_msg_debug (THIS->name, 0, "%s", + strerror (op_errno)); + } else { + gf_msg (THIS->name, GF_LOG_INFO, op_errno, + PS_MSG_SETXATTR_INFO, "client: %s, " + "error-xlator: %s", + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + } + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_rename_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *stbuf, + struct iatt *preoldparent, struct iatt *postoldparent, + struct iatt *prenewparent, struct iatt *postnewparent, + dict_t *xdata) +{ + gfx_rename_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + char oldpar_str[50] = {0,}; + char newpar_str[50] = {0,}; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret == -1) { + uuid_utoa_r (state->resolve.pargfid, oldpar_str); + uuid_utoa_r (state->resolve2.pargfid, newpar_str); + gf_msg (this->name, GF_LOG_INFO, op_errno, PS_MSG_RENAME_INFO, + "%"PRId64": RENAME %s (%s/%s) -> %s (%s/%s), " + "client: %s, error-xlator: %s", frame->root->unique, + state->loc.path, oldpar_str, state->resolve.bname, + state->loc2.path, newpar_str, state->resolve2.bname, + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_rename (frame, state, &rsp, stbuf, + preoldparent, postoldparent, + prenewparent, postnewparent); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_rename_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_unlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret) { + gf_msg (this->name, fop_log_level (GF_FOP_UNLINK, op_errno), + op_errno, PS_MSG_LINK_INFO, + "%"PRId64": UNLINK %s (%s/%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.pargfid), + state->resolve.bname, + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + /* TODO: log gfid of the inodes */ + gf_msg_trace (frame->root->client->bound_xl->name, 0, "%"PRId64": " + "UNLINK_CBK %s", frame->root->unique, state->loc.name); + + server4_post_entry_remove (state, &rsp, preparent, postparent); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_symlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + gfx_common_3iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret < 0) { + gf_msg (this->name, GF_LOG_INFO, op_errno, PS_MSG_LINK_INFO, + "%"PRId64": SYMLINK %s (%s/%s), client: %s, " + "error-xlator:%s", frame->root->unique, + (state->loc.path) ? state->loc.path : "", + uuid_utoa (state->resolve.pargfid), + state->resolve.bname, + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_3iatt (state, &rsp, inode, stbuf, preparent, + postparent); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_3iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_link_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + gfx_common_3iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + char gfid_str[50] = {0,}; + char newpar_str[50] = {0,}; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret) { + uuid_utoa_r (state->resolve.gfid, gfid_str); + uuid_utoa_r (state->resolve2.pargfid, newpar_str); + + gf_msg (this->name, GF_LOG_INFO, op_errno, PS_MSG_LINK_INFO, + "%"PRId64": LINK %s (%s) -> %s/%s, client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, gfid_str, newpar_str, + state->resolve2.bname, STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_link (state, &rsp, inode, stbuf, preparent, + postparent); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_3iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_truncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + state = CALL_STATE (frame); + gf_msg (this->name, GF_LOG_INFO, op_errno, + PS_MSG_TRUNCATE_INFO, + "%"PRId64": TRUNCATE %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_2iatt (&rsp, prebuf, postbuf); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_fstat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *stbuf, + dict_t *xdata) +{ + gfx_common_iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + if (op_ret) { + gf_msg (this->name, fop_log_level (GF_FOP_FSTAT, op_errno), + op_errno, PS_MSG_STAT_INFO, + "%"PRId64": FSTAT %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_iatt (state, &rsp, stbuf); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_ftruncate_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_FTRUNCATE, op_errno), + op_errno, PS_MSG_TRUNCATE_INFO, + "%"PRId64": FTRUNCATE %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_2iatt (&rsp, prebuf, postbuf); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_flush_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_FLUSH, op_errno), + op_errno, PS_MSG_FLUSH_INFO, + "%"PRId64": FLUSH %"PRId64" (%s), client: %s, " + "error-xlator: %s", + frame->root->unique, state->resolve.fd_no, + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_fsync_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_FSYNC, op_errno), + op_errno, PS_MSG_SYNC_INFO, + "%"PRId64": FSYNC %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_2iatt (&rsp, prebuf, postbuf); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_writev_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *prebuf, + struct iatt *postbuf, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_WRITE, op_errno), + op_errno, PS_MSG_WRITE_INFO, + "%"PRId64": WRITEV %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_2iatt (&rsp, prebuf, postbuf); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_readv_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iovec *vector, int32_t count, + struct iatt *stbuf, struct iobref *iobref, dict_t *xdata) +{ + gfx_read_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + +#ifdef GF_TESTING_IO_XDATA + { + int ret = 0; + if (!xdata) + xdata = dict_new (); + + ret = dict_set_str (xdata, "testing-the-xdata-key", + "testing-xdata-value"); + } +#endif + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_READ, op_errno), + op_errno, PS_MSG_READ_INFO, + "%"PRId64": READV %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_readv (&rsp, stbuf, op_ret); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, vector, count, iobref, + (xdrproc_t)xdr_gfx_read_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_rchecksum_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + uint32_t weak_checksum, uint8_t *strong_checksum, + dict_t *xdata) +{ + gfx_rchecksum_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + server_state_t *state = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_RCHECKSUM, op_errno), + op_errno, PS_MSG_CHKSUM_INFO, + "%"PRId64": RCHECKSUM %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_rchecksum (&rsp, weak_checksum, strong_checksum); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_rchecksum_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_open_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, dict_t *xdata) +{ + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + gfx_open_rsp rsp = {0,}; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_OPEN, op_errno), + op_errno, PS_MSG_OPEN_INFO, + "%"PRId64": OPEN %s (%s), client: %s, error-xlator: %s", + frame->root->unique, state->loc.path, + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + op_ret = server4_post_open (frame, this, &rsp, fd); + if (op_ret) + goto out; +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_open_rsp); + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_create_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, fd_t *fd, inode_t *inode, + struct iatt *stbuf, struct iatt *preparent, + struct iatt *postparent, dict_t *xdata) +{ + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + uint64_t fd_no = 0; + gfx_create_rsp rsp = {0,}; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + + if (op_ret < 0) { + gf_msg (this->name, GF_LOG_INFO, op_errno, PS_MSG_CREATE_INFO, + "%"PRId64": CREATE %s (%s/%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.pargfid), + state->resolve.bname, STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + /* TODO: log gfid too */ + gf_msg_trace (frame->root->client->bound_xl->name, 0, "%"PRId64": " + "CREATE %s (%s)", frame->root->unique, state->loc.name, + uuid_utoa (stbuf->ia_gfid)); + + op_ret = server4_post_create (frame, &rsp, state, this, fd, inode, + stbuf, + preparent, postparent); + if (op_ret) { + op_errno = -op_ret; + op_ret = -1; + goto out; + } + +out: + if (op_ret) + rsp.fd = fd_no; + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_create_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_readlink_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, const char *buf, + struct iatt *stbuf, dict_t *xdata) +{ + gfx_readlink_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, GF_LOG_INFO, op_errno, PS_MSG_LINK_INFO, + "%"PRId64": READLINK %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_readlink (&rsp, stbuf, buf); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + if (!rsp.path) + rsp.path = ""; + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_readlink_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_stat_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, struct iatt *stbuf, + dict_t *xdata) +{ + gfx_common_iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + state = CALL_STATE (frame); + if (op_ret) { + gf_msg (this->name, fop_log_level (GF_FOP_STAT, op_errno), + op_errno, PS_MSG_STAT_INFO, + "%"PRId64": STAT %s (%s), client: %s, error-xlator: %s", + frame->root->unique, + (state->loc.path) ? state->loc.path : "", + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_iatt (state, &rsp, stbuf); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_setattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *statpre, struct iatt *statpost, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + state = CALL_STATE (frame); + gf_msg (this->name, GF_LOG_INFO, op_errno, PS_MSG_SETATTR_INFO, + "%"PRId64": SETATTR %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + (state->loc.path) ? state->loc.path : "", + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_2iatt (&rsp, statpre, statpost); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_fsetattr_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *statpre, struct iatt *statpost, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_FSETATTR, op_errno), + op_errno, PS_MSG_SETATTR_INFO, + "%"PRId64": FSETATTR %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_2iatt (&rsp, statpre, statpost); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_xattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) +{ + gfx_common_dict_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_XATTROP, op_errno), + op_errno, PS_MSG_XATTROP_INFO, + "%"PRId64": XATTROP %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + dict_to_xdr (dict, &rsp.dict); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_dict_rsp); + + GF_FREE (rsp.dict.pairs.pairs_val); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_fxattrop_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *dict, + dict_t *xdata) +{ + gfx_common_dict_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_FXATTROP, op_errno), + op_errno, PS_MSG_XATTROP_INFO, + "%"PRId64": FXATTROP %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + dict_to_xdr (dict, &rsp.dict); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_dict_rsp); + + GF_FREE (rsp.dict.pairs.pairs_val); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_readdirp_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, gf_dirent_t *entries, + dict_t *xdata) +{ + gfx_readdirp_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + int ret = 0; + + state = CALL_STATE (frame); + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_READDIRP, op_errno), + op_errno, PS_MSG_DIR_INFO, + "%"PRId64": READDIRP %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + /* (op_ret == 0) is valid, and means EOF */ + if (op_ret) { + ret = server4_post_readdirp (&rsp, entries); + if (ret == -1) { + op_ret = -1; + op_errno = ENOMEM; + goto out; + } + } + + gf_link_inodes_from_dirent (this, state->fd->inode, entries); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_readdirp_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + readdirp_rsp_cleanup_v2 (&rsp); + + return 0; +} + +int +server4_fallocate_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *statpre, struct iatt *statpost, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_FALLOCATE, op_errno), + op_errno, PS_MSG_ALLOC_INFO, + "%"PRId64": FALLOCATE %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_2iatt (&rsp, statpre, statpost); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply(frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_discard_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *statpre, struct iatt *statpost, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + state = CALL_STATE (frame); + gf_msg (this->name, fop_log_level (GF_FOP_DISCARD, op_errno), + op_errno, PS_MSG_DISCARD_INFO, + "%"PRId64": DISCARD %"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_2iatt (&rsp, statpre, statpost); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply(frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_zerofill_cbk(call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *statpre, struct iatt *statpost, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + req = frame->local; + state = CALL_STATE (frame); + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + gf_msg (this->name, fop_log_level (GF_FOP_ZEROFILL, op_errno), + op_errno, PS_MSG_ZEROFILL_INFO, + "%"PRId64": ZEROFILL%"PRId64" (%s), client: %s, " + "error-xlator: %s", + frame->root->unique, state->resolve.fd_no, + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_common_2iatt (&rsp, statpre, statpost); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + server_submit_reply(frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_ipc_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + req = frame->local; + state = CALL_STATE (frame); + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + gf_msg (this->name, GF_LOG_INFO, op_errno, + PS_MSG_SERVER_IPC_INFO, + "%"PRId64": IPC%"PRId64" (%s), client: %s, " + "error-xlator: %s", + frame->root->unique, state->resolve.fd_no, + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + server_submit_reply(frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + + +int +server4_seek_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, off_t offset, dict_t *xdata) +{ + struct gfx_seek_rsp rsp = {0, }; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + req = frame->local; + state = CALL_STATE (frame); + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + gf_msg (this->name, fop_log_level (GF_FOP_SEEK, op_errno), + op_errno, PS_MSG_SEEK_INFO, + "%"PRId64": SEEK%"PRId64" (%s), client: %s, " + "error-xlator: %s", + frame->root->unique, state->resolve.fd_no, + uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + + server4_post_seek (&rsp, offset); +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_seek_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +static int +server4_setactivelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, dict_t *xdata) +{ + gfx_common_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + + state = CALL_STATE (frame); + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + gf_msg (this->name, GF_LOG_INFO, + op_errno, 0, + "%"PRId64": SETACTIVELK %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + goto out; + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_namelink_cbk (call_frame_t *frame, + void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + struct iatt *prebuf, struct iatt *postbuf, dict_t *xdata) +{ + gfx_common_2iatt_rsp rsp = {0,}; + rpcsvc_request_t *req = NULL; + + dict_to_xdr (xdata, &rsp.xdata); + if (op_ret < 0) + goto out; + + gfx_stat_from_iattx (&rsp.prestat, prebuf); + gfx_stat_from_iattx (&rsp.poststat, postbuf); + + /** + * no point in linking inode here -- there's no stbuf anyway and a + * lookup() for this name entry would be a negative lookup. + */ + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_2iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_icreate_cbk (call_frame_t *frame, + void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + inode_t *inode, struct iatt *stbuf, dict_t *xdata) +{ + server_state_t *state = NULL; + inode_t *link_inode = NULL; + rpcsvc_request_t *req = NULL; + gfx_common_iatt_rsp rsp = {0,}; + + dict_to_xdr (xdata, &rsp.xdata); + state = CALL_STATE (frame); + + if (op_ret < 0) { + gf_msg (this->name, GF_LOG_INFO, op_errno, PS_MSG_CREATE_INFO, + "%"PRId64": ICREATE [%s] ==> (%s)", + frame->root->unique, uuid_utoa (state->resolve.gfid), + strerror (op_errno)); + goto out; + } + + gf_msg_trace (frame->root->client->bound_xl->name, 0, "%"PRId64": " + "ICREATE [%s]", frame->root->unique, + uuid_utoa (stbuf->ia_gfid)); + + link_inode = inode_link (inode, + state->loc.parent, state->loc.name, stbuf); + + if (!link_inode) { + op_ret = -1; + op_errno = ENOENT; + goto out; + } + + inode_lookup (link_inode); + inode_unref (link_inode); + + gfx_stat_from_iattx (&rsp.stat, stbuf); + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_iatt_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +/* Resume function section */ + +int +server4_rchecksum_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + int op_ret = 0; + int op_errno = EINVAL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) { + op_ret = state->resolve.op_ret; + op_errno = state->resolve.op_errno; + goto err; + } + + STACK_WIND (frame, server4_rchecksum_cbk, bound_xl, + bound_xl->fops->rchecksum, state->fd, + state->offset, state->size, state->xdata); + + return 0; +err: + server4_rchecksum_cbk (frame, NULL, frame->this, op_ret, op_errno, 0, + NULL, NULL); + + return 0; + +} + +int +server4_lease_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_lease_cbk, bound_xl, bound_xl->fops->lease, + &state->loc, &state->lease, state->xdata); + + return 0; + +err: + server4_lease_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server4_lk_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_lk_cbk, bound_xl, bound_xl->fops->lk, + state->fd, state->cmd, &state->flock, state->xdata); + + return 0; + +err: + server4_lk_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server4_rename_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + int op_ret = 0; + int op_errno = 0; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) { + op_ret = state->resolve.op_ret; + op_errno = state->resolve.op_errno; + goto err; + } + + if (state->resolve2.op_ret != 0) { + op_ret = state->resolve2.op_ret; + op_errno = state->resolve2.op_errno; + goto err; + } + + STACK_WIND (frame, server4_rename_cbk, + bound_xl, bound_xl->fops->rename, + &state->loc, &state->loc2, state->xdata); + return 0; +err: + server4_rename_cbk (frame, NULL, frame->this, op_ret, op_errno, + NULL, NULL, NULL, NULL, NULL, NULL); + return 0; +} + + +int +server4_link_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + int op_ret = 0; + int op_errno = 0; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) { + op_ret = state->resolve.op_ret; + op_errno = state->resolve.op_errno; + goto err; + } + + if (state->resolve2.op_ret != 0) { + op_ret = state->resolve2.op_ret; + op_errno = state->resolve2.op_errno; + goto err; + } + + state->loc2.inode = inode_ref (state->loc.inode); + + STACK_WIND (frame, server4_link_cbk, bound_xl, bound_xl->fops->link, + &state->loc, &state->loc2, state->xdata); + + return 0; +err: + server4_link_cbk (frame, NULL, frame->this, op_ret, op_errno, + NULL, NULL, NULL, NULL, NULL); + return 0; +} + +int +server4_symlink_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + state->loc.inode = inode_new (state->itable); + + STACK_WIND (frame, server4_symlink_cbk, + bound_xl, bound_xl->fops->symlink, + state->name, &state->loc, state->umask, state->xdata); + + return 0; +err: + server4_symlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, NULL, NULL); + return 0; +} + + +int +server4_access_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_access_cbk, + bound_xl, bound_xl->fops->access, + &state->loc, state->mask, state->xdata); + return 0; +err: + server4_access_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server4_fentrylk_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + GF_UNUSED int ret = -1; + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + if (!state->xdata) + state->xdata = dict_new (); + + if (state->xdata) + ret = dict_set_str (state->xdata, "connection-id", + frame->root->client->client_uid); + + STACK_WIND (frame, server4_fentrylk_cbk, bound_xl, + bound_xl->fops->fentrylk, + state->volume, state->fd, state->name, + state->cmd, state->type, state->xdata); + + return 0; +err: + server4_fentrylk_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + + +int +server4_entrylk_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + GF_UNUSED int ret = -1; + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + if (!state->xdata) + state->xdata = dict_new (); + + if (state->xdata) + ret = dict_set_str (state->xdata, "connection-id", + frame->root->client->client_uid); + + STACK_WIND (frame, server4_entrylk_cbk, + bound_xl, bound_xl->fops->entrylk, + state->volume, &state->loc, state->name, + state->cmd, state->type, state->xdata); + return 0; +err: + server4_entrylk_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + + +int +server4_finodelk_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + GF_UNUSED int ret = -1; + server_state_t *state = NULL; + + gf_msg_debug (bound_xl->name, 0, "frame %p, xlator %p", frame, + bound_xl); + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + if (!state->xdata) + state->xdata = dict_new (); + + if (state->xdata) + ret = dict_set_str (state->xdata, "connection-id", + frame->root->client->client_uid); + + STACK_WIND (frame, server4_finodelk_cbk, bound_xl, + bound_xl->fops->finodelk, state->volume, state->fd, + state->cmd, &state->flock, state->xdata); + + return 0; +err: + server4_finodelk_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + + return 0; +} + +int +server4_inodelk_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + GF_UNUSED int ret = -1; + server_state_t *state = NULL; + + gf_msg_debug (bound_xl->name, 0, "frame %p, xlator %p", frame, + bound_xl); + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + if (!state->xdata) + state->xdata = dict_new (); + + if (state->xdata) + ret = dict_set_str (state->xdata, "connection-id", + frame->root->client->client_uid); + + STACK_WIND (frame, server4_inodelk_cbk, bound_xl, + bound_xl->fops->inodelk, state->volume, &state->loc, + state->cmd, &state->flock, state->xdata); + return 0; +err: + server4_inodelk_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server4_rmdir_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_rmdir_cbk, bound_xl, bound_xl->fops->rmdir, + &state->loc, state->flags, state->xdata); + return 0; +err: + server4_rmdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + +int +server4_mkdir_resume (call_frame_t *frame, xlator_t *bound_xl) + +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + state->loc.inode = inode_new (state->itable); + + STACK_WIND (frame, server4_mkdir_cbk, + bound_xl, bound_xl->fops->mkdir, + &(state->loc), state->mode, state->umask, state->xdata); + + return 0; +err: + server4_mkdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, NULL, NULL); + return 0; +} + + +int +server4_mknod_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + state->loc.inode = inode_new (state->itable); + + STACK_WIND (frame, server4_mknod_cbk, + bound_xl, bound_xl->fops->mknod, + &(state->loc), state->mode, state->dev, + state->umask, state->xdata); + + return 0; +err: + server4_mknod_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, NULL, NULL); + return 0; +} + + +int +server4_fsyncdir_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_fsyncdir_cbk, + bound_xl, + bound_xl->fops->fsyncdir, + state->fd, state->flags, state->xdata); + return 0; + +err: + server4_fsyncdir_cbk (frame, NULL, frame->this, + state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + + +int +server4_readdir_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + GF_ASSERT (state->fd); + + STACK_WIND (frame, server4_readdir_cbk, + bound_xl, + bound_xl->fops->readdir, + state->fd, state->size, state->offset, state->xdata); + + return 0; +err: + server4_readdir_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server4_readdirp_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_readdirp_cbk, bound_xl, + bound_xl->fops->readdirp, state->fd, state->size, + state->offset, state->xdata); + + return 0; +err: + server4_readdirp_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + + +int +server4_opendir_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + state->fd = fd_create (state->loc.inode, frame->root->pid); + if (!state->fd) { + gf_msg ("server", GF_LOG_ERROR, 0, PS_MSG_FD_CREATE_FAILED, + "could not create the fd"); + goto err; + } + + STACK_WIND (frame, server4_opendir_cbk, + bound_xl, bound_xl->fops->opendir, + &state->loc, state->fd, state->xdata); + return 0; +err: + server4_opendir_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + + +int +server4_statfs_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_statfs_cbk, + bound_xl, bound_xl->fops->statfs, + &state->loc, state->xdata); + return 0; + +err: + server4_statfs_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + + +int +server4_removexattr_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_removexattr_cbk, + bound_xl, bound_xl->fops->removexattr, + &state->loc, state->name, state->xdata); + return 0; +err: + server4_removexattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server4_fremovexattr_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_fremovexattr_cbk, + bound_xl, bound_xl->fops->fremovexattr, + state->fd, state->name, state->xdata); + return 0; +err: + server4_fremovexattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; +} + +int +server4_fgetxattr_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_fgetxattr_cbk, + bound_xl, bound_xl->fops->fgetxattr, + state->fd, state->name, state->xdata); + return 0; +err: + server4_fgetxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + + +int +server4_xattrop_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_xattrop_cbk, + bound_xl, bound_xl->fops->xattrop, + &state->loc, state->flags, state->dict, state->xdata); + return 0; +err: + server4_xattrop_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server4_fxattrop_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_fxattrop_cbk, + bound_xl, bound_xl->fops->fxattrop, + state->fd, state->flags, state->dict, state->xdata); + return 0; +err: + server4_fxattrop_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server4_fsetxattr_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_setxattr_cbk, + bound_xl, bound_xl->fops->fsetxattr, + state->fd, state->dict, state->flags, state->xdata); + return 0; +err: + server4_fsetxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + + return 0; +} + +int +server4_unlink_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_unlink_cbk, + bound_xl, bound_xl->fops->unlink, + &state->loc, state->flags, state->xdata); + return 0; +err: + server4_unlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + +int +server4_truncate_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_truncate_cbk, + bound_xl, bound_xl->fops->truncate, + &state->loc, state->offset, state->xdata); + return 0; +err: + server4_truncate_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + + + +int +server4_fstat_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_fstat_cbk, + bound_xl, bound_xl->fops->fstat, + state->fd, state->xdata); + return 0; +err: + server4_fstat_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + + +int +server4_setxattr_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_setxattr_cbk, + bound_xl, bound_xl->fops->setxattr, + &state->loc, state->dict, state->flags, state->xdata); + return 0; +err: + server4_setxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + + return 0; +} + + +int +server4_getxattr_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_getxattr_cbk, + bound_xl, bound_xl->fops->getxattr, + &state->loc, state->name, state->xdata); + return 0; +err: + server4_getxattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + + +int +server4_ftruncate_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_ftruncate_cbk, + bound_xl, bound_xl->fops->ftruncate, + state->fd, state->offset, state->xdata); + return 0; +err: + server4_ftruncate_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + + +int +server4_flush_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_flush_cbk, + bound_xl, bound_xl->fops->flush, state->fd, state->xdata); + return 0; +err: + server4_flush_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL); + + return 0; +} + + +int +server4_fsync_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_fsync_cbk, + bound_xl, bound_xl->fops->fsync, + state->fd, state->flags, state->xdata); + return 0; +err: + server4_fsync_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server4_writev_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_writev_cbk, + bound_xl, bound_xl->fops->writev, + state->fd, state->payload_vector, state->payload_count, + state->offset, state->flags, state->iobref, state->xdata); + + return 0; +err: + server4_writev_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + + +int +server4_readv_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_readv_cbk, + bound_xl, bound_xl->fops->readv, + state->fd, state->size, state->offset, state->flags, state->xdata); + + return 0; +err: + server4_readv_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, 0, NULL, NULL, NULL); + return 0; +} + + +int +server4_create_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + state->loc.inode = inode_new (state->itable); + + state->fd = fd_create (state->loc.inode, frame->root->pid); + if (!state->fd) { + gf_msg ("server", GF_LOG_ERROR, 0, PS_MSG_FD_CREATE_FAILED, + "fd creation for the inode %s failed", + state->loc.inode ? + uuid_utoa (state->loc.inode->gfid):NULL); + state->resolve.op_ret = -1; + state->resolve.op_errno = ENOMEM; + goto err; + } + state->fd->flags = state->flags; + + STACK_WIND (frame, server4_create_cbk, + bound_xl, bound_xl->fops->create, + &(state->loc), state->flags, state->mode, + state->umask, state->fd, state->xdata); + + return 0; +err: + server4_create_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, + NULL, NULL, NULL); + return 0; +} + + +int +server4_open_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + state->fd = fd_create (state->loc.inode, frame->root->pid); + state->fd->flags = state->flags; + + STACK_WIND (frame, server4_open_cbk, + bound_xl, bound_xl->fops->open, + &state->loc, state->flags, state->fd, state->xdata); + + return 0; +err: + server4_open_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + + +int +server4_readlink_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_readlink_cbk, + bound_xl, bound_xl->fops->readlink, + &state->loc, state->size, state->xdata); + return 0; +err: + server4_readlink_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + + +int +server4_fsetattr_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_fsetattr_cbk, + bound_xl, bound_xl->fops->fsetattr, + state->fd, &state->stbuf, state->valid, state->xdata); + return 0; +err: + server4_fsetattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + + +int +server4_setattr_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_setattr_cbk, + bound_xl, bound_xl->fops->setattr, + &state->loc, &state->stbuf, state->valid, state->xdata); + return 0; +err: + server4_setattr_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + + +int +server4_stat_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_stat_cbk, + bound_xl, bound_xl->fops->stat, &state->loc, state->xdata); + return 0; +err: + server4_stat_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; +} + +int +server4_lookup_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + if (!state->loc.inode) + state->loc.inode = server_inode_new (state->itable, + state->loc.gfid); + else + state->is_revalidate = 1; + + STACK_WIND (frame, server4_lookup_cbk, + bound_xl, bound_xl->fops->lookup, + &state->loc, state->xdata); + + return 0; +err: + server4_lookup_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL, NULL); + + return 0; +} + +int +server4_fallocate_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_fallocate_cbk, + bound_xl, bound_xl->fops->fallocate, + state->fd, state->flags, state->offset, state->size, + state->xdata); + return 0; +err: + server4_fallocate_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server4_discard_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_discard_cbk, + bound_xl, bound_xl->fops->discard, + state->fd, state->offset, state->size, state->xdata); + return 0; +err: + server4_discard_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server4_zerofill_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_zerofill_cbk, + bound_xl, bound_xl->fops->zerofill, + state->fd, state->offset, state->size, state->xdata); + return 0; +err: + server4_zerofill_cbk(frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + + return 0; +} + +int +server4_seek_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_seek_cbk, bound_xl, bound_xl->fops->seek, + state->fd, state->offset, state->what, state->xdata); + return 0; +err: + server4_seek_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, 0, NULL); + + return 0; +} + +static int +server4_getactivelk_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, + lock_migration_info_t *locklist, dict_t *xdata) +{ + gfx_getactivelk_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + int ret = 0; + + state = CALL_STATE (frame); + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret < 0) { + state = CALL_STATE (frame); + + gf_msg (this->name, GF_LOG_INFO, + op_errno, 0, + "%"PRId64": GETACTIVELK %s (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->loc.path, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + + goto out; + } + + /* (op_ret == 0) means there are no locks on the file*/ + if (op_ret > 0) { + ret = serialize_rsp_locklist_v2 (locklist, &rsp); + if (ret == -1) { + op_ret = -1; + op_errno = ENOMEM; + goto out; + } + } + +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + req = frame->local; + + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_getactivelk_rsp); + + GF_FREE (rsp.xdata.pairs.pairs_val); + + getactivelkinfo_rsp_cleanup_v2 (&rsp); + + return 0; +} + +int +server4_getactivelk_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_getactivelk_cbk, bound_xl, + bound_xl->fops->getactivelk, &state->loc, state->xdata); + return 0; +err: + server4_getactivelk_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL); + return 0; + +} + +int +server4_setactivelk_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + STACK_WIND (frame, server4_setactivelk_cbk, + bound_xl, bound_xl->fops->setactivelk, &state->loc, + &state->locklist, state->xdata); + return 0; +err: + server4_setactivelk_cbk (frame, NULL, frame->this, + state->resolve.op_ret, + state->resolve.op_errno, NULL); + return 0; + +} +int +server4_namelink_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + state->loc.inode = inode_new (state->itable); + + STACK_WIND (frame, server4_namelink_cbk, + bound_xl, bound_xl->fops->namelink, + &(state->loc), state->xdata); + return 0; + + err: + server4_namelink_cbk (frame, NULL, + frame->this, + state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + +int +server4_icreate_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) + goto err; + + state->loc.inode = inode_new (state->itable); + + STACK_WIND (frame, server4_icreate_cbk, + bound_xl, bound_xl->fops->icreate, + &(state->loc), state->mode, state->xdata); + + return 0; +err: + server4_icreate_cbk (frame, NULL, frame->this, state->resolve.op_ret, + state->resolve.op_errno, NULL, NULL, NULL); + return 0; +} + + +int +server4_0_stat (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_stat_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return 0; + + /* Initialize args first, then decode */ + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_stat_req, GF_FOP_STAT); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_stat_resume); + +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_setattr (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_setattr_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return 0; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_setattr_req, GF_FOP_SETATTR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + gfx_stat_to_iattx (&args.stbuf, &state->stbuf); + state->valid = args.valid; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_setattr_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + + + return ret; +} + + +int +server4_0_fallocate(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fallocate_req args = {{0},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fallocate_req, GF_FOP_FALLOCATE); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + + state->flags = args.flags; + state->offset = args.offset; + state->size = args.size; + memcpy(state->resolve.gfid, args.gfid, 16); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_fallocate_resume); + +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_discard(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_discard_req args = {{0},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_discard_req, GF_FOP_DISCARD); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + + state->offset = args.offset; + state->size = args.size; + memcpy(state->resolve.gfid, args.gfid, 16); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_discard_resume); + +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_zerofill(rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_zerofill_req args = {{0},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_zerofill_req, GF_FOP_ZEROFILL); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + + state->offset = args.offset; + state->size = args.size; + memcpy(state->resolve.gfid, args.gfid, 16); + + xdr_to_dict (&args.xdata, &state->xdata); + ret = 0; + resolve_and_resume (frame, server4_zerofill_resume); + +out: + + + if (op_errno) + req->rpc_err = GARBAGE_ARGS; + + return ret; +} + +int +server4_0_ipc (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_ipc_req args = {0,}; + int ret = -1; + int op_errno = 0; + xlator_t *bound_xl = NULL; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_ipc_req, GF_FOP_IPC); + if (ret != 0) { + goto out; + } + + bound_xl = frame->root->client->bound_xl; + xdr_to_dict (&args.xdata, &state->xdata); + ret = 0; + STACK_WIND (frame, server4_ipc_cbk, bound_xl, bound_xl->fops->ipc, + args.op, state->xdata); + +out: + + + if (op_errno) + req->rpc_err = GARBAGE_ARGS; + + return ret; +} + +int +server4_0_seek (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_seek_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_seek_req, GF_FOP_SEEK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + + state->offset = args.offset; + state->what = args.what; + memcpy(state->resolve.gfid, args.gfid, 16); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_seek_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_readlink (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_readlink_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_readlink_req, GF_FOP_READLINK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, args.gfid, 16); + + state->size = args.size; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_readlink_resume); + +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_create (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_create_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.bname = alloca (req->msg[0].iov_len); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_create_req, GF_FOP_CREATE); + if (ret != 0) { + goto out; + } + + state->resolve.bname = gf_strdup (args.bname); + state->mode = args.mode; + state->umask = args.umask; + state->flags = gf_flags_to_flags (args.flags); + + set_resolve_gfid (frame->root->client, state->resolve.pargfid, + args.pargfid); + + if (state->flags & O_EXCL) { + state->resolve.type = RESOLVE_NOT; + } else { + state->resolve.type = RESOLVE_DONTCARE; + } + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_create_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_open (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_open_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_open_req, GF_FOP_OPEN); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, args.gfid, 16); + + state->flags = gf_flags_to_flags (args.flags); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_open_resume); +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + + + return ret; +} + + +int +server4_0_readv (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_read_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + goto out; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_read_req, GF_FOP_READ); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + state->size = args.size; + state->offset = args.offset; + state->flags = args.flag; + + memcpy (state->resolve.gfid, args.gfid, 16); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_readv_resume); +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_writev (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_write_req args = {{0,},}; + ssize_t len = 0; + int i = 0; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, &len, &args, + xdr_gfx_write_req, GF_FOP_WRITE); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + state->offset = args.offset; + state->size = args.size; + state->flags = args.flag; + state->iobref = iobref_ref (req->iobref); + memcpy (state->resolve.gfid, args.gfid, 16); + + if (len < req->msg[0].iov_len) { + state->payload_vector[0].iov_base + = (req->msg[0].iov_base + len); + state->payload_vector[0].iov_len + = req->msg[0].iov_len - len; + state->payload_count = 1; + } + + for (i = 1; i < req->count; i++) { + state->payload_vector[state->payload_count++] + = req->msg[i]; + } + + len = iov_length (state->payload_vector, state->payload_count); + + GF_ASSERT (state->size == len); + + xdr_to_dict (&args.xdata, &state->xdata); + +#ifdef GF_TESTING_IO_XDATA + dict_dump_to_log (state->xdata); +#endif + + ret = 0; + resolve_and_resume (frame, server4_writev_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +#define SERVER4_0_VECWRITE_START 0 +#define SERVER4_0_VECWRITE_READING_HDR 1 +#define SERVER4_0_VECWRITE_READING_OPAQUE 2 + +int +server4_0_writev_vecsizer (int state, ssize_t *readsize, char *base_addr, + char *curr_addr) +{ + ssize_t size = 0; + int nextstate = 0; + gfx_write_req write_req = {{0,},}; + XDR xdr; + + switch (state) { + case SERVER4_0_VECWRITE_START: + size = xdr_sizeof ((xdrproc_t) xdr_gfx_write_req, + &write_req); + *readsize = size; + + nextstate = SERVER4_0_VECWRITE_READING_HDR; + break; + case SERVER4_0_VECWRITE_READING_HDR: + size = xdr_sizeof ((xdrproc_t) xdr_gfx_write_req, + &write_req); + + xdrmem_create (&xdr, base_addr, size, XDR_DECODE); + + /* This will fail if there is xdata sent from client, if not, + well and good */ + xdr_gfx_write_req (&xdr, &write_req); + + /* need to round off to proper roof (%4), as XDR packing pads + the end of opaque object with '0' */ + size = roof (write_req.xdata.xdr_size, 4); + + *readsize = size; + + if (!size) + nextstate = SERVER4_0_VECWRITE_START; + else + nextstate = SERVER4_0_VECWRITE_READING_OPAQUE; + + free (write_req.xdata.pairs.pairs_val); + + break; + + case SERVER4_0_VECWRITE_READING_OPAQUE: + *readsize = 0; + nextstate = SERVER4_0_VECWRITE_START; + break; + } + + return nextstate; +} + + +int +server4_0_release (rpcsvc_request_t *req) +{ + client_t *client = NULL; + server_ctx_t *serv_ctx = NULL; + gfx_release_req args = {{0,},}; + gfx_common_rsp rsp = {0,}; + int ret = -1; + + ret = xdr_to_generic (req->msg[0], &args, + (xdrproc_t)xdr_gfx_release_req); + if (ret < 0) { + SERVER_REQ_SET_ERROR (req, ret); + goto out; + } + + client = req->trans->xl_private; + if (!client) { + /* Handshake is not complete yet. */ + req->rpc_err = SYSTEM_ERR; + goto out; + } + + serv_ctx = server_ctx_get (client, client->this); + if (serv_ctx == NULL) { + gf_msg (req->trans->name, GF_LOG_INFO, 0, + PS_MSG_SERVER_CTX_GET_FAILED, "server_ctx_get() " + "failed"); + req->rpc_err = SYSTEM_ERR; + goto out; + } + + gf_fd_put (serv_ctx->fdtable, args.fd); + + server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + ret = 0; +out: + return ret; +} + +int +server4_0_releasedir (rpcsvc_request_t *req) +{ + client_t *client = NULL; + server_ctx_t *serv_ctx = NULL; + gfx_releasedir_req args = {{0,},}; + gfx_common_rsp rsp = {0,}; + int ret = -1; + + ret = xdr_to_generic (req->msg[0], &args, + (xdrproc_t)xdr_gfx_release_req); + if (ret < 0) { + SERVER_REQ_SET_ERROR (req, ret); + goto out; + } + + client = req->trans->xl_private; + if (!client) { + SERVER_REQ_SET_ERROR (req, ret); + goto out; + } + + serv_ctx = server_ctx_get (client, client->this); + if (serv_ctx == NULL) { + gf_msg (req->trans->name, GF_LOG_INFO, 0, + PS_MSG_SERVER_CTX_GET_FAILED, "server_ctx_get() " + "failed"); + req->rpc_err = SYSTEM_ERR; + goto out; + } + + gf_fd_put (serv_ctx->fdtable, args.fd); + + server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + ret = 0; +out: + return ret; +} + + +int +server4_0_fsync (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fsync_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fsync_req, GF_FOP_FSYNC); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + state->flags = args.data; + memcpy (state->resolve.gfid, args.gfid, 16); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_fsync_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + +int +server4_0_flush (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_flush_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_flush_req, GF_FOP_FLUSH); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + memcpy (state->resolve.gfid, args.gfid, 16); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_flush_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + +int +server4_0_ftruncate (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_ftruncate_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_ftruncate_req, GF_FOP_FTRUNCATE); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + state->offset = args.offset; + memcpy (state->resolve.gfid, args.gfid, 16); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_ftruncate_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_fstat (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fstat_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fstat_req, GF_FOP_FSTAT); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_fstat_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_truncate (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_truncate_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_truncate_req, GF_FOP_TRUNCATE); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, args.gfid, 16); + state->offset = args.offset; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_truncate_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + +int +server4_0_unlink (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_unlink_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.bname = alloca (req->msg[0].iov_len); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_unlink_req, GF_FOP_UNLINK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.bname = gf_strdup (args.bname); + + set_resolve_gfid (frame->root->client, state->resolve.pargfid, + args.pargfid); + + state->flags = args.xflags; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_unlink_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_setxattr (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_setxattr_req args = {{0,},}; + int32_t ret = -1; + int32_t op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_setxattr_req, GF_FOP_SETXATTR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->flags = args.flags; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + ret = xdr_to_dict (&args.dict, &state->dict); + if (ret) + gf_msg_debug (THIS->name, EINVAL, + "dictionary not received"); + + /* There can be some commands hidden in key, check and proceed */ + gf_server_check_setxattr_cmd (frame, state->dict); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_setxattr_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + +int +server4_0_fsetxattr (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fsetxattr_req args = {{0,},}; + int32_t ret = -1; + int32_t op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fsetxattr_req, GF_FOP_FSETXATTR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + state->flags = args.flags; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + ret = xdr_to_dict (&args.dict, &state->dict); + if (ret) + gf_msg_debug (THIS->name, EINVAL, + "dictionary not received"); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_fsetxattr_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + +int +server4_0_fxattrop (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fxattrop_req args = {{0,},}; + int32_t ret = -1; + int32_t op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fxattrop_req, GF_FOP_FXATTROP); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + state->flags = args.flags; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + ret = xdr_to_dict (&args.dict, &state->dict); + if (ret) + gf_msg_debug (THIS->name, EINVAL, + "dictionary not received"); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_fxattrop_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_xattrop (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_xattrop_req args = {{0,},}; + int32_t ret = -1; + int32_t op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_xattrop_req, GF_FOP_XATTROP); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->flags = args.flags; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + ret = xdr_to_dict (&args.dict, &state->dict); + if (ret) + gf_msg_debug (THIS->name, EINVAL, + "dictionary not received"); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_xattrop_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_getxattr (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_getxattr_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.name = alloca (256); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_getxattr_req, GF_FOP_GETXATTR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + if (args.namelen) { + state->name = gf_strdup (args.name); + /* There can be some commands hidden in key, check and proceed */ + gf_server_check_getxattr_cmd (frame, state->name); + } + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_getxattr_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_fgetxattr (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fgetxattr_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.name = alloca (256); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fgetxattr_req, GF_FOP_FGETXATTR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + if (args.namelen) + state->name = gf_strdup (args.name); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_fgetxattr_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + +int +server4_0_removexattr (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_removexattr_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.name = alloca (256); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_removexattr_req, + GF_FOP_REMOVEXATTR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + state->name = gf_strdup (args.name); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_removexattr_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_fremovexattr (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fremovexattr_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.name = alloca (256); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fremovexattr_req, + GF_FOP_FREMOVEXATTR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + state->name = gf_strdup (args.name); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_fremovexattr_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + + +int +server4_0_opendir (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_opendir_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_opendir_req, GF_FOP_OPENDIR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_opendir_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_readdirp (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_readdirp_req args = {{0,},}; + size_t headers_size = 0; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_readdirp_req, + GF_FOP_READDIRP); + if (ret != 0) { + goto out; + } + + /* FIXME: this should go away when variable sized iobufs are introduced + * and transport layer can send msgs bigger than current page-size. + */ + headers_size = sizeof (struct rpc_msg) + sizeof (gfx_readdir_rsp); + if ((frame->this->ctx->page_size < args.size) + || ((frame->this->ctx->page_size - args.size) < headers_size)) { + state->size = frame->this->ctx->page_size - headers_size; + } else { + state->size = args.size; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + state->offset = args.offset; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + /* here, dict itself works as xdata */ + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_readdirp_resume); +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_readdir (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_readdir_req args = {{0,},}; + size_t headers_size = 0; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_readdir_req, GF_FOP_READDIR); + if (ret != 0) { + goto out; + } + + /* FIXME: this should go away when variable sized iobufs are introduced + * and transport layer can send msgs bigger than current page-size. + */ + headers_size = sizeof (struct rpc_msg) + sizeof (gfx_readdir_rsp); + if ((frame->this->ctx->page_size < args.size) + || ((frame->this->ctx->page_size - args.size) < headers_size)) { + state->size = frame->this->ctx->page_size - headers_size; + } else { + state->size = args.size; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + state->offset = args.offset; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_readdir_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_fsyncdir (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fsyncdir_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fsyncdir_req, GF_FOP_FSYNCDIR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + state->flags = args.data; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_fsyncdir_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + +int +server4_0_mknod (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_mknod_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.bname = alloca (req->msg[0].iov_len); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_mknod_req, GF_FOP_MKNOD); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_NOT; + set_resolve_gfid (frame->root->client, state->resolve.pargfid, + args.pargfid); + + state->resolve.bname = gf_strdup (args.bname); + + state->mode = args.mode; + state->dev = args.dev; + state->umask = args.umask; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_mknod_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; + +} + + +int +server4_0_mkdir (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_mkdir_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.bname = alloca (req->msg[0].iov_len); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_mkdir_req, GF_FOP_MKDIR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_NOT; + set_resolve_gfid (frame->root->client, state->resolve.pargfid, + args.pargfid); + state->resolve.bname = gf_strdup (args.bname); + + state->mode = args.mode; + state->umask = args.umask; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_mkdir_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + + + return ret; +} + + +int +server4_0_rmdir (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_rmdir_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.bname = alloca (req->msg[0].iov_len); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_rmdir_req, GF_FOP_RMDIR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.pargfid, + args.pargfid); + state->resolve.bname = gf_strdup (args.bname); + + state->flags = args.xflags; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_rmdir_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + +int +server4_0_inodelk (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_inodelk_req args = {{0,},}; + int cmd = 0; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.volume = alloca (256); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_inodelk_req, GF_FOP_INODELK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_EXACT; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + cmd = args.cmd; + switch (cmd) { + case GF_LK_GETLK: + state->cmd = F_GETLK; + break; + case GF_LK_SETLK: + state->cmd = F_SETLK; + break; + case GF_LK_SETLKW: + state->cmd = F_SETLKW; + break; + } + + state->type = args.type; + state->volume = gf_strdup (args.volume); + + gf_proto_flock_to_flock (&args.flock, &state->flock); + + switch (state->type) { + case GF_LK_F_RDLCK: + state->flock.l_type = F_RDLCK; + break; + case GF_LK_F_WRLCK: + state->flock.l_type = F_WRLCK; + break; + case GF_LK_F_UNLCK: + state->flock.l_type = F_UNLCK; + break; + } + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_inodelk_resume); +out: + + + free (args.flock.lk_owner.lk_owner_val); + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_finodelk (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_finodelk_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.volume = alloca (256); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_finodelk_req, + GF_FOP_FINODELK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_EXACT; + state->volume = gf_strdup (args.volume); + state->resolve.fd_no = args.fd; + state->cmd = args.cmd; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + switch (state->cmd) { + case GF_LK_GETLK: + state->cmd = F_GETLK; + break; + case GF_LK_SETLK: + state->cmd = F_SETLK; + break; + case GF_LK_SETLKW: + state->cmd = F_SETLKW; + break; + } + + state->type = args.type; + + gf_proto_flock_to_flock (&args.flock, &state->flock); + + switch (state->type) { + case GF_LK_F_RDLCK: + state->flock.l_type = F_RDLCK; + break; + case GF_LK_F_WRLCK: + state->flock.l_type = F_WRLCK; + break; + case GF_LK_F_UNLCK: + state->flock.l_type = F_UNLCK; + break; + } + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_finodelk_resume); +out: + + + free (args.flock.lk_owner.lk_owner_val); + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_entrylk (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_entrylk_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.volume = alloca (256); + args.name = alloca (256); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_entrylk_req, + GF_FOP_ENTRYLK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_EXACT; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + if (args.namelen) + state->name = gf_strdup (args.name); + state->volume = gf_strdup (args.volume); + + state->cmd = args.cmd; + state->type = args.type; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_entrylk_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_fentrylk (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fentrylk_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.name = alloca (256); + args.volume = alloca (256); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fentrylk_req, + GF_FOP_FENTRYLK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_EXACT; + state->resolve.fd_no = args.fd; + state->cmd = args.cmd; + state->type = args.type; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + if (args.namelen) + state->name = gf_strdup (args.name); + state->volume = gf_strdup (args.volume); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_fentrylk_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_access (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_access_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_access_req, GF_FOP_ACCESS); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + state->mask = args.mask; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_access_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + + +int +server4_0_symlink (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_symlink_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.bname = alloca (req->msg[0].iov_len); + args.linkname = alloca (4096); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_symlink_req, GF_FOP_SYMLINK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_NOT; + set_resolve_gfid (frame->root->client, state->resolve.pargfid, + args.pargfid); + state->resolve.bname = gf_strdup (args.bname); + state->name = gf_strdup (args.linkname); + state->umask = args.umask; + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_symlink_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_link (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_link_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.newbname = alloca (req->msg[0].iov_len); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_link_req, GF_FOP_LINK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + memcpy (state->resolve.gfid, args.oldgfid, 16); + + state->resolve2.type = RESOLVE_NOT; + state->resolve2.bname = gf_strdup (args.newbname); + set_resolve_gfid (frame->root->client, state->resolve2.pargfid, + args.newgfid); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_link_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_rename (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_rename_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + args.oldbname = alloca (req->msg[0].iov_len); + args.newbname = alloca (req->msg[0].iov_len); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_rename_req, GF_FOP_RENAME); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.bname = gf_strdup (args.oldbname); + set_resolve_gfid (frame->root->client, state->resolve.pargfid, + args.oldgfid); + + state->resolve2.type = RESOLVE_MAY; + state->resolve2.bname = gf_strdup (args.newbname); + set_resolve_gfid (frame->root->client, state->resolve2.pargfid, + args.newgfid); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_rename_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_lease (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_lease_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_lease_req, GF_FOP_LEASE); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + gf_proto_lease_to_lease (&args.lease, &state->lease); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_lease_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_lk (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_lk_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_lk_req, GF_FOP_LK); + if (ret != 0) { + goto out; + } + + state->resolve.fd_no = args.fd; + state->cmd = args.cmd; + state->type = args.type; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + switch (state->cmd) { + case GF_LK_GETLK: + state->cmd = F_GETLK; + break; + case GF_LK_SETLK: + state->cmd = F_SETLK; + break; + case GF_LK_SETLKW: + state->cmd = F_SETLKW; + break; + case GF_LK_RESLK_LCK: + state->cmd = F_RESLK_LCK; + break; + case GF_LK_RESLK_LCKW: + state->cmd = F_RESLK_LCKW; + break; + case GF_LK_RESLK_UNLCK: + state->cmd = F_RESLK_UNLCK; + break; + case GF_LK_GETLK_FD: + state->cmd = F_GETLK_FD; + break; + + } + + + gf_proto_flock_to_flock (&args.flock, &state->flock); + + switch (state->type) { + case GF_LK_F_RDLCK: + state->flock.l_type = F_RDLCK; + break; + case GF_LK_F_WRLCK: + state->flock.l_type = F_WRLCK; + break; + case GF_LK_F_UNLCK: + state->flock.l_type = F_UNLCK; + break; + default: + gf_msg (frame->root->client->bound_xl->name, GF_LOG_ERROR, + 0, PS_MSG_LOCK_ERROR, "fd - %"PRId64" (%s): Unknown " + "lock type: %"PRId32"!", state->resolve.fd_no, + uuid_utoa (state->fd->inode->gfid), state->type); + break; + } + + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_lk_resume); +out: + + + free (args.flock.lk_owner.lk_owner_val); + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_null (rpcsvc_request_t *req) +{ + gfx_common_rsp rsp = {0,}; + + /* Accepted */ + rsp.op_ret = 0; + + server_submit_reply (NULL, req, &rsp, NULL, 0, NULL, + (xdrproc_t)xdr_gfx_common_rsp); + + return 0; +} + +int +server4_0_lookup (rpcsvc_request_t *req) +{ + call_frame_t *frame = NULL; + server_state_t *state = NULL; + gfx_lookup_req args = {{0,},}; + int ret = -1; + + GF_VALIDATE_OR_GOTO ("server", req, err); + + args.bname = alloca (req->msg[0].iov_len); + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_lookup_req, GF_FOP_LOOKUP); + if (ret != 0) { + goto err; + } + + state->resolve.type = RESOLVE_DONTCARE; + + if (args.bname && strcmp (args.bname, "")) { + set_resolve_gfid (frame->root->client, state->resolve.pargfid, + args.pargfid); + state->resolve.bname = gf_strdup (args.bname); + } else { + set_resolve_gfid (frame->root->client, + state->resolve.gfid, args.gfid); + } + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_lookup_resume); + +err: + return ret; +} + +int +server4_0_statfs (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_statfs_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_statfs_req, GF_FOP_STATFS); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_statfs_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_getactivelk (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_getactivelk_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_getactivelk_req, + GF_FOP_GETACTIVELK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + /* here, dict itself works as xdata */ + xdr_to_dict (&args.xdata, &state->xdata); + + + ret = 0; + resolve_and_resume (frame, server4_getactivelk_resume); +out: + + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + + +int +server4_0_setactivelk (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_setactivelk_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_setactivelk_req, + GF_FOP_SETACTIVELK); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + set_resolve_gfid (frame->root->client, state->resolve.gfid, args.gfid); + + /* here, dict itself works as xdata */ + xdr_to_dict (&args.xdata, &state->xdata); + + ret = unserialize_req_locklist_v2 (&args, &state->locklist); + if (ret) + goto out; + + ret = 0; + + resolve_and_resume (frame, server4_setactivelk_resume); +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_namelink (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_namelink_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_namelink_req, GF_FOP_NAMELINK); + + if (ret != 0) + goto out; + + state->resolve.bname = gf_strdup (args.bname); + memcpy (state->resolve.pargfid, args.pargfid, sizeof (uuid_t)); + + state->resolve.type = RESOLVE_NOT; + + xdr_to_dict (&args.xdata, &state->xdata); + ret = 0; + resolve_and_resume (frame, server4_namelink_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; + +} + +int +server4_icreate (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_icreate_req args = {{0,},}; + int ret = -1; + int op_errno = 0; + uuid_t gfid = {0,}; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_icreate_req, GF_FOP_ICREATE); + + if (ret != 0) + goto out; + + memcpy (gfid, args.gfid, sizeof (uuid_t)); + + state->mode = args.mode; + gf_asprintf (&state->resolve.bname, INODE_PATH_FMT, uuid_utoa (gfid)); + + /* parent is an auxillary inode number */ + memset (state->resolve.pargfid, 0, sizeof (uuid_t)); + state->resolve.pargfid[15] = GF_AUXILLARY_PARGFID; + + state->resolve.type = RESOLVE_NOT; + + xdr_to_dict (&args.xdata, &state->xdata); + ret = 0; + resolve_and_resume (frame, server4_icreate_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_fsetattr (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_fsetattr_req args = {{0},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_fsetattr_req, + GF_FOP_FSETATTR); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MUST; + state->resolve.fd_no = args.fd; + memcpy (state->resolve.gfid, args.gfid, 16); + + gfx_stat_to_iattx (&args.stbuf, &state->stbuf); + state->valid = args.valid; + + xdr_to_dict (&args.xdata, &state->xdata); + ret = 0; + resolve_and_resume (frame, server4_fsetattr_resume); + +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_0_rchecksum (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_rchecksum_req args = {{0},}; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, NULL, &args, + xdr_gfx_rchecksum_req, + GF_FOP_RCHECKSUM); + if (ret != 0) { + goto out; + } + + state->resolve.type = RESOLVE_MAY; + state->resolve.fd_no = args.fd; + state->offset = args.offset; + state->size = args.len; + + memcpy (state->resolve.gfid, args.gfid, 16); + + xdr_to_dict (&args.xdata, &state->xdata); + ret = 0; + resolve_and_resume (frame, server4_rchecksum_resume); +out: + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} + +int +server4_compound_cbk (call_frame_t *frame, void *cookie, xlator_t *this, + int32_t op_ret, int32_t op_errno, void *data, + dict_t *xdata) +{ + struct gfx_compound_rsp rsp = {0,}; + server_state_t *state = NULL; + rpcsvc_request_t *req = NULL; + compound_args_cbk_t *args_cbk = data; + int i = 0; + + req = frame->local; + state = CALL_STATE (frame); + + dict_to_xdr (xdata, &rsp.xdata); + + if (op_ret) { + gf_msg (this->name, fop_log_level (GF_FOP_COMPOUND, op_errno), + op_errno, PS_MSG_COMPOUND_INFO, + "%"PRId64": COMPOUND%"PRId64" (%s), client: %s, " + "error-xlator: %s", frame->root->unique, + state->resolve.fd_no, uuid_utoa (state->resolve.gfid), + STACK_CLIENT_NAME (frame->root), + STACK_ERR_XL_NAME (frame->root)); + } + + rsp.compound_rsp_array.compound_rsp_array_val = GF_CALLOC + (args_cbk->fop_length, + sizeof (compound_rsp_v2), + gf_server_mt_compound_rsp_t); + + if (!rsp.compound_rsp_array.compound_rsp_array_val) { + op_ret = -1; + op_errno = ENOMEM; + goto out; + } + rsp.compound_rsp_array.compound_rsp_array_len = args_cbk->fop_length; + + for (i = 0; i < args_cbk->fop_length; i++) { + op_ret = server_populate_compound_response_v2 (this, &rsp, + frame, + args_cbk, i); + + if (op_ret) { + op_errno = op_ret; + op_ret = -1; + goto out; + } + } +out: + rsp.op_ret = op_ret; + rsp.op_errno = gf_errno_to_error (op_errno); + + server_submit_reply (frame, req, &rsp, NULL, 0, NULL, + (xdrproc_t) xdr_gfx_compound_rsp); + + server_compound_rsp_cleanup_v2 (&rsp, args_cbk); + GF_FREE (rsp.xdata.pairs.pairs_val); + + return 0; +} + +int +server4_compound_resume (call_frame_t *frame, xlator_t *bound_xl) +{ + server_state_t *state = NULL; + gfx_compound_req *req = NULL; + compound_args_t *args = NULL; + int i = 0; + int ret = -1; + int length = 0; + int op_errno = ENOMEM; + compound_req_v2 *c_req = NULL; + + state = CALL_STATE (frame); + + if (state->resolve.op_ret != 0) { + ret = state->resolve.op_ret; + op_errno = state->resolve.op_errno; + goto err; + } + + req = &state->req_v2; + + length = req->compound_req_array.compound_req_array_len; + state->args = compound_fop_alloc (length, req->compound_fop_enum, + state->xdata); + args = state->args; + + if (!args) + goto err; + + for (i = 0; i < length; i++) { + c_req = &req->compound_req_array.compound_req_array_val[i]; + args->enum_list[i] = c_req->fop_enum; + + ret = server_populate_compound_request_v2 (req, frame, + &args->req_list[i], + i); + + if (ret) { + op_errno = ret; + ret = -1; + goto err; + } + } + + STACK_WIND (frame, server4_compound_cbk, + bound_xl, bound_xl->fops->compound, + args, state->xdata); + + return 0; +err: + server4_compound_cbk (frame, NULL, frame->this, ret, op_errno, + NULL, NULL); + + return ret; +} +int +server4_0_compound (rpcsvc_request_t *req) +{ + server_state_t *state = NULL; + call_frame_t *frame = NULL; + gfx_compound_req args = {0,}; + ssize_t len = 0; + int length = 0; + int i = 0; + int ret = -1; + int op_errno = 0; + + if (!req) + return ret; + + ret = rpc_receive_common (req, &frame, &state, &len, &args, + xdr_gfx_compound_req, + GF_FOP_COMPOUND); + if (ret != 0) { + goto out; + } + + state->req_v2 = args; + state->iobref = iobref_ref (req->iobref); + + if (len < req->msg[0].iov_len) { + state->payload_vector[0].iov_base + = (req->msg[0].iov_base + len); + state->payload_vector[0].iov_len + = req->msg[0].iov_len - len; + state->payload_count = 1; + } + + for (i = 1; i < req->count; i++) { + state->payload_vector[state->payload_count++] + = req->msg[i]; + } + + state->size = iov_length (state->payload_vector, state->payload_count); + + ret = server_get_compound_resolve_v2 (state, &args); + + if (ret) { + SERVER_REQ_SET_ERROR (req, ret); + goto out; + } + + xdr_to_dict (&args.xdata, &state->xdata); + + ret = 0; + resolve_and_resume (frame, server4_compound_resume); +out: + + length = args.compound_req_array.compound_req_array_len; + server_compound_req_cleanup_v2 (&args, length); + free (args.compound_req_array.compound_req_array_val); + + if (op_errno) + SERVER_REQ_SET_ERROR (req, ret); + + return ret; +} diff --git a/xlators/protocol/server/src/server.h b/xlators/protocol/server/src/server.h index 70af9fdecd3..fe407689ceb 100644 --- a/xlators/protocol/server/src/server.h +++ b/xlators/protocol/server/src/server.h @@ -58,6 +58,28 @@ free (_req->xdata.xdata_val); \ } while (0) +#define CPD4_REQ_FIELD(v, f) ((v)->compound_req_v2_u.compound_##f##_req) +#define CPD4_RSP_FIELD(v, f) ((v)->compound_rsp_v2_u.compound_##f##_rsp) + +#define SERVER4_COMMON_RSP_CLEANUP(rsp, fop, i) \ + do { \ + compound_rsp_v2 *this_rsp = NULL; \ + this_rsp = &rsp->compound_rsp_array.compound_rsp_array_val[i]; \ + gfx_common_rsp *_this_rsp = &CPD4_RSP_FIELD(this_rsp, fop); \ + \ + GF_FREE (_this_rsp->xdata.pairs.pairs_val); \ + } while (0) + +#define SERVER4_FOP_RSP_CLEANUP(rsp, fop, i, rsp_type) \ + do { \ + compound_rsp_v2 *this_rsp = NULL; \ + this_rsp = &rsp->compound_rsp_array.compound_rsp_array_val[i]; \ + gfx_##rsp_type##_rsp *_this_rsp = &CPD4_RSP_FIELD(this_rsp, fop); \ + \ + GF_FREE (_this_rsp->xdata.pairs.pairs_val); \ + } while (0) + + typedef enum { INTERNAL_LOCKS = 1, POSIX_LOCKS = 2, @@ -196,6 +218,11 @@ struct _server_state { lock_migration_info_t locklist; /* required for compound fops */ gfs3_compound_req req; + /* TODO: having xdr definition here + is not a good idea, but not taking + up the functionality right now */ + gfx_compound_req req_v2; + /* last length till which iovec for compound * writes was processed */ int write_length; @@ -233,16 +260,6 @@ int gf_server_check_getxattr_cmd (call_frame_t *frame, const char *name); void forget_inode_if_no_dentry (inode_t *inode); -int -unserialize_req_locklist (gfs3_setactivelk_req *req, - lock_migration_info_t *lmi); - -int -serialize_rsp_dirent (gf_dirent_t *entries, gfs3_readdir_rsp *rsp); - -int -serialize_rsp_direntp (gf_dirent_t *entries, gfs3_readdirp_rsp *rsp); - server_ctx_t* server_ctx_get (client_t *client, xlator_t *xlator); #endif /* !_SERVER_H */ |